Jonathan Hart | 8f5f468 | 2013-08-07 22:13:39 +1200 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.bgproute; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import java.util.Arrays; |
| 6 | |
| 7 | import org.junit.After; |
| 8 | import org.junit.Before; |
| 9 | import org.junit.Test; |
| 10 | |
| 11 | public class PrefixTest { |
| 12 | |
| 13 | @Before |
| 14 | public void setUp() throws Exception { |
| 15 | } |
| 16 | |
| 17 | @After |
| 18 | public void tearDown() throws Exception { |
| 19 | } |
| 20 | |
| 21 | @Test |
| 22 | public void testPrefixByteArray() { |
| 23 | byte[] b1 = new byte[] {(byte)0x8f, (byte)0xa0, (byte)0x00, (byte)0x00}; |
| 24 | byte[] b2 = new byte[] {(byte)0x8f, (byte)0xa0, (byte)0xff, (byte)0xff}; |
| 25 | byte[] b3 = new byte[] {(byte)0x8f, (byte)0xac, (byte)0x00, (byte)0x00}; |
| 26 | byte[] b4 = new byte[] {(byte)0x8f, (byte)0xa0, (byte)0x00, (byte)0x00}; |
| 27 | |
| 28 | Prefix p1 = new Prefix(b1, 12); |
| 29 | Prefix p2 = new Prefix(b2, 12); |
| 30 | Prefix p3 = new Prefix(b3, 12); |
| 31 | Prefix p4 = new Prefix(b4, 11); |
| 32 | |
| 33 | //Have different byte arrays, but should be equal after construction |
| 34 | assertTrue(p1.equals(p2)); |
| 35 | assertTrue(p2.equals(p3)); |
| 36 | |
| 37 | //Same byte array, but should be false |
| 38 | assertFalse(p1.equals(p4)); |
| 39 | |
| 40 | assertTrue(Arrays.equals(p1.getAddress(), p3.getAddress())); |
| 41 | assertTrue(p1.toString().equals(p2.toString())); |
| 42 | assertTrue(Arrays.equals(p1.getAddress(), p4.getAddress())); |
| 43 | assertFalse(p1.toString().equals(p4.toString())); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testPrefixString() { |
| 48 | Prefix p1 = new Prefix("192.168.166.0", 24); |
| 49 | Prefix p2 = new Prefix("192.168.166.0", 23); |
| 50 | Prefix p3 = new Prefix("192.168.166.128", 24); |
| 51 | Prefix p4 = new Prefix("192.168.166.128", 25); |
| 52 | |
| 53 | assertFalse(p1.equals(p2)); |
| 54 | assertTrue(Arrays.equals(p1.getAddress(), p2.getAddress())); |
| 55 | |
| 56 | assertTrue(p1.equals(p3)); |
| 57 | assertTrue(Arrays.equals(p1.getAddress(), p2.getAddress())); |
| 58 | |
| 59 | assertFalse(p3.equals(p4)); |
| 60 | assertFalse(Arrays.equals(p3.getAddress(), p4.getAddress())); |
| 61 | |
| 62 | assertTrue(p1.toString().equals(p3.toString())); |
| 63 | assertEquals(p1.hashCode(), p3.hashCode()); |
| 64 | } |
| 65 | |
| 66 | } |