diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-17 00:17:46 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-17 00:17:46 +0000 |
commit | 076451c75336b30e6152bd5c02f355db39107f7d (patch) | |
tree | 785a6c71ca1e5246f2ce09a9b91f98eb902ac2a0 /test | |
parent | 89f3ecf7820857f91c4039536d2bbe3cf12d5f95 (diff) | |
download | luasocket-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.lua | 294 |
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 | |||
99 | control:setoption("tcp-nodelay", true) | 99 | control:setoption("tcp-nodelay", true) |
100 | 100 | ||
101 | ------------------------------------------------------------------------ | 101 | ------------------------------------------------------------------------ |
102 | test("method registration") | ||
103 | |||
104 | function test_methods(sock, methods) | 102 | function 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") |
111 | end | 109 | end |
112 | 110 | ||
113 | test_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 | |||
128 | test_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 | ------------------------------------------------------------------------ |
143 | test("mixed patterns") | ||
144 | |||
145 | function test_mixed(len) | 112 | function 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 |
164 | end | 131 | end |
165 | 132 | ||
166 | |||
167 | test_mixed(1) | ||
168 | test_mixed(17) | ||
169 | test_mixed(200) | ||
170 | test_mixed(4091) | ||
171 | test_mixed(80199) | ||
172 | test_mixed(4091) | ||
173 | test_mixed(200) | ||
174 | test_mixed(17) | ||
175 | test_mixed(1) | ||
176 | |||
177 | ------------------------------------------------------------------------ | 133 | ------------------------------------------------------------------------ |
178 | test("character line") | ||
179 | reconnect() | ||
180 | |||
181 | function test_asciiline(len) | 134 | function 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 |
195 | end | 148 | end |
196 | 149 | ||
197 | test_asciiline(1) | ||
198 | test_asciiline(17) | ||
199 | test_asciiline(200) | ||
200 | test_asciiline(4091) | ||
201 | test_asciiline(80199) | ||
202 | test_asciiline(800000) | ||
203 | test_asciiline(80199) | ||
204 | test_asciiline(4091) | ||
205 | test_asciiline(200) | ||
206 | test_asciiline(17) | ||
207 | test_asciiline(1) | ||
208 | |||
209 | ------------------------------------------------------------------------ | 150 | ------------------------------------------------------------------------ |
210 | test("binary line") | ||
211 | reconnect() | ||
212 | |||
213 | function test_rawline(len) | 151 | function 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 |
228 | end | 166 | end |
229 | 167 | ||
230 | test_rawline(1) | ||
231 | test_rawline(17) | ||
232 | test_rawline(200) | ||
233 | test_rawline(4091) | ||
234 | test_rawline(80199) | ||
235 | test_rawline(800000) | ||
236 | test_rawline(80199) | ||
237 | test_rawline(4091) | ||
238 | test_rawline(200) | ||
239 | test_rawline(17) | ||
240 | test_rawline(1) | ||
241 | |||
242 | ------------------------------------------------------------------------ | 168 | ------------------------------------------------------------------------ |
243 | test("raw transfer") | ||
244 | reconnect() | ||
245 | |||
246 | function test_raw(len) | 169 | function 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 |
262 | end | 185 | end |
263 | 186 | ||
264 | test_raw(1) | ||
265 | test_raw(17) | ||
266 | test_raw(200) | ||
267 | test_raw(4091) | ||
268 | test_raw(80199) | ||
269 | test_raw(800000) | ||
270 | test_raw(80199) | ||
271 | test_raw(4091) | ||
272 | test_raw(200) | ||
273 | test_raw(17) | ||
274 | test_raw(1) | ||
275 | ------------------------------------------------------------------------ | ||
276 | test("non-blocking transfer") | ||
277 | reconnect() | ||
278 | |||
279 | -- the value is not important, we only want | ||
280 | -- to test non-blockin I/O anyways | ||
281 | data:settimeout(200) | ||
282 | test_raw(1) | ||
283 | test_raw(17) | ||
284 | test_raw(200) | ||
285 | test_raw(4091) | ||
286 | test_raw(80199) | ||
287 | test_raw(800000) | ||
288 | test_raw(80199) | ||
289 | test_raw(4091) | ||
290 | test_raw(200) | ||
291 | test_raw(17) | ||
292 | test_raw(1) | ||
293 | |||
294 | ------------------------------------------------------------------------ | 187 | ------------------------------------------------------------------------ |
295 | test("total timeout on receive") | ||
296 | function test_totaltimeoutreceive(len, tm, sl) | 188 | function 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) |
313 | end | 205 | end |
314 | test_totaltimeoutreceive(800091, 1, 3) | ||
315 | test_totaltimeoutreceive(800091, 2, 3) | ||
316 | test_totaltimeoutreceive(800091, 3, 2) | ||
317 | test_totaltimeoutreceive(800091, 3, 1) | ||
318 | 206 | ||
319 | ------------------------------------------------------------------------ | 207 | ------------------------------------------------------------------------ |
320 | test("total timeout on send") | ||
321 | function test_totaltimeoutsend(len, tm, sl) | 208 | function 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) |
338 | end | 225 | end |
339 | test_totaltimeoutsend(800091, 1, 3) | ||
340 | test_totaltimeoutsend(800091, 2, 3) | ||
341 | test_totaltimeoutsend(800091, 3, 2) | ||
342 | test_totaltimeoutsend(800091, 3, 1) | ||
343 | 226 | ||
344 | ------------------------------------------------------------------------ | 227 | ------------------------------------------------------------------------ |
345 | test("blocking timeout on receive") | ||
346 | function test_blockingtimeoutreceive(len, tm, sl) | 228 | function 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) |
363 | end | 245 | end |
364 | test_blockingtimeoutreceive(800091, 1, 3) | ||
365 | test_blockingtimeoutreceive(800091, 2, 3) | ||
366 | test_blockingtimeoutreceive(800091, 3, 2) | ||
367 | test_blockingtimeoutreceive(800091, 3, 1) | ||
368 | 246 | ||
369 | ------------------------------------------------------------------------ | 247 | ------------------------------------------------------------------------ |
370 | test("blocking timeout on send") | ||
371 | function test_blockingtimeoutsend(len, tm, sl) | 248 | function 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) |
388 | end | 265 | end |
389 | test_blockingtimeoutsend(800091, 1, 3) | ||
390 | test_blockingtimeoutsend(800091, 2, 3) | ||
391 | test_blockingtimeoutsend(800091, 3, 2) | ||
392 | test_blockingtimeoutsend(800091, 3, 1) | ||
393 | 266 | ||
394 | ------------------------------------------------------------------------ | 267 | ------------------------------------------------------------------------ |
395 | test("bugs") | ||
396 | |||
397 | io.write("empty host connect: ") | ||
398 | function empty_connect() | 268 | function 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 |
409 | end | 279 | end |
410 | 280 | ||
411 | empty_connect() | 281 | ------------------------------------------------------------------------ |
282 | function isclosed(c) | ||
283 | return c:fd() == -1 or c:fd() == (2^32-1) | ||
284 | end | ||
412 | 285 | ||
413 | -- io.write("active close: ") | ||
414 | function active_close() | 286 | function 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") |
425 | end | 297 | end |
426 | 298 | ||
427 | -- active_close() | ||
428 | |||
429 | ------------------------------------------------------------------------ | 299 | ------------------------------------------------------------------------ |
430 | test("closed connection detection") | ||
431 | |||
432 | function test_closed() | 300 | function 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 |
456 | pass("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 |
458 | fail("got '"..err.."' instead of 'closed'.") | 326 | fail("got '"..err.."' instead of 'closed'.") |
459 | else | 327 | else |
460 | pass("graceful 'closed' received after %d bytes were sent", total) | 328 | pass("graceful 'closed' received after %d bytes were sent", total) |
461 | end | 329 | end |
462 | end | 330 | end |
463 | 331 | ||
464 | test_closed() | ||
465 | |||
466 | ------------------------------------------------------------------------ | 332 | ------------------------------------------------------------------------ |
467 | test("select function") | ||
468 | function test_selectbugs() | 333 | function 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") |
482 | end | 347 | end |
483 | 348 | ||
349 | test("method registration") | ||
350 | test_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 | }) | ||
364 | test_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 | |||
378 | test("mixed patterns") | ||
379 | reconnect() | ||
380 | test_mixed(1) | ||
381 | test_mixed(17) | ||
382 | test_mixed(200) | ||
383 | test_mixed(4091) | ||
384 | test_mixed(801990) | ||
385 | test_mixed(4091) | ||
386 | test_mixed(200) | ||
387 | test_mixed(17) | ||
388 | test_mixed(1) | ||
389 | |||
390 | test("character line") | ||
391 | reconnect() | ||
392 | test_asciiline(1) | ||
393 | test_asciiline(17) | ||
394 | test_asciiline(200) | ||
395 | test_asciiline(4091) | ||
396 | test_asciiline(80199) | ||
397 | test_asciiline(8000000) | ||
398 | test_asciiline(80199) | ||
399 | test_asciiline(4091) | ||
400 | test_asciiline(200) | ||
401 | test_asciiline(17) | ||
402 | test_asciiline(1) | ||
403 | |||
404 | test("binary line") | ||
405 | reconnect() | ||
406 | test_rawline(1) | ||
407 | test_rawline(17) | ||
408 | test_rawline(200) | ||
409 | test_rawline(4091) | ||
410 | test_rawline(80199) | ||
411 | test_rawline(8000000) | ||
412 | test_rawline(80199) | ||
413 | test_rawline(4091) | ||
414 | test_rawline(200) | ||
415 | test_rawline(17) | ||
416 | test_rawline(1) | ||
417 | |||
418 | test("raw transfer") | ||
419 | reconnect() | ||
420 | test_raw(1) | ||
421 | test_raw(17) | ||
422 | test_raw(200) | ||
423 | test_raw(4091) | ||
424 | test_raw(80199) | ||
425 | test_raw(8000000) | ||
426 | test_raw(80199) | ||
427 | test_raw(4091) | ||
428 | test_raw(200) | ||
429 | test_raw(17) | ||
430 | test_raw(1) | ||
431 | |||
432 | test("non-blocking transfer") | ||
433 | reconnect() | ||
434 | -- the value is not important, we only want | ||
435 | -- to test non-blockin I/O anyways | ||
436 | data:settimeout(200) | ||
437 | test_raw(1) | ||
438 | test_raw(17) | ||
439 | test_raw(200) | ||
440 | test_raw(4091) | ||
441 | test_raw(80199) | ||
442 | test_raw(8000000) | ||
443 | test_raw(80199) | ||
444 | test_raw(4091) | ||
445 | test_raw(200) | ||
446 | test_raw(17) | ||
447 | test_raw(1) | ||
448 | |||
449 | test("select function") | ||
484 | test_selectbugs() | 450 | test_selectbugs() |
485 | 451 | ||
452 | test("empty host connect: ") | ||
453 | empty_connect() | ||
454 | |||
455 | test("active close: ") | ||
456 | active_close() | ||
457 | |||
458 | test("closed connection detection: ") | ||
459 | test_closed() | ||
460 | |||
461 | a = [[ | ||
462 | test("total timeout on send") | ||
463 | test_totaltimeoutsend(800091, 1, 3) | ||
464 | test_totaltimeoutsend(800091, 2, 3) | ||
465 | test_totaltimeoutsend(800091, 3, 2) | ||
466 | test_totaltimeoutsend(800091, 3, 1) | ||
467 | |||
468 | test("total timeout on receive") | ||
469 | test_totaltimeoutreceive(800091, 1, 3) | ||
470 | test_totaltimeoutreceive(800091, 2, 3) | ||
471 | test_totaltimeoutreceive(800091, 3, 2) | ||
472 | test_totaltimeoutreceive(800091, 3, 1) | ||
473 | |||
474 | test("blocking timeout on send") | ||
475 | test_blockingtimeoutsend(800091, 1, 3) | ||
476 | test_blockingtimeoutsend(800091, 2, 3) | ||
477 | test_blockingtimeoutsend(800091, 3, 2) | ||
478 | test_blockingtimeoutsend(800091, 3, 1) | ||
479 | |||
480 | test("blocking timeout on receive") | ||
481 | test_blockingtimeoutreceive(800091, 1, 3) | ||
482 | test_blockingtimeoutreceive(800091, 2, 3) | ||
483 | test_blockingtimeoutreceive(800091, 3, 2) | ||
484 | test_blockingtimeoutreceive(800091, 3, 1) | ||
485 | ]] | ||
486 | |||
487 | socket.done() | ||
486 | 488 | ||
487 | test(string.format("done in %.2fs", socket.time() - start)) | 489 | test(string.format("done in %.2fs", socket.time() - start)) |