Eressea server:

- passes tests
- crashes in report writing (memory corruption)

added more tests.
This commit is contained in:
Enno Rehling 2010-02-25 08:23:26 +00:00
parent c1f4b2e6ce
commit 6391812ee5
18 changed files with 80 additions and 468 deletions

View File

@ -1083,6 +1083,10 @@ parse_inifile(lua_State* L, dictionary * d, const char * section)
lua_rawset(L,-3);
}
}
/* special case */
lua_pushstring(L, "basepath");
lua_pushstring(L, basepath());
lua_rawset(L,-3);
}
int

View File

@ -145,10 +145,6 @@ void
destroy_curse(curse * c)
{
cunhash(c);
if (c->data.v && c->type && c->type->typ == CURSETYP_UNIT) {
free(c->data.v);
}
free(c);
}

View File

@ -0,0 +1,28 @@
#include <platform.h>
#include <external/cutest/CuTest.h>
#include <kernel/types.h>
#include "curse.h"
#include <util/attrib.h>
static void test_curse(CuTest * tc) {
attrib * attrs = NULL;
curse * c, * result;
int cid;
curse_type ct_dummy = { "dummy", CURSETYP_NORM, 0, M_SUMEFFECT, NULL };
c = create_curse(NULL, &attrs, &ct_dummy, 1.0, 1, 1, 1);
cid = c->no;
result = findcurse(cid);
CuAssertPtrEquals(tc, c, result);
destroy_curse(c);
result = findcurse(cid);
CuAssertPtrEquals(tc, NULL, result);
}
CuSuite* get_curse_suite(void)
{
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_curse);
return suite;
}

View File

