remove test_inject_messagetypes(), make that the default behavior in tests.

This commit is contained in:
Enno Rehling 2018-10-28 21:28:05 +01:00
parent 113a6e68c7
commit be84c13a72
25 changed files with 218 additions and 161 deletions

View file

@ -26,7 +26,6 @@ static void test_herbsearch(CuTest * tc)
const item_type *itype; const item_type *itype;
test_setup(); test_setup();
test_inject_messagetypes();
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
rc = rc_get_or_create("dragon"); rc = rc_get_or_create("dragon");
rc->flags |= RCF_UNARMEDGUARD; rc->flags |= RCF_UNARMEDGUARD;

View file

@ -9,17 +9,22 @@
#include "kernel/region.h" #include "kernel/region.h"
#include "kernel/unit.h" #include "kernel/unit.h"
#include "util/message.h"
#include "tests.h" #include "tests.h"
#include <CuTest.h> #include <CuTest.h>
static void test_autostudy_init(CuTest *tc) { static void test_autostudy_init(CuTest *tc) {
scholar scholars[4]; scholar scholars[4];
unit *u1, *u2, *u3; unit *u1, *u2, *u3, *u4;
faction *f; faction *f;
region *r; region *r;
test_setup(); test_setup();
mt_create_error(77);
mt_create_error(771);
r = test_create_plain(0, 0); r = test_create_plain(0, 0);
f = test_create_faction(NULL); f = test_create_faction(NULL);
u1 = test_create_unit(f, r); u1 = test_create_unit(f, r);
@ -30,8 +35,11 @@ static void test_autostudy_init(CuTest *tc) {
set_level(u2, SK_ENTERTAINMENT, 2); set_level(u2, SK_ENTERTAINMENT, 2);
u3 = test_create_unit(f, r); u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]); u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
u4 = test_create_unit(test_create_faction(NULL), r);
u4->thisorder = create_order(K_AUTOSTUDY, f->locale, "Dudelidu");
scholars[3].u = NULL; scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r)); CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
CuAssertPtrEquals(tc, u2, scholars[0].u); CuAssertPtrEquals(tc, u2, scholars[0].u);
CuAssertIntEquals(tc, 2, scholars[0].level); CuAssertIntEquals(tc, 2, scholars[0].level);
CuAssertIntEquals(tc, 0, scholars[0].learn); CuAssertIntEquals(tc, 0, scholars[0].learn);

View file

@ -145,6 +145,7 @@ static struct unit *create_recruiter(void) {
static void setup_production(void) { static void setup_production(void) {
init_resources(); init_resources();
mt_create_feedback("error_cannotmake");
mt_create_va(mt_new("produce", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END); mt_create_va(mt_new("produce", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "resource:resource", MT_NEW_END);
mt_create_va(mt_new("income", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END); mt_create_va(mt_new("income", NULL), "unit:unit", "region:region", "amount:int", "wanted:int", "mode:int", MT_NEW_END);
mt_create_va(mt_new("buy", NULL), "unit:unit", "money:int", MT_NEW_END); mt_create_va(mt_new("buy", NULL), "unit:unit", "money:int", MT_NEW_END);
@ -737,6 +738,7 @@ static void test_loot(CuTest *tc) {
test_setup(); test_setup();
setup_production(); setup_production();
mt_create_error(48); /* unit is unarmed */
it_silver = test_create_silver(); it_silver = test_create_silver();
config_set("rules.enable_loot", "1"); config_set("rules.enable_loot", "1");
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
@ -746,7 +748,7 @@ static void test_loot(CuTest *tc) {
test_clear_messages(f); test_clear_messages(f);
arm_unit(u); arm_unit(u);
produce(u->region); produce(u->region);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "income")); /* unit is unarmed */ CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "income"));
CuAssertIntEquals(tc, 2 * TAXFRACTION, i_get(u->items, it_silver)); CuAssertIntEquals(tc, 2 * TAXFRACTION, i_get(u->items, it_silver));
CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING)); CuAssertIntEquals(tc, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING));
test_teardown(); test_teardown();

View file

@ -65,11 +65,14 @@ static void setup_give(struct give *env) {
mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END); mt_create_va(mt_new("give", NULL), "unit:unit", "target:unit", "resource:resource", "amount:int", MT_NEW_END);
mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END); mt_create_va(mt_new("give_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END);
/* error messages: */ /* error messages: */
mt_create_error(129);
mt_create_error(96);
mt_create_error(10);
mt_create_feedback("feedback_give_forbidden");
mt_create_feedback("peasants_give_invalid");
mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END); mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END); mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit", "region:region", "command:order", "allowed:int", MT_NEW_END);
mt_create_va(mt_new("feedback_no_contact", NULL), "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END); mt_create_va(mt_new("feedback_no_contact", NULL), "unit:unit", "region:region", "command:order", "target:unit", MT_NEW_END);
mt_create_va(mt_new("feedback_give_forbidden", NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
mt_create_va(mt_new("peasants_give_invalid", NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
mt_create_va(mt_new("giverestriction", NULL), "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END); mt_create_va(mt_new("giverestriction", NULL), "unit:unit", "region:region", "command:order", "turns:int", MT_NEW_END);
mt_create_va(mt_new("error_unit_size", NULL), "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END); mt_create_va(mt_new("error_unit_size", NULL), "unit:unit", "region:region", "command:order", "maxsize:int", MT_NEW_END);
mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END); mt_create_va(mt_new("nogive_reserved", NULL), "unit:unit", "region:region", "command:order", "resource:resource", "reservation:int", MT_NEW_END);
@ -91,7 +94,7 @@ static void test_give_unit(CuTest * tc) {
give_unit(env.src, env.dst, NULL); give_unit(env.src, env.dst, NULL);
CuAssertPtrEquals(tc, env.f2, env.src->faction); CuAssertPtrEquals(tc, env.f2, env.src->faction);
CuAssertIntEquals(tc, 1, env.f2->newbies); CuAssertIntEquals(tc, 1, env.f2->newbies);
CuAssertPtrEquals(tc, 0, env.f1->units); CuAssertPtrEquals(tc, NULL, env.f1->units);
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
test_teardown(); test_teardown();
@ -159,11 +162,12 @@ static void test_give_men_magicians(CuTest * tc) {
message * msg; message * msg;
test_setup_ex(tc); test_setup_ex(tc);
mt_create_error(158);
env.f2 = env.f1 = test_create_faction(NULL); env.f2 = env.f1 = test_create_faction(NULL);
setup_give(&env); setup_give(&env);
set_level(env.src, SK_MAGIC, 1); set_level(env.src, SK_MAGIC, 1);
CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL)); CuAssertPtrNotNull(tc, msg = give_men(1, env.src, env.dst, NULL));
CuAssertStrEquals(tc, "error158", (const char *)msg->parameters[3].v); CuAssertStrEquals(tc, "error158", test_get_messagetype(msg));
CuAssertIntEquals(tc, 1, env.dst->number); CuAssertIntEquals(tc, 1, env.dst->number);
CuAssertIntEquals(tc, 1, env.src->number); CuAssertIntEquals(tc, 1, env.src->number);
msg_release(msg); msg_release(msg);
@ -303,7 +307,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no)); ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
test_clear_messages(env.f1); test_clear_messages(env.f1);
give_cmd(env.src, ord); give_cmd(env.src, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(env.f1->msgs, "give_person"));
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact")); CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
msg_release(msg); msg_release(msg);
@ -407,7 +411,7 @@ static void test_give_okay(CuTest * tc) {
setup_give(&env); setup_give(&env);
config_set("rules.give.flags", "0"); config_set("rules.give.flags", "0");
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL)); CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
test_teardown(); test_teardown();
} }
@ -450,7 +454,7 @@ static void test_give_new_unit(CuTest * tc) {
setup_give(&env); setup_give(&env);
env.dst->number = 0; env.dst->number = 0;
fset(env.dst, UFL_ISNEW); fset(env.dst, UFL_ISNEW);
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL)); CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
test_teardown(); test_teardown();
} }

