netaddr 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of netaddr might be problematic. Click here for more details.

data/tests/eui_test.rb CHANGED
@@ -8,63 +8,77 @@ require 'test/unit'
8
8
  class TestEUI < Test::Unit::TestCase
9
9
 
10
10
  def test_new
11
- assert_not_nil(NetAddr::EUI48.new('aa-bb-cc-dd-ee-ff') )
12
- assert_not_nil(NetAddr::EUI48.new('aa-bb-cc-dd-ee-ff') )
13
- assert_not_nil(NetAddr::EUI48.new('aa:bb:cc:dd:ee:ff') )
14
- assert_not_nil(NetAddr::EUI48.new('aabb.ccdd.eeff') )
15
- assert_not_nil(NetAddr::EUI64.new('aa-bb-cc-dd-ee-ff-00-01') )
11
+ assert_not_nil(NetAddr::EUI48.new('aabbccddeeff') )
12
+ assert_not_nil(NetAddr::EUI48.new('aabbccddeeff') )
13
+ assert_not_nil(NetAddr::EUI64.new('aabbccddeeff0001') )
16
14
  assert_not_nil(NetAddr::EUI48.new(0x000000000001) )
17
15
  assert_not_nil(NetAddr::EUI64.new(0x0000000000000001) )
18
-
16
+
19
17
  assert_raise(ArgumentError){ NetAddr::EUI48.new() }
20
18
  assert_raise(ArgumentError){ NetAddr::EUI48.new({}) }
21
19
  assert_raise(ArgumentError){ NetAddr::EUI64.new() }
22
20
  assert_raise(ArgumentError){ NetAddr::EUI64.new({}) }
23
21
  end
24
-
22
+
25
23
  def test_create
26
24
  assert_not_nil(NetAddr::EUI.create('aa-bb-cc-dd-ee-ff') )
27
25
  assert_not_nil(NetAddr::EUI.create('aa:bb:cc:dd:ee:ff') )
28
26
  assert_not_nil(NetAddr::EUI.create('aabb.ccdd.eeff') )
29
27
  assert_not_nil(NetAddr::EUI.create('aa-bb-cc-dd-ee-ff-00-01') )
30
-
28
+
31
29
  assert_raise(ArgumentError){ NetAddr::EUI.create() }
32
30
  assert_raise(ArgumentError){ NetAddr::EUI.create(0x0000000000000001) }
33
-
34
- assert_kind_of(NetAddr::EUI48, NetAddr::EUI.create('aa-bb-cc-dd-ee-ff'))
31
+
32
+ assert_kind_of(NetAddr::EUI48, NetAddr::EUI.create('aa-bb-cc-dd-ee-ff'))
35
33
  assert_kind_of(NetAddr::EUI64, NetAddr::EUI.create('aa-bb-cc-dd-ee-ff-00-01'))
36
34
  end
37
-
35
+
38
36
  def test_simple
39
- mac = NetAddr::EUI48.new('aa-bb-cc-dd-ee-ff')
37
+ mac = NetAddr::EUI.create('aa-bb-cc-dd-ee-ff')
40
38
  assert_raise(ArgumentError) {mac.oui(:test => true)}
41
39
  assert_raise(ArgumentError) {mac.ei(:test => true)}
42
-
40
+
43
41
  assert_equal('aa-bb-cc', mac.oui )
44
42
  assert_equal('dd-ee-ff', mac.ei )
43
+ assert_equal('aa:bb:cc', mac.oui(:Delimiter => ':' ) )
44
+ assert_equal('dd:ee:ff', mac.ei(:Delimiter => ':' ) )
45
+ assert_equal('aa-bb-cc-dd-ee-ff', mac.address )
46
+ assert_equal('aa:bb:cc:dd:ee:ff', mac.address(:Delimiter => ':') )
47
+ assert_equal('aabb.ccdd.eeff', mac.address(:Delimiter => '.') )
48
+ assert_equal(0xaabbccddeeff, mac.to_i )
45
49
  assert_equal(NetAddr::EUI48, mac.class )
46
-
47
-
48
- mac = NetAddr::EUI64.new('aa-bb-cc-dd-ee-ff-01-02')
50
+
51
+ mac = NetAddr::EUI.create('aa-bb-cc-dd-ee-ff-01-02')
49
52
  assert_raise(ArgumentError) {mac.oui(:test => true)}
