2014-01-23 17:29:53 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "xmpp/xmpp.h"
|
|
|
|
|
|
|
|
#include "ui/ui.h"
|
2014-12-24 15:11:24 -05:00
|
|
|
#include "ui/stub_ui.h"
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
#include "config/preferences.h"
|
|
|
|
|
2014-01-23 18:53:20 -05:00
|
|
|
#include "command/command.h"
|
2014-01-23 17:29:53 -05:00
|
|
|
#include "command/commands.h"
|
|
|
|
|
|
|
|
void cmd_alias_add_shows_usage_when_no_args(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
help->usage = "some usage";
|
|
|
|
gchar *args[] = { "add", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("Usage: some usage");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
2014-02-22 22:22:56 -05:00
|
|
|
assert_true(result);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_add_shows_usage_when_no_value(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
help->usage = "some usage";
|
|
|
|
gchar *args[] = { "add", "alias", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("Usage: some usage");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_remove_shows_usage_when_no_args(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
help->usage = "some usage";
|
|
|
|
gchar *args[] = { "remove", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("Usage: some usage");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_show_usage_when_invalid_subcmd(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
help->usage = "some usage";
|
|
|
|
gchar *args[] = { "blah", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("Usage: some usage");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_add_adds_alias(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "add", "hc", "/help commands", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("Command alias added /hc -> /help commands");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
|
|
|
|
char *returned_val = prefs_get_alias("hc");
|
|
|
|
|
|
|
|
assert_true(result);
|
|
|
|
assert_string_equal("/help commands", returned_val);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:38:12 -05:00
|
|
|
void cmd_alias_add_shows_message_when_exists(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "add", "hc", "/help commands", NULL };
|
|
|
|
|
2014-01-24 20:39:12 -05:00
|
|
|
cmd_init();
|
2014-01-23 17:38:12 -05:00
|
|
|
prefs_add_alias("hc", "/help commands");
|
2014-01-24 20:39:12 -05:00
|
|
|
cmd_autocomplete_add("/hc");
|
2014-01-23 17:38:12 -05:00
|
|
|
|
2014-01-28 16:51:43 -05:00
|
|
|
expect_cons_show("Command or alias '/hc' already exists.");
|
2014-01-23 17:38:12 -05:00
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
2014-01-23 17:29:53 -05:00
|
|
|
void cmd_alias_remove_removes_alias(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "remove", "hn", NULL };
|
|
|
|
|
|
|
|
prefs_add_alias("hn", "/help navigation");
|
|
|
|
|
|
|
|
expect_cons_show("Command alias removed -> /hn");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
|
|
|
|
char *returned_val = prefs_get_alias("hn");
|
|
|
|
|
|
|
|
assert_true(result);
|
|
|
|
assert_null(returned_val);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_remove_shows_message_when_no_alias(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "remove", "hn", NULL };
|
|
|
|
|
|
|
|
expect_cons_show("No such command alias /hn");
|
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmd_alias_list_shows_all_aliases(void **state)
|
|
|
|
{
|
|
|
|
CommandHelp *help = malloc(sizeof(CommandHelp));
|
|
|
|
gchar *args[] = { "list", NULL };
|
|
|
|
|
|
|
|
prefs_add_alias("vy", "/vercheck on");
|
|
|
|
prefs_add_alias("q", "/quit");
|
|
|
|
prefs_add_alias("hn", "/help navigation");
|
|
|
|
prefs_add_alias("hc", "/help commands");
|
|
|
|
prefs_add_alias("vn", "/vercheck off");
|
|
|
|
|
|
|
|
// write a custom checker to check the correct list is passed
|
2014-12-24 15:11:24 -05:00
|
|
|
expect_any(cons_show_aliases, aliases);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
gboolean result = cmd_alias(args, *help);
|
|
|
|
assert_true(result);
|
|
|
|
|
|
|
|
free(help);
|
|
|
|
}
|