snmp 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,23 @@
1
1
  #
2
- # Copyright (c) 2004 David R. Halliday
3
- # All rights reserved.
2
+ # Copyright (c) 2004-2014 David R. Halliday
4
3
  #
5
- # This SNMP library is free software. Redistribution is permitted under the
6
- # same terms and conditions as the standard Ruby distribution. See the
7
- # COPYING file in the Ruby distribution for details.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
8
21
  #
9
22
 
10
23
  require 'snmp/ber'
@@ -109,8 +122,8 @@ module SNMP
109
122
  class Integer32 < Integer
110
123
  def initialize(value)
111
124
  super(value)
112
- raise ArgumentError, "Out of range: #{value}" if value < -2147483648
113
- raise ArgumentError, "Out of range: #{value}" if value > 2147483647
125
+ raise ArgumentError, "Out of range: #{@value}" if @value < -2147483648
126
+ raise ArgumentError, "Out of range: #{@value}" if @value > 2147483647
114
127
  end
115
128
  end
116
129
 
@@ -336,8 +349,8 @@ module SNMP
336
349
  class UnsignedInteger < Integer
337
350
  def initialize(value)
338
351
  super(value)
339
- raise ArgumentError, "Negative integer invalid: #{value}" if value < 0
340
- raise ArgumentError, "Out of range: #{value}" if value > 4294967295
352
+ raise ArgumentError, "Negative integer invalid: #{@value}" if @value < 0
353
+ raise ArgumentError, "Out of range: #{@value}" if @value > 4294967295
341
354
  end
342
355
 
343
356
  def self.decode(value_data)
@@ -428,8 +441,8 @@ module SNMP
428
441
 
429
442
  def initialize(value)
430
443
  super(value)
431
- raise ArgumentError, "Negative integer invalid: #{value}" if value < 0
432
- raise ArgumentError, "Out of range: #{value}" if value > 18446744073709551615
444
+ raise ArgumentError, "Negative integer invalid: #{@value}" if @value < 0
445
+ raise ArgumentError, "Out of range: #{@value}" if @value > 18446744073709551615
433
446
  end
434
447
 
435
448
  def encode
@@ -1,3 +1,3 @@
1
1
  module SNMP
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  # encoding: ascii-8bit
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'snmp/varbind'
5
5
  require 'snmp/ber'
6
6
 
7
- class ASN1_Test < Test::Unit::TestCase
7
+ class ASN1_Test < MiniTest::Unit::TestCase
8
8
 
9
9
  include SNMP::BER
10
10
 
@@ -56,20 +56,20 @@ class ASN1_Test < Test::Unit::TestCase
56
56
 
57
57
  # Check invalid length - ASN.1 says that first length octet can't be 255.
58
58
  def test_bad_length
