forked from github/server
Merge pull request #376 from ennorehling/develop
fix test bugs detected by valgrind
This commit is contained in:
commit
251afca68f
4 changed files with 32 additions and 18 deletions
33
src/battle.c
33
src/battle.c
|
@ -1022,23 +1022,32 @@ static void vampirism(troop at, int damage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAXRACES 128
|
||||||
|
|
||||||
static int natural_armor(unit * du)
|
static int natural_armor(unit * du)
|
||||||
{
|
{
|
||||||
static int *bonus = 0;
|
static int cookie = -1;
|
||||||
int an = u_race(du)->armor;
|
static int bonus[MAXRACES];
|
||||||
if (bonus == 0) {
|
const race *rc = u_race(du);
|
||||||
assert(num_races > 0);
|
int index, an = rc->armor;
|
||||||
bonus = calloc((size_t)num_races, sizeof(int));
|
|
||||||
|
assert(rc);
|
||||||
|
if (cookie!=global.cookie) {
|
||||||
|
cookie = global.cookie;
|
||||||
|
memset(bonus, 0, sizeof(bonus));
|
||||||
}
|
}
|
||||||
if (bonus[u_race(du)->index] == 0) {
|
assert(num_races < MAXRACES);
|
||||||
bonus[u_race(du)->index] =
|
index = rc->index;
|
||||||
get_param_int(u_race(du)->parameters, "armor.stamina", -1);
|
assert(index >= 0 && index < num_races);
|
||||||
if (bonus[u_race(du)->index] == 0)
|
if (bonus[index] == 0) {
|
||||||
bonus[u_race(du)->index] = -1;
|
bonus[index] =
|
||||||
|
get_param_int(rc->parameters, "armor.stamina", -1);
|
||||||
|
if (bonus[index] == 0)
|
||||||
|
bonus[index] = -1;
|
||||||
}
|
}
|
||||||
if (bonus[u_race(du)->index] > 0) {
|
if (bonus[index] > 0) {
|
||||||
int sk = effskill(du, SK_STAMINA, 0);
|
int sk = effskill(du, SK_STAMINA, 0);
|
||||||
sk /= bonus[u_race(du)->index];
|
sk /= bonus[index];
|
||||||
an += sk;
|
an += sk;
|
||||||
}
|
}
|
||||||
return an;
|
return an;
|
||||||
|
|
|
@ -146,6 +146,7 @@ void free_races(void) {
|
||||||
free(races);
|
free(races);
|
||||||
races = rc;
|
races = rc;
|
||||||
}
|
}
|
||||||
|
num_races = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static race *rc_find_i(const char *name)
|
static race *rc_find_i(const char *name)
|
||||||
|
|
|
@ -26,13 +26,13 @@ static void test_flyingship(CuTest * tc)
|
||||||
ship_type *shipType1, *shipType2;
|
ship_type *shipType1, *shipType2;
|
||||||
ship *sh1, *sh2;
|
ship *sh1, *sh2;
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
|
||||||
par.param = &par_data_ptr;
|
par.param = &par_data_ptr;
|
||||||
par_data.typ = SPP_SHIP;
|
par_data.typ = SPP_SHIP;
|
||||||
|
par_data.flag = 0;
|
||||||
|
|
||||||
test_cleanup();
|
r = test_create_region(0, 0, 0);
|
||||||
test_create_world();
|
|
||||||
|
|
||||||
r = findregion(0, 0);
|
|
||||||
f = test_create_faction(test_create_race("human"));
|
f = test_create_faction(test_create_race("human"));
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@ static void test_flyingship(CuTest * tc)
|
||||||
CuAssertTrue(tc, !flying_ship(sh2));
|
CuAssertTrue(tc, !flying_ship(sh2));
|
||||||
CuAssertIntEquals(tc, 0, sp_flying_ship(&co));
|
CuAssertIntEquals(tc, 0, sp_flying_ship(&co));
|
||||||
CuAssertTrue(tc, !flying_ship(sh2));
|
CuAssertTrue(tc, !flying_ship(sh2));
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_flyingship_suite(void)
|
CuSuite *get_flyingship_suite(void)
|
||||||
|
|
|
@ -21,13 +21,16 @@ cd $ROOT/tests
|
||||||
setup
|
setup
|
||||||
cleanup
|
cleanup
|
||||||
VALGRIND=`which valgrind`
|
VALGRIND=`which valgrind`
|
||||||
|
TESTS=../Debug/eressea/test_eressea
|
||||||
SERVER=../Debug/eressea/eressea
|
SERVER=../Debug/eressea/eressea
|
||||||
if [ -n "$VALGRIND" ]; then
|
if [ -n "$VALGRIND" ]; then
|
||||||
SUPP=../share/ubuntu-12_04.supp
|
SUPP=../share/ubuntu-12_04.supp
|
||||||
SERVER="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no $SERVER"
|
VALGRIND="$VALGRIND --suppressions=$SUPP --error-exitcode=1 --leak-check=no"
|
||||||
fi
|
fi
|
||||||
|
echo "running $TESTS"
|
||||||
|
$VALGRIND $TESTS
|
||||||
echo "running $SERVER"
|
echo "running $SERVER"
|
||||||
$SERVER -t 184 ../scripts/reports.lua
|
$VALGRIND $SERVER -t 184 ../scripts/reports.lua
|
||||||
[ -d reports ] || quit 4 "no reports directory created"
|
[ -d reports ] || quit 4 "no reports directory created"
|
||||||
CRFILE=184-zvto.cr
|
CRFILE=184-zvto.cr
|
||||||
grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions"
|
grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions"
|
||||||
|
|
Loading…
Reference in a new issue