use of android.net.IpPrefix in project android_frameworks_base by ResurrectionRemix.
the class IpPrefixTest method testMappedAddressesAreBroken.
@SmallTest
public void testMappedAddressesAreBroken() {
// 192.0.2.0/24 != ::ffff:c000:0204/120, but because we use InetAddress,
// we are unable to comprehend that.
byte[] ipv6bytes = { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0xff, (byte) 0xff, (byte) 192, (byte) 0, (byte) 2, (byte) 0 };
IpPrefix p = new IpPrefix(ipv6bytes, 120);
// Fine.
assertEquals(16, p.getRawAddress().length);
// Fine.
assertArrayEquals(ipv6bytes, p.getRawAddress());
// Broken.
assertEquals("192.0.2.0/120", p.toString());
assertEquals(InetAddress.parseNumericAddress("192.0.2.0"), p.getAddress());
}
use of android.net.IpPrefix in project android_frameworks_base by ResurrectionRemix.
the class IpPrefixTest method assertParcelingIsLossless.
public void assertParcelingIsLossless(IpPrefix p) {
IpPrefix p2 = passThroughParcel(p);
assertEquals(p, p2);
}
use of android.net.IpPrefix in project android_frameworks_base by ResurrectionRemix.
the class IpPrefixTest method testHashCode.
@SmallTest
public void testHashCode() {
IpPrefix p;
int oldCode = -1;
Random random = new Random();
for (int i = 0; i < 100; i++) {
if (random.nextBoolean()) {
// IPv4.
byte[] b = new byte[4];
random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(33));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
} else {
// IPv6.
byte[] b = new byte[16];
random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(129));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
}
}
}
use of android.net.IpPrefix in project android_frameworks_base by ResurrectionRemix.
the class IpPrefixTest method passThroughParcel.
public IpPrefix passThroughParcel(IpPrefix p) {
Parcel parcel = Parcel.obtain();
IpPrefix p2 = null;
try {
p.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
p2 = IpPrefix.CREATOR.createFromParcel(parcel);
} finally {
parcel.recycle();
}
assertNotNull(p2);
return p2;
}
use of android.net.IpPrefix in project android_frameworks_base by ResurrectionRemix.
the class RouteInfoTest method testMatches.
public void testMatches() {
class PatchedRouteInfo {
private final RouteInfo mRouteInfo;
public PatchedRouteInfo(IpPrefix destination, InetAddress gateway, String iface) {
mRouteInfo = new RouteInfo(destination, gateway, iface);
}
public boolean matches(InetAddress destination) {
return mRouteInfo.matches(destination);
}
}
PatchedRouteInfo r;
r = new PatchedRouteInfo(Prefix("2001:db8:f00::ace:d00d/127"), null, "rmnet0");
assertTrue(r.matches(Address("2001:db8:f00::ace:d00c")));
assertTrue(r.matches(Address("2001:db8:f00::ace:d00d")));
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")));
assertTrue(r.matches(Address("192.0.3.21")));
assertFalse(r.matches(Address("192.0.0.21")));
assertFalse(r.matches(Address("8.8.8.8")));
PatchedRouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
assertFalse(ipv6Default.matches(Address("192.0.2.1")));
PatchedRouteInfo ipv4Default = new PatchedRouteInfo(Prefix("0.0.0.0/0"), null, "rmnet0");
assertTrue(ipv4Default.matches(Address("255.255.255.255")));
assertTrue(ipv4Default.matches(Address("192.0.2.1")));
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
Aggregations