about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-10 00:25:27 +0000
committerJames Booth <boothj5@gmail.com>2015-01-10 00:25:27 +0000
commit9bd2315d83d042156a5aa28227071756c46291b9 (patch)
tree45d1254582a4a5e4f80d900c1d6d928d4365a306 /tests
parent5e7d2f5f91d47af330742a3b554e6f03450d6623 (diff)
downloadprofani-tty-9bd2315d83d042156a5aa28227071756c46291b9.tar.gz
Fixed chat session tests
Diffstat (limited to 'tests')
-rw-r--r--tests/test_chat_session.c154
-rw-r--r--tests/test_chat_session.h16
-rw-r--r--tests/test_server_events.c16
-rw-r--r--tests/testsuite.c37
4 files changed, 35 insertions, 188 deletions
diff --git a/tests/test_chat_session.c b/tests/test_chat_session.c
index bcb8dcce..6b40f7e3 100644
--- a/tests/test_chat_session.c
+++ b/tests/test_chat_session.c
@@ -9,155 +9,43 @@
 
 void returns_false_when_chat_session_does_not_exist(void **state)
 {
-    gboolean result = chat_session_exists("somejid@server.org");
-    assert_false(result);
+    ChatSession *session = chat_session_get("somejid@server.org");
+    assert_null(session);
 }
 
-void creates_chat_session_on_message_send(void **state)
+void creates_chat_session_on_recipient_activity(void **state)
 {
     char *barejid = "myjid@server.org";
+    char *resource = "tablet";
 
-    chat_session_on_message_send(barejid);
-    gboolean exists = chat_session_exists(barejid);
+    chat_session_on_recipient_activity(barejid, resource);
+    ChatSession *session = chat_session_get(barejid);
 
-    assert_true(exists);
+    assert_non_null(session);
+    assert_string_equal(session->resource, resource);
 }
 
-void creates_chat_session_on_activity(void **state)
+void replaces_chat_session_on_recipient_activity_with_different_resource(void **state)
 {
     char *barejid = "myjid@server.org";
+    char *resource1 = "tablet";
+    char *resource2 = "mobile";
 
-    chat_session_on_activity(barejid);
-    gboolean exists = chat_session_exists(barejid);
+    chat_session_on_recipient_activity(barejid, resource1);
+    chat_session_on_recipient_activity(barejid, resource2);
+    ChatSession *session = chat_session_get(barejid);
 
-    assert_true(exists);
+    assert_string_equal(session->resource, resource2);
 }
 
-void returns_null_resource_for_new_session(void **state)
+void removes_chat_session(void **state)
 {
     char *barejid = "myjid@server.org";
+    char *resource1 = "laptop";
 
-    chat_session_on_message_send(barejid);
-    char *resource = chat_session_get_resource(barejid);
+    chat_session_on_recipient_activity(barejid, resource1);
+    chat_session_remove(barejid);
+    ChatSession *session = chat_session_get(barejid);
 
-    assert_null(resource);
-}
-
-void returns_true_send_states_for_new_session(void **state)
-{
-    char *barejid = "myjid@server.org";
-
-    chat_session_on_message_send(barejid);
-    gboolean send_states = chat_session_send_states(barejid);
-
-    assert_true(send_states);
-}
-
-void sets_resource_on_incoming_message(void **state)
-{
-    char *barejid = "myjid@server.org";
-    char *expected_resource = "laptop";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_incoming_message(barejid, expected_resource, FALSE);
-    char *actual_resource = chat_session_get_resource(barejid);
-
-    assert_string_equal(expected_resource, actual_resource);
-}
-
-void sets_send_states_on_incoming_message(void **state)
-{
-    char *barejid = "myjid@server.org";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_incoming_message(barejid, "resource", TRUE);
-    gboolean send_states = chat_session_send_states(barejid);
-
-    assert_true(send_states);
-}
-
-void replaces_chat_session_when_new_resource(void **state)
-{
-    char *barejid = "myjid@server.org";
-    char *first_resource = "laptop";
-    char *second_resource = "mobile";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_incoming_message(barejid, first_resource, TRUE);
-    chat_session_on_incoming_message(barejid, second_resource, TRUE);
-    char *actual_resource = chat_session_get_resource(barejid);
-
-    assert_string_equal(second_resource, actual_resource);
-}
-
-void removes_chat_session_on_window_close(void **state)
-{
-    char *barejid = "myjid@server.org";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_window_close(barejid);
-    gboolean exists = chat_session_exists(barejid);
-
-    assert_false(exists);
-}
-
-void removes_chat_session_on_cancel_for_barejid(void **state)
-{
-    char *barejid = "myjid@server.org";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_cancel(barejid);
-    gboolean exists = chat_session_exists(barejid);
-
-    assert_false(exists);
-}
-
-void removes_chat_session_on_cancel_for_fulljid(void **state)
-{
-    char *barejid = "myjid@server.org";
-    char *fulljid = "myjid@server.org/desktop";
-
-    chat_session_on_message_send(barejid);
-    chat_session_on_cancel(fulljid);
-    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);
+    assert_null(session);
 }
