start adding test coverage for res_changeitem

This commit is contained in:
Enno Rehling 2012-10-21 18:37:51 -07:00
parent cde0ce0742
commit 5e58f3a881
3 changed files with 33 additions and 4 deletions

View File

@ -1226,6 +1226,10 @@ void test_clear_resources(void)
void register_resources(void)
{
static bool registered = false;
if (registered) return;
registered = true;
register_function((pf_generic) mod_elves_only, "mod_elves_only");
register_function((pf_generic) mod_dwarves_only, "mod_dwarves_only");
register_function((pf_generic) res_changeitem, "changeitem");

View File

@ -2,11 +2,35 @@
#include <kernel/types.h>
#include <kernel/item.h>
#include <kernel/unit.h>
#include <util/language.h>
#include <util/functions.h>
#include <CuTest.h>
#include <tests.h>
void test_change_item(CuTest * tc)
{
rtype_uchange res_changeitem;
const resource_type * rtype;
unit * u;
register_resources();
res_changeitem = (rtype_uchange)get_function("changeitem");
CuAssertPtrNotNull(tc, res_changeitem);
test_cleanup();
test_create_world();
rtype = olditemtype[I_IRON]->rtype;
u = test_create_unit(0, 0);
CuAssertIntEquals(tc, 0, res_changeitem(u, rtype, 0));
i_change(&u->items, rtype->itype, 4);
CuAssertIntEquals(tc, 4, res_changeitem(u, rtype, 0));
CuAssertIntEquals(tc, 1, res_changeitem(u, rtype, -3));
CuAssertIntEquals(tc, 1, i_get(u->items, rtype->itype));
}
void test_resource_type(CuTest * tc)
{
struct item_type *itype;
@ -68,6 +92,7 @@ void test_findresourcetype(CuTest * tc)
CuSuite *get_item_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_change_item);
SUITE_ADD_TEST(suite, test_resource_type);
SUITE_ADD_TEST(suite, test_finditemtype);
SUITE_ADD_TEST(suite, test_findresourcetype);

View File

@ -180,15 +180,15 @@ void test_create_world(void)
terrain_type *t_plain, *t_ocean;
region *island[2];
int i;
item_type * itype;
const char * names[] = { "horse", "horse_p", "boat", "boat_p" };
const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };
make_locale("de");
init_resources();
assert(!olditemtype[I_HORSE]);
itype = test_create_itemtype(names);
olditemtype[I_HORSE] = itype;
olditemtype[I_HORSE] = test_create_itemtype(names+0);
olditemtype[I_IRON] = test_create_itemtype(names+4);
olditemtype[I_STONE] = test_create_itemtype(names+6);
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
t_plain->size = 1000;