From c51283fa62331bb6db5e481da714493f0a91b936 Mon Sep 17 00:00:00 2001
From: Diego Nehab <diego@tecgraf.puc-rio.br>
Date: Fri, 8 Jun 2001 22:42:01 +0000
Subject: Added select bug test. time became _time.

---
 test/testclnt.lua | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/test/testclnt.lua b/test/testclnt.lua
index 1efb51d..4ee2c48 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -22,7 +22,7 @@ while control == nil do
 	if control then
 		print("client: control connection stablished!") 
 	else
-		sleep(2)
+		_sleep(2)
 	end
 end
 
@@ -48,7 +48,7 @@ function reconnect()
 		data = connect(HOST, PORT)
 		if not data then 
 			print("client: waiting for data connection.") 
-			sleep(1)
+			_sleep(1)
 		end
 	end
 	sync()
@@ -296,9 +296,6 @@ function test_returntimeout(len, t, s)
 	else fail("blocks don't match") end
 end
 
-
-
-
 -----------------------------------------------------------------------------
 -- Tests read patterns
 -----------------------------------------------------------------------------
@@ -363,10 +360,26 @@ function test_patterns()
 	pass("'*a' is ok")
 end
 
+-----------------------------------------------------------------------------
+-- Test for select bugs
+-----------------------------------------------------------------------------
+function test_select()
+	local r, s, e = select(nil, nil, 0.1)
+	assert(type(r) == "table" and type(s) == "table" and e == "timeout")
+	pass("both nil")
+	data:close()
+	r, s, e = select({ data }, { data }, 0.1)
+	assert(type(r) == "table" and type(s) == "table" and e == "timeout")
+	pass("closed sockets")
+	e = call(select, {"wrong", 1, 0.1}, "x", nil)
+	assert(e == nil)
+	pass("invalid input")
+end
+
 -----------------------------------------------------------------------------
 -- Execute all tests
 -----------------------------------------------------------------------------
-start = time()
+start = _time()
 
 new_test("control connection test")
 test_command(EXIT)
@@ -376,7 +389,9 @@ test_command(ECHO_BLOCK, 12234)
 test_command(SLEEP, 1111)
 test_command(ECHO_LINE)
 
---a = [[
+new_test("testing for select bugs")
+test_select()
+
 new_test("connection close test")
 test_closed()
 
@@ -438,17 +453,15 @@ test_returntimeout(8000, 1, 2)
 test_returntimeout(80000, 2, 1)
 test_returntimeout(800000, 0.1, 0)
 test_returntimeout(800000, 2, 1)
---]]
 
 -----------------------------------------------------------------------------
 -- Close connection and exit server. We are done.
 -----------------------------------------------------------------------------
+new_test("the library has passed all tests")
 print("client: closing connection with server")
 send_command(CLOSE)
 send_command(EXIT)
 control:close()
-
-new_test("the library has passed all tests")
-print(format("time elapsed: %6.2fs", time() - start))
+print(format("time elapsed: %6.2fs", _time() - start))
 print("client: exiting...")
 exit()
-- 
cgit v1.2.3-55-g6feb