Merge 0.9->0.10
[prosody.git] / tests / test_util_stanza.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9
10 function preserialize(preserialize, st)
11         local stanza = st.stanza("message", { a = "a" });
12         local stanza2 = preserialize(stanza);
13         assert_is(stanza2 and stanza.name, "preserialize returns a stanza");
14         assert_is_not(stanza2.tags, "Preserialized stanza has no tag list");
15         assert_is_not(stanza2.last_add, "Preserialized stanza has no last_add marker");
16         assert_is_not(getmetatable(stanza2), "Preserialized stanza has no metatable");
17 end
18
19 function deserialize(deserialize, st)
20         local stanza = st.stanza("message", { a = "a" });
21
22         local stanza2 = deserialize(st.preserialize(stanza));
23         assert_is(stanza2 and stanza.name, "deserialize returns a stanza");
24         assert_table(stanza2.attr, "Deserialized stanza has attributes");
25         assert_equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes");
26         assert_table(getmetatable(stanza2), "Deserialized stanza has metatable");
27 end