android: Change format of address ranges and print sets
authorTobias Brunner <tobias@strongswan.org>
Wed, 28 Jun 2017 10:33:17 +0000 (12:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 3 Jul 2017 08:27:55 +0000 (10:27 +0200)
src/frontends/android/app/src/main/java/org/strongswan/android/utils/IPRange.java
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
src/frontends/android/app/src/test/java/org/strongswan/android/test/IPRangeTest.java

index 621dfd6..6c0aa65 100644 (file)
@@ -241,7 +241,7 @@ public class IPRange implements Comparable<IPRange>
                        {
                                return InetAddress.getByAddress(mFrom).getHostAddress() + "/" + mPrefix;
                        }
-                       return InetAddress.getByAddress(mFrom).getHostAddress() + ".." +
+                       return InetAddress.getByAddress(mFrom).getHostAddress() + "-" +
                                   InetAddress.getByAddress(mTo).getHostAddress();
                }
                catch (UnknownHostException ignored)
index d5f4b61..4716055 100644 (file)
@@ -205,4 +205,19 @@ public class IPRangeSet implements Iterable<IPRange>
        {
                return mRanges.size();
        }
+
+       @Override
+       public String toString()
+       {       /* we could use TextUtils, but that causes the unit tests to fail */
+               StringBuilder sb = new StringBuilder();
+               for (IPRange range : mRanges)
+               {
+                       if (sb.length() > 0)
+                       {
+                               sb.append(" ");
+                       }
+                       sb.append(range.toString());
+               }
+               return sb.toString();
+       }
 }
index 3b054ce..af60c15 100644 (file)
@@ -302,4 +302,11 @@ public class IPRangeSetTest
                assertEquals("next", new IPRange("192.168.1.0/24"), iterator.next());
                iterator.remove();
        }
+
+       @Test
+       public void testToString() throws UnknownHostException
+       {
+               IPRangeSet set = IPRangeSet.fromString("192.168.3.10/24 192.168.1.0/24 192.168.1.1-192.168.1.10");
+               assertEquals("string", "192.168.1.0/24 192.168.3.0/24", set.toString());
+       }
 }
index 15d710e..51e976e 100644 (file)
@@ -200,7 +200,7 @@ public class IPRangeTest
        {
                testToString("192.168.1.1", "192.168.1.1", "192.168.1.1/32");
                testToString("192.168.1.0", "192.168.1.255", "192.168.1.0/24");
-               testToString("192.168.1.1", "192.168.1.255", "192.168.1.1..192.168.1.255");
+               testToString("192.168.1.1", "192.168.1.255", "192.168.1.1-192.168.1.255");
                testToString("0.0.0.0", "255.255.255.255", "0.0.0.0/0");
                testToString("fec1::1", "fec1::1", "fec1:0:0:0:0:0:0:1/128");
                testToString("fec1::", "fec1::ffff", "fec1:0:0:0:0:0:0:0/112");