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 c8c1d8c27d
commit b57db72396
4 changed files with 75 additions and 3 deletions

30
src/kernel/item_test.c Normal file
View File

@ -0,0 +1,30 @@
#include <platform.h>
#include <kernel/item.h>
#include <cutest/CuTest.h>
#include <tests.h>
void test_resource_type(CuTest * tc)
{
resource_type *rtype;
const char *names[2] = { 0 , 0 };
CuAssertPtrEquals(tc, 0, rt_find("herpderp"));
names[0] = names[1] = "herpderp";
new_resourcetype(names, NULL, RTF_NONE);
names[0] = names[1] = "herp";
rtype = new_resourcetype(names, NULL, RTF_NONE);
names[0] = names[1] = "herpes";
new_resourcetype(names, NULL, RTF_NONE);
CuAssertPtrEquals(tc, rtype, rt_find("herp"));
}
CuSuite *get_item_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_resource_type);
return suite;
}

View File

@ -100,6 +100,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();
}
@ -155,9 +157,13 @@ void test_create_world(void)
building_type *btype;
ship_type *stype;
item_type * itype;
const char * names[2] = { "horse", "horse_p" };
const char * horses[2] = { "horse", "horse_p" };
itype = test_create_itemtype(names);
make_locale("de");
init_resources();
assert(!olditemtype[I_HORSE]);
itype = test_create_itemtype(horses);
olditemtype[I_HORSE] = itype;
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);

30
src/tests_test.c Normal file
View File

@ -0,0 +1,30 @@
#include <kernel/item.h>
#include <kernel/region.h>
#include <cutest/CuTest.h>
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));
}
CuSuite *get_tests_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_recreate_world);
return suite;
}

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)