1 /*
2 * Copyright (c) 2023-2025 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 "nativetoken_kit.h"
20 #include "token_setproc.h"
21 #include "cast_session_manager.h"
22 #include "avcast_controller_item.h"
23 #include "avsession_errors.h"
24 #include "avsession_log.h"
25 #include "hw_cast_provider_session.h"
26 #include "hw_cast_stream_player.h"
27 #include "image_type.h"
28
29 using namespace testing::ext;
30 using namespace OHOS::CastEngine::CastEngineClient;
31 using namespace OHOS::CastEngine;
32
33 namespace OHOS {
34 namespace AVSession {
35
36 const static int32_t INVAILD_STATE_CODE = 1000;
37
38 class HwCastStreamPlayerTest : public testing::TestWithParam<int> {
39 public:
40 static void SetUpTestCase();
41 static void TearDownTestCase();
42 void SetUp() override;
43 void TearDown() override;
44 std::shared_ptr<OHOS::Media::PixelMap> CreatePixelMap();
45
46 std::shared_ptr<HwCastProviderSession> hwCastProviderSession = nullptr;
47 std::shared_ptr<HwCastStreamPlayer> hwCastStreamPlayer = nullptr;
48 };
49
50 class TestCastSessionManagerListener : public ICastSessionManagerListener {
51 public:
OnDeviceFound(const std::vector<CastRemoteDevice> & deviceList)52 void OnDeviceFound(const std::vector<CastRemoteDevice> &deviceList) override
53 {
54 static_cast<void>(deviceList);
55 }
OnSessionCreated(const std::shared_ptr<ICastSession> & castSession)56 void OnSessionCreated(const std::shared_ptr<ICastSession> &castSession) override
57 {
58 static_cast<void>(castSession);
59 }
OnServiceDied()60 void OnServiceDied() override {}
OnDeviceOffline(const std::string & deviceId)61 void OnDeviceOffline(const std::string &deviceId) override
62 {
63 static_cast<void>(deviceId);
64 }
65 };
66
67 class StreamPlayerIMock : public OHOS::CastEngine::IStreamPlayer {
68 public:
StreamPlayerIMock(int state=0)69 explicit StreamPlayerIMock(int state = 0) : state_(state) {}
70
GetPosition(int32_t & currentPosition)71 int GetPosition(int32_t& currentPosition) override { return 0; }
72
Seek(int32_t position)73 int Seek(int32_t position) override { return 0; }
74
SetSpeed(const OHOS::CastEngine::PlaybackSpeed speed)75 int SetSpeed(const OHOS::CastEngine::PlaybackSpeed speed) override { return 0; }
76
FastForward(const int32_t delta)77 int FastForward(const int32_t delta) override { return 0; }
78
FastRewind(const int32_t delta)79 int FastRewind(const int32_t delta) override { return 0; }
80
SetVolume(const int32_t volume)81 int SetVolume(const int32_t volume) override { return 0; }
82
SetMute(bool mute)83 int SetMute(bool mute) override { return 0; }
84
ProvideKeyResponse(const std::string & mediaId,const std::vector<uint8_t> & response)85 int ProvideKeyResponse(const std::string &mediaId, const std::vector<uint8_t> &response) override { return 0; }
86
SetLoopMode(const OHOS::CastEngine::LoopMode loopMode)87 int SetLoopMode(const OHOS::CastEngine::LoopMode loopMode) override { return 0; }
88
RegisterListener(std::shared_ptr<OHOS::CastEngine::IStreamPlayerListener> listener)89 int RegisterListener(std::shared_ptr<OHOS::CastEngine::IStreamPlayerListener> listener) override { return 0; }
90
UnregisterListener()91 int UnregisterListener() override { return 0; }
92
SetSurface(const std::string & surfaceInfo)93 int SetSurface(const std::string &surfaceInfo) override { return 0; }
94
SendData(const OHOS::CastEngine::DataType dataType,const std::string & dataStr)95 int SendData(const OHOS::CastEngine::DataType dataType, const std::string &dataStr) override { return 0; }
96
Load(const OHOS::CastEngine::MediaInfo & media)97 int Load(const OHOS::CastEngine::MediaInfo &media) override
98 {
99 if (state_ == 0) {
100 return 0;
101 } else {
102 return 1;
103 }
104 }
105
Play()106 int Play() override { return 0; }
107
Play(const OHOS::CastEngine::MediaInfo & media)108 int Play(const OHOS::CastEngine::MediaInfo &media) override { return 0; }
109
Play(int index)110 int Play(int index) override { return 0; }
111
Pause()112 int Pause() override { return 0; }
113
Stop()114 int Stop() override { return 0; }
115
Next()116 int Next() override { return 0; }
117
Previous()118 int Previous() override { return 0; }
119
GetPlayerStatus(OHOS::CastEngine::PlayerStates & status)120 int GetPlayerStatus(OHOS::CastEngine::PlayerStates &status) override
121 {
122 if (state_ == 0) {
123 status = OHOS::CastEngine::PlayerStates::PLAYER_STATE_ERROR;
124 } else {
125 status = static_cast<OHOS::CastEngine::PlayerStates>(INVAILD_STATE_CODE);
126 }
127 return 0;
128 }
129
GetDuration(int & duration)130 int GetDuration(int &duration) override { return 0; }
131
GetVolume(int32_t & volume,int32_t & maxVolume)132 int GetVolume(int32_t &volume, int32_t &maxVolume) override { return 0; }
133
GetMute(bool & mute)134 int GetMute(bool &mute) override { return 0; }
135
GetLoopMode(OHOS::CastEngine::LoopMode & loopMode)136 int GetLoopMode(OHOS::CastEngine::LoopMode &loopMode) override
137 {
138 if (state_ == 0) {
139 loopMode = OHOS::CastEngine::LoopMode::LOOP_MODE_SINGLE;
140 } else {
141 loopMode = static_cast<OHOS::CastEngine::LoopMode>(INVAILD_STATE_CODE);
142 }
143 return 0;
144 }
145
GetMediaCapabilities(std::string & jsonCapabilities)146 int GetMediaCapabilities(std::string &jsonCapabilities) override { return 0; }
147
GetPlaySpeed(OHOS::CastEngine::PlaybackSpeed & speed)148 int GetPlaySpeed(OHOS::CastEngine::PlaybackSpeed &speed) override
149 {
150 if (state_ == 0) {
151 speed = OHOS::CastEngine::PlaybackSpeed::SPEED_FORWARD_1_00_X;
152 } else {
153 speed = static_cast<OHOS::CastEngine::PlaybackSpeed>(INVAILD_STATE_CODE);
154 }
155 return 0;
156 }
157
GetMediaInfoHolder(OHOS::CastEngine::MediaInfoHolder & hold)158 int GetMediaInfoHolder(OHOS::CastEngine::MediaInfoHolder &hold) override { return 0; }
159
SetAvailableCapability(const OHOS::CastEngine::StreamCapability & streamCapability)160 int SetAvailableCapability(const OHOS::CastEngine::StreamCapability &streamCapability) override { return 0; }
161
GetAvailableCapability(OHOS::CastEngine::StreamCapability & streamCapability)162 int GetAvailableCapability(OHOS::CastEngine::StreamCapability &streamCapability) override { return 0; }
163
Release()164 int Release() override { return 0; }
165
166 private:
167 int state_ = 0;
168 };
169
CreateSession()170 std::shared_ptr<ICastSession> CreateSession()
171 {
172 std::shared_ptr<ICastSession> session;
173 auto listener = std::make_shared<TestCastSessionManagerListener>();
174 CastSessionManager::GetInstance().RegisterListener(listener);
175 CastSessionProperty property = {CastEngine::ProtocolType::CAST_PLUS_STREAM, CastEngine::EndType::CAST_SOURCE};
176 CastSessionManager::GetInstance().CreateCastSession(property, session);
177 return session;
178 }
179
CreateAVMediaDescription()180 std::shared_ptr<AVMediaDescription> CreateAVMediaDescription()
181 {
182 std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
183 description->Reset();
184 description->SetMediaId("123");
185 description->SetTitle("Title");
186 description->SetSubtitle("SubTitle");
187 description->SetDescription("This is music description");
188 description->SetIcon(nullptr);
189 description->SetIconUri("xxxxx");
190 description->SetExtras(nullptr);
191 return description;
192 }
193
SetUpTestCase()194 void HwCastStreamPlayerTest::SetUpTestCase()
195 {}
196
TearDownTestCase()197 void HwCastStreamPlayerTest::TearDownTestCase()
198 {}
199
SetUp()200 void HwCastStreamPlayerTest::SetUp()
201 {
202 constexpr int castPermissionNum = 2;
203 const char *perms[castPermissionNum] = {
204 "ohos.permission.ACCESS_CAST_ENGINE_MIRROR",
205 "ohos.permission.ACCESS_CAST_ENGINE_STREAM",
206 };
207 NativeTokenInfoParams infoInstance = {
208 .dcapsNum = 0, // Indicates the capsbility list of the sa.
209 .permsNum = castPermissionNum,
210 .aclsNum = 0, // acls is the list of rights that can be escalated.
211 .dcaps = nullptr,
212 .perms = perms,
213 .acls = nullptr,
214 .processName = "hw_cast_stream_player_test",
215 .aplStr = "system_basic",
216 };
217 uint64_t tokenId = GetAccessTokenId(&infoInstance);
218 SetSelfTokenID(tokenId);
219 Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
220 std::shared_ptr<ICastSession> castSession = CreateSession();
221 hwCastProviderSession = std::make_shared<HwCastProviderSession>(castSession);
222 if (hwCastProviderSession) {
223 hwCastProviderSession->Init();
224 }
225 std::shared_ptr<IStreamPlayer> streamPlayer = hwCastProviderSession->CreateStreamPlayer();
226 hwCastStreamPlayer = std::make_shared<HwCastStreamPlayer>(streamPlayer);
227 if (hwCastStreamPlayer) {
228 hwCastStreamPlayer->Init();
229 hwCastStreamPlayer->streamPlayer_ = std::make_shared<StreamPlayerIMock>();
230 }
231 }
232
TearDown()233 void HwCastStreamPlayerTest::TearDown()
234 {
235 if (hwCastProviderSession) {
236 hwCastProviderSession->Release();
237 }
238 if (hwCastStreamPlayer) {
239 hwCastStreamPlayer->Release();
240 }
241 }
242
CreatePixelMap()243 std::shared_ptr<OHOS::Media::PixelMap> HwCastStreamPlayerTest::CreatePixelMap()
244 {
245 int32_t pixelMapWidth = 4;
246 int32_t pixelMapHeight = 3;
247 const std::shared_ptr<OHOS::Media::PixelMap>& pixelMap = std::make_shared<OHOS::Media::PixelMap>();
248 Media::ImageInfo info;
249 info.size.width = pixelMapWidth;
250 info.size.height = pixelMapHeight;
251 info.pixelFormat = Media::PixelFormat::RGB_888;
252 info.colorSpace = Media::ColorSpace::SRGB;
253 pixelMap->SetImageInfo(info);
254 int32_t rowDataSize = pixelMapWidth;
255 uint32_t bufferSize = rowDataSize * pixelMapHeight;
256 if (bufferSize == 0) {
257 return pixelMap;
258 }
259
260 std::vector<std::uint8_t> buffer(bufferSize, 0x03);
261 pixelMap->SetPixelsAddr(buffer.data(), nullptr, bufferSize, Media::AllocatorType::CUSTOM_ALLOC, nullptr);
262
263 return pixelMap;
264 }
265
266 INSTANTIATE_TEST_CASE_P(SendControlCommand, HwCastStreamPlayerTest, testing::Values(
267 AVCastControlCommand::CAST_CONTROL_CMD_INVALID,
268 AVCastControlCommand::CAST_CONTROL_CMD_PLAY,
269 AVCastControlCommand::CAST_CONTROL_CMD_PAUSE,
270 AVCastControlCommand::CAST_CONTROL_CMD_STOP,
271 AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT,
272 AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS,
273 AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD,
274 AVCastControlCommand::CAST_CONTROL_CMD_REWIND,
275 AVCastControlCommand::CAST_CONTROL_CMD_SEEK,
276 AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME,
277 AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED,
278 AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE,
279 AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_FAVORITE,
280 AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_MUTE,
281 AVCastControlCommand::CAST_CONTROL_CMD_MAX
282 ));
283
284 static const int32_t DURATION_TIME = 40000;
GetAVMetaData()285 static OHOS::AVSession::AVMetaData GetAVMetaData()
286 {
287 OHOS::AVSession::AVMetaData g_metaData;
288 g_metaData.Reset();
289 g_metaData.SetAssetId("123");
290 g_metaData.SetTitle("Black Humor");
291 g_metaData.SetArtist("zhoujielun");
292 g_metaData.SetAuthor("zhoujielun");
293 g_metaData.SetAlbum("Jay");
294 g_metaData.SetWriter("zhoujielun");
295 g_metaData.SetComposer("zhoujielun");
296 g_metaData.SetDuration(DURATION_TIME);
297 g_metaData.SetMediaImageUri("xxxxx");
298 g_metaData.SetSubTitle("fac");
299 g_metaData.SetDescription("for friends");
300 g_metaData.SetLyric("xxxxx");
301 return g_metaData;
302 }
303
304 /**
305 * @tc.name: SendControlCommand001
306 * @tc.desc: SendControlCommand all test
307 * @tc.type: FUNC
308 * @tc.require: NA
309 */
310 HWTEST_P(HwCastStreamPlayerTest, SendControlCommand001, TestSize.Level0)
311 {
312 SLOGI("SendControlCommand001 begin!");
313 AVCastControlCommand command;
314 int32_t cmd = GetParam();
315 if (cmd == AVCastControlCommand::CAST_CONTROL_CMD_INVALID || cmd == AVCastControlCommand::CAST_CONTROL_CMD_MAX) {
316 ASSERT_EQ(command.SetCommand(cmd), ERR_INVALID_PARAM);
317 } else {
318 ASSERT_EQ(command.SetCommand(cmd), AVSESSION_SUCCESS);
319 }
320 hwCastStreamPlayer->SendControlCommand(command);
321 SLOGI("SendControlCommand001 end!");
322 }
323
324 /**
325 * @tc.name: SendControlCommand002
326 * @tc.desc: test all AVCastControlCommand for SendControlCommand
327 * @tc.type: FUNC
328 * @tc.require: NA
329 */
330 HWTEST_P(HwCastStreamPlayerTest, SendControlCommand002, TestSize.Level0)
331 {
332 SLOGI("SendControlCommand002 begin!");
333 std::vector<int32_t> commands = {
334 AVCastControlCommand::CAST_CONTROL_CMD_INVALID,
335 AVCastControlCommand::CAST_CONTROL_CMD_PLAY,
336 AVCastControlCommand::CAST_CONTROL_CMD_PAUSE,
337 AVCastControlCommand::CAST_CONTROL_CMD_STOP,
338 AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT,
339 AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS,
340 AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD,
341 AVCastControlCommand::CAST_CONTROL_CMD_REWIND,
342 AVCastControlCommand::CAST_CONTROL_CMD_SEEK,
343 AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME,
344 AVCastControlCommand::CAST_CONTROL_CMD_SET_SPEED,
345 AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE,
346 AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_FAVORITE,
347 AVCastControlCommand::CAST_CONTROL_CMD_TOGGLE_MUTE,
348 AVCastControlCommand::CAST_CONTROL_CMD_MAX
349 };
350 ASSERT_TRUE(hwCastStreamPlayer->streamPlayer_ != nullptr);
351 for (int32_t cmd : commands) {
352 AVCastControlCommand avCastControlCommand;
353 avCastControlCommand.SetCommand(cmd);
354 hwCastStreamPlayer->SendControlCommand(avCastControlCommand);
355 }
356 SLOGI("SendControlCommand002 end!");
357 }
358
359 /**
360 * @tc.name: SendCustomData001
361 * @tc.desc: test send data for SendCustomData
362 * @tc.type: FUNC
363 * @tc.require: NA
364 */
365 HWTEST_P(HwCastStreamPlayerTest, SendCustomData001, TestSize.Level0)
366 {
367 SLOGI("SendCustomData001 begin!");
368
369 hwCastStreamPlayer->streamPlayer_ = nullptr;
370 std::string data = "test";
371 hwCastStreamPlayer->SendCustomData(data);
372
373 SLOGI("SendCustomData001 end!");
374 }
375
376 /**
377 * @tc.name: SendCustomData002
378 * @tc.desc: test send data for SendCustomData
379 * @tc.type: FUNC
380 * @tc.require: NA
381 */
382 HWTEST_P(HwCastStreamPlayerTest, SendCustomData002, TestSize.Level0)
383 {
384 SLOGI("SendCustomData002 begin!");
385 hwCastStreamPlayer->streamPlayer_ = std::make_shared<StreamPlayerIMock>();
386 ASSERT_TRUE(hwCastStreamPlayer->streamPlayer_ != nullptr);
387 std::string data = "test";
388 hwCastStreamPlayer->SendCustomData(data);
389 SLOGI("SendCustomData002 end!");
390 }
391
392 /**
393 * @tc.name: SetSpid001
394 * @tc.desc: test SetSpid
395 * @tc.type: FUNC
396 * @tc.require: NA
397 */
398 HWTEST_P(HwCastStreamPlayerTest, SetSpid001, TestSize.Level0)
399 {
400 SLOGI("SetSpid001 begin!");
401 hwCastStreamPlayer->streamPlayer_ = std::make_shared<StreamPlayerIMock>();
402 ASSERT_TRUE(hwCastStreamPlayer->streamPlayer_ != nullptr);
403 uint32_t spid = 33;
404 hwCastStreamPlayer->SetSpid(spid);
405 SLOGI("SetSpid001 end!");
406 }
407
408 /**
409 * @tc.name: Start001
410 * @tc.desc: start no media id and fd src
411 * @tc.type: FUNC
412 * @tc.require: NA
413 */
414 HWTEST_F(HwCastStreamPlayerTest, Start001, TestSize.Level0)
415 {
416 SLOGI("Start001 begin!");
417 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
418 description->SetMediaUri("");
419 AVQueueItem avQueueItem;
420 avQueueItem.SetDescription(description);
421 auto ret = hwCastStreamPlayer->Start(avQueueItem);
422 ASSERT_EQ(ret, AVSESSION_SUCCESS);
423 SLOGI("Start001 end!");
424 }
425
426 /**
427 * @tc.name: Start002
428 * @tc.desc: start with fd src
429 * @tc.type: FUNC
430 * @tc.require: NA
431 */
432 HWTEST_F(HwCastStreamPlayerTest, Start002, TestSize.Level0)
433 {
434 SLOGI("Start002 begin!");
435 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
436 description->SetMediaUri("");
437 // do not use fd of descriptor which cause crash
438 AVQueueItem avQueueItem;
439 avQueueItem.SetDescription(description);
440 auto ret = hwCastStreamPlayer->Start(avQueueItem);
441 ASSERT_EQ(ret, AVSESSION_SUCCESS);
442 SLOGI("Start002 end!");
443 }
444
445 /**
446 * @tc.name: Start003
447 * @tc.desc: start same media
448 * @tc.type: FUNC
449 * @tc.require: NA
450 */
451 HWTEST_F(HwCastStreamPlayerTest, Start003, TestSize.Level0)
452 {
453 SLOGI("Start003 begin!");
454 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
455 description->SetMediaUri("Media url");
456 AVQueueItem avQueueItem;
457 avQueueItem.SetDescription(description);
458 auto ret = hwCastStreamPlayer->Start(avQueueItem);
459 ASSERT_EQ(ret, AVSESSION_SUCCESS);
460 hwCastStreamPlayer->Start(avQueueItem);
461 SLOGI("Start003 end!");
462 }
463
464 /**
465 * @tc.name: Start004
466 * @tc.desc: set callback for data source
467 * @tc.type: FUNC
468 * @tc.require: NA
469 */
470 HWTEST_F(HwCastStreamPlayerTest, Start004, TestSize.Level0)
471 {
472 SLOGI("Start004 begin!");
473 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
474 description->SetMediaUri("Media url");
475 AVDataSrcDescriptor dataSrcDescriptor;
476 dataSrcDescriptor.hasCallback = true;
__anonf433915f0102(void*, uint32_t, int64_t) 477 dataSrcDescriptor.callback_ = [](void*, uint32_t, int64_t) -> int32_t { return 0; };
478 description->SetDataSrc(dataSrcDescriptor);
479
480 AVQueueItem avQueueItem;
481 avQueueItem.SetDescription(description);
482 auto ret = hwCastStreamPlayer->Start(avQueueItem);
483 ASSERT_EQ(ret, AVSESSION_SUCCESS);
484 hwCastStreamPlayer->Start(avQueueItem);
485 SLOGI("Start004 end!");
486 }
487
488 /**
489 * @tc.name: Start005
490 * @tc.desc: set callback for data source but callback is null
491 * @tc.type: FUNC
492 * @tc.require: NA
493 */
494 HWTEST_F(HwCastStreamPlayerTest, Start005, TestSize.Level0)
495 {
496 SLOGI("Start005 begin!");
497 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
498 description->SetMediaUri("Media url");
499 AVDataSrcDescriptor dataSrcDescriptor;
500 dataSrcDescriptor.hasCallback = true;
501 dataSrcDescriptor.callback_ = nullptr;
502 description->SetDataSrc(dataSrcDescriptor);
503
504 AVQueueItem avQueueItem;
505 avQueueItem.SetDescription(description);
506 uint32_t spid = 33;
507 hwCastStreamPlayer->SetSpid(spid);
508 auto ret = hwCastStreamPlayer->Start(avQueueItem);
509 ASSERT_EQ(ret, AVSESSION_SUCCESS);
510 hwCastStreamPlayer->Start(avQueueItem);
511 SLOGI("Start005 end!");
512 }
513
514 /**
515 * @tc.name: Start006
516 * @tc.desc: start and setspid
517 * @tc.type: FUNC
518 * @tc.require: NA
519 */
520 HWTEST_F(HwCastStreamPlayerTest, Start006, TestSize.Level0)
521 {
522 SLOGI("Start006 begin!");
523 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
524 description->SetMediaUri("Media url");
525 AVDataSrcDescriptor dataSrcDescriptor;
526 dataSrcDescriptor.hasCallback = true;
__anonf433915f0202(void*, uint32_t, int64_t) 527 dataSrcDescriptor.callback_ = [](void*, uint32_t, int64_t) -> int32_t { return 0; };
528 description->SetDataSrc(dataSrcDescriptor);
529 uint32_t spid = 33;
530 hwCastStreamPlayer->SetSpid(spid);
531 AVQueueItem avQueueItem;
532 avQueueItem.SetDescription(description);
533 auto ret = hwCastStreamPlayer->Start(avQueueItem);
534 ASSERT_EQ(ret, AVSESSION_SUCCESS);
535 hwCastStreamPlayer->Start(avQueueItem);
536 SLOGI("Start006 end!");
537 }
538
539 /**
540 * @tc.name: Prepare001
541 * @tc.desc: prepare no media id and fd src
542 * @tc.type: FUNC
543 * @tc.require: NA
544 */
545 HWTEST_F(HwCastStreamPlayerTest, Prepare001, TestSize.Level0)
546 {
547 SLOGI("Prepare001 begin!");
548 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
549 description->SetMediaUri("");
550 AVQueueItem avQueueItem;
551 avQueueItem.SetDescription(description);
552 auto ret = hwCastStreamPlayer->Start(avQueueItem);
553 ASSERT_EQ(ret, AVSESSION_SUCCESS);
554 ret = hwCastStreamPlayer->Prepare(avQueueItem);
555 ASSERT_EQ(ret, AVSESSION_SUCCESS);
556 SLOGI("Prepare001 end!");
557 }
558
559 /**
560 * @tc.name: Prepare002
561 * @tc.desc: prepare with fd src
562 * @tc.type: FUNC
563 * @tc.require: NA
564 */
565 HWTEST_F(HwCastStreamPlayerTest, Prepare002, TestSize.Level0)
566 {
567 SLOGI("Prepare002 begin!");
568 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
569 description->SetMediaUri("");
570 // do not use fd of descriptor which cause crash
571 AVQueueItem avQueueItem;
572 avQueueItem.SetDescription(description);
573 auto ret = hwCastStreamPlayer->Start(avQueueItem);
574 ASSERT_EQ(ret, AVSESSION_SUCCESS);
575 ret = hwCastStreamPlayer->Prepare(avQueueItem);
576 ASSERT_EQ(ret, AVSESSION_SUCCESS);
577 SLOGI("Prepare002 end!");
578 }
579
580 /**
581 * @tc.name: Prepare003
582 * @tc.desc: RepeatPrepare is true
583 * @tc.type: FUNC
584 * @tc.require: NA
585 */
586 HWTEST_F(HwCastStreamPlayerTest, Prepare003, TestSize.Level0)
587 {
588 SLOGI("Prepare003 begin!");
589 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
590 description->SetMediaUri("");
591 description->SetIconUri("URI_CACHE");
592 AVQueueItem avQueueItem;
593 avQueueItem.SetDescription(description);
594 auto ret = hwCastStreamPlayer->Start(avQueueItem);
595 ASSERT_EQ(ret, AVSESSION_SUCCESS);
596 ret = hwCastStreamPlayer->Prepare(avQueueItem);
597 ASSERT_EQ(ret, AVSESSION_SUCCESS);
598 SLOGI("Prepare003 end!");
599 }
600
601 /**
602 * @tc.name: Prepare004
603 * @tc.desc: set callback for dataSrcDescriptor
604 * @tc.type: FUNC
605 * @tc.require: NA
606 */
607 HWTEST_F(HwCastStreamPlayerTest, Prepare004, TestSize.Level0)
608 {
609 SLOGI("Prepare004 begin!");
610 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
611 description->SetMediaUri("");
612 description->SetIconUri("");
613 AVDataSrcDescriptor dataSrcDescriptor;
614 dataSrcDescriptor.hasCallback = true;
__anonf433915f0302(void*, uint32_t, int64_t) 615 dataSrcDescriptor.callback_ = [](void*, uint32_t, int64_t) -> int32_t { return 0; };
616 description->SetDataSrc(dataSrcDescriptor);
617
618 AVQueueItem avQueueItem;
619 avQueueItem.SetDescription(description);
620 auto ret = hwCastStreamPlayer->Start(avQueueItem);
621 ASSERT_EQ(ret, AVSESSION_SUCCESS);
622 ret = hwCastStreamPlayer->Prepare(avQueueItem);
623 ASSERT_EQ(ret, AVSESSION_SUCCESS);
624 SLOGI("Prepare004 end!");
625 }
626
627 /**
628 * @tc.name: Prepare005
629 * @tc.desc: set callback for dataSrcDescriptor but callback is null
630 * @tc.type: FUNC
631 * @tc.require: NA
632 */
633 HWTEST_F(HwCastStreamPlayerTest, Prepare005, TestSize.Level0)
634 {
635 SLOGI("Prepare005 begin!");
636 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
637 description->SetMediaUri("");
638 description->SetIconUri("");
639 AVDataSrcDescriptor dataSrcDescriptor;
640 dataSrcDescriptor.hasCallback = true;
641 dataSrcDescriptor.callback_ = nullptr;
642 description->SetDataSrc(dataSrcDescriptor);
643
644 AVQueueItem avQueueItem;
645 avQueueItem.SetDescription(description);
646 auto ret = hwCastStreamPlayer->Start(avQueueItem);
647 ASSERT_EQ(ret, AVSESSION_SUCCESS);
648 ret = hwCastStreamPlayer->Prepare(avQueueItem);
649 ASSERT_EQ(ret, AVSESSION_SUCCESS);
650 SLOGI("Prepare005 end!");
651 }
652
653 /**
654 * @tc.name: Prepare006
655 * @tc.desc: streamPlayer_ is nullptr
656 * @tc.type: FUNC
657 * @tc.require: NA
658 */
659 HWTEST_F(HwCastStreamPlayerTest, Prepare006, TestSize.Level0)
660 {
661 SLOGI("Prepare006 begin!");
662 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
663 description->SetMediaUri("");
664 description->SetIconUri("");
665 AVDataSrcDescriptor dataSrcDescriptor;
666 dataSrcDescriptor.hasCallback = true;
667 dataSrcDescriptor.callback_ = nullptr;
668 description->SetDataSrc(dataSrcDescriptor);
669
670 AVQueueItem avQueueItem;
671 avQueueItem.SetDescription(description);
672 auto ret = hwCastStreamPlayer->Start(avQueueItem);
673 ASSERT_EQ(ret, AVSESSION_SUCCESS);
674 hwCastStreamPlayer->streamPlayer_ = nullptr;
675 ret = hwCastStreamPlayer->Prepare(avQueueItem);
676 ASSERT_EQ(ret, AVSESSION_ERROR);
677 SLOGI("Prepare006 end!");
678 }
679
680 /**
681 * @tc.name: Prepare007
682 * @tc.desc: streamPlayer_->Load is not AVSESSION_SUCCESS
683 * @tc.type: FUNC
684 * @tc.require: NA
685 */
686 HWTEST_F(HwCastStreamPlayerTest, Prepare007, TestSize.Level0)
687 {
688 SLOGI("Prepare007 begin!");
689 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
690 description->SetMediaUri("");
691 description->SetIconUri("");
692 AVDataSrcDescriptor dataSrcDescriptor;
693 dataSrcDescriptor.hasCallback = true;
694 dataSrcDescriptor.callback_ = nullptr;
695 description->SetDataSrc(dataSrcDescriptor);
696
697 AVQueueItem avQueueItem;
698 avQueueItem.SetDescription(description);
699 auto ret = hwCastStreamPlayer->Start(avQueueItem);
700 ASSERT_EQ(ret, AVSESSION_SUCCESS);
701 hwCastStreamPlayer->streamPlayer_ = std::make_shared<StreamPlayerIMock>(1);
702 ret = hwCastStreamPlayer->Prepare(avQueueItem);
703 ASSERT_EQ(ret, AVSESSION_ERROR);
704 SLOGI("Prepare007 end!");
705 }
706
707 /**
708 * @tc.name: GetDuration001
709 * @tc.desc: GetDuration
710 * @tc.type: FUNC
711 * @tc.require: NA
712 */
713 HWTEST_F(HwCastStreamPlayerTest, GetDuration001, TestSize.Level0)
714 {
715 SLOGI("GetDuration001 begin!");
716 int32_t duration = 40000;
717 ASSERT_EQ(hwCastStreamPlayer->GetDuration(duration), AVSESSION_SUCCESS);
718 SLOGI("GetDuration001 end!");
719 }
720
721 /**
722 * @tc.name: GetCastAVPlaybackState001
723 * @tc.desc: GetCastAVPlaybackState
724 * @tc.type: FUNC
725 * @tc.require: NA
726 */
727 HWTEST_F(HwCastStreamPlayerTest, GetCastAVPlaybackState001, TestSize.Level0)
728 {
729 SLOGI("GetCastAVPlaybackState001 begin!");
730 AVPlaybackState state;
731 ASSERT_EQ(hwCastStreamPlayer->GetCastAVPlaybackState(state), AVSESSION_SUCCESS);
732 SLOGI("GetCastAVPlaybackState001 end!");
733 }
734
735 /**
736 * @tc.name: GetCastAVPlaybackState002
737 * @tc.desc: failed to data from map
738 * @tc.type: FUNC
739 * @tc.require: NA
740 */
741 HWTEST_F(HwCastStreamPlayerTest, GetCastAVPlaybackState002, TestSize.Level0)
742 {
743 SLOGI("GetCastAVPlaybackState002 begin!");
744 AVPlaybackState state;
745 hwCastStreamPlayer->streamPlayer_ = std::make_shared<StreamPlayerIMock>(1);
746 ASSERT_EQ(hwCastStreamPlayer->GetCastAVPlaybackState(state), AVSESSION_SUCCESS);
747 SLOGI("GetCastAVPlaybackState002 end!");
748 }
749
750 /**
751 * @tc.name: SetDisplaySurface001
752 * @tc.desc: SetDisplaySurface
753 * @tc.type: FUNC
754 * @tc.require: NA
755 */
756 HWTEST_F(HwCastStreamPlayerTest, SetDisplaySurface001, TestSize.Level0)
757 {
758 SLOGI("SetDisplaySurface001 begin!");
759 std::string surfaceId = "surfaceId";
760 ASSERT_EQ(hwCastStreamPlayer->SetDisplaySurface(surfaceId), AVSESSION_SUCCESS);
761 SLOGI("SetDisplaySurface001 end!");
762 }
763
764 /**
765 * @tc.name: ProcessMediaKeyResponse001
766 * @tc.desc: ProcessMediaKeyResponse
767 * @tc.type: FUNC
768 * @tc.require: NA
769 */
770 HWTEST_F(HwCastStreamPlayerTest, ProcessMediaKeyResponse001, TestSize.Level0)
771 {
772 SLOGI("ProcessMediaKeyResponse001 begin!");
773 std::string assetId = "assetId";
774 std::vector<uint8_t> response;
775 ASSERT_EQ(hwCastStreamPlayer->ProcessMediaKeyResponse(assetId, response), AVSESSION_SUCCESS);
776 SLOGI("ProcessMediaKeyResponse001 end!");
777 }
778
779 /**
780 * @tc.name: RegisterControllerListener001
781 * @tc.desc: RegisterControllerListener invalid listener
782 * @tc.type: FUNC
783 * @tc.require: NA
784 */
785 HWTEST_F(HwCastStreamPlayerTest, RegisterControllerListener001, TestSize.Level0)
786 {
787 SLOGI("RegisterControllerListener001 begin!");
788 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(nullptr), AVSESSION_ERROR);
789 SLOGI("RegisterControllerListener001 end!");
790 }
791
792 /**
793 * @tc.name: RegisterControllerListener002
794 * @tc.desc: RegisterControllerListener repeat
795 * @tc.type: FUNC
796 * @tc.require: NA
797 */
798 HWTEST_F(HwCastStreamPlayerTest, RegisterControllerListener002, TestSize.Level0)
799 {
800 SLOGI("RegisterControllerListener002 begin!");
801 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
802 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
803 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_ERROR);
804 SLOGI("RegisterControllerListener002 end!");
805 }
806
807 /**
808 * @tc.name: UnRegisterControllerListener001
809 * @tc.desc: UnRegisterControllerListener invalid listener
810 * @tc.type: FUNC
811 * @tc.require: NA
812 */
813 HWTEST_F(HwCastStreamPlayerTest, UnRegisterControllerListener001, TestSize.Level0)
814 {
815 SLOGI("UnRegisterControllerListener001 begin!");
816 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(nullptr), AVSESSION_ERROR);
817 SLOGI("UnRegisterControllerListener001 end!");
818 }
819
820 /**
821 * @tc.name: UnRegisterControllerListener002
822 * @tc.desc: UnRegisterControllerListener success
823 * @tc.type: FUNC
824 * @tc.require: NA
825 */
826 HWTEST_F(HwCastStreamPlayerTest, UnRegisterControllerListener002, TestSize.Level0)
827 {
828 SLOGI("UnRegisterControllerListener002 begin!");
829 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
830 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
831 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
832 SLOGI("UnRegisterControllerListener002 end!");
833 }
834
835 /**
836 * @tc.name: UnRegisterControllerListener003
837 * @tc.desc: UnRegisterControllerListener failed
838 * @tc.type: FUNC
839 * @tc.require: NA
840 */
841 HWTEST_F(HwCastStreamPlayerTest, UnRegisterControllerListener003, TestSize.Level0)
842 {
843 SLOGI("UnRegisterControllerListener003 begin!");
844 std::shared_ptr<AVCastControllerItem> avCastControllerItem1 = std::make_shared<AVCastControllerItem>();
845 std::shared_ptr<AVCastControllerItem> avCastControllerItem2 = std::make_shared<AVCastControllerItem>();
846 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem1), AVSESSION_SUCCESS);
847 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem2), AVSESSION_ERROR);
848 SLOGI("UnRegisterControllerListener003 end!");
849 }
850
851 /**
852 * @tc.name: OnStateChanged001
853 * @tc.desc: OnStateChanged
854 * @tc.type: FUNC
855 * @tc.require: NA
856 */
857 HWTEST_F(HwCastStreamPlayerTest, OnStateChanged001, TestSize.Level0)
858 {
859 SLOGI("OnStateChanged001 begin!");
860 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
861 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
862 hwCastStreamPlayer->OnStateChanged(CastEngine::PlayerStates::PLAYER_INITIALIZED, true);
863 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
864 SLOGI("OnStateChanged001 end!");
865 }
866
867 /**
868 * @tc.name: OnStateChanged002
869 * @tc.desc: push listener to streamPlayerListenerList_
870 * @tc.type: FUNC
871 * @tc.require: NA
872 */
873 HWTEST_F(HwCastStreamPlayerTest, OnStateChanged002, TestSize.Level0)
874 {
875 SLOGI("OnStateChanged002 begin!");
876 auto state = static_cast<OHOS::CastEngine::PlayerStates>(1000);
877 auto controller = std::make_shared<AVCastControllerItem>();
878 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
879 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
880 hwCastStreamPlayer->OnStateChanged(state, true);
881 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
882 SLOGI("OnStateChanged002 end!");
883 }
884
885
886 /**
887 * @tc.name: CheckIfCancelCastCapsule001
888 * @tc.desc: state is avaiable
889 * @tc.type: FUNC
890 * @tc.require:
891 */
892 HWTEST_F(HwCastStreamPlayerTest, CheckIfCancelCastCapsule001, TestSize.Level0)
893 {
894 SLOGI("CheckIfCancelCastCapsule001 begin!");
895 hwCastStreamPlayer->CheckIfCancelCastCapsule();
896 EXPECT_EQ(hwCastStreamPlayer->isPlayingState_, false);
897 }
898
899 /**
900 * @tc.name: OnPositionChanged001
901 * @tc.desc: OnPositionChanged invalid
902 * @tc.type: FUNC
903 * @tc.require: NA
904 */
905 HWTEST_F(HwCastStreamPlayerTest, OnPositionChanged001, TestSize.Level0)
906 {
907 SLOGI("OnPositionChanged001 begin!");
908 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
909 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
910 hwCastStreamPlayer->OnPositionChanged(-1, -1, -1);
911 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
912 SLOGI("OnPositionChanged001 end!");
913 }
914
915 /**
916 * @tc.name: OnPositionChanged002
917 * @tc.desc: OnPositionChanged
918 * @tc.type: FUNC
919 * @tc.require: NA
920 */
921 HWTEST_F(HwCastStreamPlayerTest, OnPositionChanged002, TestSize.Level0)
922 {
923 SLOGI("OnPositionChanged002 begin!");
924 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
925 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
926 hwCastStreamPlayer->OnPositionChanged(0, 0, 10);
927 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
928 SLOGI("OnPositionChanged002 end!");
929 }
930
931 /**
932 * @tc.name: OnPositionChanged003
933 * @tc.desc: push listener to streamPlayerListenerList_
934 * @tc.type: FUNC
935 * @tc.require: NA
936 */
937 HWTEST_F(HwCastStreamPlayerTest, OnPositionChanged003, TestSize.Level0)
938 {
939 SLOGI("OnPositionChanged003 begin!");
940 auto controller = std::make_shared<AVCastControllerItem>();
941 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
942 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
943 hwCastStreamPlayer->OnPositionChanged(1, 1, 1);
944 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
945 SLOGI("OnPositionChanged003 end!");
946 }
947
948 /**
949 * @tc.name: OnMediaItemChanged001
950 * @tc.desc: OnMediaItemChanged
951 * @tc.type: FUNC
952 * @tc.require: NA
953 */
954 HWTEST_F(HwCastStreamPlayerTest, OnMediaItemChanged001, TestSize.Level0)
955 {
956 SLOGI("OnMediaItemChanged001 begin!");
957 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
958 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
959 CastEngine::MediaInfo mediaInfo;
960 hwCastStreamPlayer->OnMediaItemChanged(mediaInfo);
961 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
962 SLOGI("OnMediaItemChanged001 end!");
963 }
964
965 /**
966 * @tc.name: OnMediaItemChanged002
967 * @tc.desc: add listener to streamPlayerListenerList_
968 * @tc.type: FUNC
969 * @tc.require: NA
970 */
971 HWTEST_F(HwCastStreamPlayerTest, OnMediaItemChanged002, TestSize.Level0)
972 {
973 SLOGI("OnMediaItemChanged002 begin!");
974 auto controller = std::make_shared<AVCastControllerItem>();
975 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
976 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
977 CastEngine::MediaInfo mediaInfo;
978 hwCastStreamPlayer->OnMediaItemChanged(mediaInfo);
979 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
980 SLOGI("OnMediaItemChanged002 end!");
981 }
982
983 /**
984 * @tc.name: OnNextRequest001
985 * @tc.desc: OnNextRequest
986 * @tc.type: FUNC
987 * @tc.require: NA
988 */
989 HWTEST_F(HwCastStreamPlayerTest, OnNextRequest001, TestSize.Level0)
990 {
991 SLOGI("OnNextRequest001 begin!");
992 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
993 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
994 hwCastStreamPlayer->OnNextRequest();
995 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
996 SLOGI("OnNextRequest001 end!");
997 }
998
999 /**
1000 * @tc.name: OnNextRequest002
1001 * @tc.desc: add listener to streamPlayerListenerList_
1002 * @tc.type: FUNC
1003 * @tc.require: NA
1004 */
1005 HWTEST_F(HwCastStreamPlayerTest, OnNextRequest002, TestSize.Level0)
1006 {
1007 SLOGI("OnNextRequest002 begin!");
1008 auto controller = std::make_shared<AVCastControllerItem>();
1009 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1010 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1011 hwCastStreamPlayer->OnNextRequest();
1012 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1013 SLOGI("OnNextRequest002 end!");
1014 }
1015
1016 /**
1017 * @tc.name: OnPreviousRequest001
1018 * @tc.desc: OnPreviousRequest
1019 * @tc.type: FUNC
1020 * @tc.require: NA
1021 */
1022 HWTEST_F(HwCastStreamPlayerTest, OnPreviousRequest001, TestSize.Level0)
1023 {
1024 SLOGI("OnPreviousRequest001 begin!");
1025 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1026 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1027 hwCastStreamPlayer->OnPreviousRequest();
1028 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1029 SLOGI("OnPreviousRequest001 end!");
1030 }
1031
1032 /**
1033 * @tc.name: OnVolumeChanged001
1034 * @tc.desc: OnVolumeChanged
1035 * @tc.type: FUNC
1036 * @tc.require: NA
1037 */
1038 HWTEST_F(HwCastStreamPlayerTest, OnVolumeChanged001, TestSize.Level0)
1039 {
1040 SLOGI("OnVolumeChanged001 begin!");
1041 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1042 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1043 hwCastStreamPlayer->OnVolumeChanged(5, 15);
1044 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1045 SLOGI("OnVolumeChanged001 end!");
1046 }
1047
1048 /**
1049 * @tc.name: OnVolumeChanged002
1050 * @tc.desc: add listener to streamPlayerListenerList_
1051 * @tc.type: FUNC
1052 * @tc.require: NA
1053 */
1054 HWTEST_F(HwCastStreamPlayerTest, OnVolumeChanged002, TestSize.Level0)
1055 {
1056 SLOGI("OnVolumeChanged002 begin!");
1057 auto controller = std::make_shared<AVCastControllerItem>();
1058 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1059 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1060 hwCastStreamPlayer->OnVolumeChanged(5, 15);
1061 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1062 SLOGI("OnVolumeChanged002 end!");
1063 }
1064
1065 /**
1066 * @tc.name: OnLoopModeChanged001
1067 * @tc.desc: OnLoopModeChanged
1068 * @tc.type: FUNC
1069 * @tc.require: NA
1070 */
1071 HWTEST_F(HwCastStreamPlayerTest, OnLoopModeChanged001, TestSize.Level0)
1072 {
1073 SLOGI("OnLoopModeChanged001 begin!");
1074 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1075 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1076 hwCastStreamPlayer->OnLoopModeChanged(CastEngine::LoopMode::LOOP_MODE_SINGLE);
1077 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1078 SLOGI("OnLoopModeChanged001 end!");
1079 }
1080
1081 /**
1082 * @tc.name: OnLoopModeChanged002
1083 * @tc.desc: send error code
1084 * @tc.type: FUNC
1085 * @tc.require: NA
1086 */
1087 HWTEST_F(HwCastStreamPlayerTest, OnLoopModeChanged002, TestSize.Level0)
1088 {
1089 SLOGI("OnLoopModeChanged002 begin!");
1090 auto controller = std::make_shared<AVCastControllerItem>();
1091 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1092 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1093 auto loopMode = static_cast<OHOS::CastEngine::LoopMode>(1000);
1094 hwCastStreamPlayer->OnLoopModeChanged(loopMode);
1095 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1096 SLOGI("OnLoopModeChanged002 end!");
1097 }
1098
1099 /**
1100 * @tc.name: OnPlaySpeedChanged001
1101 * @tc.desc: OnPlaySpeedChanged
1102 * @tc.type: FUNC
1103 * @tc.require: NA
1104 */
1105 HWTEST_F(HwCastStreamPlayerTest, OnPlaySpeedChanged001, TestSize.Level0)
1106 {
1107 SLOGI("OnPlaySpeedChanged001 begin!");
1108 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1109 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1110 hwCastStreamPlayer->OnPlaySpeedChanged(CastEngine::PlaybackSpeed::SPEED_FORWARD_2_00_X);
1111 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1112 SLOGI("OnPlaySpeedChanged001 end!");
1113 }
1114
1115 /**
1116 * @tc.name: OnPlaySpeedChanged002
1117 * @tc.desc: send error code
1118 * @tc.type: FUNC
1119 * @tc.require: NA
1120 */
1121 HWTEST_F(HwCastStreamPlayerTest, OnPlaySpeedChanged002, TestSize.Level0)
1122 {
1123 SLOGI("OnPlaySpeedChanged002 begin!");
1124 auto controller = std::make_shared<AVCastControllerItem>();
1125 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1126 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1127 auto playSpeed = static_cast<OHOS::CastEngine::PlaybackSpeed>(1000);
1128 hwCastStreamPlayer->OnPlaySpeedChanged(playSpeed);
1129 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1130 SLOGI("OnPlaySpeedChanged002 end!");
1131 }
1132
1133 /**
1134 * @tc.name: OnPlayerError001
1135 * @tc.desc: OnPlayerError
1136 * @tc.type: FUNC
1137 * @tc.require: NA
1138 */
1139 HWTEST_F(HwCastStreamPlayerTest, OnPlayerError001, TestSize.Level0)
1140 {
1141 SLOGI("OnPlayerError001 begin!");
1142 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1143 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1144 hwCastStreamPlayer->OnPlayerError(10003, "PLAYER_ERROR");
1145 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1146 SLOGI("OnPlayerError001 end!");
1147 }
1148
1149 /**
1150 * @tc.name: OnPlayerError002
1151 * @tc.desc: add listener to streamPlayerListenerList_
1152 * @tc.type: FUNC
1153 * @tc.require: NA
1154 */
1155 HWTEST_F(HwCastStreamPlayerTest, OnPlayerError002, TestSize.Level0)
1156 {
1157 SLOGI("OnPlayerError002 begin!");
1158 auto controller = std::make_shared<AVCastControllerItem>();
1159 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1160 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1161 hwCastStreamPlayer->OnPlayerError(10003, "PLAYER_ERROR");
1162 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1163 SLOGI("OnPlayerError002 end!");
1164 }
1165
1166 /**
1167 * @tc.name: OnSeekDone001
1168 * @tc.desc: OnSeekDone
1169 * @tc.type: FUNC
1170 * @tc.require: NA
1171 */
1172 HWTEST_F(HwCastStreamPlayerTest, OnSeekDone001, TestSize.Level0)
1173 {
1174 SLOGI("OnSeekDone001 begin!");
1175 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1176 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1177 int32_t seekNumber = 0;
1178 hwCastStreamPlayer->OnSeekDone(seekNumber);
1179 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1180 SLOGI("OnSeekDone001 end!");
1181 }
1182
1183 /**
1184 * @tc.name: OnSeekDone002
1185 * @tc.desc: add listener to streamPlayerListenerList_
1186 * @tc.type: FUNC
1187 * @tc.require: NA
1188 */
1189 HWTEST_F(HwCastStreamPlayerTest, OnSeekDone002, TestSize.Level0)
1190 {
1191 SLOGI("OnSeekDone002 begin!");
1192 auto controller = std::make_shared<AVCastControllerItem>();
1193 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1194 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1195 int32_t seekNumber = 0;
1196 hwCastStreamPlayer->OnSeekDone(seekNumber);
1197 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1198 SLOGI("OnSeekDone002 end!");
1199 }
1200
1201 /**
1202 * @tc.name: OnVideoSizeChanged001
1203 * @tc.desc: OnVideoSizeChanged
1204 * @tc.type: FUNC
1205 * @tc.require: NA
1206 */
1207 HWTEST_F(HwCastStreamPlayerTest, OnVideoSizeChanged001, TestSize.Level0)
1208 {
1209 SLOGI("OnVideoSizeChanged001 begin!");
1210 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1211 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1212 hwCastStreamPlayer->OnVideoSizeChanged(0, 0);
1213 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1214 SLOGI("OnVideoSizeChanged001 end!");
1215 }
1216
1217 /**
1218 * @tc.name: OnVideoSizeChanged002
1219 * @tc.desc: add listener to streamPlayerListenerList_
1220 * @tc.type: FUNC
1221 * @tc.require: NA
1222 */
1223 HWTEST_F(HwCastStreamPlayerTest, OnVideoSizeChanged002, TestSize.Level0)
1224 {
1225 SLOGI("OnVideoSizeChanged002 begin!");
1226 auto controller = std::make_shared<AVCastControllerItem>();
1227 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1228 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1229 hwCastStreamPlayer->OnVideoSizeChanged(0, 0);
1230 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1231 SLOGI("OnVideoSizeChanged002 end!");
1232 }
1233
1234 /**
1235 * @tc.name: OnEndOfStream001
1236 * @tc.desc: OnEndOfStream
1237 * @tc.type: FUNC
1238 * @tc.require: NA
1239 */
1240 HWTEST_F(HwCastStreamPlayerTest, OnEndOfStream001, TestSize.Level0)
1241 {
1242 SLOGI("OnEndOfStream001 begin!");
1243 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1244 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1245 hwCastStreamPlayer->OnEndOfStream(0);
1246 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1247 SLOGI("OnEndOfStream001 end!");
1248 }
1249
1250 /**
1251 * @tc.name: OnEndOfStream002
1252 * @tc.desc: add listener to streamPlayerListenerList_
1253 * @tc.type: FUNC
1254 * @tc.require: NA
1255 */
1256 HWTEST_F(HwCastStreamPlayerTest, OnEndOfStream002, TestSize.Level0)
1257 {
1258 SLOGI("OnEndOfStream002 begin!");
1259 auto controller = std::make_shared<AVCastControllerItem>();
1260 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1261 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1262 hwCastStreamPlayer->OnEndOfStream(0);
1263 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1264 SLOGI("OnEndOfStream002 end!");
1265 }
1266
1267 /**
1268 * @tc.name: OnPlayRequest001
1269 * @tc.desc: OnPlayRequest
1270 * @tc.type: FUNC
1271 * @tc.require: NA
1272 */
1273 HWTEST_F(HwCastStreamPlayerTest, OnPlayRequest001, TestSize.Level0)
1274 {
1275 SLOGI("OnPlayRequest001 begin!");
1276 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1277 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1278 CastEngine::MediaInfo mediaInfo;
1279 hwCastStreamPlayer->OnPlayRequest(mediaInfo);
1280 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1281 SLOGI("OnPlayRequest001 end!");
1282 }
1283
1284 /**
1285 * @tc.name: OnPlayRequest002
1286 * @tc.desc: add listener to streamPlayerListenerList_
1287 * @tc.type: FUNC
1288 * @tc.require: NA
1289 */
1290 HWTEST_F(HwCastStreamPlayerTest, OnPlayRequest002, TestSize.Level0)
1291 {
1292 SLOGI("OnPlayRequest002 begin!");
1293 auto controller = std::make_shared<AVCastControllerItem>();
1294 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1295 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1296 CastEngine::MediaInfo mediaInfo;
1297 hwCastStreamPlayer->OnPlayRequest(mediaInfo);
1298 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1299 SLOGI("OnPlayRequest002 end!");
1300 }
1301
1302 /**
1303 * @tc.name: OnKeyRequest001
1304 * @tc.desc: OnKeyRequest
1305 * @tc.type: FUNC
1306 * @tc.require: NA
1307 */
1308 HWTEST_F(HwCastStreamPlayerTest, OnKeyRequest001, TestSize.Level0)
1309 {
1310 SLOGI("OnKeyRequest001 begin!");
1311 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1312 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1313 std::string assetId = "assetId";
1314 std::vector<uint8_t> keyRequestData;
1315 hwCastStreamPlayer->OnKeyRequest(assetId, keyRequestData);
1316 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1317 SLOGI("OnKeyRequest001 end!");
1318 }
1319
1320 /**
1321 * @tc.name: OnKeyRequest002
1322 * @tc.desc: add listener to streamPlayerListenerList_
1323 * @tc.type: FUNC
1324 * @tc.require: NA
1325 */
1326 HWTEST_F(HwCastStreamPlayerTest, OnKeyRequest002, TestSize.Level0)
1327 {
1328 SLOGI("OnKeyRequest002 begin!");
1329 auto controller = std::make_shared<AVCastControllerItem>();
1330 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1331 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1332 std::string assetId = "assetId";
1333 std::vector<uint8_t> keyRequestData;
1334 hwCastStreamPlayer->OnKeyRequest(assetId, keyRequestData);
1335 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1336 SLOGI("OnKeyRequest002 end!");
1337 }
1338
1339 /**
1340 * @tc.name: OnData001
1341 * @tc.desc: test OnData
1342 * @tc.type: FUNC
1343 * @tc.require: NA
1344 */
1345 HWTEST_P(HwCastStreamPlayerTest, OnData001, TestSize.Level0)
1346 {
1347 SLOGI("OnData001 begin!");
1348
1349 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1350 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1351 std::string str = "test";
1352 hwCastStreamPlayer->OnData(DataType::CUSTOM_DATA, str);
1353 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1354
1355 SLOGI("OnData001 end!");
1356 }
1357
1358 /**
1359 * @tc.name: SetValidAbility001
1360 * @tc.desc: SetValidAbility to cast
1361 * @tc.type: FUNC
1362 * @tc.require: NA
1363 */
1364 HWTEST_F(HwCastStreamPlayerTest, SetValidAbility001, TestSize.Level0)
1365 {
1366 SLOGI("SetValidAbility001 begin!");
1367 std::vector<int32_t> validAbilityList;
1368 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY);
1369 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PAUSE);
1370 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_STOP);
1371 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT);
1372 ASSERT_EQ(hwCastStreamPlayer->SetValidAbility(validAbilityList), AVSESSION_SUCCESS);
1373 SLOGI("SetValidAbility001 end!");
1374 }
1375
1376 /**
1377 * @tc.name: GetValidAbility001
1378 * @tc.desc: GetValidAbility from cast
1379 * @tc.type: FUNC
1380 * @tc.require: NA
1381 */
1382 HWTEST_F(HwCastStreamPlayerTest, GetValidAbility001, TestSize.Level0)
1383 {
1384 SLOGI("GetValidAbility001 begin!");
1385 std::vector<int32_t> validAbilityList;
1386 ASSERT_EQ(hwCastStreamPlayer->GetValidAbility(validAbilityList), AVSESSION_SUCCESS);
1387 SLOGI("GetValidAbility001 end!");
1388 }
1389
1390 /**
1391 * @tc.name: GetValidAbility002
1392 * @tc.desc: streamPlayer_ is nullptr
1393 * @tc.type: FUNC
1394 * @tc.require: NA
1395 */
1396 HWTEST_F(HwCastStreamPlayerTest, GetValidAbility002, TestSize.Level0)
1397 {
1398 SLOGI("GetValidAbility002 begin!");
1399 std::vector<int32_t> validAbilityList;
1400 hwCastStreamPlayer->streamPlayer_ = nullptr;
1401 ASSERT_EQ(hwCastStreamPlayer->GetValidAbility(validAbilityList), AVSESSION_ERROR);
1402 SLOGI("GetValidAbility002 end!");
1403 }
1404
1405 /**
1406 * @tc.name: OnAvailableCapabilityChanged001
1407 * @tc.desc: OnAvailableCapabilityChanged
1408 * @tc.type: FUNC
1409 * @tc.require: NA
1410 */
1411 HWTEST_F(HwCastStreamPlayerTest, OnAvailableCapabilityChanged001, TestSize.Level0)
1412 {
1413 SLOGI("OnAvailableCapabilityChanged001 begin!");
1414 std::shared_ptr<AVCastControllerItem> avCastControllerItem = std::make_shared<AVCastControllerItem>();
1415 ASSERT_EQ(hwCastStreamPlayer->RegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1416 CastEngine::StreamCapability streamCapability;
1417 streamCapability.isPlaySupported = true;
1418 streamCapability.isPauseSupported = true;
1419 streamCapability.isStopSupported = true;
1420 streamCapability.isNextSupported = true;
1421 streamCapability.isPreviousSupported = true;
1422 streamCapability.isSeekSupported = true;
1423 hwCastStreamPlayer->OnAvailableCapabilityChanged(streamCapability);
1424 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(avCastControllerItem), AVSESSION_SUCCESS);
1425 SLOGI("OnAvailableCapabilityChanged001 end!");
1426 }
1427
1428 /**
1429 * @tc.name: OnAvailableCapabilityChanged002
1430 * @tc.desc: add listener to streamPlayerListenerList_
1431 * @tc.type: FUNC
1432 * @tc.require: NA
1433 */
1434 HWTEST_F(HwCastStreamPlayerTest, OnAvailableCapabilityChanged002, TestSize.Level0)
1435 {
1436 SLOGI("OnAvailableCapabilityChanged002 begin!");
1437 auto controller = std::make_shared<AVCastControllerItem>();
1438 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1439 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1440 CastEngine::StreamCapability streamCapability;
1441 streamCapability.isPlaySupported = true;
1442 streamCapability.isPauseSupported = true;
1443 streamCapability.isStopSupported = true;
1444 streamCapability.isNextSupported = true;
1445 streamCapability.isPreviousSupported = true;
1446 streamCapability.isSeekSupported = true;
1447 streamCapability.isFastForwardSupported = true;
1448 streamCapability.isFastRewindSupported = true;
1449 streamCapability.isLoopModeSupported = true;
1450 streamCapability.isSetVolumeSupported = true;
1451
1452 hwCastStreamPlayer->OnAvailableCapabilityChanged(streamCapability);
1453 ASSERT_EQ(hwCastStreamPlayer->UnRegisterControllerListener(controller), AVSESSION_SUCCESS);
1454 SLOGI("OnAvailableCapabilityChanged002 end!");
1455 }
1456
1457 /**
1458 * @tc.name: CheckCastTime001
1459 * @tc.desc: CheckCastTime
1460 * @tc.type: FUNC
1461 * @tc.require: NA
1462 */
1463 HWTEST_F(HwCastStreamPlayerTest, CheckCastTime001, TestSize.Level0)
1464 {
1465 SLOGI("CheckCastTime001 begin!");
1466 int32_t castTime = 1001;
1467 int32_t ret = hwCastStreamPlayer->CheckCastTime(castTime);
1468 EXPECT_EQ(ret, castTime);
1469 SLOGI("CheckCastTime001 end!");
1470 }
1471
1472 /**
1473 * @tc.name: CheckCastTime002
1474 * @tc.desc: castTime is less than 1000
1475 * @tc.type: FUNC
1476 * @tc.require: NA
1477 */
1478 HWTEST_F(HwCastStreamPlayerTest, CheckCastTime002, TestSize.Level0)
1479 {
1480 SLOGI("CheckCastTime002 begin!");
1481 int32_t castTime = 1;
1482 int32_t ret = hwCastStreamPlayer->CheckCastTime(castTime);
1483 EXPECT_EQ(ret, 1000);
1484 SLOGI("CheckCastTime002 end!");
1485 }
1486
1487 /**
1488 * @tc.name: RepeatPrepare001
1489 * @tc.desc: test RepeatPrepare
1490 * @tc.type: FUNC
1491 * @tc.require: NA
1492 */
1493 HWTEST_F(HwCastStreamPlayerTest, RepeatPrepare001, TestSize.Level0)
1494 {
1495 SLOGI("RepeatPrepare001 begin!");
1496 std::shared_ptr<AVSessionPixelMap> mediaPixelMap = std::make_shared<AVSessionPixelMap>();
1497 std::vector<uint8_t> imgBuffer = {1, 0, 0, 0, 1};
1498 mediaPixelMap->SetInnerImgBuffer(imgBuffer);
1499
1500 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
1501 AVQueueItem avQueueItem;
1502 avQueueItem.SetDescription(description);
1503 hwCastStreamPlayer->RefreshCurrentAVQueueItem(avQueueItem);
1504 description->SetIconUri("URI_CACHE");
1505 description->SetIcon(mediaPixelMap);
1506 auto ret = hwCastStreamPlayer->RepeatPrepare(description);
1507 EXPECT_EQ(ret, true);
1508 SLOGI("RepeatPrepare001 end!");
1509 }
1510
1511 /**
1512 * @tc.name: SetValidAbility002
1513 * @tc.desc: test SetValidAbility
1514 * @tc.type: FUNC
1515 * @tc.require: NA
1516 */
1517 HWTEST_F(HwCastStreamPlayerTest, SetValidAbility002, TestSize.Level0)
1518 {
1519 SLOGI("SetValidAbility002 begin!");
1520 std::vector<int32_t> validAbilityList;
1521 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY);
1522 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PAUSE);
1523 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_STOP);
1524 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT);
1525 hwCastStreamPlayer->streamPlayer_ = nullptr;
1526 auto ret = hwCastStreamPlayer->SetValidAbility(validAbilityList);
1527 EXPECT_EQ(ret, AVSESSION_ERROR);
1528 SLOGI("SetValidAbility002 end!");
1529 }
1530
1531 /**
1532 * @tc.name: SetValidAbility003
1533 * @tc.desc: test all cmds in SetValidAbility
1534 * @tc.type: FUNC
1535 * @tc.require: NA
1536 */
1537 HWTEST_F(HwCastStreamPlayerTest, SetValidAbility003, TestSize.Level0)
1538 {
1539 SLOGI("SetValidAbility003 begin!");
1540 std::vector<int32_t> validAbilityList;
1541 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY);
1542 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PAUSE);
1543 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_STOP);
1544 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_NEXT);
1545 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_PLAY_PREVIOUS);
1546 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SEEK);
1547 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_FAST_FORWARD);
1548 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_REWIND);
1549 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SET_LOOP_MODE);
1550 validAbilityList.push_back(AVCastControlCommand::CAST_CONTROL_CMD_SET_VOLUME);
1551 validAbilityList.push_back(INVAILD_STATE_CODE);
1552 auto ret = hwCastStreamPlayer->SetValidAbility(validAbilityList);
1553 EXPECT_EQ(ret, AVSESSION_SUCCESS);
1554 SLOGI("SetValidAbility003 end!");
1555 }
1556
1557 /**
1558 * @tc.name: OnAlbumCoverChanged001
1559 * @tc.desc: test OnAlbumCoverChanged
1560 * @tc.type: FUNC
1561 * @tc.require: NA
1562 */
1563 HWTEST_F(HwCastStreamPlayerTest, OnAlbumCoverChanged001, TestSize.Level0)
1564 {
1565 SLOGI("OnAlbumCoverChanged001 begin!");
1566 OHOS::AVSession::AVMetaData metaData = GetAVMetaData();
1567 std::shared_ptr<AVSessionPixelMap> mediaPixelMap = metaData.GetMediaImage();
1568 std::shared_ptr<Media::PixelMap> pixelMap = AVSessionPixelMapAdapter::ConvertFromInner(mediaPixelMap);
1569 hwCastStreamPlayer->OnAlbumCoverChanged(pixelMap);
1570 SLOGI("OnAlbumCoverChanged001 end!");
1571 }
1572
1573 /**
1574 * @tc.name: OnAlbumCoverChanged002
1575 * @tc.desc: pixelMap is not nullptr but innerPixelMap is nullptr
1576 * @tc.type: FUNC
1577 * @tc.require: NA
1578 */
1579 HWTEST_F(HwCastStreamPlayerTest, OnAlbumCoverChanged002, TestSize.Level0)
1580 {
1581 SLOGI("OnAlbumCoverChanged002 begin!");
1582 auto pixelMap = std::make_shared<OHOS::Media::PixelMap>();
1583 hwCastStreamPlayer->OnAlbumCoverChanged(pixelMap);
1584 std::shared_ptr<AVSessionPixelMap> innerPixelMap =
1585 AVSessionPixelMapAdapter::ConvertToInnerWithLimitedSize(pixelMap);
1586 EXPECT_TRUE(innerPixelMap == nullptr);
1587 SLOGI("OnAlbumCoverChanged002 end!");
1588 }
1589
1590 /**
1591 * @tc.name: OnAlbumCoverChanged003
1592 * @tc.desc: pixelMap is not nullptr but innerPixelMap and nullptr
1593 * @tc.type: FUNC
1594 * @tc.require: NA
1595 */
1596 HWTEST_F(HwCastStreamPlayerTest, OnAlbumCoverChanged003, TestSize.Level0)
1597 {
1598 SLOGI("OnAlbumCoverChanged003 begin!");
1599 auto pixelMap = CreatePixelMap();
1600 hwCastStreamPlayer->OnAlbumCoverChanged(pixelMap);
1601 std::shared_ptr<AVSessionPixelMap> innerPixelMap =
1602 AVSessionPixelMapAdapter::ConvertToInnerWithLimitedSize(pixelMap);
1603 EXPECT_TRUE(innerPixelMap != nullptr);
1604 SLOGI("OnAlbumCoverChanged003 end!");
1605 }
1606
1607 /**
1608 * @tc.name: OnAlbumCoverChanged004
1609 * @tc.desc: pixelMap is not nullptr but innerPixelMap and nullptr
1610 * @tc.type: FUNC
1611 * @tc.require: NA
1612 */
1613 HWTEST_F(HwCastStreamPlayerTest, OnAlbumCoverChanged004, TestSize.Level0)
1614 {
1615 SLOGI("OnAlbumCoverChanged004 begin!");
1616 auto pixelMap = CreatePixelMap();
1617 hwCastStreamPlayer->OnAlbumCoverChanged(pixelMap);
1618 auto innerPixelMap = AVSessionPixelMapAdapter::ConvertToInnerWithLimitedSize(pixelMap);
1619 EXPECT_TRUE(innerPixelMap != nullptr);
1620 SLOGI("OnAlbumCoverChanged004 end!");
1621 }
1622
1623 /**
1624 * @tc.name: OnAlbumCoverChanged005
1625 * @tc.desc: pixelMap is not nullptr but innerPixelMap and nullptr
1626 * @tc.type: FUNC
1627 * @tc.require: NA
1628 */
1629 HWTEST_F(HwCastStreamPlayerTest, OnAlbumCoverChanged005, TestSize.Level0)
1630 {
1631 SLOGI("OnAlbumCoverChanged005 begin!");
1632 auto pixelMap = CreatePixelMap();
1633 std::shared_ptr<AVMediaDescription> description = CreateAVMediaDescription();
1634 AVQueueItem avQueueItem;
1635 avQueueItem.SetDescription(description);
1636 hwCastStreamPlayer->RefreshCurrentAVQueueItem(avQueueItem);
1637
1638 auto controller = std::make_shared<AVCastControllerItem>();
1639 hwCastStreamPlayer->streamPlayerListenerList_.push_back(controller);
1640 hwCastStreamPlayer->streamPlayerListenerList_.push_back(nullptr);
1641
1642 hwCastStreamPlayer->OnAlbumCoverChanged(pixelMap);
1643 auto innerPixelMap = AVSessionPixelMapAdapter::ConvertToInnerWithLimitedSize(pixelMap);
1644 EXPECT_TRUE(innerPixelMap != nullptr);
1645 SLOGI("OnAlbumCoverChanged005 end!");
1646 }
1647
1648 /**
1649 * @tc.name: GetMediaCapabilitiesOfVideo001
1650 * @tc.desc: json contains needed data
1651 * @tc.type: FUNC
1652 * @tc.require: NA
1653 */
1654 HWTEST_F(HwCastStreamPlayerTest, GetMediaCapabilitiesOfVideo001, TestSize.Level0)
1655 {
1656 string capabilities = R"(
1657 {
1658 "decoderType": ["H264", "H265"],
1659 "decoderSupportResolution": {"video/hevc": 0, "video/avc": 1},
1660 "HDRFormat": 1,
1661 "speed": 1
1662 })";
1663
1664 cJSON* value = cJSON_Parse(capabilities.c_str());
1665 EXPECT_NE(value == nullptr, true);
1666 EXPECT_NE(cJSON_IsInvalid(value), true);
1667 hwCastStreamPlayer->GetMediaCapabilitiesOfVideo(value);
1668 if (value != nullptr) {
1669 cJSON_Delete(value);
1670 }
1671 auto vec = hwCastStreamPlayer->jsonCapabilitiesSptr_->decoderTypes_;
1672 EXPECT_NE(std::find(vec.begin(), vec.end(), "H264"), vec.end());
1673
1674 string resolution = "H264";
1675 ResolutionLevel level;
1676 auto ret = hwCastStreamPlayer->GetRecommendedResolutionLevel(resolution, level);
1677 EXPECT_EQ(ret, AVSESSION_ERROR);
1678
1679 std::vector<HDRFormat> hdrFormats;
1680 ret = hwCastStreamPlayer->GetSupportedHdrCapabilities(hdrFormats);
1681 EXPECT_EQ(ret, AVSESSION_SUCCESS);
1682
1683 std::vector<float> playSpeeds;
1684 hwCastStreamPlayer->jsonCapabilitiesSptr_->playSpeeds_.push_back(1.0f);
1685 ret = hwCastStreamPlayer->GetSupportedPlaySpeeds(playSpeeds);
1686 EXPECT_EQ(ret, AVSESSION_SUCCESS);
1687 }
1688
1689 /**
1690 * @tc.name: GetMediaCapabilitiesOfVideo002
1691 * @tc.desc: json not contains needed data
1692 * @tc.type: FUNC
1693 * @tc.require: NA
1694 */
1695 HWTEST_F(HwCastStreamPlayerTest, GetMediaCapabilitiesOfVideo002, TestSize.Level0)
1696 {
1697 string capabilities = R"(
1698 {
1699 "decoderType_NA": ["H264", "H265"],
1700 "decoderSupportResolution_NA": {"video/hevc": 0, "video/avc": 1},
1701 "HDRFormat_NA": 1
1702 })";
1703
1704 cJSON* value = cJSON_Parse(capabilities.c_str());
1705 EXPECT_NE(value == nullptr, true);
1706 EXPECT_NE(cJSON_IsInvalid(value), true);
1707 hwCastStreamPlayer->GetMediaCapabilitiesOfVideo(value);
1708 if (value != nullptr) {
1709 cJSON_Delete(value);
1710 }
1711
1712 auto vec = hwCastStreamPlayer->jsonCapabilitiesSptr_->decoderTypes_;
1713 EXPECT_EQ(std::find(vec.begin(), vec.end(), "H264"), vec.end());
1714 }
1715
1716 /**
1717 * @tc.name: GetMediaCapabilitiesOfAudio001
1718 * @tc.desc: json contains needed data
1719 * @tc.type: FUNC
1720 * @tc.require: NA
1721 */
1722 HWTEST_F(HwCastStreamPlayerTest, GetMediaCapabilitiesOfAudio001, TestSize.Level0)
1723 {
1724 string capabilities = R"(
1725 {
1726 "decoderType": "mp3"
1727 })";
1728
1729 cJSON* value = cJSON_Parse(capabilities.c_str());
1730 EXPECT_NE(value == nullptr, true);
1731 EXPECT_NE(cJSON_IsInvalid(value), true);
1732 hwCastStreamPlayer->GetMediaCapabilitiesOfAudio(value);
1733 if (value != nullptr) {
1734 cJSON_Delete(value);
1735 }
1736
1737 auto vec = hwCastStreamPlayer->jsonCapabilitiesSptr_->decoderTypes_;
1738 EXPECT_NE(std::find(vec.begin(), vec.end(), "mp3"), vec.end());
1739
1740 std::vector<std::string> decoderTypes;
1741 auto ret = hwCastStreamPlayer->GetSupportedDecoders(decoderTypes);
1742 EXPECT_EQ(ret, AVSESSION_SUCCESS);
1743 }
1744
1745 /**
1746 * @tc.name: GetMediaCapabilitiesOfAudio002
1747 * @tc.desc: json not contains needed data
1748 * @tc.type: FUNC
1749 * @tc.require: NA
1750 */
1751 HWTEST_F(HwCastStreamPlayerTest, GetMediaCapabilitiesOfAudio002, TestSize.Level0)
1752 {
1753 string capabilities = R"(
1754 {
1755 "decoderType_NA": "mp3"
1756 })";
1757
1758 cJSON* value = cJSON_Parse(capabilities.c_str());
1759 EXPECT_NE(value == nullptr, true);
1760 EXPECT_NE(cJSON_IsInvalid(value), true);
1761 hwCastStreamPlayer->GetMediaCapabilitiesOfAudio(value);
1762 if (value != nullptr) {
1763 cJSON_Delete(value);
1764 }
1765
1766 auto vec = hwCastStreamPlayer->jsonCapabilitiesSptr_->decoderTypes_;
1767 EXPECT_EQ(std::find(vec.begin(), vec.end(), "mp3"), vec.end());
1768 }
1769
1770 /**
1771 * @tc.name: checkCmdsFromAbility001
1772 * @tc.desc: test checkCmdsFromAbility when isFastForwardSupported is true
1773 * @tc.type: FUNC
1774 * @tc.require: NA
1775 */
1776 HWTEST_F(HwCastStreamPlayerTest, checkCmdsFromAbility001, TestSize.Level0)
1777 {
1778 StreamCapability avStreamCapability = {
1779 .isFastForwardSupported = true,
1780 .isFastRewindSupported = true,
1781 .isLoopModeSupported = true,
1782 .isSetVolumeSupported = true,
1783 };
1784 std::vector<int32_t> supportedCastCmds;
1785 hwCastStreamPlayer->checkCmdsFromAbility(avStreamCapability, supportedCastCmds);
1786 EXPECT_NE(std::find(supportedCastCmds.begin(), supportedCastCmds.end(), 5), supportedCastCmds.end());
1787 }
1788
1789 /**
1790 * @tc.name: checkAbilityFromCmds001
1791 * @tc.desc: test checkAbilityFromCmds
1792 * @tc.type: FUNC
1793 * @tc.require: NA
1794 */
1795 HWTEST_F(HwCastStreamPlayerTest, checkAbilityFromCmds001, TestSize.Level0)
1796 {
1797 std::vector<int32_t> supportedCastCmds;
1798 for (auto i = 0; i <= AVCastControlCommand::CAST_CONTROL_CMD_MAX; i++) {
1799 supportedCastCmds.push_back(i);
1800 }
1801 CastEngine::StreamCapability streamCapability;
1802 hwCastStreamPlayer->checkAbilityFromCmds(supportedCastCmds, streamCapability);
1803 EXPECT_EQ(streamCapability.isFastForwardSupported, true);
1804 }
1805 } // namespace AVSession
1806 } // namespace OHOS
1807