• 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 ManagerUnitTest : 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 
35 /**
36  * @tc.name   : Test Manager API
37  * @tc.number : ManagerUnitTest_001
38  * @tc.desc   : Test manager action
39  */
40 HWTEST_F(ManagerUnitTest, ManagerUnitTest_001, TestSize.Level1)
41 {
42     HdiAdapterManager &manager = HdiAdapterManager::GetInstance();
43     uint32_t id = manager.GetId(HDI_ID_BASE_RENDER, HDI_ID_TYPE_PRIMARY);
44     EXPECT_NE(id, HDI_INVALID_ID);
45 
46     id = manager.GetRenderIdByDeviceClass("");
47     EXPECT_EQ(id, HDI_INVALID_ID);
48 
49     id = manager.GetCaptureIdByDeviceClass("", SOURCE_TYPE_MIC);
50     EXPECT_EQ(id, HDI_INVALID_ID);
51 
52     manager.ReleaseId(id);
53 
54     std::shared_ptr<IAudioRenderSink> sink = manager.GetRenderSink(id);
55     EXPECT_EQ(sink, nullptr);
56 
57     std::shared_ptr<IAudioCaptureSource> source = manager.GetCaptureSource(id);
58     EXPECT_EQ(source, nullptr);
59 
60     std::function<int32_t(uint32_t, std::shared_ptr<IAudioRenderSink>)> sinkProcessFunc =
__anon557af6330102(uint32_t id, std::shared_ptr<IAudioRenderSink> sink) 61         [](uint32_t id, std::shared_ptr<IAudioRenderSink> sink) -> bool { return SUCCESS; };
62     auto ret = manager.ProcessSink(sinkProcessFunc);
63     EXPECT_EQ(ret, SUCCESS);
64 
65     std::function<int32_t(uint32_t, std::shared_ptr<IAudioCaptureSource>)> sourceProcessFunc =
__anon557af6330202(uint32_t id, std::shared_ptr<IAudioCaptureSource> source) 66         [](uint32_t id, std::shared_ptr<IAudioCaptureSource> source) -> bool { return SUCCESS; };
67     ret = manager.ProcessSource(sourceProcessFunc);
68     EXPECT_EQ(ret, SUCCESS);
69 
70     std::shared_ptr<IDeviceManager> deviceManager = manager.GetDeviceManager(HDI_DEVICE_MANAGER_TYPE_LOCAL);
71     EXPECT_NE(deviceManager, nullptr);
72 
73     manager.ReleaseDeviceManager(HDI_DEVICE_MANAGER_TYPE_NUM);
74 }
75 
76 } // namespace AudioStandard
77 } // namespace OHOS
78