diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index becc93d6f..23e227ebe 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -8,7 +8,7 @@ #include -static void test_create_spell(CuTest * tc) +static void test_create_a_spell(CuTest * tc) { spell * sp; @@ -48,7 +48,7 @@ static void test_create_spell_with_id(CuTest * tc) CuSuite *get_spell_suite(void) { CuSuite *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_create_spell); + SUITE_ADD_TEST(suite, test_create_a_spell); SUITE_ADD_TEST(suite, test_create_duplicate_spell); SUITE_ADD_TEST(suite, test_create_spell_with_id); return suite; diff --git a/src/magic.test.c b/src/magic.test.c index b208836f9..6ed4d81a9 100644 --- a/src/magic.test.c +++ b/src/magic.test.c @@ -74,24 +74,6 @@ void test_spellbooks(CuTest * tc) test_cleanup(); } -static spell * test_magic_create_spell(void) -{ - spell *sp; - sp = create_spell("testspell", 0); - - sp->components = (spell_component *)calloc(4, sizeof(spell_component)); - sp->components[0].amount = 1; - sp->components[0].type = get_resourcetype(R_SILVER); - sp->components[0].cost = SPC_FIX; - sp->components[1].amount = 1; - sp->components[1].type = get_resourcetype(R_AURA); - sp->components[1].cost = SPC_LEVEL; - sp->components[2].amount = 1; - sp->components[2].type = get_resourcetype(R_HORSE); - sp->components[2].cost = SPC_LINEAR; - return sp; -} - void test_pay_spell(CuTest * tc) { spell *sp; @@ -107,7 +89,7 @@ void test_pay_spell(CuTest * tc) u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); - sp = test_magic_create_spell(); + sp = test_create_spell(); CuAssertPtrNotNull(tc, sp); set_level(u, SK_MAGIC, 5); @@ -141,7 +123,7 @@ void test_pay_spell_failure(CuTest * tc) u = test_create_unit(f, r); CuAssertPtrNotNull(tc, u); - sp = test_magic_create_spell(); + sp = test_create_spell(); CuAssertPtrNotNull(tc, sp); set_level(u, SK_MAGIC, 5); diff --git a/src/report.c b/src/report.c index f157a75f4..42a9e8cdf 100644 --- a/src/report.c +++ b/src/report.c @@ -248,7 +248,7 @@ static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool return 0; } -static void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *lang) +void nr_spell(stream *out, spellbook_entry * sbe, const struct locale *lang) { int bytes, k, itemanz, costtyp; char buf[4096]; diff --git a/src/report.h b/src/report.h index 657bef36b..6379dbeeb 100644 --- a/src/report.h +++ b/src/report.h @@ -20,12 +20,16 @@ extern "C" { #endif struct stream; + struct spellbook_entry; struct region; struct faction; void register_nr(void); void report_cleanup(void); void write_spaces(struct stream *out, size_t num); void write_travelthru(struct stream *out, const struct region * r, const struct faction * f); + + void nr_spell(struct stream *out, struct spellbook_entry * sbe, const struct locale *lang); + #ifdef __cplusplus } #endif diff --git a/src/reports.test.c b/src/reports.test.c index 1dd9f5928..7b14680a5 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -6,6 +6,7 @@ #include "move.h" #include "seen.h" #include "travelthru.h" +#include "keyword.h" #include #include @@ -13,6 +14,8 @@ #include #include #include +#include +#include #include @@ -284,6 +287,50 @@ static void test_write_unit(CuTest *tc) { test_cleanup(); } +static void test_write_spell_syntax(CuTest *tc) { + stream strm; + char buf[1024]; + char *line; + size_t len; + spell *sp; + spellbook *spb; + spellbook_entry * sbe; + struct locale *lang; + + + test_cleanup(); + + lang = get_or_create_locale("de"); + locale_setstring(lang, "spell::testspell", "Testzauber"); + locale_setstring(lang, "nr_spell_type", "Typ:"); + locale_setstring(lang, "sptype_normal", "Normal"); + locale_setstring(lang, "nr_spell_modifiers", "Modifier:"); + locale_setstring(lang, "smod_none", "Keine"); + locale_setstring(lang, keyword(K_CAST), "ZAUBERE"); + + spb = create_spellbook("testbook"); + sp = test_create_spell(); + spellbook_add(spb, sp, 1); + sbe = spellbook_get(spb, sp); + mstream_init(&strm); + + nr_spell(&strm, sbe, lang); + stream_printf(&strm, "\n"); + + strm.api->rewind(strm.handle); + + len = strm.api->read(strm.handle, buf, sizeof(buf)); + buf[len] = '\0'; + + line = strtok(buf, "\n"); + while (line && !strstr(line, "ZAUBERE")) line = strtok(NULL, "\n") ; + + CuAssertTrue(tc, (bool) line); + CuAssertStrEquals(tc, " ZAUBERE \"Testzauber\"", line); + mstream_done(&strm); + test_cleanup(); +} + CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -296,5 +343,6 @@ CuSuite *get_reports_suite(void) SUITE_ADD_TEST(suite, test_sparagraph); SUITE_ADD_TEST(suite, test_write_travelthru); SUITE_ADD_TEST(suite, test_write_unit); + SUITE_ADD_TEST(suite, test_write_spell_syntax); return suite; } diff --git a/src/tests.c b/src/tests.c index e7518211e..380eb7069 100644 --- a/src/tests.c +++ b/src/tests.c @@ -190,6 +190,24 @@ void test_create_castorder(castorder *co, unit *u, int level, float force, int r free_order(ord); } +spell * test_create_spell(void) +{ + spell *sp; + sp = create_spell("testspell", 0); + + sp->components = (spell_component *)calloc(4, sizeof(spell_component)); + sp->components[0].amount = 1; + sp->components[0].type = get_resourcetype(R_SILVER); + sp->components[0].cost = SPC_FIX; + sp->components[1].amount = 1; + sp->components[1].type = get_resourcetype(R_AURA); + sp->components[1].cost = SPC_LEVEL; + sp->components[2].amount = 1; + sp->components[2].type = get_resourcetype(R_HORSE); + sp->components[2].cost = SPC_LINEAR; + return sp; +} + void test_translate_param(const struct locale *lang, param_t param, const char *text) { struct critbit_tree **cb; diff --git a/src/tests.h b/src/tests.h index f0b64729b..ffed85c21 100644 --- a/src/tests.h +++ b/src/tests.h @@ -22,6 +22,7 @@ extern "C" { struct terrain_type; struct castorder; struct spellparameter; + struct spell; struct CuTest; @@ -41,6 +42,7 @@ extern "C" { struct ship_type *test_create_shiptype(const char * name); struct building_type *test_create_buildingtype(const char *name); void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range, struct spellparameter *par); + struct spell * test_create_spell(void); int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text);