add a test for default_order, so I can change it.

This commit is contained in:
Enno Rehling 2016-04-09 18:49:25 +02:00
parent 01ecc72f2d
commit 11ae7dd55e
5 changed files with 26 additions and 14 deletions

View File

@ -2332,7 +2332,7 @@ void do_attack(fighter * af)
if (apr > 0) { if (apr > 0) {
/* Wenn die Waffe nachladen muss, oder es sich nicht um einen /* Wenn die Waffe nachladen muss, oder es sich nicht um einen
* Waffen-Angriff handelt, dann gilt der Speed nicht. */ * 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) if (u_race(au)->attack[a].type != AT_STANDARD)
continue; continue;
else { else {

View File

@ -1013,7 +1013,6 @@ void set_default_order(int kwd) {
// see also test_long_order_hungry // see also test_long_order_hungry
order *default_order(const struct locale *lang) order *default_order(const struct locale *lang)
{ {
static int usedefault = 1;
int i = locale_index(lang); int i = locale_index(lang);
order *result = 0; order *result = 0;
assert(i < MAXLOCALES); assert(i < MAXLOCALES);
@ -1023,14 +1022,11 @@ order *default_order(const struct locale *lang)
} }
result = defaults[i]; result = defaults[i];
if (!result && usedefault) { if (!result) {
const char * str = LOC(lang, "defaultorder"); const char * str = LOC(lang, "defaultorder");
if (str) { if (str) {
result = defaults[i] = parse_order(str, lang); result = defaults[i] = parse_order(str, lang);
} }
else {
usedefault = 0;
}
} }
return result ? copy_order(result) : 0; return result ? copy_order(result) : 0;
} }

View File

@ -172,6 +172,22 @@ static void test_forbiddenid(CuTest *tc) {
CuAssertIntEquals(tc, 1, forbiddenid(atoi36("t"))); 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 *get_config_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -181,5 +197,6 @@ CuSuite *get_config_suite(void)
SUITE_ADD_TEST(suite, test_forbiddenid); SUITE_ADD_TEST(suite, test_forbiddenid);
SUITE_ADD_TEST(suite, test_getunit); SUITE_ADD_TEST(suite, test_getunit);
SUITE_ADD_TEST(suite, test_read_unitid); SUITE_ADD_TEST(suite, test_read_unitid);
SUITE_ADD_TEST(suite, test_default_order);
return suite; return suite;
} }

View File

@ -511,7 +511,7 @@ static void json_prefixes(cJSON *json) {
} }
/** disable a feature. /** disable a feature.
* features are identified by eone of: * features are identified by one of:
* 1. the keyword for their orders, * 1. the keyword for their orders,
* 2. the name of the skill they use, * 2. the name of the skill they use,
* 3. a "module.enabled" flag in the settings * 3. a "module.enabled" flag in the settings
@ -525,14 +525,12 @@ static void disable_feature(const char *str) {
enable_skill(sk, false); enable_skill(sk, false);
return; return;
} }
for (k = 0; k != MAXKEYWORDS; ++k) { k = findkeyword(str);
// FIXME: this loop is slow as balls. if (k!=NOKEYWORD) {
if (strcmp(keywords[k], str) == 0) {
log_debug("disable keyword %s\n", str); log_debug("disable keyword %s\n", str);
enable_keyword(k, false); enable_keyword(k, false);
return; return;
} }
}
_snprintf(name, sizeof(name), "%s.enabled", str); _snprintf(name, sizeof(name), "%s.enabled", str);
log_info("disable feature %s\n", name); log_info("disable feature %s\n", name);
config_set(name, "0"); config_set(name, "0");

View File

@ -101,6 +101,7 @@ struct locale * test_create_locale(void) {
test_translate_param(loc, i, parameters[i]); test_translate_param(loc, i, parameters[i]);
} }
init_parameters(loc); init_parameters(loc);
init_keywords(loc);
init_skills(loc); init_skills(loc);
} }
return loc; return loc;