Merge pull request #692 from ennorehling/develop

noxml branch preparations
This commit is contained in:
Enno Rehling 2017-05-08 22:02:48 +02:00 committed by GitHub
commit 92844e1a9c
3 changed files with 70 additions and 145 deletions

24
conf/e2/config.xml Normal file
View file

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<eressea xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="config://game/familiars.xml"/>
<xi:include href="config://game/equipment.xml"/>
<equipment>
<set name="autoseed_unit">
<item name="log" amount="50"/>
<item name="stone" amount="50"/>
<item name="iron" amount="50"/>
<item name="laen" amount="10"/>
<item name="sword" amount="1"/>
<item name="mallorn" amount="10"/>
<item name="skillpotion" amount="5"/>
<item name="p2" amount="5"/>
<item name="money" amount="20000"/>
<skill name="perception" level="30"/>
<skill name="melee" level="1"/>
</set>
<set name="autoseed_faction">
<item name="adamantium" amount="1"/>
</set>
</equipment>
</eressea>

View file

@ -13,6 +13,8 @@
#include "order.h"
#include "terrain.h"
#include "move.h"
#include "calendar.h"
#include "prefix.h"
#include "util/language.h"
@ -75,7 +77,7 @@ static void test_settings(CuTest * tc)
"\"float\" : 1.5 }}";
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
config_set("game.id", "42"); /* should not be replaced */
config_set("game.name", "Eressea"); /* should not be replaced */
json_config(json);
@ -99,7 +101,7 @@ static void test_prefixes(CuTest * tc)
"]}";
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
json_config(json);
CuAssertPtrNotNull(tc, race_prefixes);
CuAssertStrEquals(tc, "snow", race_prefixes[0]);
@ -119,7 +121,7 @@ static void test_disable(CuTest * tc)
"]}";
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
CuAssertTrue(tc, skill_enabled(SK_ALCHEMY));
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
CuAssertTrue(tc, !keyword_disabled(K_PAY));
@ -135,6 +137,31 @@ static void test_disable(CuTest * tc)
test_cleanup();
}
static void test_calendar(CuTest * tc)
{
const char * data = "{\"calendar\": { "
"\"weeks\" : [ \"one\", \"two\", \"three\" ],"
"\"months\" : ["
"{ \"storm\" : 99, \"season\" : 1 },"
"{ \"storm\" : 22, \"season\" : 2 }"
"]"
"}}";
cJSON *json = cJSON_Parse(data);
test_setup();
json_config(json);
CuAssertPtrNotNull(tc, storms);
CuAssertIntEquals(tc, 2, months_per_year);
CuAssertIntEquals(tc, 3, weeks_per_month);
CuAssertIntEquals(tc, 99, storms[0]);
CuAssertIntEquals(tc, 22, storms[1]);
CuAssertPtrNotNull(tc, month_season);
CuAssertIntEquals(tc, 1, month_season[0]);
CuAssertIntEquals(tc, 2, month_season[1]);
cJSON_Delete(json);
test_cleanup();
}
static void test_races(CuTest * tc)
{
const char * data = "{\"races\": { \"orc\" : { "
@ -155,7 +182,7 @@ static void test_races(CuTest * tc)
cJSON *json = cJSON_Parse(data);
const struct race *rc;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, races);
@ -189,7 +216,7 @@ static void test_findrace(CuTest *tc) {
const race *rc;
CuAssertPtrNotNull(tc, json);
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
CuAssertPtrEquals(tc, 0, (void *)findrace("Zwerg", lang));
@ -211,7 +238,7 @@ static void test_items(CuTest * tc)
cJSON *json = cJSON_Parse(data);
const item_type * itype;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, it_find("axe"));
@ -249,7 +276,7 @@ static void test_ships(CuTest * tc)
const ship_type *st;
const terrain_type *ter;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, shiptypes);
@ -286,7 +313,7 @@ static void test_castles(CuTest *tc) {
cJSON *json = cJSON_Parse(data);
const building_type *bt;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, buildingtypes);
@ -311,7 +338,7 @@ static void test_spells(CuTest * tc)
cJSON *json = cJSON_Parse(data);
const spell *sp;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, find_spell("fireball"));
@ -350,7 +377,7 @@ static void test_buildings(CuTest * tc)
cJSON *json = cJSON_Parse(building_data);
const building_type *bt;
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, buildingtypes);
@ -400,7 +427,7 @@ static void test_buildings_default(CuTest * tc)
const building_type *bt;
building_type clone;
test_cleanup();
test_setup();
bt = bt_get_or_create("house");
clone = *bt;
@ -425,7 +452,7 @@ static void test_ships_default(CuTest * tc)
const ship_type *st;
ship_type clone;
test_cleanup();
test_setup();
st = st_get_or_create("hodor");
clone = *st;
@ -446,7 +473,7 @@ static void test_configs(CuTest * tc)
FILE *F;
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
F = fopen("test.json", "w");
fwrite(building_data, 1, strlen(building_data), F);
@ -475,7 +502,7 @@ static void test_terrains(CuTest * tc)
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
CuAssertPtrNotNull(tc, json);
CuAssertPtrEquals(tc, 0, (void *)get_terrain("plain"));
@ -511,7 +538,7 @@ static void test_directions(CuTest * tc)
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, json);
CuAssertIntEquals(tc, NODIRECTION, get_direction("ost", lang));
@ -533,7 +560,7 @@ static void test_skills(CuTest * tc)
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, json);
CuAssertIntEquals(tc, NOSKILL, get_skill("potato", lang));
@ -558,7 +585,7 @@ static void test_keywords(CuTest * tc)
cJSON *json = cJSON_Parse(data);
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, json);
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
@ -583,7 +610,7 @@ static void test_strings(CuTest * tc)
cJSON *json = cJSON_Parse(data);
CuAssertPtrNotNull(tc, json);
test_cleanup();
test_setup();
lang = get_or_create_locale("de");
CuAssertPtrNotNull(tc, lang);
CuAssertPtrEquals(tc, NULL, (void *)LOC(lang, "move"));
@ -640,6 +667,7 @@ CuSuite *get_jsonconf_suite(void)
SUITE_ADD_TEST(suite, test_prefixes);
SUITE_ADD_TEST(suite, test_disable);
SUITE_ADD_TEST(suite, test_infinitive_from_config);
SUITE_ADD_TEST(suite, test_calendar);
return suite;
}

