Class: ConnectionErrorTest
Constant Summary
collapse
- STREAM =
'<stream:stream xmlns:stream="http://etherx.jabber.org/streams">'
- @@SOCKET_PORT =
65225
Instance Method Summary
collapse
#assert_array_equal, expect, #run
Instance Method Details
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 14
def setup
servlisten = TCPServer.new(@@SOCKET_PORT)
serverwait = Semaphore.new
@server = nil
Thread.new do
Thread.current.abort_on_exception = true
@server = servlisten.accept
servlisten.close
@server.sync = true
serverwait.run
end
@conn = TCPSocket.new('localhost', @@SOCKET_PORT)
serverwait.wait
end
|
32
33
34
35
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 32
def teardown
@conn.close if not @conn.closed?
@server.close if not @conn.closed?
end
|
#test_connectionError_parse_withexcblock ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 60
def test_connectionError_parse_withexcblock
@stream = Stream.new
error = false
@stream.start(@conn)
@stream.on_exception do |e, o, w|
if w == :disconnected
assert_equal(nil, e)
assert_equal(Jabber::Stream, o.class)
else
assert_equal(REXML::ParseException, e.class)
assert_equal(Jabber::Stream, o.class)
assert_equal(:parser, w)
error = true
end
end
@server.puts(STREAM)
@server.flush
assert(!error)
@server.puts('</blop>')
@server.flush
sleep 0.2
assert(error)
@server.close
@stream.close
end
|
#test_connectionError_send_withexcblock ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 86
def test_connectionError_send_withexcblock
@stream = Stream.new
error = 0
@stream.start(@conn)
@stream.on_exception do |exc, o, w|
case w
when :sending
assert_equal(IOError, exc.class)
assert_equal(Jabber::Stream, o.class)
when :disconnected
assert_equal(nil, exc)
assert_equal(Jabber::Stream, o.class)
else
assert(false)
end
error += 1
end
@server.puts(STREAM)
@server.flush
assert_equal(0, error)
@server.close
sleep 0.1
assert_equal(1, error)
@stream.send('</test>')
sleep 0.1
@stream.send('</test>')
sleep 0.1
assert_equal(3, error)
@stream.close
end
|
#test_connectionError_send_withoutexcblock ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 117
def test_connectionError_send_withoutexcblock
@stream = Stream.new
@stream.start(@conn)
@server.puts(STREAM)
@server.flush
assert_raise(Errno::EPIPE) do
@server.close
sleep 0.1
@stream.send('</test>')
sleep 0.1
@stream.send('</test>')
sleep 0.1
end
end
|
#test_connectionError_start_withexcblock ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/gems/xmpp4r-0.4/test/tc_streamError.rb', line 37
def test_connectionError_start_withexcblock
@stream = Stream.new
error = false
@stream.on_exception do |e, o, w|
assert_kind_of(StandardError, e)
assert_equal(Jabber::Stream, o.class)
assert_equal(:start, w)
error = true
end
assert(!error)
begin
conn = TCPSocket.new('localhost', 1)
rescue
end
@stream.start(conn)
sleep 0.2
assert(error)
@server.close
@stream.close
end
|