parent
d6aa1637f1
commit
8fb07e22cc
@ -0,0 +1,68 @@
|
||||
require("lunit")
|
||||
|
||||
local network = require("network")
|
||||
local serialization = require("serialization")
|
||||
local BaseControl = require("bc")
|
||||
|
||||
module("cleanup", package.seeall, lunit.testcase)
|
||||
|
||||
function test_clean_simple()
|
||||
local bc = BaseControl:new()
|
||||
bc:close()
|
||||
|
||||
local bc = BaseControl:finalize()
|
||||
bc:close()
|
||||
|
||||
assert_error(function()
|
||||
bc:nouns()
|
||||
end)
|
||||
end
|
||||
|
||||
function test_clean_network()
|
||||
local bc1 = BaseControl:new()
|
||||
local addr1 = network.get_scene()
|
||||
bc1:register("cln1", 123)
|
||||
bc1:register("cln2v", function() end)
|
||||
bc1:finalize()
|
||||
|
||||
local bc2 = BaseControl:new()
|
||||
local addr2 = network.get_scene()
|
||||
|
||||
assert_true(bc2:has_noun("cln1"), "init failed")
|
||||
assert_true(bc2:has_verb("cln2v"), "init failed")
|
||||
|
||||
network.set_scene(addr1)
|
||||
bc1:close()
|
||||
|
||||
network.set_scene(addr2)
|
||||
assert_false(bc2:has_noun("cln1"), "close failed")
|
||||
assert_false(bc2:has_verb("cln2v"), "close failed")
|
||||
end
|
||||
|
||||
function test_clean_network2()
|
||||
local bc1 = BaseControl:new()
|
||||
local addr1 = network.get_scene()
|
||||
local n = 0
|
||||
bc1:register("cln3", 1231)
|
||||
bc1:register("cln4v", function()
|
||||
n = n + 1
|
||||
end)
|
||||
bc1:finalize()
|
||||
|
||||
local bc2 = BaseControl:new()
|
||||
local addr2 = network.get_scene()
|
||||
|
||||
assert_equal(0, n, "verb called too much/little")
|
||||
assert_true(bc2:call("cln4v"), "verb not called")
|
||||
assert_equal(1, n, "verb called too much/little")
|
||||
assert_equal(1231, bc2:get("cln3"), "noun not retrieved correctly")
|
||||
|
||||
network.set_scene(addr1)
|
||||
bc1:close()
|
||||
|
||||
assert_false(bc2:call("cln4v"), "verb called")
|
||||
assert_equal(1, n, "verb called too much/little")
|
||||
assert_error_match("unknown", function()
|
||||
bc2:get("cln3")
|
||||
end)
|
||||
end
|
||||
Loading…
Reference in new issue