aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-16 06:42:53 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-03-16 06:42:53 +0000
commitbcc0c2a9f0be2ca796ef5206a78e283fe15e6186 (patch)
tree65c269d4854aa5ff4a0b2c8eede5cdb18d716033 /test
parentb6edaac2841137cf0ef5105f75358bbab4570d87 (diff)
downloadluasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.gz
luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.tar.bz2
luasocket-bcc0c2a9f0be2ca796ef5206a78e283fe15e6186.zip
New filter scheme.
ltn12 and mime updated. smtp/ftp broken.
Diffstat (limited to 'test')
-rw-r--r--test/httptest.lua45
-rw-r--r--test/mimetest.lua31
-rw-r--r--test/stufftest.lua19
3 files changed, 60 insertions, 35 deletions
diff --git a/test/httptest.lua b/test/httptest.lua
index c9a74a8..04c0ed0 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -12,7 +12,7 @@ socket.http.TIMEOUT = 5
12 12
13local t = socket.time() 13local t = socket.time()
14 14
15host = host or "diego-interface2.student.dyn.CS.Princeton.EDU" 15host = host or "diego.student.princeton.edu"
16proxy = proxy or "http://localhost:3128" 16proxy = proxy or "http://localhost:3128"
17prefix = prefix or "/luasocket-test" 17prefix = prefix or "/luasocket-test"
18cgiprefix = cgiprefix or "/luasocket-test-cgi" 18cgiprefix = cgiprefix or "/luasocket-test-cgi"
@@ -71,8 +71,8 @@ local check_request = function(request, expect, ignore)
71 check_result(response, expect, ignore) 71 check_result(response, expect, ignore)
72end 72end
73 73
74local check_request_cb = function(request, response, expect, ignore) 74local check_request_cb = function(request, expect, ignore)
75 local response = socket.http.request_cb(request, response) 75 local response = socket.http.request_cb(request)
76 check_result(response, expect, ignore) 76 check_result(response, expect, ignore)
77end 77end
78 78
@@ -83,7 +83,7 @@ local back, h, c, e = socket.http.get("http://" .. host .. forth)
83if not back then fail(e) end 83if not back then fail(e) end
84back = socket.url.parse(back) 84back = socket.url.parse(back)
85if similar(back.query, "this+is+the+query+string") then print("ok") 85if similar(back.query, "this+is+the+query+string") then print("ok")
86else fail() end 86else fail(back.query) end
87 87
88------------------------------------------------------------------------ 88------------------------------------------------------------------------
89io.write("testing query string correctness: ") 89io.write("testing query string correctness: ")
@@ -168,31 +168,28 @@ back = socket.http.post("http://" .. host .. cgiprefix .. "/cat", index)
168check(back == index) 168check(back == index)
169 169
170------------------------------------------------------------------------ 170------------------------------------------------------------------------
171io.write("testing send.file and receive.file callbacks: ") 171io.write("testing ltn12.(sink|source).file: ")
172request = { 172request = {
173 url = "http://" .. host .. cgiprefix .. "/cat", 173 url = "http://" .. host .. cgiprefix .. "/cat",
174 method = "POST", 174 method = "POST",
175 body_cb = socket.callback.send.file(io.open(index_file, "r")), 175 source = ltn12.source.file(io.open(index_file, "r")),
176 sink = ltn12.sink.file(io.open(index_file .. "-back", "w")),
176 headers = { ["content-length"] = string.len(index) } 177 headers = { ["content-length"] = string.len(index) }
177} 178}
178response = {
179 body_cb = socket.callback.receive.file(io.open(index_file .. "-back", "w"))
180}
181expect = { 179expect = {
182 code = 200 180 code = 200
183} 181}
184ignore = { 182ignore = {
185 body_cb = 1,
186 status = 1, 183 status = 1,
187 headers = 1 184 headers = 1
188} 185}
189check_request_cb(request, response, expect, ignore) 186check_request_cb(request, expect, ignore)
190back = readfile(index_file .. "-back") 187back = readfile(index_file .. "-back")
191check(back == index) 188check(back == index)
192os.remove(index_file .. "-back") 189os.remove(index_file .. "-back")
193 190
194------------------------------------------------------------------------ 191------------------------------------------------------------------------
195io.write("testing send.chain and receive.chain callbacks: ") 192io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ")
196 193
197local function b64length(len) 194local function b64length(len)
198 local a = math.ceil(len/3)*4 195 local a = math.ceil(len/3)*4
@@ -200,26 +197,26 @@ local function b64length(len)
200 return a + l*2 197 return a + l*2
201end 198end
202 199
203local req_cb = socket.callback.send.chain( 200local source = ltn12.source.chain(
204 socket.callback.send.file(io.open(index_file, "r")), 201 ltn12.source.file(io.open(index_file, "r")),
205 socket.mime.chain( 202 ltn12.filter.chain(
206 socket.mime.encode("base64"), 203 mime.encode("base64"),
207 socket.mime.wrap("base64") 204 mime.wrap("base64")
208 ) 205 )
209) 206)
210 207
211local resp_cb = socket.callback.receive.chain( 208local sink = ltn12.sink.chain(
212 socket.mime.decode("base64"), 209 mime.decode("base64"),
213 socket.callback.receive.file(io.open(index_file .. "-back", "w")) 210 ltn12.sink.file(io.open(index_file .. "-back", "w"))
214) 211)
215 212
216request = { 213request = {
217 url = "http://" .. host .. cgiprefix .. "/cat", 214 url = "http://" .. host .. cgiprefix .. "/cat",
218 method = "POST", 215 method = "POST",
219 body_cb = req_cb, 216 source = source,
217 sink = sink,
220 headers = { ["content-length"] = b64length(string.len(index)) } 218 headers = { ["content-length"] = b64length(string.len(index)) }
221} 219}
222response = { body_cb = resp_cb }
223expect = { 220expect = {
224 code = 200 221 code = 200
225} 222}
@@ -228,7 +225,7 @@ ignore = {
228 status = 1, 225 status = 1,
229 headers = 1 226 headers = 1
230} 227}
231check_request_cb(request, response, expect, ignore) 228check_request_cb(request, expect, ignore)
232back = readfile(index_file .. "-back") 229back = readfile(index_file .. "-back")
233check(back == index) 230check(back == index)
234os.remove(index_file .. "-back") 231os.remove(index_file .. "-back")
@@ -362,7 +359,7 @@ io.write("testing manual basic auth: ")
362request = { 359request = {
363 url = "http://" .. host .. prefix .. "/auth/index.html", 360 url = "http://" .. host .. prefix .. "/auth/index.html",
364 headers = { 361 headers = {
365 authorization = "Basic " .. (socket.mime.b64("luasocket:password")) 362 authorization = "Basic " .. (mime.b64("luasocket:password"))
366 } 363 }
367} 364}
368expect = { 365expect = {
diff --git a/test/mimetest.lua b/test/mimetest.lua
index 1a7e427..4a0a20a 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -31,18 +31,27 @@ local mao = [[
31 assim, nem tudo o que dava exprimia grande confiança. 31 assim, nem tudo o que dava exprimia grande confiança.
32]] 32]]
33 33
34local function random(handle, io_err)
35 if handle then
36 return function()
37 local chunk = handle:read(math.random(0, 1024))
38 if not chunk then handle:close() end
39 return chunk
40 end
41 else source.empty(io_err or "unable to open file") end
42end
43
44local what = nil
34local function transform(input, output, filter) 45local function transform(input, output, filter)
35 local fi, err = io.open(input, "rb") 46 local source = random(io.open(input, "rb"))
36 if not fi then fail(err) end 47 local sink = ltn12.sink.file(io.open(output, "wb"))
37 local fo, err = io.open(output, "wb") 48 if what then
38 if not fo then fail(err) end 49 sink = ltn12.sink.chain(filter, sink)
39 while 1 do 50 else
40 local chunk = fi:read(math.random(0, 1024)) 51 source = ltn12.source.chain(source, filter)
41 fo:write(filter(chunk)) 52 end
42 if not chunk then break end 53 --what = not what
43 end 54 ltn12.pump(source, sink)
44 fi:close()
45 fo:close()
46end 55end
47 56
48local function encode_qptest(mode) 57local function encode_qptest(mode)
diff --git a/test/stufftest.lua b/test/stufftest.lua
new file mode 100644
index 0000000..5eb8005
--- /dev/null
+++ b/test/stufftest.lua
@@ -0,0 +1,19 @@
1function test_dot(original, right)
2 local result, n = socket.smtp.dot(2, original)
3 assert(result == right, "->" .. result .. "<-")
4 print("ok")
5end
6
7function test_stuff(original, right)
8 local result, n = socket.smtp.dot(2, original)
9 assert(result == right, "->" .. result .. "<-")
10 print("ok")
11end
12
13test_dot("abc", "abc")
14test_dot("", "")
15test_dot("\r\n", "\r\n")
16test_dot("\r\n.", "\r\n..")
17test_dot(".\r\n.", "..\r\n..")
18test_dot(".\r\n.", "..\r\n..")
19test_dot("abcd.\r\n.", "abcd.\r\n..")