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