From 0bd1a8d6f49886c01d705c7518590b9e223e3bfa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2015 17:50:10 +0100 Subject: [PATCH] add a utility function to test for message types. --- src/give.test.c | 6 +++--- src/kernel/curse.test.c | 4 ++-- src/tests.c | 12 ++++++++++++ src/tests.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/give.test.c b/src/give.test.c index f4d929c31..5437dfa5b 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -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(); } diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 5ac34c479..d152061de 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -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(); } diff --git a/src/tests.c b/src/tests.c index 79ff5ad38..499e9883d 100644 --- a/src/tests.c +++ b/src/tests.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -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; +} + diff --git a/src/tests.h b/src/tests.h index 5a565076f..6bb1071df 100644 --- a/src/tests.h +++ b/src/tests.h @@ -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 }