1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "accesstoken_kit.h"
19 #include "bool_wrapper.h"
20 #include "nativetoken_kit.h"
21 #include "token_setproc.h"
22 #include "want_agent.h"
23 #include "avcast_control_command.h"
24 #include "avcast_controller_item.h"
25 #include "avmedia_description.h"
26 #include "avmeta_data.h"
27 #include "avplayback_state.h"
28 #include "avqueue_item.h"
29 #include "avsession_manager.h"
30 #include "avsession_errors.h"
31 #include "avsession_log.h"
32 #include "hw_cast_stream_player.h"
33 #include "iavcast_controller.h"
34 #define private public
35 #include "hw_cast_provider.h"
36 #undef private
37 
38 using namespace testing::ext;
39 using namespace OHOS::Security::AccessToken;
40 
41 namespace OHOS {
42 namespace AVSession {
43 static int32_t g_onCall = AVSESSION_ERROR;
44 static int32_t g_sessionId = AVSESSION_ERROR;
45 static AVMetaData g_metaData;
46 static AVPlaybackState g_playbackState;
47 static char g_testSessionTag[] = "test";
48 static char g_testBundleName[] = "test.ohos.avsession";
49 static char g_testAbilityName[] = "test.ability";
50 static uint64_t g_selfTokenId = 0;
51 
52 static HapInfoParams g_info = {
53     .userID = 100,
54     .bundleName = "ohos.permission_test.demo",
55     .instIndex = 0,
56     .appIDDesc = "ohos.permission_test.demo",
57     .isSystemApp = true
58 };
59 
60 static HapPolicyParams g_policy = {
61     .apl = APL_NORMAL,
62     .domain = "test.domain",
63     .permList = {
64         {
65             .permissionName = "ohos.permission.MANAGE_MEDIA_RESOURCES",
66             .bundleName = "ohos.permission_test.demo",
67             .grantMode = 1,
68             .availableLevel = APL_NORMAL,
69             .label = "label",
70             .labelId = 1,
71             .description = "test",
72             .descriptionId = 1
73         }
74     },
75     .permStateList = {
76         {
77             .permissionName = "ohos.permission.MANAGE_MEDIA_RESOURCES",
78             .isGeneral = true,
79             .resDeviceID = { "local" },
80             .grantStatus = { PermissionState::PERMISSION_GRANTED },
81             .grantFlags = { 1 }
82         }
83     }
84 };
85 
86 class AVCastControllerTest : public testing::Test {
87 public:
88     static void SetUpTestCase();
89     static void TearDownTestCase();
90     void SetUp() override;
91     void TearDown() override;
92 
93     std::shared_ptr<AVSession> avsession_ = nullptr;
94     std::shared_ptr<AVSessionController> controller_ = nullptr;
95     std::shared_ptr<AVCastControllerItem> castController_ = std::make_shared<AVCastControllerItem>();
96     std::vector<int32_t> supportedCastCmd_;
97 
98     static constexpr int SESSION_LEN = 64;
99 };
100 
SetUpTestCase()101 void AVCastControllerTest::SetUpTestCase()
102 {
103     g_selfTokenId = GetSelfTokenID();
104     AccessTokenKit::AllocHapToken(g_info, g_policy);
105     AccessTokenIDEx tokenID = AccessTokenKit::GetHapTokenIDEx(g_info.userID, g_info.bundleName, g_info.instIndex);
106     SetSelfTokenID(tokenID.tokenIDEx);
107 }
108 
TearDownTestCase()109 void AVCastControllerTest::TearDownTestCase()
110 {
111     SetSelfTokenID(g_selfTokenId);
112     auto tokenId = AccessTokenKit::GetHapTokenID(g_info.userID, g_info.bundleName, g_info.instIndex);
113     AccessTokenKit::DeleteToken(tokenId);
114 }
115 
SetUp()116 void AVCastControllerTest::SetUp()
117 {
118     OHOS::AppExecFwk::ElementName elementName;
119     elementName.SetBundleName(g_testBundleName);
120     elementName.SetAbilityName(g_testAbilityName);
121     avsession_ = AVSessionManager::GetInstance().CreateSession(g_testSessionTag, AVSession::SESSION_TYPE_AUDIO,
122                                                                elementName);
123     ASSERT_NE(avsession_, nullptr);
124     g_sessionId++;
125     auto ret = AVSessionManager::GetInstance().CreateController(avsession_->GetSessionId(), controller_);
126     ASSERT_EQ(ret, AVSESSION_SUCCESS);
127     ASSERT_NE(controller_, nullptr);
128 
129     std::shared_ptr<HwCastStreamPlayer> HwCastStreamPlayer_ = std::make_shared<HwCastStreamPlayer>(nullptr);
130     auto validCallback = [this](int32_t cmd, std::vector<int32_t>& supportedCastCmds) {
131         SLOGI("add cast valid command %{public}d", cmd);
132         supportedCastCmds = supportedCastCmd_;
133         return;
134     };
135     auto preparecallback = []() {
136         SLOGI("prepare callback");
137     };
138     castController_->Init(HwCastStreamPlayer_, validCallback, preparecallback);
139 }
140 
TearDown()141 void AVCastControllerTest::TearDown()
142 {
143     [[maybe_unused]] int32_t ret = AVSESSION_ERROR;
144     if (avsession_ != nullptr) {
145         ret = avsession_->Destroy();
146         avsession_ = nullptr;
147     }
148     if (controller_ != nullptr) {
149         ret = controller_->Destroy();
150         controller_ = nullptr;
151     }
152     g_onCall = AVSESSION_ERROR;
153 }
154 
155 class AVCastControllerCallbackImpl : public AVCastControllerCallback {
156 public:
157     void OnCastPlaybackStateChange(const AVPlaybackState& state) override;
158 
159     void OnMediaItemChange(const AVQueueItem& avQueueItem) override;
160 
161     void OnPlayNext() override;
162 
163     void OnPlayPrevious() override;
164 
165     void OnSeekDone(const int32_t seekNumber) override;
166 
167     void OnVideoSizeChange(const int32_t width, const int32_t height) override;
168 
169     void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) override;
170 
171     void OnCastValidCommandChanged(const std::vector<int32_t> &cmds) override;
172 
173     ~AVCastControllerCallbackImpl() override;
174 
175     AVPlaybackState state_;
176     AVQueueItem avQueueItem_;
177     int32_t seekNumber_;
178     int32_t width_;
179     int32_t height_;
180     int32_t errorCode_;
181     std::string errorMsg_;
182 };
183 
~AVCastControllerCallbackImpl()184 AVCastControllerCallbackImpl::~AVCastControllerCallbackImpl()
185 {
186 }
187 
OnCastPlaybackStateChange(const AVPlaybackState & state)188 void AVCastControllerCallbackImpl::OnCastPlaybackStateChange(const AVPlaybackState& state)
189 {
190     state_ = state;
191 }
192 
OnMediaItemChange(const AVQueueItem & avQueueItem)193 void AVCastControllerCallbackImpl::OnMediaItemChange(const AVQueueItem& avQueueItem)
194 {
195     avQueueItem_ = avQueueItem;
196 }
197 
OnPlayNext()198 void AVCastControllerCallbackImpl::OnPlayNext()
199 {
200 }
201 
OnPlayPrevious()202 void AVCastControllerCallbackImpl::OnPlayPrevious()
203 {
204 }
205 
OnSeekDone(const int32_t seekNumber)206 void AVCastControllerCallbackImpl::OnSeekDone(const int32_t seekNumber)
207 {
208     seekNumber_ = seekNumber;
209 }
210 
OnVideoSizeChange(const int32_t width,const int32_t height)211 void AVCastControllerCallbackImpl::OnVideoSizeChange(const int32_t width, const int32_t height)
212 {
213     width_ = width;
214     height_ = height;
215 }
216 
OnPlayerError(const int32_t errorCode,const std::string & errorMsg)217 void AVCastControllerCallbackImpl::OnPlayerError(const int32_t errorCode, const std::string& errorMsg)
218 {
219     errorCode_ = errorCode;
220     errorMsg_ = errorMsg;
221 }
222 
OnCastValidCommandChanged(const std::vector<int32_t> & cmds)223 void AVCastControllerCallbackImpl::OnCastValidCommandChanged(const std::vector<int32_t> &cmds)
224 {
225 }
226 
227 /**
228 * @tc.name: SendControlCommand001
229 * @tc.desc: send command, check if AVCastControlCommand is invalid
230 * @tc.type: FUNC
231 * @tc.require:
232 */
233 HWTEST_F(AVCastControllerTest, SendControlCommand001, TestSize.Level1)
234 {
235     AVCastControlCommand command;
236     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_INVALID), ERR_INVALID_PARAM);
237     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_MAX), ERR_INVALID_PARAM);
238     EXPECT_EQ(command.SetForwardTime(0), ERR_INVALID_PARAM);
239     EXPECT_EQ(command.SetRewindTime(-1), ERR_INVALID_PARAM);
240     EXPECT_EQ(command.SetSeekTime(-1), ERR_INVALID_PARAM);
241     EXPECT_EQ(command.SetSpeed(-1), ERR_INVALID_PARAM);
242     EXPECT_EQ(command.SetLoopMode(-1), ERR_INVALID_PARAM);
243 }
244 
245 /**
246 * @tc.name: SendControlCommand002
247 * @tc.desc: send command, check if AVCastControlCommand is invalid
248 * @tc.type: FUNC
249 * @tc.require:
250 */
251 HWTEST_F(AVCastControllerTest, SendControlCommand002, TestSize.Level1)
252 {
253     AVCastControlCommand command;
254     int32_t mode = -1;
255     OHOS::Parcel parcel;
256     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE), AVSESSION_SUCCESS);
257     EXPECT_EQ(command.SetLoopMode(AVPlaybackState::LOOP_MODE_SEQUENCE), AVSESSION_SUCCESS);
258     EXPECT_EQ(command.Marshalling(parcel), true);
259     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
260     EXPECT_NE(ret, nullptr);
261     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE);
262     EXPECT_EQ(ret->GetLoopMode(mode), AVSESSION_SUCCESS);
263     EXPECT_EQ(mode, AVPlaybackState::LOOP_MODE_SEQUENCE);
264     delete ret;
265 }
266 
267 /**
268 * @tc.name: SendControlCommand003
269 * @tc.desc: send command, check if AVCastControlCommand is invalid
270 * @tc.type: FUNC
271 * @tc.require:
272 */
273 HWTEST_F(AVCastControllerTest, SendControlCommand003, TestSize.Level1)
274 {
275     AVCastControlCommand command;
276     int32_t speed = -1;
277     OHOS::Parcel parcel;
278     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED), AVSESSION_SUCCESS);
279     EXPECT_EQ(command.SetSpeed(1), AVSESSION_SUCCESS);
280     EXPECT_EQ(command.Marshalling(parcel), true);
281     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
282     EXPECT_NE(ret, nullptr);
283     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED);
284     EXPECT_EQ(ret->GetSpeed(speed), AVSESSION_SUCCESS);
285     EXPECT_EQ(speed, 1);
286     delete ret;
287 }
288 
289 /**
290 * @tc.name: SendControlCommand004
291 * @tc.desc: send command, check if AVCastControlCommand is invalid
292 * @tc.type: FUNC
293 * @tc.require:
294 */
295 HWTEST_F(AVCastControllerTest, SendControlCommand004, TestSize.Level1)
296 {
297     AVCastControlCommand command;
298     int32_t volumn = -1;
299     OHOS::Parcel parcel;
300     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME), AVSESSION_SUCCESS);
301     EXPECT_EQ(command.SetVolume(1), AVSESSION_SUCCESS);
302     EXPECT_EQ(command.Marshalling(parcel), true);
303     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
304     EXPECT_NE(ret, nullptr);
305     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME);
306     EXPECT_EQ(ret->GetVolume(volumn), AVSESSION_SUCCESS);
307     EXPECT_EQ(volumn, 1);
308     delete ret;
309 }
310 
311 /**
312 * @tc.name: SendControlCommand005
313 * @tc.desc: send command, check if AVCastControlCommand is invalid
314 * @tc.type: FUNC
315 * @tc.require:
316 */
317 HWTEST_F(AVCastControllerTest, SendControlCommand005, TestSize.Level1)
318 {
319     AVCastControlCommand command;
320     int32_t seek = -1;
321     OHOS::Parcel parcel;
322     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SEEK), AVSESSION_SUCCESS);
323     EXPECT_EQ(command.SetSeekTime(1), AVSESSION_SUCCESS);
324     EXPECT_EQ(command.Marshalling(parcel), true);
325     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
326     EXPECT_NE(ret, nullptr);
327     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SEEK);
328     EXPECT_EQ(ret->GetSeekTime(seek), AVSESSION_SUCCESS);
329     EXPECT_EQ(seek, 1);
330     delete ret;
331 }
332 
333 /**
334 * @tc.name: SendControlCommand006
335 * @tc.desc: send command, check if AVCastControlCommand is invalid
336 * @tc.type: FUNC
337 * @tc.require:
338 */
339 HWTEST_F(AVCastControllerTest, SendControlCommand006, TestSize.Level1)
340 {
341     AVCastControlCommand command;
342     int32_t rewind = -1;
343     OHOS::Parcel parcel;
344     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_REWIND), AVSESSION_SUCCESS);
345     EXPECT_EQ(command.SetRewindTime(1), AVSESSION_SUCCESS);
346     EXPECT_EQ(command.Marshalling(parcel), true);
347     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
348     EXPECT_NE(ret, nullptr);
349     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_REWIND);
350     EXPECT_EQ(ret->GetRewindTime(rewind), AVSESSION_SUCCESS);
351     EXPECT_EQ(rewind, 1);
352     delete ret;
353 }
354 
355 /**
356 * @tc.name: SendControlCommand007
357 * @tc.desc: send command, check if AVCastControlCommand is invalid
358 * @tc.type: FUNC
359 * @tc.require:
360 */
361 HWTEST_F(AVCastControllerTest, SendControlCommand007, TestSize.Level1)
362 {
363     AVCastControlCommand command;
364     int32_t forward = -1;
365     OHOS::Parcel parcel;
366     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD), AVSESSION_SUCCESS);
367     EXPECT_EQ(command.SetForwardTime(1), AVSESSION_SUCCESS);
368     EXPECT_EQ(command.Marshalling(parcel), true);
369     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
370     EXPECT_NE(ret, nullptr);
371     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD);
372     EXPECT_EQ(ret->GetForwardTime(forward), AVSESSION_SUCCESS);
373     EXPECT_EQ(forward, 1);
374     delete ret;
375 }
376 
377 /**
378 * @tc.name: SendControlCommand008
379 * @tc.desc: send command, check if AVCastControlCommand is invalid
380 * @tc.type: FUNC
381 * @tc.require:
382 */
383 HWTEST_F(AVCastControllerTest, SendControlCommand008, TestSize.Level1)
384 {
385     AVCastControlCommand command;
386     EXPECT_EQ(castController_->SendControlCommand(command), AVSESSION_SUCCESS);
387 }
388 
389 /**
390 * @tc.name: Start001
391 * @tc.desc: Start
392 * @tc.type: FUNC
393 * @tc.require:
394 */
395 HWTEST_F(AVCastControllerTest, Start001, TestSize.Level1)
396 {
397     AVQueueItem avQueueItem;
398     std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
399     description->SetMediaId("123");
400     description->SetTitle("Title");
401     description->SetSubtitle("Subtitle");
402     description->SetDescription("This is music description");
403     description->SetIcon(nullptr);
404     description->SetIconUri("xxxxx");
405     description->SetExtras(nullptr);
406     description->SetMediaUri("Media url");
407     avQueueItem.SetDescription(description);
408     EXPECT_EQ(castController_->Start(avQueueItem), AVSESSION_SUCCESS);
409 }
410 
411 /**
412 * @tc.name: Prepare001
413 * @tc.desc: Prepare
414 * @tc.type: FUNC
415 * @tc.require:
416 */
417 HWTEST_F(AVCastControllerTest, Prepare001, TestSize.Level1)
418 {
419     AVQueueItem avQueueItem;
420     std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
421     description->SetMediaId("123");
422     description->SetTitle("Title");
423     description->SetSubtitle("Subtitle");
424     description->SetDescription("This is music description");
425     description->SetIcon(nullptr);
426     description->SetIconUri("xxxxx");
427     description->SetExtras(nullptr);
428     description->SetMediaUri("Media url");
429     avQueueItem.SetDescription(description);
430     EXPECT_EQ(castController_->Prepare(avQueueItem), AVSESSION_SUCCESS);
431 }
432 
433 /**
434 * @tc.name: GetDuration001
435 * @tc.desc: GetDuration
436 * @tc.type: FUNC
437 * @tc.require:
438 */
439 HWTEST_F(AVCastControllerTest, GetDuration001, TestSize.Level1)
440 {
441     int32_t duration;
442     EXPECT_EQ(castController_->GetDuration(duration), AVSESSION_ERROR);
443 }
444 
445 /**
446 * @tc.name: GetCastAVPlaybackState001
447 * @tc.desc: GetCastAVPlaybackState
448 * @tc.type: FUNC
449 * @tc.require:
450 */
451 HWTEST_F(AVCastControllerTest, GetCastAVPlaybackState001, TestSize.Level1)
452 {
453     AVPlaybackState avPlaybackState;
454     EXPECT_EQ(castController_->GetCastAVPlaybackState(avPlaybackState), AVSESSION_ERROR);
455 }
456 
457 /**
458 * @tc.name: GetCurrentItem001
459 * @tc.desc: GetCurrentItem
460 * @tc.type: FUNC
461 * @tc.require:
462 */
463 HWTEST_F(AVCastControllerTest, GetCurrentItem001, TestSize.Level1)
464 {
465     AVQueueItem currentItem;
466     EXPECT_EQ(castController_->GetCurrentItem(currentItem), AVSESSION_SUCCESS);
467 }
468 
469 /**
470 * @tc.name: GetValidCommands001
471 * @tc.desc: GetValidCommands
472 * @tc.type: FUNC
473 * @tc.require:
474 */
475 HWTEST_F(AVCastControllerTest, GetValidCommands001, TestSize.Level1)
476 {
477     std::vector<int32_t> cmds;
478     EXPECT_EQ(castController_->GetValidCommands(cmds), AVSESSION_SUCCESS);
479 }
480 
481 /**
482 * @tc.name: SetDisplaySurface001
483 * @tc.desc: SetDisplaySurface
484 * @tc.type: FUNC
485 * @tc.require:
486 */
487 HWTEST_F(AVCastControllerTest, SetDisplaySurface001, TestSize.Level1)
488 {
489     std::string surfaceId = "surfaceId";
490     EXPECT_EQ(castController_->SetDisplaySurface(surfaceId), AVSESSION_ERROR);
491 }
492 
493 /**
494 * @tc.name: ProcessMediaKeyResponse001
495 * @tc.desc: ProcessMediaKeyResponse
496 * @tc.type: FUNC
497 * @tc.require:
498 */
499 HWTEST_F(AVCastControllerTest, ProcessMediaKeyResponse001, TestSize.Level1)
500 {
501     std::string assetId = "assetId";
502     std::vector<uint8_t> response;
503     EXPECT_EQ(castController_->ProcessMediaKeyResponse(assetId, response), AVSESSION_ERROR);
504 }
505 
506 /**
507 * @tc.name: SetCastPlaybackFilter001
508 * @tc.desc: SetCastPlaybackFilter
509 * @tc.type: FUNC
510 * @tc.require:
511 */
512 HWTEST_F(AVCastControllerTest, SetCastPlaybackFilter001, TestSize.Level1)
513 {
514     AVPlaybackState::PlaybackStateMaskType filter;
515     EXPECT_EQ(castController_->SetCastPlaybackFilter(filter), AVSESSION_SUCCESS);
516 }
517 
518 /**
519 * @tc.name: AddAvailableCommand001
520 * @tc.desc: AddAvailableCommand
521 * @tc.type: FUNC
522 * @tc.require:
523 */
524 HWTEST_F(AVCastControllerTest, AddAvailableCommand001, TestSize.Level1)
525 {
526     EXPECT_EQ(castController_->AddAvailableCommand(0), AVSESSION_SUCCESS);
527 }
528 
529 /**
530 * @tc.name: RemoveAvailableCommand001
531 * @tc.desc: RemoveAvailableCommand
532 * @tc.type: FUNC
533 * @tc.require:
534 */
535 HWTEST_F(AVCastControllerTest, RemoveAvailableCommand001, TestSize.Level1)
536 {
537     EXPECT_EQ(castController_->AddAvailableCommand(0), AVSESSION_SUCCESS);
538     EXPECT_EQ(castController_->RemoveAvailableCommand(0), AVSESSION_SUCCESS);
539 }
540 
541 /**
542 * @tc.name: RegisterControllerListener001
543 * @tc.desc: RegisterControllerListener
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(AVCastControllerTest, RegisterControllerListener001, TestSize.Level1)
548 {
549     std::shared_ptr<IAVCastControllerProxy> castControllerProxy = nullptr;
550     EXPECT_EQ(castController_->RegisterControllerListener(castControllerProxy), true);
551 }
552 
553 /**
554 * @tc.name: Destroy001
555 * @tc.desc: Destroy
556 * @tc.type: FUNC
557 * @tc.require:
558 */
559 HWTEST_F(AVCastControllerTest, Destroy001, TestSize.Level1)
560 {
561     EXPECT_EQ(castController_->Destroy(), AVSESSION_SUCCESS);
562 }
563 
564 /**
565 * @tc.name: OnCastPlaybackStateChange001
566 * @tc.desc: OnCastPlaybackStateChange, no callback
567 * @tc.type: FUNC
568 * @tc.require:
569 */
570 HWTEST_F(AVCastControllerTest, OnCastPlaybackStateChange001, TestSize.Level1)
571 {
572     AVPlaybackState state;
573     castController_->OnCastPlaybackStateChange(state);
574 }
575 
576 /**
577 * @tc.name: OnMediaItemChange001
578 * @tc.desc: OnMediaItemChange, no callback
579 * @tc.type: FUNC
580 * @tc.require:
581 */
582 HWTEST_F(AVCastControllerTest, OnMediaItemChange001, TestSize.Level1)
583 {
584     AVQueueItem avQueueItem;
585     castController_->OnMediaItemChange(avQueueItem);
586 }
587 
588 /**
589 * @tc.name: OnPlayNext001
590 * @tc.desc: OnPlayNext, no callback
591 * @tc.type: FUNC
592 * @tc.require:
593 */
594 HWTEST_F(AVCastControllerTest, OnPlayNext001, TestSize.Level1)
595 {
596     castController_->OnPlayNext();
597 }
598 
599 /**
600 * @tc.name: OnPlayPrevious001
601 * @tc.desc: OnPlayPrevious, no callback
602 * @tc.type: FUNC
603 * @tc.require:
604 */
605 HWTEST_F(AVCastControllerTest, OnPlayPrevious001, TestSize.Level1)
606 {
607     castController_->OnPlayPrevious();
608 }
609 
610 /**
611 * @tc.name: OnSeekDone001
612 * @tc.desc: OnSeekDone, no callback
613 * @tc.type: FUNC
614 * @tc.require:
615 */
616 HWTEST_F(AVCastControllerTest, OnSeekDone001, TestSize.Level1)
617 {
618     int32_t seekNumber = 0;
619     castController_->OnSeekDone(seekNumber);
620 }
621 
622 /**
623 * @tc.name: OnVideoSizeChange001
624 * @tc.desc: OnVideoSizeChange, no callback
625 * @tc.type: FUNC
626 * @tc.require:
627 */
628 HWTEST_F(AVCastControllerTest, OnVideoSizeChange001, TestSize.Level1)
629 {
630     int32_t width = 0;
631     int32_t height = 0;
632     castController_->OnVideoSizeChange(width, height);
633 }
634 
635 /**
636 * @tc.name: OnPlayerError001
637 * @tc.desc: OnPlayerError, no callback
638 * @tc.type: FUNC
639 * @tc.require:
640 */
641 HWTEST_F(AVCastControllerTest, OnPlayerError001, TestSize.Level1)
642 {
643     int32_t errorCode = 0;
644     std::string errorMsg = "errorMsg";
645     castController_->OnPlayerError(errorCode, errorMsg);
646 }
647 
648 /**
649 * @tc.name: StartCastDiscovery001
650 * @tc.desc: StartCastDiscovery
651 * @tc.type: FUNC
652 * @tc.require:
653 */
654 HWTEST_F(AVCastControllerTest, StartCastDiscovery001, TestSize.Level1)
655 {
656     EXPECT_EQ(AVSessionManager::GetInstance().StartCastDiscovery(1, {}), AVSESSION_SUCCESS);
657 }
658 
659 /**
660 * @tc.name: StopCastDiscovery001
661 * @tc.desc: StopCastDiscovery
662 * @tc.type: FUNC
663 * @tc.require:
664 */
665 HWTEST_F(AVCastControllerTest, StopCastDiscovery001, TestSize.Level1)
666 {
667     EXPECT_EQ(AVSessionManager::GetInstance().StopCastDiscovery(), AVSESSION_SUCCESS);
668 }
669 
670 /**
671 * @tc.name: SetDiscoverable001
672 * @tc.desc: SetDiscoverable
673 * @tc.type: FUNC
674 * @tc.require:
675 */
676 HWTEST_F(AVCastControllerTest, SetDiscoverable001, TestSize.Level1)
677 {
678     EXPECT_EQ(AVSessionManager::GetInstance().SetDiscoverable(true), AVSESSION_SUCCESS);
679 }
680 
681 /**
682 * @tc.name: StartCast001
683 * @tc.desc: StartCast
684 * @tc.type: FUNC
685 * @tc.require:
686 */
687 HWTEST_F(AVCastControllerTest, StartCast001, TestSize.Level1)
688 {
689     SessionToken sessionToken;
690     sessionToken.sessionId = avsession_->GetSessionId();
691     OutputDeviceInfo outputDeviceInfo;
692     DeviceInfo deviceInfo;
693     deviceInfo.castCategory_ = 1;
694     deviceInfo.deviceId_ = "deviceId";
695     outputDeviceInfo.deviceInfos_.push_back(deviceInfo);
696     EXPECT_EQ(AVSessionManager::GetInstance().StartCast(sessionToken, outputDeviceInfo), -1007);
697 }
698 
699 /**
700 * @tc.name: StopCast001
701 * @tc.desc: StopCast
702 * @tc.type: FUNC
703 * @tc.require:
704 */
705 HWTEST_F(AVCastControllerTest, StopCast001, TestSize.Level1)
706 {
707     SessionToken sessionToken;
708     sessionToken.sessionId = avsession_->GetSessionId();
709     EXPECT_EQ(AVSessionManager::GetInstance().StopCast(sessionToken), AVSESSION_SUCCESS);
710 }
711 
712 HWTEST_F(AVCastControllerTest, StartDiscovery001, TestSize.Level1)
713 {
714     HwCastProvider hwCastProvider;
715     std::vector<std::string> drmSchemes;
716     EXPECT_EQ(hwCastProvider.StartDiscovery(2, drmSchemes), true);
717 }
718 
719 HWTEST_F(AVCastControllerTest, StopDiscovery001, TestSize.Level1)
720 {
721     HwCastProvider hwCastProvider;
722     hwCastProvider.StopDiscovery();
723     EXPECT_TRUE(true);
724 }
725 
726 HWTEST_F(AVCastControllerTest, Release001, TestSize.Level1)
727 {
728     HwCastProvider hwCastProvider;
729     hwCastProvider.Release();
730     EXPECT_TRUE(true);
731 }
732 
733 HWTEST_F(AVCastControllerTest, StartCastSession001, TestSize.Level1)
734 {
735     HwCastProvider hwCastProvider;
736     EXPECT_EQ(hwCastProvider.StartCastSession(), AVSESSION_SUCCESS);
737 }
738 
739 HWTEST_F(AVCastControllerTest, StopCastSession001, TestSize.Level1)
740 {
741     HwCastProvider hwCastProvider;
742     hwCastProvider.StopCastSession(2);
743     EXPECT_TRUE(true);
744 }
745 
746 HWTEST_F(AVCastControllerTest, AddCastDevice001, TestSize.Level1)
747 {
748     HwCastProvider hwCastProvider;
749 
750     DeviceInfo deviceInfo1;
751     deviceInfo1.castCategory_ = 1;
752     deviceInfo1.deviceId_ = "deviceid1";
753     deviceInfo1.deviceName_ = "devicename1";
754     deviceInfo1.deviceType_ = 1;
755     deviceInfo1.ipAddress_ = "ipAddress1";
756     deviceInfo1.providerId_ = 1;
757     deviceInfo1.supportedProtocols_ = 3;
758     deviceInfo1.authenticationStatus_ = 1;
759     std::vector<std::string> supportedDrmCapabilities;
760     supportedDrmCapabilities.emplace_back("");
761     deviceInfo1.supportedDrmCapabilities_ = supportedDrmCapabilities;
762     deviceInfo1.isLegacy_ = false;
763     deviceInfo1.mediumTypes_ = 2;
764 
765     EXPECT_EQ(hwCastProvider.AddCastDevice(1, deviceInfo1), false);
766 }
767 
768 HWTEST_F(AVCastControllerTest, RemoveCastDevice001, TestSize.Level1)
769 {
770     HwCastProvider hwCastProvider;
771 
772     DeviceInfo deviceInfo1;
773     deviceInfo1.castCategory_ = 1;
774     deviceInfo1.deviceId_ = "deviceid1";
775     deviceInfo1.deviceName_ = "devicename1";
776     deviceInfo1.deviceType_ = 1;
777     deviceInfo1.ipAddress_ = "ipAddress1";
778     deviceInfo1.providerId_ = 1;
779     deviceInfo1.supportedProtocols_ = 1;
780     deviceInfo1.authenticationStatus_ = 0;
781     std::vector<std::string> supportedDrmCapabilities;
782     supportedDrmCapabilities.emplace_back("");
783     deviceInfo1.supportedDrmCapabilities_ = supportedDrmCapabilities;
784     deviceInfo1.isLegacy_ = false;
785     deviceInfo1.mediumTypes_ = 2;
786 
787     EXPECT_EQ(hwCastProvider.RemoveCastDevice(1, deviceInfo1), false);
788 }
789 
790 HWTEST_F(AVCastControllerTest, RegisterCastStateListener001, TestSize.Level1)
791 {
792     HwCastProvider hwCastProvider;
793 
794     EXPECT_EQ(hwCastProvider.RegisterCastStateListener(nullptr), false);
795 }
796 
797 HWTEST_F(AVCastControllerTest, UnRegisterCastStateListener001, TestSize.Level1)
798 {
799     HwCastProvider hwCastProvider;
800 
801     EXPECT_EQ(hwCastProvider.UnRegisterCastStateListener(nullptr), false);
802 }
803 
804 HWTEST_F(AVCastControllerTest, RegisterCastSessionStateListener001, TestSize.Level1)
805 {
806     HwCastProvider hwCastProvider;
807 
808     EXPECT_EQ(hwCastProvider.RegisterCastSessionStateListener(2, nullptr), false);
809 }
810 
811 HWTEST_F(AVCastControllerTest, UnRegisterCastSessionStateListener001, TestSize.Level1)
812 {
813     HwCastProvider hwCastProvider;
814 
815     EXPECT_EQ(hwCastProvider.UnRegisterCastSessionStateListener(2, nullptr), false);
816 }
817 } // namespace AVSession
818 } // namespace OHOS