leak: teardown build tests, free construction data

This commit is contained in:
Enno Rehling 2015-10-13 23:09:50 +02:00
parent f4f038c23c
commit 377b0d0305
1 changed files with 16 additions and 11 deletions

View File

@ -45,6 +45,11 @@ static unit * setup_build(build_fixture *bf) {
return bf->u;
}
static void teardown_build(build_fixture *bf) {
free(bf->cons.materials);
test_cleanup();
}
static void test_build_requires_materials(CuTest *tc) {
build_fixture bf = { 0 };
unit *u;
@ -57,7 +62,7 @@ static void test_build_requires_materials(CuTest *tc) {
i_change(&u->items, itype, 2);
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
test_cleanup();
teardown_build(&bf);
}
static void test_build_requires_building(CuTest *tc) {
@ -79,7 +84,7 @@ static void test_build_requires_building(CuTest *tc) {
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
btype->maxcapacity = 0;
CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
test_cleanup();
teardown_build(&bf);
}
static void test_build_failure_missing_skill(CuTest *tc) {
@ -91,7 +96,7 @@ static void test_build_failure_missing_skill(CuTest *tc) {
rtype = bf.cons.materials[0].rtype;
i_change(&u->items, rtype->itype, 1);
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1));
test_cleanup();
teardown_build(&bf);
}
static void test_build_failure_low_skill(CuTest *tc) {
@ -104,7 +109,7 @@ static void test_build_failure_low_skill(CuTest *tc) {
i_change(&u->items, rtype->itype, 1);
set_level(u, SK_ARMORER, bf.cons.minskill - 1);
CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10));
test_cleanup();
teardown_build(&bf);
}
static void test_build_failure_completed(CuTest *tc) {
@ -119,7 +124,7 @@ static void test_build_failure_completed(CuTest *tc) {
bf.cons.maxsize = 1;
CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10));
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
test_cleanup();
teardown_build(&bf);
}
static void test_build_limits(CuTest *tc) {
@ -145,7 +150,7 @@ static void test_build_limits(CuTest *tc) {
i_change(&u->items, rtype->itype, 4);
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 10));
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
test_cleanup();
teardown_build(&bf);
}
static void test_build_with_ring(CuTest *tc) {
@ -164,7 +169,7 @@ static void test_build_with_ring(CuTest *tc) {
i_change(&u->items, ring, 1);
CuAssertIntEquals(tc, 10, build(u, &bf.cons, 0, 20));
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
test_cleanup();
teardown_build(&bf);
}
static void test_build_with_potion(CuTest *tc) {
@ -192,7 +197,7 @@ static void test_build_with_potion(CuTest *tc) {
CuAssertIntEquals(tc, 4, get_effect(u, ptype));
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
test_cleanup();
teardown_build(&bf);
}
static void test_build_building_no_materials(CuTest *tc) {
@ -208,7 +213,7 @@ static void test_build_building_no_materials(CuTest *tc) {
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders));
CuAssertPtrEquals(tc, 0, u->region->buildings);
CuAssertPtrEquals(tc, 0, u->building);
test_cleanup();
teardown_build(&bf);
}
static void test_build_building_with_golem(CuTest *tc) {
@ -228,7 +233,7 @@ static void test_build_building_with_golem(CuTest *tc) {
CuAssertPtrNotNull(tc, u->region->buildings);
CuAssertIntEquals(tc, 1, u->region->buildings->size);
CuAssertIntEquals(tc, 0, u->number);
test_cleanup();
teardown_build(&bf);
}
static void test_build_building_success(CuTest *tc) {
@ -253,7 +258,7 @@ static void test_build_building_success(CuTest *tc) {
CuAssertPtrEquals(tc, u->region->buildings, u->building);
CuAssertIntEquals(tc, 1, u->building->size);
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
test_cleanup();
teardown_build(&bf);
}
CuSuite *get_build_suite(void)