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;
}
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) {
unit *u;
test_setup();
init_resources();
setup_production();
u = create_recruiter();
fset(u, UFL_HERO);
@ -163,7 +171,7 @@ static void test_normals_recruit(CuTest * tc) {
unit *u;
test_setup();
init_resources();
setup_production();
u = create_recruiter();
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;
test_setup();
init_resources();
setup_production();
test_create_locale();
setup_terrains(tc);
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 item_type *it_luxury;
test_setup();
init_resources();
setup_production();
test_create_locale();
setup_terrains(tc);
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;
test_setup();
init_resources();
setup_production();
config_set("taxing.perlevel", "20");
f = test_create_faction(NULL);
r = test_create_region(0, 0, NULL);
@ -361,6 +369,13 @@ static void test_tax_cmd(CuTest *tc) {
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
*/
@ -374,6 +389,7 @@ static void test_maintain_buildings(CuTest *tc) {
item_type *itype;
test_setup();
setup_maintenance();
btype = test_create_buildingtype("Hort");
btype->maxsize = 10;
r = test_create_region(0, 0, NULL);
@ -472,7 +488,7 @@ static void test_modify_material(CuTest *tc) {
resource_mod *mod;
test_setup();
init_resources();
setup_production();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
set_level(u, SK_WEAPONSMITH, 1);
@ -521,7 +537,7 @@ static void test_modify_skill(CuTest *tc) {
resource_mod *mod;
test_setup();
init_resources();
setup_production();
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
set_level(u, SK_WEAPONSMITH, 1);
@ -580,7 +596,7 @@ static void test_modify_production(CuTest *tc) {
double d = 0.6;
test_setup();
init_resources();
setup_production();
/* make items from other items (turn silver to stone) */
rt_silver = get_resourcetype(R_SILVER);

View File

@ -148,12 +148,24 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
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) {
if (strcmp(name, "missing_message") != 0) {
if (!mt_find("missing_message")) {
mt_register(mt_new_va("missing_message", "name:string", NULL));
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 (!mt_find("missing_message")) {
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;
}
@ -170,7 +182,6 @@ message *msg_message(const char *name, const char *sig, ...)
memset(args, 0, sizeof(args));
if (!mtype) {
log_warning("trying to create undefined message of type \"%s\"\n", name);
return missing_message(name);
}

View File

@ -46,6 +46,12 @@ extern "C" {
int level;
} 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_feedback(const struct unit *, struct order *cmd,
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/database.h>
#include <kernel/version.h>
#include <kernel/messages.h>
#include <kernel/save.h>
#include <kernel/version.h>
#include <util/filereader.h>
#include <util/language.h>
@ -305,6 +306,7 @@ int main(int argc, char **argv)
lua_State *L;
dictionary *d = 0;
setup_signal_handler();
message_handle_missing(MESSAGE_MISSING_REPLACE);
/* parse arguments again, to override ini file */
err = parse_args(argc, argv);
if (err != 0) {

View File

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