Class: StreamComponentTest
Constant Summary
collapse
- STREAM =
'stream:stream xmlns:stream="http://etherx.jabber.org/streams"'
- @@SOCKET_PORT =
65224
Instance Method Summary
collapse
#assert_array_equal, expect, #run
Instance Method Details
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamComponent.rb', line 18
def setup
servlisten = TCPServer.new(@@SOCKET_PORT)
serverwait = Semaphore.new
Thread.new do
Thread.current.abort_on_exception = true
serversock = servlisten.accept
servlisten.close
serversock.sync = true
@server = Stream.new
@server.add_xml_callback do |xml|
if xml.prefix == 'stream' and xml.name == 'stream'
@server.send("<#{STREAM} xmlns='jabber:component:accept'>")
true
else
false
end
end
@server.start(serversock)
serverwait.run
end
@stream = Component.new('test')
@stream.connect('localhost', @@SOCKET_PORT)
serverwait.wait
end
|
46
47
48
49
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamComponent.rb', line 46
def teardown
@stream.close
@server.close
end
|
#test_outgoing ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamComponent.rb', line 84
def test_outgoing
received_wait = Semaphore.new
@server.add_message_callback { |msg|
assert_kind_of(Message, msg)
received_wait.run
}
@stream.send(Message.new)
received_wait.wait
end
|
#test_process ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamComponent.rb', line 51
def test_process
stanzas = 0
message_lock = Semaphore.new
iq_lock = Semaphore.new
presence_lock = Semaphore.new
@stream.add_message_callback { |msg|
assert_kind_of(Message, msg)
stanzas += 1
message_lock.run
}
@stream.add_iq_callback { |iq|
assert_kind_of(Iq, iq)
stanzas += 1
iq_lock.run
}
@stream.add_presence_callback { |pres|
assert_kind_of(Presence, pres)
stanzas += 1
presence_lock.run
}
@server.send('<message/>')
@server.send('<iq/>')
@server.send('<presence/>')
message_lock.wait
iq_lock.wait
presence_lock.wait
assert_equal(3, stanzas)
end
|