Software /
code /
prosody
Comparison
tests/test_core_stanza_router.lua @ 302:8aedb3766ec7
You can never have too many tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 15 Nov 2008 23:14:32 +0000 |
parent | 273:b4c6b124c06f |
child | 519:cccd610a0ef9 |
comparison
equal
deleted
inserted
replaced
301:fcb7e63630ae | 302:8aedb3766ec7 |
---|---|
1 | 1 |
2 function core_process_stanza(core_process_stanza) | 2 function core_process_stanza(core_process_stanza) |
3 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" } | 3 local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" } |
4 local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin" } | |
4 local local_host_session = { host = "localhost", type = "local" } | 5 local local_host_session = { host = "localhost", type = "local" } |
5 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" } | 6 local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" } |
6 local hosts = { | 7 local hosts = { |
7 ["localhost"] = local_host_session; | 8 ["localhost"] = local_host_session; |
8 } | 9 } |
121 setfenv(core_process_stanza, env); | 122 setfenv(core_process_stanza, env); |
122 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value"); | 123 assert_equal(core_process_stanza(local_user_session, msg), nil, "core_process_stanza returned incorrect value"); |
123 assert_equal(target_routed, true, "stanza was not routed successfully"); | 124 assert_equal(target_routed, true, "stanza was not routed successfully"); |
124 end | 125 end |
125 | 126 |
127 local function test_iq_error_to_local_user() | |
128 local env = testlib_new_env(); | |
129 local msg = stanza.stanza("iq", { to = "user@localhost/resource", from = "user@remotehost", type = "error" }):tag("error", { type = 'cancel' }):tag("item-not-found", { xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' }); | |
130 | |
131 local target_routed; | |
132 | |
133 function env.core_route_stanza(p_origin, p_stanza) | |
134 assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct"); | |
135 assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); | |
136 target_routed = true; | |
137 end | |
138 | |
139 function env.core_handle_stanza(p_origin, p_stanza) | |
140 | |
141 end | |
142 | |
143 env.hosts = hosts; | |
144 setfenv(core_process_stanza, env); | |
145 assert_equal(core_process_stanza(s2sin_session, msg), nil, "core_process_stanza returned incorrect value"); | |
146 assert_equal(target_routed, true, "stanza was not routed successfully"); | |
147 end | |
148 | |
126 runtest(test_message_full_jid, "Messages with full JID destinations get routed"); | 149 runtest(test_message_full_jid, "Messages with full JID destinations get routed"); |
127 runtest(test_message_bare_jid, "Messages with bare JID destinations get routed"); | 150 runtest(test_message_bare_jid, "Messages with bare JID destinations get routed"); |
128 runtest(test_message_no_to, "Messages with no destination are handled by the server"); | 151 runtest(test_message_no_to, "Messages with no destination are handled by the server"); |
129 runtest(test_message_to_remote_bare, "Messages to a remote user are routed by the server"); | 152 runtest(test_message_to_remote_bare, "Messages to a remote user are routed by the server"); |
130 runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed"); | 153 runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed"); |
131 | 154 |
132 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); | 155 runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); |
156 runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed"); | |
133 | 157 |
134 end | 158 end |