aboutsummaryrefslogtreecommitdiff
path: root/test/testclnt.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/testclnt.lua')
-rw-r--r--test/testclnt.lua66
1 files changed, 33 insertions, 33 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 97e06f2..8ad0f38 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -59,7 +59,7 @@ end
59----------------------------------------------------------------------------- 59-----------------------------------------------------------------------------
60function reconnect() 60function reconnect()
61 if data then 61 if data then
62 close(data) 62 data:close()
63 send_command(CLOSE) 63 send_command(CLOSE)
64 data = nil 64 data = nil
65 end 65 end
@@ -105,9 +105,9 @@ function test_asciiline(len)
105 str10 = strrep("aZb.c#dAe?", floor(len/10)) 105 str10 = strrep("aZb.c#dAe?", floor(len/10))
106 str = str .. str10 106 str = str .. str10
107 write("testing ", len, " byte(s) line\n") 107 write("testing ", len, " byte(s) line\n")
108 err = send(data, str, "\n") 108 err = data:send(str, "\n")
109 if err then fail(err) end 109 if err then fail(err) end
110 back, err = receive(data) 110 back, err = data:receive()
111 if err then fail(err) end 111 if err then fail(err) end
112 if back == str then pass("lines match") 112 if back == str then pass("lines match")
113 else fail("lines don't match") end 113 else fail("lines don't match") end
@@ -123,10 +123,10 @@ function test_closed()
123 reconnect() 123 reconnect()
124 print("testing close while reading line") 124 print("testing close while reading line")
125 send_command(ECHO_BLOCK, len) 125 send_command(ECHO_BLOCK, len)
126 send(data, str) 126 data:send(str)
127 send_command(CLOSE) 127 send_command(CLOSE)
128 -- try to get a line 128 -- try to get a line
129 back, err = receive(data) 129 back, err = data:receive()
130 if not err then fail("shold have gotten 'closed'.") 130 if not err then fail("shold have gotten 'closed'.")
131 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") 131 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
132 elseif str ~= back then fail("didn't receive what i should 'closed'.") 132 elseif str ~= back then fail("didn't receive what i should 'closed'.")
@@ -134,10 +134,10 @@ function test_closed()
134 reconnect() 134 reconnect()
135 print("testing close while reading block") 135 print("testing close while reading block")
136 send_command(ECHO_BLOCK, len) 136 send_command(ECHO_BLOCK, len)
137 send(data, str) 137 data:send(str)
138 send_command(CLOSE) 138 send_command(CLOSE)
139 -- try to get a line 139 -- try to get a line
140 back, err = receive(data, 2*len) 140 back, err = data:receive(2*len)
141 if not err then fail("shold have gotten 'closed'.") 141 if not err then fail("shold have gotten 'closed'.")
142 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") 142 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
143 elseif str ~= back then fail("didn't receive what I should.") 143 elseif str ~= back then fail("didn't receive what I should.")
@@ -157,9 +157,9 @@ function test_rawline(len)
157 str10 = strrep(strchar(120,21,77,4,5,0,7,36,44,100), floor(len/10)) 157 str10 = strrep(strchar(120,21,77,4,5,0,7,36,44,100), floor(len/10))
158 str = str .. str10 158 str = str .. str10
159 write("testing ", len, " byte(s) line\n") 159 write("testing ", len, " byte(s) line\n")
160 err = send(data, str, "\n") 160 err = data:send(str, "\n")
161 if err then fail(err) end 161 if err then fail(err) end
162 back, err = receive(data) 162 back, err = data:receive()
163 if err then fail(err) end 163 if err then fail(err) end
164 if back == str then pass("lines match") 164 if back == str then pass("lines match")
165 else fail("lines don't match") end 165 else fail("lines don't match") end
@@ -177,12 +177,12 @@ function test_block(len)
177 send_command(ECHO_BLOCK, len) 177 send_command(ECHO_BLOCK, len)
178 write("testing ", len, " byte(s) block\n") 178 write("testing ", len, " byte(s) block\n")
179 s1 = strrep("x", half) 179 s1 = strrep("x", half)
180 err = send(data, s1) 180 err = data:send(s1)
181 if err then fail(err) end 181 if err then fail(err) end
182 s2 = strrep("y", len-half) 182 s2 = strrep("y", len-half)
183 err = send(data, s2) 183 err = data:send(s2)
184 if err then fail(err) end 184 if err then fail(err) end
185 back, err = receive(data, len) 185 back, err = data:receive(len)
186 if err then fail(err) end 186 if err then fail(err) end
187 if back == s1..s2 then pass("blocks match") 187 if back == s1..s2 then pass("blocks match")
188 else fail("blocks don't match") end 188 else fail("blocks don't match") end
@@ -229,15 +229,15 @@ function test_blockedtimeout(len, t, s)
229 send_command(RECEIVE_BLOCK, len) 229 send_command(RECEIVE_BLOCK, len)
230 write("testing ", len, " bytes, ", t, 230 write("testing ", len, " bytes, ", t,
231 "s block timeout, ", s, "s sleep\n") 231 "s block timeout, ", s, "s sleep\n")
232 timeout(data, t) 232 data:timeout(t)
233 str = strrep("a", 2*len) 233 str = strrep("a", 2*len)
234 err, total = send(data, str) 234 err, total = data:send(str)
235 if blockedtimed_out(t, s, err, "send") then return end 235 if blockedtimed_out(t, s, err, "send") then return end
236 if err then fail(err) end 236 if err then fail(err) end
237 send_command(SEND_BLOCK) 237 send_command(SEND_BLOCK)
238 send_command(SLEEP, s) 238 send_command(SLEEP, s)
239 send_command(SEND_BLOCK) 239 send_command(SEND_BLOCK)
240 back, err = receive(data, 2*len) 240 back, err = data:receive(2*len)
241 if blockedtimed_out(t, s, err, "receive") then return end 241 if blockedtimed_out(t, s, err, "receive") then return end
242 if err then fail(err) end 242 if err then fail(err) end
243 if back == str then pass("blocks match") 243 if back == str then pass("blocks match")
@@ -278,16 +278,16 @@ function test_returntimeout(len, t, s)
278 send_command(RECEIVE_BLOCK, len) 278 send_command(RECEIVE_BLOCK, len)
279 write("testing ", len, " bytes, ", t, 279 write("testing ", len, " bytes, ", t,
280 "s return timeout, ", s, "s sleep\n") 280 "s return timeout, ", s, "s sleep\n")
281 timeout(data, t, "return") 281 data:timeout(t, "return")
282 str = strrep("a", 2*len) 282 str = strrep("a", 2*len)
283 err, total, delta = send(data, str) 283 err, total, delta = data:send(str)
284 print("sent in " .. delta .. "s") 284 print("sent in " .. delta .. "s")
285 if returntimed_out(delta, t, err) then return end 285 if returntimed_out(delta, t, err) then return end
286 if err then fail("unexpected error: " .. err) end 286 if err then fail("unexpected error: " .. err) end
287 send_command(SEND_BLOCK) 287 send_command(SEND_BLOCK)
288 send_command(SLEEP, s) 288 send_command(SLEEP, s)
289 send_command(SEND_BLOCK) 289 send_command(SEND_BLOCK)
290 back, err, delta = receive(data, 2*len) 290 back, err, delta = data:receive(2*len)
291 print("received in " .. delta .. "s") 291 print("received in " .. delta .. "s")
292 if returntimed_out(delta, t, err) then return end 292 if returntimed_out(delta, t, err) then return end
293 if err then fail("unexpected error: " .. err) end 293 if err then fail("unexpected error: " .. err) end
@@ -308,37 +308,37 @@ function test_patterns()
308 block = block .. unix_line1 .. "\n" .. unix_line2 .. "\n" 308 block = block .. unix_line1 .. "\n" .. unix_line2 .. "\n"
309 block = block .. block 309 block = block .. block
310 send_command(ECHO_BLOCK, strlen(block)) 310 send_command(ECHO_BLOCK, strlen(block))
311 err = send(data, block) 311 err = data:send(block)
312 if err then fail(err) end 312 if err then fail(err) end
313 local back = receive(data, "*l") 313 local back = data:receive("*l")
314 if back ~= dos_line1 then fail("'*l' failed") end 314 if back ~= dos_line1 then fail("'*l' failed") end
315 back = receive(data, "*l") 315 back = data:receive("*l")
316 if back ~= dos_line2 then fail("'*l' failed") end 316 if back ~= dos_line2 then fail("'*l' failed") end
317 back = receive(data, "*lu") 317 back = data:receive("*lu")
318 if back ~= unix_line1 then fail("'*lu' failed") end 318 if back ~= unix_line1 then fail("'*lu' failed") end
319 back = receive(data, "*lu") 319 back = data:receive("*lu")
320 if back ~= unix_line2 then fail("'*lu' failed") end 320 if back ~= unix_line2 then fail("'*lu' failed") end
321 back = receive(data) 321 back = data:receive()
322 if back ~= dos_line1 then fail("default failed") end 322 if back ~= dos_line1 then fail("default failed") end
323 back = receive(data) 323 back = data:receive()
324 if back ~= dos_line2 then fail("default failed") end 324 if back ~= dos_line2 then fail("default failed") end
325 back = receive(data, "*lu") 325 back = data:receive("*lu")
326 if back ~= unix_line1 then fail("'*lu' failed") end 326 if back ~= unix_line1 then fail("'*lu' failed") end
327 back = receive(data, "*lu") 327 back = data:receive("*lu")
328 if back ~= unix_line2 then fail("'*lu' failed") end 328 if back ~= unix_line2 then fail("'*lu' failed") end
329 pass("line patterns are ok") 329 pass("line patterns are ok")
330 send_command(ECHO_BLOCK, strlen(block)) 330 send_command(ECHO_BLOCK, strlen(block))
331 err = send(data, block) 331 err = data:send(block)
332 if err then fail(err) end 332 if err then fail(err) end
333 back = receive(data, strlen(block)) 333 back = data:receive(strlen(block))
334 if back ~= block then fail("number failed") end 334 if back ~= block then fail("number failed") end
335 pass("number is ok") 335 pass("number is ok")
336 send_command(ECHO_BLOCK, strlen(block)) 336 send_command(ECHO_BLOCK, strlen(block))
337 send_command(SLEEP, 1) 337 send_command(SLEEP, 1)
338 send_command(CLOSE) 338 send_command(CLOSE)
339 err = send(data, block) 339 err = data:send(block)
340 if err then fail(err) end 340 if err then fail(err) end
341 back = receive(data, "*a") 341 back = data:receive("*a")
342 if back ~= block then fail("'*a' failed") end 342 if back ~= block then fail("'*a' failed") end
343 pass("'*a' is ok") 343 pass("'*a' is ok")
344end 344end
@@ -390,7 +390,7 @@ test_block(800000)
390new_test("non-blocking transfer test") 390new_test("non-blocking transfer test")
391-- the value is not important, we only want 391-- the value is not important, we only want
392-- to test non-blockin I/O anyways 392-- to test non-blockin I/O anyways
393timeout(data, 200) 393data:timeout(200)
394test_block(1) 394test_block(1)
395test_block(17) 395test_block(17)
396test_block(200) 396test_block(200)
@@ -421,7 +421,7 @@ test_returntimeout(800000, 2, 1)
421print("client: closing connection with server") 421print("client: closing connection with server")
422send_command(CLOSE) 422send_command(CLOSE)
423send_command(EXIT) 423send_command(EXIT)
424close(control) 424control:close()
425 425
426new_test("the library has passed all tests") 426new_test("the library has passed all tests")
427print(format("time elapsed: %6.2fs", time() - start)) 427print(format("time elapsed: %6.2fs", time() - start))