kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
blob cf59a2fde713ca98b9e9a0fff972ac03ebb36200 1860 bytes (raw)
name: test/test_accept_class.rb 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
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

debug log:

solving cf59a2f ...
found cf59a2f in https://yhbt.net/kgio.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).