From 42b5d260e490895a1c96731ee7dbc92326543cec Mon Sep 17 00:00:00 2001 From: Lars Kanis <kanis@comcard.de> Date: Thu, 25 Jun 2015 15:14:58 +0200 Subject: [PATCH] Add a test case for FXApp#addInput for socket accept() --- test/TC_FXApp.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/test/TC_FXApp.rb b/test/TC_FXApp.rb index 7501017..1ebef42 100755 --- a/test/TC_FXApp.rb +++ b/test/TC_FXApp.rb @@ -33,14 +33,16 @@ class TC_FXApp2 < Fox::TestCase app.removeInput(pipe_wr, INPUT_WRITE) app.addInput(pipe_rd, INPUT_READ, app, FXApp::ID_QUIT) - data_sent = false - app.addTimeout(1) do - data_sent = true - pipe_wr.write " " + 2.times do + data_sent = false + app.addTimeout(1) do + data_sent = true + pipe_wr.write " " + end + app.run + assert data_sent, "the read input event shouldn't fire before some data is available" + assert " ", pipe_rd.read(1) end - app.run - assert data_sent, "the read input event shouldn't fire before some data is available" - app.removeInput(pipe_rd, INPUT_READ) pipe_wr.close pipe_rd.close unless pipe_rd.closed? @@ -50,6 +52,22 @@ class TC_FXApp2 < Fox::TestCase check_events *IO.pipe end + def test_addInput_on_socket_accept + s = TCPServer.open 'localhost', 0 + app.addInput(s, INPUT_READ, app, FXApp::ID_QUIT) + 2.times do + pipe_wr = nil + app.addTimeout(1) do + pipe_wr = TCPSocket.open 'localhost', s.addr[1] + end + app.run + assert pipe_wr, "the read input event shouldn't fire before client connection happens" + s.accept.close + end + app.removeInput(s, INPUT_READ) + s.close + end + def test_addInput_on_socket s = TCPServer.open 'localhost', 0 pipe_wr = TCPSocket.open 'localhost', s.addr[1] -- GitLab