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,128 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'callbacks'
|
7
|
+
|
8
|
+
class CallbacksTest < Test::Unit::TestCase
|
9
|
+
def test_test1
|
10
|
+
called = 0
|
11
|
+
cb = Callback::new(5, "toto", Proc::new { called += 1 })
|
12
|
+
assert_equal(5, cb.priority)
|
13
|
+
assert_equal("toto", cb.ref)
|
14
|
+
cb.block.call
|
15
|
+
assert_equal(1, called)
|
16
|
+
cb.block.call
|
17
|
+
assert_equal(2, called)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_callbacklist1
|
21
|
+
cbl = CallbackList::new
|
22
|
+
called1 = false
|
23
|
+
called2 = false
|
24
|
+
called3 = false
|
25
|
+
called4 = false
|
26
|
+
cbl.add(5, "ref1") { called1 = true ; true }
|
27
|
+
cbl.add(7, "ref1") { |e| called2 = true ; false}
|
28
|
+
cbl.add(9, "ref1") { called3 = true ;false }
|
29
|
+
cbl.add(11, "ref1") { called4 = true ; false }
|
30
|
+
o = "aaaa"
|
31
|
+
assert(cbl.process(o))
|
32
|
+
assert(called1)
|
33
|
+
assert(called2)
|
34
|
+
assert(called3)
|
35
|
+
assert(called4)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_callbacklist2
|
39
|
+
cbl = CallbackList::new
|
40
|
+
assert(0, cbl.length)
|
41
|
+
cbl.add(5, "ref1") { called1 = true }
|
42
|
+
assert(1, cbl.length)
|
43
|
+
cbl.add(7, "ref2") { |e| called2 = true ; e.consume }
|
44
|
+
assert(2, cbl.length)
|
45
|
+
cbl.delete("ref2")
|
46
|
+
assert(1, cbl.length)
|
47
|
+
cbl.add(9, "ref3") { called3 = true }
|
48
|
+
assert(2, cbl.length)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_callbacklist4
|
52
|
+
cbl = CallbackList::new
|
53
|
+
cbl.add(5, "ref1") { false }
|
54
|
+
cbl.add(7, "ref1") { false }
|
55
|
+
o = "o"
|
56
|
+
assert(!cbl.process(o))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_callbacklist5
|
60
|
+
cbl = CallbackList::new
|
61
|
+
cbl.add(5, "ref1") { true }
|
62
|
+
cbl.add(7, "ref1") { false }
|
63
|
+
o = "o"
|
64
|
+
assert(cbl.process(o))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_callbacklist6
|
68
|
+
cbl = CallbackList::new
|
69
|
+
ok = false
|
70
|
+
c = 'a'
|
71
|
+
d = 'b'
|
72
|
+
cbl.add(5, "ref1") { |a, b|
|
73
|
+
if a == 'a' and b == 'b'
|
74
|
+
ok = true
|
75
|
+
end
|
76
|
+
false
|
77
|
+
}
|
78
|
+
assert(!cbl.process(c, d))
|
79
|
+
assert(ok)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_callbacklist7
|
83
|
+
cbl = CallbackList::new
|
84
|
+
called1 = false
|
85
|
+
called2 = false
|
86
|
+
called3 = false
|
87
|
+
called4 = false
|
88
|
+
cbl.add(3, "ref1") { called4 = true ; true }
|
89
|
+
cbl.add(5, "ref1") { called1 = true ; true }
|
90
|
+
cbl.add(7, "ref1") { called2 = true ; 'a'}
|
91
|
+
cbl.add(9, "ref1") { called3 = true ;1 }
|
92
|
+
o = "aaaa"
|
93
|
+
assert(cbl.process(o))
|
94
|
+
assert(called1)
|
95
|
+
assert(called2)
|
96
|
+
assert(called3)
|
97
|
+
assert(!called4)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_nested
|
101
|
+
cbl = CallbackList.new
|
102
|
+
called_outer = 0
|
103
|
+
called_inner = 0
|
104
|
+
|
105
|
+
cbl.add(100, nil) {
|
106
|
+
called_outer += 1
|
107
|
+
|
108
|
+
if called_outer == 1
|
109
|
+
cbl.add(200, nil) {
|
110
|
+
called_inner += 1
|
111
|
+
}
|
112
|
+
end
|
113
|
+
}
|
114
|
+
|
115
|
+
assert_equal(0, called_inner)
|
116
|
+
assert_equal(0, called_outer)
|
117
|
+
|
118
|
+
cbl.process
|
119
|
+
|
120
|
+
assert_equal(0, called_inner)
|
121
|
+
assert_equal(1, called_outer)
|
122
|
+
|
123
|
+
cbl.process
|
124
|
+
|
125
|
+
assert_equal(1, called_inner)
|
126
|
+
assert_equal(2, called_outer)
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r'
|
7
|
+
# No include Jabber, test full namespace
|
8
|
+
|
9
|
+
class JIDTest < Test::Unit::TestCase
|
10
|
+
def test_base
|
11
|
+
assert_kind_of(Module, Jabber)
|
12
|
+
assert_kind_of(Class, Jabber::AuthenticationFailure)
|
13
|
+
assert_kind_of(Class, Jabber::Client)
|
14
|
+
assert_kind_of(Class, Jabber::Component)
|
15
|
+
assert_kind_of(Class, Jabber::Connection)
|
16
|
+
assert_kind_of(Class, Jabber::Error)
|
17
|
+
assert_kind_of(Class, Jabber::ErrorException)
|
18
|
+
assert_kind_of(Class, Jabber::IdGenerator)
|
19
|
+
assert_kind_of(Class, Jabber::Iq)
|
20
|
+
assert_kind_of(Class, Jabber::IqQuery)
|
21
|
+
assert_kind_of(Class, Jabber::JID)
|
22
|
+
assert_kind_of(Class, Jabber::Message)
|
23
|
+
assert_kind_of(Class, Jabber::Presence)
|
24
|
+
assert_kind_of(Module, Jabber::SASL)
|
25
|
+
assert_respond_to(Jabber::SASL, :new)
|
26
|
+
assert_kind_of(Class, Jabber::SASL::Base)
|
27
|
+
assert_kind_of(Class, Jabber::SASL::Plain)
|
28
|
+
assert_kind_of(Class, Jabber::SASL::DigestMD5)
|
29
|
+
assert_kind_of(Class, Jabber::Stream)
|
30
|
+
assert_kind_of(Class, Jabber::StreamParser)
|
31
|
+
assert_kind_of(Class, Jabber::X)
|
32
|
+
assert_kind_of(Class, Jabber::XMLStanza)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_roster
|
36
|
+
require 'xmpp4r/roster'
|
37
|
+
assert_kind_of(Module, Jabber::Roster)
|
38
|
+
assert_kind_of(Class, Jabber::Roster::Helper)
|
39
|
+
assert_kind_of(Class, Jabber::Roster::Helper::RosterItem)
|
40
|
+
assert_kind_of(Class, Jabber::Roster::RosterItem)
|
41
|
+
assert_kind_of(Class, Jabber::Roster::IqQueryRoster)
|
42
|
+
assert_kind_of(Class, Jabber::Roster::XRoster)
|
43
|
+
assert_kind_of(Class, Jabber::Roster::XRosterItem)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_muc
|
47
|
+
require 'xmpp4r/muc'
|
48
|
+
assert_kind_of(Module, Jabber::MUC)
|
49
|
+
assert_kind_of(Class, Jabber::MUC::MUCBrowser)
|
50
|
+
assert_kind_of(Class, Jabber::MUC::MUCClient)
|
51
|
+
assert_kind_of(Class, Jabber::MUC::SimpleMUCClient)
|
52
|
+
assert_kind_of(Class, Jabber::MUC::XMUC)
|
53
|
+
assert_kind_of(Class, Jabber::MUC::XMUCUser)
|
54
|
+
assert_kind_of(Class, Jabber::MUC::XMUCUserInvite)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_bytestreams
|
58
|
+
require 'xmpp4r/bytestreams'
|
59
|
+
assert_kind_of(Module, Jabber::FileTransfer)
|
60
|
+
assert_kind_of(Module, Jabber::FileTransfer::TransferSource)
|
61
|
+
assert_kind_of(Class, Jabber::FileTransfer::FileSource)
|
62
|
+
assert_kind_of(Class, Jabber::FileTransfer::Helper)
|
63
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsServer)
|
64
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost)
|
65
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsPeer)
|
66
|
+
assert_kind_of(Class, Jabber::Bytestreams::IqQueryBytestreams)
|
67
|
+
assert_kind_of(Class, Jabber::Bytestreams::StreamHost)
|
68
|
+
assert_kind_of(Class, Jabber::Bytestreams::StreamHostUsed)
|
69
|
+
assert_kind_of(Class, Jabber::Bytestreams::IqSi)
|
70
|
+
assert_kind_of(Class, Jabber::Bytestreams::IqSiFile)
|
71
|
+
assert_kind_of(Class, Jabber::Bytestreams::IqSiFileRange)
|
72
|
+
assert_kind_of(Class, Jabber::Bytestreams::IBB)
|
73
|
+
assert_kind_of(Class, Jabber::Bytestreams::IBBQueueItem)
|
74
|
+
assert_kind_of(Class, Jabber::Bytestreams::IBBInitiator)
|
75
|
+
assert_kind_of(Class, Jabber::Bytestreams::IBBTarget)
|
76
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5Bytestreams)
|
77
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsInitiator)
|
78
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsTarget)
|
79
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5Error)
|
80
|
+
assert_kind_of(Class, Jabber::Bytestreams::SOCKS5Socket)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_dataforms
|
84
|
+
require 'xmpp4r/dataforms'
|
85
|
+
assert_kind_of(Module, Jabber::Dataforms)
|
86
|
+
assert_kind_of(Class, Jabber::Dataforms::XData)
|
87
|
+
assert_kind_of(Class, Jabber::Dataforms::XDataTitle)
|
88
|
+
assert_kind_of(Class, Jabber::Dataforms::XDataInstructions)
|
89
|
+
assert_kind_of(Class, Jabber::Dataforms::XDataField)
|
90
|
+
assert_kind_of(Class, Jabber::Dataforms::XDataReported)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_delay
|
94
|
+
require 'xmpp4r/delay'
|
95
|
+
assert_kind_of(Module, Jabber::Delay)
|
96
|
+
assert_kind_of(Class, Jabber::Delay::XDelay)
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_discovery
|
100
|
+
require 'xmpp4r/discovery'
|
101
|
+
assert_kind_of(Module, Jabber::Discovery)
|
102
|
+
assert_kind_of(Class, Jabber::Discovery::IqQueryDiscoInfo)
|
103
|
+
assert_kind_of(Class, Jabber::Discovery::Identity)
|
104
|
+
assert_kind_of(Class, Jabber::Discovery::Feature)
|
105
|
+
assert_kind_of(Class, Jabber::Discovery::IqQueryDiscoItems)
|
106
|
+
assert_kind_of(Class, Jabber::Discovery::Item)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_feature_negotiation
|
110
|
+
require 'xmpp4r/feature_negotiation'
|
111
|
+
assert_kind_of(Module, Jabber::FeatureNegotiation)
|
112
|
+
assert_kind_of(Class, Jabber::FeatureNegotiation::IqFeature)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_vcard
|
116
|
+
require 'xmpp4r/vcard'
|
117
|
+
assert_kind_of(Module, Jabber::Vcard)
|
118
|
+
assert_kind_of(Class, Jabber::Vcard::Helper)
|
119
|
+
assert_kind_of(Class, Jabber::Vcard::IqVcard)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_version
|
123
|
+
require 'xmpp4r/version'
|
124
|
+
assert_kind_of(Module, Jabber::Version)
|
125
|
+
assert_kind_of(Class, Jabber::Version::Responder)
|
126
|
+
assert_kind_of(Class, Jabber::Version::SimpleResponder)
|
127
|
+
assert_kind_of(Class, Jabber::Version::IqQueryVersion)
|
128
|
+
end
|
129
|
+
end
|
data/test/tc_client.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/client'
|
7
|
+
include Jabber
|
8
|
+
|
9
|
+
class ClientTest < Test::Unit::TestCase
|
10
|
+
def test_client1
|
11
|
+
=begin
|
12
|
+
c = Client::new(JID::new('client1@localhost/res'))
|
13
|
+
assert_nothing_raised("Couldn't connect") {
|
14
|
+
c.connect
|
15
|
+
}
|
16
|
+
assert_nothing_raised("Couldn't authenticate") {
|
17
|
+
c.auth('pw')
|
18
|
+
}
|
19
|
+
=end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_jid_is_jid
|
23
|
+
c1 = Client::new(JID::new('user@host/resource'))
|
24
|
+
assert_kind_of(JID, c1.jid)
|
25
|
+
assert_equal('user@host/resource', c1.jid.to_s)
|
26
|
+
c2 = Client::new('user@host/resource')
|
27
|
+
assert_kind_of(JID, c2.jid)
|
28
|
+
assert_equal('user@host/resource', c2.jid.to_s)
|
29
|
+
end
|
30
|
+
end
|
data/test/tc_error.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/rexmladdons'
|
7
|
+
require 'xmpp4r/error'
|
8
|
+
require 'xmpp4r/message'
|
9
|
+
include Jabber
|
10
|
+
|
11
|
+
class ErrorTest < Test::Unit::TestCase
|
12
|
+
def test_create
|
13
|
+
e = Error::new
|
14
|
+
assert_equal(nil, e.error)
|
15
|
+
assert_equal(nil, e.code)
|
16
|
+
assert_equal(nil, e.type)
|
17
|
+
assert_equal(nil, e.text)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_create2
|
21
|
+
e = Error::new('payment-required')
|
22
|
+
assert_equal('payment-required', e.error)
|
23
|
+
assert_equal(402, e.code)
|
24
|
+
assert_equal(:auth, e.type)
|
25
|
+
assert_equal(nil, e.text)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_create3
|
29
|
+
e = Error::new('gone', 'User moved to afterlife.gov')
|
30
|
+
assert_equal('gone', e.error)
|
31
|
+
assert_equal(302, e.code)
|
32
|
+
assert_equal(:modify, e.type)
|
33
|
+
assert_equal('User moved to afterlife.gov', e.text)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_create_invalid
|
37
|
+
assert_raise(RuntimeError) {
|
38
|
+
e = Error::new('invalid error')
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_type
|
43
|
+
e = Error::new
|
44
|
+
assert_nil(e.type)
|
45
|
+
e.type = :auth
|
46
|
+
assert_equal(:auth, e.type)
|
47
|
+
e.type = :cancel
|
48
|
+
assert_equal(:cancel, e.type)
|
49
|
+
e.type = :continue
|
50
|
+
assert_equal(:continue, e.type)
|
51
|
+
e.type = :modify
|
52
|
+
assert_equal(:modify, e.type)
|
53
|
+
e.type = :wait
|
54
|
+
assert_equal(:wait, e.type)
|
55
|
+
e.type = nil
|
56
|
+
assert_nil(e.type)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_code
|
60
|
+
e = Error::new
|
61
|
+
assert_nil(e.code)
|
62
|
+
e.code = 404
|
63
|
+
assert_equal(404, e.code)
|
64
|
+
assert_equal("<error code='404'/>", e.to_s)
|
65
|
+
e.code = nil
|
66
|
+
assert_nil(e.code)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_error
|
70
|
+
e = Error::new
|
71
|
+
assert_nil(e.error)
|
72
|
+
e.error = 'gone'
|
73
|
+
assert_equal('gone', e.error)
|
74
|
+
assert_raise(RuntimeError) {
|
75
|
+
e.error = nil
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_stanzas
|
80
|
+
m = Message.new
|
81
|
+
assert_equal(nil, m.error)
|
82
|
+
m.typed_add(Error.new)
|
83
|
+
assert_equal('<error/>', m.error.to_s)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_sample_normal
|
87
|
+
src = '<error code="302" type="modify"><gone xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">...</text></error>'
|
88
|
+
e = Error.new.import(REXML::Document.new(src).root)
|
89
|
+
assert_equal(:modify, e.type)
|
90
|
+
assert_equal(302, e.code)
|
91
|
+
assert_equal('gone', e.error)
|
92
|
+
assert_equal('...', e.text)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_sample_muc
|
96
|
+
src = '<error code="409">Please choose a different nickname.</error>'
|
97
|
+
e = Error.new.import(REXML::Document.new(src).root)
|
98
|
+
assert_equal(nil, e.type)
|
99
|
+
assert_equal(409, e.code)
|
100
|
+
assert_equal(nil, e.error)
|
101
|
+
assert_equal('Please choose a different nickname.', e.text)
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/idgenerator'
|
7
|
+
include Jabber
|
8
|
+
|
9
|
+
class IdGeneratorTest < Test::Unit::TestCase
|
10
|
+
def test_instances
|
11
|
+
assert_equal(Jabber::IdGenerator.instance, Jabber::IdGenerator.instance)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_unique
|
15
|
+
ids = []
|
16
|
+
100.times { ids.push(Jabber::IdGenerator.generate_id) }
|
17
|
+
|
18
|
+
ok = true
|
19
|
+
ids.each_index { |a|
|
20
|
+
ids.each_index { |b|
|
21
|
+
if a == b
|
22
|
+
ok = false if ids[a] != ids[b]
|
23
|
+
else
|
24
|
+
ok = false if ids[a] == ids[b]
|
25
|
+
end
|
26
|
+
}
|
27
|
+
}
|
28
|
+
assert(ok)
|
29
|
+
end
|
30
|
+
end
|
data/test/tc_iq.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'socket'
|
7
|
+
require 'xmpp4r/rexmladdons'
|
8
|
+
require 'xmpp4r/iq'
|
9
|
+
include Jabber
|
10
|
+
|
11
|
+
class IqTest < Test::Unit::TestCase
|
12
|
+
def test_create
|
13
|
+
x = Iq::new()
|
14
|
+
assert_equal("iq", x.name)
|
15
|
+
assert_equal("<iq/>", x.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_iqauth
|
19
|
+
x = Iq::new_authset(JID::new('node@domain/resource'), 'password')
|
20
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:auth'><username>node</username><password>password</password><resource>resource</resource></query></iq>", x.to_s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_iqauth_digest
|
24
|
+
x = Iq::new_authset_digest(JID::new('node@domain/resource'), '', 'password')
|
25
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:auth'><username>node</username><digest>#{Digest::SHA1.new('password').hexdigest}</digest><resource>resource</resource></query></iq>", x.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_register
|
29
|
+
x1 = Iq::new_register
|
30
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:register'/></iq>", x1.to_s)
|
31
|
+
x2 = Iq::new_register('node')
|
32
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:register'><username>node</username></query></iq>", x2.to_s)
|
33
|
+
x3 = Iq::new_register('node', 'password')
|
34
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:register'><username>node</username><password>password</password></query></iq>", x3.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_rosterget
|
38
|
+
x = Iq::new_rosterget
|
39
|
+
assert_equal("<iq type='get'><query xmlns='jabber:iq:roster'/></iq>", x.to_s)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_rosterset
|
43
|
+
x = Iq::new_rosterset
|
44
|
+
assert_equal("<iq type='set'><query xmlns='jabber:iq:roster'/></iq>", x.to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_browseget
|
48
|
+
x = Iq::new_browseget
|
49
|
+
assert_equal("<iq type='get'><query xmlns='jabber:iq:browse'/></iq>", x.to_s)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_types
|
53
|
+
iq = Iq::new
|
54
|
+
assert_equal(nil, iq.type)
|
55
|
+
iq.type = :get
|
56
|
+
assert_equal(:get, iq.type)
|
57
|
+
iq.type = :set
|
58
|
+
assert_equal(:set, iq.type)
|
59
|
+
iq.type = :result
|
60
|
+
assert_equal(:result, iq.type)
|
61
|
+
iq.type = :error
|
62
|
+
assert_equal(:error, iq.type)
|
63
|
+
iq.type = :invalid
|
64
|
+
assert_equal(nil, iq.type)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_query
|
68
|
+
x = Iq::new(:set)
|
69
|
+
assert_equal(nil, x.queryns)
|
70
|
+
query = REXML::Element::new('query')
|
71
|
+
x.add(query)
|
72
|
+
assert_equal('', x.queryns)
|
73
|
+
query.add_namespace('jabber:iq:auth')
|
74
|
+
assert_equal(query.to_s, x.query.to_s)
|
75
|
+
assert_equal('jabber:iq:auth', x.queryns)
|
76
|
+
|
77
|
+
query2 = REXML::Element::new('query')
|
78
|
+
x.query = query2
|
79
|
+
assert_equal('', x.queryns)
|
80
|
+
query2.add_namespace('jabber:iq:register')
|
81
|
+
assert_equal('jabber:iq:register', x.queryns)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_vcard
|
85
|
+
x = Iq::new
|
86
|
+
assert_equal(nil, x.vcard)
|
87
|
+
x.add(vcard = REXML::Element.new('vCard'))
|
88
|
+
assert_equal(vcard, x.vcard)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_error
|
92
|
+
x = Iq::new(:set)
|
93
|
+
e = REXML::Element::new('error')
|
94
|
+
x.add(e)
|
95
|
+
# test if, after an import, the error element is successfully changed
|
96
|
+
# into an Error object.
|
97
|
+
x2 = Iq::new.import(x)
|
98
|
+
assert_equal(Error, x2.first_element('error').class)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_new_query
|
102
|
+
x = Iq::new_query(:get, JID.new('a@b/c'))
|
103
|
+
assert_equal(:get, x.type)
|
104
|
+
assert_equal(nil, x.from)
|
105
|
+
assert_equal(JID.new('a@b/c'), x.to)
|
106
|
+
assert_kind_of(IqQuery, x.query)
|
107
|
+
assert_equal('', x.queryns)
|
108
|
+
end
|
109
|
+
end
|
data/test/tc_iqquery.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift '../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'xmpp4r/rexmladdons'
|
7
|
+
require 'xmpp4r/query'
|
8
|
+
include Jabber
|
9
|
+
|
10
|
+
class IqQueryTest < Test::Unit::TestCase
|
11
|
+
def test_create
|
12
|
+
x = IqQuery::new()
|
13
|
+
assert_equal("query", x.name)
|
14
|
+
assert_equal("<query/>", x.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_import
|
18
|
+
q = IqQuery::new
|
19
|
+
assert_equal(IqQuery, q.class)
|
20
|
+
|
21
|
+
e = REXML::Element.new('query')
|
22
|
+
e.add_namespace('jabber:iq:roster')
|
23
|
+
# kind_of? only checks that the class belongs to the IqQuery class
|
24
|
+
# hierarchy. See IqQueryRosterTest#test_import for a more strict
|
25
|
+
# check.
|
26
|
+
assert_kind_of(IqQuery, IqQuery.import(e))
|
27
|
+
|
28
|
+
# Importing specific derivates is to be tested in the test case of the derivate
|
29
|
+
# (e.g. tc_iqqueryroster.rb)
|
30
|
+
end
|
31
|
+
end
|