While trying to get the unit tests working again I stumbled over all those things that I thought could be better^TM. Now we also know "TODO: why does this make the test fail?" - because the unit tests are brittle AF ... and we have to init the subsystems we use in the test, otherwise the cleanup will fail... BTW. you can now also only run a single test ... or a pattern or so ... you'd have to read how `cmocka_set_test_filter()` works exactly. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <setjmp.h>
|
|
#include <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)
|
|
{
|
|
callbacks_init();
|
|
GList* commands = plugins_get_command_names();
|
|
|
|
assert_true(commands == NULL);
|
|
}
|
|
|
|
void
|
|
returns_commands(void** state)
|
|
{
|
|
callbacks_init();
|
|
|
|
PluginCommand* command1 = calloc(1, sizeof(PluginCommand));
|
|
command1->command_name = strdup("command1");
|
|
callbacks_add_command("plugin1", command1);
|
|
|
|
PluginCommand* command2 = calloc(1, sizeof(PluginCommand));
|
|
command2->command_name = strdup("command2");
|
|
callbacks_add_command("plugin1", command2);
|
|
|
|
PluginCommand* command3 = calloc(1, sizeof(PluginCommand));
|
|
command3->command_name = 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);
|
|
}
|