From 52e323fef8b8e3264b6e47aefc137a358ef18bb5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 20 May 2012 23:03:16 -0700 Subject: [PATCH] added a test that fails because of stupid static state in finditemtype --- src/kernel/item_test.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/kernel/item_test.c b/src/kernel/item_test.c index 98a8188a0..6c2704f13 100644 --- a/src/kernel/item_test.c +++ b/src/kernel/item_test.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -11,6 +12,8 @@ void test_resource_type(CuTest * tc) struct item_type *itype; const char *names[2] = { 0 , 0 }; + test_cleanup(); + CuAssertPtrEquals(tc, 0, rt_find("herpderp")); names[0] = names[1] = "herpderp"; @@ -26,9 +29,35 @@ void test_resource_type(CuTest * tc) CuAssertPtrEquals(tc, itype->rtype, rt_find("herp")); } +void test_finditemtype(CuTest * tc) +{ + struct item_type *itype; + const char *names[4] = { "herp" , "herp_p", "derp", "derp_p" }; + struct locale * lang = make_locale("de"); + + test_cleanup(); + + itype = test_create_itemtype(names); + CuAssertPtrNotNull(tc, itype); + locale_setstring(lang, names[0], "Foo"); + locale_setstring(lang, names[1], "Foos"); + + CuAssertPtrEquals(tc, (void*)itype, (void*)finditemtype("Foo", lang)); + CuAssertPtrEquals(tc, (void*)itype, (void*)finditemtype("Foos", lang)); + + itype = test_create_itemtype(names+2); + CuAssertPtrNotNull(tc, itype); + locale_setstring(lang, names[2], "Bar"); + locale_setstring(lang, names[3], "Bars"); + + CuAssertPtrEquals(tc, (void*)itype, (void*)finditemtype("Bar", lang)); + CuAssertPtrEquals(tc, (void*)itype, (void*)finditemtype("Bars", lang)); +} + CuSuite *get_item_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_resource_type); + SUITE_ADD_TEST(suite, test_finditemtype); return suite; }