Comparison

tests/test_util_stanza.lua @ 7505:3d950ee0de35

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 14 Jul 2016 13:41:02 +0200
parent 7503:1810f1a4ff05
child 7961:ff556d010225
comparison
equal deleted inserted replaced
7497:22942eda53f8 7505:3d950ee0de35
78 local p = presence(); 78 local p = presence();
79 assert_equal(p.name, "presence"); 79 assert_equal(p.name, "presence");
80 end 80 end
81 81
82 function reply(reply, _M) 82 function reply(reply, _M)
83 -- Test stanza 83 do
84 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" }) 84 -- Test stanza
85 :tag("child1"); 85 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
86 -- Make reply stanza 86 :tag("child1");
87 local r = reply(s); 87 -- Make reply stanza
88 assert_equal(r.name, s.name); 88 local r = reply(s);
89 assert_equal(r.id, s.id); 89 assert_equal(r.name, s.name);
90 assert_equal(r.attr.to, s.attr.from); 90 assert_equal(r.id, s.id);
91 assert_equal(r.attr.from, s.attr.to); 91 assert_equal(r.attr.to, s.attr.from);
92 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); 92 assert_equal(r.attr.from, s.attr.to);
93 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
94 end
93 95
94 -- Test stanza 96 do
95 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) 97 -- Test stanza
96 :tag("child1"); 98 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
97 -- Make reply stanza 99 :tag("child1");
98 local r = reply(s); 100 -- Make reply stanza
99 assert_equal(r.name, s.name); 101 local r = reply(s);
100 assert_equal(r.id, s.id); 102 assert_equal(r.name, s.name);
101 assert_equal(r.attr.to, s.attr.from); 103 assert_equal(r.id, s.id);
102 assert_equal(r.attr.from, s.attr.to); 104 assert_equal(r.attr.to, s.attr.from);
103 assert_equal(r.attr.type, "result"); 105 assert_equal(r.attr.from, s.attr.to);
104 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); 106 assert_equal(r.attr.type, "result");
107 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
108 end
105 109
106 -- Test stanza 110 do
107 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" }) 111 -- Test stanza
108 :tag("child1"); 112 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" })
109 -- Make reply stanza 113 :tag("child1");
110 local r = reply(s); 114 -- Make reply stanza
111 assert_equal(r.name, s.name); 115 local r = reply(s);
112 assert_equal(r.id, s.id); 116 assert_equal(r.name, s.name);
113 assert_equal(r.attr.to, s.attr.from); 117 assert_equal(r.id, s.id);
114 assert_equal(r.attr.from, s.attr.to); 118 assert_equal(r.attr.to, s.attr.from);
115 assert_equal(r.attr.type, "result"); 119 assert_equal(r.attr.from, s.attr.to);
116 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza"); 120 assert_equal(r.attr.type, "result");
121 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
122 end
117 end 123 end
118 124
119 function error_reply(error_reply, _M) 125 function error_reply(error_reply, _M)
120 -- Test stanza 126 do
121 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" }) 127 -- Test stanza
122 :tag("child1"); 128 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
123 -- Make reply stanza 129 :tag("child1");
124 local r = error_reply(s); 130 -- Make reply stanza
125 assert_equal(r.name, s.name); 131 local r = error_reply(s);
126 assert_equal(r.id, s.id); 132 assert_equal(r.name, s.name);
127 assert_equal(r.attr.to, s.attr.from); 133 assert_equal(r.id, s.id);
128 assert_equal(r.attr.from, s.attr.to); 134 assert_equal(r.attr.to, s.attr.from);
129 assert_equal(#r.tags, 1); 135 assert_equal(r.attr.from, s.attr.to);
130 136 assert_equal(#r.tags, 1);
131 -- Test stanza 137 end
132 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) 138
133 :tag("child1"); 139 do
134 -- Make reply stanza 140 -- Test stanza
135 local r = error_reply(s); 141 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
136 assert_equal(r.name, s.name); 142 :tag("child1");
137 assert_equal(r.id, s.id); 143 -- Make reply stanza
138 assert_equal(r.attr.to, s.attr.from); 144 local r = error_reply(s);
139 assert_equal(r.attr.from, s.attr.to); 145 assert_equal(r.name, s.name);
140 assert_equal(r.attr.type, "error"); 146 assert_equal(r.id, s.id);
141 assert_equal(#r.tags, 1); 147 assert_equal(r.attr.to, s.attr.from);
148 assert_equal(r.attr.from, s.attr.to);
149 assert_equal(r.attr.type, "error");
150 assert_equal(#r.tags, 1);
151 end
142 end 152 end