android: Add ability to add a range set to another
authorTobias Brunner <tobias@strongswan.org>
Thu, 22 Jun 2017 09:23:25 +0000 (11:23 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 3 Jul 2017 08:27:52 +0000 (10:27 +0200)
src/frontends/android/app/src/main/java/org/strongswan/android/utils/IPRangeSet.java
src/frontends/android/app/src/test/java/org/strongswan/android/test/IPRangeSetTest.java

index 3ced7bb..d5f4b61 100644 (file)
@@ -85,6 +85,21 @@ public class IPRangeSet implements Iterable<IPRange>
        }
 
        /**
+        * Add all ranges from the given set.
+        */
+       public void add(IPRangeSet ranges)
+       {
+               if (ranges == this)
+               {
+                       return;
+               }
+               for (IPRange range : ranges.mRanges)
+               {
+                       add(range);
+               }
+       }
+
+       /**
         * Add all ranges from the given collection to this set.
         */
        public void addAll(Collection<? extends IPRange> coll)
index 659525b..3b054ce 100644 (file)
@@ -143,6 +143,33 @@ public class IPRangeSetTest
        }
 
        @Test
+       public void testAddSet() throws UnknownHostException
+       {
+               IPRangeSet set = new IPRangeSet();
+               IPRangeSet other = new IPRangeSet();
+               other.add(new IPRange("192.168.1.0/24"));
+               other.add(new IPRange("10.0.1.0/24"));
+               other.add(new IPRange("255.255.255.255/32"));
+               set.add(other);
+               assertEquals("size", 3, set.size());
+               assertSubnets(set, new IPRange("10.0.1.0/24"), new IPRange("192.168.1.0/24"),
+                                         new IPRange("255.255.255.255/32"));
+       }
+
+       @Test
+       public void testAddSetIdent() throws UnknownHostException
+       {
+               IPRangeSet set = new IPRangeSet();
+               set.add(new IPRange("192.168.1.0/24"));
+               set.add(new IPRange("10.0.1.0/24"));
+               set.add(new IPRange("255.255.255.255/32"));
+               set.add(set);
+               assertEquals("size", 3, set.size());
+               assertSubnets(set, new IPRange("10.0.1.0/24"), new IPRange("192.168.1.0/24"),
+                                         new IPRange("255.255.255.255/32"));
+       }
+
+       @Test
        public void testRemoveNothing() throws UnknownHostException
        {
                IPRangeSet set = new IPRangeSet();