1 /*
2 * Copyright (c) 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 #include <chrono>
18 #include <thread>
19
20 #include "accesstoken_kit.h"
21 #include "nativetoken_kit.h"
22 #include "token_setproc.h"
23 #include "avmeta_data.h"
24 #include "avplayback_state.h"
25 #include "avsession_service.h"
26 #include "avsession_errors.h"
27 #include "avsession_item.h"
28 #include "avsession_log.h"
29 #include "migrate_avsession_constant.h"
30 #include "migrate_avsession_manager.h"
31 #include "migrate_avsession_proxy.h"
32 #include "system_ability_definition.h"
33 #include "softbus/softbus_session_utils.h"
34
35 using namespace testing::ext;
36 using namespace OHOS::AVSession;
37
38 static std::shared_ptr<AVSessionService> g_AVSessionService {nullptr};
39 static std::shared_ptr<MigrateAVSessionProxy> g_MigrateAVSessionProxy {nullptr};
40 static std::shared_ptr<AVSessionObserver> g_AVSessionObserver {nullptr};
41
42 class MigrateAVSessionProxyTest : public testing::Test {
43 public:
44 static void SetUpTestCase();
45 static void TearDownTestCase();
46 void SetUp();
47 void TearDown();
48 };
49
SetUpTestCase()50 void MigrateAVSessionProxyTest::SetUpTestCase()
51 {
52 SLOGI("MigrateAVSessionProxyTest SetUpTestCase");
53 g_AVSessionService = std::make_shared<AVSessionService>(OHOS::AVSESSION_SERVICE_ID);
54 g_MigrateAVSessionProxy = std::make_shared<MigrateAVSessionProxy>(g_AVSessionService.get());
55 g_AVSessionObserver = std::make_shared<AVSessionObserver>();
56 }
57
TearDownTestCase()58 void MigrateAVSessionProxyTest::TearDownTestCase()
59 {
60 SLOGI("MigrateAVSessionProxyTest TearDownTestCase");
61 g_MigrateAVSessionProxy = nullptr;
62 g_AVSessionService = nullptr;
63 g_AVSessionObserver = nullptr;
64 }
65
SetUp()66 void MigrateAVSessionProxyTest::SetUp()
67 {
68 SLOGI("MigrateAVSessionProxyTest SetUp");
69 }
70
TearDown()71 void MigrateAVSessionProxyTest::TearDown()
72 {
73 SLOGI("MigrateAVSessionProxyTest TearDown");
74 }
75
76 /**
77 * @tc.name: MigrateAVSessionProxyControllerCallback001
78 * @tc.desc: not find func
79 * @tc.type: FUNC
80 * @tc.require:
81 */
82 static HWTEST_F(MigrateAVSessionProxyTest, MigrateAVSessionProxyControllerCallback001, TestSize.Level0)
83 {
84 MigrateAVSessionProxyControllerCallbackFunc func =
85 g_MigrateAVSessionProxy->MigrateAVSessionProxyControllerCallback();
86 std::string extraEvent = "";
87 OHOS::AAFwk::WantParams extras;
88 int32_t ret = func(extraEvent, extras);
89 EXPECT_EQ(ret, ERR_COMMAND_NOT_SUPPORT);
90 }
91
92 /**
93 * @tc.name: MigrateAVSessionProxyControllerCallback002
94 * @tc.desc: find the func
95 * @tc.type: FUNC
96 * @tc.require:
97 */
98 static HWTEST_F(MigrateAVSessionProxyTest, MigrateAVSessionProxyControllerCallback002, TestSize.Level0)
99 {
100 auto maps = g_MigrateAVSessionProxy->AUDIO_EVENT_MAPS;
101 MigrateAVSessionProxyControllerCallbackFunc func =
102 g_MigrateAVSessionProxy->MigrateAVSessionProxyControllerCallback();
103 for (auto it = maps.begin(); it != maps.end(); ++it) {
104 std::string extraEvent = it->first;
105 OHOS::AAFwk::WantParams extras;
106 int32_t ret = func(extraEvent, extras);
107 EXPECT_EQ(ret, AVSESSION_SUCCESS);
108 }
109 }
110
111 /**
112 * @tc.name: ProcessSessionInfo001
113 * @tc.desc: test the member of ProcessSessionInfo
114 * @tc.type: FUNC
115 * @tc.require:
116 */
117 static HWTEST_F(MigrateAVSessionProxyTest, ProcessSessionInfo001, TestSize.Level0)
118 {
119 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
120 EXPECT_NE(jsonValue, nullptr);
121 if (jsonValue == nullptr) {
122 SLOGE("create jsonvalue nullptr");
123 FAIL();
124 }
125 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, "test", "test")) {
126 SLOGE("AddStringToJson fail");
127 cJSON_Delete(jsonValue);
128 jsonValue = nullptr;
129 FAIL();
130 }
131 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
132 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
133 g_MigrateAVSessionProxy->ProcessSessionInfo(jsonValue);
134 cJSON_Delete(jsonValue);
135 }
136
137 /**
138 * @tc.name: ProcessSessionInfo002
139 * @tc.desc: test the member of ProcessSessionInfo
140 * @tc.type: FUNC
141 * @tc.require:
142 */
143 static HWTEST_F(MigrateAVSessionProxyTest, ProcessSessionInfo002, TestSize.Level0)
144 {
145 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
146 EXPECT_NE(jsonValue, nullptr);
147 if (jsonValue == nullptr) {
148 SLOGE("create jsonvalue nullptr");
149 FAIL();
150 }
151 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_SESSION_ID, "") ||
152 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_BUNDLE_NAME, "") ||
153 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_ABILITY_NAME, "")) {
154 SLOGE("AddStringToJson fail");
155 cJSON_Delete(jsonValue);
156 jsonValue = nullptr;
157 FAIL();
158 }
159
160 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
161 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
162 g_MigrateAVSessionProxy->ProcessSessionInfo(jsonValue);
163 cJSON_Delete(jsonValue);
164 }
165
166 /**
167 * @tc.name: ProcessSessionInfo003
168 * @tc.desc: test the member of ProcessSessionInfo
169 * @tc.type: FUNC
170 * @tc.require:
171 */
172 static HWTEST_F(MigrateAVSessionProxyTest, ProcessSessionInfo003, TestSize.Level0)
173 {
174 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
175 EXPECT_NE(jsonValue, nullptr);
176 if (jsonValue == nullptr) {
177 SLOGE("create jsonvalue nullptr");
178 FAIL();
179 }
180 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_SESSION_ID, DEFAULT_STRING) ||
181 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_BUNDLE_NAME, DEFAULT_STRING) ||
182 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_ABILITY_NAME, DEFAULT_STRING)) {
183 SLOGE("AddStringToJson fail");
184 cJSON_Delete(jsonValue);
185 jsonValue = nullptr;
186 FAIL();
187 }
188
189 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
190 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
191 g_MigrateAVSessionProxy->ProcessSessionInfo(jsonValue);
192 cJSON_Delete(jsonValue);
193 }
194
195 /**
196 * @tc.name: ProcessSessionInfo004
197 * @tc.desc: test the member of ProcessSessionInfo
198 * @tc.type: FUNC
199 * @tc.require:
200 */
201 static HWTEST_F(MigrateAVSessionProxyTest, ProcessSessionInfo004, TestSize.Level0)
202 {
203 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
204 EXPECT_NE(jsonValue, nullptr);
205 if (jsonValue == nullptr) {
206 SLOGE("create jsonvalue nullptr");
207 FAIL();
208 }
209 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_SESSION_ID, EMPTY_SESSION) ||
210 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_BUNDLE_NAME, EMPTY_SESSION) ||
211 !SoftbusSessionUtils::AddStringToJson(jsonValue, MIGRATE_ABILITY_NAME, EMPTY_SESSION)) {
212 SLOGE("AddStringToJson fail");
213 cJSON_Delete(jsonValue);
214 jsonValue = nullptr;
215 FAIL();
216 }
217
218 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
219 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
220 g_MigrateAVSessionProxy->ProcessSessionInfo(jsonValue);
221 cJSON_Delete(jsonValue);
222 }
223
224 /**
225 * @tc.name: ProcessMetaData001
226 * @tc.desc: test the member of ProcessMetaData
227 * @tc.type: FUNC
228 * @tc.require:
229 */
230 static HWTEST_F(MigrateAVSessionProxyTest, ProcessMetaData001, TestSize.Level0)
231 {
232 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
233 EXPECT_NE(jsonValue, nullptr);
234 if (jsonValue == nullptr) {
235 SLOGE("create jsonvalue nullptr");
236 FAIL();
237 }
238 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, METADATA_TITLE, METADATA_TITLE) ||
239 !SoftbusSessionUtils::AddStringToJson(jsonValue, METADATA_ARTIST, METADATA_ARTIST)) {
240 SLOGE("AddStringToJson fail");
241 cJSON_Delete(jsonValue);
242 jsonValue = nullptr;
243 FAIL();
244 }
245
246 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
247 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
248 g_MigrateAVSessionProxy->ProcessMetaData(jsonValue);
249 cJSON_Delete(jsonValue);
250 }
251
252 /**
253 * @tc.name: ProcessMetaData002
254 * @tc.desc: test the member of ProcessMetaData
255 * @tc.type: FUNC
256 * @tc.require:
257 */
258 static HWTEST_F(MigrateAVSessionProxyTest, ProcessMetaData002, TestSize.Level0)
259 {
260 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
261 EXPECT_NE(jsonValue, nullptr);
262 if (jsonValue == nullptr) {
263 SLOGE("create jsonvalue nullptr");
264 FAIL();
265 }
266 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, "test", "test")) {
267 SLOGE("AddStringToJson fail");
268 cJSON_Delete(jsonValue);
269 jsonValue = nullptr;
270 FAIL();
271 }
272
273 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
274 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
275 g_MigrateAVSessionProxy->ProcessMetaData(jsonValue);
276 cJSON_Delete(jsonValue);
277 }
278
279 /**
280 * @tc.name: ProcessPlaybackState001
281 * @tc.desc: test the member of ProcessPlaybackState
282 * @tc.type: FUNC
283 * @tc.require:
284 */
285 static HWTEST_F(MigrateAVSessionProxyTest, ProcessPlaybackState001, TestSize.Level0)
286 {
287 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
288 EXPECT_NE(jsonValue, nullptr);
289 if (jsonValue == nullptr) {
290 SLOGE("create jsonvalue nullptr");
291 FAIL();
292 }
293 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, PLAYBACK_STATE, PLAYBACK_STATE) ||
294 !SoftbusSessionUtils::AddStringToJson(jsonValue, FAVOR_STATE, FAVOR_STATE)) {
295 SLOGE("AddStringToJson fail");
296 cJSON_Delete(jsonValue);
297 jsonValue = nullptr;
298 FAIL();
299 }
300
301 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
302 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
303 g_MigrateAVSessionProxy->ProcessPlaybackState(jsonValue);
304 cJSON_Delete(jsonValue);
305 }
306
307 /**
308 * @tc.name: ProcessPlaybackState002
309 * @tc.desc: test the member of ProcessPlaybackState
310 * @tc.type: FUNC
311 * @tc.require:
312 */
313 static HWTEST_F(MigrateAVSessionProxyTest, ProcessPlaybackState002, TestSize.Level0)
314 {
315 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
316 EXPECT_NE(jsonValue, nullptr);
317 if (jsonValue == nullptr) {
318 SLOGE("create jsonvalue nullptr");
319 FAIL();
320 }
321 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, "test", "test")) {
322 SLOGE("AddStringToJson fail");
323 cJSON_Delete(jsonValue);
324 jsonValue = nullptr;
325 FAIL();
326 }
327
328 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
329 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
330 g_MigrateAVSessionProxy->ProcessPlaybackState(jsonValue);
331 cJSON_Delete(jsonValue);
332 }
333
334 /**
335 * @tc.name: ProcessValidCommands001
336 * @tc.desc: test the member of ProcessValidCommands
337 * @tc.type: FUNC
338 * @tc.require:
339 */
340 static HWTEST_F(MigrateAVSessionProxyTest, ProcessValidCommands001, TestSize.Level0)
341 {
342 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
343 EXPECT_NE(jsonValue, nullptr);
344 if (jsonValue == nullptr) {
345 SLOGE("create jsonvalue nullptr");
346 FAIL();
347 }
348 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, VALID_COMMANDS, VALID_COMMANDS)) {
349 SLOGE("AddStringToJson fail");
350 cJSON_Delete(jsonValue);
351 jsonValue = nullptr;
352 FAIL();
353 }
354
355 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
356 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
357 g_MigrateAVSessionProxy->ProcessValidCommands(jsonValue);
358 cJSON_Delete(jsonValue);
359 }
360
361 /**
362 * @tc.name: ProcessValidCommands002
363 * @tc.desc: test the member of ProcessValidCommands
364 * @tc.type: FUNC
365 * @tc.require:
366 */
367 static HWTEST_F(MigrateAVSessionProxyTest, ProcessValidCommands002, TestSize.Level0)
368 {
369 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
370 EXPECT_NE(jsonValue, nullptr);
371 if (jsonValue == nullptr) {
372 SLOGE("create jsonvalue nullptr");
373 FAIL();
374 }
375 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, "test", "test")) {
376 SLOGE("AddStringToJson fail");
377 cJSON_Delete(jsonValue);
378 jsonValue = nullptr;
379 FAIL();
380 }
381
382 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
383 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
384 g_MigrateAVSessionProxy->ProcessValidCommands(jsonValue);
385 cJSON_Delete(jsonValue);
386 }
387
388 /**
389 * @tc.name: ProcessVolumeControlCommand001
390 * @tc.desc: test the member of ProcessVolumeControlCommand
391 * @tc.type: FUNC
392 * @tc.require:
393 */
394 static HWTEST_F(MigrateAVSessionProxyTest, ProcessVolumeControlCommand001, TestSize.Level0)
395 {
396 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
397 EXPECT_NE(jsonValue, nullptr);
398 if (jsonValue == nullptr) {
399 SLOGE("create jsonvalue nullptr");
400 FAIL();
401 }
402 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, AUDIO_VOLUME, AUDIO_VOLUME)) {
403 SLOGE("AddStringToJson fail");
404 cJSON_Delete(jsonValue);
405 jsonValue = nullptr;
406 FAIL();
407 }
408
409 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
410 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
411 g_MigrateAVSessionProxy->ProcessVolumeControlCommand(jsonValue);
412 cJSON_Delete(jsonValue);
413 }
414
415 /**
416 * @tc.name: ProcessVolumeControlCommand002
417 * @tc.desc: test the member of ProcessVolumeControlCommand
418 * @tc.type: FUNC
419 * @tc.require:
420 */
421 static HWTEST_F(MigrateAVSessionProxyTest, ProcessVolumeControlCommand002, TestSize.Level0)
422 {
423 cJSON* jsonValue = SoftbusSessionUtils::GetNewCJSONObject();
424 EXPECT_NE(jsonValue, nullptr);
425 if (jsonValue == nullptr) {
426 SLOGE("create jsonvalue nullptr");
427 FAIL();
428 }
429 if (!SoftbusSessionUtils::AddStringToJson(jsonValue, "test", "test")) {
430 SLOGE("AddStringToJson fail");
431 cJSON_Delete(jsonValue);
432 jsonValue = nullptr;
433 FAIL();
434 }
435
436 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
437 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
438 g_MigrateAVSessionProxy->ProcessVolumeControlCommand(jsonValue);
439 cJSON_Delete(jsonValue);
440 }
441
442 /**
443 * @tc.name: ProcessAvailableDevices001
444 * @tc.desc: test the member of ProcessAvailableDevices
445 * @tc.type: FUNC
446 * @tc.require:
447 */
448 static HWTEST_F(MigrateAVSessionProxyTest, ProcessAvailableDevices001, TestSize.Level0)
449 {
450 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
451 EXPECT_EQ(g_MigrateAVSessionProxy->preSetController_ != nullptr, true);
452
453 auto devices = AudioAdapter::GetInstance().GetAvailableDevices();
454 cJSON* jsonValue = MigrateAVSessionServer::ConvertAudioDeviceDescriptorsToJson(devices);
455 g_MigrateAVSessionProxy->ProcessAvailableDevices(jsonValue);
456 cJSON_Delete(jsonValue);
457 }
458
459 /**
460 * @tc.name: ProcessPreferredOutputDevice001
461 * @tc.desc: test the member of ProcessPreferredOutputDevice
462 * @tc.type: FUNC
463 * @tc.require:
464 */
465 static HWTEST_F(MigrateAVSessionProxyTest, ProcessPreferredOutputDevice001, TestSize.Level0)
466 {
467 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
468 EXPECT_EQ(g_MigrateAVSessionProxy->preSetController_ != nullptr, true);
469
470 auto devices = AudioAdapter::GetInstance().GetPreferredOutputDeviceForRendererInfo();
471 cJSON* jsonValue = MigrateAVSessionServer::ConvertAudioDeviceDescriptorsToJson(devices);
472 g_MigrateAVSessionProxy->ProcessPreferredOutputDevice(jsonValue);
473 cJSON_Delete(jsonValue);
474 }
475
476 /**
477 * @tc.name: ProcessBundleImg001
478 * @tc.desc: test the member of ProcessBundleImg
479 * @tc.type: FUNC
480 * @tc.require:
481 */
482 static HWTEST_F(MigrateAVSessionProxyTest, ProcessBundleImg001, TestSize.Level0)
483 {
484 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
485 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
486 std::string bundleIconStr = "";
487 g_MigrateAVSessionProxy->ProcessBundleImg(bundleIconStr);
488 }
489
490 /**
491 * @tc.name: ProcessBundleImg002
492 * @tc.desc: test the member of ProcessBundleImg
493 * @tc.type: FUNC
494 * @tc.require:
495 */
496 static HWTEST_F(MigrateAVSessionProxyTest, ProcessBundleImg002, TestSize.Level0)
497 {
498 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
499 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
500 std::string bundleIconStr = "test";
501 g_MigrateAVSessionProxy->ProcessBundleImg(bundleIconStr);
502 }
503
504 /**
505 * @tc.name: ProcessBundleImg003
506 * @tc.desc: test the member of ProcessBundleImg
507 * @tc.type: FUNC
508 * @tc.require:
509 */
510 static HWTEST_F(MigrateAVSessionProxyTest, ProcessBundleImg003, TestSize.Level0)
511 {
512 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
513 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
514 AVMetaData metaData;
515 g_MigrateAVSessionProxy->remoteSession_->SetAVMetaData(metaData);
516 std::string bundleIconStr = "test";
517 g_MigrateAVSessionProxy->ProcessBundleImg(bundleIconStr);
518 }
519
520 /**
521 * @tc.name: ProcessMediaImage001
522 * @tc.desc: test the member of ProcessMediaImage
523 * @tc.type: FUNC
524 * @tc.require:
525 */
526 static HWTEST_F(MigrateAVSessionProxyTest, ProcessMediaImage001, TestSize.Level0)
527 {
528 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
529 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
530 std::string bundleIconStr = "";
531 g_MigrateAVSessionProxy->ProcessMediaImage(bundleIconStr);
532 }
533
534 /**
535 * @tc.name: ProcessMediaImage002
536 * @tc.desc: test the member of ProcessMediaImage
537 * @tc.type: FUNC
538 * @tc.require:
539 */
540 static HWTEST_F(MigrateAVSessionProxyTest, ProcessMediaImage002, TestSize.Level0)
541 {
542 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
543 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
544 std::string bundleIconStr = "test";
545 g_MigrateAVSessionProxy->ProcessMediaImage(bundleIconStr);
546 }
547
548 /**
549 * @tc.name: ProcessMediaImage003
550 * @tc.desc: test the member of ProcessMediaImage
551 * @tc.type: FUNC
552 * @tc.require:
553 */
554 static HWTEST_F(MigrateAVSessionProxyTest, ProcessMediaImage003, TestSize.Level0)
555 {
556 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
557 EXPECT_EQ(g_MigrateAVSessionProxy->remoteSession_ != nullptr, true);
558 AVMetaData metaData;
559 g_MigrateAVSessionProxy->remoteSession_->SetAVMetaData(metaData);
560 std::string bundleIconStr = "test";
561 g_MigrateAVSessionProxy->ProcessMediaImage(bundleIconStr);
562 }
563
564 /**
565 * @tc.name: OnConnectServer001
566 * @tc.desc: test the member of OnConnectServer
567 * @tc.type: FUNC
568 * @tc.require:
569 */
570 static HWTEST_F(MigrateAVSessionProxyTest, OnConnectServer001, TestSize.Level0)
571 {
572 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
573 EXPECT_TRUE(g_MigrateAVSessionProxy->remoteSession_ != nullptr);
574 std::string deviceId = "123";
575 g_MigrateAVSessionProxy->OnConnectServer(deviceId);
576 }
577
578 /**
579 * @tc.name: OnDisconnectServer001
580 * @tc.desc: test the member of OnDisconnectServer
581 * @tc.type: FUNC
582 * @tc.require:
583 */
584 static HWTEST_F(MigrateAVSessionProxyTest, OnDisconnectServer001, TestSize.Level0)
585 {
586 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
587 EXPECT_TRUE(g_MigrateAVSessionProxy->remoteSession_ != nullptr);
588 std::string deviceId = "123";
589 g_MigrateAVSessionProxy->OnDisconnectServer(deviceId);
590 }
591
592 /**
593 * @tc.name: OnBytesReceived001
594 * @tc.desc: test the member of OnBytesReceived
595 * @tc.type: FUNC
596 * @tc.require:
597 */
598 static HWTEST_F(MigrateAVSessionProxyTest, OnBytesReceived001, TestSize.Level0)
599 {
600 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
601 EXPECT_TRUE(g_MigrateAVSessionProxy->remoteSession_ != nullptr);
602 std::string deviceId = "123";
603 std::string msg = "test";
604 g_MigrateAVSessionProxy->OnBytesReceived(deviceId, msg);
605 }
606
607 /**
608 * @tc.name: PrepareSessionFromRemote_WhenTargetLoopModeSet_Success
609 * @tc.desc: test the member of PrepareSessionFromRemote
610 * @tc.type: FUNC
611 * @tc.require:
612 */
613 static HWTEST_F(MigrateAVSessionProxyTest, PrepareSessionFromRemote_WhenTargetLoopModeSet_Success, TestSize.Level0)
614 {
615 int32_t targetLoopMode = 0;
616 std::string bundleIconStr = "";
617 g_AVSessionObserver->OnSetTargetLoopMode(targetLoopMode);
618 ASSERT_TRUE(g_MigrateAVSessionProxy != nullptr);
619 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
620 EXPECT_NE(g_MigrateAVSessionProxy->remoteSession_, nullptr);
621 }
622
623 /**
624 * @tc.name: PrepareSessionFromRemote_WhenValidBundleIcon_ExpectSuccess
625 * @tc.desc: test the member of PrepareSessionFromRemote
626 * @tc.type: FUNC
627 * @tc.require:
628 */
629 static HWTEST_F(MigrateAVSessionProxyTest, PrepareSessionFromRemote_WhenValidBundleIcon_Success, TestSize.Level1)
630 {
631 std::string assetId = "test";
632 std::string bundleIconStr = "123";
633 g_AVSessionObserver->OnPlayWithAssetId(assetId);
634 ASSERT_TRUE(g_MigrateAVSessionProxy != nullptr);
635 g_MigrateAVSessionProxy->PrepareSessionFromRemote();
636 EXPECT_NE(g_MigrateAVSessionProxy->preSetController_, nullptr);
637 g_MigrateAVSessionProxy->ProcessMediaImage(bundleIconStr);
638 }
639