1 /* 2 * Copyright (c) 2024 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 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 <gtest/gtest.h> 17 #include "v3_0/codec_callback_service.h" 18 #include "v3_0/icodec_callback.h" 19 #include "v3_0/icodec_component_manager.h" 20 using namespace std; 21 using namespace testing::ext; 22 using OHOS::sptr; 23 using namespace OHOS::HDI::Codec::V3_0; 24 constexpr int64_t APP_DATA = 3; 25 constexpr uint32_t INVALID_COMPONENT_ID = -1; 26 namespace { 27 class CodecHdiManagerTest : public testing::Test { 28 public: SetUpTestCase()29 static void SetUpTestCase() 30 {} TearDownTestCase()31 static void TearDownTestCase() 32 {} SetUp()33 void SetUp() 34 { 35 manager_ = ICodecComponentManager::Get(); 36 callback_ = new CodecCallbackService(); 37 } TearDown()38 void TearDown() 39 { 40 manager_ = nullptr; 41 callback_ = nullptr; 42 } 43 44 public: 45 sptr<ICodecComponentManager> manager_; 46 sptr<ICodecCallback> callback_; 47 }; 48 49 /** 50 * @tc.number : SUB_Driver_Codec_idlomx_0100 51 * @tc.name : HdfCodecHdiGetComponentNumTest_001 52 * @tc.desc : Verify the GetComponentNum function when the input parameter is valid. 53 @tc.type: FUNC 54 */ 55 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetComponentNumTest_001, TestSize.Level1) 56 { 57 ASSERT_TRUE(manager_ != nullptr); 58 int32_t count = 0; 59 auto ret = manager_->GetComponentNum(count); 60 ASSERT_EQ(ret, HDF_SUCCESS); 61 ASSERT_TRUE(count >= 0); 62 } 63 64 /** 65 * @tc.number : SUB_Driver_Codec_idlomx_0200 66 * @tc.name : HdfCodecHdiGetCapabilityListTest_001 67 * @tc.desc : Verify the GetComponentCapabilityList function when the input parameter is valid. 68 @tc.type: FUNC 69 */ 70 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetCapabilityListTest_001, TestSize.Level1) 71 { 72 ASSERT_TRUE(manager_ != nullptr); 73 int32_t count = 0; 74 auto ret = manager_->GetComponentNum(count); 75 ASSERT_EQ(ret, HDF_SUCCESS); 76 ASSERT_TRUE(count > 0); 77 78 std::vector<CodecCompCapability> capList;; 79 ret = manager_->GetComponentCapabilityList(capList, count); 80 ASSERT_EQ(ret, HDF_SUCCESS); 81 } 82 83 /** 84 * @tc.number : SUB_Driver_Codec_idlomx_0300 85 * @tc.name : HdfCodecHdiCreateComponentTest_001 86 * @tc.desc : Verify the CreateComponent function when the input parameter is invalid. 87 @tc.type: FUNC 88 */ 89 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_001, TestSize.Level1) 90 { 91 ASSERT_TRUE(callback_ != nullptr); 92 ASSERT_TRUE(manager_ != nullptr); 93 sptr<ICodecComponent> component; 94 uint32_t componentId = 0; 95 int32_t ret = manager_->CreateComponent(component, componentId, "", APP_DATA, callback_); 96 ASSERT_NE(ret, HDF_SUCCESS); 97 ASSERT_EQ(component, nullptr); 98 } 99 100 /** 101 * @tc.number : SUB_Driver_Codec_idlomx_0400 102 * @tc.name : HdfCodecHdiCreateComponentTest_002 103 * @tc.desc : Verify the CreateComponent function when the input parameter is invalid. 104 @tc.type: FUNC 105 */ 106 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_002, TestSize.Level1) 107 { 108 ASSERT_TRUE(manager_ != nullptr); 109 sptr<ICodecComponent> component; 110 uint32_t componentId = 0; 111 std::string compName(""); 112 113 int32_t count = 0; 114 auto ret = manager_->GetComponentNum(count); 115 ASSERT_EQ(ret, HDF_SUCCESS); 116 ASSERT_TRUE(count > 0); 117 118 std::vector<CodecCompCapability> capList;; 119 ret = manager_->GetComponentCapabilityList(capList, count); 120 ASSERT_EQ(ret, HDF_SUCCESS); 121 122 compName = capList[0].compName; 123 ret = manager_->CreateComponent(component, componentId, compName, APP_DATA, nullptr); 124 ASSERT_NE(ret, HDF_SUCCESS); 125 ASSERT_EQ(component, nullptr); 126 } 127 128 /** 129 * @tc.number : SUB_Driver_Codec_idlomx_0500 130 * @tc.name : HdfCodecHdiCreateComponentTest_003 131 * @tc.desc : Verify the CreateComponent function when the input parameter is valid. 132 @tc.type: FUNC 133 */ 134 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_003, TestSize.Level1) 135 { 136 ASSERT_TRUE(manager_ != nullptr); 137 std::string compName(""); 138 int32_t count = 0; 139 auto ret = manager_->GetComponentNum(count); 140 ASSERT_EQ(ret, HDF_SUCCESS); 141 ASSERT_TRUE(count > 0); 142 143 std::vector<CodecCompCapability> capList;; 144 ret = manager_->GetComponentCapabilityList(capList, count); 145 ASSERT_EQ(ret, HDF_SUCCESS); 146 147 compName = capList[0].compName; 148 ASSERT_FALSE(compName.empty()); 149 sptr<ICodecComponent> component; 150 uint32_t componentId = 0; 151 ret = manager_->CreateComponent(component, componentId, compName, APP_DATA, callback_); 152 ASSERT_EQ(ret, HDF_SUCCESS); 153 if (componentId != 0) { 154 ret = manager_->DestroyComponent(componentId); 155 ASSERT_EQ(ret, HDF_SUCCESS); 156 } 157 } 158 159 /** 160 * @tc.number : SUB_Driver_Codec_idlomx_0600 161 * @tc.name : HdfCodecHdiDestroyComponentTest_001 162 * @tc.desc : Verify the DestroyComponent function when the input parameter is invalid. 163 @tc.type: FUNC 164 */ 165 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiDestroyComponentTest_001, TestSize.Level1) 166 { 167 ASSERT_TRUE(manager_ != nullptr); 168 auto ret = manager_->DestroyComponent(INVALID_COMPONENT_ID); 169 ASSERT_EQ(ret, HDF_ERR_INVALID_PARAM); 170 } 171 } // namespace 172