1 /*
2 * Copyright (c) 2022-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 "distributed_sched_adapter_test.h"
17 #include "distributed_sched_test_util.h"
18 #include "dtbschedmgr_log.h"
19 #include "mock_remote_stub.h"
20 #include "snapshot.h"
21 #include "test_log.h"
22
23 using namespace testing;
24 using namespace testing::ext;
25
26 namespace OHOS {
27 namespace DistributedSchedule {
SetUpTestCase()28 void DistributedSchedAdapterTest::SetUpTestCase()
29 {
30 DTEST_LOG << "DistributedSchedAdapterTest::SetUpTestCase" << std::endl;
31 }
32
TearDownTestCase()33 void DistributedSchedAdapterTest::TearDownTestCase()
34 {
35 DTEST_LOG << "DistributedSchedAdapterTest::TearDownTestCase" << std::endl;
36 }
37
TearDown()38 void DistributedSchedAdapterTest::TearDown()
39 {
40 DTEST_LOG << "DistributedSchedAdapterTest::TearDown" << std::endl;
41 }
42
SetUp()43 void DistributedSchedAdapterTest::SetUp()
44 {
45 distributedSchedAdapter_ = std::make_shared<DistributedSchedAdapter>();
46 distributedSchedAdapter_->Init();
47 DTEST_LOG << "DistributedSchedAdapterTest::SetUp" << std::endl;
48 }
49
50 /**
51 * @tc.name: Init_001
52 * @tc.desc: dmsAdapterHandler_ is not nullptr
53 * @tc.type: FUNC
54 * @tc.require: I60TOK
55 */
56 HWTEST_F(DistributedSchedAdapterTest, Init_001, TestSize.Level3)
57 {
58 DTEST_LOG << "DistributedSchedAdapterTest Init_001 begin" << std::endl;
59 ASSERT_NE(distributedSchedAdapter_, nullptr);
60 distributedSchedAdapter_->Init();
61 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
62 DTEST_LOG << "DistributedSchedAdapterTest Init_001 end" << std::endl;
63 }
64
65 /**
66 * @tc.name: ConnectAbility_001
67 * @tc.desc: invalid params
68 * @tc.type: FUNC
69 * @tc.require: I5WKCK
70 */
71 HWTEST_F(DistributedSchedAdapterTest, ConnectAbility_001, TestSize.Level3)
72 {
73 DTEST_LOG << "DistributedSchedAdapterTest ConnectAbility_001 begin" << std::endl;
74 ASSERT_NE(distributedSchedAdapter_, nullptr);
75 const OHOS::AAFwk::Want want;
76 const sptr<IRemoteObject> connect = nullptr;
77 const sptr<IRemoteObject> callerToken = nullptr;
78 int32_t result = distributedSchedAdapter_->ConnectAbility(want, connect, callerToken);
79 EXPECT_NE(result, ERR_OK);
80 DTEST_LOG << "DistributedSchedAdapterTest ConnectAbility_001 end" << std::endl;
81 }
82
83 /**
84 * @tc.name: DisconnectAbility_001
85 * @tc.desc: invalid params
86 * @tc.type: FUNC
87 * @tc.require: I5WKCK
88 */
89 HWTEST_F(DistributedSchedAdapterTest, DisconnectAbility_001, TestSize.Level3)
90 {
91 DTEST_LOG << "DistributedSchedAdapterTest DisconnectAbility_001 begin" << std::endl;
92 ASSERT_NE(distributedSchedAdapter_, nullptr);
93 const sptr<IRemoteObject> connect = nullptr;
94 int32_t result = distributedSchedAdapter_->DisconnectAbility(connect);
95 EXPECT_NE(result, ERR_OK);
96 DTEST_LOG << "DistributedSchedAdapterTest DisconnectAbility_001 end" << std::endl;
97 }
98
99 /**
100 * @tc.name: DeviceOnline_001
101 * @tc.desc: dmsAdapterHandler_ is nullptr
102 * @tc.type: FUNC
103 * @tc.require: I5WKCK
104 */
105 HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_001, TestSize.Level3)
106 {
107 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_001 begin" << std::endl;
108 ASSERT_NE(distributedSchedAdapter_, nullptr);
109 const std::string deviceId = "";
110 distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
111 distributedSchedAdapter_->DeviceOnline(deviceId);
112 EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
113 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_001 end" << std::endl;
114 }
115
116 /**
117 * @tc.name: DeviceOnline_002
118 * @tc.desc: deviceId is empty
119 * @tc.type: FUNC
120 * @tc.require: I5WKCK
121 */
122 HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_002, TestSize.Level3)
123 {
124 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_002 begin" << std::endl;
125 ASSERT_NE(distributedSchedAdapter_, nullptr);
126 const std::string deviceId = "";
127 distributedSchedAdapter_->DeviceOnline(deviceId);
128 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
129 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_002 end" << std::endl;
130 }
131
132 /**
133 * @tc.name: DeviceOnline_003
134 * @tc.desc: deviceId is not empty
135 * @tc.type: FUNC
136 * @tc.require: I5WKCK
137 */
138 HWTEST_F(DistributedSchedAdapterTest, DeviceOnline_003, TestSize.Level3)
139 {
140 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_003 begin" << std::endl;
141 ASSERT_NE(distributedSchedAdapter_, nullptr);
142 const std::string deviceId = "mockDeviceId";
143 distributedSchedAdapter_->DeviceOnline(deviceId);
144 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
145 DTEST_LOG << "DistributedSchedAdapterTest DeviceOnline_003 end" << std::endl;
146 }
147
148 /**
149 * @tc.name: DeviceOffline_001
150 * @tc.desc: dmsAdapterHandler_ is nullptr
151 * @tc.type: FUNC
152 * @tc.require: I5WKCK
153 */
154 HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_001, TestSize.Level3)
155 {
156 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_001 begin" << std::endl;
157 ASSERT_NE(distributedSchedAdapter_, nullptr);
158 const std::string deviceId = "";
159 distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
160 distributedSchedAdapter_->DeviceOffline(deviceId);
161 EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
162 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_001 end" << std::endl;
163 }
164
165 /**
166 * @tc.name: DeviceOffline_002
167 * @tc.desc: deviceId is empty
168 * @tc.type: FUNC
169 * @tc.require: I5WKCK
170 */
171 HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_002, TestSize.Level3)
172 {
173 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_002 begin" << std::endl;
174 ASSERT_NE(distributedSchedAdapter_, nullptr);
175 const std::string deviceId = "";
176 distributedSchedAdapter_->DeviceOffline(deviceId);
177 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
178 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_002 end" << std::endl;
179 }
180
181 /**
182 * @tc.name: DeviceOffline_003
183 * @tc.desc: deviceId is not empty
184 * @tc.type: FUNC
185 * @tc.require: I5WKCK
186 */
187 HWTEST_F(DistributedSchedAdapterTest, DeviceOffline_003, TestSize.Level3)
188 {
189 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_003 begin" << std::endl;
190 ASSERT_NE(distributedSchedAdapter_, nullptr);
191 const std::string deviceId = "mockDeviceId";
192 distributedSchedAdapter_->DeviceOffline(deviceId);
193 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
194 DTEST_LOG << "DistributedSchedAdapterTest DeviceOffline_003 end" << std::endl;
195 }
196
197 /**
198 * @tc.name: ProcessConnectDied_001
199 * @tc.desc: dmsAdapterHandler_ is nullptr
200 * @tc.type: FUNC
201 * @tc.require: I5WKCK
202 */
203 HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_001, TestSize.Level3)
204 {
205 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_001 begin" << std::endl;
206 ASSERT_NE(distributedSchedAdapter_, nullptr);
207 const sptr<IRemoteObject> connect = nullptr;
208 distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
209 distributedSchedAdapter_->ProcessConnectDied(connect);
210 EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
211 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_001 end" << std::endl;
212 }
213
214 /**
215 * @tc.name: ProcessConnectDied_002
216 * @tc.desc: connect is nullptr
217 * @tc.type: FUNC
218 * @tc.require: I5WKCK
219 */
220 HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_002, TestSize.Level3)
221 {
222 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_002 begin" << std::endl;
223 ASSERT_NE(distributedSchedAdapter_, nullptr);
224 const sptr<IRemoteObject> connect = nullptr;
225 distributedSchedAdapter_->ProcessConnectDied(connect);
226 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
227 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_002 end" << std::endl;
228 }
229
230 /**
231 * @tc.name: ProcessConnectDied_003
232 * @tc.desc: process connect died
233 * @tc.type: FUNC
234 * @tc.require: I60TOK
235 */
236 HWTEST_F(DistributedSchedAdapterTest, ProcessConnectDied_003, TestSize.Level3)
237 {
238 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_003 begin" << std::endl;
239 ASSERT_NE(distributedSchedAdapter_, nullptr);
240 const sptr<IRemoteObject> connect(new MockRemoteStub());
241 distributedSchedAdapter_->ProcessConnectDied(connect);
242 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
243 DTEST_LOG << "DistributedSchedAdapterTest ProcessConnectDied_003 end" << std::endl;
244 }
245
246 /**
247 * @tc.name: ProcessCalleeDied_001
248 * @tc.desc: dmsAdapterHandler_ is nullptr
249 * @tc.type: FUNC
250 * @tc.require: I5WKCK
251 */
252 HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_001, TestSize.Level3)
253 {
254 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_001 begin" << std::endl;
255 ASSERT_NE(distributedSchedAdapter_, nullptr);
256 const sptr<IRemoteObject> connect = nullptr;
257 distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
258 distributedSchedAdapter_->ProcessCalleeDied(connect);
259 EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
260 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_001 end" << std::endl;
261 }
262
263 /**
264 * @tc.name: ProcessCalleeDied_002
265 * @tc.desc: connect is nullptr
266 * @tc.type: FUNC
267 * @tc.require: I5WKCK
268 */
269 HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_002, TestSize.Level3)
270 {
271 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_002 begin" << std::endl;
272 ASSERT_NE(distributedSchedAdapter_, nullptr);
273 const sptr<IRemoteObject> connect = nullptr;
274 distributedSchedAdapter_->ProcessCalleeDied(connect);
275 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
276 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_002 end" << std::endl;
277 }
278
279 /**
280 * @tc.name: ProcessCalleeDied_003
281 * @tc.desc: processs callee died
282 * @tc.type: FUNC
283 * @tc.require: I60TOK
284 */
285 HWTEST_F(DistributedSchedAdapterTest, ProcessCalleeDied_003, TestSize.Level3)
286 {
287 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_003 begin" << std::endl;
288 const sptr<IRemoteObject> connect(new MockRemoteStub());
289 ASSERT_NE(distributedSchedAdapter_, nullptr);
290 distributedSchedAdapter_->ProcessCalleeDied(connect);
291 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
292 DTEST_LOG << "DistributedSchedAdapterTest ProcessCalleeDied_003 end" << std::endl;
293 }
294
295 /**
296 * @tc.name: ProcessCallerDied_001
297 * @tc.desc: dmsAdapterHandler_ is nullptr
298 * @tc.type: FUNC
299 * @tc.require: I5WKCK
300 */
301 HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_001, TestSize.Level3)
302 {
303 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_001 begin" << std::endl;
304 const sptr<IRemoteObject> connect = nullptr;
305 ASSERT_NE(distributedSchedAdapter_, nullptr);
306 int32_t deviceType = 0;
307 distributedSchedAdapter_->dmsAdapterHandler_ = nullptr;
308 distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
309 EXPECT_EQ(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
310 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_001 end" << std::endl;
311 }
312
313 /**
314 * @tc.name: ProcessCallerDied_002
315 * @tc.desc: connect is nullptr
316 * @tc.type: FUNC
317 * @tc.require: I5WKCK
318 */
319 HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_002, TestSize.Level3)
320 {
321 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_002 begin" << std::endl;
322 ASSERT_NE(distributedSchedAdapter_, nullptr);
323 const sptr<IRemoteObject> connect = nullptr;
324 int32_t deviceType = 0;
325 distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
326 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
327 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_002 end" << std::endl;
328 }
329
330 /**
331 * @tc.name: ProcessCallerDied_003
332 * @tc.desc: process caller died
333 * @tc.type: FUNC
334 * @tc.require: I60TOK
335 */
336 HWTEST_F(DistributedSchedAdapterTest, ProcessCallerDied_003, TestSize.Level3)
337 {
338 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_003 begin" << std::endl;
339 const sptr<IRemoteObject> connect(new MockRemoteStub());
340 ASSERT_NE(distributedSchedAdapter_, nullptr);
341 int32_t deviceType = 0;
342 distributedSchedAdapter_->ProcessCallerDied(connect, deviceType);
343 EXPECT_NE(distributedSchedAdapter_->dmsAdapterHandler_, nullptr);
344 DTEST_LOG << "DistributedSchedAdapterTest ProcessCallerDied_003 end" << std::endl;
345 }
346
347 /**
348 * @tc.name: GetLocalMissionInfos_001
349 * @tc.desc: numMissions is invalid
350 * @tc.type: FUNC
351 * @tc.require: I5WKCK
352 */
353 HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_001, TestSize.Level4)
354 {
355 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_001 begin" << std::endl;
356 ASSERT_NE(distributedSchedAdapter_, nullptr);
357 int32_t numMissions = -1;
358 std::vector<DstbMissionInfo> missionInfos;
359 DistributedSchedUtil::MockManageMissions();
360 int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
361 EXPECT_EQ(missionInfos.empty(), true);
362 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_001 end" << std::endl;
363 }
364
365 /**
366 * @tc.name: GetLocalMissionInfos_002
367 * @tc.desc: numMissions is zero
368 * @tc.type: FUNC
369 * @tc.require: I5WKCK
370 */
371 HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_002, TestSize.Level4)
372 {
373 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_002 begin" << std::endl;
374 ASSERT_NE(distributedSchedAdapter_, nullptr);
375 int32_t numMissions = 0;
376 std::vector<DstbMissionInfo> missionInfos;
377 DistributedSchedUtil::MockManageMissions();
378 int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
379 EXPECT_EQ(missionInfos.empty(), true);
380 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_002 end" << std::endl;
381 }
382
383 /**
384 * @tc.name: GetLocalMissionInfos_003
385 * @tc.desc: numMissions is not zero
386 * @tc.type: FUNC
387 * @tc.require: I5WKCK
388 */
389 HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionInfos_003, TestSize.Level4)
390 {
391 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_003 begin" << std::endl;
392 ASSERT_NE(distributedSchedAdapter_, nullptr);
393 int32_t numMissions = 10;
394 std::vector<DstbMissionInfo> missionInfos;
395 DistributedSchedUtil::MockManageMissions();
396 int32_t result = distributedSchedAdapter_->GetLocalMissionInfos(numMissions, missionInfos);
397 EXPECT_EQ(result, ERR_OK);
398 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionInfos_003 end" << std::endl;
399 }
400
401 /**
402 * @tc.name: RegisterMissionListener_001
403 * @tc.desc: listener is nullptr
404 * @tc.type: FUNC
405 * @tc.require: I5WKCK
406 */
407 HWTEST_F(DistributedSchedAdapterTest, RegisterMissionListener_001, TestSize.Level4)
408 {
409 DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_001 begin" << std::endl;
410 ASSERT_NE(distributedSchedAdapter_, nullptr);
411 const sptr<DistributedMissionChangeListener> listener = nullptr;
412 int32_t result = distributedSchedAdapter_->RegisterMissionListener(listener);
413 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
414 DTEST_LOG << "DistributedSchedAdapterTest RegisterMissionListener_001 end" << std::endl;
415 }
416
417 /**
418 * @tc.name: UnRegisterMissionListener_001
419 * @tc.desc: listener is nullptr
420 * @tc.type: FUNC
421 * @tc.require: I5WKCK
422 */
423 HWTEST_F(DistributedSchedAdapterTest, UnRegisterMissionListener_001, TestSize.Level4)
424 {
425 DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_001 begin" << std::endl;
426 const sptr<IRemoteObject> connect(new MockRemoteStub());
427 ASSERT_NE(distributedSchedAdapter_, nullptr);
428 distributedSchedAdapter_->ProcessCallResult(nullptr, connect);
429 const sptr<DistributedMissionChangeListener> listener = nullptr;
430 int32_t result = distributedSchedAdapter_->UnRegisterMissionListener(listener);
431 EXPECT_EQ(result, INVALID_PARAMETERS_ERR);
432 DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_001 end" << std::endl;
433 }
434
435 /**
436 * @tc.name: UnRegisterMissionListener_002
437 * @tc.desc: listener is nullptr
438 * @tc.type: FUNC
439 * @tc.require: I5WKCK
440 */
441 HWTEST_F(DistributedSchedAdapterTest, UnRegisterMissionListener_002, TestSize.Level4)
442 {
443 DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_002 begin" << std::endl;
444 const sptr<IRemoteObject> connect(new MockRemoteStub());
445 ASSERT_NE(distributedSchedAdapter_, nullptr);
446 distributedSchedAdapter_->ProcessCallResult(connect, connect);
447 const sptr<DistributedMissionChangeListener> listener(new DistributedMissionChangeListener());
448 int32_t result = distributedSchedAdapter_->UnRegisterMissionListener(listener);
449 EXPECT_NE(result, INVALID_PARAMETERS_ERR);
450 DTEST_LOG << "DistributedSchedAdapterTest UnRegisterMissionListener_002 end" << std::endl;
451 }
452
453 /**
454 * @tc.name: GetLocalMissionSnapshotInfo_001
455 * @tc.desc: networkId is invalid
456 * @tc.type: FUNC
457 * @tc.require: I5WKCK
458 */
459 HWTEST_F(DistributedSchedAdapterTest, GetLocalMissionSnapshotInfo_001, TestSize.Level4)
460 {
461 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionSnapshotInfo_001 begin" << std::endl;
462 ASSERT_NE(distributedSchedAdapter_, nullptr);
463 distributedSchedAdapter_->ProcessCallResult(nullptr, nullptr);
464 const std::string networkId = "invalidNetworkId";
465 int32_t missionId = 0;
466 AAFwk::MissionSnapshot missionSnapshot;
467 int32_t result = distributedSchedAdapter_->GetLocalMissionSnapshotInfo(networkId, missionId, missionSnapshot);
468 EXPECT_NE(result, ERR_OK);
469 DTEST_LOG << "DistributedSchedAdapterTest GetLocalMissionSnapshotInfo_001 end" << std::endl;
470 }
471 }
472 }