1 /*
2 * Copyright (c) 2024 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 #include <thread>
16
17 #define private public
18 #define protected public
19 #include "gtest/gtest.h"
20
21 #include "ability_connection_wrapper_stub.h"
22 #include "accesstoken_kit.h"
23 #include "bundle/bundle_manager_internal.h"
24 #include "device_manager.h"
25 #include "distributed_sched_permission.h"
26 #include "distributed_sched_proxy.h"
27 #include "distributed_sched_service.h"
28 #include "distributed_sched_test_util.h"
29 #include "dms_constant.h"
30 #include "dtbschedmgr_device_info_storage.h"
31 #include "dtbschedmgr_log.h"
32 #include "form_mgr_errors.h"
33 #include "if_system_ability_manager.h"
34 #include "ipc_skeleton.h"
35 #include "iservice_registry.h"
36 #include "mock_form_mgr_service.h"
37 #include "mock_distributed_sched.h"
38 #include "multi_user_manager.h"
39 #include "nativetoken_kit.h"
40 #include "mock/svc_distributed_connection_mock.h"
41 #include "mock/multi_user_manager_mock.h"
42 #include "mock/mock_device_manager.h"
43 #include "system_ability_definition.h"
44 #include "test_log.h"
45 #include "token_setproc.h"
46 #include "thread_pool.h"
47 #undef private
48 #undef protected
49
50 using namespace std;
51 using namespace testing;
52 using namespace testing::ext;
53 using namespace OHOS;
54
55 namespace OHOS {
56 namespace DistributedSchedule {
57 using namespace AAFwk;
58 using namespace AppExecFwk;
59 using namespace DistributedHardware;
60 using namespace Constants;
61 namespace {
62 const std::string TAG = "DistributedSchedService";
63 const string LOCAL_DEVICEID = "192.168.43.100";
64 const string REMOTE_DEVICEID = "255.255.255.255";
65 const std::u16string DEVICE_ID = u"192.168.43.100";
66 const std::u16string DEVICE_ID_NULL = u"";
67 constexpr int32_t SESSION_ID = 123;
68 const std::string DMS_MISSION_ID = "dmsMissionId";
69 constexpr int32_t MISSION_ID = 1;
70 const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
71 const string ABILITY_NAME = "com.ohos.permissionmanager.MainAbility";
72 const string BUNDLE_NAME = "com.ohos.permissionmanager";
73 const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
74 const string DMS_VERSION_ID = "dmsVersion";
75 constexpr int32_t SLEEP_TIME = 1000;
76 constexpr int32_t WEARLINK_UID = 7259;
77 }
78
SetNativeToken()79 void SetNativeToken()
80 {
81 uint64_t tokenId;
82 const char *perms[] = {
83 "ohos.permission.GET_BUNDLE_RESOURCES",
84 "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
85 };
86 NativeTokenInfoParams infoInstance = {
87 .dcapsNum = 0,
88 .permsNum = 2,
89 .aclsNum = 0,
90 .dcaps = nullptr,
91 .perms = perms,
92 .acls = nullptr,
93 .processName = "foundation",
94 .aplStr = "system_core",
95 };
96
97 tokenId = GetAccessTokenId(&infoInstance);
98 if (tokenId == 0) {
99 HILOGE("Failed to get valid Token ID.");
100 return;
101 }
102 SetSelfTokenID(tokenId);
103 setuid(WEARLINK_UID);
104 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
105 }
106
107 class DistributedSchedServiceFirstTest : public testing::Test {
108 public:
109 static void SetUpTestCase();
110 static void TearDownTestCase();
111 void SetUp();
112 void TearDown();
113 sptr<IDistributedSched> GetDms();
114 int32_t InstallBundle(const std::string &bundlePath) const;
115 sptr<IDistributedSched> proxy_;
116 static inline std::shared_ptr<MultiUserManagerMock> multiUserMgrMock_ = nullptr;
117 static inline std::shared_ptr<DeviceManagerMock> deviceMgrMock_ = nullptr;
118 static inline std::shared_ptr<SvcDistributedConnectionMock> svcDConnMock = nullptr;
119
120 protected:
121 enum class LoopTime : int32_t {
122 LOOP_TIME = 10,
123 LOOP_PRESSURE_TIME = 100,
124 };
125 sptr<IRemoteObject> GetDSchedService() const;
126 void GetAbilityInfo(const std::string& package, const std::string& name,
127 const std::string& bundleName, const std::string& deviceId,
128 OHOS::AppExecFwk::AbilityInfo& abilityInfo);
129
130 class DeviceInitCallBack : public DmInitCallback {
131 void OnRemoteDied() override;
132 };
133 };
134
SetUpTestCase()135 void DistributedSchedServiceFirstTest::SetUpTestCase()
136 {
137 if (!DistributedSchedUtil::LoadDistributedSchedService()) {
138 DTEST_LOG << "DistributedSchedServiceFirstTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
139 }
140 multiUserMgrMock_ = std::make_shared<MultiUserManagerMock>();
141 MultiUserManagerMock::multiUserMgrMock = multiUserMgrMock_;
142 svcDConnMock = std::make_shared<SvcDistributedConnectionMock>();
143 SvcDistributedConnectionMock::connMock = svcDConnMock;
144 deviceMgrMock_ = std::make_shared<DeviceManagerMock>();
145 DeviceManagerMock::deviceMgrMock = deviceMgrMock_;
146 const std::string pkgName = "DBinderBus_" + std::to_string(getprocpid());
147 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
148 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
149 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
150 }
151
TearDownTestCase()152 void DistributedSchedServiceFirstTest::TearDownTestCase()
153 {
154 MultiUserManagerMock::multiUserMgrMock = nullptr;
155 multiUserMgrMock_ = nullptr;
156 SvcDistributedConnectionMock::connMock = nullptr;
157 svcDConnMock = nullptr;
158 DeviceManagerMock::deviceMgrMock = nullptr;
159 deviceMgrMock_ = nullptr;
160 }
161
SetUp()162 void DistributedSchedServiceFirstTest::SetUp()
163 {
164 DistributedSchedUtil::MockPermission();
165 }
166
TearDown()167 void DistributedSchedServiceFirstTest::TearDown()
168 {}
169
OnRemoteDied()170 void DistributedSchedServiceFirstTest::DeviceInitCallBack::OnRemoteDied()
171 {}
172
GetDms()173 sptr<IDistributedSched> DistributedSchedServiceFirstTest::GetDms()
174 {
175 if (proxy_ != nullptr) {
176 return proxy_;
177 }
178 auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
179 EXPECT_TRUE(sm != nullptr);
180 if (sm == nullptr) {
181 DTEST_LOG << "DistributedSchedServiceFirstTest sm is nullptr" << std::endl;
182 return nullptr;
183 }
184 DTEST_LOG << "DistributedSchedServiceFirstTest sm is not nullptr" << std::endl;
185 auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
186 proxy_ = iface_cast<IDistributedSched>(distributedObject);
187 if (proxy_ == nullptr) {
188 DTEST_LOG << "DistributedSchedServiceFirstTest DistributedSched is nullptr" << std::endl;
189 } else {
190 DTEST_LOG << "DistributedSchedServiceFirstTest DistributedSched is not nullptr" << std::endl;
191 }
192 return proxy_;
193 }
194
GetDSchedService() const195 sptr<IRemoteObject> DistributedSchedServiceFirstTest::GetDSchedService() const
196 {
197 sptr<IRemoteObject> dsched(new MockDistributedSched());
198 return dsched;
199 }
200
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)201 void DistributedSchedServiceFirstTest::GetAbilityInfo(const std::string& package, const std::string& name,
202 const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
203 {
204 abilityInfo.bundleName = bundleName;
205 abilityInfo.deviceId = deviceId;
206 }
207
208 /**
209 * @tc.name: Dump001
210 * @tc.desc: call Dump
211 * @tc.type: FUNC
212 * @tc.require: I6O5T3
213 */
214 HWTEST_F(DistributedSchedServiceFirstTest, Dump001, TestSize.Level3)
215 {
216 DTEST_LOG << "DistributedSchedServiceFirstTest Dump001 start" << std::endl;
217 int32_t fd = 1;
218 const std::vector<std::u16string> args;
219 const wptr<IRemoteObject> remote;
220 int32_t missionId = 0;
221 bool resultCode = ERR_OK;
222 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
223 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
224 DistributedSchedService::GetInstance().ProcessFormMgrDied(remote);
225 EXPECT_EQ(ret, ERR_OK);
226 DTEST_LOG << "DistributedSchedServiceFirstTest Dump001 end" << std::endl;
227 }
228
229 /**
230 * @tc.name: Dump002
231 * @tc.desc: call Dump
232 * @tc.type: FUNC
233 * @tc.require: I6O5T3
234 */
235 HWTEST_F(DistributedSchedServiceFirstTest, Dump002, TestSize.Level3)
236 {
237 DTEST_LOG << "DistributedSchedServiceFirstTest Dump002 start" << std::endl;
238 int32_t fd = 0;
239 const std::vector<std::u16string> args;
240 const std::string deviceId;
241 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
242 DistributedSchedService::GetInstance().DeviceOnlineNotify(deviceId);
243 DistributedSchedService::GetInstance().DeviceOfflineNotify(deviceId);
244 DistributedSchedService::GetInstance().DeviceOfflineNotifyAfterDelete(deviceId);
245 EXPECT_EQ(ret, DMS_WRITE_FILE_FAILED_ERR);
246 DTEST_LOG << "DistributedSchedServiceFirstTest Dump002 end" << std::endl;
247 }
248
249 /**
250 * @tc.name: StartRemoteAbility_001
251 * @tc.desc: call StartRemoteAbility with illegal params
252 * @tc.type: FUNC
253 */
254 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_001, TestSize.Level1)
255 {
256 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_001 start" << std::endl;
257 sptr<IDistributedSched> proxy = GetDms();
258 ASSERT_NE(nullptr, proxy);
259 /**
260 * @tc.steps: step1. StartRemoteAbility with uninitialized params
261 * @tc.expected: step1. StartRemoteAbility return INVALID_PARAMETERS_ERR
262 */
263 AAFwk::Want want;
264 int result1 = proxy->StartRemoteAbility(want, 0, 0, 0);
265 DTEST_LOG << "result1:" << result1 << std::endl;
266 /**
267 * @tc.steps: step2. StartRemoteAbility with empty want's deviceId
268 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
269 */
270 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
271 "com.ohos.distributedmusicplayer.MainAbility");
272 want.SetElement(element);
273 int result2 = proxy->StartRemoteAbility(want, 0, 0, 0);
274 DTEST_LOG << "result2:" << result2 << std::endl;
275
276 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result1);
277 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result2);
278 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_001 end" << std::endl;
279 }
280
281 /**
282 * @tc.name: StartRemoteAbility_002
283 * @tc.desc: call StartRemoteAbility with dms with wrong deviceId and local deviceId
284 * @tc.type: FUNC
285 */
286 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_002, TestSize.Level1)
287 {
288 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_002 start" << std::endl;
289 sptr<IDistributedSched> proxy = GetDms();
290 ASSERT_NE(nullptr, proxy);
291 /**
292 * @tc.steps: step1. set want with wrong deviceId
293 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
294 */
295 AAFwk::Want want;
296 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
297 "com.ohos.distributedmusicplayer.MainAbility");
298 want.SetElement(element);
299 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillRepeatedly(Return(true));
300 int result1 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
301 DTEST_LOG << "result:" << result1 << std::endl;
302 std::string deviceId;
303 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
304 AppExecFwk::ElementName element1(deviceId, "com.ohos.distributedmusicplayer",
305 "com.ohos.distributedmusicplayer.MainAbility");
306 want.SetElement(element1);
307 int result2 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
308 DTEST_LOG << "result:" << result2 << std::endl;
309 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
310 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
311 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_002 end" << std::endl;
312 }
313
314 /**
315 * @tc.name: StartRemoteAbility_003
316 * @tc.desc: call StartRemoteAbility with dms
317 * @tc.type: FUNC
318 */
319 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_003, TestSize.Level1)
320 {
321 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_003 start" << std::endl;
322 /**
323 * @tc.steps: step1. set want with wrong deviceId
324 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
325 */
326 AAFwk::Want want;
327 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
328 "com.ohos.distributedmusicplayer.MainAbility");
329 want.SetElement(element);
330 int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
331 DTEST_LOG << "result:" << result << std::endl;
332 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
333 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_003 end" << std::endl;
334 }
335
336 /**
337 * @tc.name: StartRemoteAbility_004
338 * @tc.desc: call StartRemoteAbility
339 * @tc.type: FUNC
340 */
341 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_004, TestSize.Level1)
342 {
343 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_004 start" << std::endl;
344 sptr<IDistributedSched> proxy = GetDms();
345 ASSERT_NE(nullptr, proxy);
346 /**
347 * @tc.steps: step1. set want and abilityInfo
348 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
349 */
350 AAFwk::Want want;
351 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
352 "com.ohos.distributedmusicplayer.MainAbility");
353 want.SetElement(element);
354 int result = proxy->StartRemoteAbility(want, 0, 0, 0);
355 DTEST_LOG << "result:" << result << std::endl;
356 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
357 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_004 end" << std::endl;
358 }
359
360 /**
361 * @tc.name: StartRemoteAbility_005
362 * @tc.desc: user is not foreground
363 * @tc.type: FUNC
364 */
365 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility_005, TestSize.Level1)
366 {
367 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_005 start" << std::endl;
368 /**
369 * @tc.steps: step1. set want with wrong deviceId
370 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
371 */
372 AAFwk::Want want;
373 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
374 "com.ohos.distributedmusicplayer.MainAbility");
375 want.SetElement(element);
376 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(false));
377 int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
378 DTEST_LOG << "result:" << result << std::endl;
379 EXPECT_EQ(static_cast<int>(DMS_NOT_FOREGROUND_USER), result);
380 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility_005 end" << std::endl;
381 }
382
383 /**
384 * @tc.name: StartRemoteAbility001
385 * @tc.desc: call StartRemoteAbility
386 * @tc.type: FUNC
387 * @tc.require: I6P0I9
388 */
389 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility001, TestSize.Level3)
390 {
391 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility001 start" << std::endl;
392 AAFwk::Want want;
393 int32_t callerUid = 0;
394 int32_t requestCode = 0;
395 uint32_t accessToken = 0;
396 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillRepeatedly(Return(true));
397 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
398 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
399 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility001 end" << std::endl;
400 }
401
402 /**
403 * @tc.name: StartRemoteAbility002
404 * @tc.desc: call StartRemoteAbility
405 * @tc.type: FUNC
406 * @tc.require: I6P0I9
407 */
408 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility002, TestSize.Level3)
409 {
410 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility002 start" << std::endl;
411 AAFwk::Want want;
412 int32_t callerUid = 1;
413 int32_t requestCode = 0;
414 uint32_t accessToken = 0;
415 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
416 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
417 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility002 end" << std::endl;
418 }
419
420 /**
421 * @tc.name: StartRemoteAbility003
422 * @tc.desc: call StartRemoteAbility
423 * @tc.type: FUNC
424 * @tc.require: I6P0I9
425 */
426 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility003, TestSize.Level3)
427 {
428 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility003 start" << std::endl;
429 AAFwk::Want want;
430 int32_t callerUid = 0;
431 int32_t requestCode = 1;
432 uint32_t accessToken = 0;
433 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
434 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
435 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility003 end" << std::endl;
436 }
437
438 /**
439 * @tc.name: StartRemoteAbility004
440 * @tc.desc: call StartRemoteAbility
441 * @tc.type: FUNC
442 * @tc.require: I6P0I9
443 */
444 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility004, TestSize.Level3)
445 {
446 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility004 start" << std::endl;
447 AAFwk::Want want;
448 int32_t callerUid = 0;
449 int32_t requestCode = 0;
450 uint32_t accessToken = 1;
451 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
452 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
453 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility004 end" << std::endl;
454 }
455
456 /**
457 * @tc.name: StartRemoteAbility005
458 * @tc.desc: call StartRemoteAbility
459 * @tc.type: FUNC
460 * @tc.require: I6P0I9
461 */
462 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility005, TestSize.Level3)
463 {
464 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility005 start" << std::endl;
465 AAFwk::Want want;
466 int32_t callerUid = 1;
467 int32_t requestCode = 1;
468 uint32_t accessToken = 0;
469 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
470 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
471 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility005 end" << std::endl;
472 }
473
474 /**
475 * @tc.name: StartRemoteAbility006
476 * @tc.desc: call StartRemoteAbility
477 * @tc.type: FUNC
478 * @tc.require: I6P0I9
479 */
480 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility006, TestSize.Level3)
481 {
482 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility006 start" << std::endl;
483 AAFwk::Want want;
484 int32_t callerUid = 1;
485 int32_t requestCode = 1;
486 uint32_t accessToken = 1;
487 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
488 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
489 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility006 end" << std::endl;
490 }
491
492 /**
493 * @tc.name: StartRemoteAbility007
494 * @tc.desc: user is not foreground
495 * @tc.type: FUNC
496 */
497 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbility007, TestSize.Level3)
498 {
499 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility007 start" << std::endl;
500 AAFwk::Want want;
501 int32_t callerUid = 0;
502 int32_t requestCode = 0;
503 uint32_t accessToken = 0;
504 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillOnce(Return(false));
505 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
506 EXPECT_EQ(ret, DMS_NOT_FOREGROUND_USER);
507 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbility007 end" << std::endl;
508 }
509
510 /**
511 * @tc.name: StartAbilityFromRemote_001
512 * @tc.desc: call StartAbilityFromRemote with illegal param
513 * @tc.type: FUNC
514 */
515 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_001, TestSize.Level1)
516 {
517 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_001 start" << std::endl;
518 sptr<IDistributedSched> proxy = GetDms();
519 ASSERT_NE(nullptr, proxy);
520 AAFwk::Want want;
521 AppExecFwk::AbilityInfo abilityInfo;
522 CallerInfo callerInfo;
523 callerInfo.uid = 0;
524 callerInfo.sourceDeviceId = "255.255.255.255";
525 IDistributedSched::AccountInfo accountInfo;
526 /**
527 * @tc.steps: step1. StartAbilityFromRemote with uninitialized params
528 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
529 */
530 int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
531 DTEST_LOG << "result1:" << result1 << std::endl;
532 /**
533 * @tc.steps: step1. StartAbilityFromRemote with with empty deviceId
534 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
535 */
536 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
537 "com.ohos.distributedmusicplayer.MainAbility");
538 want.SetElement(element);
539 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
540 "com.ohos.distributedmusicplayer", "192.168.43.101", abilityInfo);
541 int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
542 DTEST_LOG << "result2:" << result2 << std::endl;
543 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
544 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
545 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_001 end" << std::endl;
546 }
547
548 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
549 /**
550 * @tc.name: StartRemoteShareForm_002
551 * @tc.desc: call StartAbilityFromRemote with dms
552 * @tc.type: FUNC
553 * @tc.require: I76THI
554 */
555 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteShareForm_002, TestSize.Level1)
556 {
557 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteShareForm_002 start" << std::endl;
558
559 sptr<IDistributedSched> proxy = GetDms();
560 ASSERT_NE(nullptr, proxy);
561
562 AAFwk::Want want;
563 AppExecFwk::ElementName element("255.255.255.255", "com.ohos.distributedmusicplayer",
564 "com.ohos.distributedmusicplayer.MainAbility");
565 want.SetElement(element);
566 AppExecFwk::AbilityInfo abilityInfo;
567 CallerInfo callerInfo;
568 callerInfo.uid = 0;
569 callerInfo.sourceDeviceId = "255.255.255.255";
570 IDistributedSched::AccountInfo accountInfo;
571
572 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
573 DTEST_LOG << "result1 is" << result1 << std::endl;
574 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
575 "com.ohos.distributedmusicplayer.MainAbilityService");
576 want.SetElement(element2);
577 int missionId = 0;
578 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
579 want.SetParam(DMS_MISSION_ID, missionId);
580 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
581 DTEST_LOG << "result2:" << result2 << std::endl;
582
583 /**
584 * @tc.steps: step1. call StartAbilityFromRemote when remoteDeviceId is valid.
585 */
586 const std::string remoteDeviceId = "123456";
587 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
588 int32_t result = DistributedSchedService::GetInstance().StartRemoteShareForm(remoteDeviceId, formShareInfo);
589 EXPECT_EQ(result, GET_REMOTE_DMS_FAIL);
590 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteShareForm_002 end" << std::endl;
591 }
592 #endif
593
594 /**
595 * @tc.name: StartAbilityFromRemote_003
596 * @tc.desc: call StartAbilityFromRemote with dms
597 * @tc.type: FUNC
598 */
599 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_003, TestSize.Level1)
600 {
601 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_003 start" << std::endl;
602 sptr<IDistributedSched> proxy = GetDms();
603
604 AAFwk::Want want;
605 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
606 "com.ohos.distributedmusicplayer.MainAbility");
607 want.SetElement(element);
608 AppExecFwk::AbilityInfo abilityInfo;
609 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
610 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
611 CallerInfo callerInfo;
612 callerInfo.uid = 0;
613 callerInfo.sourceDeviceId = "255.255.255.255";
614 IDistributedSched::AccountInfo accountInfo;
615
616 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
617 abilityInfo, 0, callerInfo, accountInfo);
618 DTEST_LOG << "result1:" << result1 << std::endl;
619
620 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
621 "com.ohos.distributedmusicplayer.MainAbilityService");
622 want.SetElement(element2);
623 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
624 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
625 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
626 abilityInfo, 0, callerInfo, accountInfo);
627 DTEST_LOG << "result2:" << result2 << std::endl;
628 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
629 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
630 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_003 end" << std::endl;
631 }
632
633 /**
634 * @tc.name: StartAbilityFromRemote_004
635 * @tc.desc: call StartAbilityFromRemote
636 * @tc.type: FUNC
637 */
638 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_004, TestSize.Level1)
639 {
640 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_004 start" << std::endl;
641 AAFwk::Want want;
642 std::string localDeviceId;
643 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
644 AppExecFwk::ElementName element(localDeviceId, "com.ohos.distributedmusicplayer",
645 "com.ohos.distributedmusicplayer.MainAbility");
646 want.SetElement(element);
647 AppExecFwk::AbilityInfo abilityInfo;
648 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
649 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
650 abilityInfo.visible = true;
651 abilityInfo.permissions.clear();
652 CallerInfo callerInfo;
653 callerInfo.uid = 0;
654 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
655 IDistributedSched::AccountInfo accountInfo;
656 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
657 accountInfo.groupIdList.push_back("123456");
658 int result = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
659 abilityInfo, 0, callerInfo, accountInfo);
660 DTEST_LOG << "result:" << result << std::endl;
661 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
662 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_004 end" << std::endl;
663 }
664
665 /**
666 * @tc.name: StartAbilityFromRemote_005
667 * @tc.desc: test StartAbilityFromRemote
668 * @tc.type: FUNC
669 * @tc.require: issueI5T6GJ
670 */
671 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityFromRemote_005, TestSize.Level3)
672 {
673 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_005 start" << std::endl;
674
675 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
676 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
677 }
678 int32_t missionId = MISSION_ID;
679 bool isSuccess = false;
680 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, isSuccess);
681
682 AAFwk::Want want;
683 std::string localDeviceId;
684 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
685 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
686 ABILITY_NAME);
687 want.SetElement(element);
688 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
689 AppExecFwk::AbilityInfo abilityInfo;
690 abilityInfo.permissions.clear();
691 CallerInfo callerInfo;
692 callerInfo.uid = 0;
693 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
694 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
695 EXPECT_TRUE(result);
696 IDistributedSched::AccountInfo accountInfo;
697 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
698 int ret = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
699 abilityInfo, 0, callerInfo, accountInfo);
700 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
701 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityFromRemote_005 end" << std::endl;
702 }
703
704 /**
705 * @tc.name: SendResultFromRemote_001
706 * @tc.desc: call SendResultFromRemote with illegal param
707 * @tc.type: FUNC
708 */
709 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_001, TestSize.Level1)
710 {
711 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_001 start" << std::endl;
712 sptr<IDistributedSched> proxy = GetDms();
713 ASSERT_NE(nullptr, proxy);
714 AAFwk::Want want;
715 CallerInfo callerInfo;
716 callerInfo.uid = 0;
717 callerInfo.sourceDeviceId = "255.255.255.255";
718 IDistributedSched::AccountInfo accountInfo;
719 /**
720 * @tc.steps: step1. SendResultFromRemote with uninitialized params
721 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
722 */
723 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
724 DTEST_LOG << "result1:" << result1 << std::endl;
725 /**
726 * @tc.steps: step1. SendResultFromRemote with with empty deviceId
727 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
728 */
729 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
730 "com.ohos.distributedmusicplayer.MainAbility");
731 want.SetElement(element);
732 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
733 DTEST_LOG << "result2:" << result2 << std::endl;
734 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
735 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
736 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote end" << std::endl;
737 }
738
739 /**
740 * @tc.name: SendResultFromRemote_002
741 * @tc.desc: call SendResultFromRemote with dms
742 * @tc.type: FUNC
743 */
744 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_002, TestSize.Level1)
745 {
746 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_002 start" << std::endl;
747 sptr<IDistributedSched> proxy = GetDms();
748
749 AAFwk::Want want;
750 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
751 "com.ohos.distributedmusicplayer.MainAbility");
752 want.SetElement(element);
753 CallerInfo callerInfo;
754 callerInfo.uid = 0;
755 callerInfo.sourceDeviceId = "255.255.255.255";
756 IDistributedSched::AccountInfo accountInfo;
757
758 int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
759 DTEST_LOG << "result1:" << result1 << std::endl;
760
761 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
762 "com.ohos.distributedmusicplayer.MainAbilityService");
763 want.SetElement(element2);
764 int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
765 DTEST_LOG << "result2:" << result2 << std::endl;
766 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
767 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
768 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_002 end" << std::endl;
769 }
770
771 /**
772 * @tc.name: SendResultFromRemote_003
773 * @tc.desc: call SendResultFromRemote
774 * @tc.type: FUNC
775 */
776 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_003, TestSize.Level1)
777 {
778 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_003 start" << std::endl;
779 AAFwk::Want want;
780 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
781 "com.ohos.distributedmusicplayer.MainAbility");
782 want.SetElement(element);
783 std::string localDeviceId;
784 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
785 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
786 CallerInfo callerInfo;
787 callerInfo.uid = 0;
788 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
789 IDistributedSched::AccountInfo accountInfo;
790 /**
791 * @tc.steps: step1. call RemoveContinuationTimeout
792 */
793 DTEST_LOG << "DistributedSchedServiceFirstTest RemoveContinuationTimeout_001 start" << std::endl;
794 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
795 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
796 }
797 int32_t missionId = MISSION_ID;
798 DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
799 DTEST_LOG << "DistributedSchedServiceFirstTest RemoveContinuationTimeout_001 end" << std::endl;
800
801 int result = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
802 DTEST_LOG << "result:" << result << std::endl;
803 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
804 /**
805 * @tc.steps: step2. call RemoteConnectAbilityMappingLocked when connect == nullptr;
806 */
807 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(nullptr,
808 localDeviceId, localDeviceId, element, callerInfo, TargetComponent::HARMONY_COMPONENT);
809 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_003 end" << std::endl;
810 }
811
812 /**
813 * @tc.name: SendResultFromRemote_004
814 * @tc.desc: test SendResultFromRemote
815 * @tc.type: FUNC
816 * @tc.require: issueI5T6GJ
817 */
818 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_004, TestSize.Level3)
819 {
820 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_004 start" << std::endl;
821
822 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
823 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
824 }
825 int32_t missionId = MISSION_ID;
826 bool resultCode = ERR_OK;
827 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
828
829 AAFwk::Want want;
830 std::string localDeviceId;
831 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
832 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
833 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
834 "bmsThirdBundle");
835 want.SetElement(element);
836 CallerInfo callerInfo;
837 callerInfo.uid = 0;
838 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
839 IDistributedSched::AccountInfo accountInfo;
840 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
841 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
842 EXPECT_NE(ret, ERR_OK);
843 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_004 end" << std::endl;
844 }
845
846 /**
847 * @tc.name: SendResultFromRemote_005
848 * @tc.desc: test SendResultFromRemote
849 * @tc.type: FUNC
850 * @tc.require: I6P0I9
851 */
852 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_005, TestSize.Level3)
853 {
854 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_005 start" << std::endl;
855 AAFwk::Want want;
856 std::string localDeviceId;
857 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
858 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
859 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
860 "bmsThirdBundle");
861 want.SetElement(element);
862 CallerInfo callerInfo;
863 callerInfo.uid = 0;
864 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
865 IDistributedSched::AccountInfo accountInfo;
866 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
867 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
868 EXPECT_NE(ret, ERR_OK);
869 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_005 end" << std::endl;
870 }
871
872 /**
873 * @tc.name: SendResultFromRemote_006
874 * @tc.desc: test SendResultFromRemote
875 * @tc.type: FUNC
876 * @tc.require: I6P0I9
877 */
878 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_006, TestSize.Level3)
879 {
880 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_006 start" << std::endl;
881 AAFwk::Want want;
882 std::string localDeviceId;
883 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
884 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
885 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
886 "bmsThirdBundle");
887 want.SetElement(element);
888 CallerInfo callerInfo;
889 callerInfo.uid = 1;
890 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
891 IDistributedSched::AccountInfo accountInfo;
892 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
893 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
894 EXPECT_NE(ret, ERR_OK);
895 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_006 end" << std::endl;
896 }
897
898 /**
899 * @tc.name: SendResultFromRemote_007
900 * @tc.desc: test SendResultFromRemote
901 * @tc.type: FUNC
902 * @tc.require: I6P0I9
903 */
904 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_007, TestSize.Level3)
905 {
906 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_007 start" << std::endl;
907 AAFwk::Want want;
908 std::string localDeviceId;
909 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
910 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
911 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
912 "bmsThirdBundle");
913 want.SetElement(element);
914 CallerInfo callerInfo;
915 callerInfo.uid = 0;
916 callerInfo.sourceDeviceId = localDeviceId;
917 IDistributedSched::AccountInfo accountInfo;
918 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
919 int32_t ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
920 EXPECT_NE(ret, ERR_OK);
921 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_007 end" << std::endl;
922 }
923
924 /**
925 * @tc.name: SendResultFromRemote_008
926 * @tc.desc: test SendResultFromRemote
927 * @tc.type: FUNC
928 * @tc.require: I6P0I9
929 */
930 HWTEST_F(DistributedSchedServiceFirstTest, SendResultFromRemote_008, TestSize.Level3)
931 {
932 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_008 start" << std::endl;
933 AAFwk::Want want;
934 std::string localDeviceId;
935 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
936 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
937 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
938 "bmsThirdBundle");
939 want.SetElement(element);
940 CallerInfo callerInfo;
941 callerInfo.uid = 0;
942 callerInfo.sourceDeviceId = localDeviceId;
943 IDistributedSched::AccountInfo accountInfo;
944 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
945 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
946 EXPECT_NE(ret, ERR_OK);
947 DTEST_LOG << "DistributedSchedServiceFirstTest SendResultFromRemote_008 end" << std::endl;
948 }
949
950 /**
951 * @tc.name: ContinueMission_001
952 * @tc.desc: call ContinueMission
953 * @tc.type: FUNC
954 */
955 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_001, TestSize.Level1)
956 {
957 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl;
958 WantParams wantParams;
959 auto callback = GetDSchedService();
960 int32_t missionId = MISSION_ID;
961 std::string localDeviceId;
962 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
963 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
964 "string", localDeviceId, missionId, callback, wantParams);
965 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
966 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl;
967 }
968
969 /**
970 * @tc.name: ContinueMission_002
971 * @tc.desc: call ContinueMission
972 * @tc.type: FUNC
973 */
974 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_002, TestSize.Level1)
975 {
976 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl;
977 WantParams wantParams;
978 auto callback = GetDSchedService();
979 int32_t missionId = MISSION_ID;
980 std::string localDeviceId;
981 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
982 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
983 "string", "string", missionId, callback, wantParams);
984 EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
985 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl;
986 }
987
988 /**
989 * @tc.name: ContinueMission_003
990 * @tc.desc: call ContinueMission
991 * @tc.type: FUNC
992 * @tc.require: I7F8KH
993 */
994 HWTEST_F(DistributedSchedServiceFirstTest, ContinueMission_003, TestSize.Level1)
995 {
996 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 start" << std::endl;
997
998 WantParams wantParams;
999 auto callback = GetDSchedService();
1000 std::string bundleName = BUNDLE_NAME;
1001
1002 /**
1003 * @tc.steps: step1. test ContinueMission when srcDeviceId is empty;
1004 */
1005 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1006 "", "string", BUNDLE_NAME, callback, wantParams);
1007 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1008
1009 /**
1010 * @tc.steps: step2. test ContinueMission when dstDeviceId is empty;
1011 */
1012 result = DistributedSchedService::GetInstance().ContinueMission(
1013 "string", "", bundleName, callback, wantParams);
1014 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1015
1016 /**
1017 * @tc.steps: step3. test ContinueMission when callback is empty;
1018 */
1019 result = DistributedSchedService::GetInstance().ContinueMission(
1020 "string", "string", bundleName, nullptr, wantParams);
1021 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1022
1023 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 end" << std::endl;
1024 }
1025
1026 /**
1027 * @tc.name: StartContinuation_001
1028 * @tc.desc: call StartContinuation
1029 * @tc.type: FUNC
1030 * @tc.require: I5NOA1
1031 */
1032 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_001, TestSize.Level1)
1033 {
1034 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
1035 AAFwk::Want want;
1036 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1037 "com.ohos.distributedmusicplayer.MainAbility");
1038 want.SetElement(element);
1039 int32_t missionId = MISSION_ID;
1040 int32_t callerUid = 0;
1041 int32_t status = 1;
1042 uint32_t accessToken = 0;
1043 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1044 want, missionId, callerUid, status, accessToken);
1045 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1046 CallerInfo callerInfo;
1047 ConnectInfo connectInfo;
1048 /**
1049 * @tc.steps: step1. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1050 */
1051 DistributedSchedService::GetInstance().componentChangeHandler_ = nullptr;
1052 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1053 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1054 /**
1055 * @tc.steps: step2. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1056 */
1057 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1058 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1059 /**
1060 * @tc.steps: step3. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1061 */
1062 auto runner = AppExecFwk::EventRunner::Create("DmsComponentChange");
1063 DistributedSchedService::GetInstance().componentChangeHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1064 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1065 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1066 /**
1067 * @tc.steps: step4. ReportDistributedComponentChange when callerInfo.bundleNames is not empty
1068 */
1069 callerInfo.bundleNames.emplace_back("bundleName");
1070 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1071 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1072 /**
1073 * @tc.steps: step5. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1074 */
1075 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1076 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1077 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 end" << std::endl;
1078 }
1079
1080 /**
1081 * @tc.name: StartContinuation_002
1082 * @tc.desc: call StartContinuation
1083 * @tc.type: FUNC
1084 */
1085 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_002, TestSize.Level1)
1086 {
1087 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
1088 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1089 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1090 }
1091 AAFwk::Want want;
1092 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1093 "com.ohos.distributedmusicplayer.MainAbility");
1094 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1095 want.SetElement(element);
1096 want.SetFlags(flags);
1097 int32_t missionId = MISSION_ID;
1098 int32_t callerUid = 0;
1099 int32_t status = 1;
1100 uint32_t accessToken = 0;
1101 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1102 want, missionId, callerUid, status, accessToken);
1103 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1104 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 end" << std::endl;
1105 }
1106
1107 /**
1108 * @tc.name: StartContinuation_003
1109 * @tc.desc: call StartContinuation
1110 * @tc.type: FUNC
1111 * @tc.require: I6O5T3
1112 */
1113 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_003, TestSize.Level3)
1114 {
1115 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
1116 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1117 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1118 }
1119 AAFwk::Want want;
1120 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1121 "com.ohos.distributedmusicplayer.MainAbility");
1122 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1123 want.SetElement(element);
1124 want.SetFlags(flags);
1125 int32_t missionId = 0;
1126 int32_t callerUid = 1;
1127 int32_t status = ERR_OK;
1128 uint32_t accessToken = 0;
1129 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1130 want, missionId, callerUid, status, accessToken);
1131 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1132 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 end" << std::endl;
1133 }
1134
1135 /**
1136 * @tc.name: StartContinuation_004
1137 * @tc.desc: call StartContinuation
1138 * @tc.type: FUNC
1139 * @tc.require: I6O5T3
1140 */
1141 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_004, TestSize.Level3)
1142 {
1143 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 start" << std::endl;
1144 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1145 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1146 }
1147 AAFwk::Want want;
1148 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1149 "com.ohos.distributedmusicplayer.MainAbility");
1150 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1151 want.SetElement(element);
1152 want.SetFlags(flags);
1153 int32_t missionId = 0;
1154 int32_t callerUid = 0;
1155 int32_t status = ERR_OK;
1156 uint32_t accessToken = 1;
1157 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1158 want, missionId, callerUid, status, accessToken);
1159 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1160 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 end" << std::endl;
1161 }
1162
1163 /**
1164 * @tc.name: StartContinuation_005
1165 * @tc.desc: call StartContinuation
1166 * @tc.type: FUNC
1167 * @tc.require: I6O5T3
1168 */
1169 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_005, TestSize.Level3)
1170 {
1171 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 start" << std::endl;
1172 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1173 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1174 }
1175 AAFwk::Want want;
1176 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1177 "com.ohos.distributedmusicplayer.MainAbility");
1178 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1179 want.SetElement(element);
1180 want.SetFlags(flags);
1181 int32_t missionId = 0;
1182 int32_t callerUid = 1;
1183 int32_t status = ERR_OK;
1184 uint32_t accessToken = 1;
1185 bool resultCode = true;
1186 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1187 want, missionId, callerUid, status, accessToken);
1188 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1189 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1190 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 end" << std::endl;
1191 }
1192
1193 /**
1194 * @tc.name: StartContinuation_006
1195 * @tc.desc: call StartContinuation
1196 * @tc.type: FUNC
1197 * @tc.require: I6O5T3
1198 */
1199 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_006, TestSize.Level3)
1200 {
1201 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 start" << std::endl;
1202 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1203 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1204 }
1205 AAFwk::Want want;
1206 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1207 "com.ohos.distributedmusicplayer.MainAbility");
1208 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1209 want.SetElement(element);
1210 want.SetFlags(flags);
1211 int32_t missionId = 0;
1212 int32_t callerUid = 0;
1213 int32_t status = ERR_OK;
1214 uint32_t accessToken = 0;
1215 bool resultCode = ERR_OK;
1216 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1217 want, missionId, callerUid, status, accessToken);
1218 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1219 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1220 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 end" << std::endl;
1221 }
1222
1223 /**
1224 * @tc.name: StartContinuation_007
1225 * @tc.desc: call StartContinuation
1226 * @tc.type: FUNC
1227 * @tc.type: I6O5T3
1228 */
1229 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_007, TestSize.Level3)
1230 {
1231 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 start" << std::endl;
1232 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1233 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1234 }
1235 AAFwk::Want want;
1236 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1237 "com.ohos.distributedmusicplayer.MainAbility");
1238 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1239 want.SetElement(element);
1240 want.SetFlags(flags);
1241 int32_t missionId = 0;
1242 int32_t callerUid = 0;
1243 int32_t status = ERR_OK;
1244 uint32_t accessToken = 0;
1245 bool isSuccess = false;
1246 /**
1247 * @tc.steps: step1. call GetFormMgrProxy
1248 */
1249 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1250 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1251 DistributedSchedService::GetInstance().GetFormMgrProxy();
1252 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1253 #endif
1254
1255 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1256 want, missionId, callerUid, status, accessToken);
1257 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1258 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1259 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 end" << std::endl;
1260 }
1261
1262 /**
1263 * @tc.name: StartContinuation_008
1264 * @tc.desc: call StartContinuation
1265 * @tc.type: FUNC
1266 * @tc.type: I6O5T3
1267 */
1268 HWTEST_F(DistributedSchedServiceFirstTest, StartContinuation_008, TestSize.Level3)
1269 {
1270 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 start" << std::endl;
1271 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1272 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1273 }
1274 AAFwk::Want want;
1275 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1276 "com.ohos.distributedmusicplayer.MainAbility");
1277 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1278 want.SetElement(element);
1279 want.SetFlags(flags);
1280 int32_t missionId = 0;
1281 int32_t callerUid = 0;
1282 int32_t status = ERR_OK;
1283 uint32_t accessToken = 0;
1284 bool isSuccess = false;
1285 /**
1286 * @tc.steps: step1. call GetFormMgrProxy
1287 */
1288 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1289 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1290 DistributedSchedService::GetInstance().GetFormMgrProxy();
1291 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1292 #endif
1293
1294 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1295 want, missionId, callerUid, status, accessToken);
1296 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1297 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1298 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 end" << std::endl;
1299 }
1300
1301 /**
1302 * @tc.name: NotifyCompleteContinuation_001
1303 * @tc.desc: call NotifyCompleteContinuation
1304 * @tc.type: FUNC
1305 */
1306 HWTEST_F(DistributedSchedServiceFirstTest, NotifyCompleteContinuation_001, TestSize.Level1)
1307 {
1308 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
1309 bool isSuccess = false;
1310 EXPECT_NO_FATAL_FAILURE(DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID,
1311 SESSION_ID, isSuccess));
1312 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
1313 }
1314
1315 /**
1316 * @tc.name: ConnectRemoteAbility001
1317 * @tc.desc: connect remote ability with right uid and pid
1318 * @tc.type: FUNC
1319 * @tc.require: I6P0I9
1320 */
1321 HWTEST_F(DistributedSchedServiceFirstTest, ConnectRemoteAbility001, TestSize.Level3)
1322 {
1323 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility001 start" << std::endl;
1324 OHOS::AAFwk::Want want;
1325 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
1326 const sptr<IRemoteObject> connect = nullptr;
1327 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillRepeatedly(Return(true));
1328 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
1329 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1330 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility001 end" << std::endl;
1331 }
1332
1333 /**
1334 * @tc.name: ConnectRemoteAbility002
1335 * @tc.desc: connect remote ability with empty deviceId.
1336 * @tc.type: FUNC
1337 * @tc.require: I6P0I9
1338 */
1339 HWTEST_F(DistributedSchedServiceFirstTest, ConnectRemoteAbility002, TestSize.Level3)
1340 {
1341 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility002 start" << std::endl;
1342 OHOS::AAFwk::Want want;
1343 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
1344 const sptr<IRemoteObject> connect = nullptr;
1345 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillRepeatedly(Return(true));
1346 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
1347 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1348 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectRemoteAbility002 end" << std::endl;
1349 }
1350
1351 /**
1352 * @tc.name: ConnectAbilityFromRemote_001
1353 * @tc.desc: test ConnectAbilityFromRemote
1354 * @tc.type: FUNC
1355 * @tc.require: issueI5T6GJ
1356 */
1357 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_001, TestSize.Level3)
1358 {
1359 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_001 start" << std::endl;
1360 AAFwk::Want want;
1361 AppExecFwk::AbilityInfo abilityInfo;
1362 sptr<IRemoteObject> connect = nullptr;
1363 CallerInfo callerInfo;
1364 IDistributedSched::AccountInfo accountInfo;
1365 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1366 abilityInfo, connect, callerInfo, accountInfo);
1367 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1368 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_001 end" << std::endl;
1369 }
1370
1371 /**
1372 * @tc.name: ConnectAbilityFromRemote_002
1373 * @tc.desc: input invalid params
1374 * @tc.type: FUNC
1375 * @tc.require: issueI5T6GJ
1376 */
1377 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_002, TestSize.Level3)
1378 {
1379 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_002 start" << std::endl;
1380 AAFwk::Want want;
1381 AppExecFwk::AbilityInfo abilityInfo;
1382 sptr<IRemoteObject> connect(new MockDistributedSched());
1383 CallerInfo callerInfo;
1384 IDistributedSched::AccountInfo accountInfo;
1385 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1386 abilityInfo, connect, callerInfo, accountInfo);
1387 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1388 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_002 end" << std::endl;
1389 }
1390
1391 /**
1392 * @tc.name: ConnectAbilityFromRemote_003
1393 * @tc.desc: input invalid params
1394 * @tc.type: FUNC
1395 * @tc.require: issueI5T6GJ
1396 */
1397 HWTEST_F(DistributedSchedServiceFirstTest, ConnectAbilityFromRemote_003, TestSize.Level3)
1398 {
1399 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_003 start" << std::endl;
1400 AAFwk::Want want;
1401 AppExecFwk::AbilityInfo abilityInfo;
1402 sptr<IRemoteObject> connect(new MockDistributedSched());
1403 CallerInfo callerInfo;
1404 IDistributedSched::AccountInfo accountInfo;
1405 callerInfo.callerType = CALLER_TYPE_HARMONY;
1406 int32_t ret = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
1407 abilityInfo, connect, callerInfo, accountInfo);
1408 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1409 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectAbilityFromRemote_003 end" << std::endl;
1410 }
1411
1412 /**
1413 * @tc.name: NotifyProcessDiedFromRemote_001
1414 * @tc.desc: call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
1415 * @tc.type: FUNC
1416 * @tc.require: I76THI
1417 */
1418 HWTEST_F(DistributedSchedServiceFirstTest, NotifyProcessDiedFromRemote_001, TestSize.Level3)
1419 {
1420 DTEST_LOG << "DistributedSchedServiceFirstTest NotifyProcessDiedFromRemote_001 start" << std::endl;
1421
1422 sptr<IDistributedSched> proxy = GetDms();
1423
1424 AAFwk::Want want;
1425 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1426 "com.ohos.distributedmusicplayer.MainAbility");
1427 want.SetElement(element);
1428 AppExecFwk::AbilityInfo abilityInfo;
1429 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
1430 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
1431 CallerInfo callerInfo1;
1432 callerInfo1.uid = 0;
1433 callerInfo1.sourceDeviceId = "255.255.255.255";
1434 IDistributedSched::AccountInfo accountInfo;
1435 accountInfo.accountType = 1;
1436 accountInfo.groupIdList.push_back("123456");
1437
1438 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1439 abilityInfo, 0, callerInfo1, accountInfo);
1440 DTEST_LOG << "result1:" << result1 << std::endl;
1441
1442 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
1443 "com.ohos.distributedmusicplayer.MainAbilityService");
1444 want.SetElement(element2);
1445 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
1446 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
1447 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1448 abilityInfo, 0, callerInfo1, accountInfo);
1449
1450 /**
1451 * @tc.steps: step1. call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
1452 */
1453 sptr<IRemoteObject> connect(new MockDistributedSched());
1454 ConnectInfo connectInfo;
1455 connectInfo.callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1456 connectInfo.callerInfo.uid = 0;
1457 connectInfo.callerInfo.pid = 0;
1458 connectInfo.callerInfo.callerType = 0;
1459 {
1460 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
1461 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1462 }
1463 CallerInfo callerInfo;
1464 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1465 callerInfo.uid = 0;
1466 callerInfo.pid = 0;
1467 callerInfo.callerType = 0;
1468 int32_t result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
1469 EXPECT_EQ(result, ERR_OK);
1470 /**
1471 * @tc.steps: step2. call NotifyProcessDiedFromRemote when sourceDeviceId != sourceDeviceId.
1472 */
1473 callerInfo.sourceDeviceId = REMOTE_DEVICEID;
1474 result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
1475 EXPECT_EQ(result, ERR_OK);
1476
1477 /**
1478 * @tc.steps: step3. call ProcessFreeInstallOffline when dmsCallbackTask_ is not empty.
1479 */
1480 DistributedSchedService::GetInstance().dmsCallbackTask_ = make_shared<DmsCallbackTask>();
1481 DistributedSchedService::GetInstance().ProcessCalleeOffline("deviceId");
1482 DTEST_LOG << "DistributedSchedServiceFirstTest NotifyProcessDiedFromRemote_001 end" << std::endl;
1483 }
1484
1485 /**
1486 * @tc.name: StartAbilityByCallFromRemote_001
1487 * @tc.desc: input invalid params
1488 * @tc.type: FUNC
1489 * @tc.require: issueI5T6GJ
1490 */
1491 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_001, TestSize.Level3)
1492 {
1493 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_001 start" << std::endl;
1494 AAFwk::Want want;
1495 std::string localDeviceId;
1496 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1497 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1498 "bmsThirdBundle");
1499 want.SetElement(element);
1500 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1501 sptr<IRemoteObject> connect(new MockDistributedSched());
1502 CallerInfo callerInfo;
1503 callerInfo.uid = 0;
1504 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1505 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example",
1506 callerInfo.callerAppId);
1507 EXPECT_EQ(result, true);
1508 IDistributedSched::AccountInfo accountInfo;
1509 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1510 auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
1511 int ret = mockDms->StartAbilityByCallFromRemote(want, connect, callerInfo, accountInfo);
1512 EXPECT_EQ(ret, ERR_OK);
1513 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_001 end" << std::endl;
1514 }
1515
1516 /**
1517 * @tc.name: StartAbilityByCallFromRemote_002
1518 * @tc.desc: input invalid params
1519 * @tc.type: FUNC
1520 * @tc.require: issueI5T6GJ
1521 */
1522 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_002, TestSize.Level3)
1523 {
1524 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_002 start" << std::endl;
1525 AAFwk::Want want;
1526 std::string localDeviceId;
1527 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1528 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1529 "bmsThirdBundle");
1530 want.SetElement(element);
1531 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1532 sptr<IRemoteObject> connect = new MockDistributedSched();
1533 CallerInfo callerInfo;
1534 callerInfo.uid = 0;
1535 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1536 IDistributedSched::AccountInfo accountInfo;
1537 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1538 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1539 callerInfo, accountInfo);
1540 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1541 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_002 end" << std::endl;
1542 }
1543
1544 /**
1545 * @tc.name: StartAbilityByCallFromRemote_003
1546 * @tc.desc: call StartAbilityByCallFromRemote
1547 * @tc.type: FUNC
1548 * @tc.require: I6YLV1
1549 */
1550 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_003, TestSize.Level3)
1551 {
1552 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_003 start" << std::endl;
1553 AAFwk::Want want;
1554 std::string localDeviceId;
1555 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1556 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1557 "bmsThirdBundle");
1558 want.SetElement(element);
1559 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1560 CallerInfo callerInfo;
1561 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1562 EXPECT_EQ(result, true);
1563 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1564 sptr<IRemoteObject> connect(new MockDistributedSched());
1565 callerInfo.uid = 0;
1566 callerInfo.sourceDeviceId = localDeviceId;
1567 IDistributedSched::AccountInfo accountInfo;
1568 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1569 sptr<IRemoteObject> callbackWrapper(new AbilityConnectionWrapperStub(connect, localDeviceId));
1570 ConnectInfo connectInfo {callerInfo, callbackWrapper, want.GetElement()};
1571 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1572 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1573 callerInfo, accountInfo);
1574 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1575 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_003 end" << std::endl;
1576 }
1577
1578 /**
1579 * @tc.name: StartAbilityByCallFromRemote_004
1580 * @tc.desc: call StartAbilityByCallFromRemote
1581 * @tc.type: FUNC
1582 * @tc.require: I6YLV1
1583 */
1584 HWTEST_F(DistributedSchedServiceFirstTest, StartAbilityByCallFromRemote_004, TestSize.Level3)
1585 {
1586 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_004 start" << std::endl;
1587 AAFwk::Want want;
1588 std::string localDeviceId;
1589 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1590 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1591 "bmsThirdBundle");
1592 want.SetElement(element);
1593 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1594 CallerInfo callerInfo;
1595 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1596 EXPECT_EQ(result, true);
1597 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1598 sptr<IRemoteObject> connect(new MockDistributedSched());
1599 callerInfo.uid = 0;
1600 callerInfo.sourceDeviceId = localDeviceId;
1601 IDistributedSched::AccountInfo accountInfo;
1602 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1603 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1604 callerInfo, accountInfo);
1605 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1606 DTEST_LOG << "DistributedSchedServiceFirstTest StartAbilityByCallFromRemote_004 end" << std::endl;
1607 }
1608
1609 /**
1610 * @tc.name: StartRemoteAbilityByCall_001
1611 * @tc.desc: call StartRemoteAbilityByCall
1612 * @tc.type: FUNC
1613 * @tc.require: I76THI
1614 */
1615 HWTEST_F(DistributedSchedServiceFirstTest, StartRemoteAbilityByCall_001, TestSize.Level3)
1616 {
1617 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbilityByCall_001 start" << std::endl;
1618 AAFwk::Want want;
1619 int32_t callerUid = 0;
1620 int32_t callerPid = 0;
1621 uint32_t accessToken = 0;
1622 AppExecFwk::ElementName element("remoteDeviceId", "com.ohos.distributedmusicplayer",
1623 "com.ohos.distributedmusicplayer.MainAbility");
1624 want.SetElement(element);
1625 sptr<IRemoteObject> connect(new MockDistributedSched());
1626 EXPECT_CALL(*multiUserMgrMock_, IsCallerForeground(_)).WillRepeatedly(Return(true));
1627 int32_t result = DistributedSchedService::GetInstance().StartRemoteAbilityByCall(want,
1628 connect, callerUid, callerPid, accessToken);
1629 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1630 DTEST_LOG << "DistributedSchedServiceFirstTest StartRemoteAbilityByCall_001 end" << std::endl;
1631 }
1632
1633 /**
1634 * @tc.name: ReleaseAbilityFromRemote_001
1635 * @tc.desc: call ReleaseAbilityFromRemote
1636 * @tc.type: FUNC
1637 * @tc.require: I76THI
1638 */
1639 HWTEST_F(DistributedSchedServiceFirstTest, ReleaseAbilityFromRemote_001, TestSize.Level3)
1640 {
1641 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_001 start" << std::endl;
1642 sptr<IRemoteObject> connect(new MockDistributedSched());
1643 AAFwk::Want want;
1644 AppExecFwk::ElementName element;
1645 CallerInfo callerInfo;
1646 /**
1647 * @tc.steps: step1. call ReleaseAbilityFromRemote when callerInfo.sourceDeviceId is empty.
1648 * @tc.expected: step1. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1649 */
1650 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1651 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1652 /**
1653 * @tc.steps: step2. call ReleaseAbilityFromRemote when localDeviceId == callerInfo.sourceDeviceId.
1654 * @tc.expected: step2. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1655 */
1656 std::string localDeviceId;
1657 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1658 callerInfo.sourceDeviceId = localDeviceId;
1659 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1660 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1661 /**
1662 * @tc.steps: step3. call ReleaseAbilityFromRemote when itConnect == calleeMap_.end().
1663 * @tc.expected: step3. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
1664 */
1665 {
1666 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1667 DistributedSchedService::GetInstance().calleeMap_.clear();
1668 }
1669 callerInfo.sourceDeviceId = "sourceDeviceId";
1670 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1671 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
1672 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_001 end" << std::endl;
1673 }
1674
1675 /**
1676 * @tc.name: ReleaseAbilityFromRemote_002
1677 * @tc.desc: call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
1678 * @tc.type: FUNC
1679 * @tc.require: I76THI
1680 */
1681 HWTEST_F(DistributedSchedServiceFirstTest, ReleaseAbilityFromRemote_002, TestSize.Level3)
1682 {
1683 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_002 start" << std::endl;
1684 /**
1685 * @tc.steps: step1. call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
1686 */
1687 sptr<IRemoteObject> connect(new MockDistributedSched());
1688 AAFwk::Want want;
1689 AppExecFwk::ElementName element;
1690 CallerInfo callerInfo;
1691 callerInfo.sourceDeviceId = "sourceDeviceId";
1692 ConnectInfo connectInfo;
1693 {
1694 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
1695 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1696 }
1697 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
1698 EXPECT_NE(result, ERR_OK);
1699 /**
1700 * @tc.steps: step2. call ProcessConnectDied when connectSessionsList is empty.
1701 */
1702 std::list<ConnectAbilitySession> sessionsList;
1703 {
1704 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
1705 DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
1706 }
1707 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
1708 /**
1709 * @tc.steps: step3. call ProcessConnectDied when sessionsList is empty.
1710 */
1711 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
1712 DTEST_LOG << "DistributedSchedServiceFirstTest ReleaseAbilityFromRemote_002 end" << std::endl;
1713 }
1714
1715 /**
1716 * @tc.name : ConnectDExtensionFromRemote_Test01
1717 * @tc.number: ConnectDExtensionFromRemote_001
1718 * @tc.desc : Test ConnectDExtensionFromRemote function when check permission failed.
1719 */
1720 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtensionFromRemote_Test01, TestSize.Level1)
1721 {
1722 DExtSourceInfo sourceInfo("device123", "network123", "testBundle", "testModule", "testAbility");
1723 DExtSinkInfo sinkInfo(1001, 1234, "testBundle", "testModule", "testAbility", "testService");
1724 DExtConnectInfo connectInfo(sourceInfo, sinkInfo, "validToken", "delegatee");
1725 DExtConnectResultInfo resultInfo;
1726
1727 int32_t result = DistributedSchedService::GetInstance().ConnectDExtensionFromRemote(connectInfo, resultInfo);
1728 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
1729 EXPECT_EQ(resultInfo.result, DExtConnectResult::PERMISSION_DENIED);
1730
1731 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtensionFromRemote_Test01 end" << std::endl;
1732 }
1733
1734 /**
1735 * @tc.name : ConnectDExtensionFromRemote_Test02
1736 * @tc.number: ConnectDExtensionFromRemote_002
1737 * @tc.desc : Test ConnectDExtensionFromRemote function when parameter is nullptr.
1738 */
1739 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtensionFromRemote_Test02, TestSize.Level1)
1740 {
1741 DExtSourceInfo sourceInfo("", "", "", "", "");
1742 DExtSinkInfo sinkInfo(0, 0, "", "", "", "");
1743 DExtConnectInfo connectInfo(sourceInfo, sinkInfo, "validToken", "delegatee");
1744 DExtConnectResultInfo resultInfo;
1745
1746 int32_t result = DistributedSchedService::GetInstance().ConnectDExtensionFromRemote(connectInfo, resultInfo);
1747 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1748 EXPECT_EQ(resultInfo.result, DExtConnectResult::FAILED);
1749
1750 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtensionFromRemote_Test02 end" << std::endl;
1751 }
1752
1753 /**
1754 * @tc.name : ConnectDExtensionFromRemote_Test03
1755 * @tc.number: ConnectDExtensionFromRemote_003
1756 * @tc.desc : Test ConnectDExtensionFromRemote function when user is not foreground.
1757 */
1758 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtensionFromRemote_Test03, TestSize.Level1)
1759 {
1760 SetNativeToken();
1761 DExtSourceInfo sourceInfo("device123", "network123", "testBundle", "testModule", "testAbility");
1762 DExtSinkInfo sinkInfo(-1, 1234, "testBundle", "testModule", "testAbility", "testService");
1763 DExtConnectInfo connectInfo(sourceInfo, sinkInfo, "validToken", "delegatee");
1764 DExtConnectResultInfo resultInfo;
1765
1766 int32_t result = DistributedSchedService::GetInstance().ConnectDExtensionFromRemote(connectInfo, resultInfo);
1767 EXPECT_EQ(result, DMS_NOT_FOREGROUND_USER);
1768 EXPECT_EQ(resultInfo.result, DExtConnectResult::FAILED);
1769
1770 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtensionFromRemote_Test03 end" << std::endl;
1771 }
1772
1773 /**
1774 * @tc.name : ConnectDExtensionFromRemote_Test04
1775 * @tc.number: ConnectDExtensionFromRemote_004
1776 * @tc.desc : Test ConnectDExtensionFromRemote function when ConnectDExtAbility failed.
1777 */
1778 HWTEST_F(DistributedSchedServiceFirstTest, ConnectDExtensionFromRemote_Test04, TestSize.Level1)
1779 {
1780 SetNativeToken();
1781 DExtSourceInfo sourceInfo("device123", "network123", "testBundle", "testModule", "testAbility");
1782 DExtSinkInfo sinkInfo(100, 0, "com.it.welink", "dms", "AttendanceDistributedAbility", "WeLink");
1783 DExtConnectInfo connectInfo(sourceInfo, sinkInfo, "ohos.permission.dms_extension", "delegatee");
1784 DExtConnectResultInfo resultInfo;
1785
1786 EXPECT_CALL(*svcDConnMock, ConnectDExtAbility(_, _, _, _, _)).WillOnce(Return(INVALID_PARAMETERS_ERR));
1787 int32_t result = DistributedSchedService::GetInstance().ConnectDExtensionFromRemote(connectInfo, resultInfo);
1788 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1789 EXPECT_EQ(resultInfo.result, DExtConnectResult::FAILED);
1790
1791 DTEST_LOG << "DistributedSchedServiceFirstTest ConnectDExtensionFromRemote_Test04 end" << std::endl;
1792 }
1793
1794 /**
1795 * @tc.name : OnIdleTest_001
1796 * @tc.number: OnIdleTest_001
1797 * @tc.desc : Test OnIdle
1798 */
1799 HWTEST_F(DistributedSchedServiceFirstTest, OnIdleTest_001, TestSize.Level1)
1800 {
1801 SystemAbilityOnDemandReason idleReason;
1802 std::vector<DmDeviceInfo> deviceList;
1803 //true
1804 EXPECT_CALL(*deviceMgrMock_, GetTrustedDeviceList(_, _, _)).WillOnce(DoAll(SetArgReferee<2>(deviceList),
1805 Return(0)));
1806 int32_t ret = DistributedSchedService::GetInstance().OnIdle(idleReason);
1807 EXPECT_EQ(ret, 0);
1808
1809 //false
1810 EXPECT_CALL(*deviceMgrMock_, GetTrustedDeviceList(_, _, _)).WillOnce(DoAll(SetArgReferee<2>(deviceList),
1811 Return(1)));
1812 ret = DistributedSchedService::GetInstance().OnIdle(idleReason);
1813 EXPECT_EQ(ret, -1);
1814 }
1815 }
1816 }