• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
18 #include <fstream>
19 #include <cstdio>
20 #include <cstring>
21 #include "avsession_log.h"
22 #include "input_manager.h"
23 #include "key_event.h"
24 #include "avsession_manager.h"
25 #include "avsession_errors.h"
26 #include "avmeta_data.h"
27 #include "avplayback_state.h"
28 #include "avmedia_description.h"
29 #include "avqueue_item.h"
30 #include "avsession_log.h"
31 #include "nativetoken_kit.h"
32 #include "token_setproc.h"
33 #include "accesstoken_kit.h"
34 #include "system_ability_definition.h"
35 #include "system_ability_ondemand_reason.h"
36 #include "audio_info.h"
37 #include "avsession_callback_client.h"
38 #include "avsession_pixel_map.h"
39 #include "avsession_pixel_map_adapter.h"
40 #include "avsession_info.h"
41 #include "avsession_service.h"
42 #include "avsession_service_proxy.h"
43 
44 using namespace testing::ext;
45 using namespace OHOS::AVSession;
46 using namespace OHOS::Security::AccessToken;
47 using namespace OHOS::AudioStandard;
48 
49 static std::shared_ptr<AVSessionService> g_AVSessionService {nullptr};
50 
51 class AVSessionServiceAddedTest : public testing::Test {
52 public:
53     static void SetUpTestCase();
54     static void TearDownTestCase();
55     void SetUp() override;
56     void TearDown() override;
57 };
58 
SetUpTestCase()59 void AVSessionServiceAddedTest::SetUpTestCase()
60 {
61     SLOGI("set up AVSessionServiceAddedTest");
62     system("killall -9 com.example.hiMusicDemo");
63     sleep(1);
64     g_AVSessionService = std::make_shared<AVSessionService>(OHOS::AVSESSION_SERVICE_ID);
65     g_AVSessionService->InitKeyEvent();
66 }
67 
TearDownTestCase()68 void AVSessionServiceAddedTest::TearDownTestCase()
69 {
70     g_AVSessionService->Close();
71 }
72 
SetUp()73 void AVSessionServiceAddedTest::SetUp() {}
74 
TearDown()75 void AVSessionServiceAddedTest::TearDown() {}
76 
77 /**
78  * @tc.name: SuperLauncher001
79  * @tc.desc: Verifying NotifyFlowControl with a non-full flow control list.
80  * @tc.type: FUNC
81  * @tc.require: #I5Y4MZ
82  */
83 static HWTEST_F(AVSessionServiceAddedTest, SuperLauncher001, TestSize.Level1)
84 {
85     SLOGD("SuperLauncher001 begin!");
86     std::string deviceId = "IDLE";
87     std::string serviceName = "SuperLauncher-Dual";
88     std::string extraInfo = "extra";
89     const std::string& state = "CONNECTING";
90     g_AVSessionService->migrateAVSession_ = nullptr;
91     g_AVSessionService->SuperLauncher(deviceId, serviceName, extraInfo, state);
92     ASSERT_TRUE(g_AVSessionService != nullptr);
93     SLOGD("SuperLauncher001 end!");
94 }
95 
96 /**
97  * @tc.name: SuperLauncher002
98  * @tc.desc: Verifying NotifyFlowControl with a non-full flow control list.
99  * @tc.type: FUNC
100  * @tc.require: #I5Y4MZ
101  */
102 static HWTEST_F(AVSessionServiceAddedTest, SuperLauncher002, TestSize.Level1)
103 {
104     SLOGD("SuperLauncher002 begin!");
105     std::string deviceId = "NOTIDLE";
106     std::string serviceName = "SuperLauncher-Dual";
107     std::string extraInfo = "extra";
108     const std::string& state = "CONNECTING";
109     g_AVSessionService->SuperLauncher(deviceId, serviceName, extraInfo, state);
110     g_AVSessionService->migrateAVSession_ = std::make_shared<MigrateAVSessionServer>();
111     ASSERT_TRUE(g_AVSessionService != nullptr);
112     SLOGD("SuperLauncher002 end!");
113 }
114 
115 
116 /**
117  * @tc.name: SuperLauncherTest003
118  * @tc.desc: Verifies the behavior of SuperLauncher for HuaweiCast service.
119  * @tc.type: FUNC
120  * @tc.require: #I5Y4MZ
121  */
122 static HWTEST_F(AVSessionServiceAddedTest, SuperLauncherTest003, TestSize.Level1)
123 {
124     SLOGD("SuperLauncherTest003 begin!");
125     #ifdef CASTPLUS_CAST_ENGINE_ENABLE
126     std::string deviceId = "NOTIDLE";
127     std::string serviceName = "HuaweiCast";
128     std::string extraInfo = "extra";
129     const std::string& state = "IDLE";
130     g_AVSessionService->SuperLauncher(deviceId, serviceName, extraInfo, state);
131     g_AVSessionService->migrateAVSession_ = std::make_shared<MigrateAVSessionServer>();
132     #endif
133     ASSERT_TRUE(g_AVSessionService != nullptr);
134     SLOGD("SuperLauncherTest003 end!");
135 }
136 
137 /**
138  * @tc.name: SuperLauncherTest004
139  * @tc.desc: Verifies the behavior of SuperLauncher for HuaweiCast service.
140  * @tc.type: FUNC
141  * @tc.require: #I5Y4MZ
142  */
143 static HWTEST_F(AVSessionServiceAddedTest, SuperLauncherTest004, TestSize.Level1)
144 {
145     SLOGD("SuperLauncherTest004 begin!");
146     #ifdef CASTPLUS_CAST_ENGINE_ENABLE
147     SLOGD("SuperLauncherTest005 begin!");
148     std::string deviceId = "NOTIDLE";
149     std::string serviceName = "HuaweiCast";
150     std::string extraInfo = "extra";
151     const std::string& state = "CONNECT_SUCC";
152     g_AVSessionService->SuperLauncher(deviceId, serviceName, extraInfo, state);
153     g_AVSessionService->migrateAVSession_ = std::make_shared<MigrateAVSessionServer>();
154     g_AVSessionService->is2in1_ = true;
155     #endif
156     ASSERT_TRUE(g_AVSessionService != nullptr);
157     SLOGD("SuperLauncherTest004 end!");
158 }
159 
160 /**
161  * @tc.name: SuperLauncherTest005
162  * @tc.desc: test SplitExtraInfo
163  * @tc.type: FUNC
164  * @tc.require: #I5Y4MZ
165  */
166 static HWTEST_F(AVSessionServiceAddedTest, SuperLauncherTest005, TestSize.Level1)
167 {
168     SLOGD("SuperLauncherTest005 begin!");
169     #ifdef CASTPLUS_CAST_ENGINE_ENABLE
170     SLOGD("SuperLauncherTest006 begin!");
171     std::string deviceId = "test_device_id";
172     std::string serviceName = "HuaweiCast";
173     std::string extraInfo = "SUPPORT_MIRROR_TO_STREAM=true;deviceId:1001;deviceName:TestDevice;deviceType:5";
174     const std::string& state = "CONNECT_SUCC";
175     g_AVSessionService->SuperLauncher(deviceId, serviceName, extraInfo, state);
176     #endif
177     ASSERT_TRUE(g_AVSessionService != nullptr);
178     SLOGD("SuperLauncherTest005 end!");
179 }
180 
181 /**
182  * @tc.name: checkEnableCast001
183  * @tc.desc: test checkEnableCast
184  * @tc.type: FUNC
185  * @tc.require: #I5Y4MZ
186  */
187 static HWTEST_F(AVSessionServiceAddedTest, checkEnableCast001, TestSize.Level1)
188 {
189     SLOGD("checkEnableCast001 begin!");
190     bool enable = true;
191     g_AVSessionService->isInCast_ = false;
192     auto ret = g_AVSessionService->checkEnableCast(enable);
193     EXPECT_EQ(ret, AVSESSION_SUCCESS);
194     SLOGD("checkEnableCast001 end!");
195 }
196 
197 /**
198  * @tc.name: checkEnableCast002
199  * @tc.desc: test checkEnableCast
200  * @tc.type: FUNC
201  * @tc.require: #I5Y4MZ
202  */
203 static HWTEST_F(AVSessionServiceAddedTest, checkEnableCast002, TestSize.Level1)
204 {
205     SLOGD("checkEnableCast002 begin!");
206     bool enable = false;
207     g_AVSessionService->isInCast_ = true;
208     auto ret = g_AVSessionService->checkEnableCast(enable);
209     EXPECT_EQ(ret, AVSESSION_SUCCESS);
210     SLOGD("checkEnableCast002 end!");
211 }
212 
213 /**
214  * @tc.name: StopCast001
215  * @tc.desc: test StopCast
216  * @tc.type: FUNC
217  * @tc.require: #I5Y4MZ
218  */
219 static HWTEST_F(AVSessionServiceAddedTest, StopCast001, TestSize.Level1)
220 {
221     SLOGD("StopCast001 begin!");
222     #ifdef CASTPLUS_CAST_ENGINE_ENABLE
223     const OHOS::AVSession::SessionToken sessionToken = {
224         .sessionId = "success",
225         .pid = 1234,
226         .uid = 5678
227     };
228     auto ret = g_AVSessionService->StopCast(sessionToken);
229     EXPECT_EQ(ret, AVSESSION_SUCCESS);
230     #endif
231     SLOGD("StopCast001 end!");
232 }
233 
234 /**
235  * @tc.name: ProcessTargetMigrateTest001
236  * @tc.desc: Test for deviceTypeId mismatch.
237  * @tc.type: FUNC
238  * @tc.require: #I5Y4MZ
239  */
240 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest001, TestSize.Level1)
241 {
242     SLOGD("ProcessTargetMigrateTest001 begin!");
243     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
244     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
245     bool isOnline = true;
246     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
247     EXPECT_FALSE(result);
248     SLOGD("ProcessTargetMigrateTest001 end!");
249 }
250 
251 /**
252  * @tc.name: ProcessTargetMigrateTest002
253  * @tc.desc: Test when CheckWhetherTargetDevIsNext returns false.
254  * @tc.type: FUNC
255  * @tc.require: #I5Y4MZ
256  */
257 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest002, TestSize.Level1)
258 {
259     SLOGD("ProcessTargetMigrateTest002 begin!");
260     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
261     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
262     std::string name = "test";
263     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
264     deviceInfo.deviceName[name.size()] = '\0';
265     bool isOnline = true;
266     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
267     EXPECT_FALSE(result);
268     SLOGD("ProcessTargetMigrateTest002 end!");
269 }
270 
271 /**
272  * @tc.name: ProcessTargetMigrateTest003
273  * @tc.desc: Test when both conditions fail.
274  * @tc.type: FUNC
275  * @tc.require: #I5Y4MZ
276  */
277 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest003, TestSize.Level1)
278 {
279     SLOGD("ProcessTargetMigrateTest003 begin!");
280     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
281     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
282     std::string name = "test";
283     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
284     deviceInfo.deviceName[name.size()] = '\0';
285     bool isOnline = true;
286     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
287     EXPECT_FALSE(result);
288     SLOGD("ProcessTargetMigrateTest003 end!");
289 }
290 
291 /**
292  * @tc.name: ProcessTargetMigrateTest004
293  * @tc.desc: Test entering the else branch.
294  * @tc.type: FUNC
295  * @tc.require: #I5Y4MZ
296  */
297 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest004, TestSize.Level1)
298 {
299     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
300     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
301     std::string name = "valid";
302     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
303     deviceInfo.deviceName[name.size()] = '\0';
304     std::string extraData = "{\"OS_TYPE\":1}";
305     deviceInfo.extraData = extraData;
306     bool isOnline = true;
307     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
308     EXPECT_TRUE(result);
309 }
310 
311 /**
312  * @tc.name: ProcessTargetMigrateTest005
313  * @tc.desc: Test entering the else branch.
314  * @tc.type: FUNC
315  * @tc.require: #I5Y4MZ
316  */
317 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest005, TestSize.Level1)
318 {
319     SLOGD("ProcessTargetMigrateTest005 begin!");
320     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
321     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
322     std::string name = "valid";
323     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
324     deviceInfo.deviceName[name.size()] = '\0';
325     std::string extraData = "{\"OS_TYPE\":1}";
326     deviceInfo.extraData = extraData;
327     bool isOnline = true;
328     g_AVSessionService->localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
329     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
330     EXPECT_TRUE(result);
331     SLOGD("ProcessTargetMigrateTest005 end!");
332 }
333 
334 /**
335  * @tc.name: ProcessTargetMigrateTest006
336  * @tc.desc: Test entering the else branch.
337  * @tc.type: FUNC
338  * @tc.require: #I5Y4MZ
339  */
340 static HWTEST_F(AVSessionServiceAddedTest, ProcessTargetMigrateTest006, TestSize.Level1)
341 {
342     SLOGD("ProcessTargetMigrateTest006 begin!");
343     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
344     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
345     std::string name = "valid";
346     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
347     deviceInfo.deviceName[name.size()] = '\0';
348     std::string extraData = "{\"OS_TYPE\":1}";
349     deviceInfo.extraData = extraData;
350     bool isOnline = false;
351     bool result = g_AVSessionService->ProcessTargetMigrate(isOnline, deviceInfo);
352     EXPECT_TRUE(result);
353     SLOGD("ProcessTargetMigrateTest006 end!");
354 }
355 
356 /**
357  * @tc.name: CheckWhetherTargetDevIsNextTest001
358  * @tc.desc: Test entering the second if branch but not the first inner branch.
359  * @tc.type: FUNC
360  * @tc.require: #I5Y4MZ
361  */
362 static HWTEST_F(AVSessionServiceAddedTest, CheckWhetherTargetDevIsNextTest001, TestSize.Level1)
363 {
364     SLOGD("CheckWhetherTargetDevIsNextTest001 begin!");
365     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
366     std::string extraData = "{\"OS_TYPE\":\"string_value\"}";
367     deviceInfo.extraData = extraData;
368     bool result = g_AVSessionService->CheckWhetherTargetDevIsNext(deviceInfo);
369     EXPECT_FALSE(result);
370     SLOGD("CheckWhetherTargetDevIsNextTest001 end!");
371 }
372 
373 /**
374  * @tc.name: CheckWhetherTargetDevIsNextTest002
375  * @tc.desc: Test entering the first inner branch but not the second inner branch.
376  * @tc.type: FUNC
377  * @tc.require: #I5Y4MZ
378  */
379 static HWTEST_F(AVSessionServiceAddedTest, CheckWhetherTargetDevIsNextTest002, TestSize.Level1)
380 {
381     SLOGD("CheckWhetherTargetDevIsNextTest002 begin!");
382     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
383     std::string extraData = "{\"OS_TYPE\":-1}";
384     deviceInfo.extraData = extraData;
385     bool result = g_AVSessionService->CheckWhetherTargetDevIsNext(deviceInfo);
386     EXPECT_FALSE(result);
387     SLOGD("CheckWhetherTargetDevIsNextTest002 end!");
388 }
389 
390 /**
391  * @tc.name: AVSessionDeviceStateCallbackTest_OnDeviceReady_001
392  * @tc.desc: Test entering the if branch of OnDeviceReady.
393  * @tc.type: FUNC
394  * @tc.require: #I5Y4MZ
395  */
396 static HWTEST_F(AVSessionServiceAddedTest, AVSessionDeviceStateCallbackTest_OnDeviceReady_001, TestSize.Level1)
397 {
398     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceReady_001 begin!");
399     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
400     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
401     std::string name = "valid";
402     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
403     deviceInfo.deviceName[name.size()] = '\0';
404     std::string extraData = "{\"OS_TYPE\":1}";
405     deviceInfo.extraData = extraData;
406     AVSessionDeviceStateCallback callback(g_AVSessionService.get());
407     callback.OnDeviceReady(deviceInfo);
408     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceReady_001 end!");
409 }
410 
411 /**
412  * @tc.name: AVSessionDeviceStateCallbackTest_OnDeviceReady_002
413  * @tc.desc: Test not entering the if branch of OnDeviceReady.
414  * @tc.type: FUNC
415  * @tc.require: #I5Y4MZ
416  */
417 static HWTEST_F(AVSessionServiceAddedTest, AVSessionDeviceStateCallbackTest_OnDeviceReady_002, TestSize.Level1)
418 {
419     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceReady_002 begin!");
420     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
421     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
422     AVSessionDeviceStateCallback callback(g_AVSessionService.get());
423     callback.OnDeviceReady(deviceInfo);
424     ASSERT_TRUE(callback.servicePtr_ != nullptr);
425     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceReady_002 end!");
426 }
427 
428 /**
429  * @tc.name: AVSessionDeviceStateCallbackTest_OnDeviceOffline_001
430  * @tc.desc: Test entering the if branch of OnDeviceOffline.
431  * @tc.type: FUNC
432  * @tc.require: #I5Y4MZ
433  */
434 static HWTEST_F(AVSessionServiceAddedTest, AVSessionDeviceStateCallbackTest_OnDeviceOffline_001, TestSize.Level1)
435 {
436     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceOffline_001 begin!");
437     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
438     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
439     std::string name = "valid";
440     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
441     deviceInfo.deviceName[name.size()] = '\0';
442     std::string extraData = "{\"OS_TYPE\":1}";
443     deviceInfo.extraData = extraData;
444     AVSessionDeviceStateCallback callback(g_AVSessionService.get());
445     callback.OnDeviceOffline(deviceInfo);
446     ASSERT_TRUE(callback.servicePtr_ != nullptr);
447     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceOffline_001 end!");
448 }
449 
450 /**
451  * @tc.name: AVSessionDeviceStateCallbackTest_OnDeviceOffline_002
452  * @tc.desc: Test not entering the if branch of OnDeviceOffline.
453  * @tc.type: FUNC
454  * @tc.require: #I5Y4MZ
455  */
456 static HWTEST_F(AVSessionServiceAddedTest, AVSessionDeviceStateCallbackTest_OnDeviceOffline_002, TestSize.Level1)
457 {
458     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceOffline_002 begin!");
459     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
460     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
461     std::string name = "test";
462     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
463     deviceInfo.deviceName[name.size()] = '\0';
464     std::string extraData = "{\"OS_TYPE\":-1}";
465     deviceInfo.extraData = extraData;
466     AVSessionDeviceStateCallback callback(g_AVSessionService.get());
467     callback.OnDeviceOffline(deviceInfo);
468     ASSERT_TRUE(callback.servicePtr_ != nullptr);
469     SLOGD("AVSessionDeviceStateCallbackTest_OnDeviceOffline_002 end!");
470 }
471 
472 /**
473  * @tc.name: DoRemoteAVSessionLoad_001
474  * @tc.desc: Test DoRemoteAVSessionLoad.
475  * @tc.type: FUNC
476  * @tc.require: #I5Y4MZ
477  */
478 static HWTEST_F(AVSessionServiceAddedTest, DoRemoteAVSessionLoad_001, TestSize.Level1)
479 {
480     SLOGD("DoRemoteAVSessionLoad_001 begin!");
481     std::string remoteDeviceId = "device";
482     g_AVSessionService->DoRemoteAVSessionLoad(remoteDeviceId);
483     ASSERT_TRUE(g_AVSessionService != nullptr);
484     SLOGD("DoRemoteAVSessionLoad_001 end!");
485 }
486 
487 /**
488  * @tc.name: AVSessionServiceAddedTest_DoConnectProcessWithMigrate_001
489  * @tc.desc: Test entering the if branch of DoConnectProcessWithMigrate.
490  * @tc.type: FUNC
491  * @tc.require: #I5Y4MZ
492  */
493 static HWTEST_F(AVSessionServiceAddedTest, AVSessionServiceAddedTest_DoConnectProcessWithMigrate_001, TestSize.Level1)
494 {
495     SLOGD("AVSessionServiceAddedTest_DoConnectProcessWithMigrate_001 begin!");
496     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
497     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
498     std::string name = "valid";
499     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
500     deviceInfo.deviceName[name.size()] = '\0';
501     g_AVSessionService->localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
502     g_AVSessionService->DoConnectProcessWithMigrate(deviceInfo);
503     ASSERT_TRUE(g_AVSessionService != nullptr);
504     SLOGD("AVSessionServiceAddedTest_DoConnectProcessWithMigrate_001 end!");
505 }
506 
507 /**
508  * @tc.name: AVSessionServiceAddedTest_DoConnectProcessWithMigrate_002
509  * @tc.desc: Test not entering the if branch of DoConnectProcessWithMigrate.
510  * @tc.type: FUNC
511  * @tc.require: #I5Y4MZ
512  */
513 static HWTEST_F(AVSessionServiceAddedTest, AVSessionServiceAddedTest_DoConnectProcessWithMigrate_002, TestSize.Level1)
514 {
515     SLOGD("AVSessionServiceAddedTest_DoConnectProcessWithMigrate_002 begin!");
516     OHOS::DistributedHardware::DmDeviceInfo deviceInfo;
517     deviceInfo.deviceTypeId = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
518     std::string name = "valid";
519     strcpy_s(deviceInfo.deviceName, name.size(), name.c_str());
520     deviceInfo.deviceName[name.size()] = '\0';
521     g_AVSessionService->localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PAD;
522     g_AVSessionService->DoConnectProcessWithMigrate(deviceInfo);
523     ASSERT_TRUE(g_AVSessionService != nullptr);
524     SLOGD("AVSessionServiceAddedTest_DoConnectProcessWithMigrate_002 end!");
525 }