From a950b32db5b622e89585fcc510d361d7a0478d31 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Wed, 4 Dec 2024 16:45:20 +0800 Subject: [PATCH] Support optional parameters for CSLocalAgentCreationTests This is a test-only no-op refactor which only enables the ability for follow-up changes to add more parameters without exponentially increasing the number of parameter combinations. Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalAgentCreationTests Bug: 349487600 Change-Id: I61bcabf7c93dab43984da0ade3e61a7117fe040a --- .../CSLocalAgentCreationTests.kt | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tests/unit/java/com/android/server/connectivityservice/CSLocalAgentCreationTests.kt b/tests/unit/java/com/android/server/connectivityservice/CSLocalAgentCreationTests.kt index cb98454fda..16a30aac38 100644 --- a/tests/unit/java/com/android/server/connectivityservice/CSLocalAgentCreationTests.kt +++ b/tests/unit/java/com/android/server/connectivityservice/CSLocalAgentCreationTests.kt @@ -55,25 +55,28 @@ private fun defaultLnc() = FromS(LocalNetworkConfig.Builder().build()) @RunWith(DevSdkIgnoreRunner::class) @SmallTest @IgnoreUpTo(Build.VERSION_CODES.R) -class CSLocalAgentCreationTests( - private val sdkLevel: Int, - private val isTv: Boolean, - private val addLocalNetCapToRequest: Boolean -) : CSTest() { +class CSLocalAgentCreationTests : CSTest() { + @Parameterized.Parameter(0) lateinit var params: TestParams + + data class TestParams( + val sdkLevel: Int, + val isTv: Boolean = false, + val addLocalNetCapToRequest: Boolean = true) + companion object { @JvmStatic @Parameterized.Parameters fun arguments() = listOf( - arrayOf(VERSION_V, false /* isTv */, true /* addLocalNetCapToRequest */), - arrayOf(VERSION_V, false /* isTv */, false /* addLocalNetCapToRequest */), - arrayOf(VERSION_V, true /* isTv */, true /* addLocalNetCapToRequest */), - arrayOf(VERSION_V, true /* isTv */, false /* addLocalNetCapToRequest */), - arrayOf(VERSION_U, false /* isTv */, true /* addLocalNetCapToRequest */), - arrayOf(VERSION_U, false /* isTv */, false /* addLocalNetCapToRequest */), - arrayOf(VERSION_U, true /* isTv */, true /* addLocalNetCapToRequest */), - arrayOf(VERSION_U, true /* isTv */, false /* addLocalNetCapToRequest */), - arrayOf(VERSION_T, false /* isTv */, false /* addLocalNetCapToRequest */), - arrayOf(VERSION_T, true /* isTv */, false /* addLocalNetCapToRequest */), + TestParams(VERSION_V, isTv = false, addLocalNetCapToRequest = true), + TestParams(VERSION_V, isTv = false, addLocalNetCapToRequest = false), + TestParams(VERSION_V, isTv = true, addLocalNetCapToRequest = true), + TestParams(VERSION_V, isTv = true, addLocalNetCapToRequest = false), + TestParams(VERSION_U, isTv = false, addLocalNetCapToRequest = true), + TestParams(VERSION_U, isTv = false, addLocalNetCapToRequest = false), + TestParams(VERSION_U, isTv = true, addLocalNetCapToRequest = true), + TestParams(VERSION_U, isTv = true, addLocalNetCapToRequest = false), + TestParams(VERSION_T, isTv = false, addLocalNetCapToRequest = false), + TestParams(VERSION_T, isTv = true, addLocalNetCapToRequest = false), ) } @@ -84,11 +87,11 @@ class CSLocalAgentCreationTests( @Test fun testLocalAgents() { val netdInOrder = inOrder(netd) - deps.setBuildSdk(sdkLevel) - doReturn(isTv).`when`(packageManager).hasSystemFeature(FEATURE_LEANBACK) + deps.setBuildSdk(params.sdkLevel) + doReturn(params.isTv).`when`(packageManager).hasSystemFeature(FEATURE_LEANBACK) val allNetworksCb = TestableNetworkCallback() val request = NetworkRequest.Builder() - if (addLocalNetCapToRequest) { + if (params.addLocalNetCapToRequest) { request.addCapability(NET_CAPABILITY_LOCAL_NETWORK) } cm.registerNetworkCallback(request.build(), allNetworksCb) @@ -96,7 +99,8 @@ class CSLocalAgentCreationTests( addTransportType(NetworkCapabilities.TRANSPORT_WIFI) addCapability(NET_CAPABILITY_LOCAL_NETWORK) }.build() - val localAgent = if (sdkLevel >= VERSION_V || sdkLevel == VERSION_U && isTv) { + val localAgent = if (params.sdkLevel >= VERSION_V + || params.sdkLevel == VERSION_U && params.isTv) { Agent(nc = ncTemplate, score = keepConnectedScore(), lnc = defaultLnc()) } else { assertFailsWith { Agent(nc = ncTemplate, lnc = defaultLnc()) } @@ -106,7 +110,7 @@ class CSLocalAgentCreationTests( localAgent.connect() netdInOrder.verify(netd).networkCreate( makeNativeNetworkConfigLocal(localAgent.network.netId, INetd.PERMISSION_NONE)) - if (addLocalNetCapToRequest) { + if (params.addLocalNetCapToRequest) { assertEquals(localAgent.network, allNetworksCb.expect().network) } else { allNetworksCb.assertNoCallback(NO_CALLBACK_TIMEOUT_MS)