2014-01-23 17:29:53 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2014-01-23 17:29:53 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <glib.h>
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
#include "xmpp/xmpp.h"
|
|
|
|
|
|
|
|
#include "ui/ui.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "ui/stub_ui.h"
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
#include "config/preferences.h"
|
|
|
|
|
2016-05-22 18:59:52 -04:00
|
|
|
#include "command/cmd_defs.h"
|
|
|
|
#include "command/cmd_funcs.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "command/cmd_ac.h"
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
#define CMD_ALIAS "/alias"
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_add_shows_usage_when_no_args(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "add", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-02-22 22:22:56 -05:00
|
|
|
assert_true(result);
|
2014-01-23 17:29:53 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_add_shows_usage_when_no_value(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "add", "alias", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_remove_shows_usage_when_no_args(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "remove", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_show_usage_when_invalid_subcmd(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "blah", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
expect_string(cons_bad_cmd_usage, cmd, CMD_ALIAS);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_add_adds_alias(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "add", "hc", "/help commands", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
expect_cons_show("Command alias added /hc -> /help commands");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
|
|
|
assert_true(result);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2023-07-11 07:23:58 -04:00
|
|
|
gchar* returned_val = prefs_get_alias("hc");
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_string_equal("/help commands", returned_val);
|
2019-10-06 12:45:53 -04:00
|
|
|
|
|
|
|
free(returned_val);
|
2014-01-23 17:29:53 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_add_shows_message_when_exists(void** state)
|
2014-01-23 17:38:12 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "add", "hc", "/help commands", NULL };
|
2014-01-23 17:38:12 -05:00
|
|
|
|
2014-01-24 20:39:12 -05:00
|
|
|
cmd_init();
|
2014-01-23 17:38:12 -05:00
|
|
|
prefs_add_alias("hc", "/help commands");
|
2016-05-19 19:19:03 -04:00
|
|
|
cmd_ac_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
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:38:12 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_remove_removes_alias(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "remove", "hn", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
prefs_add_alias("hn", "/help navigation");
|
|
|
|
|
|
|
|
expect_cons_show("Command alias removed -> /hn");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
|
|
|
assert_true(result);
|
2014-01-23 17:29:53 -05:00
|
|
|
|
2023-07-11 07:23:58 -04:00
|
|
|
gchar* returned_val = prefs_get_alias("hn");
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_null(returned_val);
|
2020-07-07 08:18:57 -04:00
|
|
|
|
2019-10-06 12:45:53 -04:00
|
|
|
free(returned_val);
|
2014-01-23 17:29:53 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_remove_shows_message_when_no_alias(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "remove", "hn", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
expect_cons_show("No such command alias /hn");
|
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
cmd_alias_list_shows_all_aliases(void** state)
|
2014-01-23 17:29:53 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
gchar* args[] = { "list", NULL };
|
2014-01-23 17:29:53 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2015-07-26 19:04:48 -04:00
|
|
|
gboolean result = cmd_alias(NULL, CMD_ALIAS, args);
|
2014-01-23 17:29:53 -05:00
|
|
|
assert_true(result);
|
|
|
|
}
|