From bce60be30fe8e9c1b0eb33128c23c93d7bca5303 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 27 May 2009 09:31:38 +0000 Subject: Decent makefiles! --- test/README | 2 ++ test/hello.lua | 3 +++ test/httptest.lua | 10 +++++----- test/mimetest.lua | 24 ++++++++++++++++++++++++ test/testclnt.lua | 43 ++++++++++++++++++++++++++++++++++++++----- test/testmesg.lua | 2 ++ 6 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 test/hello.lua (limited to 'test') 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: To run these tests, just run lua on the server and then on the client. + hello.lua -- run to verify if installation worked + Good luck, Diego. 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 @@ +require"socket" +require"mime" +print("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") io.write("testing HEAD method: ") local r, c, h = http.request { method = "HEAD", - url = "http://www.cs.princeton.edu/~diego/" + url = "http://www.tecgraf.puc-rio.br/~diego/" } assert(r and h and (c == 200), c) print("ok") ------------------------------------------------------------------------ io.write("testing host not found: ") -local c, e = socket.connect("wronghost", 80) -local r, re = http.request{url = "http://wronghost/does/not/exist"} -assert(r == nil and e == re) -r, re = http.request("http://wronghost/does/not/exist") +local c, e = socket.connect("example.invalid", 80) +local r, re = http.request{url = "http://example.invalid/does/not/exist"} +assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) +r, re = http.request("http://example.invalid/does/not/exist") assert(r == nil and e == re) print("ok") 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: ") print("ok") end +local function test_b64lowlevel() +io.write("testing b64 low-level: ") + local a, b + a, b = mime.b64("", "") + assert(a == "" and b == "") + a, b = mime.b64(nil, "blablabla") + assert(a == nil and b == nil) + a, b = mime.b64("", nil) + assert(a == nil and b == nil) + a, b = mime.unb64("", "") + assert(a == "" and b == "") + a, b = mime.unb64(nil, "blablabla") + assert(a == nil and b == nil) + a, b = mime.unb64("", nil) + assert(a == nil and b == nil) + local binary=string.char(0x00,0x44,0x1D,0x14,0x0F,0xF4,0xDA,0x11,0xA9,0x78,0x00,0x14,0x38,0x50,0x60,0xCE) + local encoded = mime.b64(binary) + local decoded=mime.unb64(encoded) + assert(binary == decoded) + print("ok") +end + local t = socket.gettime() create_b64test() @@ -260,6 +282,7 @@ decode_b64test() compare_b64test() cleanup_b64test() padding_b64test() +test_b64lowlevel() create_qptest() encode_qptest() @@ -270,4 +293,5 @@ decode_qptest() compare_qptest() cleanup_qptest() + print(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 ------------------------------------------------------------------------ function test_selectbugs() local r, s, e = socket.select(nil, nil, 0.1) +print(r, s, e) assert(type(r) == "table" and type(s) == "table" and (e == "timeout" or e == "error")) pass("both nil: ok") @@ -352,10 +353,23 @@ function test_selectbugs() (e == "timeout" or e == "error")) pass("closed sockets: ok") e = pcall(socket.select, "wrong", 1, 0.1) - assert(e == false) + assert(e == false, tostring(e)) e = pcall(socket.select, {}, 1, 0.1) - assert(e == false) + assert(e == false, tostring(e)) pass("invalid input: ok") + local toomany = {} + for i = 1, socket._SETSIZE+1 do + toomany[#toomany+1] = socket.udp() + end + if #toomany > socket._SETSIZE then + local e = pcall(socket.select, toomany, nil, 0.1) + assert(e == false, tostring(e)) + pass("too many sockets (" .. #toomany .. "): ok") + else + pass("unable to create enough sockets (max was "..#toomany..")") + pass("try using ulimit") + end + for _, c in ipairs(toomany) do c:close() end end ------------------------------------------------------------------------ @@ -555,6 +569,25 @@ function test_readafterclose() print("ok") end +------------------------------------------------------------------------ +function test_writeafterclose() + local str = 'little string' + reconnect() + remote (string.format ([[ + data:close() + data = nil + ]])) + local sent, err, errsent + while not err do + sent, err, errsent, time = data:send(str) + end + print(sent, err, errsent, time) + print("ok") +end + +------------------------------------------------------------------------ +--test_writeafterclose() + test("method registration") test_methods(socket.tcp(), { "accept", @@ -596,12 +629,12 @@ test_methods(socket.udp(), { "settimeout" }) -test("testing read after close") -test_readafterclose() - test("select function") test_selectbugs() +test("testing read after close") +test_readafterclose() + test("connect function") connect_timeout() empty_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{ port = 2525 } +print(r, e) + -- creates a source to send a message with two parts. The first part is -- plain text, the second part is a PNG image, encoded as base64. source = smtp.message{ -- cgit v1.2.3-55-g6feb