1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "audio_manager_proxy.h"
17
18 #include "audio_log.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21 #include <gtest/gtest.h>
22
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace AudioStandard {
26 class AudioBalanceTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32 };
33
34 static sptr<IStandardAudioService> g_sProxy = nullptr;
35
SetUpTestCase(void)36 void AudioBalanceTest::SetUpTestCase(void)
37 {
38 // input testsuit setup step,setup invoked before all testcases
39 auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
40 if (samgr == nullptr) {
41 AUDIO_ERR_LOG("[AudioBalanceUnitTest] Get samgr failed");
42 return;
43 }
44
45 sptr<IRemoteObject> object = samgr->GetSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID);
46 if (object == nullptr) {
47 AUDIO_DEBUG_LOG("[AudioBalanceUnitTest] audio service remote object is NULL.");
48 return;
49 }
50
51 g_sProxy = iface_cast<IStandardAudioService>(object);
52 if (g_sProxy == nullptr) {
53 AUDIO_DEBUG_LOG("[AudioBalanceUnitTest] init g_sProxy is NULL.");
54 return;
55 }
56 }
57
TearDownTestCase(void)58 void AudioBalanceTest::TearDownTestCase(void)
59 {
60 // input testsuit teardown step,teardown invoked after all testcases
61 }
62
SetUp(void)63 void AudioBalanceTest::SetUp(void)
64 {
65 // input testcase setup step,setup invoked before each testcases
66 }
67
TearDown(void)68 void AudioBalanceTest::TearDown(void)
69 {
70 // input testcase teardown step,teardown invoked after each testcases
71 }
72
73 /**
74 * @tc.name : Test SetAudioMonoState API
75 * @tc.type : FUNC
76 * @tc.number: SetAudioMonoState_001
77 * @tc.desc : Test SetAudioMonoState interface. Set audio mono state to true
78 */
79 HWTEST_F(AudioBalanceTest, SetAudioMonoState_001, TestSize.Level0)
80 {
81 bool audioMonoState = true;
82 g_sProxy->SetAudioMonoState(audioMonoState);
83 }
84
85 /**
86 * @tc.name : Test SetAudioMonoState API
87 * @tc.type : FUNC
88 * @tc.number: SetAudioMonoState_002
89 * @tc.desc : Test SetAudioMonoState interface. Set audio mono state to false
90 */
91 HWTEST_F(AudioBalanceTest, SetAudioMonoState_002, TestSize.Level0)
92 {
93 bool audioMonoState = false;
94 g_sProxy->SetAudioMonoState(audioMonoState);
95 }
96
97 /**
98 * @tc.name : Test SetAudioBalanceValue API
99 * @tc.type : FUNC
100 * @tc.number: SetAudioBalanceValue_001
101 * @tc.desc : Test SetAudioBalanceValue interface. Set audio balance value to -1.0f
102 */
103 HWTEST_F(AudioBalanceTest, SetAudioBalanceValue_001, TestSize.Level0)
104 {
105 float audioBalanceValue = -1.0f;
106 g_sProxy->SetAudioBalanceValue(audioBalanceValue);
107 }
108
109 /**
110 * @tc.name : Test SetAudioBalanceValue API
111 * @tc.type : FUNC
112 * @tc.number: SetAudioBalanceValue_002
113 * @tc.desc : Test SetAudioBalanceValue interface. Set audio balance value to -0.5f
114 */
115 HWTEST_F(AudioBalanceTest, SetAudioBalanceValue_002, TestSize.Level0)
116 {
117 float audioBalanceValue = -0.5f;
118 g_sProxy->SetAudioBalanceValue(audioBalanceValue);
119 }
120
121 /**
122 * @tc.name : Test SetAudioBalanceValue API
123 * @tc.type : FUNC
124 * @tc.number: SetAudioBalanceValue_003
125 * @tc.desc : Test SetAudioBalanceValue interface. Set audio balance value to 0.0f
126 */
127 HWTEST_F(AudioBalanceTest, SetAudioBalanceValue_003, TestSize.Level0)
128 {
129 float audioBalanceValue = 0.0f;
130 g_sProxy->SetAudioBalanceValue(audioBalanceValue);
131 }
132
133 /**
134 * @tc.name : Test SetAudioBalanceValue API
135 * @tc.type : FUNC
136 * @tc.number: SetAudioBalanceValue_004
137 * @tc.desc : Test SetAudioBalanceValue interface. Set audio balance value to 0.5f
138 */
139 HWTEST_F(AudioBalanceTest, SetAudioBalanceValue_004, TestSize.Level0)
140 {
141 float audioBalanceValue = 0.5f;
142 g_sProxy->SetAudioBalanceValue(audioBalanceValue);
143 }
144
145 /**
146 * @tc.name : Test SetAudioBalanceValue API
147 * @tc.type : FUNC
148 * @tc.number: SetAudioBalanceValue_005
149 * @tc.desc : Test SetAudioBalanceValue interface. Set audio balance value to 1.0f
150 */
151 HWTEST_F(AudioBalanceTest, SetAudioBalanceValue_005, TestSize.Level0)
152 {
153 float audioBalanceValue = 1.0f;
154 g_sProxy->SetAudioBalanceValue(audioBalanceValue);
155 }
156 } // namespace AudioStandard
157 } // namespace OHOS