Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09e5726e authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Skip Route tests that are R-specific on Q" am: a68f1010 am:...

Merge "Skip Route tests that are R-specific on Q" am: a68f1010 am: 30787c61 am: 63d7b375 am: fdfb4edc am: 772039da

Change-Id: I3b2e240b01b33d1346e911f4d36ddb28bb38df99
parents 19067d6b 772039da
Loading
Loading
Loading
Loading
+73 −10
Original line number Diff line number Diff line
@@ -19,19 +19,40 @@ package android.net;
import static android.net.RouteInfo.RTN_UNREACHABLE;

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.ParcelUtilsKt.assertParcelSane;
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.Inet6Address;
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) {
        return InetAddress.parseNumericAddress(addr);
@@ -41,16 +62,33 @@ public class RouteInfoTest extends TestCase {
        return new IpPrefix(prefix);
    }

    @SmallTest
    @Test
    public void testConstructor() {
        RouteInfo r;

        // Invalid input.
        try {
            r = new RouteInfo((IpPrefix) null, null, "rmnet0");
            fail("Expected RuntimeException:  destination and gateway null");
        } 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.
        r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
        assertEquals(Prefix("::/0"), r.getDestination());
@@ -74,6 +112,7 @@ public class RouteInfoTest extends TestCase {
        assertNull(r.getInterface());
    }

    @Test
    public void testMatches() {
        class PatchedRouteInfo {
            private final RouteInfo mRouteInfo;
@@ -113,6 +152,7 @@ public class RouteInfoTest extends TestCase {
        assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
    }

    @Test
    public void testEquals() {
        // IPv4
        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);
    }

    @Test
    public void testHostAndDefaultRoutes() {
        RouteInfo r;

@@ -228,6 +269,7 @@ public class RouteInfoTest extends TestCase {
        assertFalse(r.isIPv6Default());
    }

    @Test
    public void testTruncation() {
      LinkAddress l;
      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
    // 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);
    @Test
    public void testMulticastRoute() {
      RouteInfo r;
      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.
    }

    @Test
    public void testParceling() {
        RouteInfo r;
        r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), null);
        assertParcelingIsLossless(r);
        r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
        assertParcelingIsLossless(r);
        r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0", RTN_UNREACHABLE);
        assertParcelingIsLossless(r);
    }

        r = new RouteInfo(Prefix("::/0"), Address("2001:db8::"), null);
    @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);
    }

        r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
        assertParcelSane(r, 7);
    @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() {
        RouteInfo r;
        r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",