59
- assert_raise(InvalidLength) {
59
+ assert_raises(InvalidLength) {
60
60
  decode_tlv("\001\377\001")
61
61
  }
62
62
  end
63
63
 
64
64
  # Check if input data is too short
65
65
  def test_out_of_data
66
- assert_raise(OutOfData) {
66
+ assert_raises(OutOfData) {
67
67
  decode_tlv("\001\001")
68
68
  }
69
- assert_raise(OutOfData) {
69
+ assert_raises(OutOfData) {
70
70
  decode_tlv("\001")
71
71
  }
72
- assert_raise(OutOfData) {
72
+ assert_raises(OutOfData) {
73
73
  decode_tlv("")
74
74
  }
75
75
  end
@@ -103,7 +103,7 @@ class ASN1_Test < Test::Unit::TestCase
103
103
  assert_equal(255, i)
104
104
  assert_equal("", data)
105
105
 
106
- assert_raise(InvalidTag) {
106
+ assert_raises(InvalidTag) {
107
107
  decode_integer("\001\004\001\002\003\004")
108
108
  }
109
109
  end
@@ -113,7 +113,7 @@ class ASN1_Test < Test::Unit::TestCase
113
113
  assert_equal(16909060, i)
114
114
  assert_equal("", data)
115
115
 
116
- assert_raise(InvalidTag) {
116
+ assert_raises(InvalidTag) {
117
117
  decode_timeticks("\002\004\001\002\003\004")
118
118
  }
119
119
  end
@@ -122,7 +122,7 @@ class ASN1_Test < Test::Unit::TestCase
122
122
  def test_decode_octet_string
123
123
  s, _ = decode_octet_string("\004\202\000\005hello")
124
124
  assert_equal("hello",s)
125
- assert_raise(InvalidTag) {
125
+ assert_raises(InvalidTag) {
126
126
  decode_octet_string("\005\202\000\005hello")
127
127
  }
128
128
  end
@@ -130,10 +130,10 @@ class ASN1_Test < Test::Unit::TestCase
130
130
  def test_decode_ip_address
131
131
  ip, _ = decode_ip_address("@\004\001\002\003\004")
132
132
  assert_equal(ip, "\001\002\003\004")
133
- assert_raise(InvalidTag) {
133
+ assert_raises(InvalidTag) {
134
134
  decode_ip_address("\004\004\001\002\003\004")
135
135
  }
136
- assert_raise(InvalidLength) {
136
+ assert_raises(InvalidLength) {
137
137
  decode_ip_address("@\005\001\002\003\004\005")
138
138
  }
139
139
  end
@@ -148,7 +148,7 @@ class ASN1_Test < Test::Unit::TestCase
148
148
  assert_equal("\002\001\077", seq)
149
149
  assert_equal("\002\001\001", data)
150
150
 
151
- assert_raise(InvalidTag) {
151
+ assert_raises(InvalidTag) {
152
152
  decode_sequence("\061\003\002\001\077")
153
153
  }
154
154
  end
@@ -180,7 +180,7 @@ class ASN1_Test < Test::Unit::TestCase
180
180
  assert_equal([0,0], object_id);
181
181
  assert_equal("", remainder)
182
182
 
183
- assert_raise(InvalidTag) do
183
+ assert_raises(InvalidTag) do
184
184
  decode_object_id("\007\001+")
185
185
  end
186
186
  end
@@ -191,7 +191,7 @@ class ASN1_Test < Test::Unit::TestCase
191
191
  assert_equal("\177", encode_length(127))
192
192
  assert_equal("\201\200", encode_length(128))
193
193
  assert_equal("\202\002\001", encode_length(513))
194
- assert_raise(InvalidLength) { encode_length(-1) }
194
+ assert_raises(InvalidLength) { encode_length(-1) }
195
195
  end
196
196
 
197
197
  def test_encode_integer
@@ -232,8 +232,8 @@ class ASN1_Test < Test::Unit::TestCase
232
232
  assert_equal("\006\002+\006", encode_object_id([1,3,6]))
233
233
  assert_equal("\006\003+\202\001", encode_object_id([1,3,257]))
234
234
  assert_equal("\006\003" << 82.chr << "\202\001", encode_object_id([2,2,257]))
235
- assert_raise(InvalidObjectId) { encode_object_id([3,2,257]) }
236
- assert_raise(InvalidObjectId) { encode_object_id([]) }
235
+ assert_raises(InvalidObjectId) { encode_object_id([3,2,257]) }
236
+ assert_raises(InvalidObjectId) { encode_object_id([]) }
237
237
 
238
238
  assert_equal("\006\a+\203\377\177\203\377\177",
239
239
  encode_object_id(SNMP::ObjectId.new("1.3.65535.65535")))
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'snmp/manager'
3
3
 
4
4
  class EchoTransport
@@ -17,7 +17,7 @@ class EchoTransport
17
17
  end
18
18
  end
19
19
 
20
- class TestConfig < Test::Unit::TestCase
20
+ class TestConfig < MiniTest::Unit::TestCase
21
21
 
22
22
  include SNMP
23
23
 
@@ -37,7 +37,7 @@ class TestConfig < Test::Unit::TestCase
37
37
  end
38
38
 
39
39
  def test_invalid_option
40
- assert_raise(RuntimeError) { Manager::Config.new(:fly_to_the_moon => true) }
40
+ assert_raises(RuntimeError) { Manager::Config.new(:fly_to_the_moon => true) }
41
41
  end
42
42
 
43
43
  def test_ipv6_address_guessing
@@ -56,7 +56,7 @@ class TestConfig < Test::Unit::TestCase
56
56
  end
57
57
  end
58
58
 
59
- class TestManager < Test::Unit::TestCase
59
+ class TestManager < MiniTest::Unit::TestCase
60
60
 
61
61
  include SNMP
62
62
 
@@ -103,6 +103,10 @@ class TestManager < Test::Unit::TestCase
103
103
  assert_equal(ObjectId.new("1.2.3.4.5"), response.varbind_list[1].name)
104
104
  end
105
105
 
106
+ def test_get_with_nil
107
+ assert_raises(ArgumentError) { @manager.get(nil) }
108
+ end
109
+
106
110
  def test_get_value
107
111
  value = @manager.get_value("1.2.3.4")
108
112
  assert_equal(Null, value)
@@ -124,6 +128,10 @@ class TestManager < Test::Unit::TestCase
124
128
  assert_equal(ObjectId.new("1.2.3.4.5"), response.varbind_list[1].name)
125
129
  end
126
130
 
131
+ def test_get_next_with_nil
132
+ assert_raises(ArgumentError) { @manager.get_next(nil) }
133
+ end
134
+
127
135
  def test_set
128
136
  v0 = VarBind.new("1.3.6.1.3.1.1.1.0", OctetString.new("Hello1"))
129
137
  v1 = VarBind.new("1.3.6.1.3.1.1.1.0", OctetString.new("Hello2"))
@@ -131,6 +139,10 @@ class TestManager < Test::Unit::TestCase
131
139
  assert_equal("Hello1", response.varbind_list[0].value.to_s)
132
140
  assert_equal("Hello2", response.varbind_list[1].value.to_s)
133
141
  end
142
+
143
+ def test_set_with_nil
144
+ assert_raises(ArgumentError) { @manager.set(nil) }
145
+ end
134
146
 
135
147
  def test_single_set
136
148
  varbind = VarBind.new("1.3.6.1.3.1.1.1.0", OctetString.new("Hello"))
@@ -147,6 +159,10 @@ class TestManager < Test::Unit::TestCase
147
159
  assert_equal("SNMPv2-SMI::experimental.1.1.2.0", response.varbind_list[1].name.to_s)
148
160
  end
149
161
 
162
+ def test_get_bulk_with_nil
163
+ assert_raises(ArgumentError) { @manager.get_bulk(nil, nil, nil) }
164
+ end
165
+
150
166
  def test_walk
151
167
  old_verbose = $VERBOSE
152
168
  $VERBOSE = nil
@@ -155,6 +171,10 @@ class TestManager < Test::Unit::TestCase
155
171
  $VERBOSE = old_verbose
156
172
  end
157
173
 
174
+ def test_walk_with_nil
175
+ assert_raises(ArgumentError) { @manager.walk(nil) {} }
176
+ end
177
+
158
178
  def test_request_id
159
179
  id = RequestId.new
160
180
  fail if id.next < 0 or id.next >= 2**31
@@ -165,8 +185,8 @@ class TestManager < Test::Unit::TestCase
165
185
  id.force_next(RequestId::MAX_REQUEST_ID-1)
166
186
  assert_equal(RequestId::MAX_REQUEST_ID-1, id.next)
167
187
 
168
- assert_raise(RuntimeError) { id.force_next(RequestId::MAX_REQUEST_ID) }
169
- assert_raise(RuntimeError) { id.force_next(0) }
188
+ assert_raises(RuntimeError) { id.force_next(RequestId::MAX_REQUEST_ID) }
189
+ assert_raises(RuntimeError) { id.force_next(0) }
170
190
  end
171
191
 
172
192
  def test_trap_v1
@@ -177,7 +197,7 @@ class TestManager < Test::Unit::TestCase
177
197
  :enterpriseSpecific,
178
198
  42,
179
199
  12345,
180
- [VarBind.new("1.3.6.1.2.3.4", Integer.new(1))]
200
+ [VarBind.new("1.3.6.1.2.3.4", SNMP::Integer.new(1))]
181
201
  )
182
202
  pdu = Message.decode(sent_data).pdu
183
203
  assert_equal(ObjectId.new("1.3.6.1.4.1.9"), pdu.enterprise)
@@ -188,6 +208,10 @@ class TestManager < Test::Unit::TestCase
188
208
  assert_equal(1, pdu.vb_list.length)
189
209
  end
190
210
 
211
+ def test_trap_v1_with_nil
212
+ assert_raises(ArgumentError) { @manager.trap_v1(nil) }
213
+ end
214
+
191
215
  def test_trap_v2
192
216
  sent_data = @manager.trap_v2(1234, "1.3.6.1.2.3.4")
193
217
  pdu = Message.decode(sent_data).pdu
@@ -203,6 +227,10 @@ class TestManager < Test::Unit::TestCase
203
227
  assert_equal("1.4.5.6", pdu.vb_list.last.name.to_s)
204
228
  end
205
229
 
230
+ def test_trap_v2_with_nil
231
+ assert_raises(ArgumentError) { @manager.trap_v2(nil, nil, nil) }
232
+ end
233
+
206
234
  def test_inform
207
235
  response = @manager.inform(1234, "1.3.6.1.2.3.4")
208
236
  assert_equal(1234, response.vb_list[0].value)
@@ -246,7 +274,7 @@ class TrapTestTransport
246
274
  end
247
275
 
248
276
 
249
- class TestTrapListener < Test::Unit::TestCase
277
+ class TestTrapListener < MiniTest::Unit::TestCase
250
278
  include SNMP
251
279
 
252
280
  def test_init_no_handlers
@@ -1,9 +1,9 @@
1
+ require 'minitest/autorun'
1
2
  require 'snmp/mib'
2
- require 'test/unit'
3
3
 
4
4
  module SNMP
5
5
 
6
- class TestMib < Test::Unit::TestCase
6
+ class TestMib < MiniTest::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @mib = MIB.new
@@ -28,15 +28,15 @@ module SNMP
28
28
  oid = @mib.oid("IF-MIB::ifTable.1.23")
29
29
  assert_equal("1.3.6.1.2.1.2.2.1.23", oid.to_s)
30
30
 
31
- assert_raise(MIB::ModuleNotLoadedError) {
31
+ assert_raises(MIB::ModuleNotLoadedError) {
32
32
  @mib.oid("IFMIB::ifTable.1.23")
33
33
  }
34
34
 
35
- assert_raise(ArgumentError) {
35
+ assert_raises(ArgumentError) {
36
36
  @mib.oid("IF-MIB::")
37
37
  }
38
38
 
39
- assert_raise(ArgumentError) {
39
+ assert_raises(ArgumentError) {
40
40
  MIB.new.oid("sysDescr.0")
41
41
  }
42
42
 
@@ -57,6 +57,10 @@ module SNMP
57
57
  assert_equal("1.3.6.1.2.1.2.2.1.23", vb_list.first.name.to_s)
58
58
  end
59
59
 
60
+ def test_varbind_list_with_nil
61
+ assert_raises(ArgumentError) { @mib.varbind_list(nil) }
62
+ end
63
+
60
64
  def test_varbind
61
65
  vb = @mib.varbind("1.2.3.4", Null)
62
66
  assert_equal("1.2.3.4", vb.name.to_s)
@@ -1,7 +1,9 @@
1
+ # encoding: ascii-8bit
2
+
1
3
  require 'snmp/pdu'
2
- require 'test/unit'
4
+ require 'minitest/autorun'
3
5
 
4
- class TestProtocol < Test::Unit::TestCase
6
+ class TestProtocol < MiniTest::Unit::TestCase
5
7
 
6
8
  include SNMP
7
9
 
@@ -27,7 +29,7 @@ class TestProtocol < Test::Unit::TestCase
27
29
  end
28
30
 
29
31
  def test_message_decoder_v3
30
- assert_raise(SNMP::UnsupportedVersion) do
32
+ assert_raises(SNMP::UnsupportedVersion) do
31
33
  SNMP::Message.decode("0>\002\001\0030\021\002\004&\266\342\314\002\003\000\377\343\004\001\004\002\001\003\004\0200\016\004\000\002\001\000\002\001\000\004\000\004\000\004\0000\024\004\000\004\000\240\016\002\004\v\3623\233\002\001\000\002\001\0000\000")
32
34
  end
33
35
  end
@@ -115,7 +117,7 @@ class TestProtocol < Test::Unit::TestCase
115
117
  request.error_status = 2
116
118
  assert_equal(:noSuchName, request.error_status)
117
119
 
118
- assert_raise(InvalidErrorStatus) {request.error_status = 42}
120
+ assert_raises(InvalidErrorStatus) {request.error_status = 42}
119
121
  end
120
122
 
121
123
  def test_snmpv2_trap
@@ -131,8 +133,8 @@ class TestProtocol < Test::Unit::TestCase
131
133
 
132
134
  def test_snmpv2_invalid_trap
133
135
  trap = SNMPv2_Trap.new(42, VarBindList.new([]))
134
- assert_raise(InvalidTrapVarbind) { trap.sys_up_time }
135
- assert_raise(InvalidTrapVarbind) { trap.trap_oid }
136
+ assert_raises(InvalidTrapVarbind) { trap.sys_up_time }
137
+ assert_raises(InvalidTrapVarbind) { trap.trap_oid }
136
138
  end
137
139
 
138
140
  def test_snmpv1_generic_trap
@@ -145,8 +147,8 @@ class TestProtocol < Test::Unit::TestCase
145
147
  trap.generic_trap = 6
146
148
  assert_equal(:enterpriseSpecific, trap.generic_trap)
147
149
 
148
- assert_raise(InvalidGenericTrap) { trap.generic_trap = -1 }
149
- assert_raise(InvalidGenericTrap) { trap.generic_trap = 7 }
150
+ assert_raises(InvalidGenericTrap) { trap.generic_trap = -1 }
151
+ assert_raises(InvalidGenericTrap) { trap.generic_trap = 7 }
150
152
  end
151
153
 
152
154
  def test_snmpv1_trap_encode
@@ -155,7 +157,7 @@ class TestProtocol < Test::Unit::TestCase
155
157
  generic_trap = :linkDown
156
158
  specific_trap = 0
157
159
  timestamp = TimeTicks.new(2176117721)
158
- varbinds = VarBindList.new([VarBind.new("1.3.6.2", Integer.new(1))])
160
+ varbinds = VarBindList.new([VarBind.new("1.3.6.2", SNMP::Integer.new(1))])
159
161
  trap = SNMPv1_Trap.new(enterprise, agent_addr, generic_trap, specific_trap, timestamp, varbinds)
160
162
  assert_equal("\244%\006\004+\006\001{@\004\001\002\003\004\002\001\002\002\001\000C\005\000\201\264\353\3310\n0\010\006\003+\006\002\002\001\001", trap.encode)
161
163
 
@@ -1,4 +1,4 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
  require 'snmp'
3
3
 
4
4
  class TimeoutManager < SNMP::Manager
@@ -53,7 +53,7 @@ class MismatchIdTransport
53
53
  end
54
54
 
55
55
 
56
- class TestRetry < Test::Unit::TestCase
56
+ class TestRetry < MiniTest::Unit::TestCase
57
57
  def test_retry_count
58
58
  assert_response_count(0, 1, SNMP::RequestTimeout)
59
59
  assert_response_count(1, 2, SNMP::RequestTimeout)
@@ -71,7 +71,7 @@ class TestRetry < Test::Unit::TestCase
71
71
  def assert_response_count(retry_count, response_count, exception)
72
72
  m = TimeoutManager.new( :Retries => retry_count )
73
73
  yield m if block_given?
74
- assert_raise(exception) { m.get("1.2.3.4") }
74
+ assert_raises(exception) { m.get("1.2.3.4") }
75
75
  assert_equal(response_count, m.response_count)
76
76
  end
77
77
 
@@ -1,9 +1,9 @@
1
- require 'test/unit'
1
+ require 'minitest/autorun'
2
2
 
3
3
  begin
4
4
  require 'smi'
5
5
 
6
- class TestSmi < Test::Unit::TestCase
6
+ class TestSmi < MiniTest::Unit::TestCase
7
7
 
8
8
  include SNMP::SMI
9
9
 
@@ -1,14 +1,16 @@
1
+ # encoding: ascii-8bit
2
+
1
3
  require 'snmp/varbind'
2
- require 'test/unit'
4
+ require 'minitest/autorun'
3
5
 
4
- class TestVarBind < Test::Unit::TestCase
6
+ class TestVarBind < MiniTest::Unit::TestCase
5
7
 
6
8
  include SNMP
7
9
 
8
10
  def test_varbind_encode
9
11
  v = VarBind.new([1,3,6,1], OctetString.new("test"))
10
12
  assert_equal("0\v\006\003+\006\001\004\004test", v.encode)
11
- assert_not_nil(v.asn1_type)
13
+ refute_nil(v.asn1_type)
12
14
  assert_equal("[name=1.3.6.1, value=test (OCTET STRING)]", v.to_s)
13
15
  end
14
16
 
@@ -57,11 +59,11 @@ class TestVarBind < Test::Unit::TestCase
57
59
 
58
60
  check_varbind_list_create(VarBindList.new(
59
61
  [VarBind.new("1.2.3.4.5", Null),
60
- VarBind.new("1.2.3.4.6", Integer.new(123)),
62
+ VarBind.new("1.2.3.4.6", SNMP::Integer.new(123)),
61
63
  ObjectId.new("1.2.3.4.7")]
62
64
  ), 3)
63
65
 
64
- list = VarBindList.new([VarBind.new("1.3.6.2", Integer.new(1))])
66
+ list = VarBindList.new([VarBind.new("1.3.6.2", SNMP::Integer.new(1))])
65
67
  assert_equal(1, list.length)
66
68
  assert_equal("1.3.6.2", list.first.name.to_s)
67
69
  assert_equal(1, list.first.value.to_i)
@@ -76,7 +78,7 @@ class TestVarBind < Test::Unit::TestCase
76
78
  def test_varbind_list_encode
77
79
  list = VarBindList.new
78
80
  assert_equal("0\000", list.encode)
79
- assert_not_nil(list.asn1_type)
81
+ refute_nil(list.asn1_type)
80
82
 
81
83
  list << VarBind.new([1,3,6,1], OctetString.new("test"))
82
84
  assert_equal("0\r0\v\006\003+\006\001\004\004test", list.encode)
@@ -103,7 +105,7 @@ class TestVarBind < Test::Unit::TestCase
103
105
  string = OctetString.new("test")
104
106
  assert_equal("test", string.to_s)
105
107
  assert_equal("\004\004test", string.encode)
106
- assert_not_nil(string.asn1_type)
108
+ refute_nil(string.asn1_type)
107
109
  end
108
110
 
109
111
  def test_octet_string_equals
@@ -112,7 +114,7 @@ class TestVarBind < Test::Unit::TestCase
112
114
  s3 = OctetString.new("test")
113
115
  assert_equal(s1, s2)
114
116
  assert(s1 == s2)
115
- assert_not_same(s1, s3)
117
+ refute_same(s1, s3)
116
118
  assert_equal(s1, s3)
117
119
  end
118
120
 
@@ -125,10 +127,10 @@ class TestVarBind < Test::Unit::TestCase
125
127
  id = ObjectId.new([1,3,6,1])
126
128
  assert_equal("1.3.6.1", id.to_s)
127
129
  assert_equal("\006\003+\006\001", id.encode)
128
- assert_not_nil(id.asn1_type)
130
+ refute_nil(id.asn1_type)
129
131
  assert_equal("1.3.6.1", id.to_varbind.name.to_s)
130
132
 
131
- assert_raise(ArgumentError) {
133
+ assert_raises(ArgumentError) {
132
134
  ObjectId.new("xyzzy")
133
135
  }
134
136
 
@@ -153,7 +155,7 @@ class TestVarBind < Test::Unit::TestCase
153
155
  def test_object_id_equals
154
156
  id1 = ObjectId.new("1.3.3.4")
155
157
  id2 = ObjectId.new([1,3,3,4])
156
- assert_not_same(id1, id2)
158
+ refute_same(id1, id2)
157
159
  assert(id1 == id2)
158
160
  assert_equal(id1, id2)
159
161
  end
@@ -193,8 +195,8 @@ class TestVarBind < Test::Unit::TestCase
193
195
  assert_equal(ObjectId.new("1"), id2.index(id1))
194
196
  assert_equal(ObjectId.new("1.2"), id3.index(id1))
195
197
  assert_equal(ObjectId.new("1.2"), id3.index("1.3.3.4"))
196
- assert_raise(ArgumentError) { id1.index(id3) }
197
- assert_raise(ArgumentError) { id1.index(id1) }
198
+ assert_raises(ArgumentError) { id1.index(id3) }
199
+ assert_raises(ArgumentError) { id1.index(id1) }
198
200
  end
199
201
 
200
202
  def test_object_name_from_string
@@ -204,24 +206,29 @@ class TestVarBind < Test::Unit::TestCase
204
206
  end
205
207
 
206
208
  def test_integer_create
207
- i = Integer.new(12345)
209
+ i = SNMP::Integer.new(12345)
208
210
  assert_equal("12345", i.to_s)
209
211
  assert_equal(12345, i.to_i)
210
212
  assert_equal("\002\00209", i.encode)
211
- assert_not_nil(i.asn1_type)
213
+ refute_nil(i.asn1_type)
214
+ end
215
+
216
+ def test_integer_create_from_string
217
+ i = Integer.new("12345")
218
+ assert_equal(12345, i.to_i)
212
219
  end
213
220
 
214
221
  def test_integer_decode
215
- i = Integer.decode("09")
222
+ i = SNMP::Integer.decode("09")
216
223
  assert_equal(12345, i.to_i)
217
224
  end
218
225
 
219
226
  def test_integer_equal
220
- i1 = Integer.new(12345)
221
- i2 = Integer.new(12345)
227
+ i1 = SNMP::Integer.new(12345)
228
+ i2 = SNMP::Integer.new(12345)
222
229
  i3 = 12345.2
223
230
  i4 = 12345
224
- assert_not_same(i1, i2)
231
+ refute_same(i1, i2)
225
232
  assert_equal(i1, i2)
226
233
  assert_equal(i4, i1)
227
234
  assert_equal(i1, i4)
@@ -229,8 +236,8 @@ class TestVarBind < Test::Unit::TestCase
229
236
  end
230
237
 
231
238
  def test_integer_comparable
232
- i1 = Integer.new(12345)
233
- i2 = Integer.new(54321.0)
239
+ i1 = SNMP::Integer.new(12345)
240
+ i2 = SNMP::Integer.new(54321.0)
234
241
  assert(i1 < i2)
235
242
  assert(i2 > i1)
236
243
  assert(123 < i1)
@@ -239,19 +246,19 @@ class TestVarBind < Test::Unit::TestCase
239
246
  end
240
247
 
241
248
  def test_integer_to_oid
242
- assert_equal(ObjectId.new("123"), Integer.new(123).to_oid)
243
- assert_equal(ObjectId.new("0"), Integer.new(0).to_oid)
249
+ assert_equal(ObjectId.new("123"), SNMP::Integer.new(123).to_oid)
250
+ assert_equal(ObjectId.new("0"), SNMP::Integer.new(0).to_oid)
244
251
 
245
- i = Integer.new(-1)
246
- assert_raise(RangeError) { i.to_oid }
252
+ i = SNMP::Integer.new(-1)
253
+ assert_raises(RangeError) { i.to_oid }
247
254
  end
248
255
 
249
256
  def test_ip_address_from_string
250
257
  ip = IpAddress.new("10.0.255.1")
251
258
  assert_equal("10.0.255.1", ip.to_s)
252
- assert_raise(InvalidIpAddress) { IpAddress.new("1233.2.3.4") }
253
- assert_raise(InvalidIpAddress) { IpAddress.new("1.2.3.-1") }
254
- assert_raise(InvalidIpAddress) { IpAddress.new("1.2.3") }
259
+ assert_raises(InvalidIpAddress) { IpAddress.new("1233.2.3.4") }
260
+ assert_raises(InvalidIpAddress) { IpAddress.new("1.2.3.-1") }
261
+ assert_raises(InvalidIpAddress) { IpAddress.new("1.2.3") }
255
262
  end
256
263
 
257
264
  def test_ip_address_from_self
@@ -265,7 +272,7 @@ class TestVarBind < Test::Unit::TestCase
265
272
  assert_equal("1.2.3.4", ip.to_s)
266
273
  assert_equal("\001\002\003\004", ip.to_str)
267
274
  assert_equal("@\004\001\002\003\004", ip.encode)
268
- assert_not_nil(ip.asn1_type)
275
+ refute_nil(ip.asn1_type)
269
276
  end
270
277
 
271
278
  def test_ip_address_decode
@@ -307,7 +314,7 @@ class TestVarBind < Test::Unit::TestCase
307
314
  assert_equal("12345", i.to_s)
308
315
  assert_equal(12345, i.to_i)
309
316
  assert_equal("\x41\00209", i.encode)
310
- assert_not_nil(i.asn1_type)
317
+ refute_nil(i.asn1_type)
311
318
  end
312
319
 
313
320
  def test_counter32_decode
@@ -331,7 +338,7 @@ class TestVarBind < Test::Unit::TestCase
331
338
  assert_equal("18446744073709551615", i.to_s)
332
339
  assert_equal("F\t\000\377\377\377\377\377\377\377\377", i.encode)
333
340
  assert_equal(i, Counter64.decode("\000\377\377\377\377\377\377\377\377"))
334
- assert_not_nil(i.asn1_type)
341
+ refute_nil(i.asn1_type)
335
342
  end
336
343
 
337
344
  def test_opaque
@@ -339,7 +346,7 @@ class TestVarBind < Test::Unit::TestCase
339
346
  assert_equal("D\004test", q.encode)
340
347
  assert_equal("test", Opaque.decode("test"))
341
348
  assert_equal("test", q.to_s)
342
- assert_not_nil(q.asn1_type)
349
+ refute_nil(q.asn1_type)
343
350
  end
344
351
 
345
352
  def test_exception_methods
@@ -363,10 +370,10 @@ class TestVarBind < Test::Unit::TestCase
363
370
  assert_equal("2 days, 00:00:00.00", TimeTicks.new(48 * 60 * 60 * 100).to_s)
364
371
  assert_equal("497 days, 02:27:52.95", TimeTicks.new(4294967295).to_s)
365
372
  assert_equal(4294967295, TimeTicks.new(4294967295).to_i)
366
- assert_raise(ArgumentError) {
373
+ assert_raises(ArgumentError) {
367
374
  TimeTicks.new(4294967296)
368
375
  }
369
- assert_raise(ArgumentError) {
376
+ assert_raises(ArgumentError) {
370
377
  TimeTicks.new(-1)
371
378
  }
372
379
  end