clean up some tests.

the test locale gets some extra strings.
test_create_world is bad, stop using it. unfinished.
This commit is contained in:
Enno Rehling 2017-03-10 21:29:37 +01:00
parent f54165d4f1
commit be0b54494e
16 changed files with 186 additions and 302 deletions

View File

@ -17,7 +17,7 @@ typedef struct alliance_fixture {
} alliance_fixture;
static void setup_alliance(alliance_fixture *fix) {
test_create_world();
test_setup();
fix->rc = test_create_race("human");
fix->f1 = test_create_faction(fix->rc);
fix->f2 = test_create_faction(fix->rc);
@ -49,7 +49,6 @@ static void test_alliance_join(CuTest *tc) {
alliance_fixture fix;
alliance * al;
test_setup();
setup_alliance(&fix);
CuAssertPtrEquals(tc, 0, fix.f1->alliance);
CuAssertPtrEquals(tc, 0, fix.f2->alliance);

View File

@ -40,18 +40,13 @@ static void test_building_set_owner(CuTest * tc)
struct building *bld;
struct unit *u1, *u2;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
btype = bt_find("castle");
f = test_create_faction(human);
r = findregion(0, 0);
f = test_create_faction(NULL);
r = test_create_region(0, 0, NULL);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
u1 = test_create_unit(f, r);
u_set_building(u1, bld);
CuAssertPtrEquals(tc, u1, building_owner(bld));
@ -70,22 +65,13 @@ static void test_buildingowner_goes_to_next_when_empty(CuTest * tc)
struct building *bld;
struct unit *u, *u2;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u = test_create_unit(f, r);
@ -105,22 +91,13 @@ static void test_buildingowner_goes_to_other_when_empty(CuTest * tc)
struct building *bld;
struct unit *u, *u2;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u2 = test_create_unit(f, r);
@ -141,23 +118,14 @@ static void test_buildingowner_goes_to_same_faction_when_empty(CuTest * tc)
struct building *bld;
struct unit *u, *u2, *u3;
struct faction *f1, *f2;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f1 = test_create_faction(human);
f2 = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u2 = test_create_unit(f2, r);
@ -181,22 +149,12 @@ static void test_buildingowner_goes_to_next_after_leave(CuTest * tc)
struct building *bld;
struct unit *u, *u2;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
f = test_create_faction(NULL);
r = test_create_plain(0, 0);
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u = test_create_unit(f, r);
@ -216,22 +174,13 @@ static void test_buildingowner_goes_to_other_after_leave(CuTest * tc)
struct building *bld;
struct unit *u, *u2;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u2 = test_create_unit(f, r);
@ -251,23 +200,14 @@ static void test_buildingowner_goes_to_same_faction_after_leave(CuTest * tc)
struct building *bld;
struct unit *u, *u2, *u3;
struct faction *f1, *f2;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f1 = test_create_faction(human);
f2 = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u2 = test_create_unit(f2, r);
@ -293,22 +233,13 @@ static void test_buildingowner_resets_when_empty(CuTest * tc)
struct building *bld;
struct unit *u;
struct faction *f;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u = test_create_unit(f, r);
@ -328,22 +259,13 @@ void test_buildingowner_goes_to_empty_unit_after_leave(CuTest * tc)
struct building *bld;
struct unit *u1, *u2, *u3;
struct faction *f1;
const struct building_type *btype;
const struct race *human;
test_cleanup();
test_create_world();
test_setup();
human = rc_find("human");
CuAssertPtrNotNull(tc, human);
f1 = test_create_faction(NULL);
r = test_create_plain(0, 0);
btype = bt_find("castle");
CuAssertPtrNotNull(tc, btype);
f1 = test_create_faction(human);
r = findregion(0, 0);
bld = test_create_building(r, btype);
bld = test_create_building(r, NULL);
CuAssertPtrNotNull(tc, bld);
u1 = test_create_unit(f1, r);
@ -394,16 +316,15 @@ static void test_buildingtype_exists(CuTest * tc)
building *b;
building_type *btype, *btype2;
test_cleanup();
test_create_world();
test_setup();
btype2 = bt_get_or_create("castle");
btype2 = test_create_buildingtype("castle");
assert(btype2);
btype = test_create_buildingtype("Hodor");
btype = test_create_buildingtype("lighhouse");
btype->maxsize = 10;
r = findregion(-1, 0);
b = new_building(btype, r, default_locale);
r = test_create_plain(0, 0);
b = test_create_building(r, btype);
CuAssertPtrNotNull(tc, b);
b->size = 10;

View File

@ -981,6 +981,7 @@ void init_resources(void)
rtype->flags |= RTF_ITEM | RTF_POOLED;
rtype->uchange = res_changeitem;
rtype->itype = it_get_or_create(rtype);
rtype->itype->weight = 1;
rtype->itype->give = give_money;
rtype = rt_get_or_create(resourcenames[R_HORSE]);

View File

@ -225,12 +225,12 @@ static void test_default_name(CuTest *tc) {
struct locale* lang;
char buf[32], compare[32];
test_cleanup();
test_create_world();
lang = get_or_create_locale("de");
test_setup();
lang = test_create_locale();
locale_setstring(lang, "unitdefault", "Zweiheit");
u = test_create_unit(test_create_faction(test_create_race("human")), findregion(0, 0));
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
default_name(u, buf, sizeof(buf));

View File

@ -34,15 +34,12 @@ static void test_new_building_can_be_renamed(CuTest * tc)
{
region *r;
building *b;
building_type *btype;
test_cleanup();
test_create_world();
test_setup();
test_create_locale();
r = test_create_region(0, 0, 0);
btype = bt_get_or_create("castle");
r = findregion(-1, 0);
b = new_building(btype, r, default_locale);
b = test_create_building(r, NULL);
CuAssertTrue(tc, !renamed_building(b));
}
@ -54,12 +51,10 @@ static void test_rename_building(CuTest * tc)
faction *f;
building_type *btype;
test_cleanup();
test_create_world();
test_setup();
btype = bt_get_or_create("castle");
r = findregion(-1, 0);
btype = test_create_buildingtype("castle");
r = test_create_region(0, 0, 0);
b = new_building(btype, r, default_locale);
f = test_create_faction(NULL);
u = test_create_unit(f, r);
@ -78,12 +73,10 @@ static void test_rename_building_twice(CuTest * tc)
building *b;
building_type *btype;
test_cleanup();
test_create_world();
test_setup();
btype = bt_get_or_create("castle");
r = findregion(-1, 0);
btype = test_create_buildingtype("castle");
r = test_create_region(0, 0, 0);
b = new_building(btype, r, default_locale);
f = test_create_faction(NULL);
u = test_create_unit(f, r);
@ -104,11 +97,10 @@ static void test_contact(CuTest * tc)
building_type *btype;
ally *al;
test_cleanup();
test_create_world();
test_setup();
btype = bt_get_or_create("castle");
r = findregion(0, 0);
btype = test_create_buildingtype("castle");
r = test_create_region(0, 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);
@ -134,13 +126,12 @@ static void test_enter_building(CuTest * tc)
building *b;
race * rc;
test_cleanup();
test_create_world();
test_setup();
r = findregion(0, 0);
r = test_create_region(0, 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"));
b = test_create_building(r, test_create_buildingtype("castle"));
rc->flags = RCF_WALK;
u->building = 0;
@ -489,7 +480,7 @@ static void setup_pay_cmd(struct pay_fixture *fix) {
f = test_create_faction(NULL);
r = findregion(0, 0);
assert(r && f);
btcastle = bt_get_or_create("castle");
btcastle = test_create_buildingtype("castle");
btcastle->taxes = level_taxes;
b = test_create_building(r, btcastle);
assert(b);
@ -530,7 +521,8 @@ static void test_pay_cmd_other_building(CuTest *tc) {
test_setup();
setup_pay_cmd(&fix);
f = fix.u1->faction;
b = test_create_building(fix.u1->region, bt_get_or_create("lighthouse"));
/* lighthouse is not in the test locale, so we're using castle */
b = test_create_building(fix.u1->region, test_create_buildingtype("lighthouse"));
config_set("rules.region_owners", "1");
config_set("rules.region_owner_pay_building", "lighthouse");
update_owners(b->region);
@ -569,14 +561,13 @@ static void test_new_units(CuTest *tc) {
region *r;
const struct locale *loc;
test_cleanup();
test_create_world();
test_setup();
f = test_create_faction(NULL);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
assert(r && f);
u = test_create_unit(f, r);
assert(u && !u->next);
loc = get_locale("de");
loc = test_create_locale();
assert(loc);
u->orders = create_order(K_MAKETEMP, loc, "hurr");
new_units();
@ -598,11 +589,10 @@ void setup_guard(guard_fixture *fix, bool armed) {
faction *f;
unit * u;
test_cleanup();
test_create_world();
test_setup();
f = test_create_faction(NULL);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
assert(r && f);
u = test_create_unit(f, r);
fset(u, UFL_GUARD);
@ -707,18 +697,18 @@ static void test_reserve_self(CuTest *tc) {
const resource_type *rtype;
const struct locale *loc;
test_cleanup();
test_create_world();
test_setup();
init_resources();
rtype = get_resourcetype(R_SILVER);
assert(rtype && rtype->itype);
f = test_create_faction(NULL);
r = findregion(0, 0);
r = test_create_region(0, 0, 0);
assert(r && f);
u1 = test_create_unit(f, r);
u2 = test_create_unit(f, r);
assert(u1 && u2);
loc = get_locale("de");
loc = test_create_locale();
assert(loc);
ord = create_order(K_RESERVE, loc, "200 SILBER");
assert(ord);
@ -741,7 +731,7 @@ static void statistic_test(CuTest *tc, int peasants, int luck, int maxp,
}
static void test_peasant_luck_effect(CuTest *tc) {
test_cleanup();
test_setup();
config_set("rules.peasants.peasantluck.factor", "10");
config_set("rules.peasants.growth.factor", "0.001");
@ -891,7 +881,7 @@ static void test_long_order_normal(CuTest *tc) {
unit *u;
order *ord;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fset(u, UFL_MOVED);
fset(u, UFL_LONGACTION);
@ -909,7 +899,7 @@ static void test_long_order_normal(CuTest *tc) {
static void test_long_order_none(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder);
@ -921,7 +911,7 @@ static void test_long_order_none(CuTest *tc) {
static void test_long_order_cast(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
@ -935,7 +925,7 @@ static void test_long_order_cast(CuTest *tc) {
static void test_long_order_buy_sell(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
@ -950,7 +940,7 @@ static void test_long_order_buy_sell(CuTest *tc) {
static void test_long_order_multi_long(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_MOVE, u->faction->locale, 0));
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, 0));
@ -964,7 +954,7 @@ static void test_long_order_multi_long(CuTest *tc) {
static void test_long_order_multi_buy(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
@ -978,7 +968,7 @@ static void test_long_order_multi_buy(CuTest *tc) {
static void test_long_order_multi_sell(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
@ -993,7 +983,7 @@ static void test_long_order_multi_sell(CuTest *tc) {
static void test_long_order_buy_cast(CuTest *tc) {
/* TODO: write more tests */
unit *u;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
@ -1006,7 +996,7 @@ static void test_long_order_buy_cast(CuTest *tc) {
static void test_long_order_hungry(CuTest *tc) {
unit *u;
test_cleanup();
test_setup();
config_set("hunger.long", "1");
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fset(u, UFL_HUNGER);
@ -1145,7 +1135,7 @@ static void test_ally_cmd(CuTest *tc) {
static void test_nmr_warnings(CuTest *tc) {
faction *f1, *f2;
test_cleanup();
test_setup();
config_set("nmr.timeout", "3");
f1 = test_create_faction(0);
f2 = test_create_faction(0);
@ -1166,7 +1156,7 @@ static void test_nmr_warnings(CuTest *tc) {
static unit * setup_mail_cmd(void) {
faction *f;
test_cleanup();
test_setup();
f = test_create_faction(0);
return test_create_unit(f, test_create_region(0, 0, 0));
}
@ -1283,7 +1273,7 @@ static void test_show_without_item(CuTest *tc)
item *i;
struct locale *loc;
test_cleanup();
test_setup();
loc = get_or_create_locale("de");
locale_setstring(loc, parameters[P_ANY], "ALLE");
@ -1326,7 +1316,7 @@ static void test_show_elf(CuTest *tc) {
struct locale *loc;
message * msg;
test_cleanup();
test_setup();
mt_register(mt_new_va("msg_event", "string:string", 0));
rc = test_create_race("elf");
@ -1362,7 +1352,7 @@ static void test_show_race(CuTest *tc) {
struct locale *loc;
message * msg;
test_cleanup();
test_setup();
mt_register(mt_new_va("msg_event", "string:string", 0));
test_create_race("human");
@ -1406,9 +1396,8 @@ static void test_immigration(CuTest * tc)
double inject[] = { 1 };
int (*old_wage)(const region*, const faction*, const race*, int) = global.functions.wage;
test_cleanup();
test_create_world();
r = findregion(0, 0);
test_setup();
r = test_create_region(0, 0, 0);
rsetpeasants(r, 0);
config_set("rules.economy.repopulate_maximum", 0);
@ -1442,9 +1431,9 @@ static void test_demon_hunger(CuTest * tc)
unit *u;
message* msg;
test_cleanup();
test_create_world();
r = findregion(0, 0);
test_setup();
init_resources();
r = test_create_region(0, 0, 0);
rc = test_create_race("demon");
f = test_create_faction(rc);
u = test_create_unit(f, r);

View File

@ -87,8 +87,8 @@ void test_pay_spell(CuTest * tc)
int level;
test_setup();
test_create_world();
r = findregion(0, 0);
init_resources();
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
u = test_create_unit(f, r);
CuAssertPtrNotNull(tc, u);
@ -121,8 +121,8 @@ void test_pay_spell_failure(CuTest * tc)
int level;
test_setup();
test_create_world();
r = findregion(0, 0);
init_resources();
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
u = test_create_unit(f, r);
CuAssertPtrNotNull(tc, u);
@ -159,8 +159,7 @@ void test_getspell_unit(CuTest * tc)
struct locale * lang;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, 0);
f = test_create_faction(0);
u = test_create_unit(f, r);
create_mage(u, M_GRAY);
@ -168,7 +167,7 @@ void test_getspell_unit(CuTest * tc)
set_level(u, SK_MAGIC, 1);
lang = get_locale("de");
lang = test_create_locale();
sp = create_spell("testspell", 0);
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
@ -188,8 +187,7 @@ void test_getspell_faction(CuTest * tc)
struct locale * lang;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);
@ -198,7 +196,7 @@ void test_getspell_faction(CuTest * tc)
set_level(u, SK_MAGIC, 1);
lang = get_locale("de");
lang = test_create_locale();
sp = create_spell("testspell", 0);
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
@ -220,8 +218,7 @@ void test_getspell_school(CuTest * tc)
struct spellbook * book;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);
@ -229,7 +226,7 @@ void test_getspell_school(CuTest * tc)
enable_skill(SK_MAGIC, true);
set_level(u, SK_MAGIC, 1);
lang = get_locale("de");
lang = test_create_locale();
sp = create_spell("testspell", 0);
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
@ -251,8 +248,7 @@ void test_set_pre_combatspell(CuTest * tc)
const int index = 0;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);
@ -284,8 +280,7 @@ void test_set_main_combatspell(CuTest * tc)
const int index = 1;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);
@ -317,8 +312,7 @@ void test_set_post_combatspell(CuTest * tc)
const int index = 2;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);
@ -349,8 +343,7 @@ void test_hasspell(CuTest * tc)
struct region * r;
test_setup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f = test_create_faction(0);
f->magiegebiet = M_TYBIED;
u = test_create_unit(f, r);

View File

@ -31,9 +31,7 @@ static void test_market_curse(CuTest * tc)
luxury_type *lux;
building_type *btype;
free_gamedata();
test_cleanup();
test_create_world();
test_setup();
htype = test_create_itemtype("herb");
htype->flags |= ITF_HERB;

View File

@ -158,16 +158,14 @@ static void test_ship_has_harbormaster_ally(CuTest * tc) {
}
static void test_walkingcapacity(CuTest *tc) {
region *r;
unit *u;
int cap;
const struct item_type *itype;
test_cleanup();
test_create_world();
test_setup();
init_resources();
r = findregion(0, 0);
u = test_create_unit(test_create_faction(0), r);
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
cap = u->number * (u->_race->capacity + u->_race->weight);
CuAssertIntEquals(tc, cap, walkingcapacity(u));
scale_number(u, 2);
@ -183,7 +181,7 @@ static void test_walkingcapacity(CuTest *tc) {
cap += itype->capacity;
CuAssertIntEquals(tc, cap, walkingcapacity(u));
itype = it_find("cart");
itype = test_create_itemtype("cart");
assert(itype);
i_change(&u->items, itype, 1);
CuAssertIntEquals(tc, cap, walkingcapacity(u));
@ -265,15 +263,15 @@ struct drift_fixture {
};
void setup_drift (struct drift_fixture *fix) {
test_cleanup();
test_setup();
config_set("rules.ship.storms", "0");
test_create_world();
test_create_shiptype("drifter");
fix->st_boat = st_get_or_create("drifter");
fix->st_boat->cabins = 20000;
fix->u = test_create_unit(fix->f = test_create_faction(0), fix->r=findregion(-1,0));
test_create_ocean(0, 0);
fix->u = test_create_unit(fix->f = test_create_faction(0), fix->r = test_create_ocean(-1, 0));
assert(fix->r && fix->u && fix->f);
set_level(fix->u, SK_SAILING, fix->st_boat->sumskill);
u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat));
@ -437,9 +435,11 @@ static void test_follow_ship_msg(CuTest * tc) {
void *p;
test_setup();
test_create_world();
init_resources();
f = test_create_faction(0);
r = findregion(0, 0);
r = test_create_plain(0, 0);
test_create_ocean(-1, 1); /* D_NORTHWEST */
stype = st_find("boat");
sh = test_create_ship(r, stype);
@ -452,7 +452,7 @@ static void test_follow_ship_msg(CuTest * tc) {
assert(ord);
unit_addorder(u, ord);
set_money(u, 999999);
set_money(u, 999999); /* overloaded ship */
a = a_add(&(r->attribs), a_new(&at_shiptrail));
td = (traveldir *)a->data.v;

View File

@ -116,7 +116,7 @@ static void test_piracy_cmd_errors(CuTest * tc) {
st_boat = st_get_or_create("boat");
r = test_create_race("pirates");
u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean")));
f->locale = get_or_create_locale("de");
f->locale = test_create_locale();
u->thisorder = create_order(K_PIRACY, f->locale, "");
assert(u && u->thisorder);

View File

@ -77,23 +77,12 @@ static void test_all_spy_message(CuTest *tc) {
test_cleanup();
}
static void setup_sabotage(void) {
struct locale *lang;
test_setup();
lang = get_or_create_locale("de");
locale_setstring(lang, parameters[P_SHIP], "SCHIFF");
locale_setstring(lang, parameters[P_ANY], "ALLE");
init_parameters(lang);
init_locales();
}
static void test_sabotage_self(CuTest *tc) {
unit *u;
region *r;
order *ord;
setup_sabotage();
test_setup();
r = test_create_region(0, 0, 0);
assert(r);
u = test_create_unit(test_create_faction(NULL), r);
@ -115,7 +104,7 @@ static void test_sabotage_other_fail(CuTest *tc) {
order *ord;
message *msg;
setup_sabotage();
test_setup();
r = test_create_region(0, 0, 0);
assert(r);
u = test_create_unit(test_create_faction(NULL), r);
@ -164,7 +153,7 @@ static void test_sabotage_other_success(CuTest *tc) {
region *r;
order *ord;
setup_sabotage();
test_setup();
r = test_create_region(0, 0, 0);
assert(r);
u = test_create_unit(test_create_faction(NULL), r);

View File

@ -63,8 +63,6 @@ static void setup_locale(struct locale *lang) {
if (!locale_getstring(lang, mkname("skill", skillnames[i])))
locale_setstring(lang, mkname("skill", skillnames[i]), skillnames[i]);
}
locale_setstring(lang, parameters[P_ANY], "ALLE");
init_parameters(lang);
init_skills(lang);
}
@ -76,10 +74,9 @@ static void setup_study(study_fixture *fix, skill_t sk) {
assert(fix);
test_setup();
config_set("study.random_progress", "0");
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, 0);
f = test_create_faction(0);
lang = get_or_create_locale(locale_name(f->locale));
f->locale = lang = test_create_locale();
setup_locale(lang);
fix->u = test_create_unit(f, r);
assert(fix->u);
@ -145,7 +142,7 @@ static void test_study_bug_2194(CuTest *tc) {
test_setup();
random_source_inject_constant(0.0);
init_resources();
loc = get_or_create_locale("de");
loc = test_create_locale();
setup_locale(loc);
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 2);
@ -219,7 +216,7 @@ static void test_academy_building(CuTest *tc) {
random_source_inject_constant(0.0);
init_resources();
loc = get_or_create_locale("de");
loc = test_create_locale();
setup_locale(loc);
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 2);

View File

@ -53,9 +53,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain)
r = new_region(x, y, findplane(x, y), 0);
}
if (!terrain) {
terrain_type *t = get_or_create_terrain("plain");
t->size = 1000;
fset(t, LAND_REGION|CAVALRY_REGION|FOREST_REGION|FLY_INTO|WALK_INTO);
terrain_type *t = test_create_terrain("plain", LAND_REGION | CAVALRY_REGION | FOREST_REGION | FLY_INTO | WALK_INTO);
terraform_region(r, t);
}
else {
@ -69,12 +67,37 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain)
return r;
}
region *test_create_ocean(int x, int y)
{
terrain_type *ter = test_create_terrain("ocean", SEA_REGION | FLY_INTO | SWIM_INTO);
return test_create_region(x, y, ter);
}
region *test_create_plain(int x, int y) {
return test_create_region(x, y, NULL);
}
struct locale * test_create_locale(void) {
struct locale *loc = get_locale("test");
if (!loc) {
int i;
loc = get_or_create_locale("test");
locale_setstring(loc, "factiondefault", parameters[P_FACTION]);
locale_setstring(loc, "unitdefault", parameters[P_UNIT]);
locale_setstring(loc, "money", "Silber");
locale_setstring(loc, "money_p", "Silber");
locale_setstring(loc, "cart", "Wagen");
locale_setstring(loc, "cart_p", "Wagen");
locale_setstring(loc, "horse", "Pferd");
locale_setstring(loc, "horse_p", "Pferde");
locale_setstring(loc, "iron", "Eisen");
locale_setstring(loc, "iron_p", "Eisen");
locale_setstring(loc, "stone", "Stein");
locale_setstring(loc, "stone_p", "Steine");
locale_setstring(loc, "plain", "Ebene");
locale_setstring(loc, "ocean", "Ozean");
locale_setstring(loc, "race::human", "Mensch");
locale_setstring(loc, "race::human_p", "Menschen");
for (i = 0; i < MAXSKILLS; ++i) {
if (!locale_getstring(loc, mkname("skill", skillnames[i])))
locale_setstring(loc, mkname("skill", skillnames[i]), skillnames[i]);
@ -314,7 +337,7 @@ void test_create_castorder(castorder *co, unit *u, int level, float force, int r
struct locale * lang;
order *ord;
lang = get_or_create_locale("en");
lang = test_create_locale();
create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), par);
free_order(ord);
}
@ -373,7 +396,7 @@ void test_create_world(void)
item_type * itype;
struct locale * loc;
loc = get_or_create_locale("de");
loc = test_create_locale();
locale_setstring(loc, parameters[P_SHIP], "SCHIFF");
locale_setstring(loc, parameters[P_ANY], "ALLE");
@ -381,7 +404,18 @@ void test_create_world(void)
locale_setstring(loc, "status_aggressive", "aggressiv");
locale_setstring(loc, keyword(K_RESERVE), "RESERVIEREN");
locale_setstring(loc, "money", "SILBER");
locale_setstring(loc, "money", "Silber");
locale_setstring(loc, "money_p", "Silber");
locale_setstring(loc, "cart", "Wagen");
locale_setstring(loc, "cart_p", "Wagen");
locale_setstring(loc, "horse", "Pferd");
locale_setstring(loc, "horse_p", "Pferde");
locale_setstring(loc, "iron", "Eisen");
locale_setstring(loc, "iron_p", "Eisen");
locale_setstring(loc, "stone", "Stein");
locale_setstring(loc, "stone_p", "Steine");
locale_setstring(loc, "plain", "Ebene");
locale_setstring(loc, "ocean", "Ozean");
init_resources();
get_resourcetype(R_SILVER)->itype->weight = 1;

View File

@ -43,8 +43,9 @@ extern "C" {
struct locale * test_create_locale(void);
struct terrain_type * test_create_terrain(const char * name, unsigned int flags);
struct race *test_create_race(const char *name);
struct region *test_create_region(int x, int y,
const struct terrain_type *terrain);
struct region *test_create_region(int x, int y, const struct terrain_type *terrain);
struct region *test_create_ocean(int x, int y);
struct region *test_create_plain(int x, int y);
struct faction *test_create_faction(const struct race *rc);
struct unit *test_create_unit(struct faction *f, struct region *r);
void test_create_world(void);

View File

@ -34,46 +34,9 @@ static void test_resources(CuTest *tc) {
CuAssertPtrEquals(tc, (void *)rtype, (void *)get_resourcetype(R_STONE));
}
static void test_recreate_world(CuTest * tc)
{
test_setup();
CuAssertPtrEquals(tc, 0, get_locale("de"));
CuAssertPtrEquals(tc, 0, (void *)rt_find("horse"));
test_create_world();
CuAssertPtrEquals(tc, default_locale, get_locale("de"));
CuAssertPtrNotNull(tc, default_locale);
CuAssertPtrNotNull(tc, findregion(0, 0));
CuAssertPtrNotNull(tc, get_terrain("plain"));
CuAssertPtrNotNull(tc, get_terrain("ocean"));
CuAssertPtrNotNull(tc, (void *)rt_find("horse"));
CuAssertPtrNotNull(tc, get_resourcetype(R_HORSE));
CuAssertPtrNotNull(tc, (void *)rt_find("money"));
CuAssertPtrNotNull(tc, get_resourcetype(R_LIFE));
CuAssertPtrNotNull(tc, get_resourcetype(R_SILVER));
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT));
test_cleanup();
CuAssertPtrEquals(tc, 0, get_locale("de"));
CuAssertPtrEquals(tc, 0, (void*)get_terrain("plain"));
CuAssertPtrEquals(tc, 0, (void*)get_terrain("ocean"));
CuAssertPtrEquals(tc, 0, (void*)rt_find("horse"));
CuAssertPtrEquals(tc, 0, (void*)get_resourcetype(R_HORSE));
CuAssertPtrEquals(tc, 0, (void *)rt_find("money"));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_LIFE));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_SILVER));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_AURA));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_PERMAURA));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_PEASANT));
CuAssertPtrEquals(tc, 0, findregion(0, 0));
}
CuSuite *get_tests_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_resources);
SUITE_ADD_TEST(suite, test_recreate_world);
return suite;
}

View File

@ -20,11 +20,10 @@ void test_upkeep_default(CuTest * tc)
const item_type *i_silver;
test_setup();
test_create_world();
init_resources();
i_silver = it_find("money");
assert(i_silver);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f1 = test_create_faction(test_create_race("human"));
f2 = test_create_faction(test_create_race("human"));
assert(f1 && f2);
@ -51,11 +50,11 @@ void test_upkeep_hunger_damage(CuTest * tc)
const item_type *i_silver;
test_setup();
test_create_world();
init_resources();
i_silver = it_find("money");
assert(i_silver);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f1 = test_create_faction(test_create_race("human"));
u1 = test_create_unit(f1, r);
assert(r && u1);
@ -76,11 +75,11 @@ void test_upkeep_from_pool(CuTest * tc)
const item_type *i_silver;
test_setup();
test_create_world();
init_resources();
i_silver = it_find("money");
assert(i_silver);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
assert(r);
u1 = test_create_unit(test_create_faction(test_create_race("human")), r);
assert(u1);
@ -110,11 +109,11 @@ void test_upkeep_from_friend(CuTest * tc)
const item_type *i_silver;
test_setup();
test_create_world();
init_resources();
i_silver = it_find("money");
assert(i_silver);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
f1 = test_create_faction(test_create_race("human"));
f2 = test_create_faction(test_create_race("human"));
assert(f1 && f2);
@ -144,11 +143,11 @@ void test_upkeep_free(CuTest * tc)
const item_type *i_silver;
test_setup();
test_create_world();
init_resources();
i_silver = it_find("money");
assert(i_silver);
r = findregion(0, 0);
r = test_create_region(0, 0, NULL);
u = test_create_unit(test_create_faction(test_create_race("human")), r);
assert(r && u);

View File

@ -23,7 +23,7 @@ static void test_move_to_vortex(CuTest *tc) {
struct locale *lang;
test_setup();
lang = get_or_create_locale("en");
lang = test_create_locale();
locale_setstring(lang, "vortex", "wirbel");
init_locale(lang);
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);