@ -310,7 +310,7 @@ enum {
enum {
RC_DWARF, /* 0 - Zwerg */
RC_ELF,
RC_GOBLIN,
RC_GOBLIN = 3,
RC_HUMAN,
RC_TROLL,

View File

@ -600,7 +600,7 @@ race_compat(void)
{
/* required for old_race, do not change order! */
const char * oldracenames[MAXRACES] = {
"dwarf", "elf", "goblin", "human", "troll", "demon", "insect",
"dwarf", "elf", NULL, "goblin", "human", "troll", "demon", "insect",
"halfling", "cat", "aquarian", "orc", "snotling", "undead", "illusion",
"youngdragon", "dragon", "wyrm", "ent", "catdragon", "dracoid",
"special", "spell", "irongolem", "stonegolem", "shadowdemon",

View File

@ -1,13 +1,15 @@
#include <external/cutest/CuTest.h>
#include <stdio.h>
CuSuite* get_base36_suite();
CuSuite* get_base36_suite(void);
CuSuite* get_curse_suite(void);
void RunAllTests(void) {
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
CuSuiteAddSuite(suite, get_base36_suite());
CuSuiteAddSuite(suite, get_curse_suite());
CuSuiteRun(suite);
CuSuiteSummary(suite, output);

View File

@ -1,6 +1,7 @@
#include <platform.h>
#include <external/cutest/CuTest.h>
#include "base36.c"
#include "base36.h"
static void test_atoi36(CuTest * tc) {
CuAssertIntEquals(tc, 0, atoi36("0"));
@ -20,7 +21,7 @@ static void test_itoa36(CuTest * tc) {
CuAssertStrEquals(tc, itoa36(666), "ii");
}
CuSuite* get_base36_suite()
CuSuite* get_base36_suite(void)
{
CuSuite* suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_itoa36);

View File

@ -22,6 +22,7 @@
<xi:include href="eressea:///core/common/buildings.xml"/>
<xi:include href="eressea:///core/equipment.xml"/>
<xi:include href="eressea:///core/terrains.xml"/>
<xi:include href="eressea/terrains.xml"/>
<xi:include href="directions.xml"/>
<xi:include href="artrewards.xml"/>
<xi:include href="buildings.xml"/>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<terrains>
<!-- used by the experimental dungeon -->
<terrain name="hell" fly="no" sail="no" size="0" land="no"/>
<!-- used for the museum only -->
<terrain name="hall1" fly="no" size="0" />
<terrain name="corridor1" fly="no" size="0" />
<terrain name="wall1" sail="no" walk="no" fly="no" forbidden="yes" size="0" />
</terrains>

View File

@ -81,8 +81,4 @@
<resource name="stone" chance="0.5" level="1" base="100" div="100" />
<resource name="laen" chance="0.075" level="1" base="4" div="100" />
</terrain>
<!-- used for the museum only -->
<terrain name="hall1" fly="no" size="0" />
<terrain name="corridor1" fly="no" size="0" />
<terrain name="wall1" sail="no" walk="no" fly="no" forbidden="yes" size="0" />
</terrains>

View File

@ -12,12 +12,12 @@ end
function dbupdate()
update_scores()
edb = db.open(basepath.."/eressea.db")
edb = db.open(config.basepath.."/eressea.db")
if edb~=nil then
edb:update_factions()
edb:update_scores()
else
print("could no open "..basepath.."/eressea.db")
print("could no open "..config.basepath.."/eressea.db")
end
end
@ -47,7 +47,7 @@ function write_emails(locales)
local locale
local file
for key, locale in pairs(locales) do
files[locale] = io.open(basepath .. "/emails." .. locale, "w")
files[locale] = io.open(config.basepath .. "/emails." .. locale, "w")
end
local faction
@ -66,7 +66,7 @@ function write_addresses()
local file
local faction
file = io.open(basepath .. "/adressen", "w")
file = io.open(config.basepath .. "/adressen", "w")
for faction in factions() do
-- print(faction.id .. " - " .. faction.locale)
file:write(tostring(faction) .. ":" .. faction.email .. ":" .. faction.info .. "\n")
@ -79,7 +79,7 @@ function write_aliases()
local file
local faction
file = io.open(basepath .. "/aliases", "w")
file = io.open(config.basepath .. "/aliases", "w")
for faction in factions() do
local unit
if faction.email ~= "" then

View File

@ -123,7 +123,7 @@ function fill(pl, w, h)
end
function seed()
local input = io.open(basepath .. "/parteien.txt")
local input = io.open(config.basepath .. "/parteien.txt")
for f in factions() do
if f.race=="vampunicorn" then
local str = input:read("*line")

View File

@ -50,7 +50,7 @@ function process(orders)
change_locales(localechange)
-- use newfactions file to place out new players
-- autoseed(basepath .. "/newfactions", false)
-- autoseed(config.basepath .. "/newfactions", false)
write_files(config.locales)

View File

@ -46,7 +46,7 @@ function process(orders)
change_locales()
-- use newfactions file to place out new players
autoseed(basepath .. "/newfactions", false)
autoseed(config.basepath .. "/newfactions", false)
write_files(locales)

View File

@ -33,7 +33,7 @@ function run_turn()
set_turn(turn)
end
orderfile = orderfile or basepath .. '/orders.' .. turn
orderfile = orderfile or config.basepath .. '/orders.' .. turn
print("executing turn " .. get_turn() .. " with " .. orderfile)
local result = process(orderfile)
if result==0 then

View File

@ -1,446 +0,0 @@
function mkunit(f, r, num)
u = unit.create(f, r)
u.number = num
u:add_item("money", num*10)
u:clear_orders()
return u
end
function test_movement()
west = direction("west")
east = direction("east")
-- im westen ohne strassen
ocean = region.create(-3, 0, "ocean")
w2 = region.create(-2, 0, "plain")
w1 = region.create(-1, 0, "plain")
-- im osten mit strassen
r0 = region.create(0, 0, "plain")
r1 = region.create(1, 0, "desert")
r2 = region.create(2, 0, "glacier")
r3 = region.create(3, 0, "plain")
r4 = region.create(4, 0, "glacier")
r0:add_direction(r4, "Wirbel", "Nimm die Abkürzung, Luke")
r0:set_road(east, 1.0)
r1:set_road(west, 1.0)
r1:set_road(east, 1.0)
r2:set_road(west, 1.0)
r2:set_road(east, 1.0)
r3:set_road(west, 1.0)
r3:set_road(east, 1.0)
r4:set_road(west, 1.0)
orcs = faction.create("orcs@eressea.de", "orc", "de")
orcs.age = 20
aqua = faction.create("aqua@eressea.de", "aquarian", "de")
aqua.age = 20
bugs = faction.create("bugz@eressea.de", "insect", "de")
bugs.age = 20
orc = mkunit(orcs, r0, 10)
orc:add_item("horse", orc.number*3)
orc:set_skill("riding", 10)
-- schiffe zum abtreiben:
ships = {}
for i = 1, 100 do
ships[i] = add_ship(ocean, "boat")
end
astra = mkunit(orcs, r0, 1)
astra:add_order("NACH Wirbel")
astra:add_order("NUMMER EINHEIT astr")
foot = mkunit(orcs, r0, 1)
foot:add_order("ROUTE W W")
foot:add_order("NUMMER EINHEIT foot")
watch = mkunit(orcs, w2, 1)
ship = add_ship(ocean, "boat")
cptn = mkunit(aqua, ocean, 1)
cptn.ship = ship
cptn:add_order("NACH O")
cptn:add_order("NUMMER EINHEIT cptn")
cptn:add_order("BENENNE EINHEIT Landungsleiter")
cptn:add_order("BENENNE PARTEI Meermenschen")
swim = mkunit(aqua, ocean, 1)
swim.ship = ship
swim:add_order("NACH O")
swim:add_order("NUMMER EINHEIT swim")
swim:add_order("BENENNE EINHEIT Landungstruppe")
-- ein schiff im landesinneren
ship = add_ship(r0, "boat")
sail = mkunit(aqua, r0, 1)
sail.ship = ship
crew = mkunit(aqua, r0, 1)
crew.ship = ship
bug = mkunit(bugs, r0, 1)
crew:add_order("NACH O")
crew:add_order("NUMMER EINHEIT crew")
crew:add_order("BENENNE EINHEIT Aussteiger")
crew:add_order("NUMMER PARTEI aqua")
sail:add_order("NACH O")
sail:add_order("NUMMER EINHEIT saiL")
sail:add_order("BENENNE EINHEIT Aussteiger")
orc:add_order("NUMMER PARTEI orcs")
orc:add_order("NUMMER EINHEIT orc")
orc:add_order("BENENNE EINHEIT Orks")
orc:add_order("ROUTE O O O P P O W W W W")
orc:add_order("GIB 0 ALLES Steine")
orc:add_order("GIB 0 ALLES Holz")
orc:add_order("TRANSPORTIEREN " .. itoa36(bug.id))
bug:add_order("NUMMER PARTEI bugs")
bug:add_order("NUMMER EINHEIT bug")
bug:add_order("BENENNE EINHEIT Käfer")
bug:add_order("GIB 0 ALLES Steine")
bug:add_order("GIB 0 ALLES Holz")
bug:add_order("FAHREN " .. itoa36(orc.id))
u = unit.create(orcs, r0)
u.number = 1
u:add_item("horse", u.number*3)
u:add_item("money", u.number*10)
u:set_skill("riding", 10)
u:set_skill("stealth", 2)
u:clear_orders()
u:add_order("FOLGEN EINHEIT " .. itoa36(bug.id))
u:add_order("NACH W")
u:add_order("NUMMER EINHEIT foLg")
u:add_order("BENENNE EINHEIT Verfolger")
u2 = unit.create(orcs, r0)
u2.number = 1
u2:add_item("horse", u2.number*3)
u2:add_item("money", u.number*10)
u2:set_skill("riding", 10)
u2:set_skill("stealth", 2)
u2:clear_orders()
u2:add_order("FOLGEN EINHEIT nix")
u2:add_order("NUMMER EINHEIT Last")
u2:add_order("BENENNE EINHEIT Verfolger-Verfolger")
end
function test_sail()
r0 = region.create(0, 0, "plain")
orcs = faction.create("enno@eressea.de", "orc", "de")
orcs.age = 20
orc = unit.create(orcs, r0)
orc.number = 1
orc:add_item("speedsail", orc.number)
orc:clear_orders()
orc:add_order("NUMMER PARTEI orcs")
orc:add_order("NUMMER EINHEIT orc")
orc:add_order("BENENNE EINHEIT Orks")
orc:add_order("ZEIGEN \"Sonnensegel\"")
end
function test_handler()
local function msg_handler(u, evt)
str = evt:get_string(0)
u2 = evt:get_unit(1)
print(u)
print(u2)
print(str)
message_unit(u, u2, "thanks unit, i got your message: " .. str)
message_faction(u, u2.faction, "thanks faction, i got your message: " .. str)
message_region(u, "thanks region, i got your message: " .. str)
end
plain = region.create(0, 0, "plain")
skill = 8
f = faction.create("enno@eressea.de", "orc", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI test")
u:add_handler("message", msg_handler)
msg = "BOTSCHAFT EINHEIT " .. itoa36(u.id) .. " Du~Elf~stinken"
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 1
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("NUMMER PARTEI eviL")
u:add_order(msg)
end
function test_combat()
plain = region.create(0, 0, "plain")
skill = 8
f = faction.create("enno@eressea.de", "orc", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 100
u:add_item("money", u.number*100)
u:add_item("sword", u.number)
u:set_skill("melee", skill)
u:clear_orders()
u:add_order("NUMMER PARTEI test")
u:add_order("KÄMPFE")
u:add_order("BEFÖRDERUNG")
attack = "ATTACKIERE " .. itoa36(u.id)
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 100
u:add_item("money", u.number*100)
u:add_item("sword", u.number)
u:set_skill("melee", skill+2)
u:clear_orders()
u:add_order("NUMMER PARTEI eviL")
u:add_order("KAEMPFE")
u:add_order(attack)
end
function test_rewards()
-- this script tests manufacturing and fighting.
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 10
u:add_item("money", u.number*100)
u:add_item("greatbow", u.number)
u:set_skill("bow", skill)
u:clear_orders()
u:add_order("KAEMPFE")
attack = "ATTACKIERE " .. itoa36(u.id)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
u:set_skill("weaponsmithing", 7)
u:clear_orders()
u:add_order("KAEMPFE NICHT")
u:add_order("MACHEN Elfenbogen")
u:add_order("NUMMER PARTEI test")
f = faction.create("enno@eressea.de", "elf", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("greatbow", u.number)
u:set_skill("bow", skill)
u:clear_orders()
u:add_order("KAEMPFE HINTEN")
u:add_order(attack)
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
u:set_skill("weaponsmithing", 7)
u:clear_orders()
u:add_order("KAEMPFE NICHT")
u:add_order("MACHEN Elfenbogen")
u:add_order("NUMMER PARTEI eviL")
u = unit.create(f, plain)
u.number = 7
u:add_item("money", u.number*100)
u:add_item("mallorn", u.number*10)
u:set_skill("weaponsmithing", 7)
u:clear_orders()
u:add_order("KAEMPFE NICHT")
items = { "hornofdancing", "trappedairelemental",
"aurapotion50", "bagpipeoffear",
"instantartacademy", "instantartsculpture" }
local index
local item
for index, item in pairs(items) do
u:add_item(item, 1)
u:add_order('@BENUTZEN "' .. get_string("de", item) .. '"')
end
u:add_order("NUMMER PARTEI eviL")
end
function test_give()
plain = region.create(0, 0, "plain")
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 10
u:add_item("money", u.number*100)
u:clear_orders()
u:add_order("MACHE TEMP eins")
u:add_order("REKRUTIERE 1")
u:add_order("ENDE")
u:add_order("GIB TEMP eins ALLES silber")
u:add_order("NUMMER PARTEI test")
end
function test_write()
read_game("24")
read_orders("befehle")
end
function move_north(u)
for order in u.orders do
print(order)
end
u:clear_orders()
u:add_order("NACH NORDEN")
end
function test_monsters()
-- magrathea = get_region(-67, -5)
local magrathea = get_region(0, 0)
if magrathea ~= nil then
if pcall(dofile, scriptpath .. "/ponnuki.lua") then
init_ponnuki(magrathea)
else
print("could not open ponnuki")
end
end
set_race_brain("braineater", move_north)
plan_monsters()
end
function test_parser()
-- this script tests the changes to quotes
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")
f.age = 20
u = unit.create(f, plain)
u.number = 10
u:clear_orders()
u:add_order("Nummer Partei test")
u:add_order("BENENNE PARTEI \"Diese Partei heisst \\\"Enno's Schergen\\\".\"")
u:add_order("BENENNE EINHEIT \"Mein Name ist \\\"Enno\\\".\"")
end
function test_fail()
plain = region.create(0, 0, "plain")
skill = 5
f = faction.create("enno@eressea.de", "human", "de")
print(f)
end
function run_scripts()
scripts = {
"xmas2004.lua"
}
local index
local name
for index, name in pairs(scripts) do
local script = scriptpath .. "/" .. name
print("- loading " .. script)
if pcall(dofile, script)==0 then
print("Could not load " .. script)
end
end
end
function test_moving()
test_movement()
run_scripts()
process_orders()
write_reports()
if swim.region==ocean then
print "ERROR: Meermenschen können nicht anschwimmen"
end
if sail.region~=r0 then
print "ERROR: Kapitän kann Schiff mit NACH ohne VERLASSE verlassen"
end
if crew.region==r0 then
print "ERROR: Einheiten kann Schiff nicht mit NACH ohne VERLASSE verlassen"
end
drift = false
for i = 1, 100 do
if ships[i].region ~= ocean then
drift = true
break
end
end
if not drift then
print "ERROR: Unbemannte Schiffe treiben nicht ab"
end
if foot.region ~= w1 then
print "ERROR: Fusseinheit hat ihr NACH nicht korrekt ausgeführt"
end
if astra.region ~= r4 then
print "ERROR: Astraleinheit konnte Wirbel nicht benutzen"
end
end
-- test_movement()
-- test_fail()
-- test_handler()
-- test_parser()
-- test_monsters()
-- test_combat()
-- test_rewards()
-- test_give()
-- test_write()
-- test_sail()
-- write_game("../testg.txt")
-- read_game("../testg.txt")
if 0==1 then
run_scripts()
process_orders()
write_reports()
end
-- test_moving()
if 0==1 then
read_game("530")
-- read_orders("../game/orders.530")
plan_monsters()
process_orders()
write_game("531")
else
read_game("531")
plan_monsters()
process_orders()
write_game("532")
end

View File

@ -567,3 +567,7 @@ function test_building_other()
assert_not_equal(10, b.size)
end
function test_config()
assert_not_equal(nil, config.basepath)
assert_not_equal(nil, config.locales)
end

View File

@ -101,3 +101,19 @@ function test_levitate()
process_orders()
assert_equal(0, u.ship.flags)
end
function test_terrains()
local terrains = { "hell", "wall1", "corridor1" }
for k,v in ipairs(terrains) do
local r = region.create(k, k, v)
assert_not_equal(nil, r)
end
end
function test_races()
local races = { "wolf", "orc", "human", "demon" }
for k,v in ipairs(races) do
local f = faction.create("noreply@eressea.de", "human", "de")
assert_not_equal(nil, f)
end
end