Class: JIDTest

Inherits:
Test::Unit::TestCase show all
Defined in:
lib/gems/xmpp4r-0.4/test/tc_class_names.rb,
lib/gems/xmpp4r-0.4/test/tc_jid.rb

Overview

No include Jabber, test full namespace

Instance Method Summary collapse

Methods inherited from Test::Unit::TestCase

#assert_array_equal, expect, #run

Instance Method Details

#test_baseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 10

def test_base
  assert_kind_of(Module, Jabber)
  assert_kind_of(Class, Jabber::JabberError)
  assert_kind_of(Class, Jabber::ErrorResponse)
  assert_kind_of(Class, Jabber::ClientAuthenticationFailure)
  assert_kind_of(Class, Jabber::ComponentAuthenticationFailure)
  assert_kind_of(Class, Jabber::Client)
  assert_kind_of(Class, Jabber::Component)
  assert_kind_of(Class, Jabber::Connection)
  assert_kind_of(Class, Jabber::ErrorResponse)
  assert_kind_of(Class, Jabber::ServerError)
  assert_kind_of(Class, Jabber::IdGenerator)
  assert_kind_of(Class, Jabber::Iq)
  assert_kind_of(Class, Jabber::IqQuery)
  assert_kind_of(Class, Jabber::JID)
  assert_kind_of(Class, Jabber::Message)
  assert_kind_of(Class, Jabber::Presence)
  assert_kind_of(Module, Jabber::SASL)
  assert_respond_to(Jabber::SASL, :new)
  assert_kind_of(Class, Jabber::SASL::Base)
  assert_kind_of(Class, Jabber::SASL::Plain)
  assert_kind_of(Class, Jabber::SASL::DigestMD5)
  assert_kind_of(Class, Jabber::Stream)
  assert_kind_of(Class, Jabber::StreamParser)
  assert_kind_of(Class, Jabber::X)
  assert_kind_of(Class, Jabber::XMPPElement)
  assert_kind_of(Class, Jabber::XMPPStanza)
end

#test_bytestreamsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 61

def test_bytestreams
  require 'xmpp4r/bytestreams'
  assert_kind_of(Class, Jabber::SOCKS5Error)
  assert_kind_of(Module, Jabber::FileTransfer)
  assert_kind_of(Module, Jabber::FileTransfer::TransferSource)
  assert_kind_of(Class, Jabber::FileTransfer::FileSource)
  assert_kind_of(Class, Jabber::FileTransfer::Helper)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsServer)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsPeer)
  assert_kind_of(Class, Jabber::Bytestreams::IqQueryBytestreams)
  assert_kind_of(Class, Jabber::Bytestreams::StreamHost)
  assert_kind_of(Class, Jabber::Bytestreams::StreamHostUsed)
  assert_kind_of(Class, Jabber::Bytestreams::IqSi)
  assert_kind_of(Class, Jabber::Bytestreams::IqSiFile)
  assert_kind_of(Class, Jabber::Bytestreams::IqSiFileRange)
  assert_kind_of(Class, Jabber::Bytestreams::IBB)
  assert_kind_of(Class, Jabber::Bytestreams::IBBQueueItem)
  assert_kind_of(Class, Jabber::Bytestreams::IBBInitiator)
  assert_kind_of(Class, Jabber::Bytestreams::IBBTarget)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5Bytestreams)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsInitiator)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5BytestreamsTarget)
  assert_kind_of(Class, Jabber::Bytestreams::SOCKS5Socket)
end

#test_change1Object



160
161
162
163
164
165
166
167
168
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 160

def test_change1
  j = JID.new('a@b/c')
  j.node = 'd'
  assert_equal('d@b/c', j.to_s)
  j.domain = 'e'
  assert_equal('d@e/c', j.to_s)
  j.resource = 'f'
  assert_equal('d@e/f', j.to_s)
end

#test_create1Object



12
13
14
15
16
17
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 12

def test_create1
  j = JID.new('a', 'b', 'c')
  assert_equal('a', j.node)
  assert_equal('b', j.domain)
  assert_equal('c', j.resource)
