diff --git a/src/creport.c b/src/creport.c index aa4fd2f98..c766ae872 100644 --- a/src/creport.c +++ b/src/creport.c @@ -91,10 +91,11 @@ bool opt_cr_absolute_coords = false; #ifdef TAG_LOCALE static const char *crtag(const char *key) { - static const struct locale *lang = NULL; - if (!lang) - lang = get_locale(TAG_LOCALE); - return LOC(lang, key); + /* TODO: those locale lookups are shit, but static kills testing */ + const char *result; + const struct locale *lang = get_locale(TAG_LOCALE); + result = LOC(lang, key); + return result; } #else #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, const struct locale *loc, int amount, int level) { + assert(name); buf += sprintf(buf, "RESOURCE %u\n", hashstring(name)); buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, name))); 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); } 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)) { sputs("1;Mallorn\n", out); diff --git a/src/creport.test.c b/src/creport.test.c index 254a73cbb..8819aab9b 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -55,23 +55,73 @@ static void test_cr_resources(CuTest *tc) { char line[1024]; faction *f; 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); r = test_create_region(0, 0, 0); r->land->horses = 100; r->land->peasants = 200; r->land->money = 300; + rsettrees(r, 0, 1); + rsettrees(r, 1, 2); + rsettrees(r, 2, 3); mstream_init(&strm); cr_output_resources(&strm, f, r, false); 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, memcmp(line, "RESOURCE ", 9)); CuAssertIntEquals(tc, 0, strm.api->readln(strm.handle, line, sizeof(line))); CuAssertStrEquals(tc, "\"Silber\";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, "\"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); test_cleanup(); }