mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c7a66ff804
commit
c9c3437b20
1 changed files with 56 additions and 0 deletions
56
test/socket/test_ancdata.rb
Normal file
56
test/socket/test_ancdata.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
require 'test/unit'
|
||||
require 'socket'
|
||||
|
||||
class TestSocketAncData < Test::Unit::TestCase
|
||||
def test_int
|
||||
ancdata = Socket::AncillaryData.int(0, 0, 0, 123)
|
||||
assert_equal(123, ancdata.int)
|
||||
assert_equal([123].pack("i"), ancdata.data)
|
||||
end
|
||||
|
||||
def test_ip_pktinfo
|
||||
addr = Addrinfo.ip("127.0.0.1")
|
||||
ifindex = 0
|
||||
spec_dst = Addrinfo.ip("127.0.0.2")
|
||||
begin
|
||||
ancdata = Socket::AncillaryData.ip_pktinfo(addr, ifindex, spec_dst)
|
||||
rescue NotImplementedError
|
||||
return
|
||||
end
|
||||
assert_equal(Socket::AF_INET, ancdata.family)
|
||||
assert_equal(Socket::IPPROTO_IP, ancdata.level)
|
||||
assert_equal(Socket::IP_PKTINFO, ancdata.type)
|
||||
assert_equal(addr.ip_address, ancdata.ip_pktinfo[0].ip_address)
|
||||
assert_equal(ifindex, ancdata.ip_pktinfo[1])
|
||||
assert_equal(spec_dst.ip_address, ancdata.ip_pktinfo[2].ip_address)
|
||||
assert(ancdata.cmsg_is?(:IP, :PKTINFO))
|
||||
assert(ancdata.cmsg_is?("IP", "PKTINFO"))
|
||||
assert(ancdata.cmsg_is?(Socket::IPPROTO_IP, Socket::IP_PKTINFO))
|
||||
if defined? Socket::IPV6_PKTINFO
|
||||
assert(!ancdata.cmsg_is?(:IPV6, :PKTINFO))
|
||||
end
|
||||
end
|
||||
|
||||
def test_ipv6_pktinfo
|
||||
addr = Addrinfo.ip("::1")
|
||||
ifindex = 0
|
||||
begin
|
||||
ancdata = Socket::AncillaryData.ipv6_pktinfo(addr, ifindex)
|
||||
rescue NotImplementedError
|
||||
return
|
||||
end
|
||||
assert_equal(Socket::AF_INET6, ancdata.family)
|
||||
assert_equal(Socket::IPPROTO_IPV6, ancdata.level)
|
||||
assert_equal(Socket::IPV6_PKTINFO, ancdata.type)
|
||||
assert_equal(addr.ip_address, ancdata.ipv6_pktinfo[0].ip_address)
|
||||
assert_equal(ifindex, ancdata.ipv6_pktinfo[1])
|
||||
assert_equal(addr.ip_address, ancdata.ipv6_pktinfo_addr.ip_address)
|
||||
assert_equal(ifindex, ancdata.ipv6_pktinfo_ifindex)
|
||||
assert(ancdata.cmsg_is?(:IPV6, :PKTINFO))
|
||||
assert(ancdata.cmsg_is?("IPV6", "PKTINFO"))
|
||||
assert(ancdata.cmsg_is?(Socket::IPPROTO_IPV6, Socket::IPV6_PKTINFO))
|
||||
if defined? Socket::IP_PKTINFO
|
||||
assert(!ancdata.cmsg_is?(:IP, :PKTINFO))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue