Class: TestLineAndTextProtocol

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/ext/eventmachine-0.12.10/tests/test_ltp.rb

Defined Under Namespace

Modules: StopClient Classes: BinaryTextTest, LineAndTextTest, SimpleLineTest

Constant Summary collapse

TestHost =
"127.0.0.1"
TestPort =
8905

Instance Method Summary collapse

Instance Method Details

#test_binary_textObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ext/eventmachine-0.12.10/tests/test_ltp.rb', line 161

def test_binary_text
  output = ''
  lines_received = []
  text_received = []
  EventMachine.run {
    EventMachine.start_server( TestHost, TestPort, BinaryTextTest ) do |conn|
      conn.instance_eval "@lines = lines_received; @text = text_received"
    end
    EventMachine.add_timer(4) {assert(false, "test timed out")}

    EventMachine.connect TestHost, TestPort, StopClient do |c|
      c.set_receive_data { |data| output << data }
      c.send_data "Content-length: 10000\n"
      c.send_data "A" * 10000
      EM.add_timer(0.2) { c.close_connection_after_writing }
    end
  }
  assert_equal( "received 10000 bytes", output )
end

#test_lines_and_textObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ext/eventmachine-0.12.10/tests/test_ltp.rb', line 121

def test_lines_and_text
  output = ''
  lines_received = []
  text_received = []
  EventMachine.run {
    EventMachine.start_server( TestHost, TestPort, LineAndTextTest ) do |conn|
      conn.instance_eval "@lines = lines_received; @text = text_received"
    end
    EventMachine.add_timer(4) {assert(false, "test timed out")}

    EventMachine.connect TestHost, TestPort, StopClient do |c|
      c.set_receive_data { |data| output << data }
      c.send_data "Content-length: 400\n"
      c.send_data "\n"
      c.send_data "A" * 400
      EM.add_timer(0.1) { c.close_connection_after_writing }
    end
  }
  assert_equal( "received 400 bytes", output )
end

#test_overlength_linesObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ext/eventmachine-0.12.10/tests/test_ltp.rb', line 84

def test_overlength_lines
  lines_received = []
  EventMachine.run {
    EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
      conn.instance_eval "@error_message = lines_received"
    end
    EventMachine.add_timer(4) {assert(false, "test timed out")}

    EventMachine.connect TestHost, TestPort, StopClient do |c|
      c.send_data "a" * (16*1024 + 1)
      c.send_data "\n"
      c.close_connection_after_writing
    end

  }
  assert_equal( ["overlength line"], lines_received )
end

#test_simple_linesObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ext/eventmachine-0.12.10/tests/test_ltp.rb', line 60

def test_simple_lines
  lines_received = []
  EventMachine.run {
    EventMachine.start_server( TestHost, TestPort, SimpleLineTest ) do |conn|
      conn.instance_eval "@line_buffer = lines_received"
    end
    EventMachine.add_timer(4) {assert(false, "test timed out")}

    EventMachine.connect TestHost, TestPort, StopClient do |c|
      c.send_data "aaa\nbbb\r\nccc\n"
      c.close_connection_after_writing
    end
  }
  assert_equal( %w(aaa bbb ccc), lines_received )
end