aboutsummaryrefslogtreecommitdiff
path: root/test/smtptest.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2011-05-25 20:57:22 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2011-05-25 20:57:22 +0000
commit3a8ba90dfb0c2eb224f317dd692ede426691e72a (patch)
treefe1cc5379a2e0e031663fe9c15d908653844bc73 /test/smtptest.lua
parentbce60be30fe8e9c1b0eb33128c23c93d7bca5303 (diff)
downloadluasocket-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.lua104
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
19dofile("testsupport.lua") 19dofile("testsupport.lua")
20 20
21local total = function() 21local 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
27end 27end
28 28
29local similar = function(s1, s2) 29local similar = function(s1, s2)
@@ -39,14 +39,14 @@ local fail = function(s)
39end 39end
40 40
41local readfile = function(name) 41local 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
50end 50end
51 51
52local empty = function() 52local empty = function()
@@ -62,7 +62,7 @@ end
62local get = function() 62local 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
68end 68end
@@ -82,40 +82,40 @@ local check_body = function(sent, got)
82end 82end
83 83
84local check = function(sent, m) 84local 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")
97end 97end
98 98
99local insert = function(sent, message) 99local 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)
106end 106end
107 107
108local mark = function() 108local mark = function()
109 local time = socket.time() 109 local time = socket.time()
110 return { time = time } 110 return { time = time }
111end 111end
112 112
113local wait = function(sentinel, n) 113local 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
129end 129end
130 130
131local stuffed_body = [[ 131local stuffed_body = [[
@@ -144,21 +144,21 @@ a lot of trouble.
144insert(sent, { 144insert(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
155insert(sent, { 155insert(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, {
210io.write("testing host not found: ") 210io.write("testing host not found: ")
211local c, e = socket.connect("wrong.host", 25) 211local c, e = socket.connect("wrong.host", 25)
212local ret, err = socket.smtp.mail{ 212local 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}
217if ret or e ~= err then fail("wrong error message") 217if ret or e ~= err then fail("wrong error message")
218else print("ok") end 218else print("ok") end
219 219
220io.write("testing invalid from: ") 220io.write("testing invalid from: ")
221local ret, err = socket.smtp.mail{ 221local ret, err = socket.smtp.mail{
222 from = ' " " (( _ * ', 222 from = ' " " (( _ * ',
223 rcpt = rcpt, 223 rcpt = rcpt,
224} 224}
225if ret or not err then fail("wrong error message") 225if ret or not err then fail("wrong error message")
226else print(err) end 226else print(err) end
227 227
228io.write("testing no rcpt: ") 228io.write("testing no rcpt: ")
229local ret, err = socket.smtp.mail{ 229local ret, err = socket.smtp.mail{
230 from = from, 230 from = from,
231} 231}
232if ret or not err then fail("wrong error message") 232if ret or not err then fail("wrong error message")
233else print(err) end 233else print(err) end
@@ -252,7 +252,7 @@ local mbox = parse(get())
252print(table.getn(mbox) .. " messages found!") 252print(table.getn(mbox) .. " messages found!")
253 253
254for i = 1, table.getn(mbox) do 254for i = 1, table.getn(mbox) do
255 check(sent, mbox[i]) 255 check(sent, mbox[i])
256end 256end
257 257
258print("passed all tests") 258print("passed all tests")