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 "videodec_unit_test.h"
17
18 using namespace std;
19 using namespace OHOS;
20 using namespace OHOS::MediaAVCodec;
21 using namespace testing::ext;
22 using namespace testing::mt;
23 using namespace OHOS::MediaAVCodec::VCodecTestParam;
24
25 namespace {
26 std::atomic<int32_t> vdecCount = 0;
27
MultiThreadCreateVDec()28 void MultiThreadCreateVDec()
29 {
30 std::shared_ptr<VDecSignal> vdecSignal = std::make_shared<VDecSignal>();
31 std::shared_ptr<VDecCallbackTest> adecCallback = std::make_shared<VDecCallbackTest>(vdecSignal);
32 ASSERT_NE(nullptr, adecCallback);
33
34 std::shared_ptr<VideoDecSample> videoDec = std::make_shared<VideoDecSample>(vdecSignal);
35 ASSERT_NE(nullptr, videoDec);
36
37 EXPECT_LE(vdecCount.load(), 16); // 16: max instances supported
38 if (videoDec->CreateVideoDecMockByName(VDEC_AVC_NAME)) {
39 vdecCount++;
40 cout << "create successed, num:" << vdecCount.load() << endl;
41 } else {
42 cout << "create failed, num:" << vdecCount.load() << endl;
43 return;
44 }
45 sleep(1);
46 videoDec->Release();
47 vdecCount--;
48 }
49 } // namespace
50
SetUpTestCase(void)51 void VideoDecUnitTest::SetUpTestCase(void) {}
52
TearDownTestCase(void)53 void VideoDecUnitTest::TearDownTestCase(void) {}
54
SetUp(void)55 void VideoDecUnitTest::SetUp(void)
56 {
57 std::shared_ptr<VDecSignal> vdecSignal = std::make_shared<VDecSignal>();
58 vdecCallback_ = std::make_shared<VDecCallbackTest>(vdecSignal);
59 ASSERT_NE(nullptr, vdecCallback_);
60
61 videoDec_ = std::make_shared<VideoDecSample>(vdecSignal);
62 ASSERT_NE(nullptr, videoDec_);
63
64 format_ = FormatMockFactory::CreateFormat();
65 ASSERT_NE(nullptr, format_);
66 }
67
TearDown(void)68 void VideoDecUnitTest::TearDown(void)
69 {
70 if (format_ != nullptr) {
71 format_->Destroy();
72 }
73 }
74
CreateVideoCodecByMime(const std::string & decMime)75 bool VideoDecUnitTest::CreateVideoCodecByMime(const std::string &decMime)
76 {
77 if (videoDec_->CreateVideoDecMockByMime(decMime) == false || videoDec_->SetCallback(vdecCallback_) != AV_ERR_OK) {
78 return false;
79 }
80 return true;
81 }
82
CreateVideoCodecByName(const std::string & decName)83 bool VideoDecUnitTest::CreateVideoCodecByName(const std::string &decName)
84 {
85 if (videoDec_->CreateVideoDecMockByName(decName) == false || videoDec_->SetCallback(vdecCallback_) != AV_ERR_OK) {
86 return false;
87 }
88 return true;
89 }
90
CreateByNameWithParam(void)91 void VideoDecUnitTest::CreateByNameWithParam(void)
92 {
93 std::string codecName = "";
94 switch (GetParam()) {
95 case VCodecTestCode::SW_AVC:
96 capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_AVC.data(), false,
97 AVCodecCategory::AVCODEC_SOFTWARE);
98 break;
99 case VCodecTestCode::HW_AVC:
100 capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_AVC.data(), false,
101 AVCodecCategory::AVCODEC_HARDWARE);
102 break;
103 case VCodecTestCode::HW_HEVC:
104 capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_HEVC.data(), false,
105 AVCodecCategory::AVCODEC_HARDWARE);
106 break;
107 default:
108 capability_ = CodecListMockFactory::GetCapabilityByCategory(CodecMimeType::VIDEO_AVC.data(), false,
109 AVCodecCategory::AVCODEC_SOFTWARE);
110 break;
111 }
112 codecName = capability_->GetName();
113 std::cout << "CodecName: " << codecName << "\n";
114 ASSERT_TRUE(CreateVideoCodecByName(codecName));
115 }
116
PrepareSource(void)117 void VideoDecUnitTest::PrepareSource(void)
118 {
119 std::string sourcePath = "/data/test/media/avc_320_240_10s.dat";
120 if (GetParam() == VCodecTestCode::HW_HEVC) {
121 sourcePath = "/data/test/media/hevc_320x240_60.dat";
122 }
123 std::cout << "SourcePath: " << sourcePath << std::endl;
124 videoDec_->SetSource(sourcePath);
125 const ::testing::TestInfo *testInfo_ = ::testing::UnitTest::GetInstance()->current_test_info();
126 string prefix = "/data/test/media/";
127 string fileName = testInfo_->name();
128 auto check = [](char it) { return it == '/'; };
129 (void)fileName.erase(std::remove_if(fileName.begin(), fileName.end(), check), fileName.end());
130 videoDec_->SetOutPath(prefix + fileName);
131 }
132
SetFormatWithParam(void)133 void VideoDecUnitTest::SetFormatWithParam(void)
134 {
135 format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
136 format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
137 }
138
139 namespace {
140 INSTANTIATE_TEST_SUITE_P(, VideoDecUnitTest, testing::Values(SW_AVC, HW_AVC, HW_HEVC));
141
142 /**
143 * @tc.name: videoDecoder_multithread_create_001
144 * @tc.desc: try create 100 instances
145 * @tc.type: FUNC
146 */
147 HWTEST_F(VideoDecUnitTest, videoDecoder_multithread_create_001, TestSize.Level1)
148 {
149 SET_THREAD_NUM(100);
150 vdecCount = 0;
151 GTEST_RUN_TASK(MultiThreadCreateVDec);
152 cout << "remaining num: " << vdecCount.load() << endl;
153 }
154
155 /**
156 * @tc.name: videoDecoder_createWithNull_001
157 * @tc.desc: video create
158 * @tc.type: FUNC
159 */
160 HWTEST_F(VideoDecUnitTest, videoDecoder_createWithNull_001, TestSize.Level1)
161 {
162 ASSERT_FALSE(CreateVideoCodecByName(""));
163 }
164
165 /**
166 * @tc.name: videoDecoder_createWithNull_002
167 * @tc.desc: video create
168 * @tc.type: FUNC
169 */
170 HWTEST_F(VideoDecUnitTest, videoDecoder_createWithNull_002, TestSize.Level1)
171 {
172 ASSERT_FALSE(CreateVideoCodecByMime(""));
173 }
174
175 /**
176 * @tc.name: videoDecoder_create_001
177 * @tc.desc: video create
178 * @tc.type: FUNC
179 */
180 HWTEST_P(VideoDecUnitTest, videoDecoder_create_001, TestSize.Level1)
181 {
182 CreateByNameWithParam();
183 }
184
185 /**
186 * @tc.name: videoDecoder_configure_001
187 * @tc.desc: correct key input.
188 * @tc.type: FUNC
189 */
190 HWTEST_P(VideoDecUnitTest, videoDecoder_configure_001, TestSize.Level1)
191 {
192 CreateByNameWithParam();
193 SetFormatWithParam();
194 format_->PutIntValue(MediaDescriptionKey::MD_KEY_ROTATION_ANGLE, 0); // set rotation_angle 0
195 format_->PutIntValue(MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE, 15000); // set max input size 15000
196 EXPECT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
197 }
198
199 /**
200 * @tc.name: videoDecoder_configure_002
201 * @tc.desc: correct key input with redundancy key input
202 * @tc.type: FUNC
203 */
204 HWTEST_P(VideoDecUnitTest, videoDecoder_configure_002, TestSize.Level1)
205 {
206 CreateByNameWithParam();
207 SetFormatWithParam();
208 format_->PutIntValue(MediaDescriptionKey::MD_KEY_ROTATION_ANGLE, 0); // set rotation_angle 0
209 format_->PutIntValue(MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE, 15000); // set max input size 15000
210 format_->PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1); // redundancy key
211 EXPECT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
212 }
213
214 /**
215 * @tc.name: videoDecoder_configure_003
216 * @tc.desc: correct key input with wrong value type input
217 * @tc.type: FUNC
218 */
219 HWTEST_P(VideoDecUnitTest, videoDecoder_configure_003, TestSize.Level1)
220 {
221 CreateByNameWithParam();
222 format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, -2); // invalid width size -2
223 format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
224 if (GetParam() == VCodecTestCode::SW_AVC) {
225 EXPECT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
226 } else {
227 EXPECT_NE(AV_ERR_OK, videoDec_->Configure(format_));
228 }
229 }
230
231 /**
232 * @tc.name: videoDecoder_configure_004
233 * @tc.desc: correct key input with wrong value type input
234 * @tc.type: FUNC
235 */
236 HWTEST_P(VideoDecUnitTest, videoDecoder_configure_004, TestSize.Level1)
237 {
238 CreateByNameWithParam();
239 format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
240 format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, -2); // invalid height size -2
241 if (GetParam() == VCodecTestCode::SW_AVC) {
242 EXPECT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
243 } else {
244 EXPECT_NE(AV_ERR_OK, videoDec_->Configure(format_));
245 }
246 }
247
248 /**
249 * @tc.name: videoDecoder_configure_005
250 * @tc.desc: empty format input
251 * @tc.type: FUNC
252 */
253 HWTEST_P(VideoDecUnitTest, videoDecoder_configure_005, TestSize.Level1)
254 {
255 CreateByNameWithParam();
256 if (GetParam() == VCodecTestCode::SW_AVC) {
257 EXPECT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
258 } else {
259 EXPECT_NE(AV_ERR_OK, videoDec_->Configure(format_));
260 }
261 }
262
263 /**
264 * @tc.name: videoDecoder_start_001
265 * @tc.desc: correct flow 1
266 * @tc.type: FUNC
267 */
268 HWTEST_P(VideoDecUnitTest, videoDecoder_start_001, TestSize.Level1)
269 {
270 CreateByNameWithParam();
271 SetFormatWithParam();
272 PrepareSource();
273 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
274 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
275 }
276
277 /**
278 * @tc.name: videoDecoder_start_002
279 * @tc.desc: correct flow 2
280 * @tc.type: FUNC
281 */
282 HWTEST_P(VideoDecUnitTest, videoDecoder_start_002, TestSize.Level1)
283 {
284 CreateByNameWithParam();
285 SetFormatWithParam();
286 PrepareSource();
287 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
288
289 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
290 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
291 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
292 }
293
294 /**
295 * @tc.name: videoDecoder_start_003
296 * @tc.desc: correct flow 2
297 * @tc.type: FUNC
298 */
299 HWTEST_P(VideoDecUnitTest, videoDecoder_start_003, TestSize.Level1)
300 {
301 CreateByNameWithParam();
302 SetFormatWithParam();
303 PrepareSource();
304 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
305
306 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
307 EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
308 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
309 }
310
311 /**
312 * @tc.name: videoDecoder_start_004
313 * @tc.desc: wrong flow 1
314 * @tc.type: FUNC
315 */
316 HWTEST_P(VideoDecUnitTest, videoDecoder_start_004, TestSize.Level1)
317 {
318 CreateByNameWithParam();
319 SetFormatWithParam();
320 PrepareSource();
321 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
322
323 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
324 EXPECT_NE(AV_ERR_OK, videoDec_->Start());
325 }
326
327 /**
328 * @tc.name: videoDecoder_start_005
329 * @tc.desc: wrong flow 2
330 * @tc.type: FUNC
331 */
332 HWTEST_P(VideoDecUnitTest, videoDecoder_start_005, TestSize.Level1)
333 {
334 CreateByNameWithParam();
335 PrepareSource();
336 EXPECT_NE(AV_ERR_OK, videoDec_->Start());
337 }
338
339 /**
340 * @tc.name: videoDecoder_stop_001
341 * @tc.desc: correct flow 1
342 * @tc.type: FUNC
343 */
344 HWTEST_P(VideoDecUnitTest, videoDecoder_stop_001, TestSize.Level1)
345 {
346 CreateByNameWithParam();
347 SetFormatWithParam();
348 PrepareSource();
349 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
350
351 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
352 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
353 }
354
355 /**
356 * @tc.name: videoDecoder_stop_002
357 * @tc.desc: correct flow 1
358 * @tc.type: FUNC
359 */
360 HWTEST_P(VideoDecUnitTest, videoDecoder_stop_002, TestSize.Level1)
361 {
362 CreateByNameWithParam();
363 SetFormatWithParam();
364 PrepareSource();
365 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
366
367 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
368 EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
369 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
370 }
371
372 /**
373 * @tc.name: videoDecoder_stop_003
374 * @tc.desc: wrong flow 1
375 * @tc.type: FUNC
376 */
377 HWTEST_P(VideoDecUnitTest, videoDecoder_stop_003, TestSize.Level1)
378 {
379 CreateByNameWithParam();
380 SetFormatWithParam();
381 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
382
383 EXPECT_NE(AV_ERR_OK, videoDec_->Stop());
384 }
385
386 /**
387 * @tc.name: videoDecoder_flush_001
388 * @tc.desc: correct flow 1
389 * @tc.type: FUNC
390 */
391 HWTEST_P(VideoDecUnitTest, videoDecoder_flush_001, TestSize.Level1)
392 {
393 CreateByNameWithParam();
394 SetFormatWithParam();
395 PrepareSource();
396 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
397
398 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
399 EXPECT_EQ(AV_ERR_OK, videoDec_->Flush());
400 }
401
402 /**
403 * @tc.name: videoDecoder_flush_002
404 * @tc.desc: wrong flow 1
405 * @tc.type: FUNC
406 */
407 HWTEST_P(VideoDecUnitTest, videoDecoder_flush_002, TestSize.Level1)
408 {
409 CreateByNameWithParam();
410 SetFormatWithParam();
411 PrepareSource();
412 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
413
414 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
415 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
416 EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
417 EXPECT_NE(AV_ERR_OK, videoDec_->Flush());
418 }
419
420 /**
421 * @tc.name: videoDecoder_reset_001
422 * @tc.desc: correct flow 1
423 * @tc.type: FUNC
424 */
425 HWTEST_P(VideoDecUnitTest, videoDecoder_reset_001, TestSize.Level1)
426 {
427 CreateByNameWithParam();
428 SetFormatWithParam();
429 PrepareSource();
430 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
431
432 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
433 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
434 EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
435 }
436
437 /**
438 * @tc.name: videoDecoder_reset_002
439 * @tc.desc: correct flow 2
440 * @tc.type: FUNC
441 */
442 HWTEST_P(VideoDecUnitTest, videoDecoder_reset_002, TestSize.Level1)
443 {
444 CreateByNameWithParam();
445 SetFormatWithParam();
446 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
447
448 EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
449 }
450
451 /**
452 * @tc.name: videoDecoder_reset_003
453 * @tc.desc: correct flow 3
454 * @tc.type: FUNC
455 */
456 HWTEST_P(VideoDecUnitTest, videoDecoder_reset_003, TestSize.Level1)
457 {
458 CreateByNameWithParam();
459 SetFormatWithParam();
460 PrepareSource();
461 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
462
463 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
464 EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
465 }
466
467 /**
468 * @tc.name: videoDecoder_release_001
469 * @tc.desc: correct flow 1
470 * @tc.type: FUNC
471 */
472 HWTEST_P(VideoDecUnitTest, videoDecoder_release_001, TestSize.Level1)
473 {
474 CreateByNameWithParam();
475 SetFormatWithParam();
476 PrepareSource();
477 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
478
479 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
480 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
481 EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
482 }
483
484 /**
485 * @tc.name: videoDecoder_release_002
486 * @tc.desc: correct flow 2
487 * @tc.type: FUNC
488 */
489 HWTEST_P(VideoDecUnitTest, videoDecoder_release_002, TestSize.Level1)
490 {
491 CreateByNameWithParam();
492 SetFormatWithParam();
493 PrepareSource();
494 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
495
496 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
497 EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
498 }
499
500 /**
501 * @tc.name: videoDecoder_release_003
502 * @tc.desc: correct flow 3
503 * @tc.type: FUNC
504 */
505 HWTEST_P(VideoDecUnitTest, videoDecoder_release_003, TestSize.Level1)
506 {
507 CreateByNameWithParam();
508 SetFormatWithParam();
509 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
510
511 EXPECT_EQ(AV_ERR_OK, videoDec_->Release());
512 }
513
514 /**
515 * @tc.name: videoDecoder_setsurface_001
516 * @tc.desc: video decodec setsurface
517 * @tc.type: FUNC
518 */
519 HWTEST_P(VideoDecUnitTest, videoDecoder_setsurface_001, TestSize.Level1)
520 {
521 CreateByNameWithParam();
522 SetFormatWithParam();
523 PrepareSource();
524 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
525 ASSERT_EQ(AV_ERR_OK, videoDec_->SetOutputSurface());
526 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
527 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
528 }
529
530 /**
531 * @tc.name: videoDecoder_setsurface_002
532 * @tc.desc: wrong flow 1
533 * @tc.type: FUNC
534 */
535 HWTEST_P(VideoDecUnitTest, videoDecoder_setsurface_002, TestSize.Level1)
536 {
537 CreateByNameWithParam();
538 SetFormatWithParam();
539 PrepareSource();
540 ASSERT_NE(AV_ERR_OK, videoDec_->SetOutputSurface());
541 }
542
543 /**
544 * @tc.name: videoDecoder_setsurface_003
545 * @tc.desc: wrong flow 2
546 * @tc.type: FUNC
547 */
548 HWTEST_P(VideoDecUnitTest, videoDecoder_setsurface_003, TestSize.Level1)
549 {
550 CreateByNameWithParam();
551 SetFormatWithParam();
552 PrepareSource();
553 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
554 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
555 ASSERT_NE(AV_ERR_OK, videoDec_->SetOutputSurface());
556 }
557
558 /**
559 * @tc.name: videoDecoder_abnormal_001
560 * @tc.desc: video codec abnormal func
561 * @tc.type: FUNC
562 */
563 HWTEST_P(VideoDecUnitTest, videoDecoder_abnormal_001, TestSize.Level1)
564 {
565 CreateByNameWithParam();
566 SetFormatWithParam();
567 PrepareSource();
568 format_->PutIntValue(MediaDescriptionKey::MD_KEY_ROTATION_ANGLE, 20); // invalid rotation_angle 20
569 format_->PutIntValue(MediaDescriptionKey::MD_KEY_MAX_INPUT_SIZE, -1); // invalid max input size -1
570
571 videoDec_->Configure(format_);
572 EXPECT_EQ(AV_ERR_OK, videoDec_->Reset());
573 EXPECT_NE(AV_ERR_OK, videoDec_->Start());
574 EXPECT_NE(AV_ERR_OK, videoDec_->Flush());
575 EXPECT_NE(AV_ERR_OK, videoDec_->Stop());
576 }
577
578 /**
579 * @tc.name: videoDecoder_abnormal_002
580 * @tc.desc: video codec abnormal func
581 * @tc.type: FUNC
582 */
583 HWTEST_P(VideoDecUnitTest, videoDecoder_abnormal_002, TestSize.Level1)
584 {
585 CreateByNameWithParam();
586 PrepareSource();
587 EXPECT_NE(AV_ERR_OK, videoDec_->Start());
588 }
589
590 /**
591 * @tc.name: videoDecoder_abnormal_003
592 * @tc.desc: video codec abnormal func
593 * @tc.type: FUNC
594 */
595 HWTEST_P(VideoDecUnitTest, videoDecoder_abnormal_003, TestSize.Level1)
596 {
597 CreateByNameWithParam();
598 PrepareSource();
599 EXPECT_NE(AV_ERR_OK, videoDec_->Flush());
600 }
601
602 /**
603 * @tc.name: videoDecoder_abnormal_004
604 * @tc.desc: video codec abnormal func
605 * @tc.type: FUNC
606 */
607 HWTEST_P(VideoDecUnitTest, videoDecoder_abnormal_004, TestSize.Level1)
608 {
609 CreateByNameWithParam();
610 PrepareSource();
611 EXPECT_NE(AV_ERR_OK, videoDec_->Stop());
612 }
613
614 /**
615 * @tc.name: videoDecoder_setParameter_001
616 * @tc.desc: video codec SetParameter
617 * @tc.type: FUNC
618 */
619 HWTEST_P(VideoDecUnitTest, videoDecoder_setParameter_001, TestSize.Level1)
620 {
621 CreateByNameWithParam();
622 SetFormatWithParam();
623 PrepareSource();
624 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
625
626 format_ = FormatMockFactory::CreateFormat();
627 ASSERT_NE(nullptr, format_);
628
629 format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, DEFAULT_WIDTH);
630 format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, DEFAULT_HEIGHT);
631 format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, YUV420P);
632 format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
633 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
634 EXPECT_EQ(AV_ERR_OK, videoDec_->SetParameter(format_));
635 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
636 }
637
638 /**
639 * @tc.name: videoDecoder_setParameter_002
640 * @tc.desc: video codec SetParameter
641 * @tc.type: FUNC
642 */
643 HWTEST_P(VideoDecUnitTest, videoDecoder_setParameter_002, TestSize.Level1)
644 {
645 CreateByNameWithParam();
646 SetFormatWithParam();
647 PrepareSource();
648 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
649
650 format_ = FormatMockFactory::CreateFormat();
651 ASSERT_NE(nullptr, format_);
652
653 format_->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, -2); // invalid width size -2
654 format_->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, -2); // invalid height size -2
655 format_->PutIntValue(MediaDescriptionKey::MD_KEY_PIXEL_FORMAT, YUV420P);
656 format_->PutIntValue(MediaDescriptionKey::MD_KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
657 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
658 EXPECT_EQ(AV_ERR_OK, videoDec_->SetParameter(format_));
659 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
660 }
661
662 /**
663 * @tc.name: videoDecoder_getOutputDescription_001
664 * @tc.desc: video codec GetOutputDescription
665 * @tc.type: FUNC
666 */
667 HWTEST_P(VideoDecUnitTest, videoDecoder_getOutputDescription_001, TestSize.Level1)
668 {
669 CreateByNameWithParam();
670 SetFormatWithParam();
671 PrepareSource();
672 ASSERT_EQ(AV_ERR_OK, videoDec_->Configure(format_));
673
674 EXPECT_EQ(AV_ERR_OK, videoDec_->Start());
675 format_ = videoDec_->GetOutputDescription();
676 EXPECT_NE(nullptr, format_);
677 EXPECT_EQ(AV_ERR_OK, videoDec_->Stop());
678 }
679 } // namespace