2010-08-08 10:06:34 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include "tests.h"
|
2015-09-12 12:41:04 +02:00
|
|
|
#include "prefix.h"
|
2018-12-02 05:04:49 +01:00
|
|
|
#include "creport.h"
|
|
|
|
#include "report.h"
|
2016-03-23 11:56:17 +01:00
|
|
|
#include "reports.h"
|
2017-08-25 08:52:15 +02:00
|
|
|
#include "vortex.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-09-29 19:32:39 +02:00
|
|
|
#include "kernel/calendar.h"
|
2019-05-19 15:47:13 +02:00
|
|
|
#include "kernel/callbacks.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/alliance.h"
|
2017-10-10 20:59:51 +02:00
|
|
|
#include <kernel/equipment.h>
|
2018-01-14 11:58:22 +01:00
|
|
|
#include <kernel/messages.h>
|
2016-02-18 08:11:39 +01:00
|
|
|
#include <kernel/plane.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/terrain.h>
|
2018-09-13 16:16:32 +02:00
|
|
|
#include <kernel/terrainid.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/unit.h>
|
2015-10-13 23:25:44 +02:00
|
|
|
#include <kernel/order.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/building.h>
|
|
|
|
#include <kernel/ship.h>
|
2012-06-04 11:41:07 +02:00
|
|
|
#include <kernel/spell.h>
|
|
|
|
#include <kernel/spellbook.h>
|
2011-03-13 02:01:20 +01:00
|
|
|
#include <kernel/terrain.h>
|
2018-09-29 19:32:39 +02:00
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
#include <util/functions.h>
|
2018-09-29 19:32:39 +02:00
|
|
|
#include "util/keyword.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <util/language.h>
|
2016-08-29 16:19:17 +02:00
|
|
|
#include <util/lists.h>
|
2015-01-12 17:50:10 +01:00
|
|
|
#include <util/message.h>
|
2012-06-02 03:05:07 +02:00
|
|
|
#include <util/log.h>
|
2018-09-29 19:32:39 +02:00
|
|
|
#include "util/param.h"
|
2015-12-08 17:48:53 +01:00
|
|
|
#include <util/rand.h>
|
2016-08-29 10:20:08 +02:00
|
|
|
#include <util/assert.h>
|
2012-06-02 03:05:07 +02:00
|
|
|
|
2015-02-01 19:14:06 +01:00
|
|
|
#include <CuTest.h>
|
|
|
|
|
2015-08-18 17:28:07 +02:00
|
|
|
#include <errno.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2018-05-18 15:34:21 +02:00
|
|
|
int test_set_item(unit * u, const item_type *itype, int value)
|
|
|
|
{
|
|
|
|
item *i;
|
|
|
|
|
|
|
|
assert(itype);
|
|
|
|
i = *i_find(&u->items, itype);
|
|
|
|
if (!i) {
|
|
|
|
i = i_add(&u->items, i_new(itype, value));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i->number = value;
|
|
|
|
assert(i->number >= 0);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct race *test_create_race(const char *name)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2017-10-06 22:15:48 +02:00
|
|
|
race *rc = rc_get_or_create(name ? name : "smurf");
|
2015-01-30 20:37:14 +01:00
|
|
|
rc->maintenance = 10;
|
2015-11-09 19:43:51 +01:00
|
|
|
rc->hitpoints = 20;
|
2017-02-03 20:06:01 +01:00
|
|
|
rc->maxaura = 100;
|
2018-05-10 22:00:23 +02:00
|
|
|
rc->flags |= (RCF_WALK|RCF_PLAYABLE);
|
2017-07-17 12:33:55 +02:00
|
|
|
rc->ec_flags |= ECF_GETITEM;
|
2015-12-05 17:17:21 +01:00
|
|
|
rc->battle_flags = BF_EQUIPMENT;
|
2015-01-30 20:37:14 +01:00
|
|
|
return rc;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
struct region *test_create_region(int x, int y, const terrain_type *terrain)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-01-28 16:00:36 +01:00
|
|
|
region *r = findregion(x, y);
|
|
|
|
if (!r) {
|
2016-02-18 08:11:39 +01:00
|
|
|
r = new_region(x, y, findplane(x, y), 0);
|
2016-01-28 16:00:36 +01:00
|
|
|
}
|
2015-02-01 19:14:06 +01:00
|
|
|
if (!terrain) {
|
2017-03-10 21:29:37 +01:00
|
|
|
terrain_type *t = test_create_terrain("plain", LAND_REGION | CAVALRY_REGION | FOREST_REGION | FLY_INTO | WALK_INTO);
|
2015-02-01 19:14:06 +01:00
|
|
|
terraform_region(r, t);
|
2016-01-28 16:00:36 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-02-01 19:14:06 +01:00
|
|
|
terraform_region(r, terrain);
|
2016-01-28 16:00:36 +01:00
|
|
|
}
|
2017-12-28 00:10:05 +01:00
|
|
|
r->flags &= ~RF_MALLORN;
|
2015-01-30 20:37:14 +01:00
|
|
|
rsettrees(r, 0, 0);
|
|
|
|
rsettrees(r, 1, 0);
|
|
|
|
rsettrees(r, 2, 0);
|
|
|
|
rsethorses(r, 0);
|
|
|
|
rsetpeasants(r, r->terrain->size);
|
|
|
|
return r;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
region *test_create_ocean(int x, int y)
|
|
|
|
{
|
|
|
|
terrain_type *ter = test_create_terrain("ocean", SEA_REGION | FLY_INTO | SWIM_INTO);
|
|
|
|
return test_create_region(x, y, ter);
|
|
|
|
}
|
|
|
|
|
|
|
|
region *test_create_plain(int x, int y) {
|
|
|
|
return test_create_region(x, y, NULL);
|
|
|
|
}
|
|
|
|
|
2016-03-23 11:56:17 +01:00
|
|
|
struct locale * test_create_locale(void) {
|
|
|
|
struct locale *loc = get_locale("test");
|
|
|
|
if (!loc) {
|
|
|
|
int i;
|
|
|
|
loc = get_or_create_locale("test");
|
2016-03-23 22:24:11 +01:00
|
|
|
locale_setstring(loc, "factiondefault", parameters[P_FACTION]);
|
2017-03-10 21:29:37 +01:00
|
|
|
locale_setstring(loc, "unitdefault", parameters[P_UNIT]);
|
|
|
|
locale_setstring(loc, "money", "Silber");
|
|
|
|
locale_setstring(loc, "money_p", "Silber");
|
|
|
|
locale_setstring(loc, "cart", "Wagen");
|
|
|
|
locale_setstring(loc, "cart_p", "Wagen");
|
|
|
|
locale_setstring(loc, "horse", "Pferd");
|
|
|
|
locale_setstring(loc, "horse_p", "Pferde");
|
|
|
|
locale_setstring(loc, "iron", "Eisen");
|
|
|
|
locale_setstring(loc, "iron_p", "Eisen");
|
|
|
|
locale_setstring(loc, "stone", "Stein");
|
|
|
|
locale_setstring(loc, "stone_p", "Steine");
|
|
|
|
locale_setstring(loc, "plain", "Ebene");
|
|
|
|
locale_setstring(loc, "ocean", "Ozean");
|
2017-04-17 20:11:44 +02:00
|
|
|
for (i = 0; i < MAXRACES; ++i) {
|
|
|
|
if (racenames[i]) {
|
|
|
|
char name[64];
|
|
|
|
rc_key(racenames[i], NAME_PLURAL, name, sizeof(name));
|
|
|
|
if (!locale_getstring(loc, name)) {
|
|
|
|
locale_setstring(loc, name, name + 6);
|
|
|
|
}
|
|
|
|
rc_key(racenames[i], NAME_SINGULAR, name, sizeof(name));
|
|
|
|
if (!locale_getstring(loc, name)) {
|
|
|
|
locale_setstring(loc, name, name + 6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-23 11:56:17 +01:00
|
|
|
for (i = 0; i < MAXSKILLS; ++i) {
|
|
|
|
if (!locale_getstring(loc, mkname("skill", skillnames[i])))
|
|
|
|
locale_setstring(loc, mkname("skill", skillnames[i]), skillnames[i]);
|
|
|
|
}
|
2016-04-08 19:45:27 +02:00
|
|
|
for (i = 0; i != ALLIANCE_MAX; ++i) {
|
|
|
|
locale_setstring(loc, alliance_kwd[i], alliance_kwd[i]);
|
|
|
|
}
|
2016-03-23 11:56:17 +01:00
|
|
|
for (i = 0; i != MAXDIRECTIONS; ++i) {
|
2017-12-11 16:24:06 +01:00
|
|
|
locale_setstring(loc, shortdirections[i], shortdirections[i] + 4);
|
2016-03-23 11:56:17 +01:00
|
|
|
locale_setstring(loc, directions[i], directions[i]);
|
|
|
|
init_direction(loc, i, directions[i]);
|
2017-11-05 16:43:01 +01:00
|
|
|
init_direction(loc, i, coasts[i] + 7);
|
2016-03-23 11:56:17 +01:00
|
|
|
}
|
|
|
|
for (i = 0; i <= ST_FLEE; ++i) {
|
2017-11-05 16:43:01 +01:00
|
|
|
locale_setstring(loc, combatstatus[i], combatstatus[i] + 7);
|
2016-03-23 11:56:17 +01:00
|
|
|
}
|
2016-03-23 23:06:45 +01:00
|
|
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
2018-09-15 18:35:27 +02:00
|
|
|
if (keywords[i]) {
|
|
|
|
locale_setstring(loc, mkname("keyword", keywords[i]), keywords[i]);
|
|
|
|
}
|
2016-03-23 23:06:45 +01:00
|
|
|
}
|
2016-03-23 22:24:11 +01:00
|
|
|
for (i = 0; i != MAXPARAMS; ++i) {
|
|
|
|
locale_setstring(loc, parameters[i], parameters[i]);
|
|
|
|
test_translate_param(loc, i, parameters[i]);
|
|
|
|
}
|
2016-09-11 11:02:04 +02:00
|
|
|
for (i = 0; i != MAXMAGIETYP; ++i) {
|
|
|
|
locale_setstring(loc, mkname("school", magic_school[i]), magic_school[i]);
|
|
|
|
}
|
|
|
|
init_locale(loc);
|
2016-03-23 11:56:17 +01:00
|
|
|
}
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct faction *test_create_faction(const struct race *rc)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-03-23 11:56:17 +01:00
|
|
|
struct locale * loc = test_create_locale();
|
2018-09-24 20:18:21 +02:00
|
|
|
faction *f = addfaction("nobody@eressea.de", NULL, rc ? rc : test_create_race("human"), loc);
|
2016-01-12 06:46:51 +01:00
|
|
|
test_clear_messages(f);
|
2015-01-30 20:37:14 +01:00
|
|
|
return f;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
struct unit *test_create_unit(struct faction *f, struct region *r)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-10-16 08:13:56 +02:00
|
|
|
const struct race * rc = f ? f->race : 0;
|
2016-09-08 09:11:17 +02:00
|
|
|
assert(f && r);
|
2016-03-13 13:31:54 +01:00
|
|
|
if (!rc) rc = rc_get_or_create("human");
|
2016-03-13 19:13:58 +01:00
|
|
|
return create_unit(r, f, 1, rc ? rc : rc_get_or_create("human"), 0, 0, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 16:19:17 +02:00
|
|
|
static void log_list(void *udata, int flags, const char *module, const char *format, va_list args) {
|
|
|
|
strlist **slp = (strlist **)udata;
|
|
|
|
addstrlist(slp, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct log_t * test_log_start(int flags, strlist **slist) {
|
|
|
|
return log_create(flags, slist, log_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_log_stop(struct log_t *log, struct strlist *slist) {
|
|
|
|
freestrlist(slist);
|
|
|
|
log_destroy(log);
|
|
|
|
}
|
|
|
|
|
2016-08-29 15:09:47 +02:00
|
|
|
void test_log_stderr(int flags) {
|
|
|
|
static struct log_t *stderrlog;
|
|
|
|
if (flags) {
|
|
|
|
if (stderrlog) {
|
2017-12-27 19:58:39 +01:00
|
|
|
log_error("stderr logging is still active. did you call test_teardown?");
|
2016-08-29 15:09:47 +02:00
|
|
|
log_destroy(stderrlog);
|
|
|
|
}
|
|
|
|
stderrlog = log_to_file(flags, stderr);
|
|
|
|
}
|
|
|
|
else {
|
2016-08-29 15:21:28 +02:00
|
|
|
if (stderrlog) {
|
|
|
|
log_destroy(stderrlog);
|
|
|
|
}
|
|
|
|
else {
|
2017-12-27 19:58:39 +01:00
|
|
|
log_warning("stderr logging is inactive. did you call test_teardown twice?");
|
2016-08-29 15:21:28 +02:00
|
|
|
}
|
2016-08-29 15:09:47 +02:00
|
|
|
stderrlog = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-09-12 17:06:47 +02:00
|
|
|
|
2016-08-29 15:09:47 +02:00
|
|
|
static void test_reset(void) {
|
|
|
|
int i;
|
2017-05-07 16:11:45 +02:00
|
|
|
turn = 1;
|
2016-03-23 23:06:45 +01:00
|
|
|
default_locale = 0;
|
2016-09-11 11:02:04 +02:00
|
|
|
|
|
|
|
if (errno) {
|
|
|
|
int error = errno;
|
|
|
|
errno = 0;
|
|
|
|
log_error("errno: %d (%s)", error, strerror(error));
|
|
|
|
}
|
2019-05-19 15:47:13 +02:00
|
|
|
memset(&callbacks, 0, sizeof(callbacks));
|
2016-01-11 18:03:53 +01:00
|
|
|
free_gamedata();
|
2014-12-30 02:02:10 +01:00
|
|
|
free_terrains();
|
2014-12-30 23:49:50 +01:00
|
|
|
free_resources();
|
2018-12-02 05:04:49 +01:00
|
|
|
free_functions();
|
2015-11-22 12:24:27 +01:00
|
|
|
free_config();
|
2014-06-17 17:46:22 +02:00
|
|
|
default_locale = 0;
|
2017-05-07 15:50:19 +02:00
|
|
|
calendar_cleanup();
|
2018-12-02 05:04:49 +01:00
|
|
|
creport_cleanup();
|
|
|
|
report_cleanup();
|
2015-10-13 23:25:44 +02:00
|
|
|
close_orders();
|
2018-10-21 19:22:30 +02:00
|
|
|
log_close();
|
|
|
|
stats_close();
|
2017-08-25 08:52:15 +02:00
|
|
|
free_special_directions();
|
2014-06-17 17:46:22 +02:00
|
|
|
free_locales();
|
|
|
|
free_spells();
|
|
|
|
free_buildingtypes();
|
|
|
|
free_shiptypes();
|
|
|
|
free_races();
|
|
|
|
free_spellbooks();
|
2015-09-12 12:41:04 +02:00
|
|
|
free_prefixes();
|
2015-08-17 19:35:07 +02:00
|
|
|
mt_clear();
|
2018-12-02 05:04:49 +01:00
|
|
|
|
2015-09-12 17:43:31 +02:00
|
|
|
for (i = 0; i != MAXSKILLS; ++i) {
|
|
|
|
enable_skill(i, true);
|
|
|
|
}
|
2015-09-12 17:06:47 +02:00
|
|
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
|
|
|
enable_keyword(i, true);
|
|
|
|
}
|
2016-09-11 11:02:04 +02:00
|
|
|
random_source_reset();
|
|
|
|
|
2018-05-18 19:58:49 +02:00
|
|
|
mt_create_va(mt_new("changepasswd", NULL),
|
|
|
|
"value:string", MT_NEW_END);
|
|
|
|
mt_create_va(mt_new("starvation", NULL),
|
|
|
|
"unit:unit", "region:region", "dead:int", "live:int", MT_NEW_END);
|
|
|
|
mt_create_va(mt_new("malnourish", NULL),
|
|
|
|
"unit:unit", "region:region", MT_NEW_END);
|
2018-01-13 08:51:40 +01:00
|
|
|
|
2015-08-18 17:08:02 +02:00
|
|
|
if (errno) {
|
|
|
|
int error = errno;
|
|
|
|
errno = 0;
|
2016-01-29 17:49:27 +01:00
|
|
|
log_error("errno: %d (%s)", error, strerror(error));
|
2015-08-18 17:08:02 +02:00
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:31:00 +02:00
|
|
|
void test_create_calendar(void) {
|
|
|
|
config_set_int("game.start", 184);
|
|
|
|
months_per_year = 9;
|
2019-08-25 15:14:21 +02:00
|
|
|
month_season = malloc(sizeof(season_t) * months_per_year);
|
2018-12-15 20:12:53 +01:00
|
|
|
if (!month_season) abort();
|
2018-08-02 14:31:00 +02:00
|
|
|
month_season[0] = SEASON_SUMMER;
|
|
|
|
month_season[1] = SEASON_AUTUMN;
|
|
|
|
month_season[2] = SEASON_AUTUMN;
|
|
|
|
month_season[3] = SEASON_WINTER;
|
|
|
|
month_season[4] = SEASON_WINTER;
|
|
|
|
month_season[5] = SEASON_WINTER;
|
|
|
|
month_season[6] = SEASON_SPRING;
|
|
|
|
month_season[7] = SEASON_SPRING;
|
|
|
|
month_season[8] = SEASON_SUMMER;
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:08:10 +01:00
|
|
|
void test_setup_test(CuTest *tc, const char *file, int line) {
|
2016-08-29 15:09:47 +02:00
|
|
|
test_log_stderr(LOG_CPERROR);
|
|
|
|
test_reset();
|
2018-10-28 21:28:05 +01:00
|
|
|
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
2016-11-16 18:08:10 +01:00
|
|
|
if (tc) {
|
|
|
|
log_debug("start test: %s", tc->name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log_debug("start test in %s:%d", file, line);
|
|
|
|
}
|
2018-05-14 04:42:59 +02:00
|
|
|
errno = 0;
|
2016-08-29 15:09:47 +02:00
|
|
|
}
|
|
|
|
|
2017-12-27 19:58:39 +01:00
|
|
|
void test_teardown(void)
|
2016-08-29 15:09:47 +02:00
|
|
|
{
|
2018-10-28 21:28:05 +01:00
|
|
|
message_handle_missing(MESSAGE_MISSING_IGNORE);
|
2016-08-29 15:09:47 +02:00
|
|
|
test_reset();
|
|
|
|
test_log_stderr(0);
|
|
|
|
}
|
|
|
|
|
2011-03-13 02:01:20 +01:00
|
|
|
terrain_type *
|
2018-03-04 20:30:29 +01:00
|
|
|
test_create_terrain(const char * name, int flags)
|
2011-03-13 02:01:20 +01:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
terrain_type * t = get_or_create_terrain(name);
|
2018-03-04 20:30:29 +01:00
|
|
|
|
|
|
|
if (flags < 0) {
|
|
|
|
/* sensible defaults for most terrains */
|
|
|
|
flags = LAND_REGION | WALK_INTO | FLY_INTO;
|
|
|
|
}
|
2017-02-03 17:43:40 +01:00
|
|
|
if (flags & LAND_REGION) {
|
|
|
|
t->size = 1000;
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
t->flags = flags;
|
|
|
|
return t;
|
2011-03-13 02:01:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
building * test_create_building(region * r, const building_type * btype)
|
|
|
|
{
|
2016-11-11 21:41:25 +01:00
|
|
|
building * b;
|
|
|
|
assert(r);
|
2017-01-25 20:57:54 +01:00
|
|
|
if (!btype) {
|
|
|
|
building_type *bt_castle = test_create_buildingtype("castle");
|
2017-02-22 19:38:46 +01:00
|
|
|
bt_castle->flags |= BTF_FORTIFICATION;
|
2017-01-25 20:57:54 +01:00
|
|
|
btype = bt_castle;
|
|
|
|
}
|
|
|
|
b = new_building(btype, r, default_locale);
|
|
|
|
b->size = btype->maxsize > 0 ? btype->maxsize : 1;
|
2015-01-30 20:37:14 +01:00
|
|
|
return b;
|
2011-03-13 02:01:20 +01:00
|
|
|
}
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2012-05-17 09:13:30 +02:00
|
|
|
ship * test_create_ship(region * r, const ship_type * stype)
|
|
|
|
{
|
2015-10-12 19:40:20 +02:00
|
|
|
ship * s = new_ship(stype ? stype : test_create_shiptype("boat"), r, default_locale);
|
2015-01-30 20:37:14 +01:00
|
|
|
s->size = s->type->construction ? s->type->construction->maxsize : 1;
|
|
|
|
return s;
|
2012-05-17 09:13:30 +02:00
|
|
|
}
|
|
|
|
|
2014-06-30 02:02:45 +02:00
|
|
|
ship_type * test_create_shiptype(const char * name)
|
2012-07-02 03:00:31 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
ship_type * stype = st_get_or_create(name);
|
2015-08-07 11:50:49 +02:00
|
|
|
stype->cptskill = 1;
|
|
|
|
stype->sumskill = 1;
|
|
|
|
stype->minskill = 1;
|
2015-10-12 19:40:20 +02:00
|
|
|
stype->range = 2;
|
2015-11-15 02:20:55 +01:00
|
|
|
stype->cargo = 1000;
|
|
|
|
stype->damage = 1;
|
2015-08-07 11:50:49 +02:00
|
|
|
if (!stype->construction) {
|
|
|
|
stype->construction = calloc(1, sizeof(construction));
|
2016-08-29 10:20:08 +02:00
|
|
|
assert_alloc(stype->construction);
|
2015-08-07 11:50:49 +02:00
|
|
|
stype->construction->maxsize = 5;
|
|
|
|
stype->construction->minskill = 1;
|
|
|
|
stype->construction->reqsize = 1;
|
|
|
|
stype->construction->skill = SK_SHIPBUILDING;
|
|
|
|
}
|
2015-11-15 02:20:55 +01:00
|
|
|
|
2016-03-10 21:54:53 +01:00
|
|
|
if (stype->coasts) {
|
|
|
|
free(stype->coasts);
|
|
|
|
}
|
2015-11-15 02:20:55 +01:00
|
|
|
stype->coasts =
|
2016-06-10 18:24:18 +02:00
|
|
|
(terrain_type **)malloc(sizeof(terrain_type *) * 3);
|
2016-06-10 20:55:27 +02:00
|
|
|
stype->coasts[0] = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION | FLY_INTO);
|
|
|
|
stype->coasts[1] = test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO);
|
2016-06-10 18:24:18 +02:00
|
|
|
stype->coasts[2] = NULL;
|
2015-08-07 11:50:49 +02:00
|
|
|
if (default_locale) {
|
|
|
|
locale_setstring(default_locale, name, name);
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
return stype;
|
2012-07-02 03:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
building_type * test_create_buildingtype(const char * name)
|
|
|
|
{
|
2018-05-01 15:32:06 +02:00
|
|
|
construction *con;
|
2015-10-13 13:56:58 +02:00
|
|
|
building_type *btype = bt_get_or_create(name);
|
2018-05-01 15:32:06 +02:00
|
|
|
if (btype->stages) {
|
|
|
|
con = btype->stages->construction;
|
|
|
|
} else {
|
|
|
|
btype->stages = calloc(1, sizeof(building_stage));
|
|
|
|
con = (construction *)calloc(1, sizeof(construction));
|
|
|
|
if (con) {
|
|
|
|
con->skill = SK_BUILDING;
|
|
|
|
con->maxsize = -1;
|
|
|
|
con->minskill = 1;
|
|
|
|
con->reqsize = 1;
|
|
|
|
btype->stages->construction = con;
|
|
|
|
}
|
2015-10-14 12:21:13 +02:00
|
|
|
}
|
2018-05-01 15:32:06 +02:00
|
|
|
if (con && !con->materials) {
|
|
|
|
con->materials = (requirement *)calloc(2, sizeof(requirement));
|
|
|
|
con->materials[1].number = 0;
|
|
|
|
con->materials[0].number = 1;
|
|
|
|
con->materials[0].rtype = get_resourcetype(R_STONE);
|
2015-10-14 12:21:13 +02:00
|
|
|
}
|
2014-09-29 23:19:59 +02:00
|
|
|
if (default_locale) {
|
2018-09-29 20:06:58 +02:00
|
|
|
if (locale_getstring(default_locale, name) == NULL) {
|
|
|
|
locale_setstring(default_locale, name, name);
|
|
|
|
}
|
2014-09-29 23:19:59 +02:00
|
|
|
}
|
2014-06-29 01:19:46 +02:00
|
|
|
return btype;
|
2012-07-02 03:00:31 +02:00
|
|
|
}
|
|
|
|
|
2014-06-30 02:02:45 +02:00
|
|
|
item_type * test_create_itemtype(const char * name) {
|
2015-01-30 20:37:14 +01:00
|
|
|
resource_type * rtype;
|
|
|
|
item_type * itype;
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
rtype = rt_get_or_create(name);
|
|
|
|
itype = it_get_or_create(rtype);
|
2011-03-16 05:04:38 +01:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
return itype;
|
2011-03-16 05:04:38 +01:00
|
|
|
}
|
|
|
|
|
2015-11-02 17:09:16 +01:00
|
|
|
void test_create_castorder(castorder *co, unit *u, int level, float force, int range, spellparameter *par) {
|
2015-11-02 16:12:56 +01:00
|
|
|
struct locale * lang;
|
|
|
|
order *ord;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
lang = test_create_locale();
|
2015-11-02 17:09:16 +01:00
|
|
|
create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), par);
|
2015-11-02 16:12:56 +01:00
|
|
|
free_order(ord);
|
|
|
|
}
|
|
|
|
|
2015-11-12 19:34:25 +01:00
|
|
|
spell * test_create_spell(void)
|
|
|
|
{
|
|
|
|
spell *sp;
|
2017-05-01 17:04:28 +02:00
|
|
|
sp = create_spell("testspell");
|
2015-11-12 19:34:25 +01:00
|
|
|
|
|
|
|
sp->components = (spell_component *)calloc(4, sizeof(spell_component));
|
2016-08-29 10:20:08 +02:00
|
|
|
assert_alloc(sp->components);
|
2015-11-12 19:34:25 +01:00
|
|
|
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;
|
2015-11-13 15:35:17 +01:00
|
|
|
sp->syntax = 0;
|
|
|
|
sp->parameter = 0;
|
2015-11-12 19:34:25 +01:00
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
2014-12-17 19:53:19 +01:00
|
|
|
void test_translate_param(const struct locale *lang, param_t param, const char *text) {
|
|
|
|
struct critbit_tree **cb;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2014-12-17 19:53:19 +01:00
|
|
|
assert(lang && text);
|
|
|
|
cb = (struct critbit_tree **)get_translations(lang, UT_PARAMS);
|
|
|
|
add_translation(cb, text, param);
|
|
|
|
}
|
|
|
|
|
2017-12-25 19:11:12 +01:00
|
|
|
item_type *test_create_silver(void) {
|
|
|
|
item_type * itype;
|
|
|
|
itype = test_create_itemtype("money");
|
|
|
|
itype->weight = 1;
|
|
|
|
return itype;
|
|
|
|
}
|
2015-11-07 23:34:51 +01:00
|
|
|
|
|
|
|
item_type *test_create_horse(void) {
|
|
|
|
item_type * itype;
|
|
|
|
itype = test_create_itemtype("horse");
|
|
|
|
itype->flags |= ITF_BIG | ITF_ANIMAL;
|
|
|
|
itype->weight = 5000;
|
|
|
|
itype->capacity = 7000;
|
|
|
|
return itype;
|
|
|
|
}
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
/** creates a small world and some stuff in it.
|
|
|
|
* two terrains: 'plain' and 'ocean'
|
|
|
|
* one race: 'human'
|
|
|
|
* one ship_type: 'boat'
|
|
|
|
* one building_type: 'castle'
|
|
|
|
* in 0.0 and 1.0 is an island of two plains, around it is ocean.
|
|
|
|
*/
|
|
|
|
void test_create_world(void)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
terrain_type *t_plain, *t_ocean;
|
|
|
|
region *island[2];
|
|
|
|
int i;
|
|
|
|
item_type * itype;
|
|
|
|
struct locale * loc;
|
|
|
|
|
2017-03-10 21:29:37 +01:00
|
|
|
loc = test_create_locale();
|
2016-01-28 16:00:36 +01:00
|
|
|
|
|
|
|
locale_setstring(loc, parameters[P_SHIP], "SCHIFF");
|
|
|
|
locale_setstring(loc, parameters[P_ANY], "ALLE");
|
|
|
|
init_parameters(loc);
|
|
|
|
|
2016-02-01 14:06:56 +01:00
|
|
|
locale_setstring(loc, "status_aggressive", "aggressiv");
|
2015-01-30 20:37:14 +01:00
|
|
|
locale_setstring(loc, keyword(K_RESERVE), "RESERVIEREN");
|
2017-03-10 21:29:37 +01:00
|
|
|
locale_setstring(loc, "money", "Silber");
|
|
|
|
locale_setstring(loc, "money_p", "Silber");
|
|
|
|
locale_setstring(loc, "cart", "Wagen");
|
|
|
|
locale_setstring(loc, "cart_p", "Wagen");
|
|
|
|
locale_setstring(loc, "horse", "Pferd");
|
|
|
|
locale_setstring(loc, "horse_p", "Pferde");
|
|
|
|
locale_setstring(loc, "iron", "Eisen");
|
|
|
|
locale_setstring(loc, "iron_p", "Eisen");
|
|
|
|
locale_setstring(loc, "stone", "Stein");
|
|
|
|
locale_setstring(loc, "stone_p", "Steine");
|
|
|
|
locale_setstring(loc, "plain", "Ebene");
|
|
|
|
locale_setstring(loc, "ocean", "Ozean");
|
2015-01-30 20:37:14 +01:00
|
|
|
init_resources();
|
2015-11-19 15:28:21 +01:00
|
|
|
get_resourcetype(R_SILVER)->itype->weight = 1;
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2015-11-07 23:34:51 +01:00
|
|
|
test_create_horse();
|
2015-01-30 20:37:14 +01:00
|
|
|
|
2015-04-14 02:32:01 +02:00
|
|
|
itype = test_create_itemtype("cart");
|
|
|
|
itype->flags |= ITF_BIG | ITF_VEHICLE;
|
|
|
|
itype->weight = 4000;
|
|
|
|
itype->capacity = 14000;
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
test_create_itemtype("iron");
|
|
|
|
test_create_itemtype("stone");
|
|
|
|
|
2017-11-05 16:43:01 +01:00
|
|
|
t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION | FLY_INTO);
|
2015-01-30 20:37:14 +01:00
|
|
|
t_plain->size = 1000;
|
|
|
|
t_plain->max_road = 100;
|
2017-11-05 16:43:01 +01:00
|
|
|
t_ocean = test_create_terrain("ocean", SEA_REGION | SWIM_INTO | FLY_INTO);
|
2015-01-30 20:37:14 +01:00
|
|
|
t_ocean->size = 0;
|
|
|
|
|
|
|
|
island[0] = test_create_region(0, 0, t_plain);
|
|
|
|
island[1] = test_create_region(1, 0, t_plain);
|
|
|
|
for (i = 0; i != 2; ++i) {
|
|
|
|
int j;
|
|
|
|
region *r = island[i];
|
|
|
|
for (j = 0; j != MAXDIRECTIONS; ++j) {
|
|
|
|
region *rn = r_connect(r, (direction_t)j);
|
|
|
|
if (!rn) {
|
|
|
|
rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
test_create_race("human");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
test_create_buildingtype("castle");
|
|
|
|
test_create_shiptype("boat");
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
2012-06-04 11:35:56 +02:00
|
|
|
|
2015-01-13 07:43:30 +01:00
|
|
|
message * test_get_last_message(message_list *msgs) {
|
2015-07-09 13:24:21 +02:00
|
|
|
if (msgs) {
|
|
|
|
struct mlist *iter = msgs->begin;
|
|
|
|
while (iter->next) {
|
|
|
|
iter = iter->next;
|
|
|
|
}
|
|
|
|
return iter->msg;
|
2015-01-13 07:43:30 +01:00
|
|
|
}
|
2015-07-09 13:24:21 +02:00
|
|
|
return 0;
|
2015-01-13 07:43:30 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 17:50:10 +01:00
|
|
|
const char * test_get_messagetype(const message *msg) {
|
2015-07-09 13:24:21 +02:00
|
|
|
const char * name;
|
|
|
|
assert(msg);
|
|
|
|
name = msg->type->name;
|
2015-01-12 17:50:10 +01:00
|
|
|
if (strcmp(name, "missing_message") == 0) {
|
|
|
|
name = (const char *)msg->parameters[0].v;
|
|
|
|
}
|
|
|
|
else if (strcmp(name, "missing_feedback") == 0) {
|
|
|
|
name = (const char *)msg->parameters[3].v;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-08-28 11:05:34 +02:00
|
|
|
struct message * test_find_messagetype_ex(struct message_list *msgs, const char *name, struct message *prev)
|
|
|
|
{
|
2015-08-15 20:25:36 +02:00
|
|
|
struct mlist *ml;
|
2015-10-11 12:44:22 +02:00
|
|
|
if (!msgs) return 0;
|
2015-08-15 20:25:36 +02:00
|
|
|
for (ml = msgs->begin; ml; ml = ml->next) {
|
2019-06-26 21:31:47 +02:00
|
|
|
if (prev && ml->msg == prev) {
|
|
|
|
prev = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp(name, test_get_messagetype(ml->msg)) == 0) {
|
|
|
|
return ml->msg;
|
2015-08-15 20:25:36 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-08 13:06:24 +02:00
|
|
|
return NULL;
|
2015-08-15 20:25:36 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 11:05:34 +02:00
|
|
|
struct message * test_find_messagetype(struct message_list *msgs, const char *name)
|
|
|
|
{
|
|
|
|
return test_find_messagetype_ex(msgs, name, NULL);
|
|
|
|
}
|
|
|
|
|
2019-09-08 13:29:10 +02:00
|
|
|
int test_count_messagetype(struct message_list *msgs, const char *name)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
struct mlist *ml;
|
|
|
|
if (!msgs) return 0;
|
|
|
|
for (ml = msgs->begin; ml; ml = ml->next) {
|
|
|
|
if (strcmp(name, test_get_messagetype(ml->msg)) == 0) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-09-27 15:40:03 +02:00
|
|
|
void test_clear_messagelist(message_list **msgs) {
|
|
|
|
if (*msgs) {
|
|
|
|
free_messagelist((*msgs)->begin);
|
|
|
|
free(*msgs);
|
|
|
|
*msgs = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-12 13:27:39 +02:00
|
|
|
void test_clear_messages(faction *f) {
|
2015-10-14 14:08:50 +02:00
|
|
|
if (f->msgs) {
|
|
|
|
free_messagelist(f->msgs->begin);
|
|
|
|
free(f->msgs);
|
2019-09-08 13:06:24 +02:00
|
|
|
f->msgs = NULL;
|
2015-10-14 14:08:50 +02:00
|
|
|
}
|
2015-10-12 13:27:39 +02:00
|
|
|
}
|
|
|
|
|
2016-06-11 13:47:38 +02:00
|
|
|
void assert_message(CuTest * tc, message *msg, char *name, int numpar) {
|
2016-05-31 10:37:01 +02:00
|
|
|
const message_type *mtype = msg->type;
|
|
|
|
assert(mtype);
|
|
|
|
|
|
|
|
CuAssertStrEquals(tc, name, mtype->name);
|
|
|
|
CuAssertIntEquals(tc, numpar, mtype->nparameters);
|
2016-06-11 13:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void assert_pointer_parameter(CuTest * tc, message *msg, int index, void *arg) {
|
|
|
|
const message_type *mtype = (msg)->type;
|
2017-11-05 16:43:01 +01:00
|
|
|
CuAssertIntEquals((tc), VAR_VOIDPTR, mtype->types[(index)]->vtype); CuAssertPtrEquals((tc), (arg), msg->parameters[(index)].v);
|
2016-06-11 13:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void assert_int_parameter(CuTest * tc, message *msg, int index, int arg) {
|
|
|
|
const message_type *mtype = (msg)->type;
|
2017-11-05 16:43:01 +01:00
|
|
|
CuAssertIntEquals((tc), VAR_INT, mtype->types[(index)]->vtype); CuAssertIntEquals((tc), (arg), msg->parameters[(index)].i);
|
2016-06-11 13:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void assert_string_parameter(CuTest * tc, message *msg, int index, const char *arg) {
|
|
|
|
const message_type *mtype = (msg)->type;
|
2017-11-05 16:43:01 +01:00
|
|
|
CuAssertIntEquals((tc), VAR_VOIDPTR, mtype->types[(index)]->vtype); CuAssertStrEquals((tc), (arg), msg->parameters[(index)].v);
|
2016-05-31 10:37:01 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 16:43:01 +01:00
|
|
|
void disabled_test(void *suite, void(*test)(CuTest *), const char *name) {
|
2015-02-08 13:42:04 +01:00
|
|
|
(void)test;
|
2015-02-08 13:37:44 +01:00
|
|
|
fprintf(stderr, "%s: SKIP\n", name);
|
|
|
|
}
|