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