From 937950096fea78f520fafe559103ed2c84ff97e9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 24 May 2012 00:38:54 +0100 Subject: [PATCH] Added more autcomplete tests, test updating items --- test_prof_autocomplete.c | 115 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/test_prof_autocomplete.c b/test_prof_autocomplete.c index d4142843..45717abd 100644 --- a/test_prof_autocomplete.c +++ b/test_prof_autocomplete.c @@ -260,6 +260,114 @@ static void add_two_same_updates_with_funcs(void) p_autocomplete_clear(ac); } +static void add_one_returns_true(void) +{ + char *item = strdup("Hello"); + PAutocomplete ac = p_autocomplete_new(); + int result = p_autocomplete_add(ac, item); + + assert_true(result); + + 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"); + char *item2 = strdup("Hello there"); + PAutocomplete ac = p_autocomplete_new(); + int result1 = p_autocomplete_add(ac, item1); + int result2 = p_autocomplete_add(ac, item2); + + assert_true(result1); + assert_true(result2); + + 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"); + char *item2 = strdup("Hello"); + PAutocomplete ac = p_autocomplete_new(); + int result1 = p_autocomplete_add(ac, item1); + int result2 = p_autocomplete_add(ac, item2); + + assert_true(result1); + assert_false(result2); + + 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"); @@ -281,4 +389,11 @@ void register_prof_autocomplete_tests(void) 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); }