Merge pull request #376 from ennorehling/develop

fix test bugs detected by valgrind
This commit is contained in:
Enno Rehling 2015-11-07 18:49:52 +01:00
commit 251afca68f
4 changed files with 32 additions and 18 deletions

View File

@ -1022,23 +1022,32 @@ static void vampirism(troop at, int damage)
}
}
#define MAXRACES 128
static int natural_armor(unit * du)
{
static int *bonus = 0;
int an = u_race(du)->armor;
if (bonus == 0) {
assert(num_races > 0);
bonus = calloc((size_t)num_races, sizeof(int));
static int cookie = -1;
static int bonus[MAXRACES];
const race *rc = u_race(du);
int index, an = rc->armor;
assert(rc);
if (cookie!=global.cookie) {
cookie = global.cookie;
memset(bonus, 0, sizeof(bonus));
}
if (bonus[u_race(du)->index] == 0) {
bonus[u_race(du)->index] =
get_param_int(u_race(du)->parameters, "armor.stamina", -1);
if (bonus[u_race(du)->index] == 0)
bonus[u_race(du)->index] = -1;
assert(num_races < MAXRACES);
index = rc->index;
assert(index >= 0 && index < num_races);
if (bonus[index] == 0) {
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);
sk /= bonus[u_race(du)->index];
sk /= bonus[index];
an += sk;
}
return an;

View File

@ -146,6 +146,7 @@ void free_races(void) {
free(races);
races = rc;
}
num_races = 0;
}
static race *rc_find_i(const char *name)

View File

@ -26,13 +26,13 @@ static void test_flyingship(CuTest * tc)
ship_type *shipType1, *shipType2;
ship *sh1, *sh2;
test_cleanup();
par.param = &par_data_ptr;
par_data.typ = SPP_SHIP;
par_data.flag = 0;
test_cleanup();
test_create_world();
r = findregion(0, 0);
r = test_create_region(0, 0, 0);
f = test_create_faction(test_create_race("human"));
u = test_create_unit(f, r);
@ -57,6 +57,7 @@ static void test_flyingship(CuTest * tc)
CuAssertTrue(tc, !flying_ship(sh2));
CuAssertIntEquals(tc, 0, sp_flying_ship(&co));
CuAssertTrue(tc, !flying_ship(sh2));
test_cleanup();
}
CuSuite *get_flyingship_suite(void)

View File

@ -21,13 +21,16 @@ cd $ROOT/tests
setup
cleanup
VALGRIND=`which valgrind`
TESTS=../Debug/eressea/test_eressea
SERVER=../Debug/eressea/eressea
if [ -n "$VALGRIND" ]; then
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
echo "running $TESTS"
$VALGRIND $TESTS
echo "running $SERVER"
$SERVER -t 184 ../scripts/reports.lua
$VALGRIND $SERVER -t 184 ../scripts/reports.lua
[ -d reports ] || quit 4 "no reports directory created"
CRFILE=184-zvto.cr
grep -q PARTEI reports/$CRFILE || quit 1 "CR did not contain any factions"