View file

@ -18,7 +18,6 @@ static void test_manacrystal(CuTest *tc) {
unit *u; unit *u;
test_setup(); test_setup();
test_inject_messagetypes();
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
itype = test_create_itemtype("manacrystal"); itype = test_create_itemtype("manacrystal");
@ -49,7 +48,6 @@ static void test_skillpotion(CuTest *tc) {
int initialWeeks_Magic = 0; int initialWeeks_Magic = 0;
test_setup(); test_setup();
test_inject_messagetypes();
u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0));
itype = test_create_itemtype("skillpotion"); itype = test_create_itemtype("skillpotion");
change_resource(u, itype->rtype, 2); change_resource(u, itype->rtype, 2);

View file

@ -500,6 +500,28 @@ static int count_materials(unit *u, const construction *type, int n, int complet
return n; return n;
} }
int build_skill(unit *u, int basesk, int skill_mod) {
int effsk, skills;
int dm = get_effect(u, oldpotiontype[P_DOMORE]);
effsk = basesk + skill_mod;
assert(effsk >= 0);
skills = effsk * u->number;
/* technically, nimblefinge and domore should be in a global set of
* "game"-attributes, (as at_skillmod) but for a while, we're leaving
* them in here. */
if (dm != 0) {
/* Auswirkung Schaffenstrunk */
if (dm > u->number) dm = u->number;
change_effect(u, oldpotiontype[P_DOMORE], -dm);
skills += dm * effsk;
}
return skills;
}
/** Use up resources for building an object. /** Use up resources for building an object.
* Build up to 'size' points of 'type', where 'completed' * Build up to 'size' points of 'type', where 'completed'
* of the first object have already been finished. return the * of the first object have already been finished. return the
@ -521,28 +543,11 @@ int build(unit * u, const construction * ctype, int completed, int want, int ski
return ECOMPLETE; return ECOMPLETE;
} }
if (con->skill != NOSKILL) { if (con->skill != NOSKILL) {
int effsk;
int dm = get_effect(u, oldpotiontype[P_DOMORE]);
basesk = effskill(u, con->skill, 0); basesk = effskill(u, con->skill, 0);
if (basesk == 0) if (basesk == 0)
return ENEEDSKILL; return ENEEDSKILL;
effsk = basesk + skill_mod; skills = build_skill(u, basesk, skill_mod);
assert(effsk >= 0);
skills = effsk * u->number;
/* technically, nimblefinge and domore should be in a global set of
* "game"-attributes, (as at_skillmod) but for a while, we're leaving
* them in here. */
if (dm != 0) {
/* Auswirkung Schaffenstrunk */
if (dm > u->number) dm = u->number;
change_effect(u, oldpotiontype[P_DOMORE], -dm);
skills += dm * effsk;
}
} }
for (; want > 0 && skills > 0;) { for (; want > 0 && skills > 0;) {
int err, n; int err, n;

View file

@ -31,7 +31,6 @@ typedef struct build_fixture {
static unit * setup_build(build_fixture *bf) { static unit * setup_build(build_fixture *bf) {
test_setup(); test_setup();
test_inject_messagetypes();
init_resources(); init_resources();
test_create_itemtype("stone"); test_create_itemtype("stone");
@ -307,7 +306,6 @@ static void test_build_destroy_road_guard(CuTest *tc)
order *ord; order *ord;
test_setup(); test_setup();
test_inject_messagetypes();
test_create_region(1, 0, 0); test_create_region(1, 0, 0);
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
rsetroad(r, D_EAST, 100); rsetroad(r, D_EAST, 100);
@ -340,7 +338,6 @@ static void test_build_destroy_road_limit(CuTest *tc)
order *ord; order *ord;
test_setup(); test_setup();
test_inject_messagetypes();
test_create_region(1, 0, 0); test_create_region(1, 0, 0);
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
rsetroad(r, D_EAST, 100); rsetroad(r, D_EAST, 100);
@ -365,6 +362,7 @@ static void test_build_destroy_cmd(CuTest *tc) {
faction *f; faction *f;
test_setup(); test_setup();
mt_create_error(138);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
u->thisorder = create_order(K_DESTROY, f->locale, NULL); u->thisorder = create_order(K_DESTROY, f->locale, NULL);
CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder)); CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder));

View file

@ -51,7 +51,6 @@ typedef struct {
static void setup_curse(curse_fixture *fix, const char *name) { static void setup_curse(curse_fixture *fix, const char *name) {
test_setup(); test_setup();
test_inject_messagetypes();
fix->r = test_create_region(0, 0, NULL); fix->r = test_create_region(0, 0, NULL);
fix->u = test_create_unit(test_create_faction(NULL), fix->r); fix->u = test_create_unit(test_create_faction(NULL), fix->r);
fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0); fix->c = create_curse(fix->u, &fix->r->attribs, ct_find(name), 1.0, 1, 1.0, 0);

View file

@ -67,6 +67,46 @@ variant v)
} }
} }
static int missing_message_mode;
void message_handle_missing(int mode) {
missing_message_mode = mode;
}
static message *missing_feedback(const char *name, const struct unit *u,
const struct region *r, struct order *ord)
{
if (missing_message_mode == MESSAGE_MISSING_ERROR) {
log_error("trying to create undefined feedback of type \"%s\"\n", name);
}
else if (missing_message_mode == MESSAGE_MISSING_REPLACE) {
if (strcmp(name, "missing_feedback") != 0) {
if (!mt_find("missing_feedback")) {
mt_create_va(mt_new("missing_feedback", NULL), "unit:unit",
"region:region", "command:order", "name:string", MT_NEW_END);
}
return msg_message("missing_feedback", "unit region command name", u, r, ord, name);
}
}
return NULL;
}
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 (!mt_find("missing_message")) {
mt_create_va(mt_new("missing_message", NULL), "name:string", MT_NEW_END);
}
return msg_message("missing_message", "name", name);
}
}
return NULL;
}
struct message *msg_feedback(const struct unit *u, struct order *ord, struct message *msg_feedback(const struct unit *u, struct order *ord,
const char *name, const char *sig, ...) const char *name, const char *sig, ...)
{ {
@ -80,13 +120,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord,
} }
if (!mtype) { if (!mtype) {
log_warning("trying to create message of unknown type \"%s\"\n", name); return missing_feedback(name, u, u->region, ord);
if (!mt_find("missing_feedback")) {
mt_create_va(mt_new("missing_feedback", NULL), "unit:unit",
"region:region", "command:order", "name:string", MT_NEW_END);
}
return msg_message("missing_feedback", "name unit region command",
name, u, u->region, ord);
} }
var.v = (void *)u; var.v = (void *)u;
@ -139,28 +173,6 @@ 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) {
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_create_va(mt_new("missing_message", NULL), "name:string", MT_NEW_END);
}
return msg_message("missing_message", "name", name);
}
}
return NULL;
}
message *msg_message(const char *name, const char *sig, ...) message *msg_message(const char *name, const char *sig, ...)
/* msg_message("oops_error", "unit region command", u, r, cmd) */ /* msg_message("oops_error", "unit region command", u, r, cmd) */
{ {

View file

@ -18,6 +18,23 @@ void test_missing_message(CuTest *tc) {
CuAssertPtrNotNull(tc, msg); CuAssertPtrNotNull(tc, msg);
CuAssertPtrNotNull(tc, msg->type); CuAssertPtrNotNull(tc, msg->type);
CuAssertStrEquals(tc, msg->type->name, "missing_message"); CuAssertStrEquals(tc, msg->type->name, "missing_message");
CuAssertStrEquals(tc, "unknown", (const char *)msg->parameters[0].v);
msg_release(msg);
test_teardown();
}
void test_missing_feedback(CuTest *tc) {
message *msg;
struct locale *lang;
test_setup();
message_handle_missing(MESSAGE_MISSING_REPLACE);
lang = test_create_locale();
msg = msg_error(NULL, NULL, 77);
CuAssertPtrNotNull(tc, msg);
CuAssertPtrNotNull(tc, msg->type);
CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
CuAssertStrEquals(tc, "error77", (const char *)msg->parameters[3].v);
msg_release(msg); msg_release(msg);
test_teardown(); test_teardown();
} }

View file

@ -342,7 +342,7 @@ order *parse_order(const char *s, const struct locale * lang)
sptr = sp; sptr = sp;
p = parse_token(&sp, token, sizeof(token)); p = parse_token(&sp, token, sizeof(token));
sk = get_skill(p, lang); sk = get_skill(p, lang);
if (!expensive_skill(sk)) { if (sk == NOSKILL || !expensive_skill(sk)) {
kwd = K_AUTOSTUDY; kwd = K_AUTOSTUDY;
} }
} }

