use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IpPrefixTest method testEquals.
@SmallTest
public void testEquals() {
IpPrefix p1, p2;
p1 = new IpPrefix("192.0.2.251/23");
p2 = new IpPrefix(new byte[] { (byte) 192, (byte) 0, (byte) 2, (byte) 251 }, 23);
assertAreEqual(p1, p2);
p1 = new IpPrefix("192.0.2.5/23");
assertAreEqual(p1, p2);
p1 = new IpPrefix("192.0.2.5/24");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("192.0.4.5/23");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::80/122");
p2 = new IpPrefix(IPV6_BYTES, 122);
assertEquals("2001:db8:dead:beef:f00::80/122", p2.toString());
assertAreEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::bf/122");
assertAreEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef:f00::8:0/123");
assertAreNotEqual(p1, p2);
p1 = new IpPrefix("2001:db8:dead:beef::/122");
assertAreNotEqual(p1, p2);
// 192.0.2.4/32 != c000:0204::/32.
byte[] ipv6bytes = new byte[16];
System.arraycopy(IPV4_BYTES, 0, ipv6bytes, 0, IPV4_BYTES.length);
p1 = new IpPrefix(ipv6bytes, 32);
assertAreEqual(p1, new IpPrefix("c000:0204::/32"));
p2 = new IpPrefix(IPV4_BYTES, 32);
assertAreNotEqual(p1, p2);
}
use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IpPrefixTest method testTruncation.
public void testTruncation() {
IpPrefix p;
p = new IpPrefix(IPV4_BYTES, 32);
assertEquals("192.0.2.4/32", p.toString());
p = new IpPrefix(IPV4_BYTES, 29);
assertEquals("192.0.2.0/29", p.toString());
p = new IpPrefix(IPV4_BYTES, 8);
assertEquals("192.0.0.0/8", p.toString());
p = new IpPrefix(IPV4_BYTES, 0);
assertEquals("0.0.0.0/0", p.toString());
try {
p = new IpPrefix(IPV4_BYTES, 33);
fail("Expected IllegalArgumentException: invalid prefix length");
} catch (RuntimeException expected) {
}
try {
p = new IpPrefix(IPV4_BYTES, 128);
fail("Expected IllegalArgumentException: invalid prefix length");
} catch (RuntimeException expected) {
}
try {
p = new IpPrefix(IPV4_BYTES, -1);
fail("Expected IllegalArgumentException: negative prefix length");
} catch (RuntimeException expected) {
}
p = new IpPrefix(IPV6_BYTES, 128);
assertEquals("2001:db8:dead:beef:f00::a0/128", p.toString());
p = new IpPrefix(IPV6_BYTES, 122);
assertEquals("2001:db8:dead:beef:f00::80/122", p.toString());
p = new IpPrefix(IPV6_BYTES, 64);
assertEquals("2001:db8:dead:beef::/64", p.toString());
p = new IpPrefix(IPV6_BYTES, 3);
assertEquals("2000::/3", p.toString());
p = new IpPrefix(IPV6_BYTES, 0);
assertEquals("::/0", p.toString());
try {
p = new IpPrefix(IPV6_BYTES, -1);
fail("Expected IllegalArgumentException: negative prefix length");
} catch (RuntimeException expected) {
}
try {
p = new IpPrefix(IPV6_BYTES, 129);
fail("Expected IllegalArgumentException: negative prefix length");
} catch (RuntimeException expected) {
}
}
use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IpPrefixTest method testContains.
@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")));
}
use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IpPrefixTest method testParceling.
public void testParceling() {
IpPrefix p;
p = new IpPrefix("2001:4860:db8::/64");
assertParcelingIsLossless(p);
p = new IpPrefix("192.0.2.0/25");
assertParcelingIsLossless(p);
}
use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IpPrefixTest method testConstructor.
@SmallTest
public void testConstructor() {
IpPrefix p;
try {
p = new IpPrefix((byte[]) null, 9);
fail("Expected NullPointerException: null byte array");
} catch (RuntimeException expected) {
}
try {
p = new IpPrefix((InetAddress) null, 10);
fail("Expected NullPointerException: null InetAddress");
} catch (RuntimeException expected) {
}
try {
p = new IpPrefix((String) null);
fail("Expected NullPointerException: null String");
} catch (RuntimeException expected) {
}
try {
byte[] b2 = { 1, 2, 3, 4, 5 };
p = new IpPrefix(b2, 29);
fail("Expected IllegalArgumentException: invalid array length");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("1.2.3.4");
fail("Expected IllegalArgumentException: no prefix length");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("1.2.3.4/");
fail("Expected IllegalArgumentException: empty prefix length");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("foo/32");
fail("Expected IllegalArgumentException: invalid address");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("1/32");
fail("Expected IllegalArgumentException: deprecated IPv4 format");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("1.2.3.256/32");
fail("Expected IllegalArgumentException: invalid IPv4 address");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("foo/32");
fail("Expected IllegalArgumentException: non-address");
} catch (IllegalArgumentException expected) {
}
try {
p = new IpPrefix("f00:::/32");
fail("Expected IllegalArgumentException: invalid IPv6 address");
} catch (IllegalArgumentException expected) {
}
}
Aggregations