Merge changes I6fb98e87,I3f61b474 into main
* changes: Delete unused TestInterfaceStateListener Reset EthernetManagerTest to reintroduce InterfaceStateListener
This commit is contained in:
commit
7134b8ca22
1 changed files with 227 additions and 183 deletions
|
|
@ -17,87 +17,10 @@ package com.android.testutils
|
|||
|
||||
import android.net.EthernetManager.ETHERNET_STATE_DISABLED
|
||||
import android.net.EthernetManager.ETHERNET_STATE_ENABLED
|
||||
import android.net.EthernetManager.InterfaceStateListener
|
||||
import android.net.EthernetManager.ROLE_CLIENT
|
||||
import android.net.EthernetManager.ROLE_NONE
|
||||
import android.net.EthernetManager.ROLE_SERVER
|
||||
import android.net.EthernetManager.STATE_ABSENT
|
||||
import android.net.EthernetManager.STATE_LINK_DOWN
|
||||
import android.net.EthernetManager.STATE_LINK_UP
|
||||
import android.net.IpConfiguration
|
||||
import com.android.net.module.util.TestableCallback
|
||||
import com.android.testutils.TestEthernetStateListener.EthernetStateChanged
|
||||
import com.android.testutils.TestInterfaceStateListener.InterfaceStateChanged
|
||||
import java.util.function.IntConsumer
|
||||
|
||||
private val DEFAULT_IP_CONFIGURATION = IpConfiguration(
|
||||
IpConfiguration.IpAssignment.DHCP,
|
||||
IpConfiguration.ProxySettings.NONE,
|
||||
null,
|
||||
null
|
||||
)
|
||||
|
||||
/**
|
||||
* A test listener for interface state.
|
||||
*/
|
||||
class TestInterfaceStateListener : TestableCallback<InterfaceStateChanged>(),
|
||||
InterfaceStateListener {
|
||||
data class InterfaceStateChanged(
|
||||
val iface: String,
|
||||
val state: Int,
|
||||
val role: Int,
|
||||
val configuration: IpConfiguration?
|
||||
) {
|
||||
override fun toString(): String {
|
||||
val stateString = when (state) {
|
||||
STATE_ABSENT -> "STATE_ABSENT"
|
||||
STATE_LINK_UP -> "STATE_LINK_UP"
|
||||
STATE_LINK_DOWN -> "STATE_LINK_DOWN"
|
||||
else -> state.toString()
|
||||
}
|
||||
val roleString = when (role) {
|
||||
ROLE_NONE -> "ROLE_NONE"
|
||||
ROLE_CLIENT -> "ROLE_CLIENT"
|
||||
ROLE_SERVER -> "ROLE_SERVER"
|
||||
else -> role.toString()
|
||||
}
|
||||
return ("InterfaceStateChanged(iface=$iface, state=$stateString, " +
|
||||
"role=$roleString, ipConfig=$configuration)")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInterfaceStateChanged(
|
||||
iface: String,
|
||||
state: Int,
|
||||
role: Int,
|
||||
configuration: IpConfiguration?,
|
||||
) {
|
||||
history.add(InterfaceStateChanged(iface, state, role, configuration))
|
||||
}
|
||||
|
||||
fun expectInterfaceStateChanged(
|
||||
iface: String,
|
||||
state: Int,
|
||||
role: Int,
|
||||
timeoutMs: Long = defaultTimeoutMs
|
||||
): InterfaceStateChanged = expect(timeoutMs = timeoutMs) {
|
||||
val expectedConfig = if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null
|
||||
it.iface == iface && it.state == state && it.role == role &&
|
||||
it.configuration == expectedConfig
|
||||
}
|
||||
|
||||
fun eventuallyExpectInterfaceStateChanged(
|
||||
iface: String,
|
||||
state: Int,
|
||||
role: Int,
|
||||
timeoutMs: Long = defaultTimeoutMs
|
||||
): InterfaceStateChanged = eventuallyExpect(timeoutMs = timeoutMs) {
|
||||
val expectedConfig = if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null
|
||||
it.iface == iface && it.state == state && it.role == role &&
|
||||
it.configuration == expectedConfig
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A test listener for ethernet state.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue