forked from github/server
code that uses newterrain needs to set up terrains in tests.
This commit is contained in:
parent
2b81334ba2
commit
440679da87
|
@ -14,6 +14,7 @@
|
|||
#include <kernel/resources.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
|
@ -170,6 +171,23 @@ static void test_normals_recruit(CuTest * tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create any terrain types that are used by the trade rules.
|
||||
*
|
||||
* This should prevent newterrain from returning NULL.
|
||||
*/
|
||||
static void setup_terrains(CuTest *tc) {
|
||||
test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION | FLY_INTO);
|
||||
test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO);
|
||||
test_create_terrain("swamp", LAND_REGION | WALK_INTO | FLY_INTO);
|
||||
test_create_terrain("desert", LAND_REGION | WALK_INTO | FLY_INTO);
|
||||
init_terrains();
|
||||
CuAssertPtrNotNull(tc, newterrain(T_OCEAN));
|
||||
CuAssertPtrNotNull(tc, newterrain(T_PLAIN));
|
||||
CuAssertPtrNotNull(tc, newterrain(T_SWAMP));
|
||||
CuAssertPtrNotNull(tc, newterrain(T_DESERT));
|
||||
}
|
||||
|
||||
static region *setup_trade_region(CuTest *tc, const struct terrain_type *terrain) {
|
||||
region *r;
|
||||
item_type *it_luxury;
|
||||
|
@ -206,6 +224,7 @@ static void test_trade_insect(CuTest *tc) {
|
|||
test_setup();
|
||||
init_resources();
|
||||
test_create_locale();
|
||||
setup_terrains(tc);
|
||||
r = setup_trade_region(tc, test_create_terrain("swamp", LAND_REGION));
|
||||
init_terrains();
|
||||
|
||||
|
@ -233,6 +252,7 @@ static void test_buy_cmd(CuTest *tc) {
|
|||
test_setup();
|
||||
init_resources();
|
||||
test_create_locale();
|
||||
setup_terrains(tc);
|
||||
r = setup_trade_region(tc, test_create_terrain("swamp", LAND_REGION));
|
||||
init_terrains();
|
||||
|
||||
|
|
|
@ -128,15 +128,20 @@ static const terrain_type *newterrains[MAXTERRAINS];
|
|||
|
||||
const struct terrain_type *newterrain(terrain_t t)
|
||||
{
|
||||
if (t == NOTERRAIN)
|
||||
const struct terrain_type *result;
|
||||
if (t == NOTERRAIN) {
|
||||
return NULL;
|
||||
}
|
||||
assert(t >= 0);
|
||||
assert(t < MAXTERRAINS);
|
||||
if (!newterrains[t]) {
|
||||
log_warning("did you call init_terrains?");
|
||||
newterrains[t] = get_terrain(terraindata[t]);
|
||||
result = newterrains[t];
|
||||
if (!result) {
|
||||
result = newterrains[t] = get_terrain(terraindata[t]);
|
||||
}
|
||||
return newterrains[t];
|
||||
if (!result) {
|
||||
log_error("no such terrain: %s.", terraindata[t]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
terrain_t oldterrain(const struct terrain_type * terrain)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <kernel/region.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/terrainid.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
|
@ -864,11 +865,25 @@ static void test_peasant_luck_effect(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create any terrain types that are used by demographics.
|
||||
*
|
||||
* This should prevent newterrain from returning NULL.
|
||||
*/
|
||||
static void setup_terrains(CuTest *tc) {
|
||||
test_create_terrain("volcano", SEA_REGION | SWIM_INTO | FLY_INTO);
|
||||
test_create_terrain("activevolcano", LAND_REGION | WALK_INTO | FLY_INTO);
|
||||
init_terrains();
|
||||
CuAssertPtrNotNull(tc, newterrain(T_VOLCANO));
|
||||
CuAssertPtrNotNull(tc, newterrain(T_VOLCANO_SMOKING));
|
||||
}
|
||||
|
||||
static void test_luck_message(CuTest *tc) {
|
||||
region* r;
|
||||
attrib *a;
|
||||
|
||||
test_setup();
|
||||
setup_terrains(tc);
|
||||
r = test_create_region(0, 0, NULL);
|
||||
rsetpeasants(r, 1);
|
||||
|
||||
|
|
Loading…
Reference in New Issue