From 11ae7dd55eccfde37eecb6f02cf1253dd27ff776 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 9 Apr 2016 18:49:25 +0200 Subject: [PATCH] add a test for default_order, so I can change it. --- src/battle.c | 2 +- src/kernel/config.c | 6 +----- src/kernel/config.test.c | 17 +++++++++++++++++ src/kernel/jsonconf.c | 14 ++++++-------- src/tests.c | 1 + 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/battle.c b/src/battle.c index 231d7f2e1..6e4a25f24 100644 --- a/src/battle.c +++ b/src/battle.c @@ -2332,7 +2332,7 @@ void do_attack(fighter * af) if (apr > 0) { /* Wenn die Waffe nachladen muss, oder es sich nicht um einen * Waffen-Angriff handelt, dann gilt der Speed nicht. */ - /* FIXME allow multiple AT_NATURAL attacks? */ + /* TODO: allow multiple AT_NATURAL attacks? */ if (u_race(au)->attack[a].type != AT_STANDARD) continue; else { diff --git a/src/kernel/config.c b/src/kernel/config.c index 64afd98d3..cc769b2c9 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1013,7 +1013,6 @@ void set_default_order(int kwd) { // see also test_long_order_hungry order *default_order(const struct locale *lang) { - static int usedefault = 1; int i = locale_index(lang); order *result = 0; assert(i < MAXLOCALES); @@ -1023,14 +1022,11 @@ order *default_order(const struct locale *lang) } result = defaults[i]; - if (!result && usedefault) { + if (!result) { const char * str = LOC(lang, "defaultorder"); if (str) { result = defaults[i] = parse_order(str, lang); } - else { - usedefault = 0; - } } return result ? copy_order(result) : 0; } diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index 30b7cef90..7cd495284 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -172,6 +172,22 @@ static void test_forbiddenid(CuTest *tc) { CuAssertIntEquals(tc, 1, forbiddenid(atoi36("t"))); } +static void test_default_order(CuTest *tc) { + order *ord; + struct locale * loc; + + test_cleanup(); + loc = test_create_locale(); + ord = default_order(loc); + CuAssertPtrEquals(tc, 0, ord); + locale_setstring(loc, "defaultorder", "work"); + ord = default_order(loc); + CuAssertPtrNotNull(tc, ord); + CuAssertIntEquals(tc, K_WORK, getkeyword(ord)); + CuAssertPtrEquals(tc, ord->data, default_order(loc)->data); + test_cleanup(); +} + CuSuite *get_config_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -181,5 +197,6 @@ CuSuite *get_config_suite(void) SUITE_ADD_TEST(suite, test_forbiddenid); SUITE_ADD_TEST(suite, test_getunit); SUITE_ADD_TEST(suite, test_read_unitid); + SUITE_ADD_TEST(suite, test_default_order); return suite; } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index aac4bce10..721e6e60f 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -511,7 +511,7 @@ static void json_prefixes(cJSON *json) { } /** disable a feature. - * features are identified by eone of: + * features are identified by one of: * 1. the keyword for their orders, * 2. the name of the skill they use, * 3. a "module.enabled" flag in the settings @@ -525,13 +525,11 @@ static void disable_feature(const char *str) { enable_skill(sk, false); return; } - for (k = 0; k != MAXKEYWORDS; ++k) { - // FIXME: this loop is slow as balls. - if (strcmp(keywords[k], str) == 0) { - log_debug("disable keyword %s\n", str); - enable_keyword(k, false); - return; - } + k = findkeyword(str); + if (k!=NOKEYWORD) { + log_debug("disable keyword %s\n", str); + enable_keyword(k, false); + return; } _snprintf(name, sizeof(name), "%s.enabled", str); log_info("disable feature %s\n", name); diff --git a/src/tests.c b/src/tests.c index e150d2089..ebc8bd5fe 100644 --- a/src/tests.c +++ b/src/tests.c @@ -101,6 +101,7 @@ struct locale * test_create_locale(void) { test_translate_param(loc, i, parameters[i]); } init_parameters(loc); + init_keywords(loc); init_skills(loc); } return loc;