source: EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-socket/test/socket.rb@ 439

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

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 1.1 KB
Line 
1unless SocketTest.win?
2
3assert('Socket.gethostname') do
4 assert_true(Socket.gethostname.is_a? String)
5end
6
7assert('Socket::getaddrinfo') do
8 ret = Socket.getaddrinfo("localhost", 53, Socket::AF_INET, Socket::SOCK_DGRAM)
9 assert_true ret.size >= 1
10 a = ret[0]
11 assert_equal "AF_INET", a[0]
12 assert_equal 53, a[1]
13 # documents says it's a hostname but CRuby returns an address
14 #assert_equal "127.0.0.1", a[2]
15 assert_equal "127.0.0.1", a[3]
16 assert_equal Socket::AF_INET, a[4]
17 assert_equal Socket::SOCK_DGRAM, a[5]
18 assert_equal Socket::IPPROTO_UDP, a[6] unless SocketTest.cygwin?
19end
20
21assert('Socket#recvfrom') do
22 begin
23 sstr = "abcdefg"
24 s = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
25 c = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
26 s.bind(Socket.sockaddr_in(0, "127.0.0.1"))
27 c.send sstr, 0, s.getsockname
28 rstr, ai = s.recvfrom sstr.size
29
30 assert_equal sstr, rstr
31 assert_equal "127.0.0.1", ai.ip_address
32 ensure
33 s.close rescue nil
34 c.close rescue nil
35 end
36end
37
38end # win?
Note: See TracBrowser for help on using the repository browser.