50
- assert_raise(ArgumentError) {mac.ei(:test => true)}
53
+ assert_raise(ArgumentError) {mac.ei(:test => true)}
51
54
  assert_equal('aa-bb-cc', mac.oui )
52
55
  assert_equal('dd-ee-ff-01-02', mac.ei )
56
+ assert_equal('aa:bb:cc', mac.oui(:Delimiter => ':') )
57
+ assert_equal('dd:ee:ff:01:02', mac.ei(:Delimiter => ':' ) )
53
58
  assert_equal('aa-bb-cc-dd-ee-ff-01-02', mac.address )
59
+ assert_equal('aa:bb:cc:dd:ee:ff:01:02', mac.address(:Delimiter => ':') )
60
+ assert_equal('aabb.ccdd.eeff.0102', mac.address(:Delimiter => '.') )
61
+ assert_equal(0xaabbccddeeff0102, mac.to_i )
54
62
  assert_equal(NetAddr::EUI64, mac.class )
55
-
63
+
56
64
  end
57
-
65
+
58
66
  def test_link_local
59
- mac = NetAddr::EUI48.new('aa-bb-cc-dd-ee-ff')
67
+ mac = NetAddr::EUI.create('aa-bb-cc-dd-ee-ff')
60
68
  assert_equal('fe80:0000:0000:0000:aabb:ccff:fedd:eeff', mac.link_local )
61
-
62
- mac = NetAddr::EUI48.new('1234.5678.9abc')
69
+
70
+ mac = NetAddr::EUI.create('1234.5678.9abc')
63
71
  assert_equal('fe80:0000:0000:0000:1234:56ff:fe78:9abc', mac.link_local )
64
-
65
- mac = NetAddr::EUI64.new('1234.5678.9abc.def0')
72
+
73
+ mac = NetAddr::EUI.create('1234.5678.9abc.def0')
66
74
  assert_equal('fe80:0000:0000:0000:1234:5678:9abc:def0', mac.link_local(:Objectify => true).ip )
67
75
  assert_raise(ArgumentError) {mac.link_local(:test => true)}
68
76
  end
69
-
77
+
78
+ def test_to_eui64
79
+ mac = NetAddr::EUI.create('aa-bb-cc-dd-ee-ff')
80
+ assert_equal('aa-bb-cc-ff-fe-dd-ee-ff', mac.to_eui64.address )
81
+
82
+ end
83
+
70
84
  end
@@ -7,6 +7,54 @@ require 'test/unit'
7
7
 
8
8
  class TestMethods < Test::Unit::TestCase
9
9
 
