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