1 /*
2 * Copyright (c) 2024-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 "media_errors.h"
17 #include "hitranscode_unit_test.h"
18 #include "avcodec_info.h"
19 #ifdef SUPPORT_AVPLAYER_DRM
20 #include "imedia_key_session_service.h"
21 #endif
22
23 namespace OHOS {
24 namespace Media {
25 using namespace std;
26 using namespace testing::ext;
27
SetUpTestCase(void)28 void HitranscodeUnitTest::SetUpTestCase(void)
29 {
30 }
31
TearDownTestCase(void)32 void HitranscodeUnitTest::TearDownTestCase(void)
33 {
34 }
35
SetUp(void)36 void HitranscodeUnitTest::SetUp(void)
37 {
38 transcoder_ = std::make_unique<HiTransCoderImpl>(0, 0, 0, 0);
39 transcoder_->Init();
40 }
41
TearDown(void)42 void HitranscodeUnitTest::TearDown(void)
43 {
44 transcoder_ = nullptr;
45 }
46
47 /**
48 * @tc.name : Test ProcessMetaKey API
49 * @tc.number : HitranscodeUnitTest_ProcessMetaKey001
50 * @tc.desc : Test ProcessMetaKey interface, set metaKey to int64_t.
51 * @tc.require : issueI5NZAQ
52 */
53 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey001, TestSize.Level0)
54 {
55 // 1. Set up the test environment
56 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
57 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
58 std::string metaKey = Tag::MEDIA_DURATION;
59 int64_t intVal = 100;
60 innerMeta->SetData(metaKey, intVal);
61
62 // 2. Call the function to be tested
63 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
64
65 // 3. Verify the result
66 EXPECT_TRUE(result);
67 int64_t outputIntVal;
68 EXPECT_TRUE(outputMeta->GetData(metaKey, outputIntVal));
69 EXPECT_EQ(intVal, outputIntVal);
70 }
71
72 /**
73 * @tc.name : Test ProcessMetaKey API
74 * @tc.number : HitranscodeUnitTest_ProcessMetaKey002
75 * @tc.desc : Test ProcessMetaKey interface, set metaKey to std::string.
76 * @tc.require : issueI5NZAQ
77 */
78 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey002, TestSize.Level0)
79 {
80 // 1. Set up the test environment
81 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
82 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
83 std::string metaKey = Tag::MEDIA_ALBUM;
84 std::string strVal = "test";
85 innerMeta->SetData(metaKey, strVal);
86
87 // 2. Call the function to be tested
88 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
89
90 // 3. Verify the result
91 EXPECT_TRUE(result);
92 std::string outputStrVal;
93 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
94 EXPECT_EQ(strVal, outputStrVal);
95 }
96
97 /**
98 * @tc.name : Test ProcessMetaKey API
99 * @tc.number : HitranscodeUnitTest_ProcessMetaKey003
100 * @tc.desc : Test ProcessMetaKey interface, set metaKey to int32_t.
101 * @tc.require :
102 */
103 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey003, TestSize.Level0)
104 {
105 // 1. Set up the test environment
106 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
107 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
108 std::string metaKey = Tag::VIDEO_HEIGHT;
109 int32_t intVal = 100;
110 innerMeta->SetData(metaKey, intVal);
111
112 // 2. Call the function to be tested
113 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
114
115 // 3. Verify the result
116 EXPECT_TRUE(result);
117 int32_t outputStrVal;
118 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
119 EXPECT_EQ(intVal, outputStrVal);
120 }
121
122 /**
123 * @tc.name : Test ProcessMetaKey API
124 * @tc.number : HitranscodeUnitTest_ProcessMetaKey004
125 * @tc.desc : Test ProcessMetaKey interface, set metaKey to double.
126 * @tc.require :
127 */
128 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey004, TestSize.Level0)
129 {
130 // 1. Set up the test environment
131 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
132 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
133 std::string metaKey = Tag::VIDEO_CAPTURE_RATE;
134 double doubleVal = 0.1;
135 innerMeta->SetData(metaKey, doubleVal);
136
137 // 2. Call the function to be tested
138 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
139
140 // 3. Verify the result
141 EXPECT_TRUE(result);
142 double outputStrVal;
143 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
144 EXPECT_EQ(doubleVal, outputStrVal);
145 }
146
147 /**
148 * @tc.name : Test ProcessMetaKey API
149 * @tc.number : HitranscodeUnitTest_ProcessMetaKey005
150 * @tc.desc : Test ProcessMetaKey interface, set metaKey to Plugins::VideoRotation.
151 * @tc.require :
152 */
153 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey005, TestSize.Level0)
154 {
155 // 1. Set up the test environment
156 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
157 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
158 std::string metaKey = Tag::VIDEO_ROTATION;
159 Plugins::VideoRotation rotation = Plugins::VideoRotation::VIDEO_ROTATION_0;
160 innerMeta->SetData(metaKey, rotation);
161
162 // 2. Call the function to be tested
163 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
164
165 // 3. Verify the result
166 EXPECT_TRUE(result);
167 Plugins::VideoRotation outputStrVal;
168 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
169 EXPECT_EQ(rotation, outputStrVal);
170 }
171
172 /**
173 * @tc.name : Test ProcessMetaKey API
174 * @tc.number : HitranscodeUnitTest_ProcessMetaKey006
175 * @tc.desc : Test ProcessMetaKey interface, set metaKey to bool.
176 * @tc.require :
177 */
178 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey006, TestSize.Level0)
179 {
180 // 1. Set up the test environment
181 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
182 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
183 std::string metaKey = Tag::VIDEO_COLOR_RANGE;
184 bool boolVal = true;
185 innerMeta->SetData(metaKey, boolVal);
186
187 // 2. Call the function to be tested
188 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
189
190 // 3. Verify the result
191 EXPECT_TRUE(result);
192 bool outputStrVal;
193 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
194 EXPECT_EQ(boolVal, outputStrVal);
195 }
196
197 /**
198 * @tc.name : Test ProcessMetaKey API
199 * @tc.number : HitranscodeUnitTest_ProcessMetaKey007
200 * @tc.desc : Test ProcessMetaKey interface, set metaKey to float.
201 * @tc.require :
202 */
203 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey007, TestSize.Level0)
204 {
205 // 1. Set up the test environment
206 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
207 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
208 std::string metaKey = Tag::MEDIA_LATITUDE;
209 float floatVal = 0.9;
210 innerMeta->SetData(metaKey, floatVal);
211
212 // 2. Call the function to be tested
213 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
214
215 // 3. Verify the result
216 EXPECT_TRUE(result);
217 float outputStrVal;
218 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
219 EXPECT_EQ(floatVal, outputStrVal);
220 }
221
222 /**
223 * @tc.name : Test SetValueByType API
224 * @tc.number : SetValueByType_001
225 * @tc.desc : Test SetValueByType interface, set innerMeta or outputMeta to nullptr.
226 * @tc.require : issueI5NZAQ
227 */
228 HWTEST_F(HitranscodeUnitTest, SetValueByType_001, TestSize.Level0)
229 {
230 // 1. Set up the test environment
231 std::shared_ptr<Meta> innerMeta = nullptr;
232 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
233
234 // 2. Call the function to be tested
235 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
236
237 // 3. Verify the result
238 EXPECT_FALSE(result);
239 }
240
241 /**
242 * @tc.name : Test SetValueByType API
243 * @tc.number : SetValueByType_002
244 * @tc.desc : Test SetValueByType interface, set both innerMeta and outputMeta to nullptr.
245 * @tc.require : issueI5NZAQ
246 */
247 HWTEST_F(HitranscodeUnitTest, SetValueByType_002, TestSize.Level0)
248 {
249 // 1. Set up the test environment
250 std::shared_ptr<Meta> innerMeta = nullptr;
251 std::shared_ptr<Meta> outputMeta = nullptr;
252
253 // 2. Call the function to be tested
254 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
255
256 // 3. Verify the result
257 EXPECT_FALSE(result);
258 }
259
260 /**
261 * @tc.name : Test SetValueByType API
262 * @tc.number : SetValueByType_003
263 * @tc.desc : Test SetValueByType interface, set valid innerMeta and outputMeta.
264 * @tc.require : issueI5NZAQ
265 */
266 HWTEST_F(HitranscodeUnitTest, SetValueByType_003, TestSize.Level0)
267 {
268 // 1. Set up the test environment
269 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
270 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
271 std::string metaKey = Tag::MEDIA_DURATION;
272 int64_t intVal = 100;
273 innerMeta->SetData(metaKey, intVal);
274
275 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
276
277 EXPECT_TRUE(result);
278 }
279
280 /**
281 * @tc.name : Test ConfigureVideoAudioMetaData API
282 * @tc.number : ConfigureVideoAudioMetaData_001
283 * @tc.desc : Test ConfigureVideoAudioMetaData interface, set demuxerFilter_ nulllptr.
284 * @tc.require :
285 */
286 HWTEST_F(HitranscodeUnitTest, ConfigureVideoAudioMetaData_001, TestSize.Level0)
287 {
288 transcoder_->demuxerFilter_ = nullptr;
289 Status result = transcoder_->ConfigureVideoAudioMetaData();
290 EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
291 }
292
293 /**
294 * @tc.name : Test Prepare API
295 * @tc.number : Prepare_001
296 * @tc.desc : Test Prepare interface, dont set width and height.
297 * @tc.require :
298 */
299 HWTEST_F(HitranscodeUnitTest, Prepare_001, TestSize.Level0)
300 {
301 transcoder_->isExistVideoTrack_ = true;
302 int32_t ret = transcoder_->Prepare();
303 EXPECT_EQ(ret, MSERR_INVALID_VAL);
304 }
305
306 /**
307 * @tc.name : Test Prepare API
308 * @tc.number : Prepare_002
309 * @tc.desc : Test Prepare interface, dont set height.
310 * @tc.require :
311 */
312 HWTEST_F(HitranscodeUnitTest, Prepare_002, TestSize.Level0)
313 {
314 transcoder_->isExistVideoTrack_ = true;
315 std::string metaKey = Tag::VIDEO_WIDTH;
316 int32_t width = 0;
317 transcoder_->videoEncFormat_->SetData(metaKey, width);
318 int32_t ret = transcoder_->Prepare();
319 EXPECT_EQ(ret, MSERR_INVALID_VAL);
320 }
321
322 /**
323 * @tc.name : Test Prepare API
324 * @tc.number : Prepare_003
325 * @tc.desc : Test Prepare interface, dont set width.
326 * @tc.require :
327 */
328 HWTEST_F(HitranscodeUnitTest, Prepare_003, TestSize.Level0)
329 {
330 transcoder_->isExistVideoTrack_ = true;
331 std::string metaKey = Tag::VIDEO_HEIGHT;
332 int32_t height = 0;
333 transcoder_->videoEncFormat_->SetData(metaKey, height);
334 int32_t ret = transcoder_->Prepare();
335 EXPECT_EQ(ret, MSERR_INVALID_VAL);
336 }
337
338 /**
339 * @tc.name : Test Prepare API
340 * @tc.number : Prepare_004
341 * @tc.desc : Test Prepare interface, set all and the condition is 001.
342 * @tc.require :
343 */
344 HWTEST_F(HitranscodeUnitTest, Prepare_004, TestSize.Level0)
345 {
346 transcoder_->isExistVideoTrack_ = true;
347 std::string widthMetaKey = Tag::VIDEO_WIDTH;
348 int32_t width = 100;
349 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
350 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
351 int32_t height = 100;
352 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
353 transcoder_->inputVideoWidth_ = 200;
354 transcoder_->inputVideoHeight_ =200;
355 int32_t ret = transcoder_->Prepare();
356 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
357 }
358
359 /**
360 * @tc.name : Test Prepare API
361 * @tc.number : Prepare_005
362 * @tc.desc : Test Prepare interface, set all and the condition is 010.
363 * @tc.require :
364 */
365 HWTEST_F(HitranscodeUnitTest, Prepare_005, TestSize.Level0)
366 {
367 transcoder_->isExistVideoTrack_ = true;
368 std::string widthMetaKey = Tag::VIDEO_WIDTH;
369 int32_t width = 480;
370 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
371 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
372 int32_t height = 640;
373 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
374 transcoder_->inputVideoWidth_ = 640;
375 transcoder_->inputVideoHeight_ = 480;
376 int32_t ret = transcoder_->Prepare();
377 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
378 }
379
380 /**
381 * @tc.name : Test Prepare API
382 * @tc.number : Prepare_006
383 * @tc.desc : Test Prepare interface, set all and the condition is 011.
384 * @tc.require :
385 */
386 HWTEST_F(HitranscodeUnitTest, Prepare_006, TestSize.Level0)
387 {
388 transcoder_->isExistVideoTrack_ = true;
389 std::string widthMetaKey = Tag::VIDEO_WIDTH;
390 int32_t width = 100;
391 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
392 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
393 int32_t height = 100;
394 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
395 transcoder_->inputVideoWidth_ = 200;
396 transcoder_->inputVideoHeight_ = 50;
397 int32_t ret = transcoder_->Prepare();
398 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
399 }
400
401 /**
402 * @tc.name : Test Prepare API
403 * @tc.number : Prepare_007
404 * @tc.desc : Test Prepare interface, set all and the condition is 100.
405 * @tc.require :
406 */
407 HWTEST_F(HitranscodeUnitTest, Prepare_007, TestSize.Level0)
408 {
409 transcoder_->isExistVideoTrack_ = true;
410 std::string widthMetaKey = Tag::VIDEO_WIDTH;
411 int32_t width = 640;
412 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
413 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
414 int32_t height = 480;
415 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
416 transcoder_->inputVideoWidth_ = 480;
417 transcoder_->inputVideoHeight_ = 640;
418 int32_t ret = transcoder_->Prepare();
419 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
420 }
421
422 /**
423 * @tc.name : Test Prepare API
424 * @tc.number : Prepare_008
425 * @tc.desc : Test Prepare interface, set all and the condition is 101.
426 * @tc.require :
427 */
428 HWTEST_F(HitranscodeUnitTest, Prepare_008, TestSize.Level0)
429 {
430 transcoder_->isExistVideoTrack_ = true;
431 std::string widhtMetaKey = Tag::VIDEO_WIDTH;
432 int32_t width = 100;
433 transcoder_->videoEncFormat_->SetData(widhtMetaKey, width);
434 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
435 int32_t height = 480;
436 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
437 transcoder_->inputVideoWidth_ = 50;
438 transcoder_->inputVideoHeight_ = 640;
439 int32_t ret = transcoder_->Prepare();
440 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
441 }
442
443 /**
444 * @tc.name : Test Prepare API
445 * @tc.number : Prepare_009
446 * @tc.desc : Test Prepare interface, set all and the condition is 110.
447 * @tc.require :
448 */
449 HWTEST_F(HitranscodeUnitTest, Prepare_009, TestSize.Level0)
450 {
451 transcoder_->isExistVideoTrack_ = true;
452 std::string widthMetaKey = Tag::VIDEO_WIDTH;
453 int32_t width = 640;
454 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
455 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
456 int32_t height = 640;
457 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
458 transcoder_->inputVideoWidth_ = 480;
459 transcoder_->inputVideoHeight_ = 480;
460 int32_t ret = transcoder_->Prepare();
461 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
462 }
463
464 /**
465 * @tc.name : Test Prepare API
466 * @tc.number : Prepare_010
467 * @tc.desc : Test Prepare interface, set all and the condition is 111.
468 * @tc.require :
469 */
470 HWTEST_F(HitranscodeUnitTest, Prepare_010, TestSize.Level0)
471 {
472 transcoder_->isExistVideoTrack_ = true;
473 std::string widthMetaKey = Tag::VIDEO_WIDTH;
474 int32_t width = 100;
475 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
476 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
477 int32_t height = 100;
478 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
479 transcoder_->inputVideoWidth_ = 50;
480 transcoder_->inputVideoHeight_ = 50;
481 int32_t ret = transcoder_->Prepare();
482 EXPECT_EQ(ret, MSERR_PARAMETER_VERIFICATION_FAILED);
483 }
484
485 /**
486 * @tc.name : Test Prepare API
487 * @tc.number : Prepare_011
488 * @tc.desc : Test Prepare interface.
489 * @tc.require :
490 */
491 HWTEST_F(HitranscodeUnitTest, Prepare_011, TestSize.Level0)
492 {
493 transcoder_->isExistVideoTrack_ = true;
494 std::string widthMetaKey = Tag::VIDEO_WIDTH;
495 int32_t width = 480;
496 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
497 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
498 int32_t height = 480;
499 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
500 transcoder_->inputVideoWidth_ = 640;
501 transcoder_->inputVideoHeight_ = 640;
502 int32_t ret = transcoder_->Prepare();
503 EXPECT_EQ(ret, MSERR_UNKNOWN);
504 }
505
506 /**
507 * @tc.name : Test GetRealPath API
508 * @tc.number : GetRealPath_001
509 * @tc.desc : Test GetRealPath interface, set url to "file://".
510 * @tc.require :
511 */
512 HWTEST_F(HitranscodeUnitTest, GetRealPath_001, TestSize.Level0)
513 {
514 // 1. Set up the test environment
515 std::string url = "file://";
516 std::string realUrlPath;
517
518 // 2. Call the function to be tested
519 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
520
521 // 3. Verify the result
522 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
523 }
524
525 /**
526 * @tc.name : Test GetRealPath API
527 * @tc.number : GetRealPath_002
528 * @tc.desc : Test GetRealPath interface, set url to "file".
529 * @tc.require :
530 */
531 HWTEST_F(HitranscodeUnitTest, GetRealPath_002, TestSize.Level0)
532 {
533 // 1. Set up the test environment
534 std::string url = "file";
535 std::string realUrlPath;
536
537 // 2. Call the function to be tested
538 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
539
540 // 3. Verify the result
541 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
542 }
543
544 /**
545 * @tc.name : Test GetRealPath API
546 * @tc.number : GetRealPath_003
547 * @tc.desc : Test GetRealPath interface, set url to "file:///storage/../test.mp3".
548 * @tc.require :
549 */
550 HWTEST_F(HitranscodeUnitTest, GetRealPath_003, TestSize.Level0)
551 {
552 // 1. Set up the test environment
553 std::string url = "file:///storage/../test.mp3";
554 std::string realUrlPath;
555
556 // 2. Call the function to be tested
557 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
558
559 // 3. Verify the result
560 EXPECT_EQ(ret, MSERR_FILE_ACCESS_FAILED);
561 }
562
563 /**
564 * @tc.name : Test ProcessMetaKey API
565 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_008
566 * @tc.desc : Test ProcessMetaKey interface, dont set int64_t to innerMeta.
567 * @tc.require :
568 */
569 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_008, TestSize.Level0)
570 {
571 // 1. Set up the test environment
572 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
573 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
574 std::string metaKey = Tag::MEDIA_DURATION;
575
576 // 2. Call the function to be tested
577 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
578
579 // 3. Verify the result
580 EXPECT_TRUE(result);
581 int64_t outputIntVal;
582 EXPECT_FALSE(outputMeta->GetData(metaKey, outputIntVal));
583 }
584
585 /**
586 * @tc.name : Test ProcessMetaKey API
587 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_009
588 * @tc.desc : Test ProcessMetaKey interface, dont set string to innerMeta.
589 * @tc.require : issueI5NZAQ
590 */
591 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_009, TestSize.Level0)
592 {
593 // 1. Set up the test environment
594 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
595 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
596 std::string metaKey = Tag::MEDIA_ALBUM;
597
598 // 2. Call the function to be tested
599 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
600
601 // 3. Verify the result
602 EXPECT_TRUE(result);
603 std::string outputStrVal;
604 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
605 }
606
607 /**
608 * @tc.name : Test ProcessMetaKey API
609 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_010
610 * @tc.desc : Test ProcessMetaKey interface, dont set int32_t to innerMeta.
611 * @tc.require :
612 */
613 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_010, TestSize.Level0)
614 {
615 // 1. Set up the test environment
616 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
617 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
618 std::string metaKey = Tag::VIDEO_HEIGHT;
619
620 // 2. Call the function to be tested
621 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
622
623 // 3. Verify the result
624 EXPECT_TRUE(result);
625 int32_t outputStrVal;
626 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
627 }
628
629 /**
630 * @tc.name : Test ProcessMetaKey API
631 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_011
632 * @tc.desc : Test ProcessMetaKey interface, dont set double to innerMeta.
633 * @tc.require :
634 */
635 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_011, TestSize.Level0)
636 {
637 // 1. Set up the test environment
638 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
639 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
640 std::string metaKey = Tag::VIDEO_CAPTURE_RATE;
641
642 // 2. Call the function to be tested
643 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
644
645 // 3. Verify the result
646 EXPECT_TRUE(result);
647 double outputStrVal;
648 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
649 }
650
651 /**
652 * @tc.name : Test ProcessMetaKey API
653 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_012
654 * @tc.desc : Test ProcessMetaKey interface, dont set Plugins::VideoRotation to innerMeta.
655 * @tc.require :
656 */
657 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_012, TestSize.Level0)
658 {
659 // 1. Set up the test environment
660 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
661 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
662 std::string metaKey = Tag::VIDEO_ROTATION;
663
664 // 2. Call the function to be tested
665 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
666
667 // 3. Verify the result
668 EXPECT_TRUE(result);
669 Plugins::VideoRotation outputStrVal;
670 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
671 }
672
673 /**
674 * @tc.name : Test ProcessMetaKey API
675 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_013
676 * @tc.desc : Test ProcessMetaKey interface, dont set bool to innerMeta.
677 * @tc.require :
678 */
679 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_013, TestSize.Level0)
680 {
681 // 1. Set up the test environment
682 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
683 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
684 std::string metaKey = Tag::VIDEO_COLOR_RANGE;
685
686 // 2. Call the function to be tested
687 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
688
689 // 3. Verify the result
690 EXPECT_TRUE(result);
691 bool outputStrVal;
692 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
693 }
694
695 /**
696 * @tc.name : Test ProcessMetaKey API
697 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_014
698 * @tc.desc : Test ProcessMetaKey interface, dont set float to innerMeta.
699 * @tc.require :
700 */
701 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_014, TestSize.Level0)
702 {
703 // 1. Set up the test environment
704 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
705 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
706 std::string metaKey = Tag::MEDIA_LATITUDE;
707
708 // 2. Call the function to be tested
709 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
710
711 // 3. Verify the result
712 EXPECT_TRUE(result);
713 float outputStrVal;
714 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
715 }
716
717 /**
718 * @tc.name: Test SetInputFile API
719 * @tc.number : SetInputFile_001
720 * @tc.desc: Test GetRealPath interface, set url to "file:///storage/../test.mp3".
721 * @tc.require:
722 */
723 HWTEST_F(HitranscodeUnitTest, SetInputFile_001, TestSize.Level0)
724 {
725 // 1. Set up the test environment
726 std::string url = "file:///storage/../test.mp3";
727
728 // 2. Call the function to be tested
729 int32_t ret = transcoder_->SetInputFile(url);
730
731 // 3. Verify the result
732 EXPECT_EQ(ret, MSERR_FILE_ACCESS_FAILED);
733 }
734
735 /**
736 * @tc.name: Test SetInputFile API
737 * @tc.number : SetInputFile_002
738 * @tc.desc: Test GetRealPath interface, set url to "file".
739 * @tc.require:
740 */
741 HWTEST_F(HitranscodeUnitTest, SetInputFile_002, TestSize.Level0)
742 {
743 // 1. Set up the test environment
744 std::string url = "file";
745
746 std::string realUrlPath;
747
748 // 2. Call the function to be tested
749 int32_t ret = transcoder_->SetInputFile(url);
750
751 // 3. Verify the result
752 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
753 }
754
755 /**
756 * @tc.name: Test SetInputFile API
757 * @tc.number : SetInputFile_003
758 * @tc.desc: Test GetRealPath interface, set url to "file://".
759 * @tc.require:
760 */
761 HWTEST_F(HitranscodeUnitTest, SetInputFile_003, TestSize.Level0)
762 {
763 // 1. Set up the test environment
764 std::string url = "file://";
765 std::string realUrlPath;
766
767 // 2. Call the function to be tested
768 int32_t ret = transcoder_->SetInputFile(url);
769
770 // 3. Verify the result
771 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
772 }
773
774 /**
775 * @tc.name : Test ConfigureVideoEncoderFormat API
776 * @tc.number : ConfigureVideoEncoderFormat_001
777 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::H264.
778 * @tc.require :
779 */
780 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_001, TestSize.Level0)
781 {
782 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::H264);
783 transcoder_->ConfigureVideoEncoderFormat(videoEnc);
784
785 std::string metaKey = Tag::MIME_TYPE;
786 std::string strVal = "video/avc";
787 std::string outputStrVal;
788 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
789 EXPECT_EQ(strVal, outputStrVal);
790
791 metaKey = Tag::VIDEO_H264_PROFILE;
792 VideoH264Profile intVal = Plugins::VideoH264Profile::BASELINE;
793 VideoH264Profile outputIntVal;
794 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputIntVal));
795 EXPECT_EQ(intVal, outputIntVal);
796
797 metaKey = Tag::VIDEO_H264_LEVEL;
798 int32_t intVal2 = 32;
799 int32_t outputIntVal2;
800 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputIntVal2));
801 EXPECT_EQ(intVal2, outputIntVal2);
802 }
803
804 /**
805 * @tc.name : Test ConfigureVideoEncoderFormat API
806 * @tc.number : ConfigureVideoEncoderFormat_002
807 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::MPEG4.
808 * @tc.require :
809 */
810 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_002, TestSize.Level0)
811 {
812 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::MPEG4);
813 transcoder_->ConfigureVideoEncoderFormat(videoEnc);
814
815 std::string metaKey = Tag::MIME_TYPE;
816 std::string strVal = "video/mp4v-es";
817 std::string outputStrVal;
818 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
819 EXPECT_EQ(strVal, outputStrVal);
820 }
821
822 /**
823 * @tc.name : Test ConfigureVideoEncoderFormat API
824 * @tc.number : ConfigureVideoEncoderFormat_003
825 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::H265.
826 * @tc.require :
827 */
828 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_003, TestSize.Level0)
829 {
830 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::H265);
831 transcoder_->ConfigureVideoEncoderFormat(videoEnc);
832
833 std::string metaKey = Tag::MIME_TYPE;
834 std::string strVal = "video/hevc";
835 std::string outputStrVal;
836 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
837 EXPECT_EQ(strVal, outputStrVal);
838 }
839
840 /**
841 * @tc.name : Test ConfigureVideoEncoderFormat API
842 * @tc.number : ConfigureVideoEncoderFormat_004
843 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::VIDEO_DEFAULT.
844 * @tc.require :
845 */
846 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_004, TestSize.Level0)
847 {
848 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::VIDEO_DEFAULT);
849 transcoder_->ConfigureVideoEncoderFormat(videoEnc);
850
851 std::string metaKey = Tag::MIME_TYPE;
852 std::string outputStrVal;
853 EXPECT_FALSE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
854 }
855
856 /**
857 * @tc.name : Test AppendSrcMediaInfo API
858 * @tc.number : AppendSrcMediaInfo_001
859 * @tc.desc : Test AppendSrcMediaInfo interface.
860 * @tc.require :
861 */
862 HWTEST_F(HitranscodeUnitTest, AppendSrcMediaInfo_001, TestSize.Level0)
863 {
864 std::shared_ptr<Meta> inputMeta = std::make_shared<Meta>();
865 std::shared_ptr<Meta> srcVideoFormat_ = std::make_shared<Meta>();
866 std::shared_ptr<Meta> srcAudioFormat_ = std::make_shared<Meta>();
867 std::string metaKey = Tag::MEDIA_TYPE;
868 Plugins::MediaType mediaType = Plugins::MediaType::AUDIO;
869 transcoder_->srcAudioFormat_->SetData(metaKey, mediaType);
870
871 mediaType = Plugins::MediaType::VIDEO;
872 transcoder_->srcVideoFormat_->SetData(metaKey, mediaType);
873
874 int64_t srcVideoBitrate = 640;
875 transcoder_->srcVideoFormat_->SetData(Tag::MEDIA_BITRATE, srcVideoBitrate);
876
877 transcoder_->srcVideoFormat_->SetData(Tag::VIDEO_IS_HDR_VIVID, true);
878 EXPECT_TRUE(inputMeta != nullptr);
879 transcoder_->AppendSrcMediaInfo(inputMeta);
880 int32_t isHdrVivid_;
881 inputMeta->GetData(Tag::AV_TRANSCODER_SRC_HDR_TYPE, isHdrVivid_);
882 EXPECT_EQ(isHdrVivid_, 1);
883 int32_t srcVideoBitrate_;
884 inputMeta->GetData(Tag::AV_TRANSCODER_SRC_VIDEO_BITRATE, srcVideoBitrate_);
885 EXPECT_EQ(srcVideoBitrate_, srcVideoBitrate);
886 }
887
888 /**
889 * @tc.name : Test ConfigureVideoBitrate API
890 * @tc.number : ConfigureVideoBitrate_001
891 * @tc.desc : Test ConfigureVideoBitrate interface.
892 * @tc.require :
893 */
894 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_001, TestSize.Level0)
895 {
896 transcoder_->isExistVideoTrack_ = true;
897 std::string metaKey = Tag::VIDEO_WIDTH;
898 int32_t width = 1100;
899 transcoder_->videoEncFormat_->SetData(metaKey, width);
900
901 int32_t height = 1100;
902 metaKey = Tag::VIDEO_HEIGHT;
903 transcoder_->videoEncFormat_->SetData(metaKey, height);
904 Status ret = transcoder_->ConfigureVideoBitrate();
905 EXPECT_EQ(ret, Status::OK);
906 }
907
908 /**
909 * @tc.name : Test ConfigureVideoBitrate API
910 * @tc.number : ConfigureVideoBitrate_002
911 * @tc.desc : Test ConfigureVideoBitrate interface.
912 * @tc.require :
913 */
914 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_002, TestSize.Level0)
915 {
916 transcoder_->isExistVideoTrack_ = true;
917 std::string metaKey = Tag::VIDEO_WIDTH;
918 int32_t width = 800;
919 transcoder_->videoEncFormat_->SetData(metaKey, width);
920
921 int32_t height = 800;
922 metaKey = Tag::VIDEO_HEIGHT;
923 transcoder_->videoEncFormat_->SetData(metaKey, height);
924 auto ret = transcoder_->ConfigureVideoBitrate();
925 EXPECT_EQ(ret, Status::OK);
926 }
927
928 /**
929 * @tc.name : Test ConfigureVideoBitrate API
930 * @tc.number : ConfigureVideoBitrate_003
931 * @tc.desc : Test ConfigureVideoBitrate interface.
932 * @tc.require :
933 */
934 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_003, TestSize.Level0)
935 {
936 transcoder_->isExistVideoTrack_ = true;
937 std::string metaKey = Tag::VIDEO_WIDTH;
938 int32_t width = 500;
939 transcoder_->videoEncFormat_->SetData(metaKey, width);
940
941 int32_t height = 500;
942 metaKey = Tag::VIDEO_HEIGHT;
943 transcoder_->videoEncFormat_->SetData(metaKey, height);
944 auto ret = transcoder_->ConfigureVideoBitrate();
945 EXPECT_EQ(ret, Status::OK);
946 }
947
948 /**
949 * @tc.name : Test ConfigureVideoWidthHeight API
950 * @tc.number : ConfigureVideoWidthHeight_001
951 * @tc.desc : Test ConfigureVideoWidthHeight.
952 * @tc.require :
953 */
954 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_001, TestSize.Level0)
955 {
956 VideoRectangle videoRectangle(1920, 1080);
957 transcoder_->ConfigureVideoWidthHeight(videoRectangle);
958 int32_t width = -1;
959 int32_t height = -1;
960 transcoder_->videoEncFormat_->Get<Tag::VIDEO_WIDTH>(width);
961 transcoder_->videoEncFormat_->Get<Tag::VIDEO_HEIGHT>(height);
962 EXPECT_EQ(width, 1920);
963 EXPECT_EQ(height, 1080);
964 }
965
966 /**
967 * @tc.name : Test ConfigureVideoWidthHeight API
968 * @tc.number : ConfigureVideoWidthHeight_002
969 * @tc.desc : Test ConfigureVideoWidthHeight.
970 * @tc.require :
971 */
972 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_002, TestSize.Level0)
973 {
974 transcoder_->videoEncFormat_->Set<Tag::VIDEO_WIDTH>(240);
975 transcoder_->videoEncFormat_->Set<Tag::VIDEO_HEIGHT>(240);
976 VideoRectangle videoRectangle(-1, -1);
977 transcoder_->ConfigureVideoWidthHeight(videoRectangle);
978 int32_t width = -1;
979 int32_t height = -1;
980 transcoder_->videoEncFormat_->Get<Tag::VIDEO_WIDTH>(width);
981 transcoder_->videoEncFormat_->Get<Tag::VIDEO_HEIGHT>(height);
982 EXPECT_EQ(width, 240);
983 EXPECT_EQ(height, 240);
984 }
985
986 /**
987 * @tc.name : Test ConfigureVideoWidthHeight API
988 * @tc.number : ConfigureVideoWidthHeight_003
989 * @tc.desc : Test ConfigureVideoWidthHeight.
990 * @tc.require :
991 */
992 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_003, TestSize.Level0)
993 {
994 transcoder_->videoEncFormat_->Set<Tag::VIDEO_WIDTH>(240);
995 transcoder_->videoEncFormat_->Set<Tag::VIDEO_HEIGHT>(240);
996 VideoRectangle videoRectangle(1920, -1);
997 transcoder_->ConfigureVideoWidthHeight(videoRectangle);
998 int32_t width = -1;
999 int32_t height = -1;
1000 transcoder_->videoEncFormat_->Get<Tag::VIDEO_WIDTH>(width);
1001 transcoder_->videoEncFormat_->Get<Tag::VIDEO_HEIGHT>(height);
1002 EXPECT_EQ(width, 1920);
1003 EXPECT_EQ(height, 240);
1004 }
1005
1006 /**
1007 * @tc.name : Test ConfigureVideoWidthHeight API
1008 * @tc.number : ConfigureVideoWidthHeight_004
1009 * @tc.desc : Test ConfigureVideoWidthHeight.
1010 * @tc.require :
1011 */
1012 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_004, TestSize.Level0)
1013 {
1014 transcoder_->videoEncFormat_->Set<Tag::VIDEO_WIDTH>(240);
1015 transcoder_->videoEncFormat_->Set<Tag::VIDEO_HEIGHT>(240);
1016 VideoRectangle videoRectangle(-1, 1080);
1017 transcoder_->ConfigureVideoWidthHeight(videoRectangle);
1018 int32_t width = -1;
1019 int32_t height = -1;
1020 transcoder_->videoEncFormat_->Get<Tag::VIDEO_WIDTH>(width);
1021 transcoder_->videoEncFormat_->Get<Tag::VIDEO_HEIGHT>(height);
1022 EXPECT_EQ(width, 240);
1023 EXPECT_EQ(height, 1080);
1024 }
1025
1026 /**
1027 * @tc.name : Test ConfigureColorSpace API
1028 * @tc.number : ConfigureColorSpace_001
1029 * @tc.desc : Test ConfigureColorSpace.
1030 * @tc.require :
1031 */
1032 HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_001, TestSize.Level0)
1033 {
1034 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL);
1035 Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt);
1036 EXPECT_EQ(ret, Status::OK);
1037 }
1038
1039 /**
1040 * @tc.name : Test ConfigureColorSpace API
1041 * @tc.number : ConfigureColorSpace_002
1042 * @tc.desc : Test ConfigureColorSpace.
1043 * @tc.require :
1044 */
1045 HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_002, TestSize.Level0)
1046 {
1047 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT);
1048 Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt);
1049 EXPECT_EQ(ret, Status::OK);
1050 }
1051
1052 /**
1053 * @tc.name : Test ConfigureColorSpace API
1054 * @tc.number : ConfigureColorSpace_003
1055 * @tc.desc : Test ConfigureColorSpace.
1056 * @tc.require :
1057 */
1058 HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_003, TestSize.Level0)
1059 {
1060 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_NONE);
1061 Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt);
1062 EXPECT_EQ(ret, Status::ERROR_INVALID_PARAMETER);
1063 }
1064
1065 /**
1066 * @tc.name : Test ConfigureColorSpace API
1067 * @tc.number : ConfigureColorSpace_004
1068 * @tc.desc : Test ConfigureColorSpace.
1069 * @tc.require :
1070 */
1071 HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_004, TestSize.Level0)
1072 {
1073 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT601_EBU_FULL);
1074 Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt);
1075 EXPECT_EQ(ret, Status::OK);
1076 }
1077
1078 /**
1079 * @tc.name : Test ConfigureColorSpace API
1080 * @tc.number : ConfigureColorSpace_005
1081 * @tc.desc : Test ConfigureColorSpace.
1082 * @tc.require :
1083 */
1084 HWTEST_F(HitranscodeUnitTest, ConfigureColorSpace_005, TestSize.Level0)
1085 {
1086 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_DISPLAY_BT2020_HLG);
1087 Status ret = transcoder_->ConfigureColorSpace(videoColSpaFmt);
1088 EXPECT_EQ(ret, Status::OK);
1089 }
1090
1091 /**
1092 * @tc.name : Test ConfigureMetaDataToTrackFormat
1093 * @tc.number : ConfigureMetaDataToTrackFormat_001
1094 * @tc.desc : Test ConfigureMetaDataToTrackFormat
1095 * @tc.require :
1096 */
1097 HWTEST_F(HitranscodeUnitTest, ConfigureMetaDataToTrackFormat_001, TestSize.Level0)
1098 {
1099 std::shared_ptr<Meta> globalInfo = std::make_shared<Meta>();
1100 std::vector<std::shared_ptr<Meta>> trackInfos;
1101 trackInfos.push_back(std::make_shared<Meta>());
1102 transcoder_->ConfigureMetaDataToTrackFormat(globalInfo, trackInfos);
1103
1104 trackInfos.clear();
1105 std::shared_ptr<Meta> audioFirstTrack = std::make_shared<Meta>();
1106 audioFirstTrack->Set<Tag::MIME_TYPE>(Plugins::MimeType::AUDIO_AAC);
1107 trackInfos.push_back(audioFirstTrack);
1108 transcoder_->ConfigureMetaDataToTrackFormat(globalInfo, trackInfos);
1109 std::string audioMime;
1110 transcoder_->audioEncFormat_->GetData(Tag::MIME_TYPE, audioMime);
1111 EXPECT_EQ(audioMime, Plugins::MimeType::AUDIO_AAC);
1112
1113 std::shared_ptr<Meta> audioSecondTrack = std::make_shared<Meta>();
1114 audioSecondTrack->Set<Tag::MIME_TYPE>(Plugins::MimeType::AUDIO_RAW);
1115 trackInfos.push_back(audioSecondTrack);
1116 transcoder_->ConfigureMetaDataToTrackFormat(globalInfo, trackInfos);
1117 transcoder_->audioEncFormat_->GetData(Tag::MIME_TYPE, audioMime);
1118 EXPECT_EQ(audioMime, Plugins::MimeType::AUDIO_AAC);
1119 trackInfos.clear();
1120 }
1121
1122 /**
1123 * @tc.name : Test Configure
1124 * @tc.number : Configure_001
1125 * @tc.desc : Test Configure
1126 * @tc.require :
1127 */
1128 HWTEST_F(HitranscodeUnitTest, Configure_001, TestSize.Level0)
1129 {
1130 VideoBitRate videoBitRate(0);
1131 int32_t ret = transcoder_->Configure(videoBitRate);
1132 EXPECT_EQ(ret, MSERR_OK);
1133
1134 AudioBitRate audioBitRate(0);
1135 ret = transcoder_->Configure(audioBitRate);
1136 EXPECT_EQ(ret, MSERR_INVALID_VAL);
1137
1138 std::string url;
1139 InputUrl inputUrl(url);
1140 ret = transcoder_->Configure(inputUrl);
1141 EXPECT_EQ(ret, MSERR_OK);
1142 }
1143
1144 /**
1145 * @tc.name : Test Configure
1146 * @tc.number : Configure_002
1147 * @tc.desc : Test Configure
1148 * @tc.require :
1149 */
1150 HWTEST_F(HitranscodeUnitTest, Configure_002, TestSize.Level0)
1151 {
1152 VideoRectangle videoRectangle(1280, 720);
1153 int32_t ret = transcoder_->Configure(videoRectangle);
1154 EXPECT_EQ(ret, MSERR_OK);
1155
1156 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT);
1157 ret = transcoder_->Configure(videoColSpaFmt);
1158 EXPECT_EQ(ret, MSERR_OK);
1159 }
1160
1161 /**
1162 * @tc.name : Test Configure
1163 * @tc.number : Configure_003
1164 * @tc.desc : Test Configure
1165 * @tc.require :
1166 */
1167 HWTEST_F(HitranscodeUnitTest, Configure_003, TestSize.Level0)
1168 {
1169 VideoRectangle videoRectangle(-1, 720);
1170 int32_t ret = transcoder_->Configure(videoRectangle);
1171 EXPECT_EQ(ret, MSERR_OK);
1172
1173 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT);
1174 ret = transcoder_->Configure(videoColSpaFmt);
1175 EXPECT_EQ(ret, MSERR_OK);
1176 }
1177
1178 /**
1179 * @tc.name : Test Configure
1180 * @tc.number : Configure_004
1181 * @tc.desc : Test Configure
1182 * @tc.require :
1183 */
1184 HWTEST_F(HitranscodeUnitTest, Configure_004, TestSize.Level0)
1185 {
1186 VideoRectangle videoRectangle(1280, -1);
1187 int32_t ret = transcoder_->Configure(videoRectangle);
1188 EXPECT_EQ(ret, MSERR_OK);
1189
1190 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_BT709_LIMIT);
1191 ret = transcoder_->Configure(videoColSpaFmt);
1192 EXPECT_EQ(ret, MSERR_OK);
1193 }
1194
1195 /**
1196 * @tc.name : Test Configure
1197 * @tc.number : Configure_005
1198 * @tc.desc : Test Configure
1199 * @tc.require :
1200 */
1201 HWTEST_F(HitranscodeUnitTest, Configure_005, TestSize.Level0)
1202 {
1203 VideoRectangle videoRectangle(1280, 720);
1204 int32_t ret = transcoder_->Configure(videoRectangle);
1205 EXPECT_EQ(ret, MSERR_OK);
1206
1207 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL);
1208 ret = transcoder_->Configure(videoColSpaFmt);
1209 EXPECT_EQ(ret, MSERR_OK);
1210 }
1211
1212 /**
1213 * @tc.name : Test Configure
1214 * @tc.number : Configure_006
1215 * @tc.desc : Test Configure
1216 * @tc.require :
1217 */
1218 HWTEST_F(HitranscodeUnitTest, Configure_006, TestSize.Level0)
1219 {
1220 VideoRectangle videoRectangle(1280, -1);
1221 int32_t ret = transcoder_->Configure(videoRectangle);
1222 EXPECT_EQ(ret, MSERR_OK);
1223
1224 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL);
1225 ret = transcoder_->Configure(videoColSpaFmt);
1226 EXPECT_EQ(ret, MSERR_OK);
1227 }
1228
1229 /**
1230 * @tc.name : Test Configure
1231 * @tc.number : Configure_007
1232 * @tc.desc : Test Configure
1233 * @tc.require :
1234 */
1235 HWTEST_F(HitranscodeUnitTest, Configure_007, TestSize.Level0)
1236 {
1237 VideoRectangle videoRectangle(-1, 720);
1238 int32_t ret = transcoder_->Configure(videoRectangle);
1239 EXPECT_EQ(ret, MSERR_OK);
1240
1241 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_P3_FULL);
1242 ret = transcoder_->Configure(videoColSpaFmt);
1243 EXPECT_EQ(ret, MSERR_OK);
1244 }
1245
1246 /**
1247 * @tc.name : Test Configure
1248 * @tc.number : Configure_008
1249 * @tc.desc : Test Configure
1250 * @tc.require :
1251 */
1252 HWTEST_F(HitranscodeUnitTest, Configure_008, TestSize.Level0)
1253 {
1254 VideoRectangle videoRectangle(1280, 720);
1255 int32_t ret = transcoder_->Configure(videoRectangle);
1256 EXPECT_EQ(ret, MSERR_OK);
1257
1258 VideoColorSpace videoColSpaFmt(TRANSCODER_COLORSPACE_NONE);
1259 ret = transcoder_->Configure(videoColSpaFmt);
1260 EXPECT_EQ(ret, MSERR_INVALID_VAL);
1261 }
1262 } // namespace Media
1263 } // namespace OHOS