Merge branch 'develop'

This commit is contained in:
Enno Rehling 2017-09-18 17:27:09 +02:00
commit 5605510351
3 changed files with 44 additions and 12 deletions

View file

@ -10,7 +10,7 @@
#include <CuTest.h>
#include <tests.h>
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;
}

View file

@ -203,16 +203,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" },
@ -255,7 +245,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;
}

View file

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