1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Fixed chat session tests

This commit is contained in:
James Booth 2015-01-10 00:25:27 +00:00
parent 5e7d2f5f91
commit 9bd2315d83
5 changed files with 38 additions and 188 deletions

View File

@ -92,6 +92,9 @@ chat_session_get(const char * const barejid)
void
chat_session_on_recipient_activity(const char * const barejid, const char * const resource)
{
assert(barejid != NULL);
assert(resource != NULL);
ChatSession *session = g_hash_table_lookup(sessions, barejid);
if (session) {
// session exists with resource, do nothing

View File

@ -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);
}

View File

@ -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);
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);

View File

@ -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();

View File

@ -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),