Saving before big changes to support IPv6.

This commit is contained in:
Diego Nehab 2011-05-25 20:57:22 +00:00
parent bce60be30f
commit 3a8ba90dfb
30 changed files with 948 additions and 850 deletions

View file

@ -19,11 +19,11 @@ local parse = mbox.parse
dofile("testsupport.lua")
local total = function()
local t = 0
for i = 1, table.getn(sent) do
t = t + sent[i].count
end
return t
local t = 0
for i = 1, table.getn(sent) do
t = t + sent[i].count
end
return t
end
local similar = function(s1, s2)
@ -39,14 +39,14 @@ local fail = function(s)
end
local readfile = function(name)
local f = io.open(name, "r")
if not f then
local f = io.open(name, "r")
if not f then
fail("unable to open file!")
return nil
end
local s = f:read("*a")
f:close()
return s
local s = f:read("*a")
f:close()
return s
end
local empty = function()
@ -62,7 +62,7 @@ end
local get = function()
local s = ""
for i,v in ipairs(files) do
s = s .. "\n" .. readfile(v)
s = s .. "\n" .. readfile(v)
end
return s
end
@ -82,40 +82,40 @@ local check_body = function(sent, got)
end
local check = function(sent, m)
io.write("checking ", m.headers.title, ": ")
for i = 1, table.getn(sent) do
local s = sent[i]
if s.title == m.headers.title and s.count > 0 then
check_headers(s.headers, m.headers)
check_body(s.body, m.body)
s.count = s.count - 1
print("ok")
return
end
end
fail("not found")
io.write("checking ", m.headers.title, ": ")
for i = 1, table.getn(sent) do
local s = sent[i]
if s.title == m.headers.title and s.count > 0 then
check_headers(s.headers, m.headers)
check_body(s.body, m.body)
s.count = s.count - 1
print("ok")
return
end
end
fail("not found")
end
local insert = function(sent, message)
if type(message.rcpt) == "table" then
message.count = table.getn(message.rcpt)
else message.count = 1 end
message.headers = message.headers or {}
message.headers.title = message.title
table.insert(sent, message)
if type(message.rcpt) == "table" then
message.count = table.getn(message.rcpt)
else message.count = 1 end
message.headers = message.headers or {}
message.headers.title = message.title
table.insert(sent, message)
end
local mark = function()
local time = socket.time()
local time = socket.time()
return { time = time }
end
local wait = function(sentinel, n)
local to
io.write("waiting for ", n, " messages: ")
io.write("waiting for ", n, " messages: ")
while 1 do
local mbox = parse(get())
if n == table.getn(mbox) then break end
local mbox = parse(get())
if n == table.getn(mbox) then break end
if socket.time() - sentinel.time > 50 then
to = 1
break
@ -124,8 +124,8 @@ local wait = function(sentinel, n)
io.write(".")
io.stdout:flush()
end
if to then fail("timeout")
else print("ok") end
if to then fail("timeout")
else print("ok") end
end
local stuffed_body = [[
@ -144,21 +144,21 @@ a lot of trouble.
insert(sent, {
from = from,
rcpt = {
"luasocket@localhost",
"luasock3@dell-diego.cs.princeton.edu",
"luasock1@dell-diego.cs.princeton.edu"
},
body = "multiple rcpt body",
title = "multiple rcpt",
"luasocket@localhost",
"luasock3@dell-diego.cs.princeton.edu",
"luasock1@dell-diego.cs.princeton.edu"
},
body = "multiple rcpt body",
title = "multiple rcpt",
})
insert(sent, {
from = from,
rcpt = {
"luasock2@localhost",
"luasock3",
"luasock1"
},
"luasock2@localhost",
"luasock3",
"luasock1"
},
headers = {
header1 = "header 1",
header2 = "header 2",
@ -210,24 +210,24 @@ insert(sent, {
io.write("testing host not found: ")
local c, e = socket.connect("wrong.host", 25)
local ret, err = socket.smtp.mail{
from = from,
rcpt = rcpt,
server = "wrong.host"
from = from,
rcpt = rcpt,
server = "wrong.host"
}
if ret or e ~= err then fail("wrong error message")
else print("ok") end
io.write("testing invalid from: ")
local ret, err = socket.smtp.mail{
from = ' " " (( _ * ',
rcpt = rcpt,
from = ' " " (( _ * ',
rcpt = rcpt,
}
if ret or not err then fail("wrong error message")
else print(err) end
io.write("testing no rcpt: ")
local ret, err = socket.smtp.mail{
from = from,
from = from,
}
if ret or not err then fail("wrong error message")
else print(err) end
@ -252,7 +252,7 @@ local mbox = parse(get())
print(table.getn(mbox) .. " messages found!")
for i = 1, table.getn(mbox) do
check(sent, mbox[i])
check(sent, mbox[i])
end
print("passed all tests")