new rule: call test_setup to begin test, test_cleanup at end.

This commit is contained in:
Enno Rehling 2016-08-29 14:21:28 +01:00
parent 1c5fcded9f
commit c032091b39
12 changed files with 48 additions and 41 deletions

View File

@ -25,7 +25,7 @@ static void test_herbsearch(CuTest * tc)
region *r;
const item_type *itype;
test_cleanup();
test_setup();
r = test_create_region(0, 0, 0);
rc = rc_get_or_create("dragon");
rc->flags |= RCF_UNARMEDGUARD;

View File

@ -16,7 +16,7 @@
#include <assert.h>
static void test_rules(CuTest *tc) {
test_cleanup();
test_setup();
config_set("stealth.faction.other", NULL);
CuAssertIntEquals(tc, true, rule_stealth_other());
config_set("stealth.faction.other", "0");
@ -37,7 +37,7 @@ static void test_otherfaction(CuTest *tc) {
unit *u;
faction *f;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
f = test_create_faction(0);
config_set("stealth.faction.other", "1");

View File

@ -17,7 +17,6 @@ typedef struct alliance_fixture {
} alliance_fixture;
static void setup_alliance(alliance_fixture *fix) {
test_cleanup();
test_create_world();
fix->rc = test_create_race("human");
fix->f1 = test_create_faction(fix->rc);
@ -28,7 +27,7 @@ static void setup_alliance(alliance_fixture *fix) {
static void test_alliance_make(CuTest *tc) {
alliance * al;
test_cleanup();
test_setup();
assert(!alliances);
al = makealliance(1, "Hodor");
CuAssertPtrNotNull(tc, al);
@ -50,6 +49,7 @@ 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);
@ -69,7 +69,7 @@ static void test_alliance_dead_faction(CuTest *tc) {
faction *f, *f2;
alliance *al;
test_cleanup();
test_setup();
f = test_create_faction(0);
f2 = test_create_faction(0);
al = makealliance(42, "Hodor");
@ -91,7 +91,7 @@ static void test_alliance_cmd(CuTest *tc) {
struct region *r;
struct alliance *al;
test_cleanup();
test_setup();
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);
u2 = test_create_unit(test_create_faction(0), r);
@ -118,7 +118,7 @@ static void test_alliance_cmd_kick(CuTest *tc) {
struct region *r;
struct alliance *al;
test_cleanup();
test_setup();
al = makealliance(42, "Hodor");
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);
@ -138,7 +138,7 @@ static void test_alliance_cmd_no_invite(CuTest *tc) {
unit *u1, *u2;
struct region *r;
test_cleanup();
test_setup();
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);
u2 = test_create_unit(test_create_faction(0), r);
@ -159,7 +159,7 @@ static void test_alliance_cmd_leave(CuTest *tc) {
struct region *r;
struct alliance *al;
test_cleanup();
test_setup();
al = makealliance(42, "Hodor");
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);
@ -180,7 +180,7 @@ static void test_alliance_cmd_transfer(CuTest *tc) {
struct region *r;
struct alliance *al;
test_cleanup();
test_setup();
al = makealliance(42, "Hodor");
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);

View File

@ -29,6 +29,7 @@ static void test_create_duplicate_spell(CuTest * tc)
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
test_setup();
test_log_stderr(0);
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
sp = create_spell("testspell", 0);
@ -43,6 +44,7 @@ static void test_create_spell_with_id(CuTest * tc)
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
test_setup();
test_log_stderr(0);
CuAssertPtrEquals(tc, 0, find_spellbyid(42));
sp = create_spell("testspell", 42);
CuAssertPtrEquals(tc, sp, find_spellbyid(42));

View File

@ -6,7 +6,7 @@
#include <CuTest.h>
static void test_add_prefix(CuTest *tc) {
test_cleanup();
test_setup();
CuAssertPtrEquals(tc, 0, race_prefixes);
add_raceprefix("sea");
CuAssertPtrNotNull(tc, race_prefixes);

View File

@ -32,7 +32,7 @@ typedef struct {
} spy_fixture;
static void setup_spy(spy_fixture *fix) {
test_cleanup();
test_setup();
fix->r = test_create_region(0, 0, NULL);
fix->spy = test_create_unit(test_create_faction(NULL), fix->r);
fix->victim = test_create_unit(test_create_faction(NULL), fix->r);
@ -88,7 +88,7 @@ static void test_all_spy_message(CuTest *tc) {
static void setup_sabotage(void) {
struct locale *lang;
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
locale_setstring(lang, parameters[P_SHIP], "SCHIFF");
locale_setstring(lang, parameters[P_ANY], "ALLE");

View File

@ -70,7 +70,7 @@ static void setup_study(study_fixture *fix, skill_t sk) {
struct locale *lang;
assert(fix);
test_cleanup();
test_setup();
config_set("study.random_progress", "0");
test_create_world();
r = findregion(0, 0);
@ -138,7 +138,7 @@ static void test_study_bug_2194(CuTest *tc) {
struct locale * loc;
building * b;
test_cleanup();
test_setup();
random_source_inject_constant(0.0);
init_resources();
loc = get_or_create_locale("de");
@ -195,7 +195,7 @@ static void test_produceexp(CuTest *tc) {
unit *u;
g_tc = tc;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 2);
config_set("study.produceexp", "20");
@ -210,7 +210,7 @@ static void test_academy_building(CuTest *tc) {
building * b;
message * msg;
test_cleanup();
test_setup();
mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", 0));
random_source_inject_constant(0.0);
@ -253,7 +253,7 @@ static void test_academy_building(CuTest *tc) {
void test_learn_skill_single(CuTest *tc) {
unit *u;
skill *sv;
test_cleanup();
test_setup();
config_set("study.random_progress", "0");
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
@ -272,7 +272,7 @@ void test_learn_skill_single(CuTest *tc) {
void test_learn_skill_multi(CuTest *tc) {
unit *u;
skill *sv;
test_cleanup();
test_setup();
config_set("study.random_progress", "0");
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 10);
@ -292,7 +292,7 @@ void test_learn_skill_multi(CuTest *tc) {
static void test_demon_skillchanges(CuTest *tc) {
unit * u;
race * rc;
test_cleanup();
test_setup();
rc = test_create_race("demon");
CuAssertPtrEquals(tc, rc, get_race(RC_DAEMON));
u = test_create_unit(test_create_faction(rc), 0);
@ -305,7 +305,7 @@ static void test_demon_skillchanges(CuTest *tc) {
static void test_study_cmd(CuTest *tc) {
unit *u;
test_cleanup();
test_setup();
init_resources();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
@ -321,7 +321,7 @@ static void test_study_cmd(CuTest *tc) {
static void test_study_cost(CuTest *tc) {
unit *u;
const struct item_type *itype;
test_cleanup();
test_setup();
init_resources();
itype = get_resourcetype(R_SILVER)->itype;
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
@ -340,7 +340,7 @@ static void test_study_cost(CuTest *tc) {
static void test_teach_cmd(CuTest *tc) {
unit *u, *ut;
test_cleanup();
test_setup();
init_resources();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 10);
@ -360,7 +360,7 @@ static void test_teach_cmd(CuTest *tc) {
static void test_teach_two(CuTest *tc) {
unit *u1, *u2, *ut;
test_cleanup();
test_setup();
init_resources();
u1 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u1, 5);
@ -390,7 +390,7 @@ static void test_teach_two_skills(CuTest *tc) {
faction *f;
region *r;
test_cleanup();
test_setup();
init_resources();
f = test_create_faction(0);
r = test_create_region(0, 0, 0);
@ -420,7 +420,7 @@ static void test_teach_two_skills(CuTest *tc) {
static void test_teach_one_to_many(CuTest *tc) {
unit *u, *ut;
test_cleanup();
test_setup();
init_resources();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 20);
@ -440,7 +440,7 @@ static void test_teach_one_to_many(CuTest *tc) {
static void test_teach_many_to_one(CuTest *tc) {
unit *u, *u1, *u2;
test_cleanup();
test_setup();
init_resources();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
scale_number(u, 20);
@ -467,7 +467,7 @@ static void test_teach_many_to_many(CuTest *tc) {
region *r;
faction *f;
test_cleanup();
test_setup();
init_resources();
f = test_create_faction(0);
r = test_create_region(0, 0, 0);

View File

@ -133,7 +133,12 @@ void test_log_stderr(int flags) {
stderrlog = log_to_file(flags, stderr);
}
else {
log_destroy(stderrlog);
if (stderrlog) {
log_destroy(stderrlog);
}
else {
log_warning("stderr logging is inactive. did you call test_cleanup twice?");
}
stderrlog = 0;
}

View File

@ -12,8 +12,8 @@
static void test_shock(CuTest *tc) {
unit *u;
trigger *tt;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
create_mage(u, M_GRAY);
set_level(u, SK_MAGIC, 5);
@ -32,8 +32,8 @@ static void test_shock(CuTest *tc) {
static void test_shock_low(CuTest *tc) {
unit *u;
trigger *tt;
test_cleanup();
test_setup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
create_mage(u, M_GRAY);
set_level(u, SK_MAGIC, 5);

View File

@ -19,7 +19,7 @@ void test_upkeep_default(CuTest * tc)
faction *f1, *f2;
const item_type *i_silver;
test_cleanup();
test_setup();
test_create_world();
i_silver = it_find("money");
@ -50,7 +50,7 @@ void test_upkeep_hunger_damage(CuTest * tc)
faction *f1;
const item_type *i_silver;
test_cleanup();
test_setup();
test_create_world();
i_silver = it_find("money");
@ -75,7 +75,7 @@ void test_upkeep_from_pool(CuTest * tc)
unit *u1, *u2;
const item_type *i_silver;
test_cleanup();
test_setup();
test_create_world();
i_silver = it_find("money");
@ -108,7 +108,7 @@ void test_upkeep_from_friend(CuTest * tc)
faction *f1, *f2;
const item_type *i_silver;
test_cleanup();
test_setup();
test_create_world();
i_silver = it_find("money");
@ -142,7 +142,7 @@ void test_upkeep_free(CuTest * tc)
unit *u;
const item_type *i_silver;
test_cleanup();
test_setup();
test_create_world();
i_silver = it_find("money");

View File

@ -22,7 +22,7 @@ static void test_move_to_vortex(CuTest *tc) {
unit *u;
struct locale *lang;
test_cleanup();
test_setup();
lang = get_or_create_locale("en");
locale_setstring(lang, "vortex", "wirbel");
init_locale(lang);

View File

@ -22,7 +22,7 @@ static void test_make_wormholes(CuTest *tc) {
terrain_type *t_plain;
building_type *btype;
test_cleanup();
test_setup();
t_plain = test_create_terrain("plain", LAND_REGION);
btype = test_create_buildingtype("wormhole");
match[0] = r1 = test_create_region(0, 0, t_plain);
@ -44,7 +44,7 @@ static void test_sort_wormhole_regions(CuTest *tc) {
terrain_type *t_plain;
quicklist *rlist = 0;
test_cleanup();
test_setup();
t_plain = test_create_terrain("plain", LAND_REGION);
r1 = test_create_region(0, 0, t_plain);
r2 = test_create_region(1, 0, t_plain);