diff --git a/src/give.test.c b/src/give.test.c index b79214040..a81278edd 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -5,12 +5,14 @@ #include #include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -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); diff --git a/src/kernel/messages.c b/src/kernel/messages.c index d5e1289bb..ea45bc835 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -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)