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 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
16 #include <gtest/gtest.h>
17 #include <memory>
18 #include "refbase.h"
19 #include "surface.h"
20 #include "metadata_generator.h"
21 #include "algorithm_errors.h"
22
23 using namespace std;
24 using namespace testing::ext;
25
26 namespace {
27 constexpr int32_t WIDTH = 1920;
28 constexpr int32_t HEIGHT = 1080;
29 }
30
31 namespace OHOS {
32 namespace Media {
33 namespace VideoProcessingEngine {
34 class MGModuleTest : public testing::Test {
35 public:
SetUpTestCase(void)36 static void SetUpTestCase(void) {};
TearDownTestCase(void)37 static void TearDownTestCase(void) {};
SetUp()38 void SetUp() {};
TearDown()39 void TearDown() {};
40
41 void SetParameter(std::shared_ptr<MetadataGenerator> plugin);
42 sptr<SurfaceBuffer> CreateSurfaceBuffer();
43 };
44
SetParameter(std::shared_ptr<MetadataGenerator> plugin)45 void MGModuleTest::SetParameter(std::shared_ptr<MetadataGenerator> plugin)
46 {
47 MetadataGeneratorParameter parameterSet;
48 int32_t ret = plugin->SetParameter(parameterSet);
49 ASSERT_EQ(VPE_ALGO_ERR_OK, ret);
50 }
51
CreateSurfaceBuffer()52 sptr<SurfaceBuffer> MGModuleTest::CreateSurfaceBuffer()
53 {
54 auto buffer = SurfaceBuffer::Create();
55 if (nullptr == buffer) {
56 return nullptr;
57 }
58 BufferRequestConfig inputCfg;
59 inputCfg.width = WIDTH;
60 inputCfg.height = HEIGHT;
61 inputCfg.strideAlignment = WIDTH;
62 inputCfg.usage = BUFFER_USAGE_HW_TEXTURE;
63 inputCfg.format = GRAPHIC_PIXEL_FMT_YCBCR_420_SP;
64 inputCfg.timeout = 0;
65 GSError err = buffer->Alloc(inputCfg);
66 if (GSERROR_OK != err) {
67 return nullptr;
68 }
69
70 return buffer;
71 }
72
73 /**
74 * @tc.number : 0101
75 * @tc.func : Create
76 * @tc.desc : Test for MetadataGenerator Create
77 */
78 HWTEST_F(MGModuleTest, Create_0101, TestSize.Level1)
79 {
80 auto plugin = MetadataGenerator::Create();
81 ASSERT_NE(nullptr, plugin);
82 }
83
84 /**
85 * @tc.number : 0201
86 * @tc.func : SetParameter
87 * @tc.desc : parameter.renderIntent != RenderIntent::RENDER_INTENT_ABSOLUTE_COLORIMETRIC
88 */
89 HWTEST_F(MGModuleTest, SetParameter_0201, TestSize.Level1)
90 {
91 auto plugin = MetadataGenerator::Create();
92 ASSERT_NE(nullptr, plugin);
93
94 MetadataGeneratorParameter parameterSet;
95 int32_t ret = plugin->SetParameter(parameterSet);
96 ASSERT_EQ(VPE_ALGO_ERR_OK, ret);
97 }
98
99 /**
100 * @tc.number : 0202
101 * @tc.func : SetParameter
102 * @tc.desc : parameter.renderIntent = RenderIntent::RENDER_INTENT_ABSOLUTE_COLORIMETRIC
103 */
104 HWTEST_F(MGModuleTest, SetParameter_0202, TestSize.Level1)
105 {
106 auto plugin = MetadataGenerator::Create();
107 ASSERT_NE(nullptr, plugin);
108
109 SetParameter(plugin);
110 }
111
112 /**
113 * @tc.number : 0301
114 * @tc.func : GetParameter
115 * @tc.desc : Call after Create
116 */
117 HWTEST_F(MGModuleTest, GetParameter_0301, TestSize.Level1)
118 {
119 auto plugin = MetadataGenerator::Create();
120 ASSERT_NE(nullptr, plugin);
121
122 MetadataGeneratorParameter parameterGet;
123 int32_t ret = plugin->GetParameter(parameterGet);
124 ASSERT_EQ(VPE_ALGO_ERR_OK, ret);
125 }
126
127 /**
128 * @tc.number : 0302
129 * @tc.func : GetParameter
130 * @tc.desc : Call after SetParameter
131 */
132 HWTEST_F(MGModuleTest, GetParameter_0302, TestSize.Level1)
133 {
134 auto plugin = MetadataGenerator::Create();
135 ASSERT_NE(nullptr, plugin);
136
137 SetParameter(plugin);
138
139 MetadataGeneratorParameter parameterGet;
140 int32_t ret = plugin->GetParameter(parameterGet);
141 ASSERT_EQ(VPE_ALGO_ERR_OK, ret);
142 }
143
144 /**
145 * @tc.number : 0401
146 * @tc.func : Process
147 * @tc.desc : Call after Create
148 */
149 HWTEST_F(MGModuleTest, Process_0401, TestSize.Level1)
150 {
151 auto plugin = MetadataGenerator::Create();
152 ASSERT_NE(nullptr, plugin);
153
154 int32_t ret = plugin->Process(SurfaceBuffer::Create());
155 ASSERT_NE(VPE_ALGO_ERR_OK, ret);
156 }
157
158 /**
159 * @tc.number : 0402
160 * @tc.func : Process
161 * @tc.desc : Call after SetParameter, input is null
162 */
163 HWTEST_F(MGModuleTest, Process_0402, TestSize.Level1)
164 {
165 auto plugin = MetadataGenerator::Create();
166 ASSERT_NE(nullptr, plugin);
167
168 SetParameter(plugin);
169
170 int32_t ret = plugin->Process(nullptr);
171 ASSERT_NE(VPE_ALGO_ERR_OK, ret);
172 }
173
174 /**
175 * @tc.number : 0404
176 * @tc.func : Process
177 * @tc.desc : Call after SetParameter, input is not null
178 */
179 HWTEST_F(MGModuleTest, Process_0404, TestSize.Level1)
180 {
181 auto plugin = MetadataGenerator::Create();
182 ASSERT_NE(nullptr, plugin);
183
184 SetParameter(plugin);
185
186 auto input = CreateSurfaceBuffer();
187 ASSERT_NE(nullptr, input);
188
189 int32_t ret = plugin->Process(input);
190 ASSERT_NE(VPE_ALGO_ERR_OK, ret);
191 }
192 } // namespace VideoProcessingEngine
193 } // namespace Media
194 } // namespace OHOS