end

#test_create10Object



83
84
85
86
87
88
89
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 83

def test_create10
  j = JID.new('@b/c')
  assert_equal('', j.node)
  assert_equal('b', j.domain)
  assert_equal('c', j.resource)
  assert_equal('@b/c', j.to_s)
end

#test_create11Object



91
92
93
94
95
96
97
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 91

def test_create11
  j = JID.new('@b')
  assert_equal('', j.node)
  assert_equal('b', j.domain)
  assert_equal(nil, j.resource)
  assert_equal('@b', j.to_s)
end

#test_create12Object



99
100
101
102
103
104
105
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 99

def test_create12
  j = JID.new('@b/')
  assert_equal('', j.node)
  assert_equal('b', j.domain)
  assert_equal('', j.resource)
  assert_equal('@b/', j.to_s)
end

#test_create13Object



107
108
109
110
111
112
113
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 107

def test_create13
  j = JID.new('a@b/')
  assert_equal('a', j.node)
  assert_equal('b', j.domain)
  assert_equal('', j.resource)
  assert_equal('a@b/', j.to_s)
end

#test_create14Object



115
116
117
118
119
120
121
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 115

def test_create14
  j = JID.new('nOdE@dOmAiN/rEsOuRcE')
  assert_equal('node', j.node)
  assert_equal('domain', j.domain)
  assert_equal('rEsOuRcE', j.resource)
  assert_equal('node@domain/rEsOuRcE', j.to_s)
end

#test_create2Object



19
20
21
22
23
24
25
26
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 19

def test_create2
  j = JID.new('a', 'b', 'c')
  j2 = JID.new(j)
  assert_equal('a', j2.node)
  assert_equal('b', j2.domain)
  assert_equal('c', j2.resource)
  assert_equal('a@b/c', j.to_s)
end

#test_create3Object



28
29
30
31
32
33
34
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 28

def test_create3
  j = JID.new('a@b/c')
  assert_equal('a', j.node)
  assert_equal('b', j.domain)
  assert_equal('c', j.resource)
  assert_equal('a@b/c', j.to_s)
end

#test_create4Object



36
37
38
39
40
41
42
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 36

def test_create4
  j = JID.new('a@b')
  assert_equal('a', j.node)
  assert_equal('b', j.domain)
  assert_equal(nil, j.resource)
  assert_equal('a@b', j.to_s)
end

#test_create5Object



44
45
46
47
48
49
50
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 44

def test_create5
  j = JID.new
  assert_equal(nil, j.node)
  assert_equal(nil, j.domain)
  assert_equal(nil, j.resource)
  assert_equal('', j.to_s)
end

#test_create6Object



52
53
54
55
56
57
58
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 52

def test_create6
  j = JID.new('dom')
  assert_equal(nil, j.node)
  assert_equal('dom', j.domain)
  assert_equal(nil, j.resource)
  assert_equal('dom', j.to_s)
end

#test_create7Object



60
61
62
63
64
65
66
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 60

def test_create7
  j = JID.new('dom/res')
  assert_equal(nil, j.node)
  assert_equal('dom', j.domain)
  assert_equal('res', j.resource)
  assert_equal('dom/res', j.to_s)
end

#test_create8Object



68
69
70
71
72
73
74
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 68

def test_create8
  j = JID.new('dom/a@b')
  assert_equal(nil, j.node)
  assert_equal('dom', j.domain)
  assert_equal('a@b', j.resource)
  assert_equal('dom/a@b', j.to_s)
end

#test_create9Object



76
77
78
79
80
81
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 76

def test_create9
  assert_nothing_raised { JID.new("#{'n'*1023}@#{'d'*1023}/#{'r'*1023}") }
  assert_raises(Jabber::ArgumentError) { JID.new("#{'n'*1024}@#{'d'*1023}/#{'r'*1023}") }
  assert_raises(Jabber::ArgumentError) { JID.new("#{'n'*1023}@#{'d'*1024}/#{'r'*1023}") }
  assert_raises(Jabber::ArgumentError) { JID.new("#{'n'*1023}@#{'d'*1023}/#{'r'*1024}") }
