#include #include #include #include #include #include #include #include "xmpp/contact.h" #include "xmpp/roster_list.h" void empty_list_when_none_added(void **state) { roster_create(); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_null(list); roster_destroy(); } void contains_one_element(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(1, g_slist_length(list)); roster_destroy(); } void first_element_correct(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact james = list->data; assert_string_equal("James", p_contact_barejid(james)); roster_destroy(); } void contains_two_elements(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(2, g_slist_length(list)); roster_destroy(); } void first_and_second_elements_correct(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; assert_string_equal("Dave", p_contact_barejid(first)); assert_string_equal("James", p_contact_barejid(second)); roster_destroy(); } void contains_three_elements(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); assert_int_equal(3, g_slist_length(list)); roster_destroy(); } void first_three_elements_correct(void **state) { roster_create(); roster_add("Bob", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact bob = list->data; PContact dave = (g_slist_next(list))->data; PContact james = (g_slist_next(g_slist_next(list)))->data; assert_string_equal("James", p_contact_barejid(james)); assert_string_equal("Dave", p_contact_barejid(dave)); assert_string_equal("Bob", p_contact_barejid(bob)); roster_destroy(); } void add_twice_at_beginning_adds_once(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; PContact third = (g_slist_next(g_slist_next(list)))->data; assert_int_equal(3, g_slist_length(list)); assert_string_equal("Bob", p_contact_barejid(first)); assert_string_equal("Dave", p_contact_barejid(second)); assert_string_equal("James", p_contact_barejid(third)); roster_destroy(); } void add_twice_in_middle_adds_once(void **state) { roster_create(); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Dave", NULL, NULL, NULL, FALSE); roster_add("James", NULL, NULL, NULL, FALSE); roster_add("Bob", NULL, NULL, NULL, FALSE); GSList *list = roster_get_contacts(ROSTER_ORD_NAME); PContact first = list->data; PContact second = (g_slist_next(list))->data; P
void presence_away(void **state);
void presence_away_with_message(void **state);
void presence_online(void **state);
void presence_online_with_message(void **state);
void presence_xa(void **state);
void presence_xa_with_message(void **state);
void presence_dnd(void **state);
void presence_dnd_with_message(void **state);
void presence_chat(void **state);
void presence_chat_with_message(void **state);
void presence_set_priority(void **state);
void presence_includes_priority(void **state);
void presence_received(void **state);
void presence_missing_resource_defaults(void **state);
f")); roster_update("person@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 2); GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0); assert_true(found != NULL); assert_string_equal(found->data, "friends"); found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); assert_string_equal(found->data, "stuff"); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contact_with_three_groups_update_removing_two(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("stuff")); roster_update("person@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 1); GSList *found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); assert_string_equal(found->data, "stuff"); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contact_with_three_groups_update_removing_three(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); roster_update("person@server.org", NULL, NULL, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 0); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contact_with_three_groups_update_two_new(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("newfriends")); groups2 = g_slist_append(groups2, strdup("somepeople")); roster_update("person@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 2); GSList *found = g_slist_find_custom(groups_res, "newfriends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "somepeople", g_strcmp0); assert_true(found != NULL); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_remove_contact_groups(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); roster_remove("person@server.org", "person@server.org"); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 0); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contacts_with_different_groups(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("newfriends")); groups2 = g_slist_append(groups2, strdup("somepeople")); roster_add("bob@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 5); GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "work", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "newfriends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "somepeople", g_strcmp0); assert_true(found != NULL); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contacts_with_same_groups(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("friends")); groups2 = g_slist_append(groups2, strdup("work")); groups2 = g_slist_append(groups2, strdup("stuff")); roster_add("bob@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 3); GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "work", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); g_slist_free_full(groups_res, g_free); roster_destroy(); } void add_contacts_with_overlapping_groups(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("friends")); groups2 = g_slist_append(groups2, strdup("work")); groups2 = g_slist_append(groups2, strdup("different")); roster_add("bob@server.org", NULL, groups2, NULL, FALSE); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 4); GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "work", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "different", g_strcmp0); assert_true(found != NULL); g_slist_free_full(groups_res, g_free); roster_destroy(); } void remove_contact_with_remaining_in_group(void **state) { roster_create(); GSList *groups1 = NULL; groups1 = g_slist_append(groups1, strdup("friends")); groups1 = g_slist_append(groups1, strdup("work")); groups1 = g_slist_append(groups1, strdup("stuff")); roster_add("person@server.org", NULL, groups1, NULL, FALSE); GSList *groups2 = NULL; groups2 = g_slist_append(groups2, strdup("friends")); groups2 = g_slist_append(groups2, strdup("work")); groups2 = g_slist_append(groups2, strdup("different")); roster_add("bob@server.org", NULL, groups2, NULL, FALSE); roster_remove("bob@server.org", "bob@server.org"); GSList *groups_res = roster_get_groups(); assert_int_equal(g_slist_length(groups_res), 3); GSList *found = g_slist_find_custom(groups_res, "friends", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "work", g_strcmp0); assert_true(found != NULL); found = g_slist_find_custom(groups_res, "stuff", g_strcmp0); assert_true(found != NULL); g_slist_free_full(groups_res, g_free); roster_destroy(); }