Add a test case for FXApp#addInput for socket accept()
Lars Kanis
8 years ago
32 | 32 | app.removeInput(pipe_wr, INPUT_WRITE) |
33 | 33 | |
34 | 34 | 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) | |
39 | 44 | end |
40 | app.run | |
41 | assert data_sent, "the read input event shouldn't fire before some data is available" | |
42 | ||
43 | 45 | app.removeInput(pipe_rd, INPUT_READ) |
44 | 46 | pipe_wr.close |
45 | 47 | pipe_rd.close unless pipe_rd.closed? |
47 | 49 | |
48 | 50 | def test_addInput_on_pipe |
49 | 51 | 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 | |
50 | 68 | end |
51 | 69 | |
52 | 70 | def test_addInput_on_socket |