diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 1e6bf1819..4ed077fb0 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -10,7 +10,7 @@ #include #include -void test_equipment(CuTest * tc) +static void test_equipment(CuTest * tc) { equipment * eq; unit * u; @@ -46,9 +46,33 @@ void test_equipment(CuTest * tc) test_cleanup(); } +static void test_get_equipment(CuTest * tc) +{ + equipment * eq; + + test_setup(); + eq = create_equipment("catapultammo"); + CuAssertPtrNotNull(tc, eq); + CuAssertStrEquals(tc, "catapultammo", eq->name); + eq = get_equipment("catapultammo"); + CuAssertPtrNotNull(tc, eq); + CuAssertStrEquals(tc, "catapultammo", eq->name); + eq = get_equipment("catapult"); + CuAssertPtrEquals(tc, NULL, eq); + eq = create_equipment("catapult"); + eq = get_equipment("catapult"); + CuAssertPtrNotNull(tc, eq); + CuAssertStrEquals(tc, "catapult", eq->name); + eq = get_equipment("catapultammo"); + CuAssertPtrNotNull(tc, eq); + CuAssertStrEquals(tc, "catapultammo", eq->name); + test_cleanup(); +} + CuSuite *get_equipment_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_equipment); + SUITE_ADD_TEST(suite, test_get_equipment); return suite; } diff --git a/src/kernel/item.c b/src/kernel/item.c index 7f77fc3bb..2c38db008 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -203,16 +203,6 @@ resource_type *rt_get_or_create(const char *name) { return rtype; } -static void it_register(item_type * itype) -{ - char buffer[64]; - const char * name = itype->rtype->_name; - size_t len = strlen(name); - - assert(len < sizeof(buffer) - sizeof(itype)); - len = cb_new_kv(name, len, &itype, sizeof(itype), buffer); -} - static const char *it_aliases[][2] = { { "Runenschwert", "runesword" }, { "p12", "truthpotion" }, @@ -255,7 +245,6 @@ item_type *it_get_or_create(resource_type *rtype) { rtype->uchange = res_changeitem; rtype->itype = itype; rtype->flags |= RTF_ITEM; - it_register(itype); return itype; } diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index c1c64bf62..c6113ec5d 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -173,12 +173,31 @@ static void test_core_resources(CuTest *tc) { test_cleanup(); } +static void test_get_resource(CuTest *tc) { + resource_type *rtype; + + test_setup(); + + CuAssertPtrEquals(tc, NULL, rt_find("catapultammo")); + rtype = rt_get_or_create("catapultammo"); + CuAssertPtrNotNull(tc, rtype); + CuAssertPtrEquals(tc, rtype, rt_find("catapultammo")); + CuAssertStrEquals(tc, "catapultammo", rtype->_name); + + CuAssertPtrEquals(tc, NULL, rt_find("catapult")); + rtype = rt_get_or_create("catapult"); + CuAssertPtrEquals(tc, rtype, rt_find("catapult")); + CuAssertStrEquals(tc, "catapult", rtype->_name); + test_cleanup(); +} + CuSuite *get_item_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_resourcename_no_appearance); SUITE_ADD_TEST(suite, test_resourcename_with_appearance); SUITE_ADD_TEST(suite, test_change_item); + SUITE_ADD_TEST(suite, test_get_resource); SUITE_ADD_TEST(suite, test_resource_type); SUITE_ADD_TEST(suite, test_finditemtype); SUITE_ADD_TEST(suite, test_findresourcetype);