• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #define private public
17 #define protected public
18 #include "gtest/gtest.h"
19 
20 #include "bundle/bundle_manager_internal.h"
21 #include "device_manager.h"
22 #include "distributed_sched_permission.h"
23 #include "distributed_sched_proxy.h"
24 #include "distributed_sched_service.h"
25 #include "distributed_sched_util.h"
26 #include "dtbschedmgr_device_info_storage.h"
27 #include "dtbschedmgr_log.h"
28 #include "form_mgr_errors.h"
29 #include "if_system_ability_manager.h"
30 #include "ipc_skeleton.h"
31 #include "iservice_registry.h"
32 #include "mock_form_mgr_service.h"
33 #include "mock_distributed_sched.h"
34 #include "system_ability_definition.h"
35 #include "test_log.h"
36 #include "thread_pool.h"
37 #undef private
38 #undef protected
39 
40 using namespace std;
41 using namespace testing;
42 using namespace testing::ext;
43 using namespace OHOS;
44 
45 namespace OHOS {
46 namespace DistributedSchedule {
47 using namespace AAFwk;
48 using namespace AppExecFwk;
49 using namespace DistributedHardware;
50 namespace {
51     const string LOCAL_DEVICEID = "192.168.43.100";
52     const string REMOTE_DEVICEID = "255.255.255.255";
53     const std::u16string DEVICE_ID = u"192.168.43.100";
54     constexpr int32_t SESSION_ID = 123;
55     const std::string DMS_MISSION_ID = "dmsMissionId";
56     constexpr int32_t MISSION_ID = 1;
57     const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
58     const int DEFAULT_REQUEST_CODE = -1;
59     const string ABILITY_NAME = "com.ohos.launcher.MainAbility";
60     const string BUNDLE_NAME = "com.ohos.launcher";
61     const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
62 }
63 
64 class DistributedSchedServiceTest : public testing::Test {
65 public:
66     static void SetUpTestCase();
67     static void TearDownTestCase();
68     void SetUp();
69     void TearDown();
70     sptr<IDistributedSched> GetDms();
71     sptr<IDistributedSched> proxy_;
72 
73 protected:
74     enum class LoopTime : int32_t {
75         LOOP_TIME = 10,
76         LOOP_PRESSURE_TIME = 100,
77     };
78     sptr<IRemoteObject> GetDSchedService() const;
79     void GetAbilityInfo(const std::string& package, const std::string& name,
80         const std::string& bundleName, const std::string& deviceId,
81         OHOS::AppExecFwk::AbilityInfo& abilityInfo);
82 
83     class DeviceInitCallBack : public DmInitCallback {
84         void OnRemoteDied() override;
85     };
86 };
87 
SetUpTestCase()88 void DistributedSchedServiceTest::SetUpTestCase()
89 {
90     const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
91     std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
92     DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
93 }
94 
TearDownTestCase()95 void DistributedSchedServiceTest::TearDownTestCase()
96 {}
97 
SetUp()98 void DistributedSchedServiceTest::SetUp()
99 {
100     DistributedSchedUtil::MockPermission();
101 }
102 
TearDown()103 void DistributedSchedServiceTest::TearDown()
104 {}
105 
OnRemoteDied()106 void DistributedSchedServiceTest::DeviceInitCallBack::OnRemoteDied()
107 {}
108 
GetDms()109 sptr<IDistributedSched> DistributedSchedServiceTest::GetDms()
110 {
111     if (proxy_ != nullptr) {
112         return proxy_;
113     }
114     auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
115     EXPECT_TRUE(sm != nullptr);
116     if (sm == nullptr) {
117         DTEST_LOG << "DistributedSchedServiceTest sm is nullptr" << std::endl;
118         return nullptr;
119     }
120     DTEST_LOG << "DistributedSchedServiceTest sm is not nullptr" << std::endl;
121     auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
122     EXPECT_TRUE(distributedObject != nullptr);
123     proxy_ = iface_cast<IDistributedSched>(distributedObject);
124     if (proxy_ == nullptr) {
125         DTEST_LOG << "DistributedSchedServiceTest DistributedSched is nullptr" << std::endl;
126     }
127     DTEST_LOG << "DistributedSchedServiceTest DistributedSched is not nullptr" << std::endl;
128     return proxy_;
129 }
130 
GetDSchedService() const131 sptr<IRemoteObject> DistributedSchedServiceTest::GetDSchedService() const
132 {
133     sptr<IRemoteObject> dsched = new MockDistributedSched();
134     return dsched;
135 }
136 
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)137 void DistributedSchedServiceTest::GetAbilityInfo(const std::string& package, const std::string& name,
138     const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
139 {
140     abilityInfo.bundleName = bundleName;
141     abilityInfo.deviceId = deviceId;
142 }
143 
144 /**
145  * @tc.name: StartRemoteAbility_001
146  * @tc.desc: call StartRemoteAbility with illegal params
147  * @tc.type: FUNC
148  */
149 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_001, TestSize.Level1)
150 {
151     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_001 start" << std::endl;
152     sptr<IDistributedSched> proxy = GetDms();
153     if (proxy == nullptr) {
154         return;
155     }
156     /**
157      * @tc.steps: step1. StartRemoteAbility with uninitialized params
158      * @tc.expected: step1. StartRemoteAbility return INVALID_PARAMETERS_ERR
159      */
160     AAFwk::Want want;
161     int result1 = proxy->StartRemoteAbility(want, 0, 0, 0);
162     DTEST_LOG << "result1:" << result1 << std::endl;
163     /**
164      * @tc.steps: step2. StartRemoteAbility with empty want's deviceId
165      * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
166      */
167     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
168         "com.ohos.distributedmusicplayer.MainAbility");
169     want.SetElement(element);
170     int result2 = proxy->StartRemoteAbility(want, 0, 0, 0);
171     DTEST_LOG << "result2:" << result2 << std::endl;
172 
173     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result1);
174     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result2);
175     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_001 end" << std::endl;
176 }
177 
178 /**
179  * @tc.name: StartRemoteAbility_002
180  * @tc.desc: call StartRemoteAbility with dms with wrong deviceId and local deviceId
181  * @tc.type: FUNC
182  */
183 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_002, TestSize.Level0)
184 {
185     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_002 start" << std::endl;
186     sptr<IDistributedSched> proxy = GetDms();
187     if (proxy == nullptr) {
188         return;
189     }
190     /**
191      * @tc.steps: step1. set want with wrong deviceId
192      * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
193      */
194     AAFwk::Want want;
195     AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
196         "com.ohos.distributedmusicplayer.MainAbility");
197     want.SetElement(element);
198     int result1 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
199     DTEST_LOG << "result:" << result1 << std::endl;
200     std::string deviceId;
201     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
202     AppExecFwk::ElementName element1(deviceId, "com.ohos.distributedmusicplayer",
203         "com.ohos.distributedmusicplayer.MainAbility");
204     want.SetElement(element1);
205     int result2 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
206     DTEST_LOG << "result:" << result2 << std::endl;
207     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
208     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
209     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_002 end" << std::endl;
210 }
211 
212 /**
213  * @tc.name: StartRemoteAbility_003
214  * @tc.desc: call StartRemoteAbility with dms
215  * @tc.type: FUNC
216  */
217 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_003, TestSize.Level0)
218 {
219     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_003 start" << std::endl;
220     /**
221      * @tc.steps: step1. set want with wrong deviceId
222      * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
223      */
224     AAFwk::Want want;
225     AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
226         "com.ohos.distributedmusicplayer.MainAbility");
227     want.SetElement(element);
228     int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
229     DTEST_LOG << "result:" << result << std::endl;
230     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
231     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_003 end" << std::endl;
232 }
233 
234 /**
235  * @tc.name: StartRemoteAbility_004
236  * @tc.desc: call StartRemoteAbility
237  * @tc.type: FUNC
238  */
239 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_004, TestSize.Level1)
240 {
241     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_004 start" << std::endl;
242     sptr<IDistributedSched> proxy = GetDms();
243     if (proxy == nullptr) {
244         return;
245     }
246     /**
247      * @tc.steps: step1. set want and abilityInfo
248      * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
249      */
250     AAFwk::Want want;
251     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
252         "com.ohos.distributedmusicplayer.MainAbility");
253     want.SetElement(element);
254     int result = proxy->StartRemoteAbility(want, 0, 0, 0);
255     DTEST_LOG << "result:" << result << std::endl;
256     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
257     DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_004 end" << std::endl;
258 }
259 
260 /**
261  * @tc.name: StartAbilityFromRemote_001
262  * @tc.desc: call StartAbilityFromRemote with illegal param
263  * @tc.type: FUNC
264  */
265 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_001, TestSize.Level0)
266 {
267     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_001 start" << std::endl;
268     sptr<IDistributedSched> proxy = GetDms();
269     if (proxy == nullptr) {
270         return;
271     }
272     AAFwk::Want want;
273     AppExecFwk::AbilityInfo abilityInfo;
274     CallerInfo callerInfo;
275     callerInfo.uid = 0;
276     callerInfo.sourceDeviceId = "255.255.255.255";
277     IDistributedSched::AccountInfo accountInfo;
278     /**
279      * @tc.steps: step1. StartAbilityFromRemote with uninitialized params
280      * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
281      */
282     int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
283     DTEST_LOG << "result1:" << result1 << std::endl;
284     /**
285      * @tc.steps: step1. StartAbilityFromRemote with with empty deviceId
286      * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
287      */
288     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
289         "com.ohos.distributedmusicplayer.MainAbility");
290     want.SetElement(element);
291     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
292         "com.ohos.distributedmusicplayer", "192.168.43.101", abilityInfo);
293     int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
294     DTEST_LOG << "result2:" << result2 << std::endl;
295     EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
296     EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
297     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_001 end" << std::endl;
298 }
299 
300 /**
301  * @tc.name: StartAbilityFromRemote_002
302  * @tc.desc: call StartAbilityFromRemote
303  * @tc.type: FUNC
304  */
305 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_002, TestSize.Level1)
306 {
307     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 start" << std::endl;
308     sptr<IDistributedSched> proxy = GetDms();
309     if (proxy == nullptr) {
310         return;
311     }
312 
313     AAFwk::Want want;
314     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
315         "com.ohos.distributedmusicplayer.MainAbility");
316     want.SetElement(element);
317     AppExecFwk::AbilityInfo abilityInfo;
318     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
319         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
320     CallerInfo callerInfo;
321     callerInfo.uid = 0;
322     callerInfo.sourceDeviceId = "255.255.255.255";
323     IDistributedSched::AccountInfo accountInfo;
324 
325     int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
326     DTEST_LOG << "result1 is" << result1 << std::endl;
327 
328     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
329         "com.ohos.distributedmusicplayer.MainAbilityService");
330     want.SetElement(element2);
331     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
332         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
333     int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
334     DTEST_LOG << "result2:" << result2 << std::endl;
335     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 end" << std::endl;
336 }
337 
338 /**
339  * @tc.name: StartAbilityFromRemote_003
340  * @tc.desc: call StartAbilityFromRemote for pressure test
341  * @tc.type: FUNC
342  */
343 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_003, TestSize.Level1)
344 {
345     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_003 start" << std::endl;
346     sptr<IDistributedSched> proxy = GetDms();
347     if (proxy == nullptr) {
348         return;
349     }
350     /**
351      * @tc.steps: step1. set want and abilityInfo
352      */
353     AAFwk::Want want;
354     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
355         "com.ohos.distributedmusicplayer.MainAbility");
356     want.SetElement(element);
357     AppExecFwk::AbilityInfo abilityInfo;
358     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
359         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
360     CallerInfo callerInfo;
361     callerInfo.uid = 0;
362     callerInfo.sourceDeviceId = "255.255.255.255";
363     IDistributedSched::AccountInfo accountInfo;
364     /**
365      * @tc.steps: step2. StartAbilityFromRemote for pressure test
366      * @tc.expected: step2. StartAbilityFromRemote for result
367      */
368     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
369         int result = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
370         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
371     }
372     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_003 end" << std::endl;
373 }
374 
375 /**
376  * @tc.name: StartAbilityFromRemote_004
377  * @tc.desc: call StartAbilityFromRemote with dms
378  * @tc.type: FUNC
379  */
380 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_004, TestSize.Level0)
381 {
382     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_004 start" << std::endl;
383     sptr<IDistributedSched> proxy = GetDms();
384 
385     AAFwk::Want want;
386     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
387         "com.ohos.distributedmusicplayer.MainAbility");
388     want.SetElement(element);
389     AppExecFwk::AbilityInfo abilityInfo;
390     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
391         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
392     CallerInfo callerInfo;
393     callerInfo.uid = 0;
394     callerInfo.sourceDeviceId = "255.255.255.255";
395     IDistributedSched::AccountInfo accountInfo;
396 
397     int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
398         abilityInfo, 0, callerInfo, accountInfo);
399     DTEST_LOG << "result1:" << result1 << std::endl;
400 
401     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
402         "com.ohos.distributedmusicplayer.MainAbilityService");
403     want.SetElement(element2);
404     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
405         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
406     int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
407         abilityInfo, 0, callerInfo, accountInfo);
408     DTEST_LOG << "result2:" << result2 << std::endl;
409     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
410     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
411     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_004 end" << std::endl;
412 }
413 
414 /**
415  * @tc.name: StartAbilityFromRemote_005
416  * @tc.desc: call StartAbilityFromRemote with dms
417  * @tc.type: FUNC
418  */
419 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_005, TestSize.Level1)
420 {
421     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_005 start" << std::endl;
422     sptr<IDistributedSched> proxy = GetDms();
423 
424     AAFwk::Want want;
425     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
426         "com.ohos.distributedmusicplayer.MainAbility");
427     want.SetElement(element);
428     AppExecFwk::AbilityInfo abilityInfo;
429     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
430         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
431     CallerInfo callerInfo;
432     callerInfo.uid = 0;
433     callerInfo.sourceDeviceId = "255.255.255.255";
434     IDistributedSched::AccountInfo accountInfo;
435     accountInfo.accountType = 1;
436     accountInfo.groupIdList.push_back("123456");
437 
438     int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
439         abilityInfo, 0, callerInfo, accountInfo);
440     DTEST_LOG << "result1:" << result1 << std::endl;
441 
442     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
443         "com.ohos.distributedmusicplayer.MainAbilityService");
444     want.SetElement(element2);
445     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
446         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
447     int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
448         abilityInfo, 0, callerInfo, accountInfo);
449     DTEST_LOG << "result2:" << result2 << std::endl;
450     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_005 end" << std::endl;
451 }
452 
453 /**
454  * @tc.name: SendResultFromRemote_001
455  * @tc.desc: call SendResultFromRemote with illegal param
456  * @tc.type: FUNC
457  */
458 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_001, TestSize.Level1)
459 {
460     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_001 start" << std::endl;
461     sptr<IDistributedSched> proxy = GetDms();
462     if (proxy == nullptr) {
463         return;
464     }
465     AAFwk::Want want;
466     CallerInfo callerInfo;
467     callerInfo.uid = 0;
468     callerInfo.sourceDeviceId = "255.255.255.255";
469     IDistributedSched::AccountInfo accountInfo;
470     /**
471      * @tc.steps: step1. SendResultFromRemote with uninitialized params
472      * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
473      */
474     int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
475     DTEST_LOG << "result1:" << result1 << std::endl;
476     /**
477      * @tc.steps: step1. SendResultFromRemote with with empty deviceId
478      * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
479      */
480     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
481         "com.ohos.distributedmusicplayer.MainAbility");
482     want.SetElement(element);
483     int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
484     DTEST_LOG << "result2:" << result2 << std::endl;
485     EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
486     EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
487     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote end" << std::endl;
488 }
489 
490 /**
491  * @tc.name: StartAbilityFromRemote_002
492  * @tc.desc: call SendResultFromRemote
493  * @tc.type: FUNC
494  */
495 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_002, TestSize.Level1)
496 {
497     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_002 start" << std::endl;
498     sptr<IDistributedSched> proxy = GetDms();
499     if (proxy == nullptr) {
500         return;
501     }
502 
503     AAFwk::Want want;
504     AppExecFwk::ElementName element("255.255.255.255", "com.ohos.distributedmusicplayer",
505         "com.ohos.distributedmusicplayer.MainAbility");
506     want.SetElement(element);
507     AppExecFwk::AbilityInfo abilityInfo;
508     CallerInfo callerInfo;
509     callerInfo.uid = 0;
510     callerInfo.sourceDeviceId = "255.255.255.255";
511     IDistributedSched::AccountInfo accountInfo;
512 
513     int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
514     DTEST_LOG << "result1 is" << result1 << std::endl;
515     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
516         "com.ohos.distributedmusicplayer.MainAbilityService");
517     want.SetElement(element2);
518     int missionId = 0;
519     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
520     want.SetParam(DMS_MISSION_ID, missionId);
521     int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
522     DTEST_LOG << "result2:" << result2 << std::endl;
523     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 end" << std::endl;
524 }
525 
526 /**
527  * @tc.name: SendResultFromRemote_003
528  * @tc.desc: call SendResultFromRemote for pressure test
529  * @tc.type: FUNC
530  */
531 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_003, TestSize.Level1)
532 {
533     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_003 start" << std::endl;
534     sptr<IDistributedSched> proxy = GetDms();
535     if (proxy == nullptr) {
536         return;
537     }
538     /**
539      * @tc.steps: step1. set want and abilityInfo
540      */
541     AAFwk::Want want;
542     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
543         "com.ohos.distributedmusicplayer.MainAbility");
544     want.SetElement(element);
545     CallerInfo callerInfo;
546     callerInfo.uid = 0;
547     callerInfo.sourceDeviceId = "255.255.255.255";
548     IDistributedSched::AccountInfo accountInfo;
549     int missionId = 0;
550     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
551     want.SetParam(DMS_MISSION_ID, missionId);
552     /**
553      * @tc.steps: step2. SendResultFromRemote for pressure test
554      * @tc.expected: step2. SendResultFromRemote for result
555      */
556     for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
557         int result = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
558         DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
559     }
560     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_003 end" << std::endl;
561 }
562 
563 /**
564  * @tc.name: SendResultFromRemote_004
565  * @tc.desc: call SendResultFromRemote with dms
566  * @tc.type: FUNC
567  */
568 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_004, TestSize.Level1)
569 {
570     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_004 start" << std::endl;
571     sptr<IDistributedSched> proxy = GetDms();
572 
573     AAFwk::Want want;
574     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
575         "com.ohos.distributedmusicplayer.MainAbility");
576     want.SetElement(element);
577     CallerInfo callerInfo;
578     callerInfo.uid = 0;
579     callerInfo.sourceDeviceId = "255.255.255.255";
580     IDistributedSched::AccountInfo accountInfo;
581 
582     int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
583     DTEST_LOG << "result1:" << result1 << std::endl;
584 
585     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
586         "com.ohos.distributedmusicplayer.MainAbilityService");
587     want.SetElement(element2);
588     int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
589     DTEST_LOG << "result2:" << result2 << std::endl;
590     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
591     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
592     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_004 end" << std::endl;
593 }
594 
595 /**
596  * @tc.name: SendResultFromRemote_005
597  * @tc.desc: call SendResultFromRemote with dms
598  * @tc.type: FUNC
599  */
600 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_005, TestSize.Level1)
601 {
602     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_005 start" << std::endl;
603     sptr<IDistributedSched> proxy = GetDms();
604 
605     AAFwk::Want want;
606     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
607         "com.ohos.distributedmusicplayer.MainAbility");
608     want.SetElement(element);
609     CallerInfo callerInfo;
610     callerInfo.uid = 0;
611     callerInfo.sourceDeviceId = "255.255.255.255";
612     IDistributedSched::AccountInfo accountInfo;
613     accountInfo.accountType = 1;
614     accountInfo.groupIdList.push_back("123456");
615     int missionId = 0;
616     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
617     want.SetParam(DMS_MISSION_ID, missionId);
618 
619     int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
620     DTEST_LOG << "result1:" << result1 << std::endl;
621 
622     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
623         "com.ohos.distributedmusicplayer.MainAbilityService");
624     want.SetElement(element2);
625     int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
626     DTEST_LOG << "result2:" << result2 << std::endl;
627     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_005 end" << std::endl;
628 }
629 
630 /**
631  * @tc.name: StartLocalAbility_001
632  * @tc.desc: call StartLocalAbility with dms
633  * @tc.type: FUNC
634  */
635 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_001, TestSize.Level1)
636 {
637     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_001 start" << std::endl;
638     sptr<IDistributedSched> proxy = GetDms();
639 
640     AAFwk::Want want;
641     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
642         "com.ohos.distributedmusicplayer.MainAbility");
643     want.SetElement(element);
644     CallerInfo callerInfo;
645     callerInfo.uid = 0;
646     callerInfo.sourceDeviceId = "255.255.255.255";
647     IDistributedSched::AccountInfo accountInfo;
648     int missionId = 0;
649     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
650     want.SetParam(DMS_MISSION_ID, missionId);
651     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
652         .accountInfo = accountInfo};
653     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
654     DTEST_LOG << "result1:" << result1 << std::endl;
655 
656     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
657         "com.ohos.distributedmusicplayer.MainAbilityService");
658     want.SetElement(element2);
659     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
660         .accountInfo = accountInfo};
661     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
662     DTEST_LOG << "result2:" << result2 << std::endl;
663     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
664     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
665     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_001 end" << std::endl;
666 }
667 
668 /**
669  * @tc.name: StartLocalAbility_002
670  * @tc.desc: call StartLocalAbility with dms
671  * @tc.type: FUNC
672  */
673 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_002, TestSize.Level1)
674 {
675     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_002 start" << std::endl;
676     sptr<IDistributedSched> proxy = GetDms();
677 
678     AAFwk::Want want;
679     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
680         "com.ohos.distributedmusicplayer.MainAbility");
681     want.SetElement(element);
682     CallerInfo callerInfo;
683     callerInfo.uid = 0;
684     callerInfo.sourceDeviceId = "255.255.255.255";
685     IDistributedSched::AccountInfo accountInfo;
686     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
687         .callerInfo = callerInfo, .accountInfo = accountInfo};
688     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
689     DTEST_LOG << "result1:" << result1 << std::endl;
690 
691     AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
692         "com.ohos.distributedmusicplayer.MainAbilityService");
693     want.SetElement(element2);
694     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
695         .callerInfo = callerInfo, .accountInfo = accountInfo};
696     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
697     DTEST_LOG << "result2:" << result2 << std::endl;
698     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
699     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
700     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_002 end" << std::endl;
701 }
702 
703 /**
704  * @tc.name: StartLocalAbility_003
705  * @tc.desc: call StartLocalAbility with dms
706  * @tc.type: FUNC
707  */
708 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_003, TestSize.Level1)
709 {
710     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_003 start" << std::endl;
711     sptr<IDistributedSched> proxy = GetDms();
712 
713     AAFwk::Want want;
714     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
715         "com.ohos.distributedmusicplayer.MainAbility");
716     want.SetElement(element);
717     CallerInfo callerInfo;
718     callerInfo.uid = 0;
719     callerInfo.sourceDeviceId = "255.255.255.255";
720     IDistributedSched::AccountInfo accountInfo;
721     accountInfo.accountType = 1;
722     accountInfo.groupIdList.push_back("123456");
723     int missionId = 0;
724     want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
725     want.SetParam(DMS_MISSION_ID, missionId);
726     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
727         .accountInfo = accountInfo};
728     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
729     DTEST_LOG << "result1:" << result1 << std::endl;
730 
731     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
732         "com.ohos.distributedmusicplayer.MainAbilityService");
733     want.SetElement(element2);
734     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
735         .accountInfo = accountInfo};
736     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
737     DTEST_LOG << "result2:" << result2 << std::endl;
738     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_003 end" << std::endl;
739 }
740 
741 /**
742  * @tc.name: StartLocalAbility_004
743  * @tc.desc: call StartLocalAbility with dms
744  * @tc.type: FUNC
745  */
746 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_004, TestSize.Level1)
747 {
748     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_004 start" << std::endl;
749     sptr<IDistributedSched> proxy = GetDms();
750 
751     AAFwk::Want want;
752     AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
753         "com.ohos.distributedmusicplayer.MainAbility");
754     want.SetElement(element);
755     CallerInfo callerInfo;
756     callerInfo.uid = 0;
757     callerInfo.sourceDeviceId = "255.255.255.255";
758     IDistributedSched::AccountInfo accountInfo;
759     accountInfo.accountType = 1;
760     accountInfo.groupIdList.push_back("123456");
761     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
762         .callerInfo = callerInfo, .accountInfo = accountInfo};
763     int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
764     DTEST_LOG << "result1:" << result1 << std::endl;
765 
766     AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
767         "com.ohos.distributedmusicplayer.MainAbilityService");
768     want.SetElement(element2);
769     DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
770         .callerInfo = callerInfo, .accountInfo = accountInfo};
771     int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
772     DTEST_LOG << "result2:" << result2 << std::endl;
773     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_004 end" << std::endl;
774 }
775 
776 /**
777  * @tc.name: StartRemoteShareForm_001
778  * @tc.desc: call StartRemoteShareForm with dms
779  * @tc.type: StartRemoteShareForm
780  * @tc.require: issueI5M62D
781  */
782 HWTEST_F(DistributedSchedServiceTest, StartRemoteShareForm_001, TestSize.Level1)
783 {
784     DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_001 start" << std::endl;
785     sptr<IDistributedSched> proxy = GetDms();
786     const std::string remoteDeviceId = "";
787     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
788     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
789     DTEST_LOG << "result:" << result << std::endl;
790     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
791     DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_001 end" << std::endl;
792 }
793 
794 /**
795  * @tc.name: StartRemoteShareForm_002
796  * @tc.desc: call StartAbilityFromRemote with dms
797  * @tc.type: StartRemoteShareForm
798  * @tc.require: issueI5M62D
799  */
800 HWTEST_F(DistributedSchedServiceTest, StartRemoteShareForm_002, TestSize.Level1)
801 {
802     DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_002 start" << std::endl;
803     sptr<IDistributedSched> proxy = GetDms();
804     const std::string remoteDeviceId = "123456";
805     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
806     auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
807     DTEST_LOG << "result:" << result << std::endl;
808     EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
809     DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_002 end" << std::endl;
810 }
811 
812 /**
813  * @tc.name: StartShareFormFromRemote_001
814  * @tc.desc: call StartAbilityFromRemote with dms
815  * @tc.type: StartShareFormFromRemote
816  * @tc.require: issueI5M62D
817  */
818 HWTEST_F(DistributedSchedServiceTest, StartShareFormFromRemote_001, TestSize.Level1)
819 {
820     DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_001 start" << std::endl;
821     std::string remoteDeviceId = "";
822     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(remoteDeviceId);
823     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
824     DistributedSchedService::GetInstance().formMgrProxy_ = new MockFormMgrService();
825     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
826     DTEST_LOG << "result:" << result << std::endl;
827     EXPECT_EQ(static_cast<int>(ERR_OK), result);
828 
829     DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_001 end" << std::endl;
830 }
831 
832 /**
833  * @tc.name: StartShareFormFromRemote_002
834  * @tc.desc: call StartAbilityFromRemote with dms
835  * @tc.type: StartShareFormFromRemote
836  * @tc.require: issueI5M62D
837  */
838 HWTEST_F(DistributedSchedServiceTest, StartShareFormFromRemote_002, TestSize.Level1)
839 {
840     DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_002 start" << std::endl;
841     std::string remoteDeviceId = "123456";
842     const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
843     auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
844     DTEST_LOG << "result:" << result << std::endl;
845     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
846     DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_002 end" << std::endl;
847 }
848 
849 /**
850  * @tc.name: StartAbilityFromRemote_006
851  * @tc.desc: call StartAbilityFromRemote
852  * @tc.type: FUNC
853  */
854 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_006, TestSize.Level1)
855 {
856     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 start" << std::endl;
857     AAFwk::Want want;
858     std::string localDeviceId;
859     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
860     AppExecFwk::ElementName element(localDeviceId, "com.ohos.distributedmusicplayer",
861         "com.ohos.distributedmusicplayer.MainAbility");
862     want.SetElement(element);
863     AppExecFwk::AbilityInfo abilityInfo;
864     GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
865         "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
866     abilityInfo.visible = true;
867     abilityInfo.permissions.clear();
868     CallerInfo callerInfo;
869     callerInfo.uid = 0;
870     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
871     IDistributedSched::AccountInfo accountInfo;
872     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
873     accountInfo.groupIdList.push_back("123456");
874     int result = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
875         abilityInfo, 0, callerInfo, accountInfo);
876     DTEST_LOG << "result:" << result << std::endl;
877     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
878     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 end" << std::endl;
879 }
880 
881 /**
882  * @tc.name: SendResultFromRemote_006
883  * @tc.desc: call SendResultFromRemote
884  * @tc.type: FUNC
885  */
886 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_006, TestSize.Level1)
887 {
888     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 start" << std::endl;
889     AAFwk::Want want;
890     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
891         "com.ohos.distributedmusicplayer.MainAbility");
892     want.SetElement(element);
893     std::string localDeviceId;
894     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
895     want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
896     CallerInfo callerInfo;
897     callerInfo.uid = 0;
898     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
899     IDistributedSched::AccountInfo accountInfo;
900     int result = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
901     DTEST_LOG << "result:" << result << std::endl;
902     EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
903     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 end" << std::endl;
904 }
905 
906 /**
907  * @tc.name: RemoveContinuationTimeout_001
908  * @tc.desc: call RemoveContinuationTimeout
909  * @tc.type: FUNC
910  */
911 HWTEST_F(DistributedSchedServiceTest, RemoveContinuationTimeout_001, TestSize.Level1)
912 {
913     DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_001 start" << std::endl;
914     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
915         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
916     }
917     int32_t missionId = MISSION_ID;
918     DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
919     DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_001 end" << std::endl;
920 }
921 
922 /**
923  * @tc.name: SetContinuationTimeout_001
924  * @tc.desc: call GetContinuaitonDevice
925  * @tc.type: FUNC
926  */
927 HWTEST_F(DistributedSchedServiceTest, SetContinuationTimeout_001, TestSize.Level1)
928 {
929     DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 start" << std::endl;
930     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
931         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
932     }
933     int32_t missionId = MISSION_ID;
934     int32_t timeout = 5;
935     DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout);
936     DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 end" << std::endl;
937 }
938 
939 /**
940  * @tc.name: GetContinuaitonDevice_001
941  * @tc.desc: call GetContinuaitonDevice
942  * @tc.type: FUNC
943  */
944 HWTEST_F(DistributedSchedServiceTest, GetContinuaitonDevice_001, TestSize.Level1)
945 {
946     DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 start" << std::endl;
947     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
948         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
949     }
950     int32_t missionId = MISSION_ID;
951     (void)DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
952     DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 end" << std::endl;
953 }
954 
955 /**
956  * @tc.name: ContinueMission_001
957  * @tc.desc: call ContinueMission
958  * @tc.type: FUNC
959  */
960 HWTEST_F(DistributedSchedServiceTest, ContinueMission_001, TestSize.Level1)
961 {
962     DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl;
963     WantParams wantParams;
964     auto callback = GetDSchedService();
965     int32_t missionId = MISSION_ID;
966     std::string localDeviceId;
967     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
968     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
969         "string", localDeviceId, missionId, callback, wantParams);
970     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
971     DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl;
972 }
973 
974 /**
975  * @tc.name: ContinueMission_002
976  * @tc.desc: call ContinueMission
977  * @tc.type: FUNC
978  */
979 HWTEST_F(DistributedSchedServiceTest, ContinueMission_002, TestSize.Level1)
980 {
981     DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl;
982     WantParams wantParams;
983     auto callback = GetDSchedService();
984     int32_t missionId = MISSION_ID;
985     std::string localDeviceId;
986     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
987     int32_t result = DistributedSchedService::GetInstance().ContinueMission(
988         "string", "string", missionId, callback, wantParams);
989     EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
990     DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl;
991 }
992 
993 /**
994  * @tc.name: StartContinuation_001
995  * @tc.desc: call StartContinuation
996  * @tc.type: FUNC
997  * @tc.require: I5NOA1
998  */
999 HWTEST_F(DistributedSchedServiceTest, StartContinuation_001, TestSize.Level1)
1000 {
1001     DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
1002     AAFwk::Want want;
1003     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1004         "com.ohos.distributedmusicplayer.MainAbility");
1005     want.SetElement(element);
1006     int32_t missionId = MISSION_ID;
1007     int32_t callerUid = 0;
1008     int32_t status = 1;
1009     uint32_t accessToken = 0;
1010     int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1011         want, missionId, callerUid, status, accessToken);
1012     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1013     CallerInfo callerInfo;
1014     ConnectInfo connectInfo;
1015     /**
1016      * @tc.steps: step1. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1017      */
1018     DistributedSchedService::GetInstance().componentChangeHandler_ = nullptr;
1019     DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1020         1, IDistributedSched::CALL, IDistributedSched::CALLER);
1021     /**
1022      * @tc.steps: step2. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1023      */
1024     DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1025         1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1026     /**
1027      * @tc.steps: step3. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1028      */
1029     auto runner = AppExecFwk::EventRunner::Create("DmsComponentChange");
1030     DistributedSchedService::GetInstance().componentChangeHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1031     DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1032         1, IDistributedSched::CALL, IDistributedSched::CALLER);
1033     /**
1034      * @tc.steps: step4. ReportDistributedComponentChange when callerInfo.bundleNames is not empty
1035      */
1036     callerInfo.bundleNames.emplace_back("bundleName");
1037     DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1038         1, IDistributedSched::CALL, IDistributedSched::CALLER);
1039     /**
1040      * @tc.steps: step5. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1041      */
1042     DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1043         1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1044     DTEST_LOG << "DSchedContinuationTest StartContinuation_001 end" << std::endl;
1045 }
1046 
1047 /**
1048  * @tc.name: StartContinuation_002
1049  * @tc.desc: call StartContinuation
1050  * @tc.type: FUNC
1051  */
1052 HWTEST_F(DistributedSchedServiceTest, StartContinuation_002, TestSize.Level1)
1053 {
1054     DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
1055     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1056         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1057     }
1058     AAFwk::Want want;
1059     AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1060         "com.ohos.distributedmusicplayer.MainAbility");
1061     int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1062     want.SetElement(element);
1063     want.SetFlags(flags);
1064     int32_t missionId = MISSION_ID;
1065     int32_t callerUid = 0;
1066     int32_t status = 1;
1067     uint32_t accessToken = 0;
1068     int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1069         want, missionId, callerUid, status, accessToken);
1070     EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1071     DTEST_LOG << "DSchedContinuationTest StartContinuation_002 end" << std::endl;
1072 }
1073 
1074 /**
1075  * @tc.name: NotifyCompleteContinuation_001
1076  * @tc.desc: call NotifyCompleteContinuation
1077  * @tc.type: FUNC
1078  */
1079 HWTEST_F(DistributedSchedServiceTest, NotifyCompleteContinuation_001, TestSize.Level1)
1080 {
1081     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
1082     bool isSuccess = false;
1083     DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID, SESSION_ID, isSuccess);
1084     DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
1085 }
1086 
1087 /**
1088  * @tc.name: NotifyContinuationCallbackResult_001
1089  * @tc.desc: call NotifyContinuationCallbackResult
1090  * @tc.type: FUNC
1091  */
1092 HWTEST_F(DistributedSchedServiceTest, NotifyContinuationCallbackResult_001, TestSize.Level1)
1093 {
1094     DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 start" << std::endl;
1095     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1096         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1097     }
1098     int32_t missionId = MISSION_ID;
1099     bool isSuccess = false;
1100     DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, isSuccess);
1101     DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 end" << std::endl;
1102 }
1103 
1104 /**
1105  * @tc.name: NotifyContinuationCallbackResult_002
1106  * @tc.desc: call NotifyContinuationCallbackResult
1107  * @tc.type: FUNC
1108  */
1109 HWTEST_F(DistributedSchedServiceTest, NotifyContinuationCallbackResult_002, TestSize.Level1)
1110 {
1111     DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_002 start" << std::endl;
1112     if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1113         DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1114     }
1115     int32_t missionId = MISSION_ID;
1116     bool resultCode = ERR_OK;
1117     DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1118     DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_002 end" << std::endl;
1119 }
1120 
1121 /**
1122  * @tc.name: GetFormMgrProxy_001
1123  * @tc.desc: call GetFormMgrProxy
1124  * @tc.type: FUNC
1125  */
1126 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1127 HWTEST_F(DistributedSchedServiceTest, GetFormMgrProxy_001, TestSize.Level1)
1128 {
1129     DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1130     DistributedSchedService::GetInstance().GetFormMgrProxy();
1131     DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1132 }
1133 #endif
1134 
1135 /**
1136  * @tc.name: StartAbilityFromRemote_007
1137  * @tc.desc: test StartAbilityFromRemote
1138  * @tc.type: FUNC
1139  * @tc.require: issueI5T6GJ
1140  */
1141 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_007, TestSize.Level3)
1142 {
1143     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_007 start" << std::endl;
1144     AAFwk::Want want;
1145     std::string localDeviceId;
1146     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1147     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1148         ABILITY_NAME);
1149     want.SetElement(element);
1150     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1151     AppExecFwk::AbilityInfo abilityInfo;
1152     abilityInfo.permissions.clear();
1153     CallerInfo callerInfo;
1154     callerInfo.uid = 0;
1155     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1156     bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
1157     EXPECT_TRUE(result);
1158     IDistributedSched::AccountInfo accountInfo;
1159     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1160     int ret = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1161         abilityInfo, 0, callerInfo, accountInfo);
1162     EXPECT_EQ(ret, ERR_OK);
1163     DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_007 end" << std::endl;
1164 }
1165 
1166 /**
1167  * @tc.name: SendResultFromRemote_007
1168  * @tc.desc: test SendResultFromRemote
1169  * @tc.type: FUNC
1170  * @tc.require: issueI5T6GJ
1171  */
1172 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_007, TestSize.Level3)
1173 {
1174     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_007 start" << std::endl;
1175     AAFwk::Want want;
1176     std::string localDeviceId;
1177     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1178     want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1179     AppExecFwk::ElementName element(localDeviceId, "ohos.samples.distributedcalc",
1180         "ohos.samples.distributedcalc.MainAbility");
1181     want.SetElement(element);
1182     CallerInfo callerInfo;
1183     callerInfo.uid = 0;
1184     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1185     IDistributedSched::AccountInfo accountInfo;
1186     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1187     int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
1188     EXPECT_NE(ret, ERR_OK);
1189     DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_007 end" << std::endl;
1190 }
1191 
1192 /**
1193  * @tc.name: StartAbilityByCallFromRemote_001
1194  * @tc.desc: input invalid params
1195  * @tc.type: FUNC
1196  * @tc.require: issueI5T6GJ
1197  */
1198 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_001, TestSize.Level3)
1199 {
1200     DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_001 start" << std::endl;
1201     AAFwk::Want want;
1202     std::string localDeviceId;
1203     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1204     AppExecFwk::ElementName element(localDeviceId, "ohos.samples.distributedcalc",
1205         "ohos.samples.distributedcalc.MainAbility");
1206     want.SetElement(element);
1207     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1208     sptr<IRemoteObject> connect = new MockDistributedSched();
1209     CallerInfo callerInfo;
1210     callerInfo.uid = 0;
1211     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1212     bool result = BundleManagerInternal::GetCallerAppIdFromBms("ohos.samples.distributedcalc",
1213         callerInfo.callerAppId);
1214     EXPECT_EQ(result, true);
1215     IDistributedSched::AccountInfo accountInfo;
1216     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1217     int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1218         callerInfo, accountInfo);
1219     EXPECT_NE(ret, ERR_OK);
1220     DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_001 end" << std::endl;
1221 }
1222 
1223 /**
1224  * @tc.name: StartAbilityByCallFromRemote_002
1225  * @tc.desc: input invalid params
1226  * @tc.type: FUNC
1227  * @tc.require: issueI5T6GJ
1228  */
1229 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_002, TestSize.Level3)
1230 {
1231     DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_002 start" << std::endl;
1232     AAFwk::Want want;
1233     std::string localDeviceId;
1234     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1235     AppExecFwk::ElementName element(localDeviceId, "ohos.samples.distributedcalc",
1236         "ohos.samples.distributedcalc.MainAbility");
1237     want.SetElement(element);
1238     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1239     sptr<IRemoteObject> connect = new MockDistributedSched();
1240     CallerInfo callerInfo;
1241     callerInfo.uid = 0;
1242     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1243     IDistributedSched::AccountInfo accountInfo;
1244     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1245     int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1246         callerInfo, accountInfo);
1247     EXPECT_EQ(ret, CALL_PERMISSION_DENIED);
1248     DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_002 end" << std::endl;
1249 }
1250 
1251 /**
1252  * @tc.name: ConnectAbilityFromRemote_001
1253  * @tc.desc: test ConnectAbilityFromRemote
1254  * @tc.type: FUNC
1255  * @tc.require: issueI5T6GJ
1256  */
1257 HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_001, TestSize.Level3)
1258 {
1259     DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_001 start" << std::endl;
1260     AAFwk::Want want;
1261     std::string localDeviceId;
1262     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1263     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1264         ABILITY_NAME);
1265     want.SetElement(element);
1266     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1267     AppExecFwk::AbilityInfo abilityInfo;
1268     abilityInfo.permissions.clear();
1269     sptr<IRemoteObject> connect = new MockDistributedSched();
1270     CallerInfo callerInfo;
1271     callerInfo.uid = 0;
1272     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1273     bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
1274     EXPECT_TRUE(result);
1275     IDistributedSched::AccountInfo accountInfo;
1276     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1277     int ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1278         abilityInfo, connect, callerInfo, accountInfo);
1279     EXPECT_EQ(ret, ERR_OK);
1280     DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_001 end" << std::endl;
1281 }
1282 
1283 /**
1284  * @tc.name: ConnectAbilityFromRemote_002
1285  * @tc.desc: input invalid params
1286  * @tc.type: FUNC
1287  * @tc.require: issueI5T6GJ
1288  */
1289 HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_002, TestSize.Level3)
1290 {
1291     DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_002 start" << std::endl;
1292     AAFwk::Want want;
1293     std::string localDeviceId;
1294     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1295     AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1296         ABILITY_NAME);
1297     want.SetElement(element);
1298     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1299     AppExecFwk::AbilityInfo abilityInfo;
1300     abilityInfo.permissions.clear();
1301     sptr<IRemoteObject> connect = new MockDistributedSched();
1302     CallerInfo callerInfo;
1303     callerInfo.uid = 0;
1304     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1305     IDistributedSched::AccountInfo accountInfo;
1306     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1307     int32_t ret1 = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1308         abilityInfo, connect, callerInfo, accountInfo);
1309     AppExecFwk::AbilityInfo targetAbility;
1310     bool ret2 = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
1311     EXPECT_EQ(ret2, true);
1312     if (targetAbility.visible) {
1313         EXPECT_EQ(ret1, ERR_OK);
1314     } else {
1315         EXPECT_EQ(ret1, DMS_START_CONTROL_PERMISSION_DENIED);
1316     }
1317     DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_002 end" << std::endl;
1318 }
1319 
1320 /**
1321  * @tc.name: StartLocalAbility_005
1322  * @tc.desc: test StartLocalAbility
1323  * @tc.type: FUNC
1324  * @tc.require: issueI5T6GJ
1325  */
1326 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_005, TestSize.Level3)
1327 {
1328     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_005 start" << std::endl;
1329     AAFwk::Want want;
1330     std::string localDeviceId;
1331     DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1332     AppExecFwk::ElementName element(localDeviceId, "com.ohos.note", "MainAbility");
1333     want.SetElement(element);
1334     want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1335     AppExecFwk::AbilityInfo abilityInfo;
1336     abilityInfo.permissions.clear();
1337     CallerInfo callerInfo;
1338     callerInfo.uid = 0;
1339     callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1340     bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.ohos.note", callerInfo.callerAppId);
1341     EXPECT_TRUE(result);
1342     IDistributedSched::AccountInfo accountInfo;
1343     accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1344     DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0,
1345         .callerInfo = callerInfo, .accountInfo = accountInfo};
1346     int ret = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
1347     EXPECT_EQ(ret, ERR_OK);
1348     DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_005 end" << std::endl;
1349 }
1350 } // namespace DistributedSchedule
1351 } // namespace OHOS