View file

@ -399,133 +399,6 @@ static int parse_buildings(xmlDocPtr doc)
return 0;
}
#if 0
static int parse_calendar(xmlDocPtr doc)
{
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
xmlXPathObjectPtr xpathCalendars;
xmlNodeSetPtr nsetCalendars;
xpathCalendars = xmlXPathEvalExpression(BAD_CAST "/eressea/calendar", xpath);
nsetCalendars = xpathCalendars->nodesetval;
if (nsetCalendars != NULL && nsetCalendars->nodeNr != 0) {
int c;
for (c = 0; c != nsetCalendars->nodeNr; ++c) {
xmlNodePtr calendar = nsetCalendars->nodeTab[c];
xmlXPathObjectPtr xpathWeeks, xpathMonths, xpathSeasons;
xmlNodeSetPtr nsetWeeks, nsetMonths, nsetSeasons;
xmlChar *propValue = xmlGetProp(calendar, BAD_CAST "name");
xmlChar *newyear = xmlGetProp(calendar, BAD_CAST "newyear");
xmlChar *start;
start = xmlGetProp(calendar, BAD_CAST "start");
if (start && config_get("game.start") == NULL) {
config_set("game.start", (const char *)start);
xmlFree(start);
}
if (propValue) {
free(agename);
agename = strdup(mkname("calendar", (const char *)propValue));
xmlFree(propValue);
}
xpath->node = calendar;
xpathWeeks = xmlXPathEvalExpression(BAD_CAST "week", xpath);
nsetWeeks = xpathWeeks->nodesetval;
if (nsetWeeks != NULL && nsetWeeks->nodeNr) {
int i;
weeks_per_month = nsetWeeks->nodeNr;
free(weeknames);
free(weeknames2);
weeknames = malloc(sizeof(char *) * weeks_per_month);
weeknames2 = malloc(sizeof(char *) * weeks_per_month);
for (i = 0; i != nsetWeeks->nodeNr; ++i) {
xmlNodePtr week = nsetWeeks->nodeTab[i];
xmlChar *propValue = xmlGetProp(week, BAD_CAST "name");
if (propValue) {
weeknames[i] = strdup(mkname("calendar", (const char *)propValue));
weeknames2[i] = malloc(strlen(weeknames[i]) + 3);
sprintf(weeknames2[i], "%s_d", weeknames[i]);
xmlFree(propValue);
}
}
}
xmlXPathFreeObject(xpathWeeks);
xpathSeasons = xmlXPathEvalExpression(BAD_CAST "season", xpath);
nsetSeasons = xpathSeasons->nodesetval;
if (nsetSeasons != NULL && nsetSeasons->nodeNr) {
int i;
seasons = nsetSeasons->nodeNr;
assert(!seasonnames);
seasonnames = malloc(sizeof(char *) * seasons);
for (i = 0; i != nsetSeasons->nodeNr; ++i) {
xmlNodePtr season = nsetSeasons->nodeTab[i];
xmlChar *propValue = xmlGetProp(season, BAD_CAST "name");
if (propValue) {
seasonnames[i] =
strdup(mkname("calendar", (const char *)propValue));
xmlFree(propValue);
}
}
}
xpathMonths = xmlXPathEvalExpression(BAD_CAST "season/month", xpath);
nsetMonths = xpathMonths->nodesetval;
if (nsetMonths != NULL && nsetMonths->nodeNr) {
int i;
months_per_year = nsetMonths->nodeNr;
free(monthnames);
monthnames = malloc(sizeof(char *) * months_per_year);
free(month_season);
month_season = malloc(sizeof(int) * months_per_year);
free(storms);
storms = malloc(sizeof(int) * months_per_year);
for (i = 0; i != nsetMonths->nodeNr; ++i) {
xmlNodePtr month = nsetMonths->nodeTab[i];
xmlChar *propValue = xmlGetProp(month, BAD_CAST "name");
if (propValue) {
if (newyear
&& strcmp((const char *)newyear, (const char *)propValue) == 0) {
first_month = i;
xmlFree(newyear);
newyear = NULL;
}
monthnames[i] = strdup(mkname("calendar", (const char *)propValue));
xmlFree(propValue);
}
if (nsetSeasons) {
int j;
for (j = 0; j != seasons; ++j) {
xmlNodePtr season = month->parent;
if (season == nsetSeasons->nodeTab[j]) {
month_season[i] = j;
break;
}
}
assert(j != seasons);
}
storms[i] = xml_ivalue(nsetMonths->nodeTab[i], "storm", 0);
}
}
xmlXPathFreeObject(xpathMonths);
xmlXPathFreeObject(xpathSeasons);
xmlFree(newyear);
newyear = NULL;
}
}
xmlXPathFreeObject(xpathCalendars);
xmlXPathFreeContext(xpath);
return 0;
}
#endif
static int parse_ships(xmlDocPtr doc)
{
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);