6 class TestAcceptClass < Test::Unit::TestCase
7 class FooSocket < Kgio::Socket
11 assert_equal Kgio::Socket, Kgio.accept_class
15 Kgio.accept_class = nil
16 assert_equal Kgio::Socket, Kgio.accept_class
20 Kgio.accept_class = Kgio::TCPSocket
21 assert_equal Kgio::TCPSocket, Kgio.accept_class
25 assert_raises(TypeError) { Kgio.accept_class = TCPSocket }
26 assert_equal Kgio::Socket, Kgio.accept_class
29 def test_accepted_class
30 @host = ENV["TEST_HOST"] || '127.0.0.1'
31 @srv = Kgio::TCPServer.new(@host, 0)
35 Kgio.accept_class = Kgio::TCPSocket
36 socks << TCPSocket.new(@host, @port)
37 assert_instance_of Kgio::TCPSocket, @srv.kgio_accept
38 socks << TCPSocket.new(@host, @port)
40 assert_instance_of Kgio::TCPSocket, @srv.kgio_tryaccept
42 Kgio.accept_class = nil
43 socks << TCPSocket.new(@host, @port)
44 assert_instance_of Kgio::Socket, @srv.kgio_accept
45 socks << TCPSocket.new(@host, @port)
47 assert_instance_of Kgio::Socket, @srv.kgio_tryaccept
49 Kgio.accept_class = Kgio::UNIXSocket
50 socks << TCPSocket.new(@host, @port)
51 assert_instance_of Kgio::UNIXSocket, @srv.kgio_accept
52 socks << TCPSocket.new(@host, @port)
54 assert_instance_of Kgio::UNIXSocket, @srv.kgio_tryaccept
56 socks << TCPSocket.new(@host, @port)
57 assert_instance_of FooSocket, @srv.kgio_accept(FooSocket)
59 socks << TCPSocket.new(@host, @port)
61 assert_instance_of FooSocket, @srv.kgio_tryaccept(FooSocket)