From 768b2aa4667a362ea1343f47c044d79b642c2497 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 29 Oct 2012 22:55:17 +0000 Subject: [PATCH] Fixed tests --- Makefile.am | 3 +- src/contact_list.c | 9 +- src/contact_list.h | 2 +- src/jabber.c | 6 +- tests/test_contact_list.c | 322 +++++++++++---------------------- tests/test_prof_autocomplete.c | 217 ---------------------- 6 files changed, 114 insertions(+), 445 deletions(-) diff --git a/Makefile.am b/Makefile.am index f28807d6..72343a7b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,8 @@ TESTS = tests/testsuite check_PROGRAMS = tests/testsuite tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \ tests/test_common.c tests/test_prof_history.c src/prof_history.c src/common.c \ - tests/test_prof_autocomplete.c src/prof_autocomplete.c tests/testsuite.c + tests/test_prof_autocomplete.c src/prof_autocomplete.c tests/testsuite.c \ + src/log.c tests_testsuite_LDADD = -lheadunit -lstdc++ man_MANS = docs/profanity.1 diff --git a/src/contact_list.c b/src/contact_list.c index 3f8ff2ee..d05d7412 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -54,21 +54,22 @@ contact_list_reset_search_attempts(void) p_autocomplete_reset(ac); } -void +gboolean contact_list_add(const char * const jid, const char * const name, const char * const presence, const char * const status, const char * const subscription) { + gboolean added = FALSE; PContact contact = g_hash_table_lookup(contacts, jid); if (contact == NULL) { contact = p_contact_new(jid, name, presence, status, subscription); g_hash_table_insert(contacts, strdup(jid), contact); - } else { - log_warning("Duplicate roster entry: %s", jid); + p_autocomplete_add(ac, strdup(jid)); + added = TRUE; } - p_autocomplete_add(ac, strdup(jid)); + return added; } gboolean diff --git a/src/contact_list.h b/src/contact_list.h index 9f6bbe4c..90ae947b 100644 --- a/src/contact_list.h +++ b/src/contact_list.h @@ -30,7 +30,7 @@ void contact_list_init(void); void contact_list_clear(void); void contact_list_reset_search_attempts(void); -void contact_list_add(const char * const jid, const char * const name, +gboolean contact_list_add(const char * const jid, const char * const name, const char * const presence, const char * const status, const char * const subscription); gboolean contact_list_update_contact(const char * const jid, const char * const presence, diff --git a/src/jabber.c b/src/jabber.c index e2e146e8..8c9c9ba0 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -386,7 +386,11 @@ _roster_handler(xmpp_conn_t * const conn, const char *jid = xmpp_stanza_get_attribute(item, "jid"); const char *name = xmpp_stanza_get_attribute(item, "name"); const char *sub = xmpp_stanza_get_attribute(item, "subscription"); - contact_list_add(jid, name, "offline", NULL, sub); + gboolean added = contact_list_add(jid, name, "offline", NULL, sub); + + if (!added) { + log_warning("Attempt to add contact twice: %s", jid); + } item = xmpp_stanza_get_next(item); } diff --git a/tests/test_contact_list.c b/tests/test_contact_list.c index 18d5a6e4..ef31abbc 100644 --- a/tests/test_contact_list.c +++ b/tests/test_contact_list.c @@ -31,24 +31,24 @@ static void empty_list_when_none_added(void) static void contains_one_element(void) { - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); } static void first_element_correct(void) { - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); + assert_string_equals("James", p_contact_jid(james)); } static void contains_two_elements(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(2, g_slist_length(list)); @@ -56,22 +56,22 @@ static void contains_two_elements(void) static void first_and_second_elements_correct(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); - PContact dave = list->data; - PContact james = (g_slist_next(list))->data; + PContact first = list->data; + PContact second = (g_slist_next(list))->data; - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); + assert_string_equals("James", p_contact_jid(first)); + assert_string_equals("Dave", p_contact_jid(second)); } static void contains_three_elements(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - contact_list_add("Dave", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(3, g_slist_length(list)); @@ -79,194 +79,100 @@ static void contains_three_elements(void) static void first_three_elements_correct(void) { - contact_list_add("Bob", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("James", NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); PContact bob = list->data; PContact dave = (g_slist_next(list))->data; PContact james = (g_slist_next(g_slist_next(list)))->data; - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); - assert_string_equals("Bob", p_contact_name(bob)); + assert_string_equals("James", p_contact_jid(james)); + assert_string_equals("Dave", p_contact_jid(dave)); + assert_string_equals("Bob", p_contact_jid(bob)); } static void add_twice_at_beginning_adds_once(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); - PContact bob = list->data; - PContact dave = (g_slist_next(list))->data; - PContact james = (g_slist_next(g_slist_next(list)))->data; + PContact first = list->data; + PContact second = (g_slist_next(list))->data; + PContact third = (g_slist_next(g_slist_next(list)))->data; assert_int_equals(3, g_slist_length(list)); - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); - assert_string_equals("Bob", p_contact_name(bob)); + assert_string_equals("James", p_contact_jid(first)); + assert_string_equals("Dave", p_contact_jid(second)); + assert_string_equals("Bob", p_contact_jid(third)); } static void add_twice_in_middle_adds_once(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("James", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); - PContact bob = list->data; - PContact dave = (g_slist_next(list))->data; - PContact james = (g_slist_next(g_slist_next(list)))->data; + PContact first = list->data; + PContact second = (g_slist_next(list))->data; + PContact third = (g_slist_next(g_slist_next(list)))->data; assert_int_equals(3, g_slist_length(list)); - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); - assert_string_equals("Bob", p_contact_name(bob)); + assert_string_equals("James", p_contact_jid(first)); + assert_string_equals("Dave", p_contact_jid(second)); + assert_string_equals("Bob", p_contact_jid(third)); } static void add_twice_at_end_adds_once(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); - PContact bob = list->data; - PContact dave = (g_slist_next(list))->data; - PContact james = (g_slist_next(g_slist_next(list)))->data; + PContact first = list->data; + PContact second = (g_slist_next(list))->data; + PContact third = (g_slist_next(g_slist_next(list)))->data; assert_int_equals(3, g_slist_length(list)); - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); - assert_string_equals("Bob", p_contact_name(bob)); -} - -static void remove_when_none_does_nothing(void) -{ - contact_list_remove("James"); - GSList *list = get_contact_list(); - - assert_int_equals(0, g_slist_length(list)); -} - -static void remove_when_one_removes(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_remove("James"); - GSList *list = get_contact_list(); - - assert_int_equals(0, g_slist_length(list)); -} - -static void remove_first_when_two(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - - contact_list_remove("James"); - GSList *list = get_contact_list(); - - assert_int_equals(1, g_slist_length(list)); - PContact dave = list->data; - assert_string_equals("Dave", p_contact_name(dave)); -} - -static void remove_second_when_two(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - - contact_list_remove("Dave"); - GSList *list = get_contact_list(); - - assert_int_equals(1, g_slist_length(list)); - PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); -} - -static void remove_first_when_three(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - - contact_list_remove("James"); - GSList *list = get_contact_list(); - - assert_int_equals(2, g_slist_length(list)); - PContact bob = list->data; - PContact dave = (g_slist_next(list))->data; - - assert_string_equals("Dave", p_contact_name(dave)); - assert_string_equals("Bob", p_contact_name(bob)); -} - -static void remove_second_when_three(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - - contact_list_remove("Dave"); - GSList *list = get_contact_list(); - - assert_int_equals(2, g_slist_length(list)); - PContact bob = list->data; - PContact james = (g_slist_next(list))->data; - - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Bob", p_contact_name(bob)); -} - -static void remove_third_when_three(void) -{ - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - - contact_list_remove("Bob"); - GSList *list = get_contact_list(); - - assert_int_equals(2, g_slist_length(list)); - PContact dave = list->data; - PContact james = (g_slist_next(list))->data; - - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("Dave", p_contact_name(dave)); + assert_string_equals("James", p_contact_jid(first)); + assert_string_equals("Dave", p_contact_jid(second)); + assert_string_equals("Bob", p_contact_jid(third)); } static void test_show_when_value(void) { - contact_list_add("James", "away", NULL); + contact_list_add("James", NULL, "away", NULL, NULL); GSList *list = get_contact_list(); PContact james = list->data; - assert_string_equals("away", p_contact_show(james)); + assert_string_equals("away", p_contact_presence(james)); } static void test_show_online_when_no_value(void) { - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); PContact james = list->data; - assert_string_equals("online", p_contact_show(james)); + assert_string_equals("online", p_contact_presence(james)); } static void test_show_online_when_empty_string(void) { - contact_list_add("James", "", NULL); + contact_list_add("James", NULL, "", NULL, NULL); GSList *list = get_contact_list(); PContact james = list->data; - assert_string_equals("online", p_contact_show(james)); + assert_string_equals("online", p_contact_presence(james)); } static void test_status_when_value(void) { - contact_list_add("James", NULL, "I'm not here right now"); + contact_list_add("James", NULL, NULL, "I'm not here right now", NULL); GSList *list = get_contact_list(); PContact james = list->data; @@ -275,7 +181,7 @@ static void test_status_when_value(void) static void test_status_when_no_value(void) { - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); GSList *list = get_contact_list(); PContact james = list->data; @@ -284,57 +190,57 @@ static void test_status_when_no_value(void) static void update_show(void) { - contact_list_add("James", "away", NULL); - contact_list_add("James", "dnd", NULL); + contact_list_add("James", NULL, "away", NULL, NULL); + contact_list_update_contact("James", "dnd", NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); - PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("dnd", p_contact_show(james)); + PContact first = list->data; + assert_string_equals("James", p_contact_jid(first)); + assert_string_equals("dnd", p_contact_presence(first)); } static void set_show_to_null(void) { - contact_list_add("James", "away", NULL); - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, "away", NULL, NULL); + contact_list_update_contact("James", NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); - assert_string_equals("online", p_contact_show(james)); + assert_string_equals("James", p_contact_jid(james)); + assert_is_null(p_contact_presence(james)); } static void update_status(void) { - contact_list_add("James", NULL, "I'm not here right now"); - contact_list_add("James", NULL, "Gone to lunch"); + contact_list_add("James", NULL, NULL, "I'm not here right now", NULL); + contact_list_update_contact("James", NULL, "Gone to lunch"); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); + assert_string_equals("James", p_contact_jid(james)); assert_string_equals("Gone to lunch", p_contact_status(james)); } static void set_status_to_null(void) { - contact_list_add("James", NULL, "Gone to lunch"); - contact_list_add("James", NULL, NULL); + contact_list_add("James", NULL, NULL, "Gone to lunch", NULL); + contact_list_update_contact("James", NULL, NULL); GSList *list = get_contact_list(); assert_int_equals(1, g_slist_length(list)); PContact james = list->data; - assert_string_equals("James", p_contact_name(james)); + assert_string_equals("James", p_contact_jid(james)); assert_is_null(p_contact_status(james)); } static void find_first_exists(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *search = (char *) malloc(2 * sizeof(char)); strcpy(search, "B"); @@ -347,9 +253,9 @@ static void find_first_exists(void) static void find_second_exists(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *result = contact_list_find_contact("Dav"); assert_string_equals("Dave", result); @@ -358,9 +264,9 @@ static void find_second_exists(void) static void find_third_exists(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *result = contact_list_find_contact("Ja"); assert_string_equals("James", result); @@ -369,9 +275,9 @@ static void find_third_exists(void) static void find_returns_null(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *result = contact_list_find_contact("Mike"); assert_is_null(result); @@ -385,9 +291,9 @@ static void find_on_empty_returns_null(void) static void find_twice_returns_second_when_two_match(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Jamie", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Jamie", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *result1 = contact_list_find_contact("Jam"); char *result2 = contact_list_find_contact(result1); @@ -398,16 +304,16 @@ static void find_twice_returns_second_when_two_match(void) static void find_five_times_finds_fifth(void) { - contact_list_add("Jama", NULL, NULL); - contact_list_add("Jamb", NULL, NULL); - contact_list_add("Mike", NULL, NULL); - contact_list_add("Dave", NULL, NULL); - contact_list_add("Jamm", NULL, NULL); - contact_list_add("Jamn", NULL, NULL); - contact_list_add("Matt", NULL, NULL); - contact_list_add("Jamo", NULL, NULL); - contact_list_add("Jamy", NULL, NULL); - contact_list_add("Jamz", NULL, NULL); + contact_list_add("Jama", NULL, NULL, NULL, NULL); + contact_list_add("Jamb", NULL, NULL, NULL, NULL); + contact_list_add("Mike", NULL, NULL, NULL, NULL); + contact_list_add("Dave", NULL, NULL, NULL, NULL); + contact_list_add("Jamm", NULL, NULL, NULL, NULL); + contact_list_add("Jamn", NULL, NULL, NULL, NULL); + contact_list_add("Matt", NULL, NULL, NULL, NULL); + contact_list_add("Jamo", NULL, NULL, NULL, NULL); + contact_list_add("Jamy", NULL, NULL, NULL, NULL); + contact_list_add("Jamz", NULL, NULL, NULL, NULL); char *result1 = contact_list_find_contact("Jam"); char *result2 = contact_list_find_contact(result1); @@ -424,9 +330,9 @@ static void find_five_times_finds_fifth(void) static void find_twice_returns_first_when_two_match_and_reset(void) { - contact_list_add("James", NULL, NULL); - contact_list_add("Jamie", NULL, NULL); - contact_list_add("Bob", NULL, NULL); + contact_list_add("James", NULL, NULL, NULL, NULL); + contact_list_add("Jamie", NULL, NULL, NULL, NULL); + contact_list_add("Bob", NULL, NULL, NULL, NULL); char *result1 = contact_list_find_contact("Jam"); contact_list_reset_search_attempts(); @@ -436,24 +342,6 @@ static void find_twice_returns_first_when_two_match_and_reset(void) free(result2); } -static void removed_contact_not_in_search(void) -{ - contact_list_add("Jamatron", NULL, NULL); - contact_list_add("Bob", NULL, NULL); - contact_list_add("Jambo", NULL, NULL); - contact_list_add("James", NULL, NULL); - contact_list_add("Jamie", NULL, NULL); - - char *result1 = contact_list_find_contact("Jam"); // Jamatron - char *result2 = contact_list_find_contact(result1); // Jambo - contact_list_remove("James"); - char *result3 = contact_list_find_contact(result2); - assert_string_equals("Jamie", result3); - free(result1); - free(result2); - free(result3); -} - void register_contact_list_tests(void) { TEST_MODULE("contact_list tests"); @@ -470,13 +358,6 @@ void register_contact_list_tests(void) TEST(add_twice_at_beginning_adds_once); TEST(add_twice_in_middle_adds_once); TEST(add_twice_at_end_adds_once); - TEST(remove_when_none_does_nothing); - TEST(remove_when_one_removes); - TEST(remove_first_when_two); - TEST(remove_second_when_two); - TEST(remove_first_when_three); - TEST(remove_second_when_three); - TEST(remove_third_when_three); TEST(test_show_when_value); TEST(test_show_online_when_no_value); TEST(test_show_online_when_empty_string); @@ -493,6 +374,5 @@ void register_contact_list_tests(void) TEST(find_on_empty_returns_null); TEST(find_twice_returns_second_when_two_match); TEST(find_twice_returns_first_when_two_match_and_reset); - TEST(removed_contact_not_in_search); TEST(find_five_times_finds_fifth); } diff --git a/tests/test_prof_autocomplete.c b/tests/test_prof_autocomplete.c index 895a4a44..b61c9cf6 100644 --- a/tests/test_prof_autocomplete.c +++ b/tests/test_prof_autocomplete.c @@ -13,16 +13,6 @@ static void clear_empty(void) p_autocomplete_clear(ac); } -static void clear_empty_with_free_func(void) -{ - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_clear(ac); -} - static void reset_after_create(void) { PAutocomplete ac = p_autocomplete_new(); @@ -47,20 +37,6 @@ static void get_after_create_returns_null(void) p_autocomplete_clear(ac); } -static void get_after_create_with_copy_func_returns_null(void) -{ - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - GSList *result = p_autocomplete_get_list(ac); - - assert_is_null(result); - - p_autocomplete_clear(ac); -} - static void add_one_and_complete(void) { char *item = strdup("Hello"); @@ -73,22 +49,6 @@ static void add_one_and_complete(void) p_autocomplete_clear(ac); } -static void add_one_and_complete_with_funcs(void) -{ - PContact contact = p_contact_new("James", "Online", "I'm here"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact); - char *result = p_autocomplete_complete(ac, "Jam"); - - assert_string_equals("James", result); - - p_autocomplete_clear(ac); -} - static void add_two_and_complete_returns_first(void) { char *item1 = strdup("Hello"); @@ -103,24 +63,6 @@ static void add_two_and_complete_returns_first(void) p_autocomplete_clear(ac); } -static void add_two_and_complete_returns_first_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact1); - p_autocomplete_add(ac, contact2); - char *result = p_autocomplete_complete(ac, "Jam"); - - assert_string_equals("James", result); - - p_autocomplete_clear(ac); -} - static void add_two_and_complete_returns_second(void) { char *item1 = strdup("Hello"); @@ -136,25 +78,6 @@ static void add_two_and_complete_returns_second(void) p_autocomplete_clear(ac); } -static void add_two_and_complete_returns_second_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact1); - p_autocomplete_add(ac, contact2); - char *result1 = p_autocomplete_complete(ac, "Jam"); - char *result2 = p_autocomplete_complete(ac, result1); - - assert_string_equals("Jamie", result2); - - p_autocomplete_clear(ac); -} - static void add_two_adds_two(void) { char *item1 = strdup("Hello"); @@ -169,24 +92,6 @@ static void add_two_adds_two(void) p_autocomplete_clear(ac); } -static void add_two_adds_two_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact1); - p_autocomplete_add(ac, contact2); - GSList *result = p_autocomplete_get_list(ac); - - assert_int_equals(2, g_slist_length(result)); - - p_autocomplete_clear(ac); -} - static void add_two_same_adds_one(void) { char *item1 = strdup("Hello"); @@ -201,24 +106,6 @@ static void add_two_same_adds_one(void) p_autocomplete_clear(ac); } -static void add_two_same_adds_one_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("James", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact1); - p_autocomplete_add(ac, contact2); - GSList *result = p_autocomplete_get_list(ac); - - assert_int_equals(1, g_slist_length(result)); - - p_autocomplete_clear(ac); -} - static void add_two_same_updates(void) { char *item1 = strdup("Hello"); @@ -237,29 +124,6 @@ static void add_two_same_updates(void) p_autocomplete_clear(ac); } -static void add_two_same_updates_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("James", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - p_autocomplete_add(ac, contact1); - p_autocomplete_add(ac, contact2); - GSList *result = p_autocomplete_get_list(ac); - - GSList *first = g_slist_nth(result, 0); - PContact contact = first->data; - - assert_string_equals("James", p_contact_name(contact)); - assert_string_equals("Away", p_contact_show(contact)); - assert_string_equals("Out to lunch", p_contact_status(contact)); - - p_autocomplete_clear(ac); -} - static void add_one_returns_true(void) { char *item = strdup("Hello"); @@ -271,21 +135,6 @@ static void add_one_returns_true(void) p_autocomplete_clear(ac); } -static void add_one_returns_true_with_funcs(void) -{ - PContact contact = p_contact_new("James", "Online", "I'm here"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - int result = p_autocomplete_add(ac, contact); - - assert_true(result); - - p_autocomplete_clear(ac); -} - static void add_two_different_returns_true(void) { char *item1 = strdup("Hello"); @@ -300,24 +149,6 @@ static void add_two_different_returns_true(void) p_autocomplete_clear(ac); } -static void add_two_different_returns_true_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("JamesB", "Away", "Out to lunch"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - int result1 = p_autocomplete_add(ac, contact1); - int result2 = p_autocomplete_add(ac, contact2); - - assert_true(result1); - assert_true(result2); - - p_autocomplete_clear(ac); -} - static void add_two_same_returns_false(void) { char *item1 = strdup("Hello"); @@ -332,68 +163,20 @@ static void add_two_same_returns_false(void) p_autocomplete_clear(ac); } -static void add_two_same_returns_false_with_funcs(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("James", "Online", "I'm here"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - int result1 = p_autocomplete_add(ac, contact1); - int result2 = p_autocomplete_add(ac, contact2); - - assert_true(result1); - assert_false(result2); - - p_autocomplete_clear(ac); -} - -static void add_two_same_different_data_returns_true(void) -{ - PContact contact1 = p_contact_new("James", "Online", "I'm here"); - PContact contact2 = p_contact_new("James", "Away", "I'm not here right now"); - PAutocomplete ac = - p_obj_autocomplete_new((PStrFunc)p_contact_name, - (PCopyFunc)p_contact_copy, - (PEqualDeepFunc)p_contacts_equal_deep, - (GDestroyNotify)p_contact_free); - int result1 = p_autocomplete_add(ac, contact1); - int result2 = p_autocomplete_add(ac, contact2); - - assert_true(result1); - assert_true(result2); - - p_autocomplete_clear(ac); -} - void register_prof_autocomplete_tests(void) { TEST_MODULE("prof_autocomplete tests"); TEST(clear_empty); - TEST(clear_empty_with_free_func); TEST(reset_after_create); TEST(find_after_create); TEST(get_after_create_returns_null); - TEST(get_after_create_with_copy_func_returns_null); TEST(add_one_and_complete); - TEST(add_one_and_complete_with_funcs); TEST(add_two_and_complete_returns_first); - TEST(add_two_and_complete_returns_first_with_funcs); TEST(add_two_and_complete_returns_second); - TEST(add_two_and_complete_returns_second_with_funcs); TEST(add_two_adds_two); - TEST(add_two_adds_two_with_funcs); TEST(add_two_same_adds_one); - TEST(add_two_same_adds_one_with_funcs); TEST(add_two_same_updates); - TEST(add_two_same_updates_with_funcs); TEST(add_one_returns_true); - TEST(add_one_returns_true_with_funcs); TEST(add_two_different_returns_true); - TEST(add_two_different_returns_true_with_funcs); TEST(add_two_same_returns_false); - TEST(add_two_same_returns_false_with_funcs); - TEST(add_two_same_different_data_returns_true); }