1begin 2 require "socket" 3 require "test/unit" 4rescue LoadError 5end 6 7 8class TestSocket_UDPSocket < Test::Unit::TestCase 9 def test_open 10 assert_nothing_raised { UDPSocket.open {} } 11 assert_nothing_raised { UDPSocket.open(Socket::AF_INET) {} } 12 assert_nothing_raised { UDPSocket.open("AF_INET") {} } 13 assert_nothing_raised { UDPSocket.open(:AF_INET) {} } 14 end 15 16 def test_connect 17 s = UDPSocket.new 18 host = Object.new 19 class << host; self end.send(:define_method, :to_str) { 20 s.close 21 "127.0.0.1" 22 } 23 assert_raise(IOError, "[ruby-dev:25045]") { 24 s.connect(host, 1) 25 } 26 end 27 28 def test_bind 29 s = UDPSocket.new 30 host = Object.new 31 class << host; self end.send(:define_method, :to_str) { 32 s.close 33 "127.0.0.1" 34 } 35 assert_raise(IOError, "[ruby-dev:25057]") { 36 s.bind(host, 2000) 37 } 38 end 39end if defined?(UDPSocket) 40