diff options
author | James Booth <boothj5@gmail.com> | 2012-05-24 00:38:54 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-05-24 00:38:54 +0100 |
commit | 937950096fea78f520fafe559103ed2c84ff97e9 (patch) | |
tree | 3abc0c010bd0cad7545dd1afb3cb48656a174358 | |
parent | fef15b932ccae738e53827c6fc025b82c4d8adb6 (diff) | |
download | profani-tty-937950096fea78f520fafe559103ed2c84ff97e9.tar.gz |
Added more autcomplete tests, test updating items
-rw-r--r-- | test_prof_autocomplete.c | 115 |
1 files changed, 115 insertions, 0 deletions
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); } |