From adfafd51a6e9e09fe2ea07339cd101ca11c7ed07 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 17 Sep 2016 12:34:02 +0200 Subject: [PATCH] test lighthouses --- src/CMakeLists.txt | 1 + src/lighthouse.c | 2 +- src/lighthouse.h | 3 ++ src/lighthouse.test.c | 95 +++++++++++++++++++++++++++++++++++++++++++ src/test_eressea.c | 1 + 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/lighthouse.test.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 11bd860ba..40be63190 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -211,6 +211,7 @@ set(TESTS_SRC keyword.test.c give.test.c laws.test.c + lighthouse.test.c magic.test.c market.test.c monsters.test.c diff --git a/src/lighthouse.c b/src/lighthouse.c index 441eb0458..58d522807 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -14,7 +14,7 @@ #include #include -static attrib_type at_lighthouse = { +const attrib_type at_lighthouse = { "lighthouse" /* Rest ist NULL; temporäres, nicht alterndes Attribut */ }; diff --git a/src/lighthouse.h b/src/lighthouse.h index b31c520cb..518b05b5a 100644 --- a/src/lighthouse.h +++ b/src/lighthouse.h @@ -27,6 +27,9 @@ extern "C" { struct faction; struct region; struct building; + struct attrib; + + extern const struct attrib_type at_lighthouse; /* leuchtturm */ bool check_leuchtturm(struct region *r, struct faction *f); void update_lighthouse(struct building *lh); diff --git a/src/lighthouse.test.c b/src/lighthouse.test.c new file mode 100644 index 000000000..193de58a6 --- /dev/null +++ b/src/lighthouse.test.c @@ -0,0 +1,95 @@ +#include + +#include "lighthouse.h" + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include "tests.h" + +static void test_lighthouse_range(CuTest * tc) +{ + faction *f; + unit *u; + region *r1, *r2; + building *b; + + test_setup(); + r1 = test_create_region(0, 0, 0); + r2 = test_create_region(1, 0, 0); + f = test_create_faction(0); + u = test_create_unit(f, r1); + b = test_create_building(r1, test_create_buildingtype("lighthouse")); + CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL)); + CuAssertIntEquals(tc, 0, lighthouse_range(b, f)); + b->size = 10; + CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL)); + u->building = b; + set_level(u, SK_PERCEPTION, 3); + CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL)); + b->flags |= BLD_MAINTAINED; + CuAssertIntEquals(tc, 1, lighthouse_range(b, NULL)); + set_level(u, SK_PERCEPTION, 6); + CuAssertIntEquals(tc, 2, lighthouse_range(b, NULL)); + b->size = 100; + CuAssertIntEquals(tc, 2, lighthouse_range(b, NULL)); + set_level(u, SK_PERCEPTION, 9); + CuAssertIntEquals(tc, 3, lighthouse_range(b, NULL)); + CuAssertIntEquals(tc, 3, lighthouse_range(b, f)); + CuAssertIntEquals(tc, 0, lighthouse_range(b, test_create_faction(0))); + test_cleanup(); +} + +static void test_lighthouse_update(CuTest * tc) +{ + region *r1, *r2, *r3; + building *b; + const struct terrain_type *t_ocean, *t_plain; + + test_setup(); + t_ocean = test_create_terrain("ocean", SEA_REGION); + t_plain = test_create_terrain("plain", LAND_REGION); + r1 = test_create_region(0, 0, t_plain); + r2 = test_create_region(1, 0, t_ocean); + r3 = test_create_region(2, 0, t_ocean); + b = test_create_building(r1, test_create_buildingtype("lighthouse")); + CuAssertIntEquals(tc, 0, r1->flags&RF_LIGHTHOUSE); + CuAssertPtrEquals(tc, NULL, r1->attribs); + CuAssertPtrEquals(tc, NULL, r2->attribs); + CuAssertPtrEquals(tc, NULL, r3->attribs); + + r1->flags = 0; + b->size = 1; + update_lighthouse(b); + CuAssertIntEquals(tc, RF_LIGHTHOUSE, r1->flags&RF_LIGHTHOUSE); + CuAssertPtrNotNull(tc, r2->attribs); + CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r2->attribs->type); + CuAssertPtrEquals(tc, NULL, r1->attribs); + CuAssertPtrEquals(tc, NULL, r3->attribs); + + a_removeall(&r2->attribs, NULL); + r1->flags = 0; + b->size = 10; + update_lighthouse(b); + CuAssertIntEquals(tc, RF_LIGHTHOUSE, r1->flags&RF_LIGHTHOUSE); + CuAssertPtrNotNull(tc, r2->attribs); + CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r2->attribs->type); + CuAssertPtrNotNull(tc, r3->attribs); + CuAssertPtrEquals(tc, (void *)&at_lighthouse, (void *)r3->attribs->type); + test_cleanup(); +} + +CuSuite *get_lighthouse_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_lighthouse_range); + SUITE_ADD_TEST(suite, test_lighthouse_update); + return suite; +} diff --git a/src/test_eressea.c b/src/test_eressea.c index 0f6fc3522..2511c5727 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -122,6 +122,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(flyingship); ADD_SUITE(give); ADD_SUITE(laws); + ADD_SUITE(lighthouse); ADD_SUITE(market); ADD_SUITE(monsters); ADD_SUITE(move);