server/scripts/tests/storage.lua
Enno Rehling 4c67e0603b remove attribs from rtype (it's only in rtype->construction that we use it?)
test to verify that mine bonus for iron works as advertised.
change the oder of arguments for faction.create (race is the only thing not optional).
2017-03-17 22:46:10 +01:00

36 lines
991 B
Lua

require "lunit"
module("tests.storage", package.seeall, lunit.testcase)
function setup()
eressea.free_game()
end
function test_store_unit()
local r = region.create(0, 0, "plain")
local f = faction.create("human", "noreply15@eressea.de", "de")
local u = unit.create(f, r, 1)
local fid = f.id
u:add_item("money", u.number * 100)
local filename = "test.dat"
store = storage.create(filename, "wb")
assert_not_equal(store, nil)
store:write_unit(u)
store:close()
eressea.free_game()
-- recreate world:
r = region.create(0, 0, "plain")
f = faction.create("human", "noreply16@eressea.de", "de")
f.id = fid
store = storage.create(filename, "rb")
assert_not_nil(store)
u = store:read_unit()
assert_not_nil(u)
assert_equal(f, u.faction)
assert_equal(nil, u.region)
store:close()
os.remove(filename)
assert_not_nil(u)
assert_equal(u:get_item("money"), u.number * 100)
os.remove(filename)
end