net-ping 1.3.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ ######################################################################
2
+ # test_net_ping.rb
3
+ #
4
+ # Test suite for all the Ping subclasses. Note that the Ping::ICMP
5
+ # class test won't be run unless this is run as a privileged process.
6
+ ######################################################################
7
+ require 'test_net_ping_external'
8
+ require 'test_net_ping_http'
9
+ require 'test_net_ping_tcp'
10
+ require 'test_net_ping_udp'
11
+
12
+ if Process.euid == 0
13
+ require 'test_net_ping_icmp'
14
+ end
15
+
16
+ if Config::CONFIG['host_os'] =~ /mswin|win32|dos|cygwin|mingw/i &&
17
+ RUBY_PLATFORM != 'java'
18
+ then
19
+ require 'test_net_ping_wmi'
20
+ end
21
+
22
+ class TC_Net_Ping < Test::Unit::TestCase
23
+ def test_net_ping_version
24
+ assert_equal('1.3.3', Net::Ping::VERSION)
25
+ end
26
+ end
@@ -0,0 +1,87 @@
1
+ #########################################################################
2
+ # test_net_ping_external.rb
3
+ #
4
+ # Test case for the Net::PingExternal class. Run this via the 'test' or
5
+ # 'test:external' rake task.
6
+ #########################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'net/ping/external'
12
+
13
+ class TC_Net_Ping_External < Test::Unit::TestCase
14
+ def setup
15
+ @host = 'www.ruby-lang.org'
16
+ @bogus = 'foo.bar.baz'
17
+ @pe = Net::Ping::External.new(@host)
18
+ @bad = Net::Ping::External.new(@bogus)
19
+ end
20
+
21
+ def test_ping
22
+ assert_respond_to(@pe, :ping)
23
+ assert_nothing_raised{ @pe.ping }
24
+ assert_nothing_raised{ @pe.ping(@host) }
25
+ end
26
+
27
+ def test_ping_aliases
28
+ assert_respond_to(@pe, :ping?)
29
+ assert_respond_to(@pe, :pingecho)
30
+ assert_nothing_raised{ @pe.ping? }
31
+ assert_nothing_raised{ @pe.ping?(@host) }
32
+ assert_nothing_raised{ @pe.pingecho }
33
+ assert_nothing_raised{ @pe.pingecho(@host) }
34
+ end
35
+
36
+ def test_good_ping
37
+ assert_equal(true, @pe.ping?)
38
+ end
39
+
40
+ def test_bad_ping
41
+ assert_equal(false, @bad.ping?)
42
+ assert_equal(false, @bad.exception.nil?, "Bad exception data")
43
+ end
44
+
45
+ def test_duration
46
+ assert_nothing_raised{ @pe.ping }
47
+ assert_respond_to(@pe, :duration)
48
+ assert_kind_of(Float, @pe.duration)
49
+ end
50
+
51
+ def test_host
52
+ assert_respond_to(@pe, :host)
53
+ assert_respond_to(@pe, :host=)
54
+ assert_equal('www.ruby-lang.org', @pe.host)
55
+ end
56
+
57
+ def test_port
58
+ assert_respond_to(@pe, :port)
59
+ assert_respond_to(@pe, :port=)
60
+ assert_equal(7, @pe.port)
61
+ end
62
+
63
+ def test_timeout
64
+ assert_respond_to(@pe, :timeout)
65
+ assert_respond_to(@pe, :timeout=)
66
+ assert_equal(5, @pe.timeout)
67
+ end
68
+
69
+ def test_exception
70
+ assert_respond_to(@pe, :exception)
71
+ assert_nothing_raised{ @pe.ping }
72
+ assert_nothing_raised{ @bad.ping }
73
+ assert_nil(@pe.exception)
74
+ assert_not_nil(@bad.exception)
75
+ end
76
+
77
+ def test_warning
78
+ assert_respond_to(@pe, :warning)
79
+ end
80
+
81
+ def teardown
82
+ @host = nil
83
+ @bogus = nil
84
+ @pe = nil
85
+ @bad = nil
86
+ end
87
+ end
@@ -0,0 +1,115 @@
1
+ #################################################################################
2
+ # test_net_ping_http.rb
3
+ #
4
+ # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
+ # 'test:http' Rake task.
6
+ #################################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'net/ping/http'
12
+
13
+ class TC_Net_Ping_HTTP < Test::Unit::TestCase
14
+ def setup
15
+ @uri = 'http://www.google.com/index.html'
16
+ @http = Net::Ping::HTTP.new(@uri, 80, 30)
17
+ @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
18
+ end
19
+
20
+ test 'ping basic functionality' do
21
+ assert_respond_to(@http, :ping)
22
+ assert_nothing_raised{ @http.ping }
23
+ end
24
+
25
+ test 'ping returns a boolean value' do
26
+ assert_boolean(@http.ping?)
27
+ assert_boolean(@bad.ping?)
28
+ end
29
+
30
+ test 'ping? is an alias for ping' do
31
+ assert_alias_method(@http, :ping?, :ping)
32
+ end
33
+
34
+ test 'pingecho is an alias for ping' do
35
+ assert_alias_method(@http, :pingecho, :ping)
36
+ end
37
+
38
+ test 'ping should succeed for a valid website' do
39
+ assert_true(@http.ping?)
40
+ end
41
+
42
+ test 'ping should fail for an invalid website' do
43
+ assert_false(@bad.ping?)
44
+ end
45
+
46
+ test 'duration basic functionality' do
47
+ assert_respond_to(@http, :duration)
48
+ assert_nothing_raised{ @http.ping }
49
+ end
50
+
51
+ test 'duration returns a float value on a successful ping' do
52
+ assert_true(@http.ping)
53
+ assert_kind_of(Float, @http.duration)
54
+ end
55
+
56
+ test 'duration is nil on an unsuccessful ping' do
57
+ assert_false(@bad.ping)
58
+ assert_nil(@http.duration)
59
+ end
60
+
61
+ test 'host attribute basic functionality' do
62
+ assert_respond_to(@http, :host)
63
+ assert_respond_to(@http, :host=)
64
+ assert_equal('http://www.google.com/index.html', @http.host)
65
+ end
66
+
67
+ test 'uri is an alias for host' do
68
+ assert_alias_method(@http, :uri, :host)
69
+ assert_alias_method(@http, :uri=, :host=)
70
+ end
71
+
72
+ test 'port attribute basic functionality' do
73
+ assert_respond_to(@http, :port)
74
+ assert_respond_to(@http, :port=)
75
+ end
76
+
77
+ test 'port attribute expected value' do
78
+ assert_equal(80, @http.port)
79
+ end
80
+
81
+ test 'timeout attribute basic functionality' do
82
+ assert_respond_to(@http, :timeout)
83
+ assert_respond_to(@http, :timeout=)
84
+ end
85
+
86
+ test 'timeout attribute expected values' do
87
+ assert_equal(30, @http.timeout)
88
+ assert_equal(5, @bad.timeout)
89
+ end
90
+
91
+ test 'exception attribute basic functionality' do
92
+ assert_respond_to(@http, :exception)
93
+ assert_nil(@http.exception)
94
+ end
95
+
96
+ test 'exception attribute is nil if the ping is successful' do
97
+ assert_true(@http.ping)
98
+ assert_nil(@http.exception)
99
+ end
100
+
101
+ test 'exception attribute is not nil if the ping is unsuccessful' do
102
+ assert_false(@bad.ping)
103
+ assert_not_nil(@bad.exception)
104
+ end
105
+
106
+ test 'warning attribute basic functionality' do
107
+ assert_respond_to(@http, :warning)
108
+ assert_nil(@http.warning)
109
+ end
110
+
111
+ def teardown
112
+ @uri = nil
113
+ @http = nil
114
+ end
115
+ end
@@ -0,0 +1,126 @@
1
+ #######################################################################
2
+ # test_net_ping_icmp.rb
3
+ #
4
+ # Test case for the Net::PingICMP class. You must run this test case
5
+ # with root privileges on UNIX systems. This should be run via the
6
+ # 'test' or 'test:icmp' Rake task.
7
+ #######################################################################
8
+ require 'rubygems'
9
+ gem 'test-unit'
10
+
11
+ require 'test/unit'
12
+ require 'net/ping/icmp'
13
+ include Net
14
+
15
+ unless Process.euid == 0
16
+ raise "The test:icmp task must be run with root privileges"
17
+ end
18
+
19
+ class TC_PingICMP < Test::Unit::TestCase
20
+ def self.startup
21
+ @@one_click = Config::CONFIG['host_os'] == 'mswin32'
22
+ end
23
+
24
+ def setup
25
+ @host = "www.ruby-lang.org"
26
+ @icmp = Ping::ICMP.new(@host)
27
+ end
28
+
29
+ def test_ping
30
+ assert_respond_to(@icmp, :ping)
31
+
32
+ omit_if(@@one_click, 'Unreliable socket library')
33
+
34
+ assert_nothing_raised{ @icmp.ping }
35
+ assert_nothing_raised{ @icmp.ping(@host) }
36
+ end
37
+
38
+ def test_ping_aliases_basic
39
+ assert_respond_to(@icmp, :ping?)
40
+ assert_respond_to(@icmp, :pingecho)
41
+
42
+ omit_if(@@one_click, 'Unreliable socket library')
43
+
44
+ assert_nothing_raised{ @icmp.ping? }
45
+ assert_nothing_raised{ @icmp.ping?(@host) }
46
+ end
47
+
48
+ def test_ping_returns_boolean
49
+ omit_if(@@one_click, 'Unreliable socket library')
50
+ assert_boolean(@icmp.pingecho)
51
+ assert_boolean(@icmp.pingecho(@host))
52
+ end
53
+
54
+ def test_ping_expected_failure
55
+ omit_if(@@one_click, 'Unreliable socket library')
56
+ assert_false(Ping::ICMP.new('bogus').ping?)
57
+ assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
58
+ end
59
+
60
+ def test_bind
61
+ omit_if(@@one_click, 'Unreliable socket library')
62
+ assert_respond_to(@icmp, :bind)
63
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
64
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
65
+ end
66
+
67
+ def test_duration
68
+ omit_if(@@one_click, 'Unreliable socket library')
69
+ assert_nothing_raised{ @icmp.ping }
70
+ assert_respond_to(@icmp, :duration)
71
+ assert_kind_of(Float, @icmp.duration)
72
+ end
73
+
74
+ def test_host
75
+ assert_respond_to(@icmp, :host)
76
+ assert_respond_to(@icmp, :host=)
77
+ assert_equal('www.ruby-lang.org', @icmp.host)
78
+ end
79
+
80
+ def test_port
81
+ assert_respond_to(@icmp, :port)
82
+ assert_equal(nil, @icmp.port)
83
+ end
84
+
85
+ def test_timeout
86
+ assert_respond_to(@icmp, :timeout)
87
+ assert_respond_to(@icmp, :timeout=)
88
+ assert_equal(5, @icmp.timeout)
89
+ end
90
+
91
+ def test_exception
92
+ assert_respond_to(@icmp, :exception)
93
+ omit_if(@@one_click, 'Unreliable socket library')
94
+ assert_nothing_raised{ @icmp.ping }
95
+ assert_nil(@icmp.exception)
96
+ end
97
+
98
+ def test_warning
99
+ assert_respond_to(@icmp, :warning)
100
+ end
101
+
102
+ def test_data_size_get
103
+ assert_respond_to(@icmp, :data_size)
104
+ assert_equal(56, @icmp.data_size)
105
+ end
106
+
107
+ def test_data_size_set
108
+ assert_respond_to(@icmp, :data_size=)
109
+ assert_nothing_raised{ @icmp.data_size = 22 }
110
+ end
111
+
112
+ def test_odd_data_size_ok
113
+ assert_nothing_raised{ @icmp.data_size = 57 }
114
+ omit_if(@@one_click, 'Unreliable socket library')
115
+ assert_boolean(@icmp.ping)
116
+ end
117
+
118
+ def teardown
119
+ @host = nil
120
+ @icmp = nil
121
+ end
122
+
123
+ def self.shutdown
124
+ @@one_click = nil
125
+ end
126
+ end
@@ -0,0 +1,108 @@
1
+ #####################################################################
2
+ # test_net_ping_tcp.rb
3
+ #
4
+ # Test case for the Net::PingTCP class. This test should be run via
5
+ # the 'test' or 'test:tcp' Rake task.
6
+ #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'test/unit'
11
+ require 'net/ping/tcp'
12
+ include Net
13
+
14
+ class TC_PingTCP < Test::Unit::TestCase
15
+ def setup
16
+ @host = 'www.ruby-lang.org'
17
+ @port = 'ftp'
18
+ @tcp = Ping::TCP.new(@host, @port)
19
+ end
20
+
21
+ def test_ping
22
+ assert_respond_to(@tcp, :ping)
23
+ assert_nothing_raised{ @tcp.ping }
24
+ assert_nothing_raised{ @tcp.ping(@host) }
25
+ end
26
+
27
+ def test_ping_aliases
28
+ assert_respond_to(@tcp, :ping?)
29
+ assert_respond_to(@tcp, :pingecho)
30
+ assert_nothing_raised{ @tcp.ping? }
31
+ assert_nothing_raised{ @tcp.ping?(@host) }
32
+ assert_nothing_raised{ @tcp.pingecho }
33
+ assert_nothing_raised{ @tcp.pingecho(@host) }
34
+ end
35
+
36
+ def test_ping_service_check_false
37
+ msg = "+this test may fail depending on your network environment+"
38
+ Ping::TCP.service_check = false
39
+ @tcp = Ping::TCP.new('localhost')
40
+ assert_false(@tcp.ping?, msg)
41
+ assert_false(@tcp.exception.nil?, "Bad exception data")
42
+ end
43
+
44
+ def test_ping_service_check_true
45
+ msg = "+this test may fail depending on your network environment+"
46
+ Ping::TCP.service_check = true
47
+ assert_true(@tcp.ping?, msg)
48
+ end
49
+
50
+ def test_service_check
51
+ assert_respond_to(Ping::TCP, :service_check)
52
+ assert_respond_to(Ping::TCP, :service_check=)
53
+ end
54
+
55
+ # These will be removed eventually
56
+ def test_service_check_aliases
57
+ assert_respond_to(Ping::TCP, :econnrefused)
58
+ assert_respond_to(Ping::TCP, :econnrefused=)
59
+ assert_respond_to(Ping::TCP, :ecr)
60
+ assert_respond_to(Ping::TCP, :ecr=)
61
+ end
62
+
63
+ def test_service_check_expected_errors
64
+ assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
65
+ end
66
+
67
+ # If the ping failed, the duration will be nil
68
+ def test_duration
69
+ assert_nothing_raised{ @tcp.ping }
70
+ assert_respond_to(@tcp, :duration)
71
+ omit_if(@tcp.duration.nil?, 'ping failed, skipping')
72
+ assert_kind_of(Float, @tcp.duration)
73
+ end
74
+
75
+ def test_host
76
+ assert_respond_to(@tcp, :host)
77
+ assert_respond_to(@tcp, :host=)
78
+ assert_equal(@host, @tcp.host)
79
+ end
80
+
81
+ def test_port
82
+ assert_respond_to(@tcp, :port)
83
+ assert_respond_to(@tcp, :port=)
84
+ assert_equal('ftp', @tcp.port)
85
+ end
86
+
87
+ def test_timeout
88
+ assert_respond_to(@tcp, :timeout)
89
+ assert_respond_to(@tcp, :timeout=)
90
+ assert_equal(5, @tcp.timeout)
91
+ end
92
+
93
+ def test_exception
94
+ msg = "+this test may fail depending on your network environment+"
95
+ assert_respond_to(@tcp, :exception)
96
+ assert_nothing_raised{ @tcp.ping }
97
+ assert_nil(@tcp.exception, msg)
98
+ end
99
+
100
+ def test_warning
101
+ assert_respond_to(@tcp, :warning)
102
+ end
103
+
104
+ def teardown
105
+ @host = nil
106
+ @tcp = nil
107
+ end
108
+ end