forked from github/server
leak: teardown build tests, free construction data
This commit is contained in:
parent
f4f038c23c
commit
377b0d0305
|
@ -45,6 +45,11 @@ static unit * setup_build(build_fixture *bf) {
|
||||||
return bf->u;
|
return bf->u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void teardown_build(build_fixture *bf) {
|
||||||
|
free(bf->cons.materials);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_build_requires_materials(CuTest *tc) {
|
static void test_build_requires_materials(CuTest *tc) {
|
||||||
build_fixture bf = { 0 };
|
build_fixture bf = { 0 };
|
||||||
unit *u;
|
unit *u;
|
||||||
|
@ -57,7 +62,7 @@ static void test_build_requires_materials(CuTest *tc) {
|
||||||
i_change(&u->items, itype, 2);
|
i_change(&u->items, itype, 2);
|
||||||
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||||
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
|
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_requires_building(CuTest *tc) {
|
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));
|
CuAssertIntEquals(tc, 1, build(u, &bf.cons, 0, 1));
|
||||||
btype->maxcapacity = 0;
|
btype->maxcapacity = 0;
|
||||||
CuAssertIntEquals_Msg(tc, "cannot build when production building capacity exceeded", EBUILDINGREQ, build(u, &bf.cons, 0, 1));
|
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) {
|
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;
|
rtype = bf.cons.materials[0].rtype;
|
||||||
i_change(&u->items, rtype->itype, 1);
|
i_change(&u->items, rtype->itype, 1);
|
||||||
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1));
|
CuAssertIntEquals(tc, ENEEDSKILL, build(u, &bf.cons, 1, 1));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_failure_low_skill(CuTest *tc) {
|
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);
|
i_change(&u->items, rtype->itype, 1);
|
||||||
set_level(u, SK_ARMORER, bf.cons.minskill - 1);
|
set_level(u, SK_ARMORER, bf.cons.minskill - 1);
|
||||||
CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10));
|
CuAssertIntEquals(tc, ELOWSKILL, build(u, &bf.cons, 0, 10));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_failure_completed(CuTest *tc) {
|
static void test_build_failure_completed(CuTest *tc) {
|
||||||
|
@ -119,7 +124,7 @@ static void test_build_failure_completed(CuTest *tc) {
|
||||||
bf.cons.maxsize = 1;
|
bf.cons.maxsize = 1;
|
||||||
CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10));
|
CuAssertIntEquals(tc, ECOMPLETE, build(u, &bf.cons, bf.cons.maxsize, 10));
|
||||||
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
|
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_limits(CuTest *tc) {
|
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);
|
i_change(&u->items, rtype->itype, 4);
|
||||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 10));
|
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 10));
|
||||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_with_ring(CuTest *tc) {
|
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);
|
i_change(&u->items, ring, 1);
|
||||||
CuAssertIntEquals(tc, 10, build(u, &bf.cons, 0, 20));
|
CuAssertIntEquals(tc, 10, build(u, &bf.cons, 0, 20));
|
||||||
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
|
CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_with_potion(CuTest *tc) {
|
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, get_effect(u, ptype));
|
||||||
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
CuAssertIntEquals(tc, 4, build(u, &bf.cons, 0, 20));
|
||||||
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
CuAssertIntEquals(tc, 2, get_effect(u, ptype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_building_no_materials(CuTest *tc) {
|
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));
|
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders));
|
||||||
CuAssertPtrEquals(tc, 0, u->region->buildings);
|
CuAssertPtrEquals(tc, 0, u->region->buildings);
|
||||||
CuAssertPtrEquals(tc, 0, u->building);
|
CuAssertPtrEquals(tc, 0, u->building);
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_building_with_golem(CuTest *tc) {
|
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);
|
CuAssertPtrNotNull(tc, u->region->buildings);
|
||||||
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
CuAssertIntEquals(tc, 1, u->region->buildings->size);
|
||||||
CuAssertIntEquals(tc, 0, u->number);
|
CuAssertIntEquals(tc, 0, u->number);
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_build_building_success(CuTest *tc) {
|
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);
|
CuAssertPtrEquals(tc, u->region->buildings, u->building);
|
||||||
CuAssertIntEquals(tc, 1, u->building->size);
|
CuAssertIntEquals(tc, 1, u->building->size);
|
||||||
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
CuAssertIntEquals(tc, 0, i_get(u->items, rtype->itype));
|
||||||
test_cleanup();
|
teardown_build(&bf);
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_build_suite(void)
|
CuSuite *get_build_suite(void)
|
||||||
|
|
Loading…
Reference in New Issue