Sha256: 18e977791dee264e9f02f5a6064725386b27ba095f60d24898c522b4247e9ecb

Contents?: true

Size: 1.72 KB

Versions: 14

Compression:

Stored size: 1.72 KB

Contents

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kgio-2.6.0 test/test_unix_connect.rb
kgio-2.5.0 test/test_unix_connect.rb
kgio-2.4.2 test/test_unix_connect.rb
kgio-2.4.1 test/test_unix_connect.rb
kgio-2.4.0 test/test_unix_connect.rb
kgio-2.3.3 test/test_unix_connect.rb
kgio-2.3.2 test/test_unix_connect.rb
kgio-2.3.1 test/test_unix_connect.rb
kgio-2.3.0 test/test_unix_connect.rb
kgio-2.2.0 test/test_unix_connect.rb
kgio-2.1.1 test/test_unix_connect.rb
kgio-2.1.0 test/test_unix_connect.rb
kgio-2.0.0 test/test_unix_connect.rb
kgio-2.0.0pre1 test/test_unix_connect.rb