diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 00:24:44 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-03-20 00:24:44 +0000 |
commit | 53857360bb1ca9cd2080b69d930763ae59db9b06 (patch) | |
tree | 6c1bc6d6462695cf9048801b2244f7fd0cd21ad5 /test | |
parent | 7da19138e37c4e0123860f1fecbceb80c3d2627d (diff) | |
download | luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.gz luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.bz2 luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.zip |
Finish port to Lua 5. Everything is working fine.
Still doesn't work in Windows.
Diffstat (limited to 'test')
-rw-r--r-- | test/ftptest.lua | 118 | ||||
-rw-r--r-- | test/httptest.lua | 18 | ||||
-rw-r--r-- | test/smtptest.lua | 161 | ||||
-rw-r--r-- | test/urltest.lua | 21 |
4 files changed, 166 insertions, 152 deletions
diff --git a/test/ftptest.lua b/test/ftptest.lua index 34cccf1..ee3af91 100644 --- a/test/ftptest.lua +++ b/test/ftptest.lua | |||
@@ -1,29 +1,32 @@ | |||
1 | dofile("noglobals.lua") | 1 | dofile("noglobals.lua") |
2 | 2 | ||
3 | local similar = function(s1, s2) | 3 | local similar = function(s1, s2) |
4 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) | 4 | return |
5 | string.lower(string.gsub(s1, "%s", "")) == | ||
6 | string.lower(string.gsub(s2, "%s", "")) | ||
5 | end | 7 | end |
6 | 8 | ||
7 | local capture = function(cmd) | 9 | local readfile = function(name) |
8 | readfrom("| " .. cmd) | 10 | local f = io.open(name, "r") |
9 | local s = read("*a") | 11 | if not f then return nil end |
10 | readfrom() | 12 | local s = f:read("*a") |
13 | f:close() | ||
11 | return s | 14 | return s |
12 | end | 15 | end |
13 | 16 | ||
14 | local readfile = function(name) | 17 | local capture = function(cmd) |
15 | local f = readfrom(name) | 18 | local f = io.popen(cmd) |
16 | if not f then return nil end | 19 | if not f then return nil end |
17 | local s = read("*a") | 20 | local s = f:read("*a") |
18 | readfrom() | 21 | f:close() |
19 | return s | 22 | return s |
20 | end | 23 | end |
21 | 24 | ||
22 | local check = function(v, e, o) | 25 | local check = function(v, e, o) |
23 | e = e or "failed!" | 26 | e = e or "failed!" |
24 | o = o or "ok" | 27 | o = o or "ok" |
25 | if v then print(o) | 28 | if v then print(o) |
26 | else print(e) exit() end | 29 | else print(e) os.exit() end |
27 | end | 30 | end |
28 | 31 | ||
29 | -- needs an account luasocket:password | 32 | -- needs an account luasocket:password |
@@ -31,81 +34,82 @@ end | |||
31 | 34 | ||
32 | local index, err, saved, back, expected | 35 | local index, err, saved, back, expected |
33 | 36 | ||
34 | local t = _time() | 37 | local t = socket._time() |
35 | 38 | ||
36 | index = readfile("index.html") | 39 | index = readfile("test/index.html") |
40 | |||
41 | io.write("testing wrong scheme: ") | ||
42 | back, err = socket.ftp.get("wrong://banana.com/lixo") | ||
43 | check(not back and err == "unknown scheme 'wrong'", err) | ||
44 | |||
45 | io.write("testing invalid url: ") | ||
46 | back, err = socket.ftp.get("localhost/dir1/index.html;type=i") | ||
47 | local c, e = socket.connect("", 21) | ||
48 | check(not back and err == e, err) | ||
37 | 49 | ||
38 | write("testing file upload: ") | 50 | io.write("testing anonymous file upload: ") |
39 | remove("/var/ftp/dir1/index.up.html") | 51 | os.remove("/var/ftp/pub/index.up.html") |
40 | err = FTP.put("ftp://localhost/dir1/index.up.html;type=i", index) | 52 | err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) |
41 | saved = readfile("/var/ftp/dir1/index.up.html") | 53 | saved = readfile("/var/ftp/pub/index.up.html") |
42 | check(not err and saved == index, err) | 54 | check(not err and saved == index, err) |
43 | 55 | ||
44 | write("testing file download: ") | 56 | io.write("testing anonymous file download: ") |
45 | back, err = FTP.get("ftp://localhost/dir1/index.up.html;type=i") | 57 | back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i") |
46 | check(not err and back == index, err) | 58 | check(not err and back == index, err) |
47 | 59 | ||
48 | write("testing no directory changes: ") | 60 | io.write("testing no directory changes: ") |
49 | back, err = FTP.get("ftp://localhost/index.html;type=i") | 61 | back, err = socket.ftp.get("ftp://localhost/index.html;type=i") |
50 | check(not err and back == index, err) | 62 | check(not err and back == index, err) |
51 | 63 | ||
52 | write("testing multiple directory changes: ") | 64 | io.write("testing multiple directory changes: ") |
53 | back, err = FTP.get("ftp://localhost/dir1/dir2/dir3/dir4/dir5/dir6/index.html;type=i") | 65 | back, err = socket.ftp.get("ftp://localhost/pub/dir1/dir2/dir3/dir4/dir5/index.html;type=i") |
54 | check(not err and back == index, err) | 66 | check(not err and back == index, err) |
55 | 67 | ||
56 | write("testing authenticated upload: ") | 68 | io.write("testing authenticated upload: ") |
57 | remove("/home/luasocket/index.up.html") | 69 | os.remove("/home/luasocket/index.up.html") |
58 | err = FTP.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) | 70 | err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) |
59 | saved = readfile("/home/luasocket/index.up.html") | 71 | saved = readfile("/home/luasocket/index.up.html") |
60 | check(not err and saved == index, err) | 72 | check(not err and saved == index, err) |
61 | 73 | ||
62 | write("testing authenticated download: ") | 74 | io.write("testing authenticated download: ") |
63 | back, err = FTP.get("ftp://luasocket:password@localhost/index.up.html;type=i") | 75 | back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i") |
64 | check(not err and back == index, err) | 76 | check(not err and back == index, err) |
65 | 77 | ||
66 | write("testing weird-character translation: ") | 78 | io.write("testing weird-character translation: ") |
67 | back, err = FTP.get("ftp://luasocket:password@localhost/%2fvar/ftp/dir1/index.html;type=i") | 79 | back, err = socket.ftp.get("ftp://luasocket:password@localhost/%2fvar/ftp/pub/index.html;type=i") |
68 | check(not err and back == index, err) | 80 | check(not err and back == index, err) |
69 | 81 | ||
70 | write("testing parameter overriding: ") | 82 | io.write("testing parameter overriding: ") |
71 | back, err = FTP.get { | 83 | back, err = socket.ftp.get { |
72 | url = "//stupid:mistake@localhost/dir1/index.html", | 84 | url = "//stupid:mistake@localhost/index.html", |
73 | user = "luasocket", | 85 | user = "luasocket", |
74 | password = "password", | 86 | password = "password", |
75 | type = "i" | 87 | type = "i" |
76 | } | 88 | } |
77 | check(not err and back == index, err) | 89 | check(not err and back == index, err) |
78 | 90 | ||
79 | write("testing wrong scheme: ") | 91 | io.write("testing home directory listing: ") |
80 | back, err = FTP.get("wrong://banana.com/lixo") | ||
81 | check(not back and err == "unknown scheme 'wrong'", err) | ||
82 | |||
83 | write("testing invalid url: ") | ||
84 | back, err = FTP.get("localhost/dir1/index.html;type=i") | ||
85 | local c, e = connect("", 21) | ||
86 | check(not back and err == e, err) | ||
87 | |||
88 | write("testing directory listing: ") | ||
89 | expected = capture("ls -F /var/ftp/dir1 | grep -v /") | ||
90 | back, err = FTP.get("ftp://localhost/dir1;type=d") | ||
91 | check(similar(back, expected)) | ||
92 | |||
93 | write("testing home directory listing: ") | ||
94 | expected = capture("ls -F /var/ftp | grep -v /") | 92 | expected = capture("ls -F /var/ftp | grep -v /") |
95 | back, err = FTP.get("ftp://localhost/") | 93 | back, err = socket.ftp.get("ftp://localhost/") |
96 | check(back and similar(back, expected), nil, err) | 94 | check(back and similar(back, expected), nil, err) |
97 | 95 | ||
98 | write("testing upload denial: ") | 96 | io.write("testing directory listing: ") |
99 | err = FTP.put("ftp://localhost/index.up.html;type=a", index) | 97 | expected = capture("ls -F /var/ftp/pub | grep -v /") |
98 | back, err = socket.ftp.get("ftp://localhost/pub;type=d") | ||
99 | check(similar(back, expected)) | ||
100 | |||
101 | io.write("testing upload denial: ") | ||
102 | err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) | ||
100 | check(err, err) | 103 | check(err, err) |
101 | 104 | ||
102 | write("testing authentication failure: ") | 105 | io.write("testing authentication failure: ") |
103 | err = FTP.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) | 106 | err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) |
107 | print(err) | ||
104 | check(err, err) | 108 | check(err, err) |
105 | 109 | ||
106 | write("testing wrong file: ") | 110 | io.write("testing wrong file: ") |
107 | back, err = FTP.get("ftp://localhost/index.wrong.html;type=a") | 111 | back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") |
108 | check(err, err) | 112 | check(err, err) |
109 | 113 | ||
110 | print("passed all tests") | 114 | print("passed all tests") |
111 | print(format("done in %.2fs", _time() - t)) | 115 | print(string.format("done in %.2fs", socket._time() - t)) |
diff --git a/test/httptest.lua b/test/httptest.lua index 2941390..8b84f84 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -31,7 +31,7 @@ local check = function (v, e) | |||
31 | end | 31 | end |
32 | 32 | ||
33 | local check_request = function(request, expect, ignore) | 33 | local check_request = function(request, expect, ignore) |
34 | local response = http.request(request) | 34 | local response = socket.http.request(request) |
35 | for i,v in response do | 35 | for i,v in response do |
36 | if not ignore[i] then | 36 | if not ignore[i] then |
37 | if v ~= expect[i] then %fail(i .. " differs!") end | 37 | if v ~= expect[i] then %fail(i .. " differs!") end |
@@ -56,13 +56,13 @@ index = readfile("test/index.html") | |||
56 | 56 | ||
57 | io.write("testing request uri correctness: ") | 57 | io.write("testing request uri correctness: ") |
58 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" | 58 | local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" |
59 | local back = http.get("http://" .. HOST .. forth) | 59 | local back = socket.http.get("http://" .. HOST .. forth) |
60 | if similar(back, forth) then print("ok") | 60 | if similar(back, forth) then print("ok") |
61 | else fail("failed!") end | 61 | else fail("failed!") end |
62 | 62 | ||
63 | io.write("testing query string correctness: ") | 63 | io.write("testing query string correctness: ") |
64 | forth = "this+is+the+query+string" | 64 | forth = "this+is+the+query+string" |
65 | back = http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) | 65 | back = socket.http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) |
66 | if similar(back, forth) then print("ok") | 66 | if similar(back, forth) then print("ok") |
67 | else fail("failed!") end | 67 | else fail("failed!") end |
68 | 68 | ||
@@ -178,7 +178,7 @@ io.write("testing manual basic auth: ") | |||
178 | request = { | 178 | request = { |
179 | url = "http://" .. HOST .. prefix .. "/auth/index.html", | 179 | url = "http://" .. HOST .. prefix .. "/auth/index.html", |
180 | headers = { | 180 | headers = { |
181 | authorization = "Basic " .. Code.base64("luasocket:password") | 181 | authorization = "Basic " .. socket.code.base64("luasocket:password") |
182 | } | 182 | } |
183 | } | 183 | } |
184 | expect = { | 184 | expect = { |
@@ -279,11 +279,11 @@ check_request(request, expect, ignore) | |||
279 | 279 | ||
280 | local body | 280 | local body |
281 | io.write("testing simple get function: ") | 281 | io.write("testing simple get function: ") |
282 | body = http.get("http://" .. HOST .. prefix .. "/index.html") | 282 | body = socket.http.get("http://" .. HOST .. prefix .. "/index.html") |
283 | check(body == index) | 283 | check(body == index) |
284 | 284 | ||
285 | io.write("testing simple get function with table args: ") | 285 | io.write("testing simple get function with table args: ") |
286 | body = http.get { | 286 | body = socket.http.get { |
287 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", | 287 | url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", |
288 | user = "luasocket", | 288 | user = "luasocket", |
289 | password = "password" | 289 | password = "password" |
@@ -291,18 +291,18 @@ body = http.get { | |||
291 | check(body == index) | 291 | check(body == index) |
292 | 292 | ||
293 | io.write("testing simple post function: ") | 293 | io.write("testing simple post function: ") |
294 | body = http.post("http://" .. HOST .. cgiprefix .. "/cat", index) | 294 | body = socket.http.post("http://" .. HOST .. cgiprefix .. "/cat", index) |
295 | check(body == index) | 295 | check(body == index) |
296 | 296 | ||
297 | io.write("testing simple post function with table args: ") | 297 | io.write("testing simple post function with table args: ") |
298 | body = http.post { | 298 | body = socket.http.post { |
299 | url = "http://" .. HOST .. cgiprefix .. "/cat", | 299 | url = "http://" .. HOST .. cgiprefix .. "/cat", |
300 | body = index | 300 | body = index |
301 | } | 301 | } |
302 | check(body == index) | 302 | check(body == index) |
303 | 303 | ||
304 | io.write("testing HEAD method: ") | 304 | io.write("testing HEAD method: ") |
305 | response = http.request { | 305 | response = socket.http.request { |
306 | method = "HEAD", | 306 | method = "HEAD", |
307 | url = "http://www.tecgraf.puc-rio.br/~diego/" | 307 | url = "http://www.tecgraf.puc-rio.br/~diego/" |
308 | } | 308 | } |
diff --git a/test/smtptest.lua b/test/smtptest.lua index 6b01134..1bba27f 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -1,122 +1,130 @@ | |||
1 | local sent = {} | 1 | local sent = {} |
2 | 2 | ||
3 | local from = "luasock@tecgraf.puc-rio.br" | 3 | local from = "diego@localhost" |
4 | local server = "mail.tecgraf.puc-rio.br" | 4 | local server = "localhost" |
5 | local rcpt = "luasock@tecgraf.puc-rio.br" | 5 | local rcpt = "luasocket@localhost" |
6 | 6 | ||
7 | local name = "/var/spool/mail/luasock" | 7 | local files = { |
8 | "/var/spool/mail/luasocket", | ||
9 | "/var/spool/mail/luasock1", | ||
10 | "/var/spool/mail/luasock2", | ||
11 | "/var/spool/mail/luasock3", | ||
12 | } | ||
8 | 13 | ||
9 | local t = _time() | 14 | local t = socket._time() |
10 | local err | 15 | local err |
11 | 16 | ||
12 | dofile("parsembox.lua") | 17 | dofile("mbox.lua") |
13 | local parse = parse | 18 | local parse = mbox.parse |
14 | dofile("noglobals.lua") | 19 | dofile("noglobals.lua") |
15 | 20 | ||
16 | local total = function() | 21 | local total = function() |
17 | local t = 0 | 22 | local t = 0 |
18 | for i = 1, getn(%sent) do | 23 | for i = 1, table.getn(sent) do |
19 | t = t + %sent[i].count | 24 | t = t + sent[i].count |
20 | end | 25 | end |
21 | return t | 26 | return t |
22 | end | 27 | end |
23 | 28 | ||
24 | local similar = function(s1, s2) | 29 | local similar = function(s1, s2) |
25 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) | 30 | return |
26 | end | 31 | string.lower(string.gsub(s1, "%s", "")) == |
27 | 32 | string.lower(string.gsub(s2, "%s", "")) | |
28 | local readfile = function(name) | ||
29 | local f = readfrom(name) | ||
30 | if not f then return nil end | ||
31 | local s = read("*a") | ||
32 | readfrom() | ||
33 | return s | ||
34 | end | ||
35 | |||
36 | local capture = function(cmd) | ||
37 | readfrom("| " .. cmd) | ||
38 | local s = read("*a") | ||
39 | readfrom() | ||
40 | return s | ||
41 | end | 33 | end |
42 | 34 | ||
43 | local fail = function(s) | 35 | local fail = function(s) |
44 | s = s or "failed!" | 36 | s = s or "failed!" |
45 | print(s) | 37 | print(s) |
46 | exit() | 38 | os.exit() |
47 | end | 39 | end |
48 | 40 | ||
49 | local empty = function() | 41 | local readfile = function(name) |
50 | local f = openfile(%name, "w") | 42 | local f = io.open(name, "r") |
51 | closefile(f) | 43 | if not f then |
44 | fail("unable to open file!") | ||
45 | return nil | ||
46 | end | ||
47 | local s = f:read("*a") | ||
48 | f:close() | ||
49 | return s | ||
52 | end | 50 | end |
53 | 51 | ||
54 | local get = function() | 52 | local empty = function() |
55 | return %readfile(%name) | 53 | for i,v in ipairs(files) do |
54 | local f = io.open(v, "w") | ||
55 | if not f then | ||
56 | fail("unable to open file!") | ||
57 | end | ||
58 | f:close() | ||
59 | end | ||
56 | end | 60 | end |
57 | 61 | ||
58 | local list = function() | 62 | local get = function() |
59 | return %capture("ls -l " .. %name) | 63 | s = "" |
64 | for i,v in ipairs(files) do | ||
65 | s = s .. "\n" .. readfile(v) | ||
66 | end | ||
67 | return s | ||
60 | end | 68 | end |
61 | 69 | ||
62 | local check_headers = function(sent, got) | 70 | local check_headers = function(sent, got) |
63 | sent = sent or {} | 71 | sent = sent or {} |
64 | got = got or {} | 72 | got = got or {} |
65 | for i,v in sent do | 73 | for i,v in sent do |
66 | if not %similar(v, got[i]) then %fail("header " .. v .. "failed!") end | 74 | if not similar(v, got[i]) then fail("header " .. v .. "failed!") end |
67 | end | 75 | end |
68 | end | 76 | end |
69 | 77 | ||
70 | local check_body = function(sent, got) | 78 | local check_body = function(sent, got) |
71 | sent = sent or "" | 79 | sent = sent or "" |
72 | got = got or "" | 80 | got = got or "" |
73 | if not %similar(sent, got) then %fail("bodies differ!") end | 81 | if not similar(sent, got) then fail("bodies differ!") end |
74 | end | 82 | end |
75 | 83 | ||
76 | local check = function(sent, m) | 84 | local check = function(sent, m) |
77 | write("checking ", m.headers.title, ": ") | 85 | io.write("checking ", m.headers.title, ": ") |
78 | for i = 1, getn(sent) do | 86 | for i = 1, table.getn(sent) do |
79 | local s = sent[i] | 87 | local s = sent[i] |
80 | if s.title == m.headers.title and s.count > 0 then | 88 | if s.title == m.headers.title and s.count > 0 then |
81 | %check_headers(s.headers, m.headers) | 89 | check_headers(s.headers, m.headers) |
82 | %check_body(s.body, m.body) | 90 | check_body(s.body, m.body) |
83 | s.count = s.count - 1 | 91 | s.count = s.count - 1 |
84 | print("ok") | 92 | print("ok") |
85 | return | 93 | return |
86 | end | 94 | end |
87 | end | 95 | end |
88 | %fail("not found") | 96 | fail("not found") |
89 | end | 97 | end |
90 | 98 | ||
91 | local insert = function(sent, message) | 99 | local insert = function(sent, message) |
92 | if type(message.rcpt) == "table" then | 100 | if type(message.rcpt) == "table" then |
93 | message.count = getn(message.rcpt) | 101 | message.count = table.getn(message.rcpt) |
94 | else message.count = 1 end | 102 | else message.count = 1 end |
95 | message.headers = message.headers or {} | 103 | message.headers = message.headers or {} |
96 | message.headers.title = message.title | 104 | message.headers.title = message.title |
97 | tinsert(sent, message) | 105 | table.insert(sent, message) |
98 | end | 106 | end |
99 | 107 | ||
100 | local mark = function() | 108 | local mark = function() |
101 | local time = _time() | 109 | local time = socket._time() |
102 | return { time = time } | 110 | return { time = time } |
103 | end | 111 | end |
104 | 112 | ||
105 | local wait = function(sentinel, n) | 113 | local wait = function(sentinel, n) |
106 | local to | 114 | local to |
107 | write("waiting for ", n, " messages: ") | 115 | io.write("waiting for ", n, " messages: ") |
108 | while 1 do | 116 | while 1 do |
109 | local mbox = %parse.mbox(%get()) | 117 | local mbox = parse(get()) |
110 | if n == getn(mbox) then break end | 118 | if n == table.getn(mbox) then break end |
111 | if _time() - sentinel.time > 50 then | 119 | if socket._time() - sentinel.time > 50 then |
112 | to = 1 | 120 | to = 1 |
113 | break | 121 | break |
114 | end | 122 | end |
115 | _sleep(1) | 123 | socket._sleep(1) |
116 | write(".") | 124 | io.write(".") |
117 | flush(_STDOUT) | 125 | io.stdout:flush() |
118 | end | 126 | end |
119 | if to then %fail("timeout") | 127 | if to then fail("timeout") |
120 | else print("ok") end | 128 | else print("ok") end |
121 | end | 129 | end |
122 | 130 | ||
@@ -129,16 +137,16 @@ Otherwise the mailer would | |||
129 | think that the dot | 137 | think that the dot |
130 | . | 138 | . |
131 | is the end of the message | 139 | is the end of the message |
132 | and the remaining will cause | 140 | and the remaining text would cause |
133 | a lot of trouble. | 141 | a lot of trouble. |
134 | ]] | 142 | ]] |
135 | 143 | ||
136 | insert(sent, { | 144 | insert(sent, { |
137 | from = from, | 145 | from = from, |
138 | rcpt = { | 146 | rcpt = { |
139 | "luasock2@tecgraf.puc-rio.br", | 147 | "luasocket@localhost", |
140 | "luasock", | 148 | "luasock3@dell-diego.cs.princeton.edu", |
141 | "luasock1" | 149 | "luasock1@dell-diego.cs.princeton.edu" |
142 | }, | 150 | }, |
143 | body = "multiple rcpt body", | 151 | body = "multiple rcpt body", |
144 | title = "multiple rcpt", | 152 | title = "multiple rcpt", |
@@ -147,8 +155,8 @@ insert(sent, { | |||
147 | insert(sent, { | 155 | insert(sent, { |
148 | from = from, | 156 | from = from, |
149 | rcpt = { | 157 | rcpt = { |
150 | "luasock2@tecgraf.puc-rio.br", | 158 | "luasock2@localhost", |
151 | "luasock", | 159 | "luasock3", |
152 | "luasock1" | 160 | "luasock1" |
153 | }, | 161 | }, |
154 | headers = { | 162 | headers = { |
@@ -199,9 +207,9 @@ insert(sent, { | |||
199 | title = "minimum message" | 207 | title = "minimum message" |
200 | }) | 208 | }) |
201 | 209 | ||
202 | write("testing host not found: ") | 210 | io.write("testing host not found: ") |
203 | local c, e = connect("wrong.host", 25) | 211 | local c, e = socket.connect("wrong.host", 25) |
204 | local err = SMTP.mail{ | 212 | local err = socket.smtp.mail{ |
205 | from = from, | 213 | from = from, |
206 | rcpt = rcpt, | 214 | rcpt = rcpt, |
207 | server = "wrong.host" | 215 | server = "wrong.host" |
@@ -209,44 +217,43 @@ local err = SMTP.mail{ | |||
209 | if e ~= err then fail("wrong error message") | 217 | if e ~= err then fail("wrong error message") |
210 | else print("ok") end | 218 | else print("ok") end |
211 | 219 | ||
212 | write("testing invalid from: ") | 220 | io.write("testing invalid from: ") |
213 | local err = SMTP.mail{ | 221 | local err = socket.smtp.mail{ |
214 | from = ' " " (( _ * ', | 222 | from = ' " " (( _ * ', |
215 | rcpt = rcpt, | 223 | rcpt = rcpt, |
216 | } | 224 | } |
217 | if not err then fail("wrong error message") | 225 | if not err then fail("wrong error message") |
218 | else print(err) end | 226 | else print(err) end |
219 | 227 | ||
220 | write("testing no rcpt: ") | 228 | io.write("testing no rcpt: ") |
221 | local err = SMTP.mail{ | 229 | local err = socket.smtp.mail{ |
222 | from = from, | 230 | from = from, |
223 | } | 231 | } |
224 | if not err then fail("wrong error message") | 232 | if not err then fail("wrong error message") |
225 | else print(err) end | 233 | else print(err) end |
226 | 234 | ||
227 | write("clearing mailbox: ") | 235 | io.write("clearing mailbox: ") |
228 | empty() | 236 | empty() |
229 | print("ok") | 237 | print("ok") |
230 | 238 | ||
231 | write("sending messages: ") | 239 | io.write("sending messages: ") |
232 | for i = 1, getn(sent) do | 240 | for i = 1, table.getn(sent) do |
233 | err = SMTP.mail(sent[i]) | 241 | err = socket.smtp.mail(sent[i]) |
234 | if err then fail(err) end | 242 | if err then fail(err) end |
235 | write("+") | 243 | io.write("+") |
236 | flush(_STDOUT) | 244 | io.stdout:flush() |
237 | end | 245 | end |
238 | print("ok") | 246 | print("ok") |
239 | 247 | ||
240 | wait(mark(), total()) | 248 | wait(mark(), total()) |
241 | 249 | ||
242 | write("parsing mailbox: ") | 250 | io.write("parsing mailbox: ") |
243 | local mbox = parse.mbox(get()) | 251 | local mbox = parse(get()) |
244 | print(getn(mbox) .. " messages found!") | 252 | print(table.getn(mbox) .. " messages found!") |
245 | 253 | ||
246 | for i = 1, getn(mbox) do | 254 | for i = 1, table.getn(mbox) do |
247 | check(sent, mbox[i]) | 255 | check(sent, mbox[i]) |
248 | end | 256 | end |
249 | 257 | ||
250 | |||
251 | print("passed all tests") | 258 | print("passed all tests") |
252 | print(format("done in %.2fs", _time() - t)) | 259 | print(string.format("done in %.2fs", socket._time() - t)) |
diff --git a/test/urltest.lua b/test/urltest.lua index 8ca36fe..b97844d 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -1,5 +1,8 @@ | |||
1 | |||
2 | |||
3 | |||
1 | local check_build_url = function(parsed) | 4 | local check_build_url = function(parsed) |
2 | local built = URL.build_url(parsed) | 5 | local built = socket.url.build(parsed) |
3 | if built ~= parsed.url then | 6 | if built ~= parsed.url then |
4 | print("built is different from expected") | 7 | print("built is different from expected") |
5 | print(built) | 8 | print(built) |
@@ -9,7 +12,7 @@ local check_build_url = function(parsed) | |||
9 | end | 12 | end |
10 | 13 | ||
11 | local check_protect = function(parsed, path, unsafe) | 14 | local check_protect = function(parsed, path, unsafe) |
12 | local built = URL.build_path(parsed, unsafe) | 15 | local built = socket.url.build_path(parsed, unsafe) |
13 | if built ~= path then | 16 | if built ~= path then |
14 | print(built, path) | 17 | print(built, path) |
15 | print("path composition failed.") | 18 | print("path composition failed.") |
@@ -18,9 +21,9 @@ local check_protect = function(parsed, path, unsafe) | |||
18 | end | 21 | end |
19 | 22 | ||
20 | local check_invert = function(url) | 23 | local check_invert = function(url) |
21 | local parsed = URL.parse_url(url) | 24 | local parsed = socket.url.parse(url) |
22 | parsed.path = URL.build_path(URL.parse_path(parsed.path)) | 25 | parsed.path = socket.url.build_path(socket.url.parse_path(parsed.path)) |
23 | local rebuilt = URL.build_url(parsed) | 26 | local rebuilt = socket.url.build(parsed) |
24 | if rebuilt ~= url then | 27 | if rebuilt ~= url then |
25 | print(url, rebuilt) | 28 | print(url, rebuilt) |
26 | print("original and rebuilt are different") | 29 | print("original and rebuilt are different") |
@@ -29,7 +32,7 @@ local check_invert = function(url) | |||
29 | end | 32 | end |
30 | 33 | ||
31 | local check_parse_path = function(path, expect) | 34 | local check_parse_path = function(path, expect) |
32 | local parsed = URL.parse_path(path) | 35 | local parsed = socket.url.parse_path(path) |
33 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do | 36 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do |
34 | if parsed[i] ~= expect[i] then | 37 | if parsed[i] ~= expect[i] then |
35 | print(path) | 38 | print(path) |
@@ -48,7 +51,7 @@ local check_parse_path = function(path, expect) | |||
48 | print("is_absolute mismatch") | 51 | print("is_absolute mismatch") |
49 | exit() | 52 | exit() |
50 | end | 53 | end |
51 | local built = URL.build_path(expect) | 54 | local built = socket.url.build_path(expect) |
52 | if built ~= path then | 55 | if built ~= path then |
53 | print(built, path) | 56 | print(built, path) |
54 | print("path composition failed.") | 57 | print("path composition failed.") |
@@ -57,7 +60,7 @@ local check_parse_path = function(path, expect) | |||
57 | end | 60 | end |
58 | 61 | ||
59 | local check_absolute_url = function(base, relative, absolute) | 62 | local check_absolute_url = function(base, relative, absolute) |
60 | local res = URL.absolute_url(base, relative) | 63 | local res = socket.url.absolute(base, relative) |
61 | if res ~= absolute then | 64 | if res ~= absolute then |
62 | write("absolute: In test for '", relative, "' expected '", | 65 | write("absolute: In test for '", relative, "' expected '", |
63 | absolute, "' but got '", res, "'\n") | 66 | absolute, "' but got '", res, "'\n") |
@@ -68,7 +71,7 @@ end | |||
68 | local check_parse_url = function(gaba) | 71 | local check_parse_url = function(gaba) |
69 | local url = gaba.url | 72 | local url = gaba.url |
70 | gaba.url = nil | 73 | gaba.url = nil |
71 | local parsed = URL.parse_url(url) | 74 | local parsed = socket.url.parse(url) |
72 | for i, v in gaba do | 75 | for i, v in gaba do |
73 | if v ~= parsed[i] then | 76 | if v ~= parsed[i] then |
74 | write("parse: In test for '", url, "' expected ", i, " = '", | 77 | write("parse: In test for '", url, "' expected ", i, " = '", |