1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.media.domain.interactor
18 
19 import android.media.AudioDeviceAttributes
20 import android.media.AudioDeviceInfo
21 import androidx.test.ext.junit.runners.AndroidJUnit4
22 import androidx.test.filters.SmallTest
23 import com.android.settingslib.media.domain.interactor.SpatializerInteractor
24 import com.android.systemui.SysuiTestCase
25 import com.android.systemui.kosmos.testScope
26 import com.android.systemui.media.spatializerRepository
27 import com.android.systemui.testKosmos
28 import com.google.common.truth.Truth.assertThat
29 import kotlinx.coroutines.test.runTest
30 import org.junit.Test
31 import org.junit.runner.RunWith
32 
33 @SmallTest
34 @RunWith(AndroidJUnit4::class)
35 class SpatializerInteractorTest : SysuiTestCase() {
36 
37     private val kosmos = testKosmos()
38     private val underTest = SpatializerInteractor(kosmos.spatializerRepository)
39 
40     @Test
setSpatialAudioEnabledFalse_isEnabled_falsenull41     fun setSpatialAudioEnabledFalse_isEnabled_false() {
42         with(kosmos) {
43             testScope.runTest {
44                 underTest.setSpatialAudioEnabled(deviceAttributes, false)
45 
46                 assertThat(underTest.isSpatialAudioEnabled(deviceAttributes)).isFalse()
47             }
48         }
49     }
50 
51     @Test
setSpatialAudioEnabledTrue_isEnabled_truenull52     fun setSpatialAudioEnabledTrue_isEnabled_true() {
53         with(kosmos) {
54             testScope.runTest {
55                 underTest.setSpatialAudioEnabled(deviceAttributes, true)
56 
57                 assertThat(underTest.isSpatialAudioEnabled(deviceAttributes)).isTrue()
58             }
59         }
60     }
61 
62     @Test
setHeadTrackingEnabledFalse_isEnabled_falsenull63     fun setHeadTrackingEnabledFalse_isEnabled_false() {
64         with(kosmos) {
65             testScope.runTest {
66                 underTest.setHeadTrackingEnabled(deviceAttributes, false)
67 
68                 assertThat(underTest.isHeadTrackingEnabled(deviceAttributes)).isFalse()
69             }
70         }
71     }
72 
73     @Test
setHeadTrackingEnabledTrue_isEnabled_truenull74     fun setHeadTrackingEnabledTrue_isEnabled_true() {
75         with(kosmos) {
76             testScope.runTest {
77                 underTest.setHeadTrackingEnabled(deviceAttributes, true)
78 
79                 assertThat(underTest.isHeadTrackingEnabled(deviceAttributes)).isTrue()
80             }
81         }
82     }
83 
84     private companion object {
85         val deviceAttributes =
86             AudioDeviceAttributes(
87                 AudioDeviceAttributes.ROLE_OUTPUT,
88                 AudioDeviceInfo.TYPE_BLE_HEADSET,
89                 "test_address",
90             )
91     }
92 }
93