Merge pull request #286 from ennorehling/feature/bug-1818-give-unit-tests

Backfill missing tests for Bug 1818.
This commit is contained in:
Enno Rehling 2015-09-07 15:30:06 +02:00
commit 8fb118c1bb
2 changed files with 44 additions and 17 deletions

View File

@ -5,12 +5,14 @@
#include <kernel/ally.h>
#include <kernel/config.h>
#include <kernel/item.h>
#include <kernel/terrain.h>
#include <kernel/region.h>
#include <kernel/order.h>
#include <kernel/unit.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/messages.h>
#include <kernel/order.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
#include <util/base36.h>
#include <util/language.h>
@ -30,8 +32,21 @@ struct give {
static void setup_give(struct give *env) {
struct terrain_type *ter = test_create_terrain("plain", LAND_REGION);
struct locale *lang;
race *rc;
assert(env->f1);
rc = test_create_race(env->f1->race ? env->f1->race->_name : "humon");
rc->ec_flags |= GIVEPERSON;
lang = get_or_create_locale(env->f1->locale ? locale_name(env->f1->locale) : "test");
env->f1->locale = lang;
locale_setstring(lang, "ALLES", "ALLES");
locale_setstring(lang, "PERSONEN", "PERSONEN");
locale_setstring(lang, "KRAEUTER", "KRAUT");
init_locale(lang);
env->r = test_create_region(0, 0, ter);
env->src = env->f1 ? test_create_unit(env->f1, env->r) : 0;
env->src = test_create_unit(env->f1, env->r);
env->dst = env->f2 ? test_create_unit(env->f2, env->r) : 0;
env->itype = it_get_or_create(rt_get_or_create("money"));
env->itype->flags |= ITF_HERB;
@ -185,6 +200,8 @@ static void test_give_men_other_faction(CuTest * tc) {
static void test_give_men_requires_contact(CuTest * tc) {
struct give env;
message * msg;
order *ord;
char cmd[32];
test_cleanup();
env.f1 = test_create_faction(0);
@ -194,6 +211,15 @@ static void test_give_men_requires_contact(CuTest * tc) {
CuAssertStrEquals(tc, "feedback_no_contact", test_get_messagetype(msg));
CuAssertIntEquals(tc, 1, env.dst->number);
CuAssertIntEquals(tc, 1, env.src->number);
_snprintf(cmd, sizeof(cmd), "%s ALLES PERSONEN", itoa36(env.dst->no));
ord = create_order(K_GIVE, env.f1->locale, cmd);
free_messagelist(env.f1->msgs);
env.f1->msgs = 0;
give_cmd(env.src, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
test_cleanup();
}
@ -257,9 +283,9 @@ static void test_give_herbs(CuTest * tc) {
lang = get_or_create_locale("test");
env.f1->locale = lang;
locale_setstring(lang, "KRAEUTER", "HERBS");
locale_setstring(lang, "KRAEUTER", "KRAUT");
init_locale(lang);
_snprintf(cmd, sizeof(cmd), "%s HERBS", itoa36(env.dst->no));
_snprintf(cmd, sizeof(cmd), "%s KRAUT", itoa36(env.dst->no));
ord = create_order(K_GIVE, lang, cmd);
assert(ord);
@ -310,9 +336,9 @@ static void test_give_invalid_target(CuTest *tc) {
i_change(&env.src->items, env.itype, 10);
lang = get_or_create_locale("test");
env.f1->locale = lang;
locale_setstring(lang, "KRAEUTER", "HERBS");
locale_setstring(lang, "KRAEUTER", "KRAUT");
init_locale(lang);
ord = create_order(K_GIVE, lang, "## HERBS");
ord = create_order(K_GIVE, lang, "## KRAUT");
assert(ord);
give_cmd(env.src, ord);

View File

@ -286,14 +286,15 @@ extern unsigned int new_hashstring(const char *s);
void free_messagelist(message_list * msgs)
{
struct mlist **mlistptr;
assert(msgs && msgs->begin);
for (mlistptr = &msgs->begin; *mlistptr;) {
struct mlist *ml = *mlistptr;
*mlistptr = ml->next;
msg_release(ml->msg);
free(ml);
if (msgs) {
for (mlistptr = &msgs->begin; *mlistptr;) {
struct mlist *ml = *mlistptr;
*mlistptr = ml->next;
msg_release(ml->msg);
free(ml);
}
free(msgs);
}
free(msgs);
}
message *add_message(message_list ** pm, message * m)