1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/socket/test_sockopt.rb
akr 6e6676a223 add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-02-11 04:31:19 +00:00

33 lines
1.1 KiB
Ruby

require 'test/unit'
require 'socket'
class TestSocketOption < Test::Unit::TestCase
def test_new
data = [1].pack("i")
sockopt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, data)
assert_equal(Socket::AF_INET, sockopt.family)
assert_equal(Socket::SOL_SOCKET, sockopt.level)
assert_equal(Socket::SO_KEEPALIVE, sockopt.optname)
assert_equal(Socket::SO_KEEPALIVE, sockopt.optname)
assert_equal(data, sockopt.data)
end
def test_bool
opt = Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, true)
assert_equal(1, opt.int)
opt = Socket::Option.bool(:INET, :SOCKET, :KEEPALIVE, false)
assert_equal(0, opt.int)
opt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 0)
assert_equal(false, opt.bool)
opt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 1)
assert_equal(true, opt.bool)
opt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 2)
assert_equal(true, opt.bool)
end
def test_unpack
sockopt = Socket::Option.new(:INET, :SOCKET, :KEEPALIVE, [1].pack("i"))
assert_equal([1], sockopt.unpack("i"))
assert_equal([1], sockopt.data.unpack("i"))
end
end