Loading mechanics/tests/src/com/android/mechanics/MotionValueTest.kt +31 −10 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ * limitations under the License. */ @file:OptIn(ExperimentalCoroutinesApi::class) package com.android.mechanics import android.util.Log Loading Loading @@ -52,7 +50,6 @@ import com.android.mechanics.testing.input import com.android.mechanics.testing.isStable import com.android.mechanics.testing.output import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.junit.Rule import org.junit.Test Loading Loading @@ -201,6 +198,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animateValueTo(21f, changePerFrame = 3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading @@ -214,6 +214,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animateValueTo(30f, changePerFrame = 3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading Loading @@ -245,6 +248,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def awaitStable() animateValueTo(3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading Loading @@ -519,7 +525,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def animatedInputSequence(0f, 1f, 1f, 0f, 0f) } assertThat(wtfLog.loggedFailures).isEmpty() assertThat(wtfLog.hasLoggedFailures()).isFalse() } @Test Loading @@ -546,8 +552,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def animatedInputSequence(0f, 0f) } assertThat(wtfLog.loggedFailures).hasSize(1) assertThat(wtfLog.loggedFailures.first()).startsWith("Delta between mappings is undefined") val loggedFailures = wtfLog.removeLoggedFailures() assertThat(loggedFailures).hasSize(1) assertThat(loggedFailures.first()).startsWith("Delta between mappings is undefined") } @Test Loading @@ -569,9 +576,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animatedInputSequence(0f, 0.5f, 1f, 1.5f, 2f, 3f) } assertThat(wtfLog.loggedFailures).hasSize(1) assertThat(wtfLog.loggedFailures.first()) .startsWith("Delta between breakpoints is undefined") val loggedFailures = wtfLog.removeLoggedFailures() assertThat(loggedFailures).hasSize(1) assertThat(loggedFailures.first()).startsWith("Delta between breakpoints is undefined") } @Test Loading Loading @@ -610,7 +617,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def } class WtfLogRule : ExternalResource() { val loggedFailures = mutableListOf<String>() private val loggedFailures = mutableListOf<String>() private lateinit var oldHandler: TerribleFailureHandler Loading @@ -625,6 +632,20 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def override fun after() { Log.setWtfHandler(oldHandler) // In eng-builds, some misconfiguration in a MotionValue would cause a crash. However, // in tests (and in production), we want animations to proceed even with such errors. // When a test ends, we should check loggedFailures, if they were expected. assertThat(loggedFailures).isEmpty() } fun hasLoggedFailures() = loggedFailures.isNotEmpty() fun removeLoggedFailures(): List<String> { if (loggedFailures.isEmpty()) error("loggedFailures is empty") val list = loggedFailures.toList() loggedFailures.clear() return list } } Loading Loading
mechanics/tests/src/com/android/mechanics/MotionValueTest.kt +31 −10 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ * limitations under the License. */ @file:OptIn(ExperimentalCoroutinesApi::class) package com.android.mechanics import android.util.Log Loading Loading @@ -52,7 +50,6 @@ import com.android.mechanics.testing.input import com.android.mechanics.testing.isStable import com.android.mechanics.testing.output import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import org.junit.Rule import org.junit.Test Loading Loading @@ -201,6 +198,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animateValueTo(21f, changePerFrame = 3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading @@ -214,6 +214,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animateValueTo(30f, changePerFrame = 3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading Loading @@ -245,6 +248,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def awaitStable() animateValueTo(3f) awaitStable() // TODO(b/420622452) This test should not produce a WTF log. wtfLog.removeLoggedFailures() } @Test Loading Loading @@ -519,7 +525,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def animatedInputSequence(0f, 1f, 1f, 0f, 0f) } assertThat(wtfLog.loggedFailures).isEmpty() assertThat(wtfLog.hasLoggedFailures()).isFalse() } @Test Loading @@ -546,8 +552,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def animatedInputSequence(0f, 0f) } assertThat(wtfLog.loggedFailures).hasSize(1) assertThat(wtfLog.loggedFailures.first()).startsWith("Delta between mappings is undefined") val loggedFailures = wtfLog.removeLoggedFailures() assertThat(loggedFailures).hasSize(1) assertThat(loggedFailures.first()).startsWith("Delta between mappings is undefined") } @Test Loading @@ -569,9 +576,9 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def ) { animatedInputSequence(0f, 0.5f, 1f, 1.5f, 2f, 3f) } assertThat(wtfLog.loggedFailures).hasSize(1) assertThat(wtfLog.loggedFailures.first()) .startsWith("Delta between breakpoints is undefined") val loggedFailures = wtfLog.removeLoggedFailures() assertThat(loggedFailures).hasSize(1) assertThat(loggedFailures.first()).startsWith("Delta between breakpoints is undefined") } @Test Loading Loading @@ -610,7 +617,7 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def } class WtfLogRule : ExternalResource() { val loggedFailures = mutableListOf<String>() private val loggedFailures = mutableListOf<String>() private lateinit var oldHandler: TerribleFailureHandler Loading @@ -625,6 +632,20 @@ class MotionValueTest : MotionBuilderContext by FakeMotionSpecBuilderContext.Def override fun after() { Log.setWtfHandler(oldHandler) // In eng-builds, some misconfiguration in a MotionValue would cause a crash. However, // in tests (and in production), we want animations to proceed even with such errors. // When a test ends, we should check loggedFailures, if they were expected. assertThat(loggedFailures).isEmpty() } fun hasLoggedFailures() = loggedFailures.isNotEmpty() fun removeLoggedFailures(): List<String> { if (loggedFailures.isEmpty()) error("loggedFailures is empty") val list = loggedFailures.toList() loggedFailures.clear() return list } } Loading