diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/command/commands.c | 5 | ||||
-rw-r--r-- | tests/unittests/test_cmd_account.c | 10 | ||||
-rw-r--r-- | tests/unittests/test_cmd_pgp.c | 43 | ||||
-rw-r--r-- | tests/unittests/test_cmd_pgp.h | 7 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 7 |
6 files changed, 69 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index e524a48f..0486982d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -74,6 +74,7 @@ unittest_sources = \ tests/unittests/test_cmd_connect.c tests/unittests/test_cmd_connect.h \ tests/unittests/test_cmd_join.c tests/unittests/test_cmd_join.h \ tests/unittests/test_cmd_otr.c tests/unittests/test_cmd_otr.h \ + tests/unittests/test_cmd_pgp.c tests/unittests/test_cmd_pgp.h \ tests/unittests/test_cmd_rooms.c tests/unittests/test_cmd_rooms.h \ tests/unittests/test_cmd_roster.c tests/unittests/test_cmd_roster.h \ tests/unittests/test_cmd_statuses.c tests/unittests/test_cmd_statuses.h \ diff --git a/src/command/commands.c b/src/command/commands.c index ba387028..85a85131 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4123,7 +4123,10 @@ gboolean cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) { #ifdef HAVE_LIBGPGME - if (g_strcmp0(args[0], "keys") == 0) { + if (args[0] == NULL) { + cons_show("Usage: %s", help.usage); + return TRUE; + } else if (g_strcmp0(args[0], "keys") == 0) { GSList *keys = p_gpg_list_keys(); if (keys) { cons_show("PGP keys:"); 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), |