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.
78 lines
2.1 KiB
78 lines
2.1 KiB
require("lunit")
|
|
|
|
local network = require("network")
|
|
local serialization = require("serialization")
|
|
local BaseControl = require("bc")
|
|
|
|
module("network", package.seeall, lunit.testcase)
|
|
|
|
function test_multinode()
|
|
local bc1 = BaseControl:finalize()
|
|
local bc2 = BaseControl:new()
|
|
bc2:register("multinode1", 123)
|
|
bc2:register("multinode2v", function() end)
|
|
bc2:finalize()
|
|
local bc3 = BaseControl:finalize()
|
|
|
|
assert_true(bc1:has_noun("multinode1"), "d1: remote noun missing")
|
|
assert_true(bc1:has_verb("multinode2v"), "d1: remote verb missing")
|
|
assert_true(bc3:has_noun("multinode1"), "d2: remote noun missing")
|
|
assert_true(bc3:has_verb("multinode2v"), "d2: remote verb missing")
|
|
end
|
|
|
|
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
|
|
|
|
function test_get_network()
|
|
local bc1 = BaseControl:new()
|
|
bc1:register("getnw1", 123)
|
|
bc1:finalize()
|
|
|
|
local bc2 = BaseControl:new()
|
|
|
|
assert_equal(123, bc2:get("getnw1"), "wrong value")
|
|
assert_nil(bc2:get("getnw2"), "found non-exisiting")
|
|
end
|
|
|
|
function test_call_network()
|
|
local bc1 = BaseControl:new()
|
|
local tmp, n = 0, 0
|
|
bc1:register("callnw1", function(param, p2)
|
|
assert_equal(p2, 1234)
|
|
tmp = param
|
|
n = n + 1
|
|
end)
|
|
bc1:finalize()
|
|
|
|
local bc2 = BaseControl:new()
|
|
|
|
bc2:call("callnw1", 4321, 1234)
|
|
assert_equal(4321, tmp, "call incomplete")
|
|
assert_equal(1, n, "call not correct")
|
|
end
|