From 483a2ba3de4ea54a11d35de9143a7d50e69022f6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 31 Oct 2014 19:15:26 +0100 Subject: [PATCH] add missing tests for groups. --- src/kernel/CMakeLists.txt | 1 + src/kernel/group.h | 4 ---- src/kernel/group.test.c | 45 +++++++++++++++++++++++++++++++++++++++ src/test_eressea.c | 1 + 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/kernel/group.test.c diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 9566317e7..a1ea20a64 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -3,6 +3,7 @@ project(kernel C) SET(_TEST_FILES build.test.c config.test.c +group.test.c faction.test.c unit.test.c save.test.c diff --git a/src/kernel/group.h b/src/kernel/group.h index ea312542c..076761d98 100755 --- a/src/kernel/group.h +++ b/src/kernel/group.h @@ -22,9 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif -/* bitfield value for group::flags */ -#define GFL_ALIVE 0x01 /* There is at least one struct unit in the group */ - struct gamedata; typedef struct group { @@ -34,7 +31,6 @@ extern "C" { struct attrib *attribs; char *name; struct ally *allies; - int flags; int gid; int members; } group; diff --git a/src/kernel/group.test.c b/src/kernel/group.test.c new file mode 100644 index 000000000..c1bd01d59 --- /dev/null +++ b/src/kernel/group.test.c @@ -0,0 +1,45 @@ +#include +#include "types.h" +#include "group.h" +#include "faction.h" +#include "unit.h" +#include "region.h" + +#include +#include +#include + +static void test_group(CuTest * tc) +{ + unit *u; + region *r; + faction *f; + group *g; + + test_cleanup(); + test_create_world(); + r = findregion(0, 0); + f = test_create_faction(0); + assert(r && f); + u = test_create_unit(f, r); + assert(u); + CuAssertTrue(tc, join_group(u, "hodor")); + CuAssertPtrNotNull(tc, (g = get_group(u))); + CuAssertStrEquals(tc, "hodor", g->name); + CuAssertIntEquals(tc, 1, g->members); + set_group(u, 0); + CuAssertIntEquals(tc, 0, g->members); + CuAssertPtrEquals(tc, 0, get_group(u)); + set_group(u, g); + CuAssertIntEquals(tc, 1, g->members); + CuAssertPtrEquals(tc, g, get_group(u)); + test_cleanup(); +} + +CuSuite *get_group_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_group); + return suite; +} + diff --git a/src/test_eressea.c b/src/test_eressea.c index 6fa8767cb..17958c7b2 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -40,6 +40,7 @@ int RunAllTests(void) /* kernel */ ADD_TESTS(suite, unit); ADD_TESTS(suite, faction); + ADD_TESTS(suite, group); ADD_TESTS(suite, build); ADD_TESTS(suite, pool); ADD_TESTS(suite, curse);