View file

@ -33,7 +33,6 @@ static void test_create_duplicate_spell(CuTest * tc)
strlist *sl = 0; strlist *sl = 0;
test_setup(); test_setup();
test_inject_messagetypes();
test_log_stderr(0); /* suppress the "duplicate spell" error message */ test_log_stderr(0); /* suppress the "duplicate spell" error message */
log = test_log_start(LOG_CPERROR, &sl); log = test_log_start(LOG_CPERROR, &sl);

View file

@ -1853,10 +1853,6 @@ bool unit_name_equals_race(const unit *u) {
return false; return false;
} }
bool unit_can_study(const unit *u) {
return !((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE));
}
static int read_newunitid(const faction * f, const region * r) static int read_newunitid(const faction * f, const region * r)
{ {
int n; int n;

View file

@ -246,7 +246,6 @@ extern "C" {
const char *unitname(const struct unit *u); const char *unitname(const struct unit *u);
char *write_unitname(const struct unit *u, char *buffer, size_t size); char *write_unitname(const struct unit *u, char *buffer, size_t size);
bool unit_name_equals_race(const struct unit *u); bool unit_name_equals_race(const struct unit *u);
bool unit_can_study(const struct unit *u);
/* getunit results: */ /* getunit results: */
#define GET_UNIT 0 #define GET_UNIT 0

View file

@ -153,8 +153,8 @@ static void test_enter_building(CuTest * tc)
rc->flags = RCF_SWIM; rc->flags = RCF_SWIM;
u->building = 0; u->building = 0;
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false)); CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
CuAssertPtrEquals(tc, 0, u->building); CuAssertPtrEquals(tc, NULL, u->building);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true)); CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
CuAssertPtrNotNull(tc, u->faction->msgs); CuAssertPtrNotNull(tc, u->faction->msgs);
@ -170,7 +170,6 @@ static void test_enter_ship(CuTest * tc)
race * rc; race * rc;
test_setup(); test_setup();
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
rc = test_create_race("smurf"); rc = test_create_race("smurf");
u = test_create_unit(test_create_faction(rc), r); u = test_create_unit(test_create_faction(rc), r);
@ -194,8 +193,8 @@ static void test_enter_ship(CuTest * tc)
rc->flags = RCF_SWIM; rc->flags = RCF_SWIM;
u->ship = 0; u->ship = 0;
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false)); CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
CuAssertPtrEquals(tc, 0, u->ship); CuAssertPtrEquals(tc, NULL, u->ship);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true)); CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
CuAssertPtrNotNull(tc, u->faction->msgs); CuAssertPtrNotNull(tc, u->faction->msgs);
@ -486,6 +485,10 @@ static void test_limit_new_units(CuTest * tc)
alliance *al; alliance *al;
test_setup(); test_setup();
mt_create_va(mt_new("too_many_units_in_faction", NULL), "unit:unit",
"region:region", "command:order", "allowed:int", MT_NEW_END);
mt_create_va(mt_new("too_many_units_in_alliance", NULL), "unit:unit",
"region:region", "command:order", "allowed:int", MT_NEW_END);
al = makealliance(1, "Hodor"); al = makealliance(1, "Hodor");
f = test_create_faction(NULL); f = test_create_faction(NULL);
u = test_create_unit(f, test_create_region(0, 0, NULL)); u = test_create_unit(f, test_create_region(0, 0, NULL));
@ -901,6 +904,9 @@ static unit * setup_name_cmd(void) {
faction *f; faction *f;
test_setup(); test_setup();
mt_create_error(84);
mt_create_error(148);
mt_create_error(12);
mt_create_va(mt_new("renamed_building_seen", NULL), "renamer:unit", "region:region", "building:building", MT_NEW_END); mt_create_va(mt_new("renamed_building_seen", NULL), "renamer:unit", "region:region", "building:building", MT_NEW_END);
mt_create_va(mt_new("renamed_building_notseen", NULL), "region:region", "building:building", MT_NEW_END); mt_create_va(mt_new("renamed_building_notseen", NULL), "region:region", "building:building", MT_NEW_END);
f = test_create_faction(NULL); f = test_create_faction(NULL);
@ -1049,8 +1055,8 @@ static void test_long_order_normal(CuTest *tc) {
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED)); CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION)); CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION));
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertPtrEquals(tc, 0, u->old_orders); CuAssertPtrEquals(tc, NULL, u->old_orders);
test_teardown(); test_teardown();
} }
@ -1060,9 +1066,9 @@ static void test_long_order_none(CuTest *tc) {
test_setup(); test_setup();
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));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrEquals(tc, 0, u->orders); CuAssertPtrEquals(tc, NULL, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
test_teardown(); test_teardown();
} }
@ -1074,9 +1080,9 @@ static void test_long_order_cast(CuTest *tc) {
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL)); unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL)); unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
test_teardown(); test_teardown();
} }
@ -1089,9 +1095,9 @@ static void test_long_order_buy_sell(CuTest *tc) {
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL)); unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL)); unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
test_teardown(); test_teardown();
} }
@ -1099,6 +1105,7 @@ static void test_long_order_multi_long(CuTest *tc) {
/* TODO: write more tests */ /* TODO: write more tests */
unit *u; unit *u;
test_setup(); test_setup();
mt_create_error(52);
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));
unit_addorder(u, create_order(K_MOVE, u->faction->locale, NULL)); unit_addorder(u, create_order(K_MOVE, u->faction->locale, NULL));
unit_addorder(u, create_order(K_DESTROY, u->faction->locale, NULL)); unit_addorder(u, create_order(K_DESTROY, u->faction->locale, NULL));
@ -1113,11 +1120,12 @@ static void test_long_order_multi_buy(CuTest *tc) {
/* TODO: write more tests */ /* TODO: write more tests */
unit *u; unit *u;
test_setup(); test_setup();
mt_create_error(52);
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));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0)); unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0)); unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
test_teardown(); test_teardown();
@ -1132,9 +1140,9 @@ static void test_long_order_multi_sell(CuTest *tc) {
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0)); unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0)); unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
test_teardown(); test_teardown();
} }
@ -1142,11 +1150,12 @@ static void test_long_order_buy_cast(CuTest *tc) {
/* TODO: write more tests */ /* TODO: write more tests */
unit *u; unit *u;
test_setup(); test_setup();
mt_create_error(52);
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));
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0)); unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0)); unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
update_long_order(u); update_long_order(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, NULL, u->thisorder);
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
test_teardown(); test_teardown();
@ -1164,7 +1173,7 @@ static void test_long_order_hungry(CuTest *tc) {
update_long_order(u); update_long_order(u);
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder)); CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, u->orders);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
test_teardown(); test_teardown();
} }
@ -1174,9 +1183,10 @@ static void test_ally_cmd_errors(CuTest *tc) {
order *ord; order *ord;
test_setup(); test_setup();
mt_create_error(66);
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));
fid = u->faction->no + 1; fid = u->faction->no + 1;
CuAssertPtrEquals(tc, 0, findfaction(fid)); CuAssertPtrEquals(tc, NULL, findfaction(fid));
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid)); ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
ally_cmd(u, ord); ally_cmd(u, ord);
@ -1273,25 +1283,25 @@ static void test_ally_cmd(CuTest *tc) {
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no)); ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
ally_cmd(u, ord); ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL)); CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord); free_order(ord);
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT])); ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
ally_cmd(u, ord); ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL)); CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord); free_order(ord);
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD])); ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
ally_cmd(u, ord); ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL)); CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord); free_order(ord);
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT])); ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
ally_cmd(u, ord); ally_cmd(u, ord);
CuAssertPtrEquals(tc, 0, u->faction->msgs); CuAssertPtrEquals(tc, NULL, u->faction->msgs);
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL)); CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
free_order(ord); free_order(ord);
@ -1325,6 +1335,8 @@ static unit * setup_mail_cmd(void) {
faction *f; faction *f;
test_setup(); test_setup();
mt_create_error(66);
mt_create_error(30);
mt_create_va(mt_new("regionmessage", NULL), "region:region", "sender:unit", "string:string", MT_NEW_END); mt_create_va(mt_new("regionmessage", NULL), "region:region", "sender:unit", "string:string", MT_NEW_END);
mt_create_va(mt_new("unitmessage", NULL), "region:region", "sender:unit", "string:string", "unit:unit", MT_NEW_END); mt_create_va(mt_new("unitmessage", NULL), "region:region", "sender:unit", "string:string", "unit:unit", MT_NEW_END);
mt_create_va(mt_new("mail_result", NULL), "message:string", "unit:unit", MT_NEW_END); mt_create_va(mt_new("mail_result", NULL), "message:string", "unit:unit", MT_NEW_END);
@ -1383,7 +1395,7 @@ static void test_mail_unit_no_msg(CuTest *tc) {
f = u->faction; f = u->faction;
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no)); ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "unitmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
free_order(ord); free_order(ord);
test_teardown(); test_teardown();
@ -1398,7 +1410,7 @@ static void test_mail_faction_no_msg(CuTest *tc) {
f = u->faction; f = u->faction;
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no)); ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
free_order(ord); free_order(ord);
test_teardown(); test_teardown();
@ -1413,7 +1425,7 @@ static void test_mail_faction_no_target(CuTest *tc) {
f = u->faction; f = u->faction;
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1)); ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66"));
free_order(ord); free_order(ord);
test_teardown(); test_teardown();
@ -1428,7 +1440,7 @@ static void test_mail_region_no_msg(CuTest *tc) {
f = u->faction; f = u->faction;
ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION])); ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION]));
mail_cmd(u, ord); mail_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->region->msgs, "mail_result"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
free_order(ord); free_order(ord);
test_teardown(); test_teardown();
@ -1444,6 +1456,8 @@ static void test_show_without_item(CuTest *tc)
struct locale *loc; struct locale *loc;
test_setup(); test_setup();
mt_create_error(21);
mt_create_error(36);
mt_create_va(mt_new("displayitem", NULL), "weight:int", "item:resource", "description:string", MT_NEW_END); mt_create_va(mt_new("displayitem", NULL), "weight:int", "item:resource", "description:string", MT_NEW_END);
loc = get_or_create_locale("de"); loc = get_or_create_locale("de");
@ -1466,14 +1480,14 @@ static void test_show_without_item(CuTest *tc)
locale_setstring(loc, "iteminfo::testitem", "testdescription"); locale_setstring(loc, "iteminfo::testitem", "testdescription");
reshow_cmd(u, ord); reshow_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36"));
test_clear_messages(f); test_clear_messages(f);
i_add(&(u->items), i_new(itype, 1)); i_add(&(u->items), i_new(itype, 1));
reshow_cmd(u, ord); reshow_cmd(u, ord);
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error36"));
test_clear_messages(f); test_clear_messages(f);
free_order(ord); free_order(ord);
@ -1488,7 +1502,6 @@ static void test_show_race(CuTest *tc) {
message * msg; message * msg;
test_setup(); test_setup();
mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END); mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END);
test_create_race("human"); test_create_race("human");
rc = test_create_race("elf"); rc = test_create_race("elf");
@ -1504,8 +1517,8 @@ static void test_show_race(CuTest *tc) {
ord = create_order(K_RESHOW, loc, "Mensch"); ord = create_order(K_RESHOW, loc, "Mensch");
reshow_cmd(u, ord); reshow_cmd(u, ord);
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") != NULL); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error21"));
CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "msg_event") == NULL); CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "msg_event"));
test_clear_messages(u->faction); test_clear_messages(u->faction);
free_order(ord); free_order(ord);
@ -1618,7 +1631,7 @@ static void test_demon_hunger(CuTest * tc)
get_food(r); get_food(r);
CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype)); CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype));
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "malnourish")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "malnourish"));
config_set("hunger.demon.peasant_tolerance", "0"); config_set("hunger.demon.peasant_tolerance", "0");

