Codebase list ruby-fxruby / 42b5d26
Add a test case for FXApp#addInput for socket accept() Lars Kanis 8 years ago
1 changed file(s) with 25 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
3232 app.removeInput(pipe_wr, INPUT_WRITE)
3333
3434 app.addInput(pipe_rd, INPUT_READ, app, FXApp::ID_QUIT)
35 data_sent = false
36 app.addTimeout(1) do
37 data_sent = true
38 pipe_wr.write " "
35 2.times do
36 data_sent = false
37 app.addTimeout(1) do
38 data_sent = true
39 pipe_wr.write " "
40 end
41 app.run
42 assert data_sent, "the read input event shouldn't fire before some data is available"
43 assert " ", pipe_rd.read(1)
3944 end
40 app.run
41 assert data_sent, "the read input event shouldn't fire before some data is available"
42
4345 app.removeInput(pipe_rd, INPUT_READ)
4446 pipe_wr.close
4547 pipe_rd.close unless pipe_rd.closed?
4749
4850 def test_addInput_on_pipe
4951 check_events *IO.pipe
52 end
53
54 def test_addInput_on_socket_accept
55 s = TCPServer.open 'localhost', 0
56 app.addInput(s, INPUT_READ, app, FXApp::ID_QUIT)
57 2.times do
58 pipe_wr = nil
59 app.addTimeout(1) do
60 pipe_wr = TCPSocket.open 'localhost', s.addr[1]
61 end
62 app.run
63 assert pipe_wr, "the read input event shouldn't fire before client connection happens"
64 s.accept.close
65 end
66 app.removeInput(s, INPUT_READ)
67 s.close
5068 end
5169
5270 def test_addInput_on_socket