end

#test_dataformsObject



87
88
89
90
91
92
93
94
95
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 87

def test_dataforms
  require 'xmpp4r/dataforms'
  assert_kind_of(Module, Jabber::Dataforms)
  assert_kind_of(Class, Jabber::Dataforms::XData)
  assert_kind_of(Class, Jabber::Dataforms::XDataTitle)
  assert_kind_of(Class, Jabber::Dataforms::XDataInstructions)
  assert_kind_of(Class, Jabber::Dataforms::XDataField)
  assert_kind_of(Class, Jabber::Dataforms::XDataReported)
end

#test_delayObject



97
98
99
100
101
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 97

def test_delay
  require 'xmpp4r/delay'
  assert_kind_of(Module, Jabber::Delay)
  assert_kind_of(Class, Jabber::Delay::XDelay)
end

#test_discoveryObject



103
104
105
106
107
108
109
110
111
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 103

def test_discovery
  require 'xmpp4r/discovery'
  assert_kind_of(Module, Jabber::Discovery)
  assert_kind_of(Class, Jabber::Discovery::IqQueryDiscoInfo)
  assert_kind_of(Class, Jabber::Discovery::Identity)
  assert_kind_of(Class, Jabber::Discovery::Feature)
  assert_kind_of(Class, Jabber::Discovery::IqQueryDiscoItems)
  assert_kind_of(Class, Jabber::Discovery::Item)
end

#test_emptyObject



183
184
185
186
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 183

def test_empty
  assert(JID.new.empty?)
  assert(!JID.new("test").empty?)
end

#test_equalObject



131
132
133
134
135
136
137
138
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 131

def test_equal
  assert_equal(JID.new('domain.fr'), JID.new('domain.fr'))
  assert_equal(JID.new('domain.fr'), JID.new(nil, 'domain.fr'))
  assert_equal(JID.new('[email protected]'), JID.new('[email protected]'))
  assert_equal(JID.new('[email protected]'), JID.new('l', 'domain.fr'))
  assert_equal(JID.new('[email protected]/res'), JID.new('[email protected]/res'))
  assert_equal(JID.new('[email protected]/res'), JID.new('l', 'domain.fr', 'res'))
end

#test_escapingObject



170
171
172
173
174
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 170

def test_escaping
  j = JID.new('user1@server1')
  j2 = JID.new(JID::escape(j), 'server2', 'res2')
  assert_equal('user1%server1@server2/res2', j2.to_s)
end

#test_feature_negotiationObject



113
114
115
116
117
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 113

def test_feature_negotiation
  require 'xmpp4r/feature_negotiation'
  assert_kind_of(Module, Jabber::FeatureNegotiation)
  assert_kind_of(Class, Jabber::FeatureNegotiation::IqFeature)
end

#test_hashObject



140
141
142
143
144
145
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 140

def test_hash
  h = {}
  j = JID.new('[email protected]/res')
  h[j] = 'a'
  assert_equal(h[j], h[JID.new('[email protected]/res')])
end

#test_invalidnodeObject



177
178
179
180
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 177

def test_invalidnode
#    assert_raises(IDN::Stringprep::StringprepError) { JID.new('toto@a/a', 'server', 'res') }
  assert_raises(IDN::Stringprep::StringprepError) { IDN::Stringprep.nodeprep('toto@a/a') }
end

#test_mucObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 50

def test_muc
  require 'xmpp4r/muc'
  assert_kind_of(Module, Jabber::MUC)
  assert_kind_of(Class, Jabber::MUC::MUCBrowser)
  assert_kind_of(Class, Jabber::MUC::MUCClient)
  assert_kind_of(Class, Jabber::MUC::SimpleMUCClient)
  assert_kind_of(Class, Jabber::MUC::XMUC)
  assert_kind_of(Class, Jabber::MUC::XMUCUser)
  assert_kind_of(Class, Jabber::MUC::XMUCUserInvite)
