2015-08-27 13:19:58 +02:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
#include "alchemy.h"
|
|
|
|
#include "move.h"
|
|
|
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
2015-09-12 23:41:37 +02:00
|
|
|
#include "guard.h"
|
|
|
|
|
2015-08-27 16:23:30 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
2015-08-27 13:19:58 +02:00
|
|
|
#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");
|
|
|
|
|
2015-08-27 14:46:08 +02:00
|
|
|
herbsearch(u, INT_MAX);
|
2015-08-27 13:19:58 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error59"));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(f);
|
2015-08-27 13:19:58 +02:00
|
|
|
|
|
|
|
set_level(u, SK_HERBALISM, 1);
|
|
|
|
CuAssertPtrEquals(tc, u2, is_guarded(r, u, GUARD_PRODUCE));
|
2015-08-27 14:46:08 +02:00
|
|
|
herbsearch(u, INT_MAX);
|
2015-08-27 13:19:58 +02:00
|
|
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
|
|
|
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(f);
|
2015-08-27 13:19:58 +02:00
|
|
|
|
|
|
|
guard(u2, GUARD_NONE);
|
|
|
|
CuAssertPtrEquals(tc, 0, is_guarded(r, u, GUARD_PRODUCE));
|
|
|
|
CuAssertPtrEquals(tc, 0, (void *)rherbtype(r));
|
2015-08-27 14:46:08 +02:00
|
|
|
herbsearch(u, INT_MAX);
|
2015-08-27 13:19:58 +02:00
|
|
|
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"));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(f);
|
2015-08-27 13:19:58 +02:00
|
|
|
|
|
|
|
rsetherbtype(r, itype);
|
|
|
|
CuAssertPtrEquals(tc, (void *)itype, (void *)rherbtype(r));
|
|
|
|
CuAssertIntEquals(tc, 0, rherbs(r));
|
2015-08-27 14:46:08 +02:00
|
|
|
herbsearch(u, INT_MAX);
|
2015-08-27 13:19:58 +02:00
|
|
|
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"));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(f);
|
2015-08-27 13:19:58 +02:00
|
|
|
|
|
|
|
rsetherbs(r, 100);
|
|
|
|
CuAssertIntEquals(tc, 100, rherbs(r));
|
2015-08-27 14:46:08 +02:00
|
|
|
herbsearch(u, INT_MAX);
|
2015-08-27 13:19:58 +02:00
|
|
|
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"));
|
2015-10-12 13:27:39 +02:00
|
|
|
test_clear_messages(f);
|
2015-08-27 13:19:58 +02:00
|
|
|
|
|
|
|
test_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
CuSuite *get_alchemy_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_herbsearch);
|
|
|
|
return suite;
|
|
|
|
}
|