about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-02-16 00:04:53 +0000
committerJames Booth <boothj5@gmail.com>2014-02-16 00:04:53 +0000
commit6295336284e0d01a0adea89d98701b80f9ee4bfe (patch)
treeeb6b9df6d5c7d263faf50bff807b7cdf6497429c /tests
parentf010dfb004a44203a16d0a804576223e60ae4a29 (diff)
downloadprofani-tty-6295336284e0d01a0adea89d98701b80f9ee4bfe.tar.gz
Added cmd_otr tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd_otr.c45
-rw-r--r--tests/test_cmd_otr.h7
-rw-r--r--tests/testsuite.c9
3 files changed, 61 insertions, 0 deletions
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);