mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-08 00:02:03 -04:00
android: Add ability to remove a range set from another
This commit is contained in:
parent
78b20efb29
commit
54714331e4
@ -108,6 +108,22 @@ public class IPRangeSet
|
|||||||
mRanges.addAll(additions);
|
mRanges.addAll(additions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the given ranges from ranges in this set.
|
||||||
|
*/
|
||||||
|
public void remove(IPRangeSet ranges)
|
||||||
|
{
|
||||||
|
if (ranges == this)
|
||||||
|
{
|
||||||
|
mRanges.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (IPRange range : ranges.mRanges)
|
||||||
|
{
|
||||||
|
remove(range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the subnets derived from all the ranges in this set.
|
* Returns the subnets derived from all the ranges in this set.
|
||||||
*/
|
*/
|
||||||
|
@ -166,6 +166,26 @@ public class IPRangeSetTest
|
|||||||
assertSubnets(set.getSubnets(), new IPRange("192.168.1.0/25"), new IPRange("192.168.2.128/25"));
|
assertSubnets(set.getSubnets(), new IPRange("192.168.1.0/25"), new IPRange("192.168.2.128/25"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveRangesIdent() throws UnknownHostException
|
||||||
|
{
|
||||||
|
IPRangeSet set = IPRangeSet.fromString("192.168.1.0/24 192.168.4.0/24");
|
||||||
|
set.remove(set);
|
||||||
|
assertEquals("size", 0, set.size());
|
||||||
|
assertSubnets(set.getSubnets());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveRanges() throws UnknownHostException
|
||||||
|
{
|
||||||
|
IPRangeSet set = IPRangeSet.fromString("192.168.0.0/16");
|
||||||
|
IPRangeSet remove = IPRangeSet.fromString("192.168.1.0/24 192.168.3.0/24 192.168.16.0-192.168.255.255");
|
||||||
|
set.remove(remove);
|
||||||
|
assertEquals("size", 3, set.size());
|
||||||
|
assertSubnets(set.getSubnets(), new IPRange("192.168.0.0/24"), new IPRange("192.168.2.0/24"),
|
||||||
|
new IPRange("192.168.4.0/22"), new IPRange("192.168.8.0/21"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFromStringSingle() throws UnknownHostException
|
public void testFromStringSingle() throws UnknownHostException
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user