diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-03-07 22:38:54 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-03-07 22:38:54 +0000 |
| commit | 22396d34f5443eb7f342b25783cbd771d2493ded (patch) | |
| tree | e8bf81cf0959946b1d412979a6c8f5798584ba87 | |
| parent | bbb4b3e2c19376ee124033b68f699d44f48bee52 (diff) | |
| download | luasocket-22396d34f5443eb7f342b25783cbd771d2493ded.tar.gz luasocket-22396d34f5443eb7f342b25783cbd771d2493ded.tar.bz2 luasocket-22396d34f5443eb7f342b25783cbd771d2493ded.zip | |
Updated for release 1.2.1.
Added '*w' pattern test.
| -rw-r--r-- | test/testclnt.lua | 70 | ||||
| -rw-r--r-- | test/testsrvr.lua | 12 |
2 files changed, 48 insertions, 34 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua index 8ad0f38..ca67761 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
| @@ -1,32 +1,11 @@ | |||
| 1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
| 2 | -- LuaSocket automated test module | 2 | -- LuaSocket automated test module |
| 3 | -- client.lua | 3 | -- testclnt.lua |
| 4 | -- This is the client module. It connects with the server module and executes | 4 | -- This is the client module. It connects with the server module and executes |
| 5 | -- all tests. | 5 | -- all tests. |
| 6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
| 7 | 7 | ||
| 8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
| 9 | -- Prints a header to separate the test phases | ||
| 10 | -- Input | ||
| 11 | -- test: test phase name | ||
| 12 | ----------------------------------------------------------------------------- | ||
| 13 | function new_test(test) | ||
| 14 | write("----------------------------------------------\n", | ||
| 15 | test, "\n", | ||
| 16 | "----------------------------------------------\n") | ||
| 17 | end | ||
| 18 | |||
| 19 | ----------------------------------------------------------------------------- | ||
| 20 | -- Get host and port from command line | ||
| 21 | ----------------------------------------------------------------------------- | ||
| 22 | HOST = "127.0.0.1" | ||
| 23 | PORT = 2020 | ||
| 24 | if arg then | ||
| 25 | HOST = arg[1] or HOST | ||
| 26 | PORT = arg[2] or PORT | ||
| 27 | end | ||
| 28 | |||
| 29 | ----------------------------------------------------------------------------- | ||
| 30 | -- Read command definitions | 9 | -- Read command definitions |
| 31 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
| 32 | assert(dofile("testcmd.lua")) | 11 | assert(dofile("testcmd.lua")) |
| @@ -114,6 +93,27 @@ function test_asciiline(len) | |||
| 114 | end | 93 | end |
| 115 | 94 | ||
| 116 | ----------------------------------------------------------------------------- | 95 | ----------------------------------------------------------------------------- |
| 96 | -- Tests multiple pattern transmission | ||
| 97 | -- Input | ||
| 98 | -- len: length of line to be tested | ||
| 99 | ----------------------------------------------------------------------------- | ||
| 100 | function test_multiple() | ||
| 101 | local p1 = "unix line\n" | ||
| 102 | local p2 = "dos line\r\n" | ||
| 103 | local p3 = "raw bytes" | ||
| 104 | local bp1, bp2, bp3 | ||
| 105 | reconnect() | ||
| 106 | send_command(ECHO_BLOCK, strlen(p1)+strlen(p2)+strlen(p3)) | ||
| 107 | err = data:send(p1, p2, p3) | ||
| 108 | if err then fail(err) end | ||
| 109 | bp1, bp2, bp3, err = data:receive("*lu", "*l", strlen(p3)) | ||
| 110 | if err then fail(err) end | ||
| 111 | if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 then | ||
| 112 | pass("patterns match") | ||
| 113 | else fail("patterns don't match") end | ||
| 114 | end | ||
| 115 | |||
| 116 | ----------------------------------------------------------------------------- | ||
| 117 | -- Tests closed connection detection | 117 | -- Tests closed connection detection |
| 118 | ----------------------------------------------------------------------------- | 118 | ----------------------------------------------------------------------------- |
| 119 | function test_closed() | 119 | function test_closed() |
| @@ -295,9 +295,27 @@ function test_returntimeout(len, t, s) | |||
| 295 | else fail("blocks don't match") end | 295 | else fail("blocks don't match") end |
| 296 | end | 296 | end |
| 297 | 297 | ||
| 298 | |||
| 299 | |||
| 300 | |||
| 298 | ----------------------------------------------------------------------------- | 301 | ----------------------------------------------------------------------------- |
| 299 | -- Tests return-timeout conformance | 302 | -- Tests read patterns |
| 300 | ----------------------------------------------------------------------------- | 303 | ----------------------------------------------------------------------------- |
| 304 | function test_word() | ||
| 305 | local b1 = " \t one two three \n this_is_a_very" | ||
| 306 | local b2 = "_big_word " | ||
| 307 | send_command(ECHO_BLOCK, strlen(b1)+strlen(b2)) | ||
| 308 | err = data:send(b1, b2) | ||
| 309 | local a1, a2, a3, a4 | ||
| 310 | a1, a2, a3, a4, err = data:receive("*w", "*w", "*w", "*w") | ||
| 311 | if err then fail(err) end | ||
| 312 | _, err = data:receive(1) -- get last space | ||
| 313 | if err then fail(err) end | ||
| 314 | if a1 ~= "one" or a2 ~= "two" or a3 ~= "three" or | ||
| 315 | a4 ~= "this_is_a_very_big_word" then fail("'*w' failed") end | ||
| 316 | pass("'*w' is ok") | ||
| 317 | end | ||
| 318 | |||
| 301 | function test_patterns() | 319 | function test_patterns() |
| 302 | local dos_line1 = "this the first dos line" | 320 | local dos_line1 = "this the first dos line" |
| 303 | local dos_line2 = "this is another dos line" | 321 | local dos_line2 = "this is another dos line" |
| @@ -333,6 +351,7 @@ function test_patterns() | |||
| 333 | back = data:receive(strlen(block)) | 351 | back = data:receive(strlen(block)) |
| 334 | if back ~= block then fail("number failed") end | 352 | if back ~= block then fail("number failed") end |
| 335 | pass("number is ok") | 353 | pass("number is ok") |
| 354 | test_word() | ||
| 336 | send_command(ECHO_BLOCK, strlen(block)) | 355 | send_command(ECHO_BLOCK, strlen(block)) |
| 337 | send_command(SLEEP, 1) | 356 | send_command(SLEEP, 1) |
| 338 | send_command(CLOSE) | 357 | send_command(CLOSE) |
| @@ -356,12 +375,16 @@ test_command(ECHO_BLOCK, 12234) | |||
| 356 | test_command(SLEEP, 1111) | 375 | test_command(SLEEP, 1111) |
| 357 | test_command(ECHO_LINE) | 376 | test_command(ECHO_LINE) |
| 358 | 377 | ||
| 378 | --a = [[ | ||
| 359 | new_test("connection close test") | 379 | new_test("connection close test") |
| 360 | test_closed() | 380 | test_closed() |
| 361 | 381 | ||
| 362 | new_test("read pattern test") | 382 | new_test("read pattern test") |
| 363 | test_patterns() | 383 | test_patterns() |
| 364 | 384 | ||
| 385 | new_test("multiple pattern test") | ||
| 386 | test_multiple() | ||
| 387 | |||
| 365 | new_test("character string test") | 388 | new_test("character string test") |
| 366 | test_asciiline(1) | 389 | test_asciiline(1) |
| 367 | test_asciiline(17) | 390 | test_asciiline(17) |
| @@ -414,6 +437,7 @@ test_returntimeout(8000, 1, 2) | |||
| 414 | test_returntimeout(80000, 2, 1) | 437 | test_returntimeout(80000, 2, 1) |
| 415 | test_returntimeout(800000, 0.1, 0) | 438 | test_returntimeout(800000, 0.1, 0) |
| 416 | test_returntimeout(800000, 2, 1) | 439 | test_returntimeout(800000, 2, 1) |
| 440 | --]] | ||
| 417 | 441 | ||
| 418 | ----------------------------------------------------------------------------- | 442 | ----------------------------------------------------------------------------- |
| 419 | -- Close connection and exit server. We are done. | 443 | -- Close connection and exit server. We are done. |
diff --git a/test/testsrvr.lua b/test/testsrvr.lua index efa5991..4530014 100644 --- a/test/testsrvr.lua +++ b/test/testsrvr.lua | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
| 2 | -- LuaSocket automated test module | 2 | -- LuaSocket automated test module |
| 3 | -- server.lua | 3 | -- testsrvr.lua |
| 4 | -- This is the server module. It's completely controled by the client module | 4 | -- This is the server module. It's completely controled by the client module |
| 5 | -- by the use of a control connection. | 5 | -- by the use of a control connection. |
| 6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
| @@ -12,16 +12,6 @@ assert(dofile("testcmd.lua")) | |||
| 12 | test_debug_mode() | 12 | test_debug_mode() |
| 13 | 13 | ||
| 14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
| 15 | -- Get host and port from command line | ||
| 16 | ----------------------------------------------------------------------------- | ||
| 17 | HOST = "localhost" | ||
| 18 | PORT = 2020 | ||
| 19 | if arg then | ||
| 20 | HOST = arg[1] or HOST | ||
| 21 | PORT = arg[2] or PORT | ||
| 22 | end | ||
| 23 | |||
| 24 | ----------------------------------------------------------------------------- | ||
| 25 | -- Start control connection | 15 | -- Start control connection |
| 26 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
| 27 | server, err = bind(HOST, PORT) | 17 | server, err = bind(HOST, PORT) |
