From 98678d9fb2e43fc93a0509b208fe3ddf0c90bf68 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 12 Jan 2018 21:15:21 +0100 Subject: [PATCH] disable the missing_message replacement used in so many tests. fix some tests so they don't need it. --- src/kernel/curse.c | 1 + src/kernel/messages.c | 2 ++ src/laws.test.c | 15 ++++++--------- src/move.test.c | 4 ++++ src/spy.test.c | 12 ++++++++++++ src/study.test.c | 2 ++ src/util/message.c | 4 ++-- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 93df39f49..0f215dbee 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -726,6 +726,7 @@ message *cinfo_simple(const void *obj, objtype_t typ, const struct curse * c, UNUSED_ARG(obj); msg = msg_message(mkname("curseinfo", c->type->cname), "id", c->no); + /* TODO: this is never NULL, because of the missing_message logic (used in many tests) */ if (msg == NULL) { log_error("There is no curseinfo for %s.\n", c->type->cname); } diff --git a/src/kernel/messages.c b/src/kernel/messages.c index 0aa19a79c..058305a58 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -161,12 +161,14 @@ message *msg_message(const char *name, const char *sig, ...) if (!mtype) { log_warning("trying to create message of unknown 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; } diff --git a/src/laws.test.c b/src/laws.test.c index aca84710f..3ba2936c2 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -255,9 +255,9 @@ static void test_force_leave_buildings(CuTest *tc) { region *r; unit *u1, *u2, *u3; building * b; - message *msg; test_setup(); + mt_register(mt_new_va("force_leave_building", "unit:unit", "owner:unit", "building:building", NULL)); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(u1->faction, r); @@ -271,8 +271,7 @@ static void test_force_leave_buildings(CuTest *tc) { CuAssertPtrEquals_Msg(tc, "owner should not be forced to leave", b, u1->building); CuAssertPtrEquals_Msg(tc, "same faction should not be forced to leave", b, u2->building); CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u3->building); - msg = test_get_last_message(u3->faction->msgs); - CuAssertStrEquals(tc, "force_leave_building", test_get_messagetype(msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u3->faction->msgs, "force_leave_building")); u_set_building(u3, b); al = ally_add(&u1->faction->allies, u3->faction); @@ -286,9 +285,9 @@ static void test_force_leave_ships(CuTest *tc) { region *r; unit *u1, *u2; ship *sh; - message *msg; test_setup(); + mt_register(mt_new_va("force_leave_ship", "unit:unit", "owner:unit", "ship:ship", NULL)); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); u2 = test_create_unit(test_create_faction(NULL), r); @@ -298,8 +297,7 @@ static void test_force_leave_ships(CuTest *tc) { ship_set_owner(u1); force_leave(r, NULL); CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u2->ship); - msg = test_get_last_message(u2->faction->msgs); - CuAssertStrEquals(tc, "force_leave_ship", test_get_messagetype(msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "force_leave_ship")); test_teardown(); } @@ -1590,9 +1588,9 @@ static void test_demon_hunger(CuTest * tc) race *rc; faction *f; unit *u; - message* msg; test_setup(); + mt_register(mt_new_va("malnourish", "unit:unit", "region:region", NULL)); init_resources(); r = test_create_region(0, 0, 0); rc = test_create_race("demon"); @@ -1617,8 +1615,7 @@ static void test_demon_hunger(CuTest * tc) get_food(r); CuAssertIntEquals(tc, 10, i_get(u->items, rtype->itype)); - msg = test_get_last_message(u->faction->msgs); - CuAssertStrEquals(tc, "malnourish", test_get_messagetype(msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "malnourish")); test_teardown(); } diff --git a/src/move.test.c b/src/move.test.c index ff65fa823..2cb7b7a4e 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -279,6 +279,10 @@ void setup_drift (struct drift_fixture *fix) { set_level(fix->u, SK_SAILING, fix->st_boat->sumskill); u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat)); assert(fix->sh); + + mt_register(mt_new_va("ship_drift", "ship:ship", "dir:int", 0)); + mt_register(mt_new_va("shipsink", "ship:ship", 0)); + mt_register(mt_new_va("massive_overload", "ship:ship", 0)); } static void test_ship_no_overload(CuTest *tc) { diff --git a/src/spy.test.c b/src/spy.test.c index e8675a406..c558a1012 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -84,6 +84,9 @@ static void test_sabotage_self(CuTest *tc) { order *ord; test_setup(); + mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", 0)); + mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", 0)); + mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", 0)); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); @@ -94,6 +97,7 @@ static void test_sabotage_self(CuTest *tc) { assert(ord); CuAssertIntEquals(tc, 0, sabotage_cmd(u, ord)); CuAssertPtrEquals(tc, 0, r->ships); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "sink_msg")); free_order(ord); test_teardown(); } @@ -106,6 +110,11 @@ static void test_sabotage_other_fail(CuTest *tc) { message *msg; test_setup(); + mt_register(mt_new_va("destroy_ship_0", "unit:unit", "ship:ship", 0)); + mt_register(mt_new_va("destroy_ship_1", "unit:unit", "ship:ship", 0)); + mt_register(mt_new_va("destroy_ship_2", "unit:unit", "ship:ship", 0)); + mt_register(mt_new_va("destroy_ship_3", "ship:ship", 0)); + mt_register(mt_new_va("destroy_ship_4", "ship:ship", 0)); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); @@ -189,6 +198,9 @@ static void test_sabotage_other_success(CuTest *tc) { order *ord; test_setup(); + mt_register(mt_new_va("sink_msg", "ship:ship", "region:region", 0)); + mt_register(mt_new_va("sink_lost_msg", "unit:unit", "region:region", "dead:int", 0)); + mt_register(mt_new_va("sink_saved_msg", "unit:unit", "region:region", 0)); r = test_create_region(0, 0, 0); assert(r); u = test_create_unit(test_create_faction(NULL), r); diff --git a/src/study.test.c b/src/study.test.c index 3ca0288c2..e34e06fc9 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -625,6 +625,8 @@ static void test_teach_message(CuTest *tc) { teaching_info *teach; test_setup(); + mt_register(mt_new_va("teach_teacher", "teacher:unit", "student:unit", "skill:int", "level:int", 0)); + mt_register(mt_new_va("teach_student", "teacher:unit", "student:unit", "skill:int", 0)); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 20); diff --git a/src/util/message.c b/src/util/message.c index a080ff7a6..c3ffbbd32 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -243,7 +243,7 @@ void msg_free(message * msg) void msg_release(struct message *msg) { - assert(msg->refcount > 0); + assert(msg && msg->refcount > 0); if (--msg->refcount > 0) return; msg_free(msg); @@ -251,7 +251,7 @@ void msg_release(struct message *msg) struct message *msg_addref(struct message *msg) { - assert(msg->refcount > 0); + assert(msg && msg->refcount > 0); ++msg->refcount; return msg; }