forked from github/server
short unit-test for resources in the CR.
now complains because Bauern!=Bauer. TODO: crtag is shit.
This commit is contained in:
parent
6a87625409
commit
83f170541b
|
@ -91,10 +91,11 @@ bool opt_cr_absolute_coords = false;
|
||||||
#ifdef TAG_LOCALE
|
#ifdef TAG_LOCALE
|
||||||
static const char *crtag(const char *key)
|
static const char *crtag(const char *key)
|
||||||
{
|
{
|
||||||
static const struct locale *lang = NULL;
|
/* TODO: those locale lookups are shit, but static kills testing */
|
||||||
if (!lang)
|
const char *result;
|
||||||
lang = get_locale(TAG_LOCALE);
|
const struct locale *lang = get_locale(TAG_LOCALE);
|
||||||
return LOC(lang, key);
|
result = LOC(lang, key);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define crtag(x) (x)
|
#define crtag(x) (x)
|
||||||
|
@ -1096,6 +1097,7 @@ static void cr_reportspell(FILE * F, spell * sp, int level, const struct locale
|
||||||
static char *cr_output_resource(char *buf, const char *name,
|
static char *cr_output_resource(char *buf, const char *name,
|
||||||
const struct locale *loc, int amount, int level)
|
const struct locale *loc, int amount, int level)
|
||||||
{
|
{
|
||||||
|
assert(name);
|
||||||
buf += sprintf(buf, "RESOURCE %u\n", hashstring(name));
|
buf += sprintf(buf, "RESOURCE %u\n", hashstring(name));
|
||||||
buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, name)));
|
buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, name)));
|
||||||
if (amount >= 0) {
|
if (amount >= 0) {
|
||||||
|
@ -1171,7 +1173,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
|
||||||
stream_printf(out, "%d;Baeume\n", trees);
|
stream_printf(out, "%d;Baeume\n", trees);
|
||||||
}
|
}
|
||||||
if (saplings > 0) {
|
if (saplings > 0) {
|
||||||
stream_printf(out, "%d;Schoesslinge\n", trees);
|
stream_printf(out, "%d;Schoesslinge\n", saplings);
|
||||||
}
|
}
|
||||||
if (fval(r, RF_MALLORN) && (trees > 0 || saplings > 0)) {
|
if (fval(r, RF_MALLORN) && (trees > 0 || saplings > 0)) {
|
||||||
sputs("1;Mallorn\n", out);
|
sputs("1;Mallorn\n", out);
|
||||||
|
|
|
@ -55,23 +55,73 @@ static void test_cr_resources(CuTest *tc) {
|
||||||
char line[1024];
|
char line[1024];
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
|
struct locale *lang;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
lang = get_or_create_locale("de"); /* CR tags are translated from this */
|
||||||
|
locale_setstring(lang, "money", "Silber");
|
||||||
|
locale_setstring(lang, "money_p", "Silber");
|
||||||
|
locale_setstring(lang, "horse", "Pferd");
|
||||||
|
locale_setstring(lang, "horse_p", "Pferde");
|
||||||
|
locale_setstring(lang, "peasant", "Bauer");
|
||||||
|
locale_setstring(lang, "peasant_p", "Bauern");
|
||||||
|
locale_setstring(lang, "tree", "Baum");
|
||||||
|
locale_setstring(lang, "tree_p", "B?ume");
|
||||||
|
locale_setstring(lang, "sapling", "Schoessling");
|
||||||
|
locale_setstring(lang, "sapling_p", "Schoesslinge");
|
||||||
|
|
||||||
test_cleanup();
|
|
||||||
f = test_create_faction(0);
|
f = test_create_faction(0);
|
||||||
r = test_create_region(0, 0, 0);
|
r = test_create_region(0, 0, 0);
|
||||||
r->land->horses = 100;
|
r->land->horses = 100;
|
||||||
r->land->peasants = 200;
|
r->land->peasants = 200;
|
||||||
r->land->money = 300;
|
r->land->money = 300;
|
||||||
|
rsettrees(r, 0, 1);
|
||||||
|
rsettrees(r, 1, 2);
|
||||||
|
rsettrees(r, 2, 3);
|
||||||
|
|
||||||
mstream_init(&strm);
|
mstream_init(&strm);
|
||||||
cr_output_resources(&strm, f, r, false);
|
cr_output_resources(&strm, f, r, false);
|
||||||
strm.api->rewind(strm.handle);
|
strm.api->rewind(strm.handle);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "3;Baeume", line);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "2;Schoesslinge", line);
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
||||||
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
CuAssertStrEquals(tc, "\"Silber\";type", line);
|
CuAssertStrEquals(tc, "\"Silber\";type", line);
|
||||||
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
CuAssertStrEquals(tc, "300;number", line);
|
CuAssertStrEquals(tc, "300;number", line);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "\"Bauern\";type", line);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "200;number", line);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "\"Pferde\";type", line);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "300;number", line);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "\"Schoesslinge\";type", line);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "2;number", line);
|
||||||
|
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertIntEquals(tc, 0, memcmp(line, "RESOURCE ", 9));
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "\"B?ume\";type", line);
|
||||||
|
CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line)));
|
||||||
|
CuAssertStrEquals(tc, "3;number", line);
|
||||||
|
|
||||||
mstream_done(&strm);
|
mstream_done(&strm);
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue