• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <gtest/gtest.h>
17 #include "audio_log.h"
18 #include "audio_manager_proxy.h"
19 #include "iservice_registry.h"
20 #include "system_ability_definition.h"
21 
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace AudioStandard {
25 class AudioBalanceUnitTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 };
32 
33 static sptr<IStandardAudioService> g_sProxy = nullptr;
34 
SetUpTestCase(void)35 void AudioBalanceUnitTest::SetUpTestCase(void)
36 {
37     // input testsuit setup step,setup invoked before all testcases
38     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
39     if (samgr == nullptr) {
40         AUDIO_ERR_LOG("[AudioBalanceUnitTest] Get samgr failed");
41         return;
42     }
43 
44     sptr<IRemoteObject> object = samgr->GetSystemAbility(AUDIO_DISTRIBUTED_SERVICE_ID);
45     if (object == nullptr) {
46         AUDIO_DEBUG_LOG("[AudioBalanceUnitTest] audio service remote object is NULL.");
47         return;
48     }
49 
50     g_sProxy = iface_cast<IStandardAudioService>(object);
51     if (g_sProxy == nullptr) {
52         AUDIO_DEBUG_LOG("[AudioBalanceUnitTest] init g_sProxy is NULL.");
53         return;
54     }
55 }
56 
TearDownTestCase(void)57 void AudioBalanceUnitTest::TearDownTestCase(void)
58 {
59     // input testsuit teardown step,teardown invoked after all testcases
60 }
61 
SetUp(void)62 void AudioBalanceUnitTest::SetUp(void)
63 {
64     // input testcase setup step,setup invoked before each testcases
65 }
66 
TearDown(void)67 void AudioBalanceUnitTest::TearDown(void)
68 {
69     // input testcase teardown step,teardown invoked after each testcases
70 }
71 
72 /**
73 * @tc.name  : Test SetAudioMonoState API
74 * @tc.type  : FUNC
75 * @tc.number: SetAudioMonoState_001
76 * @tc.desc  : Test SetAudioMonoState interface. Set audio mono state to true
77 */
78 HWTEST_F(AudioBalanceUnitTest, SetAudioMonoState_001, TestSize.Level1)
79 {
80     bool audioMonoState = true;
81     g_sProxy->SetAudioMonoState(audioMonoState);
82 }
83 
84 /**
85 * @tc.name  : Test SetAudioMonoState API
86 * @tc.type  : FUNC
87 * @tc.number: SetAudioMonoState_002
88 * @tc.desc  : Test SetAudioMonoState interface. Set audio mono state to false
89 */
90 HWTEST_F(AudioBalanceUnitTest, SetAudioMonoState_002, TestSize.Level1)
91 {
92     bool audioMonoState = false;
93     g_sProxy->SetAudioMonoState(audioMonoState);
94 }
95 
96 /**
97 * @tc.name  : Test SetAudioBalanceValue API
98 * @tc.type  : FUNC
99 * @tc.number: SetAudioBalanceValue_001
100 * @tc.desc  : Test SetAudioBalanceValue interface. Set audio balance value to -1.0f
101 */
102 HWTEST_F(AudioBalanceUnitTest, SetAudioBalanceValue_001, TestSize.Level1)
103 {
104     float audioBalanceValue = -1.0f;
105     g_sProxy->SetAudioBalanceValue(audioBalanceValue);
106 }
107 
108 /**
109 * @tc.name  : Test SetAudioBalanceValue API
110 * @tc.type  : FUNC
111 * @tc.number: SetAudioBalanceValue_002
112 * @tc.desc  : Test SetAudioBalanceValue interface. Set audio balance value to -0.5f
113 */
114 HWTEST_F(AudioBalanceUnitTest, SetAudioBalanceValue_002, TestSize.Level1)
115 {
116     float audioBalanceValue = -0.5f;
117     g_sProxy->SetAudioBalanceValue(audioBalanceValue);
118 }
119 
120 /**
121 * @tc.name  : Test SetAudioBalanceValue API
122 * @tc.type  : FUNC
123 * @tc.number: SetAudioBalanceValue_003
124 * @tc.desc  : Test SetAudioBalanceValue interface. Set audio balance value to 0.5f
125 */
126 HWTEST_F(AudioBalanceUnitTest, SetAudioBalanceValue_003, TestSize.Level1)
127 {
128     float audioBalanceValue = 0.5f;
129     g_sProxy->SetAudioBalanceValue(audioBalanceValue);
130 }
131 
132 /**
133 * @tc.name  : Test SetAudioBalanceValue API
134 * @tc.type  : FUNC
135 * @tc.number: SetAudioBalanceValue_004
136 * @tc.desc  : Test SetAudioBalanceValue interface. Set audio balance value to 1.0f
137 */
138 HWTEST_F(AudioBalanceUnitTest, SetAudioBalanceValue_004, TestSize.Level1)
139 {
140     float audioBalanceValue = 1.0f;
141     g_sProxy->SetAudioBalanceValue(audioBalanceValue);
142 }
143 
144 /**
145 * @tc.name  : Test SetAudioBalanceValue API
146 * @tc.type  : FUNC
147 * @tc.number: SetAudioBalanceValue_005
148 * @tc.desc  : Test SetAudioBalanceValue interface. Set audio balance value to 0.0f
149 */
150 HWTEST_F(AudioBalanceUnitTest, SetAudioBalanceValue_005, TestSize.Level1)
151 {
152     float audioBalanceValue = 0.0f;
153     g_sProxy->SetAudioBalanceValue(audioBalanceValue);
154 }
155 } // namespace AudioStandard
156 } // namespace OHOS