diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
| commit | bce60be30fe8e9c1b0eb33128c23c93d7bca5303 (patch) | |
| tree | 3927343c777fcb7764a0f2f89754a0ceab141c21 /test | |
| parent | d1a72435d5bd3528f3c334cd4d1da16dcead47bf (diff) | |
| download | luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.gz luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.bz2 luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.zip | |
Decent makefiles!
Diffstat (limited to 'test')
| -rw-r--r-- | test/README | 2 | ||||
| -rw-r--r-- | test/hello.lua | 3 | ||||
| -rw-r--r-- | test/httptest.lua | 10 | ||||
| -rw-r--r-- | test/mimetest.lua | 24 | ||||
| -rw-r--r-- | test/testclnt.lua | 43 | ||||
| -rw-r--r-- | test/testmesg.lua | 2 |
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 | ||
| 9 | To run these tests, just run lua on the server and then on the client. | 9 | To 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 | |||
| 11 | Good luck, | 13 | Good luck, |
| 12 | Diego. | 14 | 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 @@ | |||
| 1 | require"socket" | ||
| 2 | require"mime" | ||
| 3 | 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") | |||
| 420 | io.write("testing HEAD method: ") | 420 | io.write("testing HEAD method: ") |
| 421 | local r, c, h = http.request { | 421 | local 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 | } |
| 425 | assert(r and h and (c == 200), c) | 425 | assert(r and h and (c == 200), c) |
| 426 | print("ok") | 426 | print("ok") |
| 427 | 427 | ||
| 428 | ------------------------------------------------------------------------ | 428 | ------------------------------------------------------------------------ |
| 429 | io.write("testing host not found: ") | 429 | io.write("testing host not found: ") |
| 430 | local c, e = socket.connect("wronghost", 80) | 430 | local c, e = socket.connect("example.invalid", 80) |
| 431 | local r, re = http.request{url = "http://wronghost/does/not/exist"} | 431 | local r, re = http.request{url = "http://example.invalid/does/not/exist"} |
| 432 | assert(r == nil and e == re) | 432 | assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) |
| 433 | r, re = http.request("http://wronghost/does/not/exist") | 433 | r, re = http.request("http://example.invalid/does/not/exist") |
| 434 | assert(r == nil and e == re) | 434 | assert(r == nil and e == re) |
| 435 | print("ok") | 435 | print("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") |
| 252 | end | 252 | end |
| 253 | 253 | ||
| 254 | local function test_b64lowlevel() | ||
| 255 | io.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") | ||
| 274 | end | ||
| 275 | |||
| 254 | local t = socket.gettime() | 276 | local t = socket.gettime() |
| 255 | 277 | ||
| 256 | create_b64test() | 278 | create_b64test() |
| @@ -260,6 +282,7 @@ decode_b64test() | |||
| 260 | compare_b64test() | 282 | compare_b64test() |
| 261 | cleanup_b64test() | 283 | cleanup_b64test() |
| 262 | padding_b64test() | 284 | padding_b64test() |
| 285 | test_b64lowlevel() | ||
| 263 | 286 | ||
| 264 | create_qptest() | 287 | create_qptest() |
| 265 | encode_qptest() | 288 | encode_qptest() |
| @@ -270,4 +293,5 @@ decode_qptest() | |||
| 270 | compare_qptest() | 293 | compare_qptest() |
| 271 | cleanup_qptest() | 294 | cleanup_qptest() |
| 272 | 295 | ||
| 296 | |||
| 273 | print(string.format("done in %.2fs", socket.gettime() - t)) | 297 | 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 | |||
| 342 | ------------------------------------------------------------------------ | 342 | ------------------------------------------------------------------------ |
| 343 | function test_selectbugs() | 343 | function test_selectbugs() |
| 344 | local r, s, e = socket.select(nil, nil, 0.1) | 344 | local r, s, e = socket.select(nil, nil, 0.1) |
| 345 | print(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 | ||
| 359 | end | 373 | end |
| 360 | 374 | ||
| 361 | ------------------------------------------------------------------------ | 375 | ------------------------------------------------------------------------ |
| @@ -555,6 +569,25 @@ function test_readafterclose() | |||
| 555 | print("ok") | 569 | print("ok") |
| 556 | end | 570 | end |
| 557 | 571 | ||
| 572 | ------------------------------------------------------------------------ | ||
| 573 | function 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") | ||
| 586 | end | ||
| 587 | |||
| 588 | ------------------------------------------------------------------------ | ||
| 589 | --test_writeafterclose() | ||
| 590 | |||
| 558 | test("method registration") | 591 | test("method registration") |
| 559 | test_methods(socket.tcp(), { | 592 | test_methods(socket.tcp(), { |
| 560 | "accept", | 593 | "accept", |
| @@ -596,12 +629,12 @@ test_methods(socket.udp(), { | |||
| 596 | "settimeout" | 629 | "settimeout" |
| 597 | }) | 630 | }) |
| 598 | 631 | ||
| 599 | test("testing read after close") | ||
| 600 | test_readafterclose() | ||
| 601 | |||
| 602 | test("select function") | 632 | test("select function") |
| 603 | test_selectbugs() | 633 | test_selectbugs() |
| 604 | 634 | ||
| 635 | test("testing read after close") | ||
| 636 | test_readafterclose() | ||
| 637 | |||
| 605 | test("connect function") | 638 | test("connect function") |
| 606 | connect_timeout() | 639 | connect_timeout() |
| 607 | empty_connect() | 640 | 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{ | |||
| 32 | port = 2525 | 32 | port = 2525 |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | print(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. |
| 37 | source = smtp.message{ | 39 | source = smtp.message{ |
