1 /*
2 * Copyright (c) 2024 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 #ifdef SUPPORT_AVPLAYER_DRM
19 #include "i_keysession_service.h"
20 #endif
21
22 namespace OHOS {
23 namespace Media {
24 using namespace std;
25 using namespace testing::ext;
26
SetUpTestCase(void)27 void HitranscodeUnitTest::SetUpTestCase(void)
28 {
29 }
30
TearDownTestCase(void)31 void HitranscodeUnitTest::TearDownTestCase(void)
32 {
33 }
34
SetUp(void)35 void HitranscodeUnitTest::SetUp(void)
36 {
37 transcoder_ = std::make_unique<HiTransCoderImpl>(0, 0, 0, 0);
38 transcoder_->Init();
39 }
40
TearDown(void)41 void HitranscodeUnitTest::TearDown(void)
42 {
43 transcoder_ = nullptr;
44 }
45
46 /**
47 * @tc.name : Test ProcessMetaKey API
48 * @tc.number : HitranscodeUnitTest_ProcessMetaKey001
49 * @tc.desc : Test ProcessMetaKey interface, set metaKey to int64_t.
50 * @tc.require : issueI5NZAQ
51 */
52 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey001, TestSize.Level0)
53 {
54 // 1. Set up the test environment
55 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
56 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
57 std::string metaKey = Tag::MEDIA_DURATION;
58 int64_t intVal = 100;
59 innerMeta->SetData(metaKey, intVal);
60
61 // 2. Call the function to be tested
62 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
63
64 // 3. Verify the result
65 EXPECT_TRUE(result);
66 int64_t outputIntVal;
67 EXPECT_TRUE(outputMeta->GetData(metaKey, outputIntVal));
68 EXPECT_EQ(intVal, outputIntVal);
69 }
70
71 /**
72 * @tc.name : Test ProcessMetaKey API
73 * @tc.number : HitranscodeUnitTest_ProcessMetaKey002
74 * @tc.desc : Test ProcessMetaKey interface, set metaKey to std::string.
75 * @tc.require : issueI5NZAQ
76 */
77 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey002, TestSize.Level0)
78 {
79 // 1. Set up the test environment
80 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
81 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
82 std::string metaKey = Tag::MEDIA_ALBUM;
83 std::string strVal = "test";
84 innerMeta->SetData(metaKey, strVal);
85
86 // 2. Call the function to be tested
87 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
88
89 // 3. Verify the result
90 EXPECT_TRUE(result);
91 std::string outputStrVal;
92 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
93 EXPECT_EQ(strVal, outputStrVal);
94 }
95
96 /**
97 * @tc.name : Test ProcessMetaKey API
98 * @tc.number : HitranscodeUnitTest_ProcessMetaKey003
99 * @tc.desc : Test ProcessMetaKey interface, set metaKey to int32_t.
100 * @tc.require :
101 */
102 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey003, TestSize.Level0)
103 {
104 // 1. Set up the test environment
105 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
106 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
107 std::string metaKey = Tag::VIDEO_HEIGHT;
108 int32_t intVal = 100;
109 innerMeta->SetData(metaKey, intVal);
110
111 // 2. Call the function to be tested
112 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
113
114 // 3. Verify the result
115 EXPECT_TRUE(result);
116 int32_t outputStrVal;
117 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
118 EXPECT_EQ(intVal, outputStrVal);
119 }
120
121 /**
122 * @tc.name : Test ProcessMetaKey API
123 * @tc.number : HitranscodeUnitTest_ProcessMetaKey004
124 * @tc.desc : Test ProcessMetaKey interface, set metaKey to double.
125 * @tc.require :
126 */
127 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey004, TestSize.Level0)
128 {
129 // 1. Set up the test environment
130 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
131 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
132 std::string metaKey = Tag::VIDEO_CAPTURE_RATE;
133 double doubleVal = 0.1;
134 innerMeta->SetData(metaKey, doubleVal);
135
136 // 2. Call the function to be tested
137 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
138
139 // 3. Verify the result
140 EXPECT_TRUE(result);
141 double outputStrVal;
142 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
143 EXPECT_EQ(doubleVal, outputStrVal);
144 }
145
146 /**
147 * @tc.name : Test ProcessMetaKey API
148 * @tc.number : HitranscodeUnitTest_ProcessMetaKey005
149 * @tc.desc : Test ProcessMetaKey interface, set metaKey to Plugins::VideoRotation.
150 * @tc.require :
151 */
152 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey005, TestSize.Level0)
153 {
154 // 1. Set up the test environment
155 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
156 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
157 std::string metaKey = Tag::VIDEO_ROTATION;
158 Plugins::VideoRotation rotation = Plugins::VideoRotation::VIDEO_ROTATION_0;
159 innerMeta->SetData(metaKey, rotation);
160
161 // 2. Call the function to be tested
162 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
163
164 // 3. Verify the result
165 EXPECT_TRUE(result);
166 Plugins::VideoRotation outputStrVal;
167 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
168 EXPECT_EQ(rotation, outputStrVal);
169 }
170
171 /**
172 * @tc.name : Test ProcessMetaKey API
173 * @tc.number : HitranscodeUnitTest_ProcessMetaKey006
174 * @tc.desc : Test ProcessMetaKey interface, set metaKey to bool.
175 * @tc.require :
176 */
177 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey006, TestSize.Level0)
178 {
179 // 1. Set up the test environment
180 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
181 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
182 std::string metaKey = Tag::VIDEO_COLOR_RANGE;
183 bool boolVal = true;
184 innerMeta->SetData(metaKey, boolVal);
185
186 // 2. Call the function to be tested
187 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
188
189 // 3. Verify the result
190 EXPECT_TRUE(result);
191 bool outputStrVal;
192 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
193 EXPECT_EQ(boolVal, outputStrVal);
194 }
195
196 /**
197 * @tc.name : Test ProcessMetaKey API
198 * @tc.number : HitranscodeUnitTest_ProcessMetaKey007
199 * @tc.desc : Test ProcessMetaKey interface, set metaKey to float.
200 * @tc.require :
201 */
202 HWTEST_F(HitranscodeUnitTest, HitranscodeUnitTest_ProcessMetaKey007, TestSize.Level0)
203 {
204 // 1. Set up the test environment
205 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
206 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
207 std::string metaKey = Tag::MEDIA_LATITUDE;
208 float floatVal = 0.9;
209 innerMeta->SetData(metaKey, floatVal);
210
211 // 2. Call the function to be tested
212 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
213
214 // 3. Verify the result
215 EXPECT_TRUE(result);
216 float outputStrVal;
217 EXPECT_TRUE(outputMeta->GetData(metaKey, outputStrVal));
218 EXPECT_EQ(floatVal, outputStrVal);
219 }
220
221 /**
222 * @tc.name : Test SetValueByType API
223 * @tc.number : SetValueByType_001
224 * @tc.desc : Test SetValueByType interface, set innerMeta or outputMeta to nullptr.
225 * @tc.require : issueI5NZAQ
226 */
227 HWTEST_F(HitranscodeUnitTest, SetValueByType_001, TestSize.Level0)
228 {
229 // 1. Set up the test environment
230 std::shared_ptr<Meta> innerMeta = nullptr;
231 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
232
233 // 2. Call the function to be tested
234 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
235
236 // 3. Verify the result
237 EXPECT_FALSE(result);
238 }
239
240 /**
241 * @tc.name : Test SetValueByType API
242 * @tc.number : SetValueByType_002
243 * @tc.desc : Test SetValueByType interface, set both innerMeta and outputMeta to nullptr.
244 * @tc.require : issueI5NZAQ
245 */
246 HWTEST_F(HitranscodeUnitTest, SetValueByType_002, TestSize.Level0)
247 {
248 // 1. Set up the test environment
249 std::shared_ptr<Meta> innerMeta = nullptr;
250 std::shared_ptr<Meta> outputMeta = nullptr;
251
252 // 2. Call the function to be tested
253 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
254
255 // 3. Verify the result
256 EXPECT_FALSE(result);
257 }
258
259 /**
260 * @tc.name : Test SetValueByType API
261 * @tc.number : SetValueByType_003
262 * @tc.desc : Test SetValueByType interface, set valid innerMeta and outputMeta.
263 * @tc.require : issueI5NZAQ
264 */
265 HWTEST_F(HitranscodeUnitTest, SetValueByType_003, TestSize.Level0)
266 {
267 // 1. Set up the test environment
268 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
269 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
270 std::string metaKey = Tag::MEDIA_DURATION;
271 int64_t intVal = 100;
272 innerMeta->SetData(metaKey, intVal);
273
274 bool result = transcoder_->SetValueByType(innerMeta, outputMeta);
275
276 EXPECT_TRUE(result);
277 }
278
279 /**
280 * @tc.name : Test ConfigureVideoAudioMetaData API
281 * @tc.number : ConfigureVideoAudioMetaData_001
282 * @tc.desc : Test ConfigureVideoAudioMetaData interface, set demuxerFilter_ nulllptr.
283 * @tc.require :
284 */
285 HWTEST_F(HitranscodeUnitTest, ConfigureVideoAudioMetaData_001, TestSize.Level0)
286 {
287 transcoder_->demuxerFilter_ = nullptr;
288 Status result = transcoder_->ConfigureVideoAudioMetaData();
289 EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
290 }
291
292 /**
293 * @tc.name : Test Prepare API
294 * @tc.number : Prepare_001
295 * @tc.desc : Test Prepare interface, dont set width and height.
296 * @tc.require :
297 */
298 HWTEST_F(HitranscodeUnitTest, Prepare_001, TestSize.Level0)
299 {
300 transcoder_->isExistVideoTrack_ = true;
301 int32_t ret = transcoder_->Prepare();
302 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
303 }
304
305 /**
306 * @tc.name : Test Prepare API
307 * @tc.number : Prepare_002
308 * @tc.desc : Test Prepare interface, dont set height.
309 * @tc.require :
310 */
311 HWTEST_F(HitranscodeUnitTest, Prepare_002, TestSize.Level0)
312 {
313 transcoder_->isExistVideoTrack_ = true;
314 std::string metaKey = Tag::VIDEO_WIDTH;
315 int32_t width = 0;
316 transcoder_->videoEncFormat_->SetData(metaKey, width);
317 int32_t ret = transcoder_->Prepare();
318 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
319 }
320
321 /**
322 * @tc.name : Test Prepare API
323 * @tc.number : Prepare_003
324 * @tc.desc : Test Prepare interface, dont set width.
325 * @tc.require :
326 */
327 HWTEST_F(HitranscodeUnitTest, Prepare_003, TestSize.Level0)
328 {
329 transcoder_->isExistVideoTrack_ = true;
330 std::string metaKey = Tag::VIDEO_HEIGHT;
331 int32_t height = 0;
332 transcoder_->videoEncFormat_->SetData(metaKey, height);
333 int32_t ret = transcoder_->Prepare();
334 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
335 }
336
337 /**
338 * @tc.name : Test Prepare API
339 * @tc.number : Prepare_004
340 * @tc.desc : Test Prepare interface, set all and the condition is 001.
341 * @tc.require :
342 */
343 HWTEST_F(HitranscodeUnitTest, Prepare_004, TestSize.Level0)
344 {
345 transcoder_->isExistVideoTrack_ = true;
346 std::string widthMetaKey = Tag::VIDEO_WIDTH;
347 int32_t width = 100;
348 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
349 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
350 int32_t height = 100;
351 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
352 transcoder_->inputVideoWidth_ = 200;
353 transcoder_->inputVideoHeight_ =200;
354 int32_t ret = transcoder_->Prepare();
355 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
356 }
357
358 /**
359 * @tc.name : Test Prepare API
360 * @tc.number : Prepare_005
361 * @tc.desc : Test Prepare interface, set all and the condition is 010.
362 * @tc.require :
363 */
364 HWTEST_F(HitranscodeUnitTest, Prepare_005, TestSize.Level0)
365 {
366 transcoder_->isExistVideoTrack_ = true;
367 std::string widthMetaKey = Tag::VIDEO_WIDTH;
368 int32_t width = 480;
369 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
370 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
371 int32_t height = 640;
372 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
373 transcoder_->inputVideoWidth_ = 640;
374 transcoder_->inputVideoHeight_ = 480;
375 int32_t ret = transcoder_->Prepare();
376 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
377 }
378
379 /**
380 * @tc.name : Test Prepare API
381 * @tc.number : Prepare_006
382 * @tc.desc : Test Prepare interface, set all and the condition is 011.
383 * @tc.require :
384 */
385 HWTEST_F(HitranscodeUnitTest, Prepare_006, TestSize.Level0)
386 {
387 transcoder_->isExistVideoTrack_ = true;
388 std::string widthMetaKey = Tag::VIDEO_WIDTH;
389 int32_t width = 100;
390 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
391 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
392 int32_t height = 100;
393 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
394 transcoder_->inputVideoWidth_ = 200;
395 transcoder_->inputVideoHeight_ = 50;
396 int32_t ret = transcoder_->Prepare();
397 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
398 }
399
400 /**
401 * @tc.name : Test Prepare API
402 * @tc.number : Prepare_007
403 * @tc.desc : Test Prepare interface, set all and the condition is 100.
404 * @tc.require :
405 */
406 HWTEST_F(HitranscodeUnitTest, Prepare_007, TestSize.Level0)
407 {
408 transcoder_->isExistVideoTrack_ = true;
409 std::string widthMetaKey = Tag::VIDEO_WIDTH;
410 int32_t width = 640;
411 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
412 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
413 int32_t height = 480;
414 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
415 transcoder_->inputVideoWidth_ = 480;
416 transcoder_->inputVideoHeight_ = 640;
417 int32_t ret = transcoder_->Prepare();
418 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
419 }
420
421 /**
422 * @tc.name : Test Prepare API
423 * @tc.number : Prepare_008
424 * @tc.desc : Test Prepare interface, set all and the condition is 101.
425 * @tc.require :
426 */
427 HWTEST_F(HitranscodeUnitTest, Prepare_008, TestSize.Level0)
428 {
429 transcoder_->isExistVideoTrack_ = true;
430 std::string widhtMetaKey = Tag::VIDEO_WIDTH;
431 int32_t width = 100;
432 transcoder_->videoEncFormat_->SetData(widhtMetaKey, width);
433 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
434 int32_t height = 480;
435 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
436 transcoder_->inputVideoWidth_ = 50;
437 transcoder_->inputVideoHeight_ = 640;
438 int32_t ret = transcoder_->Prepare();
439 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
440 }
441
442 /**
443 * @tc.name : Test Prepare API
444 * @tc.number : Prepare_009
445 * @tc.desc : Test Prepare interface, set all and the condition is 110.
446 * @tc.require :
447 */
448 HWTEST_F(HitranscodeUnitTest, Prepare_009, TestSize.Level0)
449 {
450 transcoder_->isExistVideoTrack_ = true;
451 std::string widthMetaKey = Tag::VIDEO_WIDTH;
452 int32_t width = 640;
453 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
454 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
455 int32_t height = 640;
456 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
457 transcoder_->inputVideoWidth_ = 480;
458 transcoder_->inputVideoHeight_ = 480;
459 int32_t ret = transcoder_->Prepare();
460 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
461 }
462
463 /**
464 * @tc.name : Test Prepare API
465 * @tc.number : Prepare_010
466 * @tc.desc : Test Prepare interface, set all and the condition is 111.
467 * @tc.require :
468 */
469 HWTEST_F(HitranscodeUnitTest, Prepare_010, TestSize.Level0)
470 {
471 transcoder_->isExistVideoTrack_ = true;
472 std::string widthMetaKey = Tag::VIDEO_WIDTH;
473 int32_t width = 100;
474 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
475 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
476 int32_t height = 100;
477 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
478 transcoder_->inputVideoWidth_ = 50;
479 transcoder_->inputVideoHeight_ = 50;
480 int32_t ret = transcoder_->Prepare();
481 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_INVALID_PARAMETER));
482 }
483
484 /**
485 * @tc.name : Test Prepare API
486 * @tc.number : Prepare_011
487 * @tc.desc : Test Prepare interface.
488 * @tc.require :
489 */
490 HWTEST_F(HitranscodeUnitTest, Prepare_011, TestSize.Level0)
491 {
492 transcoder_->isExistVideoTrack_ = true;
493 std::string widthMetaKey = Tag::VIDEO_WIDTH;
494 int32_t width = 480;
495 transcoder_->videoEncFormat_->SetData(widthMetaKey, width);
496 std::string heightMetaKey = Tag::VIDEO_HEIGHT;
497 int32_t height = 480;
498 transcoder_->videoEncFormat_->SetData(heightMetaKey, height);
499 transcoder_->inputVideoWidth_ = 640;
500 transcoder_->inputVideoHeight_ = 640;
501 int32_t ret = transcoder_->Prepare();
502 EXPECT_EQ(ret, static_cast<int32_t>(Status::ERROR_NULL_POINTER));
503 }
504
505 /**
506 * @tc.name : Test GetRealPath API
507 * @tc.number : GetRealPath_001
508 * @tc.desc : Test GetRealPath interface, set url to "file://".
509 * @tc.require :
510 */
511 HWTEST_F(HitranscodeUnitTest, GetRealPath_001, TestSize.Level0)
512 {
513 // 1. Set up the test environment
514 std::string url = "file://";
515 std::string realUrlPath;
516
517 // 2. Call the function to be tested
518 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
519
520 // 3. Verify the result
521 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
522 }
523
524 /**
525 * @tc.name : Test GetRealPath API
526 * @tc.number : GetRealPath_002
527 * @tc.desc : Test GetRealPath interface, set url to "file".
528 * @tc.require :
529 */
530 HWTEST_F(HitranscodeUnitTest, GetRealPath_002, TestSize.Level0)
531 {
532 // 1. Set up the test environment
533 std::string url = "file";
534 std::string realUrlPath;
535
536 // 2. Call the function to be tested
537 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
538
539 // 3. Verify the result
540 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
541 }
542
543 /**
544 * @tc.name : Test GetRealPath API
545 * @tc.number : GetRealPath_003
546 * @tc.desc : Test GetRealPath interface, set url to "file:///storage/../test.mp3".
547 * @tc.require :
548 */
549 HWTEST_F(HitranscodeUnitTest, GetRealPath_003, TestSize.Level0)
550 {
551 // 1. Set up the test environment
552 std::string url = "file:///storage/../test.mp3";
553 std::string realUrlPath;
554
555 // 2. Call the function to be tested
556 int32_t ret = transcoder_->GetRealPath(url, realUrlPath);
557
558 // 3. Verify the result
559 EXPECT_EQ(ret, MSERR_FILE_ACCESS_FAILED);
560 }
561
562 /**
563 * @tc.name : Test ProcessMetaKey API
564 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_008
565 * @tc.desc : Test ProcessMetaKey interface, dont set int64_t to innerMeta.
566 * @tc.require :
567 */
568 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_008, TestSize.Level0)
569 {
570 // 1. Set up the test environment
571 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
572 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
573 std::string metaKey = Tag::MEDIA_DURATION;
574
575 // 2. Call the function to be tested
576 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
577
578 // 3. Verify the result
579 EXPECT_TRUE(result);
580 int64_t outputIntVal;
581 EXPECT_FALSE(outputMeta->GetData(metaKey, outputIntVal));
582 }
583
584 /**
585 * @tc.name : Test ProcessMetaKey API
586 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_009
587 * @tc.desc : Test ProcessMetaKey interface, dont set string to innerMeta.
588 * @tc.require : issueI5NZAQ
589 */
590 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_009, TestSize.Level0)
591 {
592 // 1. Set up the test environment
593 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
594 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
595 std::string metaKey = Tag::MEDIA_ALBUM;
596
597 // 2. Call the function to be tested
598 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
599
600 // 3. Verify the result
601 EXPECT_TRUE(result);
602 std::string outputStrVal;
603 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
604 }
605
606 /**
607 * @tc.name : Test ProcessMetaKey API
608 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_010
609 * @tc.desc : Test ProcessMetaKey interface, dont set int32_t to innerMeta.
610 * @tc.require :
611 */
612 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_010, TestSize.Level0)
613 {
614 // 1. Set up the test environment
615 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
616 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
617 std::string metaKey = Tag::VIDEO_HEIGHT;
618
619 // 2. Call the function to be tested
620 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
621
622 // 3. Verify the result
623 EXPECT_TRUE(result);
624 int32_t outputStrVal;
625 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
626 }
627
628 /**
629 * @tc.name : Test ProcessMetaKey API
630 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_011
631 * @tc.desc : Test ProcessMetaKey interface, dont set double to innerMeta.
632 * @tc.require :
633 */
634 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_011, TestSize.Level0)
635 {
636 // 1. Set up the test environment
637 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
638 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
639 std::string metaKey = Tag::VIDEO_CAPTURE_RATE;
640
641 // 2. Call the function to be tested
642 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
643
644 // 3. Verify the result
645 EXPECT_TRUE(result);
646 double outputStrVal;
647 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
648 }
649
650 /**
651 * @tc.name : Test ProcessMetaKey API
652 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_012
653 * @tc.desc : Test ProcessMetaKey interface, dont set Plugins::VideoRotation to innerMeta.
654 * @tc.require :
655 */
656 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_012, TestSize.Level0)
657 {
658 // 1. Set up the test environment
659 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
660 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
661 std::string metaKey = Tag::VIDEO_ROTATION;
662
663 // 2. Call the function to be tested
664 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
665
666 // 3. Verify the result
667 EXPECT_TRUE(result);
668 Plugins::VideoRotation outputStrVal;
669 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
670 }
671
672 /**
673 * @tc.name : Test ProcessMetaKey API
674 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_013
675 * @tc.desc : Test ProcessMetaKey interface, dont set bool to innerMeta.
676 * @tc.require :
677 */
678 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_013, TestSize.Level0)
679 {
680 // 1. Set up the test environment
681 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
682 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
683 std::string metaKey = Tag::VIDEO_COLOR_RANGE;
684
685 // 2. Call the function to be tested
686 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
687
688 // 3. Verify the result
689 EXPECT_TRUE(result);
690 bool outputStrVal;
691 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
692 }
693
694 /**
695 * @tc.name : Test ProcessMetaKey API
696 * @tc.number : HitranscodeUnitTest_ProcessMetaKey_014
697 * @tc.desc : Test ProcessMetaKey interface, dont set float to innerMeta.
698 * @tc.require :
699 */
700 HWTEST_F(HitranscodeUnitTest, ProcessMetaKey_014, TestSize.Level0)
701 {
702 // 1. Set up the test environment
703 std::shared_ptr<Meta> innerMeta = std::make_shared<Meta>();
704 std::shared_ptr<Meta> outputMeta = std::make_shared<Meta>();
705 std::string metaKey = Tag::MEDIA_LATITUDE;
706
707 // 2. Call the function to be tested
708 bool result = transcoder_->ProcessMetaKey(innerMeta, outputMeta, metaKey);
709
710 // 3. Verify the result
711 EXPECT_TRUE(result);
712 float outputStrVal;
713 EXPECT_FALSE(outputMeta->GetData(metaKey, outputStrVal));
714 }
715
716 /**
717 * @tc.name: Test SetInputFile API
718 * @tc.number : SetInputFile_001
719 * @tc.desc: Test GetRealPath interface, set url to "file:///storage/../test.mp3".
720 * @tc.require:
721 */
722 HWTEST_F(HitranscodeUnitTest, SetInputFile_001, TestSize.Level0)
723 {
724 // 1. Set up the test environment
725 std::string url = "file:///storage/../test.mp3";
726
727 // 2. Call the function to be tested
728 int32_t ret = transcoder_->SetInputFile(url);
729
730 // 3. Verify the result
731 EXPECT_EQ(ret, MSERR_FILE_ACCESS_FAILED);
732 }
733
734 /**
735 * @tc.name: Test SetInputFile API
736 * @tc.number : SetInputFile_002
737 * @tc.desc: Test GetRealPath interface, set url to "file".
738 * @tc.require:
739 */
740 HWTEST_F(HitranscodeUnitTest, SetInputFile_002, TestSize.Level0)
741 {
742 // 1. Set up the test environment
743 std::string url = "file";
744
745 std::string realUrlPath;
746
747 // 2. Call the function to be tested
748 int32_t ret = transcoder_->SetInputFile(url);
749
750 // 3. Verify the result
751 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
752 }
753
754 /**
755 * @tc.name: Test SetInputFile API
756 * @tc.number : SetInputFile_003
757 * @tc.desc: Test GetRealPath interface, set url to "file://".
758 * @tc.require:
759 */
760 HWTEST_F(HitranscodeUnitTest, SetInputFile_003, TestSize.Level0)
761 {
762 // 1. Set up the test environment
763 std::string url = "file://";
764 std::string realUrlPath;
765
766 // 2. Call the function to be tested
767 int32_t ret = transcoder_->SetInputFile(url);
768
769 // 3. Verify the result
770 EXPECT_EQ(ret, MSERR_OPEN_FILE_FAILED);
771 }
772
773 /**
774 * @tc.name : Test ConfigureVideoEncoderFormat API
775 * @tc.number : ConfigureVideoEncoderFormat_001
776 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::H264.
777 * @tc.require :
778 */
779 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_001, TestSize.Level0)
780 {
781 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::H264);
782 Status ret = transcoder_->ConfigureVideoEncoderFormat(videoEnc);
783 EXPECT_EQ(ret, Status::OK);
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 Status ret = transcoder_->ConfigureVideoEncoderFormat(videoEnc);
814 EXPECT_EQ(ret, Status::OK);
815
816 std::string metaKey = Tag::MIME_TYPE;
817 std::string strVal = "video/mp4v-es";
818 std::string outputStrVal;
819 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
820 EXPECT_EQ(strVal, outputStrVal);
821 }
822
823 /**
824 * @tc.name : Test ConfigureVideoEncoderFormat API
825 * @tc.number : ConfigureVideoEncoderFormat_003
826 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::H265.
827 * @tc.require :
828 */
829 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_003, TestSize.Level0)
830 {
831 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::H265);
832 Status ret = transcoder_->ConfigureVideoEncoderFormat(videoEnc);
833 EXPECT_EQ(ret, Status::OK);
834
835 std::string metaKey = Tag::MIME_TYPE;
836 std::string strVal = "video/hevc";
837 std::string outputStrVal;
838 EXPECT_TRUE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
839 EXPECT_EQ(strVal, outputStrVal);
840 }
841
842 /**
843 * @tc.name : Test ConfigureVideoEncoderFormat API
844 * @tc.number : ConfigureVideoEncoderFormat_004
845 * @tc.desc : Test ConfigureVideoEncoderFormat interface, set VideoCodecFormat::VIDEO_DEFAULT.
846 * @tc.require :
847 */
848 HWTEST_F(HitranscodeUnitTest, ConfigureVideoEncoderFormat_004, TestSize.Level0)
849 {
850 VideoEnc videoEnc(OHOS::Media::VideoCodecFormat::VIDEO_DEFAULT);
851 Status ret = transcoder_->ConfigureVideoEncoderFormat(videoEnc);
852 EXPECT_EQ(ret, Status::OK);
853
854 std::string metaKey = Tag::MIME_TYPE;
855 std::string outputStrVal;
856 EXPECT_FALSE(transcoder_->videoEncFormat_->GetData(metaKey, outputStrVal));
857 }
858
859 /**
860 * @tc.name : Test AppendSrcMediaInfo API
861 * @tc.number : AppendSrcMediaInfo_001
862 * @tc.desc : Test AppendSrcMediaInfo interface.
863 * @tc.require :
864 */
865 HWTEST_F(HitranscodeUnitTest, AppendSrcMediaInfo_001, TestSize.Level0)
866 {
867 std::shared_ptr<Meta> inputMeta = std::make_shared<Meta>();
868 std::shared_ptr<Meta> srcVideoFormat_ = std::make_shared<Meta>();
869 std::shared_ptr<Meta> srcAudioFormat_ = std::make_shared<Meta>();
870 std::string metaKey = Tag::MEDIA_TYPE;
871 Plugins::MediaType mediaType = Plugins::MediaType::AUDIO;
872 transcoder_->srcAudioFormat_->SetData(metaKey, mediaType);
873
874 mediaType = Plugins::MediaType::VIDEO;
875 transcoder_->srcVideoFormat_->SetData(metaKey, mediaType);
876
877 int64_t srcVideoBitrate = 640;
878 transcoder_->srcVideoFormat_->SetData(Tag::MEDIA_BITRATE, srcVideoBitrate);
879
880 transcoder_->srcVideoFormat_->SetData(Tag::VIDEO_IS_HDR_VIVID, true);
881 EXPECT_TRUE(inputMeta != nullptr);
882 transcoder_->AppendSrcMediaInfo(inputMeta);
883 int32_t isHdrVivid_;
884 inputMeta->GetData(Tag::AV_TRANSCODER_SRC_HDR_TYPE, isHdrVivid_);
885 EXPECT_EQ(isHdrVivid_, 1);
886 int32_t srcVideoBitrate_;
887 inputMeta->GetData(Tag::AV_TRANSCODER_SRC_VIDEO_BITRATE, srcVideoBitrate_);
888 EXPECT_EQ(srcVideoBitrate_, srcVideoBitrate);
889 }
890
891 /**
892 * @tc.name : Test ConfigureVideoBitrate API
893 * @tc.number : ConfigureVideoBitrate_001
894 * @tc.desc : Test ConfigureVideoBitrate interface.
895 * @tc.require :
896 */
897 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_001, TestSize.Level0)
898 {
899 transcoder_->isExistVideoTrack_ = true;
900 std::string metaKey = Tag::VIDEO_WIDTH;
901 int32_t width = 1100;
902 transcoder_->videoEncFormat_->SetData(metaKey, width);
903
904 int32_t height = 1100;
905 metaKey = Tag::VIDEO_HEIGHT;
906 transcoder_->videoEncFormat_->SetData(metaKey, height);
907 Status ret = transcoder_->ConfigureVideoBitrate();
908 EXPECT_EQ(ret, Status::OK);
909 }
910
911 /**
912 * @tc.name : Test ConfigureVideoBitrate API
913 * @tc.number : ConfigureVideoBitrate_002
914 * @tc.desc : Test ConfigureVideoBitrate interface.
915 * @tc.require :
916 */
917 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_002, TestSize.Level0)
918 {
919 transcoder_->isExistVideoTrack_ = true;
920 std::string metaKey = Tag::VIDEO_WIDTH;
921 int32_t width = 800;
922 transcoder_->videoEncFormat_->SetData(metaKey, width);
923
924 int32_t height = 800;
925 metaKey = Tag::VIDEO_HEIGHT;
926 transcoder_->videoEncFormat_->SetData(metaKey, height);
927 auto ret = transcoder_->ConfigureVideoBitrate();
928 EXPECT_EQ(ret, Status::OK);
929 }
930
931 /**
932 * @tc.name : Test ConfigureVideoBitrate API
933 * @tc.number : ConfigureVideoBitrate_003
934 * @tc.desc : Test ConfigureVideoBitrate interface.
935 * @tc.require :
936 */
937 HWTEST_F(HitranscodeUnitTest, ConfigureVideoBitrate_003, TestSize.Level0)
938 {
939 transcoder_->isExistVideoTrack_ = true;
940 std::string metaKey = Tag::VIDEO_WIDTH;
941 int32_t width = 500;
942 transcoder_->videoEncFormat_->SetData(metaKey, width);
943
944 int32_t height = 500;
945 metaKey = Tag::VIDEO_HEIGHT;
946 transcoder_->videoEncFormat_->SetData(metaKey, height);
947 auto ret = transcoder_->ConfigureVideoBitrate();
948 EXPECT_EQ(ret, Status::OK);
949 }
950
951 /**
952 * @tc.name : Test ConfigureVideoWidthHeight API
953 * @tc.number : ConfigureVideoWidthHeight_001
954 * @tc.desc : Test ConfigureVideoWidthHeight.
955 * @tc.require :
956 */
957 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_001, TestSize.Level0)
958 {
959 VideoRectangle videoRectangle(1920, 1080);
960 Status ret = transcoder_->ConfigureVideoWidthHeight(videoRectangle);
961 EXPECT_EQ(ret, Status::OK);
962 }
963
964 /**
965 * @tc.name : Test ConfigureVideoWidthHeight API
966 * @tc.number : ConfigureVideoWidthHeight_002
967 * @tc.desc : Test ConfigureVideoWidthHeight.
968 * @tc.require :
969 */
970 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_002, TestSize.Level0)
971 {
972 VideoRectangle videoRectangle(-1, -1);
973 Status ret = transcoder_->ConfigureVideoWidthHeight(videoRectangle);
974 EXPECT_EQ(ret, Status::OK);
975 }
976
977 /**
978 * @tc.name : Test ConfigureVideoWidthHeight API
979 * @tc.number : ConfigureVideoWidthHeight_003
980 * @tc.desc : Test ConfigureVideoWidthHeight.
981 * @tc.require :
982 */
983 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_003, TestSize.Level0)
984 {
985 VideoRectangle videoRectangle(1920, -1);
986 Status ret = transcoder_->ConfigureVideoWidthHeight(videoRectangle);
987 EXPECT_EQ(ret, Status::OK);
988 }
989
990 /**
991 * @tc.name : Test ConfigureVideoWidthHeight API
992 * @tc.number : ConfigureVideoWidthHeight_004
993 * @tc.desc : Test ConfigureVideoWidthHeight.
994 * @tc.require :
995 */
996 HWTEST_F(HitranscodeUnitTest, ConfigureVideoWidthHeight_004, TestSize.Level0)
997 {
998 VideoRectangle videoRectangle(-1, 1080);
999 Status ret = transcoder_->ConfigureVideoWidthHeight(videoRectangle);
1000 EXPECT_EQ(ret, Status::OK);
1001 }
1002 } // namespace Media
1003 } // namespace OHOS