net-ping 1.4.1-x86-mingw32 → 1.5.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,176 +1,182 @@
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
- @uri_https = 'https://encrypted.google.com'
17
-
18
- FakeWeb.register_uri(:get, @uri, :body => "PONG")
19
- FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
20
- FakeWeb.register_uri(:get, "http://jigsaw.w3.org/HTTP/300/302.html",
21
- :body => "PONG",
22
- :location => "#{@uri}",
23
- :status => ["302", "Found"])
24
-
25
- @http = Net::Ping::HTTP.new(@uri, 80, 30)
26
- @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
27
- end
28
-
29
- test 'ping basic functionality' do
30
- assert_respond_to(@http, :ping)
31
- assert_nothing_raised{ @http.ping }
32
- end
33
-
34
- test 'ping returns a boolean value' do
35
- assert_boolean(@http.ping?)
36
- assert_boolean(@bad.ping?)
37
- end
38
-
39
- test 'ping? is an alias for ping' do
40
- assert_alias_method(@http, :ping?, :ping)
41
- end
42
-
43
- test 'pingecho is an alias for ping' do
44
- assert_alias_method(@http, :pingecho, :ping)
45
- end
46
-
47
- test 'ping should succeed for a valid website' do
48
- assert_true(@http.ping?)
49
- end
50
-
51
- test 'ping should fail for an invalid website' do
52
- assert_false(@bad.ping?)
53
- end
54
-
55
- test 'duration basic functionality' do
56
- assert_respond_to(@http, :duration)
57
- assert_nothing_raised{ @http.ping }
58
- end
59
-
60
- test 'duration returns a float value on a successful ping' do
61
- assert_true(@http.ping)
62
- assert_kind_of(Float, @http.duration)
63
- end
64
-
65
- test 'duration is nil on an unsuccessful ping' do
66
- assert_false(@bad.ping)
67
- assert_nil(@http.duration)
68
- end
69
-
70
- test 'host attribute basic functionality' do
71
- assert_respond_to(@http, :host)
72
- assert_respond_to(@http, :host=)
73
- assert_equal('http://www.google.com/index.html', @http.host)
74
- end
75
-
76
- test 'uri is an alias for host' do
77
- assert_alias_method(@http, :uri, :host)
78
- assert_alias_method(@http, :uri=, :host=)
79
- end
80
-
81
- test 'port attribute basic functionality' do
82
- assert_respond_to(@http, :port)
83
- assert_respond_to(@http, :port=)
84
- end
85
-
86
- test 'port attribute expected value' do
87
- assert_equal(80, @http.port)
88
- end
89
-
90
- test 'timeout attribute basic functionality' do
91
- assert_respond_to(@http, :timeout)
92
- assert_respond_to(@http, :timeout=)
93
- end
94
-
95
- test 'timeout attribute expected values' do
96
- assert_equal(30, @http.timeout)
97
- assert_equal(5, @bad.timeout)
98
- end
99
-
100
- test 'exception attribute basic functionality' do
101
- assert_respond_to(@http, :exception)
102
- assert_nil(@http.exception)
103
- end
104
-
105
- test 'exception attribute is nil if the ping is successful' do
106
- assert_true(@http.ping)
107
- assert_nil(@http.exception)
108
- end
109
-
110
- test 'exception attribute is not nil if the ping is unsuccessful' do
111
- assert_false(@bad.ping)
112
- assert_not_nil(@bad.exception)
113
- end
114
-
115
- test 'warning attribute basic functionality' do
116
- assert_respond_to(@http, :warning)
117
- assert_nil(@http.warning)
118
- end
119
-
120
- test 'user_agent accessor is defined' do
121
- assert_respond_to(@http, :user_agent)
122
- assert_respond_to(@http, :user_agent=)
123
- end
124
-
125
- test 'user_agent defaults to nil' do
126
- assert_nil(@http.user_agent)
127
- end
128
-
129
- test 'ping with user agent' do
130
- @http.user_agent = "KDDI-CA32"
131
- assert_true(@http.ping)
132
- end
133
-
134
- test 'redirect_limit accessor is defined' do
135
- assert_respond_to(@http, :redirect_limit)
136
- assert_respond_to(@http, :redirect_limit=)
137
- end
138
-
139
- test 'redirect_limit defaults to 5' do
140
- assert_equal(5, @http.redirect_limit)
141
- end
142
-
143
- test 'redirects succeed by default' do
144
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
145
- assert_true(@http.ping)
146
- end
147
-
148
- test 'redirect fail if follow_redirect is set to false' do
149
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
150
- @http.follow_redirect = false
151
- assert_false(@http.ping)
152
- end
153
-
154
- test 'ping with redirect limit set to zero fails' do
155
- @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
156
- @http.redirect_limit = 0
157
- assert_false(@http.ping)
158
- assert_equal("Redirect limit exceeded", @http.exception)
159
- end
160
-
161
- test 'ping against https site defaults to port 443' do
162
- @http = Net::Ping::HTTP.new(@uri_https)
163
- assert_equal(443, @http.port)
164
- end
165
-
166
- # This will generate a warning. Nothing I can do about it.
167
- test 'ping against https site works as expected' do
168
- @http = Net::Ping::HTTP.new(@uri_https)
169
- assert_true(@http.ping)
170
- end
171
-
172
- def teardown
173
- @uri = nil
174
- @http = nil
175
- end
176
- end
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
+ @uri_https = 'https://encrypted.google.com'
17
+
18
+ FakeWeb.register_uri(:get, @uri, :body => "PONG")
19
+ FakeWeb.register_uri(:head, @uri, :body => "PONG")
20
+ FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
21
+ FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
22
+ :body => "PONG",
23
+ :location => "#{@uri}",
24
+ :status => ["302", "Found"])
25
+
26
+ @http = Net::Ping::HTTP.new(@uri, 80, 30)
27
+ @bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
28
+ end
29
+
30
+ test 'ping basic functionality' do
31
+ assert_respond_to(@http, :ping)
32
+ assert_nothing_raised{ @http.ping }
33
+ end
34
+
35
+ test 'ping returns a boolean value' do
36
+ assert_boolean(@http.ping?)
37
+ assert_boolean(@bad.ping?)
38
+ end
39
+
40
+ test 'ping? is an alias for ping' do
41
+ assert_alias_method(@http, :ping?, :ping)
42
+ end
43
+
44
+ test 'pingecho is an alias for ping' do
45
+ assert_alias_method(@http, :pingecho, :ping)
46
+ end
47
+
48
+ test 'ping should succeed for a valid website' do
49
+ assert_true(@http.ping?)
50
+ end
51
+
52
+ test 'ping should fail for an invalid website' do
53
+ assert_false(@bad.ping?)
54
+ end
55
+
56
+ test 'duration basic functionality' do
57
+ assert_respond_to(@http, :duration)
58
+ assert_nothing_raised{ @http.ping }
59
+ end
60
+
61
+ test 'duration returns a float value on a successful ping' do
62
+ assert_true(@http.ping)
63
+ assert_kind_of(Float, @http.duration)
64
+ end
65
+
66
+ test 'duration is nil on an unsuccessful ping' do
67
+ assert_false(@bad.ping)
68
+ assert_nil(@http.duration)
69
+ end
70
+
71
+ test 'host attribute basic functionality' do
72
+ assert_respond_to(@http, :host)
73
+ assert_respond_to(@http, :host=)
74
+ assert_equal('http://www.google.com/index.html', @http.host)
75
+ end
76
+
77
+ test 'uri is an alias for host' do
78
+ assert_alias_method(@http, :uri, :host)
79
+ assert_alias_method(@http, :uri=, :host=)
80
+ end
81
+
82
+ test 'port attribute basic functionality' do
83
+ assert_respond_to(@http, :port)
84
+ assert_respond_to(@http, :port=)
85
+ end
86
+
87
+ test 'port attribute expected value' do
88
+ assert_equal(80, @http.port)
89
+ end
90
+
91
+ test 'timeout attribute basic functionality' do
92
+ assert_respond_to(@http, :timeout)
93
+ assert_respond_to(@http, :timeout=)
94
+ end
95
+
96
+ test 'timeout attribute expected values' do
97
+ assert_equal(30, @http.timeout)
98
+ assert_equal(5, @bad.timeout)
99
+ end
100
+
101
+ test 'exception attribute basic functionality' do
102
+ assert_respond_to(@http, :exception)
103
+ assert_nil(@http.exception)
104
+ end
105
+
106
+ test 'exception attribute is nil if the ping is successful' do
107
+ assert_true(@http.ping)
108
+ assert_nil(@http.exception)
109
+ end
110
+
111
+ test 'exception attribute is not nil if the ping is unsuccessful' do
112
+ assert_false(@bad.ping)
113
+ assert_not_nil(@bad.exception)
114
+ end
115
+
116
+ test 'warning attribute basic functionality' do
117
+ assert_respond_to(@http, :warning)
118
+ assert_nil(@http.warning)
119
+ end
120
+
121
+ test 'user_agent accessor is defined' do
122
+ assert_respond_to(@http, :user_agent)
123
+ assert_respond_to(@http, :user_agent=)
124
+ end
125
+
126
+ test 'user_agent defaults to nil' do
127
+ assert_nil(@http.user_agent)
128
+ end
129
+
130
+ test 'ping with user agent' do
131
+ @http.user_agent = "KDDI-CA32"
132
+ assert_true(@http.ping)
133
+ end
134
+
135
+ test 'redirect_limit accessor is defined' do
136
+ assert_respond_to(@http, :redirect_limit)
137
+ assert_respond_to(@http, :redirect_limit=)
138
+ end
139
+
140
+ test 'redirect_limit defaults to 5' do
141
+ assert_equal(5, @http.redirect_limit)
142
+ end
143
+
144
+ test 'redirects succeed by default' do
145
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
146
+ assert_true(@http.ping)
147
+ end
148
+
149
+ test 'redirect fail if follow_redirect is set to false' do
150
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
151
+ @http.follow_redirect = false
152
+ assert_false(@http.ping)
153
+ end
154
+
155
+ test 'ping with redirect limit set to zero fails' do
156
+ @http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
157
+ @http.redirect_limit = 0
158
+ assert_false(@http.ping)
159
+ assert_equal("Redirect limit exceeded", @http.exception)
160
+ end
161
+
162
+ test 'ping against https site defaults to port 443' do
163
+ @http = Net::Ping::HTTP.new(@uri_https)
164
+ assert_equal(443, @http.port)
165
+ end
166
+
167
+ test 'ping against https site works as expected' do
168
+ @http = Net::Ping::HTTP.new(@uri_https)
169
+ assert_true(@http.ping)
170
+ end
171
+
172
+ test 'ping with get option' do
173
+ @http = Net::Ping::HTTP.new(@uri)
174
+ @http.get_request = true
175
+ assert_true(@http.ping)
176
+ end
177
+
178
+ def teardown
179
+ @uri = nil
180
+ @http = nil
181
+ end
182
+ end
@@ -1,116 +1,120 @@
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
- if File::ALT_SEPARATOR
16
- require 'win32/security'
17
- require 'windows/system_info'
18
- include Windows::SystemInfo
19
-
20
- if windows_version >= 6 && !Win32::Security.elevated_security?
21
- raise "The test:icmp task must be run with elevated security rights"
22
- end
23
- else
24
- unless Process.euid == 0
25
- raise "The test:icmp task must be run with root privileges"
26
- end
27
- end
28
-
29
- class TC_PingICMP < Test::Unit::TestCase
30
- def setup
31
- @host = 'localhost'
32
- @icmp = Ping::ICMP.new(@host)
33
- end
34
-
35
- def test_ping
36
- assert_respond_to(@icmp, :ping)
37
- assert_nothing_raised{ @icmp.ping }
38
- assert_nothing_raised{ @icmp.ping(@host) }
39
- end
40
-
41
- def test_ping_aliases_basic
42
- assert_respond_to(@icmp, :ping?)
43
- assert_respond_to(@icmp, :pingecho)
44
- assert_nothing_raised{ @icmp.ping? }
45
- assert_nothing_raised{ @icmp.ping?(@host) }
46
- end
47
-
48
- def test_ping_returns_boolean
49
- assert_boolean(@icmp.pingecho)
50
- assert_boolean(@icmp.pingecho(@host))
51
- end
52
-
53
- def test_ping_expected_failure
54
- assert_false(Ping::ICMP.new('bogus').ping?)
55
- assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
56
- end
57
-
58
- def test_bind
59
- assert_respond_to(@icmp, :bind)
60
- assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
61
- assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
62
- end
63
-
64
- def test_duration
65
- assert_nothing_raised{ @icmp.ping }
66
- assert_respond_to(@icmp, :duration)
67
- assert_kind_of(Float, @icmp.duration)
68
- end
69
-
70
- def test_host
71
- assert_respond_to(@icmp, :host)
72
- assert_respond_to(@icmp, :host=)
73
- assert_equal('localhost', @icmp.host)
74
- end
75
-
76
- def test_port
77
- assert_respond_to(@icmp, :port)
78
- assert_equal(nil, @icmp.port)
79
- end
80
-
81
- def test_timeout
82
- assert_respond_to(@icmp, :timeout)
83
- assert_respond_to(@icmp, :timeout=)
84
- assert_equal(5, @icmp.timeout)
85
- end
86
-
87
- def test_exception
88
- assert_respond_to(@icmp, :exception)
89
- assert_nothing_raised{ @icmp.ping }
90
- assert_nil(@icmp.exception)
91
- end
92
-
93
- def test_warning
94
- assert_respond_to(@icmp, :warning)
95
- end
96
-
97
- def test_data_size_get
98
- assert_respond_to(@icmp, :data_size)
99
- assert_equal(56, @icmp.data_size)
100
- end
101
-
102
- def test_data_size_set
103
- assert_respond_to(@icmp, :data_size=)
104
- assert_nothing_raised{ @icmp.data_size = 22 }
105
- end
106
-
107
- def test_odd_data_size_ok
108
- assert_nothing_raised{ @icmp.data_size = 57 }
109
- assert_boolean(@icmp.ping)
110
- end
111
-
112
- def teardown
113
- @host = nil
114
- @icmp = nil
115
- end
116
- end
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
+ if File::ALT_SEPARATOR
16
+ require 'win32/security'
17
+ require 'windows/system_info'
18
+ include Windows::SystemInfo
19
+
20
+ if windows_version >= 6 && !Win32::Security.elevated_security?
21
+ raise "The test:icmp task must be run with elevated security rights"
22
+ end
23
+ else
24
+ unless Process.euid == 0
25
+ raise "The test:icmp task must be run with root privileges"
26
+ end
27
+ end
28
+
29
+ class TC_PingICMP < Test::Unit::TestCase
30
+ def setup
31
+ @host = '127.0.0.1' # 'localhost'
32
+ @icmp = Ping::ICMP.new(@host)
33
+ end
34
+
35
+ def test_ping
36
+ assert_respond_to(@icmp, :ping)
37
+ assert_nothing_raised{ @icmp.ping }
38
+ assert_nothing_raised{ @icmp.ping(@host) }
39
+ end
40
+
41
+ def test_ping_aliases_basic
42
+ assert_respond_to(@icmp, :ping?)
43
+ assert_respond_to(@icmp, :pingecho)
44
+ assert_nothing_raised{ @icmp.ping? }
45
+ assert_nothing_raised{ @icmp.ping?(@host) }
46
+ end
47
+
48
+ def test_ping_returns_boolean
49
+ assert_boolean(@icmp.pingecho)
50
+ assert_boolean(@icmp.pingecho(@host))
51
+ end
52
+
53
+ def test_ping_expected_success
54
+ assert_true(Ping::ICMP.new(@host).ping?)
55
+ end
56
+
57
+ def test_ping_expected_failure
58
+ assert_false(Ping::ICMP.new('bogus').ping?)
59
+ assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
60
+ end
61
+
62
+ def test_bind
63
+ assert_respond_to(@icmp, :bind)
64
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
65
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
66
+ end
67
+
68
+ def test_duration
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(@host, @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
+ assert_nothing_raised{ @icmp.ping }
94
+ assert_nil(@icmp.exception)
95
+ end
96
+
97
+ def test_warning
98
+ assert_respond_to(@icmp, :warning)
99
+ end
100
+
101
+ def test_data_size_get
102
+ assert_respond_to(@icmp, :data_size)
103
+ assert_equal(56, @icmp.data_size)
104
+ end
105
+
106
+ def test_data_size_set
107
+ assert_respond_to(@icmp, :data_size=)
108
+ assert_nothing_raised{ @icmp.data_size = 22 }
109
+ end
110
+
111
+ def test_odd_data_size_ok
112
+ assert_nothing_raised{ @icmp.data_size = 57 }
113
+ assert_boolean(@icmp.ping)
114
+ end
115
+
116
+ def teardown
117
+ @host = nil
118
+ @icmp = nil
119
+ end
120
+ end