From a342e846bc08c15e62121c431842410d8800a80b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 19 May 2012 17:23:57 -0700 Subject: [PATCH] improved some tests fixed some resource-related things, especially registration --- src/gamecode/market_test.c | 13 +++++++------ src/kernel/item.c | 5 +++++ src/kernel/item.h | 3 +++ src/kernel/item_test.c | 18 +++++++++++------- src/kernel/xmlreader.c | 7 ++++--- src/tests.h | 1 + 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/gamecode/market_test.c b/src/gamecode/market_test.c index 985538368..69726b9eb 100644 --- a/src/gamecode/market_test.c +++ b/src/gamecode/market_test.c @@ -27,7 +27,6 @@ static void test_market_curse(CuTest * tc) int x, y; const char *names[4] = { "herb", "herbs", "balm", "balms" }; const terrain_type *terrain; - resource_type *hres, *lres; item_type *htype, *ltype; luxury_type *lux; building_type *btype; @@ -36,15 +35,17 @@ static void test_market_curse(CuTest * tc) test_cleanup(); test_create_world(); - hres = new_resourcetype(names, 0, RTF_ITEM | RTF_POOLED); - htype = new_itemtype(hres, ITF_HERB, 0, 0); - lres = new_resourcetype(names + 2, 0, RTF_ITEM | RTF_POOLED); - ltype = new_itemtype(lres, ITF_NONE, 0, 0); + htype = test_create_itemtype(names); + htype->flags |= ITF_HERB; + htype->rtype->flags |= (RTF_ITEM | RTF_POOLED); + + ltype = test_create_itemtype(names + 2); + ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED); lux = new_luxurytype(ltype, 0); set_param(&global.parameters, "rules.region_owners", "1"); - btype = calloc(sizeof(building_type), 1); + btype = (building_type *)calloc(1, sizeof(building_type)); btype->_name = "market"; bt_register(btype); diff --git a/src/kernel/item.c b/src/kernel/item.c index 8bc425078..507fe1adf 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -965,10 +965,15 @@ static const char *names[] = { void init_resources(void) { + resource_type *rtype; if (r_hp) { return; } + rtype = new_resourcetype(names + 8, NULL, RTF_NONE); + rtype->uchange = res_changepeasants; + rt_register(rtype); + /* silver was never an item: */ r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM | RTF_POOLED); i_silver = new_itemtype(r_silver, ITF_NONE, 1 /*weight */ , 0); diff --git a/src/kernel/item.h b/src/kernel/item.h index 7f70f57c8..6cace8e99 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_ITEM #define H_KRNL_ITEM + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/item_test.c b/src/kernel/item_test.c index f12845ab4..98a8188a0 100644 --- a/src/kernel/item_test.c +++ b/src/kernel/item_test.c @@ -1,5 +1,6 @@ #include +#include #include #include @@ -7,19 +8,22 @@ void test_resource_type(CuTest * tc) { - resource_type *rtype; + struct item_type *itype; 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); + test_create_itemtype(names); - CuAssertPtrEquals(tc, rtype, rt_find("herp")); + names[0] = names[1] = "herp"; + itype = test_create_itemtype(names); + + names[0] = names[1] = "herpes"; + test_create_itemtype(names); + + CuAssertPtrEquals(tc, itype, it_find("herp")); + CuAssertPtrEquals(tc, itype->rtype, rt_find("herp")); } CuSuite *get_item_suite(void) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 8e488b115..e57176d6c 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -132,6 +132,7 @@ static const resource_type *rt_findorcreate(const char *name) names[0] = name; names[1] = namep; rtype = new_resourcetype(names, NULL, RTF_NONE); + rt_register(rtype); free(namep); } return rtype; @@ -1045,12 +1046,12 @@ static int parse_resources(xmlDocPtr doc) if (appearance) { appearances[0] = (const char *)appearance; appearances[1] = appearancep; - rtype = - new_resourcetype((const char **)names, (const char **)appearances, - flags); + rtype = new_resourcetype((const char **)names, (const char **)appearances, flags); + rt_register(rtype); free(appearancep); } else { rtype = new_resourcetype(names, NULL, flags); + rt_register(rtype); } free(namep); } diff --git a/src/tests.h b/src/tests.h index c35922c7c..29a75ac4f 100644 --- a/src/tests.h +++ b/src/tests.h @@ -16,6 +16,7 @@ extern "C" { void test_create_world(void); struct building * test_create_building(struct region * r, const struct building_type * btype); struct ship * test_create_ship(struct region * r, const struct ship_type * stype); + struct item_type * test_create_itemtype(const char ** names); int RunAllTests(void); #else #define RunAllTests() 0