diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2011-05-25 20:57:22 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2011-05-25 20:57:22 +0000 |
| commit | 3a8ba90dfb0c2eb224f317dd692ede426691e72a (patch) | |
| tree | fe1cc5379a2e0e031663fe9c15d908653844bc73 /test/smtptest.lua | |
| parent | bce60be30fe8e9c1b0eb33128c23c93d7bca5303 (diff) | |
| download | luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.tar.gz luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.tar.bz2 luasocket-3a8ba90dfb0c2eb224f317dd692ede426691e72a.zip | |
Saving before big changes to support IPv6.
Diffstat (limited to 'test/smtptest.lua')
| -rw-r--r-- | test/smtptest.lua | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/test/smtptest.lua b/test/smtptest.lua index d0c938c..5f0e0e5 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
| @@ -19,11 +19,11 @@ local parse = mbox.parse | |||
| 19 | dofile("testsupport.lua") | 19 | dofile("testsupport.lua") |
| 20 | 20 | ||
| 21 | local total = function() | 21 | local total = function() |
| 22 | local t = 0 | 22 | local t = 0 |
| 23 | for i = 1, table.getn(sent) do | 23 | for i = 1, table.getn(sent) do |
| 24 | t = t + sent[i].count | 24 | t = t + sent[i].count |
| 25 | end | 25 | end |
| 26 | return t | 26 | return t |
| 27 | end | 27 | end |
| 28 | 28 | ||
| 29 | local similar = function(s1, s2) | 29 | local similar = function(s1, s2) |
| @@ -39,14 +39,14 @@ local fail = function(s) | |||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | local readfile = function(name) | 41 | local readfile = function(name) |
| 42 | local f = io.open(name, "r") | 42 | local f = io.open(name, "r") |
| 43 | if not f then | 43 | if not f then |
| 44 | fail("unable to open file!") | 44 | fail("unable to open file!") |
| 45 | return nil | 45 | return nil |
| 46 | end | 46 | end |
| 47 | local s = f:read("*a") | 47 | local s = f:read("*a") |
| 48 | f:close() | 48 | f:close() |
| 49 | return s | 49 | return s |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | local empty = function() | 52 | local empty = function() |
| @@ -62,7 +62,7 @@ end | |||
| 62 | local get = function() | 62 | local get = function() |
| 63 | local s = "" | 63 | local s = "" |
| 64 | for i,v in ipairs(files) do | 64 | for i,v in ipairs(files) do |
| 65 | s = s .. "\n" .. readfile(v) | 65 | s = s .. "\n" .. readfile(v) |
| 66 | end | 66 | end |
| 67 | return s | 67 | return s |
| 68 | end | 68 | end |
| @@ -82,40 +82,40 @@ local check_body = function(sent, got) | |||
| 82 | end | 82 | end |
| 83 | 83 | ||
| 84 | local check = function(sent, m) | 84 | local check = function(sent, m) |
| 85 | io.write("checking ", m.headers.title, ": ") | 85 | io.write("checking ", m.headers.title, ": ") |
| 86 | for i = 1, table.getn(sent) do | 86 | for i = 1, table.getn(sent) do |
| 87 | local s = sent[i] | 87 | local s = sent[i] |
| 88 | if s.title == m.headers.title and s.count > 0 then | 88 | if s.title == m.headers.title and s.count > 0 then |
| 89 | check_headers(s.headers, m.headers) | 89 | check_headers(s.headers, m.headers) |
| 90 | check_body(s.body, m.body) | 90 | check_body(s.body, m.body) |
| 91 | s.count = s.count - 1 | 91 | s.count = s.count - 1 |
| 92 | print("ok") | 92 | print("ok") |
| 93 | return | 93 | return |
| 94 | end | 94 | end |
| 95 | end | 95 | end |
| 96 | fail("not found") | 96 | fail("not found") |
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | local insert = function(sent, message) | 99 | local insert = function(sent, message) |
| 100 | if type(message.rcpt) == "table" then | 100 | if type(message.rcpt) == "table" then |
| 101 | message.count = table.getn(message.rcpt) | 101 | message.count = table.getn(message.rcpt) |
| 102 | else message.count = 1 end | 102 | else message.count = 1 end |
| 103 | message.headers = message.headers or {} | 103 | message.headers = message.headers or {} |
| 104 | message.headers.title = message.title | 104 | message.headers.title = message.title |
| 105 | table.insert(sent, message) | 105 | table.insert(sent, message) |
| 106 | end | 106 | end |
| 107 | 107 | ||
| 108 | local mark = function() | 108 | local mark = function() |
| 109 | local time = socket.time() | 109 | local time = socket.time() |
| 110 | return { time = time } | 110 | return { time = time } |
| 111 | end | 111 | end |
| 112 | 112 | ||
| 113 | local wait = function(sentinel, n) | 113 | local wait = function(sentinel, n) |
| 114 | local to | 114 | local to |
| 115 | io.write("waiting for ", n, " messages: ") | 115 | io.write("waiting for ", n, " messages: ") |
| 116 | while 1 do | 116 | while 1 do |
| 117 | local mbox = parse(get()) | 117 | local mbox = parse(get()) |
| 118 | if n == table.getn(mbox) then break end | 118 | if n == table.getn(mbox) then break end |
| 119 | if socket.time() - sentinel.time > 50 then | 119 | if socket.time() - sentinel.time > 50 then |
| 120 | to = 1 | 120 | to = 1 |
| 121 | break | 121 | break |
| @@ -124,8 +124,8 @@ local wait = function(sentinel, n) | |||
| 124 | io.write(".") | 124 | io.write(".") |
| 125 | io.stdout:flush() | 125 | io.stdout:flush() |
| 126 | end | 126 | end |
| 127 | if to then fail("timeout") | 127 | if to then fail("timeout") |
| 128 | else print("ok") end | 128 | else print("ok") end |
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | local stuffed_body = [[ | 131 | local stuffed_body = [[ |
| @@ -144,21 +144,21 @@ a lot of trouble. | |||
| 144 | insert(sent, { | 144 | insert(sent, { |
| 145 | from = from, | 145 | from = from, |
| 146 | rcpt = { | 146 | rcpt = { |
| 147 | "luasocket@localhost", | 147 | "luasocket@localhost", |
| 148 | "luasock3@dell-diego.cs.princeton.edu", | 148 | "luasock3@dell-diego.cs.princeton.edu", |
| 149 | "luasock1@dell-diego.cs.princeton.edu" | 149 | "luasock1@dell-diego.cs.princeton.edu" |
| 150 | }, | 150 | }, |
| 151 | body = "multiple rcpt body", | 151 | body = "multiple rcpt body", |
| 152 | title = "multiple rcpt", | 152 | title = "multiple rcpt", |
| 153 | }) | 153 | }) |
| 154 | 154 | ||
| 155 | insert(sent, { | 155 | insert(sent, { |
| 156 | from = from, | 156 | from = from, |
| 157 | rcpt = { | 157 | rcpt = { |
| 158 | "luasock2@localhost", | 158 | "luasock2@localhost", |
| 159 | "luasock3", | 159 | "luasock3", |
| 160 | "luasock1" | 160 | "luasock1" |
| 161 | }, | 161 | }, |
| 162 | headers = { | 162 | headers = { |
| 163 | header1 = "header 1", | 163 | header1 = "header 1", |
| 164 | header2 = "header 2", | 164 | header2 = "header 2", |
| @@ -210,24 +210,24 @@ insert(sent, { | |||
| 210 | io.write("testing host not found: ") | 210 | io.write("testing host not found: ") |
| 211 | local c, e = socket.connect("wrong.host", 25) | 211 | local c, e = socket.connect("wrong.host", 25) |
| 212 | local ret, err = socket.smtp.mail{ | 212 | local ret, err = socket.smtp.mail{ |
| 213 | from = from, | 213 | from = from, |
| 214 | rcpt = rcpt, | 214 | rcpt = rcpt, |
| 215 | server = "wrong.host" | 215 | server = "wrong.host" |
| 216 | } | 216 | } |
| 217 | if ret or e ~= err then fail("wrong error message") | 217 | if ret or e ~= err then fail("wrong error message") |
| 218 | else print("ok") end | 218 | else print("ok") end |
| 219 | 219 | ||
| 220 | io.write("testing invalid from: ") | 220 | io.write("testing invalid from: ") |
| 221 | local ret, err = socket.smtp.mail{ | 221 | local ret, err = socket.smtp.mail{ |
| 222 | from = ' " " (( _ * ', | 222 | from = ' " " (( _ * ', |
| 223 | rcpt = rcpt, | 223 | rcpt = rcpt, |
| 224 | } | 224 | } |
| 225 | if ret or not err then fail("wrong error message") | 225 | if ret or not err then fail("wrong error message") |
| 226 | else print(err) end | 226 | else print(err) end |
| 227 | 227 | ||
| 228 | io.write("testing no rcpt: ") | 228 | io.write("testing no rcpt: ") |
| 229 | local ret, err = socket.smtp.mail{ | 229 | local ret, err = socket.smtp.mail{ |
| 230 | from = from, | 230 | from = from, |
| 231 | } | 231 | } |
| 232 | if ret or not err then fail("wrong error message") | 232 | if ret or not err then fail("wrong error message") |
| 233 | else print(err) end | 233 | else print(err) end |
| @@ -252,7 +252,7 @@ local mbox = parse(get()) | |||
| 252 | print(table.getn(mbox) .. " messages found!") | 252 | print(table.getn(mbox) .. " messages found!") |
| 253 | 253 | ||
| 254 | for i = 1, table.getn(mbox) do | 254 | for i = 1, table.getn(mbox) do |
| 255 | check(sent, mbox[i]) | 255 | check(sent, mbox[i]) |
| 256 | end | 256 | end |
| 257 | 257 | ||
| 258 | print("passed all tests") | 258 | print("passed all tests") |