10
+ def test_i_to_bits
11
+ assert_equal(32, NetAddr.i_to_bits(2**32-1) )
12
+ assert_equal(24, NetAddr.i_to_bits((2**32 - 2**8 ) ) )
13
+ assert_equal(128, NetAddr.i_to_bits(2**128-1) )
14
+ assert_equal(96, NetAddr.i_to_bits((2**128 - 2**32)) )
15
+
16
+ assert_raise(ArgumentError){ NetAddr.i_to_bits('1') }
17
+ assert_raise(ArgumentError){ NetAddr.i_to_bits({}) }
18
+ assert_raise(ArgumentError){ NetAddr.i_to_bits('1')}
19
+ end
20
+
21
+ def test_i_to_ip
22
+ assert_raise(ArgumentError) {NetAddr.i_to_ip(2**32-1, :test => true)}
23
+ assert_equal('255.255.255.255', NetAddr.i_to_ip(2**32-1) )
24
+ assert_equal('0.0.0.0', NetAddr.i_to_ip(0, :Version => 4) )
25
+ assert_equal('0000:0000:0000:0000:0000:0000:0000:0000', NetAddr.i_to_ip(0, :Version => 6) )
26
+ assert_equal('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', NetAddr.i_to_ip(2**128-1) )
27
+ assert_equal('0000:0000:0000:0000:0000:0000:ffff:ffff', NetAddr.i_to_ip(2**32-1, :Version => 6) )
28
+ assert_equal('0000:0000:0000:0000:0000:ffff:10.1.0.1', NetAddr.i_to_ip(0xffff0a010001,
29
+ :IPv4Mapped => true,
30
+ :Version => 6) )
31
+ assert_raise(ArgumentError){ NetAddr.i_to_ip('1') }
32
+ assert_raise(ArgumentError){ NetAddr.i_to_ip({}) }
33
+ assert_raise(NetAddr::VersionError){ NetAddr.i_to_ip(0xffffffff,:Version => 5) }
34
+ assert_raise(ArgumentError){ NetAddr.i_to_ip('1', :Version => 4) }
35
+ end
36
+
37
+ def test_ip_to_i
38
+ assert_raise(ArgumentError) {NetAddr.ip_to_i('255.255.255.255', :test => true)}
39
+ assert_equal(2**128-1, NetAddr.ip_to_i('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') )
40
+ assert_equal(1, NetAddr.ip_to_i('::1') )
41
+ assert_equal(2**32-1, NetAddr.ip_to_i('255.255.255.255') )
42
+ assert_equal(2**128-1, NetAddr.ip_to_i('ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255') )
43
+ assert_equal(0, NetAddr.ip_to_i('::') )
44
+ assert_equal(2**32-1, NetAddr.ip_to_i('::255.255.255.255') )
45
+ assert_equal(0x0a0a0a0a, NetAddr.ip_to_i('10.10.10.10') )
46
+ assert_equal(2**127+1, NetAddr.ip_to_i('8000::0.0.0.1') )
47
+ assert_equal(0x8080000000000000000080800a0a0a0a, NetAddr.ip_to_i('8080::8080:10.10.10.10') )
48
+ assert_equal(0xffff0a010001, NetAddr.ip_to_i('::ffff:10.1.0.1') )
49
+ assert_equal(2**127+1, NetAddr.ip_to_i('8000::1') )
50
+ assert_equal(1, NetAddr.ip_to_i('::1') )
51
+ assert_equal(2**127, NetAddr.ip_to_i('8000::') )
52
+
53
+ assert_raise(ArgumentError){ NetAddr.ip_to_i({}) }
54
+ assert_raise(NetAddr::VersionError){ NetAddr.ip_to_i('192.168.1.1',:Version => 5) }
55
+ assert_raise(ArgumentError){ NetAddr.ip_to_i(0xffffffff,:Version => 4) }
56
+ end
57
+
10
58
  def test_merge
11
59
  assert_raise(ArgumentError){ NetAddr.merge(1) }
12
60
  assert_raise(ArgumentError){ NetAddr.merge({}) }
@@ -36,8 +84,7 @@ class TestMethods < Test::Unit::TestCase
36
84
  assert_equal('10.0.0.240/28', merged[0].tag[:Subnets][5].desc)
37
85
  assert(merged[0].tag[:Subnets][5].tag[:test])
38
86
  end
39
-
40
-
87
+
41
88
  def test_minimum_size
42
89
  assert_raise(ArgumentError) {NetAddr.minimum_size(200, :test => true)}
43
90
  assert_equal(24, NetAddr.minimum_size(200))
@@ -46,76 +93,49 @@ class TestMethods < Test::Unit::TestCase
46
93
  assert_equal('255.255.255.224', NetAddr.minimum_size(17, :Extended => true))
47
94
  assert_equal(24, NetAddr.minimum_size(200, :Extended => false))
48
95
  assert_equal(96, NetAddr.minimum_size(2**32-1, :Version => 6, :Extended => true))
49
-
50
96
  assert_raise(ArgumentError){ NetAddr.minimum_size({}) }
51
97
  end
