tests for entering ships (but not yet full coverage)

This commit is contained in:
Enno Rehling 2014-11-21 17:13:45 +01:00
parent 64a2073033
commit 7d5109329f
3 changed files with 64 additions and 12 deletions

View File

@ -993,31 +993,35 @@ static bool CheckOverload(void)
return value;
}
int enter_ship(unit * u, struct order *ord, int id, int report)
int enter_ship(unit * u, struct order *ord, int id, bool report)
{
region *r = u->region;
ship *sh;
const race * rc = u_race(u);
/* Muss abgefangen werden, sonst koennten Schwimmer an
* Bord von Schiffen an Land gelangen. */
if (!fval(u_race(u), RCF_CANSAIL) || (!fval(u_race(u), RCF_WALK)
&& !fval(u_race(u), RCF_FLY))) {
if (!(rc->flags & (RCF_CANSAIL|RCF_WALK|RCF_FLY))) {
if (report) {
cmistake(u, ord, 233, MSG_MOVE);
}
return 0;
}
sh = findship(id);
if (sh == NULL || sh->region != r) {
if (report)
if (report) {
cmistake(u, ord, 20, MSG_MOVE);
}
return 0;
}
if (sh == u->ship) {
return 1;
}
if (!mayboard(u, sh)) {
if (report)
if (report) {
cmistake(u, ord, 34, MSG_MOVE);
}
return 0;
}
if (CheckOverload()) {

View File

@ -44,6 +44,9 @@ extern "C" {
void get_food(struct region * r);
int can_contact(const struct region *r, const struct unit *u, const struct unit *u2);
int enter_building(struct unit *u, struct order *ord, int id, bool report);
int enter_ship(struct unit *u, struct order *ord, int id, bool report);
/* eressea-specific. put somewhere else, please. */
void processorders(void);
extern struct attrib_type at_germs;
@ -51,8 +54,6 @@ extern "C" {
extern int dropouts[2];
extern int *age;
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);
extern void defaultorders(void);

View File

@ -134,18 +134,64 @@ static void test_enter_building(CuTest * tc)
rc->flags = RCF_WALK;
u->building = 0;
enter_building(u, NULL, b->no, false);
CuAssertIntEquals(tc, 1, 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);
CuAssertIntEquals(tc, 1, 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);
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
CuAssertPtrEquals(tc, 0, u->building);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
CuAssertPtrNotNull(tc, u->faction->msgs);
test_cleanup();
}
static void test_enter_ship(CuTest * tc)
{
unit *u;
region *r;
ship *sh;
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);
sh = test_create_ship(r, st_get_or_create("boat"));
rc->flags = RCF_WALK;
u->ship = 0;
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
CuAssertPtrEquals(tc, sh, u->ship);
rc->flags = RCF_FLY;
u->ship = 0;
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
CuAssertPtrEquals(tc, sh, u->ship);
rc->flags = RCF_CANSAIL;
u->ship = 0;
CuAssertIntEquals(tc, 1, enter_ship(u, NULL, sh->no, false));
CuAssertPtrEquals(tc, sh, u->ship);
rc->flags = RCF_SWIM;
u->ship = 0;
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
CuAssertPtrEquals(tc, 0, u->ship);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
CuAssertPtrNotNull(tc, u->faction->msgs);
test_cleanup();
}
@ -479,5 +525,6 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
SUITE_ADD_TEST(suite, test_contact);
SUITE_ADD_TEST(suite, test_enter_building);
SUITE_ADD_TEST(suite, test_enter_ship);
return suite;
}