• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 "hpae_policy_manager.h"
18 
19 using namespace OHOS;
20 using namespace AudioStandard;
21 using namespace HPAE;
22 using namespace testing::ext;
23 using namespace testing;
24 constexpr uint32_t SESSION_ID = 12345;
25 
26 class HpaePolicyManagerTest : public testing::Test {
27 public:
28     void SetUp();
29     void TearDown();
30 };
31 
SetUp()32 void HpaePolicyManagerTest::SetUp()
33 {}
34 
TearDown()35 void HpaePolicyManagerTest::TearDown()
36 {}
37 
38 HWTEST_F(HpaePolicyManagerTest, TestForHpaePolicyManager_001, TestSize.Level0)
39 {
40     AudioSpatializationState spatializationState = {};
41     int32_t ret = HpaePolicyManager::GetInstance().UpdateSpatializationState(spatializationState);
42     EXPECT_EQ(ret, 0);
43 
44     ret = HpaePolicyManager::GetInstance().UpdateSpatialDeviceType(EARPHONE_TYPE_NONE);
45     EXPECT_EQ(ret, 0);
46 
47     ret = HpaePolicyManager::GetInstance().SetSpatializationSceneType(SPATIALIZATION_SCENE_TYPE_DEFAULT);
48     EXPECT_EQ(ret, 0);
49 
50     ret = HpaePolicyManager::GetInstance().EffectRotationUpdate(0);
51     EXPECT_EQ(ret, 0);
52 
53     ret = HpaePolicyManager::GetInstance().SetEffectSystemVolume(0, 1.f);
54     EXPECT_EQ(ret, 0);
55 
56     AudioEffectPropertyArrayV3 propertyArray;
57     ret = HpaePolicyManager::GetInstance().SetAudioEffectProperty(propertyArray);
58     EXPECT_EQ(ret, 0);
59 
60     AudioEffectPropertyArray propertyArray1;
61     ret = HpaePolicyManager::GetInstance().GetAudioEffectProperty(propertyArray1);
62     EXPECT_EQ(ret, 0);
63     EXPECT_EQ(propertyArray1.property.size(), 0);
64 
65     ret = HpaePolicyManager::GetInstance().SetInputDevice(0, DEVICE_TYPE_MIC, "Built_in_mic");
66     EXPECT_EQ(ret, 0);
67 
68     ret = HpaePolicyManager::GetInstance().SetOutputDevice(0, DEVICE_TYPE_SPEAKER);
69     EXPECT_EQ(ret, 0);
70 
71     AudioVolumeType volumeType = static_cast<AudioVolumeType>(0);
72     ret = HpaePolicyManager::GetInstance().SetVolumeInfo(volumeType, 1.f);
73     EXPECT_EQ(ret, 0);
74 
75     ret = HpaePolicyManager::GetInstance().SetMicrophoneMuteInfo(true);
76     EXPECT_EQ(ret, 0);
77 
78     ret = HpaePolicyManager::GetInstance().SetStreamVolumeInfo(SESSION_ID, 1.f);
79     EXPECT_EQ(ret, 0);
80 }
81 
82 HWTEST_F(HpaePolicyManagerTest, TestForHpaePolicyManager_002, TestSize.Level0)
83 {
84     AudioEffectPropertyArrayV3 propertyArray2;
85     propertyArray2.property.push_back({"invalidEffect", "property1"});
86     int32_t ret = HpaePolicyManager::GetInstance().SetAudioEnhanceProperty(propertyArray2, DEVICE_TYPE_SPEAKER);
87     EXPECT_EQ(ret, 0);
88 
89     AudioEffectPropertyArrayV3 propertyArray3;
90     ret = HpaePolicyManager::GetInstance().GetAudioEnhanceProperty(propertyArray3, DEVICE_TYPE_SPEAKER);
91     EXPECT_EQ(ret, 0);
92 
93     AudioEnhancePropertyArray propertyArray4;
94     ret = HpaePolicyManager::GetInstance().SetAudioEnhanceProperty(propertyArray4, DEVICE_TYPE_SPEAKER);
95     EXPECT_EQ(ret, 0);
96 
97     AudioEnhancePropertyArray propertyArray5;
98     ret = HpaePolicyManager::GetInstance().GetAudioEnhanceProperty(propertyArray5, DEVICE_TYPE_SPEAKER);
99     EXPECT_EQ(ret, 0);
100 
101     std::string mainkey = "other_mainkey";
102     std::string subkey = "other_subkey";
103     std::string extraSceneType = "extra_scene";
104     HpaePolicyManager::GetInstance().UpdateExtraSceneType(mainkey, subkey, extraSceneType);
105     EXPECT_EQ(mainkey, "other_mainkey");
106     EXPECT_EQ(subkey, "other_subkey");
107     EXPECT_EQ(extraSceneType, "extra_scene");
108 }
109