diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 4762bf6e0..1b4028694 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include "save.h" #include "unit.h" @@ -61,9 +63,36 @@ static void test_readwrite_unit(CuTest * tc) test_cleanup(); } +static void test_readwrite_attrib(CuTest *tc) { + gamedata *data; + attrib *a = NULL; + const char *path = "attrib.dat"; + test_cleanup(); + data = gamedata_open(path, "wb"); + CuAssertPtrNotNull(tc, data); + add_key(&a, 41); + add_key(&a, 42); + a_write(data->store, a, NULL); + gamedata_close(data); + a_removeall(&a, NULL); + CuAssertPtrEquals(tc, 0, a); + + data = gamedata_open(path, "rb"); + CuAssertPtrNotNull(tc, data); + a_read(data->store, &a, NULL); + gamedata_close(data); + CuAssertPtrNotNull(tc, find_key(a, 41)); + CuAssertPtrNotNull(tc, find_key(a, 42)); + a_removeall(&a, NULL); + + CuAssertIntEquals(tc, 0, remove(path)); + test_cleanup(); +} + CuSuite *get_save_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_readwrite_attrib); SUITE_ADD_TEST(suite, test_readwrite_data); SUITE_ADD_TEST(suite, test_readwrite_unit); return suite; diff --git a/src/util/attrib.c b/src/util/attrib.c index c076b74f2..837f9aff4 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -209,28 +209,37 @@ int a_remove(attrib ** pa, attrib * a) void a_removeall(attrib ** pa, const attrib_type * at) { attrib **pnexttype = pa; - attrib **pnext = NULL; - while (*pnexttype) { - attrib *next = *pnexttype; - if (next->type == at) - break; - pnexttype = &next->nexttype; - pnext = &next->next; - } - if (*pnexttype && (*pnexttype)->type == at) { - attrib *a = *pnexttype; - - *pnexttype = a->nexttype; - if (pnext) { - while (*pnext && (*pnext)->type != at) - pnext = &(*pnext)->next; - *pnext = a->nexttype; + if (!at) { + while (*pnexttype) { + attrib *a = *pnexttype; + *pnexttype = a->next; + a_free(a); } - while (a && a->type == at) { - attrib *ra = a; - a = a->next; - a_free(ra); + } + else { + attrib **pnext = NULL; + while (*pnexttype) { + attrib *a = *pnexttype; + if (a->type == at) + break; + pnexttype = &a->nexttype; + pnext = &a->next; + } + if (*pnexttype && (*pnexttype)->type == at) { + attrib *a = *pnexttype; + + *pnexttype = a->nexttype; + if (pnext) { + while (*pnext && (*pnext)->type != at) + pnext = &(*pnext)->next; + *pnext = a->nexttype; + } + while (a && a->type == at) { + attrib *ra = a; + a = a->next; + a_free(ra); + } } } } diff --git a/src/util/attrib.test.c b/src/util/attrib.test.c index 691087477..76533887d 100644 --- a/src/util/attrib.test.c +++ b/src/util/attrib.test.c @@ -51,6 +51,23 @@ static void test_attrib_remove_self(CuTest * tc) { CuAssertPtrEquals(tc, a, alist); } + +static void test_attrib_removeall(CuTest * tc) { + const attrib_type at_foo = { "foo" }; + const attrib_type at_bar = { "bar" }; + attrib *alist = 0, *a; + a_add(&alist, a_new(&at_foo)); + a = a_add(&alist, a_new(&at_bar)); + a_add(&alist, a_new(&at_foo)); + a_removeall(&alist, &at_foo); + CuAssertPtrEquals(tc, a, alist); + CuAssertPtrEquals(tc, 0, alist->next); + a_add(&alist, a_new(&at_bar)); + a_add(&alist, a_new(&at_foo)); + a_removeall(&alist, NULL); + CuAssertPtrEquals(tc, 0, alist); +} + static void test_attrib_remove(CuTest * tc) { attrib_type at_foo = { "foo" }; @@ -98,6 +115,7 @@ CuSuite *get_attrib_suite(void) 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_removeall); SUITE_ADD_TEST(suite, test_attrib_remove_self); SUITE_ADD_TEST(suite, test_attrib_nexttype); return suite; diff --git a/tests/score b/tests/score deleted file mode 100644 index 5f282702b..000000000 --- a/tests/score +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tests/score.alliances b/tests/score.alliances deleted file mode 100644 index 003fe8605..000000000 --- a/tests/score.alliances +++ /dev/null @@ -1,3 +0,0 @@ -# alliance:factions:persons:score -1248287:1:0:0 -1490214:1:0:2105