2004-12-06 11:15:56 +03:00
|
|
|
begin
|
|
|
|
require "socket"
|
|
|
|
require "test/unit"
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
class TestUDPSocket < Test::Unit::TestCase
|
2009-01-01 18:15:31 +03:00
|
|
|
def test_open
|
|
|
|
assert_nothing_raised { UDPSocket.open {} }
|
|
|
|
assert_nothing_raised { UDPSocket.open(Socket::AF_INET) {} }
|
|
|
|
assert_nothing_raised { UDPSocket.open("AF_INET") {} }
|
2009-01-01 18:59:10 +03:00
|
|
|
assert_nothing_raised { UDPSocket.open(:AF_INET) {} }
|
2009-01-01 18:15:31 +03:00
|
|
|
end
|
|
|
|
|
2007-11-18 10:18:56 +03:00
|
|
|
def test_connect
|
2004-12-06 11:15:56 +03:00
|
|
|
s = UDPSocket.new
|
|
|
|
host = Object.new
|
2007-11-04 23:36:20 +03:00
|
|
|
class << host; self end.send(:define_method, :to_str) {
|
2004-12-06 11:15:56 +03:00
|
|
|
s.close
|
|
|
|
"127.0.0.1"
|
|
|
|
}
|
2007-11-18 10:18:56 +03:00
|
|
|
assert_raise(IOError, "[ruby-dev:25045]") {
|
2004-12-06 11:15:56 +03:00
|
|
|
s.connect(host, 1)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2007-11-18 10:18:56 +03:00
|
|
|
def test_bind
|
2004-12-06 11:15:56 +03:00
|
|
|
s = UDPSocket.new
|
|
|
|
host = Object.new
|
2007-11-04 23:36:20 +03:00
|
|
|
class << host; self end.send(:define_method, :to_str) {
|
2004-12-06 11:15:56 +03:00
|
|
|
s.close
|
|
|
|
"127.0.0.1"
|
|
|
|
}
|
2007-11-18 10:18:56 +03:00
|
|
|
assert_raise(IOError, "[ruby-dev:25057]") {
|
2004-12-06 11:15:56 +03:00
|
|
|
s.bind(host, 2000)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end if defined?(UDPSocket)
|