aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-17 00:17:46 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-17 00:17:46 +0000
commit076451c75336b30e6152bd5c02f355db39107f7d (patch)
tree785a6c71ca1e5246f2ce09a9b91f98eb902ac2a0 /test
parent89f3ecf7820857f91c4039536d2bbe3cf12d5f95 (diff)
downloadluasocket-076451c75336b30e6152bd5c02f355db39107f7d.tar.gz
luasocket-076451c75336b30e6152bd5c02f355db39107f7d.tar.bz2
luasocket-076451c75336b30e6152bd5c02f355db39107f7d.zip
Tested in windows. Still needs more testing, but progress has been made.
Diffstat (limited to 'test')
-rw-r--r--test/testclnt.lua294
1 files changed, 148 insertions, 146 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 2420711..6b07dca 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -99,8 +99,6 @@ else pass("connected!") end
99control:setoption("tcp-nodelay", true) 99control:setoption("tcp-nodelay", true)
100 100
101------------------------------------------------------------------------ 101------------------------------------------------------------------------
102test("method registration")
103
104function test_methods(sock, methods) 102function test_methods(sock, methods)
105 for _, v in methods do 103 for _, v in methods do
106 if type(sock[v]) ~= "function" then 104 if type(sock[v]) ~= "function" then
@@ -110,38 +108,7 @@ function test_methods(sock, methods)
110 pass(sock.class .. " methods are ok") 108 pass(sock.class .. " methods are ok")
111end 109end
112 110
113test_methods(socket.tcp(), {
114 "connect",
115 "send",
116 "receive",
117 "bind",
118 "accept",
119 "setpeername",
120 "setsockname",
121 "getpeername",
122 "getsockname",
123 "setoption",
124 "settimeout",
125 "close",
126})
127
128test_methods(socket.udp(), {
129 "getpeername",
130 "getsockname",
131 "setsockname",
132 "setpeername",
133 "send",
134 "sendto",
135 "receive",
136 "receivefrom",
137 "setoption",
138 "settimeout",
139 "close",
140})
141
142------------------------------------------------------------------------ 111------------------------------------------------------------------------
143test("mixed patterns")
144
145function test_mixed(len) 112function test_mixed(len)
146 reconnect() 113 reconnect()
147 local inter = math.ceil(len/4) 114 local inter = math.ceil(len/4)
@@ -163,21 +130,7 @@ remote "data:send(str); data:close()"
163 else fail("patterns don't match") end 130 else fail("patterns don't match") end
164end 131end
165 132
166
167test_mixed(1)
168test_mixed(17)
169test_mixed(200)
170test_mixed(4091)
171test_mixed(80199)
172test_mixed(4091)
173test_mixed(200)
174test_mixed(17)
175test_mixed(1)
176
177------------------------------------------------------------------------ 133------------------------------------------------------------------------
178test("character line")
179reconnect()
180
181function test_asciiline(len) 134function test_asciiline(len)
182 local str, str10, back, err 135 local str, str10, back, err
183 str = string.rep("x", math.mod(len, 10)) 136 str = string.rep("x", math.mod(len, 10))
@@ -194,22 +147,7 @@ remote "data:send(str, '\\n')"
194 else fail("lines don't match") end 147 else fail("lines don't match") end
195end 148end
196 149
197test_asciiline(1)
198test_asciiline(17)
199test_asciiline(200)
200test_asciiline(4091)
201test_asciiline(80199)
202test_asciiline(800000)
203test_asciiline(80199)
204test_asciiline(4091)
205test_asciiline(200)
206test_asciiline(17)
207test_asciiline(1)
208
209------------------------------------------------------------------------ 150------------------------------------------------------------------------
210test("binary line")
211reconnect()
212
213function test_rawline(len) 151function test_rawline(len)
214 local str, str10, back, err 152 local str, str10, back, err
215 str = string.rep(string.char(47), math.mod(len, 10)) 153 str = string.rep(string.char(47), math.mod(len, 10))
@@ -227,22 +165,7 @@ remote "data:send(str, '\\n')"
227 else fail("lines don't match") end 165 else fail("lines don't match") end
228end 166end
229 167
230test_rawline(1)
231test_rawline(17)
232test_rawline(200)
233test_rawline(4091)
234test_rawline(80199)
235test_rawline(800000)
236test_rawline(80199)
237test_rawline(4091)
238test_rawline(200)
239test_rawline(17)
240test_rawline(1)
241
242------------------------------------------------------------------------ 168------------------------------------------------------------------------
243test("raw transfer")
244reconnect()
245
246function test_raw(len) 169function test_raw(len)
247 local half = math.floor(len/2) 170 local half = math.floor(len/2)
248 local s1, s2, back, err 171 local s1, s2, back, err
@@ -261,38 +184,7 @@ remote "data:send(str)"
261 else fail("blocks don't match") end 184 else fail("blocks don't match") end
262end 185end
263 186
264test_raw(1)
265test_raw(17)
266test_raw(200)
267test_raw(4091)
268test_raw(80199)
269test_raw(800000)
270test_raw(80199)
271test_raw(4091)
272test_raw(200)
273test_raw(17)
274test_raw(1)
275------------------------------------------------------------------------
276test("non-blocking transfer")
277reconnect()
278
279-- the value is not important, we only want
280-- to test non-blockin I/O anyways
281data:settimeout(200)
282test_raw(1)
283test_raw(17)
284test_raw(200)
285test_raw(4091)
286test_raw(80199)
287test_raw(800000)
288test_raw(80199)
289test_raw(4091)
290test_raw(200)
291test_raw(17)
292test_raw(1)
293
294------------------------------------------------------------------------ 187------------------------------------------------------------------------
295test("total timeout on receive")
296function test_totaltimeoutreceive(len, tm, sl) 188function test_totaltimeoutreceive(len, tm, sl)
297 local str, err, total 189 local str, err, total
298 reconnect() 190 reconnect()
@@ -311,13 +203,8 @@ function test_totaltimeoutreceive(len, tm, sl)
311 check_timeout(tm, sl, elapsed, err, "receive", "total", 203 check_timeout(tm, sl, elapsed, err, "receive", "total",
312 string.len(str) == 2*len) 204 string.len(str) == 2*len)
313end 205end
314test_totaltimeoutreceive(800091, 1, 3)
315test_totaltimeoutreceive(800091, 2, 3)
316test_totaltimeoutreceive(800091, 3, 2)
317test_totaltimeoutreceive(800091, 3, 1)
318 206
319------------------------------------------------------------------------ 207------------------------------------------------------------------------
320test("total timeout on send")
321function test_totaltimeoutsend(len, tm, sl) 208function test_totaltimeoutsend(len, tm, sl)
322 local str, err, total 209 local str, err, total
323 reconnect() 210 reconnect()
@@ -336,13 +223,8 @@ function test_totaltimeoutsend(len, tm, sl)
336 check_timeout(tm, sl, elapsed, err, "send", "total", 223 check_timeout(tm, sl, elapsed, err, "send", "total",
337 total == 2*len) 224 total == 2*len)
338end 225end
339test_totaltimeoutsend(800091, 1, 3)
340test_totaltimeoutsend(800091, 2, 3)
341test_totaltimeoutsend(800091, 3, 2)
342test_totaltimeoutsend(800091, 3, 1)
343 226
344------------------------------------------------------------------------ 227------------------------------------------------------------------------
345test("blocking timeout on receive")
346function test_blockingtimeoutreceive(len, tm, sl) 228function test_blockingtimeoutreceive(len, tm, sl)
347 local str, err, total 229 local str, err, total
348 reconnect() 230 reconnect()
@@ -361,13 +243,8 @@ function test_blockingtimeoutreceive(len, tm, sl)
361 check_timeout(tm, sl, elapsed, err, "receive", "blocking", 243 check_timeout(tm, sl, elapsed, err, "receive", "blocking",
362 string.len(str) == 2*len) 244 string.len(str) == 2*len)
363end 245end
364test_blockingtimeoutreceive(800091, 1, 3)
365test_blockingtimeoutreceive(800091, 2, 3)
366test_blockingtimeoutreceive(800091, 3, 2)
367test_blockingtimeoutreceive(800091, 3, 1)
368 246
369------------------------------------------------------------------------ 247------------------------------------------------------------------------
370test("blocking timeout on send")
371function test_blockingtimeoutsend(len, tm, sl) 248function test_blockingtimeoutsend(len, tm, sl)
372 local str, err, total 249 local str, err, total
373 reconnect() 250 reconnect()
@@ -386,15 +263,8 @@ function test_blockingtimeoutsend(len, tm, sl)
386 check_timeout(tm, sl, elapsed, err, "send", "blocking", 263 check_timeout(tm, sl, elapsed, err, "send", "blocking",
387 total == 2*len) 264 total == 2*len)
388end 265end
389test_blockingtimeoutsend(800091, 1, 3)
390test_blockingtimeoutsend(800091, 2, 3)
391test_blockingtimeoutsend(800091, 3, 2)
392test_blockingtimeoutsend(800091, 3, 1)
393 266
394------------------------------------------------------------------------ 267------------------------------------------------------------------------
395test("bugs")
396
397io.write("empty host connect: ")
398function empty_connect() 268function empty_connect()
399 if data then data:close() data = nil end 269 if data then data:close() data = nil end
400 remote [[ 270 remote [[
@@ -408,27 +278,25 @@ function empty_connect()
408 else fail("should not have connected!") end 278 else fail("should not have connected!") end
409end 279end
410 280
411empty_connect() 281------------------------------------------------------------------------
282function isclosed(c)
283 return c:fd() == -1 or c:fd() == (2^32-1)
284end
412 285
413-- io.write("active close: ")
414function active_close() 286function active_close()
415 reconnect() 287 reconnect()
416 if socket._isclosed(data) then fail("should not be closed") end 288 if isclosed(data) then fail("should not be closed") end
417 data:close() 289 data:close()
418 if not socket._isclosed(data) then fail("should be closed") end 290 if not isclosed(data) then fail("should be closed") end
419 data = nil 291 data = nil
420 local udp = socket.udp() 292 local udp = socket.udp()
421 if socket._isclosed(udp) then fail("should not be closed") end 293 if isclosed(udp) then fail("should not be closed") end
422 udp:close() 294 udp:close()
423 if not socket._isclosed(udp) then fail("should be closed") end 295 if not isclosed(udp) then fail("should be closed") end
424 pass("ok") 296 pass("ok")
425end 297end
426 298
427-- active_close()
428
429------------------------------------------------------------------------ 299------------------------------------------------------------------------
430test("closed connection detection")
431
432function test_closed() 300function test_closed()
433 local back, err 301 local back, err
434 local str = 'little string' 302 local str = 'little string'
@@ -453,18 +321,15 @@ function test_closed()
453 ]] 321 ]]
454 total, err = data:send(string.rep("ugauga", 100000)) 322 total, err = data:send(string.rep("ugauga", 100000))
455 if not err then 323 if not err then
456pass("failed: output buffer is at least %d bytes long!", total) 324 pass("failed: output buffer is at least %d bytes long!", total)
457 elseif err ~= "closed" then 325 elseif err ~= "closed" then
458fail("got '"..err.."' instead of 'closed'.") 326 fail("got '"..err.."' instead of 'closed'.")
459 else 327 else
460pass("graceful 'closed' received after %d bytes were sent", total) 328 pass("graceful 'closed' received after %d bytes were sent", total)
461 end 329 end
462end 330end
463 331
464test_closed()
465
466------------------------------------------------------------------------ 332------------------------------------------------------------------------
467test("select function")
468function test_selectbugs() 333function test_selectbugs()
469 local r, s, e = socket.select(nil, nil, 0.1) 334 local r, s, e = socket.select(nil, nil, 0.1)
470 assert(type(r) == "table" and type(s) == "table" and e == "timeout") 335 assert(type(r) == "table" and type(s) == "table" and e == "timeout")
@@ -481,7 +346,144 @@ function test_selectbugs()
481 pass("invalid input: ok") 346 pass("invalid input: ok")
482end 347end
483 348
349test("method registration")
350test_methods(socket.tcp(), {
351 "connect",
352 "send",
353 "receive",
354 "bind",
355 "accept",
356 "setpeername",
357 "setsockname",
358 "getpeername",
359 "getsockname",
360 "setoption",
361 "settimeout",
362 "close",
363})
364test_methods(socket.udp(), {
365 "getpeername",
366 "getsockname",
367 "setsockname",
368 "setpeername",
369 "send",
370 "sendto",
371 "receive",
372 "receivefrom",
373 "setoption",
374 "settimeout",
375 "close",
376})
377
378test("mixed patterns")
379reconnect()
380test_mixed(1)
381test_mixed(17)
382test_mixed(200)
383test_mixed(4091)
384test_mixed(801990)
385test_mixed(4091)
386test_mixed(200)
387test_mixed(17)
388test_mixed(1)
389
390test("character line")
391reconnect()
392test_asciiline(1)
393test_asciiline(17)
394test_asciiline(200)
395test_asciiline(4091)
396test_asciiline(80199)
397test_asciiline(8000000)
398test_asciiline(80199)
399test_asciiline(4091)
400test_asciiline(200)
401test_asciiline(17)
402test_asciiline(1)
403
404test("binary line")
405reconnect()
406test_rawline(1)
407test_rawline(17)
408test_rawline(200)
409test_rawline(4091)
410test_rawline(80199)
411test_rawline(8000000)
412test_rawline(80199)
413test_rawline(4091)
414test_rawline(200)
415test_rawline(17)
416test_rawline(1)
417
418test("raw transfer")
419reconnect()
420test_raw(1)
421test_raw(17)
422test_raw(200)
423test_raw(4091)
424test_raw(80199)
425test_raw(8000000)
426test_raw(80199)
427test_raw(4091)
428test_raw(200)
429test_raw(17)
430test_raw(1)
431
432test("non-blocking transfer")
433reconnect()
434-- the value is not important, we only want
435-- to test non-blockin I/O anyways
436data:settimeout(200)
437test_raw(1)
438test_raw(17)
439test_raw(200)
440test_raw(4091)
441test_raw(80199)
442test_raw(8000000)
443test_raw(80199)
444test_raw(4091)
445test_raw(200)
446test_raw(17)
447test_raw(1)
448
449test("select function")
484test_selectbugs() 450test_selectbugs()
485 451
452test("empty host connect: ")
453empty_connect()
454
455test("active close: ")
456active_close()
457
458test("closed connection detection: ")
459test_closed()
460
461a = [[
462test("total timeout on send")
463test_totaltimeoutsend(800091, 1, 3)
464test_totaltimeoutsend(800091, 2, 3)
465test_totaltimeoutsend(800091, 3, 2)
466test_totaltimeoutsend(800091, 3, 1)
467
468test("total timeout on receive")
469test_totaltimeoutreceive(800091, 1, 3)
470test_totaltimeoutreceive(800091, 2, 3)
471test_totaltimeoutreceive(800091, 3, 2)
472test_totaltimeoutreceive(800091, 3, 1)
473
474test("blocking timeout on send")
475test_blockingtimeoutsend(800091, 1, 3)
476test_blockingtimeoutsend(800091, 2, 3)
477test_blockingtimeoutsend(800091, 3, 2)
478test_blockingtimeoutsend(800091, 3, 1)
479
480test("blocking timeout on receive")
481test_blockingtimeoutreceive(800091, 1, 3)
482test_blockingtimeoutreceive(800091, 2, 3)
483test_blockingtimeoutreceive(800091, 3, 2)
484test_blockingtimeoutreceive(800091, 3, 1)
485]]
486
487socket.done()
486 488
487test(string.format("done in %.2fs", socket.time() - start)) 489test(string.format("done in %.2fs", socket.time() - start))