Merge "Add CTS test for Network.fromNetworkHandle()" into pi-dev

am: 9269dc3d3f

Change-Id: I6cc1a78a3b402ce178a21a5dcd1f7ffdeac888b5
This commit is contained in:
Lorenzo Colitti
2018-03-30 14:33:14 +00:00
committed by android-build-merger

View File

@@ -152,4 +152,27 @@ public class MultinetworkApiTest extends AndroidTestCase {
// to query on the default network.
// assertEquals(-OsConstants.ENONET, runGetaddrinfoCheck(eNoNetHandle));
}
public void testNetworkHandle() {
// Test Network -> NetworkHandle -> Network results in the same Network.
for (Network network : getTestableNetworks()) {
long networkHandle = network.getNetworkHandle();
Network newNetwork = Network.fromNetworkHandle(networkHandle);
assertEquals(newNetwork, network);
}
// Test that only obfuscated handles are allowed.
try {
Network.fromNetworkHandle(100);
fail();
} catch (IllegalArgumentException e) {}
try {
Network.fromNetworkHandle(-1);
fail();
} catch (IllegalArgumentException e) {}
try {
Network.fromNetworkHandle(0);
fail();
} catch (IllegalArgumentException e) {}
}
}