additional testing.

This commit is contained in:
Enno Rehling 2014-10-18 14:16:26 +02:00
parent a86c2d88ab
commit 74a6bd72c2
7 changed files with 345 additions and 298 deletions

View file

@ -113,8 +113,6 @@ char *rns(FILE * f, char *c, size_t size)
return c;
}
extern unsigned int __at_hashkey(const char *s);
static unit *unitorders(FILE * F, int enc, struct faction *f)
{

View file

@ -30,6 +30,7 @@ int RunAllTests(void)
ADD_TESTS(suite, race);
/* util */
ADD_TESTS(suite, config);
ADD_TESTS(suite, attrib);
ADD_TESTS(suite, base36);
ADD_TESTS(suite, bsdstring);
ADD_TESTS(suite, functions);

View file

@ -1,5 +1,8 @@
#ifndef ERESSEA_TESTS_H
#define ERESSEA_TESTS_H
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif

View file

@ -2,6 +2,7 @@ project(util C)
SET(_TEST_FILES
base36.test.c
attrib.test.c
strings.test.c
bsdstring.test.c
functions.test.c

View file

@ -29,7 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h>
#define MAXATHASH 61
attrib_type *at_hash[MAXATHASH];
static attrib_type *at_hash[MAXATHASH];
static unsigned int __at_hashkey(const char *s)
{
@ -51,12 +51,14 @@ void at_register(attrib_type * at)
}
at->hashkey = __at_hashkey(at->name);
find = at_hash[at->hashkey % MAXATHASH];
while (find && at->hashkey != find->hashkey)
while (find && at->hashkey != find->hashkey) {
find = find->nexthash;
}
if (find && find == at) {
log_warning("attribute '%s' was registered more than once\n", at->name);
return;
} else {
}
else {
assert(!find || !"hashkey is already in use");
}
at->nexthash = at_hash[at->hashkey % MAXATHASH];
@ -180,7 +182,8 @@ static int a_unlink(attrib ** pa, attrib * a)
return 1;
while (*pnext && (*pnext)->type != a->type)
pnext = &(*pnext)->next;
} else {
}
else {
pnext = &(*pnexttype)->next;
}
while (*pnext && (*pnext)->type == a->type) {
@ -294,12 +297,14 @@ int a_read(struct storage *store, attrib ** attribs, void *owner)
if (at) {
reader = at->read;
na = a_new(at);
} else {
}
else {
const void * kv;
cb_find_prefix(&cb_deprecated, zText, strlen(zText) + 1, &kv, 1, 0);
if (kv) {
cb_get_kv(kv, &reader, sizeof(reader));
} else {
}
else {
fprintf(stderr, "attribute hash: %d (%s)\n", key, zText);
assert(at || !"attribute not registered");
}
@ -320,7 +325,8 @@ int a_read(struct storage *store, attrib ** attribs, void *owner)
break;
}
}
} else {
}
else {
assert(!"error: no registered callback can read attribute");
}
@ -342,7 +348,8 @@ void a_write(struct storage *store, const attrib * attribs, const void *owner)
WRITE_TOK(store, na->type->name);
na->type->write(na, owner, store);
na = na->next;
} else {
}
else {
na = na->nexttype;
}
}

View file

@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef ATTRIB_H
#define ATTRIB_H
#ifdef __cplusplus
extern "C" {
#endif

36
src/util/attrib.test.c Normal file
View file

@ -0,0 +1,36 @@
#include <platform.h>
#include "attrib.h"
#include <CuTest.h>
#include <tests.h>
static void test_attrib_new(CuTest * tc)
{
attrib_type at_test = { "test" };
attrib * a;
CuAssertPtrNotNull(tc, (a = a_new(&at_test)));
CuAssertPtrEquals(tc, 0, a->next);
CuAssertPtrEquals(tc, 0, a->nexttype);
CuAssertPtrEquals(tc, (void *)a->type, (void *)&at_test);
}
static void test_attrib_add(CuTest * tc)
{
attrib_type at_test = { "test" };
attrib *a, *alist = 0;
CuAssertPtrNotNull(tc, (a = a_new(&at_test)));
CuAssertPtrEquals(tc, a, a_add(&alist, a));
CuAssertPtrEquals(tc, a, alist);
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_test))));
CuAssertPtrEquals(tc, alist->next, a);
CuAssertPtrEquals(tc, alist->nexttype, a);
}
CuSuite *get_attrib_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_attrib_new);
return suite;
}