52
-
53
-
54
- def test_pack_ip_addr
55
- assert_raise(ArgumentError) {NetAddr.pack_ip_addr('255.255.255.255', :test => true)}
56
- assert_equal(2**128-1, NetAddr.pack_ip_addr('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff') )
57
- assert_equal(1, NetAddr.pack_ip_addr('::1') )
58
- assert_equal(2**32-1, NetAddr.pack_ip_addr('255.255.255.255') )
59
- assert_equal(2**128-1, NetAddr.pack_ip_addr('ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255') )
60
- assert_equal(0, NetAddr.pack_ip_addr('::') )
61
- assert_equal(2**32-1, NetAddr.pack_ip_addr('::255.255.255.255') )
62
- assert_equal(0x0a0a0a0a, NetAddr.pack_ip_addr('10.10.10.10') )
63
- assert_equal(2**127+1, NetAddr.pack_ip_addr('8000::0.0.0.1') )
64
- assert_equal(0x8080000000000000000080800a0a0a0a, NetAddr.pack_ip_addr('8080::8080:10.10.10.10') )
65
- assert_equal(0xffff0a010001, NetAddr.pack_ip_addr('::ffff:10.1.0.1') )
66
- assert_equal(2**127+1, NetAddr.pack_ip_addr('8000::1') )
67
- assert_equal(1, NetAddr.pack_ip_addr('::1') )
68
- assert_equal(2**127, NetAddr.pack_ip_addr('8000::') )
69
-
70
- assert_raise(ArgumentError){ NetAddr.pack_ip_addr({}) }
71
- assert_raise(NetAddr::VersionError){ NetAddr.pack_ip_addr('192.168.1.1',:Version => 5) }
72
- assert_raise(ArgumentError){ NetAddr.pack_ip_addr(0xffffffff,:Version => 4) }
73
- end
74
-
75
-
76
- def test_pack_ip_netmask
77
- assert_raise(ArgumentError) {NetAddr.pack_ip_netmask('32', :test => true)}
78
- assert_equal(2**32-1, NetAddr.pack_ip_netmask('255.255.255.255') )
79
- assert_equal(2**32-1, NetAddr.pack_ip_netmask('32') )
80
- assert_equal(2**32-1, NetAddr.pack_ip_netmask('/32') )
81
- assert_equal(2**32-1, NetAddr.pack_ip_netmask(32) )
82
- assert_equal(2**128-1, NetAddr.pack_ip_netmask('128', :Version => 6) )
83
- assert_equal(2**128-1, NetAddr.pack_ip_netmask('/128', :Version => 6) )
84
- assert_equal(2**128-1, NetAddr.pack_ip_netmask(128, :Version => 6) )
85
-
86
- assert_raise(ArgumentError){ NetAddr.pack_ip_netmask({}) }
87
- assert_raise(NetAddr::VersionError){ NetAddr.pack_ip_netmask('/24',:Version => 5) }
88
- assert_raise(ArgumentError){ NetAddr.pack_ip_netmask([], :Version => 4) }
98
+
99
+ def test_netmask_to_i
100
+ assert_raise(ArgumentError) {NetAddr.netmask_to_i('32', :test => true)}
101
+ assert_equal(2**32-1, NetAddr.netmask_to_i('255.255.255.255') )
102
+ assert_equal(2**32-1, NetAddr.netmask_to_i('32') )
103
+ assert_equal(2**32-1, NetAddr.netmask_to_i('/32') )
104
+ assert_equal(2**32-1, NetAddr.netmask_to_i(32) )
105
+ assert_equal(2**128-1, NetAddr.netmask_to_i('128', :Version => 6) )
106
+ assert_equal(2**128-1, NetAddr.netmask_to_i('/128', :Version => 6) )
107
+ assert_equal(2**128-1, NetAddr.netmask_to_i(128, :Version => 6) )
108
+ assert_raise(ArgumentError){ NetAddr.netmask_to_i({}) }
109
+ assert_raise(NetAddr::VersionError){ NetAddr.netmask_to_i('/24',:Version => 5) }
110
+ assert_raise(ArgumentError){ NetAddr.netmask_to_i([], :Version => 4) }
89
111
  end
90
-
91
-
112
+
92
113
  def test_range
93
114
  cidr4_1 = NetAddr::CIDR.create('192.168.1.0/24')
94
115
  cidr4_2 = NetAddr::CIDR.create('192.168.1.50/24')
95
116
  cidr4_3 = NetAddr::CIDR.create('192.168.1.2/24')
96
117
  cidr6_1 = NetAddr::CIDR.create('fec0::/64')
97
- cidr6_2 = NetAddr::CIDR.create('fec0::32/64')
98
-
118
+ cidr6_2 = NetAddr::CIDR.create('fec0::32/64')
119
+
99
120
  assert_raise(ArgumentError) {NetAddr.range(cidr4_1,cidr4_2, :test => true)}
