xmpp4r 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/ChangeLog +28 -0
- data/LICENSE +59 -0
- data/README +20 -0
- data/Rakefile +103 -0
- data/UPDATING +40 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +425 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -0
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +89 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +42 -0
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +172 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
- data/lib/callbacks.rb +122 -0
- data/lib/xmpp4r/authenticationfailure.rb +13 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
- data/lib/xmpp4r/bytestreams.rb +11 -0
- data/lib/xmpp4r/client.rb +249 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +166 -0
- data/lib/xmpp4r/dataforms/x/data.rb +248 -0
- data/lib/xmpp4r/dataforms.rb +1 -0
- data/lib/xmpp4r/debuglog.rb +34 -0
- data/lib/xmpp4r/delay/x/delay.rb +100 -0
- data/lib/xmpp4r/delay.rb +1 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
- data/lib/xmpp4r/discovery.rb +2 -0
- data/lib/xmpp4r/error.rb +230 -0
- data/lib/xmpp4r/errorexception.rb +32 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
- data/lib/xmpp4r/feature_negotiation.rb +1 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +229 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/message.rb +171 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
- data/lib/xmpp4r/muc/x/muc.rb +98 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
- data/lib/xmpp4r/muc.rb +6 -0
- data/lib/xmpp4r/presence.rb +255 -0
- data/lib/xmpp4r/query.rb +43 -0
- data/lib/xmpp4r/rexmladdons.rb +826 -0
- data/lib/xmpp4r/roster/helper/roster.rb +514 -0
- data/lib/xmpp4r/roster/iq/roster.rb +244 -0
- data/lib/xmpp4r/roster/x/roster.rb +155 -0
- data/lib/xmpp4r/roster.rb +4 -0
- data/lib/xmpp4r/sasl.rb +167 -0
- data/lib/xmpp4r/stream.rb +543 -0
- data/lib/xmpp4r/streamparser.rb +77 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
- data/lib/xmpp4r/vcard.rb +3 -0
- data/lib/xmpp4r/version/helper/responder.rb +71 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +118 -0
- data/lib/xmpp4r/version.rb +3 -0
- data/lib/xmpp4r/x.rb +43 -0
- data/lib/xmpp4r/xmlstanza.rb +174 -0
- data/lib/xmpp4r/xmpp4r.rb +16 -0
- data/lib/xmpp4r.rb +122 -0
- data/setup.rb +1360 -0
- data/test/bytestreams/tc_ibb.rb +186 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/lib/clienttester.rb +110 -0
- data/test/muc/tc_muc_mucclient.rb +569 -0
- data/test/muc/tc_muc_simplemucclient.rb +72 -0
- data/test/roster/.tc_helper.rb.swp +0 -0
- data/test/roster/tc_helper.rb +389 -0
- data/test/roster/tc_iqqueryroster.rb +140 -0
- data/test/roster/tc_xroster.rb +70 -0
- data/test/tc_callbacks.rb +128 -0
- data/test/tc_class_names.rb +129 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_error.rb +103 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +109 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +202 -0
- data/test/tc_message.rb +114 -0
- data/test/tc_presence.rb +148 -0
- data/test/tc_stream.rb +182 -0
- data/test/tc_streamError.rb +87 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamThreaded.rb +168 -0
- data/test/tc_xmlstanza.rb +76 -0
- data/test/ts_xmpp4r.rb +34 -0
- data/test/vcard/tc_iqvcard.rb +52 -0
- data/test/version/tc_helper.rb +46 -0
- data/test/version/tc_iqqueryversion.rb +96 -0
- data/tools/doctoweb.bash +30 -0
- data/tools/gen_requires.bash +10 -0
- metadata +232 -0
@@ -0,0 +1,389 @@
|
|
1
|
+
#!/usr/bin/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/roster/helper/roster'
|
10
|
+
include Jabber
|
11
|
+
|
12
|
+
class Roster::HelperTest < Test::Unit::TestCase
|
13
|
+
include ClientTester
|
14
|
+
|
15
|
+
def test_simple
|
16
|
+
state { |iq|
|
17
|
+
assert_kind_of(Iq, iq)
|
18
|
+
assert_equal(:get, iq.type)
|
19
|
+
assert_nil(iq.to)
|
20
|
+
assert_equal('jabber:iq:roster', iq.queryns)
|
21
|
+
|
22
|
+
send("<iq type='result'><query xmlns='jabber:iq:version'/></iq>")
|
23
|
+
send("<iq type='result' id='#{iq.id}'>
|
24
|
+
<query xmlns='jabber:iq:roster'>
|
25
|
+
<item jid='a@b.c' subscription='both'/>
|
26
|
+
<item jid='b@b.c' name='b guy' subscription='from' ask='subscribe'/>
|
27
|
+
<item jid='123@xyz' name='123' subscription='to'/>
|
28
|
+
</query>
|
29
|
+
</iq>")
|
30
|
+
}
|
31
|
+
|
32
|
+
query_waiter = Mutex.new
|
33
|
+
query_waiter.lock
|
34
|
+
h = Roster::Helper::new(@client)
|
35
|
+
h.add_query_callback { |iq|
|
36
|
+
query_waiter.unlock
|
37
|
+
}
|
38
|
+
wait_state
|
39
|
+
query_waiter.lock
|
40
|
+
|
41
|
+
assert_equal([nil], h.groups)
|
42
|
+
jids = h.find_by_group(nil).collect { |item| item.jid }.sort
|
43
|
+
assert_equal([JID.new('123@xyz'), JID.new('a@b.c'), JID.new('b@b.c')], jids)
|
44
|
+
assert_equal(1, h.find('123@xyz/res').size)
|
45
|
+
|
46
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
47
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
48
|
+
assert_nil(h['a@b.c'].iname)
|
49
|
+
assert_equal(:both, h['a@b.c'].subscription)
|
50
|
+
assert_nil(h['a@b.c'].ask)
|
51
|
+
|
52
|
+
assert_kind_of(Roster::Helper::RosterItem, h[JID.new('b@b.c')])
|
53
|
+
assert_equal(JID.new('b@b.c'), h['b@b.c'].jid)
|
54
|
+
assert_equal('b guy', h['b@b.c'].iname)
|
55
|
+
assert_equal(:from, h['b@b.c'].subscription)
|
56
|
+
assert_equal(:subscribe, h['b@b.c'].ask)
|
57
|
+
|
58
|
+
assert_kind_of(Roster::Helper::RosterItem, h['123@xyz'])
|
59
|
+
assert_equal(JID.new('123@xyz'), h['123@xyz'].jid)
|
60
|
+
assert_equal('123', h['123@xyz'].iname)
|
61
|
+
assert_equal(:to, h['123@xyz'].subscription)
|
62
|
+
assert_nil(h['123@xyz'].ask)
|
63
|
+
|
64
|
+
assert_nil(h['c@b.c'])
|
65
|
+
assert_nil(h[JID.new('c@b.c')])
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_rosterpush
|
69
|
+
state { |iq|
|
70
|
+
send("<iq type='result' id='#{iq.id}'>
|
71
|
+
<query xmlns='jabber:iq:roster'>
|
72
|
+
</query>
|
73
|
+
</iq>")
|
74
|
+
}
|
75
|
+
|
76
|
+
query_waiter = Mutex.new
|
77
|
+
query_waiter.lock
|
78
|
+
h = Roster::Helper::new(@client)
|
79
|
+
h.add_query_callback { |iq| query_waiter.unlock }
|
80
|
+
wait_state
|
81
|
+
query_waiter.lock
|
82
|
+
|
83
|
+
assert_equal([], h.groups)
|
84
|
+
assert_nil(h['a@b.c'])
|
85
|
+
|
86
|
+
send("<iq type='set'>
|
87
|
+
<query xmlns='jabber:iq:roster'>
|
88
|
+
<item jid='a@b.c'/>
|
89
|
+
</query>
|
90
|
+
</iq>")
|
91
|
+
query_waiter.lock
|
92
|
+
|
93
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
94
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
95
|
+
assert_nil(h['a@b.c'].iname)
|
96
|
+
assert_nil(h['a@b.c'].subscription)
|
97
|
+
assert_nil(h['a@b.c'].ask)
|
98
|
+
|
99
|
+
send("<iq type='set'>
|
100
|
+
<query xmlns='jabber:iq:roster'>
|
101
|
+
<item jid='a@b.c' subscription='from' name='ABC' ask='subscribe'/>
|
102
|
+
</query>
|
103
|
+
</iq>")
|
104
|
+
query_waiter.lock
|
105
|
+
|
106
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
107
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
108
|
+
assert_equal('ABC', h['a@b.c'].iname)
|
109
|
+
assert_equal(:from, h['a@b.c'].subscription)
|
110
|
+
assert_equal(:subscribe, h['a@b.c'].ask)
|
111
|
+
|
112
|
+
send("<iq type='set'>
|
113
|
+
<query xmlns='jabber:iq:roster'>
|
114
|
+
<item jid='a@b.c'/>
|
115
|
+
</query>
|
116
|
+
</iq>")
|
117
|
+
query_waiter.lock
|
118
|
+
|
119
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
120
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
121
|
+
assert_nil(h['a@b.c'].iname)
|
122
|
+
assert_nil(h['a@b.c'].subscription)
|
123
|
+
assert_nil(h['a@b.c'].ask)
|
124
|
+
|
125
|
+
send("<iq type='set'>
|
126
|
+
<query xmlns='jabber:iq:roster'>
|
127
|
+
<item jid='a@b.c' subscription='remove'/>
|
128
|
+
</query>
|
129
|
+
</iq>")
|
130
|
+
query_waiter.lock
|
131
|
+
|
132
|
+
assert_nil(h['a@b.c'])
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_presence
|
136
|
+
state { |iq|
|
137
|
+
send("<iq type='result' id='#{iq.id}'>
|
138
|
+
<query xmlns='jabber:iq:roster'>
|
139
|
+
<item jid='a@b.c' subscription='both'/>
|
140
|
+
</query>
|
141
|
+
</iq>")
|
142
|
+
}
|
143
|
+
|
144
|
+
query_waiter = Mutex.new
|
145
|
+
query_waiter.lock
|
146
|
+
presence_waiter = Mutex.new
|
147
|
+
presence_waiter.lock
|
148
|
+
h = Roster::Helper::new(@client)
|
149
|
+
h.add_query_callback { |iq|
|
150
|
+
query_waiter.unlock
|
151
|
+
}
|
152
|
+
cb_item, cb_op, cb_p = nil, nil, nil
|
153
|
+
h.add_presence_callback { |item,oldpres,pres|
|
154
|
+
cb_item, cb_op, cb_p = item, oldpres, pres
|
155
|
+
presence_waiter.unlock
|
156
|
+
}
|
157
|
+
|
158
|
+
wait_state
|
159
|
+
query_waiter.lock
|
160
|
+
|
161
|
+
assert_equal(false, h['a@b.c'].online?)
|
162
|
+
presences = 0
|
163
|
+
h['a@b.c'].each_presence { presences += 1 }
|
164
|
+
assert_equal(0, presences)
|
165
|
+
|
166
|
+
send("<presence from='a@b.c/r'/>")
|
167
|
+
presence_waiter.lock
|
168
|
+
|
169
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
170
|
+
assert_nil(cb_op)
|
171
|
+
assert_kind_of(Presence, cb_p)
|
172
|
+
assert_nil(cb_p.type)
|
173
|
+
assert_equal(true, h['a@b.c'].online?)
|
174
|
+
presences = 0
|
175
|
+
h['a@b.c'].each_presence { presences += 1 }
|
176
|
+
assert_equal(1, presences)
|
177
|
+
|
178
|
+
send("<presence from='a@b.c/r2'/>")
|
179
|
+
presence_waiter.lock
|
180
|
+
|
181
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
182
|
+
assert_nil(cb_op)
|
183
|
+
assert_kind_of(Presence, cb_p)
|
184
|
+
assert_nil(cb_p.type)
|
185
|
+
assert_equal(true, h['a@b.c'].online?)
|
186
|
+
presences = 0
|
187
|
+
h['a@b.c'].each_presence { presences += 1 }
|
188
|
+
assert_equal(2, presences)
|
189
|
+
|
190
|
+
send("<presence from='a@b.c/r'/>")
|
191
|
+
presence_waiter.lock
|
192
|
+
|
193
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
194
|
+
assert_kind_of(Presence, cb_op)
|
195
|
+
assert_nil(cb_op.type)
|
196
|
+
assert_kind_of(Presence, cb_p)
|
197
|
+
assert_nil(cb_p.type)
|
198
|
+
assert_equal(true, h['a@b.c'].online?)
|
199
|
+
presences = 0
|
200
|
+
h['a@b.c'].each_presence { presences += 1 }
|
201
|
+
assert_equal(2, presences)
|
202
|
+
|
203
|
+
send("<presence from='a@b.c/r' type='error'/>")
|
204
|
+
presence_waiter.lock
|
205
|
+
|
206
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
207
|
+
assert_kind_of(Presence, cb_op)
|
208
|
+
assert_nil(cb_op.type)
|
209
|
+
assert_kind_of(Presence, cb_p)
|
210
|
+
assert_equal(:error, cb_p.type)
|
211
|
+
assert_equal(true, h['a@b.c'].online?)
|
212
|
+
presences = 0
|
213
|
+
h['a@b.c'].each_presence { presences += 1 }
|
214
|
+
assert_equal(2, presences)
|
215
|
+
|
216
|
+
send("<presence from='a@b.c/r2' type='unavailable'/>")
|
217
|
+
presence_waiter.lock
|
218
|
+
|
219
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
220
|
+
assert_kind_of(Presence, cb_op)
|
221
|
+
assert_nil(cb_op.type)
|
222
|
+
assert_kind_of(Presence, cb_p)
|
223
|
+
assert_equal(:unavailable, cb_p.type)
|
224
|
+
assert_equal(false, h['a@b.c'].online?)
|
225
|
+
presences = 0
|
226
|
+
h['a@b.c'].each_presence { presences += 1 }
|
227
|
+
assert_equal(2, presences)
|
228
|
+
|
229
|
+
send("<presence from='a@b.c/r'/>")
|
230
|
+
presence_waiter.lock
|
231
|
+
|
232
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
233
|
+
assert_kind_of(Presence, cb_op)
|
234
|
+
assert_equal(:error, cb_op.type)
|
235
|
+
assert_kind_of(Presence, cb_p)
|
236
|
+
assert_nil(cb_p.type)
|
237
|
+
assert_equal(true, h['a@b.c'].online?)
|
238
|
+
presences = 0
|
239
|
+
h['a@b.c'].each_presence { presences += 1 }
|
240
|
+
assert_equal(2, presences)
|
241
|
+
|
242
|
+
send("<presence from='a@b.c/r2'/>")
|
243
|
+
presence_waiter.lock
|
244
|
+
|
245
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
246
|
+
assert_kind_of(Presence, cb_op)
|
247
|
+
assert_equal(:unavailable, cb_op.type)
|
248
|
+
assert_kind_of(Presence, cb_p)
|
249
|
+
assert_nil(cb_p.type)
|
250
|
+
assert_equal(true, h['a@b.c'].online?)
|
251
|
+
presences = 0
|
252
|
+
h['a@b.c'].each_presence { presences += 1 }
|
253
|
+
assert_equal(2, presences)
|
254
|
+
|
255
|
+
send("<presence from='a@b.c' type='error'/>")
|
256
|
+
2.times {
|
257
|
+
presence_waiter.lock
|
258
|
+
|
259
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
260
|
+
assert_kind_of(Presence, cb_op)
|
261
|
+
assert_kind_of(Presence, cb_p)
|
262
|
+
assert_equal(:error, cb_p.type)
|
263
|
+
}
|
264
|
+
assert_equal(false, h['a@b.c'].online?)
|
265
|
+
presences = 0
|
266
|
+
h['a@b.c'].each_presence { presences += 1 }
|
267
|
+
assert_equal(1, presences)
|
268
|
+
|
269
|
+
send("<presence from='a@b.c/r'/>")
|
270
|
+
presence_waiter.lock
|
271
|
+
|
272
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
273
|
+
assert_nil(cb_op)
|
274
|
+
assert_kind_of(Presence, cb_p)
|
275
|
+
assert_nil(cb_p.type)
|
276
|
+
assert_equal(true, h['a@b.c'].online?)
|
277
|
+
presences = 0
|
278
|
+
h['a@b.c'].each_presence { presences += 1 }
|
279
|
+
assert_equal(1, presences)
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_subscribe
|
283
|
+
state { |iq|
|
284
|
+
send("<iq type='result' id='#{iq.id}'>
|
285
|
+
<query xmlns='jabber:iq:roster'/>
|
286
|
+
</iq>")
|
287
|
+
}
|
288
|
+
|
289
|
+
query_waiter = Mutex.new
|
290
|
+
query_waiter.lock
|
291
|
+
h = Roster::Helper::new(@client)
|
292
|
+
h.add_query_callback { |iq| query_waiter.unlock }
|
293
|
+
wait_state
|
294
|
+
query_waiter.lock
|
295
|
+
|
296
|
+
state { |iq|
|
297
|
+
assert_kind_of(Iq, iq)
|
298
|
+
assert_equal('jabber:iq:roster', iq.queryns)
|
299
|
+
assert_equal(JID.new('contact@example.org'), iq.query.first_element('item').jid)
|
300
|
+
assert_equal('MyContact', iq.query.first_element('item').iname)
|
301
|
+
send("<iq type='set'>
|
302
|
+
<query xmlns='jabber:iq:roster'>
|
303
|
+
<item jid='contact@example.org' subscription='none' name='MyContact'/>
|
304
|
+
</query>
|
305
|
+
</iq>
|
306
|
+
<iq type='result' id='#{iq.id}'/>")
|
307
|
+
}
|
308
|
+
state { |pres|
|
309
|
+
assert_kind_of(Presence, pres)
|
310
|
+
assert_equal(:subscribe, pres.type)
|
311
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
312
|
+
}
|
313
|
+
h.add('contact@example.org', 'MyContact', true)
|
314
|
+
wait_state
|
315
|
+
query_waiter.lock
|
316
|
+
wait_state
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_accept_subscription
|
320
|
+
state { |iq|
|
321
|
+
send("<iq type='result' id='#{iq.id}'>
|
322
|
+
<query xmlns='jabber:iq:roster'/>
|
323
|
+
</iq>")
|
324
|
+
}
|
325
|
+
|
326
|
+
query_waiter = Mutex.new
|
327
|
+
query_waiter.lock
|
328
|
+
h = Roster::Helper::new(@client)
|
329
|
+
h.add_query_callback { |iq| query_waiter.unlock }
|
330
|
+
wait_state
|
331
|
+
query_waiter.lock
|
332
|
+
|
333
|
+
cb_lock = Mutex.new
|
334
|
+
cb_lock.lock
|
335
|
+
h.add_subscription_request_callback { |item,pres|
|
336
|
+
assert_nil(item)
|
337
|
+
assert_kind_of(Presence, pres)
|
338
|
+
h.accept_subscription(pres.from)
|
339
|
+
|
340
|
+
cb_lock.unlock
|
341
|
+
}
|
342
|
+
|
343
|
+
send("<presence type='subscribe' from='contact@example.org' to='user@example.com'/>")
|
344
|
+
cb_lock.lock
|
345
|
+
|
346
|
+
state { |pres|
|
347
|
+
assert_kind_of(Presence, pres)
|
348
|
+
assert_equal(:subscribed, pres.type)
|
349
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
350
|
+
}
|
351
|
+
wait_state
|
352
|
+
end
|
353
|
+
|
354
|
+
def test_decline_subscription
|
355
|
+
state { |iq|
|
356
|
+
send("<iq type='result' id='#{iq.id}'>
|
357
|
+
<query xmlns='jabber:iq:roster'/>
|
358
|
+
</iq>")
|
359
|
+
}
|
360
|
+
|
361
|
+
query_waiter = Mutex.new
|
362
|
+
query_waiter.lock
|
363
|
+
h = Roster::Helper::new(@client)
|
364
|
+
h.add_query_callback { |iq| query_waiter.unlock }
|
365
|
+
wait_state
|
366
|
+
query_waiter.lock
|
367
|
+
|
368
|
+
cb_lock = Mutex.new
|
369
|
+
cb_lock.lock
|
370
|
+
h.add_subscription_request_callback { |item,pres|
|
371
|
+
assert_nil(item)
|
372
|
+
assert_kind_of(Presence, pres)
|
373
|
+
h.decline_subscription(pres.from)
|
374
|
+
|
375
|
+
cb_lock.unlock
|
376
|
+
}
|
377
|
+
|
378
|
+
send("<presence type='subscribe' from='contact@example.org' to='user@example.com'/>")
|
379
|
+
cb_lock.lock
|
380
|
+
|
381
|
+
state { |pres|
|
382
|
+
assert_kind_of(Presence, pres)
|
383
|
+
assert_equal(:unsubscribed, pres.type)
|
384
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
385
|
+
}
|
386
|
+
wait_state
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/rexmladdons'
|
7
|
+
require 'xmpp4r/roster/iq/roster'
|
8
|
+
include Jabber
|
9
|
+
|
10
|
+
class Roster::IqQueryRosterTest < Test::Unit::TestCase
|
11
|
+
def test_create
|
12
|
+
r = Roster::IqQueryRoster::new
|
13
|
+
assert_equal('jabber:iq:roster', r.namespace)
|
14
|
+
assert_equal(r.to_a.size, 0)
|
15
|
+
assert_equal(r.to_a, [])
|
16
|
+
assert_equal(r.to_s, "<query xmlns='jabber:iq:roster'/>")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_import
|
20
|
+
iq = Iq::new
|
21
|
+
q = REXML::Element::new('query')
|
22
|
+
q.add_namespace('jabber:iq:roster')
|
23
|
+
iq.add(q)
|
24
|
+
iq2 = Iq::new.import(iq)
|
25
|
+
assert_equal(Roster::IqQueryRoster, iq2.query.class)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_items
|
29
|
+
r = Roster::IqQueryRoster::new
|
30
|
+
r.add(Roster::RosterItem.new)
|
31
|
+
r.add(Roster::RosterItem.new(JID.new('a@b/d'), 'ABC', :none, :subscribe)).groups = ['a']
|
32
|
+
itemstr = "<item jid='astro@spaceboyz.net' name='Astro' subscribtion='both'>" \
|
33
|
+
+ "<group>SpaceBoyZ</group><group>xmpp4r</group></item>"
|
34
|
+
r.typed_add(REXML::Document.new(itemstr).root)
|
35
|
+
|
36
|
+
r.each { |item|
|
37
|
+
assert_equal(item, r[item.jid])
|
38
|
+
}
|
39
|
+
|
40
|
+
r.to_a.each { |item|
|
41
|
+
assert_equal(item, r[item.jid])
|
42
|
+
}
|
43
|
+
|
44
|
+
assert_equal(JID.new, r.to_a[0].jid)
|
45
|
+
assert_equal(nil, r.to_a[0].iname)
|
46
|
+
assert_equal(nil, r.to_a[0].subscription)
|
47
|
+
assert_equal(nil, r.to_a[0].ask)
|
48
|
+
|
49
|
+
assert_equal(JID.new('a@b/d'), r.to_a[1].jid)
|
50
|
+
assert_equal('ABC', r.to_a[1].iname)
|
51
|
+
assert_equal(:none, r.to_a[1].subscription)
|
52
|
+
assert_equal(:subscribe, r.to_a[1].ask)
|
53
|
+
|
54
|
+
assert_equal(REXML::Document.new(itemstr).root.to_s, r.to_a[2].to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_dupitems
|
58
|
+
r = Roster::IqQueryRoster::new
|
59
|
+
jid = JID::new('a@b')
|
60
|
+
jid2 = JID::new('c@d')
|
61
|
+
ri = Roster::RosterItem::new(jid, 'ab')
|
62
|
+
r.add(ri)
|
63
|
+
assert_equal('ab', ri.iname)
|
64
|
+
assert_equal('ab', r[jid].iname)
|
65
|
+
ri.iname = 'cd'
|
66
|
+
assert_equal('cd', ri.iname)
|
67
|
+
# There are no shallow copies - everything is alright.
|
68
|
+
assert_equal('cd', r[jid].iname)
|
69
|
+
|
70
|
+
r.add(ri)
|
71
|
+
assert_equal('cd', r[jid].iname)
|
72
|
+
assert_equal(ri, r[jid])
|
73
|
+
|
74
|
+
ri.jid = jid2
|
75
|
+
assert_equal(nil, r[jid])
|
76
|
+
assert_equal(ri, r[jid2])
|
77
|
+
assert_equal(2, r.to_a.size)
|
78
|
+
|
79
|
+
r.each_element('item') { |item|
|
80
|
+
assert_equal(ri, item)
|
81
|
+
assert_equal(ri.jid, item.jid)
|
82
|
+
assert_equal(ri.iname, item.iname)
|
83
|
+
assert_equal(jid2, item.jid)
|
84
|
+
assert_equal('cd', item.iname)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Roster::RosterItemTest < Test::Unit::TestCase
|
90
|
+
def test_create
|
91
|
+
ri = Roster::RosterItem::new
|
92
|
+
assert_equal(JID.new, ri.jid)
|
93
|
+
assert_equal(nil, ri.iname)
|
94
|
+
assert_equal(nil, ri.subscription)
|
95
|
+
assert_equal(nil, ri.ask)
|
96
|
+
|
97
|
+
ri = Roster::RosterItem::new(JID.new('a@b/c'), 'xyz', :both, nil)
|
98
|
+
assert_equal(JID.new('a@b/c'), ri.jid)
|
99
|
+
assert_equal('xyz', ri.iname)
|
100
|
+
assert_equal(:both, ri.subscription)
|
101
|
+
assert_equal(nil, ri.ask)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_modify
|
105
|
+
ri = Roster::RosterItem::new(JID.new('a@b/c'), 'xyz', :both, :subscribe)
|
106
|
+
|
107
|
+
assert_equal(JID.new('a@b/c'), ri.jid)
|
108
|
+
ri.jid = nil
|
109
|
+
assert_equal(JID::new, ri.jid)
|
110
|
+
|
111
|
+
assert_equal('xyz', ri.iname)
|
112
|
+
ri.iname = nil
|
113
|
+
assert_equal(nil, ri.iname)
|
114
|
+
|
115
|
+
assert_equal(:both, ri.subscription)
|
116
|
+
ri.subscription = nil
|
117
|
+
assert_equal(nil, ri.subscription)
|
118
|
+
|
119
|
+
assert_equal(:subscribe, ri.ask)
|
120
|
+
ri.ask = nil
|
121
|
+
assert_equal(nil, ri.ask)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_groupdeletion
|
125
|
+
ri = Roster::RosterItem::new
|
126
|
+
g1 = ['a', 'b', 'c']
|
127
|
+
ri.groups = g1
|
128
|
+
assert_equal(g1, ri.groups.sort)
|
129
|
+
g2 = ['c', 'd', 'e']
|
130
|
+
ri.groups = g2
|
131
|
+
assert_equal(g2, ri.groups.sort)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_dupgroups
|
135
|
+
ri = Roster::RosterItem::new
|
136
|
+
mygroups = ['a', 'a', 'b']
|
137
|
+
ri.groups = mygroups
|
138
|
+
assert_equal(mygroups.uniq, ri.groups)
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/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
|
+
r = Roster::XRoster.new
|
14
|
+
assert_equal('x', r.name)
|
15
|
+
assert_equal('http://jabber.org/protocol/rosterx', r.namespace)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_import
|
19
|
+
x1 = X.new
|
20
|
+
x1.add_namespace('jabber:x:roster')
|
21
|
+
x2 = X::import(x1)
|
22
|
+
assert_equal(Roster::XRoster, x2.class)
|
23
|
+
assert_equal('jabber:x:roster', x2.namespace)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_typed_add
|
27
|
+
x = REXML::Element.new('x')
|
28
|
+
x.add(REXML::Element.new('item'))
|
29
|
+
r = Roster::XRoster.new.import(x)
|
30
|
+
assert_kind_of(Roster::XRosterItem, r.first_element('item'))
|
31
|
+
assert_kind_of(Roster::XRosterItem, r.typed_add(REXML::Element.new('item')))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_items
|
35
|
+
j1 = Roster::XRosterItem.new
|
36
|
+
assert_equal(JID.new(nil), j1.jid)
|
37
|
+
assert_equal(nil, j1.iname)
|
38
|
+
|
39
|
+
j2 = Roster::XRosterItem.new(JID.new('a@b/c'))
|
40
|
+
assert_equal(JID.new('a@b/c'), j2.jid)
|
41
|
+
assert_equal(nil, j2.iname)
|
42
|
+
j3 = Roster::XRosterItem.new(JID.new('a@b/c'), 'Mr. Abc')
|
43
|
+
assert_equal(JID.new('a@b/c'), j3.jid)
|
44
|
+
assert_equal('Mr. Abc', j3.iname)
|
45
|
+
assert_equal([], j3.groups)
|
46
|
+
|
47
|
+
j3.groups = ['X', 'Y', 'Z']
|
48
|
+
assert_equal(['X', 'Y', 'Z'], j3.groups)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_actions
|
52
|
+
j = Roster::XRosterItem.new
|
53
|
+
assert_equal(:add, j.action)
|
54
|
+
|
55
|
+
j.action = :modify
|
56
|
+
assert_equal(:modify, j.action)
|
57
|
+
|
58
|
+
j.action = :delete
|
59
|
+
assert_equal(:delete, j.action)
|
60
|
+
|
61
|
+
j.action = :invalid
|
62
|
+
assert_equal(:add, j.action)
|
63
|
+
|
64
|
+
j.attributes['action'] = 'modify'
|
65
|
+
assert_equal(:modify, j.action)
|
66
|
+
|
67
|
+
j.attributes['action'] = 'invalid'
|
68
|
+
assert_equal(:add, j.action)
|
69
|
+
end
|
70
|
+
end
|