add a utility function to test for message types.

This commit is contained in:
Enno Rehling 2015-01-12 17:50:10 +01:00
parent 798b3d6ad6
commit 0bd1a8d6f4
4 changed files with 18 additions and 5 deletions

View File

@ -106,7 +106,7 @@ static void test_give_men_none(CuTest * tc) {
env.f2 = env.f1 = test_create_faction(0);
setup_give(&env);
msg = give_men(0, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "error96", (const char *)msg->parameters[3].v);
CuAssertStrEquals(tc, "error96", test_get_messagetype(msg));
CuAssertIntEquals(tc, 1, env.dst->number);
CuAssertIntEquals(tc, 1, env.src->number);
test_cleanup();
@ -137,7 +137,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
env.f2 = test_create_faction(0);
setup_give(&env);
msg = give_men(1, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "feedback_no_contact", (const char *)msg->parameters[3].v);
CuAssertStrEquals(tc, "feedback_no_contact", test_get_messagetype(msg));
CuAssertIntEquals(tc, 1, env.dst->number);
CuAssertIntEquals(tc, 1, env.src->number);
test_cleanup();
@ -150,7 +150,7 @@ static void test_give_men_not_to_self(CuTest * tc) {
env.f2 = env.f1 = test_create_faction(0);
setup_give(&env);
msg = give_men(1, env.src, env.src, NULL);
CuAssertStrEquals(tc, "error10", (const char *)msg->parameters[3].v);
CuAssertStrEquals(tc, "error10", test_get_messagetype(msg));
CuAssertIntEquals(tc, 1, env.src->number);
test_cleanup();
}

View File

@ -45,7 +45,7 @@ static void test_magicstreet(CuTest *tc) {
setup_curse(&fix, "magicstreet");
fix.c->duration = 3;
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
CuAssertStrEquals(tc, "curseinfo::magicstreet", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "curseinfo::magicstreet", test_get_messagetype(msg));
msg_release(msg);
test_cleanup();
}
@ -56,7 +56,7 @@ static void test_magicstreet_warning(CuTest *tc) {
setup_curse(&fix, "magicstreet");
fix.c->duration = 2;
msg = fix.c->type->curseinfo(fix.r, TYP_REGION, fix.c, 0);
CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "curseinfo::magicstreetwarn", test_get_messagetype(msg));
msg_release(msg);
test_cleanup();
}

View File

@ -16,6 +16,7 @@
#include <kernel/terrain.h>
#include <util/functions.h>
#include <util/language.h>
#include <util/message.h>
#include <util/log.h>
#include <assert.h>
@ -192,3 +193,14 @@ void test_create_world(void)
test_create_shiptype("boat");
}
const char * test_get_messagetype(const message *msg) {
const char * name = msg->type->name;
if (strcmp(name, "missing_message") == 0) {
name = (const char *)msg->parameters[0].v;
}
else if (strcmp(name, "missing_feedback") == 0) {
name = (const char *)msg->parameters[3].v;
}
return name;
}

View File

@ -35,6 +35,7 @@ extern "C" {
int RunAllTests(void);
void test_translate_param(const struct locale *lang, param_t param, const char *text);
const char * test_get_messagetype(const struct message *msg);
#ifdef __cplusplus
}