tests for entering buildings.

This commit is contained in:
Enno Rehling 2014-11-21 16:39:49 +01:00
parent 2fe40f00f5
commit 64a2073033
3 changed files with 36 additions and 2 deletions

View File

@ -1054,7 +1054,7 @@ int enter_ship(unit * u, struct order *ord, int id, int report)
return 0;
}
int enter_building(unit * u, order * ord, int id, int report)
int enter_building(unit * u, order * ord, int id, bool report)
{
region *r = u->region;
building *b;

View File

@ -51,7 +51,7 @@ extern "C" {
extern int dropouts[2];
extern int *age;
extern int enter_building(struct unit *u, struct order *ord, int id, int report);
extern int enter_building(struct unit *u, struct order *ord, int id, bool report);
extern int enter_ship(struct unit *u, struct order *ord, int id, int report);
extern void new_units(void);

View File

@ -117,6 +117,39 @@ static void test_contact(CuTest * tc)
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
}
static void test_enter_building(CuTest * tc)
{
unit *u;
region *r;
building *b;
race * rc;
test_cleanup();
test_create_world();
r = findregion(0, 0);
rc = rc_get_or_create("human");
u = test_create_unit(test_create_faction(rc), r);
b = test_create_building(r, bt_get_or_create("castle"));
rc->flags = RCF_WALK;
u->building = 0;
enter_building(u, NULL, b->no, false);
CuAssertPtrEquals(tc, b, u->building);
rc->flags = RCF_FLY;
u->building = 0;
enter_building(u, NULL, b->no, false);
CuAssertPtrEquals(tc, b, u->building);
rc->flags = RCF_SWIM;
u->building = 0;
enter_building(u, NULL, b->no, false);
CuAssertPtrEquals(tc, 0, u->building);
test_cleanup();
}
static void test_fishing_feeds_2_people(CuTest * tc)
{
const resource_type *rtype;
@ -445,5 +478,6 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_new_units);
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
SUITE_ADD_TEST(suite, test_contact);
SUITE_ADD_TEST(suite, test_enter_building);
return suite;
}