aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/auth/.htaccess2
-rw-r--r--test/excepttest.lua32
-rwxr-xr-xtest/find-connect-limit2
-rw-r--r--test/ftptest.lua34
-rw-r--r--test/httptest.lua31
-rw-r--r--test/ltn12test.lua33
-rw-r--r--test/mimetest.lua46
-rw-r--r--test/smtptest.lua20
-rwxr-xr-xtest/tcp-getoptions28
-rw-r--r--test/test_socket_error.lua2
-rw-r--r--test/testclnt.lua1
-rw-r--r--test/testmesg.lua14
-rw-r--r--test/testsupport.lua2
-rwxr-xr-xtest/udp-zero-length-send4
-rwxr-xr-xtest/udp-zero-length-send-recv4
-rw-r--r--test/unixdgramclnt.lua9
-rw-r--r--test/unixdgramsrvr.lua9
-rw-r--r--test/unixstreamclnt.lua (renamed from test/unixclnt.lua)2
-rw-r--r--test/unixstreamsrvr.lua (renamed from test/unixsrvr.lua)2
-rw-r--r--test/urltest.lua211
-rw-r--r--test/utestclnt.lua68
-rw-r--r--test/utestsrvr.lua2
22 files changed, 385 insertions, 173 deletions
diff --git a/test/auth/.htaccess b/test/auth/.htaccess
index bb2794a..2509ae3 100644
--- a/test/auth/.htaccess
+++ b/test/auth/.htaccess
@@ -1,4 +1,4 @@
1AuthName "test-auth" 1AuthName "test-auth"
2 AuthType Basic 2 AuthType Basic
3 AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd 3 AuthUserFile /home/diego/impa/luasocket/test/auth/.htpasswd
4 Require valid-user 4 Require valid-user
diff --git a/test/excepttest.lua b/test/excepttest.lua
index ce9f197..80c9cb8 100644
--- a/test/excepttest.lua
+++ b/test/excepttest.lua
@@ -1,6 +1,30 @@
1local socket = require("socket") 1local socket = require("socket")
2try = socket.newtry(function() 2
3 print("finalized!!!") 3local finalizer_called
4
5local func = socket.protect(function(err, ...)
6 local try = socket.newtry(function()
7 finalizer_called = true
8 end)
9
10 if err then
11 return error(err, 0)
12 else
13 return try(...)
14 end
4end) 15end)
5try = socket.protect(try) 16
6print(try(nil, "it works")) 17local ret1, ret2, ret3 = func(false, 1, 2, 3)
18assert(not finalizer_called, "unexpected finalizer call")
19assert(ret1 == 1 and ret2 == 2 and ret3 == 3, "incorrect return values")
20
21ret1, ret2, ret3 = func(false, false, "error message")
22assert(finalizer_called, "finalizer not called")
23assert(ret1 == nil and ret2 == "error message" and ret3 == nil, "incorrect return values")
24
25local err = {key = "value"}
26ret1, ret2 = pcall(func, err)
27assert(not ret1, "error not rethrown")
28assert(ret2 == err, "incorrect error rethrown")
29
30print("OK")
diff --git a/test/find-connect-limit b/test/find-connect-limit
index ad0c3f5..199e515 100755
--- a/test/find-connect-limit
+++ b/test/find-connect-limit
@@ -10,7 +10,7 @@ ulimit -n
10You'll probably need to be root to do this. 10You'll probably need to be root to do this.
11]] 11]]
12 12
13require "socket" 13socket = require "socket"
14 14
15host = arg[1] or "google.com" 15host = arg[1] or "google.com"
16port = arg[2] or 80 16port = arg[2] or 80
diff --git a/test/ftptest.lua b/test/ftptest.lua
index fb13326..3ea0d39 100644
--- a/test/ftptest.lua
+++ b/test/ftptest.lua
@@ -3,19 +3,31 @@ local ftp = require("socket.ftp")
3local url = require("socket.url") 3local url = require("socket.url")
4local ltn12 = require("ltn12") 4local ltn12 = require("ltn12")
5 5
6-- use dscl to create user "luasocket" with password "password"
7-- with home in /Users/diego/luasocket/test/ftp
8-- with group com.apple.access_ftp
9-- with shell set to /sbin/nologin
10-- set /etc/ftpchroot to chroot luasocket
11-- must set group com.apple.access_ftp on user _ftp (for anonymous access)
12-- copy index.html to /var/empty/pub (home of user ftp)
13-- start ftp server with
14-- sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
15-- copy index.html to /Users/diego/luasocket/test/ftp
16-- stop with
17-- sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
18
6-- override protection to make sure we see all errors 19-- override protection to make sure we see all errors
7--socket.protect = function(s) return s end 20--socket.protect = function(s) return s end
8 21
9dofile("testsupport.lua") 22dofile("testsupport.lua")
10 23
11local host, port, index_file, index, back, err, ret 24local host = host or "localhost"
25local port, index_file, index, back, err, ret
12 26
13local t = socket.gettime() 27local t = socket.gettime()
14 28
15host = host or "localhost"
16index_file = "index.html" 29index_file = "index.html"
17 30
18
19-- a function that returns a directory listing 31-- a function that returns a directory listing
20local function nlst(u) 32local function nlst(u)
21 local t = {} 33 local t = {}
@@ -55,27 +67,27 @@ assert(not err and back == index, err)
55print("ok") 67print("ok")
56 68
57io.write("erasing before upload: ") 69io.write("erasing before upload: ")
58ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") 70ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html")
59if not ret then print(err) 71if not ret then print(err)
60else print("ok") end 72else print("ok") end
61 73
62io.write("testing upload: ") 74io.write("testing upload: ")
63ret, err = ftp.put("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i", index) 75ret, err = ftp.put("ftp://luasocket:password@" .. host .. "/index.up.html;type=i", index)
64assert(ret and not err, err) 76assert(ret and not err, err)
65print("ok") 77print("ok")
66 78
67io.write("downloading uploaded file: ") 79io.write("downloading uploaded file: ")
68back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/index.up.html;type=i") 80back, err = ftp.get("ftp://luasocket:password@" .. host .. "/index.up.html;type=i")
69assert(ret and not err and index == back, err) 81assert(ret and not err and index == back, err)
70print("ok") 82print("ok")
71 83
72io.write("erasing after upload/download: ") 84io.write("erasing after upload/download: ")
73ret, err = dele("ftp://luasocket:pedrovian@" .. host .. "/index.up.html") 85ret, err = dele("ftp://luasocket:password@" .. host .. "/index.up.html")
74assert(ret and not err, err) 86assert(ret and not err, err)
75print("ok") 87print("ok")
76 88
77io.write("testing weird-character translation: ") 89io.write("testing weird-character translation: ")
78back, err = ftp.get("ftp://luasocket:pedrovian@" .. host .. "/%23%3f;type=i") 90back, err = ftp.get("ftp://luasocket:password@" .. host .. "/%23%3f;type=i")
79assert(not err and back == index, err) 91assert(not err and back == index, err)
80print("ok") 92print("ok")
81 93
@@ -84,7 +96,7 @@ local back = {}
84ret, err = ftp.get{ 96ret, err = ftp.get{
85 url = "//stupid:mistake@" .. host .. "/index.html", 97 url = "//stupid:mistake@" .. host .. "/index.html",
86 user = "luasocket", 98 user = "luasocket",
87 password = "pedrovian", 99 password = "password",
88 type = "i", 100 type = "i",
89 sink = ltn12.sink.table(back) 101 sink = ltn12.sink.table(back)
90} 102}
diff --git a/test/httptest.lua b/test/httptest.lua
index 63ff921..3457b07 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -265,6 +265,37 @@ ignore = {
265} 265}
266check_request(request, expect, ignore) 266check_request(request, expect, ignore)
267 267
268-- Use https://httpbin.org/#/Dynamic_data/get_base64__value_ for testing
269-----------------------------------------------------
270io.write("testing absolute https redirection: ")
271request = {
272 url = "https://httpbin.org/redirect-to?url=https://httpbin.org/base64/THVhIFNvY2tldA=="
273}
274expect = {
275 code = 200,
276 body = "Lua Socket"
277}
278ignore = {
279 status = 1,
280 headers = 1
281}
282check_request(request, expect, ignore)
283
284-----------------------------------------------------
285io.write("testing relative https redirection: ")
286request = {
287 url = "https://httpbin.org/redirect-to?url=/base64/THVhIFNvY2tldA=="
288}
289expect = {
290 code = 200,
291 body = "Lua Socket"
292}
293ignore = {
294 status = 1,
295 headers = 1
296}
297check_request(request, expect, ignore)
298
268------------------------------------------------------------------------ 299------------------------------------------------------------------------
269--[[ 300--[[
270io.write("testing proxy with redirection: ") 301io.write("testing proxy with redirection: ")
diff --git a/test/ltn12test.lua b/test/ltn12test.lua
index e3f85fb..0cafbc9 100644
--- a/test/ltn12test.lua
+++ b/test/ltn12test.lua
@@ -38,7 +38,7 @@ local function named(f, name)
38end 38end
39 39
40-------------------------------- 40--------------------------------
41local function split(size) 41local function split(size)
42 local buffer = "" 42 local buffer = ""
43 local last_out = "" 43 local last_out = ""
44 local last_in = "" 44 local last_in = ""
@@ -50,12 +50,12 @@ local function split(size)
50 return last_out 50 return last_out
51 end 51 end
52 return function(chunk, done) 52 return function(chunk, done)
53 if done then 53 if done then
54 return not last_in and not last_out 54 return not last_in and not last_out
55 end 55 end
56 -- check if argument is consistent with state 56 -- check if argument is consistent with state
57 if not chunk then 57 if not chunk then
58 if last_in and last_in ~= "" and last_out ~= "" then 58 if last_in and last_in ~= "" and last_out ~= "" then
59 error("nil chunk following data chunk", 2) 59 error("nil chunk following data chunk", 2)
60 end 60 end
61 if not last_out then error("extra nil chunk", 2) end 61 if not last_out then error("extra nil chunk", 2) end
@@ -67,8 +67,8 @@ local function split(size)
67 return output(chunk) 67 return output(chunk)
68 else 68 else
69 if not last_in then error("data chunk following nil chunk", 2) end 69 if not last_in then error("data chunk following nil chunk", 2) end
70 if last_in ~= "" and last_out ~= "" then 70 if last_in ~= "" and last_out ~= "" then
71 error("data chunk following data chunk", 2) 71 error("data chunk following data chunk", 2)
72 end 72 end
73 buffer = chunk 73 buffer = chunk
74 return output(chunk) 74 return output(chunk)
@@ -85,7 +85,7 @@ local function format(chunk)
85end 85end
86 86
87-------------------------------- 87--------------------------------
88local function merge(size) 88local function merge(size)
89 local buffer = "" 89 local buffer = ""
90 local last_out = "" 90 local last_out = ""
91 local last_in = "" 91 local last_in = ""
@@ -102,12 +102,12 @@ local function merge(size)
102 return last_out 102 return last_out
103 end 103 end
104 return function(chunk, done) 104 return function(chunk, done)
105 if done then 105 if done then
106 return not last_in and not last_out 106 return not last_in and not last_out
107 end 107 end
108 -- check if argument is consistent with state 108 -- check if argument is consistent with state
109 if not chunk then 109 if not chunk then
110 if last_in and last_in ~= "" and last_out ~= "" then 110 if last_in and last_in ~= "" and last_out ~= "" then
111 error("nil chunk following data chunk", 2) 111 error("nil chunk following data chunk", 2)
112 end 112 end
113 if not last_out then error("extra nil chunk", 2) end 113 if not last_out then error("extra nil chunk", 2) end
@@ -119,8 +119,8 @@ local function merge(size)
119 return output(chunk) 119 return output(chunk)
120 else 120 else
121 if not last_in then error("data chunk following nil chunk", 2) end 121 if not last_in then error("data chunk following nil chunk", 2) end
122 if last_in ~= "" and last_out ~= "" then 122 if last_in ~= "" and last_out ~= "" then
123 error("data chunk following data chunk", 2) 123 error("data chunk following data chunk", 2)
124 end 124 end
125 buffer = buffer .. chunk 125 buffer = buffer .. chunk
126 return output(chunk) 126 return output(chunk)
@@ -181,6 +181,15 @@ assert(table.concat(t) == s, "mismatch")
181print("ok") 181print("ok")
182 182
183-------------------------------- 183--------------------------------
184io.write("testing source.table: ")
185local inp = {'a','b','c','d','e'}
186local source = ltn12.source.table(inp)
187sink, t = ltn12.sink.table()
188assert(ltn12.pump.all(source, sink), "returned error")
189for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end
190print("ok")
191
192--------------------------------
184io.write("testing source.chain (with split): ") 193io.write("testing source.chain (with split): ")
185source = ltn12.source.string(s) 194source = ltn12.source.string(s)
186filter = split(5) 195filter = split(5)
diff --git a/test/mimetest.lua b/test/mimetest.lua
index f5b3747..a3c89ac 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -15,27 +15,27 @@ local eb64test = "b64test.bin2"
15local db64test = "b64test.bin3" 15local db64test = "b64test.bin3"
16 16
17 17
18-- from Machado de Assis, "A Mão e a Rosa" 18-- from Machado de Assis, "A M�o e a Rosa"
19local mao = [[ 19local mao = [[
20 Cursavam estes dois moços a academia de S. Paulo, estando 20 Cursavam estes dois mo�os a academia de S. Paulo, estando
21 Luís Alves no quarto ano e Estêvão no terceiro. 21 Lu�s Alves no quarto ano e Est�v�o no terceiro.
22 Conheceram-se na academia, e ficaram amigos íntimos, tanto 22 Conheceram-se na academia, e ficaram amigos �ntimos, tanto
23 quanto podiam sê-lo dois espíritos diferentes, ou talvez por 23 quanto podiam s�-lo dois esp�ritos diferentes, ou talvez por
24 isso mesmo que o eram. Estêvão, dotado de extrema 24 isso mesmo que o eram. Est�v�o, dotado de extrema
25 sensibilidade, e não menor fraqueza de ânimo, afetuoso e 25 sensibilidade, e n�o menor fraqueza de �nimo, afetuoso e
26 bom, não daquela bondade varonil, que é apanágio de uma alma 26 bom, n�o daquela bondade varonil, que � apan�gio de uma alma
27 forte, mas dessa outra bondade mole e de cera, que vai à 27 forte, mas dessa outra bondade mole e de cera, que vai �
28 mercê de todas as circunstâncias, tinha, além de tudo isso, 28 merc� de todas as circunst�ncias, tinha, al�m de tudo isso,
29 o infortúnio de trazer ainda sobre o nariz os óculos 29 o infort�nio de trazer ainda sobre o nariz os �culos
30 cor-de-rosa de suas virginais ilusões. Luís Alves via bem 30 cor-de-rosa de suas virginais ilus�es. Lu�s Alves via bem
31 com os olhos da cara. Não era mau rapaz, mas tinha o seu 31 com os olhos da cara. N�o era mau rapaz, mas tinha o seu
32 grão de egoísmo, e se não era incapaz de afeições, sabia 32 gr�o de ego�smo, e se n�o era incapaz de afei��es, sabia
33 regê-las, moderá-las, e sobretudo guiá-las ao seu próprio 33 reg�-las, moder�-las, e sobretudo gui�-las ao seu pr�prio
34 interesse. Entre estes dois homens travara-se amizade 34 interesse. Entre estes dois homens travara-se amizade
35 íntima, nascida para um na simpatia, para outro no costume. 35 �ntima, nascida para um na simpatia, para outro no costume.
36 Eram eles os naturais confidentes um do outro, com a 36 Eram eles os naturais confidentes um do outro, com a
37 diferença que Luís Alves dava menos do que recebia, e, ainda 37 diferen�a que Lu�s Alves dava menos do que recebia, e, ainda
38 assim, nem tudo o que dava exprimia grande confiança. 38 assim, nem tudo o que dava exprimia grande confian�a.
39]] 39]]
40 40
41local function random(handle, io_err) 41local function random(handle, io_err)
@@ -44,8 +44,8 @@ local function random(handle, io_err)
44 if not handle then error("source is empty!", 2) end 44 if not handle then error("source is empty!", 2) end
45 local len = math.random(0, 1024) 45 local len = math.random(0, 1024)
46 local chunk = handle:read(len) 46 local chunk = handle:read(len)
47 if not chunk then 47 if not chunk then
48 handle:close() 48 handle:close()
49 handle = nil 49 handle = nil
50 end 50 end
51 return chunk 51 return chunk
@@ -62,7 +62,7 @@ local what = nil
62local function transform(input, output, filter) 62local function transform(input, output, filter)
63 local source = random(io.open(input, "rb")) 63 local source = random(io.open(input, "rb"))
64 local sink = ltn12.sink.file(io.open(output, "wb")) 64 local sink = ltn12.sink.file(io.open(output, "wb"))
65 if what then 65 if what then
66 sink = ltn12.sink.chain(filter, sink) 66 sink = ltn12.sink.chain(filter, sink)
67 else 67 else
68 source = ltn12.source.chain(source, filter) 68 source = ltn12.source.chain(source, filter)
@@ -147,7 +147,7 @@ local function create_qptest()
147 f:write(' ',string.char(32)) 147 f:write(' ',string.char(32))
148 end 148 end
149 f:write("\r\n") 149 f:write("\r\n")
150 150
151 f:close() 151 f:close()
152end 152end
153 153
@@ -157,7 +157,7 @@ local function cleanup_qptest()
157 os.remove(dqptest) 157 os.remove(dqptest)
158end 158end
159 159
160-- create test file 160-- create test file
161local function create_b64test() 161local function create_b64test()
162 local f = assert(io.open(b64test, "wb")) 162 local f = assert(io.open(b64test, "wb"))
163 local t = {} 163 local t = {}
diff --git a/test/smtptest.lua b/test/smtptest.lua
index b5380ff..9d06054 100644
--- a/test/smtptest.lua
+++ b/test/smtptest.lua
@@ -27,8 +27,8 @@ local total = function()
27end 27end
28 28
29local similar = function(s1, s2) 29local similar = function(s1, s2)
30 return 30 return
31 string.lower(string.gsub(s1, "%s", "")) == 31 string.lower(string.gsub(s1, "%s", "")) ==
32 string.lower(string.gsub(s2, "%s", "")) 32 string.lower(string.gsub(s2, "%s", ""))
33end 33end
34 34
@@ -40,9 +40,9 @@ end
40 40
41local readfile = function(name) 41local readfile = function(name)
42 local f = io.open(name, "r") 42 local f = io.open(name, "r")
43 if not f then 43 if not f then
44 fail("unable to open file!") 44 fail("unable to open file!")
45 return nil 45 return nil
46 end 46 end
47 local s = f:read("*a") 47 local s = f:read("*a")
48 f:close() 48 f:close()
@@ -52,7 +52,7 @@ end
52local empty = function() 52local empty = function()
53 for i,v in ipairs(files) do 53 for i,v in ipairs(files) do
54 local f = io.open(v, "w") 54 local f = io.open(v, "w")
55 if not f then 55 if not f then
56 fail("unable to open file!") 56 fail("unable to open file!")
57 end 57 end
58 f:close() 58 f:close()
@@ -116,8 +116,8 @@ local wait = function(sentinel, n)
116 while 1 do 116 while 1 do
117 local mbox = parse(get()) 117 local mbox = parse(get())
118 if n == #mbox then break end 118 if n == #mbox then break end
119 if socket.time() - sentinel.time > 50 then 119 if socket.time() - sentinel.time > 50 then
120 to = 1 120 to = 1
121 break 121 break
122 end 122 end
123 socket.sleep(1) 123 socket.sleep(1)
@@ -132,7 +132,7 @@ local stuffed_body = [[
132This message body needs to be 132This message body needs to be
133stuffed because it has a dot 133stuffed because it has a dot
134. 134.
135by itself on a line. 135by itself on a line.
136Otherwise the mailer would 136Otherwise the mailer would
137think that the dot 137think that the dot
138. 138.
@@ -219,7 +219,7 @@ else print("ok") end
219 219
220io.write("testing invalid from: ") 220io.write("testing invalid from: ")
221local ret, err = socket.smtp.mail{ 221local ret, err = socket.smtp.mail{
222 from = ' " " (( _ * ', 222 from = ' " " (( _ * ',
223 rcpt = rcpt, 223 rcpt = rcpt,
224} 224}
225if ret or not err then fail("wrong error message") 225if ret or not err then fail("wrong error message")
@@ -227,7 +227,7 @@ else print(err) end
227 227
228io.write("testing no rcpt: ") 228io.write("testing no rcpt: ")
229local ret, err = socket.smtp.mail{ 229local ret, err = socket.smtp.mail{
230 from = from, 230 from = from,
231} 231}
232if ret or not err then fail("wrong error message") 232if ret or not err then fail("wrong error message")
233else print(err) end 233else print(err) end
diff --git a/test/tcp-getoptions b/test/tcp-getoptions
index f9b3d1b..fbcc884 100755
--- a/test/tcp-getoptions
+++ b/test/tcp-getoptions
@@ -1,19 +1,35 @@
1#!/usr/bin/env lua 1#!/usr/bin/env lua
2 2
3require"socket" 3local socket = require"socket"
4 4
5port = 8765 5port = 8765
6 6
7function pcalltest(msg, o, opt)
8 local a = { pcall(o.getoption, o, opt) }
9 if a[1] then
10 print(msg, opt, unpack(a))
11 else
12 print(msg, opt, 'fail: ' .. a[2])
13 end
14end
15
7function options(o) 16function options(o)
8 print("options for", o) 17 print("options for", o)
9 18
10 for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do 19 for _, opt in ipairs{
11 print("getoption", opt, o:getoption(opt)) 20 "keepalive", "reuseaddr",
21 "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
22 pcalltest("getoption", o, opt)
12 end 23 end
13 24
14 print("getoption", "linger", 25 r = o:getoption'linger'
15 "on", o:getoption("linger").on, 26 if r then
16 "timeout", o:getoption("linger").timeout) 27 print("getoption", "linger",
28 "on", r.on,
29 "timeout", r.timeout)
30 else
31 print("getoption", "linger", "no result")
32 end
17end 33end
18 34
19local m = socket.tcp() 35local m = socket.tcp()
diff --git a/test/test_socket_error.lua b/test/test_socket_error.lua
index bda6408..1b4b601 100644
--- a/test/test_socket_error.lua
+++ b/test/test_socket_error.lua
@@ -19,7 +19,7 @@ for i = 1, 10 do
19 assert(ss == sock) 19 assert(ss == sock)
20 else 20 else
21 assert('timeout' == err, 'unexpected error :' .. tostring(err)) 21 assert('timeout' == err, 'unexpected error :' .. tostring(err))
22 end 22 end
23 err = sock:getoption("error") -- i get 'connection refused' on WinXP 23 err = sock:getoption("error") -- i get 'connection refused' on WinXP
24 if err then 24 if err then
25 print("Passed! Error is '" .. err .. "'.") 25 print("Passed! Error is '" .. err .. "'.")
diff --git a/test/testclnt.lua b/test/testclnt.lua
index ee1201f..170e187 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -669,7 +669,6 @@ local udp_methods = {
669 "settimeout" 669 "settimeout"
670} 670}
671 671
672
673------------------------------------------------------------------------ 672------------------------------------------------------------------------
674test_methods(socket.udp(), udp_methods) 673test_methods(socket.udp(), udp_methods)
675do local sock = socket.tcp6() 674do local sock = socket.tcp6()
diff --git a/test/testmesg.lua b/test/testmesg.lua
index 135a008..8c086d5 100644
--- a/test/testmesg.lua
+++ b/test/testmesg.lua
@@ -34,11 +34,11 @@ r, e = smtp.send{
34 34
35print(r, e) 35print(r, e)
36 36
37-- 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
38-- 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.
39source = smtp.message{ 39source = smtp.message{
40 headers = { 40 headers = {
41 -- Remember that headers are *ignored* by smtp.send. 41 -- Remember that headers are *ignored* by smtp.send.
42 from = "Sicrano <sicrano@tecgraf.puc-rio.br>", 42 from = "Sicrano <sicrano@tecgraf.puc-rio.br>",
43 to = "Fulano <fulano@tecgraf.puc-rio.br>", 43 to = "Fulano <fulano@tecgraf.puc-rio.br>",
44 subject = "Here is a message with attachments" 44 subject = "Here is a message with attachments"
@@ -49,18 +49,18 @@ source = smtp.message{
49 "Preamble might show up even in a MIME enabled client.", 49 "Preamble might show up even in a MIME enabled client.",
50 -- first part: No headers means plain text, us-ascii. 50 -- first part: No headers means plain text, us-ascii.
51 -- The mime.eol low-level filter normalizes end-of-line markers. 51 -- The mime.eol low-level filter normalizes end-of-line markers.
52 [1] = { 52 [1] = {
53 body = mime.eol(0, [[ 53 body = mime.eol(0, [[
54 Lines in a message body should always end with CRLF. 54 Lines in a message body should always end with CRLF.
55 The smtp module will *NOT* perform translation. It will 55 The smtp module will *NOT* perform translation. It will
56 perform necessary stuffing, though. 56 perform necessary stuffing, though.
57 ]]) 57 ]])
58 }, 58 },
59 -- second part: Headers describe content the to be an image, 59 -- second part: Headers describe content the to be an image,
60 -- sent under the base64 transfer content encoding. 60 -- sent under the base64 transfer content encoding.
61 -- Notice that nothing happens until the message is sent. Small 61 -- Notice that nothing happens until the message is sent. Small
62 -- chunks are loaded into memory and translation happens on the fly. 62 -- chunks are loaded into memory and translation happens on the fly.
63 [2] = { 63 [2] = {
64 headers = { 64 headers = {
65 ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', 65 ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"',
66 ["content-disposition"] = 'attachment; filename="luasocket.png"', 66 ["content-disposition"] = 'attachment; filename="luasocket.png"',
diff --git a/test/testsupport.lua b/test/testsupport.lua
index b986088..4360b6b 100644
--- a/test/testsupport.lua
+++ b/test/testsupport.lua
@@ -7,7 +7,7 @@ function readfile(name)
7end 7end
8 8
9function similar(s1, s2) 9function similar(s1, s2)
10 return string.lower(string.gsub(s1 or "", "%s", "")) == 10 return string.lower(string.gsub(s1 or "", "%s", "")) ==
11 string.lower(string.gsub(s2 or "", "%s", "")) 11 string.lower(string.gsub(s2 or "", "%s", ""))
12end 12end
13 13
diff --git a/test/udp-zero-length-send b/test/udp-zero-length-send
index a594944..9038c99 100755
--- a/test/udp-zero-length-send
+++ b/test/udp-zero-length-send
@@ -1,4 +1,4 @@
1#!/usr/bin/lua 1#!/usr/bin/env lua
2 2
3--[[ 3--[[
4Show that luasocket returns an error message on zero-length UDP sends, 4Show that luasocket returns an error message on zero-length UDP sends,
@@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
12 12
13]] 13]]
14 14
15require"socket" 15socket = require"socket"
16 16
17s = assert(socket.udp()) 17s = assert(socket.udp())
18r = assert(socket.udp()) 18r = assert(socket.udp())
diff --git a/test/udp-zero-length-send-recv b/test/udp-zero-length-send-recv
index 541efd4..064ca52 100755
--- a/test/udp-zero-length-send-recv
+++ b/test/udp-zero-length-send-recv
@@ -1,4 +1,4 @@
1#!/usr/bin/lua 1#!/usr/bin/env lua
2 2
3--[[ 3--[[
4Show that luasocket returns an error message on zero-length UDP sends, 4Show that luasocket returns an error message on zero-length UDP sends,
@@ -12,7 +12,7 @@ listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
12 12
13]] 13]]
14 14
15require"socket" 15socket = require"socket"
16 16
17s = assert(socket.udp()) 17s = assert(socket.udp())
18r = assert(socket.udp()) 18r = assert(socket.udp())
diff --git a/test/unixdgramclnt.lua b/test/unixdgramclnt.lua
new file mode 100644
index 0000000..9bd60f7
--- /dev/null
+++ b/test/unixdgramclnt.lua
@@ -0,0 +1,9 @@
1socket = require"socket"
2socket.unix = require"socket.unix"
3c = assert(socket.unix.dgram())
4print(c:bind("/tmp/bar"))
5while 1 do
6 local l = io.read("*l")
7 assert(c:sendto(l, "/tmp/foo"))
8 print(assert(c:receivefrom()))
9end
diff --git a/test/unixdgramsrvr.lua b/test/unixdgramsrvr.lua
new file mode 100644
index 0000000..4c11f55
--- /dev/null
+++ b/test/unixdgramsrvr.lua
@@ -0,0 +1,9 @@
1 socket = require"socket"
2 socket.unix = require"socket.unix"
3 u = assert(socket.unix.dgram())
4 assert(u:bind("/tmp/foo"))
5 while 1 do
6 x, r = assert(u:receivefrom())
7 print(x, r)
8 assert(u:sendto(">" .. x, r))
9 end
diff --git a/test/unixclnt.lua b/test/unixstreamclnt.lua
index 5171535..4f2e1e3 100644
--- a/test/unixclnt.lua
+++ b/test/unixstreamclnt.lua
@@ -1,6 +1,6 @@
1socket = require"socket" 1socket = require"socket"
2socket.unix = require"socket.unix" 2socket.unix = require"socket.unix"
3c = assert(socket.unix()) 3c = assert(socket.unix.stream())
4assert(c:connect("/tmp/foo")) 4assert(c:connect("/tmp/foo"))
5while 1 do 5while 1 do
6 local l = io.read() 6 local l = io.read()
diff --git a/test/unixsrvr.lua b/test/unixstreamsrvr.lua
index 81b9c99..0a5c644 100644
--- a/test/unixsrvr.lua
+++ b/test/unixstreamsrvr.lua
@@ -1,6 +1,6 @@
1 socket = require"socket" 1 socket = require"socket"
2 socket.unix = require"socket.unix" 2 socket.unix = require"socket.unix"
3 u = assert(socket.unix()) 3 u = assert(socket.unix.stream())
4 assert(u:bind("/tmp/foo")) 4 assert(u:bind("/tmp/foo"))
5 assert(u:listen()) 5 assert(u:listen())
6 c = assert(u:accept()) 6 c = assert(u:accept())
diff --git a/test/urltest.lua b/test/urltest.lua
index 32cb348..9a3c470 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -60,8 +60,8 @@ end
60 60
61local check_absolute_url = function(base, relative, absolute) 61local check_absolute_url = function(base, relative, absolute)
62 local res = socket.url.absolute(base, relative) 62 local res = socket.url.absolute(base, relative)
63 if res ~= absolute then 63 if res ~= absolute then
64 io.write("absolute: In test for '", relative, "' expected '", 64 io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '",
65 absolute, "' but got '", res, "'\n") 65 absolute, "' but got '", res, "'\n")
66 os.exit() 66 os.exit()
67 end 67 end
@@ -73,7 +73,7 @@ local check_parse_url = function(gaba)
73 local parsed = socket.url.parse(url) 73 local parsed = socket.url.parse(url)
74 for i, v in pairs(gaba) do 74 for i, v in pairs(gaba) do
75 if v ~= parsed[i] then 75 if v ~= parsed[i] then
76 io.write("parse: In test for '", url, "' expected ", i, " = '", 76 io.write("parse: In test for '", url, "' expected ", i, " = '",
77 v, "' but got '", tostring(parsed[i]), "'\n") 77 v, "' but got '", tostring(parsed[i]), "'\n")
78 for i,v in pairs(parsed) do print(i,v) end 78 for i,v in pairs(parsed) do print(i,v) end
79 os.exit() 79 os.exit()
@@ -81,7 +81,7 @@ local check_parse_url = function(gaba)
81 end 81 end
82 for i, v in pairs(parsed) do 82 for i, v in pairs(parsed) do
83 if v ~= gaba[i] then 83 if v ~= gaba[i] then
84 io.write("parse: In test for '", url, "' expected ", i, " = '", 84 io.write("parse: In test for '", url, "' expected ", i, " = '",
85 tostring(gaba[i]), "' but got '", v, "'\n") 85 tostring(gaba[i]), "' but got '", v, "'\n")
86 for i,v in pairs(parsed) do print(i,v) end 86 for i,v in pairs(parsed) do print(i,v) end
87 os.exit() 87 os.exit()
@@ -91,9 +91,78 @@ end
91 91
92print("testing URL parsing") 92print("testing URL parsing")
93check_parse_url{ 93check_parse_url{
94 url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment",
95 scheme = "scheme",
96 authority = "user:pass$%?#wd@host:port",
97 host = "host",
98 port = "port",
99 userinfo = "user:pass$%?#wd",
100 password = "pass$%?#wd",
101 user = "user",
102 path = "/path",
103 params = "params",
104 query = "query",
105 fragment = "fragment"
106}
107check_parse_url{
108 url = "scheme://user:pass?#wd@host:port/path;params?query#fragment",
109 scheme = "scheme",
110 authority = "user:pass?#wd@host:port",
111 host = "host",
112 port = "port",
113 userinfo = "user:pass?#wd",
114 password = "pass?#wd",
115 user = "user",
116 path = "/path",
117 params = "params",
118 query = "query",
119 fragment = "fragment"
120}
121check_parse_url{
122 url = "scheme://user:pass-wd@host:port/path;params?query#fragment",
123 scheme = "scheme",
124 authority = "user:pass-wd@host:port",
125 host = "host",
126 port = "port",
127 userinfo = "user:pass-wd",
128 password = "pass-wd",
129 user = "user",
130 path = "/path",
131 params = "params",
132 query = "query",
133 fragment = "fragment"
134}
135check_parse_url{
136 url = "scheme://user:pass#wd@host:port/path;params?query#fragment",
137 scheme = "scheme",
138 authority = "user:pass#wd@host:port",
139 host = "host",
140 port = "port",
141 userinfo = "user:pass#wd",
142 password = "pass#wd",
143 user = "user",
144 path = "/path",
145 params = "params",
146 query = "query",
147 fragment = "fragment"
148}
149check_parse_url{
150 url = "scheme://user:pass#wd@host:port/path;params?query",
151 scheme = "scheme",
152 authority = "user:pass#wd@host:port",
153 host = "host",
154 port = "port",
155 userinfo = "user:pass#wd",
156 password = "pass#wd",
157 user = "user",
158 path = "/path",
159 params = "params",
160 query = "query",
161}
162check_parse_url{
94 url = "scheme://userinfo@host:port/path;params?query#fragment", 163 url = "scheme://userinfo@host:port/path;params?query#fragment",
95 scheme = "scheme", 164 scheme = "scheme",
96 authority = "userinfo@host:port", 165 authority = "userinfo@host:port",
97 host = "host", 166 host = "host",
98 port = "port", 167 port = "port",
99 userinfo = "userinfo", 168 userinfo = "userinfo",
@@ -106,8 +175,8 @@ check_parse_url{
106 175
107check_parse_url{ 176check_parse_url{
108 url = "scheme://user:password@host:port/path;params?query#fragment", 177 url = "scheme://user:password@host:port/path;params?query#fragment",
109 scheme = "scheme", 178 scheme = "scheme",
110 authority = "user:password@host:port", 179 authority = "user:password@host:port",
111 host = "host", 180 host = "host",
112 port = "port", 181 port = "port",
113 userinfo = "user:password", 182 userinfo = "user:password",
@@ -121,8 +190,8 @@ check_parse_url{
121 190
122check_parse_url{ 191check_parse_url{
123 url = "scheme://userinfo@host:port/path;params?query#", 192 url = "scheme://userinfo@host:port/path;params?query#",
124 scheme = "scheme", 193 scheme = "scheme",
125 authority = "userinfo@host:port", 194 authority = "userinfo@host:port",
126 host = "host", 195 host = "host",
127 port = "port", 196 port = "port",
128 userinfo = "userinfo", 197 userinfo = "userinfo",
@@ -135,8 +204,8 @@ check_parse_url{
135 204
136check_parse_url{ 205check_parse_url{
137 url = "scheme://userinfo@host:port/path;params?#fragment", 206 url = "scheme://userinfo@host:port/path;params?#fragment",
138 scheme = "scheme", 207 scheme = "scheme",
139 authority = "userinfo@host:port", 208 authority = "userinfo@host:port",
140 host = "host", 209 host = "host",
141 port = "port", 210 port = "port",
142 userinfo = "userinfo", 211 userinfo = "userinfo",
@@ -149,8 +218,8 @@ check_parse_url{
149 218
150check_parse_url{ 219check_parse_url{
151 url = "scheme://userinfo@host:port/path;params#fragment", 220 url = "scheme://userinfo@host:port/path;params#fragment",
152 scheme = "scheme", 221 scheme = "scheme",
153 authority = "userinfo@host:port", 222 authority = "userinfo@host:port",
154 host = "host", 223 host = "host",
155 port = "port", 224 port = "port",
156 userinfo = "userinfo", 225 userinfo = "userinfo",
@@ -162,8 +231,8 @@ check_parse_url{
162 231
163check_parse_url{ 232check_parse_url{
164 url = "scheme://userinfo@host:port/path;?query#fragment", 233 url = "scheme://userinfo@host:port/path;?query#fragment",
165 scheme = "scheme", 234 scheme = "scheme",
166 authority = "userinfo@host:port", 235 authority = "userinfo@host:port",
167 host = "host", 236 host = "host",
168 port = "port", 237 port = "port",
169 userinfo = "userinfo", 238 userinfo = "userinfo",
@@ -176,8 +245,8 @@ check_parse_url{
176 245
177check_parse_url{ 246check_parse_url{
178 url = "scheme://userinfo@host:port/path?query#fragment", 247 url = "scheme://userinfo@host:port/path?query#fragment",
179 scheme = "scheme", 248 scheme = "scheme",
180 authority = "userinfo@host:port", 249 authority = "userinfo@host:port",
181 host = "host", 250 host = "host",
182 port = "port", 251 port = "port",
183 userinfo = "userinfo", 252 userinfo = "userinfo",
@@ -189,8 +258,8 @@ check_parse_url{
189 258
190check_parse_url{ 259check_parse_url{
191 url = "scheme://userinfo@host:port/;params?query#fragment", 260 url = "scheme://userinfo@host:port/;params?query#fragment",
192 scheme = "scheme", 261 scheme = "scheme",
193 authority = "userinfo@host:port", 262 authority = "userinfo@host:port",
194 host = "host", 263 host = "host",
195 port = "port", 264 port = "port",
196 userinfo = "userinfo", 265 userinfo = "userinfo",
@@ -203,8 +272,8 @@ check_parse_url{
203 272
204check_parse_url{ 273check_parse_url{
205 url = "scheme://userinfo@host:port", 274 url = "scheme://userinfo@host:port",
206 scheme = "scheme", 275 scheme = "scheme",
207 authority = "userinfo@host:port", 276 authority = "userinfo@host:port",
208 host = "host", 277 host = "host",
209 port = "port", 278 port = "port",
210 userinfo = "userinfo", 279 userinfo = "userinfo",
@@ -213,7 +282,7 @@ check_parse_url{
213 282
214check_parse_url{ 283check_parse_url{
215 url = "//userinfo@host:port/path;params?query#fragment", 284 url = "//userinfo@host:port/path;params?query#fragment",
216 authority = "userinfo@host:port", 285 authority = "userinfo@host:port",
217 host = "host", 286 host = "host",
218 port = "port", 287 port = "port",
219 userinfo = "userinfo", 288 userinfo = "userinfo",
@@ -226,7 +295,7 @@ check_parse_url{
226 295
227check_parse_url{ 296check_parse_url{
228 url = "//userinfo@host:port/path", 297 url = "//userinfo@host:port/path",
229 authority = "userinfo@host:port", 298 authority = "userinfo@host:port",
230 host = "host", 299 host = "host",
231 port = "port", 300 port = "port",
232 userinfo = "userinfo", 301 userinfo = "userinfo",
@@ -236,7 +305,7 @@ check_parse_url{
236 305
237check_parse_url{ 306check_parse_url{
238 url = "//userinfo@host/path", 307 url = "//userinfo@host/path",
239 authority = "userinfo@host", 308 authority = "userinfo@host",
240 host = "host", 309 host = "host",
241 userinfo = "userinfo", 310 userinfo = "userinfo",
242 user = "userinfo", 311 user = "userinfo",
@@ -245,7 +314,7 @@ check_parse_url{
245 314
246check_parse_url{ 315check_parse_url{
247 url = "//user:password@host/path", 316 url = "//user:password@host/path",
248 authority = "user:password@host", 317 authority = "user:password@host",
249 host = "host", 318 host = "host",
250 userinfo = "user:password", 319 userinfo = "user:password",
251 password = "password", 320 password = "password",
@@ -255,7 +324,7 @@ check_parse_url{
255 324
256check_parse_url{ 325check_parse_url{
257 url = "//user:@host/path", 326 url = "//user:@host/path",
258 authority = "user:@host", 327 authority = "user:@host",
259 host = "host", 328 host = "host",
260 userinfo = "user:", 329 userinfo = "user:",
261 password = "", 330 password = "",
@@ -265,7 +334,7 @@ check_parse_url{
265 334
266check_parse_url{ 335check_parse_url{
267 url = "//user@host:port/path", 336 url = "//user@host:port/path",
268 authority = "user@host:port", 337 authority = "user@host:port",
269 host = "host", 338 host = "host",
270 userinfo = "user", 339 userinfo = "user",
271 user = "user", 340 user = "user",
@@ -275,7 +344,7 @@ check_parse_url{
275 344
276check_parse_url{ 345check_parse_url{
277 url = "//host:port/path", 346 url = "//host:port/path",
278 authority = "host:port", 347 authority = "host:port",
279 port = "port", 348 port = "port",
280 host = "host", 349 host = "host",
281 path = "/path", 350 path = "/path",
@@ -283,14 +352,14 @@ check_parse_url{
283 352
284check_parse_url{ 353check_parse_url{
285 url = "//host/path", 354 url = "//host/path",
286 authority = "host", 355 authority = "host",
287 host = "host", 356 host = "host",
288 path = "/path", 357 path = "/path",
289} 358}
290 359
291check_parse_url{ 360check_parse_url{
292 url = "//host", 361 url = "//host",
293 authority = "host", 362 authority = "host",
294 host = "host", 363 host = "host",
295} 364}
296 365
@@ -364,7 +433,7 @@ check_parse_url{
364 433
365check_parse_url{ 434check_parse_url{
366 url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", 435 url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment",
367 authority = "userinfo@[::FFFF:129.144.52.38]:port", 436 authority = "userinfo@[::FFFF:129.144.52.38]:port",
368 host = "::FFFF:129.144.52.38", 437 host = "::FFFF:129.144.52.38",
369 port = "port", 438 port = "port",
370 userinfo = "userinfo", 439 userinfo = "userinfo",
@@ -378,7 +447,7 @@ check_parse_url{
378check_parse_url{ 447check_parse_url{
379 url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", 448 url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment",
380 scheme = "scheme", 449 scheme = "scheme",
381 authority = "user:password@[::192.9.5.5]:port", 450 authority = "user:password@[::192.9.5.5]:port",
382 host = "::192.9.5.5", 451 host = "::192.9.5.5",
383 port = "port", 452 port = "port",
384 userinfo = "user:password", 453 userinfo = "user:password",
@@ -393,7 +462,7 @@ check_parse_url{
393print("testing URL building") 462print("testing URL building")
394check_build_url { 463check_build_url {
395 url = "scheme://user:password@host:port/path;params?query#fragment", 464 url = "scheme://user:password@host:port/path;params?query#fragment",
396 scheme = "scheme", 465 scheme = "scheme",
397 host = "host", 466 host = "host",
398 port = "port", 467 port = "port",
399 user = "user", 468 user = "user",
@@ -430,7 +499,7 @@ check_build_url{
430 499
431check_build_url { 500check_build_url {
432 url = "scheme://user:password@host/path;params?query#fragment", 501 url = "scheme://user:password@host/path;params?query#fragment",
433 scheme = "scheme", 502 scheme = "scheme",
434 host = "host", 503 host = "host",
435 user = "user", 504 user = "user",
436 password = "password", 505 password = "password",
@@ -442,7 +511,7 @@ check_build_url {
442 511
443check_build_url { 512check_build_url {
444 url = "scheme://user@host/path;params?query#fragment", 513 url = "scheme://user@host/path;params?query#fragment",
445 scheme = "scheme", 514 scheme = "scheme",
446 host = "host", 515 host = "host",
447 user = "user", 516 user = "user",
448 path = "/path", 517 path = "/path",
@@ -453,7 +522,7 @@ check_build_url {
453 522
454check_build_url { 523check_build_url {
455 url = "scheme://host/path;params?query#fragment", 524 url = "scheme://host/path;params?query#fragment",
456 scheme = "scheme", 525 scheme = "scheme",
457 host = "host", 526 host = "host",
458 path = "/path", 527 path = "/path",
459 params = "params", 528 params = "params",
@@ -463,7 +532,7 @@ check_build_url {
463 532
464check_build_url { 533check_build_url {
465 url = "scheme://host/path;params#fragment", 534 url = "scheme://host/path;params#fragment",
466 scheme = "scheme", 535 scheme = "scheme",
467 host = "host", 536 host = "host",
468 path = "/path", 537 path = "/path",
469 params = "params", 538 params = "params",
@@ -472,7 +541,7 @@ check_build_url {
472 541
473check_build_url { 542check_build_url {
474 url = "scheme://host/path#fragment", 543 url = "scheme://host/path#fragment",
475 scheme = "scheme", 544 scheme = "scheme",
476 host = "host", 545 host = "host",
477 path = "/path", 546 path = "/path",
478 fragment = "fragment" 547 fragment = "fragment"
@@ -480,7 +549,7 @@ check_build_url {
480 549
481check_build_url { 550check_build_url {
482 url = "scheme://host/path", 551 url = "scheme://host/path",
483 scheme = "scheme", 552 scheme = "scheme",
484 host = "host", 553 host = "host",
485 path = "/path", 554 path = "/path",
486} 555}
@@ -498,7 +567,7 @@ check_build_url {
498 567
499check_build_url { 568check_build_url {
500 url = "scheme://user:password@host:port/path;params?query#fragment", 569 url = "scheme://user:password@host:port/path;params?query#fragment",
501 scheme = "scheme", 570 scheme = "scheme",
502 host = "host", 571 host = "host",
503 port = "port", 572 port = "port",
504 user = "user", 573 user = "user",
@@ -512,7 +581,7 @@ check_build_url {
512 581
513check_build_url { 582check_build_url {
514 url = "scheme://user:password@host:port/path;params?query#fragment", 583 url = "scheme://user:password@host:port/path;params?query#fragment",
515 scheme = "scheme", 584 scheme = "scheme",
516 host = "host", 585 host = "host",
517 port = "port", 586 port = "port",
518 user = "user", 587 user = "user",
@@ -527,7 +596,7 @@ check_build_url {
527 596
528check_build_url { 597check_build_url {
529 url = "scheme://user:password@host:port/path;params?query#fragment", 598 url = "scheme://user:password@host:port/path;params?query#fragment",
530 scheme = "scheme", 599 scheme = "scheme",
531 host = "host", 600 host = "host",
532 port = "port", 601 port = "port",
533 userinfo = "user:password", 602 userinfo = "user:password",
@@ -540,7 +609,7 @@ check_build_url {
540 609
541check_build_url { 610check_build_url {
542 url = "scheme://user:password@host:port/path;params?query#fragment", 611 url = "scheme://user:password@host:port/path;params?query#fragment",
543 scheme = "scheme", 612 scheme = "scheme",
544 authority = "user:password@host:port", 613 authority = "user:password@host:port",
545 path = "/path", 614 path = "/path",
546 params = "params", 615 params = "params",
@@ -558,25 +627,37 @@ check_absolute_url("http://a/b/c/d;p?q#f", "/g", "http://a/g")
558check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g") 627check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g")
559check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y") 628check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y")
560check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y") 629check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y")
561check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x") 630check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/x")
562check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s") 631check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s")
563check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s") 632check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s")
564check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x") 633check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/x")
565check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s") 634check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s")
566check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x") 635check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x")
567check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x") 636check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x")
568check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s") 637check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s")
569check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/") 638check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/")
570check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/") 639check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/")
640check_absolute_url("http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g")
641check_absolute_url("http://a/b/c/d;p?q#f", "./g/", "http://a/b/c/g/")
642check_absolute_url("http://a/b/c/d;p?q#f", "././g", "http://a/b/c/g")
643check_absolute_url("http://a/b/c/d;p?q#f", "././g/", "http://a/b/c/g/")
644check_absolute_url("http://a/b/c/d;p?q#f", "g/.", "http://a/b/c/g/")
645check_absolute_url("http://a/b/c/d;p?q#f", "g/./", "http://a/b/c/g/")
646check_absolute_url("http://a/b/c/d;p?q#f", "g/./.", "http://a/b/c/g/")
647check_absolute_url("http://a/b/c/d;p?q#f", "g/././", "http://a/b/c/g/")
648check_absolute_url("http://a/b/c/d;p?q#f", "./.", "http://a/b/c/")
649check_absolute_url("http://a/b/c/d;p?q#f", "././.", "http://a/b/c/")
650check_absolute_url("http://a/b/c/d;p?q#f", "././g/./.", "http://a/b/c/g/")
571check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/") 651check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/")
572check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/") 652check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/")
573check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g") 653check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g")
574check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") 654check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/")
575check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") 655check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/")
576check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") 656check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g")
657check_absolute_url("http://a/b/c/d;p?q#f", "../../../g", "http://a/g")
577check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") 658check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f")
578check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/./g") 659check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g")
579check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/../g") 660check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/g")
580check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.") 661check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.")
581check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g") 662check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g")
582check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..") 663check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..")
@@ -586,31 +667,53 @@ check_absolute_url("http://a/b/c/d;p?q#f", "./g/.", "http://a/b/c/g/")
586check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h") 667check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h")
587check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h") 668check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h")
588 669
670check_absolute_url("http://a/b/c/d:p?q#f/", "../g/", "http://a/b/g/")
671check_absolute_url("http://a/b/c/d:p?q#f/", "../g", "http://a/b/g")
672check_absolute_url("http://a/b/c/d:p?q#f/", "../.g/", "http://a/b/.g/")
673check_absolute_url("http://a/b/c/d:p?q#f/", "../.g", "http://a/b/.g")
674check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h/", "http://a/b/.g.h/")
675check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h", "http://a/b/.g.h")
676
677check_absolute_url("http://a/b/c/d:p?q#f/", "g.h/", "http://a/b/c/g.h/")
678check_absolute_url("http://a/b/c/d:p?q#f/", "../g.h/", "http://a/b/g.h/")
679check_absolute_url("http://a/", "../g.h/", "http://a/g.h/")
680
589-- extra tests 681-- extra tests
590check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") 682check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f")
591check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") 683check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f")
592check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") 684check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f")
593check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") 685check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f")
594check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", 686check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html",
595 "http://velox.telemar.com.br/dashboard/index.html") 687 "http://velox.telemar.com.br/dashboard/index.html")
688check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/")
689check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/")
690check_absolute_url("http://example.com/a/b/c/d/", "../q", "http://example.com/a/b/c/q")
691check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com/a/b/q")
692check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q")
693check_absolute_url("http://example.com", ".badhost.com", "http://example.com/.badhost.com")
694check_absolute_url("http://example.com/a/b/c/d/", "..//../../../q", "http://example.com/a/q")
695check_absolute_url("http://example.com/a/b/c/d/", "..//a/../../../../q", "http://example.com/a/q")
696check_absolute_url("http://example.com/a/b/c/d/", "..//a/..//../../../q", "http://example.com/a/b/q")
697check_absolute_url("http://example.com/a/b/c/d/", "..//a/..///../../../../q", "http://example.com/a/b/q")
698check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", "http://example.com/a/b/q")
596 699
597print("testing path parsing and composition") 700print("testing path parsing and composition")
598check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) 701check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })
599check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) 702check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 })
600check_parse_path("eu/tu/ele/nos/vos/eles/", 703check_parse_path("eu/tu/ele/nos/vos/eles/",
601 { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) 704 { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1})
602check_parse_path("/", { is_absolute = 1, is_directory = 1}) 705check_parse_path("/", { is_absolute = 1, is_directory = 1})
603check_parse_path("", { }) 706check_parse_path("", { })
604check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", 707check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/",
605 { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) 708 { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1})
606check_parse_path("eu/tu", { "eu", "tu" }) 709check_parse_path("eu/tu", { "eu", "tu" })
607 710
608print("testing path protection") 711print("testing path protection")
609check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") 712check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu")
610check_protect({ "eu ", "~diego" }, "eu%20/~diego") 713check_protect({ "eu ", "~diego" }, "eu%20/~diego")
611check_protect({ "/eu>", "<diego?" }, "%2feu%3e/%3cdiego%3f") 714check_protect({ "/eu>", "<diego?" }, "%2Feu%3E/%3Cdiego%3F")
612check_protect({ "\\eu]", "[diego`" }, "%5ceu%5d/%5bdiego%60") 715check_protect({ "\\eu]", "[diego`" }, "%5Ceu%5D/%5Bdiego%60")
613check_protect({ "{eu}", "|diego\127" }, "%7beu%7d/%7cdiego%7f") 716check_protect({ "{eu}", "|diego\127" }, "%7Beu%7D/%7Cdiego%7F")
614check_protect({ "eu ", "~diego" }, "eu /~diego", 1) 717check_protect({ "eu ", "~diego" }, "eu /~diego", 1)
615check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1) 718check_protect({ "/eu>", "<diego?" }, "/eu>/<diego?", 1)
616check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1) 719check_protect({ "\\eu]", "[diego`" }, "\\eu]/[diego`", 1)
diff --git a/test/utestclnt.lua b/test/utestclnt.lua
index 34a0718..7f10643 100644
--- a/test/utestclnt.lua
+++ b/test/utestclnt.lua
@@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone)
54 if not err then warn("must be buffered") 54 if not err then warn("must be buffered")
55 elseif err == "timeout" then pass("proper timeout") 55 elseif err == "timeout" then pass("proper timeout")
56 else fail("unexpected error '%s'", err) end 56 else fail("unexpected error '%s'", err) end
57 else 57 else
58 if err ~= "timeout" then fail("should have timed out") 58 if err ~= "timeout" then fail("should have timed out")
59 else pass("proper timeout") end 59 else pass("proper timeout") end
60 end 60 end
61 else 61 else
62 if mode == "total" then 62 if mode == "total" then
63 if elapsed > tm then 63 if elapsed > tm then
64 if err ~= "timeout" then fail("should have timed out") 64 if err ~= "timeout" then fail("should have timed out")
65 else pass("proper timeout") end 65 else pass("proper timeout") end
66 elseif elapsed < tm then 66 elseif elapsed < tm then
67 if err then fail(err) 67 if err then fail(err)
68 else pass("ok") end 68 else pass("ok") end
69 else 69 else
70 if alldone then 70 if alldone then
71 if err then fail("unexpected error '%s'", err) 71 if err then fail("unexpected error '%s'", err)
72 else pass("ok") end 72 else pass("ok") end
73 else 73 else
74 if err ~= "timeout" then fail(err) 74 if err ~= "timeout" then fail(err)
75 else pass("proper timeoutk") end 75 else pass("proper timeoutk") end
76 end 76 end
77 end 77 end
78 else 78 else
79 if err then fail(err) 79 if err then fail(err)
80 else pass("ok") end 80 else pass("ok") end
81 end 81 end
82 end 82 end
83end 83end
@@ -104,7 +104,7 @@ function reconnect()
104 print("done " .. i) 104 print("done " .. i)
105 ]] 105 ]]
106 data, err = uconnect(host, port) 106 data, err = uconnect(host, port)
107 if not data then fail(err) 107 if not data then fail(err)
108 else pass("connected!") end 108 else pass("connected!") end
109end 109end
110 110
@@ -116,8 +116,8 @@ else pass("connected!") end
116------------------------------------------------------------------------ 116------------------------------------------------------------------------
117function test_methods(sock, methods) 117function test_methods(sock, methods)
118 for _, v in pairs(methods) do 118 for _, v in pairs(methods) do
119 if type(sock[v]) ~= "function" then 119 if type(sock[v]) ~= "function" then
120 fail(sock.class .. " method '" .. v .. "' not registered") 120 fail(sock.class .. " method '" .. v .. "' not registered")
121 end 121 end
122 end 122 end
123 pass(sock.class .. " methods are ok") 123 pass(sock.class .. " methods are ok")
@@ -132,7 +132,7 @@ function test_mixed(len)
132 local p3 = "raw " .. string.rep("z", inter) .. "bytes" 132 local p3 = "raw " .. string.rep("z", inter) .. "bytes"
133 local p4 = "end" .. string.rep("w", inter) .. "bytes" 133 local p4 = "end" .. string.rep("w", inter) .. "bytes"
134 local bp1, bp2, bp3, bp4 134 local bp1, bp2, bp3, bp4
135remote (string.format("str = data:receive(%d)", 135remote (string.format("str = data:receive(%d)",
136 string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) 136 string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4)))
137 sent, err = data:send(p1..p2..p3..p4) 137 sent, err = data:send(p1..p2..p3..p4)
138 if err then fail(err) end 138 if err then fail(err) end
@@ -172,7 +172,7 @@ function test_rawline(len)
172 reconnect() 172 reconnect()
173 local str, str10, back, err 173 local str, str10, back, err
174 str = string.rep(string.char(47), math.mod(len, 10)) 174 str = string.rep(string.char(47), math.mod(len, 10))
175 str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), 175 str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100),
176 math.floor(len/10)) 176 math.floor(len/10))
177 str = str .. str10 177 str = str .. str10
178remote "str = data:receive()" 178remote "str = data:receive()"
@@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl)
221 data:settimeout(tm, "total") 221 data:settimeout(tm, "total")
222local t = socket.gettime() 222local t = socket.gettime()
223 str, err, partial, elapsed = data:receive(2*len) 223 str, err, partial, elapsed = data:receive(2*len)
224 check_timeout(tm, sl, elapsed, err, "receive", "total", 224 check_timeout(tm, sl, elapsed, err, "receive", "total",
225 string.len(str or partial) == 2*len) 225 string.len(str or partial) == 2*len)
226end 226end
227 227
@@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl)
241 data:settimeout(tm, "total") 241 data:settimeout(tm, "total")
242 str = string.rep("a", 2*len) 242 str = string.rep("a", 2*len)
243 total, err, partial, elapsed = data:send(str) 243 total, err, partial, elapsed = data:send(str)
244 check_timeout(tm, sl, elapsed, err, "send", "total", 244 check_timeout(tm, sl, elapsed, err, "send", "total",
245 total == 2*len) 245 total == 2*len)
246end 246end
247 247
@@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl)
261 ]], 2*tm, len, sl, sl)) 261 ]], 2*tm, len, sl, sl))
262 data:settimeout(tm) 262 data:settimeout(tm)
263 str, err, partial, elapsed = data:receive(2*len) 263 str, err, partial, elapsed = data:receive(2*len)
264 check_timeout(tm, sl, elapsed, err, "receive", "blocking", 264 check_timeout(tm, sl, elapsed, err, "receive", "blocking",
265 string.len(str or partial) == 2*len) 265 string.len(str or partial) == 2*len)
266end 266end
267 267
@@ -294,10 +294,10 @@ function empty_connect()
294 data = server:accept() 294 data = server:accept()
295 ]] 295 ]]
296 data, err = socket.connect("", port) 296 data, err = socket.connect("", port)
297 if not data then 297 if not data then
298 pass("ok") 298 pass("ok")
299 data = socket.connect(host, port) 299 data = socket.connect(host, port)
300 else 300 else
301 pass("gethostbyname returns localhost on empty string...") 301 pass("gethostbyname returns localhost on empty string...")
302 end 302 end
303end 303end
@@ -331,7 +331,7 @@ function test_closed()
331 data:close() 331 data:close()
332 data = nil 332 data = nil
333 ]], str)) 333 ]], str))
334 -- try to get a line 334 -- try to get a line
335 back, err, partial = data:receive() 335 back, err, partial = data:receive()
336 if not err then fail("should have gotten 'closed'.") 336 if not err then fail("should have gotten 'closed'.")
337 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") 337 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
@@ -344,25 +344,25 @@ function test_closed()
344 data = nil 344 data = nil
345 ]] 345 ]]
346 total, err, partial = data:send(string.rep("ugauga", 100000)) 346 total, err, partial = data:send(string.rep("ugauga", 100000))
347 if not err then 347 if not err then
348 pass("failed: output buffer is at least %d bytes long!", total) 348 pass("failed: output buffer is at least %d bytes long!", total)
349 elseif err ~= "closed" then 349 elseif err ~= "closed" then
350 fail("got '"..err.."' instead of 'closed'.") 350 fail("got '"..err.."' instead of 'closed'.")
351 else 351 else
352 pass("graceful 'closed' received after %d bytes were sent", partial) 352 pass("graceful 'closed' received after %d bytes were sent", partial)
353 end 353 end
354end 354end
355 355
356------------------------------------------------------------------------ 356------------------------------------------------------------------------
357function test_selectbugs() 357function test_selectbugs()
358 local r, s, e = socket.select(nil, nil, 0.1) 358 local r, s, e = socket.select(nil, nil, 0.1)
359 assert(type(r) == "table" and type(s) == "table" and 359 assert(type(r) == "table" and type(s) == "table" and
360 (e == "timeout" or e == "error")) 360 (e == "timeout" or e == "error"))
361 pass("both nil: ok") 361 pass("both nil: ok")
362 local udp = socket.udp() 362 local udp = socket.udp()
363 udp:close() 363 udp:close()
364 r, s, e = socket.select({ udp }, { udp }, 0.1) 364 r, s, e = socket.select({ udp }, { udp }, 0.1)
365 assert(type(r) == "table" and type(s) == "table" and 365 assert(type(r) == "table" and type(s) == "table" and
366 (e == "timeout" or e == "error")) 366 (e == "timeout" or e == "error"))
367 pass("closed sockets: ok") 367 pass("closed sockets: ok")
368 e = pcall(socket.select, "wrong", 1, 0.1) 368 e = pcall(socket.select, "wrong", 1, 0.1)
@@ -380,7 +380,7 @@ function accept_timeout()
380 local t = socket.gettime() 380 local t = socket.gettime()
381 s:settimeout(1) 381 s:settimeout(1)
382 local c, e = s:accept() 382 local c, e = s:accept()
383 assert(not c, "should not accept") 383 assert(not c, "should not accept")
384 assert(e == "timeout", string.format("wrong error message (%s)", e)) 384 assert(e == "timeout", string.format("wrong error message (%s)", e))
385 t = socket.gettime() - t 385 t = socket.gettime() - t
386 assert(t < 2, string.format("took to long to give up (%gs)", t)) 386 assert(t < 2, string.format("took to long to give up (%gs)", t))
@@ -398,9 +398,9 @@ function connect_timeout()
398 local t = socket.gettime() 398 local t = socket.gettime()
399 local r, e = c:connect("127.0.0.2", 80) 399 local r, e = c:connect("127.0.0.2", 80)
400 assert(not r, "should not connect") 400 assert(not r, "should not connect")
401 assert(socket.gettime() - t < 2, "took too long to give up.") 401 assert(socket.gettime() - t < 2, "took too long to give up.")
402 c:close() 402 c:close()
403 print("ok") 403 print("ok")
404end 404end
405 405
406------------------------------------------------------------------------ 406------------------------------------------------------------------------
@@ -463,9 +463,9 @@ function getstats_test()
463 data:receive(c) 463 data:receive(c)
464 t = t + c 464 t = t + c
465 local r, s, a = data:getstats() 465 local r, s, a = data:getstats()
466 assert(r == t, "received count failed" .. tostring(r) 466 assert(r == t, "received count failed" .. tostring(r)
467 .. "/" .. tostring(t)) 467 .. "/" .. tostring(t))
468 assert(s == t, "sent count failed" .. tostring(s) 468 assert(s == t, "sent count failed" .. tostring(s)
469 .. "/" .. tostring(t)) 469 .. "/" .. tostring(t))
470 end 470 end
471 print("ok") 471 print("ok")
@@ -473,7 +473,7 @@ end
473 473
474 474
475------------------------------------------------------------------------ 475------------------------------------------------------------------------
476function test_nonblocking(size) 476function test_nonblocking(size)
477 reconnect() 477 reconnect()
478print("Testing " .. 2*size .. " bytes") 478print("Testing " .. 2*size .. " bytes")
479remote(string.format([[ 479remote(string.format([[
diff --git a/test/utestsrvr.lua b/test/utestsrvr.lua
index a96b570..b6e4246 100644
--- a/test/utestsrvr.lua
+++ b/test/utestsrvr.lua
@@ -9,7 +9,7 @@ ack = "\n";
9while 1 do 9while 1 do
10 print("server: waiting for client connection..."); 10 print("server: waiting for client connection...");
11 control = assert(server:accept()); 11 control = assert(server:accept());
12 while 1 do 12 while 1 do
13 command = assert(control:receive()); 13 command = assert(control:receive());
14 assert(control:send(ack)); 14 assert(control:send(ack));
15 ((loadstring or load)(command))(); 15 ((loadstring or load)(command))();