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