read items from JSON, with no properties yet

This commit is contained in:
Enno Rehling 2014-06-24 22:54:10 -07:00
parent 92f43a7b51
commit 31c0e5c2a4
2 changed files with 26 additions and 0 deletions

View file

@ -450,6 +450,9 @@ void json_config(cJSON *json) {
if (strcmp(child->string, "races")==0) {
json_races(child);
}
else if (strcmp(child->string, "items")==0) {
json_items(child);
}
else if (strcmp(child->string, "ships")==0) {
json_ships(child);
}

View file

@ -4,6 +4,7 @@
#include "building.h"
#include "direction.h"
#include "item.h"
#include "keyword.h"
#include "race.h"
#include "ship.h"
@ -82,6 +83,27 @@ static void test_races(CuTest * tc)
test_cleanup();
}
static void test_items(CuTest * tc)
{
const char * data = "{\"items\": { "
"\"axe\" : {},"
"\"horse\" : {}"
"}}";
cJSON *json = cJSON_Parse(data);
test_cleanup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, it_find("axe"));
CuAssertPtrEquals(tc, 0, rt_find("axe"));
CuAssertPtrEquals(tc, 0, (void *)get_resourcetype(R_HORSE));
json_config(json);
CuAssertPtrNotNull(tc, it_find("axe"));
CuAssertPtrNotNull(tc, rt_find("axe"));
CuAssertPtrNotNull(tc, (void *)get_resourcetype(R_HORSE));
}
static void test_ships(CuTest * tc)
{
const char * data = "{\"ships\": { \"boat\" : { "
@ -234,6 +256,7 @@ CuSuite *get_jsonconf_suite(void)
SUITE_ADD_TEST(suite, test_keywords);
SUITE_ADD_TEST(suite, test_skills);
SUITE_ADD_TEST(suite, test_directions);
SUITE_ADD_TEST(suite, test_items);
SUITE_ADD_TEST(suite, test_ships);
SUITE_ADD_TEST(suite, test_buildings);
SUITE_ADD_TEST(suite, test_terrains);