File: SocketServerTestCase.rb

package info (click to toggle)
quickfix 1.15.1%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 42,080 kB
  • sloc: cpp: 631,686; python: 129,549; ruby: 106,716; xml: 43,737; ansic: 7,668; java: 1,826; cs: 816; makefile: 544; sh: 462; sql: 313
file content (68 lines) | stat: -rw-r--r-- 1,516 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require './SocketServer'
require 'runit/testcase'
require "thread"

class SocketServerTestCase < RUNIT::TestCase

  def test_listen
    socketServer = SocketServer.new
    connectQueue = Queue.new
    receiveQueue = Queue.new
    disconnectQueue = Queue.new

    def socketServer.connectQueue=(q)
      @connectQueue = q
    end
    def socketServer.connectQueue
      return @connectQueue
    end

    def socketServer.receiveQueue=(q)
      @receiveQueue = q
    end
    def socketServer.receiveQueue
      return @receiveQueue
    end

    def socketServer.disconnectQueue=(q)
      @disconnectQueue = q
    end
    def socketServer.disconnectQueue
      return @disconnectQueue
    end

    def socketServer.connectAction(s)
      @connectQueue.push(true)
    end

    def socketServer.disconnectAction(s)
      @disconnectQueue.push(true)
    end

    def socketServer.receiveAction(s)
      while( str = s.gets )
	@receiveQueue.push(str)
      end
    end

    socketServer.connectQueue = connectQueue
    socketServer.receiveQueue = receiveQueue
    socketServer.disconnectQueue = disconnectQueue

    Thread.start do
      socketServer.listen(RUNIT::TestCase.port)
    end
    socketServer.wait

    s = TCPSocket.open("localhost", RUNIT::TestCase.port)
    assert(connectQueue.pop)
    s.write("test\r\n")
    s.write("test2\r\n")
    assert_equals("test\r\n", receiveQueue.pop)
    assert_equals("test2\r\n", receiveQueue.pop)
    s.close
    assert(disconnectQueue.pop)
    socketServer.stop()
  end

end