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 "player_server_mem_unit_test.h"
17 #include "media_errors.h"
18 #include "hiplayer_impl.h"
19
20 namespace OHOS {
21 namespace Media {
22 using namespace std;
23 using namespace testing::ext;
24 const std::string MEDIA_ROOT = "/data/test/";
25 const std::string VIDEO_FILE1 = MEDIA_ROOT + "H264_AAC.mp4";
26
27
SetUpTestCase(void)28 void PlayerServerMemUnitTest::SetUpTestCase(void)
29 {
30 }
31
TearDownTestCase(void)32 void PlayerServerMemUnitTest::TearDownTestCase(void)
33 {
34 }
35
SetUp(void)36 void PlayerServerMemUnitTest::SetUp(void)
37 {
38 playerServerMem_ = std::make_shared<PlayerServerMem>();
39 }
40
TearDown(void)41 void PlayerServerMemUnitTest::TearDown(void)
42 {
43 playerServerMem_ = nullptr;
44 }
45
46 /**
47 * @tc.name : Test AudioHapticManager RegisterSource API
48 * @tc.number: AudioHapticManager_RegisterSource_001
49 * @tc.desc : Test AudioHapticManager RegisterSource interface
50 */
51 HWTEST_F(PlayerServerMemUnitTest, PlayerServerMem_RegisterSource_001, TestSize.Level1)
52 {
53 EXPECT_NE(nullptr, playerServerMem_);
54 sleep(1);
55 }
56
57 /**
58 * @tc.name : Test SetSourceInternal API
59 * @tc.number : SetSourceInternal_004
60 * @tc.desc : Test SetSourceInternal interface, set sourceType to invalid value.
61 * @tc.require : issueI5NZAQ
62 */
63 HWTEST_F(PlayerServerMemUnitTest, SetSourceInternal_004, TestSize.Level0)
64 {
65 // 1. Set up the test environment
66 playerServerMem_->recoverConfig_.sourceType = 100; // Invalid value
67
68 // 2. Call the function to be tested
69 int32_t ret = playerServerMem_->SetSourceInternal();
70
71 // 3. Verify the result
72 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
73 sleep(1);
74 }
75
76 /**
77 * @tc.name : AddSubSourceInternal_001
78 * @tc.number : AddSubSourceInternal_001
79 * @tc.desc : Test AddSubSourceInternal interface, set recoverConfig_.subUrl not empty.
80 * @tc.require : issueI5NZAQ
81 */
82 HWTEST_F(PlayerServerMemUnitTest, AddSubSourceInternal_001, TestSize.Level0)
83 {
84 // 1. Set up the test environment
85 playerServerMem_->recoverConfig_.subUrl.push_back("http://test.com");
86
87 // 2. Call the function to be tested
88 int32_t ret = playerServerMem_->AddSubSourceInternal();
89
90 // 3. Verify the result
91 EXPECT_EQ(ret, MSERR_OK);
92 sleep(1);
93 }
94
95 /**
96 * @tc.name : AddSubSourceInternal_002
97 * @tc.number : AddSubSourceInternal_002
98 * @tc.desc : Test AddSubSourceInternal interface, set recoverConfig_.subFdSrc not empty.
99 * @tc.require : issueI5NZAQ
100 */
101 HWTEST_F(PlayerServerMemUnitTest, AddSubSourceInternal_002, TestSize.Level0)
102 {
103 // 1. Set up the test environment
104 playerServerMem_->recoverConfig_.subFdSrc.push_back({1, 0, 1024});
105
106 // 2. Call the function to be tested
107 int32_t ret = playerServerMem_->AddSubSourceInternal();
108
109 // 3. Verify the result
110 EXPECT_EQ(ret, MSERR_OK);;
111 sleep(1);
112 }
113
114 /**
115 * @tc.name : SetConfigInternal_001
116 * @tc.number : SetConfigInternal_001
117 * @tc.desc : Test SetConfigInternal interface, set recoverConfig_.leftVolume and recoverConfig_.rightVolume not 1.0f.
118 * @tc.require : issueI5NZAQ
119 */
120 HWTEST_F(PlayerServerMemUnitTest, SetConfigInternal_001, TestSize.Level0)
121 {
122 // 1. Set up the test environment
123 playerServerMem_->recoverConfig_.leftVolume = 0.5f;
124 playerServerMem_->recoverConfig_.rightVolume = 0.5f;
125
126 // 2. Call the function to be tested
127 int32_t ret = playerServerMem_->SetConfigInternal();
128
129 // 3. Verify the result
130 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
131 sleep(1);
132 }
133
134 /**
135 * @tc.name : SetConfigInternal_003
136 * @tc.number : SetConfigInternal_003
137 * @tc.desc : Test SetConfigInternal interface, set recoverConfig_.loop not false.
138 * @tc.require : issueI5NZAQ
139 */
140 HWTEST_F(PlayerServerMemUnitTest, SetConfigInternal_003, TestSize.Level0)
141 {
142 // 1. Set up the test environment
143 playerServerMem_->recoverConfig_.loop = true;
144
145 // 2. Call the function to be tested
146 int32_t ret = playerServerMem_->SetConfigInternal();
147
148 // 3. Verify the result
149 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
150 sleep(1);
151 }
152
153 /**
154 * @tc.name : SetConfigInternal_004
155 * @tc.number : SetConfigInternal_004
156 * @tc.desc : Test SetConfigInternal interface, set recoverConfig_.bitRate not 0.
157 * @tc.require : issueI5NZAQ
158 */
159 HWTEST_F(PlayerServerMemUnitTest, SetConfigInternal_004, TestSize.Level0)
160 {
161 // 1. Set up the test environment
162 playerServerMem_->recoverConfig_.bitRate = 1024;
163
164 // 2. Call the function to be tested
165 int32_t ret = playerServerMem_->SetConfigInternal();
166
167 // 3. Verify the result
168 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
169 sleep(1);
170 }
171
172 /**
173 * @tc.name : Test SetBehaviorInternal API
174 * @tc.number : SetBehaviorInternal_001
175 * @tc.desc : Test SetBehaviorInternal interface, set speedMode to SPEED_FORWARD_1_00_X.
176 * @tc.require : issueI5NZAQ
177 */
178 HWTEST_F(PlayerServerMemUnitTest, SetBehaviorInternal_001, TestSize.Level0)
179 {
180 // 1. Set up the test environment
181 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
182 playerServerMem_->recoverConfig_.currentTime = 0;
183 playerServerMem_->recoverConfig_.audioIndex = 0;
184
185 // 2. Call the function to be tested
186 int32_t ret = playerServerMem_->SetBehaviorInternal();
187
188 // 3. Verify the result
189 EXPECT_EQ(ret, MSERR_OK);
190 sleep(1);
191 }
192
193 /**
194 * @tc.name : Test SetBehaviorInternal API
195 * @tc.number : SetBehaviorInternal_002
196 * @tc.desc : Test SetBehaviorInternal interface, set currentTime to a non-zero value.
197 * @tc.require : issueI5NZAQ
198 */
199 HWTEST_F(PlayerServerMemUnitTest, SetBehaviorInternal_002, TestSize.Level0)
200 {
201 // 1. Set up the test environment
202 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
203 playerServerMem_->recoverConfig_.currentTime = 100;
204 playerServerMem_->recoverConfig_.audioIndex = 0;
205
206 // 2. Call the function to be tested
207 int32_t ret = playerServerMem_->SetBehaviorInternal();
208
209 // 3. Verify the result
210 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
211 sleep(1);
212 }
213
214 /**
215 * @tc.name : Test SetBehaviorInternal API
216 * @tc.number : SetBehaviorInternal_003
217 * @tc.desc : Test SetBehaviorInternal interface, set audioIndex to a non-zero value.
218 * @tc.require : issueI5NZAQ
219 */
220 HWTEST_F(PlayerServerMemUnitTest, SetBehaviorInternal_003, TestSize.Level0)
221 {
222 // 1. Set up the test environment
223 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
224 playerServerMem_->recoverConfig_.currentTime = 0;
225 playerServerMem_->recoverConfig_.audioIndex = 1;
226
227 // 2. Call the function to be tested
228 int32_t ret = playerServerMem_->SetBehaviorInternal();
229
230 // 3. Verify the result
231 EXPECT_EQ(ret, MSERR_OK);
232 sleep(1);
233 }
234
235 HWTEST_F(PlayerServerMemUnitTest, SetBehaviorInternal_004, TestSize.Level0)
236 {
237 playerServerMem_->lastOpStatus_ = PLAYER_IDLE;
238 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_25_X;
239 EXPECT_EQ(playerServerMem_->SetBehaviorInternal(), MSERR_INVALID_OPERATION);
240 }
241
242 HWTEST_F(PlayerServerMemUnitTest, SetBehaviorInternal_005, TestSize.Level0)
243 {
244 playerServerMem_->lastOpStatus_ = PLAYER_IDLE;
245 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
246 playerServerMem_->recoverConfig_.currentTime = 0;
247 playerServerMem_->defaultAudioIndex_ = 1;
248 EXPECT_EQ(playerServerMem_->SetBehaviorInternal(), MSERR_INVALID_OPERATION);
249 }
250
251 /**
252 * @tc.name : Test NeedSelectAudioTrack API
253 * @tc.number : NeedSelectAudioTrack_001
254 * @tc.desc : Test NeedSelectAudioTrack interface, set audioIndex to a non-zero value and
255 * defaultAudioIndex_ to a different value.
256 * @tc.require : issueI5NZAQ
257 */
258 HWTEST_F(PlayerServerMemUnitTest, NeedSelectAudioTrack_001, TestSize.Level0)
259 {
260 // 1. Set up the test environment
261 playerServerMem_->recoverConfig_.audioIndex = 1;
262 playerServerMem_->defaultAudioIndex_ = 0;
263
264 // 2. Call the function to be tested
265 bool result = playerServerMem_->NeedSelectAudioTrack();
266
267 // 3. Verify the result
268 EXPECT_TRUE(result);
269 sleep(1);
270 }
271
272 /**
273 * @tc.name : Test NeedSelectAudioTrack API
274 * @tc.number : NeedSelectAudioTrack_002
275 * @tc.desc : Test NeedSelectAudioTrack interface, set audioIndex to a non-zero value and
276 * defaultAudioIndex_ to the same value.
277 * @tc.require : issueI5NZAQ
278 */
279 HWTEST_F(PlayerServerMemUnitTest, NeedSelectAudioTrack_002, TestSize.Level0)
280 {
281 // 1. Set up the test environment
282 playerServerMem_->recoverConfig_.audioIndex = 1;
283 playerServerMem_->defaultAudioIndex_ = 1;
284
285 // 2. Call the function to be tested
286 bool result = playerServerMem_->NeedSelectAudioTrack();
287
288 // 3. Verify the result
289 EXPECT_FALSE(result);
290 sleep(1);
291 }
292
293 /**
294 * @tc.name : Test NeedSelectAudioTrack API
295 * @tc.number : NeedSelectAudioTrack_003
296 * @tc.desc : Test NeedSelectAudioTrack interface, set audioIndex to a negative value.
297 * @tc.require : issueI5NZAQ
298 */
299 HWTEST_F(PlayerServerMemUnitTest, NeedSelectAudioTrack_003, TestSize.Level0)
300 {
301 // 1. Set up the test environment
302 playerServerMem_->recoverConfig_.audioIndex = -1;
303 playerServerMem_->defaultAudioIndex_ = 0;
304
305 // 2. Call the function to be tested
306 bool result = playerServerMem_->NeedSelectAudioTrack();
307
308 // 3. Verify the result
309 EXPECT_FALSE(result);
310 sleep(1);
311 }
312
313
314 /**
315 * @tc.name : Test SetSource API with URL
316 * @tc.number : SetSource_001
317 * @tc.desc : Test SetSource interface with URL, set url to a valid value.
318 * @tc.require : issueI5NZAQ
319 */
320 HWTEST_F(PlayerServerMemUnitTest, SetSource_001, TestSize.Level0)
321 {
322 // 1. Set up the test environment
323 std::string url = "file://..";
324
325 // 2. Call the function to be tested
326 int32_t ret = playerServerMem_->SetSource(url);
327
328 // 3. Verify the result
329 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
330 sleep(1);
331 }
332
333 /**
334 * @tc.name : Test SetSource API with Invalid URL
335 * @tc.number : SetSource_003
336 * @tc.desc : Test SetSource interface with URL, set url to an invalid value.
337 * @tc.require : issueI5NZAQ
338 */
339 HWTEST_F(PlayerServerMemUnitTest, SetSource_003, TestSize.Level0)
340 {
341 // 1. Set up the test environment
342 std::string url = "invalid_url";
343
344 // 2. Call the function to be tested
345 int32_t ret = playerServerMem_->SetSource(url);
346
347 // 3. Verify the result
348 EXPECT_NE(ret, MSERR_OK);
349 sleep(1);
350 }
351
352 /**
353 * @tc.name : Test SetSource API with Empty URL
354 * @tc.number : SetSource_004
355 * @tc.desc : Test SetSource interface with URL, set url to an empty string.
356 * @tc.require : issueI5NZAQ
357 */
358 HWTEST_F(PlayerServerMemUnitTest, SetSource_004, TestSize.Level0)
359 {
360 // 1. Set up the test environment
361 std::string url = "";
362
363 // 2. Call the function to be tested
364 int32_t ret = playerServerMem_->SetSource(url);
365
366 // 3. Verify the result
367 EXPECT_NE(ret, MSERR_OK);
368 sleep(1);
369 }
370
371
372 /**
373 * @tc.name : Test GetCurrentTime API
374 * @tc.number : GetCurrentTime_001
375 * @tc.desc : Test GetCurrentTime interface, get current time. isLocalResource_ is false
376 * @tc.require : issueI5NZAQ
377 */
378 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTime_001, TestSize.Level0)
379 {
380 // 1. Set up the test environment
381 int32_t currentTime = 0;
382
383 // 2. Call the function to be tested
384 int32_t ret = playerServerMem_->GetCurrentTime(currentTime);
385
386 // 3. Verify the result
387 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
388 sleep(1);
389 }
390
391 /**
392 * @tc.name : Test GetCurrentTime API
393 * @tc.number : GetCurrentTime_002
394 * @tc.desc : Test GetCurrentTime interface, get current time. isReleaseMemByManage_ is false
395 * @tc.require : issueI5NZAQ
396 */
397 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTime_002, TestSize.Level0)
398 {
399 // 1. Set up the test environment
400 int32_t currentTime = 0;
401 playerServerMem_->isLocalResource_ = true;
402 // 2. Call the function to be tested
403 int32_t ret = playerServerMem_->GetCurrentTime(currentTime);
404
405 // 3. Verify the result
406 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
407 sleep(1);
408 }
409
410 /**
411 * @tc.name : Test GetCurrentTime API
412 * @tc.number : GetCurrentTime_003
413 * @tc.desc : Test GetCurrentTime interface, get current time.isReleaseMemByManage_ = isLocalResource_ = true
414 * @tc.require : issueI5NZAQ
415 */
416 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTime_003, TestSize.Level0)
417 {
418 // 1. Set up the test environment
419 int32_t currentTime = 0;
420 playerServerMem_->isLocalResource_ = true;
421 playerServerMem_->isReleaseMemByManage_ = true;
422
423 // 2. Call the function to be tested
424 int32_t ret = playerServerMem_->GetCurrentTime(currentTime);
425
426 // 3. Verify the result
427 EXPECT_EQ(ret, MSERR_OK);
428 sleep(1);
429 }
430
431 /**
432 * @tc.name : Test GetVideoTrackInfo API
433 * @tc.number : GetVideoTrackInfo_001
434 * @tc.desc : Test GetVideoTrackInfo interface, get video track info. isLocalResource_ is false
435 * @tc.require : issueI5NZAQ
436 */
437 HWTEST_F(PlayerServerMemUnitTest, GetVideoTrackInfo_001, TestSize.Level0)
438 {
439 // 1. Set up the test environment
440 std::vector<Format> videoTrack;
441
442 // 2. Call the function to be tested
443 int32_t ret = playerServerMem_->GetVideoTrackInfo(videoTrack);
444
445 // 3. Verify the result
446 EXPECT_EQ(ret, MSERR_NO_MEMORY);
447 sleep(1);
448 }
449
450 /**
451 * @tc.name : Test GetVideoTrackInfo API
452 * @tc.number : GetVideoTrackInfo_002
453 * @tc.desc : Test GetVideoTrackInfo interface, get video track info.isReleaseMemByManage_ is false
454 * @tc.require : issueI5NZAQ
455 */
456 HWTEST_F(PlayerServerMemUnitTest, GetVideoTrackInfo_002, TestSize.Level0)
457 {
458 // 1. Set up the test environment
459 std::vector<Format> videoTrack;
460 playerServerMem_->isLocalResource_ = true;
461 // 2. Call the function to be tested
462 int32_t ret = playerServerMem_->GetVideoTrackInfo(videoTrack);
463
464 // 3. Verify the result
465 EXPECT_EQ(ret, MSERR_NO_MEMORY);
466 sleep(1);
467 }
468
469 /**
470 * @tc.name : Test GetVideoTrackInfo API
471 * @tc.number : GetVideoTrackInfo_003
472 * @tc.desc : Test GetVideoTrackInfo interface, get video track info.isReleaseMemByManage_ = isLocalResource_ = true
473 * @tc.require : issueI5NZAQ
474 */
475 HWTEST_F(PlayerServerMemUnitTest, GetVideoTrackInfo_003, TestSize.Level0)
476 {
477 // 1. Set up the test environment
478 std::vector<Format> videoTrack;
479 playerServerMem_->isLocalResource_ = true;
480 playerServerMem_->isReleaseMemByManage_ = true;
481
482 // 2. Call the function to be tested
483 int32_t ret = playerServerMem_->GetVideoTrackInfo(videoTrack);
484
485 // 3. Verify the result
486 EXPECT_EQ(ret, MSERR_OK);
487 sleep(1);
488 }
489
490 /**
491 * @tc.name : Test GetAudioTrackInfo API
492 * @tc.number : GetAudioTrackInfo_001
493 * @tc.desc : Test GetAudioTrackInfo interface, get audio track info.isLocalResource_ is false
494 * @tc.require : issueI5NZAQ
495 */
496 HWTEST_F(PlayerServerMemUnitTest, GetAudioTrackInfo_001, TestSize.Level0)
497 {
498 // 1. Set up the test environment
499 std::vector<Format> audioTrack;
500
501 // 2. Call the function to be tested
502 int32_t ret = playerServerMem_->GetAudioTrackInfo(audioTrack);
503
504 // 3. Verify the result
505 EXPECT_EQ(ret, MSERR_NO_MEMORY);
506 sleep(1);
507 }
508
509 /**
510 * @tc.name : Test GetAudioTrackInfo API
511 * @tc.number : GetAudioTrackInfo_002
512 * @tc.desc : Test GetAudioTrackInfo interface, get audio track info.isReleaseMemByManage_ is false
513 * @tc.require : issueI5NZAQ
514 */
515 HWTEST_F(PlayerServerMemUnitTest, GetAudioTrackInfo_002, TestSize.Level0)
516 {
517 // 1. Set up the test environment
518 std::vector<Format> audioTrack;
519 playerServerMem_->isLocalResource_ = true;
520
521 // 2. Call the function to be tested
522 int32_t ret = playerServerMem_->GetAudioTrackInfo(audioTrack);
523
524 // 3. Verify the result
525 EXPECT_EQ(ret, MSERR_NO_MEMORY);
526 sleep(1);
527 }
528
529 /**
530 * @tc.name : Test GetAudioTrackInfo API
531 * @tc.number : GetAudioTrackInfo_003
532 * @tc.desc : Test GetAudioTrackInfo interface, get audio track info.isReleaseMemByManage_ = isLocalResource_ = true
533 * @tc.require : issueI5NZAQ
534 */
535 HWTEST_F(PlayerServerMemUnitTest, GetAudioTrackInfo_003, TestSize.Level0)
536 {
537 // 1. Set up the test environment
538 std::vector<Format> audioTrack;
539 playerServerMem_->isLocalResource_ = true;
540 playerServerMem_->isReleaseMemByManage_ = true;
541 // 2. Call the function to be tested
542 int32_t ret = playerServerMem_->GetAudioTrackInfo(audioTrack);
543
544 // 3. Verify the result
545 EXPECT_EQ(ret, MSERR_OK);
546 sleep(1);
547 }
548
549
550 /**
551 * @tc.name : Test GetVideoWidth API
552 * @tc.number : GetVideoWidth_001
553 * @tc.desc : Test GetVideoWidth interface, get video width.
554 * @tc.require : issueI5NZAQ
555 */
556 HWTEST_F(PlayerServerMemUnitTest, GetVideoWidth_001, TestSize.Level0)
557 {
558 // 1. Set up the test environment
559
560 // 2. Call the function to be tested
561 int32_t width = playerServerMem_->GetVideoWidth();
562
563 // 3. Verify the result
564 EXPECT_GT(width, 0);
565 sleep(1);
566 }
567
568 /**
569 * @tc.name : Test GetVideoWidth API
570 * @tc.number : GetVideoWidth_002
571 * @tc.desc : Test GetVideoWidth interface, get video width.
572 * @tc.require : issueI5NZAQ
573 */
574 HWTEST_F(PlayerServerMemUnitTest, GetVideoWidth_002, TestSize.Level0)
575 {
576 // 1. Set up the test environment
577 playerServerMem_->isLocalResource_ = true;
578 // 2. Call the function to be tested
579 int32_t width = playerServerMem_->GetVideoWidth();
580
581 // 3. Verify the result
582 EXPECT_GT(width, 0);
583 sleep(1);
584 }
585
586 /**
587 * @tc.name : Test GetVideoWidth API
588 * @tc.number : GetVideoWidth_003
589 * @tc.desc : Test GetVideoWidth interface, get video width.
590 * @tc.require : issueI5NZAQ
591 */
592 HWTEST_F(PlayerServerMemUnitTest, GetVideoWidth_003, TestSize.Level0)
593 {
594 // 1. Set up the test environment
595 playerServerMem_->isLocalResource_ = true;
596 playerServerMem_->isReleaseMemByManage_ = true;
597 // 2. Call the function to be tested
598 int32_t width = playerServerMem_->GetVideoWidth();
599
600 // 3. Verify the result
601 EXPECT_EQ(width, 0);
602 sleep(1);
603 }
604
605 /**
606 * @tc.name : Test GetVideoHeight API
607 * @tc.number : GetVideoHeight_001
608 * @tc.desc : Test GetVideoHeight interface, get video height.
609 * @tc.require : issueI5NZAQ
610 */
611 HWTEST_F(PlayerServerMemUnitTest, GetVideoHeight_001, TestSize.Level0)
612 {
613 // 1. Set up the test environment
614
615 // 2. Call the function to be tested
616 int32_t height = playerServerMem_->GetVideoHeight();
617
618 // 3. Verify the result
619 EXPECT_GT(height, 0);
620 sleep(1);
621 }
622
623 /**
624 * @tc.name : Test GetDuration API
625 * @tc.number : GetDuration_001
626 * @tc.desc : Test GetDuration interface, get video duration.
627 * @tc.require : issueI5NZAQ
628 */
629 HWTEST_F(PlayerServerMemUnitTest, GetDuration_001, TestSize.Level0)
630 {
631 // 1. Set up the test environment
632 int32_t duration = 0;
633
634 // 2. Call the function to be tested
635 int32_t ret = playerServerMem_->GetDuration(duration);
636
637 // 3. Verify the result
638 EXPECT_EQ(ret, MSERR_INVALID_OPERATION);
639 sleep(1);
640 }
641
642 /**
643 * @tc.name : Test IsPlaying API
644 * @tc.number : IsPlaying_001
645 * @tc.desc : Test IsPlaying interface, set isLocalResource_ and isReleaseMemByManage_ to true.
646 * @tc.require : issueI5NZAQ
647 */
648 HWTEST_F(PlayerServerMemUnitTest, IsPlaying_001, TestSize.Level0)
649 {
650 // 1. Set up the test environment
651 playerServerMem_->isLocalResource_ = true;
652 playerServerMem_->isReleaseMemByManage_ = true;
653 playerServerMem_->recoverConfig_.isPlaying = true;
654
655 // 2. Call the function to be tested
656 bool result = playerServerMem_->IsPlaying();
657
658 // 3. Verify the result
659 EXPECT_TRUE(result);
660 sleep(1);
661 }
662
663 /**
664 * @tc.name : Test IsPlaying API
665 * @tc.number : IsPlaying_002
666 * @tc.desc : Test IsPlaying interface, set isLocalResource_ to true and isReleaseMemByManage_ to false.
667 * @tc.require : issueI5NZAQ
668 */
669 HWTEST_F(PlayerServerMemUnitTest, IsPlaying_002, TestSize.Level0)
670 {
671 // 1. Set up the test environment
672 playerServerMem_->isLocalResource_ = true;
673 playerServerMem_->isReleaseMemByManage_ = false;
674
675 // 2. Call the function to be tested
676 bool result = playerServerMem_->IsPlaying();
677
678 // 3. Verify the result
679 EXPECT_FALSE(result);
680 sleep(1);
681 }
682
683 /**
684 * @tc.name : Test IsLooping API
685 * @tc.number : IsLooping_001
686 * @tc.desc : Test IsLooping interface, set isLocalResource_ and isReleaseMemByManage_ to true.
687 * @tc.require : issueI5NZAQ
688 */
689 HWTEST_F(PlayerServerMemUnitTest, IsLooping_001, TestSize.Level0)
690 {
691 // 1. Set up the test environment
692 playerServerMem_->isLocalResource_ = true;
693 playerServerMem_->isReleaseMemByManage_ = true;
694 playerServerMem_->recoverConfig_.loop = true;
695
696 // 2. Call the function to be tested
697 bool result = playerServerMem_->IsLooping();
698
699 // 3. Verify the result
700 EXPECT_TRUE(result);
701 sleep(1);
702 }
703
704 /**
705 * @tc.name : Test IsLooping API
706 * @tc.number : IsLooping_002
707 * @tc.desc : Test IsLooping interface, set isLocalResource_ to true and isReleaseMemByManage_ to false.
708 * @tc.require : issueI5NZAQ
709 */
710 HWTEST_F(PlayerServerMemUnitTest, IsLooping_002, TestSize.Level0)
711 {
712 // 1. Set up the test environment
713 playerServerMem_->isLocalResource_ = true;
714 playerServerMem_->isReleaseMemByManage_ = false;
715
716 // 2. Call the function to be tested
717 bool result = playerServerMem_->IsLooping();
718
719 // 3. Verify the result
720 EXPECT_FALSE(result);
721 sleep(1);
722 }
723
724 /**
725 * @tc.name : Test SetSaveParameter API
726 * @tc.number : SetSaveParameter_001
727 * @tc.desc : Test SetSaveParameter interface, set videoScaleType to valid value.
728 * @tc.require : issueI5NZAQ
729 */
730 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_001, TestSize.Level0)
731 {
732 // 1. Set up the test environment
733 playerServerMem_->recoverConfig_.videoScaleType = 1;
734 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
735
736 // 2. Call the function to be tested
737 int32_t result = playerServerMem_->SetSaveParameter();
738
739 // 3. Verify the result
740 EXPECT_EQ(result, MSERR_OK);
741 sleep(1);
742 }
743
744 /**
745 * @tc.name : Test SetSaveParameter API
746 * @tc.number : SetSaveParameter_002
747 * @tc.desc : Test SetSaveParameter interface, set videoScaleType to invalid value.
748 * @tc.require : issueI5NZAQ
749 */
750 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_002, TestSize.Level0)
751 {
752 // 1. Set up the test environment
753 playerServerMem_->recoverConfig_.videoScaleType = -1;
754 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
755
756 // 2. Call the function to be tested
757 int32_t result = playerServerMem_->SetSaveParameter();
758
759 // 3. Verify the result
760 EXPECT_EQ(result, MSERR_OK);
761 sleep(1);
762 }
763
764 /**
765 * @tc.name : Test SetSaveParameter API
766 * @tc.number : SetSaveParameter_003
767 * @tc.desc : Test SetSaveParameter interface, set contentType and streamUsage to valid values.
768 * @tc.require : issueI5NZAQ
769 */
770 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_003, TestSize.Level0)
771 {
772 // 1. Set up the test environment
773 playerServerMem_->recoverConfig_.contentType = 1;
774 playerServerMem_->recoverConfig_.streamUsage = 1;
775 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
776 ;
777
778 // 2. Call the function to be tested
779 int32_t result = playerServerMem_->SetSaveParameter();
780
781 // 3. Verify the result
782 EXPECT_EQ(result, MSERR_OK);
783 sleep(1);
784 }
785
786 /**
787 * @tc.name : Test SetSaveParameter API
788 * @tc.number : SetSaveParameter_004
789 * @tc.desc : Test SetSaveParameter interface, set contentType or streamUsage to invalid values.
790 * @tc.require : issueI5NZAQ
791 */
792 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_004, TestSize.Level0)
793 {
794 // 1. Set up the test environment
795 playerServerMem_->recoverConfig_.contentType = -1;
796 playerServerMem_->recoverConfig_.streamUsage = 1;
797 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
798
799 // 2. Call the function to be tested
800 int32_t result = playerServerMem_->SetSaveParameter();
801
802 // 3. Verify the result
803 EXPECT_EQ(result, MSERR_OK);
804 sleep(1);
805 }
806
807 /**
808 * @tc.name : Test SetSaveParameter API
809 * @tc.number : SetSaveParameter_005
810 * @tc.desc : Test SetSaveParameter interface, set interruptMode to valid value.
811 * @tc.require : issueI5NZAQ
812 */
813 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_005, TestSize.Level0)
814 {
815 // 1. Set up the test environment
816 playerServerMem_->recoverConfig_.interruptMode = 1;
817 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
818
819 // 2. Call the function to be tested
820 int32_t result = playerServerMem_->SetSaveParameter();
821
822 // 3. Verify the result
823 EXPECT_EQ(result, MSERR_OK);
824 sleep(1);
825 }
826
827 /**
828 * @tc.name : Test SetSaveParameter API
829 * @tc.number : SetSaveParameter_006
830 * @tc.desc : Test SetSaveParameter interface, set interruptMode to invalid value.
831 * @tc.require : issueI5NZAQ
832 */
833 HWTEST_F(PlayerServerMemUnitTest, SetSaveParameter_006, TestSize.Level0)
834 {
835 // 1. Set up the test environment
836 playerServerMem_->recoverConfig_.interruptMode = -1;
837 playerServerMem_->playerEngine_ = std::make_unique<HiPlayerImpl>(0, 0, 0, 0);
838
839 // 2. Call the function to be tested
840 int32_t result = playerServerMem_->SetSaveParameter();
841
842 // 3. Verify the result
843 EXPECT_EQ(result, MSERR_OK);
844 sleep(1);
845 sleep(1);
846 }
847
848 HWTEST_F(PlayerServerMemUnitTest, SetPlaybackSpeedInternal_001, TestSize.Level0)
849 {
850 playerServerMem_->lastOpStatus_ = PLAYER_IDLE;
851 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_25_X;
852 EXPECT_EQ(playerServerMem_->SetPlaybackSpeedInternal(), MSERR_INVALID_OPERATION);
853 }
854
855 HWTEST_F(PlayerServerMemUnitTest, SetPlaybackSpeedInternal_002, TestSize.Level0)
856 {
857 playerServerMem_->lastOpStatus_ = PLAYER_IDLE;
858 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
859 playerServerMem_->defaultAudioIndex_ = 1;
860 EXPECT_EQ(playerServerMem_->SetPlaybackSpeedInternal(), MSERR_INVALID_OPERATION);
861 }
862
863 HWTEST_F(PlayerServerMemUnitTest, SetPlaybackSpeedInternal_003, TestSize.Level0)
864 {
865 playerServerMem_->lastOpStatus_ = PLAYER_IDLE;
866 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
867 playerServerMem_->defaultAudioIndex_ = -1;
868 EXPECT_EQ(playerServerMem_->SetPlaybackSpeedInternal(), MSERR_OK);
869 }
870
871 HWTEST_F(PlayerServerMemUnitTest, SetPlaybackSpeedInternal_004, TestSize.Level0)
872 {
873 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_00_X;
874 playerServerMem_->defaultAudioIndex_ = 1;
875 EXPECT_EQ(playerServerMem_->SetPlaybackSpeedInternal(), MSERR_INVALID_OPERATION);
876 }
877
878 // Scenario1: Test when trackType is MEDIA_TYPE_AUD, isLocalResource_ is true and isReleaseMemByManage_ is true.
879 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTrack_001, TestSize.Level0)
880 {
881 int32_t trackType = Media::MediaType::MEDIA_TYPE_AUD;
882 int32_t index = -1;
883 playerServerMem_->isLocalResource_ = true;
884 playerServerMem_->isReleaseMemByManage_ = true;
885 playerServerMem_->recoverConfig_.audioIndex = 1;
886 int32_t result = playerServerMem_->GetCurrentTrack(trackType, index);
887 ASSERT_EQ(result, MSERR_OK);
888 ASSERT_EQ(index, 1);
889 }
890
891 // Scenario2: Test when trackType is MEDIA_TYPE_VID, isLocalResource_ is true and isReleaseMemByManage_ is true.
892 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTrack_002, TestSize.Level0)
893 {
894 int32_t trackType = Media::MediaType::MEDIA_TYPE_VID;
895 int32_t index = -1;
896 playerServerMem_->isLocalResource_ = true;
897 playerServerMem_->isReleaseMemByManage_ = true;
898 playerServerMem_->recoverConfig_.videoIndex = 2;
899 int32_t result = playerServerMem_->GetCurrentTrack(trackType, index);
900 ASSERT_EQ(result, MSERR_OK);
901 ASSERT_EQ(index, 2);
902 }
903
904 // Scenario3: Test when trackType is MEDIA_TYPE_SUBTITLE, isLocalResource_ is true and isReleaseMemByManage_ is true.
905 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTrack_003, TestSize.Level0)
906 {
907 int32_t trackType = Media::MediaType::MEDIA_TYPE_SUBTITLE;
908 int32_t index = -1;
909 playerServerMem_->isLocalResource_ = true;
910 playerServerMem_->isReleaseMemByManage_ = true;
911 playerServerMem_->recoverConfig_.textIndex = 3;
912 int32_t result = playerServerMem_->GetCurrentTrack(trackType, index);
913 ASSERT_EQ(result, MSERR_OK);
914 ASSERT_EQ(index, 3);
915 }
916
917 // Scenario4: Test when trackType is invalid, isLocalResource_ is true and isReleaseMemByManage_ is true.
918 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTrack_004, TestSize.Level0)
919 {
920 int32_t trackType = 100;
921 int32_t index = -1;
922 playerServerMem_->isLocalResource_ = true;
923 playerServerMem_->isReleaseMemByManage_ = true;
924 int32_t result = playerServerMem_->GetCurrentTrack(trackType, index);
925 ASSERT_EQ(result, MSERR_INVALID_OPERATION);
926 }
927
928 // Scenario5: Test when isLocalResource_ is false or isReleaseMemByManage_ is false.
929 HWTEST_F(PlayerServerMemUnitTest, GetCurrentTrack_005, TestSize.Level0)
930 {
931 int32_t trackType = Media::MediaType::MEDIA_TYPE_AUD;
932 int32_t index = -1;
933 playerServerMem_->isLocalResource_ = false;
934 playerServerMem_->isReleaseMemByManage_ = false;
935 int32_t result = playerServerMem_->GetCurrentTrack(trackType, index);
936 ASSERT_NE(result, MSERR_OK);
937 }
938
939 HWTEST_F(PlayerServerMemUnitTest, LocalResourceRelease_001, TestSize.Level0)
940 {
941 playerServerMem_->isReleaseMemByManage_ = true;
942 EXPECT_EQ(playerServerMem_->LocalResourceRelease(), MSERR_OK);
943 }
944
945 HWTEST_F(PlayerServerMemUnitTest, RecoverToInitialized_001, TestSize.Level0)
946 {
947 playerServerMem_->RecoverToInitialized(INFO_TYPE_STATE_CHANGE, PLAYER_INITIALIZED);
948 playerServerMem_->RecoverToInitialized(INFO_TYPE_STATE_CHANGE, PLAYER_IDLE);
949 playerServerMem_->RecoverToInitialized(INFO_TYPE_EOS, PLAYER_INITIALIZED);
950 EXPECT_EQ(playerServerMem_->isRecoverMemByUser_, false);
951 }
952
953 HWTEST_F(PlayerServerMemUnitTest, RecoverToPrepared_001, TestSize.Level0)
954 {
955 playerServerMem_->defaultAudioIndex_ = 1;
956 playerServerMem_->RecoverToPrepared(INFO_TYPE_TRACKCHANGE, 0);
957
958 playerServerMem_->recoverConfig_.currentTime = 1;
959 playerServerMem_->RecoverToPrepared(INFO_TYPE_SEEKDONE, 0);
960
961 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_25_X;
962 playerServerMem_->RecoverToPrepared(INFO_TYPE_SPEEDDONE, 0);
963
964 EXPECT_EQ(playerServerMem_->isRecoverMemByUser_, false);
965 }
966
967 HWTEST_F(PlayerServerMemUnitTest, RecoverToCompleted_001, TestSize.Level0)
968 {
969 playerServerMem_->defaultAudioIndex_ = 1;
970 playerServerMem_->RecoverToCompleted(INFO_TYPE_TRACKCHANGE, 0);
971
972 playerServerMem_->RecoverToCompleted(INFO_TYPE_STATE_CHANGE, PLAYER_PREPARED);
973
974 playerServerMem_->recoverConfig_.speedMode = SPEED_FORWARD_1_25_X;
975 playerServerMem_->RecoverToCompleted(INFO_TYPE_SPEEDDONE, 0);
976
977 playerServerMem_->RecoverToCompleted(INFO_TYPE_BUFFERING_UPDATE, 0);
978 EXPECT_EQ(playerServerMem_->isRecoverMemByUser_, false);
979 }
980
981 HWTEST_F(PlayerServerMemUnitTest, ResetFrontGroundForMemManage_001, TestSize.Level0)
982 {
983 playerServerMem_->isAudioPlayer_ = false;
984 playerServerMem_->ResetFrontGroundForMemManage();
985 EXPECT_EQ(playerServerMem_->continueReset, 0);
986 }
987
988 HWTEST_F(PlayerServerMemUnitTest, ResetFrontGroundForMemManage_002, TestSize.Level0)
989 {
990 playerServerMem_->ResetFrontGroundForMemManage();
991 EXPECT_EQ(playerServerMem_->continueReset, 0);
992 }
993
994 HWTEST_F(PlayerServerMemUnitTest, ResetFrontGroundForMemManage_003, TestSize.Level0)
995 {
996 playerServerMem_->lastOpStatus_ = PLAYER_PREPARED;
997 playerServerMem_->isAudioPlayer_ = false;
998 playerServerMem_->continueReset = 4;
999 playerServerMem_->ResetFrontGroundForMemManage();
1000 EXPECT_EQ(playerServerMem_->continueReset, 5);
1001 }
1002
1003 HWTEST_F(PlayerServerMemUnitTest, ResetFrontGroundForMemManage_004, TestSize.Level0)
1004 {
1005 playerServerMem_->lastOpStatus_ = PLAYER_PREPARED;
1006 playerServerMem_->isAudioPlayer_ = false;
1007 playerServerMem_->continueReset = 5;
1008 playerServerMem_->ResetFrontGroundForMemManage();
1009 EXPECT_EQ(playerServerMem_->continueReset, 0);
1010 }
1011
1012 HWTEST_F(PlayerServerMemUnitTest, ResetBackGroundForMemManage_001, TestSize.Level0)
1013 {
1014 playerServerMem_->isAudioPlayer_ = true;
1015 playerServerMem_->ResetBackGroundForMemManage();
1016 EXPECT_EQ(playerServerMem_->continueReset, 0);
1017 }
1018
1019 HWTEST_F(PlayerServerMemUnitTest, ResetBackGroundForMemManage_002, TestSize.Level0)
1020 {
1021 playerServerMem_->isAudioPlayer_ = false;
1022 playerServerMem_->lastOpStatus_ = PLAYER_STARTED;
1023 playerServerMem_->ResetBackGroundForMemManage();
1024 EXPECT_EQ(playerServerMem_->continueReset, 0);
1025 }
1026
1027 HWTEST_F(PlayerServerMemUnitTest, ResetBackGroundForMemManage_003, TestSize.Level0)
1028 {
1029 playerServerMem_->lastOpStatus_ = PLAYER_PREPARED;
1030 playerServerMem_->isAudioPlayer_ = false;
1031 playerServerMem_->continueReset = 4; // 5 CONTINUE_RESET_MAX_NUM
1032 playerServerMem_->ResetBackGroundForMemManage();
1033 EXPECT_EQ(playerServerMem_->continueReset, 5);
1034 }
1035
1036 HWTEST_F(PlayerServerMemUnitTest, ResetBackGroundForMemManage_004, TestSize.Level0)
1037 {
1038 playerServerMem_->lastOpStatus_ = PLAYER_PREPARED;
1039 playerServerMem_->isAudioPlayer_ = false;
1040 playerServerMem_->continueReset = 5; // 5 CONTINUE_RESET_MAX_NUM
1041 playerServerMem_->ResetBackGroundForMemManage();
1042 EXPECT_EQ(playerServerMem_->continueReset, 0);
1043 }
1044
1045 // Scenario1: Test when type is INFO_TYPE_DEFAULTTRACK and mediaType is MEDIA_TYPE_AUD.
1046 HWTEST_F(PlayerServerMemUnitTest, GetDefaultTrack_001, TestSize.Level0)
1047 {
1048 PlayerOnInfoType type = INFO_TYPE_DEFAULTTRACK;
1049 int32_t extra = 0;
1050 Format infoBody;
1051 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_TYPE, 0); // 0 MEDIA_TYPE_AUD
1052 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_INDEX, 1);
1053 playerServerMem_->GetDefaultTrack(type, extra, infoBody);
1054 EXPECT_EQ(playerServerMem_->defaultAudioIndex_, 1);
1055 }
1056
1057 // Scenario2: Test when type is not INFO_TYPE_DEFAULTTRACK.
1058 HWTEST_F(PlayerServerMemUnitTest, GetDefaultTrack_002, TestSize.Level0)
1059 {
1060 PlayerOnInfoType type = INFO_TYPE_EOS;
1061 int32_t extra = 0;
1062 Format infoBody;
1063 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_TYPE, 0); // 0 MEDIA_TYPE_AUD
1064 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_INDEX, 1);
1065 playerServerMem_->GetDefaultTrack(type, extra, infoBody);
1066 EXPECT_NE(playerServerMem_->defaultAudioIndex_, 1);
1067 }
1068
1069 // Scenario3: Test when mediaType is not MEDIA_TYPE_AUD.
1070 HWTEST_F(PlayerServerMemUnitTest, GetDefaultTrack_003, TestSize.Level0)
1071 {
1072 PlayerOnInfoType type = INFO_TYPE_DEFAULTTRACK;
1073 int32_t extra = 0;
1074 Format infoBody;
1075 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_TYPE, 1); // 1 MEDIA_TYPE_VID
1076 infoBody.PutIntValue(PlayerKeys::PLAYER_TRACK_INDEX, 1);
1077 playerServerMem_->GetDefaultTrack(type, extra, infoBody);
1078 EXPECT_NE(playerServerMem_->defaultAudioIndex_, 1);
1079 }
1080 } // namespace Media
1081 } // namespace OHOS