diff options
author | James Booth <boothj5@gmail.com> | 2014-02-17 23:10:00 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-02-17 23:10:00 +0000 |
commit | 037ca818214dad46745576bf9af740f032ca0fc7 (patch) | |
tree | 58f0fd1dd3df417dd142680a03b97235b97d466a | |
parent | b4b463998bec925c9f04def3ce48bbd475fd8aae (diff) | |
download | profani-tty-037ca818214dad46745576bf9af740f032ca0fc7.tar.gz |
Test /otr theirfp
-rw-r--r-- | tests/otr/mock_otr.c | 15 | ||||
-rw-r--r-- | tests/otr/mock_otr.h | 1 | ||||
-rw-r--r-- | tests/test_cmd_otr.c | 27 | ||||
-rw-r--r-- | tests/test_cmd_otr.h | 1 | ||||
-rw-r--r-- | tests/testsuite.c | 1 |
5 files changed, 45 insertions, 0 deletions
diff --git a/tests/otr/mock_otr.c b/tests/otr/mock_otr.c index 2fb2eab0..a259c156 100644 --- a/tests/otr/mock_otr.c +++ b/tests/otr/mock_otr.c @@ -27,6 +27,13 @@ _mock_otr_get_my_fingerprint(void) return (char *)mock(); } +static char * +_mock_otr_get_their_fingerprint(const char * const recipient) +{ + check_expected(recipient); + return (char *)mock(); +} + void otr_keygen_expect(ProfAccount *account) { @@ -47,3 +54,11 @@ otr_get_my_fingerprint_returns(char *fingerprint) otr_get_my_fingerprint = _mock_otr_get_my_fingerprint; will_return(_mock_otr_get_my_fingerprint, fingerprint); } + +void +otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint) +{ + otr_get_their_fingerprint = _mock_otr_get_their_fingerprint; + expect_string(_mock_otr_get_their_fingerprint, recipient, recipient); + will_return(_mock_otr_get_their_fingerprint, fingerprint); +} diff --git a/tests/otr/mock_otr.h b/tests/otr/mock_otr.h index e3908a64..3296c145 100644 --- a/tests/otr/mock_otr.h +++ b/tests/otr/mock_otr.h @@ -8,5 +8,6 @@ void otr_keygen_expect(ProfAccount *account); void otr_libotr_version_returns(char *version); void otr_get_my_fingerprint_returns(char *fingerprint); +void otr_get_their_fingerprint_expect_and_return(char *recipient, char *fingerprint); #endif diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index f16eee19..57b26df3 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -441,6 +441,33 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state) free(help); } +void cmd_otr_theirfp_shows_fingerprint(void **state) +{ + char *recipient = "someone@chat.com"; + char *fingerprint = "AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD EEEEEEEE"; + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "theirfp", NULL }; + mock_connection_status(JABBER_CONNECTED); + mock_current_win_type(WIN_CHAT); + ui_current_win_is_otr_returns(TRUE); + mock_ui_current_recipient(); + ui_current_recipient_returns(recipient); + mock_ui_current_print_formatted_line(); + + GString *message = g_string_new(recipient); + g_string_append(message, "'s OTR fingerprint: "); + g_string_append(message, fingerprint); + + otr_get_their_fingerprint_expect_and_return(recipient, strdup(fingerprint)); + ui_current_print_formatted_line_expect('!', 0, message->str); + + gboolean result = cmd_otr(args, *help); + assert_true(result); + + g_string_free(message, TRUE); + 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 58089071..95c67a46 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -33,6 +33,7 @@ void cmd_otr_theirfp_shows_message_when_in_muc(void **state); void cmd_otr_theirfp_shows_message_when_in_private(void **state); void cmd_otr_theirfp_shows_message_when_in_duck(void **state); void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state); +void cmd_otr_theirfp_shows_fingerprint(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 c49d0de8..0e3911ad 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -474,6 +474,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_otr_theirfp_shows_message_when_in_private), unit_test(cmd_otr_theirfp_shows_message_when_in_duck), unit_test(cmd_otr_theirfp_shows_message_when_non_otr_chat_window), + unit_test(cmd_otr_theirfp_shows_fingerprint), #else unit_test(cmd_otr_shows_message_when_otr_unsupported), #endif |