Address review comments
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
index 975c7d3..065331f 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv4AddressTest.java
@@ -1,10 +1,6 @@
package org.projectfloodlight.openflow.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import org.hamcrest.CoreMatchers;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -102,6 +98,35 @@
@Test
+ public void testConstants() {
+ byte[] zeros = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
+ byte[] ones = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
+ // Make sure class initializtation and static assignment don't get
+ // messed up. Test everything twice for cached values
+ assertTrue(IPv4Address.NONE.isCidrMask());
+ assertEquals(0, IPv4Address.NONE.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv4Address.NONE.getBytes());
+ assertTrue(IPv4Address.NONE.isCidrMask());
+ assertEquals(0, IPv4Address.NONE.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv4Address.NONE.getBytes());
+
+ assertTrue(IPv4Address.NO_MASK.isCidrMask());
+ assertEquals(32, IPv4Address.NO_MASK.asCidrMaskLength());
+ assertArrayEquals(ones, IPv4Address.NO_MASK.getBytes());
+ assertTrue(IPv4Address.NO_MASK.isCidrMask());
+ assertEquals(32, IPv4Address.NO_MASK.asCidrMaskLength());
+ assertArrayEquals(ones, IPv4Address.NO_MASK.getBytes());
+
+ assertTrue(IPv4Address.FULL_MASK.isCidrMask());
+ assertEquals(0, IPv4Address.FULL_MASK.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv4Address.FULL_MASK.getBytes());
+ assertTrue(IPv4Address.FULL_MASK.isCidrMask());
+ assertEquals(0, IPv4Address.FULL_MASK.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv4Address.FULL_MASK.getBytes());
+ }
+
+
+ @Test
public void testOfString() {
for(int i=0; i < testAddresses.length; i++ ) {
IPv4Address ip = IPv4Address.of(testStrings[i]);
@@ -153,7 +178,18 @@
assertArrayEquals(ipsWithMaskValues[i][0], ip.getBytes());
}
IPv4Address mask = value.getMask();
- assertEquals(ipsWithMaskLengths[i], value.getMask().asCidrMaskLength());
+ if (ipsWithMaskLengths[i] == -1) {
+ assertFalse(mask.isCidrMask());
+ try {
+ mask.asCidrMaskLength();
+ fail("Expected IllegalStateException not thrown");
+ } catch(IllegalStateException e) {
+ //expected
+ }
+ } else {
+ assertTrue(mask.isCidrMask());
+ assertEquals(ipsWithMaskLengths[i], mask.asCidrMaskLength());
+ }
assertArrayEquals(ipsWithMaskValues[i][1], mask.getBytes());
byte[] ipBytes = new byte[4];
System.arraycopy(ipsWithMaskValues[i][0], 0, ipBytes, 0, 4);
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
index 706fb25..a008070 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPv6AddressTest.java
@@ -1,10 +1,6 @@
package org.projectfloodlight.openflow.types;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.net.Inet6Address;
import java.net.InetAddress;
@@ -71,6 +67,40 @@
};
@Test
+ public void testConstants() {
+ byte[] zeros = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
+ byte[] ones = { (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
+ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
+ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
+ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF };
+ // Make sure class initializtation and static assignment don't get
+ // messed up. Test everything twice for cached values
+ assertTrue(IPv6Address.NONE.isCidrMask());
+ assertEquals(0, IPv6Address.NONE.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv6Address.NONE.getBytes());
+ assertTrue(IPv6Address.NONE.isCidrMask());
+ assertEquals(0, IPv6Address.NONE.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv6Address.NONE.getBytes());
+
+ assertTrue(IPv6Address.NO_MASK.isCidrMask());
+ assertEquals(128, IPv6Address.NO_MASK.asCidrMaskLength());
+ assertArrayEquals(ones, IPv6Address.NO_MASK.getBytes());
+ assertTrue(IPv6Address.NO_MASK.isCidrMask());
+ assertEquals(128, IPv6Address.NO_MASK.asCidrMaskLength());
+ assertArrayEquals(ones, IPv6Address.NO_MASK.getBytes());
+
+ assertTrue(IPv6Address.FULL_MASK.isCidrMask());
+ assertEquals(0, IPv6Address.FULL_MASK.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv6Address.FULL_MASK.getBytes());
+ assertTrue(IPv6Address.FULL_MASK.isCidrMask());
+ assertEquals(0, IPv6Address.FULL_MASK.asCidrMaskLength());
+ assertArrayEquals(zeros, IPv6Address.FULL_MASK.getBytes());
+ }
+
+ @Test
public void testMasked() throws UnknownHostException {
for(WithMaskTaskCase w: withMasks) {
IPv6AddressWithMask value = IPv6AddressWithMask.of(w.input);
@@ -83,7 +113,19 @@
}
InetAddress inetAddress = InetAddress.getByName(w.input.split("/")[0]);
- assertEquals("Input " + w.input, w.expectedMaskLength, value.getMask().asCidrMaskLength());
+ if (w.expectedMaskLength == -1) {
+ assertFalse(value.getMask().isCidrMask());
+ try {
+ value.getMask().asCidrMaskLength();
+ fail("Expected IllegalStateException not thrown");
+ } catch(IllegalStateException e) {
+ //expected
+ }
+ } else {
+ assertTrue(value.getMask().isCidrMask());
+ assertEquals("Input " + w.input, w.expectedMaskLength,
+ value.getMask().asCidrMaskLength());
+ }
byte[] address = inetAddress.getAddress();
assertEquals(address.length, value.getValue().getBytes().length);