end

#test_pubsubObject



141
142
143
144
145
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 141

def test_pubsub
  require 'xmpp4r/pubsub'
  assert_kind_of(Module, Jabber::PubSub)
  assert_kind_of(Class, Jabber::PubSub::ServiceHelper)
end

#test_rosterObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 39

def test_roster
  require 'xmpp4r/roster'
  assert_kind_of(Module, Jabber::Roster)
  assert_kind_of(Class, Jabber::Roster::Helper)
  assert_kind_of(Class, Jabber::Roster::Helper::RosterItem)
  assert_kind_of(Class, Jabber::Roster::RosterItem)
  assert_kind_of(Class, Jabber::Roster::IqQueryRoster)
  assert_kind_of(Class, Jabber::Roster::XRoster)
  assert_kind_of(Class, Jabber::Roster::XRosterItem)
end

#test_rpcObject



134
135
136
137
138
139
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 134

def test_rpc
  require 'xmpp4r/rpc'
  assert_kind_of(Module, Jabber::RPC)
  assert_kind_of(Class, Jabber::RPC::Server)
  assert_kind_of(Class, Jabber::RPC::Client)
end

#test_sortObject



195
196
197
198
199
200
201
202
203
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 195

def test_sort
  assert_equal(-1, JID.new('a@b') <=> JID.new('b@b'))
  assert_equal(0, JID.new('a@b') <=> JID.new('a@b'))
  assert_equal(1, JID.new('a@b/r') <=> JID.new('a@b'))

  jids = [JID.new('b@b'), JID.new('a@b/r'), JID.new('a@b')]
  jids.sort!
  assert_equal([JID.new('a@b'), JID.new('a@b/r'), JID.new('b@b')], jids)
end

#test_stripObject



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 147

def test_strip
  assert_equal(JID.new('[email protected]'), JID.new('[email protected]/res').strip)
  assert_equal(JID.new('[email protected]'), JID.new('[email protected]').strip)
  assert_equal(JID.new('[email protected]'), JID.new('[email protected]/res').bare)
  jid = JID.new('[email protected]/res')
  jid.strip!
  assert_equal(JID.new('[email protected]'), jid)

  jid = JID.new('[email protected]/res')
  jid.bare!
  assert_equal(JID.new('[email protected]'), jid)
end

#test_strippedObject



188
189
190
191
192
193
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 188

def test_stripped
  assert(JID.new("node@domain").stripped?)
  assert(!JID.new("node@domain/res").stripped?)
  assert(JID.new("node@domain").bared?)
  assert(!JID.new("node@domain/res").bared?)
end

#test_tosObject



123
124
125
126
127
128
129
# File 'lib/gems/xmpp4r-0.4/test/tc_jid.rb', line 123

def test_tos
  assert_equal('', JID.new.to_s)
  assert_equal('domain.fr', JID.new('domain.fr').to_s)
  assert_equal('[email protected]', JID.new('l','domain.fr').to_s)
  assert_equal('[email protected]/res', JID.new('l','domain.fr','res').to_s)
  assert_equal('domain.fr/res', JID.new(nil,'domain.fr','res').to_s)
end

#test_vcardObject



119
120
121
122
123
124
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 119

def test_vcard
  require 'xmpp4r/vcard'
  assert_kind_of(Module, Jabber::Vcard)
  assert_kind_of(Class, Jabber::Vcard::Helper)
  assert_kind_of(Class, Jabber::Vcard::IqVcard)
end

#test_versionObject



126
127
128
129
130
131
132
# File 'lib/gems/xmpp4r-0.4/test/tc_class_names.rb', line 126

def test_version
  require 'xmpp4r/version'
  assert_kind_of(Module, Jabber::Version)
  assert_kind_of(Class, Jabber::Version::Responder)
  assert_kind_of(Class, Jabber::Version::SimpleResponder)
  assert_kind_of(Class, Jabber::Version::IqQueryVersion)
end