forked from github/server
quick addition to a_removeall
additional testing for attributes
This commit is contained in:
parent
8a3bb35987
commit
7b4b879cc1
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
# alliance:factions:persons:score
|
||||
1248287:1:0:0
|
||||
1490214:1:0:2105
|
Loading…
Reference in New Issue