eliminate use of test_create_world

This commit is contained in:
Enno Rehling 2015-11-07 23:34:51 +01:00
parent 1182ccf139
commit 318820fb00
5 changed files with 26 additions and 16 deletions

View File

@ -25,8 +25,8 @@ static void test_make_fighter(CuTest * tc)
const resource_type *rtype; const resource_type *rtype;
test_cleanup(); test_cleanup();
test_create_world(); test_create_horse();
r = findregion(0, 0); r = test_create_region(0, 0, 0);
f = test_create_faction(NULL); f = test_create_faction(NULL);
au = test_create_unit(f, r); au = test_create_unit(f, r);
enable_skill(SK_MAGIC, true); enable_skill(SK_MAGIC, true);
@ -75,8 +75,7 @@ static void test_defenders_get_building_bonus(CuTest * tc)
building_type * btype; building_type * btype;
test_cleanup(); test_cleanup();
test_create_world(); r = test_create_region(0, 0, 0);
r = findregion(0, 0);
btype = bt_get_or_create("castle"); btype = bt_get_or_create("castle");
btype->protection = &add_two; btype->protection = &add_two;
bld = test_create_building(r, btype); bld = test_create_building(r, btype);
@ -120,8 +119,7 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
building_type * btype; building_type * btype;
test_cleanup(); test_cleanup();
test_create_world(); r = test_create_region(0, 0, 0);
r = findregion(0, 0);
btype = bt_get_or_create("castle"); btype = bt_get_or_create("castle");
btype->protection = &add_two; btype->protection = &add_two;
bld = test_create_building(r, btype); bld = test_create_building(r, btype);
@ -151,8 +149,7 @@ static void test_building_bonus_respects_size(CuTest * tc)
faction * f; faction * f;
test_cleanup(); test_cleanup();
test_create_world(); r = test_create_region(0, 0, 0);
r = findregion(0, 0);
btype = bt_get_or_create("castle"); btype = bt_get_or_create("castle");
btype->protection = &add_two; btype->protection = &add_two;
bld = test_create_building(r, btype); bld = test_create_building(r, btype);

View File

@ -819,7 +819,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
/* gebäude fertig */ /* gebäude fertig */
new_order = default_order(lang); new_order = default_order(lang);
} }
else if (want != INT_MAX) { else if (want != INT_MAX && btname) {
/* reduzierte restgröße */ /* reduzierte restgröße */
const char *hasspace = strchr(btname, ' '); const char *hasspace = strchr(btname, ' ');
if (hasspace) { if (hasspace) {

View File

@ -27,10 +27,14 @@ typedef struct build_fixture {
static unit * setup_build(build_fixture *bf) { static unit * setup_build(build_fixture *bf) {
test_cleanup(); test_cleanup();
test_create_world(); init_resources();
test_create_itemtype("stone");
test_create_buildingtype("castle");
bf->rc = test_create_race("human"); 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 = test_create_faction(bf->rc);
bf->f->locale = get_or_create_locale("de");
assert(bf->rc && bf->f && bf->r); assert(bf->rc && bf->f && bf->r);
bf->u = test_create_unit(bf->f, bf->r); bf->u = test_create_unit(bf->f, bf->r);
assert(bf->u); assert(bf->u);
@ -134,6 +138,7 @@ static void test_build_limits(CuTest *tc) {
u = setup_build(&bf); u = setup_build(&bf);
rtype = bf.cons.materials[0].rtype; rtype = bf.cons.materials[0].rtype;
assert(rtype);
i_change(&u->items, rtype->itype, 1); i_change(&u->items, rtype->itype, 1);
set_level(u, SK_ARMORER, bf.cons.minskill); set_level(u, SK_ARMORER, bf.cons.minskill);
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 10)); CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 10));

View File

@ -45,7 +45,7 @@ struct region *test_create_region(int x, int y, const terrain_type *terrain)
if (!terrain) { if (!terrain) {
terrain_type *t = get_or_create_terrain("plain"); terrain_type *t = get_or_create_terrain("plain");
t->size = 1000; t->size = 1000;
fset(t, LAND_REGION); fset(t, LAND_REGION|CAVALRY_REGION|FOREST_REGION);
terraform_region(r, t); terraform_region(r, t);
} else } else
terraform_region(r, terrain); 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); 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. /** creates a small world and some stuff in it.
* two terrains: 'plain' and 'ocean' * two terrains: 'plain' and 'ocean'
* one race: 'human' * one race: 'human'
@ -216,10 +226,7 @@ void test_create_world(void)
locale_setstring(loc, "money", "SILBER"); locale_setstring(loc, "money", "SILBER");
init_resources(); init_resources();
itype = test_create_itemtype("horse"); test_create_horse();
itype->flags |= ITF_BIG | ITF_ANIMAL;
itype->weight = 5000;
itype->capacity = 7000;
itype = test_create_itemtype("cart"); itype = test_create_itemtype("cart");
itype->flags |= ITF_BIG | ITF_VEHICLE; itype->flags |= ITF_BIG | ITF_VEHICLE;

View File

@ -34,6 +34,7 @@ extern "C" {
struct faction *test_create_faction(const struct race *rc); struct faction *test_create_faction(const struct race *rc);
struct unit *test_create_unit(struct faction *f, struct region *r); struct unit *test_create_unit(struct faction *f, struct region *r);
void test_create_world(void); 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 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 ship * test_create_ship(struct region * r, const struct ship_type * stype);
struct item_type * test_create_itemtype(const char * name); struct item_type * test_create_itemtype(const char * name);