Merge remote-tracking branch 'eressea/master'

Conflicts:
	.travis.yml
	critbit
	src/buildno.h
	src/test_eressea.c
This commit is contained in:
Enno Rehling 2014-12-12 17:28:20 +01:00
commit 3d0f8d0101
14 changed files with 99 additions and 20 deletions

View File

@ -13,7 +13,12 @@ if [ -d $REPORTS ]; then
fi fi
mkdir $REPORTS mkdir $REPORTS
$BIN/backup-eressea $GAME $BIN/backup-eressea $GAME
if [ -d test ]; then
touch test/execute.lock
fi
rm -f execute.lock
$BIN/run-turn $GAME $BIN/run-turn $GAME
touch execute.lock
if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then
echo "server did not create orders for turn $TURN in game $GAME" echo "server did not create orders for turn $TURN in game $GAME"
exit 2 exit 2
@ -29,5 +34,6 @@ if [ ! -s $REPORTS/reports.txt ]; then
fi fi
$BIN/compress.sh $GAME $TURN $BIN/compress.sh $GAME $TURN
$BIN/sendreports.sh $GAME $BIN/sendreports.sh $GAME
$BIN/backup-eressea $GAME $BIN/backup-eressea $GAME $TURN
[ $GAME -lt 4 ] && $BIN/send-summary $GAME [ $GAME -lt 4 ] && $BIN/send-summary $GAME
rm -f test/execute.lock

View File

@ -78,7 +78,12 @@ ln -f $LIVE/data/$turn.dat data/
rm -rf reports rm -rf reports
mkdir -p reports mkdir -p reports
$SOURCE/build-x86_64-gcc-Debug/eressea/eressea -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua SERVER="$SOURCE/build-x86_64-gcc-Debug/eressea/eressea"
VALGRIND=$(which valgrind)
if [ ! -z $VALGRIND ]; then
SERVER="$VALGRIND --leak-check=no $SERVER"
fi
$SERVER -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua
let turn=$turn+1 let turn=$turn+1
[ -e data/$turn.dat ] || abort "no data file created" [ -e data/$turn.dat ] || abort "no data file created"
} }

5
s/pull Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
if [ ! -z $1 ]; then
git checkout $1
fi
git pull && git submodule update

View File

@ -17,5 +17,6 @@ fi
$ROOT/$BIN_DIR/eressea/test_eressea $ROOT/$BIN_DIR/eressea/test_eressea
cd $ROOT cd $ROOT
[ -e eressea.ini ] || ln -sf conf/eressea.ini
$ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests.lua $ROOT/$BIN_DIR/eressea/eressea -v0 scripts/run-tests.lua
cd $OLDWPD cd $OLDWPD

View File

@ -26,6 +26,18 @@ function callbacks(rules, name, ...)
end end
end end
local function change_locales(localechange)
for loc, flist in pairs(localechange) do
for index, name in pairs(flist) do
f = get_faction(atoi36(name))
if f ~= nil and f.locale ~= loc then
print("LOCALECHANGE ", f, f.locale, loc)
f.locale = loc
end
end
end
end
local function dbupdate() local function dbupdate()
update_scores() update_scores()
dbname = config.dbname or 'eressea.db' dbname = config.dbname or 'eressea.db'
@ -141,6 +153,9 @@ function process(rules, orders)
process_orders() process_orders()
callbacks(rules, 'update') callbacks(rules, 'update')
local localechange = { de = { 'ii' } }
change_locales(localechange)
write_files(config.locales) write_files(config.locales)
file = '' .. get_turn() .. '.dat' file = '' .. get_turn() .. '.dat'
@ -167,6 +182,16 @@ function run_turn(rules)
return result return result
end end
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
if file_exists('execute.lock') then
eressea.log.error("Lockfile exists, aborting.")
assert(false)
end
local path = 'scripts' local path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path path = config.install .. '/' .. path
@ -174,6 +199,12 @@ end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
require 'eressea' require 'eressea'
require 'eressea.xmlconf' -- read xml data require 'eressea.xmlconf' -- read xml data
local rules = require('eressea.rules')
local rules = {}
if config.rules then
rules = require('eressea.' .. config.rules)
eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules)
else
eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r')
end
run_turn(rules) run_turn(rules)

