You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.4 KiB
109 lines
2.4 KiB
require("lunit")
|
|
|
|
local network = require("network")
|
|
local serialization = require("serialization")
|
|
local BaseControl = require("bc")
|
|
|
|
module("dirty", package.seeall, lunit.testcase)
|
|
|
|
function test_get_network_robust()
|
|
local bc1 = BaseControl:new()
|
|
bc1:register("getrob1", 123)
|
|
bc1:finalize()
|
|
|
|
local bc2 = BaseControl:new()
|
|
local addr2 = network.get_scene()
|
|
|
|
network.inject(
|
|
addr2,
|
|
"A-GETROB-1",
|
|
BaseControl.Network.default_port,
|
|
serialization.serialize{
|
|
ty=BaseControl.Message.NounResponse,
|
|
noun="getrob2",
|
|
value=321,
|
|
}
|
|
)
|
|
|
|
assert_equal(123, bc2:get("getrob1"), "wrong value")
|
|
assert_nil(bc2:get("getrob2"), "found non-exisiting")
|
|
end
|
|
|
|
function test_call_sync_network_robust()
|
|
local bc1 = BaseControl:new()
|
|
local addr1 = network.get_scene()
|
|
local n = 0
|
|
bc1:register("syncr1", function(p1, p2)
|
|
assert_equal(p2, 12)
|
|
n = n + 1
|
|
return p1 + 10, "hello"
|
|
end)
|
|
bc1:finalize()
|
|
|
|
local bc2 = BaseControl:new()
|
|
local addr2 = network.get_scene()
|
|
|
|
assert_nil(bc2:call("syncr1", 20, 12), "call not nil")
|
|
|
|
network.inject(
|
|
addr2,
|
|
addr1,
|
|
BaseControl.Network.default_port,
|
|
serialization.serialize{
|
|
ty=BaseControl.Message.VerbResponse,
|
|
verb="syncr2",
|
|
ret={1, 2, 3},
|
|
}
|
|
)
|
|
|
|
local ret, val = bc2:call_sync("syncr1", 30, 12)
|
|
assert_equal(40, ret, "local sync not correct")
|
|
assert_equal("hello", val, "local sync not multiple")
|
|
assert_equal(2, n, "wrong invokation number")
|
|
end
|
|
|
|
function test_finalize_robust()
|
|
local bc1 = BaseControl:new()
|
|
bc1:register("finaln1", 123)
|
|
bc1:finalize()
|
|
|
|
local bc2 = BaseControl:new()
|
|
local addr2 = network.get_scene()
|
|
|
|
network.inject(
|
|
addr2,
|
|
"A-FINALIZE-1",
|
|
BaseControl.Network.default_port,
|
|
serialization.serialize({
|
|
ty=BaseControl.Message.Register,
|
|
nouns={"finaln2"},
|
|
})
|
|
)
|
|
|
|
network.inject(
|
|
addr2,
|
|
"A-FINALIZE-1",
|
|
BaseControl.Network.default_port,
|
|
serialization.serialize({
|
|
ty=BaseControl.Message.VerbRequest,
|
|
verb="finaln2v",
|
|
param={1, 2},
|
|
})
|
|
)
|
|
network.inject(
|
|
addr2,
|
|
"A-FINALIZE-2",
|
|
BaseControl.Network.default_port,
|
|
serialization.serialize({
|
|
ty=BaseControl.Message.Register,
|
|
nouns={"finaln3"},
|
|
})
|
|
)
|
|
|
|
bc2:finalize{"finaln1", "finaln2", "finaln3"}
|
|
|
|
assert_true(bc2:has_noun("finaln1"), "noun missing")
|
|
assert_true(bc2:has_noun("finaln2"), "noun missing")
|
|
assert_true(bc2:has_noun("finaln3"), "noun missing")
|
|
end
|