2011-02-19 15:13:24 +01:00
|
|
|
require "lunit"
|
|
|
|
|
|
|
|
module("tests.bson", package.seeall, lunit.testcase)
|
|
|
|
|
|
|
|
function setup()
|
|
|
|
free_game()
|
|
|
|
end
|
|
|
|
|
|
|
|
function test_bson_create()
|
|
|
|
local a = attrib.create("global", 12)
|
|
|
|
assert_not_equal(nil, a)
|
|
|
|
for a in attrib.get("global") do
|
|
|
|
assert_equal(a.data, 12)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-19 15:15:15 +01:00
|
|
|
function test_illegal_arg()
|
|
|
|
local a = attrib.create(nil, 42)
|
|
|
|
assert_equal(nil, a)
|
|
|
|
a = attrib.create("fred", 42)
|
|
|
|
assert_equal(nil, a)
|
|
|
|
end
|
|
|
|
|
2011-02-19 15:13:24 +01:00
|
|
|
function test_bson_readwrite()
|
2011-02-27 07:57:42 +01:00
|
|
|
local i, r = region.create(0, 0, "mountain")
|
2011-02-19 15:13:24 +01:00
|
|
|
attrib.create(r, 42)
|
2011-02-27 07:57:42 +01:00
|
|
|
i = write_game("test_read_write.dat")
|
|
|
|
assert_equal(0, i)
|
2011-02-19 15:13:24 +01:00
|
|
|
free_game()
|
|
|
|
r = get_region(0, 0)
|
|
|
|
assert_equal(nil, r)
|
2011-02-27 07:57:42 +01:00
|
|
|
i = read_game("test_read_write.dat")
|
|
|
|
assert_equal(0, i)
|
2011-02-19 15:13:24 +01:00
|
|
|
r = get_region(0, 0)
|
|
|
|
assert_not_equal(nil, r)
|
|
|
|
for a in attrib.get(r) do
|
|
|
|
assert_equal(a.data, 42)
|
|
|
|
end
|
|
|
|
end
|