From 2f8dc29396de3a033e725eace0a26e1ce9137ee1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 7 Nov 2015 13:52:18 +0100 Subject: [PATCH] clean up item tests so they don't use test_create_world fix intermittent skillpotion test --- src/items/xerewards.test.c | 6 +++--- src/kernel/item.test.c | 34 +++++++++++++++++----------------- src/kernel/pool.c | 2 ++ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/items/xerewards.test.c b/src/items/xerewards.test.c index 52a4d0ed0..f2f6e50ff 100644 --- a/src/items/xerewards.test.c +++ b/src/items/xerewards.test.c @@ -33,17 +33,17 @@ static void test_skillpotion(CuTest *tc) { learn_skill(u, SK_ENTERTAINMENT, 1.0); pSkill = unit_skill(u, SK_ENTERTAINMENT); sk_set(pSkill, 5); - initialWeeks_Entertainment = pSkill->weeks; + initialWeeks_Entertainment = pSkill->weeks = 4; learn_skill(u, SK_STAMINA, 1.0); pSkill = unit_skill(u, SK_STAMINA); sk_set(pSkill, 5); - initialWeeks_Stamina = pSkill->weeks; + initialWeeks_Stamina = pSkill->weeks = 4; learn_skill(u, SK_MAGIC, 1.0); pSkill = unit_skill(u, SK_MAGIC); sk_set(pSkill, 5); - initialWeeks_Magic = pSkill->weeks; + initialWeeks_Magic = pSkill->weeks = 4; CuAssertIntEquals(tc, 1, use_skillpotion(u, itype, 1, NULL)); diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index cd1351dac..2d76422ff 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -45,6 +45,8 @@ static void test_resourcename_with_appearance(CuTest *tc) { static void test_uchange(CuTest * tc, unit * u, const resource_type * rtype) { int n; + + assert(rtype); change_resource(u, rtype, 4); n = get_resource(u, rtype); CuAssertPtrNotNull(tc, rtype->uchange); @@ -59,8 +61,8 @@ void test_change_item(CuTest * tc) unit * u; test_cleanup(); + test_create_itemtype("iron"); init_resources(); - test_create_world(); u = test_create_unit(0, 0); test_uchange(tc, u, get_resourcetype(R_IRON)); @@ -79,43 +81,41 @@ void test_resource_type(CuTest * tc) itype = test_create_itemtype("herp"); CuAssertPtrEquals(tc, itype->rtype, rt_find("herp")); + test_cleanup(); } void test_finditemtype(CuTest * tc) { const item_type *itype; - const resource_type *rtype; struct locale * lang; test_cleanup(); - test_create_world(); - lang = get_locale("de"); + lang = get_or_create_locale("de"); locale_setstring(lang, "horse", "Pferd"); - rtype = get_resourcetype(R_HORSE); - itype = finditemtype("Pferd", lang); - CuAssertPtrNotNull(tc, itype); - CuAssertPtrEquals(tc, (void*)rtype->itype, (void*)itype); + itype = test_create_itemtype("horse"); + CuAssertPtrEquals(tc, (void *)itype, (void *)finditemtype("Pferd", lang)); + test_cleanup(); } void test_findresourcetype(CuTest * tc) { - const resource_type *rtype, *rresult; + const item_type *itype; struct locale * lang; test_cleanup(); - test_create_world(); - lang = get_locale("de"); + lang = get_or_create_locale("de"); locale_setstring(lang, "horse", "Pferd"); locale_setstring(lang, "peasant", "Bauer"); + init_resources(); + CuAssertPtrNotNull(tc, rt_find("peasant")); + CuAssertPtrEquals(tc, 0, rt_find("horse")); + itype = test_create_itemtype("horse"); - rtype = get_resourcetype(R_HORSE); - rresult = findresourcetype("Pferd", lang); - CuAssertPtrNotNull(tc, rresult); - CuAssertPtrEquals(tc, (void*)rtype, (void*)rresult); - - CuAssertPtrNotNull(tc, findresourcetype("Bauer", lang)); + CuAssertPtrEquals(tc, (void*)itype->rtype, (void*)findresourcetype("Pferd", lang)); + CuAssertPtrEquals(tc, (void *)rt_find("peasant"), (void *)findresourcetype("Bauer", lang)); + test_cleanup(); } #include diff --git a/src/kernel/pool.c b/src/kernel/pool.c index ab1800556..442553c28 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -68,6 +68,8 @@ int change_resource(unit * u, const resource_type * rtype, int change) { int i = 0; + assert(rtype); + if (rtype->uchange) i = rtype->uchange(u, rtype, change); else if (rtype == get_resourcetype(R_AURA))