diff options
author | Matthew Wild <mwild1@gmail.com> | 2016-03-09 13:19:38 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2016-03-09 13:19:38 +0000 |
commit | 5ea1c295b302a15b2322fb0b103e0bab32d62643 (patch) | |
tree | 0370db4c0d6aab56f53997277141a014c9590d80 /tests | |
parent | 72212273c0de9674bccc060a9d9c8ca4d286d72a (diff) | |
parent | b1279bc9a50d82e07ec96ed5b021071cd78c8521 (diff) | |
download | prosody-5ea1c295b302a15b2322fb0b103e0bab32d62643.tar.gz prosody-5ea1c295b302a15b2322fb0b103e0bab32d62643.zip |
Merge 0.10->trunk
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_util_stanza.lua | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/test_util_stanza.lua b/tests/test_util_stanza.lua index 20cc8274..e5c96425 100644 --- a/tests/test_util_stanza.lua +++ b/tests/test_util_stanza.lua @@ -25,3 +25,118 @@ function deserialize(deserialize, st) assert_equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes"); assert_table(getmetatable(stanza2), "Deserialized stanza has metatable"); end + +function stanza(stanza) + local s = stanza("foo", { xmlns = "myxmlns", a = "attr-a" }); + assert_equal(s.name, "foo"); + assert_equal(s.attr.xmlns, "myxmlns"); + assert_equal(s.attr.a, "attr-a"); + + local s1 = stanza("s1"); + assert_equal(s1.name, "s1"); + assert_equal(s1.attr.xmlns, nil); + assert_equal(#s1, 0); + assert_equal(#s1.tags, 0); + + s1:tag("child1"); + assert_equal(#s1.tags, 1); + assert_equal(s1.tags[1].name, "child1"); + + s1:tag("grandchild1"):up(); + assert_equal(#s1.tags, 1); + assert_equal(s1.tags[1].name, "child1"); + assert_equal(#s1.tags[1], 1); + assert_equal(s1.tags[1][1].name, "grandchild1"); + + s1:up():tag("child2"); + assert_equal(#s1.tags, 2, tostring(s1)); + assert_equal(s1.tags[1].name, "child1"); + assert_equal(s1.tags[2].name, "child2"); + assert_equal(#s1.tags[1], 1); + assert_equal(s1.tags[1][1].name, "grandchild1"); + + s1:up():text("Hello world"); + assert_equal(#s1.tags, 2); + assert_equal(#s1, 3); + assert_equal(s1.tags[1].name, "child1"); + assert_equal(s1.tags[2].name, "child2"); + assert_equal(#s1.tags[1], 1); + assert_equal(s1.tags[1][1].name, "grandchild1"); +end + +function message(message) + local m = message(); + assert_equal(m.name, "message"); +end + +function iq(iq) + local i = iq(); + assert_equal(i.name, "iq"); +end + +function presence(presence) + local p = presence(); + assert_equal(p.name, "presence"); +end + +function reply(reply, _M) + -- Test stanza + local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" }) + :tag("child1"); + -- Make reply stanza + local r = reply(s); + assert_equal(r.name, s.name); + assert_equal(r.id, s.id); + assert_equal(r.attr.to, s.attr.from); + assert_equal(r.attr.from, s.attr.to); + assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); + + -- Test stanza + local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) + :tag("child1"); + -- Make reply stanza + local r = reply(s); + assert_equal(r.name, s.name); + assert_equal(r.id, s.id); + assert_equal(r.attr.to, s.attr.from); + assert_equal(r.attr.from, s.attr.to); + assert_equal(r.attr.type, "result"); + assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); + + -- Test stanza + local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" }) + :tag("child1"); + -- Make reply stanza + local r = reply(s); + assert_equal(r.name, s.name); + assert_equal(r.id, s.id); + assert_equal(r.attr.to, s.attr.from); + assert_equal(r.attr.from, s.attr.to); + assert_equal(r.attr.type, "result"); + assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); +end + +function error_reply(error_reply, _M) + -- Test stanza + local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" }) + :tag("child1"); + -- Make reply stanza + local r = error_reply(s); + assert_equal(r.name, s.name); + assert_equal(r.id, s.id); + assert_equal(r.attr.to, s.attr.from); + assert_equal(r.attr.from, s.attr.to); + assert_equal(#r.tags, 1); + + -- Test stanza + local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) + :tag("child1"); + -- Make reply stanza + local r = error_reply(s); + assert_equal(r.name, s.name); + assert_equal(r.id, s.id); + assert_equal(r.attr.to, s.attr.from); + assert_equal(r.attr.from, s.attr.to); + assert_equal(r.attr.type, "error"); + assert_equal(#r.tags, 1); +end |