View File

@ -3661,7 +3661,7 @@ static void free_fighter(fighter * fig)
} }
static void free_battle(battle * b) void free_battle(battle * b)
{ {
int max_fac_no = 0; int max_fac_no = 0;
@ -4246,7 +4246,6 @@ void do_battle(region * r)
message_all(b, m); message_all(b, m);
msg_release(m); msg_release(m);
free_battle(b); free_battle(b);
free(b);
return; return;
} }
join_allies(b); join_allies(b);
@ -4293,7 +4292,6 @@ void do_battle(region * r)
if (b) { if (b) {
free_battle(b); free_battle(b);
free(b);
} }
} }
@ -4312,5 +4310,6 @@ void battle_free(battle * b) {
} }
free_side(s); free_side(s);
} }
free(b);
} }

View File

@ -263,15 +263,16 @@ extern "C" {
extern void drain_exp(struct unit *u, int d); extern void drain_exp(struct unit *u, int d);
extern void kill_troop(troop dt); extern void kill_troop(troop dt);
extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */ extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */
extern bool is_attacker(const fighter * fig);
extern struct battle *make_battle(struct region * r); bool is_attacker(const fighter * fig);
extern fighter *make_fighter(struct battle *b, struct unit *u, side * s, struct battle *make_battle(struct region * r);
bool attack); void free_battle(struct battle * b);
extern struct side *make_side(struct battle * b, const struct faction * f, struct fighter *make_fighter(struct battle *b, struct unit *u,
const struct group * g, unsigned int flags, struct side * s, bool attack);
const struct faction * stealthfaction); struct side *make_side(struct battle * b, const struct faction * f,
extern int skilldiff(troop at, troop dt, int dist); const struct group * g, unsigned int flags,
const struct faction * stealthfaction);
int skilldiff(troop at, troop dt, int dist);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -53,6 +53,8 @@ static void test_make_fighter(CuTest * tc)
CuAssertIntEquals(tc, 3, af->magic); CuAssertIntEquals(tc, 3, af->magic);
CuAssertIntEquals(tc, 1, af->horses); CuAssertIntEquals(tc, 1, af->horses);
CuAssertIntEquals(tc, 0, af->elvenhorses); CuAssertIntEquals(tc, 0, af->elvenhorses);
free_battle(b);
test_cleanup();
} }
static int add_two(building * b, unit * u) { static int add_two(building * b, unit * u) {
@ -102,6 +104,8 @@ static void test_defenders_get_building_bonus(CuTest * tc)
diff = skilldiff(dt, at, 0); diff = skilldiff(dt, at, 0);
CuAssertIntEquals(tc, 0, diff); CuAssertIntEquals(tc, 0, diff);
free_battle(b);
test_cleanup();
} }
static void test_attackers_get_no_building_bonus(CuTest * tc) static void test_attackers_get_no_building_bonus(CuTest * tc)
@ -130,6 +134,8 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
af = make_fighter(b, au, as, true); af = make_fighter(b, au, as, true);
CuAssertPtrEquals(tc, 0, af->building); CuAssertPtrEquals(tc, 0, af->building);
free_battle(b);
test_cleanup();
} }
static void test_building_bonus_respects_size(CuTest * tc) static void test_building_bonus_respects_size(CuTest * tc)
@ -166,6 +172,8 @@ static void test_building_bonus_respects_size(CuTest * tc)
CuAssertPtrEquals(tc, bld, af->building); CuAssertPtrEquals(tc, bld, af->building);
CuAssertPtrEquals(tc, 0, df->building); CuAssertPtrEquals(tc, 0, df->building);
free_battle(b);
test_cleanup();
} }
CuSuite *get_battle_suite(void) CuSuite *get_battle_suite(void)

View File

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 4 #define VERSION_MINOR 4
#define VERSION_BUILD 693 #define VERSION_BUILD 694

View File

