From 6295336284e0d01a0adea89d98701b80f9ee4bfe Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Feb 2014 00:04:53 +0000 Subject: [PATCH] Added cmd_otr tests --- Makefile.am | 1 + src/command/commands.c | 5 +++++ tests/test_cmd_otr.c | 45 ++++++++++++++++++++++++++++++++++++++++++ tests/test_cmd_otr.h | 7 +++++++ tests/testsuite.c | 9 +++++++++ 5 files changed, 67 insertions(+) create mode 100644 tests/test_cmd_otr.c create mode 100644 tests/test_cmd_otr.h 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 +#include +#include +#include +#include +#include +#include + +#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 #include +#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);