From 1f659327946ef73b70c1cbc839ec4f9c21a1943c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Sep 2017 17:20:09 +0200 Subject: [PATCH 1/3] add a test for get_equipment with substrings. --- src/kernel/equipment.test.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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; } From 69079ce319da71321874cd5bfe2b598e752fdcb2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Sep 2017 17:20:58 +0200 Subject: [PATCH 2/3] remove it_register, because it does nothing. --- src/kernel/item.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/kernel/item.c b/src/kernel/item.c index 8639ac5d1..81a0c78cb 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -192,16 +192,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" }, @@ -244,7 +234,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; } From 7fdbb1b939c8ccbb2392d6d261a45bf7c69e40d6 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Sep 2017 17:26:34 +0200 Subject: [PATCH 3/3] add a test for rt_find to flush out substring matches. --- src/kernel/item.test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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);