diff --git a/src/util/attrib.test.c b/src/util/attrib.test.c index be3987bfe..2790f3edb 100644 --- a/src/util/attrib.test.c +++ b/src/util/attrib.test.c @@ -12,6 +12,7 @@ static void test_attrib_new(CuTest * tc) CuAssertPtrEquals(tc, 0, a->next); CuAssertPtrEquals(tc, 0, a->nexttype); CuAssertPtrEquals(tc, (void *)a->type, (void *)&at_test); + a_free(a); } @@ -20,18 +21,55 @@ static void test_attrib_add(CuTest * tc) attrib_type at_foo = { "foo" }; attrib_type at_bar = { "bar" }; attrib *a, *alist = 0; + CuAssertPtrNotNull(tc, (a = a_new(&at_foo))); CuAssertPtrEquals(tc, a, a_add(&alist, a)); CuAssertPtrEquals(tc, a, alist); - CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo)))); - CuAssertPtrEquals(tc, alist->next, a); + CuAssertPtrEquals_Msg(tc, "new attribute not added after existing", alist->next, a); + + CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); + CuAssertPtrEquals_Msg(tc, "new atribute not added at end of list", alist->next->next, a); + + CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_foo)))); + CuAssertPtrEquals_Msg(tc, "messages not sorted by type", alist->next->next, a); + a_removeall(&alist, &at_foo); + a_removeall(&alist, &at_bar); +} + +static void test_attrib_remove(CuTest * tc) +{ + attrib_type at_foo = { "foo" }; + attrib *a, *alist = 0; + + CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo))); + CuAssertPtrNotNull(tc, a = a_add(&alist, a_new(&at_foo))); + CuAssertIntEquals(tc, 1, a_remove(&alist, a)); + CuAssertPtrNotNull(tc, alist); + CuAssertIntEquals(tc, 1, a_remove(&alist, alist)); + CuAssertPtrEquals(tc, 0, alist); +} + +static void test_attrib_nexttype(CuTest * tc) +{ + attrib_type at_foo = { "foo" }; + attrib_type at_bar = { "bar" }; + attrib *a, *alist = 0; + CuAssertPtrNotNull(tc, (a = a_new(&at_foo))); + CuAssertPtrEquals(tc, 0, a->nexttype); + CuAssertPtrEquals(tc, a, a_add(&alist, a)); + CuAssertPtrEquals(tc, 0, alist->nexttype); + + CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo))); CuAssertPtrEquals(tc, 0, alist->nexttype); CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar)))); - CuAssertPtrEquals(tc, alist->next->next, a); CuAssertPtrEquals(tc, a, alist->nexttype); + CuAssertPtrEquals(tc, 0, a->nexttype); + + a_removeall(&alist, &at_foo); + a_removeall(&alist, &at_bar); } CuSuite *get_attrib_suite(void) @@ -39,5 +77,7 @@ CuSuite *get_attrib_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_attrib_new); SUITE_ADD_TEST(suite, test_attrib_add); + SUITE_ADD_TEST(suite, test_attrib_remove); + SUITE_ADD_TEST(suite, test_attrib_nexttype); return suite; }