diff options
author | James Booth <boothj5@gmail.com> | 2015-06-18 01:34:27 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-06-18 01:34:27 +0100 |
commit | ea99012d9bf1b8de356d3d9beb7cc45c3f456bad (patch) | |
tree | 78f31a66fcd330a30f5b262b38cb4621f509e52e | |
parent | 85cc5ab50deaec93f5520f3d587fba57040c2c88 (diff) | |
download | profani-tty-ea99012d9bf1b8de356d3d9beb7cc45c3f456bad.tar.gz |
Added initial /pgp start checks
-rw-r--r-- | src/command/commands.c | 7 | ||||
-rw-r--r-- | tests/unittests/test_cmd_pgp.c | 86 | ||||
-rw-r--r-- | tests/unittests/test_cmd_pgp.h | 10 | ||||
-rw-r--r-- | tests/unittests/unittests.c | 10 |
4 files changed, 113 insertions, 0 deletions
diff --git a/src/command/commands.c b/src/command/commands.c index 85a85131..f40723be 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4172,6 +4172,13 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) } else { cons_show("Could not get libgpgme version"); } + } else if (g_strcmp0(args[0], "start") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + if (conn_status != JABBER_CONNECTED) { + cons_show("You must be connected to start PGP encrpytion."); + } else if (window->type != WIN_CHAT && args[1] == NULL) { + cons_show("You must be in a regular chat window to start PGP encrpytion."); + } } return TRUE; diff --git a/tests/unittests/test_cmd_pgp.c b/tests/unittests/test_cmd_pgp.c index 7ee0e776..aef4baf7 100644 --- a/tests/unittests/test_cmd_pgp.c +++ b/tests/unittests/test_cmd_pgp.c @@ -27,6 +27,92 @@ void cmd_pgp_shows_usage_when_no_args(void **state) free(help); } +void cmd_pgp_start_shows_message_when_connection(jabber_conn_status_t conn_status) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "Some usage"; + gchar *args[] = { "start", NULL }; + ProfWin window; + window.type = WIN_CHAT; + + will_return(jabber_get_connection_status, conn_status); + + expect_cons_show("You must be connected to start PGP encrpytion."); + + gboolean result = cmd_pgp(&window, args, *help); + assert_true(result); + + free(help); +} + +void cmd_pgp_start_shows_message_when_disconnected(void **state) +{ + cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTED); +} + +void cmd_pgp_start_shows_message_when_disconnecting(void **state) +{ + cmd_pgp_start_shows_message_when_connection(JABBER_DISCONNECTING); +} + +void cmd_pgp_start_shows_message_when_connecting(void **state) +{ + cmd_pgp_start_shows_message_when_connection(JABBER_CONNECTING); +} + +void cmd_pgp_start_shows_message_when_undefined(void **state) +{ + cmd_pgp_start_shows_message_when_connection(JABBER_UNDEFINED); +} + +void cmd_pgp_start_shows_message_when_started(void **state) +{ + cmd_pgp_start_shows_message_when_connection(JABBER_STARTED); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_wintype(win_type_t wintype) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + help->usage = "Some usage"; + gchar *args[] = { "start", NULL }; + ProfWin window; + window.type = wintype; + + will_return(jabber_get_connection_status, JABBER_CONNECTED); + + expect_cons_show("You must be in a regular chat window to start PGP encrpytion."); + + gboolean result = cmd_pgp(&window, args, *help); + assert_true(result); + + free(help); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_console(void **state) +{ + cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_CONSOLE); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_muc(void **state) +{ + cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_MUC); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_mucconf(void **state) +{ + cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_MUC_CONFIG); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_private(void **state) +{ + cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_PRIVATE); +} + +void cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(void **state) +{ + cmd_pgp_start_shows_message_when_no_arg_in_wintype(WIN_XML); +} + #else void cmd_pgp_shows_message_when_pgp_unsupported(void **state) { diff --git a/tests/unittests/test_cmd_pgp.h b/tests/unittests/test_cmd_pgp.h index e7ed0b20..fcb24500 100644 --- a/tests/unittests/test_cmd_pgp.h +++ b/tests/unittests/test_cmd_pgp.h @@ -2,6 +2,16 @@ #ifdef HAVE_LIBGPGME void cmd_pgp_shows_usage_when_no_args(void **state); +void cmd_pgp_start_shows_message_when_disconnected(void **state); +void cmd_pgp_start_shows_message_when_disconnecting(void **state); +void cmd_pgp_start_shows_message_when_connecting(void **state); +void cmd_pgp_start_shows_message_when_undefined(void **state); +void cmd_pgp_start_shows_message_when_started(void **state); +void cmd_pgp_start_shows_message_when_no_arg_in_console(void **state); +void cmd_pgp_start_shows_message_when_no_arg_in_muc(void **state); +void cmd_pgp_start_shows_message_when_no_arg_in_mucconf(void **state); +void cmd_pgp_start_shows_message_when_no_arg_in_private(void **state); +void cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole(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 6e9c13bf..a0fb8886 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -542,6 +542,16 @@ int main(int argc, char* argv[]) { #ifdef HAVE_LIBGPGME unit_test(cmd_pgp_shows_usage_when_no_args), + unit_test(cmd_pgp_start_shows_message_when_disconnected), + unit_test(cmd_pgp_start_shows_message_when_disconnecting), + unit_test(cmd_pgp_start_shows_message_when_connecting), + unit_test(cmd_pgp_start_shows_message_when_undefined), + unit_test(cmd_pgp_start_shows_message_when_started), + unit_test(cmd_pgp_start_shows_message_when_no_arg_in_console), + unit_test(cmd_pgp_start_shows_message_when_no_arg_in_muc), + unit_test(cmd_pgp_start_shows_message_when_no_arg_in_mucconf), + unit_test(cmd_pgp_start_shows_message_when_no_arg_in_private), + unit_test(cmd_pgp_start_shows_message_when_no_arg_in_xmlconsole), #else unit_test(cmd_pgp_shows_message_when_pgp_unsupported), #endif |