Add CTS for SocketUtils.makePacketSocketAddress(int, int, byte[])
Bug: 149426063
Bug: 150640362
Test: atest CtsNetTestCasesLatestSdk:android.net.util.SocketUtilsTest
on both Q and R devices
Change-Id: I4b5a3dfb78b404d414b7dc358e6f16c3414a8b33
Merged-In: I4b5a3dfb78b404d414b7dc358e6f16c3414a8b33
(cherry picked from aosp/1243868)
This commit is contained in:
committed by
Paul Hu
parent
10736d2107
commit
1494a56ecf
@@ -14,8 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package android.net.util;
|
package android.net.util
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
import android.system.NetlinkSocketAddress
|
import android.system.NetlinkSocketAddress
|
||||||
import android.system.Os
|
import android.system.Os
|
||||||
import android.system.OsConstants.AF_INET
|
import android.system.OsConstants.AF_INET
|
||||||
@@ -26,18 +27,26 @@ import android.system.OsConstants.SOCK_DGRAM
|
|||||||
import android.system.PacketSocketAddress
|
import android.system.PacketSocketAddress
|
||||||
import androidx.test.filters.SmallTest
|
import androidx.test.filters.SmallTest
|
||||||
import androidx.test.runner.AndroidJUnit4
|
import androidx.test.runner.AndroidJUnit4
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule
|
||||||
|
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Assert.fail
|
import org.junit.Assert.fail
|
||||||
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
private const val TEST_INDEX = 123
|
private const val TEST_INDEX = 123
|
||||||
private const val TEST_PORT = 555
|
private const val TEST_PORT = 555
|
||||||
|
private const val FF_BYTE = 0xff.toByte()
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@SmallTest
|
@SmallTest
|
||||||
class SocketUtilsTest {
|
class SocketUtilsTest {
|
||||||
|
@Rule @JvmField
|
||||||
|
val ignoreRule = DevSdkIgnoreRule()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMakeNetlinkSocketAddress() {
|
fun testMakeNetlinkSocketAddress() {
|
||||||
val nlAddress = SocketUtils.makeNetlinkSocketAddress(TEST_PORT, RTMGRP_NEIGH)
|
val nlAddress = SocketUtils.makeNetlinkSocketAddress(TEST_PORT, RTMGRP_NEIGH)
|
||||||
@@ -50,16 +59,21 @@ class SocketUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testMakePacketSocketAddress() {
|
fun testMakePacketSocketAddress_Q() {
|
||||||
val pkAddress = SocketUtils.makePacketSocketAddress(ETH_P_ALL, TEST_INDEX)
|
val pkAddress = SocketUtils.makePacketSocketAddress(ETH_P_ALL, TEST_INDEX)
|
||||||
assertTrue("Not PacketSocketAddress object", pkAddress is PacketSocketAddress)
|
assertTrue("Not PacketSocketAddress object", pkAddress is PacketSocketAddress)
|
||||||
|
|
||||||
val ff = 0xff.toByte()
|
val pkAddress2 = SocketUtils.makePacketSocketAddress(TEST_INDEX, ByteArray(6) { FF_BYTE })
|
||||||
val pkAddress2 = SocketUtils.makePacketSocketAddress(TEST_INDEX,
|
|
||||||
byteArrayOf(ff, ff, ff, ff, ff, ff))
|
|
||||||
assertTrue("Not PacketSocketAddress object", pkAddress2 is PacketSocketAddress)
|
assertTrue("Not PacketSocketAddress object", pkAddress2 is PacketSocketAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||||
|
fun testMakePacketSocketAddress() {
|
||||||
|
val pkAddress = SocketUtils.makePacketSocketAddress(
|
||||||
|
ETH_P_ALL, TEST_INDEX, ByteArray(6) { FF_BYTE })
|
||||||
|
assertTrue("Not PacketSocketAddress object", pkAddress is PacketSocketAddress)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCloseSocket() {
|
fun testCloseSocket() {
|
||||||
// Expect no exception happening with null object.
|
// Expect no exception happening with null object.
|
||||||
|
|||||||
Reference in New Issue
Block a user