source: EcnlProtoTool/trunk/mrbgems/mruby-socket/test/ipsocket.rb@ 279

Last change on this file since 279 was 279, checked in by coas-nagasima, 7 years ago

ファイルを追加、更新。

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 884 bytes
Line 
1# Note: most of tests below will fail if UDPSocket is broken.
2
3assert('IPSocket.getaddress') do
4 l = IPSocket.getaddress("localhost")
5 assert_true (l == "127.0.0.1" or l == "::1")
6end
7
8assert('IPSocket.addr') do
9 localhost = "127.0.0.1"
10 s = UDPSocket.new
11 s.bind(localhost, 0)
12 port = Addrinfo.new(s.getsockname).ip_port
13
14 a = s.addr
15 assert_equal "AF_INET", a[0]
16 assert_equal port, a[1]
17 assert_equal localhost, a[2]
18 assert_equal localhost, a[3]
19 s.close
20 true
21end
22
23assert('IPSocket.peeraddr') do
24 localhost = "127.0.0.1"
25 server = UDPSocket.new
26 server.bind(localhost, 0)
27 port = server.local_address.ip_port
28
29 client = UDPSocket.new
30 client.connect(localhost, port)
31
32 a = client.peeraddr
33 assert_equal "AF_INET", a[0]
34 assert_equal port, a[1]
35 assert_equal localhost, a[2]
36 assert_equal localhost, a[3]
37 client.close
38 server.close
39 true
40end
Note: See TracBrowser for help on using the repository browser.