diff options
author | James Booth <boothj5@gmail.com> | 2014-02-23 21:20:41 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-02-23 21:20:41 +0000 |
commit | c00376087f2ea0060b40d6adc1ef81ef17d8868a (patch) | |
tree | cc18959ae2b7fa40a4b778fd0132b94d83271a19 | |
parent | da058359ac552bc90e7b70749d5f96289434a9c8 (diff) | |
download | profani-tty-c00376087f2ea0060b40d6adc1ef81ef17d8868a.tar.gz |
Test /otr start sends OTR query message to current recipient
-rw-r--r-- | tests/otr/mock_otr.c | 13 | ||||
-rw-r--r-- | tests/otr/mock_otr.h | 2 | ||||
-rw-r--r-- | tests/test_cmd_otr.c | 22 | ||||
-rw-r--r-- | tests/test_cmd_otr.h | 1 | ||||
-rw-r--r-- | tests/testsuite.c | 1 | ||||
-rw-r--r-- | tests/xmpp/mock_xmpp.c | 15 | ||||
-rw-r--r-- | tests/xmpp/mock_xmpp.h | 2 |
7 files changed, 56 insertions, 0 deletions
diff --git a/tests/otr/mock_otr.c b/tests/otr/mock_otr.c index 64ec1166..0cda802e 100644 --- a/tests/otr/mock_otr.c +++ b/tests/otr/mock_otr.c @@ -40,6 +40,12 @@ _mock_otr_key_loaded(void) return (gboolean)mock(); } +static char * +_mock_otr_start_query(void) +{ + return (char *)mock(); +} + void otr_keygen_expect(ProfAccount *account) { @@ -75,3 +81,10 @@ otr_key_loaded_returns(gboolean loaded) otr_key_loaded = _mock_otr_key_loaded; will_return(_mock_otr_key_loaded, loaded); } + +void +otr_start_query_returns(char *query) +{ + otr_start_query = _mock_otr_start_query; + will_return(_mock_otr_start_query, query); +} diff --git a/tests/otr/mock_otr.h b/tests/otr/mock_otr.h index 742fb215..ab28ed6c 100644 --- a/tests/otr/mock_otr.h +++ b/tests/otr/mock_otr.h @@ -11,4 +11,6 @@ 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); +void otr_start_query_returns(char *query); + #endif diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 39241e7a..0d029d94 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -557,6 +557,28 @@ void cmd_otr_start_shows_message_when_no_key(void **state) free(help); } +void +cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state) +{ + char *recipient = "buddy@chat.com"; + char *query_message = "?OTR?"; + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "start", NULL }; + mock_connection_status(JABBER_CONNECTED); + mock_current_win_type(WIN_CHAT); + ui_current_win_is_otr_returns(FALSE); + otr_key_loaded_returns(TRUE); + ui_current_recipient_returns(recipient); + otr_start_query_returns(query_message); + + message_send_expect(query_message, recipient); + + 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 83b34fe1..fb45bcf7 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -41,6 +41,7 @@ void cmd_otr_start_shows_message_when_in_private(void **state); void cmd_otr_start_shows_message_when_in_duck(void **state); void cmd_otr_start_shows_message_when_already_started(void **state); void cmd_otr_start_shows_message_when_no_key(void **state); +void cmd_otr_start_sends_otr_query_message_to_current_recipeint(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 36fa1a1d..5a09b599 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -482,6 +482,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_otr_start_shows_message_when_in_duck), unit_test(cmd_otr_start_shows_message_when_already_started), unit_test(cmd_otr_start_shows_message_when_no_key), + unit_test(cmd_otr_start_sends_otr_query_message_to_current_recipeint), #else unit_test(cmd_otr_shows_message_when_otr_unsupported), #endif diff --git a/tests/xmpp/mock_xmpp.c b/tests/xmpp/mock_xmpp.c index 054e3fdd..c9843ed5 100644 --- a/tests/xmpp/mock_xmpp.c +++ b/tests/xmpp/mock_xmpp.c @@ -81,6 +81,13 @@ _mock_bookmark_remove(const char *jid, gboolean autojoin) return (gboolean)mock(); } +static void +_mock_message_send(const char * const msg, const char * const recipient) +{ + check_expected(msg); + check_expected(recipient); +} + void mock_jabber_connect_with_details(void) { @@ -219,3 +226,11 @@ expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin will_return(_mock_bookmark_remove, removed); } + +void +message_send_expect(char *message, char *recipient) +{ + message_send = _mock_message_send; + expect_string(_mock_message_send, msg, message); + expect_string(_mock_message_send, recipient, recipient); +} diff --git a/tests/xmpp/mock_xmpp.h b/tests/xmpp/mock_xmpp.h index 5c4c19d0..7400fe92 100644 --- a/tests/xmpp/mock_xmpp.h +++ b/tests/xmpp/mock_xmpp.h @@ -31,4 +31,6 @@ void mock_bookmark_remove(void); void expect_and_return_bookmark_remove(char *expected_jid, gboolean expected_autojoin, gboolean removed); +void message_send_expect(char *message, char *recipient); + #endif |