Merge pull request #557 from ennorehling/develop

clear up some memory leaks in tests
This commit is contained in:
Enno Rehling 2016-09-06 21:25:41 +01:00 committed by GitHub
commit 927e41add6
4 changed files with 17 additions and 15 deletions

View File

@ -288,7 +288,7 @@ static void perform_join(void)
static syntaxtree * build_syntax(void) { static syntaxtree * build_syntax(void) {
syntaxtree *slang, *stree = stree_create(); syntaxtree *slang, *stree = stree_create();
for (slang = stree; slang; slang = slang->next) { for (slang = stree; slang; slang = slang->next) {
void *leaf = 0; struct tnode *leaf = 0;
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_KICK]), &cmd_kick); add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_KICK]), &cmd_kick);
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_LEAVE]), &cmd_leave); add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_LEAVE]), &cmd_leave);
add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_TRANSFER]), &cmd_transfer); add_command(&leaf, NULL, LOC(slang->lang, alliance_kwd[ALLIANCE_TRANSFER]), &cmd_transfer);

View File

@ -68,7 +68,7 @@ syntaxtree *stree_create(void)
} }
void void
add_command(void **keys, void *tnext, add_command(struct tnode **keys, void *tnext,
const char *str, parser fun) const char *str, parser fun)
{ {
command *cmd = (command *)malloc(sizeof(command)); command *cmd = (command *)malloc(sizeof(command));
@ -78,10 +78,10 @@ const char *str, parser fun)
cmd->fun = fun; cmd->fun = fun;
cmd->nodes = tnext; cmd->nodes = tnext;
var.v = cmd; var.v = cmd;
addtoken((struct tnode **)keys, str, var); addtoken(keys, str, var);
} }
static int do_command_i(const void *keys, struct unit *u, struct order *ord) static int do_command_i(const struct tnode *keys, struct unit *u, struct order *ord)
{ {
char token[128]; char token[128];
const char *c; const char *c;
@ -102,7 +102,7 @@ static int do_command_i(const void *keys, struct unit *u, struct order *ord)
return E_TOK_NOMATCH; return E_TOK_NOMATCH;
} }
void do_command(const void *keys, struct unit *u, struct order *ord) void do_command(const struct tnode *keys, struct unit *u, struct order *ord)
{ {
init_order(ord); init_order(ord);
if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) { if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) {

View File

@ -19,17 +19,18 @@ extern "C" {
struct locale; struct locale;
struct order; struct order;
struct unit; struct unit;
struct tnode;
typedef struct syntaxtree { typedef struct syntaxtree {
const struct locale *lang; const struct locale *lang;
void *root; struct tnode *root;
struct syntaxtree *next; struct syntaxtree *next;
} syntaxtree; } syntaxtree;
typedef void(*parser) (const void *nodes, struct unit * u, struct order *); typedef void(*parser) (const void *nodes, struct unit * u, struct order *);
void add_command(void **troot, void *tnext, void add_command(struct tnode **troot, void *tnext,
const char *str, parser fun); const char *str, parser fun);
void do_command(const void *troot, struct unit *u, struct order *); void do_command(const struct tnode *troot, struct unit *u, struct order *);
struct syntaxtree *stree_create(void); struct syntaxtree *stree_create(void);
void stree_free(struct syntaxtree *); void stree_free(struct syntaxtree *);

View File

@ -21,7 +21,7 @@ static void test_read_unitid(CuTest *tc) {
struct locale *lang; struct locale *lang;
struct terrain_type *t_plain; struct terrain_type *t_plain;
test_cleanup(); test_setup();
lang = test_create_locale(); lang = test_create_locale();
/* note that the english order is FIGHT, not COMBAT, so this is a poor example */ /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
t_plain = test_create_terrain("plain", LAND_REGION); t_plain = test_create_terrain("plain", LAND_REGION);
@ -66,7 +66,7 @@ static void test_getunit(CuTest *tc) {
struct locale *lang; struct locale *lang;
struct terrain_type *t_plain; struct terrain_type *t_plain;
test_cleanup(); test_setup();
lang = test_create_locale(); lang = test_create_locale();
/* note that the english order is FIGHT, not COMBAT, so this is a poor example */ /* note that the english order is FIGHT, not COMBAT, so this is a poor example */
t_plain = test_create_terrain("plain", LAND_REGION); t_plain = test_create_terrain("plain", LAND_REGION);
@ -122,7 +122,7 @@ static void test_getunit(CuTest *tc) {
static void test_get_set_param(CuTest * tc) static void test_get_set_param(CuTest * tc)
{ {
struct param *par = 0; struct param *par = 0;
test_cleanup(); test_setup();
CuAssertStrEquals(tc, 0, get_param(par, "foo")); CuAssertStrEquals(tc, 0, get_param(par, "foo"));
set_param(&par, "foo", "bar"); set_param(&par, "foo", "bar");
set_param(&par, "bar", "foo"); set_param(&par, "bar", "foo");
@ -139,7 +139,7 @@ static void test_get_set_param(CuTest * tc)
static void test_param_int(CuTest * tc) static void test_param_int(CuTest * tc)
{ {
struct param *par = 0; struct param *par = 0;
test_cleanup(); test_setup();
CuAssertIntEquals(tc, 13, get_param_int(par, "foo", 13)); CuAssertIntEquals(tc, 13, get_param_int(par, "foo", 13));
set_param(&par, "foo", "23"); set_param(&par, "foo", "23");
set_param(&par, "bar", "42"); set_param(&par, "bar", "42");
@ -152,7 +152,7 @@ static void test_param_int(CuTest * tc)
static void test_param_flt(CuTest * tc) static void test_param_flt(CuTest * tc)
{ {
struct param *par = 0; struct param *par = 0;
test_cleanup(); test_setup();
CuAssertDblEquals(tc, 13, get_param_flt(par, "foo", 13), 0.01); CuAssertDblEquals(tc, 13, get_param_flt(par, "foo", 13), 0.01);
set_param(&par, "foo", "23.0"); set_param(&par, "foo", "23.0");
set_param(&par, "bar", "42.0"); set_param(&par, "bar", "42.0");
@ -176,16 +176,17 @@ static void test_default_order(CuTest *tc) {
order *ord; order *ord;
struct locale * loc; struct locale * loc;
test_cleanup(); test_setup();
loc = test_create_locale(); loc = test_create_locale();
ord = default_order(loc); ord = default_order(loc);
CuAssertPtrEquals(tc, 0, ord); CuAssertPtrEquals(tc, 0, ord);
free_order(ord);
config_set("orders.default", "work"); config_set("orders.default", "work");
ord = default_order(loc); ord = default_order(loc);
CuAssertPtrNotNull(tc, ord); CuAssertPtrNotNull(tc, ord);
CuAssertIntEquals(tc, K_WORK, getkeyword(ord)); CuAssertIntEquals(tc, K_WORK, getkeyword(ord));
CuAssertPtrEquals(tc, ord->data, default_order(loc)->data); free_order(ord);
test_cleanup(); test_cleanup();
} }