From c60060fe5a7203daa72f4807c17d5dd86f780802 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 14 Nov 2015 22:21:57 +0000 Subject: [PATCH] Added more group tests --- tests/unittests/test_roster_list.c | 265 ++++++++++++++++++++++++++++- tests/unittests/test_roster_list.h | 19 ++- tests/unittests/unittests.c | 19 ++- 3 files changed, 288 insertions(+), 15 deletions(-) diff --git a/tests/unittests/test_roster_list.c b/tests/unittests/test_roster_list.c index 5b626e74..f12361e4 100644 --- a/tests/unittests/test_roster_list.c +++ b/tests/unittests/test_roster_list.c @@ -288,7 +288,7 @@ void find_twice_returns_first_when_two_match_and_reset(void **state) roster_free(); } -void add_contact_with_no_group_returns_no_groups(void **state) +void add_contact_with_no_group(void **state) { roster_init(); roster_add("person@server.org", NULL, NULL, NULL, FALSE); @@ -301,7 +301,7 @@ void add_contact_with_no_group_returns_no_groups(void **state) roster_free(); } -void add_contact_with_group_returns_group(void **state) +void add_contact_with_group(void **state) { roster_init(); @@ -321,7 +321,7 @@ void add_contact_with_group_returns_group(void **state) roster_free(); } -void add_contact_with_two_groups_returns_groups(void **state) +void add_contact_with_two_groups(void **state) { roster_init(); @@ -345,7 +345,7 @@ void add_contact_with_two_groups_returns_groups(void **state) roster_free(); } -void add_contact_with_three_groups_returns_groups(void **state) +void add_contact_with_three_groups(void **state) { roster_init(); @@ -373,7 +373,7 @@ void add_contact_with_three_groups_returns_groups(void **state) roster_free(); } -void add_contact_with_three_groups_update_adding_two_returns_groups(void **state) +void add_contact_with_three_groups_update_adding_two(void **state) { roster_init(); @@ -414,3 +414,258 @@ void add_contact_with_three_groups_update_adding_two_returns_groups(void **state roster_clear(); roster_free(); } + +void add_contact_with_three_groups_update_removing_one(void **state) +{ + roster_init(); + + 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("stuff")); + 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_clear(); + roster_free(); +} + +void add_contact_with_three_groups_update_removing_two(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_contact_with_three_groups_update_removing_three(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_contact_with_three_groups_update_two_new(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_remove_contact_groups(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_contacts_with_different_groups(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_contacts_with_same_groups(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void add_contacts_with_overlapping_groups(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} + +void remove_contact_with_remaining_in_group(void **state) +{ + roster_init(); + + 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_clear(); + roster_free(); +} diff --git a/tests/unittests/test_roster_list.h b/tests/unittests/test_roster_list.h index d0da560a..464ecd55 100644 --- a/tests/unittests/test_roster_list.h +++ b/tests/unittests/test_roster_list.h @@ -16,8 +16,17 @@ void find_on_empty_returns_null(void **state); void find_twice_returns_second_when_two_match(void **state); void find_five_times_finds_fifth(void **state); void find_twice_returns_first_when_two_match_and_reset(void **state); -void add_contact_with_no_group_returns_no_groups(void **state); -void add_contact_with_group_returns_group(void **state); -void add_contact_with_two_groups_returns_groups(void **state); -void add_contact_with_three_groups_returns_groups(void **state); -void add_contact_with_three_groups_update_adding_two_returns_groups(void **state); +void add_contact_with_no_group(void **state); +void add_contact_with_group(void **state); +void add_contact_with_two_groups(void **state); +void add_contact_with_three_groups(void **state); +void add_contact_with_three_groups_update_adding_two(void **state); +void add_contact_with_three_groups_update_removing_one(void **state); +void add_contact_with_three_groups_update_removing_two(void **state); +void add_contact_with_three_groups_update_removing_three(void **state); +void add_contact_with_three_groups_update_two_new(void **state); +void add_remove_contact_groups(void **state); +void add_contacts_with_different_groups(void **state); +void add_contacts_with_same_groups(void **state); +void add_contacts_with_overlapping_groups(void **state); +void remove_contact_with_remaining_in_group(void **state); diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c index 55008b9c..e511df9d 100644 --- a/tests/unittests/unittests.c +++ b/tests/unittests/unittests.c @@ -210,11 +210,20 @@ int main(int argc, char* argv[]) { unit_test(find_twice_returns_second_when_two_match), unit_test(find_five_times_finds_fifth), unit_test(find_twice_returns_first_when_two_match_and_reset), - unit_test(add_contact_with_no_group_returns_no_groups), - unit_test(add_contact_with_group_returns_group), - unit_test(add_contact_with_two_groups_returns_groups), - unit_test(add_contact_with_three_groups_returns_groups), - unit_test(add_contact_with_three_groups_update_adding_two_returns_groups), + unit_test(add_contact_with_no_group), + unit_test(add_contact_with_group), + unit_test(add_contact_with_two_groups), + unit_test(add_contact_with_three_groups), + unit_test(add_contact_with_three_groups_update_adding_two), + unit_test(add_contact_with_three_groups_update_removing_one), + unit_test(add_contact_with_three_groups_update_removing_two), + unit_test(add_contact_with_three_groups_update_removing_three), + unit_test(add_contact_with_three_groups_update_two_new), + unit_test(add_remove_contact_groups), + unit_test(add_contacts_with_different_groups), + unit_test(add_contacts_with_same_groups), + unit_test(add_contacts_with_overlapping_groups), + unit_test(remove_contact_with_remaining_in_group), unit_test_setup_teardown(returns_false_when_chat_session_does_not_exist, init_chat_sessions,