1 /*
2 * Copyright (c) 2021-2023 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 "bundle/bundle_manager_internal.h"
23 #include "device_manager.h"
24 #include "distributed_sched_permission.h"
25 #include "distributed_sched_proxy.h"
26 #include "distributed_sched_service.h"
27 #include "distributed_sched_util.h"
28 #include "dtbschedmgr_device_info_storage.h"
29 #include "dtbschedmgr_log.h"
30 #include "form_mgr_errors.h"
31 #include "if_system_ability_manager.h"
32 #include "ipc_skeleton.h"
33 #include "iservice_registry.h"
34 #include "mock_form_mgr_service.h"
35 #include "mock_distributed_sched.h"
36 #include "system_ability_definition.h"
37 #include "test_log.h"
38 #include "thread_pool.h"
39 #undef private
40 #undef protected
41
42 using namespace std;
43 using namespace testing;
44 using namespace testing::ext;
45 using namespace OHOS;
46
47 namespace OHOS {
48 namespace DistributedSchedule {
49 using namespace AAFwk;
50 using namespace AppExecFwk;
51 using namespace DistributedHardware;
52 namespace {
53 const string LOCAL_DEVICEID = "192.168.43.100";
54 const string REMOTE_DEVICEID = "255.255.255.255";
55 const std::u16string DEVICE_ID = u"192.168.43.100";
56 const std::u16string DEVICE_ID_NULL = u"";
57 constexpr int32_t SESSION_ID = 123;
58 const std::string DMS_MISSION_ID = "dmsMissionId";
59 const std::string DMS_CONNECT_TOKEN = "connectToken";
60 constexpr int32_t MISSION_ID = 1;
61 const std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId";
62 const int DEFAULT_REQUEST_CODE = -1;
63 const string ABILITY_NAME = "com.ohos.launcher.MainAbility";
64 const string BUNDLE_NAME = "com.ohos.launcher";
65 const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
66 const string DMS_VERSION_ID = "dmsVersion";
67 const string DMS_VERSION = "4.0.0";
68 constexpr int32_t FOREGROUND = 2;
69 constexpr int32_t MAX_TOKEN_NUM = 100000000;
70 constexpr int32_t SLEEP_TIME = 1000;
71 }
72
73 class DistributedSchedServiceTest : public testing::Test {
74 public:
75 static void SetUpTestCase();
76 static void TearDownTestCase();
77 void SetUp();
78 void TearDown();
79 sptr<IDistributedSched> GetDms();
80 int32_t InstallBundle(const std::string &bundlePath) const;
81 sptr<IDistributedSched> proxy_;
82
83 protected:
84 enum class LoopTime : int32_t {
85 LOOP_TIME = 10,
86 LOOP_PRESSURE_TIME = 100,
87 };
88 sptr<IRemoteObject> GetDSchedService() const;
89 void GetAbilityInfo(const std::string& package, const std::string& name,
90 const std::string& bundleName, const std::string& deviceId,
91 OHOS::AppExecFwk::AbilityInfo& abilityInfo);
92
93 class DeviceInitCallBack : public DmInitCallback {
94 void OnRemoteDied() override;
95 };
96 };
97
SetUpTestCase()98 void DistributedSchedServiceTest::SetUpTestCase()
99 {
100 if (!DistributedSchedUtil::LoadDistributedSchedService()) {
101 DTEST_LOG << "DistributedSchedServiceTest::SetUpTestCase LoadDistributedSchedService failed" << std::endl;
102 }
103 const std::string pkgName = "DBinderBus_" + std::to_string(getpid());
104 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
105 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
106 DistributedSchedUtil::InstallThirdPartyHap();
107 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
108 }
109
TearDownTestCase()110 void DistributedSchedServiceTest::TearDownTestCase()
111 {}
112
SetUp()113 void DistributedSchedServiceTest::SetUp()
114 {
115 DistributedSchedUtil::MockPermission();
116 }
117
TearDown()118 void DistributedSchedServiceTest::TearDown()
119 {}
120
OnRemoteDied()121 void DistributedSchedServiceTest::DeviceInitCallBack::OnRemoteDied()
122 {}
123
GetDms()124 sptr<IDistributedSched> DistributedSchedServiceTest::GetDms()
125 {
126 if (proxy_ != nullptr) {
127 return proxy_;
128 }
129 auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
130 EXPECT_TRUE(sm != nullptr);
131 if (sm == nullptr) {
132 DTEST_LOG << "DistributedSchedServiceTest sm is nullptr" << std::endl;
133 return nullptr;
134 }
135 DTEST_LOG << "DistributedSchedServiceTest sm is not nullptr" << std::endl;
136 auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
137 proxy_ = iface_cast<IDistributedSched>(distributedObject);
138 if (proxy_ == nullptr) {
139 DTEST_LOG << "DistributedSchedServiceTest DistributedSched is nullptr" << std::endl;
140 } else {
141 DTEST_LOG << "DistributedSchedServiceTest DistributedSched is not nullptr" << std::endl;
142 }
143 return proxy_;
144 }
145
GetDSchedService() const146 sptr<IRemoteObject> DistributedSchedServiceTest::GetDSchedService() const
147 {
148 sptr<IRemoteObject> dsched = new MockDistributedSched();
149 return dsched;
150 }
151
GetAbilityInfo(const std::string & package,const std::string & name,const std::string & bundleName,const std::string & deviceId,OHOS::AppExecFwk::AbilityInfo & abilityInfo)152 void DistributedSchedServiceTest::GetAbilityInfo(const std::string& package, const std::string& name,
153 const std::string& bundleName, const std::string& deviceId, OHOS::AppExecFwk::AbilityInfo& abilityInfo)
154 {
155 abilityInfo.bundleName = bundleName;
156 abilityInfo.deviceId = deviceId;
157 }
158
159 /**
160 * @tc.name: StartRemoteAbility_001
161 * @tc.desc: call StartRemoteAbility with illegal params
162 * @tc.type: FUNC
163 */
164 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_001, TestSize.Level1)
165 {
166 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_001 start" << std::endl;
167 sptr<IDistributedSched> proxy = GetDms();
168 if (proxy == nullptr) {
169 return;
170 }
171 /**
172 * @tc.steps: step1. StartRemoteAbility with uninitialized params
173 * @tc.expected: step1. StartRemoteAbility return INVALID_PARAMETERS_ERR
174 */
175 AAFwk::Want want;
176 int result1 = proxy->StartRemoteAbility(want, 0, 0, 0);
177 DTEST_LOG << "result1:" << result1 << std::endl;
178 /**
179 * @tc.steps: step2. StartRemoteAbility with empty want's deviceId
180 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
181 */
182 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
183 "com.ohos.distributedmusicplayer.MainAbility");
184 want.SetElement(element);
185 int result2 = proxy->StartRemoteAbility(want, 0, 0, 0);
186 DTEST_LOG << "result2:" << result2 << std::endl;
187
188 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result1);
189 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result2);
190 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_001 end" << std::endl;
191 }
192
193 /**
194 * @tc.name: StartRemoteAbility_002
195 * @tc.desc: call StartRemoteAbility with dms with wrong deviceId and local deviceId
196 * @tc.type: FUNC
197 */
198 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_002, TestSize.Level0)
199 {
200 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_002 start" << std::endl;
201 sptr<IDistributedSched> proxy = GetDms();
202 if (proxy == nullptr) {
203 return;
204 }
205 /**
206 * @tc.steps: step1. set want with wrong deviceId
207 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
208 */
209 AAFwk::Want want;
210 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
211 "com.ohos.distributedmusicplayer.MainAbility");
212 want.SetElement(element);
213 int result1 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
214 DTEST_LOG << "result:" << result1 << std::endl;
215 std::string deviceId;
216 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
217 AppExecFwk::ElementName element1(deviceId, "com.ohos.distributedmusicplayer",
218 "com.ohos.distributedmusicplayer.MainAbility");
219 want.SetElement(element1);
220 int result2 = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
221 DTEST_LOG << "result:" << result2 << std::endl;
222 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
223 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
224 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_002 end" << std::endl;
225 }
226
227 /**
228 * @tc.name: StartRemoteAbility_003
229 * @tc.desc: call StartRemoteAbility with dms
230 * @tc.type: FUNC
231 */
232 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_003, TestSize.Level0)
233 {
234 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_003 start" << std::endl;
235 /**
236 * @tc.steps: step1. set want with wrong deviceId
237 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
238 */
239 AAFwk::Want want;
240 AppExecFwk::ElementName element("123456", "com.ohos.distributedmusicplayer",
241 "com.ohos.distributedmusicplayer.MainAbility");
242 want.SetElement(element);
243 int result = DistributedSchedService::GetInstance().StartRemoteAbility(want, 0, 0, 0);
244 DTEST_LOG << "result:" << result << std::endl;
245 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
246 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_003 end" << std::endl;
247 }
248
249 /**
250 * @tc.name: StartRemoteAbility_004
251 * @tc.desc: call StartRemoteAbility
252 * @tc.type: FUNC
253 */
254 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility_004, TestSize.Level1)
255 {
256 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_004 start" << std::endl;
257 sptr<IDistributedSched> proxy = GetDms();
258 if (proxy == nullptr) {
259 return;
260 }
261 /**
262 * @tc.steps: step1. set want and abilityInfo
263 * @tc.expected: step2. StartRemoteAbility return INVALID_PARAMETERS_ERR
264 */
265 AAFwk::Want want;
266 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
267 "com.ohos.distributedmusicplayer.MainAbility");
268 want.SetElement(element);
269 int result = proxy->StartRemoteAbility(want, 0, 0, 0);
270 DTEST_LOG << "result:" << result << std::endl;
271 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
272 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility_004 end" << std::endl;
273 }
274
275 /**
276 * @tc.name: StartAbilityFromRemote_001
277 * @tc.desc: call StartAbilityFromRemote with illegal param
278 * @tc.type: FUNC
279 */
280 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_001, TestSize.Level0)
281 {
282 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_001 start" << std::endl;
283 sptr<IDistributedSched> proxy = GetDms();
284 if (proxy == nullptr) {
285 return;
286 }
287 AAFwk::Want want;
288 AppExecFwk::AbilityInfo abilityInfo;
289 CallerInfo callerInfo;
290 callerInfo.uid = 0;
291 callerInfo.sourceDeviceId = "255.255.255.255";
292 IDistributedSched::AccountInfo accountInfo;
293 /**
294 * @tc.steps: step1. StartAbilityFromRemote with uninitialized params
295 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
296 */
297 int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
298 DTEST_LOG << "result1:" << result1 << std::endl;
299 /**
300 * @tc.steps: step1. StartAbilityFromRemote with with empty deviceId
301 * @tc.expected: step1. StartAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
302 */
303 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
304 "com.ohos.distributedmusicplayer.MainAbility");
305 want.SetElement(element);
306 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
307 "com.ohos.distributedmusicplayer", "192.168.43.101", abilityInfo);
308 int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
309 DTEST_LOG << "result2:" << result2 << std::endl;
310 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
311 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
312 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_001 end" << std::endl;
313 }
314
315 /**
316 * @tc.name: StartAbilityFromRemote_002
317 * @tc.desc: call StartAbilityFromRemote
318 * @tc.type: FUNC
319 */
320 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_002, TestSize.Level1)
321 {
322 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 start" << std::endl;
323 sptr<IDistributedSched> proxy = GetDms();
324 if (proxy == nullptr) {
325 return;
326 }
327
328 AAFwk::Want want;
329 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
330 "com.ohos.distributedmusicplayer.MainAbility");
331 want.SetElement(element);
332 AppExecFwk::AbilityInfo abilityInfo;
333 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
334 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
335 CallerInfo callerInfo;
336 callerInfo.uid = 0;
337 callerInfo.sourceDeviceId = "255.255.255.255";
338 IDistributedSched::AccountInfo accountInfo;
339
340 int result1 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
341 DTEST_LOG << "result1 is" << result1 << std::endl;
342
343 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
344 "com.ohos.distributedmusicplayer.MainAbilityService");
345 want.SetElement(element2);
346 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
347 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
348 int result2 = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
349 DTEST_LOG << "result2:" << result2 << std::endl;
350 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 end" << std::endl;
351 }
352
353 /**
354 * @tc.name: StartAbilityFromRemote_003
355 * @tc.desc: call StartAbilityFromRemote for pressure test
356 * @tc.type: FUNC
357 */
358 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_003, TestSize.Level1)
359 {
360 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_003 start" << std::endl;
361 sptr<IDistributedSched> proxy = GetDms();
362 if (proxy == nullptr) {
363 return;
364 }
365 /**
366 * @tc.steps: step1. set want and abilityInfo
367 */
368 AAFwk::Want want;
369 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
370 "com.ohos.distributedmusicplayer.MainAbility");
371 want.SetElement(element);
372 AppExecFwk::AbilityInfo abilityInfo;
373 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
374 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
375 CallerInfo callerInfo;
376 callerInfo.uid = 0;
377 callerInfo.sourceDeviceId = "255.255.255.255";
378 IDistributedSched::AccountInfo accountInfo;
379 /**
380 * @tc.steps: step2. StartAbilityFromRemote for pressure test
381 * @tc.expected: step2. StartAbilityFromRemote for result
382 */
383 for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
384 int result = proxy->StartAbilityFromRemote(want, abilityInfo, 0, callerInfo, accountInfo);
385 DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
386 }
387 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_003 end" << std::endl;
388 }
389
390 /**
391 * @tc.name: StartAbilityFromRemote_004
392 * @tc.desc: call StartAbilityFromRemote with dms
393 * @tc.type: FUNC
394 */
395 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_004, TestSize.Level0)
396 {
397 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_004 start" << std::endl;
398 sptr<IDistributedSched> proxy = GetDms();
399
400 AAFwk::Want want;
401 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
402 "com.ohos.distributedmusicplayer.MainAbility");
403 want.SetElement(element);
404 AppExecFwk::AbilityInfo abilityInfo;
405 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
406 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
407 CallerInfo callerInfo;
408 callerInfo.uid = 0;
409 callerInfo.sourceDeviceId = "255.255.255.255";
410 IDistributedSched::AccountInfo accountInfo;
411
412 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
413 abilityInfo, 0, callerInfo, accountInfo);
414 DTEST_LOG << "result1:" << result1 << std::endl;
415
416 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
417 "com.ohos.distributedmusicplayer.MainAbilityService");
418 want.SetElement(element2);
419 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
420 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
421 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
422 abilityInfo, 0, callerInfo, accountInfo);
423 DTEST_LOG << "result2:" << result2 << std::endl;
424 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
425 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
426 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_004 end" << std::endl;
427 }
428
429 /**
430 * @tc.name: StartAbilityFromRemote_005
431 * @tc.desc: call StartAbilityFromRemote with dms
432 * @tc.type: FUNC
433 */
434 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_005, TestSize.Level1)
435 {
436 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_005 start" << std::endl;
437 sptr<IDistributedSched> proxy = GetDms();
438
439 AAFwk::Want want;
440 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
441 "com.ohos.distributedmusicplayer.MainAbility");
442 want.SetElement(element);
443 AppExecFwk::AbilityInfo abilityInfo;
444 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
445 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
446 CallerInfo callerInfo;
447 callerInfo.uid = 0;
448 callerInfo.sourceDeviceId = "255.255.255.255";
449 IDistributedSched::AccountInfo accountInfo;
450 accountInfo.accountType = 1;
451 accountInfo.groupIdList.push_back("123456");
452
453 int result1 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
454 abilityInfo, 0, callerInfo, accountInfo);
455 DTEST_LOG << "result1:" << result1 << std::endl;
456
457 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
458 "com.ohos.distributedmusicplayer.MainAbilityService");
459 want.SetElement(element2);
460 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbilityService",
461 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
462 int result2 = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
463 abilityInfo, 0, callerInfo, accountInfo);
464 DTEST_LOG << "result2:" << result2 << std::endl;
465 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_005 end" << std::endl;
466 }
467
468 /**
469 * @tc.name: SendResultFromRemote_001
470 * @tc.desc: call SendResultFromRemote with illegal param
471 * @tc.type: FUNC
472 */
473 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_001, TestSize.Level1)
474 {
475 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_001 start" << std::endl;
476 sptr<IDistributedSched> proxy = GetDms();
477 if (proxy == nullptr) {
478 return;
479 }
480 AAFwk::Want want;
481 CallerInfo callerInfo;
482 callerInfo.uid = 0;
483 callerInfo.sourceDeviceId = "255.255.255.255";
484 IDistributedSched::AccountInfo accountInfo;
485 /**
486 * @tc.steps: step1. SendResultFromRemote with uninitialized params
487 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
488 */
489 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
490 DTEST_LOG << "result1:" << result1 << std::endl;
491 /**
492 * @tc.steps: step1. SendResultFromRemote with with empty deviceId
493 * @tc.expected: step1. SendResultFromRemote return INVALID_REMOTE_PARAMETERS_ERR
494 */
495 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
496 "com.ohos.distributedmusicplayer.MainAbility");
497 want.SetElement(element);
498 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
499 DTEST_LOG << "result2:" << result2 << std::endl;
500 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result1);
501 EXPECT_EQ(static_cast<int>(IPC_STUB_UNKNOW_TRANS_ERR), result2);
502 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote end" << std::endl;
503 }
504
505 /**
506 * @tc.name: StartAbilityFromRemote_002
507 * @tc.desc: call SendResultFromRemote
508 * @tc.type: FUNC
509 */
510 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_002, TestSize.Level1)
511 {
512 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_002 start" << std::endl;
513 sptr<IDistributedSched> proxy = GetDms();
514 if (proxy == nullptr) {
515 return;
516 }
517
518 AAFwk::Want want;
519 AppExecFwk::ElementName element("255.255.255.255", "com.ohos.distributedmusicplayer",
520 "com.ohos.distributedmusicplayer.MainAbility");
521 want.SetElement(element);
522 AppExecFwk::AbilityInfo abilityInfo;
523 CallerInfo callerInfo;
524 callerInfo.uid = 0;
525 callerInfo.sourceDeviceId = "255.255.255.255";
526 IDistributedSched::AccountInfo accountInfo;
527
528 int result1 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
529 DTEST_LOG << "result1 is" << result1 << std::endl;
530 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
531 "com.ohos.distributedmusicplayer.MainAbilityService");
532 want.SetElement(element2);
533 int missionId = 0;
534 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
535 want.SetParam(DMS_MISSION_ID, missionId);
536 int result2 = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
537 DTEST_LOG << "result2:" << result2 << std::endl;
538 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_002 end" << std::endl;
539 }
540
541 /**
542 * @tc.name: SendResultFromRemote_003
543 * @tc.desc: call SendResultFromRemote for pressure test
544 * @tc.type: FUNC
545 */
546 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_003, TestSize.Level1)
547 {
548 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_003 start" << std::endl;
549 sptr<IDistributedSched> proxy = GetDms();
550 if (proxy == nullptr) {
551 return;
552 }
553 /**
554 * @tc.steps: step1. set want and abilityInfo
555 */
556 AAFwk::Want want;
557 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
558 "com.ohos.distributedmusicplayer.MainAbility");
559 want.SetElement(element);
560 CallerInfo callerInfo;
561 callerInfo.uid = 0;
562 callerInfo.sourceDeviceId = "255.255.255.255";
563 IDistributedSched::AccountInfo accountInfo;
564 int missionId = 0;
565 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
566 want.SetParam(DMS_MISSION_ID, missionId);
567 /**
568 * @tc.steps: step2. SendResultFromRemote for pressure test
569 * @tc.expected: step2. SendResultFromRemote for result
570 */
571 for (int index = 0; index < static_cast<int32_t>(LoopTime::LOOP_TIME); index++) {
572 int result = proxy->SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
573 DTEST_LOG << "pressure" + to_string(index) + " result is " << result << std::endl;
574 }
575 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_003 end" << std::endl;
576 }
577
578 /**
579 * @tc.name: SendResultFromRemote_004
580 * @tc.desc: call SendResultFromRemote with dms
581 * @tc.type: FUNC
582 */
583 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_004, TestSize.Level1)
584 {
585 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_004 start" << std::endl;
586 sptr<IDistributedSched> proxy = GetDms();
587
588 AAFwk::Want want;
589 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
590 "com.ohos.distributedmusicplayer.MainAbility");
591 want.SetElement(element);
592 CallerInfo callerInfo;
593 callerInfo.uid = 0;
594 callerInfo.sourceDeviceId = "255.255.255.255";
595 IDistributedSched::AccountInfo accountInfo;
596
597 int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
598 DTEST_LOG << "result1:" << result1 << std::endl;
599
600 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
601 "com.ohos.distributedmusicplayer.MainAbilityService");
602 want.SetElement(element2);
603 int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
604 DTEST_LOG << "result2:" << result2 << std::endl;
605 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result1);
606 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result2);
607 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_004 end" << std::endl;
608 }
609
610 /**
611 * @tc.name: SendResultFromRemote_005
612 * @tc.desc: call SendResultFromRemote with dms
613 * @tc.type: FUNC
614 */
615 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_005, TestSize.Level1)
616 {
617 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_005 start" << std::endl;
618 sptr<IDistributedSched> proxy = GetDms();
619
620 AAFwk::Want want;
621 AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
622 "com.ohos.distributedmusicplayer.MainAbility");
623 want.SetElement(element);
624 CallerInfo callerInfo;
625 callerInfo.uid = 0;
626 callerInfo.sourceDeviceId = "255.255.255.255";
627 IDistributedSched::AccountInfo accountInfo;
628 accountInfo.accountType = 1;
629 accountInfo.groupIdList.push_back("123456");
630 int missionId = 0;
631 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
632 want.SetParam(DMS_MISSION_ID, missionId);
633
634 int result1 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
635 DTEST_LOG << "result1:" << result1 << std::endl;
636
637 AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
638 "com.ohos.distributedmusicplayer.MainAbilityService");
639 want.SetElement(element2);
640 int result2 = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
641 DTEST_LOG << "result2:" << result2 << std::endl;
642 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_005 end" << std::endl;
643 }
644
645 /**
646 * @tc.name: StartLocalAbility_001
647 * @tc.desc: call StartLocalAbility with dms
648 * @tc.type: FUNC
649 */
650 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_001, TestSize.Level1)
651 {
652 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_001 start" << std::endl;
653 sptr<IDistributedSched> proxy = GetDms();
654
655 AAFwk::Want want;
656 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
657 "com.ohos.distributedmusicplayer.MainAbility");
658 want.SetElement(element);
659 CallerInfo callerInfo;
660 callerInfo.uid = 0;
661 callerInfo.sourceDeviceId = "255.255.255.255";
662 IDistributedSched::AccountInfo accountInfo;
663 int missionId = 0;
664 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
665 want.SetParam(DMS_MISSION_ID, missionId);
666 DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
667 .accountInfo = accountInfo};
668 int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
669 DTEST_LOG << "result1:" << result1 << std::endl;
670
671 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
672 "com.ohos.distributedmusicplayer.MainAbilityService");
673 want.SetElement(element2);
674 DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
675 .accountInfo = accountInfo};
676 int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
677 DTEST_LOG << "result2:" << result2 << std::endl;
678 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
679 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
680 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_001 end" << std::endl;
681 }
682
683 /**
684 * @tc.name: StartLocalAbility_002
685 * @tc.desc: call StartLocalAbility with dms
686 * @tc.type: FUNC
687 */
688 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_002, TestSize.Level1)
689 {
690 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_002 start" << std::endl;
691 sptr<IDistributedSched> proxy = GetDms();
692
693 AAFwk::Want want;
694 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
695 "com.ohos.distributedmusicplayer.MainAbility");
696 want.SetElement(element);
697 CallerInfo callerInfo;
698 callerInfo.uid = 0;
699 callerInfo.sourceDeviceId = "255.255.255.255";
700 IDistributedSched::AccountInfo accountInfo;
701 DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
702 .callerInfo = callerInfo, .accountInfo = accountInfo};
703 int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
704 DTEST_LOG << "result1:" << result1 << std::endl;
705
706 AppExecFwk::ElementName element2("", "com.ohos.distributedmusicplayer",
707 "com.ohos.distributedmusicplayer.MainAbilityService");
708 want.SetElement(element2);
709 DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
710 .callerInfo = callerInfo, .accountInfo = accountInfo};
711 int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
712 DTEST_LOG << "result2:" << result2 << std::endl;
713 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result1);
714 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result2);
715 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_002 end" << std::endl;
716 }
717
718 /**
719 * @tc.name: StartLocalAbility_003
720 * @tc.desc: call StartLocalAbility with dms
721 * @tc.type: FUNC
722 */
723 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_003, TestSize.Level1)
724 {
725 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_003 start" << std::endl;
726 sptr<IDistributedSched> proxy = GetDms();
727
728 AAFwk::Want want;
729 AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
730 "com.ohos.distributedmusicplayer.MainAbility");
731 want.SetElement(element);
732 CallerInfo callerInfo;
733 callerInfo.uid = 0;
734 callerInfo.sourceDeviceId = "255.255.255.255";
735 IDistributedSched::AccountInfo accountInfo;
736 accountInfo.accountType = 1;
737 accountInfo.groupIdList.push_back("123456");
738 int missionId = 0;
739 want.SetParam(DMS_SRC_NETWORK_ID, callerInfo.sourceDeviceId);
740 want.SetParam(DMS_MISSION_ID, missionId);
741 DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
742 .accountInfo = accountInfo};
743 int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
744 DTEST_LOG << "result1:" << result1 << std::endl;
745
746 AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
747 "com.ohos.distributedmusicplayer.MainAbilityService");
748 want.SetElement(element2);
749 DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = 0, .callerInfo = callerInfo,
750 .accountInfo = accountInfo};
751 int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
752 DTEST_LOG << "result2:" << result2 << std::endl;
753 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_003 end" << std::endl;
754 }
755
756 /**
757 * @tc.name: StartLocalAbility_004
758 * @tc.desc: call StartLocalAbility with dms
759 * @tc.type: FUNC
760 */
761 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_004, TestSize.Level1)
762 {
763 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_004 start" << std::endl;
764 sptr<IDistributedSched> proxy = GetDms();
765
766 AAFwk::Want want;
767 AppExecFwk::ElementName element("1.1.1.1", "com.ohos.distributedmusicplayer",
768 "com.ohos.distributedmusicplayer.MainAbility");
769 want.SetElement(element);
770 CallerInfo callerInfo;
771 callerInfo.uid = 0;
772 callerInfo.sourceDeviceId = "255.255.255.255";
773 IDistributedSched::AccountInfo accountInfo;
774 accountInfo.accountType = 1;
775 accountInfo.groupIdList.push_back("123456");
776 DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
777 .callerInfo = callerInfo, .accountInfo = accountInfo};
778 int result1 = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
779 DTEST_LOG << "result1:" << result1 << std::endl;
780
781 AppExecFwk::ElementName element2("1.1.1.1", "com.ohos.distributedmusicplayer",
782 "com.ohos.distributedmusicplayer.MainAbilityService");
783 want.SetElement(element2);
784 DistributedSchedProxy::FreeInstallInfo info2 = {.want = want, .requestCode = DEFAULT_REQUEST_CODE,
785 .callerInfo = callerInfo, .accountInfo = accountInfo};
786 int result2 = DistributedSchedService::GetInstance().StartLocalAbility(info2, 0, 0);
787 DTEST_LOG << "result2:" << result2 << std::endl;
788 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_004 end" << std::endl;
789 }
790
791 /**
792 * @tc.name: StartRemoteShareForm_001
793 * @tc.desc: call StartRemoteShareForm with dms
794 * @tc.type: StartRemoteShareForm
795 * @tc.require: issueI5M62D
796 */
797 HWTEST_F(DistributedSchedServiceTest, StartRemoteShareForm_001, TestSize.Level1)
798 {
799 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_001 start" << std::endl;
800 sptr<IDistributedSched> proxy = GetDms();
801 const std::string remoteDeviceId = "";
802 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
803 auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
804 DTEST_LOG << "result:" << result << std::endl;
805 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), result);
806 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_001 end" << std::endl;
807 }
808
809 /**
810 * @tc.name: StartRemoteShareForm_002
811 * @tc.desc: call StartAbilityFromRemote with dms
812 * @tc.type: StartRemoteShareForm
813 * @tc.require: issueI5M62D
814 */
815 HWTEST_F(DistributedSchedServiceTest, StartRemoteShareForm_002, TestSize.Level1)
816 {
817 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_002 start" << std::endl;
818 sptr<IDistributedSched> proxy = GetDms();
819 const std::string remoteDeviceId = "123456";
820 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
821 auto result = proxy->StartRemoteShareForm(remoteDeviceId, formShareInfo);
822 DTEST_LOG << "result:" << result << std::endl;
823 EXPECT_EQ(static_cast<int>(DMS_PERMISSION_DENIED), result);
824 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_002 end" << std::endl;
825 }
826
827 /**
828 * @tc.name: StartShareFormFromRemote_001
829 * @tc.desc: call StartAbilityFromRemote with dms
830 * @tc.type: StartShareFormFromRemote
831 * @tc.require: issueI5M62D
832 */
833 HWTEST_F(DistributedSchedServiceTest, StartShareFormFromRemote_001, TestSize.Level1)
834 {
835 DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_001 start" << std::endl;
836 std::string remoteDeviceId = "";
837 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(remoteDeviceId);
838 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
839 DistributedSchedService::GetInstance().formMgrProxy_ = new MockFormMgrService();
840 auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
841 DTEST_LOG << "result:" << result << std::endl;
842 EXPECT_EQ(static_cast<int>(ERR_OK), result);
843
844 DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_001 end" << std::endl;
845 }
846
847 /**
848 * @tc.name: StartShareFormFromRemote_002
849 * @tc.desc: call StartAbilityFromRemote with dms
850 * @tc.type: StartShareFormFromRemote
851 * @tc.require: issueI5M62D
852 */
853 HWTEST_F(DistributedSchedServiceTest, StartShareFormFromRemote_002, TestSize.Level1)
854 {
855 DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_002 start" << std::endl;
856 std::string remoteDeviceId = "123456";
857 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
858 /**
859 * @tc.steps: step1. call GetContinuaitonDevice
860 */
861 DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 start" << std::endl;
862 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
863 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
864 }
865 int32_t missionId = MISSION_ID;
866 (void)DistributedSchedService::GetInstance().GetContinuaitonDevice(missionId);
867 DTEST_LOG << "DistributedSchedServiceTest GetContinuaitonDevice_001 end" << std::endl;
868
869 auto result = DistributedSchedService::GetInstance().StartShareFormFromRemote(remoteDeviceId, formShareInfo);
870 DTEST_LOG << "result:" << result << std::endl;
871 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
872 DTEST_LOG << "DistributedSchedServiceTest StartShareFormFromRemote_002 end" << std::endl;
873 }
874
875 /**
876 * @tc.name: StartAbilityFromRemote_006
877 * @tc.desc: call StartAbilityFromRemote
878 * @tc.type: FUNC
879 */
880 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_006, TestSize.Level1)
881 {
882 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 start" << std::endl;
883 AAFwk::Want want;
884 std::string localDeviceId;
885 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
886 AppExecFwk::ElementName element(localDeviceId, "com.ohos.distributedmusicplayer",
887 "com.ohos.distributedmusicplayer.MainAbility");
888 want.SetElement(element);
889 AppExecFwk::AbilityInfo abilityInfo;
890 GetAbilityInfo("com.ohos.distributedmusicplayer", "com.ohos.distributedmusicplayer.MainAbility",
891 "com.ohos.distributedmusicplayer", "192.168.43.100", abilityInfo);
892 abilityInfo.visible = true;
893 abilityInfo.permissions.clear();
894 CallerInfo callerInfo;
895 callerInfo.uid = 0;
896 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
897 IDistributedSched::AccountInfo accountInfo;
898 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
899 accountInfo.groupIdList.push_back("123456");
900 int result = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
901 abilityInfo, 0, callerInfo, accountInfo);
902 DTEST_LOG << "result:" << result << std::endl;
903 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
904 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_006 end" << std::endl;
905 }
906
907 /**
908 * @tc.name: SendResultFromRemote_006
909 * @tc.desc: call SendResultFromRemote
910 * @tc.type: FUNC
911 */
912 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_006, TestSize.Level1)
913 {
914 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 start" << std::endl;
915 AAFwk::Want want;
916 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
917 "com.ohos.distributedmusicplayer.MainAbility");
918 want.SetElement(element);
919 std::string localDeviceId;
920 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
921 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
922 CallerInfo callerInfo;
923 callerInfo.uid = 0;
924 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
925 IDistributedSched::AccountInfo accountInfo;
926 /**
927 * @tc.steps: step1. call RemoveContinuationTimeout
928 */
929 DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_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 DistributedSchedService::GetInstance().RemoveContinuationTimeout(missionId);
935 DTEST_LOG << "DistributedSchedServiceTest RemoveContinuationTimeout_001 end" << std::endl;
936
937 int result = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
938 DTEST_LOG << "result:" << result << std::endl;
939 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
940 /**
941 * @tc.steps: step2. call RemoteConnectAbilityMappingLocked when connect == nullptr;
942 */
943 DistributedSchedService::GetInstance().RemoteConnectAbilityMappingLocked(nullptr,
944 localDeviceId, localDeviceId, element, callerInfo, TargetComponent::HARMONY_COMPONENT);
945 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_006 end" << std::endl;
946 }
947
948 /**
949 * @tc.name: SetContinuationTimeout_001
950 * @tc.desc: call GetContinuaitonDevice
951 * @tc.type: FUNC
952 */
953 HWTEST_F(DistributedSchedServiceTest, SetContinuationTimeout_001, TestSize.Level1)
954 {
955 DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 start" << std::endl;
956 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
957 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
958 }
959 int32_t missionId = MISSION_ID;
960 int32_t timeout = 5;
961 DistributedSchedService::GetInstance().SetContinuationTimeout(missionId, timeout);
962 DTEST_LOG << "DistributedSchedServiceTest SetContinuationTimeout_001 end" << std::endl;
963 }
964
965 /**
966 * @tc.name: ContinueRemoteMission_001
967 * @tc.desc: call ContinueRemoteMission
968 * @tc.type: FUNC
969 */
970 HWTEST_F(DistributedSchedServiceTest, ContinueRemoteMission_001, TestSize.Level1)
971 {
972 DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 start" << std::endl;
973 WantParams wantParams;
974 auto callback = GetDSchedService();
975 int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
976 "", "string", "bundleName", callback, wantParams);
977 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
978 DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_001 end" << std::endl;
979 }
980
981 /**
982 * @tc.name: ContinueRemoteMission_002
983 * @tc.desc: call ContinueRemoteMission
984 * @tc.type: FUNC
985 */
986 HWTEST_F(DistributedSchedServiceTest, ContinueRemoteMission_002, TestSize.Level1)
987 {
988 DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 start" << std::endl;
989 WantParams wantParams;
990 auto callback = GetDSchedService();
991 std::string localDeviceId;
992 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
993 int32_t result = DistributedSchedService::GetInstance().ContinueRemoteMission(
994 "string", localDeviceId, "bundleName", callback, wantParams);
995 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
996 DTEST_LOG << "DSchedContinuationTest ContinueRemoteMission_002 end" << std::endl;
997 }
998
999 /**
1000 * @tc.name: ContinueMission_001
1001 * @tc.desc: call ContinueMission
1002 * @tc.type: FUNC
1003 */
1004 HWTEST_F(DistributedSchedServiceTest, ContinueMission_001, TestSize.Level1)
1005 {
1006 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 start" << std::endl;
1007 WantParams wantParams;
1008 auto callback = GetDSchedService();
1009 int32_t missionId = MISSION_ID;
1010 std::string localDeviceId;
1011 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1012 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1013 "string", localDeviceId, missionId, callback, wantParams);
1014 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
1015 DTEST_LOG << "DSchedContinuationTest ContinueMission_001 end" << std::endl;
1016 }
1017
1018 /**
1019 * @tc.name: ContinueMission_002
1020 * @tc.desc: call ContinueMission
1021 * @tc.type: FUNC
1022 */
1023 HWTEST_F(DistributedSchedServiceTest, ContinueMission_002, TestSize.Level1)
1024 {
1025 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 start" << std::endl;
1026 WantParams wantParams;
1027 auto callback = GetDSchedService();
1028 int32_t missionId = MISSION_ID;
1029 std::string localDeviceId;
1030 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1031 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1032 "string", "string", missionId, callback, wantParams);
1033 EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
1034 DTEST_LOG << "DSchedContinuationTest ContinueMission_002 end" << std::endl;
1035 }
1036
1037 /**
1038 * @tc.name: ContinueMission_003
1039 * @tc.desc: call ContinueMission
1040 * @tc.type: FUNC
1041 * @tc.require: I7F8KH
1042 */
1043 HWTEST_F(DistributedSchedServiceTest, ContinueMission_003, TestSize.Level1)
1044 {
1045 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 start" << std::endl;
1046
1047 WantParams wantParams;
1048 auto callback = GetDSchedService();
1049 std::string bundleName = BUNDLE_NAME;
1050
1051 /**
1052 * @tc.steps: step1. test ContinueMission when srcDeviceId is empty;
1053 */
1054 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1055 "", "string", BUNDLE_NAME, callback, wantParams);
1056 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1057
1058 /**
1059 * @tc.steps: step2. test ContinueMission when dstDeviceId is empty;
1060 */
1061 result = DistributedSchedService::GetInstance().ContinueMission(
1062 "string", "", bundleName, callback, wantParams);
1063 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1064
1065 /**
1066 * @tc.steps: step3. test ContinueMission when callback is empty;
1067 */
1068 result = DistributedSchedService::GetInstance().ContinueMission(
1069 "string", "string", bundleName, nullptr, wantParams);
1070 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
1071
1072 DTEST_LOG << "DSchedContinuationTest ContinueMission_003 end" << std::endl;
1073 }
1074
1075 /**
1076 * @tc.name: ContinueMissionBundleName_001
1077 * @tc.desc: call ContinueMissionBundleName
1078 * @tc.type: FUNC
1079 */
1080 HWTEST_F(DistributedSchedServiceTest, ContinueMissionBundleName_001, TestSize.Level1)
1081 {
1082 DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 start" << std::endl;
1083 WantParams wantParams;
1084 auto callback = GetDSchedService();
1085 std::string localDeviceId;
1086 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1087 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1088 "string", localDeviceId, "bundleName", callback, wantParams);
1089 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), result);
1090 DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_001 end" << std::endl;
1091 }
1092
1093 /**
1094 * @tc.name: ContinueMissionBundleName_002
1095 * @tc.desc: call ContinueMissionBundleName
1096 * @tc.type: FUNC
1097 */
1098 HWTEST_F(DistributedSchedServiceTest, ContinueMissionBundleName_002, TestSize.Level1)
1099 {
1100 DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 start" << std::endl;
1101 WantParams wantParams;
1102 auto callback = GetDSchedService();
1103 int32_t result = DistributedSchedService::GetInstance().ContinueMission(
1104 "string", "string", "bundleName", callback, wantParams);
1105 EXPECT_EQ(static_cast<int>(OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET), result);
1106 DTEST_LOG << "DSchedContinuationTest ContinueMissionBundleName_002 end" << std::endl;
1107 }
1108
1109 /**
1110 * @tc.name: StartContinuation_001
1111 * @tc.desc: call StartContinuation
1112 * @tc.type: FUNC
1113 * @tc.require: I5NOA1
1114 */
1115 HWTEST_F(DistributedSchedServiceTest, StartContinuation_001, TestSize.Level1)
1116 {
1117 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
1118 AAFwk::Want want;
1119 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1120 "com.ohos.distributedmusicplayer.MainAbility");
1121 want.SetElement(element);
1122 int32_t missionId = MISSION_ID;
1123 int32_t callerUid = 0;
1124 int32_t status = 1;
1125 uint32_t accessToken = 0;
1126 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1127 want, missionId, callerUid, status, accessToken);
1128 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1129 CallerInfo callerInfo;
1130 ConnectInfo connectInfo;
1131 /**
1132 * @tc.steps: step1. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1133 */
1134 DistributedSchedService::GetInstance().componentChangeHandler_ = nullptr;
1135 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1136 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1137 /**
1138 * @tc.steps: step2. ReportDistributedComponentChange when componentChangeHandler_ is nullptr
1139 */
1140 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1141 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1142 /**
1143 * @tc.steps: step3. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1144 */
1145 auto runner = AppExecFwk::EventRunner::Create("DmsComponentChange");
1146 DistributedSchedService::GetInstance().componentChangeHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
1147 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1148 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1149 /**
1150 * @tc.steps: step4. ReportDistributedComponentChange when callerInfo.bundleNames is not empty
1151 */
1152 callerInfo.bundleNames.emplace_back("bundleName");
1153 DistributedSchedService::GetInstance().ReportDistributedComponentChange(callerInfo,
1154 1, IDistributedSched::CALL, IDistributedSched::CALLER);
1155 /**
1156 * @tc.steps: step5. ReportDistributedComponentChange when componentChangeHandler_ is not nullptr
1157 */
1158 DistributedSchedService::GetInstance().ReportDistributedComponentChange(connectInfo,
1159 1, IDistributedSched::CALL, IDistributedSched::CALLEE);
1160 DTEST_LOG << "DSchedContinuationTest StartContinuation_001 end" << std::endl;
1161 }
1162
1163 /**
1164 * @tc.name: StartContinuation_002
1165 * @tc.desc: call StartContinuation
1166 * @tc.type: FUNC
1167 */
1168 HWTEST_F(DistributedSchedServiceTest, StartContinuation_002, TestSize.Level1)
1169 {
1170 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
1171 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1172 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1173 }
1174 AAFwk::Want want;
1175 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1176 "com.ohos.distributedmusicplayer.MainAbility");
1177 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1178 want.SetElement(element);
1179 want.SetFlags(flags);
1180 int32_t missionId = MISSION_ID;
1181 int32_t callerUid = 0;
1182 int32_t status = 1;
1183 uint32_t accessToken = 0;
1184 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1185 want, missionId, callerUid, status, accessToken);
1186 EXPECT_EQ(static_cast<int>(INVALID_REMOTE_PARAMETERS_ERR), ret);
1187 DTEST_LOG << "DSchedContinuationTest StartContinuation_002 end" << std::endl;
1188 }
1189
1190 /**
1191 * @tc.name: StartContinuation_003
1192 * @tc.desc: call StartContinuation
1193 * @tc.type: FUNC
1194 * @tc.require: I6O5T3
1195 */
1196 HWTEST_F(DistributedSchedServiceTest, StartContinuation_003, TestSize.Level3)
1197 {
1198 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
1199 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1200 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1201 }
1202 AAFwk::Want want;
1203 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1204 "com.ohos.distributedmusicplayer.MainAbility");
1205 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1206 want.SetElement(element);
1207 want.SetFlags(flags);
1208 int32_t missionId = 0;
1209 int32_t callerUid = 1;
1210 int32_t status = ERR_OK;
1211 uint32_t accessToken = 0;
1212 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1213 want, missionId, callerUid, status, accessToken);
1214 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1215 DTEST_LOG << "DSchedContinuationTest StartContinuation_003 end" << std::endl;
1216 }
1217
1218 /**
1219 * @tc.name: StartContinuation_004
1220 * @tc.desc: call StartContinuation
1221 * @tc.type: FUNC
1222 * @tc.require: I6O5T3
1223 */
1224 HWTEST_F(DistributedSchedServiceTest, StartContinuation_004, TestSize.Level3)
1225 {
1226 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 start" << std::endl;
1227 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1228 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1229 }
1230 AAFwk::Want want;
1231 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1232 "com.ohos.distributedmusicplayer.MainAbility");
1233 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1234 want.SetElement(element);
1235 want.SetFlags(flags);
1236 int32_t missionId = 0;
1237 int32_t callerUid = 0;
1238 int32_t status = ERR_OK;
1239 uint32_t accessToken = 1;
1240 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1241 want, missionId, callerUid, status, accessToken);
1242 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1243 DTEST_LOG << "DSchedContinuationTest StartContinuation_004 end" << std::endl;
1244 }
1245
1246 /**
1247 * @tc.name: StartContinuation_005
1248 * @tc.desc: call StartContinuation
1249 * @tc.type: FUNC
1250 * @tc.require: I6O5T3
1251 */
1252 HWTEST_F(DistributedSchedServiceTest, StartContinuation_005, TestSize.Level3)
1253 {
1254 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 start" << std::endl;
1255 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1256 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1257 }
1258 AAFwk::Want want;
1259 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1260 "com.ohos.distributedmusicplayer.MainAbility");
1261 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1262 want.SetElement(element);
1263 want.SetFlags(flags);
1264 int32_t missionId = 0;
1265 int32_t callerUid = 1;
1266 int32_t status = ERR_OK;
1267 uint32_t accessToken = 1;
1268 bool resultCode = true;
1269 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1270 want, missionId, callerUid, status, accessToken);
1271 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1272 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1273 DTEST_LOG << "DSchedContinuationTest StartContinuation_005 end" << std::endl;
1274 }
1275
1276 /**
1277 * @tc.name: StartContinuation_006
1278 * @tc.desc: call StartContinuation
1279 * @tc.type: FUNC
1280 * @tc.require: I6O5T3
1281 */
1282 HWTEST_F(DistributedSchedServiceTest, StartContinuation_006, TestSize.Level3)
1283 {
1284 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 start" << std::endl;
1285 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1286 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1287 }
1288 AAFwk::Want want;
1289 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1290 "com.ohos.distributedmusicplayer.MainAbility");
1291 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1292 want.SetElement(element);
1293 want.SetFlags(flags);
1294 int32_t missionId = 0;
1295 int32_t callerUid = 0;
1296 int32_t status = ERR_OK;
1297 uint32_t accessToken = 0;
1298 bool resultCode = ERR_OK;
1299 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1300 want, missionId, callerUid, status, accessToken);
1301 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1302 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1303 DTEST_LOG << "DSchedContinuationTest StartContinuation_006 end" << std::endl;
1304 }
1305
1306 /**
1307 * @tc.name: StartContinuation_007
1308 * @tc.desc: call StartContinuation
1309 * @tc.type: FUNC
1310 * @tc.type: I6O5T3
1311 */
1312 HWTEST_F(DistributedSchedServiceTest, StartContinuation_007, TestSize.Level3)
1313 {
1314 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 start" << std::endl;
1315 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1316 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1317 }
1318 AAFwk::Want want;
1319 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1320 "com.ohos.distributedmusicplayer.MainAbility");
1321 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1322 want.SetElement(element);
1323 want.SetFlags(flags);
1324 int32_t missionId = 0;
1325 int32_t callerUid = 0;
1326 int32_t status = ERR_OK;
1327 uint32_t accessToken = 0;
1328 bool isSuccess = false;
1329 /**
1330 * @tc.steps: step1. call GetFormMgrProxy
1331 */
1332 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1333 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1334 DistributedSchedService::GetInstance().GetFormMgrProxy();
1335 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1336 #endif
1337
1338 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1339 want, missionId, callerUid, status, accessToken);
1340 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1341 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1342 DTEST_LOG << "DSchedContinuationTest StartContinuation_007 end" << std::endl;
1343 }
1344
1345 /**
1346 * @tc.name: StartContinuation_007
1347 * @tc.desc: call StartContinuation
1348 * @tc.type: FUNC
1349 * @tc.type: I6O5T3
1350 */
1351 HWTEST_F(DistributedSchedServiceTest, StartContinuation_008, TestSize.Level3)
1352 {
1353 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 start" << std::endl;
1354 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1355 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1356 }
1357 AAFwk::Want want;
1358 AppExecFwk::ElementName element("", "com.ohos.distributedmusicplayer",
1359 "com.ohos.distributedmusicplayer.MainAbility");
1360 int32_t flags = Want::FLAG_ABILITY_CONTINUATION;
1361 want.SetElement(element);
1362 want.SetFlags(flags);
1363 int32_t missionId = 0;
1364 int32_t callerUid = 0;
1365 int32_t status = ERR_OK;
1366 uint32_t accessToken = 0;
1367 bool isSuccess = false;
1368 /**
1369 * @tc.steps: step1. call GetFormMgrProxy
1370 */
1371 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
1372 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 start" << std::endl;
1373 DistributedSchedService::GetInstance().GetFormMgrProxy();
1374 DTEST_LOG << "DSchedContinuationTest GetFormMgrProxy_001 end" << std::endl;
1375 #endif
1376
1377 int32_t ret = DistributedSchedService::GetInstance().StartContinuation(
1378 want, missionId, callerUid, status, accessToken);
1379 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID_NULL, SESSION_ID, isSuccess);
1380 EXPECT_EQ(static_cast<int>(INVALID_PARAMETERS_ERR), ret);
1381 DTEST_LOG << "DSchedContinuationTest StartContinuation_008 end" << std::endl;
1382 }
1383
1384 /**
1385 * @tc.name: NotifyCompleteContinuation_001
1386 * @tc.desc: call NotifyCompleteContinuation
1387 * @tc.type: FUNC
1388 */
1389 HWTEST_F(DistributedSchedServiceTest, NotifyCompleteContinuation_001, TestSize.Level1)
1390 {
1391 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
1392 bool isSuccess = false;
1393 DistributedSchedService::GetInstance().NotifyCompleteContinuation(DEVICE_ID, SESSION_ID, isSuccess);
1394 DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
1395 }
1396
1397 /**
1398 * @tc.name: NotifyContinuationCallbackResult_001
1399 * @tc.desc: call NotifyContinuationCallbackResult
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(DistributedSchedServiceTest, NotifyContinuationCallbackResult_001, TestSize.Level1)
1403 {
1404 DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 start" << std::endl;
1405 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1406 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1407 }
1408 int32_t missionId = MISSION_ID;
1409 bool isSuccess = false;
1410 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, isSuccess);
1411 DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_001 end" << std::endl;
1412 }
1413
1414 /**
1415 * @tc.name: NotifyContinuationCallbackResult_002
1416 * @tc.desc: call NotifyContinuationCallbackResult
1417 * @tc.type: FUNC
1418 */
1419 HWTEST_F(DistributedSchedServiceTest, NotifyContinuationCallbackResult_002, TestSize.Level1)
1420 {
1421 DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_002 start" << std::endl;
1422 if (DistributedSchedService::GetInstance().dschedContinuation_ == nullptr) {
1423 DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared<DSchedContinuation>();
1424 }
1425 int32_t missionId = MISSION_ID;
1426 bool resultCode = ERR_OK;
1427 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
1428 DTEST_LOG << "DSchedContinuationTest NotifyContinuationCallbackResult_002 end" << std::endl;
1429 }
1430
1431 /**
1432 * @tc.name: StartAbilityFromRemote_007
1433 * @tc.desc: test StartAbilityFromRemote
1434 * @tc.type: FUNC
1435 * @tc.require: issueI5T6GJ
1436 */
1437 HWTEST_F(DistributedSchedServiceTest, StartAbilityFromRemote_007, TestSize.Level3)
1438 {
1439 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_007 start" << std::endl;
1440 AAFwk::Want want;
1441 std::string localDeviceId;
1442 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1443 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
1444 ABILITY_NAME);
1445 want.SetElement(element);
1446 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1447 AppExecFwk::AbilityInfo abilityInfo;
1448 abilityInfo.permissions.clear();
1449 CallerInfo callerInfo;
1450 callerInfo.uid = 0;
1451 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1452 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
1453 EXPECT_TRUE(result);
1454 IDistributedSched::AccountInfo accountInfo;
1455 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1456 int ret = DistributedSchedService::GetInstance().StartAbilityFromRemote(want,
1457 abilityInfo, 0, callerInfo, accountInfo);
1458 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1459 DTEST_LOG << "DistributedSchedServiceTest StartAbilityFromRemote_007 end" << std::endl;
1460 }
1461
1462 /**
1463 * @tc.name: SendResultFromRemote_007
1464 * @tc.desc: test SendResultFromRemote
1465 * @tc.type: FUNC
1466 * @tc.require: issueI5T6GJ
1467 */
1468 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_007, TestSize.Level3)
1469 {
1470 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_007 start" << std::endl;
1471 AAFwk::Want want;
1472 std::string localDeviceId;
1473 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1474 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1475 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1476 "bmsThirdBundle");
1477 want.SetElement(element);
1478 CallerInfo callerInfo;
1479 callerInfo.uid = 0;
1480 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1481 IDistributedSched::AccountInfo accountInfo;
1482 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1483 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
1484 EXPECT_NE(ret, ERR_OK);
1485 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_007 end" << std::endl;
1486 }
1487
1488 /**
1489 * @tc.name: SendResultFromRemote_008
1490 * @tc.desc: test SendResultFromRemote
1491 * @tc.type: FUNC
1492 * @tc.require: I6P0I9
1493 */
1494 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_008, TestSize.Level3)
1495 {
1496 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_008 start" << std::endl;
1497 AAFwk::Want want;
1498 std::string localDeviceId;
1499 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1500 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1501 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1502 "bmsThirdBundle");
1503 want.SetElement(element);
1504 CallerInfo callerInfo;
1505 callerInfo.uid = 0;
1506 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1507 IDistributedSched::AccountInfo accountInfo;
1508 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1509 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
1510 EXPECT_NE(ret, ERR_OK);
1511 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_008 end" << std::endl;
1512 }
1513
1514 /**
1515 * @tc.name: SendResultFromRemote_009
1516 * @tc.desc: test SendResultFromRemote
1517 * @tc.type: FUNC
1518 * @tc.require: I6P0I9
1519 */
1520 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_009, TestSize.Level3)
1521 {
1522 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_009 start" << std::endl;
1523 AAFwk::Want want;
1524 std::string localDeviceId;
1525 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1526 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1527 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1528 "bmsThirdBundle");
1529 want.SetElement(element);
1530 CallerInfo callerInfo;
1531 callerInfo.uid = 1;
1532 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1533 IDistributedSched::AccountInfo accountInfo;
1534 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1535 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
1536 EXPECT_NE(ret, ERR_OK);
1537 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_009 end" << std::endl;
1538 }
1539
1540 /**
1541 * @tc.name: SendResultFromRemote_010
1542 * @tc.desc: test SendResultFromRemote
1543 * @tc.type: FUNC
1544 * @tc.require: I6P0I9
1545 */
1546 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_010, TestSize.Level3)
1547 {
1548 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_010 start" << std::endl;
1549 AAFwk::Want want;
1550 std::string localDeviceId;
1551 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1552 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1553 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1554 "bmsThirdBundle");
1555 want.SetElement(element);
1556 CallerInfo callerInfo;
1557 callerInfo.uid = 0;
1558 callerInfo.sourceDeviceId = localDeviceId;
1559 IDistributedSched::AccountInfo accountInfo;
1560 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1561 int32_t ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 0, callerInfo, accountInfo, 0);
1562 EXPECT_NE(ret, ERR_OK);
1563 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_010 end" << std::endl;
1564 }
1565
1566 /**
1567 * @tc.name: SendResultFromRemote_011
1568 * @tc.desc: test SendResultFromRemote
1569 * @tc.type: FUNC
1570 * @tc.require: I6P0I9
1571 */
1572 HWTEST_F(DistributedSchedServiceTest, SendResultFromRemote_011, TestSize.Level3)
1573 {
1574 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_011 start" << std::endl;
1575 AAFwk::Want want;
1576 std::string localDeviceId;
1577 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1578 want.SetParam(DMS_SRC_NETWORK_ID, localDeviceId);
1579 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1580 "bmsThirdBundle");
1581 want.SetElement(element);
1582 CallerInfo callerInfo;
1583 callerInfo.uid = 0;
1584 callerInfo.sourceDeviceId = localDeviceId;
1585 IDistributedSched::AccountInfo accountInfo;
1586 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1587 int ret = DistributedSchedService::GetInstance().SendResultFromRemote(want, 1, callerInfo, accountInfo, 0);
1588 EXPECT_NE(ret, ERR_OK);
1589 DTEST_LOG << "DistributedSchedServiceTest SendResultFromRemote_011 end" << std::endl;
1590 }
1591
1592 /**
1593 * @tc.name: StartAbilityByCallFromRemote_001
1594 * @tc.desc: input invalid params
1595 * @tc.type: FUNC
1596 * @tc.require: issueI5T6GJ
1597 */
1598 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_001, TestSize.Level3)
1599 {
1600 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_001 start" << std::endl;
1601 AAFwk::Want want;
1602 std::string localDeviceId;
1603 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1604 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1605 "bmsThirdBundle");
1606 want.SetElement(element);
1607 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1608 sptr<IRemoteObject> connect = new MockDistributedSched();
1609 CallerInfo callerInfo;
1610 callerInfo.uid = 0;
1611 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1612 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example",
1613 callerInfo.callerAppId);
1614 EXPECT_EQ(result, true);
1615 IDistributedSched::AccountInfo accountInfo;
1616 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1617 auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
1618 int ret = mockDms->StartAbilityByCallFromRemote(want, connect, callerInfo, accountInfo);
1619 EXPECT_EQ(ret, ERR_OK);
1620 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_001 end" << std::endl;
1621 }
1622
1623 /**
1624 * @tc.name: StartAbilityByCallFromRemote_002
1625 * @tc.desc: input invalid params
1626 * @tc.type: FUNC
1627 * @tc.require: issueI5T6GJ
1628 */
1629 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_002, TestSize.Level3)
1630 {
1631 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_002 start" << std::endl;
1632 AAFwk::Want want;
1633 std::string localDeviceId;
1634 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1635 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1636 "bmsThirdBundle");
1637 want.SetElement(element);
1638 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1639 sptr<IRemoteObject> connect = new MockDistributedSched();
1640 CallerInfo callerInfo;
1641 callerInfo.uid = 0;
1642 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
1643 IDistributedSched::AccountInfo accountInfo;
1644 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1645 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1646 callerInfo, accountInfo);
1647 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1648 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_002 end" << std::endl;
1649 }
1650
1651 /**
1652 * @tc.name: NotifyStateChangedFromRemote_001
1653 * @tc.desc: call NotifyStateChangedFromRemote with illegal params
1654 * @tc.type: FUNC
1655 * @tc.require: I6SJQ6
1656 */
1657 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_001, TestSize.Level1)
1658 {
1659 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_001 start" << std::endl;
1660 sptr<IDistributedSched> proxy = GetDms();
1661 if (proxy == nullptr) {
1662 return;
1663 }
1664 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1665 int result1 = proxy->NotifyStateChangedFromRemote(0, 0, element);
1666 DTEST_LOG << "result1:" << result1 << std::endl;
1667
1668 EXPECT_NE(result1, ERR_OK);
1669 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_001 end" << std::endl;
1670 }
1671
1672 /**
1673 * @tc.name: NotifyStateChanged_001
1674 * @tc.desc: test NotifyStateChanged
1675 * @tc.type: FUNC
1676 * @tc.require: I6SJQ6
1677 */
1678 HWTEST_F(DistributedSchedServiceTest, NotifyStateChanged_001, TestSize.Level3)
1679 {
1680 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_001 start" << std::endl;
1681 int32_t abilityState = FOREGROUND;
1682 std::string localDeviceId;
1683 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1684 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
1685 DTEST_LOG << "ret:" << ret << std::endl;
1686 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1687 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_001 end" << std::endl;
1688 }
1689
1690 /**
1691 * @tc.name: NotifyStateChangedFromRemote_002
1692 * @tc.desc: test NotifyStateChangedFromRemote
1693 * @tc.type: FUNC
1694 * @tc.require: I6SJQ6
1695 */
1696 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_002, TestSize.Level3)
1697 {
1698 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_002 start" << std::endl;
1699 std::string localDeviceId;
1700 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1701 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1702
1703 int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
1704 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1705 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_002 end" << std::endl;
1706 }
1707
1708 /**
1709 * @tc.name: NotifyStateChangedFromRemote_003
1710 * @tc.desc: test NotifyStateChangedFromRemote
1711 * @tc.type: FUNC
1712 * @tc.require: I6SJQ6
1713 */
1714 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_003, TestSize.Level3)
1715 {
1716 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_003 start" << std::endl;
1717 std::string localDeviceId;
1718 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1719 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1720
1721 sptr<IRemoteObject> connect = nullptr;
1722 DistributedSchedService::GetInstance().callMap_[connect] = {1, localDeviceId};
1723 int ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(0, 0, element);
1724 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1725 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_003 end" << std::endl;
1726 }
1727
1728 /**
1729 * @tc.name: RegisterAppStateObserver_001
1730 * @tc.desc: test RegisterAppStateObserver
1731 * @tc.type: FUNC
1732 * @tc.require: I6VDBO
1733 */
1734 HWTEST_F(DistributedSchedServiceTest, RegisterAppStateObserver_001, TestSize.Level3)
1735 {
1736 DTEST_LOG << "DistributedSchedServiceTest RegisterAppStateObserver_001 start" << std::endl;
1737 AAFwk::Want want;
1738 std::string localDeviceId;
1739 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1740 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1741 want.SetElement(element);
1742 want.SetParam(DMS_MISSION_ID, 0);
1743 want.SetParam(DMS_CONNECT_TOKEN, 0);
1744 sptr<IRemoteObject> connect = new MockDistributedSched();
1745 CallerInfo callerInfo;
1746 callerInfo.uid = 0;
1747 callerInfo.sourceDeviceId = localDeviceId;
1748 bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1749 DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1750 EXPECT_TRUE(ret);
1751 DTEST_LOG << "DistributedSchedServiceTest RegisterAppStateObserver_001 end" << std::endl;
1752 }
1753
1754 /**
1755 * @tc.name: UnregisterAppStateObserver_001
1756 * @tc.desc: test UnregisterAppStateObserver
1757 * @tc.type: FUNC
1758 * @tc.require: I6VDBO
1759 */
1760 HWTEST_F(DistributedSchedServiceTest, UnregisterAppStateObserver_001, TestSize.Level3)
1761 {
1762 DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_001 start" << std::endl;
1763 sptr<IRemoteObject> connect;
1764 DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect);
1765 EXPECT_EQ(connect, nullptr);
1766 DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_001 end" << std::endl;
1767 }
1768
1769 /**
1770 * @tc.name: UnregisterAppStateObserver_002
1771 * @tc.desc: test UnregisterAppStateObserver
1772 * @tc.type: FUNC
1773 * @tc.require: I6VDBO
1774 */
1775 HWTEST_F(DistributedSchedServiceTest, UnregisterAppStateObserver_002, TestSize.Level3)
1776 {
1777 DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_002 start" << std::endl;
1778 AAFwk::Want want;
1779 std::string localDeviceId;
1780 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1781 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1782 want.SetElement(element);
1783 want.SetParam(DMS_MISSION_ID, 0);
1784 want.SetParam(DMS_CONNECT_TOKEN, 0);
1785 sptr<IRemoteObject> connect = new MockDistributedSched();
1786 CallerInfo callerInfo;
1787 callerInfo.uid = 0;
1788 callerInfo.sourceDeviceId = localDeviceId;
1789 bool ret = DistributedSchedService::GetInstance().RegisterAppStateObserver(want, callerInfo, nullptr, connect);
1790 EXPECT_TRUE(ret);
1791 sptr<IRemoteObject> connect1 = new MockDistributedSched();
1792 DistributedSchedService::GetInstance().UnregisterAppStateObserver(connect1);
1793 EXPECT_NE(connect, connect1);
1794 DTEST_LOG << "DistributedSchedServiceTest UnregisterAppStateObserver_002 end" << std::endl;
1795 }
1796
1797 /**
1798 * @tc.name: GetAppManager_001
1799 * @tc.desc: test GetAppManager
1800 * @tc.type: FUNC
1801 * @tc.require: I6VDBO
1802 */
1803 HWTEST_F(DistributedSchedServiceTest, GetAppManager_001, TestSize.Level3)
1804 {
1805 DTEST_LOG << "DistributedSchedServiceTest GetAppManager_001 start" << std::endl;
1806 auto ret = DistributedSchedService::GetInstance().GetAppManager();
1807 EXPECT_NE(ret, nullptr);
1808 DTEST_LOG << "DistributedSchedServiceTest GetAppManager_001 end" << std::endl;
1809 }
1810
1811 /**
1812 * @tc.name: NotifyStateChanged_002
1813 * @tc.desc: test NotifyStateChanged
1814 * @tc.type: FUNC
1815 * @tc.require: I6VDBO
1816 */
1817 HWTEST_F(DistributedSchedServiceTest, NotifyStateChanged_002, TestSize.Level3)
1818 {
1819 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_002 start" << std::endl;
1820 sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
1821 int32_t abilityState = FOREGROUND;
1822 std::string localDeviceId;
1823 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1824 sptr<IRemoteObject> connect = new MockDistributedSched();
1825 DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, localDeviceId, 0, BUNDLE_NAME,
1826 ABILITY_NAME};
1827 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1828 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
1829 DTEST_LOG << "ret:" << ret << std::endl;
1830 DistributedSchedService::GetInstance().observerMap_.clear();
1831 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1832 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_002 end" << std::endl;
1833 }
1834
1835 /**
1836 * @tc.name: NotifyStateChanged_003
1837 * @tc.desc: test NotifyStateChanged
1838 * @tc.type: FUNC
1839 * @tc.require: I6VDBO
1840 */
1841 HWTEST_F(DistributedSchedServiceTest, NotifyStateChanged_003, TestSize.Level3)
1842 {
1843 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_003 start" << std::endl;
1844 sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
1845 int32_t abilityState = FOREGROUND;
1846 std::string localDeviceId;
1847 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1848 sptr<IRemoteObject> connect = new MockDistributedSched();
1849 DistributedSchedService::GetInstance().observerMap_[connect] = {appStateObserver, REMOTE_DEVICEID, 0, BUNDLE_NAME,
1850 ABILITY_NAME};
1851 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1852 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChanged(abilityState, element, nullptr);
1853 DTEST_LOG << "ret:" << ret << std::endl;
1854 DistributedSchedService::GetInstance().observerMap_.clear();
1855 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1856 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChanged_003 end" << std::endl;
1857 }
1858
1859 /**
1860 * @tc.name: NotifyStateChangedFromRemote_004
1861 * @tc.desc: test NotifyStateChangedFromRemote
1862 * @tc.type: FUNC
1863 * @tc.require: I6VDBO
1864 */
1865 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_004, TestSize.Level3)
1866 {
1867 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_004 start" << std::endl;
1868 sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
1869 int32_t abilityState = FOREGROUND;
1870 std::string localDeviceId;
1871 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1872 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1873 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
1874 DTEST_LOG << "ret:" << ret << std::endl;
1875 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1876 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_004 end" << std::endl;
1877 }
1878
1879 /**
1880 * @tc.name: NotifyStateChangedFromRemote_005
1881 * @tc.desc: test NotifyStateChangedFromRemote
1882 * @tc.type: FUNC
1883 * @tc.require: I6VDBO
1884 */
1885 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_005, TestSize.Level3)
1886 {
1887 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_005 start" << std::endl;
1888 sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
1889 int32_t abilityState = FOREGROUND;
1890 std::string localDeviceId;
1891 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1892 sptr<IRemoteObject> connect = nullptr;
1893 DistributedSchedService::GetInstance().callMap_[connect] = {2, localDeviceId};
1894 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1895 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 0, element);
1896 DTEST_LOG << "ret:" << ret << std::endl;
1897 DistributedSchedService::GetInstance().callMap_.clear();
1898 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
1899 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_005 end" << std::endl;
1900 }
1901
1902 /**
1903 * @tc.name: NotifyStateChangedFromRemote_006
1904 * @tc.desc: test NotifyStateChangedFromRemote
1905 * @tc.type: FUNC
1906 * @tc.require: I6VDBO
1907 */
1908 HWTEST_F(DistributedSchedServiceTest, NotifyStateChangedFromRemote_006, TestSize.Level3)
1909 {
1910 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_006 start" << std::endl;
1911 sptr<AppStateObserver> appStateObserver = sptr<AppStateObserver>(new (std::nothrow) AppStateObserver());
1912 int32_t abilityState = FOREGROUND;
1913 std::string localDeviceId;
1914 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1915 sptr<IRemoteObject> connect = new MockDistributedSched();
1916 DistributedSchedService::GetInstance().callMap_[connect] = {3, localDeviceId};
1917 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME, ABILITY_NAME);
1918 int32_t ret = DistributedSchedService::GetInstance().NotifyStateChangedFromRemote(abilityState, 3, element);
1919 DTEST_LOG << "ret:" << ret << std::endl;
1920 DistributedSchedService::GetInstance().callMap_.clear();
1921 EXPECT_EQ(ret, ERR_OK);
1922 DTEST_LOG << "DistributedSchedServiceTest NotifyStateChangedFromRemote_006 end" << std::endl;
1923 }
1924
1925 /**
1926 * @tc.name: StartAbilityByCallFromRemote_003
1927 * @tc.desc: call StartAbilityByCallFromRemote
1928 * @tc.type: FUNC
1929 * @tc.require: I6YLV1
1930 */
1931 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_003, TestSize.Level3)
1932 {
1933 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_003 start" << std::endl;
1934 AAFwk::Want want;
1935 std::string localDeviceId;
1936 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1937 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1938 "bmsThirdBundle");
1939 want.SetElement(element);
1940 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1941 CallerInfo callerInfo;
1942 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1943 EXPECT_EQ(result, true);
1944 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1945 sptr<IRemoteObject> connect = new MockDistributedSched();
1946 callerInfo.uid = 0;
1947 callerInfo.sourceDeviceId = localDeviceId;
1948 IDistributedSched::AccountInfo accountInfo;
1949 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1950 sptr<IRemoteObject> callbackWrapper = new AbilityConnectionWrapperStub(connect, localDeviceId);
1951 ConnectInfo connectInfo {callerInfo, callbackWrapper, want.GetElement()};
1952 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
1953 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1954 callerInfo, accountInfo);
1955 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1956 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_003 end" << std::endl;
1957 }
1958
1959 /**
1960 * @tc.name: StartAbilityByCallFromRemote_004
1961 * @tc.desc: call StartAbilityByCallFromRemote
1962 * @tc.type: FUNC
1963 * @tc.require: I6YLV1
1964 */
1965 HWTEST_F(DistributedSchedServiceTest, StartAbilityByCallFromRemote_004, TestSize.Level3)
1966 {
1967 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_004 start" << std::endl;
1968 AAFwk::Want want;
1969 std::string localDeviceId;
1970 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
1971 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example",
1972 "bmsThirdBundle");
1973 want.SetElement(element);
1974 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1975 CallerInfo callerInfo;
1976 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
1977 EXPECT_EQ(result, true);
1978 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1979 sptr<IRemoteObject> connect = new MockDistributedSched();
1980 callerInfo.uid = 0;
1981 callerInfo.sourceDeviceId = localDeviceId;
1982 IDistributedSched::AccountInfo accountInfo;
1983 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1984 int ret = DistributedSchedService::GetInstance().StartAbilityByCallFromRemote(want, connect,
1985 callerInfo, accountInfo);
1986 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
1987 DTEST_LOG << "DistributedSchedServiceTest StartAbilityByCallFromRemote_004 end" << std::endl;
1988 }
1989
1990 /**
1991 * @tc.name: HandleLocalCallerDied_001
1992 * @tc.desc: call HandleLocalCallerDied
1993 * @tc.type: FUNC
1994 * @tc.require: I6YLV1
1995 */
1996 HWTEST_F(DistributedSchedServiceTest, HandleLocalCallerDied_001, TestSize.Level1)
1997 {
1998 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied_001 start" << std::endl;
1999 std::string localDeviceId;
2000 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2001 sptr<IRemoteObject> connect = new MockDistributedSched();
2002 std::list<ConnectAbilitySession> sessionsList;
2003 DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
2004 DistributedSchedService::GetInstance().callMap_[connect] = {4, localDeviceId};
2005 DistributedSchedService::GetInstance().HandleLocalCallerDied(connect);
2006 DistributedSchedService::GetInstance().callerMap_.clear();
2007 EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
2008 DistributedSchedService::GetInstance().callMap_.clear();
2009 EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
2010 DTEST_LOG << "DistributedSchedServiceTest HandleLocalCallerDied_001 end" << std::endl;
2011 }
2012
2013 /**
2014 * @tc.name: ProcessCalleeDied_001
2015 * @tc.desc: call ProcessCalleeDied
2016 * @tc.type: FUNC
2017 * @tc.require: I6YLV1
2018 */
2019 HWTEST_F(DistributedSchedServiceTest, ProcessCalleeDied_001, TestSize.Level1)
2020 {
2021 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied_001 start" << std::endl;
2022 std::string localDeviceId;
2023 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2024 sptr<IRemoteObject> connect = new MockDistributedSched();
2025 DistributedSchedService::GetInstance().ProcessCalleeDied(connect);
2026 DistributedSchedService::GetInstance().calleeMap_.clear();
2027 EXPECT_TRUE(DistributedSchedService::GetInstance().calleeMap_.empty());
2028 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeDied_001 end" << std::endl;
2029 }
2030
2031 /**
2032 * @tc.name: RemoveCallerComponent_001
2033 * @tc.desc: call RemoveCallerComponent
2034 * @tc.type: FUNC
2035 * @tc.require: I6YLV1
2036 */
2037 HWTEST_F(DistributedSchedServiceTest, RemoveCallerComponent_001, TestSize.Level1)
2038 {
2039 DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent_001 start" << std::endl;
2040 std::string localDeviceId;
2041 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2042 sptr<IRemoteObject> connect = new MockDistributedSched();
2043 std::list<ConnectAbilitySession> sessionsList;
2044 DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
2045 DistributedSchedService::GetInstance().callMap_[connect] = {5, localDeviceId};
2046 DistributedSchedService::GetInstance().RemoveCallerComponent(connect);
2047 DistributedSchedService::GetInstance().callerMap_.clear();
2048 EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
2049 DistributedSchedService::GetInstance().callMap_.clear();
2050 EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
2051 DTEST_LOG << "DistributedSchedServiceTest RemoveCallerComponent_001 end" << std::endl;
2052 }
2053
2054 /**
2055 * @tc.name: ProcessCalleeOffline_001
2056 * @tc.desc: call ProcessCalleeOffline
2057 * @tc.type: FUNC
2058 * @tc.require: I6YLV1
2059 */
2060 HWTEST_F(DistributedSchedServiceTest, ProcessCalleeOffline_001, TestSize.Level1)
2061 {
2062 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeOffline_001 start" << std::endl;
2063 std::string localDeviceId;
2064 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2065 sptr<IRemoteObject> connect = new MockDistributedSched();
2066 std::list<ConnectAbilitySession> sessionsList;
2067 DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
2068 DistributedSchedService::GetInstance().callMap_[connect] = {6, localDeviceId};
2069 DistributedSchedService::GetInstance().ProcessCalleeOffline(REMOTE_DEVICEID);
2070
2071 sptr<IRemoteObject> mockConnect;
2072 DistributedSchedService::GetInstance().callerMap_[mockConnect] = sessionsList;
2073 DistributedSchedService::GetInstance().ProcessCalleeOffline(localDeviceId);
2074 DistributedSchedService::GetInstance().callerMap_.clear();
2075 EXPECT_TRUE(DistributedSchedService::GetInstance().callerMap_.empty());
2076 DistributedSchedService::GetInstance().callMap_.clear();
2077 EXPECT_TRUE(DistributedSchedService::GetInstance().callMap_.empty());
2078 DTEST_LOG << "DistributedSchedServiceTest ProcessCalleeOffline_001 end" << std::endl;
2079 }
2080
2081 /**
2082 * @tc.name: ConnectAbilityFromRemote_001
2083 * @tc.desc: test ConnectAbilityFromRemote
2084 * @tc.type: FUNC
2085 * @tc.require: issueI5T6GJ
2086 */
2087 HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_001, TestSize.Level3)
2088 {
2089 DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_001 start" << std::endl;
2090 AAFwk::Want want;
2091 std::string localDeviceId;
2092 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2093 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
2094 ABILITY_NAME);
2095 want.SetElement(element);
2096 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
2097 AppExecFwk::AbilityInfo abilityInfo;
2098 abilityInfo.permissions.clear();
2099 sptr<IRemoteObject> connect = new MockDistributedSched();
2100 CallerInfo callerInfo;
2101 callerInfo.uid = 0;
2102 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2103 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
2104 EXPECT_TRUE(result);
2105 IDistributedSched::AccountInfo accountInfo;
2106 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
2107 auto mockDms = iface_cast<IDistributedSched>(GetDSchedService());
2108 int ret = mockDms->ConnectAbilityFromRemote(want, abilityInfo, connect, callerInfo, accountInfo);
2109 EXPECT_EQ(ret, ERR_OK);
2110 DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_001 end" << std::endl;
2111 }
2112
2113 /**
2114 * @tc.name: ConnectAbilityFromRemote_002
2115 * @tc.desc: input invalid params
2116 * @tc.type: FUNC
2117 * @tc.require: issueI5T6GJ
2118 */
2119 HWTEST_F(DistributedSchedServiceTest, ConnectAbilityFromRemote_002, TestSize.Level3)
2120 {
2121 DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_002 start" << std::endl;
2122 AAFwk::Want want;
2123 std::string localDeviceId;
2124 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2125 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
2126 ABILITY_NAME);
2127 want.SetElement(element);
2128 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
2129 AppExecFwk::AbilityInfo abilityInfo;
2130 abilityInfo.permissions.clear();
2131 sptr<IRemoteObject> connect = new MockDistributedSched();
2132 CallerInfo callerInfo;
2133 callerInfo.uid = 0;
2134 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2135 IDistributedSched::AccountInfo accountInfo;
2136 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
2137 int32_t ret1 = DistributedSchedService::GetInstance().ConnectAbilityFromRemote(want,
2138 abilityInfo, connect, callerInfo, accountInfo);
2139 AppExecFwk::AbilityInfo targetAbility;
2140 bool ret2 = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
2141 EXPECT_EQ(ret2, true);
2142 if (targetAbility.visible) {
2143 EXPECT_EQ(ret1, ERR_OK);
2144 } else {
2145 EXPECT_EQ(ret1, INVALID_REMOTE_PARAMETERS_ERR);
2146 }
2147 DTEST_LOG << "DistributedSchedServiceTest ConnectAbilityFromRemote_002 end" << std::endl;
2148 }
2149
2150 /**
2151 * @tc.name: StartLocalAbility_005
2152 * @tc.desc: test StartLocalAbility
2153 * @tc.type: FUNC
2154 * @tc.require: issueI5T6GJ
2155 */
2156 HWTEST_F(DistributedSchedServiceTest, StartLocalAbility_005, TestSize.Level3)
2157 {
2158 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_005 start" << std::endl;
2159 AAFwk::Want want;
2160 std::string localDeviceId;
2161 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2162 AppExecFwk::ElementName element(localDeviceId, "com.third.hiworld.example", "bmsThirdBundle");
2163 want.SetElement(element);
2164 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
2165 AppExecFwk::AbilityInfo abilityInfo;
2166 abilityInfo.permissions.clear();
2167 CallerInfo callerInfo;
2168 callerInfo.uid = 0;
2169 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2170 bool result = BundleManagerInternal::GetCallerAppIdFromBms("com.third.hiworld.example", callerInfo.callerAppId);
2171 EXPECT_TRUE(result);
2172 IDistributedSched::AccountInfo accountInfo;
2173 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
2174 DistributedSchedProxy::FreeInstallInfo info = {.want = want, .requestCode = 0,
2175 .callerInfo = callerInfo, .accountInfo = accountInfo};
2176 int ret = DistributedSchedService::GetInstance().StartLocalAbility(info, 0, 0);
2177 EXPECT_EQ(ret, ERR_OK);
2178 DTEST_LOG << "DistributedSchedServiceTest StartLocalAbility_005 end" << std::endl;
2179 }
2180
2181 /**
2182 * @tc.name: Dump001
2183 * @tc.desc: call Dump
2184 * @tc.type: FUNC
2185 * @tc.require: I6O5T3
2186 */
2187 HWTEST_F(DistributedSchedServiceTest, Dump001, TestSize.Level3)
2188 {
2189 DTEST_LOG << "DistributedSchedServiceTest Dump001 start" << std::endl;
2190 int32_t fd = 1;
2191 const std::vector<std::u16string> args;
2192 const wptr<IRemoteObject> remote;
2193 int32_t missionId = 0;
2194 bool resultCode = ERR_OK;
2195 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
2196 DistributedSchedService::GetInstance().NotifyContinuationCallbackResult(missionId, resultCode);
2197 DistributedSchedService::GetInstance().ProcessFormMgrDied(remote);
2198 EXPECT_EQ(ret, ERR_OK);
2199 DTEST_LOG << "DistributedSchedServiceTest Dump001 end" << std::endl;
2200 }
2201
2202 /**
2203 * @tc.name: Dump002
2204 * @tc.desc: call Dump
2205 * @tc.type: FUNC
2206 * @tc.require: I6O5T3
2207 */
2208 HWTEST_F(DistributedSchedServiceTest, Dump002, TestSize.Level3)
2209 {
2210 DTEST_LOG << "DistributedSchedServiceTest Dump002 start" << std::endl;
2211 int32_t fd = 0;
2212 const std::vector<std::u16string> args;
2213 const std::string deviceId;
2214 int32_t ret = DistributedSchedService::GetInstance().Dump(fd, args);
2215 DistributedSchedService::GetInstance().DeviceOnlineNotify(deviceId);
2216 DistributedSchedService::GetInstance().DeviceOfflineNotify(deviceId);
2217 EXPECT_EQ(ret, DMS_WRITE_FILE_FAILED_ERR);
2218 DTEST_LOG << "DistributedSchedServiceTest Dump002 end" << std::endl;
2219 }
2220
2221 /**
2222 * @tc.name: StartRemoteAbility001
2223 * @tc.desc: call StartRemoteAbility
2224 * @tc.type: FUNC
2225 * @tc.require: I6P0I9
2226 */
2227 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility001, TestSize.Level3)
2228 {
2229 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility001 start" << std::endl;
2230 AAFwk::Want want;
2231 int32_t callerUid = 0;
2232 int32_t requestCode = 0;
2233 uint32_t accessToken = 0;
2234 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2235 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2236 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility001 end" << std::endl;
2237 }
2238
2239 /**
2240 * @tc.name: StartRemoteAbility002
2241 * @tc.desc: call StartRemoteAbility
2242 * @tc.type: FUNC
2243 * @tc.require: I6P0I9
2244 */
2245 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility002, TestSize.Level3)
2246 {
2247 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility002 start" << std::endl;
2248 AAFwk::Want want;
2249 int32_t callerUid = 1;
2250 int32_t requestCode = 0;
2251 uint32_t accessToken = 0;
2252 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2253 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2254 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility002 end" << std::endl;
2255 }
2256
2257 /**
2258 * @tc.name: StartRemoteAbility003
2259 * @tc.desc: call StartRemoteAbility
2260 * @tc.type: FUNC
2261 * @tc.require: I6P0I9
2262 */
2263 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility003, TestSize.Level3)
2264 {
2265 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility003 start" << std::endl;
2266 AAFwk::Want want;
2267 int32_t callerUid = 0;
2268 int32_t requestCode = 1;
2269 uint32_t accessToken = 0;
2270 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2271 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2272 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility003 end" << std::endl;
2273 }
2274
2275 /**
2276 * @tc.name: StartRemoteAbility004
2277 * @tc.desc: call StartRemoteAbility
2278 * @tc.type: FUNC
2279 * @tc.require: I6P0I9
2280 */
2281 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility004, TestSize.Level3)
2282 {
2283 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility004 start" << std::endl;
2284 AAFwk::Want want;
2285 int32_t callerUid = 0;
2286 int32_t requestCode = 0;
2287 uint32_t accessToken = 1;
2288 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2289 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2290 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility004 end" << std::endl;
2291 }
2292
2293 /**
2294 * @tc.name: StartRemoteAbility005
2295 * @tc.desc: call StartRemoteAbility
2296 * @tc.type: FUNC
2297 * @tc.require: I6P0I9
2298 */
2299 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility005, TestSize.Level3)
2300 {
2301 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility005 start" << std::endl;
2302 AAFwk::Want want;
2303 int32_t callerUid = 1;
2304 int32_t requestCode = 1;
2305 uint32_t accessToken = 0;
2306 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2307 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2308 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility005 end" << std::endl;
2309 }
2310
2311 /**
2312 * @tc.name: StartRemoteAbility006
2313 * @tc.desc: call StartRemoteAbility
2314 * @tc.type: FUNC
2315 * @tc.require: I6P0I9
2316 */
2317 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbility006, TestSize.Level3)
2318 {
2319 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility006 start" << std::endl;
2320 AAFwk::Want want;
2321 int32_t callerUid = 1;
2322 int32_t requestCode = 1;
2323 uint32_t accessToken = 1;
2324 int32_t ret = DistributedSchedService::GetInstance().StartRemoteAbility(want, callerUid, requestCode, accessToken);
2325 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2326 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbility006 end" << std::endl;
2327 }
2328
2329
2330 /**
2331 * @tc.name: CheckDistributedConnectLocked001
2332 * @tc.desc: call CheckDistributedConnectLocked
2333 * @tc.type: FUNC
2334 * @tc.require: I6P0I9
2335 */
2336 HWTEST_F(DistributedSchedServiceTest, CheckDistributedConnectLocked001, TestSize.Level3)
2337 {
2338 DTEST_LOG << "DistributedSchedServiceTest CheckDistributedConnectLocked001 start" << std::endl;
2339 int32_t uid = IPCSkeleton::GetCallingUid();
2340 CallerInfo callerInfo;
2341 callerInfo.uid = uid;
2342 int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
2343 EXPECT_EQ(ret, ERR_OK);
2344 DTEST_LOG << "DistributedSchedServiceTest CheckDistributedConnectLocked001 end" << std::endl;
2345 }
2346
2347 /**
2348 * @tc.name: CheckDistributedConnectLocked002
2349 * @tc.desc: call CheckDistributedConnectLocked
2350 * @tc.type: FUNC
2351 * @tc.require: I6P0I9
2352 */
2353 HWTEST_F(DistributedSchedServiceTest, CheckDistributedConnectLocked002, TestSize.Level3)
2354 {
2355 DTEST_LOG << "DistributedSchedServiceTest CheckDistributedConnectLocked002 start" << std::endl;
2356 int32_t uid = -1;
2357 CallerInfo callerInfo;
2358 callerInfo.uid = uid;
2359 int32_t ret = DistributedSchedService::GetInstance().CheckDistributedConnectLocked(callerInfo);
2360 EXPECT_EQ(ret, BIND_ABILITY_UID_INVALID_ERR);
2361 DTEST_LOG << "DistributedSchedServiceTest CheckDistributedConnectLocked002 end" << std::endl;
2362 }
2363
2364
2365 /**
2366 * @tc.name: ConnectRemoteAbility001
2367 * @tc.desc: connect remote ability with right uid and pid
2368 * @tc.type: FUNC
2369 * @tc.require: I6P0I9
2370 */
2371 HWTEST_F(DistributedSchedServiceTest, ConnectRemoteAbility001, TestSize.Level3)
2372 {
2373 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 start" << std::endl;
2374 OHOS::AAFwk::Want want;
2375 want.SetElementName("123_remote_device_id", "ohos.demo.bundleName", "abilityName");
2376 const sptr<IRemoteObject> connect;
2377 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
2378 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2379 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility001 end" << std::endl;
2380 }
2381
2382 /**
2383 * @tc.name: ConnectRemoteAbility002
2384 * @tc.desc: connect remote ability with empty deviceId.
2385 * @tc.type: FUNC
2386 * @tc.require: I6P0I9
2387 */
2388 HWTEST_F(DistributedSchedServiceTest, ConnectRemoteAbility002, TestSize.Level3)
2389 {
2390 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 start" << std::endl;
2391 OHOS::AAFwk::Want want;
2392 want.SetElementName("", "ohos.demo.bundleName", "abilityName");
2393 const sptr<IRemoteObject> connect;
2394 int32_t ret = DistributedSchedService::GetInstance().ConnectRemoteAbility(want, connect, 1, 1, 1);
2395 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2396 DTEST_LOG << "DistributedSchedServiceTest ConnectRemoteAbility002 end" << std::endl;
2397 }
2398
2399 /**
2400 * @tc.name: TryConnectRemoteAbility001
2401 * @tc.desc: call TryConnectRemoteAbility
2402 * @tc.type: FUNC
2403 * @tc.require: I6P0I9
2404 */
2405 HWTEST_F(DistributedSchedServiceTest, TryConnectRemoteAbility001, TestSize.Level3)
2406 {
2407 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 start" << std::endl;
2408 std::string remoteDeviceId = "remoteDeviceId";
2409 OHOS::AAFwk::Want want;
2410 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
2411 sptr<IRemoteObject> connect;
2412 CallerInfo callerInfo;
2413 int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
2414 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2415 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility001 end" << std::endl;
2416 }
2417
2418 /**
2419 * @tc.name: TryConnectRemoteAbility002
2420 * @tc.desc: call TryConnectRemoteAbility
2421 * @tc.type: FUNC
2422 * @tc.require: I6P0I9
2423 */
2424 HWTEST_F(DistributedSchedServiceTest, TryConnectRemoteAbility002, TestSize.Level3)
2425 {
2426 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility002 start" << std::endl;
2427 std::string remoteDeviceId = "remoteDeviceId";
2428 OHOS::AAFwk::Want want;
2429 want.SetElementName(remoteDeviceId, "ohos.demo.bundleName", "abilityName");
2430 sptr<IRemoteObject> connect;
2431 CallerInfo callerInfo;
2432 int32_t ret = DistributedSchedService::GetInstance().TryConnectRemoteAbility(want, connect, callerInfo);
2433 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
2434 DTEST_LOG << "DistributedSchedServiceTest TryConnectRemoteAbility002 end" << std::endl;
2435 }
2436
2437 /**
2438 * @tc.name: StopRemoteExtensionAbility_001
2439 * @tc.desc: StopRemoteExtensionAbility with uninitialized params, return INVALID_PARAMETERS_ERR.
2440 * @tc.type: FUNC
2441 */
2442 HWTEST_F(DistributedSchedServiceTest, StopRemoteExtensionAbility_001, TestSize.Level3)
2443 {
2444 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_001 start" << std::endl;
2445 AAFwk::Want want;
2446 int32_t callerUid = 0;
2447 uint32_t accessToken = 0;
2448 int32_t extensionType = 3;
2449 std::string deviceId;
2450 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
2451 AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
2452 "com.ohos.distributedmusicplayer.MainAbility");
2453 want.SetElement(element);
2454 EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
2455 extensionType), INVALID_PARAMETERS_ERR);
2456 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_001 end" << std::endl;
2457 }
2458
2459 /**
2460 * @tc.name: StopRemoteExtensionAbility_002
2461 * @tc.desc: StopRemoteExtensionAbility with empty want's deviceId, return INVALID_PARAMETERS_ERR.
2462 * @tc.type: FUNC
2463 */
2464 HWTEST_F(DistributedSchedServiceTest, StopRemoteExtensionAbility_002, TestSize.Level3)
2465 {
2466 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_002 start" << std::endl;
2467 AAFwk::Want want;
2468 int32_t callerUid = 0;
2469 uint32_t accessToken = 0;
2470 int32_t extensionType = 3;
2471 AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
2472 "com.ohos.distributedmusicplayer.MainAbility");
2473 want.SetElement(element);
2474 EXPECT_EQ(DistributedSchedService::GetInstance().StopRemoteExtensionAbility(want, callerUid, accessToken,
2475 extensionType), INVALID_PARAMETERS_ERR);
2476 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_002 end" << std::endl;
2477 }
2478
2479 /**
2480 * @tc.name: StopExtensionAbilityFromRemote_001
2481 * @tc.desc: StopExtensionAbilityFromRemote with uninitialized params, return INVALID_REMOTE_PARAMETERS_ERR.
2482 * @tc.type: FUNC
2483 */
2484 HWTEST_F(DistributedSchedServiceTest, StopExtensionAbilityFromRemote_001, TestSize.Level3)
2485 {
2486 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_001 start" << std::endl;
2487 sptr<IDistributedSched> proxy = GetDms();
2488 if (proxy == nullptr) {
2489 return;
2490 }
2491 AAFwk::Want remoteWant;
2492 std::string deviceId;
2493 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId);
2494 AppExecFwk::ElementName element(deviceId, "com.ohos.distributedmusicplayer",
2495 "com.ohos.distributedmusicplayer.MainAbility");
2496 remoteWant.SetElement(element);
2497 CallerInfo callerInfo;
2498 callerInfo.uid = 0;
2499 callerInfo.sourceDeviceId = "255.255.255.255";
2500 IDistributedSched::AccountInfo accountInfo;
2501 int32_t extensionType = 3;
2502 EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo,
2503 accountInfo, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
2504 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_001 end" << std::endl;
2505 }
2506
2507 /**
2508 * @tc.name: StopExtensionAbilityFromRemote_002
2509 * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return DMS_PERMISSION_DENIED.
2510 * @tc.type: FUNC
2511 */
2512 HWTEST_F(DistributedSchedServiceTest, StopExtensionAbilityFromRemote_002, TestSize.Level3)
2513 {
2514 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_002 start" << std::endl;
2515 AAFwk::Want remoteWant;
2516 AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
2517 "com.ohos.distributedmusicplayer.MainAbility");
2518 remoteWant.SetElement(element);
2519 CallerInfo callerInfo;
2520 callerInfo.uid = 0;
2521 callerInfo.sourceDeviceId = "255.255.255.255";
2522 IDistributedSched::AccountInfo accountInfo;
2523 int32_t extensionType = 3;
2524 EXPECT_EQ(DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(remoteWant, callerInfo,
2525 accountInfo, extensionType), INVALID_REMOTE_PARAMETERS_ERR);
2526 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_002 end" << std::endl;
2527 }
2528
2529 /**
2530 * @tc.name: StopExtensionAbilityFromRemote_003
2531 * @tc.desc: StopExtensionAbilityFromRemote with empty want's deviceId, return INVALID_REMOTE_PARAMETERS_ERR.
2532 * @tc.type: FUNC
2533 */
2534 HWTEST_F(DistributedSchedServiceTest, StopExtensionAbilityFromRemote_003, TestSize.Level3)
2535 {
2536 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_003 start" << std::endl;
2537 sptr<IDistributedSched> proxy = GetDms();
2538 if (proxy == nullptr) {
2539 return;
2540 }
2541 AAFwk::Want remoteWant;
2542 AppExecFwk::ElementName element("abcdefg123456", "com.ohos.distributedmusicplayer",
2543 "com.ohos.distributedmusicplayer.MainAbility");
2544 remoteWant.SetElement(element);
2545 CallerInfo callerInfo;
2546 callerInfo.uid = 0;
2547 callerInfo.sourceDeviceId = "255.255.255.255";
2548 IDistributedSched::AccountInfo accountInfo;
2549 int32_t extensionType = 3;
2550 EXPECT_EQ(proxy->StopExtensionAbilityFromRemote(remoteWant, callerInfo,
2551 accountInfo, extensionType), IPC_STUB_UNKNOW_TRANS_ERR);
2552 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_003 end" << std::endl;
2553 }
2554
2555 /**
2556 * @tc.name: StopExtensionAbilityFromRemote_004
2557 * @tc.desc: call StopExtensionAbilityFromRemote
2558 * @tc.type: FUNC
2559 * @tc.require: I6YLV1
2560 */
2561 HWTEST_F(DistributedSchedServiceTest, StopExtensionAbilityFromRemote_004, TestSize.Level3)
2562 {
2563 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_004 start" << std::endl;
2564 AAFwk::Want want;
2565 std::string localDeviceId;
2566 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2567 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
2568 ABILITY_NAME);
2569 want.SetElement(element);
2570 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
2571 AppExecFwk::AbilityInfo abilityInfo;
2572 abilityInfo.permissions.clear();
2573 sptr<IRemoteObject> connect = new MockDistributedSched();
2574 CallerInfo callerInfo;
2575 callerInfo.uid = 0;
2576 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2577 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
2578 EXPECT_TRUE(result);
2579 IDistributedSched::AccountInfo accountInfo;
2580 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
2581 int32_t extensionType = 3;
2582 int ret = DistributedSchedService::GetInstance().StopExtensionAbilityFromRemote(want, callerInfo,
2583 accountInfo, extensionType);
2584 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
2585 DTEST_LOG << "DistributedSchedServiceTest StopExtensionAbilityFromRemote_004 end" << std::endl;
2586 }
2587
2588 /**
2589 * @tc.name: StopRemoteExtensionAbility_003
2590 * @tc.desc: call StopRemoteExtensionAbility
2591 * @tc.type: FUNC
2592 * @tc.require: I6YLV1
2593 */
2594 HWTEST_F(DistributedSchedServiceTest, StopRemoteExtensionAbility_003, TestSize.Level3)
2595 {
2596 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_003 start" << std::endl;
2597 sptr<IDistributedSched> proxy = GetDms();
2598 if (proxy == nullptr) {
2599 return;
2600 }
2601 AAFwk::Want want;
2602 std::string localDeviceId;
2603 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2604 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
2605 ABILITY_NAME);
2606 want.SetElement(element);
2607 int32_t extensionType = 3;
2608 int result = proxy->StopRemoteExtensionAbility(want, 0, 0, extensionType);
2609 EXPECT_EQ(result, DMS_PERMISSION_DENIED);
2610 DTEST_LOG << "DistributedSchedServiceTest StopRemoteExtensionAbility_003 end" << std::endl;
2611 }
2612
2613 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
2614 /**
2615 * @tc.name: StartRemoteShareForm_003
2616 * @tc.desc: call StartAbilityFromRemote with dms
2617 * @tc.type: FUNC
2618 * @tc.require: I76THI
2619 */
2620 HWTEST_F(DistributedSchedServiceTest, StartRemoteShareForm_003, TestSize.Level1)
2621 {
2622 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_003 start" << std::endl;
2623 /**
2624 * @tc.steps: step1. call StartAbilityFromRemote when remoteDeviceId is valid.
2625 */
2626 const std::string remoteDeviceId = "123456";
2627 const OHOS::AppExecFwk::FormShareInfo formShareInfo {};
2628 int32_t result = DistributedSchedService::GetInstance().StartRemoteShareForm(remoteDeviceId, formShareInfo);
2629 EXPECT_EQ(result, GET_REMOTE_DMS_FAIL);
2630 DTEST_LOG << "DistributedSchedServiceTest StartRemoteShareForm_003 end" << std::endl;
2631 }
2632 #endif
2633
2634 /**
2635 * @tc.name: GetConnectComponentList_001
2636 * @tc.desc: call GetConnectComponentList
2637 * @tc.type: FUNC
2638 * @tc.require: I76THI
2639 */
2640 HWTEST_F(DistributedSchedServiceTest, GetConnectComponentList_001, TestSize.Level1)
2641 {
2642 DTEST_LOG << "DistributedSchedServiceTest GetConnectComponentList_001 start" << std::endl;
2643 /**
2644 * @tc.steps: step1. call GetConnectComponentList when iter.second is empty.
2645 */
2646 sptr<IRemoteObject> connect = new MockDistributedSched();
2647 std::list<ConnectAbilitySession> sessionsList;
2648 std::vector<std::string> distributedComponents;
2649 {
2650 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
2651 DistributedSchedService::GetInstance().distributedConnectAbilityMap_.clear();
2652 DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
2653 }
2654 DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
2655 EXPECT_TRUE(distributedComponents.empty());
2656 /**
2657 * @tc.steps: step2. call GetConnectComponentList when iter.second is not empty.
2658 */
2659 CallerInfo callerInfo;
2660 ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
2661 sessionsList.emplace_back(connectAbilitySession);
2662 {
2663 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
2664 DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
2665 }
2666 DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
2667 EXPECT_FALSE(distributedComponents.empty());
2668 /**
2669 * @tc.steps: step3. call GetConnectComponentList when connectAbilityMap_ is not empty.
2670 */
2671 distributedComponents.clear();
2672 ConnectInfo connectInfo;
2673 {
2674 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
2675 DistributedSchedService::GetInstance().connectAbilityMap_[connect] = connectInfo;
2676 }
2677 DistributedSchedService::GetInstance().GetConnectComponentList(distributedComponents);
2678 EXPECT_FALSE(distributedComponents.empty());
2679 DTEST_LOG << "DistributedSchedServiceTest GetConnectComponentList_001 end" << std::endl;
2680 }
2681
2682 /**
2683 * @tc.name: GetCallComponentList_001
2684 * @tc.desc: call GetCallComponentList
2685 * @tc.type: FUNC
2686 * @tc.require: I76THI
2687 */
2688 HWTEST_F(DistributedSchedServiceTest, GetCallComponentList_001, TestSize.Level1)
2689 {
2690 DTEST_LOG << "DistributedSchedServiceTest GetCallComponentList_001 start" << std::endl;
2691 /**
2692 * @tc.steps: step1. call GetCallComponentList when iter.second is empty.
2693 */
2694 sptr<IRemoteObject> connect = new MockDistributedSched();
2695 std::list<ConnectAbilitySession> sessionsList;
2696 std::vector<std::string> distributedComponents;
2697 {
2698 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
2699 DistributedSchedService::GetInstance().callerMap_.clear();
2700 DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
2701 }
2702 DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
2703 EXPECT_TRUE(distributedComponents.empty());
2704 /**
2705 * @tc.steps: step2. call GetCallComponentList when iter.second is not empty.
2706 */
2707 CallerInfo callerInfo;
2708 ConnectAbilitySession connectAbilitySession("sourceDeviceId", "destinationDeviceId", callerInfo);
2709 sessionsList.emplace_back(connectAbilitySession);
2710 {
2711 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().callerLock_);
2712 DistributedSchedService::GetInstance().callerMap_[connect] = sessionsList;
2713 }
2714 DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
2715 EXPECT_FALSE(distributedComponents.empty());
2716 /**
2717 * @tc.steps: step3. call GetCallComponentList when calleeMap_ is not empty.
2718 */
2719 distributedComponents.clear();
2720 ConnectInfo connectInfo;
2721 {
2722 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
2723 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
2724 }
2725 DistributedSchedService::GetInstance().GetCallComponentList(distributedComponents);
2726 EXPECT_FALSE(distributedComponents.empty());
2727 DTEST_LOG << "DistributedSchedServiceTest GetCallComponentList_001 end" << std::endl;
2728 }
2729
2730 /**
2731 * @tc.name: SaveConnectToken_001
2732 * @tc.desc: call SaveConnectToken
2733 * @tc.type: FUNC
2734 * @tc.require: I76THI
2735 */
2736 HWTEST_F(DistributedSchedServiceTest, SaveConnectToken_001, TestSize.Level3)
2737 {
2738 DTEST_LOG << "DistributedSchedServiceTest SaveConnectToken_001 start" << std::endl;
2739 AAFwk::Want want;
2740 std::string localDeviceId;
2741 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2742 AppExecFwk::ElementName element(localDeviceId, BUNDLE_NAME,
2743 ABILITY_NAME);
2744 sptr<IRemoteObject> connect = new MockDistributedSched();
2745 /**
2746 * @tc.steps: step1. call SaveConnectToken
2747 * @tc.expected: step1. SaveConnectToken return token_
2748 */
2749 int32_t token = 0;
2750 {
2751 std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
2752 token = DistributedSchedService::GetInstance().token_.load();
2753 }
2754 int32_t result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
2755 EXPECT_EQ(result, token + 1);
2756 /**
2757 * @tc.steps: step2. call SaveConnectToken when tToken > MAX_TOKEN_NUM
2758 * @tc.expected: step2. SaveConnectToken return 1
2759 */
2760 {
2761 std::lock_guard<std::mutex> tokenLock(DistributedSchedService::GetInstance().tokenMutex_);
2762 DistributedSchedService::GetInstance().token_.store(MAX_TOKEN_NUM);
2763 }
2764 result = DistributedSchedService::GetInstance().SaveConnectToken(want, connect);
2765 EXPECT_EQ(result, 1);
2766 DTEST_LOG << "DistributedSchedServiceTest SaveConnectToken_001 end" << std::endl;
2767 }
2768
2769 /**
2770 * @tc.name: StartRemoteAbilityByCall_001
2771 * @tc.desc: call StartRemoteAbilityByCall
2772 * @tc.type: FUNC
2773 * @tc.require: I76THI
2774 */
2775 HWTEST_F(DistributedSchedServiceTest, StartRemoteAbilityByCall_001, TestSize.Level3)
2776 {
2777 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbilityByCall_001 start" << std::endl;
2778 AAFwk::Want want;
2779 int32_t callerUid = 0;
2780 int32_t callerPid = 0;
2781 uint32_t accessToken = 0;
2782 AppExecFwk::ElementName element("remoteDeviceId", "com.ohos.distributedmusicplayer",
2783 "com.ohos.distributedmusicplayer.MainAbility");
2784 want.SetElement(element);
2785 sptr<IRemoteObject> connect = new MockDistributedSched();
2786 int32_t result = DistributedSchedService::GetInstance().StartRemoteAbilityByCall(want,
2787 connect, callerUid, callerPid, accessToken);
2788 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
2789 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbilityByCall_001 end" << std::endl;
2790 }
2791
2792 /**
2793 * @tc.name: ReleaseAbilityFromRemote_001
2794 * @tc.desc: call ReleaseAbilityFromRemote
2795 * @tc.type: FUNC
2796 * @tc.require: I76THI
2797 */
2798 HWTEST_F(DistributedSchedServiceTest, ReleaseAbilityFromRemote_001, TestSize.Level3)
2799 {
2800 DTEST_LOG << "DistributedSchedServiceTest ReleaseAbilityFromRemote_001 start" << std::endl;
2801 sptr<IRemoteObject> connect = new MockDistributedSched();
2802 AAFwk::Want want;
2803 AppExecFwk::ElementName element;
2804 CallerInfo callerInfo;
2805 /**
2806 * @tc.steps: step1. call ReleaseAbilityFromRemote when callerInfo.sourceDeviceId is empty.
2807 * @tc.expected: step1. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
2808 */
2809 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
2810 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
2811 /**
2812 * @tc.steps: step2. call ReleaseAbilityFromRemote when localDeviceId == callerInfo.sourceDeviceId.
2813 * @tc.expected: step2. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
2814 */
2815 std::string localDeviceId;
2816 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId);
2817 callerInfo.sourceDeviceId = localDeviceId;
2818 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
2819 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
2820 /**
2821 * @tc.steps: step3. call ReleaseAbilityFromRemote when itConnect == calleeMap_.end().
2822 * @tc.expected: step3. ReleaseAbilityFromRemote return INVALID_REMOTE_PARAMETERS_ERR
2823 */
2824 {
2825 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
2826 DistributedSchedService::GetInstance().calleeMap_.clear();
2827 }
2828 callerInfo.sourceDeviceId = "sourceDeviceId";
2829 result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
2830 EXPECT_EQ(result, INVALID_REMOTE_PARAMETERS_ERR);
2831 DTEST_LOG << "DistributedSchedServiceTest ReleaseAbilityFromRemote_001 end" << std::endl;
2832 }
2833
2834 /**
2835 * @tc.name: ReleaseAbilityFromRemote_002
2836 * @tc.desc: call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
2837 * @tc.type: FUNC
2838 * @tc.require: I76THI
2839 */
2840 HWTEST_F(DistributedSchedServiceTest, ReleaseAbilityFromRemote_002, TestSize.Level3)
2841 {
2842 DTEST_LOG << "DistributedSchedServiceTest ReleaseAbilityFromRemote_002 start" << std::endl;
2843 /**
2844 * @tc.steps: step1. call ReleaseAbilityFromRemote when itConnect != calleeMap_.end().
2845 */
2846 sptr<IRemoteObject> connect = new MockDistributedSched();
2847 AAFwk::Want want;
2848 AppExecFwk::ElementName element;
2849 CallerInfo callerInfo;
2850 callerInfo.sourceDeviceId = "sourceDeviceId";
2851 ConnectInfo connectInfo;
2852 {
2853 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().calleeLock_);
2854 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
2855 }
2856 int32_t result = DistributedSchedService::GetInstance().ReleaseAbilityFromRemote(connect, element, callerInfo);
2857 EXPECT_NE(result, ERR_OK);
2858 /**
2859 * @tc.steps: step2. call ProcessConnectDied when connectSessionsList is empty.
2860 */
2861 std::list<ConnectAbilitySession> sessionsList;
2862 {
2863 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().distributedLock_);
2864 DistributedSchedService::GetInstance().distributedConnectAbilityMap_[connect] = sessionsList;
2865 }
2866 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
2867 /**
2868 * @tc.steps: step3. call ProcessConnectDied when sessionsList is empty.
2869 */
2870 DistributedSchedService::GetInstance().ProcessConnectDied(connect);
2871 DTEST_LOG << "DistributedSchedServiceTest ReleaseAbilityFromRemote_002 end" << std::endl;
2872 }
2873
2874 /**
2875 * @tc.name: NotifyProcessDiedFromRemote_001
2876 * @tc.desc: call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
2877 * @tc.type: FUNC
2878 * @tc.require: I76THI
2879 */
2880 HWTEST_F(DistributedSchedServiceTest, NotifyProcessDiedFromRemote_001, TestSize.Level3)
2881 {
2882 DTEST_LOG << "DistributedSchedServiceTest NotifyProcessDiedFromRemote_001 start" << std::endl;
2883 /**
2884 * @tc.steps: step1. call NotifyProcessDiedFromRemote when sourceDeviceId == sourceDeviceId.
2885 */
2886 sptr<IRemoteObject> connect = new MockDistributedSched();
2887 ConnectInfo connectInfo;
2888 connectInfo.callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2889 connectInfo.callerInfo.uid = 0;
2890 connectInfo.callerInfo.pid = 0;
2891 connectInfo.callerInfo.callerType = 0;
2892 {
2893 std::lock_guard<std::mutex> autoLock(DistributedSchedService::GetInstance().connectLock_);
2894 DistributedSchedService::GetInstance().calleeMap_[connect] = connectInfo;
2895 }
2896 CallerInfo callerInfo;
2897 callerInfo.sourceDeviceId = LOCAL_DEVICEID;
2898 callerInfo.uid = 0;
2899 callerInfo.pid = 0;
2900 callerInfo.callerType = 0;
2901 int32_t result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
2902 EXPECT_EQ(result, ERR_OK);
2903 /**
2904 * @tc.steps: step2. call NotifyProcessDiedFromRemote when sourceDeviceId != sourceDeviceId.
2905 */
2906 callerInfo.sourceDeviceId = REMOTE_DEVICEID;
2907 result = DistributedSchedService::GetInstance().NotifyProcessDiedFromRemote(callerInfo);
2908 EXPECT_EQ(result, ERR_OK);
2909
2910 /**
2911 * @tc.steps: step3. call ProcessFreeInstallOffline when dmsCallbackTask_ is not empty.
2912 */
2913 DistributedSchedService::GetInstance().dmsCallbackTask_ = make_shared<DmsCallbackTask>();
2914 DistributedSchedService::GetInstance().ProcessCalleeOffline("deviceId");
2915 DTEST_LOG << "DistributedSchedServiceTest NotifyProcessDiedFromRemote_001 end" << std::endl;
2916 }
2917
2918 /**
2919 * @tc.name: SetCallerInfo_001
2920 * @tc.desc: call SetCallerInfo
2921 * @tc.type: FUNC
2922 * @tc.require: I76THI
2923 */
2924 HWTEST_F(DistributedSchedServiceTest, SetCallerInfo_001, TestSize.Level3)
2925 {
2926 DTEST_LOG << "DistributedSchedServiceTest SetCallerInfo_001 start" << std::endl;
2927 /**
2928 * @tc.steps: step1. call SetCallerInfo with invalid parameters.
2929 */
2930 CallerInfo callerInfo;
2931 int32_t result = DistributedSchedService::GetInstance().SetCallerInfo(0, LOCAL_DEVICEID, 0, callerInfo);
2932 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
2933 /**
2934 * @tc.steps: step2. call OnRemoteDied.
2935 */
2936 const wptr<IRemoteObject> remote;
2937 CallerDeathRecipient callerDeathRecipient;
2938 callerDeathRecipient.OnRemoteDied(remote);
2939 DTEST_LOG << "DistributedSchedServiceTest StartRemoteAbilityByCall_001 end" << std::endl;
2940 }
2941
2942 /**
2943 * @tc.name: StartRemoteFreeInstall_001
2944 * @tc.desc: call StartRemoteFreeInstall
2945 * @tc.type: FUNC
2946 * @tc.require: I76THI
2947 */
2948 HWTEST_F(DistributedSchedServiceTest, StartRemoteFreeInstall_001, TestSize.Level3)
2949 {
2950 DTEST_LOG << "DistributedSchedServiceTest StartRemoteFreeInstall_001 start" << std::endl;
2951 AAFwk::Want want;
2952 AppExecFwk::ElementName element("devicdId", "com.ohos.distributedmusicplayer",
2953 "com.ohos.distributedmusicplayer.MainAbility");
2954 want.SetElement(element);
2955 auto callback = GetDSchedService();
2956 int32_t result = DistributedSchedService::GetInstance().StartRemoteFreeInstall(want, 0, 0, 0, callback);
2957 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
2958 DTEST_LOG << "DistributedSchedServiceTest StartRemoteFreeInstall_001 end" << std::endl;
2959 }
2960
2961 /**
2962 * @tc.name: NotifyCompleteFreeInstall_001
2963 * @tc.desc: call NotifyCompleteFreeInstall
2964 * @tc.type: FUNC
2965 * @tc.require: I76THI
2966 */
2967 HWTEST_F(DistributedSchedServiceTest, NotifyCompleteFreeInstall_001, TestSize.Level3)
2968 {
2969 DTEST_LOG << "DistributedSchedServiceTest NotifyCompleteFreeInstall_001 start" << std::endl;
2970 /**
2971 * @tc.steps: step1. call NotifyCompleteFreeInstall when resultCode is not ERR_OK.
2972 */
2973 IDistributedSched::FreeInstallInfo info;
2974 int32_t result = DistributedSchedService::GetInstance().NotifyCompleteFreeInstall(info, 1, -1);
2975 EXPECT_NE(result, ERR_OK);
2976 /**
2977 * @tc.steps: step2. call ProcessCallResult.
2978 */
2979 sptr<IRemoteObject> connect = new MockDistributedSched();
2980 DistributedSchedService::GetInstance().ProcessCallResult(connect, connect);
2981 DTEST_LOG << "DistributedSchedServiceTest NotifyCompleteFreeInstall_001 end" << std::endl;
2982 }
2983 } // namespace DistributedSchedule
2984 } // namespace OHOS