Make LinkPropertiesTest pass, and fix an NPE.
aosp/973686 added the DHCP server address to LinkProperties, but it did not have any tests, and would throw NPE when parceling a LinkProperties that did not have a DHCP server. Add tests and fix the bug. Bug: 134098566 Test: unit test now passes Change-Id: If28f0be650963e8d9af7eb53f6940824582a2db3
This commit is contained in:
@@ -1674,7 +1674,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
dest.writeString(mPrivateDnsServerName);
|
dest.writeString(mPrivateDnsServerName);
|
||||||
writeAddresses(dest, mPcscfs);
|
writeAddresses(dest, mPcscfs);
|
||||||
dest.writeString(mDomains);
|
dest.writeString(mDomains);
|
||||||
dest.writeByteArray(mDhcpServerAddress.getAddress());
|
writeAddress(dest, mDhcpServerAddress);
|
||||||
dest.writeInt(mMtu);
|
dest.writeInt(mMtu);
|
||||||
dest.writeString(mTcpBufferSizes);
|
dest.writeString(mTcpBufferSizes);
|
||||||
dest.writeInt(mRoutes.size());
|
dest.writeInt(mRoutes.size());
|
||||||
@@ -1703,8 +1703,9 @@ public final class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeAddress(@NonNull Parcel dest, @NonNull InetAddress addr) {
|
private static void writeAddress(@NonNull Parcel dest, @Nullable InetAddress addr) {
|
||||||
dest.writeByteArray(addr.getAddress());
|
byte[] addressBytes = (addr == null ? null : addr.getAddress());
|
||||||
|
dest.writeByteArray(addressBytes);
|
||||||
if (addr instanceof Inet6Address) {
|
if (addr instanceof Inet6Address) {
|
||||||
final Inet6Address v6Addr = (Inet6Address) addr;
|
final Inet6Address v6Addr = (Inet6Address) addr;
|
||||||
final boolean hasScopeId = v6Addr.getScopeId() != 0;
|
final boolean hasScopeId = v6Addr.getScopeId() != 0;
|
||||||
@@ -1713,9 +1714,11 @@ public final class LinkProperties implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@Nullable
|
||||||
private static InetAddress readAddress(@NonNull Parcel p) throws UnknownHostException {
|
private static InetAddress readAddress(@NonNull Parcel p) throws UnknownHostException {
|
||||||
final byte[] addr = p.createByteArray();
|
final byte[] addr = p.createByteArray();
|
||||||
|
if (addr == null) return null;
|
||||||
|
|
||||||
if (addr.length == INET6_ADDR_LENGTH) {
|
if (addr.length == INET6_ADDR_LENGTH) {
|
||||||
final boolean hasScopeId = p.readBoolean();
|
final boolean hasScopeId = p.readBoolean();
|
||||||
final int scopeId = hasScopeId ? p.readInt() : 0;
|
final int scopeId = hasScopeId ? p.readInt() : 0;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import androidx.test.runner.AndroidJUnit4;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -65,6 +66,7 @@ public class LinkPropertiesTest {
|
|||||||
private static final InetAddress GATEWAY62 = address("fe80::6:22%lo");
|
private static final InetAddress GATEWAY62 = address("fe80::6:22%lo");
|
||||||
private static final InetAddress TESTIPV4ADDR = address("192.168.47.42");
|
private static final InetAddress TESTIPV4ADDR = address("192.168.47.42");
|
||||||
private static final InetAddress TESTIPV6ADDR = address("fe80::7:33%43");
|
private static final InetAddress TESTIPV6ADDR = address("fe80::7:33%43");
|
||||||
|
private static final Inet4Address DHCPSERVER = (Inet4Address) address("192.0.2.1");
|
||||||
private static final String NAME = "qmi0";
|
private static final String NAME = "qmi0";
|
||||||
private static final String DOMAINS = "google.com";
|
private static final String DOMAINS = "google.com";
|
||||||
private static final String PRIV_DNS_SERVER_NAME = "private.dns.com";
|
private static final String PRIV_DNS_SERVER_NAME = "private.dns.com";
|
||||||
@@ -93,6 +95,7 @@ public class LinkPropertiesTest {
|
|||||||
assertNull(lp.getHttpProxy());
|
assertNull(lp.getHttpProxy());
|
||||||
assertNull(lp.getTcpBufferSizes());
|
assertNull(lp.getTcpBufferSizes());
|
||||||
assertNull(lp.getNat64Prefix());
|
assertNull(lp.getNat64Prefix());
|
||||||
|
assertNull(lp.getDhcpServerAddress());
|
||||||
assertFalse(lp.isProvisioned());
|
assertFalse(lp.isProvisioned());
|
||||||
assertFalse(lp.isIpv4Provisioned());
|
assertFalse(lp.isIpv4Provisioned());
|
||||||
assertFalse(lp.isIpv6Provisioned());
|
assertFalse(lp.isIpv6Provisioned());
|
||||||
@@ -119,6 +122,7 @@ public class LinkPropertiesTest {
|
|||||||
lp.setMtu(MTU);
|
lp.setMtu(MTU);
|
||||||
lp.setTcpBufferSizes(TCP_BUFFER_SIZES);
|
lp.setTcpBufferSizes(TCP_BUFFER_SIZES);
|
||||||
lp.setNat64Prefix(new IpPrefix("2001:db8:0:64::/96"));
|
lp.setNat64Prefix(new IpPrefix("2001:db8:0:64::/96"));
|
||||||
|
lp.setDhcpServerAddress(DHCPSERVER);
|
||||||
lp.setWakeOnLanSupported(true);
|
lp.setWakeOnLanSupported(true);
|
||||||
return lp;
|
return lp;
|
||||||
}
|
}
|
||||||
@@ -960,11 +964,13 @@ public class LinkPropertiesTest {
|
|||||||
|
|
||||||
source.setWakeOnLanSupported(true);
|
source.setWakeOnLanSupported(true);
|
||||||
|
|
||||||
|
source.setDhcpServerAddress((Inet4Address) GATEWAY1);
|
||||||
|
|
||||||
final LinkProperties stacked = new LinkProperties();
|
final LinkProperties stacked = new LinkProperties();
|
||||||
stacked.setInterfaceName("test-stacked");
|
stacked.setInterfaceName("test-stacked");
|
||||||
source.addStackedLink(stacked);
|
source.addStackedLink(stacked);
|
||||||
|
|
||||||
assertParcelSane(source, 15 /* fieldCount */);
|
assertParcelSane(source, 16 /* fieldCount */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -1090,6 +1096,15 @@ public class LinkPropertiesTest {
|
|||||||
assertFalse(lp.isPrivateDnsActive());
|
assertFalse(lp.isPrivateDnsActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDhcpServerAddress() {
|
||||||
|
final LinkProperties lp = makeTestObject();
|
||||||
|
assertEquals(DHCPSERVER, lp.getDhcpServerAddress());
|
||||||
|
|
||||||
|
lp.clear();
|
||||||
|
assertNull(lp.getDhcpServerAddress());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWakeOnLanSupported() {
|
public void testWakeOnLanSupported() {
|
||||||
final LinkProperties lp = makeTestObject();
|
final LinkProperties lp = makeTestObject();
|
||||||
|
|||||||
Reference in New Issue
Block a user