forked from github/server
Add missing test coverage for update_guards. Fix the weapon:minskill default.
This commit is contained in:
parent
815cf3edbc
commit
ce3e9cd7d0
|
@ -226,7 +226,7 @@ int armedmen(const unit * u, bool siege_weapons)
|
||||||
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
const weapon_type *wtype = resource2weapon(itm->type->rtype);
|
||||||
if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE)))
|
if (wtype == NULL || (!siege_weapons && (wtype->flags & WTF_SIEGE)))
|
||||||
continue;
|
continue;
|
||||||
if (effskill(u, wtype->skill) >= 1)
|
if (effskill(u, wtype->skill) >= wtype->minskill)
|
||||||
n += itm->number;
|
n += itm->number;
|
||||||
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
/* if (effskill(u, wtype->skill) >= wtype->minskill) n += itm->number; */
|
||||||
if (n > u->number)
|
if (n > u->number)
|
||||||
|
|
|
@ -186,7 +186,7 @@ resource_type *rt_get_or_create(const char *name) {
|
||||||
return rtype;
|
return rtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
void it_register(item_type * itype)
|
static void it_register(item_type * itype)
|
||||||
{
|
{
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
const char * name = itype->rtype->_name;
|
const char * name = itype->rtype->_name;
|
||||||
|
@ -270,6 +270,7 @@ weapon_type *new_weapontype(item_type * itype,
|
||||||
{
|
{
|
||||||
weapon_type *wtype;
|
weapon_type *wtype;
|
||||||
|
|
||||||
|
assert(minskill > 0);
|
||||||
assert(resource2weapon(itype->rtype) == NULL);
|
assert(resource2weapon(itype->rtype) == NULL);
|
||||||
|
|
||||||
wtype = calloc(sizeof(weapon_type), 1);
|
wtype = calloc(sizeof(weapon_type), 1);
|
||||||
|
|
|
@ -229,8 +229,6 @@ extern "C" {
|
||||||
item_type *it_find(const char *name);
|
item_type *it_find(const char *name);
|
||||||
|
|
||||||
void it_set_appearance(item_type *itype, const char *appearance);
|
void it_set_appearance(item_type *itype, const char *appearance);
|
||||||
void it_register(item_type * it);
|
|
||||||
void wt_register(weapon_type * wt);
|
|
||||||
|
|
||||||
extern const item_type *resource2item(const resource_type * rtype);
|
extern const item_type *resource2item(const resource_type * rtype);
|
||||||
extern const resource_type *item2resource(const item_type * i);
|
extern const resource_type *item2resource(const item_type * i);
|
||||||
|
|
|
@ -119,7 +119,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct race {
|
typedef struct race {
|
||||||
struct param *parameters;
|
struct param *parameters;
|
||||||
const char *_name; /* neu: name[4]völker */
|
const char *_name;
|
||||||
float magres;
|
float magres;
|
||||||
float maxaura; /* Faktor auf Maximale Aura */
|
float maxaura; /* Faktor auf Maximale Aura */
|
||||||
float regaura; /* Faktor auf Regeneration */
|
float regaura; /* Faktor auf Regeneration */
|
||||||
|
|
|
@ -631,7 +631,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
||||||
xmlChar *propValue;
|
xmlChar *propValue;
|
||||||
int k;
|
int k;
|
||||||
skill_t sk;
|
skill_t sk;
|
||||||
int minskill = xml_ivalue(node, "minskill", 0);
|
int minskill = xml_ivalue(node, "minskill", 1);
|
||||||
int offmod = xml_ivalue(node, "offmod", 0);
|
int offmod = xml_ivalue(node, "offmod", 0);
|
||||||
int defmod = xml_ivalue(node, "defmod", 0);
|
int defmod = xml_ivalue(node, "defmod", 0);
|
||||||
int reload = xml_ivalue(node, "reload", 0);
|
int reload = xml_ivalue(node, "reload", 0);
|
||||||
|
|
256
src/laws.test.c
256
src/laws.test.c
|
@ -22,67 +22,67 @@
|
||||||
|
|
||||||
static void test_new_building_can_be_renamed(CuTest * tc)
|
static void test_new_building_can_be_renamed(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
building *b;
|
building *b;
|
||||||
building_type *btype;
|
building_type *btype;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
|
||||||
btype = bt_get_or_create("castle");
|
btype = bt_get_or_create("castle");
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
|
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale);
|
||||||
CuAssertTrue(tc, !renamed_building(b));
|
CuAssertTrue(tc, !renamed_building(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_rename_building(CuTest * tc)
|
static void test_rename_building(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
building *b;
|
building *b;
|
||||||
unit *u;
|
unit *u;
|
||||||
faction *f;
|
faction *f;
|
||||||
building_type *btype;
|
building_type *btype;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
|
||||||
btype = bt_get_or_create("castle");
|
btype = bt_get_or_create("castle");
|
||||||
|
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale);
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
u_set_building(u, b);
|
u_set_building(u, b);
|
||||||
|
|
||||||
rename_building(u, NULL, b, "Villa Nagel");
|
rename_building(u, NULL, b, "Villa Nagel");
|
||||||
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_rename_building_twice(CuTest * tc)
|
static void test_rename_building_twice(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
building *b;
|
building *b;
|
||||||
unit *u;
|
unit *u;
|
||||||
faction *f;
|
faction *f;
|
||||||
building_type *btype;
|
building_type *btype;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
|
||||||
btype = bt_get_or_create("castle");
|
btype = bt_get_or_create("castle");
|
||||||
|
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
b = new_building(btype, r, default_locale);
|
b = new_building(btype, r, default_locale);
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
u_set_building(u, b);
|
u_set_building(u, b);
|
||||||
|
|
||||||
rename_building(u, NULL, b, "Villa Nagel");
|
rename_building(u, NULL, b, "Villa Nagel");
|
||||||
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
||||||
|
|
||||||
rename_building(u, NULL, b, "Villa Kunterbunt");
|
rename_building(u, NULL, b, "Villa Kunterbunt");
|
||||||
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fishing_feeds_2_people(CuTest * tc)
|
static void test_fishing_feeds_2_people(CuTest * tc)
|
||||||
|
@ -97,7 +97,7 @@ static void test_fishing_feeds_2_people(CuTest * tc)
|
||||||
test_create_world();
|
test_create_world();
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
sh = new_ship(st_find("boat"), r, 0);
|
sh = new_ship(st_find("boat"), r, 0);
|
||||||
u_set_ship(u, sh);
|
u_set_ship(u, sh);
|
||||||
|
@ -122,7 +122,7 @@ static void test_fishing_feeds_2_people(CuTest * tc)
|
||||||
|
|
||||||
static int not_so_hungry(const unit * u)
|
static int not_so_hungry(const unit * u)
|
||||||
{
|
{
|
||||||
return 6 * u->number;
|
return 6 * u->number;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fishing_does_not_give_goblins_money(CuTest * tc)
|
static void test_fishing_does_not_give_goblins_money(CuTest * tc)
|
||||||
|
@ -139,7 +139,7 @@ static void test_fishing_does_not_give_goblins_money(CuTest * tc)
|
||||||
|
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
sh = new_ship(st_find("boat"), r, 0);
|
sh = new_ship(st_find("boat"), r, 0);
|
||||||
u_set_ship(u, sh);
|
u_set_ship(u, sh);
|
||||||
|
@ -165,7 +165,7 @@ static void test_fishing_gets_reset(CuTest * tc)
|
||||||
rtype = get_resourcetype(R_SILVER);
|
rtype = get_resourcetype(R_SILVER);
|
||||||
r = findregion(-1, 0);
|
r = findregion(-1, 0);
|
||||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
sh = new_ship(st_find("boat"), r, 0);
|
sh = new_ship(st_find("boat"), r, 0);
|
||||||
u_set_ship(u, sh);
|
u_set_ship(u, sh);
|
||||||
|
@ -183,33 +183,33 @@ static void test_fishing_gets_reset(CuTest * tc)
|
||||||
|
|
||||||
static void test_unit_limit(CuTest * tc)
|
static void test_unit_limit(CuTest * tc)
|
||||||
{
|
{
|
||||||
set_param(&global.parameters, "rules.limit.faction", "250");
|
set_param(&global.parameters, "rules.limit.faction", "250");
|
||||||
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.faction", "200");
|
set_param(&global.parameters, "rules.limit.faction", "200");
|
||||||
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.alliance", "250");
|
set_param(&global.parameters, "rules.limit.alliance", "250");
|
||||||
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int checkunitnumber(const faction * f, int add);
|
extern int checkunitnumber(const faction * f, int add);
|
||||||
static void test_cannot_create_unit_above_limit(CuTest * tc)
|
static void test_cannot_create_unit_above_limit(CuTest * tc)
|
||||||
{
|
{
|
||||||
faction *f;
|
faction *f;
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
set_param(&global.parameters, "rules.limit.faction", "4");
|
set_param(&global.parameters, "rules.limit.faction", "4");
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, checkunitnumber(f, 4));
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 4));
|
||||||
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
||||||
|
|
||||||
set_param(&global.parameters, "rules.limit.alliance", "3");
|
set_param(&global.parameters, "rules.limit.alliance", "3");
|
||||||
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
||||||
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_reserve_cmd(CuTest *tc) {
|
static void test_reserve_cmd(CuTest *tc) {
|
||||||
|
@ -225,7 +225,7 @@ static void test_reserve_cmd(CuTest *tc) {
|
||||||
|
|
||||||
rtype = get_resourcetype(R_SILVER);
|
rtype = get_resourcetype(R_SILVER);
|
||||||
assert(rtype && rtype->itype);
|
assert(rtype && rtype->itype);
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
r = findregion(0, 0);
|
r = findregion(0, 0);
|
||||||
assert(r && f);
|
assert(r && f);
|
||||||
u1 = test_create_unit(f, r);
|
u1 = test_create_unit(f, r);
|
||||||
|
@ -251,7 +251,7 @@ static void test_new_units(CuTest *tc) {
|
||||||
const struct locale *loc;
|
const struct locale *loc;
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
test_create_world();
|
test_create_world();
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
r = findregion(0, 0);
|
r = findregion(0, 0);
|
||||||
assert(r && f);
|
assert(r && f);
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
|
@ -266,6 +266,102 @@ static void test_new_units(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct guard_fixture {
|
||||||
|
unit * u;
|
||||||
|
} guard_fixture;
|
||||||
|
|
||||||
|
void setup_guard(guard_fixture *fix, bool armed) {
|
||||||
|
region *r;
|
||||||
|
faction *f;
|
||||||
|
unit * u;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
test_create_world();
|
||||||
|
|
||||||
|
f = test_create_faction(NULL);
|
||||||
|
r = findregion(0, 0);
|
||||||
|
assert(r && f);
|
||||||
|
u = test_create_unit(f, r);
|
||||||
|
fset(u, UFL_GUARD);
|
||||||
|
u->status = ST_FIGHT;
|
||||||
|
|
||||||
|
if (armed) {
|
||||||
|
item_type *itype;
|
||||||
|
weapon_type *wtype;
|
||||||
|
itype = it_get_or_create(rt_get_or_create("sword"));
|
||||||
|
wtype = new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2);
|
||||||
|
i_change(&u->items, itype, 1);
|
||||||
|
set_level(u, SK_MELEE, 2);
|
||||||
|
}
|
||||||
|
fix->u = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_update_guards(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
|
||||||
|
setup_guard(&fix, true);
|
||||||
|
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, fval(fix.u, UFL_GUARD));
|
||||||
|
freset(fix.u, UFL_GUARD);
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_newbie_cannot_guard(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
|
||||||
|
setup_guard(&fix, true);
|
||||||
|
set_param(&global.parameters, "NewbieImmunity", "4");
|
||||||
|
CuAssertTrue(tc, IsImmune(fix.u->faction));
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_unarmed_cannot_guard(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
|
||||||
|
setup_guard(&fix, false);
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_unarmed_races_can_guard(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
race * rc;
|
||||||
|
|
||||||
|
setup_guard(&fix, false);
|
||||||
|
rc = rc_get_or_create(fix.u->race_->_name);
|
||||||
|
rc->flags |= RCF_UNARMEDGUARD;
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_low_skill_cannot_guard(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
|
||||||
|
setup_guard(&fix, true);
|
||||||
|
set_level(fix.u, SK_MELEE, 1);
|
||||||
|
fix.u->status = ST_FLEE;
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_fleeing_cannot_guard(CuTest *tc) {
|
||||||
|
guard_fixture fix;
|
||||||
|
|
||||||
|
setup_guard(&fix, true);
|
||||||
|
fix.u->status = ST_FLEE;
|
||||||
|
update_guards();
|
||||||
|
CuAssertTrue(tc, !fval(fix.u, UFL_GUARD));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_reserve_self(CuTest *tc) {
|
static void test_reserve_self(CuTest *tc) {
|
||||||
unit *u1, *u2;
|
unit *u1, *u2;
|
||||||
faction *f;
|
faction *f;
|
||||||
|
@ -279,7 +375,7 @@ static void test_reserve_self(CuTest *tc) {
|
||||||
|
|
||||||
rtype = get_resourcetype(R_SILVER);
|
rtype = get_resourcetype(R_SILVER);
|
||||||
assert(rtype && rtype->itype);
|
assert(rtype && rtype->itype);
|
||||||
f = test_create_faction(rc_find("human"));
|
f = test_create_faction(NULL);
|
||||||
r = findregion(0, 0);
|
r = findregion(0, 0);
|
||||||
assert(r && f);
|
assert(r && f);
|
||||||
u1 = test_create_unit(f, r);
|
u1 = test_create_unit(f, r);
|
||||||
|
@ -299,17 +395,23 @@ static void test_reserve_self(CuTest *tc) {
|
||||||
|
|
||||||
CuSuite *get_laws_suite(void)
|
CuSuite *get_laws_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_new_building_can_be_renamed);
|
SUITE_ADD_TEST(suite, test_new_building_can_be_renamed);
|
||||||
SUITE_ADD_TEST(suite, test_rename_building);
|
SUITE_ADD_TEST(suite, test_rename_building);
|
||||||
SUITE_ADD_TEST(suite, test_rename_building_twice);
|
SUITE_ADD_TEST(suite, test_rename_building_twice);
|
||||||
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
||||||
SUITE_ADD_TEST(suite, test_fishing_does_not_give_goblins_money);
|
SUITE_ADD_TEST(suite, test_fishing_does_not_give_goblins_money);
|
||||||
SUITE_ADD_TEST(suite, test_fishing_gets_reset);
|
SUITE_ADD_TEST(suite, test_fishing_gets_reset);
|
||||||
SUITE_ADD_TEST(suite, test_unit_limit);
|
SUITE_ADD_TEST(suite, test_unit_limit);
|
||||||
SUITE_ADD_TEST(suite, test_reserve_self);
|
SUITE_ADD_TEST(suite, test_update_guards);
|
||||||
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
SUITE_ADD_TEST(suite, test_newbie_cannot_guard);
|
||||||
SUITE_ADD_TEST(suite, test_new_units);
|
SUITE_ADD_TEST(suite, test_unarmed_cannot_guard);
|
||||||
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
SUITE_ADD_TEST(suite, test_unarmed_races_can_guard);
|
||||||
return suite;
|
SUITE_ADD_TEST(suite, test_fleeing_cannot_guard);
|
||||||
|
SUITE_ADD_TEST(suite, test_low_skill_cannot_guard);
|
||||||
|
SUITE_ADD_TEST(suite, test_reserve_self);
|
||||||
|
SUITE_ADD_TEST(suite, test_reserve_cmd);
|
||||||
|
SUITE_ADD_TEST(suite, test_new_units);
|
||||||
|
SUITE_ADD_TEST(suite, test_cannot_create_unit_above_limit);
|
||||||
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue