From 4afec6ab5e6385e15e605130e5f275aa759fab9a Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 17 Feb 2014 22:14:33 +0000 Subject: [PATCH] Added test for /otr theirfp when in console --- tests/test_cmd_otr.c | 16 ++++++++++++++++ tests/test_cmd_otr.h | 1 + tests/testsuite.c | 1 + tests/ui/mock_ui.c | 22 ++++++++++++++++++++++ tests/ui/mock_ui.h | 3 +++ 5 files changed, 43 insertions(+) diff --git a/tests/test_cmd_otr.c b/tests/test_cmd_otr.c index 9a731d12..707bb3d2 100644 --- a/tests/test_cmd_otr.c +++ b/tests/test_cmd_otr.c @@ -387,6 +387,22 @@ void cmd_otr_myfp_shows_my_fingerprint(void **state) free(help); } +void cmd_otr_theirfp_shows_message_when_in_console(void **state) +{ + CommandHelp *help = malloc(sizeof(CommandHelp)); + gchar *args[] = { "theirfp", NULL }; + mock_connection_status(JABBER_CONNECTED); + mock_current_win_type(WIN_CONSOLE); + mock_ui_current_print_line(); + + ui_current_print_line_expect("You must be in a regular chat window to view a recipient's fingerprint."); + + 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 4fda3559..8d2b7040 100644 --- a/tests/test_cmd_otr.h +++ b/tests/test_cmd_otr.h @@ -28,6 +28,7 @@ void cmd_otr_myfp_shows_message_when_started(void **state); void cmd_otr_myfp_shows_message_when_connecting(void **state); void cmd_otr_myfp_shows_message_when_disconnecting(void **state); void cmd_otr_myfp_shows_my_fingerprint(void **state); +void cmd_otr_theirfp_shows_message_when_in_console(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 b49ff7b2..9396a06b 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -469,6 +469,7 @@ int main(int argc, char* argv[]) { unit_test(cmd_otr_myfp_shows_message_when_connecting), unit_test(cmd_otr_myfp_shows_message_when_disconnecting), unit_test(cmd_otr_myfp_shows_my_fingerprint), + unit_test(cmd_otr_theirfp_shows_message_when_in_console), #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 af9d1a6b..d2f6944e 100644 --- a/tests/ui/mock_ui.c +++ b/tests/ui/mock_ui.c @@ -171,6 +171,16 @@ void _mock_ui_current_print_formatted_line(const char show_char, int attrs, cons va_end(args); } +static +void _mock_ui_current_print_line(const char * const msg, ...) +{ + va_list args; + va_start(args, msg); + vsnprintf(output, sizeof(output), msg, args); + check_expected(output); + va_end(args); +} + // bind mocks and stubs void @@ -270,6 +280,12 @@ mock_ui_current_print_formatted_line(void) ui_current_print_formatted_line = _mock_ui_current_print_formatted_line; } +void +mock_ui_current_print_line(void) +{ + ui_current_print_line = _mock_ui_current_print_line; +} + // expectations void @@ -394,3 +410,9 @@ ui_current_print_formatted_line_expect(char show_char, int attrs, char *message) expect_value(_mock_ui_current_print_formatted_line, attrs, attrs); expect_string(_mock_ui_current_print_formatted_line, output, message); } + +void +ui_current_print_line_expect(char *message) +{ + expect_string(_mock_ui_current_print_line, output, message); +} diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h index 9cdd6b34..e7db7247 100644 --- a/tests/ui/mock_ui.h +++ b/tests/ui/mock_ui.h @@ -54,4 +54,7 @@ void stub_ui_current_refresh(void); void mock_ui_current_print_formatted_line(void); void ui_current_print_formatted_line_expect(char show_char, int attrs, char *message); +void mock_ui_current_print_line(void); +void ui_current_print_line_expect(char *message); + #endif