Merge "Skip Route tests that are R-specific on Q"
This commit is contained in:
@@ -19,19 +19,40 @@ package android.net;
|
|||||||
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
||||||
|
|
||||||
import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
|
import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
|
||||||
|
import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
|
||||||
import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
|
import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
|
||||||
import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
|
|
||||||
import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
|
import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
|
||||||
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import android.os.Build;
|
||||||
|
|
||||||
|
import androidx.test.filters.SmallTest;
|
||||||
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule;
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
|
||||||
public class RouteInfoTest extends TestCase {
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@SmallTest
|
||||||
|
public class RouteInfoTest {
|
||||||
|
@Rule
|
||||||
|
public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
|
||||||
|
|
||||||
|
private static final int INVALID_ROUTE_TYPE = -1;
|
||||||
|
|
||||||
private InetAddress Address(String addr) {
|
private InetAddress Address(String addr) {
|
||||||
return InetAddress.parseNumericAddress(addr);
|
return InetAddress.parseNumericAddress(addr);
|
||||||
@@ -41,15 +62,32 @@ public class RouteInfoTest extends TestCase {
|
|||||||
return new IpPrefix(prefix);
|
return new IpPrefix(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@Test
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
|
|
||||||
// Invalid input.
|
// Invalid input.
|
||||||
try {
|
try {
|
||||||
r = new RouteInfo((IpPrefix) null, null, "rmnet0");
|
r = new RouteInfo((IpPrefix) null, null, "rmnet0");
|
||||||
fail("Expected RuntimeException: destination and gateway null");
|
fail("Expected RuntimeException: destination and gateway null");
|
||||||
} catch(RuntimeException e) {}
|
} catch (RuntimeException e) { }
|
||||||
|
|
||||||
|
try {
|
||||||
|
r = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("2001:db8::1"), "rmnet0",
|
||||||
|
INVALID_ROUTE_TYPE);
|
||||||
|
fail("Invalid route type should cause exception");
|
||||||
|
} catch (IllegalArgumentException e) { }
|
||||||
|
|
||||||
|
try {
|
||||||
|
r = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("192.0.2.1"), "rmnet0",
|
||||||
|
RTN_UNREACHABLE);
|
||||||
|
fail("Address family mismatch should cause exception");
|
||||||
|
} catch (IllegalArgumentException e) { }
|
||||||
|
|
||||||
|
try {
|
||||||
|
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("2001:db8::1"), "rmnet0",
|
||||||
|
RTN_UNREACHABLE);
|
||||||
|
fail("Address family mismatch should cause exception");
|
||||||
|
} catch (IllegalArgumentException e) { }
|
||||||
|
|
||||||
// Null destination is default route.
|
// Null destination is default route.
|
||||||
r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
|
r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
|
||||||
@@ -74,6 +112,7 @@ public class RouteInfoTest extends TestCase {
|
|||||||
assertNull(r.getInterface());
|
assertNull(r.getInterface());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMatches() {
|
public void testMatches() {
|
||||||
class PatchedRouteInfo {
|
class PatchedRouteInfo {
|
||||||
private final RouteInfo mRouteInfo;
|
private final RouteInfo mRouteInfo;
|
||||||
@@ -113,6 +152,7 @@ public class RouteInfoTest extends TestCase {
|
|||||||
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
|
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testEquals() {
|
public void testEquals() {
|
||||||
// IPv4
|
// IPv4
|
||||||
RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
|
RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
|
||||||
@@ -146,6 +186,7 @@ public class RouteInfoTest extends TestCase {
|
|||||||
assertNotEqualEitherWay(r1, r3);
|
assertNotEqualEitherWay(r1, r3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHostAndDefaultRoutes() {
|
public void testHostAndDefaultRoutes() {
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
|
|
||||||
@@ -228,6 +269,7 @@ public class RouteInfoTest extends TestCase {
|
|||||||
assertFalse(r.isIPv6Default());
|
assertFalse(r.isIPv6Default());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTruncation() {
|
public void testTruncation() {
|
||||||
LinkAddress l;
|
LinkAddress l;
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
@@ -244,6 +286,7 @@ public class RouteInfoTest extends TestCase {
|
|||||||
// Make sure that creating routes to multicast addresses doesn't throw an exception. Even though
|
// Make sure that creating routes to multicast addresses doesn't throw an exception. Even though
|
||||||
// there's nothing we can do with them, we don't want to crash if, e.g., someone calls
|
// there's nothing we can do with them, we don't want to crash if, e.g., someone calls
|
||||||
// requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
|
// requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
|
||||||
|
@Test
|
||||||
public void testMulticastRoute() {
|
public void testMulticastRoute() {
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
|
r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
|
||||||
@@ -251,16 +294,36 @@ public class RouteInfoTest extends TestCase {
|
|||||||
// No exceptions? Good.
|
// No exceptions? Good.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testParceling() {
|
public void testParceling() {
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
|
r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), null);
|
||||||
r = new RouteInfo(Prefix("::/0"), Address("2001:db8::"), null);
|
|
||||||
assertParcelingIsLossless(r);
|
assertParcelingIsLossless(r);
|
||||||
|
|
||||||
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
|
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
|
||||||
assertParcelSane(r, 7);
|
assertParcelingIsLossless(r);
|
||||||
|
r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0", RTN_UNREACHABLE);
|
||||||
|
assertParcelingIsLossless(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||||
|
public void testMtuParceling() {
|
||||||
|
final RouteInfo r = new RouteInfo(Prefix("ff02::1/128"), Address("2001:db8::"), "testiface",
|
||||||
|
RTN_UNREACHABLE, 1450 /* mtu */);
|
||||||
|
assertParcelingIsLossless(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @IgnoreAfter(Build.VERSION_CODES.Q)
|
||||||
|
public void testFieldCount_Q() {
|
||||||
|
assertFieldCountEquals(6, RouteInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||||
|
public void testFieldCount() {
|
||||||
|
// Make sure any new field is covered by the above parceling tests when changing this number
|
||||||
|
assertFieldCountEquals(7, RouteInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||||
public void testMtu() {
|
public void testMtu() {
|
||||||
RouteInfo r;
|
RouteInfo r;
|
||||||
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",
|
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",
|
||||||
|
|||||||
Reference in New Issue
Block a user