1 /* 2 * Copyright (c) 2023 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 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetComponentNumTest_001, TestSize.Level1) 50 { 51 ASSERT_TRUE(manager_ != nullptr); 52 int32_t count = 0; 53 auto ret = manager_->GetComponentNum(count); 54 ASSERT_EQ(ret, HDF_SUCCESS); 55 ASSERT_TRUE(count >= 0); 56 } 57 58 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiGetCapabilityListTest_001, TestSize.Level1) 59 { 60 ASSERT_TRUE(manager_ != nullptr); 61 int32_t count = 0; 62 auto ret = manager_->GetComponentNum(count); 63 ASSERT_EQ(ret, HDF_SUCCESS); 64 ASSERT_TRUE(count > 0); 65 66 std::vector<CodecCompCapability> capList;; 67 ret = manager_->GetComponentCapabilityList(capList, count); 68 ASSERT_EQ(ret, HDF_SUCCESS); 69 } 70 71 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_001, TestSize.Level1) 72 { 73 ASSERT_TRUE(callback_ != nullptr); 74 ASSERT_TRUE(manager_ != nullptr); 75 sptr<ICodecComponent> component; 76 uint32_t componentId = 0; 77 int32_t ret = manager_->CreateComponent(component, componentId, "", APP_DATA, callback_); 78 ASSERT_NE(ret, HDF_SUCCESS); 79 ASSERT_EQ(component, nullptr); 80 } 81 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_002, TestSize.Level1) 82 { 83 ASSERT_TRUE(manager_ != nullptr); 84 sptr<ICodecComponent> component; 85 uint32_t componentId = 0; 86 std::string compName(""); 87 88 int32_t count = 0; 89 auto ret = manager_->GetComponentNum(count); 90 ASSERT_EQ(ret, HDF_SUCCESS); 91 ASSERT_TRUE(count > 0); 92 93 std::vector<CodecCompCapability> capList;; 94 ret = manager_->GetComponentCapabilityList(capList, count); 95 ASSERT_EQ(ret, HDF_SUCCESS); 96 97 compName = capList[0].compName; 98 ret = manager_->CreateComponent(component, componentId, compName, APP_DATA, nullptr); 99 ASSERT_NE(ret, HDF_SUCCESS); 100 ASSERT_EQ(component, nullptr); 101 } 102 103 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiCreateComponentTest_003, TestSize.Level1) 104 { 105 ASSERT_TRUE(manager_ != nullptr); 106 std::string compName(""); 107 int32_t count = 0; 108 auto ret = manager_->GetComponentNum(count); 109 ASSERT_EQ(ret, HDF_SUCCESS); 110 ASSERT_TRUE(count > 0); 111 112 std::vector<CodecCompCapability> capList;; 113 ret = manager_->GetComponentCapabilityList(capList, count); 114 ASSERT_EQ(ret, HDF_SUCCESS); 115 116 compName = capList[0].compName; 117 ASSERT_FALSE(compName.empty()); 118 sptr<ICodecComponent> component; 119 uint32_t componentId = 0; 120 ret = manager_->CreateComponent(component, componentId, compName, APP_DATA, callback_); 121 ASSERT_EQ(ret, HDF_SUCCESS); 122 if (componentId != 0) { 123 ret = manager_->DestroyComponent(componentId); 124 ASSERT_EQ(ret, HDF_SUCCESS); 125 } 126 } 127 128 HWTEST_F(CodecHdiManagerTest, HdfCodecHdiDestroyComponentTest_001, TestSize.Level1) 129 { 130 ASSERT_TRUE(manager_ != nullptr); 131 auto ret = manager_->DestroyComponent(INVALID_COMPONENT_ID); 132 ASSERT_EQ(ret, HDF_ERR_INVALID_PARAM); 133 } 134 } // namespace 135