backfill missing tests for ally_cmd

This commit is contained in:
Enno Rehling 2015-08-05 12:19:17 +02:00
parent 91efc30afd
commit 8efc874952
5 changed files with 76 additions and 5 deletions

View File

@ -919,6 +919,10 @@ static const char * parameter_key(int i)
return parameters[i];
}
void init_parameters(struct locale *lang) {
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
}
void init_terrains_translation(const struct locale *lang) {
void **tokens;
@ -1009,7 +1013,7 @@ void init_locale(struct locale *lang)
if (name) addtoken(tokens, name, var);
}
init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS);
init_parameters(lang);
init_options_translation(lang);
init_terrains_translation(lang);

View File

@ -291,6 +291,7 @@ extern "C" {
void set_default_order(int kwd);
int entertainmoney(const struct region *r);
void init_parameters(struct locale *lang);
void free_gamedata(void);

View File

@ -285,8 +285,9 @@ extern unsigned int new_hashstring(const char *s);
void free_messagelist(message_list * msgs)
{
struct mlist **mlistptr = &msgs->begin;
while (*mlistptr) {
struct mlist **mlistptr;
assert(msgs && msgs->begin);
for (mlistptr = &msgs->begin; *mlistptr;) {
struct mlist *ml = *mlistptr;
*mlistptr = ml->next;
msg_release(ml->msg);

View File

@ -1347,10 +1347,12 @@ int ally_cmd(unit * u, struct order *ord)
s = gettoken(token, sizeof(token));
if (s && !s[0])
if (!s || !s[0]) {
keyword = P_ANY;
else
}
else {
keyword = findparam(s, u->faction->locale);
}
sfp = &u->faction->allies;
if (fval(u, UFL_GROUP)) {

View File

@ -1,6 +1,7 @@
#include <platform.h>
#include "laws.h"
#include "battle.h"
#include "monster.h"
#include <kernel/ally.h>
#include <kernel/config.h>
@ -913,9 +914,71 @@ static void test_long_order_hungry(CuTest *tc) {
test_cleanup();
}
static void test_ally_cmd_errors(CuTest *tc) {
unit *u;
int fid;
order *ord;
test_cleanup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
u->faction->locale = get_or_create_locale("de");
fid = u->faction->no + 1;
CuAssertPtrEquals(tc, 0, findfaction(fid));
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
ally_cmd(u, ord);
CuAssertStrEquals(tc, "error66", test_get_messagetype(u->faction->msgs->begin->msg));
free_order(ord);
test_cleanup();
}
static void test_ally_cmd(CuTest *tc) {
unit *u;
faction * f;
order *ord;
struct locale *lang;
test_cleanup();
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
f = test_create_faction(0);
u->faction->locale = lang = get_or_create_locale("de");
locale_setstring(lang, parameters[P_NOT], "NICHT");
locale_setstring(lang, parameters[P_GUARD], "BEWACHE");
init_parameters(lang);
ord = create_order(K_ALLY, lang, "%s", itoa36(f->no));
ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord);
ord = create_order(K_ALLY, lang, "%s NICHT", itoa36(f->no));
ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord);
ord = create_order(K_ALLY, lang, "%s BEWACHE", itoa36(f->no));
ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord);
ord = create_order(K_ALLY, lang, "%s BEWACHE NICHT", itoa36(f->no));
ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs);
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord);
test_cleanup();
}
CuSuite *get_laws_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_ally_cmd);
SUITE_ADD_TEST(suite, test_ally_cmd_errors);
SUITE_ADD_TEST(suite, test_long_order_normal);
SUITE_ADD_TEST(suite, test_long_order_none);
SUITE_ADD_TEST(suite, test_long_order_cast);