From 460e6b025896dee64b39d194d4c1a536129654de Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 23 Sep 2010 22:56:44 +0000 Subject: initial commit + release everything shou^Wmight be working... --- test/test_unix_connect.rb | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/test_unix_connect.rb (limited to 'test/test_unix_connect.rb') diff --git a/test/test_unix_connect.rb b/test/test_unix_connect.rb new file mode 100644 index 0000000..458149d --- /dev/null +++ b/test/test_unix_connect.rb @@ -0,0 +1,58 @@ +require 'test/unit' +require 'io/nonblock' +$-w = true +require 'kgio' +require 'tempfile' + +class SubSocket < Kgio::Socket + attr_accessor :foo + def wait_writable + @foo = "waited" + end +end + +class TestKgioUnixConnect < Test::Unit::TestCase + + def setup + tmp = Tempfile.new('kgio_unix') + @path = tmp.path + File.unlink(@path) + tmp.close rescue nil + @srv = Kgio::UNIXServer.new(@path) + @addr = Socket.pack_sockaddr_un(@path) + end + + def teardown + @srv.close unless @srv.closed? + File.unlink(@path) + Kgio.accept_cloexec = true + end + + def test_unix_socket_new_invalid + assert_raises(ArgumentError) { Kgio::UNIXSocket.new('*' * 1024 * 1024) } + end + + def test_unix_socket_new + sock = Kgio::UNIXSocket.new(@path) + assert_instance_of Kgio::UNIXSocket, sock + ready = IO.select(nil, [ sock ]) + assert_equal sock, ready[1][0] + assert_equal nil, sock.kgio_write("HELLO") + end + + def test_new + sock = Kgio::Socket.new(@addr) + assert_instance_of Kgio::Socket, sock + ready = IO.select(nil, [ sock ]) + assert_equal sock, ready[1][0] + assert_equal nil, sock.kgio_write("HELLO") + end + + def test_wait_writable_set + Kgio::wait_writable = :wait_writable + sock = SubSocket.new(@addr) + assert_kind_of Kgio::Socket, sock + assert_instance_of SubSocket, sock + assert_equal nil, sock.kgio_write("HELLO") + end +end -- cgit v1.2.3-24-ge0c7