diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:59 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-01-25 21:59:59 +0000 |
commit | 2bb209ab9eb746fdfb9b8f5c83eee12b40fc211e (patch) | |
tree | e905c6ad0c4112371ae30d2c608368c8dfe65e6e | |
parent | 7096b8df82eebfe857e0043bc8a853353bd78480 (diff) | |
download | luasocket-2bb209ab9eb746fdfb9b8f5c83eee12b40fc211e.tar.gz luasocket-2bb209ab9eb746fdfb9b8f5c83eee12b40fc211e.tar.bz2 luasocket-2bb209ab9eb746fdfb9b8f5c83eee12b40fc211e.zip |
Updated for LuaSocket 1.2.
More tests added.
-rw-r--r-- | test/testclnt.lua | 787 |
1 files changed, 428 insertions, 359 deletions
diff --git a/test/testclnt.lua b/test/testclnt.lua index c1c22bd..8a36512 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua | |||
@@ -1,359 +1,428 @@ | |||
1 | ----------------------------------------------------------------------------- | 1 | ----------------------------------------------------------------------------- |
2 | -- LuaSocket automated test module | 2 | -- LuaSocket automated test module |
3 | -- client.lua | 3 | -- client.lua |
4 | -- This is the client module. It connects with the server module and executes | 4 | -- This is the client module. It connects with the server module and executes |
5 | -- all tests. | 5 | -- all tests. |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | 7 | ||
8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
9 | -- Prints a header to separate the test phases | 9 | -- Prints a header to separate the test phases |
10 | -- Input | 10 | -- Input |
11 | -- test: test phase name | 11 | -- test: test phase name |
12 | ----------------------------------------------------------------------------- | 12 | ----------------------------------------------------------------------------- |
13 | function new_test(test) | 13 | function new_test(test) |
14 | write("----------------------------------------------\n", | 14 | write("----------------------------------------------\n", |
15 | test, "\n", | 15 | test, "\n", |
16 | "----------------------------------------------\n") | 16 | "----------------------------------------------\n") |
17 | end | 17 | end |
18 | 18 | ||
19 | ----------------------------------------------------------------------------- | 19 | ----------------------------------------------------------------------------- |
20 | -- Read command definitions and stablish control connection | 20 | -- Get host and port from command line |
21 | ----------------------------------------------------------------------------- | 21 | ----------------------------------------------------------------------------- |
22 | new_test("initializing...") | 22 | HOST = "127.0.0.1" |
23 | dofile("command.lua") | 23 | PORT = 2020 |
24 | test_debug_mode() | 24 | if arg then |
25 | while control == nil do | 25 | HOST = arg[1] or HOST |
26 | print("client: trying control connection...") | 26 | PORT = arg[2] or PORT |
27 | control, err = connect(HOST, PORT) | 27 | end |
28 | if control then | 28 | |
29 | print("client: control connection stablished!") | 29 | ----------------------------------------------------------------------------- |
30 | else | 30 | -- Read command definitions |
31 | sleep(2) | 31 | ----------------------------------------------------------------------------- |
32 | end | 32 | assert(dofile("testcmd.lua")) |
33 | end | 33 | test_debug_mode() |
34 | 34 | ||
35 | ----------------------------------------------------------------------------- | 35 | ----------------------------------------------------------------------------- |
36 | -- Make sure server is ready for data transmission | 36 | -- Start control connection |
37 | ----------------------------------------------------------------------------- | 37 | ----------------------------------------------------------------------------- |
38 | function sync() | 38 | new_test("initializing...") |
39 | send_command(SYNC) | 39 | while control == nil do |
40 | get_command() | 40 | print("client: trying control connection...") |
41 | end | 41 | control, err = connect(HOST, PORT) |
42 | 42 | if control then | |
43 | ----------------------------------------------------------------------------- | 43 | print("client: control connection stablished!") |
44 | -- Close and reopen data connection, to get rid of any unread blocks | 44 | else |
45 | ----------------------------------------------------------------------------- | 45 | sleep(2) |
46 | function reconnect() | 46 | end |
47 | if data then | 47 | end |
48 | data:close() | 48 | |
49 | send_command(CLOSE) | 49 | ----------------------------------------------------------------------------- |
50 | data = nil | 50 | -- Make sure server is ready for data transmission |
51 | end | 51 | ----------------------------------------------------------------------------- |
52 | while data == nil do | 52 | function sync() |
53 | send_command(CONNECT) | 53 | send_command(SYNC) |
54 | data = connect(HOST, PORT) | 54 | get_command() |
55 | if not data then | 55 | end |
56 | print("client: waiting for data connection.") | 56 | |
57 | sleep(1) | 57 | ----------------------------------------------------------------------------- |
58 | end | 58 | -- Close and reopen data connection, to get rid of any unread blocks |
59 | end | 59 | ----------------------------------------------------------------------------- |
60 | sync() | 60 | function reconnect() |
61 | end | 61 | if data then |
62 | 62 | close(data) | |
63 | ----------------------------------------------------------------------------- | 63 | send_command(CLOSE) |
64 | -- Tests the command connection | 64 | data = nil |
65 | ----------------------------------------------------------------------------- | 65 | end |
66 | function test_command(cmd, par) | 66 | while data == nil do |
67 | local cmd_back, par_back | 67 | send_command(CONNECT) |
68 | reconnect() | 68 | data = connect(HOST, PORT) |
69 | send_command(COMMAND) | 69 | if not data then |
70 | write("testing command ") | 70 | print("client: waiting for data connection.") |
71 | print_command(cmd, par) | 71 | sleep(1) |
72 | send_command(cmd, par) | 72 | end |
73 | cmd_back, par_back = get_command() | 73 | end |
74 | if cmd_back ~= cmd or par_back ~= par then | 74 | sync() |
75 | fail(cmd) | 75 | end |
76 | else | 76 | |
77 | pass() | 77 | ----------------------------------------------------------------------------- |
78 | end | 78 | -- Tests the command connection |
79 | end | 79 | ----------------------------------------------------------------------------- |
80 | 80 | function test_command(cmd, par) | |
81 | ----------------------------------------------------------------------------- | 81 | local cmd_back, par_back |
82 | -- Tests ASCII line transmission | 82 | reconnect() |
83 | -- Input | 83 | send_command(COMMAND) |
84 | -- len: length of line to be tested | 84 | write("testing command ") |
85 | ----------------------------------------------------------------------------- | 85 | print_command(cmd, par) |
86 | function test_asciiline(len) | 86 | send_command(cmd, par) |
87 | local str, str10, back, err | 87 | cmd_back, par_back = get_command() |
88 | reconnect() | 88 | if cmd_back ~= cmd or par_back ~= par then |
89 | send_command(ECHO_LINE) | 89 | fail(cmd) |
90 | str = strrep("x", mod(len, 10)) | 90 | else |
91 | str10 = strrep("aZb.c#dAe?", floor(len/10)) | 91 | pass() |
92 | str = str .. str10 | 92 | end |
93 | write("testing ", len, " byte(s) line\n") | 93 | end |
94 | err = data:send(str, "\n") | 94 | |
95 | if err then fail(err) end | 95 | ----------------------------------------------------------------------------- |
96 | back, err = data:receive() | 96 | -- Tests ASCII line transmission |
97 | if err then fail(err) end | 97 | -- Input |
98 | if back == str then pass("lines match") | 98 | -- len: length of line to be tested |
99 | else fail("lines don't match") end | 99 | ----------------------------------------------------------------------------- |
100 | end | 100 | function test_asciiline(len) |
101 | 101 | local str, str10, back, err | |
102 | ----------------------------------------------------------------------------- | 102 | reconnect() |
103 | -- Tests closed connection detection | 103 | send_command(ECHO_LINE) |
104 | ----------------------------------------------------------------------------- | 104 | str = strrep("x", mod(len, 10)) |
105 | function test_closed() | 105 | str10 = strrep("aZb.c#dAe?", floor(len/10)) |
106 | local str = "This is our little test line" | 106 | str = str .. str10 |
107 | local len = strlen(str) | 107 | write("testing ", len, " byte(s) line\n") |
108 | local back, err, total | 108 | err = send(data, str, "\n") |
109 | reconnect() | 109 | if err then fail(err) end |
110 | print("testing close while reading line") | 110 | back, err = receive(data) |
111 | send_command(ECHO_BLOCK, len) | 111 | if err then fail(err) end |
112 | data:send(str) | 112 | if back == str then pass("lines match") |
113 | send_command(CLOSE) | 113 | else fail("lines don't match") end |
114 | -- try to get a line | 114 | end |
115 | back, err = data:receive() | 115 | |
116 | if not err then fail("shold have gotten 'closed'.") | 116 | ----------------------------------------------------------------------------- |
117 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") | 117 | -- Tests closed connection detection |
118 | elseif str ~= back then fail("didn't receive what i should 'closed'.") | 118 | ----------------------------------------------------------------------------- |
119 | else pass("rightfull 'closed' received") end | 119 | function test_closed() |
120 | reconnect() | 120 | local str = "This is our little test line" |
121 | print("testing close while reading block") | 121 | local len = strlen(str) |
122 | send_command(ECHO_BLOCK, len) | 122 | local back, err, total |
123 | data:send(str) | 123 | reconnect() |
124 | send_command(CLOSE) | 124 | print("testing close while reading line") |
125 | -- try to get a line | 125 | send_command(ECHO_BLOCK, len) |
126 | back, err = data:receive(2*len) | 126 | send(data, str) |
127 | if not err then fail("shold have gotten 'closed'.") | 127 | send_command(CLOSE) |
128 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") | 128 | -- try to get a line |
129 | elseif str ~= back then fail("didn't receive what I should.") | 129 | back, err = receive(data) |
130 | else pass("rightfull 'closed' received") end | 130 | if not err then fail("shold have gotten 'closed'.") |
131 | end | 131 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") |
132 | 132 | elseif str ~= back then fail("didn't receive what i should 'closed'.") | |
133 | ----------------------------------------------------------------------------- | 133 | else pass("rightfull 'closed' received") end |
134 | -- Tests binary line transmission | 134 | reconnect() |
135 | -- Input | 135 | print("testing close while reading block") |
136 | -- len: length of line to be tested | 136 | send_command(ECHO_BLOCK, len) |
137 | ----------------------------------------------------------------------------- | 137 | send(data, str) |
138 | function test_rawline(len) | 138 | send_command(CLOSE) |
139 | local str, str10, back, err | 139 | -- try to get a line |
140 | reconnect() | 140 | back, err = receive(data, 2*len) |
141 | send_command(ECHO_LINE) | 141 | if not err then fail("shold have gotten 'closed'.") |
142 | str = strrep(strchar(47), mod(len, 10)) | 142 | elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") |
143 | str10 = strrep(strchar(120,21,77,4,5,0,7,36,44,100), floor(len/10)) | 143 | elseif str ~= back then fail("didn't receive what I should.") |
144 | str = str .. str10 | 144 | else pass("rightfull 'closed' received") end |
145 | write("testing ", len, " byte(s) line\n") | 145 | end |
146 | err = data:send(str, "\n") | 146 | |
147 | if err then fail(err) end | 147 | ----------------------------------------------------------------------------- |
148 | back, err = data:receive() | 148 | -- Tests binary line transmission |
149 | if err then fail(err) end | 149 | -- Input |
150 | if back == str then pass("lines match") | 150 | -- len: length of line to be tested |
151 | else fail("lines don't match") end | 151 | ----------------------------------------------------------------------------- |
152 | end | 152 | function test_rawline(len) |
153 | 153 | local str, str10, back, err | |
154 | ----------------------------------------------------------------------------- | 154 | reconnect() |
155 | -- Tests block transmission | 155 | send_command(ECHO_LINE) |
156 | -- Input | 156 | str = strrep(strchar(47), mod(len, 10)) |
157 | -- len: length of block to be tested | 157 | str10 = strrep(strchar(120,21,77,4,5,0,7,36,44,100), floor(len/10)) |
158 | ----------------------------------------------------------------------------- | 158 | str = str .. str10 |
159 | function test_block(len) | 159 | write("testing ", len, " byte(s) line\n") |
160 | local half = floor(len/2) | 160 | err = send(data, str, "\n") |
161 | local s1, s2, back, err | 161 | if err then fail(err) end |
162 | reconnect() | 162 | back, err = receive(data) |
163 | send_command(ECHO_BLOCK, len) | 163 | if err then fail(err) end |
164 | write("testing ", len, " byte(s) block\n") | 164 | if back == str then pass("lines match") |
165 | s1 = strrep("x", half) | 165 | else fail("lines don't match") end |
166 | err = data:send(s1) | 166 | end |
167 | if err then fail(err) end | 167 | |
168 | sleep(1) | 168 | ----------------------------------------------------------------------------- |
169 | s2 = strrep("y", len-half) | 169 | -- Tests block transmission |
170 | err = data:send(s2) | 170 | -- Input |
171 | if err then fail(err) end | 171 | -- len: length of block to be tested |
172 | back, err = data:receive(len) | 172 | ----------------------------------------------------------------------------- |
173 | if err then fail(err) end | 173 | function test_block(len) |
174 | if back == s1..s2 then pass("blocks match") | 174 | local half = floor(len/2) |
175 | else fail("blocks don't match") end | 175 | local s1, s2, back, err |
176 | end | 176 | reconnect() |
177 | 177 | send_command(ECHO_BLOCK, len) | |
178 | ----------------------------------------------------------------------------- | 178 | write("testing ", len, " byte(s) block\n") |
179 | -- Tests if return-timeout was respected | 179 | s1 = strrep("x", half) |
180 | -- delta: time elapsed during transfer | 180 | err = send(data, s1) |
181 | -- t: timeout value | 181 | if err then fail(err) end |
182 | -- err: error code returned by I/O operation | 182 | s2 = strrep("y", len-half) |
183 | ----------------------------------------------------------------------------- | 183 | err = send(data, s2) |
184 | function returntimed_out(delta, t, err) | 184 | if err then fail(err) end |
185 | if err == "timeout" then | 185 | back, err = receive(data, len) |
186 | if delta + 0.1 >= t then | 186 | if err then fail(err) end |
187 | pass("got right timeout") | 187 | if back == s1..s2 then pass("blocks match") |
188 | return 1 | 188 | else fail("blocks don't match") end |
189 | else | 189 | end |
190 | fail("shouldn't have gotten timeout") | 190 | |
191 | end | 191 | ----------------------------------------------------------------------------- |
192 | elseif delta > t then | 192 | -- Tests if return-timeout was respected |
193 | fail("should have gotten timeout") | 193 | -- delta: time elapsed during transfer |
194 | end | 194 | -- t: timeout value |
195 | end | 195 | -- s: time server slept |
196 | 196 | -- err: error code returned by I/O operation | |
197 | ----------------------------------------------------------------------------- | 197 | -- o: operation being executed |
198 | -- Tests if return-timeout was respected | 198 | ----------------------------------------------------------------------------- |
199 | -- delta: time elapsed during transfer | 199 | function blockedtimed_out(t, s, err, o) |
200 | -- t: timeout value | 200 | if err == "timeout" then |
201 | -- err: error code returned by I/O operation | 201 | if s >= t then |
202 | -- o: operation being executed | 202 | pass("got rightfull forced timeout") |
203 | ----------------------------------------------------------------------------- | 203 | return 1 |
204 | function blockedtimed_out(t, s, err, o) | 204 | else |
205 | if err == "timeout" then | 205 | pass("got natural cause timeout") |
206 | if s >= t then | 206 | return 1 |
207 | pass("got right forced timeout") | 207 | end |
208 | return 1 | 208 | elseif 0.9*s > t then |
209 | else | 209 | if o == "send" then |
210 | pass("got natural cause timeout (may be wrong)") | 210 | pass("must have been buffered (may be wrong)") |
211 | return 1 | 211 | else |
212 | end | 212 | fail("should have gotten timeout") |
213 | elseif s > t then | 213 | end |
214 | if o == "send" then | 214 | end |
215 | pass("must have been buffered (may be wrong)") | 215 | end |
216 | else | 216 | |
217 | fail("should have gotten timeout") | 217 | ----------------------------------------------------------------------------- |
218 | end | 218 | -- Tests blocked-timeout conformance |
219 | end | 219 | -- Input |
220 | end | 220 | -- len: length of block to be tested |
221 | 221 | -- t: timeout value | |
222 | ----------------------------------------------------------------------------- | 222 | -- s: server sleep between transfers |
223 | -- Tests blocked-timeout conformance | 223 | ----------------------------------------------------------------------------- |
224 | -- Input | 224 | function test_blockedtimeout(len, t, s) |
225 | -- len: length of block to be tested | 225 | local str, err, back, total |
226 | -- t: timeout value | 226 | reconnect() |
227 | -- s: server sleep between transfers | 227 | send_command(RECEIVE_BLOCK, len) |
228 | ----------------------------------------------------------------------------- | 228 | send_command(SLEEP, s) |
229 | function test_blockedtimeout(len, t, s) | 229 | send_command(RECEIVE_BLOCK, len) |
230 | local str, err, back, total | 230 | write("testing ", len, " bytes, ", t, |
231 | reconnect() | 231 | "s block timeout, ", s, "s sleep\n") |
232 | send_command(RECEIVE_BLOCK, len) | 232 | timeout(data, t) |
233 | send_command(SLEEP, s) | 233 | str = strrep("a", 2*len) |
234 | send_command(RECEIVE_BLOCK, len) | 234 | err, total = send(data, str) |
235 | write("testing ", len, " bytes, ", t, | 235 | if blockedtimed_out(t, s, err, "send") then return end |
236 | "s block timeout, ", s, "s sleep\n") | 236 | if err then fail(err) end |
237 | data:timeout(t) | 237 | send_command(SEND_BLOCK) |
238 | str = strrep("a", 2*len) | 238 | send_command(SLEEP, s) |
239 | err, total = data:send(str) | 239 | send_command(SEND_BLOCK) |
240 | if blockedtimed_out(t, s, err, "send") then return end | 240 | back, err = receive(data, 2*len) |
241 | if err then fail(err) end | 241 | if blockedtimed_out(t, s, err, "receive") then return end |
242 | send_command(SEND_BLOCK) | 242 | if err then fail(err) end |
243 | send_command(SLEEP, s) | 243 | if back == str then pass("blocks match") |
244 | send_command(SEND_BLOCK) | 244 | else fail("blocks don't match") end |
245 | back, err = data:receive(2*len) | 245 | end |
246 | if blockedtimed_out(t, s, err, "receive") then return end | 246 | |
247 | if err then fail(err) end | 247 | ----------------------------------------------------------------------------- |
248 | if back == str then pass("blocks match") | 248 | -- Tests if return-timeout was respected |
249 | else fail("blocks don't match") end | 249 | -- delta: time elapsed during transfer |
250 | end | 250 | -- t: timeout value |
251 | 251 | -- err: error code returned by I/O operation | |
252 | ----------------------------------------------------------------------------- | 252 | ----------------------------------------------------------------------------- |
253 | -- Tests return-timeout conformance | 253 | function returntimed_out(delta, t, err) |
254 | -- Input | 254 | if err == "timeout" then |
255 | -- len: length of block to be tested | 255 | if 1.1*delta >= t then |
256 | -- t: timeout value | 256 | pass("got rightfull timeout") |
257 | -- s: server sleep between transfers | 257 | return 1 |
258 | ----------------------------------------------------------------------------- | 258 | else |
259 | function test_returntimeout(len, t, s) | 259 | fail("shouldn't have gotten timeout") |
260 | local str, err, back, delta, total | 260 | end |
261 | reconnect() | 261 | elseif 0.9*delta > t then |
262 | send_command(RECEIVE_BLOCK, len) | 262 | fail("should have gotten timeout") |
263 | send_command(SLEEP, s) | 263 | end |
264 | send_command(RECEIVE_BLOCK, len) | 264 | end |
265 | write("testing ", len, " bytes, ", t, | 265 | |
266 | "s return timeout, ", s, "s sleep\n") | 266 | ----------------------------------------------------------------------------- |
267 | data:timeout(t, "return") | 267 | -- Tests return-timeout conformance |
268 | str = strrep("a", 2*len) | 268 | -- Input |
269 | err, total, delta = data:send(str) | 269 | -- len: length of block to be tested |
270 | print("delta: " .. delta) | 270 | -- t: timeout value |
271 | if returntimed_out(delta, t, err) then return end | 271 | -- s: server sleep between transfers |
272 | if err then fail(err) end | 272 | ----------------------------------------------------------------------------- |
273 | send_command(SEND_BLOCK) | 273 | function test_returntimeout(len, t, s) |
274 | send_command(SLEEP, s) | 274 | local str, err, back, delta, total |
275 | send_command(SEND_BLOCK) | 275 | reconnect() |
276 | back, err, delta = data:receive(2*len) | 276 | send_command(RECEIVE_BLOCK, len) |
277 | print("delta: " .. delta) | 277 | send_command(SLEEP, s) |
278 | if returntimed_out(delta, t, err) then return end | 278 | send_command(RECEIVE_BLOCK, len) |
279 | if err then fail(err) end | 279 | write("testing ", len, " bytes, ", t, |
280 | if back == str then pass("blocks match") | 280 | "s return timeout, ", s, "s sleep\n") |
281 | else fail("blocks don't match") end | 281 | timeout(data, t, "return") |
282 | end | 282 | str = strrep("a", 2*len) |
283 | 283 | err, total, delta = send(data, str) | |
284 | ----------------------------------------------------------------------------- | 284 | print("sent in " .. delta .. "s") |
285 | -- Execute all tests | 285 | if returntimed_out(delta, t, err) then return end |
286 | ----------------------------------------------------------------------------- | 286 | if err then fail("unexpected error: " .. err) end |
287 | new_test("control connection test") | 287 | send_command(SEND_BLOCK) |
288 | test_command(EXIT) | 288 | send_command(SLEEP, s) |
289 | test_command(CONNECT) | 289 | send_command(SEND_BLOCK) |
290 | test_command(CLOSE) | 290 | back, err, delta = receive(data, 2*len) |
291 | test_command(ECHO_BLOCK, 12234) | 291 | print("received in " .. delta .. "s") |
292 | test_command(SLEEP, 1111) | 292 | if returntimed_out(delta, t, err) then return end |
293 | test_command(ECHO_LINE) | 293 | if err then fail("unexpected error: " .. err) end |
294 | 294 | if back == str then pass("blocks match") | |
295 | new_test("connection close test") | 295 | else fail("blocks don't match") end |
296 | test_closed() | 296 | end |
297 | 297 | ||
298 | new_test("binary string test") | 298 | ----------------------------------------------------------------------------- |
299 | test_rawline(1) | 299 | -- Tests return-timeout conformance |
300 | test_rawline(17) | 300 | ----------------------------------------------------------------------------- |
301 | test_rawline(200) | 301 | function test_patterns() |
302 | test_rawline(3000) | 302 | local dos_line1 = "this the first dos line" |
303 | test_rawline(8000) | 303 | local dos_line2 = "this is another dos line" |
304 | test_rawline(40000) | 304 | local unix_line1 = "this the first unix line" |
305 | 305 | local unix_line2 = "this is another unix line" | |
306 | new_test("blocking transfer test") | 306 | local block = dos_line1 .. "\r\n" .. dos_line2 .. "\r\n" |
307 | test_block(1) | 307 | reconnect() |
308 | test_block(17) | 308 | block = block .. unix_line1 .. "\n" .. unix_line2 .. "\n" |
309 | test_block(200) | 309 | block = block .. block |
310 | test_block(3000) | 310 | send_command(ECHO_BLOCK, strlen(block)) |
311 | test_block(80000) | 311 | err = send(data, block) |
312 | test_block(800000) | 312 | if err then fail(err) end |
313 | 313 | local back = receive(data, "*l") | |
314 | new_test("non-blocking transfer test") | 314 | if back ~= dos_line1 then fail("'*l' failed") end |
315 | -- the value is not important, we only want | 315 | back = receive(data, "*l") |
316 | -- to test non-blockin I/O anyways | 316 | if back ~= dos_line2 then fail("'*l' failed") end |
317 | data:timeout(200) | 317 | back = receive(data, "*lu") |
318 | test_block(1) | 318 | if back ~= unix_line1 then fail("'*lu' failed") end |
319 | test_block(17) | 319 | back = receive(data, "*lu") |
320 | test_block(200) | 320 | if back ~= unix_line2 then fail("'*lu' failed") end |
321 | test_block(3000) | 321 | back = receive(data) |
322 | test_block(80000) | 322 | if back ~= dos_line1 then fail("default failed") end |
323 | test_block(800000) | 323 | back = receive(data) |
324 | test_block(8000000) | 324 | if back ~= dos_line2 then fail("default failed") end |
325 | 325 | back = receive(data, "*lu") | |
326 | new_test("character string test") | 326 | if back ~= unix_line1 then fail("'*lu' failed") end |
327 | test_asciiline(1) | 327 | back = receive(data, "*lu") |
328 | test_asciiline(17) | 328 | if back ~= unix_line2 then fail("'*lu' failed") end |
329 | test_asciiline(200) | 329 | pass("line patterns are ok") |
330 | test_asciiline(3000) | 330 | send_command(ECHO_BLOCK, strlen(block)) |
331 | test_asciiline(8000) | 331 | err = send(data, block) |
332 | test_asciiline(40000) | 332 | if err then fail(err) end |
333 | 333 | back = receive(data, strlen(block)) | |
334 | new_test("return timeout test") | 334 | if back ~= block then fail("number failed") end |
335 | test_returntimeout(80, .5, 1) | 335 | pass("number is ok") |
336 | test_returntimeout(80, 1, 0.5) | 336 | send_command(ECHO_BLOCK, strlen(block)) |
337 | test_returntimeout(8000, .5, 0) | 337 | send_command(SLEEP, 1) |
338 | test_returntimeout(80000, .5, 0) | 338 | send_command(CLOSE) |
339 | test_returntimeout(800000, .5, 0) | 339 | err = send(data, block) |
340 | 340 | if err then fail(err) end | |
341 | new_test("blocked timeout test") | 341 | back = receive(data, "*a") |
342 | test_blockedtimeout(80, .5, 1) | 342 | if back ~= block then fail("'*a' failed") end |
343 | test_blockedtimeout(80, 1, 1) | 343 | pass("'*a' is ok") |
344 | test_blockedtimeout(80, 1.5, 1) | 344 | end |
345 | test_blockedtimeout(800, 1, 0) | 345 | |
346 | test_blockedtimeout(8000, 1, 0) | 346 | ----------------------------------------------------------------------------- |
347 | test_blockedtimeout(80000, 1, 0) | 347 | -- Execute all tests |
348 | test_blockedtimeout(800000, 1, 0) | 348 | ----------------------------------------------------------------------------- |
349 | 349 | start = time() | |
350 | ----------------------------------------------------------------------------- | 350 | |
351 | -- Close connection and exit server. We are done. | 351 | new_test("control connection test") |
352 | ----------------------------------------------------------------------------- | 352 | test_command(EXIT) |
353 | new_test("the library has passed all tests") | 353 | test_command(CONNECT) |
354 | print("client: closing connection with server") | 354 | test_command(CLOSE) |
355 | send_command(CLOSE) | 355 | test_command(ECHO_BLOCK, 12234) |
356 | send_command(EXIT) | 356 | test_command(SLEEP, 1111) |
357 | control:close() | 357 | test_command(ECHO_LINE) |
358 | print("client: exiting...") | 358 | |
359 | exit() | 359 | new_test("connection close test") |
360 | test_closed() | ||
361 | |||
362 | new_test("read pattern test") | ||
363 | test_patterns() | ||
364 | |||
365 | new_test("character string test") | ||
366 | test_asciiline(1) | ||
367 | test_asciiline(17) | ||
368 | test_asciiline(200) | ||
369 | test_asciiline(3000) | ||
370 | test_asciiline(80000) | ||
371 | test_asciiline(800000) | ||
372 | |||
373 | new_test("binary string test") | ||
374 | test_rawline(1) | ||
375 | test_rawline(17) | ||
376 | test_rawline(200) | ||
377 | test_rawline(3000) | ||
378 | test_rawline(8000) | ||
379 | test_rawline(80000) | ||
380 | test_rawline(800000) | ||
381 | |||
382 | new_test("blocking transfer test") | ||
383 | test_block(1) | ||
384 | test_block(17) | ||
385 | test_block(200) | ||
386 | test_block(3000) | ||
387 | test_block(80000) | ||
388 | test_block(800000) | ||
389 | |||
390 | new_test("non-blocking transfer test") | ||
391 | -- the value is not important, we only want | ||
392 | -- to test non-blockin I/O anyways | ||
393 | timeout(data, 200) | ||
394 | test_block(1) | ||
395 | test_block(17) | ||
396 | test_block(200) | ||
397 | test_block(3000) | ||
398 | test_block(80000) | ||
399 | test_block(800000) | ||
400 | |||
401 | new_test("blocked timeout test") | ||
402 | test_blockedtimeout(80, .5, 1) | ||
403 | test_blockedtimeout(80, 1, 1) | ||
404 | test_blockedtimeout(80, 1.5, 1) | ||
405 | test_blockedtimeout(800, 1, 0) | ||
406 | test_blockedtimeout(8000, 1, 1.5) | ||
407 | test_blockedtimeout(80000, 1, 0) | ||
408 | test_blockedtimeout(800000, 0.01, 0) | ||
409 | |||
410 | new_test("return timeout test") | ||
411 | test_returntimeout(80, 1, 0.5) | ||
412 | test_returntimeout(80, 0.5, 1) | ||
413 | test_returntimeout(8000, .5, 1) | ||
414 | test_returntimeout(80000, 1, 0.5) | ||
415 | test_returntimeout(800000, 1, 0.5) | ||
416 | |||
417 | ----------------------------------------------------------------------------- | ||
418 | -- Close connection and exit server. We are done. | ||
419 | ----------------------------------------------------------------------------- | ||
420 | print("client: closing connection with server") | ||
421 | send_command(CLOSE) | ||
422 | send_command(EXIT) | ||
423 | close(control) | ||
424 | |||
425 | new_test("the library has passed all tests") | ||
426 | print(format("time elapsed: %6.2fs", time() - start)) | ||
427 | print("client: exiting...") | ||
428 | exit() | ||