about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-06 23:19:56 +0000
committerJames Booth <boothj5@gmail.com>2015-01-06 23:19:56 +0000
commit95ad5643725d1cc857454d47460091ca18cbb807 (patch)
tree424b86f34e596324feaeef3248fd873ae26ac8a8 /tests
parent36790dc26bbd4d00702a75469980e7c9fbf1282d (diff)
downloadprofani-tty-95ad5643725d1cc857454d47460091ca18cbb807.tar.gz
Added offline handler for chat sessions
Diffstat (limited to 'tests')
-rw-r--r--tests/test_chat_session.c38
-rw-r--r--tests/test_chat_session.h5
-rw-r--r--tests/test_server_events.c19
-rw-r--r--tests/test_server_events.h3
-rw-r--r--tests/testsuite.c10
5 files changed, 73 insertions, 2 deletions
diff --git a/tests/test_chat_session.c b/tests/test_chat_session.c
index a93c64b6..bcb8dcce 100644
--- a/tests/test_chat_session.c
+++ b/tests/test_chat_session.c
@@ -122,4 +122,42 @@ void removes_chat_session_on_cancel_for_fulljid(void **state)
     gboolean exists = chat_session_exists(barejid);
 
     assert_false(exists);
+}
+
+void removes_chat_session_on_offline_matching_resource(void **state)
+{
+    char *barejid = "myjid@server.org";
+    char *resource = "work";
+
+    chat_session_on_message_send(barejid);
+    chat_session_on_incoming_message(barejid, resource, TRUE);
+    chat_session_on_offline(barejid, resource);
+    gboolean exists = chat_session_exists(barejid);
+
+    assert_false(exists);
+}
+
+void does_not_remove_chat_session_on_offline_different_resource(void **state)
+{
+    char *barejid = "myjid@server.org";
+    char *resource = "work";
+    char *offline_resource = "home";
+
+    chat_session_on_message_send(barejid);
+    chat_session_on_incoming_message(barejid, resource, TRUE);
+    chat_session_on_offline(barejid, offline_resource);
+    gboolean exists = chat_session_exists(barejid);
+
+    assert_true(exists);
+}
+
+void does_not_remove_chat_session_on_offline_null_resource(void **state)
+{
+    char *barejid = "myjid@server.org";
+
+    chat_session_on_message_send(barejid);
+    chat_session_on_offline(barejid, NULL);
+    gboolean exists = chat_session_exists(barejid);
+
+    assert_true(exists);
 }
\ No newline at end of file
diff --git a/tests/test_chat_session.h b/tests/test_chat_session.h
index 8916f6b4..068f4d5f 100644
--- a/tests/test_chat_session.h
+++ b/tests/test_chat_session.h
@@ -8,4 +8,7 @@ void sets_send_states_on_incoming_message(void **state);
 void replaces_chat_session_when_new_resource(void **state);
 void removes_chat_session_on_window_close(void **state);
 void removes_chat_session_on_cancel_for_barejid(void **state);
-void removes_chat_session_on_cancel_for_fulljid(void **state);
\ No newline at end of file
+void removes_chat_session_on_cancel_for_fulljid(void **state);
+void removes_chat_session_on_offline_matching_resource(void **state);
+void does_not_remove_chat_session_on_offline_different_resource(void **state);
+void does_not_remove_chat_session_on_offline_null_resource(void **state);
\ No newline at end of file
diff --git a/tests/test_server_events.c b/tests/test_server_events.c
index fcf6fb1c..20ad246c 100644
--- a/tests/test_server_events.c
+++ b/tests/test_server_events.c
@@ -175,3 +175,22 @@ void handle_presence_error_when_from_recipient(void **state)
 
     handle_presence_error(from, type, err_msg);
 }
+
+void handle_offline_removes_chat_session(void **state)
+{
+    chat_sessions_init();
+    char *barejid = "friend@server.chat.com";
+    char *resource = "home";
+    roster_init();
+    roster_add(barejid, "bob", NULL, "both", FALSE);
+    Resource *resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
+    roster_update_presence(barejid, resourcep, NULL);
+    chat_session_on_incoming_message(barejid, resource, TRUE);
+    handle_contact_offline(barejid, resource, NULL);
+    gboolean exists = chat_session_exists(barejid);
+
+    assert_false(exists);
+
+    roster_clear();
+    chat_sessions_clear();
+}
diff --git a/tests/test_server_events.h b/tests/test_server_events.h
index 68e78557..15a8f597 100644
--- a/tests/test_server_events.h
+++ b/tests/test_server_events.h
@@ -9,4 +9,5 @@ void handle_message_error_when_recipient_cancel(void **state);
 void handle_message_error_when_recipient_cancel_disables_chat_session(void **state);
 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);
\ No newline at end of file
+void handle_presence_error_when_from_recipient(void **state);
+void handle_offline_removes_chat_session(void **state);
\ No newline at end of file
diff --git a/tests/testsuite.c b/tests/testsuite.c
index db05639d..3b86d5ed 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -239,6 +239,15 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(removes_chat_session_on_cancel_for_fulljid,
             init_chat_sessions,
             close_chat_sessions),
+        unit_test_setup_teardown(removes_chat_session_on_offline_matching_resource,
+            init_chat_sessions,
+            close_chat_sessions),
+        unit_test_setup_teardown(does_not_remove_chat_session_on_offline_different_resource,
+            init_chat_sessions,
+            close_chat_sessions),
+        unit_test_setup_teardown(does_not_remove_chat_session_on_offline_null_resource,
+            init_chat_sessions,
+            close_chat_sessions),
 
         unit_test_setup_teardown(cmd_connect_shows_message_when_disconnecting,
             load_preferences,
@@ -475,6 +484,7 @@ int main(int argc, char* argv[]) {
         unit_test(handle_message_error_when_recipient_and_no_type),
         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(cmd_alias_add_shows_usage_when_no_args),
         unit_test(cmd_alias_add_shows_usage_when_no_value),