blob: 23494b74cea7391b4c7b03f3e92e0fb0c3e63660 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070016package org.onlab.packet;
17
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080018import com.google.common.net.InetAddresses;
19import com.google.common.testing.EqualsTester;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070020import org.junit.Test;
21
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080022import java.net.InetAddress;
23
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070024import static org.hamcrest.Matchers.is;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070025import static org.junit.Assert.assertThat;
26import static org.junit.Assert.assertTrue;
27import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
28
29/**
30 * Tests for class {@link Ip4Address}.
31 */
32public class Ip4AddressTest {
33 /**
34 * Tests the immutability of {@link Ip4Address}.
35 */
36 @Test
37 public void testImmutable() {
38 assertThatClassIsImmutable(Ip4Address.class);
39 }
40
41 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080042 * Tests the IPv4 address version constant.
43 */
44 @Test
45 public void testAddressVersion() {
46 assertThat(Ip4Address.VERSION, is(IpAddress.Version.INET));
47 }
48
49 /**
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070050 * Tests the length of the address in bytes (octets).
51 */
52 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080053 public void testAddrByteLength() {
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070054 assertThat(Ip4Address.BYTE_LENGTH, is(4));
55 }
56
57 /**
58 * Tests the length of the address in bits.
59 */
60 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080061 public void testAddrBitLength() {
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070062 assertThat(Ip4Address.BIT_LENGTH, is(32));
63 }
64
65 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080066 * Tests returning the IP address version.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070067 */
68 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080069 public void testVersion() {
70 Ip4Address ipAddress;
71
72 // IPv4
73 ipAddress = Ip4Address.valueOf("0.0.0.0");
74 assertThat(ipAddress.version(), is(IpAddress.Version.INET));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070075 }
76
77 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080078 * Tests returning an IPv4 address as a byte array.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070079 */
80 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080081 public void testAddressToOctetsIPv4() {
82 Ip4Address ipAddress;
83 byte[] value;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070084
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080085 value = new byte[] {1, 2, 3, 4};
86 ipAddress = Ip4Address.valueOf("1.2.3.4");
87 assertThat(ipAddress.toOctets(), is(value));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070088
Pavlin Radoslavovf182f012014-11-04 15:03:18 -080089 value = new byte[] {0, 0, 0, 0};
90 ipAddress = Ip4Address.valueOf("0.0.0.0");
91 assertThat(ipAddress.toOctets(), is(value));
92
93 value = new byte[] {(byte) 0xff, (byte) 0xff,
94 (byte) 0xff, (byte) 0xff};
95 ipAddress = Ip4Address.valueOf("255.255.255.255");
96 assertThat(ipAddress.toOctets(), is(value));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -070097 }
98
99 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800100 * Tests returning an IPv4 address as an integer.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700101 */
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800102 @Test
103 public void testToInt() {
104 Ip4Address ipAddress;
105
106 ipAddress = Ip4Address.valueOf("1.2.3.4");
107 assertThat(ipAddress.toInt(), is(0x01020304));
108
109 ipAddress = Ip4Address.valueOf("0.0.0.0");
110 assertThat(ipAddress.toInt(), is(0));
111
112 ipAddress = Ip4Address.valueOf("255.255.255.255");
113 assertThat(ipAddress.toInt(), is(-1));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700114 }
115
116 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800117 * Tests valueOf() converter for IPv4 integer value.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700118 */
119 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800120 public void testValueOfForIntegerIPv4() {
121 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700122
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800123 ipAddress = Ip4Address.valueOf(0x01020304);
124 assertThat(ipAddress.toString(), is("1.2.3.4"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700125
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800126 ipAddress = Ip4Address.valueOf(0);
127 assertThat(ipAddress.toString(), is("0.0.0.0"));
128
129 ipAddress = Ip4Address.valueOf(0xffffffff);
130 assertThat(ipAddress.toString(), is("255.255.255.255"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700131 }
132
133 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800134 * Tests valueOf() converter for IPv4 byte array.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700135 */
136 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800137 public void testValueOfByteArrayIPv4() {
138 Ip4Address ipAddress;
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800139 byte[] value;
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800140
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800141 value = new byte[] {1, 2, 3, 4};
142 ipAddress = Ip4Address.valueOf(value);
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800143 assertThat(ipAddress.toString(), is("1.2.3.4"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700144
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800145 value = new byte[] {0, 0, 0, 0};
146 ipAddress = Ip4Address.valueOf(value);
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800147 assertThat(ipAddress.toString(), is("0.0.0.0"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700148
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800149 value = new byte[] {(byte) 0xff, (byte) 0xff,
150 (byte) 0xff, (byte) 0xff};
151 ipAddress = Ip4Address.valueOf(value);
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800152 assertThat(ipAddress.toString(), is("255.255.255.255"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700153 }
154
155 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800156 * Tests invalid valueOf() converter for a null array for IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700157 */
158 @Test(expected = NullPointerException.class)
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800159 public void testInvalidValueOfNullArrayIPv4() {
160 Ip4Address ipAddress;
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800161 byte[] value;
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800162
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800163 value = null;
164 ipAddress = Ip4Address.valueOf(value);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700165 }
166
167 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800168 * Tests invalid valueOf() converger for an array that is too short for
169 * IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700170 */
171 @Test(expected = IllegalArgumentException.class)
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800172 public void testInvalidValueOfShortArrayIPv4() {
173 Ip4Address ipAddress;
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800174 byte[] value;
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800175
Pavlin Radoslavov315d6c82014-11-04 15:36:04 -0800176 value = new byte[] {1, 2, 3};
177 ipAddress = Ip4Address.valueOf(value);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700178 }
179
180 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800181 * Tests valueOf() converter for IPv4 byte array and an offset.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700182 */
183 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800184 public void testValueOfByteArrayOffsetIPv4() {
185 Ip4Address ipAddress;
186 byte[] value;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700187
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800188 value = new byte[] {11, 22, 33, // Preamble
189 1, 2, 3, 4,
190 44, 55}; // Extra bytes
191 ipAddress = Ip4Address.valueOf(value, 3);
192 assertThat(ipAddress.toString(), is("1.2.3.4"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700193
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800194 value = new byte[] {11, 22, // Preamble
195 0, 0, 0, 0,
196 33}; // Extra bytes
197 ipAddress = Ip4Address.valueOf(value, 2);
198 assertThat(ipAddress.toString(), is("0.0.0.0"));
199
200 value = new byte[] {11, 22, // Preamble
201 (byte) 0xff, (byte) 0xff,
202 (byte) 0xff, (byte) 0xff,
203 33}; // Extra bytes
204 ipAddress = Ip4Address.valueOf(value, 2);
205 assertThat(ipAddress.toString(), is("255.255.255.255"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700206 }
207
208 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800209 * Tests invalid valueOf() converger for an array and an invalid offset
210 * for IPv4.
211 */
212 @Test(expected = IllegalArgumentException.class)
213 public void testInvalidValueOfArrayInvalidOffsetIPv4() {
214 Ip4Address ipAddress;
215 byte[] value;
216
217 value = new byte[] {11, 22, 33, // Preamble
218 1, 2, 3, 4,
219 44, 55}; // Extra bytes
220 ipAddress = Ip4Address.valueOf(value, 6);
221 }
222
223 /**
224 * Tests valueOf() converter for IPv4 InetAddress.
225 */
226 @Test
227 public void testValueOfInetAddressIPv4() {
228 Ip4Address ipAddress;
229 InetAddress inetAddress;
230
231 inetAddress = InetAddresses.forString("1.2.3.4");
232 ipAddress = Ip4Address.valueOf(inetAddress);
233 assertThat(ipAddress.toString(), is("1.2.3.4"));
234
235 inetAddress = InetAddresses.forString("0.0.0.0");
236 ipAddress = Ip4Address.valueOf(inetAddress);
237 assertThat(ipAddress.toString(), is("0.0.0.0"));
238
239 inetAddress = InetAddresses.forString("255.255.255.255");
240 ipAddress = Ip4Address.valueOf(inetAddress);
241 assertThat(ipAddress.toString(), is("255.255.255.255"));
242 }
243
244 /**
245 * Tests valueOf() converter for IPv4 string.
246 */
247 @Test
248 public void testValueOfStringIPv4() {
249 Ip4Address ipAddress;
250
251 ipAddress = Ip4Address.valueOf("1.2.3.4");
252 assertThat(ipAddress.toString(), is("1.2.3.4"));
253
254 ipAddress = Ip4Address.valueOf("0.0.0.0");
255 assertThat(ipAddress.toString(), is("0.0.0.0"));
256
257 ipAddress = Ip4Address.valueOf("255.255.255.255");
258 assertThat(ipAddress.toString(), is("255.255.255.255"));
259 }
260
261 /**
262 * Tests invalid valueOf() converter for a null string.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700263 */
264 @Test(expected = NullPointerException.class)
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800265 public void testInvalidValueOfNullString() {
266 Ip4Address ipAddress;
267
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700268 String fromString = null;
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800269 ipAddress = Ip4Address.valueOf(fromString);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700270 }
271
272 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800273 * Tests invalid valueOf() converter for an empty string.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700274 */
275 @Test(expected = IllegalArgumentException.class)
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800276 public void testInvalidValueOfEmptyString() {
277 Ip4Address ipAddress;
278
279 String fromString = "";
280 ipAddress = Ip4Address.valueOf(fromString);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700281 }
282
283 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800284 * Tests invalid valueOf() converter for an incorrect string.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700285 */
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800286 @Test(expected = IllegalArgumentException.class)
287 public void testInvalidValueOfIncorrectString() {
288 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700289
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800290 String fromString = "NoSuchIpAddress";
291 ipAddress = Ip4Address.valueOf(fromString);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700292 }
293
294 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800295 * Tests making a mask prefix for a given prefix length for IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700296 */
297 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800298 public void testMakeMaskPrefixIPv4() {
299 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700300
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800301 ipAddress = Ip4Address.makeMaskPrefix(25);
302 assertThat(ipAddress.toString(), is("255.255.255.128"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700303
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800304 ipAddress = Ip4Address.makeMaskPrefix(0);
305 assertThat(ipAddress.toString(), is("0.0.0.0"));
306
307 ipAddress = Ip4Address.makeMaskPrefix(32);
308 assertThat(ipAddress.toString(), is("255.255.255.255"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700309 }
310
311 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800312 * Tests making a mask prefix for an invalid prefix length for IPv4:
313 * negative prefix length.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700314 */
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800315 @Test(expected = IllegalArgumentException.class)
316 public void testInvalidMakeNegativeMaskPrefixIPv4() {
317 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700318
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800319 ipAddress = Ip4Address.makeMaskPrefix(-1);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700320 }
321
322 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800323 * Tests making a mask prefix for an invalid prefix length for IPv4:
324 * too long prefix length.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700325 */
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800326 @Test(expected = IllegalArgumentException.class)
327 public void testInvalidMakeTooLongMaskPrefixIPv4() {
328 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700329
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800330 ipAddress = Ip4Address.makeMaskPrefix(33);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700331 }
332
333 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800334 * Tests making of a masked address for IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700335 */
336 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800337 public void testMakeMaskedAddressIPv4() {
338 Ip4Address ipAddress = Ip4Address.valueOf("1.2.3.5");
339 Ip4Address ipAddressMasked;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700340
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800341 ipAddressMasked = Ip4Address.makeMaskedAddress(ipAddress, 24);
342 assertThat(ipAddressMasked.toString(), is("1.2.3.0"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700343
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800344 ipAddressMasked = Ip4Address.makeMaskedAddress(ipAddress, 0);
345 assertThat(ipAddressMasked.toString(), is("0.0.0.0"));
346
347 ipAddressMasked = Ip4Address.makeMaskedAddress(ipAddress, 32);
348 assertThat(ipAddressMasked.toString(), is("1.2.3.5"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700349 }
350
351 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800352 * Tests making of a masked address for invalid prefix length for IPv4:
353 * negative prefix length.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700354 */
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800355 @Test(expected = IllegalArgumentException.class)
356 public void testInvalidMakeNegativeMaskedAddressIPv4() {
357 Ip4Address ipAddress = Ip4Address.valueOf("1.2.3.5");
358 Ip4Address ipAddressMasked;
359
360 ipAddressMasked = Ip4Address.makeMaskedAddress(ipAddress, -1);
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700361 }
362
363 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800364 * Tests making of a masked address for an invalid prefix length for IPv4:
365 * too long prefix length.
366 */
367 @Test(expected = IllegalArgumentException.class)
368 public void testInvalidMakeTooLongMaskedAddressIPv4() {
369 Ip4Address ipAddress = Ip4Address.valueOf("1.2.3.5");
370 Ip4Address ipAddressMasked;
371
372 ipAddressMasked = Ip4Address.makeMaskedAddress(ipAddress, 33);
373 }
374
375 /**
376 * Tests comparison of {@link Ip4Address} for IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700377 */
378 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800379 public void testComparisonIPv4() {
380 Ip4Address addr1, addr2, addr3, addr4;
381
382 addr1 = Ip4Address.valueOf("1.2.3.4");
383 addr2 = Ip4Address.valueOf("1.2.3.4");
384 addr3 = Ip4Address.valueOf("1.2.3.3");
385 addr4 = Ip4Address.valueOf("1.2.3.5");
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700386 assertTrue(addr1.compareTo(addr2) == 0);
387 assertTrue(addr1.compareTo(addr3) > 0);
388 assertTrue(addr1.compareTo(addr4) < 0);
389
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800390 addr1 = Ip4Address.valueOf("255.2.3.4");
391 addr2 = Ip4Address.valueOf("255.2.3.4");
392 addr3 = Ip4Address.valueOf("255.2.3.3");
393 addr4 = Ip4Address.valueOf("255.2.3.5");
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700394 assertTrue(addr1.compareTo(addr2) == 0);
395 assertTrue(addr1.compareTo(addr3) > 0);
396 assertTrue(addr1.compareTo(addr4) < 0);
397 }
398
399 /**
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800400 * Tests equality of {@link Ip4Address} for IPv4.
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700401 */
402 @Test
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800403 public void testEqualityIPv4() {
404 new EqualsTester()
405 .addEqualityGroup(Ip4Address.valueOf("1.2.3.4"),
406 Ip4Address.valueOf("1.2.3.4"))
407 .addEqualityGroup(Ip4Address.valueOf("1.2.3.5"),
408 Ip4Address.valueOf("1.2.3.5"))
409 .addEqualityGroup(Ip4Address.valueOf("0.0.0.0"),
410 Ip4Address.valueOf("0.0.0.0"))
411 .addEqualityGroup(Ip4Address.valueOf("255.255.255.255"),
412 Ip4Address.valueOf("255.255.255.255"))
413 .testEquals();
414 }
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700415
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800416 /**
417 * Tests object string representation for IPv4.
418 */
419 @Test
420 public void testToStringIPv4() {
421 Ip4Address ipAddress;
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700422
Pavlin Radoslavovf182f012014-11-04 15:03:18 -0800423 ipAddress = Ip4Address.valueOf("1.2.3.4");
424 assertThat(ipAddress.toString(), is("1.2.3.4"));
425
426 ipAddress = Ip4Address.valueOf("0.0.0.0");
427 assertThat(ipAddress.toString(), is("0.0.0.0"));
428
429 ipAddress = Ip4Address.valueOf("255.255.255.255");
430 assertThat(ipAddress.toString(), is("255.255.255.255"));
Pavlin Radoslavov9de27722014-10-23 20:31:15 -0700431 }
432}