You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2013/12/06 16:23:10 UTC

svn commit: r1548561 - /commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java

Author: ggregory
Date: Fri Dec  6 15:23:09 2013
New Revision: 1548561

URL: http://svn.apache.org/r1548561
Log:
Sort members in AB order.

Modified:
    commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java

Modified: commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java?rev=1548561&r1=1548560&r2=1548561&view=diff
==============================================================================
--- commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java (original)
+++ commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java Fri Dec  6 15:23:09 2013
@@ -24,75 +24,6 @@ import junit.framework.TestCase;
 
 public class SubnetUtilsTest extends TestCase {
 
-    public void testParseSimpleNetmask() {
-        final String address = "192.168.0.1";
-        final String masks[] = new String[] { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248"};
-        final String bcastAddresses[] = new String[] { "192.255.255.255", "192.168.255.255", "192.168.0.255", "192.168.0.7"};
-        final String lowAddresses[] = new String[] { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" };
-        final String highAddresses[] = new String[] { "192.255.255.254", "192.168.255.254", "192.168.0.254", "192.168.0.6" };
-        final String networkAddresses[] = new String[] { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" };
-        final String cidrSignatures[] = new String[] { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24", "192.168.0.1/29" };
-        final int usableAddresses[] = new int[] { 16777214, 65534, 254, 6 };
-
-        for (int i = 0; i < masks.length; ++i) {
-            SubnetUtils utils = new SubnetUtils(address, masks[i]);
-            SubnetInfo info = utils.getInfo();
-            assertEquals(bcastAddresses[i], info.getBroadcastAddress());
-            assertEquals(cidrSignatures[i], info.getCidrSignature());
-            assertEquals(lowAddresses[i], info.getLowAddress());
-            assertEquals(highAddresses[i], info.getHighAddress());
-            assertEquals(networkAddresses[i], info.getNetworkAddress());
-            assertEquals(usableAddresses[i], info.getAddressCount());
-        }
-    }
-
-    public void testParseSimpleNetmaskInclusive() {
-         String address = "192.168.15.7";
-         String masks[]=new String[]{ "255.255.255.252",  "255.255.255.254",  "255.255.255.255"};
-         String bcast[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7"};
-         String netwk[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
-         String lowAd[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
-         String highA[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7" };
-         String cidrS[]=new String[]{ "192.168.15.7/30",  "192.168.15.7/31",  "192.168.15.7/32"};
-         int usableAd[]=new int[]   { 4 ,                 2,                  1};
-
-         for (int i = 0; i < masks.length; ++i) {
-             SubnetUtils utils = new SubnetUtils(address, masks[i]);
-             utils.setInclusiveHostCount(true);
-             SubnetInfo info = utils.getInfo();
-             assertEquals("ci "+masks[i], cidrS[i], info.getCidrSignature());
-             assertEquals("bc "+masks[i], bcast[i], info.getBroadcastAddress());
-             assertEquals("ac "+masks[i], usableAd[i], info.getAddressCount());
-             assertEquals("nw "+masks[i], netwk[i], info.getNetworkAddress());
-             assertEquals("lo "+masks[i], lowAd[i], info.getLowAddress());
-             assertEquals("hi "+masks[i], highA[i], info.getHighAddress());
-         }
-     }
-
-    public void testParseSimpleNetmaskExclusive() {
-        String address = "192.168.15.7";
-        String masks[]=new String[]{ "255.255.255.252",  "255.255.255.254",  "255.255.255.255"};
-        String bcast[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7"};
-        String netwk[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
-        String lowAd[]=new String[]{ "192.168.15.5",     "0.0.0.0",          "0.0.0.0"    };
-        String highA[]=new String[]{ "192.168.15.6",     "0.0.0.0",          "0.0.0.0"    };
-        String cidrS[]=new String[]{ "192.168.15.7/30",  "192.168.15.7/31",  "192.168.15.7/32"};
-        int usableAd[]=new int[]   { 2 ,                 0,                  0};
-       // low and high addresses don't exist
-
-        for (int i = 0; i < masks.length; ++i) {
-            SubnetUtils utils = new SubnetUtils(address, masks[i]);
-            utils.setInclusiveHostCount(false);
-            SubnetInfo info = utils.getInfo();
-            assertEquals("ci "+masks[i], cidrS[i], info.getCidrSignature());
-            assertEquals("bc "+masks[i], bcast[i], info.getBroadcastAddress());
-            assertEquals("nw "+masks[i], netwk[i], info.getNetworkAddress());
-            assertEquals("ac "+masks[i], usableAd[i], info.getAddressCount());
-            assertEquals("lo "+masks[i], lowAd[i], info.getLowAddress());
-            assertEquals("hi "+masks[i], highA[i], info.getHighAddress());
-        }
-    }
-
     // TODO Lower address test
     public void testAddresses() {
         SubnetUtils utils = new SubnetUtils("192.168.0.1/29");
@@ -106,15 +37,6 @@ public class SubnetUtilsTest extends Tes
         assertFalse(info.isInRange("192.168.0.255"));
     }
 
-    public void testZeroNetmaskBits() {
-        try {
-            new SubnetUtils("192.168.0.1/0");
-            fail("Mask /0 should have generated an IllegalArgumentException");
-        }
-        catch (IllegalArgumentException expected) {
-        }
-    }
-
     /**
      * Test using the inclusiveHostCount flag, which includes
      * the network and broadcast addresses in host counts
@@ -306,4 +228,82 @@ public class SubnetUtilsTest extends Tes
         assertNotNull(address);
         assertEquals(0,address.length);
     }
+
+    public void testParseSimpleNetmask() {
+        final String address = "192.168.0.1";
+        final String masks[] = new String[] { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248"};
+        final String bcastAddresses[] = new String[] { "192.255.255.255", "192.168.255.255", "192.168.0.255", "192.168.0.7"};
+        final String lowAddresses[] = new String[] { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" };
+        final String highAddresses[] = new String[] { "192.255.255.254", "192.168.255.254", "192.168.0.254", "192.168.0.6" };
+        final String networkAddresses[] = new String[] { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" };
+        final String cidrSignatures[] = new String[] { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24", "192.168.0.1/29" };
+        final int usableAddresses[] = new int[] { 16777214, 65534, 254, 6 };
+
+        for (int i = 0; i < masks.length; ++i) {
+            SubnetUtils utils = new SubnetUtils(address, masks[i]);
+            SubnetInfo info = utils.getInfo();
+            assertEquals(bcastAddresses[i], info.getBroadcastAddress());
+            assertEquals(cidrSignatures[i], info.getCidrSignature());
+            assertEquals(lowAddresses[i], info.getLowAddress());
+            assertEquals(highAddresses[i], info.getHighAddress());
+            assertEquals(networkAddresses[i], info.getNetworkAddress());
+            assertEquals(usableAddresses[i], info.getAddressCount());
+        }
+    }
+
+    public void testParseSimpleNetmaskExclusive() {
+        String address = "192.168.15.7";
+        String masks[]=new String[]{ "255.255.255.252",  "255.255.255.254",  "255.255.255.255"};
+        String bcast[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7"};
+        String netwk[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
+        String lowAd[]=new String[]{ "192.168.15.5",     "0.0.0.0",          "0.0.0.0"    };
+        String highA[]=new String[]{ "192.168.15.6",     "0.0.0.0",          "0.0.0.0"    };
+        String cidrS[]=new String[]{ "192.168.15.7/30",  "192.168.15.7/31",  "192.168.15.7/32"};
+        int usableAd[]=new int[]   { 2 ,                 0,                  0};
+       // low and high addresses don't exist
+
+        for (int i = 0; i < masks.length; ++i) {
+            SubnetUtils utils = new SubnetUtils(address, masks[i]);
+            utils.setInclusiveHostCount(false);
+            SubnetInfo info = utils.getInfo();
+            assertEquals("ci "+masks[i], cidrS[i], info.getCidrSignature());
+            assertEquals("bc "+masks[i], bcast[i], info.getBroadcastAddress());
+            assertEquals("nw "+masks[i], netwk[i], info.getNetworkAddress());
+            assertEquals("ac "+masks[i], usableAd[i], info.getAddressCount());
+            assertEquals("lo "+masks[i], lowAd[i], info.getLowAddress());
+            assertEquals("hi "+masks[i], highA[i], info.getHighAddress());
+        }
+    }
+
+    public void testParseSimpleNetmaskInclusive() {
+         String address = "192.168.15.7";
+         String masks[]=new String[]{ "255.255.255.252",  "255.255.255.254",  "255.255.255.255"};
+         String bcast[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7"};
+         String netwk[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
+         String lowAd[]=new String[]{ "192.168.15.4",     "192.168.15.6",     "192.168.15.7" };
+         String highA[]=new String[]{ "192.168.15.7",     "192.168.15.7",     "192.168.15.7" };
+         String cidrS[]=new String[]{ "192.168.15.7/30",  "192.168.15.7/31",  "192.168.15.7/32"};
+         int usableAd[]=new int[]   { 4 ,                 2,                  1};
+
+         for (int i = 0; i < masks.length; ++i) {
+             SubnetUtils utils = new SubnetUtils(address, masks[i]);
+             utils.setInclusiveHostCount(true);
+             SubnetInfo info = utils.getInfo();
+             assertEquals("ci "+masks[i], cidrS[i], info.getCidrSignature());
+             assertEquals("bc "+masks[i], bcast[i], info.getBroadcastAddress());
+             assertEquals("ac "+masks[i], usableAd[i], info.getAddressCount());
+             assertEquals("nw "+masks[i], netwk[i], info.getNetworkAddress());
+             assertEquals("lo "+masks[i], lowAd[i], info.getLowAddress());
+             assertEquals("hi "+masks[i], highA[i], info.getHighAddress());
+         }
+     }
+
+    public void testZeroNetmaskBits() {
+        try {
+            new SubnetUtils("192.168.0.1/0");
+            fail("Mask /0 should have generated an IllegalArgumentException");
+        }
+        catch (IllegalArgumentException expected) {
+        }
+    }
 }