1 /* 2 * Copyright (c) 2024 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 18 #include "audio_service_log.h" 19 #include "audio_errors.h" 20 #include "audio_stream_manager.h" 21 22 using namespace testing::ext; 23 24 namespace OHOS { 25 namespace AudioStandard { 26 27 class AudioSteamManagerUnitTest : public testing::Test { 28 public: 29 static void SetUpTestCase(void); 30 static void TearDownTestCase(void); 31 void SetUp(); 32 void TearDown(); 33 }; 34 35 /** 36 * @tc.name : Test IsStreamActive API 37 * @tc.type : FUNC 38 * @tc.number: IsStreamActive_001 39 * @tc.desc : Test IsStreamActive interface. 40 */ 41 HWTEST(AudioStreamManagerUnitTest, IsStreamActive_001, TestSize.Level1) 42 { 43 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActive_001 start"); 44 bool result = AudioStreamManager::GetInstance()->IsStreamActive(STREAM_MUSIC); 45 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActive_001 result1:%{public}d", result); 46 EXPECT_EQ(result, false); 47 48 result = AudioStreamManager::GetInstance()->IsStreamActive(STREAM_VOICE_ASSISTANT); 49 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActive_001 result2:%{public}d", result); 50 EXPECT_EQ(result, false); 51 52 result = AudioStreamManager::GetInstance()->IsStreamActive(STREAM_ULTRASONIC); 53 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActive_001 result2:%{public}d", result); 54 EXPECT_EQ(result, false); 55 56 result = AudioStreamManager::GetInstance()->IsStreamActive(STREAM_ALL); 57 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActive_001 result3:%{public}d", result); 58 EXPECT_EQ(result, false); 59 } 60 61 /** 62 * @tc.name : Test IsStreamActiveByStreamUsage API 63 * @tc.number: IsStreamActiveByStreamUsage_001 64 * @tc.desc : Test IsStreamActiveByStreamUsage interface. 65 */ 66 HWTEST(AudioStreamManagerUnitTest, IsStreamActiveByStreamUsage_001, TestSize.Level1) 67 { 68 StreamUsage ILLEGAL_STREAM_USAGE = static_cast<StreamUsage>(static_cast<int32_t>(STREAM_USAGE_MAX)+999); 69 70 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActiveByStreamUsage_001 start"); 71 bool result = AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_MUSIC); 72 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActiveByStreamUsage_001 result1:%{public}d", result); 73 EXPECT_EQ(result, false); 74 75 result = AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_ULTRASONIC); 76 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActiveByStreamUsage_001 result2:%{public}d", result); 77 EXPECT_EQ(result, false); 78 79 result = AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(ILLEGAL_STREAM_USAGE); 80 AUDIO_INFO_LOG("AudioSystemManagerUnitTest IsStreamActiveByStreamUsage_001 result2:%{public}d", result); 81 EXPECT_EQ(result, false); 82 } 83 /** 84 * @tc.name : Test GetHardeareOutputSamplingRate API 85 * @tc.type : FUNC 86 * @tc.number: GetHardeareOutputSamplingRate_001 87 * @tc.desc : Test IsStreamActive interface. 88 */ 89 HWTEST(AudioStreamManagerUnitTest, GetHardwareOutputSamplingRate_001, TestSize.Level1) 90 { 91 std::shared_ptr<AudioDeviceDescriptor> desc = std::make_shared<AudioDeviceDescriptor>(); 92 AudioStreamManager::GetInstance()->GetHardwareOutputSamplingRate(desc); 93 94 EXPECT_EQ(desc->deviceRole_, -1); 95 } 96 97 /** 98 * @tc.name : Test IsStreamActiveByStreamUsage API 99 * @tc.type : FUNC 100 * @tc.number: IsStreamActiveByStreamUsage_001 101 * @tc.desc : Test IsStreamActiveByStreamUsage interface. 102 */ 103 HWTEST(AudioStreamManagerUnitTest, IsStreamActiveByStreamUsage_002, TestSize.Level1) 104 { 105 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_MEDIA)); 106 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_VOICE_COMMUNICATION)); 107 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_SYSTEM)); 108 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_DTMF)); 109 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_ENFORCED_TONE)); 110 EXPECT_FALSE(AudioStreamManager::GetInstance()->IsStreamActiveByStreamUsage(STREAM_USAGE_VOICE_CALL_ASSISTANT)); 111 } 112 /** 113 * @tc.name : Test GetHardeareOutputSamplingRate API 114 * @tc.type : FUNC 115 * @tc.number: GetHardeareOutputSamplingRate_001 116 * @tc.desc : Test IsStreamActive interface. 117 */ 118 HWTEST(AudioStreamManagerUnitTest, GetSupportedAudioEffectProperty_001, TestSize.Level1) 119 { 120 AudioEffectPropertyArray propertyArray; 121 122 int32_t result = AudioStreamManager::GetInstance()->GetSupportedAudioEffectProperty(propertyArray); 123 124 EXPECT_NE(result, 1); 125 } 126 /** 127 * @tc.name : Test GetAudioEffectProperty API 128 * @tc.type : FUNC 129 * @tc.number: GetAudioEffectPropertye_001 130 * @tc.desc : Test IsStreamActive interface. 131 */ 132 HWTEST(AudioStreamManagerUnitTest, GetAudioEffectProperty_001, TestSize.Level1) 133 { 134 AudioEffectPropertyArray propertyArray; 135 136 int32_t result = AudioStreamManager::GetInstance()->GetAudioEffectProperty(propertyArray); 137 EXPECT_NE(result, 1); 138 } 139 /** 140 * @tc.name : Test GetAudioEnhanceProperty API 141 * @tc.type : FUNC 142 * @tc.number: GetAudioEnhanceProperty_001 143 * @tc.desc : Test IsStreamActive interface. 144 */ 145 HWTEST(AudioStreamManagerUnitTest, GetAudioEnhanceProperty_001, TestSize.Level1) 146 { 147 AudioEnhancePropertyArray propertyArray; 148 149 int32_t result = AudioStreamManager::GetInstance()->GetAudioEnhanceProperty(propertyArray); 150 151 EXPECT_NE(result, 1); 152 } 153 /** 154 * @tc.name : Test ForceStopAudioStream API 155 * @tc.type : FUNC 156 * @tc.number: ForceStopAudioStream 157 * @tc.desc : Test IsStreamActive interface. 158 */ 159 HWTEST(AudioStreamManagerUnitTest, ForceStopAudioStream_001, TestSize.Level1) 160 { 161 StopAudioType audioType = STOP_ALL; 162 163 int32_t result = AudioStreamManager::GetInstance()->ForceStopAudioStream(audioType); 164 EXPECT_NE(result, 1); 165 } 166 /** 167 * @tc.name : Test IsAudioLoopbackSupported API 168 * @tc.type : FUNC 169 * @tc.number: IsAudioLoopbackSupported_001 170 * @tc.desc : Test IsStreamActive interface. 171 */ 172 HWTEST(AudioStreamManagerUnitTest, IsAudioLoopbackSupported_001, TestSize.Level1) 173 { 174 AudioLoopbackMode mode = LOOPBACK_HARDWARE; 175 176 int32_t result = AudioStreamManager::GetInstance()->IsAudioLoopbackSupported(mode); 177 178 EXPECT_EQ(result, 0); 179 } 180 181 /** 182 * @tc.name : Test RegisterAudioRendererEventListener API 183 * @tc.type : FUNC 184 * @tc.number: RegisterAudioRendererEventListener_001 185 * @tc.desc : Test RegisterAudioRendererEventListener interface. 186 */ 187 HWTEST(AudioStreamManagerUnitTest, RegisterAudioRendererEventListener_001, TestSize.Level1) 188 { 189 int32_t clientPid = 1; 190 std::shared_ptr<AudioRendererStateChangeCallback> callback = nullptr; 191 192 EXPECT_EQ(AudioStreamManager::GetInstance() 193 ->RegisterAudioRendererEventListener(clientPid, callback), ERR_INVALID_PARAM); 194 } 195 196 /** 197 * @tc.name : Test GetHardwareOutputSamplingRate API 198 * @tc.type : FUNC 199 * @tc.number: GetHardwareOutputSamplingRate_002 200 * @tc.desc : Test GetHardwareOutputSamplingRate interface. 201 */ 202 HWTEST(AudioStreamManagerUnitTest, GetHardwareOutputSamplingRate_002, TestSize.Level1) 203 { 204 std::shared_ptr<AudioDeviceDescriptor> desc = nullptr; 205 int32_t result = AudioStreamManager::GetInstance()->GetHardwareOutputSamplingRate(desc); 206 EXPECT_NE(result, ERR_INVALID_PARAM); 207 } 208 209 /** 210 * @tc.name : Test GetHardwareOutputSamplingRate API 211 * @tc.type : FUNC 212 * @tc.number: GetHardwareOutputSamplingRate_003 213 * @tc.desc : Test GetHardwareOutputSamplingRate interface. 214 */ 215 HWTEST(AudioStreamManagerUnitTest, GetHardwareOutputSamplingRate_003, TestSize.Level1) 216 { 217 std::shared_ptr<AudioDeviceDescriptor> desc = std::make_shared<AudioDeviceDescriptor>(); 218 desc->deviceType_ = DEVICE_TYPE_SPEAKER; 219 desc->deviceRole_ = OUTPUT_DEVICE; 220 int32_t result = AudioStreamManager::GetInstance()->GetHardwareOutputSamplingRate(desc); 221 EXPECT_NE(result, 0); 222 } 223 224 /** 225 * @tc.name : Test GetSupportedAudioEffectProperty API 226 * @tc.type : FUNC 227 * @tc.number: GetSupportedAudioEffectProperty_002 228 * @tc.desc : Test GetSupportedAudioEffectProperty interface. 229 */ 230 HWTEST(AudioStreamManagerUnitTest, GetSupportedAudioEffectProperty_002, TestSize.Level1) 231 { 232 AudioEffectPropertyArray propertyArray; 233 int32_t result = AudioStreamManager::GetInstance()->GetSupportedAudioEffectProperty(propertyArray); 234 EXPECT_NE(result, 0); 235 } 236 237 /** 238 * @tc.name : Test GetSupportedAudioEnhanceProperty API 239 * @tc.type : FUNC 240 * @tc.number: GetSupportedAudioEnhanceProperty_001 241 * @tc.desc : Test GetSupportedAudioEnhanceProperty interface. 242 */ 243 HWTEST(AudioStreamManagerUnitTest, GetSupportedAudioEnhanceProperty_001, TestSize.Level1) 244 { 245 AudioEnhancePropertyArray propertyArray; 246 int32_t result = AudioStreamManager::GetInstance()->GetSupportedAudioEnhanceProperty(propertyArray); 247 EXPECT_NE(result, 0); 248 } 249 250 /** 251 * @tc.name : Test SetAudioEffectProperty API 252 * @tc.type : FUNC 253 * @tc.number: SetAudioEffectProperty_001 254 * @tc.desc : Test SetAudioEffectProperty interface. 255 */ 256 HWTEST(AudioStreamManagerUnitTest, SetAudioEffectProperty_001, TestSize.Level1) 257 { 258 AudioEffectPropertyArray propertyArray; 259 int32_t result = AudioStreamManager::GetInstance()->SetAudioEffectProperty(propertyArray); 260 EXPECT_NE(result, 0); 261 } 262 263 /** 264 * @tc.name : Test GetAudioEffectProperty API 265 * @tc.type : FUNC 266 * @tc.number: GetAudioEffectProperty_002 267 * @tc.desc : Test GetAudioEffectProperty interface. 268 */ 269 HWTEST(AudioStreamManagerUnitTest, GetAudioEffectProperty_002, TestSize.Level1) 270 { 271 AudioEffectPropertyArray propertyArray; 272 int32_t result = AudioStreamManager::GetInstance()->GetAudioEffectProperty(propertyArray); 273 EXPECT_NE(result, 0); 274 } 275 276 /** 277 * @tc.name : Test SetAudioEnhanceProperty API 278 * @tc.type : FUNC 279 * @tc.number: SetAudioEnhanceProperty_001 280 * @tc.desc : Test SetAudioEnhanceProperty interface. 281 */ 282 HWTEST(AudioStreamManagerUnitTest, SetAudioEnhanceProperty_001, TestSize.Level1) 283 { 284 AudioEnhancePropertyArray propertyArray; 285 int32_t result = AudioStreamManager::GetInstance()->SetAudioEnhanceProperty(propertyArray); 286 EXPECT_NE(result, 0); 287 } 288 289 /** 290 * @tc.name : Test GetAudioEnhanceProperty API 291 * @tc.type : FUNC 292 * @tc.number: GetAudioEnhanceProperty_002 293 * @tc.desc : Test GetAudioEnhanceProperty interface. 294 */ 295 HWTEST(AudioStreamManagerUnitTest, GetAudioEnhanceProperty_002, TestSize.Level1) 296 { 297 AudioEnhancePropertyArray propertyArray; 298 int32_t result = AudioStreamManager::GetInstance()->GetAudioEnhanceProperty(propertyArray); 299 EXPECT_NE(result, 0); 300 } 301 302 /** 303 * @tc.name : Test IsCapturerFocusAvailable API 304 * @tc.type : FUNC 305 * @tc.number: IsCapturerFocusAvailable_001 306 * @tc.desc : Test IsCapturerFocusAvailable interface. 307 */ 308 HWTEST(AudioStreamManagerUnitTest, IsCapturerFocusAvailable_001, TestSize.Level1) 309 { 310 AudioCapturerInfo capturerInfo; 311 int32_t result = AudioStreamManager::GetInstance()->IsCapturerFocusAvailable(capturerInfo); 312 EXPECT_EQ(result, 0); 313 } 314 } // namespace AudioStandard 315 } // namespace OHOS