From 318820fb008af28e77a07ddd1e98817b2df43541 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Nov 2015 23:34:51 +0100 Subject: [PATCH] eliminate use of test_create_world --- src/battle.test.c | 13 +++++-------- src/kernel/build.c | 2 +- src/kernel/build.test.c | 9 +++++++-- src/tests.c | 17 ++++++++++++----- src/tests.h | 1 + 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/battle.test.c b/src/battle.test.c index 8d8f83b8a..02213d35b 100644 --- a/src/battle.test.c +++ b/src/battle.test.c @@ -25,8 +25,8 @@ static void test_make_fighter(CuTest * tc) const resource_type *rtype; test_cleanup(); - test_create_world(); - r = findregion(0, 0); + test_create_horse(); + r = test_create_region(0, 0, 0); f = test_create_faction(NULL); au = test_create_unit(f, r); enable_skill(SK_MAGIC, true); @@ -75,8 +75,7 @@ static void test_defenders_get_building_bonus(CuTest * tc) building_type * btype; test_cleanup(); - test_create_world(); - r = findregion(0, 0); + r = test_create_region(0, 0, 0); btype = bt_get_or_create("castle"); btype->protection = &add_two; bld = test_create_building(r, btype); @@ -120,8 +119,7 @@ static void test_attackers_get_no_building_bonus(CuTest * tc) building_type * btype; test_cleanup(); - test_create_world(); - r = findregion(0, 0); + r = test_create_region(0, 0, 0); btype = bt_get_or_create("castle"); btype->protection = &add_two; bld = test_create_building(r, btype); @@ -151,8 +149,7 @@ static void test_building_bonus_respects_size(CuTest * tc) faction * f; test_cleanup(); - test_create_world(); - r = findregion(0, 0); + r = test_create_region(0, 0, 0); btype = bt_get_or_create("castle"); btype->protection = &add_two; bld = test_create_building(r, btype); diff --git a/src/kernel/build.c b/src/kernel/build.c index e38d76641..416bb3eb4 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -819,7 +819,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order * /* gebäude fertig */ new_order = default_order(lang); } - else if (want != INT_MAX) { + else if (want != INT_MAX && btname) { /* reduzierte restgröße */ const char *hasspace = strchr(btname, ' '); if (hasspace) { diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index b879295e1..8e26d86c5 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -27,10 +27,14 @@ typedef struct build_fixture { static unit * setup_build(build_fixture *bf) { test_cleanup(); - test_create_world(); + init_resources(); + + test_create_itemtype("stone"); + test_create_buildingtype("castle"); bf->rc = test_create_race("human"); - bf->r = findregion(0, 0); + bf->r = test_create_region(0, 0, 0); bf->f = test_create_faction(bf->rc); + bf->f->locale = get_or_create_locale("de"); assert(bf->rc && bf->f && bf->r); bf->u = test_create_unit(bf->f, bf->r); assert(bf->u); @@ -134,6 +138,7 @@ static void test_build_limits(CuTest *tc) { u = setup_build(&bf); rtype = bf.cons.materials[0].rtype; + assert(rtype); i_change(&u->items, rtype->itype, 1); set_level(u, SK_ARMORER, bf.cons.minskill); CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 10)); diff --git a/src/tests.c b/src/tests.c index 4e0206189..8cf97bede 100644 --- a/src/tests.c +++ b/src/tests.c @@ -45,7 +45,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain) if (!terrain) { terrain_type *t = get_or_create_terrain("plain"); t->size = 1000; - fset(t, LAND_REGION); + fset(t, LAND_REGION|CAVALRY_REGION|FOREST_REGION); terraform_region(r, t); } else terraform_region(r, terrain); @@ -196,6 +196,16 @@ void test_translate_param(const struct locale *lang, param_t param, const char * add_translation(cb, text, param); } + +item_type *test_create_horse(void) { + item_type * itype; + itype = test_create_itemtype("horse"); + itype->flags |= ITF_BIG | ITF_ANIMAL; + itype->weight = 5000; + itype->capacity = 7000; + return itype; +} + /** creates a small world and some stuff in it. * two terrains: 'plain' and 'ocean' * one race: 'human' @@ -216,10 +226,7 @@ void test_create_world(void) locale_setstring(loc, "money", "SILBER"); init_resources(); - itype = test_create_itemtype("horse"); - itype->flags |= ITF_BIG | ITF_ANIMAL; - itype->weight = 5000; - itype->capacity = 7000; + test_create_horse(); itype = test_create_itemtype("cart"); itype->flags |= ITF_BIG | ITF_VEHICLE; diff --git a/src/tests.h b/src/tests.h index ba33dd5a7..f0b64729b 100644 --- a/src/tests.h +++ b/src/tests.h @@ -34,6 +34,7 @@ extern "C" { 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); + struct item_type * test_create_horse(void); struct building * test_create_building(struct region * r, const struct building_type * btype); struct ship * test_create_ship(struct region * r, const struct ship_type * stype); struct item_type * test_create_itemtype(const char * name);