Merge changes I2399960f,I7b6e1a3b into main
* changes: ethernet: clean up EthernetManagerTest ethernet: test adding listener after removing server mode iface
This commit is contained in:
@@ -92,7 +92,6 @@ import kotlin.test.assertFalse
|
|||||||
import kotlin.test.assertNotNull
|
import kotlin.test.assertNotNull
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import kotlin.test.fail
|
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Assume.assumeFalse
|
import org.junit.Assume.assumeFalse
|
||||||
import org.junit.Assume.assumeTrue
|
import org.junit.Assume.assumeTrue
|
||||||
@@ -254,7 +253,7 @@ class EthernetManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <T : CallbackEntry> expectCallback(expected: T): T {
|
fun <T : CallbackEntry> expectCallback(expected: T): T {
|
||||||
val event = pollOrThrow()
|
val event = events.poll(TIMEOUT_MS)
|
||||||
assertEquals(expected, event)
|
assertEquals(expected, event)
|
||||||
return event as T
|
return event as T
|
||||||
}
|
}
|
||||||
@@ -267,14 +266,10 @@ class EthernetManagerTest {
|
|||||||
expectCallback(EthernetStateChanged(state))
|
expectCallback(EthernetStateChanged(state))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createChangeEvent(iface: String, state: Int, role: Int) =
|
private fun createChangeEvent(iface: String, state: Int, role: Int) =
|
||||||
InterfaceStateChanged(iface, state, role,
|
InterfaceStateChanged(iface, state, role,
|
||||||
if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null)
|
if (state != STATE_ABSENT) DEFAULT_IP_CONFIGURATION else null)
|
||||||
|
|
||||||
fun pollOrThrow(): CallbackEntry {
|
|
||||||
return events.poll(TIMEOUT_MS) ?: fail("Did not receive callback after ${TIMEOUT_MS}ms")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun eventuallyExpect(expected: CallbackEntry) {
|
fun eventuallyExpect(expected: CallbackEntry) {
|
||||||
val cb = events.poll(TIMEOUT_MS) { it == expected }
|
val cb = events.poll(TIMEOUT_MS) { it == expected }
|
||||||
assertNotNull(cb, "Never received expected $expected. Received: ${events.backtrace()}")
|
assertNotNull(cb, "Never received expected $expected. Received: ${events.backtrace()}")
|
||||||
@@ -667,6 +662,20 @@ class EthernetManagerTest {
|
|||||||
listener.expectCallback(iface, STATE_LINK_UP, ROLE_CLIENT)
|
listener.expectCallback(iface, STATE_LINK_UP, ROLE_CLIENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCallbacks_afterRemovingServerModeInterface() {
|
||||||
|
// do not run this test if an interface that can be used for tethering already exists.
|
||||||
|
assumeNoInterfaceForTetheringAvailable()
|
||||||
|
|
||||||
|
val iface = createInterface()
|
||||||
|
requestTetheredInterface().expectOnAvailable()
|
||||||
|
removeInterface(iface)
|
||||||
|
|
||||||
|
val listener = EthernetStateListener()
|
||||||
|
addInterfaceStateListener(listener)
|
||||||
|
listener.assertNoCallback()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetInterfaceList() {
|
fun testGetInterfaceList() {
|
||||||
// Create two test interfaces and check the return list contains the interface names.
|
// Create two test interfaces and check the return list contains the interface names.
|
||||||
|
|||||||
Reference in New Issue
Block a user