additional testing

improved directory detection in build script
This commit is contained in:
Enno Rehling 2014-03-16 14:08:37 -07:00
parent 5647905db3
commit 632322a445
4 changed files with 95 additions and 6 deletions

1
.gitattributes vendored
View File

@ -5,6 +5,7 @@
*.md text *.md text
*.txt text *.txt text
*.lua text *.lua text
*.bat text
# Shell scripts should *always* be LF, regardless of platfrom # Shell scripts should *always* be LF, regardless of platfrom
s/* text eol=lf s/* text eol=lf

View File

@ -68,6 +68,9 @@ int json_export(stream * out, unsigned int flags) {
cJSON_AddNumberToObject(data, "x", r->x); cJSON_AddNumberToObject(data, "x", r->x);
cJSON_AddNumberToObject(data, "y", r->y); cJSON_AddNumberToObject(data, "y", r->y);
cJSON_AddStringToObject(data, "type", r->terrain->_name); cJSON_AddStringToObject(data, "type", r->terrain->_name);
if (r->land) {
cJSON_AddStringToObject(data, "name", r->land->name);
}
} }
} }
if (factions && (flags & EXPORT_FACTIONS)) { if (factions && (flags & EXPORT_FACTIONS)) {

View File

@ -3,22 +3,102 @@
#include <stream.h> #include <stream.h>
#include <memstream.h> #include <memstream.h>
#include "json.h" #include "json.h"
#include "bind_eressea.h" #include "tests.h"
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <cJSON.h>
#include <stdlib.h>
static char *strip(char *str) {
char *s = str, *b = str, *e = str;
// b is where text begins, e where it ends, s where we insert it.
for (; *b && isspace(*b); ++b) {};
for (e = b; *e && !isspace(*e); ++e) {};
while (*b) {
memcpy(s, b, e - b);
s += e - b;
for (b = e; *b && isspace(*b); ++b) {};
for (e = b; *e && !isspace(*e); ++e) {};
}
*s = 0;
return str;
}
static void test_export_no_regions(CuTest * tc) { static void test_export_no_regions(CuTest * tc) {
char buf[1024]; char buf[1024];
stream out = { 0 }; stream out = { 0 };
int err; int err;
mstream_init(&out); mstream_init(&out);
err = json_export(&out, EXPORT_REGIONS); err = json_export(&out, EXPORT_REGIONS);
CuAssertIntEquals(tc, 0, err); CuAssertIntEquals(tc, 0, err);
out.api->rewind(out.handle); out.api->rewind(out.handle);
out.api->read(out.handle, buf, sizeof(buf)); out.api->read(out.handle, buf, sizeof(buf));
CuAssertStrEquals(tc, "{\n}\n", buf); CuAssertStrEquals(tc, "{}", strip(buf));
mstream_done(&out); mstream_done(&out);
} }
static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, region **_r) {
char buf[1024];
stream out = { 0 };
int err;
region *r;
cJSON *json, *attr;
r = test_create_region(0, 0, terrain);
mstream_init(&out);
err = json_export(&out, EXPORT_REGIONS);
CuAssertIntEquals(tc, 0, err);
out.api->rewind(out.handle);
out.api->read(out.handle, buf, sizeof(buf));
mstream_done(&out);
json = cJSON_Parse(buf);
CuAssertPtrNotNull(tc, json);
CuAssertIntEquals(tc, cJSON_Object, json->type);
json = json->child;
CuAssertPtrEquals(tc, 0, json->next);
CuAssertIntEquals(tc, cJSON_Object, json->type);
CuAssertStrEquals(tc, "regions", json->string);
json = json->child;
CuAssertIntEquals(tc, r->uid, atoi(json->string));
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "x"));
CuAssertIntEquals(tc, r->x, attr->valueint);
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "y"));
CuAssertIntEquals(tc, r->y, attr->valueint);
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "type"));
CuAssertStrEquals(tc, terrain->_name, attr->valuestring);
if (_r) *_r = r;
return json;
}
static void test_export_land_region(CuTest * tc) {
region *r;
struct terrain_type *terrain;
cJSON *json, *attr;
test_cleanup();
terrain = test_create_terrain("plain", LAND_REGION);
json = export_a_region(tc, terrain, &r);
CuAssertPtrNotNull(tc, attr = cJSON_GetObjectItem(json, "name"));
CuAssertStrEquals(tc, r->land->name, attr->valuestring);
cJSON_Delete(json);
}
static void test_export_ocean_region(CuTest * tc) {
struct terrain_type *terrain;
cJSON *json;
test_cleanup();
terrain = test_create_terrain("ocean", SEA_REGION);
json = export_a_region(tc, terrain, 0);
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
cJSON_Delete(json);
}
static void test_export_no_factions(CuTest * tc) { static void test_export_no_factions(CuTest * tc) {
char buf[1024]; char buf[1024];
stream out = { 0 }; stream out = { 0 };
@ -29,13 +109,15 @@ static void test_export_no_factions(CuTest * tc) {
CuAssertIntEquals(tc, 0, err); CuAssertIntEquals(tc, 0, err);
out.api->rewind(out.handle); out.api->rewind(out.handle);
out.api->read(out.handle, buf, sizeof(buf)); out.api->read(out.handle, buf, sizeof(buf));
CuAssertStrEquals(tc, "{\n}\n", buf); CuAssertStrEquals(tc, "{}", strip(buf));
mstream_done(&out); mstream_done(&out);
} }
CuSuite *get_json_suite(void) { CuSuite *get_json_suite(void) {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_export_no_regions); SUITE_ADD_TEST(suite, test_export_no_regions);
SUITE_ADD_TEST(suite, test_export_ocean_region);
SUITE_ADD_TEST(suite, test_export_land_region);
SUITE_ADD_TEST(suite, test_export_no_factions); SUITE_ADD_TEST(suite, test_export_no_factions);
return suite; return suite;
} }

View File

@ -1,7 +1,10 @@
@ECHO OFF @ECHO OFF
SET VSVERSION=12 SET VSVERSION=12
SET ERESSEA=%Userprofile%/Documents/Eressea SET SRCDIR=%CD%
CD ..
SET ERESSEA=%CD%
CD %SRCDIR%
mkdir build-vs%VSVERSION% mkdir build-vs%VSVERSION%
cd build-vs%VSVERSION% cd build-vs%VSVERSION%
"%ProgramFiles(x86)%\CMake 2.8\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%ERESSEA%/server/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. "%ProgramFiles(x86)%\CMake 2.8\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%ERESSEA%/server/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE ..