Make the behavior for missing messages configurable.

message_handle_missing function to set it (test_eressea should enetually use MESSAGE_MISSING_ERROR).
This commit is contained in:
Enno Rehling 2018-01-14 11:25:44 +01:00
parent f776450f9b
commit b432fbe9d8
6 changed files with 51 additions and 15 deletions

View file

@ -141,11 +141,19 @@ static struct unit *create_recruiter(void) {
return u; return u;
} }
static void setup_production(void) {
init_resources();
mt_register(mt_new_va("produce", "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", NULL));
mt_register(mt_new_va("income", "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", NULL));
mt_register(mt_new_va("buy", "unit:unit", "money:int", NULL));
mt_register(mt_new_va("buyamount", "unit:unit", "amount:int", "resource:resource", NULL));
}
static void test_heroes_dont_recruit(CuTest * tc) { static void test_heroes_dont_recruit(CuTest * tc) {
unit *u; unit *u;
test_setup(); test_setup();
init_resources(); setup_production();
u = create_recruiter(); u = create_recruiter();
fset(u, UFL_HERO); fset(u, UFL_HERO);
@ -163,7 +171,7 @@ static void test_normals_recruit(CuTest * tc) {
unit *u; unit *u;
test_setup(); test_setup();
init_resources(); setup_production();
u = create_recruiter(); u = create_recruiter();
unit_addorder(u, create_order(K_RECRUIT, default_locale, "1")); unit_addorder(u, create_order(K_RECRUIT, default_locale, "1"));
@ -227,7 +235,7 @@ static void test_trade_insect(CuTest *tc) {
const item_type *it_silver; const item_type *it_silver;
test_setup(); test_setup();
init_resources(); setup_production();
test_create_locale(); test_create_locale();
setup_terrains(tc); setup_terrains(tc);
r = setup_trade_region(tc, get_terrain("swamp")); r = setup_trade_region(tc, get_terrain("swamp"));
@ -259,7 +267,7 @@ static void test_buy_cmd(CuTest *tc) {
const resource_type *rt_silver; const resource_type *rt_silver;
const item_type *it_luxury; const item_type *it_luxury;
test_setup(); test_setup();
init_resources(); setup_production();
test_create_locale(); test_create_locale();
setup_terrains(tc); setup_terrains(tc);
r = setup_trade_region(tc, test_create_terrain("swamp", LAND_REGION)); r = setup_trade_region(tc, test_create_terrain("swamp", LAND_REGION));
@ -312,7 +320,7 @@ static void test_tax_cmd(CuTest *tc) {
econ_request *taxorders = 0; econ_request *taxorders = 0;
test_setup(); test_setup();
init_resources(); setup_production();
config_set("taxing.perlevel", "20"); config_set("taxing.perlevel", "20");
f = test_create_faction(NULL); f = test_create_faction(NULL);
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
@ -361,6 +369,13 @@ static void test_tax_cmd(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void setup_maintenance(void) {
mt_register(mt_new_va("maintenance", "unit:unit", "building:building", NULL));
mt_register(mt_new_va("maintenancefail", "unit:unit", "building:building", NULL));
mt_register(mt_new_va("maintenance_nowork", "building:building", NULL));
mt_register(mt_new_va("maintenance_noowner", "building:building", NULL));
}
/** /**
* see https://bugs.eressea.de/view.php?id=2234 * see https://bugs.eressea.de/view.php?id=2234
*/ */
@ -374,6 +389,7 @@ static void test_maintain_buildings(CuTest *tc) {
item_type *itype; item_type *itype;
test_setup(); test_setup();
setup_maintenance();
btype = test_create_buildingtype("Hort"); btype = test_create_buildingtype("Hort");
btype->maxsize = 10; btype->maxsize = 10;
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
@ -472,7 +488,7 @@ static void test_modify_material(CuTest *tc) {
resource_mod *mod; resource_mod *mod;
test_setup(); test_setup();
init_resources(); setup_production();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
set_level(u, SK_WEAPONSMITH, 1); set_level(u, SK_WEAPONSMITH, 1);
@ -521,7 +537,7 @@ static void test_modify_skill(CuTest *tc) {
resource_mod *mod; resource_mod *mod;
test_setup(); test_setup();
init_resources(); setup_production();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
set_level(u, SK_WEAPONSMITH, 1); set_level(u, SK_WEAPONSMITH, 1);
@ -580,7 +596,7 @@ static void test_modify_production(CuTest *tc) {
double d = 0.6; double d = 0.6;
test_setup(); test_setup();
init_resources(); setup_production();
/* make items from other items (turn silver to stone) */ /* make items from other items (turn silver to stone) */
rt_silver = get_resourcetype(R_SILVER); rt_silver = get_resourcetype(R_SILVER);

View file

@ -148,13 +148,25 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
return msg_create(mtype, args); return msg_create(mtype, args);
} }
static int missing_message_mode;
void message_handle_missing(int mode) {
missing_message_mode = mode;
}
static message *missing_message(const char *name) { static message *missing_message(const char *name) {
if (missing_message_mode == MESSAGE_MISSING_ERROR) {
log_error("trying to create undefined message of type \"%s\"\n", name);
}
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
log_warning("trying to create undefined message of type \"%s\"\n", name);
if (strcmp(name, "missing_message") != 0) { if (strcmp(name, "missing_message") != 0) {
if (!mt_find("missing_message")) { if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", NULL)); mt_register(mt_new_va("missing_message", "name:string", NULL));
} }
return msg_message("missing_message", "name", name); return msg_message("missing_message", "name", name);
} }
}
return NULL; return NULL;
} }
@ -170,7 +182,6 @@ message *msg_message(const char *name, const char *sig, ...)
memset(args, 0, sizeof(args)); memset(args, 0, sizeof(args));
if (!mtype) { if (!mtype) {
log_warning("trying to create undefined message of type \"%s\"\n", name);
return missing_message(name); return missing_message(name);
} }

View file

@ -46,6 +46,12 @@ extern "C" {
int level; int level;
} msglevel; } msglevel;
#define MESSAGE_MISSING_IGNORE 0
#define MESSAGE_MISSING_ERROR 1
#define MESSAGE_MISSING_REPLACE 2
void message_handle_missing(int mode);
struct message *msg_message(const char *name, const char *sig, ...); struct message *msg_message(const char *name, const char *sig, ...);
struct message *msg_feedback(const struct unit *, struct order *cmd, struct message *msg_feedback(const struct unit *, struct order *cmd,
const char *name, const char *sig, ...); const char *name, const char *sig, ...);

View file

@ -22,8 +22,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/database.h> #include <kernel/database.h>
#include <kernel/version.h> #include <kernel/messages.h>
#include <kernel/save.h> #include <kernel/save.h>
#include <kernel/version.h>
#include <util/filereader.h> #include <util/filereader.h>
#include <util/language.h> #include <util/language.h>
@ -305,6 +306,7 @@ int main(int argc, char **argv)
lua_State *L; lua_State *L;
dictionary *d = 0; dictionary *d = 0;
setup_signal_handler(); setup_signal_handler();
message_handle_missing(MESSAGE_MISSING_REPLACE);
/* parse arguments again, to override ini file */ /* parse arguments again, to override ini file */
err = parse_args(argc, argv); err = parse_args(argc, argv);
if (err != 0) { if (err != 0) {

View file

@ -2,6 +2,7 @@
#include <eressea.h> #include <eressea.h>
#include <kernel/config.h> #include <kernel/config.h>
#include <kernel/database.h> #include <kernel/database.h>
#include <kernel/messages.h>
#include <CuTest.h> #include <CuTest.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -184,5 +185,6 @@ int main(int argc, char ** argv) {
++argv; ++argv;
--argc; --argc;
} }
message_handle_missing(MESSAGE_MISSING_REPLACE);
return RunAllTests(argc, argv); return RunAllTests(argc, argv);
} }

View file

@ -222,7 +222,6 @@ static void log_write(int flags, const char *module, const char *format, va_list
} }
} }
void log_fatal(const char *format, ...) void log_fatal(const char *format, ...)
{ {
va_list args; va_list args;