diff options
Diffstat (limited to 'test/mimetest.lua')
-rw-r--r-- | test/mimetest.lua | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/test/mimetest.lua b/test/mimetest.lua index 2f6b7a8..f52a351 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua | |||
@@ -39,9 +39,13 @@ local mao = [[ | |||
39 | local function random(handle, io_err) | 39 | local function random(handle, io_err) |
40 | if handle then | 40 | if handle then |
41 | return function() | 41 | return function() |
42 | if not handle then error("source is empty!", 2) end | ||
42 | local len = math.random(0, 1024) | 43 | local len = math.random(0, 1024) |
43 | local chunk = handle:read(len) | 44 | local chunk = handle:read(len) |
44 | if not chunk then handle:close() end | 45 | if not chunk then |
46 | handle:close() | ||
47 | handle = nil | ||
48 | end | ||
45 | return chunk | 49 | return chunk |
46 | end | 50 | end |
47 | else return ltn12.source.empty(io_err or "unable to open file") end | 51 | else return ltn12.source.empty(io_err or "unable to open file") end |
@@ -73,6 +77,7 @@ local function encode_qptest(mode) | |||
73 | end | 77 | end |
74 | 78 | ||
75 | local function compare_qptest() | 79 | local function compare_qptest() |
80 | io.write("testing qp encoding and wrap: ") | ||
76 | compare(qptest, dqptest) | 81 | compare(qptest, dqptest) |
77 | end | 82 | end |
78 | 83 | ||
@@ -173,7 +178,6 @@ local function encode_b64test() | |||
173 | local sp2 = mime.wrap("base64", 30) | 178 | local sp2 = mime.wrap("base64", 30) |
174 | local sp1 = mime.wrap(27) | 179 | local sp1 = mime.wrap(27) |
175 | local chain = ltn12.filter.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) | 180 | local chain = ltn12.filter.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) |
176 | chain = socket.protect(chain) | ||
177 | transform(b64test, eb64test, chain) | 181 | transform(b64test, eb64test, chain) |
178 | end | 182 | end |
179 | 183 | ||
@@ -193,10 +197,12 @@ local function cleanup_b64test() | |||
193 | end | 197 | end |
194 | 198 | ||
195 | local function compare_b64test() | 199 | local function compare_b64test() |
200 | io.write("testing b64 chained encode: ") | ||
196 | compare(b64test, db64test) | 201 | compare(b64test, db64test) |
197 | end | 202 | end |
198 | 203 | ||
199 | local function identity_test() | 204 | local function identity_test() |
205 | io.write("testing identity: ") | ||
200 | local chain = named(ltn12.filter.chain( | 206 | local chain = named(ltn12.filter.chain( |
201 | named(mime.encode("quoted-printable"), "1 eq"), | 207 | named(mime.encode("quoted-printable"), "1 eq"), |
202 | named(mime.encode("base64"), "2 eb"), | 208 | named(mime.encode("base64"), "2 eb"), |
@@ -223,11 +229,12 @@ local function chunkcheck(original, encoded) | |||
223 | local b = string.sub(original, i+1) | 229 | local b = string.sub(original, i+1) |
224 | local e, r = mime.b64(a, b) | 230 | local e, r = mime.b64(a, b) |
225 | local f = (mime.b64(r)) | 231 | local f = (mime.b64(r)) |
226 | if (e .. f ~= encoded) then fail(e .. f) end | 232 | if (e .. (f or "") ~= encoded) then fail(e .. (f or "")) end |
227 | end | 233 | end |
228 | end | 234 | end |
229 | 235 | ||
230 | local function padding_b64test() | 236 | local function padding_b64test() |
237 | io.write("testing b64 padding: ") | ||
231 | padcheck("a", "YQ==") | 238 | padcheck("a", "YQ==") |
232 | padcheck("ab", "YWI=") | 239 | padcheck("ab", "YWI=") |
233 | padcheck("abc", "YWJj") | 240 | padcheck("abc", "YWJj") |