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,173 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/rexmladdons'
7
+ require 'xmpp4r/roster/iq/roster'
8
+ require 'xmpp4r/jid'
9
+ require 'xmpp4r/iq'
10
+ include Jabber
11
+
12
+ class Roster::IqQueryRosterTest < Test::Unit::TestCase
13
+ def test_create
14
+ r = Roster::IqQueryRoster.new
15
+ assert_equal('jabber:iq:roster', r.namespace)
16
+ assert_equal(r.to_a.size, 0)
17
+ assert_equal(r.to_a, [])
18
+ assert_equal(r.to_s, "<query xmlns='jabber:iq:roster'/>")
19
+ end
20
+
21
+ def test_import
22
+ iq = Iq.new
23
+ q = REXML::Element.new('query')
24
+ q.add_namespace('jabber:iq:roster')
25
+ iq.add(q)
26
+ iq2 = Iq.new.import(iq)
27
+ assert_equal(Roster::IqQueryRoster, iq2.query.class)
28
+ end
29
+
30
+ def test_answer
31
+ iq = Iq.new_rosterget
32
+ assert_equal(:get, iq.type)
33
+ assert_nil(iq.to)
34
+ assert_equal('jabber:client', iq.namespace)
35
+ assert_equal('jabber:iq:roster', iq.queryns)
36
+ assert_equal(0, iq.query.children.size)
37
+
38
+ iq2 = iq.answer(true)
39
+ assert_equal(:get, iq2.type)
40
+ assert_nil(iq2.from)
41
+ assert_equal('jabber:client', iq2.namespace)
42
+ assert_equal('jabber:iq:roster', iq2.queryns)
43
+ assert_equal(0, iq2.query.children.size)
44
+ end
45
+
46
+ def test_xmlns
47
+ ri = Roster::RosterItem.new
48
+ assert_equal('jabber:iq:roster', ri.namespace)
49
+ assert_equal('jabber:iq:roster', ri.attributes['xmlns'])
50
+
51
+ r = Roster::IqQueryRoster.new
52
+ assert_equal('jabber:iq:roster', r.namespace)
53
+ assert_equal('jabber:iq:roster', r.attributes['xmlns'])
54
+
55
+ r.add(ri)
56
+
57
+ assert_equal('jabber:iq:roster', ri.namespace)
58
+ assert_nil(ri.attributes['xmlns'])
59
+ end
60
+
61
+ def test_items
62
+ r = Roster::IqQueryRoster.new
63
+ r.add(Roster::RosterItem.new)
64
+ r.add(Roster::RosterItem.new(JID.new('a@b/d'), 'ABC', :none, :subscribe)).groups = ['a']
65
+ itemstr = "<item jid='astro@spaceboyz.net' name='Astro' subscribtion='both'>" \
66
+ + "<group>SpaceBoyZ</group><group>xmpp4r</group></item>"
67
+ r.typed_add(REXML::Document.new(itemstr).root)
68
+
69
+ r.each { |item|
70
+ assert_equal(item, r[item.jid])
71
+ }
72
+
73
+ r.to_a.each { |item|
74
+ assert_equal(item, r[item.jid])
75
+ }
76
+
77
+ assert_equal(JID.new, r.to_a[0].jid)
78
+ assert_equal(nil, r.to_a[0].iname)
79
+ assert_equal(nil, r.to_a[0].subscription)
80
+ assert_equal(nil, r.to_a[0].ask)
81
+
82
+ assert_equal(JID.new('a@b/d'), r.to_a[1].jid)
83
+ assert_equal('ABC', r.to_a[1].iname)
84
+ assert_equal(:none, r.to_a[1].subscription)
85
+ assert_equal(:subscribe, r.to_a[1].ask)
86
+
87
+ assert_equal(REXML::Document.new(itemstr).root.to_s, r.to_a[2].to_s)
88
+ end
89
+
90
+ def test_dupitems
91
+ r = Roster::IqQueryRoster.new
92
+ jid = JID.new('a@b')
93
+ jid2 = JID.new('c@d')
94
+ ri = Roster::RosterItem.new(jid, 'ab')
95
+ r.add(ri)
96
+ assert_equal('ab', ri.iname)
97
+ assert_equal('ab', r[jid].iname)
98
+ ri.iname = 'cd'
99
+ assert_equal('cd', ri.iname)
100
+ # There are no shallow copies - everything is alright.
101
+ assert_equal('cd', r[jid].iname)
102
+
103
+ r.add(ri)
104
+ assert_equal('cd', r[jid].iname)
105
+ assert_equal(ri, r[jid])
106
+
107
+ ri.jid = jid2
108
+ assert_equal(nil, r[jid])
109
+ assert_equal(ri, r[jid2])
110
+ assert_equal(2, r.to_a.size)
111
+
112
+ r.each_element('item') { |item|
113
+ assert_equal(ri, item)
114
+ assert_equal(ri.jid, item.jid)
115
+ assert_equal(ri.iname, item.iname)
116
+ assert_equal(jid2, item.jid)
117
+ assert_equal('cd', item.iname)
118
+ }
119
+ end
120
+ end
121
+
122
+ class Roster::RosterItemTest < Test::Unit::TestCase
123
+ def test_create
124
+ ri = Roster::RosterItem.new
125
+ assert_equal(JID.new, ri.jid)
126
+ assert_equal(nil, ri.iname)
127
+ assert_equal(nil, ri.subscription)
128
+ assert_equal(nil, ri.ask)
129
+
130
+ ri = Roster::RosterItem.new(JID.new('a@b/c'), 'xyz', :both, nil)
131
+ assert_equal(JID.new('a@b/c'), ri.jid)
132
+ assert_equal('xyz', ri.iname)
133
+ assert_equal(:both, ri.subscription)
134
+ assert_equal(nil, ri.ask)
135
+ end
136
+
137
+ def test_modify
138
+ ri = Roster::RosterItem.new(JID.new('a@b/c'), 'xyz', :both, :subscribe)
139
+
140
+ assert_equal(JID.new('a@b/c'), ri.jid)
141
+ ri.jid = nil
142
+ assert_equal(JID.new, ri.jid)
143
+
144
+ assert_equal('xyz', ri.iname)
145
+ ri.iname = nil
146
+ assert_equal(nil, ri.iname)
147
+
148
+ assert_equal(:both, ri.subscription)
149
+ ri.subscription = nil
150
+ assert_equal(nil, ri.subscription)
151
+
152
+ assert_equal(:subscribe, ri.ask)
153
+ ri.ask = nil
154
+ assert_equal(nil, ri.ask)
155
+ end
156
+
157
+ def test_groupdeletion
158
+ ri = Roster::RosterItem.new
159
+ g1 = ['a', 'b', 'c']
160
+ ri.groups = g1
161
+ assert_equal(g1, ri.groups.sort)
162
+ g2 = ['c', 'd', 'e']
163
+ ri.groups = g2
164
+ assert_equal(g2, ri.groups.sort)
165
+ end
166
+
167
+ def test_dupgroups
168
+ ri = Roster::RosterItem.new
169
+ mygroups = ['a', 'a', 'b']
170
+ ri.groups = mygroups
171
+ assert_equal(mygroups.uniq, ri.groups)
172
+ end
173
+ end
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/rexmladdons'
7
+ require 'xmpp4r/roster/x/roster'
8
+ require 'xmpp4r/jid'
9
+ include Jabber
10
+
11
+ class Roster::XRosterTest < Test::Unit::TestCase
12
+ def test_create
13
+ r1 = Roster::XRoster.new
14
+ assert_equal('x', r1.name)
15
+ assert_equal('jabber:x:roster', r1.namespace)
16
+ r2 = Roster::RosterX.new
17
+ assert_equal('x', r2.name)
18
+ assert_equal('http://jabber.org/protocol/rosterx', r2.namespace)
19
+ end
20
+
21
+ def test_import
22
+ x1 = X.new
23
+ x1.add_namespace('jabber:x:roster')
24
+ x2 = X::import(x1)
25
+ assert_equal(Roster::XRoster, x2.class)
26
+ assert_equal('jabber:x:roster', x2.namespace)
27
+ end
28
+
29
+ def test_typed_add
30
+ x = REXML::Element.new('x')
31
+ x.add(REXML::Element.new('item'))
32
+ r = Roster::XRoster.new.import(x)
33
+ assert_kind_of(Roster::XRosterItem, r.first_element('item'))
34
+ assert_kind_of(Roster::XRosterItem, r.typed_add(REXML::Element.new('item')))
35
+ end
36
+
37
+ def test_items
38
+ j1 = Roster::XRosterItem.new
39
+ assert_equal(JID.new(nil), j1.jid)
40
+ assert_equal(nil, j1.iname)
41
+
42
+ j2 = Roster::XRosterItem.new(JID.new('a@b/c'))
43
+ assert_equal(JID.new('a@b/c'), j2.jid)
44
+ assert_equal(nil, j2.iname)
45
+ j3 = Roster::XRosterItem.new(JID.new('a@b/c'), 'Mr. Abc')
46
+ assert_equal(JID.new('a@b/c'), j3.jid)
47
+ assert_equal('Mr. Abc', j3.iname)
48
+ assert_equal([], j3.groups)
49
+
50
+ j3.groups = ['X', 'Y', 'Z']
51
+ assert_equal(['X', 'Y', 'Z'], j3.groups)
52
+ end
53
+
54
+ def test_actions
55
+ j = Roster::XRosterItem.new
56
+ assert_equal(:add, j.action)
57
+
58
+ j.action = :modify
59
+ assert_equal(:modify, j.action)
60
+
61
+ j.action = :delete
62
+ assert_equal(:delete, j.action)
63
+
64
+ j.action = :invalid
65
+ assert_equal(:add, j.action)
66
+
67
+ j.attributes['action'] = 'modify'
68
+ assert_equal(:modify, j.action)
69
+
70
+ j.attributes['action'] = 'invalid'
71
+ assert_equal(:add, j.action)
72
+ end
73
+ end
@@ -0,0 +1,96 @@
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/rpc/helper/client'
10
+ require 'xmpp4r/rpc/helper/server'
11
+ include Jabber
12
+
13
+ class RPC::HelperTest < Test::Unit::TestCase
14
+ include ClientTester
15
+
16
+ def give_client_jid!
17
+ class << @client
18
+ remove_method(:jid) # avoids warning
19
+ def jid; Jabber::JID.new('client@test.com/clienttester'); end
20
+ end
21
+ end
22
+
23
+ def test_create
24
+ give_client_jid!
25
+
26
+ cl = RPC::Client.new(@client, 'a@b/c')
27
+ assert_kind_of(RPC::Client, cl)
28
+ sv = RPC::Server.new(@server)
29
+ assert_kind_of(RPC::Server, sv)
30
+ end
31
+
32
+ def echo(msg = nil)
33
+ msg
34
+ end
35
+
36
+ def test_simple
37
+ give_client_jid!
38
+
39
+ sv = RPC::Server.new(@server)
40
+ sv.add_handler("echo", &method(:echo))
41
+
42
+ cl = RPC::Client.new(@client, 'a@b/c')
43
+ assert_nothing_raised do
44
+ assert_equal('Test string', cl.call("echo", 'Test string'))
45
+ end
46
+
47
+ # exception during serialisation bug identified on xmpp4r-devel
48
+ # https://mail.gna.org/public/xmpp4r-devel/2008-05/msg00010.html
49
+ assert_raise XMLRPC::FaultException do
50
+ cl.call("echo")
51
+ end
52
+ end
53
+
54
+ def test_introspection
55
+ give_client_jid!
56
+
57
+ sv = RPC::Server.new(@server)
58
+ sv.add_introspection
59
+
60
+ cl = RPC::Client.new(@client, 'a@b/c')
61
+ cl_methods = cl.call("system.listMethods")
62
+ assert(cl_methods.size > 0)
63
+ cl_methods.each { |method|
64
+ assert_kind_of(String, method)
65
+ assert(method =~ /^system\./)
66
+ }
67
+ end
68
+
69
+ def test_multicall
70
+ give_client_jid!
71
+
72
+ sv = RPC::Server.new(@server)
73
+ sv.add_multicall
74
+ sv.add_handler("reverse") do |s| s.reverse end
75
+ sv.add_handler("upcase") do |s| s.upcase end
76
+
77
+ cl = RPC::Client.new(@client, 'a@b/c')
78
+ assert_equal(['tseT', 'TEST'], cl.multicall(['reverse', 'Test'], ['upcase', 'Test']))
79
+ end
80
+
81
+ def test_10calls
82
+ give_client_jid!
83
+
84
+ sv = RPC::Server.new(@server)
85
+ sv.add_handler("add") do |a,b| a+b end
86
+
87
+ cl = RPC::Client.new(@client, 'a@b/c')
88
+ correct = true
89
+ 10.times {
90
+ a, b = rand(1000), rand(1000)
91
+ correct &&= (cl.call('add', a, b) == a + b)
92
+ }
93
+
94
+ assert(correct)
95
+ end
96
+ end
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/callbacks'
7
+ include Jabber
8
+
9
+ class CallbacksTest < Test::Unit::TestCase
10
+ def test_test1
11
+ called = 0
12
+ cb = Callback.new(5, "toto", Proc.new { called += 1 })
13
+ assert_equal(5, cb.priority)
14
+ assert_equal("toto", cb.ref)
15
+ cb.block.call
16
+ assert_equal(1, called)
17
+ cb.block.call
18
+ assert_equal(2, called)
19
+ end
20
+
21
+ def test_callbacklist1
22
+ cbl = CallbackList.new
23
+ called1 = false
24
+ called2 = false
25
+ called3 = false
26
+ called4 = false
27
+ cbl.add(5, "ref1") { called1 = true ; true }
28
+ cbl.add(7, "ref1") { |e| called2 = true ; false}
29
+ cbl.add(9, "ref1") { called3 = true ;false }
30
+ cbl.add(11, "ref1") { called4 = true ; false }
31
+ o = "aaaa"
32
+ assert(cbl.process(o))
33
+ assert(called1)
34
+ assert(called2)
35
+ assert(called3)
36
+ assert(called4)
37
+ end
38
+
39
+ def test_callbacklist2
40
+ cbl = CallbackList.new
41
+ assert(0, cbl.length)
42
+ cbl.add(5, "ref1") { called1 = true }
43
+ assert(1, cbl.length)
44
+ cbl.add(7, "ref2") { |e| called2 = true ; e.consume }
45
+ assert(2, cbl.length)
46
+ cbl.delete("ref2")
47
+ assert(1, cbl.length)
48
+ cbl.add(9, "ref3") { called3 = true }
49
+ assert(2, cbl.length)
50
+ end
51
+
52
+ def test_callbacklist4
53
+ cbl = CallbackList.new
54
+ cbl.add(5, "ref1") { false }
55
+ cbl.add(7, "ref1") { false }
56
+ o = "o"
57
+ assert(!cbl.process(o))
58
+ end
59
+
60
+ def test_callbacklist5
61
+ cbl = CallbackList.new
62
+ cbl.add(5, "ref1") { true }
63
+ cbl.add(7, "ref1") { false }
64
+ o = "o"
65
+ assert(cbl.process(o))
66
+ end
67
+
68
+ def test_callbacklist6
69
+ cbl = CallbackList.new
70
+ ok = false
71
+ c = 'a'
72
+ d = 'b'
73
+ cbl.add(5, "ref1") { |a, b|
74
+ if a == 'a' and b == 'b'
75
+ ok = true
76
+ end
77
+ false
78
+ }
79
+ assert(!cbl.process(c, d))
80
+ assert(ok)
81
+ end
82
+
83
+ def test_callbacklist7
84
+ cbl = CallbackList.new
85
+ called1 = false
86
+ called2 = false
87
+ called3 = false
88
+ called4 = false
89
+ cbl.add(3, "ref1") { called4 = true ; true }
90
+ cbl.add(5, "ref1") { called1 = true ; true }
91
+ cbl.add(7, "ref1") { called2 = true ; 'a'}
92
+ cbl.add(9, "ref1") { called3 = true ;1 }
93
+ o = "aaaa"
94
+ assert(cbl.process(o))
95
+ assert(called1)
96
+ assert(called2)
97
+ assert(called3)
98
+ assert(!called4)
99
+ end
100
+
101
+ def test_nested
102
+ cbl = CallbackList.new
103
+ called_outer = 0
104
+ called_inner = 0
105
+
106
+ cbl.add(100, nil) {
107
+ called_outer += 1
108
+
109
+ if called_outer == 1
110
+ cbl.add(200, nil) {
111
+ called_inner += 1
112
+ }
113
+ end
114
+ }
115
+
116
+ assert_equal(0, called_inner)
117
+ assert_equal(0, called_outer)
118
+
119
+ cbl.process
120
+
121
+ assert_equal(0, called_inner)
122
+ assert_equal(1, called_outer)
123
+
124
+ cbl.process
125
+
126
+ assert_equal(1, called_inner)
127
+ assert_equal(2, called_outer)
128
+ end
129
+ end