aboutsummaryrefslogtreecommitdiff
path: root/test/testclnt.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-21 07:50:15 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-21 07:50:15 +0000
commit4919a83d2271a9e43b83c7d488e3f94c850681e3 (patch)
treea2ae9a27ead4cb85cbbd857ef74bc39c01b9bf64 /test/testclnt.lua
parent2a14ac4fe4bb4dd6d7a7ec5195c15a4e3f783ad5 (diff)
downloadluasocket-4919a83d2271a9e43b83c7d488e3f94c850681e3.tar.gz
luasocket-4919a83d2271a9e43b83c7d488e3f94c850681e3.tar.bz2
luasocket-4919a83d2271a9e43b83c7d488e3f94c850681e3.zip
Changed receive function. Now uniform with all other functions. Returns nil
on error, return partial result in the end. http.lua rewritten.
Diffstat (limited to 'test/testclnt.lua')
-rw-r--r--test/testclnt.lua34
1 files changed, 19 insertions, 15 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 1b64abd..ecf419b 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -17,14 +17,12 @@ function warn(...)
17 io.stderr:write("WARNING: ", s, "\n") 17 io.stderr:write("WARNING: ", s, "\n")
18end 18end
19 19
20pad = string.rep(" ", 8192)
21
22function remote(...) 20function remote(...)
23 local s = string.format(unpack(arg)) 21 local s = string.format(unpack(arg))
24 s = string.gsub(s, "\n", ";") 22 s = string.gsub(s, "\n", ";")
25 s = string.gsub(s, "%s+", " ") 23 s = string.gsub(s, "%s+", " ")
26 s = string.gsub(s, "^%s*", "") 24 s = string.gsub(s, "^%s*", "")
27 control:send(pad, s, "\n") 25 control:send(s, "\n")
28 control:receive() 26 control:receive()
29end 27end
30 28
@@ -122,7 +120,13 @@ remote (string.format("str = data:receive(%d)",
122 sent, err = data:send(p1, p2, p3, p4) 120 sent, err = data:send(p1, p2, p3, p4)
123 if err then fail(err) end 121 if err then fail(err) end
124remote "data:send(str); data:close()" 122remote "data:send(str); data:close()"
125 bp1, bp2, bp3, bp4, err = data:receive("*l", "*l", string.len(p3), "*a") 123 bp1, err = data:receive()
124 if err then fail(err) end
125 bp2, err = data:receive()
126 if err then fail(err) end
127 bp3, err = data:receive(string.len(p3))
128 if err then fail(err) end
129 bp4, err = data:receive("*a")
126 if err then fail(err) end 130 if err then fail(err) end
127 if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 and bp4 == p4 then 131 if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 and bp4 == p4 then
128 pass("patterns match") 132 pass("patterns match")
@@ -186,7 +190,7 @@ end
186------------------------------------------------------------------------ 190------------------------------------------------------------------------
187function test_totaltimeoutreceive(len, tm, sl) 191function test_totaltimeoutreceive(len, tm, sl)
188 reconnect() 192 reconnect()
189 local str, err, total 193 local str, err, partial
190 pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl) 194 pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl)
191 remote (string.format ([[ 195 remote (string.format ([[
192 data:settimeout(%d) 196 data:settimeout(%d)
@@ -198,9 +202,9 @@ function test_totaltimeoutreceive(len, tm, sl)
198 data:send(str) 202 data:send(str)
199 ]], 2*tm, len, sl, sl)) 203 ]], 2*tm, len, sl, sl))
200 data:settimeout(tm, "total") 204 data:settimeout(tm, "total")
201 str, err, elapsed = data:receive(2*len) 205 str, err, partial, elapsed = data:receive(2*len)
202 check_timeout(tm, sl, elapsed, err, "receive", "total", 206 check_timeout(tm, sl, elapsed, err, "receive", "total",
203 string.len(str) == 2*len) 207 string.len(str or partial) == 2*len)
204end 208end
205 209
206------------------------------------------------------------------------ 210------------------------------------------------------------------------
@@ -226,7 +230,7 @@ end
226------------------------------------------------------------------------ 230------------------------------------------------------------------------
227function test_blockingtimeoutreceive(len, tm, sl) 231function test_blockingtimeoutreceive(len, tm, sl)
228 reconnect() 232 reconnect()
229 local str, err, total 233 local str, err, partial
230 pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl) 234 pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl)
231 remote (string.format ([[ 235 remote (string.format ([[
232 data:settimeout(%d) 236 data:settimeout(%d)
@@ -238,9 +242,9 @@ function test_blockingtimeoutreceive(len, tm, sl)
238 data:send(str) 242 data:send(str)
239 ]], 2*tm, len, sl, sl)) 243 ]], 2*tm, len, sl, sl))
240 data:settimeout(tm) 244 data:settimeout(tm)
241 str, err, elapsed = data:receive(2*len) 245 str, err, partial, elapsed = data:receive(2*len)
242 check_timeout(tm, sl, elapsed, err, "receive", "blocking", 246 check_timeout(tm, sl, elapsed, err, "receive", "blocking",
243 string.len(str) == 2*len) 247 string.len(str or partial) == 2*len)
244end 248end
245 249
246------------------------------------------------------------------------ 250------------------------------------------------------------------------
@@ -298,7 +302,7 @@ end
298 302
299------------------------------------------------------------------------ 303------------------------------------------------------------------------
300function test_closed() 304function test_closed()
301 local back, err 305 local back, partial, err
302 local str = 'little string' 306 local str = 'little string'
303 reconnect() 307 reconnect()
304 pass("trying read detection") 308 pass("trying read detection")
@@ -308,10 +312,10 @@ function test_closed()
308 data = nil 312 data = nil
309 ]], str)) 313 ]], str))
310 -- try to get a line 314 -- try to get a line
311 back, err = data:receive() 315 back, err, partial = data:receive()
312 if not err then fail("shold have gotten 'closed'.") 316 if not err then fail("should have gotten 'closed'.")
313 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") 317 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
314 elseif str ~= back then fail("didn't receive partial result.") 318 elseif str ~= partial then fail("didn't receive partial result.")
315 else pass("graceful 'closed' received") end 319 else pass("graceful 'closed' received") end
316 reconnect() 320 reconnect()
317 pass("trying write detection") 321 pass("trying write detection")
@@ -456,7 +460,6 @@ test_methods(socket.udp(), {
456 "setpeername", 460 "setpeername",
457 "setsockname", 461 "setsockname",
458 "settimeout", 462 "settimeout",
459 "shutdown",
460}) 463})
461 464
462test("select function") 465test("select function")
@@ -481,6 +484,7 @@ accept_timeout()
481accept_errors() 484accept_errors()
482 485
483 486
487
484test("mixed patterns") 488test("mixed patterns")
485test_mixed(1) 489test_mixed(1)
486test_mixed(17) 490test_mixed(17)