diff --git a/src/kernel/item_test.c b/src/kernel/item_test.c index 4ce7d8bf9..f12845ab4 100644 --- a/src/kernel/item_test.c +++ b/src/kernel/item_test.c @@ -12,11 +12,11 @@ void test_resource_type(CuTest * tc) CuAssertPtrEquals(tc, 0, rt_find("herpderp")); - names[0] = "herpderp"; + names[0] = names[1] = "herpderp"; new_resourcetype(names, NULL, RTF_NONE); - names[0] = "herp"; + names[0] = names[1] = "herp"; rtype = new_resourcetype(names, NULL, RTF_NONE); - names[0] = "herpes"; + names[0] = names[1] = "herpes"; new_resourcetype(names, NULL, RTF_NONE); CuAssertPtrEquals(tc, rtype, rt_find("herp")); diff --git a/src/tests.c b/src/tests.c index 3da1d8096..ab345bd88 100644 --- a/src/tests.c +++ b/src/tests.c @@ -107,6 +107,8 @@ void test_cleanup(void) test_clear_resources(); global.functions.maintenance = NULL; global.functions.wage = NULL; + default_locale = 0; + locales = 0; /* TODO: this is evil and leaky */ free_gamedata(); } @@ -164,6 +166,7 @@ void test_create_world(void) item_type * itype; const char * horses[2] = { "horse", "horse_p" }; + make_locale("de"); init_resources(); assert(!olditemtype[I_HORSE]); diff --git a/src/tests_test.c b/src/tests_test.c index 65c678e14..3f8a65513 100644 --- a/src/tests_test.c +++ b/src/tests_test.c @@ -6,13 +6,17 @@ static void test_recreate_world(CuTest * tc) { test_cleanup(); + CuAssertPtrEquals(tc, 0, find_locale("de")); CuAssertPtrEquals(tc, 0, it_find("money")); CuAssertPtrEquals(tc, 0, it_find("horse")); test_create_world(); + CuAssertPtrEquals(tc, default_locale, find_locale("de")); + CuAssertPtrNotNull(tc, default_locale); CuAssertPtrNotNull(tc, it_find("money")); CuAssertPtrNotNull(tc, it_find("horse")); CuAssertPtrNotNull(tc, findregion(0, 0)); test_cleanup(); + CuAssertPtrEquals(tc, 0, find_locale("de")); CuAssertPtrEquals(tc, 0, it_find("money")); CuAssertPtrEquals(tc, 0, it_find("horse")); CuAssertPtrEquals(tc, 0, findregion(0, 0)); diff --git a/src/util/language.c b/src/util/language.c index 9bb36cd2d..2af939234 100644 --- a/src/util/language.c +++ b/src/util/language.c @@ -57,6 +57,10 @@ locale *make_locale(const char *name) locale *l = (locale *) calloc(sizeof(locale), 1); locale **lp = &locales; + if (!locales) { + nextlocaleindex = 0; + } + while (*lp && (*lp)->hashkey != hkey) lp = &(*lp)->next; if (*lp) { @@ -164,8 +168,10 @@ void locale_setstring(locale * lang, const char *key, const char *value) unsigned int hkey = hashstring(key); unsigned int id = hkey & (SMAXHASH - 1); struct locale_str *find; - if (lang == NULL) + if (!lang) { lang = default_locale; + } + assert(lang); find = lang->strings[id]; while (find) { if (find->hashkey == hkey && strcmp(key, find->key) == 0)