diff options
author | Erik Kline <ek@google.com> | 2015-04-14 09:58:38 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-14 09:58:38 +0000 |
commit | 172cf0243587db7baaa2502a04d403185ec50f7b (patch) | |
tree | 7db6d130a4b71b386ae717c51b3b6ee9e3f80ba3 /core/tests/coretests/src | |
parent | 75f4b76638addc27f3297bb934e68741ecd27d32 (diff) | |
parent | 73e056d3931b419c2653eb7365fb72b50a9a36c3 (diff) | |
download | frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.zip frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.tar.gz frameworks_base-172cf0243587db7baaa2502a04d403185ec50f7b.tar.bz2 |
am 73e056d3: am 402f2501: am 3312c6b9: Merge "Add android.net.IpPrefix#contains()"
* commit '73e056d3931b419c2653eb7365fb72b50a9a36c3':
Add android.net.IpPrefix#contains()
Diffstat (limited to 'core/tests/coretests/src')
-rw-r--r-- | core/tests/coretests/src/android/net/IpPrefixTest.java | 32 | ||||
-rw-r--r-- | core/tests/coretests/src/android/net/RouteInfoTest.java | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/net/IpPrefixTest.java b/core/tests/coretests/src/android/net/IpPrefixTest.java index cf278fb..fcc6389 100644 --- a/core/tests/coretests/src/android/net/IpPrefixTest.java +++ b/core/tests/coretests/src/android/net/IpPrefixTest.java @@ -29,6 +29,10 @@ import junit.framework.TestCase; public class IpPrefixTest extends TestCase { + private static InetAddress Address(String addr) { + return InetAddress.parseNumericAddress(addr); + } + // Explicitly cast everything to byte because "error: possible loss of precision". private static final byte[] IPV4_BYTES = { (byte) 192, (byte) 0, (byte) 2, (byte) 4}; private static final byte[] IPV6_BYTES = { @@ -209,6 +213,34 @@ public class IpPrefixTest extends TestCase { } @SmallTest + public void testContains() { + IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127"); + assertTrue(p.contains(Address("2001:db8:f00::ace:d00c"))); + assertTrue(p.contains(Address("2001:db8:f00::ace:d00d"))); + assertFalse(p.contains(Address("2001:db8:f00::ace:d00e"))); + assertFalse(p.contains(Address("2001:db8:f00::bad:d00d"))); + assertFalse(p.contains(Address("2001:4868:4860::8888"))); + assertFalse(p.contains(null)); + assertFalse(p.contains(Address("8.8.8.8"))); + + p = new IpPrefix("192.0.2.0/23"); + assertTrue(p.contains(Address("192.0.2.43"))); + assertTrue(p.contains(Address("192.0.3.21"))); + assertFalse(p.contains(Address("192.0.0.21"))); + assertFalse(p.contains(Address("8.8.8.8"))); + assertFalse(p.contains(Address("2001:4868:4860::8888"))); + + IpPrefix ipv6Default = new IpPrefix("::/0"); + assertTrue(ipv6Default.contains(Address("2001:db8::f00"))); + assertFalse(ipv6Default.contains(Address("192.0.2.1"))); + + IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0"); + assertTrue(ipv4Default.contains(Address("255.255.255.255"))); + assertTrue(ipv4Default.contains(Address("192.0.2.1"))); + assertFalse(ipv4Default.contains(Address("2001:db8::f00"))); + } + + @SmallTest public void testHashCode() { IpPrefix p; int oldCode = -1; diff --git a/core/tests/coretests/src/android/net/RouteInfoTest.java b/core/tests/coretests/src/android/net/RouteInfoTest.java index 0b88bc7..831fefd 100644 --- a/core/tests/coretests/src/android/net/RouteInfoTest.java +++ b/core/tests/coretests/src/android/net/RouteInfoTest.java @@ -90,6 +90,7 @@ public class RouteInfoTest extends TestCase { assertFalse(r.matches(Address("2001:db8:f00::ace:d00e"))); assertFalse(r.matches(Address("2001:db8:f00::bad:d00d"))); assertFalse(r.matches(Address("2001:4868:4860::8888"))); + assertFalse(r.matches(Address("8.8.8.8"))); r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0"); assertTrue(r.matches(Address("192.0.2.43"))); |