From b4b463998bec925c9f04def3ce48bbd475fd8aae Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 17 Feb 2014 22:57:36 +0000 Subject: Test for /otr theirfp in non OTR window --- tests/test_cmd_otr.c | 17 +++++++++++++++++ tests/test_cmd_otr.h | 1 + tests/testsuite.c | 1 + tests/ui/mock_ui.c | 13 +++++++++++++ tests/ui/mock_ui.h | 2 ++ 5 files changed, 34 insertions(+) diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 34496ea1..f16eee19 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -424,6 +424,23 @@ void cmd_otr_theirfp_shows_message_when_in_duck(void **state) test_cmd_otr_theirfp_from_wintype(WIN_DUCK); } +void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state) +{ + 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(FALSE); + mock_ui_current_print_formatted_line(); + + ui_current_print_formatted_line_expect('!', 0, "You are not currently in an OTR session."); + + 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 c741c0d8..58089071 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -32,6 +32,7 @@ void cmd_otr_theirfp_shows_message_when_in_console(void **state); 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); #else void cmd_otr_shows_message_when_otr_unsupported(void **state); #endif diff --git a/tests/testsuite.c b/tests/testsuite.c index fd73f147..c49d0de8 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -473,6 +473,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_otr_theirfp_shows_message_when_in_muc), 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), #else unit_test(cmd_otr_shows_message_when_otr_unsupported), #endif diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c index d2f6944e..a79f0521 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -181,6 +181,12 @@ void _mock_ui_current_print_line(const char * const msg, ...) va_end(args); } +static +gboolean _mock_ui_current_win_is_otr(void) +{ + return (gboolean)mock(); +} + // bind mocks and stubs void @@ -416,3 +422,10 @@ ui_current_print_line_expect(char *message) { expect_string(_mock_ui_current_print_line, output, message); } + +void +ui_current_win_is_otr_returns(gboolean result) +{ + ui_current_win_is_otr = _mock_ui_current_win_is_otr; + will_return(_mock_ui_current_win_is_otr, result); +} diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h index e7db7247..a814f06e 100644 --- a/tests/ui/mock_ui.h +++ b/tests/ui/mock_ui.h @@ -57,4 +57,6 @@ void ui_current_print_formatted_line_expect(char show_char, int attrs, char *mes void mock_ui_current_print_line(void); void ui_current_print_line_expect(char *message); +void ui_current_win_is_otr_returns(gboolean result); + #endif -- cgit 1.4.1-2-gfad0