net-ping 1.7.1-universal-mingw32 → 1.7.2-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/CHANGES +309 -298
- data/Gemfile +2 -2
- data/MANIFEST +0 -1
- data/README +62 -57
- data/Rakefile +94 -94
- data/doc/ping.txt +246 -246
- data/lib/net/ping.rb +17 -17
- data/lib/net/ping/external.rb +74 -122
- data/lib/net/ping/http.rb +171 -159
- data/lib/net/ping/icmp.rb +178 -179
- data/lib/net/ping/ping.rb +89 -89
- data/lib/net/ping/tcp.rb +102 -102
- data/net-ping.gemspec +40 -46
- data/test/test_net_ping.rb +35 -35
- data/test/test_net_ping_external.rb +129 -129
- data/test/test_net_ping_http.rb +230 -210
- data/test/test_net_ping_icmp.rb +139 -139
- data/test/test_net_ping_tcp.rb +105 -105
- data/test/test_net_ping_udp.rb +119 -119
- data/test/test_net_ping_wmi.rb +81 -81
- metadata +20 -33
- data/lib/net/ping/helper.rb +0 -33
data/test/test_net_ping_http.rb
CHANGED
@@ -1,210 +1,230 @@
|
|
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 'test-unit'
|
8
|
-
require 'fakeweb'
|
9
|
-
require 'net/ping/http'
|
10
|
-
|
11
|
-
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
ENV['http_proxy'] = ENV['https_proxy'] = ENV['no_proxy'] = nil
|
14
|
-
@uri = 'http://www.google.com/index.html'
|
15
|
-
@uri_https = 'https://encrypted.google.com'
|
16
|
-
@proxy = 'http://username:password@proxymoxie:3128'
|
17
|
-
FakeWeb.allow_net_connect = false
|
18
|
-
|
19
|
-
FakeWeb.register_uri(:get, @uri, :body => "PONG")
|
20
|
-
FakeWeb.register_uri(:head, @uri, :body => "PONG")
|
21
|
-
FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
|
22
|
-
FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
|
23
|
-
FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
|
24
|
-
:body => "PONG",
|
25
|
-
:location => "#{@uri}",
|
26
|
-
:status => ["302", "Found"])
|
27
|
-
|
28
|
-
FakeWeb.register_uri(:any, 'http://www.blabfoobarurghxxxx.com', :exception => SocketError)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
@http
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@http =
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
@http
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
@http = Net::Ping::HTTP.new(@uri_https)
|
193
|
-
@http.
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
@
|
208
|
-
|
209
|
-
|
210
|
-
|
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 'test-unit'
|
8
|
+
require 'fakeweb'
|
9
|
+
require 'net/ping/http'
|
10
|
+
|
11
|
+
class TC_Net_Ping_HTTP < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
ENV['http_proxy'] = ENV['https_proxy'] = ENV['no_proxy'] = nil
|
14
|
+
@uri = 'http://www.google.com/index.html'
|
15
|
+
@uri_https = 'https://encrypted.google.com'
|
16
|
+
@proxy = 'http://username:password@proxymoxie:3128'
|
17
|
+
FakeWeb.allow_net_connect = false
|
18
|
+
|
19
|
+
FakeWeb.register_uri(:get, @uri, :body => "PONG")
|
20
|
+
FakeWeb.register_uri(:head, @uri, :body => "PONG")
|
21
|
+
FakeWeb.register_uri(:head, @uri_https, :body => "PONG")
|
22
|
+
FakeWeb.register_uri(:get, @uri_https, :body => "PONG")
|
23
|
+
FakeWeb.register_uri(:head, "http://jigsaw.w3.org/HTTP/300/302.html",
|
24
|
+
:body => "PONG",
|
25
|
+
:location => "#{@uri}",
|
26
|
+
:status => ["302", "Found"])
|
27
|
+
|
28
|
+
FakeWeb.register_uri(:any, 'http://www.blabfoobarurghxxxx.com', :exception => SocketError)
|
29
|
+
FakeWeb.register_uri(:head, 'http://http502.com',
|
30
|
+
:body => "",
|
31
|
+
:status => ["502", "Bad Gateway"])
|
32
|
+
|
33
|
+
@http = Net::Ping::HTTP.new(@uri, 80, 30)
|
34
|
+
@bad = Net::Ping::HTTP.new('http://www.blabfoobarurghxxxx.com') # One hopes not
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'ping basic functionality' do
|
38
|
+
assert_respond_to(@http, :ping)
|
39
|
+
assert_nothing_raised{ @http.ping }
|
40
|
+
end
|
41
|
+
|
42
|
+
test 'ping returns a boolean value' do
|
43
|
+
assert_boolean(@http.ping?)
|
44
|
+
assert_boolean(@bad.ping?)
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'ping? is an alias for ping' do
|
48
|
+
assert_alias_method(@http, :ping?, :ping)
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'pingecho is an alias for ping' do
|
52
|
+
assert_alias_method(@http, :pingecho, :ping)
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'ping should succeed for a valid website' do
|
56
|
+
assert_true(@http.ping?)
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'ping should fail for an invalid website' do
|
60
|
+
assert_false(@bad.ping?)
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'duration basic functionality' do
|
64
|
+
assert_respond_to(@http, :duration)
|
65
|
+
assert_nothing_raised{ @http.ping }
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'duration returns a float value on a successful ping' do
|
69
|
+
assert_true(@http.ping)
|
70
|
+
assert_kind_of(Float, @http.duration)
|
71
|
+
end
|
72
|
+
|
73
|
+
test 'duration is nil on an unsuccessful ping' do
|
74
|
+
assert_false(@bad.ping)
|
75
|
+
assert_nil(@http.duration)
|
76
|
+
end
|
77
|
+
|
78
|
+
test 'host attribute basic functionality' do
|
79
|
+
assert_respond_to(@http, :host)
|
80
|
+
assert_respond_to(@http, :host=)
|
81
|
+
assert_equal('http://www.google.com/index.html', @http.host)
|
82
|
+
end
|
83
|
+
|
84
|
+
test 'uri is an alias for host' do
|
85
|
+
assert_alias_method(@http, :uri, :host)
|
86
|
+
assert_alias_method(@http, :uri=, :host=)
|
87
|
+
end
|
88
|
+
|
89
|
+
test 'port attribute basic functionality' do
|
90
|
+
assert_respond_to(@http, :port)
|
91
|
+
assert_respond_to(@http, :port=)
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'port attribute expected value' do
|
95
|
+
assert_equal(80, @http.port)
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'timeout attribute basic functionality' do
|
99
|
+
assert_respond_to(@http, :timeout)
|
100
|
+
assert_respond_to(@http, :timeout=)
|
101
|
+
end
|
102
|
+
|
103
|
+
test 'timeout attribute expected values' do
|
104
|
+
assert_equal(30, @http.timeout)
|
105
|
+
assert_equal(5, @bad.timeout)
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'exception attribute basic functionality' do
|
109
|
+
assert_respond_to(@http, :exception)
|
110
|
+
assert_nil(@http.exception)
|
111
|
+
end
|
112
|
+
|
113
|
+
test 'exception attribute is nil if the ping is successful' do
|
114
|
+
assert_true(@http.ping)
|
115
|
+
assert_nil(@http.exception)
|
116
|
+
end
|
117
|
+
|
118
|
+
test 'exception attribute is not nil if the ping is unsuccessful' do
|
119
|
+
assert_false(@bad.ping)
|
120
|
+
assert_not_nil(@bad.exception)
|
121
|
+
end
|
122
|
+
|
123
|
+
test 'warning attribute basic functionality' do
|
124
|
+
assert_respond_to(@http, :warning)
|
125
|
+
assert_nil(@http.warning)
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'code attribute is set' do
|
129
|
+
assert_true(@http.ping)
|
130
|
+
assert_equal('200', @http.code)
|
131
|
+
end
|
132
|
+
|
133
|
+
test 'user_agent accessor is defined' do
|
134
|
+
assert_respond_to(@http, :user_agent)
|
135
|
+
assert_respond_to(@http, :user_agent=)
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'user_agent defaults to nil' do
|
139
|
+
assert_nil(@http.user_agent)
|
140
|
+
end
|
141
|
+
|
142
|
+
test 'ping with user agent' do
|
143
|
+
@http.user_agent = "KDDI-CA32"
|
144
|
+
assert_true(@http.ping)
|
145
|
+
end
|
146
|
+
|
147
|
+
test 'redirect_limit accessor is defined' do
|
148
|
+
assert_respond_to(@http, :redirect_limit)
|
149
|
+
assert_respond_to(@http, :redirect_limit=)
|
150
|
+
end
|
151
|
+
|
152
|
+
test 'redirect_limit defaults to 5' do
|
153
|
+
assert_equal(5, @http.redirect_limit)
|
154
|
+
end
|
155
|
+
|
156
|
+
test 'redirects succeed by default' do
|
157
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
158
|
+
assert_true(@http.ping)
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'redirect fail if follow_redirect is set to false' do
|
162
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
163
|
+
@http.follow_redirect = false
|
164
|
+
assert_false(@http.ping)
|
165
|
+
end
|
166
|
+
|
167
|
+
test 'ping with redirect limit set to zero fails' do
|
168
|
+
@http = Net::Ping::HTTP.new("http://jigsaw.w3.org/HTTP/300/302.html")
|
169
|
+
@http.redirect_limit = 0
|
170
|
+
assert_false(@http.ping)
|
171
|
+
assert_equal("Redirect limit exceeded", @http.exception)
|
172
|
+
end
|
173
|
+
|
174
|
+
test 'http 502 sets exception' do
|
175
|
+
@http = Net::Ping::HTTP.new("http://http502.com")
|
176
|
+
assert_false(@http.ping)
|
177
|
+
assert_equal('Bad Gateway', @http.exception)
|
178
|
+
end
|
179
|
+
|
180
|
+
test 'http 502 sets code' do
|
181
|
+
@http = Net::Ping::HTTP.new("http://http502.com")
|
182
|
+
assert_false(@http.ping)
|
183
|
+
assert_equal('502', @http.code)
|
184
|
+
end
|
185
|
+
|
186
|
+
test 'ping against https site defaults to port 443' do
|
187
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
188
|
+
assert_equal(443, @http.port)
|
189
|
+
end
|
190
|
+
|
191
|
+
test 'ping against https site works as expected' do
|
192
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
193
|
+
assert_true(@http.ping)
|
194
|
+
end
|
195
|
+
|
196
|
+
test 'ping with get option' do
|
197
|
+
@http = Net::Ping::HTTP.new(@uri)
|
198
|
+
@http.get_request = true
|
199
|
+
assert_true(@http.ping)
|
200
|
+
end
|
201
|
+
|
202
|
+
test 'ping with http proxy' do
|
203
|
+
ENV['http_proxy'] = "http://proxymoxie:3128"
|
204
|
+
@http = Net::Ping::HTTP.new(@uri)
|
205
|
+
@http.get_request = true
|
206
|
+
assert_true(@http.ping)
|
207
|
+
assert_true(@http.proxied)
|
208
|
+
end
|
209
|
+
|
210
|
+
test 'ping with https proxy' do
|
211
|
+
ENV['https_proxy'] = "http://proxymoxie:3128"
|
212
|
+
@http = Net::Ping::HTTP.new(@uri_https)
|
213
|
+
@http.get_request = true
|
214
|
+
assert_true(@http.ping)
|
215
|
+
assert_true(@http.proxied)
|
216
|
+
end
|
217
|
+
|
218
|
+
test 'ping with no_proxy' do
|
219
|
+
ENV['no_proxy'] = "google.com"
|
220
|
+
@http = Net::Ping::HTTP.new(@uri)
|
221
|
+
@http.get_request = true
|
222
|
+
assert_true(@http.ping)
|
223
|
+
assert_false(@http.proxied)
|
224
|
+
end
|
225
|
+
|
226
|
+
def teardown
|
227
|
+
@uri = nil
|
228
|
+
@http = nil
|
229
|
+
end
|
230
|
+
end
|
data/test/test_net_ping_icmp.rb
CHANGED
@@ -1,139 +1,139 @@
|
|
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 'test-unit'
|
9
|
-
require 'net/ping/icmp'
|
10
|
-
|
11
|
-
if File::ALT_SEPARATOR
|
12
|
-
require 'win32/security'
|
13
|
-
|
14
|
-
unless Win32::Security.elevated_security?
|
15
|
-
raise "The test:icmp task must be run with elevated security rights"
|
16
|
-
end
|
17
|
-
else
|
18
|
-
unless Process.euid == 0
|
19
|
-
raise "The test:icmp task must be run with root privileges"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class TC_PingICMP < Test::Unit::TestCase
|
24
|
-
def setup
|
25
|
-
@host = '127.0.0.1' # 'localhost'
|
26
|
-
@icmp = Net::Ping::ICMP.new(@host)
|
27
|
-
end
|
28
|
-
|
29
|
-
test "icmp ping basic functionality" do
|
30
|
-
assert_respond_to(@icmp, :ping)
|
31
|
-
assert_nothing_raised{ @icmp.ping }
|
32
|
-
end
|
33
|
-
|
34
|
-
test "icmp ping accepts a host" do
|
35
|
-
assert_nothing_raised{ @icmp.ping(@host) }
|
36
|
-
end
|
37
|
-
|
38
|
-
test "icmp ping returns a boolean" do
|
39
|
-
assert_boolean(@icmp.ping)
|
40
|
-
assert_boolean(@icmp.ping(@host))
|
41
|
-
end
|
42
|
-
|
43
|
-
test "icmp ping of local host is successful" do
|
44
|
-
assert_true(Net::Ping::ICMP.new(@host).ping?)
|
45
|
-
assert_true(Net::Ping::ICMP.new('192.168.0.1').ping?)
|
46
|
-
end
|
47
|
-
|
48
|
-
test "ping? is an alias for ping" do
|
49
|
-
assert_respond_to(@icmp, :ping?)
|
50
|
-
assert_alias_method(@icmp, :ping?, :ping)
|
51
|
-
end
|
52
|
-
|
53
|
-
test "pingecho is an alias for ping" do
|
54
|
-
assert_respond_to(@icmp, :pingecho)
|
55
|
-
assert_alias_method(@icmp, :pingecho, :ping)
|
56
|
-
end
|
57
|
-
|
58
|
-
test "icmp ping fails if host is invalid" do
|
59
|
-
assert_false(Net::Ping::ICMP.new('bogus').ping?)
|
60
|
-
assert_false(Net::Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
61
|
-
end
|
62
|
-
|
63
|
-
test "bind method basic functionality" do
|
64
|
-
assert_respond_to(@icmp, :bind)
|
65
|
-
assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
|
66
|
-
assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
|
67
|
-
end
|
68
|
-
|
69
|
-
test "duration method basic functionality" do
|
70
|
-
assert_nothing_raised{ @icmp.ping }
|
71
|
-
assert_respond_to(@icmp, :duration)
|
72
|
-
assert_kind_of(Float, @icmp.duration)
|
73
|
-
end
|
74
|
-
|
75
|
-
test "host getter method basic functionality" do
|
76
|
-
assert_respond_to(@icmp, :host)
|
77
|
-
assert_equal(@host, @icmp.host)
|
78
|
-
end
|
79
|
-
|
80
|
-
test "host setter method basic functionality" do
|
81
|
-
assert_respond_to(@icmp, :host=)
|
82
|
-
assert_nothing_raised{ @icmp.host = '192.168.0.1' }
|
83
|
-
assert_equal(@icmp.host, '192.168.0.1')
|
84
|
-
end
|
85
|
-
|
86
|
-
test "port method basic functionality" do
|
87
|
-
assert_respond_to(@icmp, :port)
|
88
|
-
assert_equal(nil, @icmp.port)
|
89
|
-
end
|
90
|
-
|
91
|
-
test "timeout getter method basic functionality" do
|
92
|
-
assert_respond_to(@icmp, :timeout)
|
93
|
-
assert_equal(5, @icmp.timeout)
|
94
|
-
end
|
95
|
-
|
96
|
-
test "timeout setter method basic functionality" do
|
97
|
-
assert_respond_to(@icmp, :timeout=)
|
98
|
-
assert_nothing_raised{ @icmp.timeout = 7 }
|
99
|
-
assert_equal(7, @icmp.timeout)
|
100
|
-
end
|
101
|
-
|
102
|
-
test "exception method basic functionality" do
|
103
|
-
assert_respond_to(@icmp, :exception)
|
104
|
-
assert_nothing_raised{ @icmp.ping }
|
105
|
-
end
|
106
|
-
|
107
|
-
test "exception method returns nil if no ping has happened yet" do
|
108
|
-
assert_nil(@icmp.exception)
|
109
|
-
end
|
110
|
-
|
111
|
-
test "warning method basic functionality" do
|
112
|
-
assert_respond_to(@icmp, :warning)
|
113
|
-
end
|
114
|
-
|
115
|
-
test "data_size getter method basic functionality" do
|
116
|
-
assert_respond_to(@icmp, :data_size)
|
117
|
-
assert_nothing_raised{ @icmp.data_size }
|
118
|
-
assert_kind_of(Numeric, @icmp.data_size)
|
119
|
-
end
|
120
|
-
|
121
|
-
test "data_size returns expected value" do
|
122
|
-
assert_equal(56, @icmp.data_size)
|
123
|
-
end
|
124
|
-
|
125
|
-
test "data_size setter method basic functionality" do
|
126
|
-
assert_respond_to(@icmp, :data_size=)
|
127
|
-
assert_nothing_raised{ @icmp.data_size = 22 }
|
128
|
-
end
|
129
|
-
|
130
|
-
test "setting an odd data_size is valid" do
|
131
|
-
assert_nothing_raised{ @icmp.data_size = 57 }
|
132
|
-
assert_boolean(@icmp.ping)
|
133
|
-
end
|
134
|
-
|
135
|
-
def teardown
|
136
|
-
@host = nil
|
137
|
-
@icmp = nil
|
138
|
-
end
|
139
|
-
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 'test-unit'
|
9
|
+
require 'net/ping/icmp'
|
10
|
+
|
11
|
+
if File::ALT_SEPARATOR
|
12
|
+
require 'win32/security'
|
13
|
+
|
14
|
+
unless Win32::Security.elevated_security?
|
15
|
+
raise "The test:icmp task must be run with elevated security rights"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
unless Process.euid == 0
|
19
|
+
raise "The test:icmp task must be run with root privileges"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TC_PingICMP < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
@host = '127.0.0.1' # 'localhost'
|
26
|
+
@icmp = Net::Ping::ICMP.new(@host)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "icmp ping basic functionality" do
|
30
|
+
assert_respond_to(@icmp, :ping)
|
31
|
+
assert_nothing_raised{ @icmp.ping }
|
32
|
+
end
|
33
|
+
|
34
|
+
test "icmp ping accepts a host" do
|
35
|
+
assert_nothing_raised{ @icmp.ping(@host) }
|
36
|
+
end
|
37
|
+
|
38
|
+
test "icmp ping returns a boolean" do
|
39
|
+
assert_boolean(@icmp.ping)
|
40
|
+
assert_boolean(@icmp.ping(@host))
|
41
|
+
end
|
42
|
+
|
43
|
+
test "icmp ping of local host is successful" do
|
44
|
+
assert_true(Net::Ping::ICMP.new(@host).ping?)
|
45
|
+
assert_true(Net::Ping::ICMP.new('192.168.0.1').ping?)
|
46
|
+
end
|
47
|
+
|
48
|
+
test "ping? is an alias for ping" do
|
49
|
+
assert_respond_to(@icmp, :ping?)
|
50
|
+
assert_alias_method(@icmp, :ping?, :ping)
|
51
|
+
end
|
52
|
+
|
53
|
+
test "pingecho is an alias for ping" do
|
54
|
+
assert_respond_to(@icmp, :pingecho)
|
55
|
+
assert_alias_method(@icmp, :pingecho, :ping)
|
56
|
+
end
|
57
|
+
|
58
|
+
test "icmp ping fails if host is invalid" do
|
59
|
+
assert_false(Net::Ping::ICMP.new('bogus').ping?)
|
60
|
+
assert_false(Net::Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
|
61
|
+
end
|
62
|
+
|
63
|
+
test "bind method basic functionality" do
|
64
|
+
assert_respond_to(@icmp, :bind)
|
65
|
+
assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
|
66
|
+
assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
|
67
|
+
end
|
68
|
+
|
69
|
+
test "duration method basic functionality" do
|
70
|
+
assert_nothing_raised{ @icmp.ping }
|
71
|
+
assert_respond_to(@icmp, :duration)
|
72
|
+
assert_kind_of(Float, @icmp.duration)
|
73
|
+
end
|
74
|
+
|
75
|
+
test "host getter method basic functionality" do
|
76
|
+
assert_respond_to(@icmp, :host)
|
77
|
+
assert_equal(@host, @icmp.host)
|
78
|
+
end
|
79
|
+
|
80
|
+
test "host setter method basic functionality" do
|
81
|
+
assert_respond_to(@icmp, :host=)
|
82
|
+
assert_nothing_raised{ @icmp.host = '192.168.0.1' }
|
83
|
+
assert_equal(@icmp.host, '192.168.0.1')
|
84
|
+
end
|
85
|
+
|
86
|
+
test "port method basic functionality" do
|
87
|
+
assert_respond_to(@icmp, :port)
|
88
|
+
assert_equal(nil, @icmp.port)
|
89
|
+
end
|
90
|
+
|
91
|
+
test "timeout getter method basic functionality" do
|
92
|
+
assert_respond_to(@icmp, :timeout)
|
93
|
+
assert_equal(5, @icmp.timeout)
|
94
|
+
end
|
95
|
+
|
96
|
+
test "timeout setter method basic functionality" do
|
97
|
+
assert_respond_to(@icmp, :timeout=)
|
98
|
+
assert_nothing_raised{ @icmp.timeout = 7 }
|
99
|
+
assert_equal(7, @icmp.timeout)
|
100
|
+
end
|
101
|
+
|
102
|
+
test "exception method basic functionality" do
|
103
|
+
assert_respond_to(@icmp, :exception)
|
104
|
+
assert_nothing_raised{ @icmp.ping }
|
105
|
+
end
|
106
|
+
|
107
|
+
test "exception method returns nil if no ping has happened yet" do
|
108
|
+
assert_nil(@icmp.exception)
|
109
|
+
end
|
110
|
+
|
111
|
+
test "warning method basic functionality" do
|
112
|
+
assert_respond_to(@icmp, :warning)
|
113
|
+
end
|
114
|
+
|
115
|
+
test "data_size getter method basic functionality" do
|
116
|
+
assert_respond_to(@icmp, :data_size)
|
117
|
+
assert_nothing_raised{ @icmp.data_size }
|
118
|
+
assert_kind_of(Numeric, @icmp.data_size)
|
119
|
+
end
|
120
|
+
|
121
|
+
test "data_size returns expected value" do
|
122
|
+
assert_equal(56, @icmp.data_size)
|
123
|
+
end
|
124
|
+
|
125
|
+
test "data_size setter method basic functionality" do
|
126
|
+
assert_respond_to(@icmp, :data_size=)
|
127
|
+
assert_nothing_raised{ @icmp.data_size = 22 }
|
128
|
+
end
|
129
|
+
|
130
|
+
test "setting an odd data_size is valid" do
|
131
|
+
assert_nothing_raised{ @icmp.data_size = 57 }
|
132
|
+
assert_boolean(@icmp.ping)
|
133
|
+
end
|
134
|
+
|
135
|
+
def teardown
|
136
|
+
@host = nil
|
137
|
+
@icmp = nil
|
138
|
+
end
|
139
|
+
end
|