1 /* 2 * Copyright (c) 2022 Shenzhen Kaihong DID 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 #include <gtest/gtest.h> 16 #include <osal_mem.h> 17 #include "codec_callback_if.h" 18 #include "codec_callback_type_stub.h" 19 #include "codec_component_manager.h" 20 using namespace std; 21 using namespace testing::ext; 22 namespace { 23 class CodecHdiManagerTest : public testing::Test { 24 public: SetUpTestCase()25 static void SetUpTestCase() 26 {} TearDownTestCase()27 static void TearDownTestCase() 28 {} SetUp()29 void SetUp() 30 { 31 manager_ = GetCodecComponentManager(); 32 } TearDown()33 void TearDown() 34 { 35 CodecComponentManagerRelease(); 36 manager_ = nullptr; 37 } 38 39 public: 40 struct CodecComponentManager *manager_ = nullptr; 41 }; 42 43 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetComponentNumTest_001, TestSize.Level1) 44 { 45 ASSERT_TRUE(manager_ != nullptr); 46 auto count = manager_->GetComponentNum(); 47 EXPECT_TRUE(count >= 0); 48 } 49 50 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetCapabilityListTest_001, TestSize.Level1) 51 { 52 ASSERT_TRUE(manager_ != nullptr); 53 auto count = manager_->GetComponentNum(); 54 ASSERT_TRUE(count > 0); 55 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 56 ASSERT_TRUE(capList != nullptr); 57 auto err = manager_->GetComponentCapabilityList(capList, count); 58 EXPECT_EQ(err, HDF_SUCCESS); 59 OsalMemFree(capList); 60 capList = nullptr; 61 } 62 63 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_001, TestSize.Level1) 64 { 65 struct CodecCallbackType *callback = CodecCallbackTypeStubGetInstance(); 66 ASSERT_TRUE(callback != nullptr); 67 ASSERT_TRUE(manager_ != nullptr); 68 struct CodecComponentType *component = nullptr; 69 uint32_t componentId = 0; 70 int32_t ret = manager_->CreateComponent(&component, &componentId, nullptr, (int64_t)this, callback); 71 EXPECT_NE(ret, HDF_SUCCESS); 72 EXPECT_EQ(component, nullptr); 73 CodecCallbackTypeStubRelease(callback); 74 callback = nullptr; 75 } 76 77 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_002, TestSize.Level1) 78 { 79 ASSERT_TRUE(manager_ != nullptr); 80 std::string compName(""); 81 auto count = manager_->GetComponentNum(); 82 ASSERT_TRUE(count > 0); 83 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 84 ASSERT_TRUE(capList != nullptr); 85 auto err = manager_->GetComponentCapabilityList(capList, count); 86 EXPECT_EQ(err, HDF_SUCCESS); 87 compName = capList[0].compName; 88 OsalMemFree(capList); 89 capList = nullptr; 90 91 ASSERT_FALSE(compName.empty()); 92 struct CodecCallbackType *callback = CodecCallbackTypeStubGetInstance(); 93 struct CodecComponentType *component = nullptr; 94 uint32_t componentId = 0; 95 ASSERT_TRUE(callback != nullptr); 96 auto ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback); 97 EXPECT_EQ(ret, HDF_SUCCESS); 98 if (componentId != 0) { 99 manager_->DestroyComponent(componentId); 100 } 101 CodecCallbackTypeStubRelease(callback); 102 callback = nullptr; 103 } 104 105 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiDestroyComponentTest_001, TestSize.Level1) 106 { 107 ASSERT_TRUE(manager_ != nullptr); 108 auto ret = manager_->DestroyComponent(0); 109 EXPECT_EQ(ret, HDF_SUCCESS); 110 } 111 } // namespace