1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added cmd_pgp tests

This commit is contained in:
James Booth 2015-06-18 00:12:01 +01:00
parent 97ba9d2692
commit 85cc5ab50d
6 changed files with 69 additions and 4 deletions

View File

@ -74,6 +74,7 @@ unittest_sources = \
tests/unittests/test_cmd_connect.c tests/unittests/test_cmd_connect.h \ 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_join.c tests/unittests/test_cmd_join.h \
tests/unittests/test_cmd_otr.c tests/unittests/test_cmd_otr.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_rooms.c tests/unittests/test_cmd_rooms.h \
tests/unittests/test_cmd_roster.c tests/unittests/test_cmd_roster.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 \ tests/unittests/test_cmd_statuses.c tests/unittests/test_cmd_statuses.h \

View File

@ -4123,7 +4123,10 @@ gboolean
cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help)
{ {
#ifdef HAVE_LIBGPGME #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(); GSList *keys = p_gpg_list_keys();
if (keys) { if (keys) {
cons_show("PGP keys:"); cons_show("PGP keys:");

View File

@ -926,8 +926,7 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
{ {
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "set", "a_account", "online", "10", NULL }; 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); expect_any(accounts_account_exists, account_name);
will_return(accounts_account_exists, TRUE); will_return(accounts_account_exists, TRUE);
@ -940,11 +939,16 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese
expect_any(accounts_get_last_presence, account_name); expect_any(accounts_get_last_presence, account_name);
will_return(accounts_get_last_presence, RESOURCE_ONLINE); will_return(accounts_get_last_presence, RESOURCE_ONLINE);
will_return(jabber_get_account_name, "a_account");
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); expect_any(accounts_get_account, name);
will_return(accounts_get_account, account); will_return(accounts_get_account, account);
#endif
will_return(jabber_get_presence_message, "Free to chat"); will_return(jabber_get_presence_message, "Free to chat");

View File

@ -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

View File

@ -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

View File

@ -21,6 +21,7 @@
#include "test_cmd_sub.h" #include "test_cmd_sub.h"
#include "test_cmd_statuses.h" #include "test_cmd_statuses.h"
#include "test_cmd_otr.h" #include "test_cmd_otr.h"
#include "test_cmd_pgp.h"
#include "test_jid.h" #include "test_jid.h"
#include "test_parser.h" #include "test_parser.h"
#include "test_roster_list.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), unit_test(cmd_otr_shows_message_when_otr_unsupported),
#endif #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_disconnecting),
unit_test(cmd_join_shows_message_when_connecting), unit_test(cmd_join_shows_message_when_connecting),
unit_test(cmd_join_shows_message_when_disconnected), unit_test(cmd_join_shows_message_when_disconnected),