fix misc compiler warnings
[kgio.git] / test / test_unix_connect.rb
blobf99a877e2cbbc4dabb68a6ad37d583c32cd108a5
1 require 'test/unit'
2 require 'io/nonblock'
3 $-w = true
4 require 'kgio'
5 require 'tempfile'
7 class SubSocket < Kgio::Socket
8   attr_accessor :foo
9   def kgio_wait_writable
10     @foo = "waited"
11   end
12 end
14 class TestKgioUnixConnect < Test::Unit::TestCase
16   def setup
17     tmp = Tempfile.new('kgio_unix')
18     @path = tmp.path
19     File.unlink(@path)
20     tmp.close rescue nil
21     @srv = Kgio::UNIXServer.new(@path)
22     @addr = Socket.pack_sockaddr_un(@path)
23   end
25   def teardown
26     @srv.close unless @srv.closed?
27     File.unlink(@path)
28     Kgio.accept_cloexec = true
29   end
31   def test_unix_socket_new_invalid
32     assert_raises(ArgumentError) { Kgio::UNIXSocket.new('*' * 1024 * 1024) }
33   end
35   def test_unix_socket_new
36     sock = Kgio::UNIXSocket.new(@path)
37     assert_instance_of Kgio::UNIXSocket, sock
38     ready = IO.select(nil, [ sock ])
39     assert_equal sock, ready[1][0]
40     assert_equal nil, sock.kgio_write("HELLO")
41   end
43   def test_new
44     sock = Kgio::Socket.new(@addr)
45     assert_instance_of Kgio::Socket, sock
46     ready = IO.select(nil, [ sock ])
47     assert_equal sock, ready[1][0]
48     assert_equal nil, sock.kgio_write("HELLO")
49   end
51   def test_start
52     sock = Kgio::Socket.start(@addr)
53     assert_instance_of Kgio::Socket, sock
54     ready = IO.select(nil, [ sock ])
55     assert_equal sock, ready[1][0]
56     assert_equal nil, sock.kgio_write("HELLO")
57   end
59   def test_socket_start
60     sock = SubSocket.start(@addr)
61     assert_nil sock.foo
62     ready = IO.select(nil, [ sock ])
63     assert_equal sock, ready[1][0]
64     assert_equal nil, sock.kgio_write("HELLO")
65   end
67   def test_wait_writable_set
68     sock = SubSocket.new(@addr)
69     assert_kind_of Kgio::Socket, sock
70     assert_instance_of SubSocket, sock
71     assert_equal nil, sock.kgio_write("HELLO")
72   end
73 end