net-ping 1.7.4-universal-mingw32 → 1.7.5-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,186 +1,186 @@
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
- require 'thread'
11
-
12
- if File::ALT_SEPARATOR
13
- require 'win32/security'
14
-
15
- unless Win32::Security.elevated_security?
16
- raise "The test:icmp task must be run with elevated security rights"
17
- end
18
- else
19
- unless Process.euid == 0
20
- raise "The test:icmp task must be run with root privileges"
21
- end
22
- end
23
-
24
- class TC_PingICMP < Test::Unit::TestCase
25
- def self.startup
26
- @@jruby = RUBY_PLATFORM == 'java'
27
- end
28
-
29
- def setup
30
- @host = '127.0.0.1' # 'localhost'
31
- @icmp = Net::Ping::ICMP.new(@host)
32
- @concurrency = 3
33
- end
34
-
35
- test "icmp ping basic functionality" do
36
- assert_respond_to(@icmp, :ping)
37
- omit_if(@@jruby)
38
- assert_nothing_raised{ @icmp.ping }
39
- end
40
-
41
- test "icmp ping accepts a host" do
42
- omit_if(@@jruby)
43
- assert_nothing_raised{ @icmp.ping(@host) }
44
- end
45
-
46
- test "icmp ping returns a boolean" do
47
- omit_if(@@jruby)
48
- assert_boolean(@icmp.ping)
49
- assert_boolean(@icmp.ping(@host))
50
- end
51
-
52
- test "icmp ping of local host is successful" do
53
- omit_if(@@jruby)
54
- assert_true(Net::Ping::ICMP.new(@host).ping?)
55
- assert_true(Net::Ping::ICMP.new('192.168.0.1').ping?)
56
- end
57
-
58
- test "threaded icmp ping returns expected results" do
59
- omit_if(@@jruby)
60
- ips = ['8.8.4.4', '8.8.9.9', '127.0.0.1', '8.8.8.8', '8.8.8.9']
61
- queue = Queue.new
62
- threads = []
63
-
64
- ips.each{ |ip| queue << ip }
65
-
66
- @concurrency.times{
67
- threads << Thread.new(queue) do |q|
68
- ip = q.pop
69
- icmp = Net::Ping::ICMP.new(ip, nil, 1)
70
- if ip =~ /9/
71
- assert_false(icmp.ping?)
72
- else
73
- assert_true(icmp.ping?)
74
- end
75
- end
76
- }
77
-
78
- threads.each{ |t| t.join }
79
- end
80
-
81
- test "ping? is an alias for ping" do
82
- assert_respond_to(@icmp, :ping?)
83
- assert_alias_method(@icmp, :ping?, :ping)
84
- end
85
-
86
- test "pingecho is an alias for ping" do
87
- assert_respond_to(@icmp, :pingecho)
88
- assert_alias_method(@icmp, :pingecho, :ping)
89
- end
90
-
91
- test "icmp ping fails if host is invalid" do
92
- omit_if(@@jruby)
93
- assert_false(Net::Ping::ICMP.new('bogus').ping?)
94
- assert_false(Net::Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
95
- end
96
-
97
- test "bind method basic functionality" do
98
- assert_respond_to(@icmp, :bind)
99
- assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
100
- assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
101
- end
102
-
103
- test "duration method basic functionality" do
104
- omit_if(@@jruby)
105
- assert_nothing_raised{ @icmp.ping }
106
- assert_respond_to(@icmp, :duration)
107
- assert_kind_of(Float, @icmp.duration)
108
- end
109
-
110
- test "host getter method basic functionality" do
111
- assert_respond_to(@icmp, :host)
112
- assert_equal(@host, @icmp.host)
113
- end
114
-
115
- test "host setter method basic functionality" do
116
- assert_respond_to(@icmp, :host=)
117
- assert_nothing_raised{ @icmp.host = '192.168.0.1' }
118
- assert_equal(@icmp.host, '192.168.0.1')
119
- end
120
-
121
- test "port method basic functionality" do
122
- assert_respond_to(@icmp, :port)
123
- assert_equal(nil, @icmp.port)
124
- end
125
-
126
- test "timeout getter method basic functionality" do
127
- assert_respond_to(@icmp, :timeout)
128
- assert_equal(5, @icmp.timeout)
129
- end
130
-
131
- test "timeout setter method basic functionality" do
132
- assert_respond_to(@icmp, :timeout=)
133
- assert_nothing_raised{ @icmp.timeout = 7 }
134
- assert_equal(7, @icmp.timeout)
135
- end
136
-
137
- test "timeout works as expected" do
138
- omit_if(@@jruby)
139
- icmp = Net::Ping::ICMP.new('bogus.com', nil, 0.000001)
140
- assert_false(icmp.ping?)
141
- assert_kind_of(Timeout::Error, icmp.exception)
142
- end
143
-
144
- test "exception method basic functionality" do
145
- assert_respond_to(@icmp, :exception)
146
- end
147
-
148
- test "exception method returns nil if no ping has happened yet" do
149
- assert_nil(@icmp.exception)
150
- end
151
-
152
- test "warning method basic functionality" do
153
- assert_respond_to(@icmp, :warning)
154
- end
155
-
156
- test "data_size getter method basic functionality" do
157
- assert_respond_to(@icmp, :data_size)
158
- assert_nothing_raised{ @icmp.data_size }
159
- assert_kind_of(Numeric, @icmp.data_size)
160
- end
161
-
162
- test "data_size returns expected value" do
163
- assert_equal(56, @icmp.data_size)
164
- end
165
-
166
- test "data_size setter method basic functionality" do
167
- assert_respond_to(@icmp, :data_size=)
168
- assert_nothing_raised{ @icmp.data_size = 22 }
169
- end
170
-
171
- test "setting an odd data_size is valid" do
172
- omit_if(@@jruby)
173
- assert_nothing_raised{ @icmp.data_size = 57 }
174
- assert_boolean(@icmp.ping)
175
- end
176
-
177
- def teardown
178
- @host = nil
179
- @icmp = nil
180
- @concurrency = nil
181
- end
182
-
183
- def self.shutdown
184
- @@jruby = nil
185
- end
186
- 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
+ require 'thread'
11
+
12
+ if File::ALT_SEPARATOR
13
+ require 'win32/security'
14
+
15
+ unless Win32::Security.elevated_security?
16
+ raise "The test:icmp task must be run with elevated security rights"
17
+ end
18
+ else
19
+ unless Process.euid == 0
20
+ raise "The test:icmp task must be run with root privileges"
21
+ end
22
+ end
23
+
24
+ class TC_PingICMP < Test::Unit::TestCase
25
+ def self.startup
26
+ @@jruby = RUBY_PLATFORM == 'java'
27
+ end
28
+
29
+ def setup
30
+ @host = '127.0.0.1' # 'localhost'
31
+ @icmp = Net::Ping::ICMP.new(@host)
32
+ @concurrency = 3
33
+ end
34
+
35
+ test "icmp ping basic functionality" do
36
+ assert_respond_to(@icmp, :ping)
37
+ omit_if(@@jruby)
38
+ assert_nothing_raised{ @icmp.ping }
39
+ end
40
+
41
+ test "icmp ping accepts a host" do
42
+ omit_if(@@jruby)
43
+ assert_nothing_raised{ @icmp.ping(@host) }
44
+ end
45
+
46
+ test "icmp ping returns a boolean" do
47
+ omit_if(@@jruby)
48
+ assert_boolean(@icmp.ping)
49
+ assert_boolean(@icmp.ping(@host))
50
+ end
51
+
52
+ test "icmp ping of local host is successful" do
53
+ omit_if(@@jruby)
54
+ assert_true(Net::Ping::ICMP.new(@host).ping?)
55
+ assert_true(Net::Ping::ICMP.new('192.168.0.1').ping?)
56
+ end
57
+
58
+ test "threaded icmp ping returns expected results" do
59
+ omit_if(@@jruby)
60
+ ips = ['8.8.4.4', '8.8.9.9', '127.0.0.1', '8.8.8.8', '8.8.8.9']
61
+ queue = Queue.new
62
+ threads = []
63
+
64
+ ips.each{ |ip| queue << ip }
65
+
66
+ @concurrency.times{
67
+ threads << Thread.new(queue) do |q|
68
+ ip = q.pop
69
+ icmp = Net::Ping::ICMP.new(ip, nil, 1)
70
+ if ip =~ /9/
71
+ assert_false(icmp.ping?)
72
+ else
73
+ assert_true(icmp.ping?)
74
+ end
75
+ end
76
+ }
77
+
78
+ threads.each{ |t| t.join }
79
+ end
80
+
81
+ test "ping? is an alias for ping" do
82
+ assert_respond_to(@icmp, :ping?)
83
+ assert_alias_method(@icmp, :ping?, :ping)
84
+ end
85
+
86
+ test "pingecho is an alias for ping" do
87
+ assert_respond_to(@icmp, :pingecho)
88
+ assert_alias_method(@icmp, :pingecho, :ping)
89
+ end
90
+
91
+ test "icmp ping fails if host is invalid" do
92
+ omit_if(@@jruby)
93
+ assert_false(Net::Ping::ICMP.new('bogus').ping?)
94
+ assert_false(Net::Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
95
+ end
96
+
97
+ test "bind method basic functionality" do
98
+ assert_respond_to(@icmp, :bind)
99
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname) }
100
+ assert_nothing_raised{ @icmp.bind(Socket.gethostname, 80) }
101
+ end
102
+
103
+ test "duration method basic functionality" do
104
+ omit_if(@@jruby)
105
+ assert_nothing_raised{ @icmp.ping }
106
+ assert_respond_to(@icmp, :duration)
107
+ assert_kind_of(Float, @icmp.duration)
108
+ end
109
+
110
+ test "host getter method basic functionality" do
111
+ assert_respond_to(@icmp, :host)
112
+ assert_equal(@host, @icmp.host)
113
+ end
114
+
115
+ test "host setter method basic functionality" do
116
+ assert_respond_to(@icmp, :host=)
117
+ assert_nothing_raised{ @icmp.host = '192.168.0.1' }
118
+ assert_equal(@icmp.host, '192.168.0.1')
119
+ end
120
+
121
+ test "port method basic functionality" do
122
+ assert_respond_to(@icmp, :port)
123
+ assert_equal(nil, @icmp.port)
124
+ end
125
+
126
+ test "timeout getter method basic functionality" do
127
+ assert_respond_to(@icmp, :timeout)
128
+ assert_equal(5, @icmp.timeout)
129
+ end
130
+
131
+ test "timeout setter method basic functionality" do
132
+ assert_respond_to(@icmp, :timeout=)
133
+ assert_nothing_raised{ @icmp.timeout = 7 }
134
+ assert_equal(7, @icmp.timeout)
135
+ end
136
+
137
+ test "timeout works as expected" do
138
+ omit_if(@@jruby)
139
+ icmp = Net::Ping::ICMP.new('bogus.com', nil, 0.000001)
140
+ assert_false(icmp.ping?)
141
+ assert_kind_of(Timeout::Error, icmp.exception)
142
+ end
143
+
144
+ test "exception method basic functionality" do
145
+ assert_respond_to(@icmp, :exception)
146
+ end
147
+
148
+ test "exception method returns nil if no ping has happened yet" do
149
+ assert_nil(@icmp.exception)
150
+ end
151
+
152
+ test "warning method basic functionality" do
153
+ assert_respond_to(@icmp, :warning)
154
+ end
155
+
156
+ test "data_size getter method basic functionality" do
157
+ assert_respond_to(@icmp, :data_size)
158
+ assert_nothing_raised{ @icmp.data_size }
159
+ assert_kind_of(Numeric, @icmp.data_size)
160
+ end
161
+
162
+ test "data_size returns expected value" do
163
+ assert_equal(56, @icmp.data_size)
164
+ end
165
+
166
+ test "data_size setter method basic functionality" do
167
+ assert_respond_to(@icmp, :data_size=)
168
+ assert_nothing_raised{ @icmp.data_size = 22 }
169
+ end
170
+
171
+ test "setting an odd data_size is valid" do
172
+ omit_if(@@jruby)
173
+ assert_nothing_raised{ @icmp.data_size = 57 }
174
+ assert_boolean(@icmp.ping)
175
+ end
176
+
177
+ def teardown
178
+ @host = nil
179
+ @icmp = nil
180
+ @concurrency = nil
181
+ end
182
+
183
+ def self.shutdown
184
+ @@jruby = nil
185
+ end
186
+ end
@@ -1,105 +1,105 @@
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 'test-unit'
8
- require 'net/ping/tcp'
9
- include Net
10
-
11
- class TC_PingTCP < Test::Unit::TestCase
12
- def setup
13
- @host = 'localhost'
14
- @port = 22
15
- @tcp = Ping::TCP.new(@host, @port)
16
- end
17
-
18
- def test_ping
19
- assert_respond_to(@tcp, :ping)
20
- assert_nothing_raised{ @tcp.ping }
21
- assert_nothing_raised{ @tcp.ping(@host) }
22
- end
23
-
24
- def test_ping_aliases
25
- assert_respond_to(@tcp, :ping?)
26
- assert_respond_to(@tcp, :pingecho)
27
- assert_nothing_raised{ @tcp.ping? }
28
- assert_nothing_raised{ @tcp.ping?(@host) }
29
- assert_nothing_raised{ @tcp.pingecho }
30
- assert_nothing_raised{ @tcp.pingecho(@host) }
31
- end
32
-
33
- def test_ping_service_check_false
34
- msg = "+this test may fail depending on your network environment+"
35
- Ping::TCP.service_check = false
36
- @tcp = Ping::TCP.new('localhost')
37
- assert_false(@tcp.ping?, msg)
38
- assert_false(@tcp.exception.nil?, "Bad exception data")
39
- end
40
-
41
- def test_ping_service_check_true
42
- msg = "+this test may fail depending on your network environment+"
43
- Ping::TCP.service_check = true
44
- assert_true(@tcp.ping?, msg)
45
- end
46
-
47
- def test_service_check
48
- assert_respond_to(Ping::TCP, :service_check)
49
- assert_respond_to(Ping::TCP, :service_check=)
50
- end
51
-
52
- # These will be removed eventually
53
- def test_service_check_aliases
54
- assert_respond_to(Ping::TCP, :econnrefused)
55
- assert_respond_to(Ping::TCP, :econnrefused=)
56
- assert_respond_to(Ping::TCP, :ecr)
57
- assert_respond_to(Ping::TCP, :ecr=)
58
- end
59
-
60
- def test_service_check_expected_errors
61
- assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
62
- end
63
-
64
- # If the ping failed, the duration will be nil
65
- def test_duration
66
- assert_nothing_raised{ @tcp.ping }
67
- assert_respond_to(@tcp, :duration)
68
- omit_if(@tcp.duration.nil?, 'ping failed, skipping')
69
- assert_kind_of(Float, @tcp.duration)
70
- end
71
-
72
- def test_host
73
- assert_respond_to(@tcp, :host)
74
- assert_respond_to(@tcp, :host=)
75
- assert_equal(@host, @tcp.host)
76
- end
77
-
78
- def test_port
79
- assert_respond_to(@tcp, :port)
80
- assert_respond_to(@tcp, :port=)
81
- assert_equal(22, @tcp.port)
82
- end
83
-
84
- def test_timeout
85
- assert_respond_to(@tcp, :timeout)
86
- assert_respond_to(@tcp, :timeout=)
87
- assert_equal(5, @tcp.timeout)
88
- end
89
-
90
- def test_exception
91
- msg = "+this test may fail depending on your network environment+"
92
- assert_respond_to(@tcp, :exception)
93
- assert_nothing_raised{ @tcp.ping }
94
- assert_nil(@tcp.exception, msg)
95
- end
96
-
97
- def test_warning
98
- assert_respond_to(@tcp, :warning)
99
- end
100
-
101
- def teardown
102
- @host = nil
103
- @tcp = nil
104
- end
105
- end
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 'test-unit'
8
+ require 'net/ping/tcp'
9
+ include Net
10
+
11
+ class TC_PingTCP < Test::Unit::TestCase
12
+ def setup
13
+ @host = 'localhost'
14
+ @port = 22
15
+ @tcp = Ping::TCP.new(@host, @port)
16
+ end
17
+
18
+ def test_ping
19
+ assert_respond_to(@tcp, :ping)
20
+ assert_nothing_raised{ @tcp.ping }
21
+ assert_nothing_raised{ @tcp.ping(@host) }
22
+ end
23
+
24
+ def test_ping_aliases
25
+ assert_respond_to(@tcp, :ping?)
26
+ assert_respond_to(@tcp, :pingecho)
27
+ assert_nothing_raised{ @tcp.ping? }
28
+ assert_nothing_raised{ @tcp.ping?(@host) }
29
+ assert_nothing_raised{ @tcp.pingecho }
30
+ assert_nothing_raised{ @tcp.pingecho(@host) }
31
+ end
32
+
33
+ def test_ping_service_check_false
34
+ msg = "+this test may fail depending on your network environment+"
35
+ Ping::TCP.service_check = false
36
+ @tcp = Ping::TCP.new('localhost')
37
+ assert_false(@tcp.ping?, msg)
38
+ assert_false(@tcp.exception.nil?, "Bad exception data")
39
+ end
40
+
41
+ def test_ping_service_check_true
42
+ msg = "+this test may fail depending on your network environment+"
43
+ Ping::TCP.service_check = true
44
+ assert_true(@tcp.ping?, msg)
45
+ end
46
+
47
+ def test_service_check
48
+ assert_respond_to(Ping::TCP, :service_check)
49
+ assert_respond_to(Ping::TCP, :service_check=)
50
+ end
51
+
52
+ # These will be removed eventually
53
+ def test_service_check_aliases
54
+ assert_respond_to(Ping::TCP, :econnrefused)
55
+ assert_respond_to(Ping::TCP, :econnrefused=)
56
+ assert_respond_to(Ping::TCP, :ecr)
57
+ assert_respond_to(Ping::TCP, :ecr=)
58
+ end
59
+
60
+ def test_service_check_expected_errors
61
+ assert_raises(ArgumentError){ Ping::TCP.service_check = "blah" }
62
+ end
63
+
64
+ # If the ping failed, the duration will be nil
65
+ def test_duration
66
+ assert_nothing_raised{ @tcp.ping }
67
+ assert_respond_to(@tcp, :duration)
68
+ omit_if(@tcp.duration.nil?, 'ping failed, skipping')
69
+ assert_kind_of(Float, @tcp.duration)
70
+ end
71
+
72
+ def test_host
73
+ assert_respond_to(@tcp, :host)
74
+ assert_respond_to(@tcp, :host=)
75
+ assert_equal(@host, @tcp.host)
76
+ end
77
+
78
+ def test_port
79
+ assert_respond_to(@tcp, :port)
80
+ assert_respond_to(@tcp, :port=)
81
+ assert_equal(22, @tcp.port)
82
+ end
83
+
84
+ def test_timeout
85
+ assert_respond_to(@tcp, :timeout)
86
+ assert_respond_to(@tcp, :timeout=)
87
+ assert_equal(5, @tcp.timeout)
88
+ end
89
+
90
+ def test_exception
91
+ msg = "+this test may fail depending on your network environment+"
92
+ assert_respond_to(@tcp, :exception)
93
+ assert_nothing_raised{ @tcp.ping }
94
+ assert_nil(@tcp.exception, msg)
95
+ end
96
+
97
+ def test_warning
98
+ assert_respond_to(@tcp, :warning)
99
+ end
100
+
101
+ def teardown
102
+ @host = nil
103
+ @tcp = nil
104
+ end
105
+ end