about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-10 01:17:38 +0000
committerJames Booth <boothj5@gmail.com>2015-01-10 01:17:38 +0000
commitf180925c3b4c28d3839efe5526596506c781a9ec (patch)
tree4b8b56ffd778527c8f83a6430f587fe95b5a072a /tests
parentab7bd6fe5f9c0a0abdc82426ab2eaaeb9416da28 (diff)
downloadprofani-tty-f180925c3b4c28d3839efe5526596506c781a9ec.tar.gz
Added tests for clearing chat sessions on lost connection
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd_disconnect.c9
-rw-r--r--tests/test_server_events.c16
-rw-r--r--tests/test_server_events.h3
-rw-r--r--tests/testsuite.c1
-rw-r--r--tests/ui/stub_ui.c6
-rw-r--r--tests/ui/stub_ui.h1
6 files changed, 32 insertions, 4 deletions
diff --git a/tests/test_cmd_disconnect.c b/tests/test_cmd_disconnect.c
index 43152872..c0310cbf 100644
--- a/tests/test_cmd_disconnect.c
+++ b/tests/test_cmd_disconnect.c
@@ -17,8 +17,9 @@ void clears_chat_sessions(void **state)
     CommandHelp *help = malloc(sizeof(CommandHelp));
 
     chat_sessions_init();
-    chat_session_on_recipient_activity("bob@server.org", "laptop");
     roster_init();
+    chat_session_on_recipient_activity("bob@server.org", "laptop");
+    chat_session_on_recipient_activity("mike@server.org", "work");
 
     will_return(jabber_get_connection_status, JABBER_CONNECTED);
     will_return(jabber_get_fulljid, "myjid@myserver.com");
@@ -28,7 +29,9 @@ void clears_chat_sessions(void **state)
 
     assert_true(result);
 
-    ChatSession *session = chat_session_get("bob@server.org");
-    assert_null(session);
+    ChatSession *session1 = chat_session_get("bob@server.org");
+    ChatSession *session2 = chat_session_get("mike@server.org");
+    assert_null(session1);
+    assert_null(session2);
     free(help);
 }
\ No newline at end of file
diff --git a/tests/test_server_events.c b/tests/test_server_events.c
index 78eee8b9..03119db0 100644
--- a/tests/test_server_events.c
+++ b/tests/test_server_events.c
@@ -11,6 +11,7 @@
 #include "chat_session.h"
 #include "config/preferences.h"
 #include "ui/ui.h"
+#include "ui/stub_ui.h"
 #include "muc.h"
 
 void console_doesnt_show_online_presence_when_set_none(void **state)
@@ -194,3 +195,18 @@ void handle_offline_removes_chat_session(void **state)
     roster_clear();
     chat_sessions_clear();
 }
+
+void lost_connection_clears_chat_sessions(void **state)
+{
+    chat_sessions_init();
+    chat_session_on_recipient_activity("bob@server.org", "laptop");
+    chat_session_on_recipient_activity("steve@server.org", "mobile");
+    expect_any_cons_show_error();
+
+    handle_lost_connection();
+
+    ChatSession *session1 = chat_session_get("bob@server.org");
+    ChatSession *session2 = chat_session_get("steve@server.org");
+    assert_null(session1);
+    assert_null(session2);
+}
diff --git a/tests/test_server_events.h b/tests/test_server_events.h
index 15a8f597..81a436f4 100644
--- a/tests/test_server_events.h
+++ b/tests/test_server_events.h
@@ -10,4 +10,5 @@ void handle_message_error_when_recipient_cancel_disables_chat_session(void **sta
 void handle_message_error_when_recipient_and_no_type(void **state);
 void handle_presence_error_when_no_recipient(void **state);
 void handle_presence_error_when_from_recipient(void **state);
-void handle_offline_removes_chat_session(void **state);
\ No newline at end of file
+void handle_offline_removes_chat_session(void **state);
+void lost_connection_clears_chat_sessions(void **state);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index ebc4c7ac..eb039cbe 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -455,6 +455,7 @@ int main(int argc, char* argv[]) {
         unit_test(handle_presence_error_when_no_recipient),
         unit_test(handle_presence_error_when_from_recipient),
         unit_test(handle_offline_removes_chat_session),
+        unit_test(lost_connection_clears_chat_sessions),
 
         unit_test(cmd_alias_add_shows_usage_when_no_args),
         unit_test(cmd_alias_add_shows_usage_when_no_value),
diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c
index f0dd1195..f7d34eab 100644
--- a/tests/ui/stub_ui.c
+++ b/tests/ui/stub_ui.c
@@ -32,6 +32,12 @@ expect_cons_show_error(char *expected)
 }
 
 void
+expect_any_cons_show_error(void)
+{
+    expect_any(cons_show_error, output);
+}
+
+void
 expect_ui_current_print_line(char *message)
 {
     expect_string(ui_current_print_line, output, message);
diff --git a/tests/ui/stub_ui.h b/tests/ui/stub_ui.h
index 3e6e435f..81357a86 100644
--- a/tests/ui/stub_ui.h
+++ b/tests/ui/stub_ui.h
@@ -1,5 +1,6 @@
 void expect_cons_show(char *expected);
 void expect_any_cons_show(void);
 void expect_cons_show_error(char *expected);
+void expect_any_cons_show_error(void);
 void expect_ui_current_print_line(char *message);
 void expect_ui_current_print_formatted_line(char show_char, int attrs, char *message);
\ No newline at end of file