about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-02-17 22:57:36 +0000
committerJames Booth <boothj5@gmail.com>2014-02-17 22:57:36 +0000
commitb4b463998bec925c9f04def3ce48bbd475fd8aae (patch)
treece7759a29f44bc50dd2b84c7aff701a6c6c0c727
parenta25714b6dcab354e5802344755b57e893361e4d6 (diff)
downloadprofani-tty-b4b463998bec925c9f04def3ce48bbd475fd8aae.tar.gz
Test for /otr theirfp in non OTR window
-rw-r--r--tests/test_cmd_otr.c17
-rw-r--r--tests/test_cmd_otr.h1
-rw-r--r--tests/testsuite.c1
-rw-r--r--tests/ui/mock_ui.c13
-rw-r--r--tests/ui/mock_ui.h2
5 files changed, 34 insertions, 0 deletions
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