1 /*
2 * Copyright (C) 2025 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 "super_resolution_post_processor_unit_test.h"
17
18 #include "gmock/gmock.h"
19
20 using namespace OHOS;
21 using namespace OHOS::Media;
22 using namespace std;
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace Media {
28 namespace Pipeline {
29
SetUpTestCase(void)30 void SuperResolutionPostProcessorUnitTest::SetUpTestCase(void) {}
31
TearDownTestCase(void)32 void SuperResolutionPostProcessorUnitTest::TearDownTestCase(void) {}
33
SetUp(void)34 void SuperResolutionPostProcessorUnitTest::SetUp(void)
35 {
36 postProcessor_ = std::make_shared<SuperResolutionPostProcessor>();
37 EXPECT_NE(postProcessor_, nullptr);
38 callback_ = std::make_shared<MockPostProcessorCallback>();
39 postProcessor_->SetCallback(callback_);
40 EXPECT_NE(postProcessor_->filterCallback_, nullptr);
41 }
42
TearDown(void)43 void SuperResolutionPostProcessorUnitTest::TearDown(void)
44 {
45 postProcessor_ = nullptr;
46 }
47
48 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Supported_001, TestSize.Level1)
49 {
50 std::shared_ptr<Meta> meta = std::make_shared<Meta>();
51
52 meta->SetData(Tag::VIDEO_WIDTH, 1280);
53 meta->SetData(Tag::VIDEO_HEIGHT, 720);
54 meta->SetData(Tag::VIDEO_IS_HDR_VIVID, false);
55 meta->SetData(Tag::AV_PLAYER_IS_DRM_PROTECTED, false);
56 EXPECT_EQ(isSuperResolutionSupported(meta), true);
57
58 meta->SetData(Tag::VIDEO_WIDTH, 1920);
59 meta->SetData(Tag::VIDEO_HEIGHT, 1080);
60 meta->SetData(Tag::VIDEO_IS_HDR_VIVID, false);
61 meta->SetData(Tag::AV_PLAYER_IS_DRM_PROTECTED, false);
62 EXPECT_EQ(isSuperResolutionSupported(meta), true);
63
64 meta->SetData(Tag::VIDEO_WIDTH, 0);
65 meta->SetData(Tag::VIDEO_HEIGHT, 0);
66 meta->SetData(Tag::VIDEO_IS_HDR_VIVID, false);
67 meta->SetData(Tag::AV_PLAYER_IS_DRM_PROTECTED, false);
68 EXPECT_EQ(isSuperResolutionSupported(meta), false);
69
70 meta->SetData(Tag::VIDEO_WIDTH, 720);
71 meta->SetData(Tag::VIDEO_HEIGHT, 480);
72 meta->SetData(Tag::VIDEO_IS_HDR_VIVID, true);
73 meta->SetData(Tag::AV_PLAYER_IS_DRM_PROTECTED, false);
74 EXPECT_EQ(isSuperResolutionSupported(meta), false);
75
76 meta->SetData(Tag::VIDEO_WIDTH, 720);
77 meta->SetData(Tag::VIDEO_HEIGHT, 480);
78 meta->SetData(Tag::VIDEO_IS_HDR_VIVID, false);
79 meta->SetData(Tag::AV_PLAYER_IS_DRM_PROTECTED, true);
80 EXPECT_EQ(isSuperResolutionSupported(meta), false);
81 }
82
83 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_VpeCallback_001, TestSize.Level1)
84 {
85 Format format;
86 VpeBufferSize bufferSize;
87 VpeBufferInfo bufferInfo;
88 VPECallback vpeCb(nullptr);
89
90 vpeCb.OnError(VPEAlgoErrCode::VPE_ALGO_ERR_OK);
91 vpeCb.OnEffectChange(0);
92 format.PutBuffer(ParameterKey::DETAIL_ENHANCER_TARGET_SIZE, reinterpret_cast<uint8_t*>(&bufferSize),
93 sizeof(bufferSize));
94 vpeCb.OnOutputFormatChanged(format);
95 vpeCb.OnOutputBufferAvailable(0, bufferInfo);
96 EXPECT_EQ(vpeCb.postProcessor_.lock(), nullptr);
97 }
98
99 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_VpeCallback_002, TestSize.Level1)
100 {
101 Format format;
102 VpeBufferSize bufferSize;
103 VpeBufferInfo bufferInfo;
104 VPECallback vpeCb(postProcessor_);
105
106 vpeCb.OnError(VPEAlgoErrCode::VPE_ALGO_ERR_OK);
107 vpeCb.OnEffectChange(0);
108 vpeCb.OnOutputFormatChanged(format);
109 bufferSize.width = 1920;
110 bufferSize.height = 1080;
111 format.PutBuffer(ParameterKey::DETAIL_ENHANCER_TARGET_SIZE, reinterpret_cast<uint8_t*>(&bufferSize),
112 sizeof(bufferSize));
113 vpeCb.OnOutputFormatChanged(format);
114 bufferSize.width = 1920;
115 bufferSize.height = -1;
116 format.PutBuffer(ParameterKey::DETAIL_ENHANCER_TARGET_SIZE, reinterpret_cast<uint8_t*>(&bufferSize),
117 sizeof(bufferSize));
118 vpeCb.OnOutputFormatChanged(format);
119 bufferSize.width = -1;
120 bufferSize.height = 1080;
121 format.PutBuffer(ParameterKey::DETAIL_ENHANCER_TARGET_SIZE, reinterpret_cast<uint8_t*>(&bufferSize),
122 sizeof(bufferSize));
123 vpeCb.OnOutputFormatChanged(format);
124 vpeCb.OnOutputBufferAvailable(0, bufferInfo);
125 EXPECT_NE(vpeCb.postProcessor_.lock(), nullptr);
126 }
127
128 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Init_001, TestSize.Level1)
129 {
130 EXPECT_CALL(*(postProcessor_->postProcessor_),
131 SetParameter(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
132 EXPECT_CALL(*(postProcessor_->postProcessor_),
133 RegisterCallback(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
134 EXPECT_EQ(postProcessor_->Init(), Status::OK);
135 }
136
137 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Init_002, TestSize.Level1)
138 {
139 EXPECT_CALL(*(postProcessor_->postProcessor_),
140 SetParameter(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
141 EXPECT_CALL(*(postProcessor_->postProcessor_),
142 RegisterCallback(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
143 EXPECT_EQ(postProcessor_->Init(), Status::ERROR_INVALID_PARAMETER);
144 }
145
146 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Init_003, TestSize.Level1)
147 {
148 EXPECT_CALL(*(postProcessor_->postProcessor_),
149 SetParameter(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
150 EXPECT_CALL(*(postProcessor_->postProcessor_),
151 RegisterCallback(_)).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
152 EXPECT_EQ(postProcessor_->Init(), Status::ERROR_INVALID_STATE);
153 }
154
155 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Flush_001, TestSize.Level1)
156 {
157 EXPECT_CALL(*(postProcessor_->postProcessor_),
158 Flush()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
159 EXPECT_EQ(postProcessor_->Flush(), Status::OK);
160 }
161
162 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Flush_002, TestSize.Level1)
163 {
164 EXPECT_CALL(*(postProcessor_->postProcessor_),
165 Flush()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
166 EXPECT_EQ(postProcessor_->Flush(), Status::ERROR_INVALID_STATE);
167 }
168
169 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Stop_001, TestSize.Level1)
170 {
171 EXPECT_CALL(*(postProcessor_->postProcessor_),
172 Stop()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
173 EXPECT_CALL(*(postProcessor_->postProcessor_),
174 Release()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
175 EXPECT_EQ(postProcessor_->Stop(), Status::OK);
176 }
177
178 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Stop_002, TestSize.Level1)
179 {
180 EXPECT_CALL(*(postProcessor_->postProcessor_),
181 Stop()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
182 EXPECT_CALL(*(postProcessor_->postProcessor_),
183 Release()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
184 EXPECT_EQ(postProcessor_->Stop(), Status::ERROR_INVALID_STATE);
185 }
186
187 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Start_001, TestSize.Level1)
188 {
189 EXPECT_CALL(*(postProcessor_->postProcessor_),
190 Start()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
191 EXPECT_EQ(postProcessor_->Start(), Status::OK);
192 }
193
194 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Start_002, TestSize.Level1)
195 {
196 EXPECT_CALL(*(postProcessor_->postProcessor_),
197 Start()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
198 EXPECT_EQ(postProcessor_->Start(), Status::ERROR_INVALID_STATE);
199 }
200
201 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Release_001, TestSize.Level1)
202 {
203 EXPECT_CALL(*(postProcessor_->postProcessor_),
204 Release()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
205 EXPECT_EQ(postProcessor_->Release(), Status::OK);
206 }
207
208 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_Release_002, TestSize.Level1)
209 {
210 EXPECT_CALL(*(postProcessor_->postProcessor_),
211 Release()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
212 EXPECT_EQ(postProcessor_->Release(), Status::ERROR_INVALID_STATE);
213 }
214
215 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnOutputBufferAvailable_001, TestSize.Level1)
216 {
217 uint32_t index = 0;
218 VpeBufferFlag flag = VPE_BUFFER_FLAG_NONE;
219 postProcessor_->OnOutputBufferAvailable(index, flag);
220 EXPECT_FALSE(callback_->buffer_->flag_ & static_cast<uint32_t>(Plugins::AVBufferFlag::EOS));
221 }
222
223 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnOutputBufferAvailable_002, TestSize.Level1)
224 {
225 uint32_t index = 0;
226 VpeBufferFlag flag = VPE_BUFFER_FLAG_EOS;
227 postProcessor_->OnOutputBufferAvailable(index, flag);
228 EXPECT_TRUE(callback_->buffer_->flag_ & static_cast<uint32_t>(Plugins::AVBufferFlag::EOS));
229 }
230
231 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnOutputBufferAvailable_003, TestSize.Level1)
232 {
233 uint32_t index = 0;
234 VpeBufferInfo bufferInfo;
235 bufferInfo.flag = VPE_BUFFER_FLAG_NONE;
236 postProcessor_->OnOutputBufferAvailable(index, bufferInfo);
237 EXPECT_FALSE(callback_->buffer_->flag_ & static_cast<uint32_t>(Plugins::AVBufferFlag::EOS));
238 }
239
240 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnOutputBufferAvailable_004, TestSize.Level1)
241 {
242 uint32_t index = 0;
243 VpeBufferInfo bufferInfo;
244 bufferInfo.flag = VPE_BUFFER_FLAG_EOS;
245 postProcessor_->OnOutputBufferAvailable(index, bufferInfo);
246 EXPECT_TRUE(callback_->buffer_->flag_ & static_cast<uint32_t>(Plugins::AVBufferFlag::EOS));
247 }
248
249 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_SetPostProcessorOn_001, TestSize.Level1)
250 {
251 EXPECT_CALL(*(postProcessor_->postProcessor_),
252 Enable()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
253 EXPECT_CALL(*(postProcessor_->postProcessor_),
254 Disable()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_OK));
255 EXPECT_EQ(postProcessor_->SetPostProcessorOn(true), Status::OK);
256 EXPECT_EQ(postProcessor_->SetPostProcessorOn(false), Status::OK);
257 }
258
259 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_SetPostProcessorOn_002, TestSize.Level1)
260 {
261 EXPECT_CALL(*(postProcessor_->postProcessor_),
262 Enable()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
263 EXPECT_CALL(*(postProcessor_->postProcessor_),
264 Disable()).WillRepeatedly(Return(VPEAlgoErrCode::VPE_ALGO_ERR_UNKNOWN));
265 EXPECT_EQ(postProcessor_->SetPostProcessorOn(true), Status::ERROR_INVALID_STATE);
266 EXPECT_EQ(postProcessor_->SetPostProcessorOn(false), Status::ERROR_INVALID_STATE);
267 }
268
269 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnSuperResolutionChanged_001, TestSize.Level1)
270 {
271 postProcessor_->eventReceiver_ = nullptr;
272 postProcessor_->OnSuperResolutionChanged(false);
273 EXPECT_EQ(postProcessor_->isPostProcessorOn_, false);
274 postProcessor_->OnSuperResolutionChanged(true);
275 EXPECT_EQ(postProcessor_->isPostProcessorOn_, true);
276 }
277
278 HWTEST_F(SuperResolutionPostProcessorUnitTest, SuperResolution_OnSuperResolutionChanged_002, TestSize.Level1)
279 {
280 postProcessor_->eventReceiver_ = std::make_shared<MockEventReceiver>();
281 postProcessor_->OnSuperResolutionChanged(false);
282 EXPECT_EQ(postProcessor_->isPostProcessorOn_, false);
283 postProcessor_->OnSuperResolutionChanged(true);
284 EXPECT_EQ(postProcessor_->isPostProcessorOn_, true);
285 }
286 } // namespace Pipeline
287 } // namespace Media
288 } // namespace OHOS
289