mirror of
https://github.com/profanity-im/profanity.git
synced 2024-10-27 20:30:13 -04:00
Unit test for callback_add_command()
This commit is contained in:
parent
71879a3f64
commit
3fe1d76a05
@ -20,13 +20,38 @@ void returns_no_commands(void **state)
|
|||||||
void returns_commands(void **state)
|
void returns_commands(void **state)
|
||||||
{
|
{
|
||||||
callbacks_init();
|
callbacks_init();
|
||||||
PluginCommand *command = malloc(sizeof(PluginCommand));
|
|
||||||
command->command_name = strdup("something");
|
|
||||||
callbacks_add_command("Cool plugin", command);
|
|
||||||
|
|
||||||
GList *commands = plugins_get_command_names();
|
PluginCommand *command1 = malloc(sizeof(PluginCommand));
|
||||||
assert_true(g_list_length(commands) == 1);
|
command1->command_name = strdup("command1");
|
||||||
|
callbacks_add_command("plugin1", command1);
|
||||||
|
|
||||||
char *name = commands->data;
|
PluginCommand *command2 = malloc(sizeof(PluginCommand));
|
||||||
assert_string_equal(name, "something");
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_true(foundCommand1 && foundCommand2 && foundCommand3);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user