View file

@ -555,7 +555,7 @@ static order *monster_learn(unit * u)
const struct locale *lang = u->faction->locale; const struct locale *lang = u->faction->locale;
/* can these monsters even study? */ /* can these monsters even study? */
if (!unit_can_study(u)) { if (!check_student(u, NULL, SK_PERCEPTION)) {
return NULL; return NULL;
} }
@ -828,7 +828,7 @@ void plan_monsters(faction * f)
} }
} }
} }
if (long_order == NULL && unit_can_study(u)) { if (long_order == NULL && check_student(u, NULL, SK_WEAPONLESS)) {
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um /* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
* zu bewachen: */ * zu bewachen: */
if (rc->bonus[SK_WEAPONLESS] != -99) { if (rc->bonus[SK_WEAPONLESS] != -99) {

View file

@ -30,6 +30,8 @@ static void setup_piracy(void) {
st_boat = test_create_shiptype("boat"); st_boat = test_create_shiptype("boat");
st_boat->cargo = 1000; st_boat->cargo = 1000;
mt_create_error(144);
mt_create_error(146);
mt_create_va(mt_new("piratenovictim", NULL), mt_create_va(mt_new("piratenovictim", NULL),
"ship:ship", "unit:unit", "region:region", MT_NEW_END); "ship:ship", "unit:unit", "region:region", MT_NEW_END);
mt_create_va(mt_new("piratesawvictim", NULL), mt_create_va(mt_new("piratesawvictim", NULL),

View file

@ -14,12 +14,19 @@
#include <stddef.h> #include <stddef.h>
#include <CuTest.h> #include <CuTest.h>
static void setup_renumber(CuTest *tc) {
test_setup_ex(tc);
mt_create_error(114);
mt_create_error(115);
mt_create_error(116);
}
static void test_renumber_faction(CuTest *tc) { static void test_renumber_faction(CuTest *tc) {
unit *u; unit *u;
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
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));
no = u->faction->no; no = u->faction->no;
uno = (no > 1) ? no - 1 : no + 1; uno = (no > 1) ? no - 1 : no + 1;
@ -37,7 +44,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
int no; int no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END); mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END);
f2 = test_create_faction(NULL); f2 = test_create_faction(NULL);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
@ -57,7 +64,7 @@ static void test_renumber_faction_invalid(CuTest *tc) {
int no; int no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0)); u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = f->no; no = f->no;
lang = f->locale; lang = f->locale;
@ -87,7 +94,7 @@ static void test_renumber_building(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
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));
u->building = test_create_building(u->region, NULL); u->building = test_create_building(u->region, NULL);
no = u->building->no; no = u->building->no;
@ -105,7 +112,7 @@ static void test_renumber_building_duplicate(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
u->building = test_create_building(u->region, NULL); u->building = test_create_building(u->region, NULL);
uno = u->building->no; uno = u->building->no;
@ -124,7 +131,7 @@ static void test_renumber_ship(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
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));
u->ship = test_create_ship(u->region, NULL); u->ship = test_create_ship(u->region, NULL);
no = u->ship->no; no = u->ship->no;
@ -141,7 +148,7 @@ static void test_renumber_ship_twice(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
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));
u->ship = test_create_ship(u->region, NULL); u->ship = test_create_ship(u->region, NULL);
no = u->ship->no; no = u->ship->no;
@ -163,7 +170,7 @@ static void test_renumber_ship_duplicate(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
u->ship = test_create_ship(u->region, NULL); u->ship = test_create_ship(u->region, NULL);
uno = u->ship->no; uno = u->ship->no;
@ -182,7 +189,7 @@ static void test_renumber_unit(CuTest *tc) {
int uno, no; int uno, no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
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));
no = u->no; no = u->no;
uno = (no > 1) ? no - 1 : no + 1; uno = (no > 1) ? no - 1 : no + 1;
@ -200,7 +207,7 @@ static void test_renumber_unit_duplicate(CuTest *tc) {
int no; int no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
no = u->no; no = u->no;
u2 = test_create_unit(f, u->region); u2 = test_create_unit(f, u->region);
@ -219,7 +226,7 @@ static void test_renumber_unit_limit(CuTest *tc) {
int no; int no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
no = u->no; no = u->no;
lang = f->locale; lang = f->locale;
@ -237,7 +244,7 @@ static void test_renumber_unit_invalid(CuTest *tc) {
int no; int no;
const struct locale *lang; const struct locale *lang;
test_setup_ex(tc); setup_renumber(tc);
u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL));
no = u->no; no = u->no;
lang = f->locale; lang = f->locale;

View file

@ -791,7 +791,6 @@ static void test_insect_warnings(CuTest *tc) {
test_setup(); test_setup();
test_create_calendar(); test_create_calendar();
test_inject_messagetypes();
f = test_create_faction(test_create_race("insect")); f = test_create_faction(test_create_race("insect"));
CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season); CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season);
@ -819,7 +818,6 @@ static void test_newbie_warning(CuTest *tc) {
faction *f; faction *f;
test_setup(); test_setup();
test_inject_messagetypes();
f = test_create_faction(NULL); f = test_create_faction(NULL);
config_set_int("NewbieImmunity", 3); config_set_int("NewbieImmunity", 3);

View file

@ -27,10 +27,6 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
static void setup_spells(void) {
test_inject_messagetypes();
}
static void test_good_dreams(CuTest *tc) { static void test_good_dreams(CuTest *tc) {
struct region *r; struct region *r;
struct faction *f1, *f2; struct faction *f1, *f2;
@ -40,7 +36,6 @@ static void test_good_dreams(CuTest *tc) {
curse *curse; curse *curse;
test_setup(); test_setup();
setup_spells();
test_create_world(); test_create_world();
r = findregion(0, 0); r = findregion(0, 0);
f1 = test_create_faction(NULL); f1 = test_create_faction(NULL);
@ -70,7 +65,6 @@ static void test_dreams(CuTest *tc) {
castorder co; castorder co;
test_setup(); test_setup();
setup_spells();
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
f1 = test_create_faction(NULL); f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL); f2 = test_create_faction(NULL);
@ -98,7 +92,6 @@ static void test_bad_dreams(CuTest *tc) {
curse *curse; curse *curse;
test_setup(); test_setup();
setup_spells();
test_create_world(); test_create_world();
r = findregion(0, 0); r = findregion(0, 0);
f1 = test_create_faction(NULL); f1 = test_create_faction(NULL);
@ -129,7 +122,6 @@ static void test_view_reality(CuTest *tc) {
castorder co; castorder co;
test_setup(); test_setup();
setup_spells();
mt_create_va(mt_new("spell_astral_only", NULL), mt_create_va(mt_new("spell_astral_only", NULL),
"unit:unit", "region:region", "command:order", MT_NEW_END); "unit:unit", "region:region", "command:order", MT_NEW_END);
mt_create_va(mt_new("viewreality_effect", NULL), mt_create_va(mt_new("viewreality_effect", NULL),
@ -165,7 +157,6 @@ static void test_watch_region(CuTest *tc) {
region *r; region *r;
faction *f; faction *f;
test_setup(); test_setup();
setup_spells();
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
f = test_create_faction(NULL); f = test_create_faction(NULL);
CuAssertIntEquals(tc, -1, get_observer(r, f)); CuAssertIntEquals(tc, -1, get_observer(r, f));

View file

@ -58,6 +58,11 @@ typedef struct {
} study_fixture; } study_fixture;
static void setup_study(void) { static void setup_study(void) {
test_setup();
mt_create_error(178);
mt_create_error(65);
mt_create_va(mt_new("teach_asgood", NULL),
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
mt_create_va(mt_new("studycost", NULL), mt_create_va(mt_new("studycost", NULL),
"unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END); "unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END);
mt_create_va(mt_new("teach_teacher", NULL), mt_create_va(mt_new("teach_teacher", NULL),
@ -81,7 +86,7 @@ static void setup_teacher(study_fixture *fix, skill_t sk) {
struct locale *lang; struct locale *lang;
assert(fix); assert(fix);
test_setup(); setup_study();
config_set("study.random_progress", "0"); config_set("study.random_progress", "0");
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
f = test_create_faction(NULL); f = test_create_faction(NULL);
@ -148,7 +153,7 @@ static void test_study_bug_2194(CuTest *tc) {
struct locale * loc; struct locale * loc;
building * b; building * b;
test_setup(); setup_study();
random_source_inject_constant(0.0); random_source_inject_constant(0.0);
init_resources(); init_resources();
loc = test_create_locale(); loc = test_create_locale();
@ -205,7 +210,7 @@ static void test_produceexp(CuTest *tc) {
unit *u; unit *u;
g_tc = tc; g_tc = tc;
test_setup(); setup_study();
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));
scale_number(u, 2); scale_number(u, 2);
config_set("study.produceexp", "20"); config_set("study.produceexp", "20");
@ -220,7 +225,7 @@ static void test_academy_building(CuTest *tc) {
building * b; building * b;
message * msg; message * msg;
test_setup(); setup_study();
mt_create_va(mt_new("teach_asgood", NULL), mt_create_va(mt_new("teach_asgood", NULL),
"unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END); "unit:unit", "region:region", "command:order", "student:unit", MT_NEW_END);
@ -271,7 +276,6 @@ static void test_academy_bonus(CuTest *tc) {
struct locale * loc; struct locale * loc;
building * b; building * b;
test_setup();
setup_study(); setup_study();
random_source_inject_constant(0.0); random_source_inject_constant(0.0);
@ -328,7 +332,8 @@ static void test_academy_bonus(CuTest *tc) {
void test_learn_skill_single(CuTest *tc) { void test_learn_skill_single(CuTest *tc) {
unit *u; unit *u;
skill *sv; skill *sv;
test_setup();
setup_study();
config_set("study.random_progress", "0"); config_set("study.random_progress", "0");
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));
learn_skill(u, SK_ALCHEMY, STUDYDAYS); learn_skill(u, SK_ALCHEMY, STUDYDAYS);
@ -347,7 +352,8 @@ void test_learn_skill_single(CuTest *tc) {
void test_learn_skill_multi(CuTest *tc) { void test_learn_skill_multi(CuTest *tc) {
unit *u; unit *u;
skill *sv; skill *sv;
test_setup();
setup_study();
config_set("study.random_progress", "0"); config_set("study.random_progress", "0");
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));
scale_number(u, 10); scale_number(u, 10);
@ -367,7 +373,8 @@ void test_learn_skill_multi(CuTest *tc) {
static void test_demon_skillchanges(CuTest *tc) { static void test_demon_skillchanges(CuTest *tc) {
unit * u; unit * u;
const race * rc; const race * rc;
test_setup();
setup_study();
rc = test_create_race("demon"); rc = test_create_race("demon");
CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON)); CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON));
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL)); u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
@ -380,7 +387,8 @@ static void test_demon_skillchanges(CuTest *tc) {
static void test_study_cmd(CuTest *tc) { static void test_study_cmd(CuTest *tc) {
unit *u; unit *u;
test_setup();
setup_study();
init_resources(); init_resources();
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));
u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW"); u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW");
@ -399,7 +407,6 @@ static void test_study_magic(CuTest *tc) {
const struct locale *lang; const struct locale *lang;
const struct item_type *itype; const struct item_type *itype;
test_setup();
setup_study(); setup_study();
init_resources(); init_resources();
f = test_create_faction(NULL); f = test_create_faction(NULL);
@ -432,7 +439,6 @@ static void test_study_magic(CuTest *tc) {
static void test_study_cost_magic(CuTest *tc) { static void test_study_cost_magic(CuTest *tc) {
unit * u; unit * u;
test_setup();
setup_study(); setup_study();
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));
@ -456,7 +462,6 @@ static void test_study_cost(CuTest *tc) {
unit *u; unit *u;
const struct item_type *itype; const struct item_type *itype;
test_setup();
setup_study(); setup_study();
itype = test_create_silver(); itype = test_create_silver();
@ -484,7 +489,6 @@ static void test_teach_magic(CuTest *tc) {
faction *f; faction *f;
const struct item_type *itype; const struct item_type *itype;
test_setup();
setup_study(); setup_study();
init_resources(); init_resources();
itype = get_resourcetype(R_SILVER)->itype; itype = get_resourcetype(R_SILVER)->itype;
@ -510,7 +514,8 @@ static void test_teach_magic(CuTest *tc) {
static void test_teach_cmd(CuTest *tc) { static void test_teach_cmd(CuTest *tc) {
unit *u, *ut; unit *u, *ut;
test_setup();
setup_study();
init_resources(); init_resources();
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));
scale_number(u, 10); scale_number(u, 10);
@ -530,7 +535,8 @@ static void test_teach_cmd(CuTest *tc) {
static void test_teach_two(CuTest *tc) { static void test_teach_two(CuTest *tc) {
unit *u1, *u2, *ut; unit *u1, *u2, *ut;
test_setup();
setup_study();
init_resources(); init_resources();
u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
scale_number(u1, 5); scale_number(u1, 5);
@ -560,7 +566,7 @@ static void test_teach_two_skills(CuTest *tc) {
faction *f; faction *f;
region *r; region *r;
test_setup(); setup_study();
init_resources(); init_resources();
f = test_create_faction(NULL); f = test_create_faction(NULL);
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);
@ -590,7 +596,8 @@ static void test_teach_two_skills(CuTest *tc) {
static void test_teach_one_to_many(CuTest *tc) { static void test_teach_one_to_many(CuTest *tc) {
unit *u, *ut; unit *u, *ut;
test_setup();
setup_study();
init_resources(); init_resources();
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));
scale_number(u, 20); scale_number(u, 20);
@ -611,7 +618,7 @@ static void test_teach_one_to_many(CuTest *tc) {
static void test_teach_many_to_one(CuTest *tc) { static void test_teach_many_to_one(CuTest *tc) {
unit *u, *u1, *u2; unit *u, *u1, *u2;
test_setup(); setup_study();
init_resources(); init_resources();
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));
scale_number(u, 20); scale_number(u, 20);
@ -639,11 +646,7 @@ static void test_teach_message(CuTest *tc) {
ally *al; ally *al;
teaching_info *teach; teaching_info *teach;
test_setup(); setup_study();
mt_create_va(mt_new("teach_teacher", NULL),
"teacher:unit", "student:unit", "skill:int", "level:int", MT_NEW_END);
mt_create_va(mt_new("teach_student", NULL),
"teacher:unit", "student:unit", "skill:int", MT_NEW_END);
init_resources(); init_resources();
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));
scale_number(u, 20); scale_number(u, 20);
@ -683,7 +686,7 @@ static void test_teach_many_to_many(CuTest *tc) {
region *r; region *r;
faction *f; faction *f;
test_setup(); setup_study();
init_resources(); init_resources();
f = test_create_faction(NULL); f = test_create_faction(NULL);
r = test_create_region(0, 0, NULL); r = test_create_region(0, 0, NULL);

View file

@ -277,15 +277,10 @@ void test_create_calendar(void) {
month_season[8] = SEASON_SUMMER; month_season[8] = SEASON_SUMMER;
} }
void test_inject_messagetypes(void)
{
message_handle_missing(MESSAGE_MISSING_REPLACE);
}
void test_setup_test(CuTest *tc, const char *file, int line) { void test_setup_test(CuTest *tc, const char *file, int line) {
test_log_stderr(LOG_CPERROR); test_log_stderr(LOG_CPERROR);
test_reset(); test_reset();
message_handle_missing(MESSAGE_MISSING_ERROR); message_handle_missing(MESSAGE_MISSING_REPLACE);
if (tc) { if (tc) {
log_debug("start test: %s", tc->name); log_debug("start test: %s", tc->name);
} }
@ -297,6 +292,7 @@ void test_setup_test(CuTest *tc, const char *file, int line) {
void test_teardown(void) void test_teardown(void)
{ {
message_handle_missing(MESSAGE_MISSING_IGNORE);
test_reset(); test_reset();
test_log_stderr(0); test_log_stderr(0);
} }

View file

@ -75,7 +75,6 @@ extern "C" {
void assert_string_parameter(struct CuTest * tc, struct message *msg, int index, const char *arg); void assert_string_parameter(struct CuTest * tc, struct message *msg, int index, const char *arg);
void disabled_test(void *suite, void (*)(struct CuTest *), const char *name); void disabled_test(void *suite, void (*)(struct CuTest *), const char *name);
void test_inject_messagetypes(void);
#define DISABLE_TEST(SUITE, TEST) disabled_test(SUITE, TEST, #TEST) #define DISABLE_TEST(SUITE, TEST) disabled_test(SUITE, TEST, #TEST)

View file

@ -198,6 +198,16 @@ message_type *mt_create_va(message_type *mtype, ...)
return mt_create(mtype, args, i - 1); return mt_create(mtype, args, i - 1);
} }
message_type *mt_create_feedback(const char *name) {
return mt_create_va(mt_new(name, NULL), "unit:unit", "region:region", "command:order", MT_NEW_END);
}
message_type *mt_create_error(int error) {
char name[16];
snprintf(name, sizeof(name), "error%d", error);
return mt_create_feedback(name);
}
static variant copy_arg(const arg_type * atype, variant data) static variant copy_arg(const arg_type * atype, variant data)
{ {
assert(atype != NULL); assert(atype != NULL);

View file

@ -64,6 +64,8 @@ extern "C" {
struct message_type *mt_new(const char *name, const char *section); struct message_type *mt_new(const char *name, const char *section);
/** message_type registry (optional): **/ /** message_type registry (optional): **/
struct message_type *mt_create(struct message_type *, const char *args[], int nargs); struct message_type *mt_create(struct message_type *, const char *args[], int nargs);
struct message_type *mt_create_feedback(const char *name);
struct message_type *mt_create_error(int error);
struct message_type *mt_create_va(struct message_type *, ...); struct message_type *mt_create_va(struct message_type *, ...);
const struct message_type *mt_find(const char *); const struct message_type *mt_find(const char *);