xmpp4r 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog +28 -0
  3. data/LICENSE +59 -0
  4. data/README +20 -0
  5. data/Rakefile +103 -0
  6. data/UPDATING +40 -0
  7. data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +425 -0
  13. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -0
  15. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  16. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  17. data/data/doc/xmpp4r/examples/advanced/migrate.rb +89 -0
  18. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  19. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
  20. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -0
  21. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  22. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  23. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  24. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  25. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  26. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
  27. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
  28. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
  29. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  30. data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
  31. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  32. data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
  33. data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
  34. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  35. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
  36. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
  37. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
  38. data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
  39. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  40. data/data/doc/xmpp4r/examples/basic/roster.rb +42 -0
  41. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  42. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  43. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +172 -0
  44. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
  45. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  46. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
  47. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
  48. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
  49. data/lib/callbacks.rb +122 -0
  50. data/lib/xmpp4r/authenticationfailure.rb +13 -0
  51. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
  52. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
  53. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
  54. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
  55. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
  56. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
  57. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
  60. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
  61. data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
  62. data/lib/xmpp4r/bytestreams.rb +11 -0
  63. data/lib/xmpp4r/client.rb +249 -0
  64. data/lib/xmpp4r/component.rb +103 -0
  65. data/lib/xmpp4r/connection.rb +166 -0
  66. data/lib/xmpp4r/dataforms/x/data.rb +248 -0
  67. data/lib/xmpp4r/dataforms.rb +1 -0
  68. data/lib/xmpp4r/debuglog.rb +34 -0
  69. data/lib/xmpp4r/delay/x/delay.rb +100 -0
  70. data/lib/xmpp4r/delay.rb +1 -0
  71. data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
  72. data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
  73. data/lib/xmpp4r/discovery.rb +2 -0
  74. data/lib/xmpp4r/error.rb +230 -0
  75. data/lib/xmpp4r/errorexception.rb +32 -0
  76. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
  77. data/lib/xmpp4r/feature_negotiation.rb +1 -0
  78. data/lib/xmpp4r/idgenerator.rb +37 -0
  79. data/lib/xmpp4r/iq.rb +229 -0
  80. data/lib/xmpp4r/jid.rb +167 -0
  81. data/lib/xmpp4r/message.rb +171 -0
  82. data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
  83. data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
  84. data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
  85. data/lib/xmpp4r/muc/x/muc.rb +98 -0
  86. data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
  87. data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
  88. data/lib/xmpp4r/muc.rb +6 -0
  89. data/lib/xmpp4r/presence.rb +255 -0
  90. data/lib/xmpp4r/query.rb +43 -0
  91. data/lib/xmpp4r/rexmladdons.rb +826 -0
  92. data/lib/xmpp4r/roster/helper/roster.rb +514 -0
  93. data/lib/xmpp4r/roster/iq/roster.rb +244 -0
  94. data/lib/xmpp4r/roster/x/roster.rb +155 -0
  95. data/lib/xmpp4r/roster.rb +4 -0
  96. data/lib/xmpp4r/sasl.rb +167 -0
  97. data/lib/xmpp4r/stream.rb +543 -0
  98. data/lib/xmpp4r/streamparser.rb +77 -0
  99. data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
  100. data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
  101. data/lib/xmpp4r/vcard.rb +3 -0
  102. data/lib/xmpp4r/version/helper/responder.rb +71 -0
  103. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  104. data/lib/xmpp4r/version/iq/version.rb +118 -0
  105. data/lib/xmpp4r/version.rb +3 -0
  106. data/lib/xmpp4r/x.rb +43 -0
  107. data/lib/xmpp4r/xmlstanza.rb +174 -0
  108. data/lib/xmpp4r/xmpp4r.rb +16 -0
  109. data/lib/xmpp4r.rb +122 -0
  110. data/setup.rb +1360 -0
  111. data/test/bytestreams/tc_ibb.rb +186 -0
  112. data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
  113. data/test/delay/tc_xdelay.rb +51 -0
  114. data/test/lib/clienttester.rb +110 -0
  115. data/test/muc/tc_muc_mucclient.rb +569 -0
  116. data/test/muc/tc_muc_simplemucclient.rb +72 -0
  117. data/test/roster/.tc_helper.rb.swp +0 -0
  118. data/test/roster/tc_helper.rb +389 -0
  119. data/test/roster/tc_iqqueryroster.rb +140 -0
  120. data/test/roster/tc_xroster.rb +70 -0
  121. data/test/tc_callbacks.rb +128 -0
  122. data/test/tc_class_names.rb +129 -0
  123. data/test/tc_client.rb +30 -0
  124. data/test/tc_error.rb +103 -0
  125. data/test/tc_idgenerator.rb +30 -0
  126. data/test/tc_iq.rb +109 -0
  127. data/test/tc_iqquery.rb +31 -0
  128. data/test/tc_jid.rb +202 -0
  129. data/test/tc_message.rb +114 -0
  130. data/test/tc_presence.rb +148 -0
  131. data/test/tc_stream.rb +182 -0
  132. data/test/tc_streamError.rb +87 -0
  133. data/test/tc_streamSend.rb +59 -0
  134. data/test/tc_streamThreaded.rb +168 -0
  135. data/test/tc_xmlstanza.rb +76 -0
  136. data/test/ts_xmpp4r.rb +34 -0
  137. data/test/vcard/tc_iqvcard.rb +52 -0
  138. data/test/version/tc_helper.rb +46 -0
  139. data/test/version/tc_iqqueryversion.rb +96 -0
  140. data/tools/doctoweb.bash +30 -0
  141. data/tools/gen_requires.bash +10 -0
  142. metadata +232 -0
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'test/unit'
6
+ require 'socket'
7
+ require 'xmpp4r/client'
8
+ include Jabber
9
+
10
+ class ConnectionErrorTest < Test::Unit::TestCase
11
+ def test_connectionError_start_withexcblock
12
+ @conn, @server = IO.pipe
13
+ @stream = Stream::new(false)
14
+ error = false
15
+ @stream.on_exception do |e, o, w|
16
+ assert_equal(RuntimeError, e.class)
17
+ assert_equal(Jabber::Stream, o.class)
18
+ assert_equal(:start, w)
19
+ error = true
20
+ end
21
+ assert(!error)
22
+ @stream.start(nil)
23
+ sleep 0.2
24
+ assert(error)
25
+ @server.close
26
+ @stream.close
27
+ end
28
+
29
+ def test_connectionError_parse_withexcblock
30
+ @conn, @server = IO.pipe
31
+ @stream = Stream::new(false)
32
+ error = false
33
+ @stream.start(@conn)
34
+ @stream.on_exception do |e, o, w|
35
+ assert_equal(REXML::ParseException, e.class)
36
+ assert_equal(Jabber::Stream, o.class)
37
+ assert_equal(:parser, w)
38
+ error = true
39
+ end
40
+ @server.puts('<stream:stream>')
41
+ @server.flush
42
+ assert(!error)
43
+ assert_raise(Errno::EPIPE) {
44
+ @server.puts('</blop>')
45
+ }
46
+ @server.flush
47
+ sleep 0.2
48
+ assert(error)
49
+ @server.close
50
+ @stream.close
51
+ end
52
+
53
+ def test_connectionError_send_withexcblock
54
+ @conn, @server = IO.pipe
55
+ @stream = Stream::new(false)
56
+ error = false
57
+ @stream.start(@conn)
58
+ @stream.on_exception do |e, o, w|
59
+ assert_equal(IOError, e.class)
60
+ assert_equal(Jabber::Stream, o.class)
61
+ assert_equal(:sending, w)
62
+ error = true
63
+ end
64
+ @server.puts('<stream:stream>')
65
+ @server.flush
66
+ assert(!error)
67
+ @stream.send('</test>')
68
+ sleep 0.2
69
+ assert(error)
70
+ @server.close
71
+ @stream.close
72
+ end
73
+
74
+ def test_connectionError_send_withoutexcblock
75
+ @conn, @server = IO.pipe
76
+ @stream = Stream::new(false)
77
+ @stream.start(@conn)
78
+ @server.puts('<stream:stream>')
79
+ @server.flush
80
+ assert_raise(IOError) { @stream.send('</test>') }
81
+ @server.close
82
+ @stream.close
83
+ end
84
+
85
+
86
+
87
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'test/unit'
6
+ require 'socket'
7
+ require 'tempfile'
8
+ require 'io/wait'
9
+ require 'xmpp4r'
10
+ include Jabber
11
+
12
+ class StreamSendTest < Test::Unit::TestCase
13
+ def setup
14
+ @tmpfile = Tempfile::new("StreamSendTest")
15
+ @tmpfilepath = @tmpfile.path()
16
+ @tmpfile.unlink
17
+ @servlisten = UNIXServer::new(@tmpfilepath)
18
+ thServer = Thread.new { @server = @servlisten.accept }
19
+ @iostream = UNIXSocket::new(@tmpfilepath)
20
+ @stream = Stream::new(false)
21
+ @stream.start(@iostream)
22
+
23
+ thServer.join
24
+ end
25
+
26
+ def teardown
27
+ @stream.close
28
+ @server.close
29
+ @servlisten.close
30
+ end
31
+
32
+ def mysend(s)
33
+ @stream.send(s)
34
+ @stream.send("\n") #needed for easy test writing
35
+ end
36
+
37
+ ##
38
+ # Tries to send a basic message
39
+ def test_sendbasic
40
+ mysend(Message::new)
41
+ assert_equal("<message/>\n", @server.gets)
42
+ end
43
+
44
+ def test_sendmessage
45
+ mysend(Message::new('lucas@linux.ensimag.fr', 'coucou'))
46
+ assert_equal("<message to='lucas@linux.ensimag.fr'><body>coucou</body></message>\n", @server.gets)
47
+ end
48
+
49
+ def test_sendpresence
50
+ mysend(Presence::new)
51
+ assert_equal("<presence/>\n", @server.gets)
52
+ end
53
+
54
+ def test_sendiq
55
+ mysend(Iq::new)
56
+ assert_equal("<iq/>\n", @server.gets)
57
+ end
58
+
59
+ end
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'tempfile'
6
+ require 'test/unit'
7
+ require 'socket'
8
+ require 'xmpp4r/stream'
9
+ include Jabber
10
+
11
+ class StreamThreadedTest < Test::Unit::TestCase
12
+ def setup
13
+ @tmpfile = Tempfile::new("StreamSendTest")
14
+ @tmpfilepath = @tmpfile.path()
15
+ @tmpfile.unlink
16
+ @servlisten = UNIXServer::new(@tmpfilepath)
17
+ thServer = Thread.new { @server = @servlisten.accept }
18
+ @iostream = UNIXSocket::new(@tmpfilepath)
19
+ n = 0
20
+ while not defined? @server and n < 10
21
+ sleep 0.1
22
+ n += 1
23
+ end
24
+ @stream = Stream::new
25
+ @stream.start(@iostream)
26
+ end
27
+
28
+ def teardown
29
+ @stream.close
30
+ @server.close
31
+ end
32
+
33
+ ##
34
+ # tests that connection really waits the call to process() to dispatch
35
+ # stanzas to filters
36
+ def test_process
37
+ called = false
38
+ @stream.add_xml_callback { called = true }
39
+ assert(!called)
40
+ @server.puts('<stream:stream>')
41
+ @server.flush
42
+ assert(called)
43
+ end
44
+
45
+ def test_process100
46
+ @server.puts('<stream:stream>')
47
+ @server.flush
48
+
49
+ n = 0
50
+ @stream.add_message_callback { n += 1 }
51
+
52
+ 100.times {
53
+ @server.puts('<message/>')
54
+ @server.flush
55
+ }
56
+
57
+ assert_equal(100, n)
58
+
59
+ @server.puts('<message/>' * 100)
60
+ @server.flush
61
+ sleep 0.1
62
+
63
+ assert_equal(200, n)
64
+ end
65
+
66
+ def test_send
67
+ @server.puts('<stream:stream>')
68
+ @server.flush
69
+
70
+ Thread.new {
71
+ assert_equal(Iq.new(:get).to_s, @server.gets('>'))
72
+ @stream.receive(Iq.new(:result))
73
+ }
74
+
75
+ called = 0
76
+ @stream.send(Iq.new(:get)) { |reply|
77
+ called += 1
78
+ if reply.kind_of? Iq and reply.type == :result
79
+ true
80
+ else
81
+ false
82
+ end
83
+ }
84
+
85
+ assert_equal(1, called)
86
+ end
87
+
88
+ def test_send_nested
89
+ @server.puts('<stream:stream>')
90
+ @server.flush
91
+ finished = Mutex.new
92
+ finished.lock
93
+
94
+ Thread.new {
95
+ assert_equal(Iq.new(:get).to_s, @server.gets('>'))
96
+ @server.puts(Iq.new(:result).set_id('1').to_s)
97
+ @server.flush
98
+ assert_equal(Iq.new(:set).to_s, @server.gets('>'))
99
+ @server.puts(Iq.new(:result).set_id('2').to_s)
100
+ @server.flush
101
+ assert_equal(Iq.new(:get).to_s, @server.gets('>'))
102
+ @server.puts(Iq.new(:result).set_id('3').to_s)
103
+ @server.flush
104
+
105
+ finished.unlock
106
+ }
107
+
108
+ called_outer = 0
109
+ called_inner = 0
110
+
111
+ @stream.send(Iq.new(:get)) { |reply|
112
+ called_outer += 1
113
+ assert_kind_of(Iq, reply)
114
+ assert_equal(:result, reply.type)
115
+
116
+ if reply.id == '1'
117
+ @stream.send(Iq.new(:set)) { |reply|
118
+ called_inner += 1
119
+ assert_kind_of(Iq, reply)
120
+ assert_equal(:result, reply.type)
121
+ assert_equal('2', reply.id)
122
+
123
+ @stream.send(Iq.new(:get))
124
+
125
+ true
126
+ }
127
+ false
128
+ elsif reply.id == '3'
129
+ true
130
+ else
131
+ false
132
+ end
133
+ }
134
+
135
+ assert_equal(2, called_outer)
136
+ assert_equal(1, called_inner)
137
+
138
+ finished.lock
139
+ end
140
+
141
+ def test_bidi
142
+ @server.puts('<stream:stream>')
143
+ @server.flush
144
+ finished = Mutex.new
145
+ ok = true
146
+
147
+ Thread.new {
148
+ 100.times { |i|
149
+ ok &&= (Iq.new(:get).set_id(i).to_s == @server.gets('>'))
150
+ @server.puts(Iq.new(:result).set_id(i).to_s)
151
+ @server.flush
152
+ }
153
+ finished.unlock
154
+ }
155
+
156
+ 100.times { |i|
157
+ @stream.send(Iq.new(:get).set_id(i)) { |reply|
158
+ ok &&= reply.kind_of? Iq
159
+ ok &&= (:result == reply.type)
160
+ ok &&= (i.to_s == reply.id)
161
+ true
162
+ }
163
+ }
164
+
165
+ assert(ok)
166
+ 2.times { finished.lock }
167
+ end
168
+ end
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'test/unit'
6
+ require 'socket'
7
+ require 'xmpp4r/rexmladdons'
8
+ require 'xmpp4r/xmlstanza'
9
+ require 'xmpp4r/iq'
10
+ include Jabber
11
+
12
+ class XMLStanzaTest < Test::Unit::TestCase
13
+
14
+ def test_from
15
+ x = XMLStanza::new("message")
16
+ assert_equal(nil, x.from)
17
+ assert_equal(x, x.set_from("blop"))
18
+ assert_equal("blop", x.from.to_s)
19
+ x.from = "tada"
20
+ assert_equal("tada", x.from.to_s)
21
+ end
22
+
23
+ def test_to
24
+ x = XMLStanza::new("message")
25
+ assert_equal(nil, x.to)
26
+ assert_equal(x, x.set_to("blop"))
27
+ assert_equal("blop", x.to.to_s)
28
+ x.to = "tada"
29
+ assert_equal("tada", x.to.to_s)
30
+ end
31
+
32
+ def test_id
33
+ x = XMLStanza::new("message")
34
+ assert_equal(nil, x.id)
35
+ assert_equal(x, x.set_id("blop"))
36
+ assert_equal("blop", x.id)
37
+ x.id = "tada"
38
+ assert_equal("tada", x.id)
39
+ end
40
+
41
+ def test_type
42
+ x = XMLStanza::new("message")
43
+ assert_equal(nil, x.type)
44
+ assert_equal(x, x.set_type("blop"))
45
+ assert_equal("blop", x.type)
46
+ x.type = "tada"
47
+ assert_equal("tada", x.type)
48
+ end
49
+
50
+ def test_import
51
+ x = XMLStanza::new("iq")
52
+ x.id = "heya"
53
+ q = x.add_element("query")
54
+ q.add_namespace("about:blank")
55
+ q.add_element("b").text = "I am b"
56
+ q.add_text("I am text")
57
+ q.add_element("a").add_attribute("href", "http://home.gna.org/xmpp4r/")
58
+ x.add_text("yow")
59
+ x.add_element("query")
60
+
61
+ iq = Iq.import(x)
62
+
63
+ assert_equal(x.id, iq.id)
64
+ assert_equal(q.to_s, iq.query.to_s)
65
+ assert_equal(x.to_s, iq.to_s)
66
+ assert_equal(q.namespace, iq.queryns)
67
+ end
68
+
69
+ def test_error
70
+ x = XMLStanza::new("presence")
71
+ assert_equal(nil, x.error)
72
+ x.typed_add(REXML::Element.new('error'))
73
+ assert_equal('<error/>', x.error.to_s)
74
+ assert_equal(Error, x.error.class)
75
+ end
76
+ end
data/test/ts_xmpp4r.rb ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'test')
6
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
7
+ $:.unshift File.join(File.dirname(__FILE__), 'test')
8
+
9
+ require 'tc_streamThreaded'
10
+ require 'bytestreams/tc_ibb'
11
+ require 'bytestreams/tc_socks5bytestreams'
12
+ require 'delay/tc_xdelay'
13
+ require 'muc/tc_muc_simplemucclient'
14
+ require 'muc/tc_muc_mucclient'
15
+ require 'tc_error'
16
+ require 'tc_stream'
17
+ require 'tc_idgenerator'
18
+ require 'tc_iqquery'
19
+ #require 'tc_streamError'
20
+ require 'tc_presence'
21
+ require 'vcard/tc_iqvcard'
22
+ require 'roster/tc_iqqueryroster'
23
+ require 'roster/tc_xroster'
24
+ require 'roster/tc_helper'
25
+ require 'version/tc_iqqueryversion'
26
+ require 'version/tc_helper'
27
+ require 'tc_streamSend'
28
+ require 'tc_jid'
29
+ require 'tc_iq'
30
+ require 'tc_client'
31
+ require 'tc_callbacks'
32
+ require 'tc_xmlstanza'
33
+ require 'tc_message'
34
+ require 'tc_class_names'
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/rexmladdons'
7
+ require 'xmpp4r/vcard/iq/vcard'
8
+ include Jabber
9
+
10
+ class IqVcardTest < Test::Unit::TestCase
11
+ def test_create
12
+ v = Vcard::IqVcard.new
13
+ assert_equal([], v.fields)
14
+ end
15
+
16
+ def test_create_with_fields
17
+ v = Vcard::IqVcard.new({'FN' => 'B C', 'NICKNAME' => 'D'})
18
+ assert_equal(['FN', 'NICKNAME'], v.fields.sort)
19
+ assert_equal('B C', v['FN'])
20
+ assert_equal('D', v['NICKNAME'])
21
+ assert_equal(nil, v['x'])
22
+ end
23
+
24
+ def test_fields
25
+ v = Vcard::IqVcard.new
26
+ f = ['a', 'b', 'c', 'd', 'e']
27
+ f.each { |s|
28
+ v[s.downcase] = s.upcase
29
+ }
30
+
31
+ assert_equal(f, v.fields.sort)
32
+
33
+ f.each { |s|
34
+ assert_equal(s.upcase, v[s.downcase])
35
+ assert_equal(nil, v[s.upcase])
36
+ }
37
+ end
38
+
39
+ def test_deep
40
+ v = Vcard::IqVcard.new({
41
+ 'FN' => 'John D. Random',
42
+ 'PHOTO/TYPE' => 'image/png',
43
+ 'PHOTO/BINVAL' => '===='})
44
+
45
+ assert_equal(['FN', 'PHOTO/BINVAL', 'PHOTO/TYPE'], v.fields.sort)
46
+ assert_equal('John D. Random', v['FN'])
47
+ assert_equal('image/png', v['PHOTO/TYPE'])
48
+ assert_equal('====', v['PHOTO/BINVAL'])
49
+ assert_equal(nil, v['PHOTO'])
50
+ assert_equal(nil, v['NICKNAME'])
51
+ end
52
+ end
@@ -0,0 +1,46 @@
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/version/helper/responder'
10
+ include Jabber
11
+
12
+ class Version::HelperTest < Test::Unit::TestCase
13
+ include ClientTester
14
+
15
+ def test_create
16
+ h = Version::Responder::new(@client)
17
+ assert_kind_of(Version::Responder, h)
18
+ assert_respond_to(h, :add_version_callback)
19
+ end
20
+
21
+ def test_callback
22
+ # Prepare helper
23
+ h = Version::Responder::new(@client)
24
+
25
+ calls = 0
26
+ h.add_version_callback { |iq,responder|
27
+ calls += 1
28
+ assert('jabber:iq:version', iq.queryns)
29
+ responder.call('Test program', '1.0', 'Ruby Test::Unit')
30
+ }
31
+
32
+ # Send stanzas which shouldn't match
33
+ @server.send("<iq type='set'><query xmlns='jabber:iq:version'/></iq>")
34
+ @server.send("<iq type='get'><query xmlns='jabber:iq:browse'/></iq>")
35
+ assert_equal(0, calls)
36
+
37
+ # Send a query
38
+ @server.send("<iq type='get'><query xmlns='jabber:iq:version'/></iq>") { |reply|
39
+ assert_equal('Test program', reply.query.iname)
40
+ assert_equal('1.0', reply.query.version)
41
+ assert_equal('Ruby Test::Unit', reply.query.os)
42
+ true
43
+ }
44
+ assert_equal(1, calls)
45
+ end
46
+ end
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift File::dirname(__FILE__) + '/../../lib'
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r/rexmladdons'
7
+ require 'xmpp4r/version/iq/version'
8
+ include Jabber
9
+
10
+ class Version::IqQueryVersionTest < Test::Unit::TestCase
11
+ def test_create_empty
12
+ x = Version::IqQueryVersion::new
13
+ assert_equal('jabber:iq:version', x.namespace)
14
+ assert_equal('', x.iname)
15
+ assert_equal('', x.version)
16
+ assert_equal(nil, x.os)
17
+ end
18
+
19
+ def test_create
20
+ x = Version::IqQueryVersion::new('my test', 'XP')
21
+ assert_equal('jabber:iq:version', x.namespace)
22
+ assert_equal('my test', x.iname)
23
+ assert_equal('XP', x.version)
24
+ assert_equal(nil, x.os)
25
+ end
26
+
27
+ def test_create_with_os
28
+ x = Version::IqQueryVersion::new('superbot', '1.0-final', 'FreeBSD 5.4-RELEASE-p4')
29
+ assert_equal('jabber:iq:version', x.namespace)
30
+ assert_equal('superbot', x.iname)
31
+ assert_equal('1.0-final', x.version)
32
+ assert_equal('FreeBSD 5.4-RELEASE-p4', x.os)
33
+ end
34
+
35
+ def test_import1
36
+ iq = Iq::new
37
+ q = REXML::Element::new('query')
38
+ q.add_namespace('jabber:iq:version')
39
+ iq.add(q)
40
+ iq2 = Iq::new.import(iq)
41
+ assert_equal(Version::IqQueryVersion, iq2.query.class)
42
+ end
43
+
44
+ def test_import2
45
+ iq = Iq::new
46
+ q = REXML::Element::new('query')
47
+ q.add_namespace('jabber:iq:version')
48
+ q.add_element('name').text = 'AstroBot'
49
+ q.add_element('version').text = 'XP'
50
+ q.add_element('os').text = 'FreeDOS'
51
+ iq.add(q)
52
+ iq = Iq::new.import(iq)
53
+ assert_equal(Version::IqQueryVersion, iq.query.class)
54
+ assert_equal('AstroBot', iq.query.iname)
55
+ assert_equal('XP', iq.query.version)
56
+ assert_equal('FreeDOS', iq.query.os)
57
+ end
58
+
59
+ def test_replace
60
+ x = Version::IqQueryVersion::new('name', 'version', 'os')
61
+
62
+ num = 0
63
+ x.each_element('name') { |e| num += 1 }
64
+ assert_equal(1, num)
65
+ num = 0
66
+ x.each_element('version') { |e| num += 1 }
67
+ assert_equal(1, num)
68
+ num = 0
69
+ x.each_element('os') { |e| num += 1 }
70
+ assert_equal(1, num)
71
+
72
+ x.set_iname('N').set_version('V').set_os('O')
73
+
74
+ num = 0
75
+ x.each_element('name') { |e| num += 1 }
76
+ assert_equal(1, num)
77
+ num = 0
78
+ x.each_element('version') { |e| num += 1 }
79
+ assert_equal(1, num)
80
+ num = 0
81
+ x.each_element('os') { |e| num += 1 }
82
+ assert_equal(1, num)
83
+
84
+ x.set_iname(nil).set_version(nil).set_os(nil)
85
+
86
+ num = 0
87
+ x.each_element('name') { |e| num += 1 }
88
+ assert_equal(1, num)
89
+ num = 0
90
+ x.each_element('version') { |e| num += 1 }
91
+ assert_equal(1, num)
92
+ num = 0
93
+ x.each_element('os') { |e| num += 1 }
94
+ assert_equal(0, num)
95
+ end
96
+ end
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ if [ -z $CVSDIR ]; then
4
+ CVSDIR=$HOME/dev/xmpp4r-web
5
+ fi
6
+
7
+ TARGET=$CVSDIR/rdoc
8
+
9
+ echo "Copying rdoc documentation to $TARGET."
10
+
11
+ if [ ! -d $TARGET ]; then
12
+ echo "$TARGET doesn't exist, exiting."
13
+ exit 1
14
+ fi
15
+ rsync -a rdoc/ $TARGET/
16
+
17
+ echo "###########################################################"
18
+ echo "CVS status :"
19
+ cd $TARGET
20
+ cvs -q up
21
+ echo "CVS Adding files."
22
+ while [ $(cvs -q up | grep "^? " | wc -l) -gt 0 ]; do
23
+ cvs add $(cvs -q up | grep "^? " | awk '{print $2}')
24
+ done
25
+ echo "###########################################################"
26
+ echo "CVS status after adding missing files:"
27
+ cvs -q up
28
+ echo "Commit changes now with"
29
+ echo "# (cd $TARGET && cvs commit -m \"rdoc update\")"
30
+ exit 0
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ cd lib
4
+ f=$(mktemp)
5
+ echo "strict digraph requirestree { " > $f
6
+ grep -r "^require " * |grep -v svn |grep -v swp | sed "s/^\(.*\).rb:require '\(.*\)'/\1 -> \2;/" | sed 's/\//_/g' >> $f
7
+ echo "}" >> $f
8
+ cd ..
9
+ dot -Tpng $f -o gen_requires.png
10
+ rm -f $f