about summary refs log tree commit homepage
path: root/test/test_unix_connect.rb
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2010-09-23 22:56:44 +0000
committerEric Wong <e@yhbt.net>2010-09-25 02:28:32 +0000
commit460e6b025896dee64b39d194d4c1a536129654de (patch)
treef38119dbf55b0e0a9f8ebca7acd41860245461a9 /test/test_unix_connect.rb
downloadkgio-460e6b025896dee64b39d194d4c1a536129654de.tar.gz
everything shou^Wmight be working...
Diffstat (limited to 'test/test_unix_connect.rb')
-rw-r--r--test/test_unix_connect.rb58
1 files changed, 58 insertions, 0 deletions
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