1 #include <stdarg.h>
2 #include <stddef.h>
3 #include <setjmp.h>
4 #include <cmocka.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <glib.h>
8 
9 #include "plugins/callbacks.h"
10 #include "plugins/plugins.h"
11 
12 void
returns_no_commands(void ** state)13 returns_no_commands(void** state)
14 {
15     callbacks_init();
16     GList* commands = plugins_get_command_names();
17 
18     assert_true(commands == NULL);
19 
20     callbacks_close();
21     g_list_free(commands);
22 }
23 
24 void
returns_commands(void ** state)25 returns_commands(void** state)
26 {
27     callbacks_init();
28 
29     PluginCommand* command1 = malloc(sizeof(PluginCommand));
30     command1->command_name = strdup("command1");
31     callbacks_add_command("plugin1", command1);
32 
33     PluginCommand* command2 = malloc(sizeof(PluginCommand));
34     command2->command_name = strdup("command2");
35     callbacks_add_command("plugin1", command2);
36 
37     PluginCommand* command3 = malloc(sizeof(PluginCommand));
38     command3->command_name = strdup("command3");
39     callbacks_add_command("plugin2", command3);
40 
41     GList* names = plugins_get_command_names();
42     assert_true(g_list_length(names) == 3);
43 
44     gboolean foundCommand1 = FALSE;
45     gboolean foundCommand2 = FALSE;
46     gboolean foundCommand3 = FALSE;
47     GList* curr = names;
48     while (curr) {
49         if (g_strcmp0(curr->data, "command1") == 0) {
50             foundCommand1 = TRUE;
51         }
52         if (g_strcmp0(curr->data, "command2") == 0) {
53             foundCommand2 = TRUE;
54         }
55         if (g_strcmp0(curr->data, "command3") == 0) {
56             foundCommand3 = TRUE;
57         }
58         curr = g_list_next(curr);
59     }
60 
61     assert_true(foundCommand1 && foundCommand2 && foundCommand3);
62 
63     g_list_free(names);
64     //TODO: why does this make the test fail?
65     //callbacks_close();
66 }
67