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)
34 Kgio.accept_class = Kgio::TCPSocket
35 client = TCPSocket.new(@host, @port)
36 assert_instance_of Kgio::TCPSocket, @srv.kgio_accept
37 client = TCPSocket.new(@host, @port)
39 assert_instance_of Kgio::TCPSocket, @srv.kgio_tryaccept
41 Kgio.accept_class = nil
42 client = TCPSocket.new(@host, @port)
43 assert_instance_of Kgio::Socket, @srv.kgio_accept
44 client = TCPSocket.new(@host, @port)
46 assert_instance_of Kgio::Socket, @srv.kgio_tryaccept
48 Kgio.accept_class = Kgio::UNIXSocket
49 client = TCPSocket.new(@host, @port)
50 assert_instance_of Kgio::UNIXSocket, @srv.kgio_accept
51 client = TCPSocket.new(@host, @port)
53 assert_instance_of Kgio::UNIXSocket, @srv.kgio_tryaccept
55 client = TCPSocket.new(@host, @port)
56 assert_instance_of FooSocket, @srv.kgio_accept(FooSocket)
58 client = TCPSocket.new(@host, @port)
60 assert_instance_of FooSocket, @srv.kgio_tryaccept(FooSocket)