1 /*
2 * Copyright (c) 2022 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 #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 * @tc.name HdfCodecHdiGetComponentNumTest
43 * @tc.number SUB_Driver_Codec_CodecHdi_0200
44 * @tc.desc Obtain the total number of codec HDI2.0 capability sets
45 */
HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0200, Function | MediumTest | Level3)46 HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0200, Function | MediumTest | Level3)
47 {
48 ASSERT_TRUE(manager_ != nullptr);
49 auto count = manager_->GetComponentNum();
50 EXPECT_TRUE(count >= 0);
51 }
52 /**
53 * @tc.name HdfCodecHdiGetCapabilityListTest_001
54 * @tc.number SUB_Driver_Codec_CodecHdi_0300
55 * @tc.desc Obtains the capability data of the codec capability and prints the data to the Hilog
56 */
HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0300, Function | MediumTest | Level3)57 HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0300, Function | MediumTest | Level3)
58 {
59 ASSERT_TRUE(manager_ != nullptr);
60 auto count = manager_->GetComponentNum();
61 ASSERT_TRUE(count > 0);
62 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
63 ASSERT_TRUE(capList != nullptr);
64 auto err = manager_->GetComponentCapabilityList(capList, count);
65 EXPECT_EQ(err, HDF_SUCCESS);
66 OsalMemFree(capList);
67 capList = nullptr;
68 }
69 /**
70 * @tc.name HdfCodecHdiCreateComponentTest_001
71 * @tc.number SUB_Driver_Codec_CodecHdi_0400
72 * @tc.desc Open the OpenMax component based on a name that does not exist
73 */
HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0400, Function | MediumTest | Level3)74 HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0400, Function | MediumTest | Level3)
75 {
76 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
77 ASSERT_TRUE(callback != nullptr);
78 ASSERT_TRUE(manager_ != nullptr);
79 struct CodecComponentType *component = nullptr;
80 uint32_t componentId = 0;
81 int32_t ret = manager_->CreateComponent(&component, &componentId, nullptr, (int64_t)this, callback);
82 EXPECT_NE(ret, HDF_SUCCESS);
83 EXPECT_EQ(component, nullptr);
84 CodecCallbackTypeRelease(callback);
85 callback = nullptr;
86 }
87 /**
88 * @tc.name HdfCodecHdiCreateComponentTest_002
89 * @tc.number SUB_Driver_Codec_CodecHdi_0500
90 * @tc.desc When a component is opened, the name of the component is transferred to a null pointer
91 */
HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0500, Function | MediumTest | Level3)92 HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_0500, Function | MediumTest | Level3)
93 {
94 ASSERT_TRUE(manager_ != nullptr);
95 std::string compName("");
96 auto count = manager_->GetComponentNum();
97 ASSERT_TRUE(count > 0);
98 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count);
99 ASSERT_TRUE(capList != nullptr);
100 auto err = manager_->GetComponentCapabilityList(capList, count);
101 ASSERT_TRUE(err == HDF_SUCCESS);
102 compName = capList[0].compName;
103 OsalMemFree(capList);
104 capList = nullptr;
105
106 ASSERT_FALSE(compName.empty());
107 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
108 struct CodecComponentType *component = nullptr;
109 uint32_t componentId = 0;
110 ASSERT_TRUE(callback != nullptr);
111 auto ret = manager_->CreateComponent(&component, &componentId, compName.data(), (int64_t)this, callback);
112 ASSERT_EQ(ret, HDF_SUCCESS);
113 ret = manager_->DestroyComponent(componentId);
114 CodecCallbackTypeRelease(callback);
115 callback = nullptr;
116 }
117 /**
118 * @tc.name HdfCodecHdiDestoryComponentTest_001
119 * @tc.number SUB_Driver_Codec_CodecHdi_7400
120 * @tc.desc Releasing Components
121 */
HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_7400, Function | MediumTest | Level3)122 HWTEST_F(CodecHdiManagerTest, SUB_Driver_Codec_CodecHdi_7400, Function | MediumTest | Level3)
123 {
124 ASSERT_TRUE(manager_ != nullptr);
125 auto ret = manager_->DestroyComponent(0);
126 EXPECT_EQ(ret, HDF_SUCCESS);
127 }
128 } // namespace