From 31c0e5c2a42f5330abbd6c5e8301def32728c433 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 24 Jun 2014 22:54:10 -0700 Subject: [PATCH] read items from JSON, with no properties yet --- src/kernel/jsonconf.c | 3 +++ src/kernel/jsonconf.test.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index b8db55d5b..dbc999d85 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -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); } diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 26827ae42..9b9d3ed61 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -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);