quick addition to a_removeall

additional testing for attributes
This commit is contained in:
Enno Rehling 2016-02-06 10:56:08 +01:00
parent 8a3bb35987
commit 7b4b879cc1
5 changed files with 76 additions and 24 deletions

View File

@ -1,5 +1,7 @@
#include <platform.h>
#include <kernel/config.h>
#include <util/attrib.h>
#include <attributes/key.h>
#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;

View File

@ -209,14 +209,22 @@ int a_remove(attrib ** pa, attrib * a)
void a_removeall(attrib ** pa, const attrib_type * at)
{
attrib **pnexttype = pa;
attrib **pnext = NULL;
if (!at) {
while (*pnexttype) {
attrib *next = *pnexttype;
if (next->type == at)
attrib *a = *pnexttype;
*pnexttype = a->next;
a_free(a);
}
}
else {
attrib **pnext = NULL;
while (*pnexttype) {
attrib *a = *pnexttype;
if (a->type == at)
break;
pnexttype = &next->nexttype;
pnext = &next->next;
pnexttype = &a->nexttype;
pnext = &a->next;
}
if (*pnexttype && (*pnexttype)->type == at) {
attrib *a = *pnexttype;
@ -233,6 +241,7 @@ void a_removeall(attrib ** pa, const attrib_type * at)
a_free(ra);
}
}
}
}
attrib *a_new(const attrib_type * at)

View File

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

View File

@ -1 +0,0 @@


View File

@ -1,3 +0,0 @@
# alliance:factions:persons:score
1248287:1:0:0
1490214:1:0:2105