• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 callback = [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     castController_->Init(HwCastStreamPlayer_, callback);
136 }
137 
TearDown()138 void AVCastControllerTest::TearDown()
139 {
140     [[maybe_unused]] int32_t ret = AVSESSION_ERROR;
141     if (avsession_ != nullptr) {
142         ret = avsession_->Destroy();
143         avsession_ = nullptr;
144     }
145     if (controller_ != nullptr) {
146         ret = controller_->Destroy();
147         controller_ = nullptr;
148     }
149     g_onCall = AVSESSION_ERROR;
150 }
151 
152 class AVCastControllerCallbackImpl : public AVCastControllerCallback {
153 public:
154     void OnCastPlaybackStateChange(const AVPlaybackState& state) override;
155 
156     void OnMediaItemChange(const AVQueueItem& avQueueItem) override;
157 
158     void OnPlayNext() override;
159 
160     void OnPlayPrevious() override;
161 
162     void OnSeekDone(const int32_t seekNumber) override;
163 
164     void OnVideoSizeChange(const int32_t width, const int32_t height) override;
165 
166     void OnPlayerError(const int32_t errorCode, const std::string& errorMsg) override;
167 
168     void OnCastValidCommandChanged(const std::vector<int32_t> &cmds) override;
169 
170     ~AVCastControllerCallbackImpl() override;
171 
172     AVPlaybackState state_;
173     AVQueueItem avQueueItem_;
174     int32_t seekNumber_;
175     int32_t width_;
176     int32_t height_;
177     int32_t errorCode_;
178     std::string errorMsg_;
179 };
180 
~AVCastControllerCallbackImpl()181 AVCastControllerCallbackImpl::~AVCastControllerCallbackImpl()
182 {
183 }
184 
OnCastPlaybackStateChange(const AVPlaybackState & state)185 void AVCastControllerCallbackImpl::OnCastPlaybackStateChange(const AVPlaybackState& state)
186 {
187     state_ = state;
188 }
189 
OnMediaItemChange(const AVQueueItem & avQueueItem)190 void AVCastControllerCallbackImpl::OnMediaItemChange(const AVQueueItem& avQueueItem)
191 {
192     avQueueItem_ = avQueueItem;
193 }
194 
OnPlayNext()195 void AVCastControllerCallbackImpl::OnPlayNext()
196 {
197 }
198 
OnPlayPrevious()199 void AVCastControllerCallbackImpl::OnPlayPrevious()
200 {
201 }
202 
OnSeekDone(const int32_t seekNumber)203 void AVCastControllerCallbackImpl::OnSeekDone(const int32_t seekNumber)
204 {
205     seekNumber_ = seekNumber;
206 }
207 
OnVideoSizeChange(const int32_t width,const int32_t height)208 void AVCastControllerCallbackImpl::OnVideoSizeChange(const int32_t width, const int32_t height)
209 {
210     width_ = width;
211     height_ = height;
212 }
213 
OnPlayerError(const int32_t errorCode,const std::string & errorMsg)214 void AVCastControllerCallbackImpl::OnPlayerError(const int32_t errorCode, const std::string& errorMsg)
215 {
216     errorCode_ = errorCode;
217     errorMsg_ = errorMsg;
218 }
219 
OnCastValidCommandChanged(const std::vector<int32_t> & cmds)220 void AVCastControllerCallbackImpl::OnCastValidCommandChanged(const std::vector<int32_t> &cmds)
221 {
222 }
223 
224 /**
225 * @tc.name: SendControlCommand001
226 * @tc.desc: send command, check if AVCastControlCommand is invalid
227 * @tc.type: FUNC
228 * @tc.require:
229 */
230 HWTEST_F(AVCastControllerTest, SendControlCommand001, TestSize.Level1)
231 {
232     AVCastControlCommand command;
233     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_INVALID), ERR_INVALID_PARAM);
234     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_MAX), ERR_INVALID_PARAM);
235     EXPECT_EQ(command.SetForwardTime(0), ERR_INVALID_PARAM);
236     EXPECT_EQ(command.SetRewindTime(-1), ERR_INVALID_PARAM);
237     EXPECT_EQ(command.SetSeekTime(-1), ERR_INVALID_PARAM);
238     EXPECT_EQ(command.SetSpeed(-1), ERR_INVALID_PARAM);
239     EXPECT_EQ(command.SetLoopMode(-1), ERR_INVALID_PARAM);
240 }
241 
242 /**
243 * @tc.name: SendControlCommand002
244 * @tc.desc: send command, check if AVCastControlCommand is invalid
245 * @tc.type: FUNC
246 * @tc.require:
247 */
248 HWTEST_F(AVCastControllerTest, SendControlCommand002, TestSize.Level1)
249 {
250     AVCastControlCommand command;
251     int32_t mode = -1;
252     OHOS::Parcel parcel;
253     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE), AVSESSION_SUCCESS);
254     EXPECT_EQ(command.SetLoopMode(AVPlaybackState::LOOP_MODE_SEQUENCE), AVSESSION_SUCCESS);
255     EXPECT_EQ(command.Marshalling(parcel), true);
256     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
257     EXPECT_NE(ret, nullptr);
258     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE);
259     EXPECT_EQ(ret->GetLoopMode(mode), AVSESSION_SUCCESS);
260     EXPECT_EQ(mode, AVPlaybackState::LOOP_MODE_SEQUENCE);
261     delete ret;
262 }
263 
264 /**
265 * @tc.name: SendControlCommand003
266 * @tc.desc: send command, check if AVCastControlCommand is invalid
267 * @tc.type: FUNC
268 * @tc.require:
269 */
270 HWTEST_F(AVCastControllerTest, SendControlCommand003, TestSize.Level1)
271 {
272     AVCastControlCommand command;
273     int32_t speed = -1;
274     OHOS::Parcel parcel;
275     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED), AVSESSION_SUCCESS);
276     EXPECT_EQ(command.SetSpeed(1), AVSESSION_SUCCESS);
277     EXPECT_EQ(command.Marshalling(parcel), true);
278     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
279     EXPECT_NE(ret, nullptr);
280     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED);
281     EXPECT_EQ(ret->GetSpeed(speed), AVSESSION_SUCCESS);
282     EXPECT_EQ(speed, 1);
283     delete ret;
284 }
285 
286 /**
287 * @tc.name: SendControlCommand004
288 * @tc.desc: send command, check if AVCastControlCommand is invalid
289 * @tc.type: FUNC
290 * @tc.require:
291 */
292 HWTEST_F(AVCastControllerTest, SendControlCommand004, TestSize.Level1)
293 {
294     AVCastControlCommand command;
295     int32_t volumn = -1;
296     OHOS::Parcel parcel;
297     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME), AVSESSION_SUCCESS);
298     EXPECT_EQ(command.SetVolume(1), AVSESSION_SUCCESS);
299     EXPECT_EQ(command.Marshalling(parcel), true);
300     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
301     EXPECT_NE(ret, nullptr);
302     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME);
303     EXPECT_EQ(ret->GetVolume(volumn), AVSESSION_SUCCESS);
304     EXPECT_EQ(volumn, 1);
305     delete ret;
306 }
307 
308 /**
309 * @tc.name: SendControlCommand005
310 * @tc.desc: send command, check if AVCastControlCommand is invalid
311 * @tc.type: FUNC
312 * @tc.require:
313 */
314 HWTEST_F(AVCastControllerTest, SendControlCommand005, TestSize.Level1)
315 {
316     AVCastControlCommand command;
317     int32_t seek = -1;
318     OHOS::Parcel parcel;
319     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_SEEK), AVSESSION_SUCCESS);
320     EXPECT_EQ(command.SetSeekTime(1), AVSESSION_SUCCESS);
321     EXPECT_EQ(command.Marshalling(parcel), true);
322     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
323     EXPECT_NE(ret, nullptr);
324     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_SEEK);
325     EXPECT_EQ(ret->GetSeekTime(seek), AVSESSION_SUCCESS);
326     EXPECT_EQ(seek, 1);
327     delete ret;
328 }
329 
330 /**
331 * @tc.name: SendControlCommand006
332 * @tc.desc: send command, check if AVCastControlCommand is invalid
333 * @tc.type: FUNC
334 * @tc.require:
335 */
336 HWTEST_F(AVCastControllerTest, SendControlCommand006, TestSize.Level1)
337 {
338     AVCastControlCommand command;
339     int32_t rewind = -1;
340     OHOS::Parcel parcel;
341     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_REWIND), AVSESSION_SUCCESS);
342     EXPECT_EQ(command.SetRewindTime(1), AVSESSION_SUCCESS);
343     EXPECT_EQ(command.Marshalling(parcel), true);
344     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
345     EXPECT_NE(ret, nullptr);
346     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_REWIND);
347     EXPECT_EQ(ret->GetRewindTime(rewind), AVSESSION_SUCCESS);
348     EXPECT_EQ(rewind, 1);
349     delete ret;
350 }
351 
352 /**
353 * @tc.name: SendControlCommand007
354 * @tc.desc: send command, check if AVCastControlCommand is invalid
355 * @tc.type: FUNC
356 * @tc.require:
357 */
358 HWTEST_F(AVCastControllerTest, SendControlCommand007, TestSize.Level1)
359 {
360     AVCastControlCommand command;
361     int32_t forward = -1;
362     OHOS::Parcel parcel;
363     EXPECT_EQ(command.SetCommand(AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD), AVSESSION_SUCCESS);
364     EXPECT_EQ(command.SetForwardTime(1), AVSESSION_SUCCESS);
365     EXPECT_EQ(command.Marshalling(parcel), true);
366     AVCastControlCommand *ret = AVCastControlCommand::Unmarshalling(parcel);
367     EXPECT_NE(ret, nullptr);
368     EXPECT_EQ(ret->GetCommand(), AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD);
369     EXPECT_EQ(ret->GetForwardTime(forward), AVSESSION_SUCCESS);
370     EXPECT_EQ(forward, 1);
371     delete ret;
372 }
373 
374 /**
375 * @tc.name: SendControlCommand008
376 * @tc.desc: send command, check if AVCastControlCommand is invalid
377 * @tc.type: FUNC
378 * @tc.require:
379 */
380 HWTEST_F(AVCastControllerTest, SendControlCommand008, TestSize.Level1)
381 {
382     AVCastControlCommand command;
383     EXPECT_EQ(castController_->SendControlCommand(command), AVSESSION_SUCCESS);
384 }
385 
386 /**
387 * @tc.name: Start001
388 * @tc.desc: Start
389 * @tc.type: FUNC
390 * @tc.require:
391 */
392 HWTEST_F(AVCastControllerTest, Start001, TestSize.Level1)
393 {
394     AVQueueItem avQueueItem;
395     std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
396     description->SetMediaId("123");
397     description->SetTitle("Title");
398     description->SetSubtitle("Subtitle");
399     description->SetDescription("This is music description");
400     description->SetIcon(nullptr);
401     description->SetIconUri("xxxxx");
402     description->SetExtras(nullptr);
403     description->SetMediaUri("Media url");
404     avQueueItem.SetDescription(description);
405     EXPECT_EQ(castController_->Start(avQueueItem), AVSESSION_SUCCESS);
406 }
407 
408 /**
409 * @tc.name: Prepare001
410 * @tc.desc: Prepare
411 * @tc.type: FUNC
412 * @tc.require:
413 */
414 HWTEST_F(AVCastControllerTest, Prepare001, TestSize.Level1)
415 {
416     AVQueueItem avQueueItem;
417     std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
418     description->SetMediaId("123");
419     description->SetTitle("Title");
420     description->SetSubtitle("Subtitle");
421     description->SetDescription("This is music description");
422     description->SetIcon(nullptr);
423     description->SetIconUri("xxxxx");
424     description->SetExtras(nullptr);
425     description->SetMediaUri("Media url");
426     avQueueItem.SetDescription(description);
427     EXPECT_EQ(castController_->Prepare(avQueueItem), AVSESSION_SUCCESS);
428 }
429 
430 /**
431 * @tc.name: GetDuration001
432 * @tc.desc: GetDuration
433 * @tc.type: FUNC
434 * @tc.require:
435 */
436 HWTEST_F(AVCastControllerTest, GetDuration001, TestSize.Level1)
437 {
438     int32_t duration;
439     EXPECT_EQ(castController_->GetDuration(duration), AVSESSION_ERROR);
440 }
441 
442 /**
443 * @tc.name: GetCastAVPlaybackState001
444 * @tc.desc: GetCastAVPlaybackState
445 * @tc.type: FUNC
446 * @tc.require:
447 */
448 HWTEST_F(AVCastControllerTest, GetCastAVPlaybackState001, TestSize.Level1)
449 {
450     AVPlaybackState avPlaybackState;
451     EXPECT_EQ(castController_->GetCastAVPlaybackState(avPlaybackState), AVSESSION_ERROR);
452 }
453 
454 /**
455 * @tc.name: GetCurrentItem001
456 * @tc.desc: GetCurrentItem
457 * @tc.type: FUNC
458 * @tc.require:
459 */
460 HWTEST_F(AVCastControllerTest, GetCurrentItem001, TestSize.Level1)
461 {
462     AVQueueItem currentItem;
463     EXPECT_EQ(castController_->GetCurrentItem(currentItem), AVSESSION_SUCCESS);
464 }
465 
466 /**
467 * @tc.name: GetValidCommands001
468 * @tc.desc: GetValidCommands
469 * @tc.type: FUNC
470 * @tc.require:
471 */
472 HWTEST_F(AVCastControllerTest, GetValidCommands001, TestSize.Level1)
473 {
474     std::vector<int32_t> cmds;
475     EXPECT_EQ(castController_->GetValidCommands(cmds), AVSESSION_SUCCESS);
476 }
477 
478 /**
479 * @tc.name: SetDisplaySurface001
480 * @tc.desc: SetDisplaySurface
481 * @tc.type: FUNC
482 * @tc.require:
483 */
484 HWTEST_F(AVCastControllerTest, SetDisplaySurface001, TestSize.Level1)
485 {
486     std::string surfaceId = "surfaceId";
487     EXPECT_EQ(castController_->SetDisplaySurface(surfaceId), AVSESSION_ERROR);
488 }
489 
490 /**
491 * @tc.name: ProcessMediaKeyResponse001
492 * @tc.desc: ProcessMediaKeyResponse
493 * @tc.type: FUNC
494 * @tc.require:
495 */
496 HWTEST_F(AVCastControllerTest, ProcessMediaKeyResponse001, TestSize.Level1)
497 {
498     std::string assetId = "assetId";
499     std::vector<uint8_t> response;
500     EXPECT_EQ(castController_->ProcessMediaKeyResponse(assetId, response), AVSESSION_ERROR);
501 }
502 
503 /**
504 * @tc.name: SetCastPlaybackFilter001
505 * @tc.desc: SetCastPlaybackFilter
506 * @tc.type: FUNC
507 * @tc.require:
508 */
509 HWTEST_F(AVCastControllerTest, SetCastPlaybackFilter001, TestSize.Level1)
510 {
511     AVPlaybackState::PlaybackStateMaskType filter;
512     EXPECT_EQ(castController_->SetCastPlaybackFilter(filter), AVSESSION_SUCCESS);
513 }
514 
515 /**
516 * @tc.name: AddAvailableCommand001
517 * @tc.desc: AddAvailableCommand
518 * @tc.type: FUNC
519 * @tc.require:
520 */
521 HWTEST_F(AVCastControllerTest, AddAvailableCommand001, TestSize.Level1)
522 {
523     EXPECT_EQ(castController_->AddAvailableCommand(0), AVSESSION_SUCCESS);
524 }
525 
526 /**
527 * @tc.name: RemoveAvailableCommand001
528 * @tc.desc: RemoveAvailableCommand
529 * @tc.type: FUNC
530 * @tc.require:
531 */
532 HWTEST_F(AVCastControllerTest, RemoveAvailableCommand001, TestSize.Level1)
533 {
534     EXPECT_EQ(castController_->AddAvailableCommand(0), AVSESSION_SUCCESS);
535     EXPECT_EQ(castController_->RemoveAvailableCommand(0), AVSESSION_SUCCESS);
536 }
537 
538 /**
539 * @tc.name: RegisterControllerListener001
540 * @tc.desc: RegisterControllerListener
541 * @tc.type: FUNC
542 * @tc.require:
543 */
544 HWTEST_F(AVCastControllerTest, RegisterControllerListener001, TestSize.Level1)
545 {
546     std::shared_ptr<IAVCastControllerProxy> castControllerProxy = nullptr;
547     EXPECT_EQ(castController_->RegisterControllerListener(castControllerProxy), true);
548 }
549 
550 /**
551 * @tc.name: Destroy001
552 * @tc.desc: Destroy
553 * @tc.type: FUNC
554 * @tc.require:
555 */
556 HWTEST_F(AVCastControllerTest, Destroy001, TestSize.Level1)
557 {
558     EXPECT_EQ(castController_->Destroy(), AVSESSION_SUCCESS);
559 }
560 
561 /**
562 * @tc.name: OnCastPlaybackStateChange001
563 * @tc.desc: OnCastPlaybackStateChange, no callback
564 * @tc.type: FUNC
565 * @tc.require:
566 */
567 HWTEST_F(AVCastControllerTest, OnCastPlaybackStateChange001, TestSize.Level1)
568 {
569     AVPlaybackState state;
570     castController_->OnCastPlaybackStateChange(state);
571 }
572 
573 /**
574 * @tc.name: OnMediaItemChange001
575 * @tc.desc: OnMediaItemChange, no callback
576 * @tc.type: FUNC
577 * @tc.require:
578 */
579 HWTEST_F(AVCastControllerTest, OnMediaItemChange001, TestSize.Level1)
580 {
581     AVQueueItem avQueueItem;
582     castController_->OnMediaItemChange(avQueueItem);
583 }
584 
585 /**
586 * @tc.name: OnPlayNext001
587 * @tc.desc: OnPlayNext, no callback
588 * @tc.type: FUNC
589 * @tc.require:
590 */
591 HWTEST_F(AVCastControllerTest, OnPlayNext001, TestSize.Level1)
592 {
593     castController_->OnPlayNext();
594 }
595 
596 /**
597 * @tc.name: OnPlayPrevious001
598 * @tc.desc: OnPlayPrevious, no callback
599 * @tc.type: FUNC
600 * @tc.require:
601 */
602 HWTEST_F(AVCastControllerTest, OnPlayPrevious001, TestSize.Level1)
603 {
604     castController_->OnPlayPrevious();
605 }
606 
607 /**
608 * @tc.name: OnSeekDone001
609 * @tc.desc: OnSeekDone, no callback
610 * @tc.type: FUNC
611 * @tc.require:
612 */
613 HWTEST_F(AVCastControllerTest, OnSeekDone001, TestSize.Level1)
614 {
615     int32_t seekNumber = 0;
616     castController_->OnSeekDone(seekNumber);
617 }
618 
619 /**
620 * @tc.name: OnVideoSizeChange001
621 * @tc.desc: OnVideoSizeChange, no callback
622 * @tc.type: FUNC
623 * @tc.require:
624 */
625 HWTEST_F(AVCastControllerTest, OnVideoSizeChange001, TestSize.Level1)
626 {
627     int32_t width = 0;
628     int32_t height = 0;
629     castController_->OnVideoSizeChange(width, height);
630 }
631 
632 /**
633 * @tc.name: OnPlayerError001
634 * @tc.desc: OnPlayerError, no callback
635 * @tc.type: FUNC
636 * @tc.require:
637 */
638 HWTEST_F(AVCastControllerTest, OnPlayerError001, TestSize.Level1)
639 {
640     int32_t errorCode = 0;
641     std::string errorMsg = "errorMsg";
642     castController_->OnPlayerError(errorCode, errorMsg);
643 }
644 
645 /**
646 * @tc.name: StartCastDiscovery001
647 * @tc.desc: StartCastDiscovery
648 * @tc.type: FUNC
649 * @tc.require:
650 */
651 HWTEST_F(AVCastControllerTest, StartCastDiscovery001, TestSize.Level1)
652 {
653     EXPECT_EQ(AVSessionManager::GetInstance().StartCastDiscovery(1, {}), AVSESSION_SUCCESS);
654 }
655 
656 /**
657 * @tc.name: StopCastDiscovery001
658 * @tc.desc: StopCastDiscovery
659 * @tc.type: FUNC
660 * @tc.require:
661 */
662 HWTEST_F(AVCastControllerTest, StopCastDiscovery001, TestSize.Level1)
663 {
664     EXPECT_EQ(AVSessionManager::GetInstance().StopCastDiscovery(), AVSESSION_SUCCESS);
665 }
666 
667 /**
668 * @tc.name: SetDiscoverable001
669 * @tc.desc: SetDiscoverable
670 * @tc.type: FUNC
671 * @tc.require:
672 */
673 HWTEST_F(AVCastControllerTest, SetDiscoverable001, TestSize.Level1)
674 {
675     EXPECT_EQ(AVSessionManager::GetInstance().SetDiscoverable(true), AVSESSION_SUCCESS);
676 }
677 
678 /**
679 * @tc.name: StartCast001
680 * @tc.desc: StartCast
681 * @tc.type: FUNC
682 * @tc.require:
683 */
684 HWTEST_F(AVCastControllerTest, StartCast001, TestSize.Level1)
685 {
686     SessionToken sessionToken;
687     sessionToken.sessionId = avsession_->GetSessionId();
688     OutputDeviceInfo outputDeviceInfo;
689     DeviceInfo deviceInfo;
690     deviceInfo.castCategory_ = 1;
691     deviceInfo.deviceId_ = "deviceId";
692     outputDeviceInfo.deviceInfos_.push_back(deviceInfo);
693     EXPECT_EQ(AVSessionManager::GetInstance().StartCast(sessionToken, outputDeviceInfo), -1007);
694 }
695 
696 /**
697 * @tc.name: StopCast001
698 * @tc.desc: StopCast
699 * @tc.type: FUNC
700 * @tc.require:
701 */
702 HWTEST_F(AVCastControllerTest, StopCast001, TestSize.Level1)
703 {
704     SessionToken sessionToken;
705     sessionToken.sessionId = avsession_->GetSessionId();
706     EXPECT_EQ(AVSessionManager::GetInstance().StopCast(sessionToken), AVSESSION_SUCCESS);
707 }
708 
709 HWTEST_F(AVCastControllerTest, StartDiscovery001, TestSize.Level1)
710 {
711     HwCastProvider hwCastProvider;
712     std::vector<std::string> drmSchemes;
713     EXPECT_EQ(hwCastProvider.StartDiscovery(2, drmSchemes), true);
714 }
715 
716 HWTEST_F(AVCastControllerTest, StopDiscovery001, TestSize.Level1)
717 {
718     HwCastProvider hwCastProvider;
719     hwCastProvider.StopDiscovery();
720     EXPECT_TRUE(true);
721 }
722 
723 HWTEST_F(AVCastControllerTest, Release001, TestSize.Level1)
724 {
725     HwCastProvider hwCastProvider;
726     hwCastProvider.Release();
727     EXPECT_TRUE(true);
728 }
729 
730 HWTEST_F(AVCastControllerTest, StartCastSession001, TestSize.Level1)
731 {
732     HwCastProvider hwCastProvider;
733     EXPECT_EQ(hwCastProvider.StartCastSession(), AVSESSION_SUCCESS);
734 }
735 
736 HWTEST_F(AVCastControllerTest, StopCastSession001, TestSize.Level1)
737 {
738     HwCastProvider hwCastProvider;
739     hwCastProvider.StopCastSession(2);
740     EXPECT_TRUE(true);
741 }
742 
743 HWTEST_F(AVCastControllerTest, AddCastDevice001, TestSize.Level1)
744 {
745     HwCastProvider hwCastProvider;
746 
747     DeviceInfo deviceInfo1;
748     deviceInfo1.castCategory_ = 1;
749     deviceInfo1.deviceId_ = "deviceid1";
750     deviceInfo1.deviceName_ = "devicename1";
751     deviceInfo1.deviceType_ = 1;
752     deviceInfo1.ipAddress_ = "ipAddress1";
753     deviceInfo1.providerId_ = 1;
754     deviceInfo1.supportedProtocols_ = 3;
755     deviceInfo1.authenticationStatus_ = 1;
756     std::vector<std::string> supportedDrmCapabilities;
757     supportedDrmCapabilities.emplace_back("");
758     deviceInfo1.supportedDrmCapabilities_ = supportedDrmCapabilities;
759     deviceInfo1.isLegacy_ = false;
760     deviceInfo1.mediumTypes_ = 2;
761 
762     EXPECT_EQ(hwCastProvider.AddCastDevice(1, deviceInfo1), false);
763 }
764 
765 HWTEST_F(AVCastControllerTest, RemoveCastDevice001, TestSize.Level1)
766 {
767     HwCastProvider hwCastProvider;
768 
769     DeviceInfo deviceInfo1;
770     deviceInfo1.castCategory_ = 1;
771     deviceInfo1.deviceId_ = "deviceid1";
772     deviceInfo1.deviceName_ = "devicename1";
773     deviceInfo1.deviceType_ = 1;
774     deviceInfo1.ipAddress_ = "ipAddress1";
775     deviceInfo1.providerId_ = 1;
776     deviceInfo1.supportedProtocols_ = 1;
777     deviceInfo1.authenticationStatus_ = 0;
778     std::vector<std::string> supportedDrmCapabilities;
779     supportedDrmCapabilities.emplace_back("");
780     deviceInfo1.supportedDrmCapabilities_ = supportedDrmCapabilities;
781     deviceInfo1.isLegacy_ = false;
782     deviceInfo1.mediumTypes_ = 2;
783 
784     EXPECT_EQ(hwCastProvider.RemoveCastDevice(1, deviceInfo1), false);
785 }
786 
787 HWTEST_F(AVCastControllerTest, RegisterCastStateListener001, TestSize.Level1)
788 {
789     HwCastProvider hwCastProvider;
790 
791     EXPECT_EQ(hwCastProvider.RegisterCastStateListener(nullptr), false);
792 }
793 
794 HWTEST_F(AVCastControllerTest, UnRegisterCastStateListener001, TestSize.Level1)
795 {
796     HwCastProvider hwCastProvider;
797 
798     EXPECT_EQ(hwCastProvider.UnRegisterCastStateListener(nullptr), false);
799 }
800 
801 HWTEST_F(AVCastControllerTest, RegisterCastSessionStateListener001, TestSize.Level1)
802 {
803     HwCastProvider hwCastProvider;
804 
805     EXPECT_EQ(hwCastProvider.RegisterCastSessionStateListener(2, nullptr), false);
806 }
807 
808 HWTEST_F(AVCastControllerTest, UnRegisterCastSessionStateListener001, TestSize.Level1)
809 {
810     HwCastProvider hwCastProvider;
811 
812     EXPECT_EQ(hwCastProvider.UnRegisterCastSessionStateListener(2, nullptr), false);
813 }
814 } // namespace AVSession
815 } // namespace OHOS