diff options
author | James Booth <boothj5@gmail.com> | 2014-01-19 01:25:04 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-01-19 01:25:04 +0000 |
commit | c7325de0732cdb50ee8f339dc4f5a74ad30cc92f (patch) | |
tree | 1e1eb9bda9b06e4ae42de049466d79d77b6d638d | |
parent | 2f58b2488f66761d693d071861bbfbf228f06602 (diff) | |
download | profani-tty-c7325de0732cdb50ee8f339dc4f5a74ad30cc92f.tar.gz |
Added cmd_statuses validation tests
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/command/command.c | 25 | ||||
-rw-r--r-- | src/command/commands.c | 23 | ||||
-rw-r--r-- | tests/test_cmd_statuses.c | 72 | ||||
-rw-r--r-- | tests/test_cmd_statuses.h | 4 | ||||
-rw-r--r-- | tests/testsuite.c | 6 |
6 files changed, 122 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am index 700f437a..bb662711 100644 --- a/Makefile.am +++ b/Makefile.am @@ -73,6 +73,7 @@ test_sources = \ tests/test_cmd_account.c \ tests/test_cmd_rooms.c \ tests/test_cmd_sub.c \ + tests/test_cmd_statuses.c \ tests/test_history.c \ tests/test_jid.c \ tests/test_parser.c \ diff --git a/src/command/command.c b/src/command/command.c index 31af72c4..717656bf 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -755,13 +755,24 @@ static struct cmd_t command_defs[] = { "/statuses", - cmd_statuses, parse_args, 1, 1, &cons_statuses_setting, - { "/statuses on|off", "Set notifications for status messages.", - { "/statuses on|off", - "----------------", - "Show status updates from contacts, such as online/offline/away etc.", - "When disabled, status updates are not displayed.", - "The default is 'on'.", + cmd_statuses, parse_args, 2, 2, &cons_statuses_setting, + { "/statuses console|chat|muc setting", "Set preferences for presence change messages.", + { "/statuses console|chat|muc setting", + "----------------------------------", + "Configure how presence changes are displayed in various windows.", + "Settings for the console:", + "all - Show all presence changes in the console", + "online - Show only when contacts log in/out.", + "none - Don't show any presence changes in the console.", + "Settings for chat windows:", + "all - Show all presence changes in the contact's chat window if one is open.", + "online - Show only when contacts log in/out.", + "none - Don't show any presence changes in the chat windows.", + "Settings for chat room windows:", + "on - Show presence changes in chat rooms.", + "off - Do not show presence changes in chat rooms (user entering/leaving are still displayed).", + "The defaults are:", + "console - all, chat - all, muc - on.", NULL } } }, { "/away", diff --git a/src/command/commands.c b/src/command/commands.c index 90cf8134..1a4e8c83 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2253,8 +2253,27 @@ cmd_priority(gchar **args, struct cmd_help_t help) gboolean cmd_statuses(gchar **args, struct cmd_help_t help) { - return _cmd_set_boolean_preference(args[0], help, - "Status notifications", PREF_STATUSES); + if (strcmp(args[0], "console") != 0 && + strcmp(args[0], "chat") != 0 && + strcmp(args[0], "muc") != 0) { + cons_show("Usage: %s", help.usage); + } + + if (strcmp(args[0], "console") == 0 || strcmp(args[0], "chat") == 0) { + if (strcmp(args[1], "all") != 0 && + strcmp(args[1], "online") != 0 && + strcmp(args[1], "none") != 0) { + cons_show("Usage: %s", help.usage); + } + + } + + if (strcmp(args[0], "muc") == 0) { + if (strcmp(args[1], "on") != 0 && strcmp(args[1], "off") != 0) { + cons_show("Usage: %s", help.usage); + } + } + return TRUE; } gboolean diff --git a/tests/test_cmd_statuses.c b/tests/test_cmd_statuses.c new file mode 100644 index 00000000..1cc7a277 --- /dev/null +++ b/tests/test_cmd_statuses.c @@ -0,0 +1,72 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#include "ui/ui.h" +#include "ui/mock_ui.h" + +#include "command/commands.h" + +void cmd_statuses_shows_usage_when_bad_subcmd(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "badcmd", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_console_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "console", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_chat_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "chat", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} + +void cmd_statuses_shows_usage_when_bad_muc_setting(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "some usage"; + gchar *args[] = { "muc", "badsetting", NULL }; + + expect_cons_show("Usage: some usage"); + + gboolean result = cmd_statuses(args, *help); + assert_true(result); + + free(help); +} diff --git a/tests/test_cmd_statuses.h b/tests/test_cmd_statuses.h new file mode 100644 index 00000000..473bd212 --- /dev/null +++ b/tests/test_cmd_statuses.h @@ -0,0 +1,4 @@ +void cmd_statuses_shows_usage_when_bad_subcmd(void **state); +void cmd_statuses_shows_usage_when_bad_console_setting(void **state); +void cmd_statuses_shows_usage_when_bad_chat_setting(void **state); +void cmd_statuses_shows_usage_when_bad_muc_setting(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index ade951e1..7d1e5165 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -10,6 +10,7 @@ #include "test_cmd_account.h" #include "test_cmd_rooms.h" #include "test_cmd_sub.h" +#include "test_cmd_statuses.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" @@ -295,6 +296,11 @@ int main(int argc, char* argv[]) { unit_test(contact_available_when_highest_priority_online), unit_test(contact_available_when_highest_priority_chat), + unit_test(cmd_statuses_shows_usage_when_bad_subcmd), + unit_test(cmd_statuses_shows_usage_when_bad_console_setting), + unit_test(cmd_statuses_shows_usage_when_bad_chat_setting), + unit_test(cmd_statuses_shows_usage_when_bad_muc_setting), + }; return run_tests(tests); } |