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_group_manager_unit_test.h"
17
18 #include "audio_errors.h"
19 #include "audio_info.h"
20
21 using namespace std;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace AudioStandard {
26 namespace {
27 constexpr int32_t MAX_VOL = 15;
28 constexpr int32_t MIN_VOL = 0;
29 std::string networkId = "LocalDevice";
30 }
31
SetUpTestCase(void)32 void AudioGroupManagerUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)33 void AudioGroupManagerUnitTest::TearDownTestCase(void) {}
SetUp(void)34 void AudioGroupManagerUnitTest::SetUp(void) {}
TearDown(void)35 void AudioGroupManagerUnitTest::TearDown(void) {}
36
37 /**
38 * @tc.name : Test AudioVolume API
39 * @tc.number: AudioVolume_001
40 * @tc.desc : Test AudioVolume manager interface multiple requests
41 * @tc.require: issueI5M1XV
42 */
43 HWTEST(AudioGroupManagerUnitTest, AudioVolume_001, TestSize.Level1)
44 {
45 int32_t volume = 0;
46 bool mute = true;
47 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
48 if (infos.size() > 0) {
49 int32_t groupId = infos[0]->volumeGroupId_;
50 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
51
52 auto ret = audioGroupMngr_->SetVolume(AudioVolumeType::STREAM_ALL, volume);
53 EXPECT_EQ(SUCCESS, ret);
54
55 ret = audioGroupMngr_->GetVolume(AudioVolumeType::STREAM_ALL);
56 EXPECT_EQ(volume, ret);
57
58 ret = audioGroupMngr_->SetMute(AudioVolumeType::STREAM_ALL, mute);
59 EXPECT_EQ(SUCCESS, ret);
60
61 ret = audioGroupMngr_->IsStreamMute(AudioVolumeType::STREAM_ALL);
62 EXPECT_EQ(true, ret);
63 }
64 }
65
66 /**
67 * @tc.name : Test SetVolume API
68 * @tc.number: SetVolumeTest_001
69 * @tc.desc : Test setting volume of ringtone stream with max volume
70 * @tc.require: issueI5M1XV
71 */
72 HWTEST(AudioGroupManagerUnitTest, SetVolumeTest_001, TestSize.Level0)
73 {
74 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
75 if (infos.size() > 0) {
76 int32_t groupId = infos[0]->volumeGroupId_;
77 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
78
79 auto ret = audioGroupMngr_->SetVolume(AudioVolumeType::STREAM_RING, MAX_VOL);
80 EXPECT_EQ(SUCCESS, ret);
81
82 int32_t volume = audioGroupMngr_->GetVolume(AudioVolumeType::STREAM_RING);
83 EXPECT_EQ(MAX_VOL, volume);
84 }
85 }
86
87 /**
88 * @tc.name : Test SetVolume API
89 * @tc.number: SetVolumeTest_002
90 * @tc.desc : Test setting volume of ringtone stream with min volume
91 * @tc.require: issueI5M1XV
92 */
93 HWTEST(AudioGroupManagerUnitTest, SetVolumeTest_002, TestSize.Level0)
94 {
95 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
96 if (infos.size() > 0) {
97 int32_t groupId = infos[0]->volumeGroupId_;
98 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
99
100 auto ret = audioGroupMngr_->SetVolume(AudioVolumeType::STREAM_RING, MIN_VOL);
101 EXPECT_EQ(SUCCESS, ret);
102
103 int32_t volume = audioGroupMngr_->GetVolume(AudioVolumeType::STREAM_RING);
104 EXPECT_EQ(MIN_VOL, volume);
105 }
106 }
107
108 /**
109 * @tc.name : Test SetVolume API
110 * @tc.number: SetVolumeTest_003
111 * @tc.desc : Test setting volume of media stream with max volume
112 * @tc.require: issueI5M1XV
113 */
114 HWTEST(AudioGroupManagerUnitTest, SetVolumeTest_003, TestSize.Level0)
115 {
116 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
117 if (infos.size() > 0) {
118 int32_t groupId = infos[0]->volumeGroupId_;
119 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
120
121 auto ret = audioGroupMngr_->SetVolume(AudioVolumeType::STREAM_MUSIC, MAX_VOL);
122 EXPECT_EQ(SUCCESS, ret);
123
124 int32_t mediaVol = audioGroupMngr_->GetVolume(AudioVolumeType::STREAM_MUSIC);
125 EXPECT_EQ(MAX_VOL, mediaVol);
126
127 int32_t ringVolume = audioGroupMngr_->GetVolume(AudioVolumeType::STREAM_RING);
128 EXPECT_EQ(MIN_VOL, ringVolume);
129 }
130 }
131
132 /**
133 * @tc.name : Test GetMaxVolume API
134 * @tc.number: GetMaxVolumeTest_001
135 * @tc.desc : Test GetMaxVolume of media stream
136 * @tc.require: issueI5M1XV
137 */
138 HWTEST(AudioGroupManagerUnitTest, GetMaxVolumeTest_001, TestSize.Level0)
139 {
140 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
141 if (infos.size() > 0) {
142 int32_t groupId = infos[0]->volumeGroupId_;
143 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
144
145 int32_t mediaVol = audioGroupMngr_->GetMaxVolume(AudioVolumeType::STREAM_MUSIC);
146 EXPECT_EQ(MAX_VOL, mediaVol);
147
148 int32_t ringVolume = audioGroupMngr_->GetMaxVolume(AudioVolumeType::STREAM_RING);
149 EXPECT_EQ(MAX_VOL, ringVolume);
150 }
151 }
152
153 /**
154 * @tc.name : Test GetMaxVolume API
155 * @tc.number: GetMinVolumeTest_001
156 * @tc.desc : Test GetMaxVolume of media stream
157 * @tc.require: issueI5M1XV
158 */
159 HWTEST(AudioGroupManagerUnitTest, GetMinVolumeTest_001, TestSize.Level0)
160 {
161 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
162 if (infos.size() > 0) {
163 int32_t groupId = infos[0]->volumeGroupId_;
164 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
165
166 int32_t mediaVol = audioGroupMngr_->GetMinVolume(AudioVolumeType::STREAM_MUSIC);
167 EXPECT_EQ(MIN_VOL, mediaVol);
168
169 int32_t ringVolume = audioGroupMngr_->GetMinVolume(AudioVolumeType::STREAM_RING);
170 EXPECT_EQ(MIN_VOL, ringVolume);
171 }
172 }
173
174 /**
175 * @tc.name : Test SetMute API
176 * @tc.number: SetMute_001
177 * @tc.desc : Test mute functionality of ringtone stream
178 * @tc.require: issueI5M1XV
179 */
180 HWTEST(AudioGroupManagerUnitTest, SetMute_001, TestSize.Level0)
181 {
182 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
183 if (infos.size() > 0) {
184 int32_t groupId = infos[0]->volumeGroupId_;
185 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
186
187 auto ret = audioGroupMngr_->SetMute(AudioVolumeType::STREAM_RING, true);
188 EXPECT_EQ(SUCCESS, ret);
189
190 ret = audioGroupMngr_->IsStreamMute(AudioVolumeType::STREAM_RING);
191 EXPECT_EQ(true, ret);
192 }
193 }
194
195 /**
196 * @tc.name : Test SetMute IsStreamMute API
197 * @tc.number: SetMute_002
198 * @tc.desc : Test unmute functionality of ringtone stream
199 * @tc.require: issueI5M1XV
200 */
201 HWTEST(AudioGroupManagerUnitTest, SetMute_002, TestSize.Level0)
202 {
203 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
204 if (infos.size() > 0) {
205 int32_t groupId = infos[0]->volumeGroupId_;
206 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
207
208 auto ret = audioGroupMngr_->SetMute(AudioVolumeType::STREAM_RING, false);
209 EXPECT_EQ(SUCCESS, ret);
210
211 ret = audioGroupMngr_->IsStreamMute(AudioVolumeType::STREAM_RING);
212 EXPECT_EQ(false, ret);
213 }
214 }
215
216 /**
217 * @tc.name : Test SetMute IsStreamMute API
218 * @tc.number: SetMute_003
219 * @tc.desc : Test mute functionality of media stream
220 * @tc.require: issueI5M1XV
221 */
222 HWTEST(AudioGroupManagerUnitTest, SetMute_003, TestSize.Level0)
223 {
224 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
225 if (infos.size() > 0) {
226 int32_t groupId = infos[0]->volumeGroupId_;
227 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
228
229 auto ret = audioGroupMngr_->SetMute(AudioVolumeType::STREAM_MUSIC, true);
230 EXPECT_EQ(SUCCESS, ret);
231
232 ret = audioGroupMngr_->IsStreamMute(AudioVolumeType::STREAM_MUSIC);
233 EXPECT_EQ(true, ret);
234 }
235 }
236
237 /**
238 * @tc.name : Test SetMute IsStreamMute API
239 * @tc.number: SetMute_004
240 * @tc.desc : Test unmute functionality of media stream
241 * @tc.require: issueI5M1XV
242 */
243 HWTEST(AudioGroupManagerUnitTest, SetMute_004, TestSize.Level0)
244 {
245 std::vector<sptr<VolumeGroupInfo>> infos = AudioSystemManager::GetInstance()->GetVolumeGroups(networkId);
246 if (infos.size() > 0) {
247 int32_t groupId = infos[0]->volumeGroupId_;
248 auto audioGroupMngr_ = AudioSystemManager::GetInstance()->GetGroupManager(groupId);
249
250 auto ret = audioGroupMngr_->SetMute(AudioVolumeType::STREAM_MUSIC, false);
251 EXPECT_EQ(SUCCESS, ret);
252
253 ret = audioGroupMngr_->IsStreamMute(AudioVolumeType::STREAM_RING);
254 EXPECT_EQ(false, ret);
255 }
256 }
257 } // namespace AudioStandard
258 } // namespace OHOS
259