100
121
  assert_equal(['192.168.1.1'], NetAddr.range(cidr4_1,cidr4_2, :Limit => 1) )
101
122
  assert_equal(['fec0:0000:0000:0000:0000:0000:0000:0001'], NetAddr.range(cidr6_1,cidr6_2, :Limit => 1) )
102
-
103
- list = NetAddr.range('192.168.1.0/24','192.168.1.50/24', :Bitstep => 2)
123
+
124
+ list = NetAddr.range('192.168.1.0/24','192.168.1.50/24', :Bitstep => 2)
104
125
  assert_equal(25, list.length)
105
126
  assert_equal('192.168.1.49', list[24])
106
-
107
- list = NetAddr.range(cidr4_1,cidr4_3, :Objectify => true)
127
+
128
+ list = NetAddr.range(cidr4_1,cidr4_3, :Objectify => true)
108
129
  assert_kind_of(NetAddr::CIDR, list[0])
109
130
  assert_equal('192.168.1.1/32', (list[0]).desc)
110
-
131
+
111
132
  assert_raise(ArgumentError){ NetAddr.range(:Limit => 1) }
112
133
  assert_raise(NetAddr::VersionError){ NetAddr.range(cidr4_1,cidr6_2) }
113
-
134
+
114
135
  assert_equal(256, NetAddr.range('192.168.0.0', '192.168.0.255', :Size => true, :Inclusive => true) )
115
136
  end
116
-
117
-
118
- def test_shorten
137
+
138
+ def test_shorten
119
139
  assert_equal('fec0::', NetAddr.shorten('fec0:0000:0000:0000:0000:0000:0000:0000') )
120
140
  assert_equal('fec0::2:0:0:1', NetAddr.shorten('fec0:0000:0000:0000:0002:0000:0000:0001') )
121
141
  assert_equal('fec0::2:0:0:1', NetAddr.shorten('fec0:00:0000:0:02:0000:0:1') )
@@ -126,72 +146,37 @@ class TestMethods < Test::Unit::TestCase
126
146
  assert_equal('fec0:ffff:ffff:ffff:ffff:ffff:ffff:ffff', NetAddr.shorten('fec0:ffff:ffff:ffff:ffff:ffff:ffff:ffff') )
127
147
  assert_equal('fec0::', NetAddr.shorten('fec0::') )
128
148
  assert_equal('fec0::192.168.1.1', NetAddr.shorten('fec0:0:0:0:0:0:192.168.1.1') )
129
-
130
149
  assert_raise(ArgumentError){ NetAddr.shorten(1) }
131
150
  end
132
-
133
-
151
+
134
152
  def test_sort
135
153
  cidr4_1 = NetAddr::CIDR.create('192.168.1.0/24')
136
154
  cidr4_2 = NetAddr::CIDR.create('192.168.1.128/25')
137
155
  cidr4_3 = NetAddr::CIDR.create('192.168.1.64/26')
138
156
  cidr4_4 = NetAddr::CIDR.create('192.168.1.0/30')
139
157
  cidr4_5 = '192.168.2.0/24'
140
-
158
+
141
159
  cidr6_1 = NetAddr::CIDR.create('fec0::0/64')
142
160
  cidr6_2 = NetAddr::CIDR.create('fec0::0/10')
143
161
  cidr6_3 = NetAddr::CIDR.create('fe80::0/10')
144
162
  cidr6_4 = 'fe80::0'
145
-
163
+
146
164
  sort1 = NetAddr.sort([cidr4_1,cidr4_2,cidr4_3,cidr4_4,cidr4_5])
147
165
  sort2 = NetAddr.sort([cidr6_1,cidr6_2,cidr6_3,cidr6_4])
148
-
166
+
149
167
  assert_equal([cidr4_1,cidr4_4,cidr4_3,cidr4_2,cidr4_5], sort1)
150
168
  assert_equal([cidr6_3,cidr6_4,cidr6_2,cidr6_1], sort2)
151
-
152
169
  end
153
-
154
-
155
- def test_unshorten
170
+
171
+ def test_unshorten
156
172
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0000', NetAddr.unshorten('fec0::') )
157
173
  assert_equal('fec0:0000:0000:0000:0002:0000:0000:0001', NetAddr.unshorten('fec0::2:0:0:1') )
