fix memory leaks in all tests that create an order without calling free_order at the end.

This commit is contained in:
Enno Rehling 2015-10-13 15:45:38 +02:00
parent 96be12218e
commit 7854684d8b
8 changed files with 29 additions and 12 deletions

View File

@ -141,14 +141,12 @@ static struct unit *create_recruiter(void) {
static void test_heroes_dont_recruit(CuTest * tc) { static void test_heroes_dont_recruit(CuTest * tc) {
unit *u; unit *u;
order *ord;
test_cleanup(); test_cleanup();
u = create_recruiter(); u = create_recruiter();
fset(u, UFL_HERO); fset(u, UFL_HERO);
ord = create_order(K_RECRUIT, default_locale, "1"); unit_addorder(u, create_order(K_RECRUIT, default_locale, "1"));
unit_addorder(u, ord);
economics(u->region); economics(u->region);
@ -160,13 +158,11 @@ static void test_heroes_dont_recruit(CuTest * tc) {
static void test_normals_recruit(CuTest * tc) { static void test_normals_recruit(CuTest * tc) {
unit *u; unit *u;
order *ord;
test_cleanup(); test_cleanup();
u = create_recruiter(); u = create_recruiter();
ord = create_order(K_RECRUIT, default_locale, "1"); unit_addorder(u, create_order(K_RECRUIT, default_locale, "1"));
unit_addorder(u, ord);
economics(u->region); economics(u->region);

View File

@ -217,6 +217,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -290,6 +291,7 @@ static void test_give_herbs(CuTest * tc) {
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype)); CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype));
CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype)); CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -342,6 +344,7 @@ static void test_give_invalid_target(CuTest *tc) {
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertIntEquals(tc, 10, i_get(env.src->items, env.itype)); CuAssertIntEquals(tc, 10, i_get(env.src->items, env.itype));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_unit_not_found")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_unit_not_found"));
free_order(ord);
test_cleanup(); test_cleanup();
} }

View File

@ -577,6 +577,7 @@ static void test_infinitive_from_config(CuTest *tc) {
ord = create_order(K_STUDY, lang, ""); ord = create_order(K_STUDY, lang, "");
CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer))); CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer)));
free_order(ord);
test_cleanup(); test_cleanup();
} }

View File

@ -123,6 +123,7 @@ static void test_init_order(CuTest *tc) {
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
CuAssertStrEquals(tc, "hurr", getstrtoken()); CuAssertStrEquals(tc, "hurr", getstrtoken());
CuAssertStrEquals(tc, "durr", getstrtoken()); CuAssertStrEquals(tc, "durr", getstrtoken());
free_order(ord);
} }
static void test_getstrtoken(CuTest *tc) { static void test_getstrtoken(CuTest *tc) {

View File

@ -35,6 +35,7 @@ static void test_infinitive(CuTest *tc) {
ord = create_order(K_STUDY, lang, ""); ord = create_order(K_STUDY, lang, "");
CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer))); CuAssertStrEquals(tc, "LERNE", get_command(ord, buffer, sizeof(buffer)));
free_order(ord);
test_cleanup(); test_cleanup();
} }

View File

