• 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 <iostream>
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include "audio_utils.h"
20 #include "common/hdi_adapter_info.h"
21 #include "manager/hdi_adapter_manager.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 class AdapterUnitTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase() {}
TearDownTestCase()30     static void TearDownTestCase() {}
SetUp()31     virtual void SetUp() {}
TearDown()32     virtual void TearDown() {}
33 
34     void TestAction(HdiDeviceManagerType type);
35     void TestSetAndGet(HdiDeviceManagerType type);
36 
37 protected:
38     std::string adapterName_ = "test";
39 };
40 
TestAction(HdiDeviceManagerType type)41 void AdapterUnitTest::TestAction(HdiDeviceManagerType type)
42 {
43     std::shared_ptr<IDeviceManager> deviceManager = HdiAdapterManager::GetInstance().GetDeviceManager(type);
44     ASSERT_NE(deviceManager, nullptr);
45 
46     auto ret = deviceManager->LoadAdapter(adapterName_);
47     EXPECT_NE(ret, SUCCESS);
48 
49     uint32_t id = 0;
50     void *render = deviceManager->CreateRender(adapterName_, nullptr, nullptr, id);
51     EXPECT_EQ(render, nullptr);
52     deviceManager->DestroyRender(adapterName_, id);
53 
54     void *capture = deviceManager->CreateCapture(adapterName_, nullptr, nullptr, id);
55     EXPECT_EQ(capture, nullptr);
56     deviceManager->DestroyCapture(adapterName_, id);
57 
58     deviceManager->UnloadAdapter(adapterName_);
59 }
60 
TestSetAndGet(HdiDeviceManagerType type)61 void AdapterUnitTest::TestSetAndGet(HdiDeviceManagerType type)
62 {
63     std::shared_ptr<IDeviceManager> deviceManager = HdiAdapterManager::GetInstance().GetDeviceManager(type);
64     ASSERT_NE(deviceManager, nullptr);
65 
66     deviceManager->SetAudioParameter(adapterName_, AudioParamKey::NONE, "", "");
67 
68     std::string value = deviceManager->GetAudioParameter(adapterName_, AudioParamKey::NONE, "");
69     EXPECT_EQ(value, "");
70 
71     auto ret = deviceManager->SetVoiceVolume(adapterName_, 0.0);
72     EXPECT_NE(ret, SUCCESS);
73 
74     ret = deviceManager->SetOutputRoute(adapterName_, { DEVICE_TYPE_SPEAKER, DEVICE_TYPE_EARPIECE }, 0);
75     EXPECT_NE(ret, SUCCESS);
76 
77     ret = deviceManager->SetInputRoute(adapterName_, DEVICE_TYPE_MIC, 0, 0);
78     EXPECT_NE(ret, SUCCESS);
79 
80     deviceManager->SetMicMute(adapterName_, false);
81 }
82 
83 /**
84  * @tc.name   : Test Adapter API
85  * @tc.number : AdapterUnitTest_001
86  * @tc.desc   : Test local adapter action
87  */
88 HWTEST_F(AdapterUnitTest, AdapterUnitTest_001, TestSize.Level1)
89 {
90     TestAction(HDI_DEVICE_MANAGER_TYPE_LOCAL);
91 }
92 
93 /**
94  * @tc.name   : Test Adapter API
95  * @tc.number : AdapterUnitTest_002
96  * @tc.desc   : Test local adapter set/get operation
97  */
98 HWTEST_F(AdapterUnitTest, AdapterUnitTest_002, TestSize.Level1)
99 {
100     TestSetAndGet(HDI_DEVICE_MANAGER_TYPE_LOCAL);
101 }
102 
103 /**
104  * @tc.name   : Test Adapter API
105  * @tc.number : AdapterUnitTest_003
106  * @tc.desc   : Test bt adapter action
107  */
108 HWTEST_F(AdapterUnitTest, AdapterUnitTest_003, TestSize.Level1)
109 {
110     TestAction(HDI_DEVICE_MANAGER_TYPE_BLUETOOTH);
111 }
112 
113 /**
114  * @tc.name   : Test Adapter API
115  * @tc.number : AdapterUnitTest_004
116  * @tc.desc   : Test bt adapter set/get operation
117  */
118 HWTEST_F(AdapterUnitTest, AdapterUnitTest_004, TestSize.Level1)
119 {
120     TestSetAndGet(HDI_DEVICE_MANAGER_TYPE_BLUETOOTH);
121 }
122 
123 /**
124  * @tc.name   : Test Adapter API
125  * @tc.number : AdapterUnitTest_005
126  * @tc.desc   : Test remote adapter action
127  */
128 HWTEST_F(AdapterUnitTest, AdapterUnitTest_005, TestSize.Level1)
129 {
130     TestAction(HDI_DEVICE_MANAGER_TYPE_REMOTE);
131 }
132 
133 /**
134  * @tc.name   : Test Adapter API
135  * @tc.number : AdapterUnitTest_006
136  * @tc.desc   : Test remote adapter set/get operation
137  */
138 HWTEST_F(AdapterUnitTest, AdapterUnitTest_006, TestSize.Level1)
139 {
140     TestSetAndGet(HDI_DEVICE_MANAGER_TYPE_REMOTE);
141 }
142 
143 } // namespace AudioStandard
144 } // namespace OHOS
145