From be0b54494ee2cf9532175655c09c6636aca2659a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 10 Mar 2017 21:29:37 +0100 Subject: [PATCH 1/5] clean up some tests. the test locale gets some extra strings. test_create_world is bad, stop using it. unfinished. --- src/kernel/alliance.test.c | 3 +- src/kernel/building.test.c | 165 ++++++++++--------------------------- src/kernel/item.c | 1 + src/kernel/unit.test.c | 8 +- src/laws.test.c | 107 +++++++++++------------- src/magic.test.c | 35 ++++---- src/market.test.c | 4 +- src/move.test.c | 24 +++--- src/piracy.test.c | 2 +- src/spy.test.c | 17 +--- src/study.test.c | 11 +-- src/tests.c | 46 +++++++++-- src/tests.h | 5 +- src/tests.test.c | 37 --------- src/upkeep.test.c | 21 +++-- src/vortex.test.c | 2 +- 16 files changed, 186 insertions(+), 302 deletions(-) diff --git a/src/kernel/alliance.test.c b/src/kernel/alliance.test.c index c0ec03fbc..f63767672 100644 --- a/src/kernel/alliance.test.c +++ b/src/kernel/alliance.test.c @@ -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); diff --git a/src/kernel/building.test.c b/src/kernel/building.test.c index 2819d4a16..3f415a913 100644 --- a/src/kernel/building.test.c +++ b/src/kernel/building.test.c @@ -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; diff --git a/src/kernel/item.c b/src/kernel/item.c index 48ea7a690..605511005 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -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]); diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index 7c7bb087b..e1654b821 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -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)); diff --git a/src/laws.test.c b/src/laws.test.c index c27651d83..672105e08 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -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); diff --git a/src/magic.test.c b/src/magic.test.c index a5a842172..a3a199e42 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -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); diff --git a/src/market.test.c b/src/market.test.c index b4d5f05f5..b70288e90 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -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; diff --git a/src/move.test.c b/src/move.test.c index c444fe4a8..bb3b9d88d 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -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; diff --git a/src/piracy.test.c b/src/piracy.test.c index d690776f1..40e66af18 100644 --- a/src/piracy.test.c +++ b/src/piracy.test.c @@ -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); diff --git a/src/spy.test.c b/src/spy.test.c index 0dfaada7a..190cb09a5 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -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); diff --git a/src/study.test.c b/src/study.test.c index 3b411c7df..74104704b 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -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); diff --git a/src/tests.c b/src/tests.c index c448a27ae..faa8f6e2e 100644 --- a/src/tests.c +++ b/src/tests.c @@ -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; diff --git a/src/tests.h b/src/tests.h index c99147e6a..669318d99 100644 --- a/src/tests.h +++ b/src/tests.h @@ -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); diff --git a/src/tests.test.c b/src/tests.test.c index 9dd47e4d1..880956e8b 100644 --- a/src/tests.test.c +++ b/src/tests.test.c @@ -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; } diff --git a/src/upkeep.test.c b/src/upkeep.test.c index 2a91a0df1..bc53d5bbc 100644 --- a/src/upkeep.test.c +++ b/src/upkeep.test.c @@ -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); diff --git a/src/vortex.test.c b/src/vortex.test.c index 21ea6596c..b4940b6bc 100644 --- a/src/vortex.test.c +++ b/src/vortex.test.c @@ -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); From fe95ddafa112f5cb85bfa81decdf51362e38aa2e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 10 Mar 2017 21:43:36 +0100 Subject: [PATCH 2/5] reduce "translation not found" warnings in tests. --- src/laws.test.c | 29 ++++++++++++++--------------- src/move.test.c | 4 ++-- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 672105e08..0f61c7613 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -52,7 +52,7 @@ static void test_rename_building(CuTest * tc) building_type *btype; test_setup(); - + test_create_locale(); btype = test_create_buildingtype("castle"); r = test_create_region(0, 0, 0); b = new_building(btype, r, default_locale); @@ -74,7 +74,7 @@ static void test_rename_building_twice(CuTest * tc) building_type *btype; test_setup(); - + test_create_locale(); btype = test_create_buildingtype("castle"); r = test_create_region(0, 0, 0); b = new_building(btype, r, default_locale); @@ -98,7 +98,7 @@ static void test_contact(CuTest * tc) ally *al; test_setup(); - + test_create_locale(); btype = test_create_buildingtype("castle"); r = test_create_region(0, 0, 0); b = new_building(btype, r, default_locale); @@ -127,9 +127,9 @@ static void test_enter_building(CuTest * tc) race * rc; test_setup(); - + test_create_locale(); r = test_create_region(0, 0, 0); - rc = rc_get_or_create("human"); + rc = test_create_race("human"); u = test_create_unit(test_create_faction(rc), r); b = test_create_building(r, test_create_buildingtype("castle")); @@ -1270,7 +1270,6 @@ static void test_show_without_item(CuTest *tc) unit *u; order *ord; item_type *itype; - item *i; struct locale *loc; test_setup(); @@ -1283,26 +1282,26 @@ static void test_show_without_item(CuTest *tc) f = test_create_faction(test_create_race("human")); u = test_create_unit(f, r); + itype = it_get_or_create(rt_get_or_create("testitem")); + ord = create_order(K_RESHOW, f->locale, "testname"); - itype = it_get_or_create(rt_get_or_create("testitem")); - i = i_new(itype, 1); - reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(f->msgs, "error21") != NULL); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error21")); test_clear_messages(f); locale_setstring(loc, "testitem", "testname"); locale_setstring(loc, "iteminfo::testitem", "testdescription"); + reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(f->msgs, "error21") == NULL); - CuAssertTrue(tc, test_find_messagetype(f->msgs, "error36") != NULL); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21")); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36")); test_clear_messages(f); - i_add(&(u->items), i); + i_add(&(u->items), i_new(itype, 1)); reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(f->msgs, "error21") == NULL); - CuAssertTrue(tc, test_find_messagetype(f->msgs, "error36") == NULL); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21")); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36")); test_clear_messages(f); free_order(ord); diff --git a/src/move.test.c b/src/move.test.c index bb3b9d88d..ab30300e8 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -264,10 +264,10 @@ struct drift_fixture { void setup_drift (struct drift_fixture *fix) { test_setup(); + test_create_locale(); config_set("rules.ship.storms", "0"); - test_create_shiptype("drifter"); - fix->st_boat = st_get_or_create("drifter"); + fix->st_boat = test_create_shiptype("boat"); fix->st_boat->cabins = 20000; test_create_ocean(0, 0); From 98a48edb9ad40efe9b333d977a17f8a35a565813 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Mar 2017 12:25:49 +0100 Subject: [PATCH 3/5] I've got a 64-bit CMake on Windows now. --- vs2015-build.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vs2015-build.bat b/vs2015-build.bat index 6c39659d1..262d498bf 100644 --- a/vs2015-build.bat +++ b/vs2015-build.bat @@ -9,5 +9,5 @@ IF exist build-vs%VSVERSION% goto HAVEDIR mkdir build-vs%VSVERSION% :HAVEDIR cd build-vs%VSVERSION% -"%ProgramFiles(x86)%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. +"%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. PAUSE From 41c679396449b09be1da65421f94326ff5fb0b4b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Mar 2017 12:57:02 +0100 Subject: [PATCH 4/5] matching test_setup and test_cleanup calls. --- src/laws.test.c | 38 ++++++++++++++++++++++++++------------ src/market.test.c | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/laws.test.c b/src/laws.test.c index 0f61c7613..937754988 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -41,6 +41,7 @@ static void test_new_building_can_be_renamed(CuTest * tc) b = test_create_building(r, NULL); CuAssertTrue(tc, !renamed_building(b)); + test_cleanup(); } static void test_rename_building(CuTest * tc) @@ -63,6 +64,7 @@ static void test_rename_building(CuTest * tc) rename_building(u, NULL, b, "Villa Nagel"); CuAssertStrEquals(tc, "Villa Nagel", b->name); CuAssertTrue(tc, renamed_building(b)); + test_cleanup(); } static void test_rename_building_twice(CuTest * tc) @@ -87,6 +89,7 @@ static void test_rename_building_twice(CuTest * tc) rename_building(u, NULL, b, "Villa Kunterbunt"); CuAssertStrEquals(tc, "Villa Kunterbunt", b->name); + test_cleanup(); } static void test_contact(CuTest * tc) @@ -117,6 +120,7 @@ static void test_contact(CuTest * tc) CuAssertIntEquals(tc, HELP_GIVE, can_contact(r, u1, u2)); u_set_building(u2, b); CuAssertIntEquals(tc, 1, can_contact(r, u1, u2)); + test_cleanup(); } static void test_enter_building(CuTest * tc) @@ -229,6 +233,7 @@ static void test_display_cmd(CuTest *tc) { } static void test_rule_force_leave(CuTest *tc) { + test_setup(); config_set("rules.owners.force_leave", "0"); CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_ALL)); CuAssertIntEquals(tc, false, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); @@ -241,6 +246,7 @@ static void test_rule_force_leave(CuTest *tc) { config_set("rules.owners.force_leave", "3"); CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_ALL)); CuAssertIntEquals(tc, true, rule_force_leave(FORCE_LEAVE_POSTCOMBAT)); + test_cleanup(); } static void test_force_leave_buildings(CuTest *tc) { @@ -249,7 +255,8 @@ static void test_force_leave_buildings(CuTest *tc) { unit *u1, *u2, *u3; building * b; message *msg; - test_cleanup(); + + test_setup(); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(u1->faction, r); @@ -279,7 +286,8 @@ static void test_force_leave_ships(CuTest *tc) { unit *u1, *u2; ship *sh; message *msg; - test_cleanup(); + + test_setup(); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); @@ -298,7 +306,8 @@ static void test_force_leave_ships_on_ocean(CuTest *tc) { region *r; unit *u1, *u2; ship *sh; - test_cleanup(); + + test_setup(); r = test_create_region(0, 0, test_create_terrain("ocean", SEA_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); @@ -319,7 +328,7 @@ static void test_fishing_feeds_2_people(CuTest * tc) unit *u; ship *sh; - test_cleanup(); + test_setup(); test_create_world(); r = findregion(-1, 0); CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */ @@ -344,6 +353,7 @@ static void test_fishing_feeds_2_people(CuTest * tc) sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype)); + test_cleanup(); } static void test_fishing_does_not_give_goblins_money(CuTest * tc) @@ -354,7 +364,7 @@ static void test_fishing_does_not_give_goblins_money(CuTest * tc) unit *u; ship *sh; - test_cleanup(); + test_setup(); test_create_world(); rtype = get_resourcetype(R_SILVER); @@ -370,6 +380,7 @@ static void test_fishing_does_not_give_goblins_money(CuTest * tc) sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype)); + test_cleanup(); } static void test_fishing_gets_reset(CuTest * tc) @@ -380,7 +391,7 @@ static void test_fishing_gets_reset(CuTest * tc) unit *u; ship *sh; - test_cleanup(); + test_setup(); test_create_world(); rtype = get_resourcetype(R_SILVER); r = findregion(-1, 0); @@ -399,10 +410,12 @@ static void test_fishing_gets_reset(CuTest * tc) scale_number(u, 1); get_food(r); CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype)); + test_cleanup(); } static void test_unit_limit(CuTest * tc) { + test_setup(); config_set("rules.limit.faction", "250"); CuAssertIntEquals(tc, 250, rule_faction_limit()); @@ -411,7 +424,7 @@ static void test_unit_limit(CuTest * tc) config_set("rules.limit.alliance", "250"); CuAssertIntEquals(tc, 250, rule_alliance_limit()); - + test_cleanup(); } extern int checkunitnumber(const faction * f, int add); @@ -419,7 +432,7 @@ static void test_cannot_create_unit_above_limit(CuTest * tc) { faction *f; - test_cleanup(); + test_setup(); test_create_world(); f = test_create_faction(NULL); config_set("rules.limit.faction", "4"); @@ -430,6 +443,7 @@ static void test_cannot_create_unit_above_limit(CuTest * tc) config_set("rules.limit.alliance", "3"); CuAssertIntEquals(tc, 0, checkunitnumber(f, 3)); CuAssertIntEquals(tc, 1, checkunitnumber(f, 4)); + test_cleanup(); } static void test_reserve_cmd(CuTest *tc) { @@ -439,7 +453,7 @@ static void test_reserve_cmd(CuTest *tc) { order *ord; const resource_type *rtype; - test_cleanup(); + test_setup(); test_create_world(); rtype = get_resourcetype(R_SILVER); @@ -499,7 +513,7 @@ static void test_pay_cmd(CuTest *tc) { faction *f; building *b; - test_cleanup(); + test_setup(); setup_pay_cmd(&fix); b = fix.u1->building; f = fix.u1->faction; @@ -542,7 +556,7 @@ static void test_pay_cmd_must_be_owner(CuTest *tc) { faction *f; building *b; - test_cleanup(); + test_setup(); setup_pay_cmd(&fix); b = fix.u1->building; f = fix.u1->faction; @@ -1321,7 +1335,7 @@ static void test_show_elf(CuTest *tc) { rc = test_create_race("elf"); test_create_itemtype("elvenhorse"); - loc = get_or_create_locale("de"); + loc = test_create_locale(); locale_setstring(loc, "elvenhorse", "Elfenpferd"); locale_setstring(loc, "elvenhorse_p", "Elfenpferde"); locale_setstring(loc, "race::elf_p", "Elfen"); diff --git a/src/market.test.c b/src/market.test.c index b70288e90..a631dbcb7 100644 --- a/src/market.test.c +++ b/src/market.test.c @@ -76,6 +76,7 @@ static void test_market_curse(CuTest * tc) CuAssertIntEquals(tc, 70, i_get(u->items, htype)); CuAssertIntEquals(tc, 35, i_get(u->items, ltype)); + test_cleanup(); } static void test_rc_trade(CuTest *tc) { From cdf13c9fec49288d52e5286d263bdf8329e211d8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 11 Mar 2017 14:22:21 +0100 Subject: [PATCH 5/5] stop using test_create_world, use test_setup. --- src/economy.test.c | 24 +++++++++++------------- src/give.test.c | 3 +-- src/kernel/faction.test.c | 6 ++---- src/reports.test.c | 15 ++++----------- src/spells/magicresistance.test.c | 18 ++++++++---------- 5 files changed, 26 insertions(+), 40 deletions(-) diff --git a/src/economy.test.c b/src/economy.test.c index e14b473b4..7534afe7e 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -128,12 +128,9 @@ static struct unit *create_recruiter(void) { unit *u; const resource_type* rtype; - test_cleanup(); - test_create_world(); - - r=findregion(0, 0); + r=test_create_region(0, 0, NULL); rsetpeasants(r, 999); - f = test_create_faction(rc_find("human")); + f = test_create_faction(NULL); u = test_create_unit(f, r); rtype = get_resourcetype(R_SILVER); change_resource(u, rtype, 1000); @@ -143,9 +140,10 @@ static struct unit *create_recruiter(void) { static void test_heroes_dont_recruit(CuTest * tc) { unit *u; - test_cleanup(); - + test_setup(); + init_resources(); u = create_recruiter(); + fset(u, UFL_HERO); unit_addorder(u, create_order(K_RECRUIT, default_locale, "1")); @@ -160,8 +158,8 @@ static void test_heroes_dont_recruit(CuTest * tc) { static void test_normals_recruit(CuTest * tc) { unit *u; - test_cleanup(); - + test_setup(); + init_resources(); u = create_recruiter(); unit_addorder(u, create_order(K_RECRUIT, default_locale, "1")); @@ -193,11 +191,11 @@ static void test_tax_cmd(CuTest *tc) { request *taxorders = 0; - test_cleanup(); + test_setup(); + init_resources(); config_set("taxing.perlevel", "20"); - test_create_world(); 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); @@ -210,7 +208,7 @@ static void test_tax_cmd(CuTest *tc) { silver = get_resourcetype(R_SILVER)->itype; - sword = it_get_or_create(rt_get_or_create("sword")); + sword = test_create_itemtype("sword"); new_weapontype(sword, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 1); i_change(&u->items, sword, 1); set_level(u, SK_MELEE, 1); diff --git a/src/give.test.c b/src/give.test.c index 33f70fb90..1767dec36 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -324,8 +324,7 @@ static void test_give_herbs(CuTest * tc) { struct order *ord; test_setup_ex(tc); - test_create_world(); - env.f2 = env.f1 = test_create_faction(0); + env.f2 = env.f1 = test_create_faction(NULL); setup_give(&env); i_change(&env.src->items, env.itype, 10); diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index c01731964..80faba3c1 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -153,8 +153,7 @@ static void test_set_origin(CuTest *tc) { int x = 0, y = 0; plane *pl; - test_cleanup(); - test_create_world(); + test_setup(); pl = create_new_plane(0, "", 0, 19, 0, 19, 0); f = test_create_faction(0); CuAssertPtrEquals(tc, 0, f->ursprung); @@ -179,8 +178,7 @@ static void test_set_origin_bug(CuTest *tc) { plane *pl; int x = 17, y = 10; - test_cleanup(); - test_create_world(); + test_setup(); pl = create_new_plane(0, "", 0, 19, 0, 19, 0); f = test_create_faction(0); faction_setorigin(f, 0, -10, 3); diff --git a/src/reports.test.c b/src/reports.test.c index 976e9dfe1..f66d94684 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -45,18 +45,11 @@ static void test_reorder_units(CuTest * tc) ship * s; unit *u0, *u1, *u2, *u3, *u4; struct faction * f; - const building_type *btype; - const ship_type *stype; - test_cleanup(); - test_create_world(); - - btype = bt_find("castle"); - stype = st_find("boat"); - - r = findregion(-1, 0); - b = test_create_building(r, btype); - s = test_create_ship(r, stype); + test_setup(); + r = test_create_region(0, 0, NULL); + b = test_create_building(r, NULL); + s = test_create_ship(r, NULL); f = test_create_faction(0); u0 = test_create_unit(f, r); diff --git a/src/spells/magicresistance.test.c b/src/spells/magicresistance.test.c index e9cc98e34..621d2c3b4 100644 --- a/src/spells/magicresistance.test.c +++ b/src/spells/magicresistance.test.c @@ -28,13 +28,12 @@ static void test_magicresistance_unit(CuTest *tc) { message *msg; curse *c; - test_cleanup(); - test_create_world(); - r=findregion(0, 0); - f1 = test_create_faction(test_create_race("human")); + test_setup(); + r = test_create_plain(0, 0); + f1 = test_create_faction(NULL); u1 = test_create_unit(f1, r); - f2 = test_create_faction(test_create_race("human")); + f2 = test_create_faction(NULL); u2 = test_create_unit(f2, r); c = create_curse(u1, &u2->attribs, ct_find("magicresistance"), 10, 20, 30, u2->number); @@ -56,13 +55,12 @@ static void test_magicresistance_building(CuTest *tc) { message *msg; curse *c; - test_cleanup(); - test_create_world(); - r = findregion(0, 0); - f1 = test_create_faction(test_create_race("human")); + test_setup(); + r = test_create_plain(0, 0); + f1 = test_create_faction(NULL); u1 = test_create_unit(f1, r); - b1 = test_create_building(r, test_create_buildingtype("castle")); + b1 = test_create_building(r, NULL); c = create_curse(u1, &b1->attribs, ct_find("magicresistance"), 10, 20, 30, 0); CuAssertPtrNotNull(tc, b1->attribs);