@ -467,6 +467,7 @@ static void test_reserve_cmd(CuTest *tc) {
CuAssertIntEquals(tc, 200, reserve_cmd(u1, ord)); CuAssertIntEquals(tc, 200, reserve_cmd(u1, ord));
CuAssertIntEquals(tc, 200, i_get(u1->items, rtype->itype)); CuAssertIntEquals(tc, 200, i_get(u1->items, rtype->itype));
CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype)); CuAssertIntEquals(tc, 0, i_get(u2->items, rtype->itype));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -517,6 +518,7 @@ static void test_pay_cmd(CuTest *tc) {
assert(ord); assert(ord);
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));
CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY); CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY);
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -541,6 +543,7 @@ static void test_pay_cmd_other_building(CuTest *tc) {
CuAssertPtrEquals(tc, fix.u1, building_owner(b)); CuAssertPtrEquals(tc, fix.u1, building_owner(b));
CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u1, ord));
CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY); CuAssertIntEquals(tc, BLD_DONTPAY, b->flags&BLD_DONTPAY);
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -559,6 +562,7 @@ static void test_pay_cmd_must_be_owner(CuTest *tc) {
assert(ord); assert(ord);
CuAssertIntEquals(tc, 0, pay_cmd(fix.u2, ord)); CuAssertIntEquals(tc, 0, pay_cmd(fix.u2, ord));
CuAssertIntEquals(tc, 0, b->flags&BLD_DONTPAY); CuAssertIntEquals(tc, 0, b->flags&BLD_DONTPAY);
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -566,8 +570,8 @@ static void test_new_units(CuTest *tc) {
unit *u; unit *u;
faction *f; faction *f;
region *r; region *r;
order *ord;
const struct locale *loc; const struct locale *loc;
test_cleanup(); test_cleanup();
test_create_world(); test_create_world();
f = test_create_faction(NULL); f = test_create_faction(NULL);
@ -577,9 +581,7 @@ static void test_new_units(CuTest *tc) {
assert(u && !u->next); assert(u && !u->next);
loc = get_locale("de"); loc = get_locale("de");
assert(loc); assert(loc);
ord = create_order(K_MAKETEMP, loc, "hurr"); u->orders = create_order(K_MAKETEMP, loc, "hurr");
assert(ord);
u->orders = ord;
new_units(); new_units();
CuAssertPtrNotNull(tc, u->next); CuAssertPtrNotNull(tc, u->next);
test_cleanup(); test_cleanup();
@ -708,6 +710,7 @@ static void test_reserve_self(CuTest *tc) {
CuAssertIntEquals(tc, 100, reserve_self(u1, ord)); CuAssertIntEquals(tc, 100, reserve_self(u1, ord));
CuAssertIntEquals(tc, 100, i_get(u1->items, rtype->itype)); CuAssertIntEquals(tc, 100, i_get(u1->items, rtype->itype));
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype)); CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -879,13 +882,13 @@ static void test_long_order_normal(CuTest *tc) {
// TODO: write more tests // TODO: write more tests
unit *u; unit *u;
order *ord; order *ord;
test_cleanup(); test_cleanup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
fset(u, UFL_MOVED); fset(u, UFL_MOVED);
fset(u, UFL_LONGACTION); fset(u, UFL_LONGACTION);
u->faction->locale = get_or_create_locale("de"); u->faction->locale = get_or_create_locale("de");
ord = create_order(K_MOVE, u->faction->locale, 0); unit_addorder(u, ord = create_order(K_MOVE, u->faction->locale, 0));
unit_addorder(u, ord);
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, ord->data, u->thisorder->data); CuAssertPtrEquals(tc, ord->data, u->thisorder->data);
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED)); CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
@ -1121,6 +1124,7 @@ static void test_mail_unit(CuTest *tc) {
ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no)); ord = create_order(K_MAIL, u->faction->locale, "EINHEIT %s 'Hodor!'", itoa36(u->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "unitmessage")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "unitmessage"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1132,6 +1136,7 @@ static void test_mail_faction(CuTest *tc) {
ord = create_order(K_MAIL, u->faction->locale, "PARTEI %s 'Hodor!'", itoa36(u->faction->no)); ord = create_order(K_MAIL, u->faction->locale, "PARTEI %s 'Hodor!'", itoa36(u->faction->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "regionmessage")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "regionmessage"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1143,6 +1148,7 @@ static void test_mail_region(CuTest *tc) {
ord = create_order(K_MAIL, u->faction->locale, "REGION 'Hodor!'", itoa36(u->no)); ord = create_order(K_MAIL, u->faction->locale, "REGION 'Hodor!'", itoa36(u->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(u->region->msgs, "mail_result")); CuAssertPtrNotNull(tc, test_find_messagetype(u->region->msgs, "mail_result"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1155,6 +1161,7 @@ static void test_mail_unit_no_msg(CuTest *tc) {
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "unitmessage")); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "unitmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1167,6 +1174,7 @@ static void test_mail_faction_no_msg(CuTest *tc) {
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage")); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1179,6 +1187,7 @@ static void test_mail_faction_no_target(CuTest *tc) {
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage")); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "regionmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error66")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error66"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -1191,6 +1200,7 @@ static void test_mail_region_no_msg(CuTest *tc) {
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result")); CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result"));
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error30"));
free_order(ord);
test_cleanup(); test_cleanup();
} }

View File

@ -61,6 +61,7 @@ static void test_piracy_cmd(CuTest * tc) {
CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); // FIXME: this is testing implementation, not interface CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); // FIXME: this is testing implementation, not interface
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim")); CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim"));
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail")); CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -93,6 +94,7 @@ static void test_piracy_cmd_errors(CuTest * tc) {
test_clear_messages(f); test_clear_messages(f);
piracy_cmd(u, ord); piracy_cmd(u, ord);
CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim")); CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
free_order(ord);
test_cleanup(); test_cleanup();
} }

View File

@ -110,6 +110,7 @@ static void test_sabotage_self(CuTest *tc) {
assert(ord); assert(ord);
CuAssertIntEquals(tc, 0, sabotage_cmd(u, ord)); CuAssertIntEquals(tc, 0, sabotage_cmd(u, ord));
CuAssertPtrEquals(tc, 0, r->ships); CuAssertPtrEquals(tc, 0, r->ships);
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -139,6 +140,7 @@ static void test_sabotage_other_fail(CuTest *tc) {
msg = test_get_last_message(u->faction->msgs); msg = test_get_last_message(u->faction->msgs);
CuAssertStrEquals(tc, "destroy_ship_3", test_get_messagetype(msg)); CuAssertStrEquals(tc, "destroy_ship_3", test_get_messagetype(msg));
CuAssertPtrNotNull(tc, r->ships); CuAssertPtrNotNull(tc, r->ships);
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -164,6 +166,7 @@ static void test_sabotage_other_success(CuTest *tc) {
set_level(u2, SK_SPY, 1); set_level(u2, SK_SPY, 1);
CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord)); CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord));
CuAssertPtrEquals(tc, 0, r->ships); CuAssertPtrEquals(tc, 0, r->ships);
free_order(ord);
test_cleanup(); test_cleanup();
} }