1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added more autcomplete tests, test updating items

This commit is contained in:
James Booth 2012-05-24 00:38:54 +01:00
parent fef15b932c
commit 937950096f

View File

@ -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);
}