From 4eac5c0d4324d7d651b539c837b1e3c51300a982 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Feb 2014 19:35:40 +0000 Subject: [PATCH] Test /otr gen --- tests/otr/mock_otr.c | 7 +------ tests/otr/mock_otr.h | 1 - tests/test_cmd_otr.c | 23 +++++++++++++++++++++++ tests/test_cmd_otr.h | 1 + tests/testsuite.c | 1 + 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/otr/mock_otr.c b/tests/otr/mock_otr.c index 8750feb7..b8b43d9b 100644 --- a/tests/otr/mock_otr.c +++ b/tests/otr/mock_otr.c @@ -21,12 +21,6 @@ _mock_otr_libotr_version(void) return (char *)mock(); } -void -mock_otr_keygen(void) -{ - otr_keygen = _mock_otr_keygen; -} - void mock_otr_libotr_version(void) { @@ -36,6 +30,7 @@ mock_otr_libotr_version(void) void otr_keygen_expect(ProfAccount *account) { + otr_keygen = _mock_otr_keygen; expect_memory(_mock_otr_keygen, account, account, sizeof(ProfAccount)); } diff --git a/tests/otr/mock_otr.h b/tests/otr/mock_otr.h index fd71e3da..d9a6c492 100644 --- a/tests/otr/mock_otr.h +++ b/tests/otr/mock_otr.h @@ -3,7 +3,6 @@ #include "config/account.h" -void mock_otr_keygen(void); void otr_keygen_expect(ProfAccount *account); void mock_otr_libotr_version(void); diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 8f58590d..2d82163f 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -18,6 +18,7 @@ #include "ui/mock_ui.h" #include "xmpp/mock_xmpp.h" +#include "config/mock_accounts.h" #include "command/command.h" #include "command/commands.h" @@ -278,6 +279,28 @@ void cmd_otr_gen_shows_message_when_not_connected(void **state) free(help); } + +void cmd_otr_gen_generates_key_for_connected_account(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "gen", NULL }; + char *account_name = "myaccount"; + ProfAccount *account = account_new(account_name, "me@jabber.org", NULL, + TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL); + + stub_cons_show(); + mock_connection_status(JABBER_CONNECTED); + mock_accounts_get_account(); + mock_connection_account_name(account_name); + accounts_get_account_expect_and_return(account_name, account); + + otr_keygen_expect(account); + + gboolean result = cmd_otr(args, *help); + assert_true(result); + + free(help); +} #else void cmd_otr_shows_message_when_otr_unsupported(void **state) { diff --git a/tests/test_cmd_otr.h b/tests/test_cmd_otr.h index 1f8584d8..c198a4f6 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -16,6 +16,7 @@ void cmd_otr_warn_on_enables_unencrypted_warning(void **state); void cmd_otr_warn_off_disables_unencrypted_warning(void **state); void cmd_otr_libver_shows_libotr_version(void **state); void cmd_otr_gen_shows_message_when_not_connected(void **state); +void cmd_otr_gen_generates_key_for_connected_account(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 f8315832..17ae3172 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -457,6 +457,7 @@ int main(int argc, char* argv[]) { close_preferences), unit_test(cmd_otr_libver_shows_libotr_version), unit_test(cmd_otr_gen_shows_message_when_not_connected), + unit_test(cmd_otr_gen_generates_key_for_connected_account), #else unit_test(cmd_otr_shows_message_when_otr_unsupported), #endif