aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2001-03-07 22:38:54 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2001-03-07 22:38:54 +0000
commit22396d34f5443eb7f342b25783cbd771d2493ded (patch)
treee8bf81cf0959946b1d412979a6c8f5798584ba87
parentbbb4b3e2c19376ee124033b68f699d44f48bee52 (diff)
downloadluasocket-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.lua70
-rw-r--r--test/testsrvr.lua12
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-----------------------------------------------------------------------------
13function new_test(test)
14 write("----------------------------------------------\n",
15 test, "\n",
16 "----------------------------------------------\n")
17end
18
19-----------------------------------------------------------------------------
20-- Get host and port from command line
21-----------------------------------------------------------------------------
22HOST = "127.0.0.1"
23PORT = 2020
24if arg then
25 HOST = arg[1] or HOST
26 PORT = arg[2] or PORT
27end
28
29-----------------------------------------------------------------------------
30-- Read command definitions 9-- Read command definitions
31----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
32assert(dofile("testcmd.lua")) 11assert(dofile("testcmd.lua"))
@@ -114,6 +93,27 @@ function test_asciiline(len)
114end 93end
115 94
116----------------------------------------------------------------------------- 95-----------------------------------------------------------------------------
96-- Tests multiple pattern transmission
97-- Input
98-- len: length of line to be tested
99-----------------------------------------------------------------------------
100function 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
114end
115
116-----------------------------------------------------------------------------
117-- Tests closed connection detection 117-- Tests closed connection detection
118----------------------------------------------------------------------------- 118-----------------------------------------------------------------------------
119function test_closed() 119function 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
296end 296end
297 297
298
299
300
298----------------------------------------------------------------------------- 301-----------------------------------------------------------------------------
299-- Tests return-timeout conformance 302-- Tests read patterns
300----------------------------------------------------------------------------- 303-----------------------------------------------------------------------------
304function 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")
317end
318
301function test_patterns() 319function 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)
356test_command(SLEEP, 1111) 375test_command(SLEEP, 1111)
357test_command(ECHO_LINE) 376test_command(ECHO_LINE)
358 377
378--a = [[
359new_test("connection close test") 379new_test("connection close test")
360test_closed() 380test_closed()
361 381
362new_test("read pattern test") 382new_test("read pattern test")
363test_patterns() 383test_patterns()
364 384
385new_test("multiple pattern test")
386test_multiple()
387
365new_test("character string test") 388new_test("character string test")
366test_asciiline(1) 389test_asciiline(1)
367test_asciiline(17) 390test_asciiline(17)
@@ -414,6 +437,7 @@ test_returntimeout(8000, 1, 2)
414test_returntimeout(80000, 2, 1) 437test_returntimeout(80000, 2, 1)
415test_returntimeout(800000, 0.1, 0) 438test_returntimeout(800000, 0.1, 0)
416test_returntimeout(800000, 2, 1) 439test_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"))
12test_debug_mode() 12test_debug_mode()
13 13
14----------------------------------------------------------------------------- 14-----------------------------------------------------------------------------
15-- Get host and port from command line
16-----------------------------------------------------------------------------
17HOST = "localhost"
18PORT = 2020
19if arg then
20 HOST = arg[1] or HOST
21 PORT = arg[2] or PORT
22end
23
24-----------------------------------------------------------------------------
25-- Start control connection 15-- Start control connection
26----------------------------------------------------------------------------- 16-----------------------------------------------------------------------------
27server, err = bind(HOST, PORT) 17server, err = bind(HOST, PORT)