aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2009-05-27 09:31:38 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2009-05-27 09:31:38 +0000
commitbce60be30fe8e9c1b0eb33128c23c93d7bca5303 (patch)
tree3927343c777fcb7764a0f2f89754a0ceab141c21 /test
parentd1a72435d5bd3528f3c334cd4d1da16dcead47bf (diff)
downloadluasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.gz
luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.bz2
luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.zip
Decent makefiles!
Diffstat (limited to 'test')
-rw-r--r--test/README2
-rw-r--r--test/hello.lua3
-rw-r--r--test/httptest.lua10
-rw-r--r--test/mimetest.lua24
-rw-r--r--test/testclnt.lua43
-rw-r--r--test/testmesg.lua2
6 files changed, 74 insertions, 10 deletions
diff --git a/test/README b/test/README
index 180fa27..27837e0 100644
--- a/test/README
+++ b/test/README
@@ -8,5 +8,7 @@ The files provided are:
8 8
9To run these tests, just run lua on the server and then on the client. 9To run these tests, just run lua on the server and then on the client.
10 10
11 hello.lua -- run to verify if installation worked
12
11Good luck, 13Good luck,
12Diego. 14Diego.
diff --git a/test/hello.lua b/test/hello.lua
new file mode 100644
index 0000000..cfa5c82
--- /dev/null
+++ b/test/hello.lua
@@ -0,0 +1,3 @@
1require"socket"
2require"mime"
3print("Hello from " .. socket._VERSION .. " and " .. mime._VERSION .. "!")
diff --git a/test/httptest.lua b/test/httptest.lua
index dd53ec3..9d50a14 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -420,17 +420,17 @@ print("ok")
420io.write("testing HEAD method: ") 420io.write("testing HEAD method: ")
421local r, c, h = http.request { 421local r, c, h = http.request {
422 method = "HEAD", 422 method = "HEAD",
423 url = "http://www.cs.princeton.edu/~diego/" 423 url = "http://www.tecgraf.puc-rio.br/~diego/"
424} 424}
425assert(r and h and (c == 200), c) 425assert(r and h and (c == 200), c)
426print("ok") 426print("ok")
427 427
428------------------------------------------------------------------------ 428------------------------------------------------------------------------
429io.write("testing host not found: ") 429io.write("testing host not found: ")
430local c, e = socket.connect("wronghost", 80) 430local c, e = socket.connect("example.invalid", 80)
431local r, re = http.request{url = "http://wronghost/does/not/exist"} 431local r, re = http.request{url = "http://example.invalid/does/not/exist"}
432assert(r == nil and e == re) 432assert(r == nil and e == re, tostring(r) .. " " .. tostring(re))
433r, re = http.request("http://wronghost/does/not/exist") 433r, re = http.request("http://example.invalid/does/not/exist")
434assert(r == nil and e == re) 434assert(r == nil and e == re)
435print("ok") 435print("ok")
436 436
diff --git a/test/mimetest.lua b/test/mimetest.lua
index f52a351..11c3f4f 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -251,6 +251,28 @@ io.write("testing b64 padding: ")
251 print("ok") 251 print("ok")
252end 252end
253 253
254local function test_b64lowlevel()
255io.write("testing b64 low-level: ")
256 local a, b
257 a, b = mime.b64("", "")
258 assert(a == "" and b == "")
259 a, b = mime.b64(nil, "blablabla")
260 assert(a == nil and b == nil)
261 a, b = mime.b64("", nil)
262 assert(a == nil and b == nil)
263 a, b = mime.unb64("", "")
264 assert(a == "" and b == "")
265 a, b = mime.unb64(nil, "blablabla")
266 assert(a == nil and b == nil)
267 a, b = mime.unb64("", nil)
268 assert(a == nil and b == nil)
269 local binary=string.char(0x00,0x44,0x1D,0x14,0x0F,0xF4,0xDA,0x11,0xA9,0x78,0x00,0x14,0x38,0x50,0x60,0xCE)
270 local encoded = mime.b64(binary)
271 local decoded=mime.unb64(encoded)
272 assert(binary == decoded)
273 print("ok")
274end
275
254local t = socket.gettime() 276local t = socket.gettime()
255 277
256create_b64test() 278create_b64test()
@@ -260,6 +282,7 @@ decode_b64test()
260compare_b64test() 282compare_b64test()
261cleanup_b64test() 283cleanup_b64test()
262padding_b64test() 284padding_b64test()
285test_b64lowlevel()
263 286
264create_qptest() 287create_qptest()
265encode_qptest() 288encode_qptest()
@@ -270,4 +293,5 @@ decode_qptest()
270compare_qptest() 293compare_qptest()
271cleanup_qptest() 294cleanup_qptest()
272 295
296
273print(string.format("done in %.2fs", socket.gettime() - t)) 297print(string.format("done in %.2fs", socket.gettime() - t))
diff --git a/test/testclnt.lua b/test/testclnt.lua
index a7ca1ba..1f03b10 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -342,6 +342,7 @@ end
342------------------------------------------------------------------------ 342------------------------------------------------------------------------
343function test_selectbugs() 343function test_selectbugs()
344 local r, s, e = socket.select(nil, nil, 0.1) 344 local r, s, e = socket.select(nil, nil, 0.1)
345print(r, s, e)
345 assert(type(r) == "table" and type(s) == "table" and 346 assert(type(r) == "table" and type(s) == "table" and
346 (e == "timeout" or e == "error")) 347 (e == "timeout" or e == "error"))
347 pass("both nil: ok") 348 pass("both nil: ok")
@@ -352,10 +353,23 @@ function test_selectbugs()
352 (e == "timeout" or e == "error")) 353 (e == "timeout" or e == "error"))
353 pass("closed sockets: ok") 354 pass("closed sockets: ok")
354 e = pcall(socket.select, "wrong", 1, 0.1) 355 e = pcall(socket.select, "wrong", 1, 0.1)
355 assert(e == false) 356 assert(e == false, tostring(e))
356 e = pcall(socket.select, {}, 1, 0.1) 357 e = pcall(socket.select, {}, 1, 0.1)
357 assert(e == false) 358 assert(e == false, tostring(e))
358 pass("invalid input: ok") 359 pass("invalid input: ok")
360 local toomany = {}
361 for i = 1, socket._SETSIZE+1 do
362 toomany[#toomany+1] = socket.udp()
363 end
364 if #toomany > socket._SETSIZE then
365 local e = pcall(socket.select, toomany, nil, 0.1)
366 assert(e == false, tostring(e))
367 pass("too many sockets (" .. #toomany .. "): ok")
368 else
369 pass("unable to create enough sockets (max was "..#toomany..")")
370 pass("try using ulimit")
371 end
372 for _, c in ipairs(toomany) do c:close() end
359end 373end
360 374
361------------------------------------------------------------------------ 375------------------------------------------------------------------------
@@ -555,6 +569,25 @@ function test_readafterclose()
555 print("ok") 569 print("ok")
556end 570end
557 571
572------------------------------------------------------------------------
573function test_writeafterclose()
574 local str = 'little string'
575 reconnect()
576 remote (string.format ([[
577 data:close()
578 data = nil
579 ]]))
580 local sent, err, errsent
581 while not err do
582 sent, err, errsent, time = data:send(str)
583 end
584 print(sent, err, errsent, time)
585 print("ok")
586end
587
588------------------------------------------------------------------------
589--test_writeafterclose()
590
558test("method registration") 591test("method registration")
559test_methods(socket.tcp(), { 592test_methods(socket.tcp(), {
560 "accept", 593 "accept",
@@ -596,12 +629,12 @@ test_methods(socket.udp(), {
596 "settimeout" 629 "settimeout"
597}) 630})
598 631
599test("testing read after close")
600test_readafterclose()
601
602test("select function") 632test("select function")
603test_selectbugs() 633test_selectbugs()
604 634
635test("testing read after close")
636test_readafterclose()
637
605test("connect function") 638test("connect function")
606connect_timeout() 639connect_timeout()
607empty_connect() 640empty_connect()
diff --git a/test/testmesg.lua b/test/testmesg.lua
index 580693b..135a008 100644
--- a/test/testmesg.lua
+++ b/test/testmesg.lua
@@ -32,6 +32,8 @@ r, e = smtp.send{
32 port = 2525 32 port = 2525
33} 33}
34 34
35print(r, e)
36
35-- creates a source to send a message with two parts. The first part is 37-- creates a source to send a message with two parts. The first part is
36-- plain text, the second part is a PNG image, encoded as base64. 38-- plain text, the second part is a PNG image, encoded as base64.
37source = smtp.message{ 39source = smtp.message{