parent
9c44faa811
commit
4b5fcf3d99
@ -0,0 +1,108 @@
|
|||||||
|
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
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
require("lunit")
|
||||||
|
|
||||||
|
local network = require("network")
|
||||||
|
local serialization = require("serialization")
|
||||||
|
local BaseControl = require("bc")
|
||||||
|
|
||||||
|
module("iters", package.seeall, lunit.testcase)
|
||||||
|
|
||||||
|
function test_multinode_iters()
|
||||||
|
local bc1 = BaseControl:new(
|
||||||
|
BaseControl.Network(121233)
|
||||||
|
)
|
||||||
|
bc1:register("miter1", 123)
|
||||||
|
bc1:register("miter2v", function() end)
|
||||||
|
bc1:finalize()
|
||||||
|
|
||||||
|
local bc2 = BaseControl:new(
|
||||||
|
BaseControl.Network(121233)
|
||||||
|
)
|
||||||
|
bc2:register("miter3", 321)
|
||||||
|
bc2:register("miter4v", function() end)
|
||||||
|
bc2:finalize()
|
||||||
|
|
||||||
|
local nouns = bc2:nouns()
|
||||||
|
table.sort(nouns)
|
||||||
|
assert_equal(2, #nouns, "noun-list incorrect")
|
||||||
|
assert_equal("miter1", nouns[1], "noun-list incorrect")
|
||||||
|
assert_equal("miter3", nouns[2], "noun-list incorrect")
|
||||||
|
|
||||||
|
local verbs = bc2:verbs()
|
||||||
|
table.sort(verbs)
|
||||||
|
assert_equal(2, #verbs, "verb-list incorrect")
|
||||||
|
assert_equal("miter2v", verbs[1], "verb-list incorrect")
|
||||||
|
assert_equal("miter4v", verbs[2], "verb-list incorrect")
|
||||||
|
end
|
||||||
Loading…
Reference in new issue