add missing tests for contacting during a siege.

This commit is contained in:
Enno Rehling 2014-10-30 07:50:01 +01:00
parent 526c561b90
commit aa4a93435e
1 changed files with 34 additions and 1 deletions

View File

@ -2,6 +2,7 @@
#include <kernel/types.h> #include <kernel/types.h>
#include "laws.h" #include "laws.h"
#include <kernel/ally.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/faction.h> #include <kernel/faction.h>
@ -63,9 +64,9 @@ static void test_rename_building(CuTest * tc)
static void test_rename_building_twice(CuTest * tc) static void test_rename_building_twice(CuTest * tc)
{ {
region *r; region *r;
building *b;
unit *u; unit *u;
faction *f; faction *f;
building *b;
building_type *btype; building_type *btype;
test_cleanup(); test_cleanup();
@ -86,6 +87,37 @@ static void test_rename_building_twice(CuTest * tc)
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name); CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
} }
static void test_contact(CuTest * tc)
{
region *r;
unit *u1, *u2, *u3;
building *b;
building_type *btype;
test_cleanup();
test_create_world();
btype = bt_get_or_create("castle");
r = findregion(0, 0);
b = new_building(btype, r, default_locale);
u1 = test_create_unit(test_create_faction(0), r);
u2 = test_create_unit(test_create_faction(0), r);
u3 = test_create_unit(test_create_faction(0), r);
set_level(u3, SK_PERCEPTION, 2);
usetsiege(u3, b);
b->besieged = 1;
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
u_set_building(u1, b);
CuAssertIntEquals(tc, 0, can_contact(r, u1, u2));
u1->faction->allies = calloc(1, sizeof(ally));
u1->faction->allies->faction = u2->faction;
u1->faction->allies->status = HELP_ALL;
CuAssertIntEquals(tc, HELP_GIVE, can_contact(r, u1, u2));
u_set_building(u2, b);
CuAssertIntEquals(tc, 1, can_contact(r, u1, u2));
}
static void test_fishing_feeds_2_people(CuTest * tc) static void test_fishing_feeds_2_people(CuTest * tc)
{ {
const resource_type *rtype; const resource_type *rtype;
@ -413,5 +445,6 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_reserve_cmd); SUITE_ADD_TEST(suite, test_reserve_cmd);
SUITE_ADD_TEST(suite, test_new_units); SUITE_ADD_TEST(suite, test_new_units);
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit); SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
SUITE_ADD_TEST(suite, test_contact);
return suite; return suite;
} }