about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_cmd_account.c10
-rw-r--r--tests/unittests/test_cmd_pgp.c43
-rw-r--r--tests/unittests/test_cmd_pgp.h7
-rw-r--r--tests/unittests/unittests.c7
4 files changed, 64 insertions, 3 deletions
diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c
index c1609065..8aa13609 100644
--- a/tests/unittests/test_cmd_account.c
+++ b/tests/unittests/test_cmd_account.c
@@ -926,8 +926,7 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
 {
     CommandHelp *help = malloc(sizeof(CommandHelp));
     gchar *args[] = { "set", "a_account", "online", "10", NULL };
-    ProfAccount *account = account_new("a_account", "a_jid", NULL, NULL, TRUE, NULL, 5222, "a_resource",
-        NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+
 
     expect_any(accounts_account_exists, account_name);
     will_return(accounts_account_exists, TRUE);
@@ -941,10 +940,15 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
     will_return(accounts_get_last_presence, RESOURCE_ONLINE);
 
     will_return(jabber_get_account_name, "a_account");
-    will_return(jabber_get_account_name, "a_account");
 
+#ifdef HAVE_LIBGPGME
+    ProfAccount *account = account_new("a_account", "a_jid", NULL, NULL, TRUE, NULL, 5222, "a_resource",
+        NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+
+    will_return(jabber_get_account_name, "a_account");
     expect_any(accounts_get_account, name);
     will_return(accounts_get_account, account);
+#endif
 
     will_return(jabber_get_presence_message, "Free to chat");
 
diff --git a/tests/unittests/test_cmd_pgp.c b/tests/unittests/test_cmd_pgp.c
new file mode 100644
index 00000000..7ee0e776
--- /dev/null
+++ b/tests/unittests/test_cmd_pgp.c
@@ -0,0 +1,43 @@
+#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 "command/commands.h"
+
+#include "ui/stub_ui.h"
+
+#ifdef HAVE_LIBGPGME
+void cmd_pgp_shows_usage_when_no_args(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    help->usage = "Some usage";
+    gchar *args[] = { NULL };
+
+    expect_cons_show("Usage: Some usage");
+
+    gboolean result = cmd_pgp(NULL, args, *help);
+    assert_true(result);
+
+    free(help);
+}
+
+#else
+void cmd_pgp_shows_message_when_pgp_unsupported(void **state)
+{
+    CommandHelp *help = malloc(sizeof(CommandHelp));
+    gchar *args[] = { "gen", NULL };
+
+    expect_cons_show("This version of Profanity has not been built with PGP support enabled");
+
+    gboolean result = cmd_pgp(NULL, args, *help);
+    assert_true(result);
+
+    free(help);
+}
+#endif
diff --git a/tests/unittests/test_cmd_pgp.h b/tests/unittests/test_cmd_pgp.h
new file mode 100644
index 00000000..e7ed0b20
--- /dev/null
+++ b/tests/unittests/test_cmd_pgp.h
@@ -0,0 +1,7 @@
+#include "config.h"
+
+#ifdef HAVE_LIBGPGME
+void cmd_pgp_shows_usage_when_no_args(void **state);
+#else
+void cmd_pgp_shows_message_when_pgp_unsupported(void **state);
+#endif
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
index 3f860178..6e9c13bf 100644
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -21,6 +21,7 @@
 #include "test_cmd_sub.h"
 #include "test_cmd_statuses.h"
 #include "test_cmd_otr.h"
+#include "test_cmd_pgp.h"
 #include "test_jid.h"
 #include "test_parser.h"
 #include "test_roster_list.h"
@@ -539,6 +540,12 @@ int main(int argc, char* argv[]) {
         unit_test(cmd_otr_shows_message_when_otr_unsupported),
 #endif
 
+#ifdef HAVE_LIBGPGME
+        unit_test(cmd_pgp_shows_usage_when_no_args),
+#else
+        unit_test(cmd_pgp_shows_message_when_pgp_unsupported),
+#endif
+
         unit_test(cmd_join_shows_message_when_disconnecting),
         unit_test(cmd_join_shows_message_when_connecting),
         unit_test(cmd_join_shows_message_when_disconnected),