From c0acfddb71de01cb23ebf477837978c4e7ab4462 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Apr 2016 14:26:10 +0200 Subject: [PATCH] test some simple facts about planes --- src/kernel/CMakeLists.txt | 1 + src/kernel/pathfinder.c | 2 ++ src/kernel/pathfinder.h | 5 --- src/kernel/plane.h | 1 - src/kernel/plane.test.c | 67 +++++++++++++++++++++++++++++++++++++++ src/test_eressea.c | 1 + 6 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/kernel/plane.test.c diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index f40d2acbb..2bd771b67 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -14,6 +14,7 @@ group.test.c item.test.c messages.test.c order.test.c +plane.test.c pool.test.c race.test.c save.test.c diff --git a/src/kernel/pathfinder.c b/src/kernel/pathfinder.c index 683da5699..8ae9bf128 100644 --- a/src/kernel/pathfinder.c +++ b/src/kernel/pathfinder.c @@ -28,6 +28,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#define MAXDEPTH 1024 + bool allowed_swim(const region * src, const region * r) { if (fval(r->terrain, SWIM_INTO)) diff --git a/src/kernel/pathfinder.h b/src/kernel/pathfinder.h index b7ab0f779..81692e835 100644 --- a/src/kernel/pathfinder.h +++ b/src/kernel/pathfinder.h @@ -22,11 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif -#define MAXDEPTH 1024 - - extern int search[MAXDEPTH][2]; - extern int search_len; - extern struct region **path_find(struct region *start, const struct region *target, int maxlen, bool(*allowed) (const struct region *, const struct region *)); diff --git a/src/kernel/plane.h b/src/kernel/plane.h index 926ffb4e2..051c05b69 100644 --- a/src/kernel/plane.h +++ b/src/kernel/plane.h @@ -60,7 +60,6 @@ extern "C" { struct plane *getplane(const struct region *r); struct plane *findplane(int x, int y); - void init_planes(void); int getplaneid(const struct region *r); struct plane *getplanebyid(int id); int plane_center_x(const struct plane *pl); diff --git a/src/kernel/plane.test.c b/src/kernel/plane.test.c new file mode 100644 index 000000000..a479a34be --- /dev/null +++ b/src/kernel/plane.test.c @@ -0,0 +1,67 @@ +#include +#include +#include "plane.h" +#include "faction.h" +#include +#include + +static void test_plane(CuTest *tc) { + struct region *r; + plane *pl; + + test_cleanup(); + r = test_create_region(0, 0, 0); + CuAssertPtrEquals(tc, 0, findplane(0, 0)); + CuAssertPtrEquals(tc, 0, getplane(r)); + CuAssertIntEquals(tc, 0, getplaneid(r)); + CuAssertPtrEquals(tc, 0, getplanebyid(0)); + CuAssertIntEquals(tc, 0, plane_center_x(0)); + CuAssertIntEquals(tc, 0, plane_center_y(0)); + CuAssertIntEquals(tc, 0, plane_width(0)); + CuAssertIntEquals(tc, 0, plane_height(0)); + CuAssertPtrEquals(tc, 0, get_homeplane()); + + pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15); + r = test_create_region(4, 40, 0); + CuAssertIntEquals(tc, 15, pl->flags); + CuAssertIntEquals(tc, 4, pl->minx); + CuAssertIntEquals(tc, 8, pl->maxx); + CuAssertIntEquals(tc, 40, pl->miny); + CuAssertIntEquals(tc, 80, pl->maxy); + CuAssertPtrEquals(tc, 0, pl->attribs); + CuAssertStrEquals(tc, "Hell", pl->name); + CuAssertPtrEquals(tc, pl, findplane(4, 40)); + CuAssertPtrEquals(tc, pl, getplane(r)); + CuAssertPtrEquals(tc, pl, getplanebyid(1)); + CuAssertIntEquals(tc, 1, getplaneid(r)); + CuAssertIntEquals(tc, 6, plane_center_x(pl)); + CuAssertIntEquals(tc, 60, plane_center_y(pl)); + CuAssertIntEquals(tc, 5, plane_width(pl)); + CuAssertIntEquals(tc, 41, plane_height(pl)); +} + +static void test_origin(CuTest *tc) { + struct faction *f; + int x, y; + + test_cleanup(); + f = test_create_faction(0); + x = 0; + y = 0; + adjust_coordinates(f, &x, &y, 0); + CuAssertIntEquals(tc, 0, x); + CuAssertIntEquals(tc, 0, y); + faction_setorigin(f, 0, 10, 20); + adjust_coordinates(f, &x, &y, 0); + CuAssertIntEquals(tc, -10, x); + CuAssertIntEquals(tc, -20, y); + test_cleanup(); +} + +CuSuite *get_plane_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_plane); + SUITE_ADD_TEST(suite, test_origin); + return suite; +} diff --git a/src/test_eressea.c b/src/test_eressea.c index 23cfdb203..4f7ec1359 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -87,6 +87,7 @@ int RunAllTests(int argc, char *argv[]) /* kernel */ ADD_SUITE(alliance); ADD_SUITE(command); + ADD_SUITE(plane); ADD_SUITE(unit); ADD_SUITE(faction); ADD_SUITE(group);