Merge "Remove expectLinkPropertiesThat"
This commit is contained in:
@@ -34,6 +34,7 @@ import com.android.testutils.RecorderCallback.CallbackEntry.Companion.NETWORK_CA
|
|||||||
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.RESUMED
|
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.RESUMED
|
||||||
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.SUSPENDED
|
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.SUSPENDED
|
||||||
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.UNAVAILABLE
|
import com.android.testutils.RecorderCallback.CallbackEntry.Companion.UNAVAILABLE
|
||||||
|
import com.android.testutils.RecorderCallback.CallbackEntry.LinkPropertiesChanged
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFails
|
import kotlin.test.assertFails
|
||||||
@@ -215,7 +216,7 @@ class TestableNetworkCallbackTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLinkPropertiesThat() {
|
fun testLinkPropertiesCallbacks() {
|
||||||
val net = Network(112)
|
val net = Network(112)
|
||||||
val linkAddress = LinkAddress("fe80::ace:d00d/64")
|
val linkAddress = LinkAddress("fe80::ace:d00d/64")
|
||||||
val mtu = 1984
|
val mtu = 1984
|
||||||
@@ -226,30 +227,30 @@ class TestableNetworkCallbackTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that expecting linkPropsThat anything fails when no callback has been received.
|
// Check that expecting linkPropsThat anything fails when no callback has been received.
|
||||||
assertFails { mCallback.expectLinkPropertiesThat(net, SHORT_TIMEOUT_MS) { true } }
|
assertFails { mCallback.expect<LinkPropertiesChanged>(net, SHORT_TIMEOUT_MS) { true } }
|
||||||
|
|
||||||
// Basic test for true and false
|
// Basic test for true and false
|
||||||
mCallback.onLinkPropertiesChanged(net, linkProps)
|
mCallback.onLinkPropertiesChanged(net, linkProps)
|
||||||
mCallback.expectLinkPropertiesThat(net) { true }
|
mCallback.expect<LinkPropertiesChanged>(net) { true }
|
||||||
mCallback.onLinkPropertiesChanged(net, linkProps)
|
mCallback.onLinkPropertiesChanged(net, linkProps)
|
||||||
assertFails { mCallback.expectLinkPropertiesThat(net, SHORT_TIMEOUT_MS) { false } }
|
assertFails { mCallback.expect<LinkPropertiesChanged>(net, SHORT_TIMEOUT_MS) { false } }
|
||||||
|
|
||||||
// Try a positive and negative case
|
// Try a positive and negative case
|
||||||
mCallback.onLinkPropertiesChanged(net, linkProps)
|
mCallback.onLinkPropertiesChanged(net, linkProps)
|
||||||
mCallback.expectLinkPropertiesThat(net) { lp ->
|
mCallback.expect<LinkPropertiesChanged>(net) {
|
||||||
lp.interfaceName == TEST_INTERFACE_NAME &&
|
it.lp.interfaceName == TEST_INTERFACE_NAME &&
|
||||||
lp.linkAddresses.contains(linkAddress) &&
|
it.lp.linkAddresses.contains(linkAddress) &&
|
||||||
lp.mtu == mtu
|
it.lp.mtu == mtu
|
||||||
}
|
}
|
||||||
mCallback.onLinkPropertiesChanged(net, linkProps)
|
mCallback.onLinkPropertiesChanged(net, linkProps)
|
||||||
assertFails { mCallback.expectLinkPropertiesThat(net, SHORT_TIMEOUT_MS) { lp ->
|
assertFails { mCallback.expect<LinkPropertiesChanged>(net, SHORT_TIMEOUT_MS) {
|
||||||
lp.interfaceName != TEST_INTERFACE_NAME
|
it.lp.interfaceName != TEST_INTERFACE_NAME
|
||||||
} }
|
} }
|
||||||
|
|
||||||
// Try a matching callback on the wrong network
|
// Try a matching callback on the wrong network
|
||||||
mCallback.onLinkPropertiesChanged(net, linkProps)
|
mCallback.onLinkPropertiesChanged(net, linkProps)
|
||||||
assertFails { mCallback.expectLinkPropertiesThat(Network(114), SHORT_TIMEOUT_MS) { lp ->
|
assertFails { mCallback.expect<LinkPropertiesChanged>(Network(114), SHORT_TIMEOUT_MS) {
|
||||||
lp.interfaceName == TEST_INTERFACE_NAME
|
it.lp.interfaceName == TEST_INTERFACE_NAME
|
||||||
} }
|
} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -414,13 +414,6 @@ open class TestableNetworkCallback private constructor(
|
|||||||
crossinline predicate: (T) -> Boolean = { true }
|
crossinline predicate: (T) -> Boolean = { true }
|
||||||
) = history.poll(timeoutMs, from) { it is T && predicate(it) } as T?
|
) = history.poll(timeoutMs, from) { it is T && predicate(it) } as T?
|
||||||
|
|
||||||
inline fun expectLinkPropertiesThat(
|
|
||||||
net: Network,
|
|
||||||
tmt: Long = defaultTimeoutMs,
|
|
||||||
valid: (LinkProperties) -> Boolean
|
|
||||||
): LinkPropertiesChanged =
|
|
||||||
expect(net, tmt, "LinkProperties don't match expectations") { valid(it.lp) }
|
|
||||||
|
|
||||||
// Expects onAvailable and the callbacks that follow it. These are:
|
// Expects onAvailable and the callbacks that follow it. These are:
|
||||||
// - onSuspended, iff the network was suspended when the callbacks fire.
|
// - onSuspended, iff the network was suspended when the callbacks fire.
|
||||||
// - onCapabilitiesChanged.
|
// - onCapabilitiesChanged.
|
||||||
@@ -551,13 +544,6 @@ open class TestableNetworkCallback private constructor(
|
|||||||
expectAvailableThenValidatedCallbacks(n.network, defaultTimeoutMs)
|
expectAvailableThenValidatedCallbacks(n.network, defaultTimeoutMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmOverloads
|
|
||||||
fun expectLinkPropertiesThat(
|
|
||||||
n: HasNetwork,
|
|
||||||
tmt: Long = defaultTimeoutMs,
|
|
||||||
valid: (LinkProperties) -> Boolean
|
|
||||||
) = expectLinkPropertiesThat(n.network, tmt, valid)
|
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun expectCaps(
|
fun expectCaps(
|
||||||
n: HasNetwork,
|
n: HasNetwork,
|
||||||
|
|||||||
Reference in New Issue
Block a user