158
174
  assert_equal('fec0:0000:0000:0000:0002:0000:0000:0001', NetAddr.unshorten('fec0:0:0:0:2:0:0:1') )
159
- assert_equal('0000:0000:0000:0000:0000:ffff:10.1.0.1', NetAddr.unshorten('::ffff:10.1.0.1') )
160
-
175
+ assert_equal('0000:0000:0000:0000:0000:ffff:10.1.0.1', NetAddr.unshorten('::ffff:10.1.0.1') )
176
+
161
177
  assert_raise(ArgumentError){ NetAddr.unshorten(1) }
162
178
  end
163
-
164
-
165
- def test_unpack_ip_addr
166
- assert_raise(ArgumentError) {NetAddr.unpack_ip_addr(2**32-1, :test => true)}
167
- assert_equal('255.255.255.255', NetAddr.unpack_ip_addr(2**32-1) )
168
- assert_equal('0.0.0.0', NetAddr.unpack_ip_addr(0, :Version => 4) )
169
- assert_equal('0000:0000:0000:0000:0000:0000:0000:0000', NetAddr.unpack_ip_addr(0, :Version => 6) )
170
- assert_equal('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', NetAddr.unpack_ip_addr(2**128-1) )
171
- assert_equal('0000:0000:0000:0000:0000:0000:ffff:ffff', NetAddr.unpack_ip_addr(2**32-1, :Version => 6) )
172
- assert_equal('0000:0000:0000:0000:0000:ffff:10.1.0.1', NetAddr.unpack_ip_addr(0xffff0a010001,
173
- :IPv4Mapped => true,
174
- :Version => 6) )
175
-
176
- assert_raise(ArgumentError){ NetAddr.unpack_ip_addr('1') }
177
- assert_raise(ArgumentError){ NetAddr.unpack_ip_addr({}) }
178
- assert_raise(NetAddr::VersionError){ NetAddr.unpack_ip_addr(0xffffffff,:Version => 5) }
179
- assert_raise(ArgumentError){ NetAddr.unpack_ip_addr('1', :Version => 4) }
180
- end
181
-
182
-
183
- def test_unpack_ip_netmask
184
- assert_equal(32, NetAddr.unpack_ip_netmask(2**32-1) )
185
- assert_equal(24, NetAddr.unpack_ip_netmask((2**32 - 2**8 ) ) )
186
- assert_equal(128, NetAddr.unpack_ip_netmask(2**128-1) )
187
- assert_equal(96, NetAddr.unpack_ip_netmask((2**128 - 2**32)) )
188
-
189
- assert_raise(ArgumentError){ NetAddr.unpack_ip_netmask('1') }
190
- assert_raise(ArgumentError){ NetAddr.unpack_ip_netmask({}) }
191
- assert_raise(ArgumentError){ NetAddr.unpack_ip_netmask('1')}
192
- end
193
-
194
-
179
+
195
180
  def test_validate_eui
196
181
  assert_nothing_raised(NetAddr::ValidationError) {NetAddr.validate_eui('aa-bb-cc-dd-ee-ff')}
197
182
  assert_nothing_raised(NetAddr::ValidationError) {NetAddr.validate_eui('aabb.ccdd.eeff') }
@@ -204,10 +189,9 @@ class TestMethods < Test::Unit::TestCase
204
189
  assert_raise(NetAddr::ValidationError){NetAddr.validate_eui('aa:bb:cc:dd:ee:^^') }
205
190
  assert_raise(NetAddr::ValidationError){NetAddr.validate_eui('aa:bb:cc:dd:ee:ZZ') }
206
191
  assert_raise(ArgumentError){ NetAddr.validate_eui(0xaabbccddeeff) }
207
- assert_raise(ArgumentError){ NetAddr.validate_eui() }
192
+ assert_raise(ArgumentError){ NetAddr.validate_eui() }
208
193
  end
209
-
210
-
194
+
211
195
  def test_validate_ip_addr
212
196
  assert_raise(ArgumentError) {NetAddr.validate_ip_addr('192.168.1.0', :test => true)}
