diff options
author | James Booth <boothj5@gmail.com> | 2014-02-16 00:04:53 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-02-16 00:04:53 +0000 |
commit | 6295336284e0d01a0adea89d98701b80f9ee4bfe (patch) | |
tree | eb6b9df6d5c7d263faf50bff807b7cdf6497429c | |
parent | f010dfb004a44203a16d0a804576223e60ae4a29 (diff) | |
download | profani-tty-6295336284e0d01a0adea89d98701b80f9ee4bfe.tar.gz |
Added cmd_otr tests
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/command/commands.c | 5 | ||||
-rw-r--r-- | tests/test_cmd_otr.c | 45 | ||||
-rw-r--r-- | tests/test_cmd_otr.h | 7 | ||||
-rw-r--r-- | tests/testsuite.c | 9 |
5 files changed, 67 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 2d63d3c1..a2d5058e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,6 +80,7 @@ test_sources = \ tests/test_cmd_alias.c \ tests/test_cmd_statuses.c \ tests/test_cmd_bookmark.c \ + tests/test_cmd_otr.c \ tests/test_history.c \ tests/test_jid.c \ tests/test_parser.c \ diff --git a/src/command/commands.c b/src/command/commands.c index 3137970a..397c6a54 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2566,6 +2566,11 @@ gboolean cmd_otr(gchar **args, struct cmd_help_t help) { #ifdef HAVE_LIBOTR + if (args[0] == NULL) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + if (strcmp(args[0], "log") == 0) { char *choice = args[1]; if (g_strcmp0(choice, "on") == 0) { diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c new file mode 100644 index 00000000..940614a2 --- /dev/null +++ b/tests/test_cmd_otr.c @@ -0,0 +1,45 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#include "config.h" + +#include "ui/mock_ui.h" + +#include "command/command.h" +#include "command/commands.h" + +#ifdef HAVE_LIBOTR +void cmd_otr_shows_usage_when_no_args(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "Some usage"; + gchar *args[] = { NULL }; + + expect_cons_show("Usage: Some usage"); + + gboolean result = cmd_otr(args, *help); + assert_true(result); + + free(help); +} +#else +void cmd_otr_shows_message_when_otr_unsupported(void **state) +{ + mock_cons_show(); + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "gen", NULL }; + + expect_cons_show("This version of Profanity has not been built with OTR support enabled"); + + gboolean result = cmd_otr(args, *help); + assert_true(result); + + free(help); +} +#endif diff --git a/tests/test_cmd_otr.h b/tests/test_cmd_otr.h new file mode 100644 index 00000000..e4a84281 --- /dev/null +++ b/tests/test_cmd_otr.h @@ -0,0 +1,7 @@ +#include "config.h" + +#ifdef HAVE_LIBOTR +void cmd_otr_shows_usage_when_no_args(void **state); +#else +void cmd_otr_shows_message_when_otr_unsupported(void **state); +#endif diff --git a/tests/testsuite.c b/tests/testsuite.c index 5e246020..fd7a6524 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -7,6 +7,8 @@ #include <cmocka.h> #include <sys/stat.h> +#include "config.h" + #include "helpers.h" #include "test_autocomplete.h" #include "test_common.h" @@ -16,6 +18,7 @@ #include "test_cmd_rooms.h" #include "test_cmd_sub.h" #include "test_cmd_statuses.h" +#include "test_cmd_otr.h" #include "test_history.h" #include "test_jid.h" #include "test_parser.h" @@ -423,6 +426,12 @@ int main(int argc, char* argv[]) { unit_test(cmd_bookmark_add_shows_message_when_upated), unit_test(cmd_bookmark_remove_shows_message_when_no_bookmark), unit_test(cmd_bookmark_remove_autojoin_shows_message_when_no_bookmark), + +#ifdef HAVE_LIBOTR + unit_test(cmd_otr_shows_usage_when_no_args), +#else + unit_test(cmd_otr_shows_message_when_otr_unsupported), +#endif }; return run_tests(all_tests); |