Loading tests/net/java/android/net/ipmemorystore/ParcelableTests.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.net.ipmemorystore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import android.net.quirks.IPv6ProvisioningLossQuirk; import android.net.quirks.IPv6ProvisioningLossQuirkParcelable; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading Loading @@ -46,7 +48,7 @@ public class ParcelableTests { builder.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); builder.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); // lease will expire in two hours // lease will expire in two hours builder.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); builder.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); // groupHint stays null this time around // cluster stays null this time around builder.setDnsAddresses(Collections.emptyList()); builder.setDnsAddresses(Collections.emptyList()); builder.setMtu(18); builder.setMtu(18); in = builder.build(); in = builder.build(); Loading @@ -69,7 +71,7 @@ public class ParcelableTests { // Verify that this test does not miss any new field added later. // Verify that this test does not miss any new field added later. // If any field is added to NetworkAttributes it must be tested here for parceling // If any field is added to NetworkAttributes it must be tested here for parceling // roundtrip. // roundtrip. assertEquals(5, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) assertEquals(6, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); } } Loading Loading @@ -104,6 +106,22 @@ public class ParcelableTests { assertEquals(in.confidence, out.confidence, 0.01f /* delta */); assertEquals(in.confidence, out.confidence, 0.01f /* delta */); } } @Test public void testIPv6ProvisioningLossQuirkParceling() throws Exception { final NetworkAttributes.Builder builder = new NetworkAttributes.Builder(); final IPv6ProvisioningLossQuirkParcelable parcelable = new IPv6ProvisioningLossQuirkParcelable(); final long expiry = System.currentTimeMillis() + 7_200_000; parcelable.detectionCount = 3; parcelable.quirkExpiry = expiry; // quirk info will expire in two hours builder.setIpv6ProvLossQuirk(IPv6ProvisioningLossQuirk.fromStableParcelable(parcelable)); final NetworkAttributes in = builder.build(); final NetworkAttributes out = new NetworkAttributes(parcelingRoundTrip(in.toParcelable())); assertEquals(out.ipv6ProvLossQuirk, in.ipv6ProvLossQuirk); } private <T extends Parcelable> T parcelingRoundTrip(final T in) throws Exception { private <T extends Parcelable> T parcelingRoundTrip(final T in) throws Exception { final Parcel p = Parcel.obtain(); final Parcel p = Parcel.obtain(); in.writeToParcel(p, /* flags */ 0); in.writeToParcel(p, /* flags */ 0); Loading tests/net/java/com/android/server/net/ipmemorystore/NetworkAttributesTest.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.net.ipmemorystore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import android.net.ipmemorystore.NetworkAttributes; import android.net.ipmemorystore.NetworkAttributes; import android.net.quirks.IPv6ProvisioningLossQuirk; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -52,6 +53,8 @@ public class NetworkAttributesTest { } } assertEquals(sum, NetworkAttributes.TOTAL_WEIGHT, EPSILON); assertEquals(sum, NetworkAttributes.TOTAL_WEIGHT, EPSILON); final IPv6ProvisioningLossQuirk ipv6ProvLossQuirk = new IPv6ProvisioningLossQuirk(3, System.currentTimeMillis() + 7_200_000); // Use directly the constructor with all attributes, and make sure that when compared // Use directly the constructor with all attributes, and make sure that when compared // to itself the score is a clean 1.0f. // to itself the score is a clean 1.0f. final NetworkAttributes na = final NetworkAttributes na = Loading @@ -61,7 +64,7 @@ public class NetworkAttributesTest { "some hint", "some hint", Arrays.asList(Inet4Address.getByAddress(new byte[] {5, 6, 7, 8}), Arrays.asList(Inet4Address.getByAddress(new byte[] {5, 6, 7, 8}), Inet4Address.getByAddress(new byte[] {9, 0, 1, 2})), Inet4Address.getByAddress(new byte[] {9, 0, 1, 2})), 98); 98, ipv6ProvLossQuirk); assertEquals(1.0f, na.getNetworkGroupSamenessConfidence(na), EPSILON); assertEquals(1.0f, na.getNetworkGroupSamenessConfidence(na), EPSILON); } } } } Loading
tests/net/java/android/net/ipmemorystore/ParcelableTests.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,8 @@ package android.net.ipmemorystore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import android.net.quirks.IPv6ProvisioningLossQuirk; import android.net.quirks.IPv6ProvisioningLossQuirkParcelable; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; Loading Loading @@ -46,7 +48,7 @@ public class ParcelableTests { builder.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); builder.setAssignedV4Address((Inet4Address) Inet4Address.getByName("1.2.3.4")); // lease will expire in two hours // lease will expire in two hours builder.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); builder.setAssignedV4AddressExpiry(System.currentTimeMillis() + 7_200_000); // groupHint stays null this time around // cluster stays null this time around builder.setDnsAddresses(Collections.emptyList()); builder.setDnsAddresses(Collections.emptyList()); builder.setMtu(18); builder.setMtu(18); in = builder.build(); in = builder.build(); Loading @@ -69,7 +71,7 @@ public class ParcelableTests { // Verify that this test does not miss any new field added later. // Verify that this test does not miss any new field added later. // If any field is added to NetworkAttributes it must be tested here for parceling // If any field is added to NetworkAttributes it must be tested here for parceling // roundtrip. // roundtrip. assertEquals(5, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) assertEquals(6, Arrays.stream(NetworkAttributes.class.getDeclaredFields()) .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); .filter(f -> !Modifier.isStatic(f.getModifiers())).count()); } } Loading Loading @@ -104,6 +106,22 @@ public class ParcelableTests { assertEquals(in.confidence, out.confidence, 0.01f /* delta */); assertEquals(in.confidence, out.confidence, 0.01f /* delta */); } } @Test public void testIPv6ProvisioningLossQuirkParceling() throws Exception { final NetworkAttributes.Builder builder = new NetworkAttributes.Builder(); final IPv6ProvisioningLossQuirkParcelable parcelable = new IPv6ProvisioningLossQuirkParcelable(); final long expiry = System.currentTimeMillis() + 7_200_000; parcelable.detectionCount = 3; parcelable.quirkExpiry = expiry; // quirk info will expire in two hours builder.setIpv6ProvLossQuirk(IPv6ProvisioningLossQuirk.fromStableParcelable(parcelable)); final NetworkAttributes in = builder.build(); final NetworkAttributes out = new NetworkAttributes(parcelingRoundTrip(in.toParcelable())); assertEquals(out.ipv6ProvLossQuirk, in.ipv6ProvLossQuirk); } private <T extends Parcelable> T parcelingRoundTrip(final T in) throws Exception { private <T extends Parcelable> T parcelingRoundTrip(final T in) throws Exception { final Parcel p = Parcel.obtain(); final Parcel p = Parcel.obtain(); in.writeToParcel(p, /* flags */ 0); in.writeToParcel(p, /* flags */ 0); Loading
tests/net/java/com/android/server/net/ipmemorystore/NetworkAttributesTest.java +4 −1 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.net.ipmemorystore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import android.net.ipmemorystore.NetworkAttributes; import android.net.ipmemorystore.NetworkAttributes; import android.net.quirks.IPv6ProvisioningLossQuirk; import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import androidx.test.runner.AndroidJUnit4; Loading Loading @@ -52,6 +53,8 @@ public class NetworkAttributesTest { } } assertEquals(sum, NetworkAttributes.TOTAL_WEIGHT, EPSILON); assertEquals(sum, NetworkAttributes.TOTAL_WEIGHT, EPSILON); final IPv6ProvisioningLossQuirk ipv6ProvLossQuirk = new IPv6ProvisioningLossQuirk(3, System.currentTimeMillis() + 7_200_000); // Use directly the constructor with all attributes, and make sure that when compared // Use directly the constructor with all attributes, and make sure that when compared // to itself the score is a clean 1.0f. // to itself the score is a clean 1.0f. final NetworkAttributes na = final NetworkAttributes na = Loading @@ -61,7 +64,7 @@ public class NetworkAttributesTest { "some hint", "some hint", Arrays.asList(Inet4Address.getByAddress(new byte[] {5, 6, 7, 8}), Arrays.asList(Inet4Address.getByAddress(new byte[] {5, 6, 7, 8}), Inet4Address.getByAddress(new byte[] {9, 0, 1, 2})), Inet4Address.getByAddress(new byte[] {9, 0, 1, 2})), 98); 98, ipv6ProvLossQuirk); assertEquals(1.0f, na.getNetworkGroupSamenessConfidence(na), EPSILON); assertEquals(1.0f, na.getNetworkGroupSamenessConfidence(na), EPSILON); } } } }