1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "dsched_continue_manager_test.h"
17
18 #include "datetime_ex.h"
19
20 #include "dtbschedmgr_device_info_storage.h"
21 #include "distributed_sched_test_util.h"
22 #include "test_log.h"
23 #include "mock_distributed_sched.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27 using namespace OHOS::DistributedHardware;
28
29 namespace OHOS {
30 namespace DistributedSchedule {
31
32 namespace {
33 const std::string LOCAL_DEVICEID = "localdeviceid";
34 const std::string REMOTE_DEVICEID = "remotedeviceid";
35 const std::string CONTINUETYPE = "continueType";
36 const std::string BASEDIR = "/data/service/el1/public/database/DistributedSchedule";
37 constexpr int32_t MISSION_ID = 1;
38 const int32_t WAITTIME = 2000;
39 const std::string BUNDLE_NAME = "com.ohos.permissionmanager";
40 }
41
SetUpTestCase()42 void DSchedContinueManagerTest::SetUpTestCase()
43 {
44 mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
45 const std::string pkgName = "DBinderBus_PermissionTest" + std::to_string(getprocpid());
46 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
47 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
48 dmsStoreMock = std::make_shared<MockDmsMgrDeviceInfoStore>();
49 DmsMgrDeviceInfoStore::dmsStore = dmsStoreMock;
50 DTEST_LOG << "DSchedContinueManagerTest::SetUpTestCase" << std::endl;
51 }
52
TearDownTestCase()53 void DSchedContinueManagerTest::TearDownTestCase()
54 {
55 (void)remove(BASEDIR.c_str());
56 DmsMgrDeviceInfoStore::dmsStore = nullptr;
57 dmsStoreMock = nullptr;
58 DTEST_LOG << "DSchedContinueManagerTest::TearDownTestCase" << std::endl;
59 }
60
TearDown()61 void DSchedContinueManagerTest::TearDown()
62 {
63 usleep(WAITTIME);
64 DTEST_LOG << "DSchedContinueManagerTest::TearDown" << std::endl;
65 }
66
SetUp()67 void DSchedContinueManagerTest::SetUp()
68 {
69 usleep(WAITTIME);
70 DTEST_LOG << "DSchedContinueManagerTest::SetUp" << std::endl;
71 }
72
OnRemoteDied()73 void DSchedContinueManagerTest::DeviceInitCallBack::OnRemoteDied()
74 {
75 }
76
GetDSchedService() const77 sptr<IRemoteObject> DSchedContinueManagerTest::GetDSchedService() const
78 {
79 sptr<IRemoteObject> dsched(new MockDistributedSched());
80 return dsched;
81 }
82
CreateObject()83 std::shared_ptr<DSchedContinue> DSchedContinueManagerTest::CreateObject()
84 {
85 int32_t subServiceType = 0;
86 int32_t direction = 0;
87 sptr<IRemoteObject> callback = nullptr;
88 DSchedContinueInfo continueInfo;
89 std::shared_ptr<DSchedContinue> dContinue = std::make_shared<DSchedContinue>(subServiceType, direction,
90 callback, continueInfo);
91 dContinue->Init();
92 return dContinue;
93 }
94
95 /**
96 * @tc.name: Init_001
97 * @tc.desc: test Init func
98 * @tc.type: FUNC
99 */
HWTEST_F(DSchedContinueManagerTest, Init_001, TestSize.Level3)100 HWTEST_F(DSchedContinueManagerTest, Init_001, TestSize.Level3)
101 {
102 DTEST_LOG << "DSchedContinueManagerTest Init_001 begin" << std::endl;
103 DSchedContinueManager::GetInstance().Init();
104 std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler =
105 DSchedContinueManager::GetInstance().eventHandler_;
106 EXPECT_NE(eventHandler, nullptr);
107 DTEST_LOG << "DSchedContinueManagerTest Init_001 end" << std::endl;
108 }
109
110 /**
111 * @tc.name: ContinueMission_001
112 * @tc.desc: test ContinueMission func
113 * @tc.type: FUNC
114 */
HWTEST_F(DSchedContinueManagerTest, ContinueMission_001, TestSize.Level3)115 HWTEST_F(DSchedContinueManagerTest, ContinueMission_001, TestSize.Level3)
116 {
117 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_001 begin" << std::endl;
118 auto callback = GetDSchedService();
119 OHOS::AAFwk::WantParams wantParams;
120 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
121 int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
122 callback, wantParams);
123 EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
124 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_001 end" << std::endl;
125 }
126
127 /**
128 * @tc.name: ContinueMission_002
129 * @tc.desc: test ContinueMission func
130 * @tc.type: FUNC
131 */
HWTEST_F(DSchedContinueManagerTest, ContinueMission_002, TestSize.Level3)132 HWTEST_F(DSchedContinueManagerTest, ContinueMission_002, TestSize.Level3)
133 {
134 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_002 begin" << std::endl;
135 OHOS::AAFwk::WantParams wantParams;
136 auto callback = GetDSchedService();
137 DSchedContinueManager::GetInstance().HandleContinueMission("", REMOTE_DEVICEID, MISSION_ID, callback, wantParams);
138 DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, "", MISSION_ID, callback, wantParams);
139 DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
140 nullptr, wantParams);
141
142 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true)).WillOnce(Return(true));
143 DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
144 callback, wantParams);
145
146 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
147 DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
148 callback, wantParams);
149
150 int32_t ret = DSchedContinueManager::GetInstance().ContinueMission("", REMOTE_DEVICEID, MISSION_ID,
151 callback, wantParams);
152 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
153
154 ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, "", MISSION_ID,
155 nullptr, wantParams);
156 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
157
158 ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
159 nullptr, wantParams);
160 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
161 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_002 end" << std::endl;
162 }
163
164 /**
165 * @tc.name: ContinueMission_003
166 * @tc.desc: test ContinueMission func
167 * @tc.type: FUNC
168 */
HWTEST_F(DSchedContinueManagerTest, ContinueMission_003, TestSize.Level3)169 HWTEST_F(DSchedContinueManagerTest, ContinueMission_003, TestSize.Level3)
170 {
171 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_003 begin" << std::endl;
172 DistributedSchedUtil::MockPermission();
173 OHOS::AAFwk::WantParams wantParams;
174 int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(
175 DSchedContinueInfo("", BUNDLE_NAME, "", BUNDLE_NAME, CONTINUETYPE),
176 nullptr, wantParams);
177 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
178
179 ret = DSchedContinueManager::GetInstance().ContinueMission(
180 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, "", BUNDLE_NAME, CONTINUETYPE),
181 nullptr, wantParams);
182 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
183
184 ret = DSchedContinueManager::GetInstance().ContinueMission(
185 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
186 nullptr, wantParams);
187 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
188
189 auto callback = GetDSchedService();
190 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
191 ret = DSchedContinueManager::GetInstance().ContinueMission(
192 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
193 callback, wantParams);
194 EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
195
196 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
197 ret = DSchedContinueManager::GetInstance().ContinueMission(
198 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
199 callback, wantParams);
200 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
201
202 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
203 ret = DSchedContinueManager::GetInstance().ContinueMission(
204 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
205 callback, wantParams);
206 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
207 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_003 end" << std::endl;
208 }
209
210 /**
211 * @tc.name: HandleContinueMission_001
212 * @tc.desc: test HandleContinueMission func
213 * @tc.type: FUNC
214 */
HWTEST_F(DSchedContinueManagerTest, HandleContinueMission_001, TestSize.Level3)215 HWTEST_F(DSchedContinueManagerTest, HandleContinueMission_001, TestSize.Level3)
216 {
217 DTEST_LOG << "DSchedContinueManagerTest HandleContinueMission_001 begin" << std::endl;
218 OHOS::AAFwk::WantParams wantParams;
219 auto callback = GetDSchedService();
220 DSchedContinueManager::GetInstance().HandleContinueMission(
221 DSchedContinueInfo("", BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
222 callback, wantParams);
223 DSchedContinueManager::GetInstance().HandleContinueMission(
224 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, "", BUNDLE_NAME, CONTINUETYPE),
225 callback, wantParams);
226 DSchedContinueManager::GetInstance().HandleContinueMission(
227 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
228 nullptr, wantParams);
229
230 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
231 DSchedContinueManager::GetInstance().HandleContinueMission(
232 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
233 callback, wantParams);
234 DTEST_LOG << "DSchedContinueManagerTest HandleContinueMission_001 end" << std::endl;
235 }
236
237 /**
238 * @tc.name: SetTimeOut_001
239 * @tc.desc: test SetTimeOut func
240 * @tc.type: FUNC
241 */
HWTEST_F(DSchedContinueManagerTest, SetTimeOut_001, TestSize.Level3)242 HWTEST_F(DSchedContinueManagerTest, SetTimeOut_001, TestSize.Level3)
243 {
244 DTEST_LOG << "DSchedContinueManagerTest SetTimeOut_001 begin" << std::endl;
245 DSchedContinueInfo info;
246 int32_t timeout = 0;
247 DSchedContinueManager::GetInstance().continues_.clear();
248 DSchedContinueManager::GetInstance().SetTimeOut(info, timeout);
249 EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
250 DTEST_LOG << "DSchedContinueManagerTest SetTimeOut_001 end" << std::endl;
251 }
252
253 /**
254 * @tc.name: StartContinuation_001
255 * @tc.desc: test StartContinuation func
256 * @tc.type: FUNC
257 */
HWTEST_F(DSchedContinueManagerTest, StartContinuation_001, TestSize.Level3)258 HWTEST_F(DSchedContinueManagerTest, StartContinuation_001, TestSize.Level3)
259 {
260 DTEST_LOG << "DSchedContinueManagerTest StartContinuation_001 begin" << std::endl;
261 OHOS::AAFwk::Want want;
262 int32_t missionId = 0;
263 int32_t callerUid = 0;
264 int32_t status = 0;
265 uint32_t accessToken = 0;
266 int32_t ret1 = DSchedContinueManager::GetInstance().StartContinuation(want, missionId,
267 callerUid, status, accessToken);
268 EXPECT_EQ(ret1, INVALID_REMOTE_PARAMETERS_ERR);
269 DTEST_LOG << "DSchedContinueManagerTest StartContinuation_001 end" << std::endl;
270 }
271
272 /**
273 * @tc.name: CheckContinuationLimit_001
274 * @tc.desc: test CheckContinuationLimit func
275 * @tc.type: FUNC
276 */
HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_001, TestSize.Level3)277 HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_001, TestSize.Level3)
278 {
279 DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_001 begin" << std::endl;
280 int32_t direction = 0;
281 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
282 int32_t ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
283 direction);
284 EXPECT_EQ(ret, OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET);
285 DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_001 end" << std::endl;
286 }
287
288 /**
289 * @tc.name: GetContinueInfo_001
290 * @tc.desc: test GetContinueInfo func
291 * @tc.type: FUNC
292 */
HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_001, TestSize.Level3)293 HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_001, TestSize.Level3)
294 {
295 DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_001 begin" << std::endl;
296 std::string localDeviceId = "localdeviceid";
297 std::string remoteDeviceId = "remotedeviceid";
298 int32_t ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
299 EXPECT_EQ(ret, ERR_OK);
300 DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_001 end" << std::endl;
301 }
302
303 /**
304 * @tc.name: GetContinueInfo_002
305 * @tc.desc: test GetContinueInfo func
306 * @tc.type: FUNC
307 */
HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_002, TestSize.Level3)308 HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_002, TestSize.Level3)
309 {
310 DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_002 begin" << std::endl;
311 DSchedContinueManager::GetInstance().OnShutdown(1, true);
312
313 DSchedContinueManager::GetInstance().OnShutdown(1, false);
314
315 DSchedContinueManager::GetInstance().OnShutdown(1, false);
316
317 DSchedContinueInfo info;
318 std::shared_ptr<DSchedContinue> dContinue = CreateObject();
319 std::string localDeviceId = "localdeviceid";
320 std::string remoteDeviceId = "remotedeviceid";
321 DSchedContinueManager::GetInstance().continues_[info] = dContinue;
322 int32_t ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
323 EXPECT_EQ(ret, ERR_OK);
324
325 DSchedContinueManager::GetInstance().continues_.clear();
326 DSchedContinueManager::GetInstance().continues_[info] = nullptr;
327 ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
328 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
329 DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_002 end" << std::endl;
330 }
331
332 /**
333 * @tc.name: HandleNotifyCompleteContinuation_001
334 * @tc.desc: test HandleNotifyCompleteContinuation func
335 * @tc.type: FUNC
336 */
HWTEST_F(DSchedContinueManagerTest, HandleNotifyCompleteContinuation_001, TestSize.Level3)337 HWTEST_F(DSchedContinueManagerTest, HandleNotifyCompleteContinuation_001, TestSize.Level3)
338 {
339 DTEST_LOG << "DSchedContinueManagerTest HandleNotifyCompleteContinuation_001 begin" << std::endl;
340 std::u16string devId;
341 int32_t missionId = 0;
342 std::string callerBundleName;
343 DSchedContinueManager::GetInstance().continues_.clear();
344 DSchedContinueManager::GetInstance().HandleNotifyCompleteContinuation(devId, missionId, false, callerBundleName);
345
346 DSchedContinueInfo info;
347 DSchedContinueManager::GetInstance().continues_[info] = nullptr;
348 DSchedContinueManager::GetInstance().HandleNotifyCompleteContinuation(devId, missionId, false, callerBundleName);
349 bool ret = DSchedContinueManager::GetInstance().continues_.empty();
350 EXPECT_EQ(ret, false);
351 DTEST_LOG << "DSchedContinueManagerTest HandleNotifyCompleteContinuation_001 end" << std::endl;
352 }
353
354 /**
355 * @tc.name: NotifyCompleteContinuation_001
356 * @tc.desc: test NotifyCompleteContinuation func
357 * @tc.type: FUNC
358 */
HWTEST_F(DSchedContinueManagerTest, NotifyCompleteContinuation_001, TestSize.Level3)359 HWTEST_F(DSchedContinueManagerTest, NotifyCompleteContinuation_001, TestSize.Level3)
360 {
361 DTEST_LOG << "DSchedContinueManagerTest NotifyCompleteContinuation_001 begin" << std::endl;
362 std::u16string devId;
363 int32_t sessionId = 0;
364 bool isSuccess = false;
365 std::string callerBundleName;
366 DSchedContinueManager::GetInstance().Init();
367 int32_t ret = DSchedContinueManager::GetInstance().NotifyCompleteContinuation(devId,
368 sessionId, isSuccess, callerBundleName);
369 EXPECT_EQ(ret, ERR_OK);
370 DTEST_LOG << "DSchedContinueManagerTest NotifyCompleteContinuation_001 end" << std::endl;
371 }
372
373 /**
374 * @tc.name: OnContinueEnd_001
375 * @tc.desc: test OnContinueEnd func
376 * @tc.type: FUNC
377 */
HWTEST_F(DSchedContinueManagerTest, OnContinueEnd_001, TestSize.Level3)378 HWTEST_F(DSchedContinueManagerTest, OnContinueEnd_001, TestSize.Level3)
379 {
380 DTEST_LOG << "DSchedContinueManagerTest OnContinueEnd_001 begin" << std::endl;
381 DSchedContinueInfo info(LOCAL_DEVICEID, "sourceBundleName", REMOTE_DEVICEID, "sinkBundleName",
382 "continueType");
383 DSchedContinueManager::GetInstance().UnInit();
384 int32_t ret = DSchedContinueManager::GetInstance().OnContinueEnd(info);
385 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
386
387 DSchedContinueManager::GetInstance().Init();
388
389 ret = DSchedContinueManager::GetInstance().OnContinueEnd(info);
390 EXPECT_EQ(ret, ERR_OK);
391 DTEST_LOG << "DSchedContinueManagerTest OnContinueEnd_001 end" << std::endl;
392 }
393
394 /**
395 * @tc.name: HandleContinueEnd_001
396 * @tc.desc: test HandleContinueEnd func
397 * @tc.type: FUNC
398 */
HWTEST_F(DSchedContinueManagerTest, HandleContinueEnd_001, TestSize.Level3)399 HWTEST_F(DSchedContinueManagerTest, HandleContinueEnd_001, TestSize.Level3)
400 {
401 DTEST_LOG << "DSchedContinueManagerTest HandleContinueEnd_001 begin" << std::endl;
402 DSchedContinueInfo info(LOCAL_DEVICEID, "sourceBundleName", REMOTE_DEVICEID, "sinkBundleName",
403 "continueType");
404 DSchedContinueManager::GetInstance().RemoveTimeout(info);
405
406 DSchedContinueManager::GetInstance().Init();
407 DSchedContinueManager::GetInstance().RemoveTimeout(info);
408
409 DSchedContinueManager::GetInstance().continues_.clear();
410 DSchedContinueManager::GetInstance().HandleContinueEnd(info);
411 int32_t ret = DSchedContinueManager::GetInstance().continues_.empty();
412 EXPECT_EQ(ret, true);
413
414 std::shared_ptr<DSchedContinue> ptr = nullptr;
415 DSchedContinueManager::GetInstance().continues_[info] = ptr;
416 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
417 DSchedContinueManager::GetInstance().HandleContinueEnd(info);
418
419 DSchedContinueManager::GetInstance().continues_[info] = ptr;
420 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
421 DSchedContinueManager::GetInstance().HandleContinueEnd(info);
422 EXPECT_EQ(DSchedContinueManager::GetInstance().cntSource_, 0);
423 DTEST_LOG << "DSchedContinueManagerTest HandleContinueEnd_001 end" << std::endl;
424 }
425
426 /**
427 * @tc.name: GetDSchedContinueByWant_001
428 * @tc.desc: test GetDSchedContinueByWant func
429 * @tc.type: FUNC
430 */
HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_001, TestSize.Level3)431 HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_001, TestSize.Level3)
432 {
433 DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_001 begin" << std::endl;
434 OHOS::AAFwk::Want want;
435 int32_t missionId = 0;
436 DSchedContinueManager::GetInstance().continues_.clear();
437 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
438 auto ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
439 EXPECT_EQ(ret, nullptr);
440 DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_001 end" << std::endl;
441 }
442
443 /**
444 * @tc.name: NotifyTerminateContinuation_001
445 * @tc.desc: test NotifyTerminateContinuation func
446 * @tc.type: FUNC
447 */
HWTEST_F(DSchedContinueManagerTest, NotifyTerminateContinuation_001, TestSize.Level3)448 HWTEST_F(DSchedContinueManagerTest, NotifyTerminateContinuation_001, TestSize.Level3)
449 {
450 DTEST_LOG << "DSchedContinueManagerTest NotifyTerminateContinuation_001 begin" << std::endl;
451 int32_t missionId = 0;
452 int32_t sessionId = 0;
453 DSchedContinueManager::GetInstance().continues_.clear();
454 DSchedContinueManager::GetInstance().HandleDataRecv(sessionId, nullptr);
455 DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
456 EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
457 DTEST_LOG << "DSchedContinueManagerTest NotifyTerminateContinuation_001 end" << std::endl;
458 }
459
460 /**
461 * @tc.name: GetFirstBundleName_001
462 * @tc.desc: test GetFirstBundleName func
463 * @tc.type: FUNC
464 */
HWTEST_F(DSchedContinueManagerTest, GetFirstBundleName_001, TestSize.Level3)465 HWTEST_F(DSchedContinueManagerTest, GetFirstBundleName_001, TestSize.Level3)
466 {
467 DTEST_LOG << "DSchedContinueManagerTest GetFirstBundleName_001 begin" << std::endl;
468 DSchedContinueInfo info;
469 std::string firstBundleName;
470 std::string bundleName;
471 std::string deviceId;
472 bool ret = DSchedContinueManager::GetInstance().GetFirstBundleName(info, firstBundleName, bundleName, deviceId);
473 EXPECT_EQ(ret, false);
474 DTEST_LOG << "DSchedContinueManagerTest GetFirstBundleName_001 end" << std::endl;
475 }
476
477 /**
478 * @tc.name: ContinueMission_004
479 * @tc.desc: test ContinueMission func
480 * @tc.type: FUNC
481 */
HWTEST_F(DSchedContinueManagerTest, ContinueMission_004, TestSize.Level3)482 HWTEST_F(DSchedContinueManagerTest, ContinueMission_004, TestSize.Level3)
483 {
484 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 begin" << std::endl;
485 auto callback = GetDSchedService();
486 OHOS::AAFwk::WantParams wantParams;
487 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
488 int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
489 callback, wantParams);
490 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
491
492 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
493 ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
494 callback, wantParams);
495 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
496
497 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
498 ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
499 callback, wantParams);
500 EXPECT_EQ(ret, INVALID_REMOTE_PARAMETERS_ERR);
501 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 end" << std::endl;
502 }
503
504 /**
505 * @tc.name: ContinueMission_005
506 * @tc.desc: test ContinueMission func
507 * @tc.type: FUNC
508 */
HWTEST_F(DSchedContinueManagerTest, ContinueMission_005, TestSize.Level3)509 HWTEST_F(DSchedContinueManagerTest, ContinueMission_005, TestSize.Level3)
510 {
511 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_005 begin" << std::endl;
512 auto callback = GetDSchedService();
513 OHOS::AAFwk::WantParams wantParams;
514 int32_t timeout = 0;
515 DSchedContinueManager::GetInstance().WaitAllConnectDecision(CONTINUE_SOURCE,
516 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE), timeout);
517
518 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
519 int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(
520 DSchedContinueInfo(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE),
521 callback, wantParams);
522 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
523 DTEST_LOG << "DSchedContinueManagerTest ContinueMission_005 end" << std::endl;
524 }
525
526 /**
527 * @tc.name: GetDSchedContinueByWant_002
528 * @tc.desc: test GetDSchedContinueByWant func
529 * @tc.type: FUNC
530 */
HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_002, TestSize.Level3)531 HWTEST_F(DSchedContinueManagerTest, GetDSchedContinueByWant_002, TestSize.Level3)
532 {
533 DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_002 begin" << std::endl;
534 OHOS::AAFwk::Want want;
535 int32_t missionId = 0;
536 int32_t callerUid = 0;
537 int32_t status = 0;
538 uint32_t accessToken = 0;
539 DSchedContinueInfo info(LOCAL_DEVICEID, BUNDLE_NAME, REMOTE_DEVICEID, BUNDLE_NAME, CONTINUETYPE);
540 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
541 DSchedContinueManager::GetInstance().HandleStartContinuation(want, missionId, callerUid, status, accessToken);
542
543 DSchedContinueManager::GetInstance().continues_.clear();
544 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
545 auto ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
546 EXPECT_EQ(ret, nullptr);
547
548 std::shared_ptr<DSchedContinue> dContinue = CreateObject();
549 DSchedContinueManager::GetInstance().continues_[info] = nullptr;
550 DSchedContinueManager::GetInstance().continues_[info] = dContinue;
551
552 DSchedContinueManager::GetInstance().NotifyTerminateContinuation(missionId);
553 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(true));
554 ret = DSchedContinueManager::GetInstance().GetDSchedContinueByWant(want, missionId);
555 EXPECT_NE(ret, nullptr);
556 DTEST_LOG << "DSchedContinueManagerTest GetDSchedContinueByWant_002 end" << std::endl;
557 }
558
559 /**
560 * @tc.name: CheckContinuationLimit_002
561 * @tc.desc: test CheckContinuationLimit func
562 * @tc.type: FUNC
563 */
HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_002, TestSize.Level3)564 HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_002, TestSize.Level3)
565 {
566 DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_002 begin" << std::endl;
567 int32_t direction = 0;
568 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(Return(false));
569 int32_t ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
570 direction);
571 EXPECT_EQ(ret, GET_LOCAL_DEVICE_ERR);
572
573 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(LOCAL_DEVICEID), Return(true)));
574 DSchedContinueManager::GetInstance().cntSink_.store(MAX_CONCURRENT_SINK);
575 ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
576 direction);
577 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
578
579 EXPECT_CALL(*dmsStoreMock, GetLocalDeviceId(_)).WillOnce(DoAll(SetArgReferee<0>(REMOTE_DEVICEID), Return(true)));
580 DSchedContinueManager::GetInstance().cntSink_.store(0);
581 ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID,
582 direction);
583 EXPECT_EQ(ret, INVALID_PARAMETERS_ERR);
584 DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_002 end" << std::endl;
585 }
586
587 /**
588 * @tc.name: NotifyContinueDataRecv_001
589 * @tc.desc: test NotifyContinueDataRecv func
590 * @tc.type: FUNC
591 */
HWTEST_F(DSchedContinueManagerTest, NotifyContinueDataRecv_001, TestSize.Level3)592 HWTEST_F(DSchedContinueManagerTest, NotifyContinueDataRecv_001, TestSize.Level3)
593 {
594 DTEST_LOG << "DSchedContinueManagerTest NotifyContinueDataRecv_001 begin" << std::endl;
595 int32_t sessionId = 0;
596 int32_t command = 0;
597 std::string jsonStr = "jsonStr";
598 std::shared_ptr<DSchedDataBuffer> dataBuffer = nullptr;
599 DSchedContinueManager::GetInstance().continues_.clear();
600 DSchedContinueManager::GetInstance().NotifyContinueDataRecv(sessionId, command, jsonStr, dataBuffer);
601 EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
602 DTEST_LOG << "DSchedContinueManagerTest NotifyContinueDataRecv_001 end" << std::endl;
603 }
604 }
605 }
606