aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-02-04 14:29:11 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-02-04 14:29:11 +0000
commit0b2542d1a61fc5425ff65ab3dbf7ba7de174763f (patch)
tree8a6188e11db0c9ef6891c31e8a1bebca050b23b2 /test
parentf67864f86c7d703325e86b14d0ba33992c52891b (diff)
downloadluasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.gz
luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.tar.bz2
luasocket-0b2542d1a61fc5425ff65ab3dbf7ba7de174763f.zip
Worked on the manual.
Implemented stuffing (needs test) Added cddb and qp examples.
Diffstat (limited to 'test')
-rw-r--r--test/mimetest.lua15
-rw-r--r--test/testclnt.lua28
-rw-r--r--test/urltest.lua2
3 files changed, 30 insertions, 15 deletions
diff --git a/test/mimetest.lua b/test/mimetest.lua
index 81814de..5a461fa 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -181,6 +181,19 @@ local function compare_b64test()
181 compare(b64test, db64test) 181 compare(b64test, db64test)
182end 182end
183 183
184local function identity_test()
185 local chain = socket.mime.chain(
186 socket.mime.encode("quoted-printable"),
187 socket.mime.encode("base64"),
188 socket.mime.decode("base64"),
189 socket.mime.decode("quoted-printable")
190 )
191 transform(b64test, eb64test, chain)
192 compare(b64test, eb64test)
193 os.remove(eb64test)
194end
195
196
184local function padcheck(original, encoded) 197local function padcheck(original, encoded)
185 local e = (socket.mime.b64(original)) 198 local e = (socket.mime.b64(original))
186 local d = (socket.mime.unb64(encoded)) 199 local d = (socket.mime.unb64(encoded))
@@ -233,4 +246,6 @@ compare_b64test()
233cleanup_b64test() 246cleanup_b64test()
234padding_b64test() 247padding_b64test()
235 248
249identity_test()
250
236print(string.format("done in %.2fs", socket.time() - t)) 251print(string.format("done in %.2fs", socket.time() - t))
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 348439a..1b64abd 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -3,18 +3,18 @@ port = port or "8080"
3 3
4function pass(...) 4function pass(...)
5 local s = string.format(unpack(arg)) 5 local s = string.format(unpack(arg))
6 io.write(s, "\n") 6 io.stderr:write(s, "\n")
7end 7end
8 8
9function fail(...) 9function fail(...)
10 local s = string.format(unpack(arg)) 10 local s = string.format(unpack(arg))
11 io.write("ERROR: ", s, "!\n") 11 io.stderr:write("ERROR: ", s, "!\n")
12 os.exit() 12 os.exit()
13end 13end
14 14
15function warn(...) 15function warn(...)
16 local s = string.format(unpack(arg)) 16 local s = string.format(unpack(arg))
17 io.write("WARNING: ", s, "\n") 17 io.stderr:write("WARNING: ", s, "\n")
18end 18end
19 19
20pad = string.rep(" ", 8192) 20pad = string.rep(" ", 8192)
@@ -29,7 +29,7 @@ function remote(...)
29end 29end
30 30
31function test(test) 31function test(test)
32 io.write("----------------------------------------------\n", 32 io.stderr:write("----------------------------------------------\n",
33 "testing: ", test, "\n", 33 "testing: ", test, "\n",
34 "----------------------------------------------\n") 34 "----------------------------------------------\n")
35end 35end
@@ -72,14 +72,14 @@ if not socket.debug then
72 fail("Please define LUASOCKET_DEBUG and recompile LuaSocket") 72 fail("Please define LUASOCKET_DEBUG and recompile LuaSocket")
73end 73end
74 74
75io.write("----------------------------------------------\n", 75io.stderr:write("----------------------------------------------\n",
76"LuaSocket Test Procedures\n", 76"LuaSocket Test Procedures\n",
77"----------------------------------------------\n") 77"----------------------------------------------\n")
78 78
79start = socket.time() 79start = socket.time()
80 80
81function reconnect() 81function reconnect()
82 io.write("attempting data connection... ") 82 io.stderr:write("attempting data connection... ")
83 if data then data:close() end 83 if data then data:close() end
84 remote [[ 84 remote [[
85 if data then data:close() data = nil end 85 if data then data:close() data = nil end
@@ -348,7 +348,7 @@ end
348 348
349------------------------------------------------------------------------ 349------------------------------------------------------------------------
350function accept_timeout() 350function accept_timeout()
351 io.write("accept with timeout (if it hangs, it failed): ") 351 io.stderr:write("accept with timeout (if it hangs, it failed): ")
352 local s, e = socket.bind("*", 0, 0) 352 local s, e = socket.bind("*", 0, 0)
353 assert(s, e) 353 assert(s, e)
354 local t = socket.time() 354 local t = socket.time()
@@ -364,7 +364,8 @@ end
364 364
365------------------------------------------------------------------------ 365------------------------------------------------------------------------
366function connect_timeout() 366function connect_timeout()
367 io.write("connect with timeout (if it hangs, it failed): ") 367 io.stderr:write("connect with timeout (if it hangs, it failed): ")
368 local t = socket.time()
368 local c, e = socket.tcp() 369 local c, e = socket.tcp()
369 assert(c, e) 370 assert(c, e)
370 c:settimeout(0.1) 371 c:settimeout(0.1)
@@ -380,16 +381,17 @@ end
380 381
381------------------------------------------------------------------------ 382------------------------------------------------------------------------
382function accept_errors() 383function accept_errors()
383 io.write("not listening: ") 384 io.stderr:write("not listening: ")
384 local d, e = socket.bind("*", 0) 385 local d, e = socket.bind("*", 0)
385 assert(d, e); 386 assert(d, e);
386 local c, e = socket.tcp(); 387 local c, e = socket.tcp();
387 assert(c, e); 388 assert(c, e);
388 d:setfd(c:getfd()) 389 d:setfd(c:getfd())
390 d:settimeout(2)
389 local r, e = d:accept() 391 local r, e = d:accept()
390 assert(not r and e == "not listening", e) 392 assert(not r and e == "not listening", e)
391 print("ok") 393 print("ok")
392 io.write("not supported: ") 394 io.stderr:write("not supported: ")
393 local c, e = socket.udp() 395 local c, e = socket.udp()
394 assert(c, e); 396 assert(c, e);
395 d:setfd(c:getfd()) 397 d:setfd(c:getfd())
@@ -400,11 +402,11 @@ end
400 402
401------------------------------------------------------------------------ 403------------------------------------------------------------------------
402function connect_errors() 404function connect_errors()
403 io.write("connection refused: ") 405 io.stderr:write("connection refused: ")
404 local c, e = socket.connect("localhost", 1); 406 local c, e = socket.connect("localhost", 1);
405 assert(not c and e == "connection refused", e) 407 assert(not c and e == "connection refused", e)
406 print("ok") 408 print("ok")
407 io.write("host not found: ") 409 io.stderr:write("host not found: ")
408 local c, e = socket.connect("not.exist.com", 1); 410 local c, e = socket.connect("not.exist.com", 1);
409 assert(not c and e == "host not found", e) 411 assert(not c and e == "host not found", e)
410 print("ok") 412 print("ok")
@@ -534,7 +536,7 @@ test_raw(1)
534test("non-blocking transfer") 536test("non-blocking transfer")
535reconnect() 537reconnect()
536-- the value is not important, we only want 538-- the value is not important, we only want
537-- to test non-blockin I/O anyways 539-- to test non-blocking I/O anyways
538data:settimeout(200) 540data:settimeout(200)
539test_raw(1) 541test_raw(1)
540test_raw(17) 542test_raw(17)
diff --git a/test/urltest.lua b/test/urltest.lua
index 7b1f0c0..990a3e5 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -35,8 +35,6 @@ local check_parse_path = function(path, expect)
35 for i = 1, math.max(table.getn(parsed), table.getn(expect)) do 35 for i = 1, math.max(table.getn(parsed), table.getn(expect)) do
36 if parsed[i] ~= expect[i] then 36 if parsed[i] ~= expect[i] then
37 print(path) 37 print(path)
38 write("segment: ", i, " = '", Code.hexa(tostring(parsed[i])),
39 "' but expected '", Code.hexa(tostring(expect[i])), "'\n")
40 exit() 38 exit()
41 end 39 end
42 end 40 end