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_monitor.h" 23 24 using namespace testing::ext; 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class ManagerUnitTest : 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 36 /** 37 * @tc.name : Test Manager API 38 * @tc.number : ManagerUnitTest_001 39 * @tc.desc : Test manager action 40 */ 41 HWTEST_F(ManagerUnitTest, ManagerUnitTest_001, TestSize.Level1) 42 { 43 HdiAdapterManager &manager = HdiAdapterManager::GetInstance(); 44 uint32_t id = manager.GetId(HDI_ID_BASE_RENDER, HDI_ID_TYPE_PRIMARY); 45 EXPECT_NE(id, HDI_INVALID_ID); 46 47 id = manager.GetRenderIdByDeviceClass(""); 48 EXPECT_EQ(id, HDI_INVALID_ID); 49 50 id = manager.GetCaptureIdByDeviceClass("", SOURCE_TYPE_MIC); 51 EXPECT_EQ(id, HDI_INVALID_ID); 52 53 manager.ReleaseId(id); 54 55 std::shared_ptr<IAudioRenderSink> sink = manager.GetRenderSink(id); 56 EXPECT_EQ(sink, nullptr); 57 58 std::shared_ptr<IAudioCaptureSource> source = manager.GetCaptureSource(id); 59 EXPECT_EQ(source, nullptr); 60 61 std::function<int32_t(uint32_t, std::shared_ptr<IAudioRenderSink>)> sinkProcessFunc = __anon55f4f1950102(uint32_t id, std::shared_ptr<IAudioRenderSink> sink) 62 [](uint32_t id, std::shared_ptr<IAudioRenderSink> sink) -> bool { return SUCCESS; }; 63 auto ret = manager.ProcessSink(sinkProcessFunc); 64 EXPECT_EQ(ret, SUCCESS); 65 66 std::function<int32_t(uint32_t, std::shared_ptr<IAudioCaptureSource>)> sourceProcessFunc = __anon55f4f1950202(uint32_t id, std::shared_ptr<IAudioCaptureSource> source) 67 [](uint32_t id, std::shared_ptr<IAudioCaptureSource> source) -> bool { return SUCCESS; }; 68 ret = manager.ProcessSource(sourceProcessFunc); 69 EXPECT_EQ(ret, SUCCESS); 70 71 manager.UpdateSinkPrestoreInfo<bool>("test", true); 72 73 std::shared_ptr<IDeviceManager> deviceManager = manager.GetDeviceManager(HDI_DEVICE_MANAGER_TYPE_LOCAL); 74 EXPECT_NE(deviceManager, nullptr); 75 76 manager.ReleaseDeviceManager(HDI_DEVICE_MANAGER_TYPE_NUM); 77 78 HdiMonitor::ReportHdiException(LOCAL, CALL_HDI_FAILED, 0, "test report hdi"); 79 } 80 81 } // namespace AudioStandard 82 } // namespace OHOS 83