From 71dea1eca790b9a0cfafe2143f20474a95e3516e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 27 Aug 2015 13:19:58 +0200 Subject: [PATCH] backfill missing tests for herbsearch (alchemy). --- src/CMakeLists.txt | 1 + src/alchemy.h | 2 +- src/alchemy.test.c | 91 +++++++++++++++++++++++++++++++++++++++++++ src/kernel/messages.h | 2 +- src/kernel/unit.h | 4 +- src/test_eressea.c | 1 + 6 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 src/alchemy.test.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a67ad35b4..922417b03 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -175,6 +175,7 @@ target_link_libraries(eressea set(TESTS_SRC wormhole.test.c + alchemy.test.c test_eressea.c tests.c battle.test.c diff --git a/src/alchemy.h b/src/alchemy.h index ead8ab09e..79f771b45 100644 --- a/src/alchemy.h +++ b/src/alchemy.h @@ -56,7 +56,7 @@ extern "C" { MAX_POTIONS }; - extern void herbsearch(struct region *r, struct unit *u, int max); + void herbsearch(struct region *r, struct unit *u, int max); extern int use_potion(struct unit *u, const struct item_type *itype, int amount, struct order *); extern int use_potion_delayed(struct unit *u, const struct item_type *itype, diff --git a/src/alchemy.test.c b/src/alchemy.test.c new file mode 100644 index 000000000..16811725a --- /dev/null +++ b/src/alchemy.test.c @@ -0,0 +1,91 @@ +#include + +#include "alchemy.h" +#include "move.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include "tests.h" + +static void test_herbsearch(CuTest * tc) +{ + faction *f; + race *rc; + unit *u, *u2; + region *r; + const item_type *itype; + + test_cleanup(); + r = test_create_region(0, 0, 0); + rc = rc_get_or_create("dragon"); + rc->flags |= RCF_UNARMEDGUARD; + u2 = test_create_unit(test_create_faction(rc), r); + guard(u2, GUARD_PRODUCE); + + f = test_create_faction(0); + u = test_create_unit(f, r); + itype = test_create_itemtype("rosemary"); + + herbsearch(r, u, INT_MAX); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error59")); + free_messagelist(f->msgs); + f->msgs = 0; + + set_level(u, SK_HERBALISM, 1); + CuAssertPtrEquals(tc, u2, is_guarded(r, u, GUARD_PRODUCE)); + herbsearch(r, u, INT_MAX); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59")); + free_messagelist(f->msgs); + f->msgs = 0; + + guard(u2, GUARD_NONE); + CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE)); + CuAssertPtrEquals(tc, 0, (void *)rherbtype(r)); + herbsearch(r, u, INT_MAX); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59")); + free_messagelist(f->msgs); + f->msgs = 0; + + rsetherbtype(r, itype); + CuAssertPtrEquals(tc, (void *)itype, (void *)rherbtype(r)); + CuAssertIntEquals(tc, 0, rherbs(r)); + herbsearch(r, u, INT_MAX); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "researchherb_none")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59")); + free_messagelist(f->msgs); + f->msgs = 0; + + rsetherbs(r, 100); + CuAssertIntEquals(tc, 100, rherbs(r)); + herbsearch(r, u, INT_MAX); + CuAssertIntEquals(tc, 99, rherbs(r)); + CuAssertIntEquals(tc, 1, i_get(u->items, itype)); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "herbfound")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "researchherb_none")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59")); + free_messagelist(f->msgs); + f->msgs = 0; + + test_cleanup(); +} + +CuSuite *get_alchemy_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_herbsearch); + return suite; +} diff --git a/src/kernel/messages.h b/src/kernel/messages.h index 75d1f23b1..6891de586 100644 --- a/src/kernel/messages.h +++ b/src/kernel/messages.h @@ -37,7 +37,7 @@ extern "C" { struct mlist *begin, **end; } message_list; - extern void free_messagelist(message_list * msgs); + void free_messagelist(message_list * msgs); typedef struct msglevel { /* used to set specialized msg-levels */ diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 631809bf9..3a5261d94 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -164,8 +164,8 @@ extern "C" { int produceexp(struct unit *u, skill_t sk, int n); int SkillCap(skill_t sk); - extern void set_level(struct unit *u, skill_t id, int level); - extern int get_level(const struct unit *u, skill_t id); + void set_level(struct unit *u, skill_t id, int level); + int get_level(const struct unit *u, skill_t id); extern void transfermen(struct unit *u, struct unit *u2, int n); extern int eff_skill(const struct unit *u, skill_t sk, diff --git a/src/test_eressea.c b/src/test_eressea.c index cef5193cd..1ae1dfe85 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -67,6 +67,7 @@ int RunAllTests(void) RUN_TESTS(suite, equipment); RUN_TESTS(suite, item); RUN_TESTS(suite, magic); + RUN_TESTS(suite, alchemy); RUN_TESTS(suite, reports); RUN_TESTS(suite, save); RUN_TESTS(suite, ship);