kgio.git  about / heads / tags
kinder, gentler I/O for Ruby
blob f99a877e2cbbc4dabb68a6ad37d583c32cd108a5 1763 bytes (raw)
$ git show v2.2.0:test/test_unix_connect.rb	# shows this blob on the CLI

 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
63
64
65
66
67
68
69
70
71
72
73
 
require 'test/unit'
require 'io/nonblock'
$-w = true
require 'kgio'
require 'tempfile'

class SubSocket < Kgio::Socket
  attr_accessor :foo
  def kgio_wait_writable
    @foo = "waited"
  end
end

class TestKgioUnixConnect < Test::Unit::TestCase

  def setup
    tmp = Tempfile.new('kgio_unix')
    @path = tmp.path
    File.unlink(@path)
    tmp.close rescue nil
    @srv = Kgio::UNIXServer.new(@path)
    @addr = Socket.pack_sockaddr_un(@path)
  end

  def teardown
    @srv.close unless @srv.closed?
    File.unlink(@path)
    Kgio.accept_cloexec = true
  end

  def test_unix_socket_new_invalid
    assert_raises(ArgumentError) { Kgio::UNIXSocket.new('*' * 1024 * 1024) }
  end

  def test_unix_socket_new
    sock = Kgio::UNIXSocket.new(@path)
    assert_instance_of Kgio::UNIXSocket, sock
    ready = IO.select(nil, [ sock ])
    assert_equal sock, ready[1][0]
    assert_equal nil, sock.kgio_write("HELLO")
  end

  def test_new
    sock = Kgio::Socket.new(@addr)
    assert_instance_of Kgio::Socket, sock
    ready = IO.select(nil, [ sock ])
    assert_equal sock, ready[1][0]
    assert_equal nil, sock.kgio_write("HELLO")
  end

  def test_start
    sock = Kgio::Socket.start(@addr)
    assert_instance_of Kgio::Socket, sock
    ready = IO.select(nil, [ sock ])
    assert_equal sock, ready[1][0]
    assert_equal nil, sock.kgio_write("HELLO")
  end

  def test_socket_start
    sock = SubSocket.start(@addr)
    assert_nil sock.foo
    ready = IO.select(nil, [ sock ])
    assert_equal sock, ready[1][0]
    assert_equal nil, sock.kgio_write("HELLO")
  end

  def test_wait_writable_set
    sock = SubSocket.new(@addr)
    assert_kind_of Kgio::Socket, sock
    assert_instance_of SubSocket, sock
    assert_equal nil, sock.kgio_write("HELLO")
  end
end

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