From 113a6e68c721659129d31f4f9c77b3b1d877b028 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 28 Oct 2018 21:27:24 +0100 Subject: [PATCH 1/4] BUG 2507: LERNE AUTO with invalid skill. --- src/automate.c | 20 +++++++++------- src/skill.c | 5 +++- src/study.c | 65 +++++++++++++++++++++++++++++++++----------------- src/study.h | 1 + 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/automate.c b/src/automate.c index 1a553df29..9a3516c44 100644 --- a/src/automate.c +++ b/src/automate.c @@ -34,17 +34,19 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r) int nscholars = 0; for (u = r->units; u; u = u->next) { - keyword_t kwd = getkeyword(u->thisorder); + keyword_t kwd = init_order(u->thisorder, u->faction->locale); if (kwd == K_AUTOSTUDY) { - if (long_order_allowed(u) && unit_can_study(u)) { + if (long_order_allowed(u)) { scholar * st = scholars + nscholars; - init_order(u->thisorder, u->faction->locale); - st->sk = getskill(u->faction->locale); - st->level = effskill_study(u, st->sk); - st->learn = 0; - st->u = u; - if (++nscholars == max_scholars) { - log_fatal("you must increase MAXSCHOLARS"); + skill_t sk = getskill(u->faction->locale); + if (check_student(u, u->thisorder, sk)) { + st->sk = sk; + st->level = effskill_study(u, st->sk); + st->learn = 0; + st->u = u; + if (++nscholars == max_scholars) { + log_fatal("you must increase MAXSCHOLARS"); + } } } else { diff --git a/src/skill.c b/src/skill.c index b279ab488..2521befc6 100644 --- a/src/skill.c +++ b/src/skill.c @@ -116,7 +116,9 @@ skill_t get_skill(const char *s, const struct locale * lang) int skill_cost(skill_t sk) { static int config; static int costs[MAXSKILLS]; - int cost; + int cost = -1; + + assert(sk >= 0 && sk < MAXSKILLS); switch (sk) { case SK_SPY: cost = 100; @@ -146,5 +148,6 @@ int skill_cost(skill_t sk) { } bool expensive_skill(skill_t sk) { + assert(sk >= 0 && sk < MAXSKILLS); return (sk == SK_MAGIC) || skill_cost(sk) > 0; } diff --git a/src/study.c b/src/study.c index c978e69ad..738c591d7 100644 --- a/src/study.c +++ b/src/study.c @@ -523,6 +523,48 @@ static void msg_teachers(struct selist *teachers, struct unit *u, skill_t sk) { selist_foreach_ex(teachers, cb_msg_teach, &cbdata); } +bool check_student(const struct unit *u, struct order *ord, skill_t sk) { + int err = 0; + + if (sk < 0) { + err = 77; + } + /* Hack: Talente mit Malus -99 koennen nicht gelernt werden */ + else if (u_race(u)->bonus[sk] == -99) { + err = 771; + } + else { + static int config; + static bool learn_newskills; + + if (config_changed(&config)) { + learn_newskills = config_get_int("study.newskills", 1) != 0; + } + if (!learn_newskills) { + skill *sv = unit_skill(u, sk); + if (sv == NULL) { + /* we can only learn skills we already have */ + err = 771; + } + } + } + if (err) { + if (ord) { + cmistake(u, ord, err, MSG_EVENT); + } + return false; + } + + if ((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) { + if (ord) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "error_race_nolearn", "race", u_race(u))); + } + return false; + } + return true; +} + int study_cmd(unit * u, order * ord) { region *r = u->region; @@ -536,7 +578,6 @@ int study_cmd(unit * u, order * ord) skill_t sk; int maxalchemy = 0; int speed_rule = (study_rule_t)config_get_int("study.speedup", 0); - bool learn_newskills = config_get_int("study.newskills", 1) != 0; static const race *rc_snotling; static int rc_cache; @@ -544,32 +585,12 @@ int study_cmd(unit * u, order * ord) rc_snotling = get_race(RC_SNOTLING); } - if (!unit_can_study(u)) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race", - u_race(u))); - return -1; - } - (void)init_order(ord, u->faction->locale); sk = getskill(u->faction->locale); - if (sk < 0) { - cmistake(u, ord, 77, MSG_EVENT); + if (!check_student(u, ord, sk)) { return -1; } - /* Hack: Talente mit Malus -99 koennen nicht gelernt werden */ - if (u_race(u)->bonus[sk] == -99) { - cmistake(u, ord, 771, MSG_EVENT); - return -1; - } - if (!learn_newskills) { - skill *sv = unit_skill(u, sk); - if (sv == NULL) { - /* we can only learn skills we already have */ - cmistake(u, ord, 771, MSG_EVENT); - return -1; - } - } /* snotlings koennen Talente nur bis T8 lernen */ if (u_race(u) == rc_snotling) { diff --git a/src/study.h b/src/study.h index cca0428b7..f85508dec 100644 --- a/src/study.h +++ b/src/study.h @@ -47,6 +47,7 @@ extern "C" { skill_t getskill(const struct locale *lang); bool is_migrant(struct unit *u); int study_cost(struct unit *u, skill_t sk); + bool check_student(const struct unit *u, struct order *ord, skill_t sk); typedef void(*learn_fun)(struct unit *u, skill_t sk, int days); From be84c13a72a88fa6d084c25f44a331ef2ca85d0f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 28 Oct 2018 21:28:05 +0100 Subject: [PATCH 2/4] remove test_inject_messagetypes(), make that the default behavior in tests. --- src/alchemy.test.c | 1 - src/automate.test.c | 10 ++++- src/economy.test.c | 4 +- src/give.test.c | 18 +++++---- src/items/xerewards.test.c | 2 - src/kernel/build.c | 41 ++++++++++--------- src/kernel/build.test.c | 4 +- src/kernel/curse.test.c | 1 - src/kernel/messages.c | 70 +++++++++++++++++++------------- src/kernel/messages.test.c | 17 ++++++++ src/kernel/order.c | 2 +- src/kernel/spell.test.c | 1 - src/kernel/unit.c | 4 -- src/kernel/unit.h | 1 - src/laws.test.c | 83 ++++++++++++++++++++++---------------- src/monsters.c | 4 +- src/piracy.test.c | 2 + src/renumber.test.c | 31 ++++++++------ src/reports.test.c | 2 - src/spells.test.c | 9 ----- src/study.test.c | 51 ++++++++++++----------- src/tests.c | 8 +--- src/tests.h | 1 - src/util/message.c | 10 +++++ src/util/message.h | 2 + 25 files changed, 218 insertions(+), 161 deletions(-) diff --git a/src/alchemy.test.c b/src/alchemy.test.c index 7510933fe..32024ba1c 100644 --- a/src/alchemy.test.c +++ b/src/alchemy.test.c @@ -26,7 +26,6 @@ static void test_herbsearch(CuTest * tc) const item_type *itype; test_setup(); - test_inject_messagetypes(); r = test_create_region(0, 0, NULL); rc = rc_get_or_create("dragon"); rc->flags |= RCF_UNARMEDGUARD; diff --git a/src/automate.test.c b/src/automate.test.c index a77376668..6c87b8656 100644 --- a/src/automate.test.c +++ b/src/automate.test.c @@ -9,17 +9,22 @@ #include "kernel/region.h" #include "kernel/unit.h" +#include "util/message.h" + #include "tests.h" #include static void test_autostudy_init(CuTest *tc) { scholar scholars[4]; - unit *u1, *u2, *u3; + unit *u1, *u2, *u3, *u4; faction *f; region *r; test_setup(); + mt_create_error(77); + mt_create_error(771); + r = test_create_plain(0, 0); f = test_create_faction(NULL); u1 = test_create_unit(f, r); @@ -30,8 +35,11 @@ static void test_autostudy_init(CuTest *tc) { set_level(u2, SK_ENTERTAINMENT, 2); u3 = test_create_unit(f, r); 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; CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r)); + CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77")); CuAssertPtrEquals(tc, u2, scholars[0].u); CuAssertIntEquals(tc, 2, scholars[0].level); CuAssertIntEquals(tc, 0, scholars[0].learn); diff --git a/src/economy.test.c b/src/economy.test.c index 90a4bd260..12fff57f8 100644 --- a/src/economy.test.c +++ b/src/economy.test.c @@ -145,6 +145,7 @@ static struct unit *create_recruiter(void) { static void setup_production(void) { 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("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); @@ -737,6 +738,7 @@ static void test_loot(CuTest *tc) { test_setup(); setup_production(); + mt_create_error(48); /* unit is unarmed */ it_silver = test_create_silver(); config_set("rules.enable_loot", "1"); 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); arm_unit(u); 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, UFL_LONGACTION | UFL_NOTMOVING, fval(u, UFL_LONGACTION | UFL_NOTMOVING)); test_teardown(); diff --git a/src/give.test.c b/src/give.test.c index 9c07c8cd0..3f6ffa40a 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -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_peasants", NULL), "unit:unit", "resource:resource", "amount:int", MT_NEW_END); /* 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_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_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("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); @@ -91,7 +94,7 @@ static void test_give_unit(CuTest * tc) { give_unit(env.src, env.dst, NULL); CuAssertPtrEquals(tc, env.f2, env.src->faction); 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.f2->msgs, "receive_person")); test_teardown(); @@ -159,11 +162,12 @@ static void test_give_men_magicians(CuTest * tc) { message * msg; test_setup_ex(tc); + mt_create_error(158); env.f2 = env.f1 = test_create_faction(NULL); setup_give(&env); set_level(env.src, SK_MAGIC, 1); 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.src->number); 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)); test_clear_messages(env.f1); 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")); msg_release(msg); @@ -407,7 +411,7 @@ static void test_give_okay(CuTest * tc) { setup_give(&env); 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(); } @@ -450,7 +454,7 @@ static void test_give_new_unit(CuTest * tc) { setup_give(&env); env.dst->number = 0; 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(); } diff --git a/src/items/xerewards.test.c b/src/items/xerewards.test.c index 8e30d88eb..dc9aa2621 100644 --- a/src/items/xerewards.test.c +++ b/src/items/xerewards.test.c @@ -18,7 +18,6 @@ static void test_manacrystal(CuTest *tc) { unit *u; test_setup(); - test_inject_messagetypes(); u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); itype = test_create_itemtype("manacrystal"); @@ -49,7 +48,6 @@ static void test_skillpotion(CuTest *tc) { int initialWeeks_Magic = 0; test_setup(); - test_inject_messagetypes(); u = test_create_unit(test_create_faction(NULL), test_create_plain(0, 0)); itype = test_create_itemtype("skillpotion"); change_resource(u, itype->rtype, 2); diff --git a/src/kernel/build.c b/src/kernel/build.c index 11324f752..1f96fcda9 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -500,6 +500,28 @@ static int count_materials(unit *u, const construction *type, int n, int complet 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. * Build up to 'size' points of 'type', where 'completed' * 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; } if (con->skill != NOSKILL) { - int effsk; - int dm = get_effect(u, oldpotiontype[P_DOMORE]); - basesk = effskill(u, con->skill, 0); if (basesk == 0) return ENEEDSKILL; - 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; - } + skills = build_skill(u, basesk, skill_mod); } for (; want > 0 && skills > 0;) { int err, n; diff --git a/src/kernel/build.test.c b/src/kernel/build.test.c index 9bae742c2..537f9d860 100644 --- a/src/kernel/build.test.c +++ b/src/kernel/build.test.c @@ -31,7 +31,6 @@ typedef struct build_fixture { static unit * setup_build(build_fixture *bf) { test_setup(); - test_inject_messagetypes(); init_resources(); test_create_itemtype("stone"); @@ -307,7 +306,6 @@ static void test_build_destroy_road_guard(CuTest *tc) order *ord; test_setup(); - test_inject_messagetypes(); test_create_region(1, 0, 0); r = test_create_region(0, 0, NULL); rsetroad(r, D_EAST, 100); @@ -340,7 +338,6 @@ static void test_build_destroy_road_limit(CuTest *tc) order *ord; test_setup(); - test_inject_messagetypes(); test_create_region(1, 0, 0); r = test_create_region(0, 0, NULL); rsetroad(r, D_EAST, 100); @@ -365,6 +362,7 @@ static void test_build_destroy_cmd(CuTest *tc) { faction *f; test_setup(); + mt_create_error(138); u = test_create_unit(f = test_create_faction(NULL), test_create_region(0, 0, NULL)); u->thisorder = create_order(K_DESTROY, f->locale, NULL); CuAssertIntEquals(tc, 138, destroy_cmd(u, u->thisorder)); diff --git a/src/kernel/curse.test.c b/src/kernel/curse.test.c index 9c74544e1..dc3603d50 100644 --- a/src/kernel/curse.test.c +++ b/src/kernel/curse.test.c @@ -51,7 +51,6 @@ typedef struct { static void setup_curse(curse_fixture *fix, const char *name) { test_setup(); - test_inject_messagetypes(); fix->r = test_create_region(0, 0, NULL); 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); diff --git a/src/kernel/messages.c b/src/kernel/messages.c index e0513b00d..48ea13f1f 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -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, const char *name, const char *sig, ...) { @@ -80,13 +120,7 @@ struct message *msg_feedback(const struct unit *u, struct order *ord, } if (!mtype) { - log_warning("trying to create message of unknown type \"%s\"\n", name); - 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); + return missing_feedback(name, u, u->region, ord); } var.v = (void *)u; @@ -139,28 +173,6 @@ 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 (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, ...) /* msg_message("oops_error", "unit region command", u, r, cmd) */ { diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index 3c9c684c6..4ac106ff3 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -18,6 +18,23 @@ void test_missing_message(CuTest *tc) { CuAssertPtrNotNull(tc, msg); CuAssertPtrNotNull(tc, msg->type); 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); test_teardown(); } diff --git a/src/kernel/order.c b/src/kernel/order.c index c14a2b30b..8561744dd 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -342,7 +342,7 @@ order *parse_order(const char *s, const struct locale * lang) sptr = sp; p = parse_token(&sp, token, sizeof(token)); sk = get_skill(p, lang); - if (!expensive_skill(sk)) { + if (sk == NOSKILL || !expensive_skill(sk)) { kwd = K_AUTOSTUDY; } } diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 622780e20..025584114 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -33,7 +33,6 @@ static void test_create_duplicate_spell(CuTest * tc) strlist *sl = 0; test_setup(); - test_inject_messagetypes(); test_log_stderr(0); /* suppress the "duplicate spell" error message */ log = test_log_start(LOG_CPERROR, &sl); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 770723bea..b63e8beb8 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1853,10 +1853,6 @@ bool unit_name_equals_race(const unit *u) { 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) { int n; diff --git a/src/kernel/unit.h b/src/kernel/unit.h index a6135715c..0b0e9da6f 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -246,7 +246,6 @@ extern "C" { const char *unitname(const struct unit *u); char *write_unitname(const struct unit *u, char *buffer, size_t size); bool unit_name_equals_race(const struct unit *u); - bool unit_can_study(const struct unit *u); /* getunit results: */ #define GET_UNIT 0 diff --git a/src/laws.test.c b/src/laws.test.c index c7c7a6682..99490c8c3 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -153,8 +153,8 @@ static void test_enter_building(CuTest * tc) rc->flags = RCF_SWIM; u->building = 0; CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false)); - CuAssertPtrEquals(tc, 0, u->building); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->building); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true)); CuAssertPtrNotNull(tc, u->faction->msgs); @@ -170,7 +170,6 @@ static void test_enter_ship(CuTest * tc) race * rc; test_setup(); - r = test_create_region(0, 0, NULL); rc = test_create_race("smurf"); u = test_create_unit(test_create_faction(rc), r); @@ -194,8 +193,8 @@ static void test_enter_ship(CuTest * tc) rc->flags = RCF_SWIM; u->ship = 0; CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false)); - CuAssertPtrEquals(tc, 0, u->ship); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->ship); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true)); CuAssertPtrNotNull(tc, u->faction->msgs); @@ -486,6 +485,10 @@ static void test_limit_new_units(CuTest * tc) alliance *al; 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"); f = test_create_faction(NULL); u = test_create_unit(f, test_create_region(0, 0, NULL)); @@ -901,6 +904,9 @@ static unit * setup_name_cmd(void) { faction *f; 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_notseen", NULL), "region:region", "building:building", MT_NEW_END); 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_LONGACTION)); CuAssertPtrNotNull(tc, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); - CuAssertPtrEquals(tc, 0, u->old_orders); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->old_orders); test_teardown(); } @@ -1060,9 +1066,9 @@ static void test_long_order_none(CuTest *tc) { test_setup(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); - CuAssertPtrEquals(tc, 0, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->orders); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); 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)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); 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)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); test_teardown(); } @@ -1099,6 +1105,7 @@ static void test_long_order_multi_long(CuTest *tc) { /* TODO: write more tests */ unit *u; test_setup(); + mt_create_error(52); 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_DESTROY, u->faction->locale, NULL)); @@ -1113,11 +1120,12 @@ static void test_long_order_multi_buy(CuTest *tc) { /* TODO: write more tests */ unit *u; test_setup(); + mt_create_error(52); 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)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); 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_SELL, u->faction->locale, 0)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); test_teardown(); } @@ -1142,11 +1150,12 @@ static void test_long_order_buy_cast(CuTest *tc) { /* TODO: write more tests */ unit *u; test_setup(); + mt_create_error(52); 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_CAST, u->faction->locale, 0)); update_long_order(u); - CuAssertPtrEquals(tc, 0, u->thisorder); + CuAssertPtrEquals(tc, NULL, u->thisorder); CuAssertPtrNotNull(tc, u->orders); CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); test_teardown(); @@ -1164,7 +1173,7 @@ static void test_long_order_hungry(CuTest *tc) { update_long_order(u); CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder)); CuAssertPtrNotNull(tc, u->orders); - CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertPtrEquals(tc, NULL, u->faction->msgs); test_teardown(); } @@ -1174,9 +1183,10 @@ static void test_ally_cmd_errors(CuTest *tc) { order *ord; test_setup(); + mt_create_error(66); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); 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)); 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)); 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)); free_order(ord); ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT])); 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)); free_order(ord); ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD])); 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)); 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])); 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)); free_order(ord); @@ -1325,6 +1335,8 @@ static unit * setup_mail_cmd(void) { faction *f; 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("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); @@ -1383,7 +1395,7 @@ static void test_mail_unit_no_msg(CuTest *tc) { f = u->faction; ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no)); 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")); free_order(ord); test_teardown(); @@ -1398,7 +1410,7 @@ static void test_mail_faction_no_msg(CuTest *tc) { f = u->faction; ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no)); 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")); free_order(ord); test_teardown(); @@ -1413,7 +1425,7 @@ static void test_mail_faction_no_target(CuTest *tc) { f = u->faction; ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1)); 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")); free_order(ord); test_teardown(); @@ -1428,7 +1440,7 @@ static void test_mail_region_no_msg(CuTest *tc) { f = u->faction; ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION])); 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")); free_order(ord); test_teardown(); @@ -1444,6 +1456,8 @@ static void test_show_without_item(CuTest *tc) struct locale *loc; 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); loc = get_or_create_locale("de"); @@ -1466,14 +1480,14 @@ static void test_show_without_item(CuTest *tc) locale_setstring(loc, "iteminfo::testitem", "testdescription"); 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")); test_clear_messages(f); i_add(&(u->items), i_new(itype, 1)); reshow_cmd(u, ord); - CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21")); - CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36")); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21")); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error36")); test_clear_messages(f); free_order(ord); @@ -1488,7 +1502,6 @@ static void test_show_race(CuTest *tc) { message * msg; test_setup(); - mt_create_va(mt_new("msg_event", NULL), "string:string", MT_NEW_END); test_create_race("human"); rc = test_create_race("elf"); @@ -1504,8 +1517,8 @@ static void test_show_race(CuTest *tc) { ord = create_order(K_RESHOW, loc, "Mensch"); reshow_cmd(u, ord); - CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "error21") != NULL); - CuAssertTrue(tc, test_find_messagetype(u->faction->msgs, "msg_event") == NULL); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error21")); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "msg_event")); test_clear_messages(u->faction); free_order(ord); @@ -1618,7 +1631,7 @@ static void test_demon_hunger(CuTest * tc) get_food(r); 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"); diff --git a/src/monsters.c b/src/monsters.c index 89a678f11..cd59f9b23 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -555,7 +555,7 @@ static order *monster_learn(unit * u) const struct locale *lang = u->faction->locale; /* can these monsters even study? */ - if (!unit_can_study(u)) { + if (!check_student(u, NULL, SK_PERCEPTION)) { 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 * zu bewachen: */ if (rc->bonus[SK_WEAPONLESS] != -99) { diff --git a/src/piracy.test.c b/src/piracy.test.c index 096e267b7..9d2603d42 100644 --- a/src/piracy.test.c +++ b/src/piracy.test.c @@ -30,6 +30,8 @@ static void setup_piracy(void) { st_boat = test_create_shiptype("boat"); st_boat->cargo = 1000; + mt_create_error(144); + mt_create_error(146); mt_create_va(mt_new("piratenovictim", NULL), "ship:ship", "unit:unit", "region:region", MT_NEW_END); mt_create_va(mt_new("piratesawvictim", NULL), diff --git a/src/renumber.test.c b/src/renumber.test.c index 98ca9b48b..8ad0c6e12 100644 --- a/src/renumber.test.c +++ b/src/renumber.test.c @@ -14,12 +14,19 @@ #include #include +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) { unit *u; int uno, no; 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)); no = u->faction->no; uno = (no > 1) ? no - 1 : no + 1; @@ -37,7 +44,7 @@ static void test_renumber_faction_duplicate(CuTest *tc) { int no; const struct locale *lang; - test_setup_ex(tc); + setup_renumber(tc); mt_create_va(mt_new("renumber_inuse", NULL), "id:int", MT_NEW_END); f2 = test_create_faction(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; 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)); no = f->no; lang = f->locale; @@ -87,7 +94,7 @@ static void test_renumber_building(CuTest *tc) { int uno, no; 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->building = test_create_building(u->region, NULL); no = u->building->no; @@ -105,7 +112,7 @@ static void test_renumber_building_duplicate(CuTest *tc) { int uno, no; 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->building = test_create_building(u->region, NULL); uno = u->building->no; @@ -124,7 +131,7 @@ static void test_renumber_ship(CuTest *tc) { int uno, no; 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->ship = test_create_ship(u->region, NULL); no = u->ship->no; @@ -141,7 +148,7 @@ static void test_renumber_ship_twice(CuTest *tc) { int uno, no; 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->ship = test_create_ship(u->region, NULL); no = u->ship->no; @@ -163,7 +170,7 @@ static void test_renumber_ship_duplicate(CuTest *tc) { int uno, no; 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->ship = test_create_ship(u->region, NULL); uno = u->ship->no; @@ -182,7 +189,7 @@ static void test_renumber_unit(CuTest *tc) { int uno, no; 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)); no = u->no; uno = (no > 1) ? no - 1 : no + 1; @@ -200,7 +207,7 @@ static void test_renumber_unit_duplicate(CuTest *tc) { int no; 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)); no = u->no; u2 = test_create_unit(f, u->region); @@ -219,7 +226,7 @@ static void test_renumber_unit_limit(CuTest *tc) { int no; 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)); no = u->no; lang = f->locale; @@ -237,7 +244,7 @@ static void test_renumber_unit_invalid(CuTest *tc) { int no; 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)); no = u->no; lang = f->locale; diff --git a/src/reports.test.c b/src/reports.test.c index 65b5b06b0..6c19719e2 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -791,7 +791,6 @@ static void test_insect_warnings(CuTest *tc) { test_setup(); test_create_calendar(); - test_inject_messagetypes(); f = test_create_faction(test_create_race("insect")); CuAssertIntEquals(tc, SEASON_AUTUMN, get_gamedate(1083, &gd)->season); @@ -819,7 +818,6 @@ static void test_newbie_warning(CuTest *tc) { faction *f; test_setup(); - test_inject_messagetypes(); f = test_create_faction(NULL); config_set_int("NewbieImmunity", 3); diff --git a/src/spells.test.c b/src/spells.test.c index e6150cb46..1e024ef7f 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -27,10 +27,6 @@ #include #include -static void setup_spells(void) { - test_inject_messagetypes(); -} - static void test_good_dreams(CuTest *tc) { struct region *r; struct faction *f1, *f2; @@ -40,7 +36,6 @@ static void test_good_dreams(CuTest *tc) { curse *curse; test_setup(); - setup_spells(); test_create_world(); r = findregion(0, 0); f1 = test_create_faction(NULL); @@ -70,7 +65,6 @@ static void test_dreams(CuTest *tc) { castorder co; test_setup(); - setup_spells(); r = test_create_region(0, 0, NULL); f1 = test_create_faction(NULL); f2 = test_create_faction(NULL); @@ -98,7 +92,6 @@ static void test_bad_dreams(CuTest *tc) { curse *curse; test_setup(); - setup_spells(); test_create_world(); r = findregion(0, 0); f1 = test_create_faction(NULL); @@ -129,7 +122,6 @@ static void test_view_reality(CuTest *tc) { castorder co; test_setup(); - setup_spells(); mt_create_va(mt_new("spell_astral_only", NULL), "unit:unit", "region:region", "command:order", MT_NEW_END); mt_create_va(mt_new("viewreality_effect", NULL), @@ -165,7 +157,6 @@ static void test_watch_region(CuTest *tc) { region *r; faction *f; test_setup(); - setup_spells(); r = test_create_region(0, 0, NULL); f = test_create_faction(NULL); CuAssertIntEquals(tc, -1, get_observer(r, f)); diff --git a/src/study.test.c b/src/study.test.c index a63be7cf1..679615203 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -58,6 +58,11 @@ typedef struct { } study_fixture; 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), "unit:unit", "region:region", "cost:int", "skill:int", MT_NEW_END); 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; assert(fix); - test_setup(); + setup_study(); config_set("study.random_progress", "0"); r = test_create_region(0, 0, NULL); f = test_create_faction(NULL); @@ -148,7 +153,7 @@ static void test_study_bug_2194(CuTest *tc) { struct locale * loc; building * b; - test_setup(); + setup_study(); random_source_inject_constant(0.0); init_resources(); loc = test_create_locale(); @@ -205,7 +210,7 @@ static void test_produceexp(CuTest *tc) { unit *u; g_tc = tc; - test_setup(); + setup_study(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 2); config_set("study.produceexp", "20"); @@ -220,7 +225,7 @@ static void test_academy_building(CuTest *tc) { building * b; message * msg; - test_setup(); + setup_study(); mt_create_va(mt_new("teach_asgood", NULL), "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; building * b; - test_setup(); setup_study(); random_source_inject_constant(0.0); @@ -328,7 +332,8 @@ static void test_academy_bonus(CuTest *tc) { void test_learn_skill_single(CuTest *tc) { unit *u; skill *sv; - test_setup(); + + setup_study(); config_set("study.random_progress", "0"); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); learn_skill(u, SK_ALCHEMY, STUDYDAYS); @@ -347,7 +352,8 @@ void test_learn_skill_single(CuTest *tc) { void test_learn_skill_multi(CuTest *tc) { unit *u; skill *sv; - test_setup(); + + setup_study(); config_set("study.random_progress", "0"); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 10); @@ -367,7 +373,8 @@ void test_learn_skill_multi(CuTest *tc) { static void test_demon_skillchanges(CuTest *tc) { unit * u; const race * rc; - test_setup(); + + setup_study(); rc = test_create_race("demon"); CuAssertPtrEquals(tc, (void *)rc, (void *)get_race(RC_DAEMON)); 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) { unit *u; - test_setup(); + + setup_study(); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); 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 item_type *itype; - test_setup(); setup_study(); init_resources(); f = test_create_faction(NULL); @@ -432,7 +439,6 @@ static void test_study_magic(CuTest *tc) { static void test_study_cost_magic(CuTest *tc) { unit * u; - test_setup(); setup_study(); 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; const struct item_type *itype; - test_setup(); setup_study(); itype = test_create_silver(); @@ -484,7 +489,6 @@ static void test_teach_magic(CuTest *tc) { faction *f; const struct item_type *itype; - test_setup(); setup_study(); init_resources(); itype = get_resourcetype(R_SILVER)->itype; @@ -510,7 +514,8 @@ static void test_teach_magic(CuTest *tc) { static void test_teach_cmd(CuTest *tc) { unit *u, *ut; - test_setup(); + + setup_study(); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 10); @@ -530,7 +535,8 @@ static void test_teach_cmd(CuTest *tc) { static void test_teach_two(CuTest *tc) { unit *u1, *u2, *ut; - test_setup(); + + setup_study(); init_resources(); u1 = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u1, 5); @@ -560,7 +566,7 @@ static void test_teach_two_skills(CuTest *tc) { faction *f; region *r; - test_setup(); + setup_study(); init_resources(); f = test_create_faction(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) { unit *u, *ut; - test_setup(); + + setup_study(); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); 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) { unit *u, *u1, *u2; - test_setup(); + setup_study(); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 20); @@ -639,11 +646,7 @@ static void test_teach_message(CuTest *tc) { ally *al; teaching_info *teach; - test_setup(); - 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); + setup_study(); init_resources(); u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL)); scale_number(u, 20); @@ -683,7 +686,7 @@ static void test_teach_many_to_many(CuTest *tc) { region *r; faction *f; - test_setup(); + setup_study(); init_resources(); f = test_create_faction(NULL); r = test_create_region(0, 0, NULL); diff --git a/src/tests.c b/src/tests.c index f8035e129..6c6ce7b58 100644 --- a/src/tests.c +++ b/src/tests.c @@ -277,15 +277,10 @@ void test_create_calendar(void) { 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) { test_log_stderr(LOG_CPERROR); test_reset(); - message_handle_missing(MESSAGE_MISSING_ERROR); + message_handle_missing(MESSAGE_MISSING_REPLACE); if (tc) { 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) { + message_handle_missing(MESSAGE_MISSING_IGNORE); test_reset(); test_log_stderr(0); } diff --git a/src/tests.h b/src/tests.h index 441db9e16..d2a77d1b4 100644 --- a/src/tests.h +++ b/src/tests.h @@ -75,7 +75,6 @@ extern "C" { 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 test_inject_messagetypes(void); #define DISABLE_TEST(SUITE, TEST) disabled_test(SUITE, TEST, #TEST) diff --git a/src/util/message.c b/src/util/message.c index 8915dca8f..82258e02f 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -198,6 +198,16 @@ message_type *mt_create_va(message_type *mtype, ...) 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) { assert(atype != NULL); diff --git a/src/util/message.h b/src/util/message.h index 5aa16232b..52b087203 100644 --- a/src/util/message.h +++ b/src/util/message.h @@ -64,6 +64,8 @@ extern "C" { struct message_type *mt_new(const char *name, const char *section); /** message_type registry (optional): **/ 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 *, ...); const struct message_type *mt_find(const char *); From dce5f7857be2e9dc7c69ec4a28eb0c2f8a7d42b2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 28 Oct 2018 21:31:58 +0100 Subject: [PATCH 3/4] unused variable --- src/kernel/messages.test.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/kernel/messages.test.c b/src/kernel/messages.test.c index 4ac106ff3..9e66638d9 100644 --- a/src/kernel/messages.test.c +++ b/src/kernel/messages.test.c @@ -25,11 +25,9 @@ void test_missing_message(CuTest *tc) { 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); From e5207fd1c7b858b7c551f9bc873a1ad0506ff643 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 28 Oct 2018 21:55:34 +0100 Subject: [PATCH 4/4] do not backup eressea.db right now --- process/backup-eressea | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/backup-eressea b/process/backup-eressea index 4e5f69002..0f81cf53e 100755 --- a/process/backup-eressea +++ b/process/backup-eressea @@ -34,4 +34,4 @@ fi tar cjf backup/$TURN.tar.bz2 $files echo "uploading game-$GAME/$TURN.tar.bz2" curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2 -curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db +#curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db