Merge "Replaced bitwise operator usage with java lang APIs for robustness. Had found...
[packetcable.git] / packetcable-driver / src / test / java / org / umu / cops / stack / COPSIpv4AddressTest.java
1 package org.umu.cops.stack;
2
3 import org.junit.Assert;
4 import org.junit.Test;
5
6 import java.net.InetAddress;
7 import java.net.UnknownHostException;
8
9 /**
10  * Tests for the COPSIpv4Address class.
11  */
12 public class COPSIpv4AddressTest {
13
14     @Test(expected = UnknownHostException.class)
15     public void badHost() throws Exception {
16         new COPSIpv4Address("foo");
17     }
18
19     @Test
20     public void localhost() throws Exception {
21         final COPSIpv4Address address = new COPSIpv4Address("localhost");
22         Assert.assertEquals(4, address.getDataLength());
23         Assert.assertArrayEquals(InetAddress.getByName("localhost").getAddress(), address.getAddressBytes());
24         Assert.assertTrue(address.getIpName().equals("localhost") || address.getIpName().equals("127.0.0.1"));
25     }
26
27     @Test
28     public void addrBytes() throws Exception {
29         final byte[] addr = InetAddress.getByName("localhost").getAddress();
30         final COPSIpv4Address address = new COPSIpv4Address(addr);
31         Assert.assertEquals(4, address.getDataLength());
32         Assert.assertArrayEquals(addr, address.getAddressBytes());
33         Assert.assertTrue(address.getIpName().equals("localhost") || address.getIpName().equals("127.0.0.1"));
34     }
35
36 }