Loading service/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ filegroup { srcs: [ ":statslog-bluetooth-java-gen", "src/**/*.java", "src/AdapterState.kt", "src/RadioModeListener.kt", "src/com/**/*.kt", ], Loading Loading @@ -159,12 +160,16 @@ android_robolectric_test { instrumentation_for: "ServiceBluetoothFakeTestApp", srcs: [ "src/AdapterState.kt", "src/AdapterStateTest.kt", "src/RadioModeListener.kt", "src/RadioModeListenerTest.kt", ], static_libs: [ "androidx.test.core", "kotlinx_coroutines", "kotlinx_coroutines_test", "mockito-robolectric-prebuilt", "platform-test-annotations", "testng", Loading service/src/com/android/server/bluetooth/BluetoothAdapterState.kt→service/src/AdapterState.kt +0 −0 File moved. View file service/tests/src/com/android/server/bluetooth/BluetoothAdapterStateTest.kt→service/src/AdapterStateTest.kt +22 −16 Original line number Diff line number Diff line Loading @@ -27,9 +27,9 @@ import kotlinx.coroutines.yield import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.robolectric.RobolectricTestRunner @RunWith(JUnit4::class) @RunWith(RobolectricTestRunner::class) @kotlinx.coroutines.ExperimentalCoroutinesApi class BluetoothAdapterStateTest { Loading @@ -41,30 +41,34 @@ class BluetoothAdapterStateTest { } @Test fun testStateIsProperlyInit() { fun init_isStateOff() { Log.d("BluetoothAdapterStateTest", "Initial state is " + mState) assertThat(mState.get()).isEqualTo(STATE_OFF) } @Test fun testStateReturnOnlyLastValue() { fun get_afterBusy_returnLastValue() { val max = 10 for (i in 0..max) mState.set(i) assertThat(mState.get()).isEqualTo(max) } @Test fun testStateDoesNotTimeoutWhenStateIsAlreadyCorrect() = runTest { fun immediateReturn_whenStateIsAlreadyCorrect() = runTest { val state = 10 mState.set(state) assertThat(runBlocking { mState.waitForState(100.days, state) }).isTrue() } @Test fun expectTimeout() = runTest { assertThat(mState.waitForState(100.days, -1)).isFalse() } @Test fun testStateTimeout() = runTest { assertThat(mState.waitForState(100.days, -1)).isFalse() } fun expectTimeout_CalledJavaApi() = runTest { assertThat(mState.waitForState(java.time.Duration.ofMillis(10), -1)).isFalse() } @Test fun testStateConcurrent() = runTest { fun setState_whileWaiting() = runTest { val state = 42 val waiter = async { mState.waitForState(100.days, state) } mState.set(state) Loading @@ -72,7 +76,7 @@ class BluetoothAdapterStateTest { } @Test fun testStateMultipleWaiters() = runTest { fun concurrentWaiter_NoStateMissed() = runTest { val state0 = 42 val state1 = 50 val state2 = 65 Loading @@ -96,12 +100,7 @@ class BluetoothAdapterStateTest { } @Test fun testStateTimeoutFromJava() = runTest { assertThat(mState.waitForState(java.time.Duration.ofMillis(10), -1)).isFalse() } @Test fun testStateCycle() = runTest { fun expectTimeout_waitAfterOverride() = runTest { val state0 = 42 val state1 = 50 mState.set(state0) Loading @@ -113,12 +112,19 @@ class BluetoothAdapterStateTest { } @Test fun testStateOneOf() { fun oneOf_expectMatch() { val state0 = 42 val state1 = 50 val state2 = 65 mState.set(state0) assertThat(mState.oneOf(state0, state1)).isTrue() } @Test fun oneOf_expectNotMatch() { val state0 = 42 val state1 = 50 val state2 = 65 mState.set(state0) assertThat(mState.oneOf(state1, state2)).isFalse() } } Loading
service/Android.bp +5 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ filegroup { srcs: [ ":statslog-bluetooth-java-gen", "src/**/*.java", "src/AdapterState.kt", "src/RadioModeListener.kt", "src/com/**/*.kt", ], Loading Loading @@ -159,12 +160,16 @@ android_robolectric_test { instrumentation_for: "ServiceBluetoothFakeTestApp", srcs: [ "src/AdapterState.kt", "src/AdapterStateTest.kt", "src/RadioModeListener.kt", "src/RadioModeListenerTest.kt", ], static_libs: [ "androidx.test.core", "kotlinx_coroutines", "kotlinx_coroutines_test", "mockito-robolectric-prebuilt", "platform-test-annotations", "testng", Loading
service/src/com/android/server/bluetooth/BluetoothAdapterState.kt→service/src/AdapterState.kt +0 −0 File moved. View file
service/tests/src/com/android/server/bluetooth/BluetoothAdapterStateTest.kt→service/src/AdapterStateTest.kt +22 −16 Original line number Diff line number Diff line Loading @@ -27,9 +27,9 @@ import kotlinx.coroutines.yield import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.robolectric.RobolectricTestRunner @RunWith(JUnit4::class) @RunWith(RobolectricTestRunner::class) @kotlinx.coroutines.ExperimentalCoroutinesApi class BluetoothAdapterStateTest { Loading @@ -41,30 +41,34 @@ class BluetoothAdapterStateTest { } @Test fun testStateIsProperlyInit() { fun init_isStateOff() { Log.d("BluetoothAdapterStateTest", "Initial state is " + mState) assertThat(mState.get()).isEqualTo(STATE_OFF) } @Test fun testStateReturnOnlyLastValue() { fun get_afterBusy_returnLastValue() { val max = 10 for (i in 0..max) mState.set(i) assertThat(mState.get()).isEqualTo(max) } @Test fun testStateDoesNotTimeoutWhenStateIsAlreadyCorrect() = runTest { fun immediateReturn_whenStateIsAlreadyCorrect() = runTest { val state = 10 mState.set(state) assertThat(runBlocking { mState.waitForState(100.days, state) }).isTrue() } @Test fun expectTimeout() = runTest { assertThat(mState.waitForState(100.days, -1)).isFalse() } @Test fun testStateTimeout() = runTest { assertThat(mState.waitForState(100.days, -1)).isFalse() } fun expectTimeout_CalledJavaApi() = runTest { assertThat(mState.waitForState(java.time.Duration.ofMillis(10), -1)).isFalse() } @Test fun testStateConcurrent() = runTest { fun setState_whileWaiting() = runTest { val state = 42 val waiter = async { mState.waitForState(100.days, state) } mState.set(state) Loading @@ -72,7 +76,7 @@ class BluetoothAdapterStateTest { } @Test fun testStateMultipleWaiters() = runTest { fun concurrentWaiter_NoStateMissed() = runTest { val state0 = 42 val state1 = 50 val state2 = 65 Loading @@ -96,12 +100,7 @@ class BluetoothAdapterStateTest { } @Test fun testStateTimeoutFromJava() = runTest { assertThat(mState.waitForState(java.time.Duration.ofMillis(10), -1)).isFalse() } @Test fun testStateCycle() = runTest { fun expectTimeout_waitAfterOverride() = runTest { val state0 = 42 val state1 = 50 mState.set(state0) Loading @@ -113,12 +112,19 @@ class BluetoothAdapterStateTest { } @Test fun testStateOneOf() { fun oneOf_expectMatch() { val state0 = 42 val state1 = 50 val state2 = 65 mState.set(state0) assertThat(mState.oneOf(state0, state1)).isTrue() } @Test fun oneOf_expectNotMatch() { val state0 = 42 val state1 = 50 val state2 = 65 mState.set(state0) assertThat(mState.oneOf(state1, state2)).isFalse() } }