forked from github/server
make tests more valgrind-friendly by not leaking memory
This commit is contained in:
parent
1864d1fc86
commit
9334677d81
|
@ -78,7 +78,12 @@ ln -f $LIVE/data/$turn.dat data/
|
|||
rm -rf reports
|
||||
mkdir -p reports
|
||||
|
||||
$SOURCE/build-x86_64-gcc-Debug/eressea/eressea -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua
|
||||
SERVER="$SOURCE/build-x86_64-gcc-Debug/eressea/eressea"
|
||||
VALGRIND=$(which valgrind)
|
||||
if [ ! -z $VALGRIND ]; then
|
||||
SERVER="$VALGRIND --leak-check=no $SERVER"
|
||||
fi
|
||||
$SERVER -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua
|
||||
let turn=$turn+1
|
||||
[ -e data/$turn.dat ] || abort "no data file created"
|
||||
}
|
||||
|
|
|
@ -3675,7 +3675,7 @@ static void free_fighter(fighter * fig)
|
|||
|
||||
}
|
||||
|
||||
static void free_battle(battle * b)
|
||||
void free_battle(battle * b)
|
||||
{
|
||||
int max_fac_no = 0;
|
||||
|
||||
|
@ -4338,5 +4338,6 @@ void battle_free(battle * b) {
|
|||
}
|
||||
free_side(s);
|
||||
}
|
||||
free(b);
|
||||
}
|
||||
|
||||
|
|
13
src/battle.h
13
src/battle.h
|
@ -260,15 +260,16 @@ extern "C" {
|
|||
extern void drain_exp(struct unit *u, int d);
|
||||
extern void kill_troop(troop dt);
|
||||
extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */
|
||||
extern bool is_attacker(const fighter * fig);
|
||||
|
||||
extern struct battle *make_battle(struct region * r);
|
||||
extern fighter *make_fighter(struct battle *b, struct unit *u, side * s,
|
||||
bool attack);
|
||||
extern struct side *make_side(struct battle * b, const struct faction * f,
|
||||
bool is_attacker(const fighter * fig);
|
||||
struct battle *make_battle(struct region * r);
|
||||
void free_battle(struct battle * b);
|
||||
struct fighter *make_fighter(struct battle *b, struct unit *u,
|
||||
struct side * s, bool attack);
|
||||
struct side *make_side(struct battle * b, const struct faction * f,
|
||||
const struct group * g, unsigned int flags,
|
||||
const struct faction * stealthfaction);
|
||||
extern int skilldiff(troop at, troop dt, int dist);
|
||||
int skilldiff(troop at, troop dt, int dist);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ static void test_make_fighter(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 3, af->magic);
|
||||
CuAssertIntEquals(tc, 1, af->horses);
|
||||
CuAssertIntEquals(tc, 0, af->elvenhorses);
|
||||
free_battle(b);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static int add_two(building * b, unit * u) {
|
||||
|
@ -103,6 +105,8 @@ static void test_defenders_get_building_bonus(CuTest * tc)
|
|||
|
||||
diff = skilldiff(dt, at, 0);
|
||||
CuAssertIntEquals(tc, 0, diff);
|
||||
free_battle(b);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_attackers_get_no_building_bonus(CuTest * tc)
|
||||
|
@ -131,6 +135,8 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
|
|||
af = make_fighter(b, au, as, true);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, af->building);
|
||||
free_battle(b);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_building_bonus_respects_size(CuTest * tc)
|
||||
|
@ -167,6 +173,8 @@ static void test_building_bonus_respects_size(CuTest * tc)
|
|||
|
||||
CuAssertPtrEquals(tc, bld, af->building);
|
||||
CuAssertPtrEquals(tc, 0, df->building);
|
||||
free_battle(b);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_battle_suite(void)
|
||||
|
|
|
@ -113,6 +113,7 @@ static void test_findrace(CuTest *tc) {
|
|||
rc = findrace("Zwerg", lang);
|
||||
CuAssertPtrNotNull(tc, rc);
|
||||
CuAssertStrEquals(tc, "dwarf", rc->_name);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_items(CuTest * tc)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <util/parser.h>
|
||||
#include <util/language.h>
|
||||
|
||||
#include <tests.h>
|
||||
#include <CuTest.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -13,7 +14,10 @@
|
|||
static void test_create_order(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
struct locale * lang;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, "keyword::move", "MOVE");
|
||||
ord = create_order(K_MOVE, lang, "NORTH");
|
||||
|
@ -24,12 +28,16 @@ static void test_create_order(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_parse_order(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
struct locale * lang;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, "keyword::move", "MOVE");
|
||||
ord = parse_order("MOVE NORTH", lang);
|
||||
|
@ -40,12 +48,16 @@ static void test_parse_order(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_parse_make(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
struct locale * lang;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
|
||||
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
||||
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
||||
|
@ -58,13 +70,16 @@ static void test_parse_make(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_MAKE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
|
||||
free_order(ord);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_parse_make_temp(CuTest *tc) {
|
||||
char cmd[32];
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
struct locale * lang;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("en");
|
||||
locale_setstring(lang, keyword(K_MAKE), "MAKE");
|
||||
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
|
||||
locale_setstring(lang, "TEMP", "TEMP");
|
||||
|
@ -78,6 +93,7 @@ static void test_parse_make_temp(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "herp", getstrtoken());
|
||||
free_order(ord);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_parse_maketemp(CuTest *tc) {
|
||||
|
|
|
@ -12,11 +12,13 @@ static void test_readwrite_data(CuTest * tc)
|
|||
{
|
||||
const char *filename = "test.dat";
|
||||
char path[MAX_PATH];
|
||||
test_cleanup();
|
||||
sprintf(path, "%s/%s", datapath(), filename);
|
||||
CuAssertIntEquals(tc, 0, writegame(filename));
|
||||
CuAssertIntEquals(tc, 0, readgame(filename, 0));
|
||||
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
|
||||
CuAssertIntEquals(tc, 0, remove(path));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_save_suite(void)
|
||||
|
|
|
@ -42,6 +42,7 @@ static void test_findkeyword(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_STUDY, findkeyword("study"));
|
||||
CuAssertIntEquals(tc, NOKEYWORD, findkeyword(""));
|
||||
CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato"));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_get_keyword_default(CuTest *tc) {
|
||||
|
@ -51,6 +52,7 @@ static void test_get_keyword_default(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
|
||||
CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang));
|
||||
CuAssertIntEquals(tc, K_STUDY, get_keyword("study", lang));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_get_shortest_match(CuTest *tc) {
|
||||
|
@ -69,6 +71,7 @@ static void test_get_shortest_match(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, K_STATUS, get_keyword("COM", lang));
|
||||
CuAssertIntEquals(tc, K_STATUS, get_keyword("COMBAT", lang));
|
||||
CuAssertIntEquals(tc, K_COMBATSPELL, get_keyword("COMBATS", lang));
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
#define SUITE_DISABLE_TEST(suite, test) (void)test
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
#pragma warning(disable: 4210)
|
||||
#define ADD_TESTS(suite, name) \
|
||||
CuSuite *get_##name##_suite(void); \
|
||||
CuSuiteAddSuite(suite, get_##name##_suite())
|
||||
CuSuite *name = get_##name##_suite(); \
|
||||
CuSuiteAddSuite(suite, name);
|
||||
|
||||
int RunAllTests(void)
|
||||
{
|
||||
CuString *output = CuStringNew();
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
int flags = log_flags;
|
||||
int result, flags = log_flags;
|
||||
|
||||
log_flags = LOG_FLUSH | LOG_CPERROR;
|
||||
kernel_init();
|
||||
|
@ -67,7 +68,9 @@ int RunAllTests(void)
|
|||
printf("%s\n", output->buffer);
|
||||
|
||||
log_flags = flags;
|
||||
return suite->failCount;
|
||||
result = suite->failCount;
|
||||
CuSuiteDelete(suite);
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
|
|
@ -33,6 +33,7 @@ static void test_move_to_vortex(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r));
|
||||
CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r));
|
||||
CuAssertPtrEquals(tc, r2, r);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_vortex(CuTest *tc) {
|
||||
|
|
Loading…
Reference in New Issue