2016-09-13 20:13:26 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include "report.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "travelthru.h"
|
|
|
|
|
2018-11-26 22:01:18 +01:00
|
|
|
#include <kernel/ally.h>
|
2016-09-13 20:13:26 +02:00
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
2017-03-05 17:18:17 +01:00
|
|
|
#include <kernel/resources.h>
|
2016-09-13 20:13:26 +02:00
|
|
|
#include <kernel/ship.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
#include <kernel/spellbook.h>
|
|
|
|
|
2018-09-30 13:45:19 +02:00
|
|
|
#include "util/keyword.h"
|
|
|
|
#include "util/param.h"
|
2016-09-13 20:13:26 +02:00
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/lists.h>
|
|
|
|
#include <util/message.h>
|
2017-12-28 18:29:40 +01:00
|
|
|
#include <util/strings.h>
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
#include <stream.h>
|
|
|
|
#include <memstream.h>
|
|
|
|
|
|
|
|
#include <CuTest.h>
|
|
|
|
#include <tests.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static void test_write_spaces(CuTest *tc) {
|
|
|
|
stream out = { 0 };
|
|
|
|
char buf[1024];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
write_spaces(&out, 4);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, " ", buf);
|
|
|
|
CuAssertIntEquals(tc, ' ', buf[3]);
|
|
|
|
mstream_done(&out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_write_many_spaces(CuTest *tc) {
|
|
|
|
stream out = { 0 };
|
|
|
|
char buf[1024];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
write_spaces(&out, 100);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertIntEquals(tc, 100, (int)len);
|
|
|
|
CuAssertIntEquals(tc, ' ', buf[99]);
|
|
|
|
mstream_done(&out);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
static void test_report_region(CuTest *tc) {
|
|
|
|
char buf[1024];
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
2017-03-05 17:18:17 +01:00
|
|
|
unit *u;
|
2017-03-05 16:55:11 +01:00
|
|
|
stream out = { 0 };
|
|
|
|
size_t len;
|
|
|
|
struct locale *lang;
|
2017-03-05 17:18:17 +01:00
|
|
|
struct resource_type *rt_stone;
|
|
|
|
construction *cons;
|
2017-03-05 16:55:11 +01:00
|
|
|
|
|
|
|
test_setup();
|
|
|
|
init_resources();
|
2017-03-05 17:18:17 +01:00
|
|
|
rt_stone = rt_get_or_create("stone");
|
|
|
|
rt_stone->itype = it_get_or_create(rt_stone);
|
|
|
|
cons = rt_stone->itype->construction = calloc(1, sizeof(construction));
|
|
|
|
cons->minskill = 1;
|
|
|
|
cons->skill = SK_QUARRYING;
|
|
|
|
rmt_create(rt_stone);
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
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", "Blume");
|
|
|
|
locale_setstring(lang, "tree_p", "Blumen");
|
|
|
|
locale_setstring(lang, "stone", "Stein");
|
|
|
|
locale_setstring(lang, "stone_p", "Steine");
|
|
|
|
locale_setstring(lang, "sapling", "Schoessling");
|
|
|
|
locale_setstring(lang, "sapling_p", "Schoesslinge");
|
|
|
|
locale_setstring(lang, "plain", "Ebene");
|
2017-03-05 17:18:17 +01:00
|
|
|
locale_setstring(lang, "see_travel", "durchgereist");
|
2017-03-05 16:55:11 +01:00
|
|
|
|
|
|
|
mstream_init(&out);
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2017-03-22 20:37:09 +01:00
|
|
|
add_resource(r, 1, 135, 10, rt_stone);
|
2017-03-05 17:18:17 +01:00
|
|
|
CuAssertIntEquals(tc, 1, r->resources->level);
|
|
|
|
r->land->peasants = 5;
|
|
|
|
r->land->horses = 7;
|
|
|
|
r->land->money = 2;
|
2017-03-05 16:55:11 +01:00
|
|
|
rsettrees(r, 0, 1);
|
|
|
|
rsettrees(r, 1, 2);
|
|
|
|
rsettrees(r, 2, 3);
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2017-03-05 16:55:11 +01:00
|
|
|
f->locale = lang;
|
2017-03-05 17:18:17 +01:00
|
|
|
u = test_create_unit(f, r);
|
|
|
|
set_level(u, SK_QUARRYING, 1);
|
2017-03-05 16:55:11 +01:00
|
|
|
|
2018-11-28 20:18:22 +01:00
|
|
|
region_setname(r, "1234567890123456789012345678901234567890");
|
|
|
|
r->seen.mode = seen_travel;
|
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, "1234567890123456789012345678901234567890 (0,0) (durchgereist), Ebene, 3/2\nBlumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf);
|
|
|
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
region_setname(r, "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
|
|
|
r->seen.mode = seen_travel;
|
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n(0,0) (durchgereist), Ebene, 3/2 Blumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf);
|
|
|
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
region_setname(r, "Hodor");
|
2017-03-05 17:18:17 +01:00
|
|
|
r->seen.mode = seen_travel;
|
2017-03-05 16:55:11 +01:00
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
2017-03-05 17:18:17 +01:00
|
|
|
CuAssertStrEquals(tc, "Hodor (0,0) (durchgereist), Ebene, 3/2 Blumen, 5 Bauern, 2 Silber, 7 Pferde.\n", buf);
|
|
|
|
|
|
|
|
out.api->rewind(out.handle);
|
2018-11-28 20:18:22 +01:00
|
|
|
r->seen.mode = seen_unit;
|
2017-03-05 17:18:17 +01:00
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 3/2 Blumen, 135 Steine/1, 5 Bauern, 2 Silber, 7 Pferde.\n", buf);
|
|
|
|
|
2018-11-28 20:18:22 +01:00
|
|
|
out.api->rewind(out.handle);
|
2017-03-05 17:26:00 +01:00
|
|
|
r->resources->amount = 1;
|
|
|
|
r->land->peasants = 1;
|
|
|
|
r->land->horses = 1;
|
|
|
|
r->land->money = 1;
|
|
|
|
r->seen.mode = seen_unit;
|
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 3/2 Blumen, 1 Stein/1, 1 Bauer, 1 Silber, 1 Pferd.\n", buf);
|
|
|
|
|
2018-11-28 20:18:22 +01:00
|
|
|
r->land->peasants = 0;
|
|
|
|
r->land->horses = 0;
|
|
|
|
r->land->money = 0;
|
|
|
|
rsettrees(r, 0, 0);
|
|
|
|
rsettrees(r, 1, 0);
|
|
|
|
rsettrees(r, 2, 0);
|
|
|
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
report_region(&out, r, f);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, "Hodor (0,0), Ebene, 1 Stein/1.\n", buf);
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
mstream_done(&out);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2017-03-05 16:55:11 +01:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:01:18 +01:00
|
|
|
static void test_report_allies(CuTest *tc) {
|
|
|
|
stream out = { 0 };
|
|
|
|
char buf[1024];
|
|
|
|
char exp[1024];
|
|
|
|
size_t len, linebreak = 72;
|
|
|
|
struct locale *lang;
|
|
|
|
faction *f, *f1, *f2, *f3;
|
|
|
|
|
|
|
|
test_setup();
|
|
|
|
lang = test_create_locale();
|
|
|
|
locale_setstring(lang, "list_and", " und ");
|
|
|
|
mstream_init(&out);
|
|
|
|
f = test_create_faction(NULL);
|
|
|
|
f->locale = lang;
|
|
|
|
f1 = test_create_faction(NULL);
|
|
|
|
f2 = test_create_faction(NULL);
|
|
|
|
f3 = test_create_faction(NULL);
|
|
|
|
snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n",
|
|
|
|
factionname(f1),
|
|
|
|
LOC(lang, parameters[P_GUARD]));
|
|
|
|
ally_set(&f->allies, f1, HELP_GUARD);
|
|
|
|
report_allies(&out, linebreak, f, f->allies, "Wir helfen ");
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = 0;
|
|
|
|
CuAssertStrEquals(tc, exp, buf);
|
|
|
|
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
ally_set(&f->allies, f2, HELP_GIVE);
|
|
|
|
ally_set(&f->allies, f3, HELP_ALL);
|
|
|
|
snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)",
|
|
|
|
factionname(f1),
|
|
|
|
LOC(lang, parameters[P_GUARD]),
|
|
|
|
factionname(f2),
|
|
|
|
LOC(lang, parameters[P_GIVE]));
|
|
|
|
linebreak = strlen(exp);
|
|
|
|
snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n",
|
|
|
|
factionname(f1),
|
|
|
|
LOC(lang, parameters[P_GUARD]),
|
|
|
|
factionname(f2),
|
|
|
|
LOC(lang, parameters[P_GIVE]),
|
|
|
|
factionname(f3),
|
|
|
|
LOC(lang, parameters[P_ANY]));
|
|
|
|
report_allies(&out, linebreak, f, f->allies, "Wir helfen ");
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = 0;
|
|
|
|
CuAssertStrEquals(tc, exp, buf);
|
|
|
|
|
|
|
|
test_teardown();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
static void test_report_travelthru(CuTest *tc) {
|
2016-09-13 20:13:26 +02:00
|
|
|
stream out = { 0 };
|
|
|
|
char buf[1024];
|
|
|
|
size_t len;
|
|
|
|
region *r;
|
|
|
|
faction *f;
|
|
|
|
unit *u;
|
|
|
|
struct locale *lang;
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
test_setup();
|
2016-09-13 20:13:26 +02:00
|
|
|
lang = get_or_create_locale("de");
|
|
|
|
locale_setstring(lang, "travelthru_header", "Durchreise: ");
|
|
|
|
mstream_init(&out);
|
2018-01-14 09:38:26 +01:00
|
|
|
r = test_create_region(0, 0, NULL);
|
2016-09-13 20:13:26 +02:00
|
|
|
r->flags |= RF_TRAVELUNIT;
|
2018-01-14 09:38:26 +01:00
|
|
|
f = test_create_faction(NULL);
|
2016-09-13 20:13:26 +02:00
|
|
|
f->locale = lang;
|
2018-01-14 09:58:45 +01:00
|
|
|
u = test_create_unit(f, test_create_region(0, 1, NULL));
|
2016-09-13 20:13:26 +02:00
|
|
|
unit_setname(u, "Hodor");
|
|
|
|
unit_setid(u, 1);
|
|
|
|
|
2017-03-05 16:55:11 +01:00
|
|
|
report_travelthru(&out, r, f);
|
2016-09-13 20:13:26 +02:00
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
CuAssertIntEquals_Msg(tc, "no travelers, no report", 0, (int)len);
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
travelthru_add(r, u);
|
2017-03-05 16:55:11 +01:00
|
|
|
report_travelthru(&out, r, f);
|
2016-09-13 20:13:26 +02:00
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals_Msg(tc, "list one unit", "Durchreise: Hodor (1).\n", buf);
|
|
|
|
mstream_done(&out);
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
move_unit(u, r, 0);
|
2017-03-05 16:55:11 +01:00
|
|
|
report_travelthru(&out, r, f);
|
2016-09-13 20:13:26 +02:00
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
CuAssertIntEquals_Msg(tc, "do not list units that stopped in the region", 0, (int)len);
|
|
|
|
|
|
|
|
mstream_done(&out);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-13 20:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct locale *lang;
|
|
|
|
spell *sp;
|
|
|
|
spellbook *spb;
|
|
|
|
spellbook_entry * sbe;
|
|
|
|
} spell_fixture;
|
|
|
|
|
|
|
|
static void setup_spell_fixture(spell_fixture * spf) {
|
|
|
|
spf->lang = test_create_locale();
|
|
|
|
locale_setstring(spf->lang, mkname("spell", "testspell"), "Testzauber");
|
|
|
|
locale_setstring(spf->lang, "nr_spell_type", "Typ:");
|
|
|
|
locale_setstring(spf->lang, "sptype_normal", "Normal");
|
|
|
|
locale_setstring(spf->lang, "nr_spell_modifiers", "Modifier:");
|
|
|
|
locale_setstring(spf->lang, "smod_none", "Keine");
|
|
|
|
locale_setstring(spf->lang, keyword(K_CAST), "ZAUBERE");
|
|
|
|
locale_setstring(spf->lang, parameters[P_REGION], "REGION");
|
|
|
|
locale_setstring(spf->lang, parameters[P_LEVEL], "STUFE");
|
|
|
|
locale_setstring(spf->lang, "par_unit", "enr");
|
|
|
|
locale_setstring(spf->lang, "par_ship", "snr");
|
|
|
|
locale_setstring(spf->lang, "par_building", "bnr");
|
|
|
|
locale_setstring(spf->lang, "spellpar::hodor", "Hodor");
|
|
|
|
|
|
|
|
spf->spb = create_spellbook("testbook");
|
|
|
|
spf->sp = test_create_spell();
|
|
|
|
spellbook_add(spf->spb, spf->sp, 1);
|
|
|
|
spf->sbe = spellbook_get(spf->spb, spf->sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_spell_fixture(spell_fixture *spf) {
|
|
|
|
spellbook_clear(spf->spb);
|
|
|
|
free(spf->spb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_parameter(spell_fixture spell, char *value) {
|
|
|
|
free(spell.sp->parameter);
|
2017-12-28 18:29:40 +01:00
|
|
|
spell.sp->parameter = str_strdup(value);
|
2016-09-13 20:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void check_spell_syntax(CuTest *tc, char *msg, spell_fixture *spell, char *syntax) {
|
|
|
|
char buf[1024];
|
|
|
|
|
2018-06-03 13:29:54 +02:00
|
|
|
nr_spell_syntax(buf, sizeof(buf), spell->sbe, spell->lang);
|
2016-09-13 20:13:26 +02:00
|
|
|
|
2018-06-03 13:29:54 +02:00
|
|
|
CuAssertStrEquals_Msg(tc, msg, syntax, buf);
|
2016-09-13 20:13:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_write_spell_syntax(CuTest *tc) {
|
|
|
|
spell_fixture spell;
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
test_setup();
|
2016-09-13 20:13:26 +02:00
|
|
|
setup_spell_fixture(&spell);
|
|
|
|
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "vanilla", &spell, "ZAUBERE Testzauber");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
spell.sp->sptyp |= FARCASTING;
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "far", &spell, "ZAUBERE [REGION x y] Testzauber");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
spell.sp->sptyp |= SPELLLEVEL;
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "farlevel", &spell, "ZAUBERE [REGION x y] [STUFE n] Testzauber");
|
2016-09-13 20:13:26 +02:00
|
|
|
spell.sp->sptyp = 0;
|
|
|
|
|
|
|
|
set_parameter(spell, "kc");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "kc", &spell, "ZAUBERE Testzauber ( REGION | EINHEIT <enr> | SCHIFF <snr> | BURG <bnr> )");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
spell.sp->sptyp |= BUILDINGSPELL;
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "kc typed", &spell, "ZAUBERE Testzauber BURG <bnr>");
|
2016-09-13 20:13:26 +02:00
|
|
|
spell.sp->sptyp = 0;
|
|
|
|
|
|
|
|
set_parameter(spell, "b");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "b", &spell, "ZAUBERE Testzauber <bnr>");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
set_parameter(spell, "s");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "s", &spell, "ZAUBERE Testzauber <snr>");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
set_parameter(spell, "s+");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "s+", &spell, "ZAUBERE Testzauber <snr> [<snr> ...]");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
set_parameter(spell, "u");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "u", &spell, "ZAUBERE Testzauber <enr>");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
set_parameter(spell, "r");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "r", &spell, "ZAUBERE Testzauber <x> <y>");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
set_parameter(spell, "bc");
|
|
|
|
free(spell.sp->syntax);
|
2017-12-28 18:29:40 +01:00
|
|
|
spell.sp->syntax = str_strdup("hodor");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "bc hodor", &spell, "ZAUBERE Testzauber <bnr> <Hodor>");
|
2016-09-13 20:13:26 +02:00
|
|
|
free(spell.sp->syntax);
|
|
|
|
spell.sp->syntax = 0;
|
|
|
|
|
|
|
|
set_parameter(spell, "c?");
|
|
|
|
free(spell.sp->syntax);
|
2017-12-28 18:29:40 +01:00
|
|
|
spell.sp->syntax = str_strdup("hodor");
|
2018-06-03 13:29:54 +02:00
|
|
|
check_spell_syntax(tc, "c?", &spell, "ZAUBERE Testzauber [<Hodor>]");
|
2016-09-13 20:13:26 +02:00
|
|
|
free(spell.sp->syntax);
|
|
|
|
spell.sp->syntax = 0;
|
|
|
|
|
|
|
|
set_parameter(spell, "kc+");
|
|
|
|
check_spell_syntax(tc, "kc+", &spell,
|
2018-06-03 13:29:54 +02:00
|
|
|
"ZAUBERE Testzauber ( REGION | EINHEIT <enr> [<enr> ...] | SCHIFF <snr> [<snr> ...] | BURG <bnr> [<bnr> ...] )");
|
2016-09-13 20:13:26 +02:00
|
|
|
|
|
|
|
cleanup_spell_fixture(&spell);
|
2017-12-27 19:58:39 +01:00
|
|
|
test_teardown();
|
2016-09-13 20:13:26 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 21:56:21 +01:00
|
|
|
static void test_paragraph(CuTest *tc) {
|
|
|
|
const char *toolong = "im Westen das Hochland von Geraldin (93,-303).";
|
|
|
|
const char *expect = "im Westen das Hochland von Geraldin (93,-303).\n";
|
|
|
|
char buf[256];
|
|
|
|
stream out = { 0 };
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
|
|
|
paragraph(&out, toolong, 0, 0, 0);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, expect, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_paragraph_break(CuTest *tc) {
|
|
|
|
const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303).";
|
|
|
|
const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n";
|
|
|
|
char buf[256];
|
|
|
|
stream out = { 0 };
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
|
|
|
paragraph(&out, toolong, 0, 0, 0);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, expect, buf);
|
|
|
|
}
|
|
|
|
|
2018-12-01 21:51:52 +01:00
|
|
|
static void test_pump_paragraph_toolong(CuTest *tc) {
|
|
|
|
const char *toolong = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin (93,-303).";
|
|
|
|
const char *expect = "die Ebene von Godsettova (94,-304) und im Westen das Hochland von Geraldin\n(93,-303).\n";
|
|
|
|
sbstring sbs;
|
|
|
|
char buf[256];
|
|
|
|
stream out = { 0 };
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
mstream_init(&out);
|
|
|
|
|
|
|
|
sbs_init(&sbs, buf, sizeof(buf));
|
|
|
|
sbs_strcat(&sbs, toolong);
|
|
|
|
|
|
|
|
pump_paragraph(&sbs, &out, 78, true);
|
|
|
|
out.api->rewind(out.handle);
|
|
|
|
len = out.api->read(out.handle, buf, sizeof(buf));
|
|
|
|
buf[len] = '\0';
|
|
|
|
CuAssertStrEquals(tc, expect, buf);
|
|
|
|
}
|
|
|
|
|
2016-09-13 20:13:26 +02:00
|
|
|
CuSuite *get_report_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_write_spaces);
|
|
|
|
SUITE_ADD_TEST(suite, test_write_many_spaces);
|
2018-12-01 21:56:21 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_paragraph);
|
|
|
|
SUITE_ADD_TEST(suite, test_paragraph_break);
|
2018-12-01 21:51:52 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_pump_paragraph_toolong);
|
2017-03-05 16:55:11 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_report_travelthru);
|
|
|
|
SUITE_ADD_TEST(suite, test_report_region);
|
2018-11-26 22:01:18 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_report_allies);
|
2016-09-13 20:13:26 +02:00
|
|
|
SUITE_ADD_TEST(suite, test_write_spell_syntax);
|
|
|
|
return suite;
|
|
|
|
}
|