Temporarily re-enable the missing_message code.

I think we'll want to make this injectable.
Fix the give tests.
This commit is contained in:
Enno Rehling 2018-01-13 22:46:02 +01:00
parent b83a1ee136
commit 84309caad7
3 changed files with 23 additions and 16 deletions

View File

@ -165,7 +165,7 @@ static void test_give_men_magicians(CuTest * tc) {
p = rpeasants(env.r);
CuAssertPtrNotNull(tc, msg = disband_men(1, env.dst, NULL));
CuAssertStrEquals(tc, "give_person_peasants", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "give_person_peasants", test_get_messagetype(msg));
CuAssertIntEquals(tc, 0, env.dst->number);
CuAssertIntEquals(tc, p+1, rpeasants(env.r));
msg_release(msg);
@ -176,6 +176,7 @@ static void test_give_men_magicians(CuTest * tc) {
static void test_give_men_limit(CuTest * tc) {
struct give env = { 0 };
message *msg;
test_setup_ex(tc);
env.f2 = test_create_faction(0);
env.f1 = test_create_faction(0);
@ -185,7 +186,7 @@ static void test_give_men_limit(CuTest * tc) {
/* below the limit, give men, increase newbies counter */
usetcontact(env.dst, env.src);
msg = give_men(1, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, 1, env.f2->newbies);
@ -194,7 +195,7 @@ static void test_give_men_limit(CuTest * tc) {
/* beyond the limit, do nothing */
usetcontact(env.src, env.dst);
msg = give_men(2, env.dst, env.src, NULL);
CuAssertStrEquals(tc, "error129", (const char *)msg->parameters[3].v);
CuAssertStrEquals(tc, "error129", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, 0, env.f1->newbies);
@ -213,7 +214,7 @@ static void test_give_men_in_ocean(CuTest * tc) {
setup_give(&env);
env.r->terrain = test_create_terrain("ocean", SEA_REGION);
msg = disband_men(1, env.src, NULL);
CuAssertStrEquals(tc, "give_person_ocean", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "give_person_ocean", test_get_messagetype(msg));
CuAssertIntEquals(tc, 0, env.src->number);
msg_release(msg);
test_teardown();
@ -270,7 +271,7 @@ static void test_give_men_other_faction(CuTest * tc) {
setup_give(&env);
usetcontact(env.dst, env.src);
msg = give_men(1, env.src, env.dst, NULL);
CuAssertStrEquals(tc, "give_person", (const char *)msg->parameters[0].v);
CuAssertStrEquals(tc, "give_person", test_get_messagetype(msg));
CuAssertIntEquals(tc, 2, env.dst->number);
CuAssertIntEquals(tc, 0, env.src->number);
msg_release(msg);
@ -325,7 +326,7 @@ static void test_give_peasants(CuTest * tc) {
setup_give(&env);
rsetpeasants(env.r, 0);
msg = disband_men(1, env.src, NULL);
CuAssertStrEquals(tc, "give_person_peasants", (const char*)msg->parameters[0].v);
CuAssertStrEquals(tc, "give_person_peasants", test_get_messagetype(msg));
CuAssertIntEquals(tc, 0, env.src->number);
CuAssertIntEquals(tc, 1, rpeasants(env.r));
msg_release(msg);

View File

@ -148,6 +148,16 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
return msg_create(mtype, args);
}
static message *missing_message(const char *name) {
if (strcmp(name, "missing_message") != 0) {
if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", 0));
}
return msg_message("missing_message", "name", name);
}
return NULL;
}
message *msg_message(const char *name, const char *sig, ...)
/* msg_message("oops_error", "unit region command", u, r, cmd) */
{
@ -160,16 +170,8 @@ message *msg_message(const char *name, const char *sig, ...)
memset(args, 0, sizeof(args));
if (!mtype) {
log_error("trying to create undefined message of type \"%s\"\n", name);
#if 0
if (strcmp(name, "missing_message") != 0) {
if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", 0));
}
return msg_message("missing_message", "name", name);
}
#endif
return NULL;
log_warning("trying to create undefined message of type \"%s\"\n", name);
return missing_message(name);
}
va_start(vargs, sig);

View File

@ -875,6 +875,7 @@ static void test_luck_message(CuTest *tc) {
attrib *a;
test_setup();
mt_register(mt_new_va("peasantluck_success", "births:int", 0));
setup_terrains(tc);
r = test_create_region(0, 0, NULL);
rsetpeasants(r, 1);
@ -899,6 +900,8 @@ static unit * setup_name_cmd(void) {
faction *f;
test_setup();
mt_register(mt_new_va("renamed_building_seen", "renamer:unit", "region:region", "building:building", 0));
mt_register(mt_new_va("renamed_building_notseen", "region:region", "building:building", 0));
f = test_create_faction(0);
return test_create_unit(f, test_create_region(0, 0, 0));
}
@ -1440,6 +1443,7 @@ static void test_show_without_item(CuTest *tc)
struct locale *loc;
test_setup();
mt_register(mt_new_va("displayitem", "weight:int", "item:resource", "description:string", 0));
loc = get_or_create_locale("de");
locale_setstring(loc, parameters[P_ANY], "ALLE");