forked from github/server
backfill missing tests for herbsearch (alchemy).
This commit is contained in:
parent
eb26cc971f
commit
71dea1eca7
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
#include <platform.h>
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "move.h"
|
||||
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/messages.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#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;
|
||||
}
|
|
@ -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 */
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue