gmcmillan-xmpp4r 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +91 -0
  3. data/COPYING +340 -0
  4. data/LICENSE +59 -0
  5. data/README.rdoc +122 -0
  6. data/README_ruby19.txt +43 -0
  7. data/Rakefile +258 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  13. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  15. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
  16. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  17. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  18. data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
  19. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  20. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  21. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  22. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
  23. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
  24. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  25. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  26. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  27. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  28. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  29. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
  30. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
  31. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
  32. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  33. data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
  34. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  35. data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
  36. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  37. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
  38. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
  39. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
  40. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
  41. data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
  42. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  43. data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
  44. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  45. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  46. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
  47. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
  48. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  49. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  50. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  51. data/lib/xmpp4r.rb +118 -0
  52. data/lib/xmpp4r/base64.rb +32 -0
  53. data/lib/xmpp4r/bytestreams.rb +15 -0
  54. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
  55. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  56. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  57. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  60. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  61. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  62. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
  63. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  64. data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  65. data/lib/xmpp4r/callbacks.rb +133 -0
  66. data/lib/xmpp4r/caps.rb +1 -0
  67. data/lib/xmpp4r/caps/c.rb +67 -0
  68. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  69. data/lib/xmpp4r/caps/helper/helper.rb +84 -0
  70. data/lib/xmpp4r/client.rb +345 -0
  71. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  72. data/lib/xmpp4r/command/iq/command.rb +154 -0
  73. data/lib/xmpp4r/component.rb +103 -0
  74. data/lib/xmpp4r/connection.rb +231 -0
  75. data/lib/xmpp4r/dataforms.rb +5 -0
  76. data/lib/xmpp4r/dataforms/x/data.rb +297 -0
  77. data/lib/xmpp4r/debuglog.rb +63 -0
  78. data/lib/xmpp4r/delay.rb +5 -0
  79. data/lib/xmpp4r/delay/x/delay.rb +99 -0
  80. data/lib/xmpp4r/discovery.rb +8 -0
  81. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  82. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  83. data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  84. data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  85. data/lib/xmpp4r/entity_time.rb +6 -0
  86. data/lib/xmpp4r/entity_time/iq.rb +45 -0
  87. data/lib/xmpp4r/entity_time/responder.rb +57 -0
  88. data/lib/xmpp4r/errors.rb +284 -0
  89. data/lib/xmpp4r/feature_negotiation.rb +5 -0
  90. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  91. data/lib/xmpp4r/framework/base.rb +55 -0
  92. data/lib/xmpp4r/framework/bot.rb +148 -0
  93. data/lib/xmpp4r/httpbinding.rb +5 -0
  94. data/lib/xmpp4r/httpbinding/client.rb +275 -0
  95. data/lib/xmpp4r/idgenerator.rb +37 -0
  96. data/lib/xmpp4r/iq.rb +221 -0
  97. data/lib/xmpp4r/jid.rb +167 -0
  98. data/lib/xmpp4r/last.rb +2 -0
  99. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  100. data/lib/xmpp4r/last/iq/last.rb +67 -0
  101. data/lib/xmpp4r/location.rb +2 -0
  102. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  103. data/lib/xmpp4r/location/location.rb +179 -0
  104. data/lib/xmpp4r/message.rb +226 -0
  105. data/lib/xmpp4r/muc.rb +14 -0
  106. data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  107. data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
  108. data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  109. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  110. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  111. data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  112. data/lib/xmpp4r/muc/item.rb +143 -0
  113. data/lib/xmpp4r/muc/x/muc.rb +70 -0
  114. data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  115. data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  116. data/lib/xmpp4r/presence.rb +232 -0
  117. data/lib/xmpp4r/pubsub.rb +8 -0
  118. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  119. data/lib/xmpp4r/pubsub/children/event.rb +49 -0
  120. data/lib/xmpp4r/pubsub/children/item.rb +35 -0
  121. data/lib/xmpp4r/pubsub/children/items.rb +53 -0
  122. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  123. data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
  124. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  125. data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  126. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  127. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
  128. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
  129. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  130. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
  131. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
  132. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  133. data/lib/xmpp4r/query.rb +15 -0
  134. data/lib/xmpp4r/reliable.rb +168 -0
  135. data/lib/xmpp4r/rexmladdons.rb +197 -0
  136. data/lib/xmpp4r/roster.rb +7 -0
  137. data/lib/xmpp4r/roster/helper/roster.rb +532 -0
  138. data/lib/xmpp4r/roster/iq/roster.rb +215 -0
  139. data/lib/xmpp4r/roster/x/roster.rb +138 -0
  140. data/lib/xmpp4r/rpc.rb +2 -0
  141. data/lib/xmpp4r/rpc/helper/client.rb +123 -0
  142. data/lib/xmpp4r/rpc/helper/server.rb +74 -0
  143. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  144. data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  145. data/lib/xmpp4r/sasl.rb +259 -0
  146. data/lib/xmpp4r/semaphore.rb +38 -0
  147. data/lib/xmpp4r/stream.rb +611 -0
  148. data/lib/xmpp4r/streamparser.rb +66 -0
  149. data/lib/xmpp4r/test/listener_mocker.rb +118 -0
  150. data/lib/xmpp4r/tune.rb +2 -0
  151. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  152. data/lib/xmpp4r/tune/tune.rb +113 -0
  153. data/lib/xmpp4r/vcard.rb +6 -0
  154. data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  155. data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  156. data/lib/xmpp4r/version.rb +7 -0
  157. data/lib/xmpp4r/version/helper/responder.rb +72 -0
  158. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  159. data/lib/xmpp4r/version/iq/version.rb +105 -0
  160. data/lib/xmpp4r/x.rb +37 -0
  161. data/lib/xmpp4r/xhtml.rb +1 -0
  162. data/lib/xmpp4r/xhtml/html.rb +115 -0
  163. data/lib/xmpp4r/xmpp4r.rb +20 -0
  164. data/lib/xmpp4r/xmppelement.rb +168 -0
  165. data/lib/xmpp4r/xmppstanza.rb +162 -0
  166. data/setup.rb +1586 -0
  167. data/test/bytestreams/tc_ibb.rb +188 -0
  168. data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
  169. data/test/caps/tc_helper.rb +158 -0
  170. data/test/dataforms/tc_data.rb +81 -0
  171. data/test/delay/tc_xdelay.rb +51 -0
  172. data/test/discovery/tc_responder.rb +91 -0
  173. data/test/entity_time/tc_responder.rb +65 -0
  174. data/test/last/tc_helper.rb +75 -0
  175. data/test/lib/assert_equal_xml.rb +14 -0
  176. data/test/lib/clienttester.rb +149 -0
  177. data/test/muc/tc_muc_mucclient.rb +834 -0
  178. data/test/muc/tc_muc_simplemucclient.rb +114 -0
  179. data/test/muc/tc_mucowner.rb +50 -0
  180. data/test/pubsub/tc_helper.rb +785 -0
  181. data/test/pubsub/tc_nodeconfig.rb +61 -0
  182. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  183. data/test/roster/tc_helper.rb +523 -0
  184. data/test/roster/tc_iqqueryroster.rb +173 -0
  185. data/test/roster/tc_xroster.rb +73 -0
  186. data/test/rpc/tc_helper.rb +96 -0
  187. data/test/tc_callbacks.rb +129 -0
  188. data/test/tc_class_names.rb +146 -0
  189. data/test/tc_client.rb +30 -0
  190. data/test/tc_errors.rb +146 -0
  191. data/test/tc_idgenerator.rb +30 -0
  192. data/test/tc_iq.rb +113 -0
  193. data/test/tc_iqquery.rb +31 -0
  194. data/test/tc_jid.rb +204 -0
  195. data/test/tc_presence.rb +150 -0
  196. data/test/tc_rexml.rb +139 -0
  197. data/test/tc_stream.rb +193 -0
  198. data/test/tc_streamComponent.rb +105 -0
  199. data/test/tc_streamError.rb +129 -0
  200. data/test/tc_streamSend.rb +59 -0
  201. data/test/tc_streamparser.rb +137 -0
  202. data/test/tc_xmppstanza.rb +135 -0
  203. data/test/ts_xmpp4r.rb +44 -0
  204. data/test/tune/tc_helper_recv.rb +82 -0
  205. data/test/tune/tc_helper_send.rb +74 -0
  206. data/test/tune/tc_tune.rb +79 -0
  207. data/test/vcard/tc_helper.rb +49 -0
  208. data/test/vcard/tc_iqvcard.rb +62 -0
  209. data/test/version/tc_helper.rb +60 -0
  210. data/test/version/tc_iqqueryversion.rb +97 -0
  211. data/test/xhtml/tc_html.rb +41 -0
  212. data/tools/gen_requires.bash +31 -0
  213. data/tools/xmpp4r-gemspec-test.rb +11 -0
  214. data/xmpp4r.gemspec +249 -0
  215. metadata +299 -0
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/dataforms'
7
+ include Jabber
8
+
9
+ class DataFormsTest < Test::Unit::TestCase
10
+
11
+ def test_create_defaults
12
+ v = Dataforms::XDataTitle.new
13
+ assert_nil(v.title)
14
+ assert_equal("", v.to_s)
15
+
16
+ v = Dataforms::XDataInstructions.new
17
+ assert_nil(v.instructions)
18
+ assert_equal("", v.to_s)
19
+
20
+ v = Dataforms::XDataField.new
21
+ assert_nil(v.label)
22
+ assert_nil(v.var)
23
+ assert_nil(v.type)
24
+ assert_equal(false, v.required?)
25
+ assert_equal([], v.values)
26
+ assert_equal({}, v.options)
27
+
28
+ v = Dataforms::XData.new
29
+ assert_equal([], v.fields)
30
+ assert_nil(v.type)
31
+ end
32
+
33
+ def test_create
34
+ v = Dataforms::XDataTitle.new "This is the title"
35
+ assert_equal("This is the title",v.title)
36
+ assert_equal("This is the title", v.to_s)
37
+
38
+ v = Dataforms::XDataInstructions.new "Instructions"
39
+ assert_equal("Instructions",v.instructions)
40
+ assert_equal("Instructions", v.to_s)
41
+
42
+ f = Dataforms::XDataField.new "botname", :text_single
43
+ assert_nil(f.label)
44
+ assert_equal("botname", f.var)
45
+ assert_equal(:text_single, f.type)
46
+ assert_equal(false, f.required?)
47
+ assert_equal([], f.values)
48
+ assert_equal({}, f.options)
49
+ f.label = "The name of your bot"
50
+ assert_equal("The name of your bot", f.label)
51
+ [:boolean, :fixed, :hidden, :jid_multi, :jid_single,
52
+ :list_multi, :list_single, :text_multi, :text_private,
53
+ :text_single].each do |type|
54
+ f.type = type
55
+ assert_equal(type, f.type)
56
+ end
57
+ f.type = :wrong_type
58
+ assert_nil(f.type)
59
+ f.required= true
60
+ assert_equal(true, f.required?)
61
+ f.values = ["the value"]
62
+ assert_equal(["the value"], f.values)
63
+ f.options = { "option 1" => "Label 1", "option 2" => "Label 2", "option 3" => nil }
64
+ assert_equal({ "option 1" => "Label 1", "option 2" => "Label 2", "option 3" => nil }, f.options)
65
+
66
+
67
+ f = Dataforms::XDataField.new "test", :text_single
68
+ v = Dataforms::XData.new :form
69
+ assert_equal([], v.fields)
70
+ assert_equal(:form, v.type)
71
+ [:form, :result, :submit, :cancel].each do |type|
72
+ v.type = type
73
+ assert_equal(type, v.type)
74
+ end
75
+ v.add f
76
+ assert_equal(f, v.field('test'))
77
+ assert_nil(v.field('wrong field'))
78
+ assert_equal([f], v.fields)
79
+ end
80
+
81
+ end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/rexmladdons'
7
+ require 'xmpp4r/delay/x/delay'
8
+ include Jabber
9
+
10
+ class XDelayTest < Test::Unit::TestCase
11
+ def test_create1
12
+ d = Delay::XDelay.new(false)
13
+ assert_equal(nil, d.stamp)
14
+ assert_equal(nil, d.from)
15
+ assert_equal('jabber:x:delay', d.namespace)
16
+ end
17
+
18
+ def test_create2
19
+ d = Delay::XDelay.new
20
+ # Hopefully the seconds don't change here...
21
+ assert_equal(Time.now.to_s, d.stamp.to_s)
22
+ assert_equal(nil, d.from)
23
+ assert_equal('jabber:x:delay', d.namespace)
24
+ end
25
+
26
+ def test_from
27
+ d = Delay::XDelay.new
28
+ assert_equal(nil, d.from)
29
+ d.from = JID.new('astro@spaceboyz.net')
30
+ assert_equal(JID.new('astro@spaceboyz.net'), d.from)
31
+ assert_equal(d, d.set_from(nil))
32
+ assert_equal(nil, d.from)
33
+ end
34
+
35
+ def test_stamp
36
+ d = Delay::XDelay.new(false)
37
+ assert_equal(nil, d.stamp)
38
+ now = Time.now
39
+ d.stamp = now
40
+ assert_equal(now.to_s, d.stamp.to_s)
41
+ assert_equal(d, d.set_stamp(nil))
42
+ assert_equal(nil, d.stamp)
43
+ end
44
+
45
+ def test_import
46
+ x1 = X.new
47
+ x1.add_namespace('jabber:x:delay')
48
+ x2 = X::import(x1)
49
+ assert_equal(Delay::XDelay, x2.class)
50
+ end
51
+ end
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require File::dirname(__FILE__) + '/../lib/clienttester'
7
+
8
+ require 'xmpp4r/discovery/helper/responder'
9
+ include Jabber
10
+
11
+ class Discovery::ResponderTest < Test::Unit::TestCase
12
+ include ClientTester
13
+
14
+ def test_new
15
+ r = Discovery::Responder.new(@client)
16
+ assert_nil(r.node)
17
+ assert_equal([], r.identities)
18
+ assert_equal([], r.features)
19
+ assert_equal([], r.forms)
20
+ assert_equal([], r.items)
21
+ end
22
+
23
+ def test_new2
24
+ r = Discovery::Responder.new(@client, 'xmpp4r',
25
+ [Discovery::Identity.new('client', 'XMPP4R', 'bot'),
26
+ Discovery::Identity.new('pubsub', 'Personal events', 'pep')],
27
+ ['ipv6', Discovery::Feature.new('sslc2s')],
28
+ [Discovery::Item.new('foo@bar', 'Foo', nil), Discovery::Item.new('bar@baz', 'Bar', 'barbaz')])
29
+ assert_equal('xmpp4r', r.node)
30
+ assert_equal([Discovery::Identity.new('client', 'XMPP4R', 'bot'),
31
+ Discovery::Identity.new('pubsub', 'Personal events', 'pep')], r.identities)
32
+ assert_equal([Discovery::Feature.new('ipv6'), Discovery::Feature.new('sslc2s')], r.features)
33
+ assert_equal([], r.forms)
34
+ assert_equal([Discovery::Item.new('foo@bar', 'Foo', nil), Discovery::Item.new('bar@baz', 'Bar', 'barbaz')], r.items)
35
+ end
36
+
37
+ def test_generate_item
38
+ r = Discovery::Responder.new(@client, nil, [Discovery::Identity.new('client', 'XMPP4R', 'bot')])
39
+ assert_equal(Discovery::Item.new(@client.jid, 'XMPP4R'), r.generate_item)
40
+ end
41
+
42
+ def test_query
43
+ Discovery::Responder.new(@client, nil,
44
+ [Discovery::Identity.new('client', 'XMPP4R', 'bot')],
45
+ ['ipv6'],
46
+ [Discovery::Item.new('foo@bar', 'Foo', nil)])
47
+
48
+ iq1 = Iq.new(:get)
49
+ iq1.add(Discovery::IqQueryDiscoInfo.new)
50
+ reply1 = @server.send_with_id(iq1)
51
+ assert_equal(:result, reply1.type)
52
+ assert_kind_of(Discovery::IqQueryDiscoInfo, reply1.query)
53
+ assert_nil(reply1.query.node)
54
+ assert_equal(1, reply1.query.identities.size)
55
+ assert_equal('XMPP4R', reply1.query.identities[0].iname)
56
+ assert_equal(['ipv6'], reply1.query.features)
57
+
58
+ iq2 = Iq.new(:get)
59
+ iq2.add(Discovery::IqQueryDiscoItems.new)
60
+ reply2 = @server.send_with_id(iq2)
61
+ assert_equal(:result, reply2.type)
62
+ assert_kind_of(Discovery::IqQueryDiscoItems, reply2.query)
63
+ assert_nil(reply2.query.node)
64
+ assert_equal(1, reply2.query.items.size)
65
+ assert_equal(JID.new('foo@bar'), reply2.query.items[0].jid)
66
+ end
67
+
68
+ def test_linked
69
+ class << @client
70
+ remove_method(:jid) # avoids warning
71
+ def jid
72
+ JID.new('foo@bar/baz')
73
+ end
74
+ end
75
+ r1 = Discovery::Responder.new(@client, 'child',
76
+ [Discovery::Identity.new('client', 'Child', 'bot')])
77
+ r2 = Discovery::Responder.new(@client, nil,
78
+ [], [],
79
+ [r1])
80
+
81
+ iq = Iq.new(:get)
82
+ iq.add(Discovery::IqQueryDiscoItems.new)
83
+ reply = @server.send_with_id(iq)
84
+ assert_kind_of(Discovery::IqQueryDiscoItems, reply.query)
85
+ assert_nil(reply.query.node)
86
+ assert_equal(1, reply.query.items.size)
87
+ assert_equal(JID.new('foo@bar/baz'), reply.query.items[0].jid)
88
+ assert_equal('Child', reply.query.items[0].iname)
89
+ assert_equal('child', reply.query.items[0].node)
90
+ end
91
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require File::dirname(__FILE__) + '/../lib/clienttester'
7
+
8
+ require 'xmpp4r/entity_time/responder'
9
+ include Jabber
10
+
11
+ class EntityTime::ResponderTest < Test::Unit::TestCase
12
+ include ClientTester
13
+
14
+ def a_utc_time
15
+ Time.utc(2000,"jan",1,20,15,1) # xmlschema = "2000-01-01T20:15:01Z"
16
+ end
17
+
18
+ def test_entity_time_iq
19
+ el_time = EntityTime::IqTime.new(a_utc_time)
20
+
21
+ assert_equal('time', el_time.name, "element has wrong name")
22
+ assert_equal('urn:xmpp:time', el_time.namespace, "element has wrong namespace")
23
+
24
+ assert(el_time.elements["utc"], "element does not have a utc child")
25
+ assert_equal('2000-01-01T20:15:01Z', el_time.elements["utc"].text, "element/utc has the wrong text")
26
+
27
+ assert(el_time.elements["tzo"], "element does not have a tzo child")
28
+ assert_equal("+00:00", el_time.elements["tzo"].text, "element/tzo has the wrong time zone offset")
29
+ end
30
+
31
+ =begin
32
+ http://xmpp.org/extensions/xep-0202.html
33
+ <iq type='get'
34
+ from='romeo@montague.net/orchard'
35
+ to='juliet@capulet.com/balcony'
36
+ id='time_1'>
37
+ <time xmlns='urn:xmpp:time'/>
38
+ </iq>
39
+ =end
40
+ def test_query
41
+ EntityTime::Responder.new(@client)
42
+
43
+ iq = Iq.new(:get)
44
+ t = REXML::Element.new('time')
45
+ t.add_namespace('urn:xmpp:time')
46
+ iq.add_element(t)
47
+
48
+ reply = @server.send_with_id(iq)
49
+
50
+ assert_equal(:result, reply.type)
51
+ assert_equal('time', reply[0].name)
52
+ assert_equal('urn:xmpp:time', reply[0].namespace)
53
+
54
+ assert(reply[0].elements["utc"].has_text?, "element must have a utc time (actual time should be check here)")
55
+
56
+ tmp = Time.now
57
+ local_offset = Time.now.utc_offset
58
+ hour_offset = local_offset / 3600
59
+ min_offset = local_offset % 60
60
+ offset = "%+03d:%02d"%[hour_offset, min_offset]
61
+
62
+ assert_equal(offset, reply[0].elements["tzo"].text, "element should has an incorrect time zone offset")
63
+ end
64
+
65
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require File::dirname(__FILE__) + '/../lib/clienttester'
7
+
8
+ require 'xmpp4r'
9
+ require 'xmpp4r/last/helper/helper'
10
+ include Jabber
11
+
12
+
13
+ class LastActivity::HelperTest < Test::Unit::TestCase
14
+ include ClientTester
15
+
16
+ def test_simple_query
17
+ state { |iq|
18
+ assert_kind_of(Iq, iq)
19
+ assert_equal(JID.new('juliet@capulet.com'), iq.to)
20
+ assert_equal(:get, iq.type)
21
+ assert_kind_of(LastActivity::IqQueryLastActivity, iq.query)
22
+ send("
23
+ <iq type='result' from='#{iq.to}' to='#{iq.from}' id='#{iq.id}'>
24
+ <query xmlns='jabber:iq:last' seconds='903'/>
25
+ </iq>")
26
+ }
27
+
28
+ res = LastActivity::Helper.new(@client).get_last_activity_from('juliet@capulet.com')
29
+ wait_state
30
+ assert_equal(903, res.seconds)
31
+ assert_nil(res.text)
32
+ end
33
+
34
+ def test_text_query
35
+ state { |iq|
36
+ send("
37
+ <iq type='result' from='#{iq.to}' to='#{iq.from}' id='#{iq.id}'>
38
+ <query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>
39
+ </iq>")
40
+ }
41
+
42
+ res = LastActivity::Helper.new(@client).get_last_activity_from('juliet@capulet.com')
43
+ wait_state
44
+ assert_equal(903, res.seconds)
45
+ assert_equal('Heading Home', res.text)
46
+ end
47
+
48
+ def test_empty_query
49
+ state { |iq|
50
+ send("
51
+ <iq type='result' from='#{iq.to}' to='#{iq.from}' id='#{iq.id}'>
52
+ <query xmlns='jabber:iq:last'/>
53
+ </iq>")
54
+ }
55
+
56
+ res = LastActivity::Helper.new(@client).get_last_activity_from('juliet@capulet.com')
57
+ wait_state
58
+ assert_nil(res.seconds)
59
+ assert_nil(res.text)
60
+ end
61
+
62
+ def test_forbidden_query
63
+ state { |iq|
64
+ send("
65
+ <iq type='error' from='#{iq.to}' to='#{iq.from}' id='#{iq.id}'>
66
+ <error type='auth'>
67
+ <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
68
+ </error>
69
+ </iq>")
70
+ }
71
+
72
+ assert_raises(ServerError) { LastActivity::Helper.new(@client).get_last_activity_from('juliet@capulet.com') }
73
+ end
74
+
75
+ end
@@ -0,0 +1,14 @@
1
+ module Test::Unit::Assertions
2
+ public
3
+ ##
4
+ # Like assert_equal, but actual comparision switches parameters to
5
+ # make use of our attribute order agnostic REXML#==
6
+ def assert_equal_xml(expected, actual, message=nil)
7
+ full_message = build_message(message, <<EOT, expected, actual)
8
+ <?> expected but was
9
+ <?>.
10
+ EOT
11
+ assert_block(full_message) { actual == expected }
12
+ end
13
+ end
14
+
@@ -0,0 +1,149 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ $:.unshift '../lib'
6
+ require 'xmpp4r'
7
+ require 'test/unit'
8
+ require 'socket'
9
+ require 'xmpp4r/semaphore'
10
+
11
+ # Jabber::debug = true
12
+ $ctdebug = false
13
+ # $ctdebug = true
14
+
15
+ # This is sane for tests:
16
+ Thread::abort_on_exception = true
17
+
18
+ # Turn $VERBOSE off to suppress warnings about redefinition
19
+ oldverbose = $VERBOSE
20
+ $VERBOSE = false
21
+
22
+ module Jabber
23
+ ##
24
+ # The ClientTester is a mix-in which provides a setup and teardown
25
+ # method to prepare a Stream object (@client) and the method
26
+ # interfacing as the "server side":
27
+ # * send(xml):: Send a stanza to @client
28
+ #
29
+ # The server side is a stream, too: add your callbacks to @server
30
+ #
31
+ # ClientTester is written to test complex helper classes.
32
+ module ClientTester
33
+ @@SOCKET_PORT = 65223
34
+
35
+ def setup
36
+ servlisten = TCPServer.new(@@SOCKET_PORT)
37
+ serverwait = Semaphore.new
38
+ stream = '<stream:stream xmlns:stream="http://etherx.jabber.org/streams">'
39
+
40
+ @state = 0
41
+ @states = []
42
+
43
+ Thread.new do
44
+ Thread.current.abort_on_exception = true
45
+ serversock = servlisten.accept
46
+ servlisten.close
47
+ serversock.sync = true
48
+ @server = Stream.new
49
+ @server.add_xml_callback do |xml|
50
+ if xml.prefix == 'stream' and xml.name == 'stream'
51
+ send(stream)
52
+ true
53
+ else
54
+ false
55
+ end
56
+ end
57
+ @server.start(serversock)
58
+
59
+ serverwait.run
60
+ end
61
+
62
+ clientsock = TCPSocket.new('localhost', @@SOCKET_PORT)
63
+ clientsock.sync = true
64
+ @client = Stream.new
65
+ #=begin
66
+ class << @client
67
+ def jid
68
+ begin
69
+ #raise
70
+ rescue
71
+ puts $!.backtrace.join("\n")
72
+ end
73
+ JID.new('test@test.com/test')
74
+ end
75
+ end
76
+ #=end
77
+ @client.start(clientsock)
78
+
79
+ @processdone_wait = Semaphore.new
80
+ @nextstate_wait = Semaphore.new
81
+ serverwait.wait
82
+ @server.add_stanza_callback { |stanza|
83
+ # Client prepares everything, then calls wait_state. Problem: because
84
+ # of a race condition, it is possible that we receive the stanza before
85
+ # what to do with it is defined. We busy-wait on @states here.
86
+ n = 0
87
+ while @state >= @states.size and n < 1000
88
+ Thread.pass
89
+ n += 1
90
+ end
91
+ if n == 1000
92
+ puts "Unmanaged stanza in state. Maybe processed by helper?" if $ctdebug
93
+ else
94
+ begin
95
+ puts "Calling #{@states[@state]} for #{stanza.to_s}" if $ctdebug
96
+ @states[@state].call(stanza)
97
+ rescue Exception => e
98
+ puts "Exception in state: #{e.class}: #{e}\n#{e.backtrace.join("\n")}"
99
+ end
100
+ @state += 1
101
+ @nextstate_wait.wait
102
+ @processdone_wait.run
103
+ end
104
+
105
+ false
106
+ }
107
+ @client.send(stream) { |reply| true }
108
+
109
+ end
110
+
111
+ def teardown
112
+ # In some cases, we might lost count of some stanzas
113
+ # (for example, if the handler raises an exception)
114
+ # so we can't block forever.
115
+ n = 0
116
+ while @client.processing > 0 and n < 1000
117
+ Thread::pass
118
+ n += 1
119
+ end
120
+ n = 0
121
+ while @server.processing > 0 and n < 1000
122
+ Thread::pass
123
+ n += 1
124
+ end
125
+ @client.close
126
+ @server.close
127
+ end
128
+
129
+ def send(xml)
130
+ @server.send(xml)
131
+ end
132
+
133
+ def state(&block)
134
+ @states << block
135
+ end
136
+
137
+ def wait_state
138
+ @nextstate_wait.run
139
+ @processdone_wait.wait
140
+ end
141
+
142
+ def skip_state
143
+ @nextstate_wait.run
144
+ end
145
+ end
146
+ end
147
+
148
+ # Restore the old $VERBOSE setting
149
+ $VERBOSE = oldverbose