@ -116,6 +116,7 @@ static void test_findrace(CuTest *tc) {
rc = findrace("Zwerg", lang); rc = findrace("Zwerg", lang);
CuAssertPtrNotNull(tc, rc); CuAssertPtrNotNull(tc, rc);
CuAssertStrEquals(tc, "dwarf", rc->_name); CuAssertStrEquals(tc, "dwarf", rc->_name);
test_cleanup();
} }
static void test_items(CuTest * tc) static void test_items(CuTest * tc)

View File

@ -6,6 +6,7 @@
#include <util/parser.h> #include <util/parser.h>
#include <util/language.h> #include <util/language.h>
#include <tests.h>
#include <CuTest.h> #include <CuTest.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -13,7 +14,10 @@
static void test_create_order(CuTest *tc) { static void test_create_order(CuTest *tc) {
char cmd[32]; char cmd[32];
order *ord; order *ord;
struct locale * lang = get_or_create_locale("en"); struct locale * lang;
test_cleanup();
lang = get_or_create_locale("en");
locale_setstring(lang, "keyword::move", "MOVE"); locale_setstring(lang, "keyword::move", "MOVE");
ord = create_order(K_MOVE, lang, "NORTH"); ord = create_order(K_MOVE, lang, "NORTH");
@ -24,12 +28,16 @@ static void test_create_order(CuTest *tc) {
CuAssertIntEquals(tc, K_MOVE, init_order(ord)); CuAssertIntEquals(tc, K_MOVE, init_order(ord));
CuAssertStrEquals(tc, "NORTH", getstrtoken()); CuAssertStrEquals(tc, "NORTH", getstrtoken());
free_order(ord); free_order(ord);
test_cleanup();
} }
static void test_parse_order(CuTest *tc) { static void test_parse_order(CuTest *tc) {
char cmd[32]; char cmd[32];
order *ord; order *ord;
struct locale * lang = get_or_create_locale("en"); struct locale * lang;
test_cleanup();
lang = get_or_create_locale("en");
locale_setstring(lang, "keyword::move", "MOVE"); locale_setstring(lang, "keyword::move", "MOVE");
init_keyword(lang, K_MOVE, "MOVE"); init_keyword(lang, K_MOVE, "MOVE");
@ -41,12 +49,16 @@ static void test_parse_order(CuTest *tc) {
CuAssertIntEquals(tc, K_MOVE, init_order(ord)); CuAssertIntEquals(tc, K_MOVE, init_order(ord));
CuAssertStrEquals(tc, "NORTH", getstrtoken()); CuAssertStrEquals(tc, "NORTH", getstrtoken());
free_order(ord); free_order(ord);
test_cleanup();
} }
static void test_parse_make(CuTest *tc) { static void test_parse_make(CuTest *tc) {
char cmd[32]; char cmd[32];
order *ord; order *ord;
struct locale * lang = get_or_create_locale("en"); struct locale * lang;
test_cleanup();
lang = get_or_create_locale("en");
locale_setstring(lang, keyword(K_MAKE), "MAKE"); locale_setstring(lang, keyword(K_MAKE), "MAKE");
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP"); locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
@ -59,13 +71,16 @@ static void test_parse_make(CuTest *tc) {
CuAssertIntEquals(tc, K_MAKE, init_order(ord)); CuAssertIntEquals(tc, K_MAKE, init_order(ord));
CuAssertStrEquals(tc, "hurrdurr", getstrtoken()); CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
free_order(ord); free_order(ord);
test_cleanup();
} }
static void test_parse_make_temp(CuTest *tc) { static void test_parse_make_temp(CuTest *tc) {
char cmd[32]; char cmd[32];
order *ord; order *ord;
struct locale * lang = get_or_create_locale("en"); struct locale * lang;
test_cleanup();
lang = get_or_create_locale("en");
locale_setstring(lang, keyword(K_MAKE), "MAKE"); locale_setstring(lang, keyword(K_MAKE), "MAKE");
locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP"); locale_setstring(lang, keyword(K_MAKETEMP), "MAKETEMP");
locale_setstring(lang, "TEMP", "TEMP"); locale_setstring(lang, "TEMP", "TEMP");
@ -79,6 +94,7 @@ static void test_parse_make_temp(CuTest *tc) {
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
CuAssertStrEquals(tc, "herp", getstrtoken()); CuAssertStrEquals(tc, "herp", getstrtoken());
free_order(ord); free_order(ord);
test_cleanup();
} }
static void test_parse_maketemp(CuTest *tc) { static void test_parse_maketemp(CuTest *tc) {

View File

@ -12,11 +12,13 @@ static void test_readwrite_data(CuTest * tc)
{ {
const char *filename = "test.dat"; const char *filename = "test.dat";
char path[MAX_PATH]; char path[MAX_PATH];
test_cleanup();
sprintf(path, "%s/%s", datapath(), filename); sprintf(path, "%s/%s", datapath(), filename);
CuAssertIntEquals(tc, 0, writegame(filename)); CuAssertIntEquals(tc, 0, writegame(filename));
CuAssertIntEquals(tc, 0, readgame(filename, 0)); CuAssertIntEquals(tc, 0, readgame(filename, 0));
CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version); CuAssertIntEquals(tc, RELEASE_VERSION, global.data_version);
CuAssertIntEquals(tc, 0, remove(path)); CuAssertIntEquals(tc, 0, remove(path));
test_cleanup();
} }
CuSuite *get_save_suite(void) CuSuite *get_save_suite(void)

View File

@ -61,6 +61,7 @@ static void test_findkeyword(CuTest *tc) {
CuAssertIntEquals(tc, K_STUDY, findkeyword("study")); CuAssertIntEquals(tc, K_STUDY, findkeyword("study"));
CuAssertIntEquals(tc, NOKEYWORD, findkeyword("")); CuAssertIntEquals(tc, NOKEYWORD, findkeyword(""));
CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato")); CuAssertIntEquals(tc, NOKEYWORD, findkeyword("potato"));
test_cleanup();
} }
static void test_get_keyword_default(CuTest *tc) { static void test_get_keyword_default(CuTest *tc) {
@ -70,6 +71,7 @@ static void test_get_keyword_default(CuTest *tc) {
CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang)); CuAssertIntEquals(tc, NOKEYWORD, get_keyword("potato", lang));
CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang)); CuAssertIntEquals(tc, K_MOVE, get_keyword("move", lang));
CuAssertIntEquals(tc, K_STUDY, get_keyword("study", lang)); CuAssertIntEquals(tc, K_STUDY, get_keyword("study", lang));
test_cleanup();
} }
static void test_get_shortest_match(CuTest *tc) { static void test_get_shortest_match(CuTest *tc) {
@ -88,6 +90,7 @@ static void test_get_shortest_match(CuTest *tc) {
CuAssertIntEquals(tc, K_STATUS, get_keyword("COM", lang)); CuAssertIntEquals(tc, K_STATUS, get_keyword("COM", lang));
CuAssertIntEquals(tc, K_STATUS, get_keyword("COMBAT", lang)); CuAssertIntEquals(tc, K_STATUS, get_keyword("COMBAT", lang));
CuAssertIntEquals(tc, K_COMBATSPELL, get_keyword("COMBATS", lang)); CuAssertIntEquals(tc, K_COMBATSPELL, get_keyword("COMBATS", lang));
test_cleanup();
} }
#define SUITE_DISABLE_TEST(suite, test) (void)test #define SUITE_DISABLE_TEST(suite, test) (void)test

View File

@ -33,6 +33,7 @@ static void test_move_to_vortex(CuTest *tc) {
CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r)); CuAssertIntEquals(tc, E_MOVE_NOREGION, movewhere(u, "barf", r1, &r));
CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r)); CuAssertIntEquals(tc, E_MOVE_OK, movewhere(u, "wirbel", r1, &r));
CuAssertPtrEquals(tc, r2, r); CuAssertPtrEquals(tc, r2, r);
test_cleanup();
} }
CuSuite *get_vortex_suite(void) CuSuite *get_vortex_suite(void)