fix broken tests and clear locales (badly) when clearing global stte

This commit is contained in:
Enno Rehling 2012-05-19 20:49:47 +02:00
parent 7f7c883583
commit b44737387a
4 changed files with 17 additions and 4 deletions

View File

@ -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"));

View File

@ -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]);

View File

@ -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));

View File

@ -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)