Tested in windows. Still needs more testing, but progress has been made.
This commit is contained in:
parent
89f3ecf782
commit
076451c753
11 changed files with 620 additions and 296 deletions
|
@ -99,8 +99,6 @@ else pass("connected!") end
|
|||
control:setoption("tcp-nodelay", true)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("method registration")
|
||||
|
||||
function test_methods(sock, methods)
|
||||
for _, v in methods do
|
||||
if type(sock[v]) ~= "function" then
|
||||
|
@ -110,38 +108,7 @@ function test_methods(sock, methods)
|
|||
pass(sock.class .. " methods are ok")
|
||||
end
|
||||
|
||||
test_methods(socket.tcp(), {
|
||||
"connect",
|
||||
"send",
|
||||
"receive",
|
||||
"bind",
|
||||
"accept",
|
||||
"setpeername",
|
||||
"setsockname",
|
||||
"getpeername",
|
||||
"getsockname",
|
||||
"setoption",
|
||||
"settimeout",
|
||||
"close",
|
||||
})
|
||||
|
||||
test_methods(socket.udp(), {
|
||||
"getpeername",
|
||||
"getsockname",
|
||||
"setsockname",
|
||||
"setpeername",
|
||||
"send",
|
||||
"sendto",
|
||||
"receive",
|
||||
"receivefrom",
|
||||
"setoption",
|
||||
"settimeout",
|
||||
"close",
|
||||
})
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("mixed patterns")
|
||||
|
||||
function test_mixed(len)
|
||||
reconnect()
|
||||
local inter = math.ceil(len/4)
|
||||
|
@ -163,21 +130,7 @@ remote "data:send(str); data:close()"
|
|||
else fail("patterns don't match") end
|
||||
end
|
||||
|
||||
|
||||
test_mixed(1)
|
||||
test_mixed(17)
|
||||
test_mixed(200)
|
||||
test_mixed(4091)
|
||||
test_mixed(80199)
|
||||
test_mixed(4091)
|
||||
test_mixed(200)
|
||||
test_mixed(17)
|
||||
test_mixed(1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("character line")
|
||||
reconnect()
|
||||
|
||||
function test_asciiline(len)
|
||||
local str, str10, back, err
|
||||
str = string.rep("x", math.mod(len, 10))
|
||||
|
@ -194,22 +147,7 @@ remote "data:send(str, '\\n')"
|
|||
else fail("lines don't match") end
|
||||
end
|
||||
|
||||
test_asciiline(1)
|
||||
test_asciiline(17)
|
||||
test_asciiline(200)
|
||||
test_asciiline(4091)
|
||||
test_asciiline(80199)
|
||||
test_asciiline(800000)
|
||||
test_asciiline(80199)
|
||||
test_asciiline(4091)
|
||||
test_asciiline(200)
|
||||
test_asciiline(17)
|
||||
test_asciiline(1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("binary line")
|
||||
reconnect()
|
||||
|
||||
function test_rawline(len)
|
||||
local str, str10, back, err
|
||||
str = string.rep(string.char(47), math.mod(len, 10))
|
||||
|
@ -227,22 +165,7 @@ remote "data:send(str, '\\n')"
|
|||
else fail("lines don't match") end
|
||||
end
|
||||
|
||||
test_rawline(1)
|
||||
test_rawline(17)
|
||||
test_rawline(200)
|
||||
test_rawline(4091)
|
||||
test_rawline(80199)
|
||||
test_rawline(800000)
|
||||
test_rawline(80199)
|
||||
test_rawline(4091)
|
||||
test_rawline(200)
|
||||
test_rawline(17)
|
||||
test_rawline(1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("raw transfer")
|
||||
reconnect()
|
||||
|
||||
function test_raw(len)
|
||||
local half = math.floor(len/2)
|
||||
local s1, s2, back, err
|
||||
|
@ -261,38 +184,7 @@ remote "data:send(str)"
|
|||
else fail("blocks don't match") end
|
||||
end
|
||||
|
||||
test_raw(1)
|
||||
test_raw(17)
|
||||
test_raw(200)
|
||||
test_raw(4091)
|
||||
test_raw(80199)
|
||||
test_raw(800000)
|
||||
test_raw(80199)
|
||||
test_raw(4091)
|
||||
test_raw(200)
|
||||
test_raw(17)
|
||||
test_raw(1)
|
||||
------------------------------------------------------------------------
|
||||
test("non-blocking transfer")
|
||||
reconnect()
|
||||
|
||||
-- the value is not important, we only want
|
||||
-- to test non-blockin I/O anyways
|
||||
data:settimeout(200)
|
||||
test_raw(1)
|
||||
test_raw(17)
|
||||
test_raw(200)
|
||||
test_raw(4091)
|
||||
test_raw(80199)
|
||||
test_raw(800000)
|
||||
test_raw(80199)
|
||||
test_raw(4091)
|
||||
test_raw(200)
|
||||
test_raw(17)
|
||||
test_raw(1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("total timeout on receive")
|
||||
function test_totaltimeoutreceive(len, tm, sl)
|
||||
local str, err, total
|
||||
reconnect()
|
||||
|
@ -311,13 +203,8 @@ function test_totaltimeoutreceive(len, tm, sl)
|
|||
check_timeout(tm, sl, elapsed, err, "receive", "total",
|
||||
string.len(str) == 2*len)
|
||||
end
|
||||
test_totaltimeoutreceive(800091, 1, 3)
|
||||
test_totaltimeoutreceive(800091, 2, 3)
|
||||
test_totaltimeoutreceive(800091, 3, 2)
|
||||
test_totaltimeoutreceive(800091, 3, 1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("total timeout on send")
|
||||
function test_totaltimeoutsend(len, tm, sl)
|
||||
local str, err, total
|
||||
reconnect()
|
||||
|
@ -336,13 +223,8 @@ function test_totaltimeoutsend(len, tm, sl)
|
|||
check_timeout(tm, sl, elapsed, err, "send", "total",
|
||||
total == 2*len)
|
||||
end
|
||||
test_totaltimeoutsend(800091, 1, 3)
|
||||
test_totaltimeoutsend(800091, 2, 3)
|
||||
test_totaltimeoutsend(800091, 3, 2)
|
||||
test_totaltimeoutsend(800091, 3, 1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("blocking timeout on receive")
|
||||
function test_blockingtimeoutreceive(len, tm, sl)
|
||||
local str, err, total
|
||||
reconnect()
|
||||
|
@ -361,13 +243,8 @@ function test_blockingtimeoutreceive(len, tm, sl)
|
|||
check_timeout(tm, sl, elapsed, err, "receive", "blocking",
|
||||
string.len(str) == 2*len)
|
||||
end
|
||||
test_blockingtimeoutreceive(800091, 1, 3)
|
||||
test_blockingtimeoutreceive(800091, 2, 3)
|
||||
test_blockingtimeoutreceive(800091, 3, 2)
|
||||
test_blockingtimeoutreceive(800091, 3, 1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("blocking timeout on send")
|
||||
function test_blockingtimeoutsend(len, tm, sl)
|
||||
local str, err, total
|
||||
reconnect()
|
||||
|
@ -386,15 +263,8 @@ function test_blockingtimeoutsend(len, tm, sl)
|
|||
check_timeout(tm, sl, elapsed, err, "send", "blocking",
|
||||
total == 2*len)
|
||||
end
|
||||
test_blockingtimeoutsend(800091, 1, 3)
|
||||
test_blockingtimeoutsend(800091, 2, 3)
|
||||
test_blockingtimeoutsend(800091, 3, 2)
|
||||
test_blockingtimeoutsend(800091, 3, 1)
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("bugs")
|
||||
|
||||
io.write("empty host connect: ")
|
||||
function empty_connect()
|
||||
if data then data:close() data = nil end
|
||||
remote [[
|
||||
|
@ -408,27 +278,25 @@ function empty_connect()
|
|||
else fail("should not have connected!") end
|
||||
end
|
||||
|
||||
empty_connect()
|
||||
------------------------------------------------------------------------
|
||||
function isclosed(c)
|
||||
return c:fd() == -1 or c:fd() == (2^32-1)
|
||||
end
|
||||
|
||||
-- io.write("active close: ")
|
||||
function active_close()
|
||||
reconnect()
|
||||
if socket._isclosed(data) then fail("should not be closed") end
|
||||
if isclosed(data) then fail("should not be closed") end
|
||||
data:close()
|
||||
if not socket._isclosed(data) then fail("should be closed") end
|
||||
if not isclosed(data) then fail("should be closed") end
|
||||
data = nil
|
||||
local udp = socket.udp()
|
||||
if socket._isclosed(udp) then fail("should not be closed") end
|
||||
if isclosed(udp) then fail("should not be closed") end
|
||||
udp:close()
|
||||
if not socket._isclosed(udp) then fail("should be closed") end
|
||||
if not isclosed(udp) then fail("should be closed") end
|
||||
pass("ok")
|
||||
end
|
||||
|
||||
-- active_close()
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("closed connection detection")
|
||||
|
||||
function test_closed()
|
||||
local back, err
|
||||
local str = 'little string'
|
||||
|
@ -453,18 +321,15 @@ function test_closed()
|
|||
]]
|
||||
total, err = data:send(string.rep("ugauga", 100000))
|
||||
if not err then
|
||||
pass("failed: output buffer is at least %d bytes long!", total)
|
||||
pass("failed: output buffer is at least %d bytes long!", total)
|
||||
elseif err ~= "closed" then
|
||||
fail("got '"..err.."' instead of 'closed'.")
|
||||
fail("got '"..err.."' instead of 'closed'.")
|
||||
else
|
||||
pass("graceful 'closed' received after %d bytes were sent", total)
|
||||
pass("graceful 'closed' received after %d bytes were sent", total)
|
||||
end
|
||||
end
|
||||
|
||||
test_closed()
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("select function")
|
||||
function test_selectbugs()
|
||||
local r, s, e = socket.select(nil, nil, 0.1)
|
||||
assert(type(r) == "table" and type(s) == "table" and e == "timeout")
|
||||
|
@ -481,7 +346,144 @@ function test_selectbugs()
|
|||
pass("invalid input: ok")
|
||||
end
|
||||
|
||||
test("method registration")
|
||||
test_methods(socket.tcp(), {
|
||||
"connect",
|
||||
"send",
|
||||
"receive",
|
||||
"bind",
|
||||
"accept",
|
||||
"setpeername",
|
||||
"setsockname",
|
||||
"getpeername",
|
||||
"getsockname",
|
||||
"setoption",
|
||||
"settimeout",
|
||||
"close",
|
||||
})
|
||||
test_methods(socket.udp(), {
|
||||
"getpeername",
|
||||
"getsockname",
|
||||
"setsockname",
|
||||
"setpeername",
|
||||
"send",
|
||||
"sendto",
|
||||
"receive",
|
||||
"receivefrom",
|
||||
"setoption",
|
||||
"settimeout",
|
||||
"close",
|
||||
})
|
||||
|
||||
test("mixed patterns")
|
||||
reconnect()
|
||||
test_mixed(1)
|
||||
test_mixed(17)
|
||||
test_mixed(200)
|
||||
test_mixed(4091)
|
||||
test_mixed(801990)
|
||||
test_mixed(4091)
|
||||
test_mixed(200)
|
||||
test_mixed(17)
|
||||
test_mixed(1)
|
||||
|
||||
test("character line")
|
||||
reconnect()
|
||||
test_asciiline(1)
|
||||
test_asciiline(17)
|
||||
test_asciiline(200)
|
||||
test_asciiline(4091)
|
||||
test_asciiline(80199)
|
||||
test_asciiline(8000000)
|
||||
test_asciiline(80199)
|
||||
test_asciiline(4091)
|
||||
test_asciiline(200)
|
||||
test_asciiline(17)
|
||||
test_asciiline(1)
|
||||
|
||||
test("binary line")
|
||||
reconnect()
|
||||
test_rawline(1)
|
||||
test_rawline(17)
|
||||
test_rawline(200)
|
||||
test_rawline(4091)
|
||||
test_rawline(80199)
|
||||
test_rawline(8000000)
|
||||
test_rawline(80199)
|
||||
test_rawline(4091)
|
||||
test_rawline(200)
|
||||
test_rawline(17)
|
||||
test_rawline(1)
|
||||
|
||||
test("raw transfer")
|
||||
reconnect()
|
||||
test_raw(1)
|
||||
test_raw(17)
|
||||
test_raw(200)
|
||||
test_raw(4091)
|
||||
test_raw(80199)
|
||||
test_raw(8000000)
|
||||
test_raw(80199)
|
||||
test_raw(4091)
|
||||
test_raw(200)
|
||||
test_raw(17)
|
||||
test_raw(1)
|
||||
|
||||
test("non-blocking transfer")
|
||||
reconnect()
|
||||
-- the value is not important, we only want
|
||||
-- to test non-blockin I/O anyways
|
||||
data:settimeout(200)
|
||||
test_raw(1)
|
||||
test_raw(17)
|
||||
test_raw(200)
|
||||
test_raw(4091)
|
||||
test_raw(80199)
|
||||
test_raw(8000000)
|
||||
test_raw(80199)
|
||||
test_raw(4091)
|
||||
test_raw(200)
|
||||
test_raw(17)
|
||||
test_raw(1)
|
||||
|
||||
test("select function")
|
||||
test_selectbugs()
|
||||
|
||||
test("empty host connect: ")
|
||||
empty_connect()
|
||||
|
||||
test("active close: ")
|
||||
active_close()
|
||||
|
||||
test("closed connection detection: ")
|
||||
test_closed()
|
||||
|
||||
a = [[
|
||||
test("total timeout on send")
|
||||
test_totaltimeoutsend(800091, 1, 3)
|
||||
test_totaltimeoutsend(800091, 2, 3)
|
||||
test_totaltimeoutsend(800091, 3, 2)
|
||||
test_totaltimeoutsend(800091, 3, 1)
|
||||
|
||||
test("total timeout on receive")
|
||||
test_totaltimeoutreceive(800091, 1, 3)
|
||||
test_totaltimeoutreceive(800091, 2, 3)
|
||||
test_totaltimeoutreceive(800091, 3, 2)
|
||||
test_totaltimeoutreceive(800091, 3, 1)
|
||||
|
||||
test("blocking timeout on send")
|
||||
test_blockingtimeoutsend(800091, 1, 3)
|
||||
test_blockingtimeoutsend(800091, 2, 3)
|
||||
test_blockingtimeoutsend(800091, 3, 2)
|
||||
test_blockingtimeoutsend(800091, 3, 1)
|
||||
|
||||
test("blocking timeout on receive")
|
||||
test_blockingtimeoutreceive(800091, 1, 3)
|
||||
test_blockingtimeoutreceive(800091, 2, 3)
|
||||
test_blockingtimeoutreceive(800091, 3, 2)
|
||||
test_blockingtimeoutreceive(800091, 3, 1)
|
||||
]]
|
||||
|
||||
socket.done()
|
||||
|
||||
test(string.format("done in %.2fs", socket.time() - start))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue