forked from github/server
prepared test for nr_spell
This commit is contained in:
parent
5ef9b624ff
commit
f3972a2390
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void test_create_spell(CuTest * tc)
|
static void test_create_a_spell(CuTest * tc)
|
||||||
{
|
{
|
||||||
spell * sp;
|
spell * sp;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ static void test_create_spell_with_id(CuTest * tc)
|
||||||
CuSuite *get_spell_suite(void)
|
CuSuite *get_spell_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
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_duplicate_spell);
|
||||||
SUITE_ADD_TEST(suite, test_create_spell_with_id);
|
SUITE_ADD_TEST(suite, test_create_spell_with_id);
|
||||||
return suite;
|
return suite;
|
||||||
|
|
|
@ -74,24 +74,6 @@ void test_spellbooks(CuTest * tc)
|
||||||
test_cleanup();
|
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)
|
void test_pay_spell(CuTest * tc)
|
||||||
{
|
{
|
||||||
spell *sp;
|
spell *sp;
|
||||||
|
@ -107,7 +89,7 @@ void test_pay_spell(CuTest * tc)
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
CuAssertPtrNotNull(tc, u);
|
CuAssertPtrNotNull(tc, u);
|
||||||
|
|
||||||
sp = test_magic_create_spell();
|
sp = test_create_spell();
|
||||||
CuAssertPtrNotNull(tc, sp);
|
CuAssertPtrNotNull(tc, sp);
|
||||||
|
|
||||||
set_level(u, SK_MAGIC, 5);
|
set_level(u, SK_MAGIC, 5);
|
||||||
|
@ -141,7 +123,7 @@ void test_pay_spell_failure(CuTest * tc)
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
CuAssertPtrNotNull(tc, u);
|
CuAssertPtrNotNull(tc, u);
|
||||||
|
|
||||||
sp = test_magic_create_spell();
|
sp = test_create_spell();
|
||||||
CuAssertPtrNotNull(tc, sp);
|
CuAssertPtrNotNull(tc, sp);
|
||||||
|
|
||||||
set_level(u, SK_MAGIC, 5);
|
set_level(u, SK_MAGIC, 5);
|
||||||
|
|
|
@ -248,7 +248,7 @@ static size_t write_spell_modifier(spell * sp, int flag, const char * str, bool
|
||||||
return 0;
|
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;
|
int bytes, k, itemanz, costtyp;
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
|
@ -20,12 +20,16 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct stream;
|
struct stream;
|
||||||
|
struct spellbook_entry;
|
||||||
struct region;
|
struct region;
|
||||||
struct faction;
|
struct faction;
|
||||||
void register_nr(void);
|
void register_nr(void);
|
||||||
void report_cleanup(void);
|
void report_cleanup(void);
|
||||||
void write_spaces(struct stream *out, size_t num);
|
void write_spaces(struct stream *out, size_t num);
|
||||||
void write_travelthru(struct stream *out, const struct region * r, const struct faction * f);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "seen.h"
|
#include "seen.h"
|
||||||
#include "travelthru.h"
|
#include "travelthru.h"
|
||||||
|
#include "keyword.h"
|
||||||
|
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
|
@ -13,6 +14,8 @@
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/ship.h>
|
#include <kernel/ship.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/spell.h>
|
||||||
|
#include <kernel/spellbook.h>
|
||||||
|
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
|
||||||
|
@ -284,6 +287,50 @@ static void test_write_unit(CuTest *tc) {
|
||||||
test_cleanup();
|
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 *get_reports_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -296,5 +343,6 @@ CuSuite *get_reports_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_sparagraph);
|
SUITE_ADD_TEST(suite, test_sparagraph);
|
||||||
SUITE_ADD_TEST(suite, test_write_travelthru);
|
SUITE_ADD_TEST(suite, test_write_travelthru);
|
||||||
SUITE_ADD_TEST(suite, test_write_unit);
|
SUITE_ADD_TEST(suite, test_write_unit);
|
||||||
|
SUITE_ADD_TEST(suite, test_write_spell_syntax);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
18
src/tests.c
18
src/tests.c
|
@ -190,6 +190,24 @@ void test_create_castorder(castorder *co, unit *u, int level, float force, int r
|
||||||
free_order(ord);
|
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) {
|
void test_translate_param(const struct locale *lang, param_t param, const char *text) {
|
||||||
struct critbit_tree **cb;
|
struct critbit_tree **cb;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
||||||
struct terrain_type;
|
struct terrain_type;
|
||||||
struct castorder;
|
struct castorder;
|
||||||
struct spellparameter;
|
struct spellparameter;
|
||||||
|
struct spell;
|
||||||
|
|
||||||
struct CuTest;
|
struct CuTest;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ extern "C" {
|
||||||
struct ship_type *test_create_shiptype(const char * name);
|
struct ship_type *test_create_shiptype(const char * name);
|
||||||
struct building_type *test_create_buildingtype(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);
|
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);
|
int RunAllTests(void);
|
||||||
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
void test_translate_param(const struct locale *lang, param_t param, const char *text);
|
||||||
|
|
Loading…
Reference in New Issue