cleanup: Map test files according to structure in src

For example cmd_account() is located in src/command/cmd_funcs.c.
The unit test was located in tests/unittests/test_cmd_account.c.
Let's move it to a subdirectory like tests/unittests/command/test_cmd_account.c
to correpsond to the same structure.
This commit is contained in:
Michael Vetter
2026-02-28 11:28:24 +01:00
parent 38624f26a5
commit a7408a970e
53 changed files with 74 additions and 74 deletions

View File

@@ -0,0 +1,57 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "plugins/callbacks.h"
#include "plugins/plugins.h"
void
returns_no_commands(void** state)
{
plugins_init();
GList* commands = plugins_get_command_names();
assert_true(commands == NULL);
}
void
returns_commands(void** state)
{
plugins_init();
PluginCommand* command1 = g_new0(PluginCommand, 1);
command1->command_name = g_strdup("command1");
callbacks_add_command("plugin1", command1);
PluginCommand* command2 = g_new0(PluginCommand, 1);
command2->command_name = g_strdup("command2");
callbacks_add_command("plugin1", command2);
PluginCommand* command3 = g_new0(PluginCommand, 1);
command3->command_name = g_strdup("command3");
callbacks_add_command("plugin2", command3);
GList* names = plugins_get_command_names();
assert_true(g_list_length(names) == 3);
gboolean foundCommand1 = FALSE;
gboolean foundCommand2 = FALSE;
gboolean foundCommand3 = FALSE;
GList* curr = names;
while (curr) {
if (g_strcmp0(curr->data, "command1") == 0) {
foundCommand1 = TRUE;
}
if (g_strcmp0(curr->data, "command2") == 0) {
foundCommand2 = TRUE;
}
if (g_strcmp0(curr->data, "command3") == 0) {
foundCommand3 = TRUE;
}
curr = g_list_next(curr);
}
assert_true(foundCommand1 && foundCommand2 && foundCommand3);
g_list_free(names);
}

View File

@@ -0,0 +1,2 @@
void returns_no_commands(void** state);
void returns_commands(void** state);

View File

@@ -0,0 +1,128 @@
#include "prof_cmocka.h"
#include <stdlib.h>
#include "plugins/disco.h"
void
returns_empty_list_when_none(void** state)
{
disco_close();
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 0);
g_list_free(features);
disco_close();
}
void
returns_added_feature(void** state)
{
disco_close();
disco_add_feature("my_plugin", "some:feature:example");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 1);
char* feature = features->data;
assert_string_equal(feature, "some:feature:example");
g_list_free(features);
disco_close();
}
void
resets_features_on_close(void** state)
{
disco_close();
disco_add_feature("my_plugin", "some:feature:example");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 1);
g_list_free(features);
disco_close();
features = disco_get_features();
assert_int_equal(g_list_length(features), 0);
g_list_free(features);
disco_close();
}
void
returns_all_added_features(void** state)
{
disco_close();
disco_add_feature("first_plugin", "first:feature");
disco_add_feature("first_plugin", "second:feature");
disco_add_feature("second_plugin", "third:feature");
disco_add_feature("third_plugin", "fourth:feature");
disco_add_feature("third_plugin", "fifth:feature");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 5);
assert_true(g_list_find_custom(features, "first:feature", (GCompareFunc)g_strcmp0));
assert_true(g_list_find_custom(features, "second:feature", (GCompareFunc)g_strcmp0));
assert_true(g_list_find_custom(features, "third:feature", (GCompareFunc)g_strcmp0));
assert_true(g_list_find_custom(features, "fourth:feature", (GCompareFunc)g_strcmp0));
assert_true(g_list_find_custom(features, "fifth:feature", (GCompareFunc)g_strcmp0));
g_list_free(features);
disco_close();
}
void
does_not_add_duplicate_feature(void** state)
{
disco_close();
disco_add_feature("my_plugin", "my:feature");
disco_add_feature("some_other_plugin", "my:feature");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 1);
g_list_free(features);
disco_close();
}
void
removes_plugin_features(void** state)
{
disco_close();
disco_add_feature("plugin1", "plugin1:feature1");
disco_add_feature("plugin1", "plugin1:feature2");
disco_add_feature("plugin2", "plugin2:feature1");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 3);
g_list_free(features);
disco_remove_features("plugin1");
features = disco_get_features();
assert_int_equal(g_list_length(features), 1);
g_list_free(features);
disco_close();
}
void
does_not_remove_feature_when_more_than_one_reference(void** state)
{
disco_close();
disco_add_feature("plugin1", "feature1");
disco_add_feature("plugin1", "feature2");
disco_add_feature("plugin2", "feature1");
GList* features = disco_get_features();
assert_int_equal(g_list_length(features), 2);
g_list_free(features);
disco_remove_features("plugin1");
features = disco_get_features();
assert_int_equal(g_list_length(features), 1);
g_list_free(features);
disco_close();
}

View File

@@ -0,0 +1,7 @@
void returns_empty_list_when_none(void** state);
void returns_added_feature(void** state);
void resets_features_on_close(void** state);
void returns_all_added_features(void** state);
void does_not_add_duplicate_feature(void** state);
void removes_plugin_features(void** state);
void does_not_remove_feature_when_more_than_one_reference(void** state);