diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-02-04 14:29:11 +0000 |
commit | 0b2542d1a61fc5425ff65ab3dbf7ba7de174763f (patch) | |
tree | 8a6188e11db0c9ef6891c31e8a1bebca050b23b2 /test | |
parent | f67864f86c7d703325e86b14d0ba33992c52891b (diff) | |
download | luasocket-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.lua | 15 | ||||
-rw-r--r-- | test/testclnt.lua | 28 | ||||
-rw-r--r-- | test/urltest.lua | 2 |
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) |
182 | end | 182 | end |
183 | 183 | ||
184 | local 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) | ||
194 | end | ||
195 | |||
196 | |||
184 | local function padcheck(original, encoded) | 197 | local 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() | |||
233 | cleanup_b64test() | 246 | cleanup_b64test() |
234 | padding_b64test() | 247 | padding_b64test() |
235 | 248 | ||
249 | identity_test() | ||
250 | |||
236 | print(string.format("done in %.2fs", socket.time() - t)) | 251 | print(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 | ||
4 | function pass(...) | 4 | function 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") |
7 | end | 7 | end |
8 | 8 | ||
9 | function fail(...) | 9 | function 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() |
13 | end | 13 | end |
14 | 14 | ||
15 | function warn(...) | 15 | function 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") |
18 | end | 18 | end |
19 | 19 | ||
20 | pad = string.rep(" ", 8192) | 20 | pad = string.rep(" ", 8192) |
@@ -29,7 +29,7 @@ function remote(...) | |||
29 | end | 29 | end |
30 | 30 | ||
31 | function test(test) | 31 | function test(test) |
32 | io.write("----------------------------------------------\n", | 32 | io.stderr:write("----------------------------------------------\n", |
33 | "testing: ", test, "\n", | 33 | "testing: ", test, "\n", |
34 | "----------------------------------------------\n") | 34 | "----------------------------------------------\n") |
35 | end | 35 | end |
@@ -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") |
73 | end | 73 | end |
74 | 74 | ||
75 | io.write("----------------------------------------------\n", | 75 | io.stderr:write("----------------------------------------------\n", |
76 | "LuaSocket Test Procedures\n", | 76 | "LuaSocket Test Procedures\n", |
77 | "----------------------------------------------\n") | 77 | "----------------------------------------------\n") |
78 | 78 | ||
79 | start = socket.time() | 79 | start = socket.time() |
80 | 80 | ||
81 | function reconnect() | 81 | function 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 | ------------------------------------------------------------------------ |
350 | function accept_timeout() | 350 | function 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 | ------------------------------------------------------------------------ |
366 | function connect_timeout() | 366 | function 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 | ------------------------------------------------------------------------ |
382 | function accept_errors() | 383 | function 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 | ------------------------------------------------------------------------ |
402 | function connect_errors() | 404 | function 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) | |||
534 | test("non-blocking transfer") | 536 | test("non-blocking transfer") |
535 | reconnect() | 537 | reconnect() |
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 |
538 | data:settimeout(200) | 540 | data:settimeout(200) |
539 | test_raw(1) | 541 | test_raw(1) |
540 | test_raw(17) | 542 | test_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 |