improved some tests

fixed some resource-related things, especially registration
This commit is contained in:
Enno Rehling 2012-05-19 17:23:57 -07:00
parent a8a8dfbbb6
commit a342e846bc
6 changed files with 31 additions and 16 deletions

View File

@ -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);

View File

@ -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);

View File

@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_KRNL_ITEM
#define H_KRNL_ITEM
#include <util/variant.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -1,5 +1,6 @@
#include <platform.h>
#include <kernel/types.h>
#include <kernel/item.h>
#include <cutest/CuTest.h>
@ -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)

View File

@ -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);
}

View File

@ -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