diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/ipsocket.rb | 40 | ||||
| -rw-r--r-- | test/socket.rb | 13 |
2 files changed, 53 insertions, 0 deletions
diff --git a/test/ipsocket.rb b/test/ipsocket.rb new file mode 100644 index 000000000..2b9f7e1d7 --- /dev/null +++ b/test/ipsocket.rb @@ -0,0 +1,40 @@ +# Note: most of tests below will fail if UDPSocket is broken. + +assert('IPSocket.getaddress') do + l = IPSocket.getaddress("localhost") + assert_true (l == "127.0.0.1" or l == "::1") +end + +assert('IPSocket.addr') do + localhost = "127.0.0.1" + s = UDPSocket.new + s.bind(localhost, 0) + port = Addrinfo.new(s.getsockname).ip_port + + a = s.addr + assert_equal "AF_INET", a[0] + assert_equal port, a[1] + assert_equal localhost, a[2] + assert_equal localhost, a[3] + s.close + true +end + +assert('IPSocket.peeraddr') do + localhost = "127.0.0.1" + server = UDPSocket.new + server.bind(localhost, 0) + port = server.local_address.ip_port + + client = UDPSocket.new + client.connect(localhost, port) + + a = client.peeraddr + assert_equal "AF_INET", a[0] + assert_equal port, a[1] + assert_equal localhost, a[2] + assert_equal localhost, a[3] + client.close + server.close + true +end diff --git a/test/socket.rb b/test/socket.rb index 309e7cf11..cd50cbaff 100644 --- a/test/socket.rb +++ b/test/socket.rb @@ -133,3 +133,16 @@ assert('Socket.gethostname') do assert_true(Socket.gethostname.is_a? String) end +assert('Socket::getaddrinfo') do + ret = Socket.getaddrinfo("localhost", "domain", Socket::AF_INET, Socket::SOCK_DGRAM) + assert_true ret.size >= 1 + a = ret[0] + assert_equal "AF_INET", a[0] + assert_equal 53, a[1] + # documents says it's a hostname but CRuby returns an address + #assert_equal "127.0.0.1", a[2] + assert_equal "127.0.0.1", a[3] + assert_equal Socket::AF_INET, a[4] + assert_equal Socket::SOCK_DGRAM, a[5] + assert_equal Socket::IPPROTO_UDP, a[6] +end |
