Add some tests back which were removed for fixing kotlin nullable errors
Followup CL for aosp/2700076 Bug: 296972712 Test: build with aosp/2688146 Change-Id: I617b330c42a99e4c839adac2ea614756b5955ce9
This commit is contained in:
@@ -22,6 +22,7 @@ import androidx.test.filters.SmallTest
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import com.android.testutils.DevSdkIgnoreRule
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
|
||||
import com.android.testutils.NonNullTestUtils
|
||||
import java.net.InetAddress
|
||||
import java.util.Arrays
|
||||
import org.junit.Assert.assertEquals
|
||||
@@ -50,34 +51,47 @@ class KeepalivePacketDataTest {
|
||||
|
||||
// Add for test because constructor of KeepalivePacketData is protected.
|
||||
private inner class TestKeepalivePacketData(
|
||||
srcAddress: InetAddress = TEST_SRC_ADDRV4,
|
||||
srcAddress: InetAddress? = TEST_SRC_ADDRV4,
|
||||
srcPort: Int = TEST_SRC_PORT,
|
||||
dstAddress: InetAddress = TEST_DST_ADDRV4,
|
||||
dstAddress: InetAddress? = TEST_DST_ADDRV4,
|
||||
dstPort: Int = TEST_DST_PORT,
|
||||
data: ByteArray = TESTBYTES
|
||||
) : KeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, data)
|
||||
) : KeepalivePacketData(NonNullTestUtils.nullUnsafe(srcAddress), srcPort,
|
||||
NonNullTestUtils.nullUnsafe(dstAddress), dstPort, data)
|
||||
|
||||
@Test
|
||||
@IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||
fun testConstructor() {
|
||||
var data: TestKeepalivePacketData
|
||||
try {
|
||||
TestKeepalivePacketData(srcAddress = null)
|
||||
fail("Null src address should cause exception")
|
||||
} catch (e: InvalidPacketException) {
|
||||
assertEquals(e.error, ERROR_INVALID_IP_ADDRESS)
|
||||
}
|
||||
|
||||
try {
|
||||
data = TestKeepalivePacketData(dstAddress = TEST_ADDRV6)
|
||||
TestKeepalivePacketData(dstAddress = null)
|
||||
fail("Null dst address should cause exception")
|
||||
} catch (e: InvalidPacketException) {
|
||||
assertEquals(e.error, ERROR_INVALID_IP_ADDRESS)
|
||||
}
|
||||
|
||||
try {
|
||||
TestKeepalivePacketData(dstAddress = TEST_ADDRV6)
|
||||
fail("Ip family mismatched should cause exception")
|
||||
} catch (e: InvalidPacketException) {
|
||||
assertEquals(e.error, ERROR_INVALID_IP_ADDRESS)
|
||||
}
|
||||
|
||||
try {
|
||||
data = TestKeepalivePacketData(srcPort = INVALID_PORT)
|
||||
TestKeepalivePacketData(srcPort = INVALID_PORT)
|
||||
fail("Invalid srcPort should cause exception")
|
||||
} catch (e: InvalidPacketException) {
|
||||
assertEquals(e.error, ERROR_INVALID_PORT)
|
||||
}
|
||||
|
||||
try {
|
||||
data = TestKeepalivePacketData(dstPort = INVALID_PORT)
|
||||
TestKeepalivePacketData(dstPort = INVALID_PORT)
|
||||
fail("Invalid dstPort should cause exception")
|
||||
} catch (e: InvalidPacketException) {
|
||||
assertEquals(e.error, ERROR_INVALID_PORT)
|
||||
|
||||
Reference in New Issue
Block a user