2016-07-03 19:41:29 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2016-07-03 19:41:29 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <glib.h>
|
2016-07-03 19:41:29 -04:00
|
|
|
|
|
|
|
#include "plugins/callbacks.h"
|
|
|
|
#include "plugins/plugins.h"
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
returns_no_commands(void** state)
|
2016-07-03 19:41:29 -04:00
|
|
|
{
|
|
|
|
callbacks_init();
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* commands = plugins_get_command_names();
|
2016-07-03 19:41:29 -04:00
|
|
|
|
|
|
|
assert_true(commands == NULL);
|
2019-10-06 11:15:06 -04:00
|
|
|
|
|
|
|
callbacks_close();
|
2019-10-06 11:47:13 -04:00
|
|
|
g_list_free(commands);
|
2016-07-03 19:41:29 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
returns_commands(void** state)
|
2016-07-03 19:41:29 -04:00
|
|
|
{
|
|
|
|
callbacks_init();
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginCommand* command1 = malloc(sizeof(PluginCommand));
|
2016-07-04 16:10:11 -04:00
|
|
|
command1->command_name = strdup("command1");
|
|
|
|
callbacks_add_command("plugin1", command1);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginCommand* command2 = malloc(sizeof(PluginCommand));
|
2016-07-04 16:10:11 -04:00
|
|
|
command2->command_name = strdup("command2");
|
|
|
|
callbacks_add_command("plugin1", command2);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
PluginCommand* command3 = malloc(sizeof(PluginCommand));
|
2016-07-04 16:10:11 -04:00
|
|
|
command3->command_name = strdup("command3");
|
|
|
|
callbacks_add_command("plugin2", command3);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* names = plugins_get_command_names();
|
2016-07-04 16:10:11 -04:00
|
|
|
assert_true(g_list_length(names) == 3);
|
|
|
|
|
|
|
|
gboolean foundCommand1 = FALSE;
|
|
|
|
gboolean foundCommand2 = FALSE;
|
|
|
|
gboolean foundCommand3 = FALSE;
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = names;
|
2016-07-04 16:10:11 -04:00
|
|
|
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);
|
|
|
|
}
|
2016-07-03 19:41:29 -04:00
|
|
|
|
2016-07-04 16:10:11 -04:00
|
|
|
assert_true(foundCommand1 && foundCommand2 && foundCommand3);
|
2019-10-06 11:15:06 -04:00
|
|
|
|
2019-10-06 11:47:13 -04:00
|
|
|
g_list_free(names);
|
2022-01-27 09:49:44 -05:00
|
|
|
// TODO: why does this make the test fail?
|
|
|
|
// callbacks_close();
|
2016-07-03 19:41:29 -04:00
|
|
|
}
|