aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-18 22:56:14 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-18 22:56:14 +0000
commitc8b402e00442cd249397d4d33d2723a1f08a8108 (patch)
treed72a1ace55b42aa9d41c741fa2f757d92fad6592 /test
parente4e2223cff658a7016724a625ebbd3dacb92a8f9 (diff)
downloadluasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.tar.gz
luasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.tar.bz2
luasocket-c8b402e00442cd249397d4d33d2723a1f08a8108.zip
Changed send function.
Diffstat (limited to 'test')
-rw-r--r--test/testclnt.lua86
-rw-r--r--test/testsrvr.lua33
2 files changed, 70 insertions, 49 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua
index f98a504..356350a 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -25,7 +25,7 @@ function remote(...)
25 s = string.gsub(s, "\n", ";") 25 s = string.gsub(s, "\n", ";")
26 s = string.gsub(s, "%s+", " ") 26 s = string.gsub(s, "%s+", " ")
27 s = string.gsub(s, "^%s*", "") 27 s = string.gsub(s, "^%s*", "")
28 control:send(s, "\n") 28 control:send(s .. "\n")
29 control:receive() 29 control:receive()
30end 30end
31 31
@@ -120,7 +120,7 @@ function test_mixed(len)
120 local bp1, bp2, bp3, bp4 120 local bp1, bp2, bp3, bp4
121remote (string.format("str = data:receive(%d)", 121remote (string.format("str = data:receive(%d)",
122 string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) 122 string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4)))
123 sent, err = data:send(p1, p2, p3, p4) 123 sent, err = data:send(p1..p2..p3..p4)
124 if err then fail(err) end 124 if err then fail(err) end
125remote "data:send(str); data:close()" 125remote "data:send(str); data:close()"
126 bp1, err = data:receive() 126 bp1, err = data:receive()
@@ -144,9 +144,9 @@ function test_asciiline(len)
144 str10 = string.rep("aZb.c#dAe?", math.floor(len/10)) 144 str10 = string.rep("aZb.c#dAe?", math.floor(len/10))
145 str = str .. str10 145 str = str .. str10
146remote "str = data:receive()" 146remote "str = data:receive()"
147 sent, err = data:send(str, "\n") 147 sent, err = data:send(str.."\n")
148 if err then fail(err) end 148 if err then fail(err) end
149remote "data:send(str, '\\n')" 149remote "data:send(str ..'\\n')"
150 back, err = data:receive() 150 back, err = data:receive()
151 if err then fail(err) end 151 if err then fail(err) end
152 if back == str then pass("lines match") 152 if back == str then pass("lines match")
@@ -162,9 +162,9 @@ function test_rawline(len)
162 math.floor(len/10)) 162 math.floor(len/10))
163 str = str .. str10 163 str = str .. str10
164remote "str = data:receive()" 164remote "str = data:receive()"
165 sent, err = data:send(str, "\n") 165 sent, err = data:send(str.."\n")
166 if err then fail(err) end 166 if err then fail(err) end
167remote "data:send(str, '\\n')" 167remote "data:send(str..'\\n')"
168 back, err = data:receive() 168 back, err = data:receive()
169 if err then fail(err) end 169 if err then fail(err) end
170 if back == str then pass("lines match") 170 if back == str then pass("lines match")
@@ -457,7 +457,62 @@ function getstats_test()
457 print("ok") 457 print("ok")
458end 458end
459 459
460
460------------------------------------------------------------------------ 461------------------------------------------------------------------------
462function test_nonblocking(size)
463 reconnect()
464remote(string.format([[
465 data:send(string.rep("a", %d))
466 socket.sleep(0.5)
467 data:send(string.rep("b", %d))
468]], size, size))
469 local err = "timeout"
470 local part = ""
471 local str
472 data:settimeout(0)
473 while 1 do
474 str, err, part = data:receive(2*size - string.len(part), part)
475 if err ~= "timeout" then break end
476 end
477 assert(str == (string.rep("a", size) .. string.rep("b", size)))
478 reconnect()
479remote(string.format([[
480 str = data:receive(%d)
481 socket.sleep(0.5)
482 str = data:receive(%d, str)
483 str = data:receive("*l", str)
484 data:send(str)
485 data:send("\n")
486]], size, size))
487 data:settimeout(0)
488 local sofar = 1
489 while 1 do
490 _, err, part = data:send(str, sofar)
491 if err ~= "timeout" then break end
492 sofar = sofar + part
493 end
494 data:send("\n")
495 data:settimeout(-1)
496 local back = data:receive()
497 assert(back == str)
498 print("ok")
499end
500
501
502------------------------------------------------------------------------
503test("non-blocking transfer")
504test_nonblocking(1)
505test_nonblocking(17)
506test_nonblocking(200)
507test_nonblocking(4091)
508test_nonblocking(80199)
509test_nonblocking(8000000)
510test_nonblocking(80199)
511test_nonblocking(4091)
512test_nonblocking(200)
513test_nonblocking(17)
514test_nonblocking(1)
515
461test("method registration") 516test("method registration")
462test_methods(socket.tcp(), { 517test_methods(socket.tcp(), {
463 "accept", 518 "accept",
@@ -548,7 +603,6 @@ test_mixed(1)
548 603
549 604
550test("binary line") 605test("binary line")
551reconnect()
552test_rawline(1) 606test_rawline(1)
553test_rawline(17) 607test_rawline(17)
554test_rawline(200) 608test_rawline(200)
@@ -562,24 +616,6 @@ test_rawline(17)
562test_rawline(1) 616test_rawline(1)
563 617
564test("raw transfer") 618test("raw transfer")
565reconnect()
566test_raw(1)
567test_raw(17)
568test_raw(200)
569test_raw(4091)
570test_raw(80199)
571test_raw(8000000)
572test_raw(80199)
573test_raw(4091)
574test_raw(200)
575test_raw(17)
576test_raw(1)
577
578test("non-blocking transfer")
579reconnect()
580-- the value is not important, we only want
581-- to test non-blocking I/O anyways
582data:settimeout(200)
583test_raw(1) 619test_raw(1)
584test_raw(17) 620test_raw(17)
585test_raw(200) 621test_raw(200)
diff --git a/test/testsrvr.lua b/test/testsrvr.lua
index 969f95b..23e3850 100644
--- a/test/testsrvr.lua
+++ b/test/testsrvr.lua
@@ -1,29 +1,14 @@
1socket = require"socket" 1socket = require("socket");
2 2host = host or "localhost";
3host = host or "localhost" 3port = port or "8080";
4port = port or "8080" 4server = assert(socket.bind(host, port));
5 5ack = "\n";
6server, error = socket.bind(host, port)
7if not server then print("server: " .. tostring(error)) os.exit() end
8ack = "\n"
9while 1 do 6while 1 do
10 print("server: waiting for client connection..."); 7 print("server: waiting for client connection...");
11 control, error = server:accept() 8 control = assert(server:accept());
12 assert(control, error)
13 -- control:setoption("nodelay", true)
14 while 1 do 9 while 1 do
15 command, error = control:receive() 10 command = assert(control:receive());
16 if error then 11 assert(control:send(ack));
17 control:close() 12 (loadstring(command))();
18 print("server: closing connection...")
19 break
20 end
21 sent, error = control:send(ack)
22 if error then
23 control:close()
24 print("server: closing connection...")
25 break
26 end
27 (loadstring(command))()
28 end 13 end
29end 14end