about summary refs log tree commit diff stats
path: root/tests/unittests/test_callbacks.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-04 21:10:11 +0100
committerJames Booth <boothj5@gmail.com>2016-07-04 21:10:11 +0100
commit3fe1d76a059f476372b242dee5f9fb93d434e66a (patch)
tree284361248bcc0439b65ad6a62f9c345af1ed302e /tests/unittests/test_callbacks.c
parent71879a3f64f5f04cdceeedf0317175b2bab1701c (diff)
downloadprofani-tty-3fe1d76a059f476372b242dee5f9fb93d434e66a.tar.gz
Unit test for callback_add_command()
Diffstat (limited to 'tests/unittests/test_callbacks.c')
-rw-r--r--tests/unittests/test_callbacks.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/tests/unittests/test_callbacks.c b/tests/unittests/test_callbacks.c
index 32959aa7..78693d4c 100644
--- a/tests/unittests/test_callbacks.c
+++ b/tests/unittests/test_callbacks.c
@@ -20,13 +20,38 @@ void returns_no_commands(void **state)
 void returns_commands(void **state)
 {
     callbacks_init();
-    PluginCommand *command = malloc(sizeof(PluginCommand));
-    command->command_name = strdup("something");
-    callbacks_add_command("Cool plugin", command);
 
-    GList *commands = plugins_get_command_names();
-    assert_true(g_list_length(commands) == 1);
+    PluginCommand *command1 = malloc(sizeof(PluginCommand));
+    command1->command_name = strdup("command1");
+    callbacks_add_command("plugin1", command1);
+
+    PluginCommand *command2 = malloc(sizeof(PluginCommand));
+    command2->command_name = strdup("command2");
+    callbacks_add_command("plugin1", command2);
+
+    PluginCommand *command3 = malloc(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);
+    }
 
-    char *name = commands->data;
-    assert_string_equal(name, "something");
+    assert_true(foundCommand1 && foundCommand2 && foundCommand3);
 }