213
197
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('192.168.1.0')}
@@ -218,7 +202,7 @@ class TestMethods < Test::Unit::TestCase
218
202
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr(0xff0000)}
219
203
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr(2**32-1)}
220
204
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr(0)}
221
-
205
+
222
206
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')}
223
207
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('::')}
224
208
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('ffff::1')}
@@ -232,7 +216,7 @@ class TestMethods < Test::Unit::TestCase
232
216
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr(2**128-1)}
233
217
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('fec0:0:0:0:0:0:192.168.1.1')}
234
218
  assert_nothing_raised(Exception) {NetAddr.validate_ip_addr('8080::8080:10.10.10.10')}
235
-
219
+
236
220
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('') }
237
221
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('10.0') }
238
222
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('10.0..0') }
@@ -242,7 +226,7 @@ class TestMethods < Test::Unit::TestCase
242
226
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('192.168.1.1.1') }
243
227
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('ff.ff.ff.ff') }
244
228
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr(2**128-1, :Version => 4) }
245
-
229
+
246
230
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('ffff::1111::1111') }
247
231
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('abcd:efgh::1') }
248
232
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('fffff::1') }
@@ -252,58 +236,56 @@ class TestMethods < Test::Unit::TestCase
252
236
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('::192.168.256.0') }
253
237
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('::192.168.a3.0') }
254
238
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_addr('::192.168.1.1.0') }
255
-
239
+
256
240
  assert_raise(ArgumentError){ NetAddr.validate_ip_addr({}) }
257
241
  assert_raise(ArgumentError){ NetAddr.validate_ip_addr([])}
258
242
  assert_raise(ArgumentError){ NetAddr.validate_ip_addr('192.168.1.0', :Version => 5)}
259
-
243
+
260
244
  end
261
-
262
-
245
+
263
246
  def test_validate_ip_netmask
264
247
  assert_raise(ArgumentError) {NetAddr.validate_ip_netmask('255.255.255.255', :test => true)}
265
248
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask('255.255.255.255')}
266
249
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask('32')}
267
250
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask('/32')}
268
251
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask(32)}
269
- assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask(0xffffffff, :Packed => true)}
252
+ assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask(0xffffffff, :Integer => true)}
270
253
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask('128', :Version => 6)}
271
254
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask('/128', :Version => 6)}
272
255
  assert_nothing_raised(Exception) {NetAddr.validate_ip_netmask(128, :Version => 6)}
273
-
256
+
274
257
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_netmask('255.192.255.0') }
275
258
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_netmask(33) }
276
259
  assert_raise(NetAddr::ValidationError){ NetAddr.validate_ip_netmask(129, :Version => 6) }
277
-
260
+
278
261
  assert_raise(ArgumentError){ NetAddr.validate_ip_netmask({}) }
279
262
  assert_raise(ArgumentError){ NetAddr.validate_ip_netmask([])}
280
263
  assert_raise(ArgumentError){ NetAddr.validate_ip_netmask('/24', :Version => 5)}
281
- end
282
-
283
-
264
+ end
265
+
284
266
  def test_wildcard
285
267
  cidr = NetAddr.wildcard('192.168.*')
286
268
  assert_equal(NetAddr::CIDRv4, cidr.class )
287
269
  assert_equal(16, cidr.bits)
288
270
  assert_equal('192.168.0.0', cidr.network)
289
-
271
+
290
272
  cidr = NetAddr.wildcard('192.*.1.0')
291
273
  assert_equal(8, cidr.bits)
292
274
  assert_equal('192.0.0.0', cidr.network)
293
-
275
+
294
276
  cidr = NetAddr.wildcard('fec0:*')
295
277
  assert_equal(NetAddr::CIDRv6, cidr.class )
296
278
  assert_equal(16, cidr.bits)
297
279
  assert_equal('fec0:0000:0000:0000:0000:0000:0000:0000', cidr.network)
298
-
280
+
299
281
  cidr = NetAddr.wildcard('fec0:1:*')
300
282
  assert_equal(32, cidr.bits)
301
283
  assert_equal('fec0:0001:0000:0000:0000:0000:0000:0000', cidr.network)
302
-
284
+
303
285
  assert_raise(ArgumentError){NetAddr.wildcard('fec0::*')}
304
286
  assert_raise(ArgumentError){NetAddr.wildcard('::ffff:192.168.*')}
305
287
  end
306
-
288
+
307
289
  end
308
290
 
309
291