\ No newline at end of file
diff --git a/tests/test_chat_session.h b/tests/test_chat_session.h
index 068f4d5f..4ce03fd5 100644
--- a/tests/test_chat_session.h
+++ b/tests/test_chat_session.h
@@ -1,14 +1,4 @@
 void returns_false_when_chat_session_does_not_exist(void **state);
-void creates_chat_session_on_message_send(void **state);
-void creates_chat_session_on_activity(void **state);
-void returns_null_resource_for_new_session(void **state);
-void returns_true_send_states_for_new_session(void **state);
-void sets_resource_on_incoming_message(void **state);
-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);
-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
+void creates_chat_session_on_recipient_activity(void **state);
+void replaces_chat_session_on_recipient_activity_with_different_resource(void **state);
+void removes_chat_session(void **state);
\ No newline at end of file
diff --git a/tests/test_server_events.c b/tests/test_server_events.c
index 20ad246c..78eee8b9 100644
--- a/tests/test_server_events.c
+++ b/tests/test_server_events.c
@@ -126,18 +126,18 @@ void handle_message_error_when_recipient_cancel(void **state)
 void handle_message_error_when_recipient_cancel_disables_chat_session(void **state)
 {
     char *err_msg = "Some error.";
-    char *from = "bob@server.com";
+    char *barejid = "bob@server.com";
     char *resource = "resource";
     char *type = "cancel";
 
     prefs_set_boolean(PREF_STATES, TRUE);
     chat_sessions_init();
-    chat_session_on_incoming_message(from, resource, TRUE);
+    chat_session_on_recipient_activity(barejid, resource);
 
-    handle_message_error(from, type, err_msg);
-    gboolean session_exists = chat_session_exists(from);
+    handle_message_error(barejid, type, err_msg);
+    ChatSession *session = chat_session_get(barejid);
 
-    assert_false(session_exists);
+    assert_null(session);
     chat_sessions_clear();
 }
 
@@ -185,11 +185,11 @@ void handle_offline_removes_chat_session(void **state)
     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);
+    chat_session_on_recipient_activity(barejid, resource);
     handle_contact_offline(barejid, resource, NULL);
-    gboolean exists = chat_session_exists(barejid);
+    ChatSession *session = chat_session_get(barejid);
 
-    assert_false(exists);
+    assert_null(session);
 
     roster_clear();
     chat_sessions_clear();
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 3b86d5ed..e333c93f 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -209,46 +209,15 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(returns_false_when_chat_session_does_not_exist,
             init_chat_sessions,
             close_chat_sessions),
-        unit_test_setup_teardown(creates_chat_session_on_message_send,
+        unit_test_setup_teardown(creates_chat_session_on_recipient_activity,
             init_chat_sessions,
             close_chat_sessions),
-        unit_test_setup_teardown(creates_chat_session_on_activity,
+        unit_test_setup_teardown(replaces_chat_session_on_recipient_activity_with_different_resource,
             init_chat_sessions,
             close_chat_sessions),
-        unit_test_setup_teardown(returns_null_resource_for_new_session,
+        unit_test_setup_teardown(removes_chat_session,
             init_chat_sessions,
             close_chat_sessions),
-        unit_test_setup_teardown(returns_true_send_states_for_new_session,
-            init_chat_sessions,
-            close_chat_sessions),
-        unit_test_setup_teardown(sets_resource_on_incoming_message,
-            init_chat_sessions,
-            close_chat_sessions),
-        unit_test_setup_teardown(sets_send_states_on_incoming_message,
-            init_chat_sessions,
-            close_chat_sessions),
-        unit_test_setup_teardown(replaces_chat_session_when_new_resource,
-            init_chat_sessions,
-            close_chat_sessions),
-        unit_test_setup_teardown(removes_chat_session_on_window_close,
-            init_chat_sessions,
-            close_chat_sessions),
-        unit_test_setup_teardown(removes_chat_session_on_cancel_for_barejid,
-            init_chat_sessions,
-            close_chat_sessions),
-        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,
             close_preferences),