Sha256: 2c15a80b10c2f901440b41117ec314c4cad64be5f4100d12858b6cd525a651bf

Contents?: true

Size: 1.82 KB

Versions: 17

Compression:

Stored size: 1.82 KB

Contents

require 'test/unit'
require 'io/nonblock'
$-w = true
require 'kgio'

class TestAcceptClass < Test::Unit::TestCase
  class FooSocket < Kgio::Socket
  end

  def setup
    assert_equal Kgio::Socket, Kgio.accept_class
  end

  def teardown
    assert_nothing_raised { Kgio.accept_class = nil }
    assert_equal Kgio::Socket, Kgio.accept_class
  end

  def test_tcp_socket
    assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket }
    assert_equal Kgio::TCPSocket, Kgio.accept_class
  end

  def test_invalid
    assert_raises(TypeError) { Kgio.accept_class = TCPSocket }
    assert_equal Kgio::Socket, Kgio.accept_class
  end

  def test_accepted_class
    @host = ENV["TEST_HOST"] || '127.0.0.1'
    @srv = Kgio::TCPServer.new(@host, 0)
    @port = @srv.addr[1]

    assert_nothing_raised { Kgio.accept_class = Kgio::TCPSocket }
    client = TCPSocket.new(@host, @port)
    assert_instance_of Kgio::TCPSocket, @srv.kgio_accept
    client = TCPSocket.new(@host, @port)
    IO.select([@srv])
    assert_instance_of Kgio::TCPSocket, @srv.kgio_tryaccept

    assert_nothing_raised { Kgio.accept_class = nil }
    client = TCPSocket.new(@host, @port)
    assert_instance_of Kgio::Socket, @srv.kgio_accept
    client = TCPSocket.new(@host, @port)
    IO.select([@srv])
    assert_instance_of Kgio::Socket, @srv.kgio_tryaccept

    assert_nothing_raised { Kgio.accept_class = Kgio::UNIXSocket }
    client = TCPSocket.new(@host, @port)
    assert_instance_of Kgio::UNIXSocket, @srv.kgio_accept
    client = TCPSocket.new(@host, @port)
    IO.select([@srv])
    assert_instance_of Kgio::UNIXSocket, @srv.kgio_tryaccept

    client = TCPSocket.new(@host, @port)
    assert_instance_of FooSocket, @srv.kgio_accept(FooSocket)

    client = TCPSocket.new(@host, @port)
    IO.select([@srv])
    assert_instance_of FooSocket, @srv.kgio_tryaccept(FooSocket)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
kgio-2.7.3 test/test_accept_class.rb
kgio-2.7.2 test/test_accept_class.rb
kgio-2.7.1 test/test_accept_class.rb
kgio-2.7.0.3.gfd1e test/test_accept_class.rb
kgio-2.7.0 test/test_accept_class.rb
kgio-2.6.0 test/test_accept_class.rb
kgio-2.5.0 test/test_accept_class.rb
kgio-2.4.2 test/test_accept_class.rb
kgio-2.4.1 test/test_accept_class.rb
kgio-2.4.0 test/test_accept_class.rb
kgio-2.3.3 test/test_accept_class.rb
kgio-2.3.2 test/test_accept_class.rb
kgio-2.3.1 test/test_accept_class.rb
kgio-2.3.0 test/test_accept_class.rb
kgio-2.2.0 test/test_accept_class.rb
kgio-2.1.1 test/test_accept_class.rb
kgio-2.1.0 test/test_accept_class.rb