1 /*
2 * Copyright (c) 2022-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
16 #include "continuation_manager_test.h"
17
18 #include "distributed_ability_manager_client.h"
19 #include "distributed_sched_test_util.h"
20 #include "dtbschedmgr_log.h"
21 #include "mock_remote_stub.h"
22 #include "test_log.h"
23
24 namespace OHOS {
25 namespace DistributedSchedule {
26 using namespace std;
27 using namespace testing;
28 using namespace testing::ext;
29 namespace {
30 constexpr int32_t INVALID_LEN = -1;
31 constexpr int32_t UNREGISTER_TOKEN = 10000;
32 constexpr int32_t TEST_TOKEN = 1000;
33 constexpr int32_t TEST_ACCESS_TOKEN = 10000000;
34 constexpr int32_t ERROR_CONNECT_STATUS = 10;
35 constexpr int32_t ERROR_CONTINUATION_MODE = 10;
36 constexpr uint32_t SELECTED_DEVICE_SIZE = 2;
37 constexpr uint32_t UNSELECTED_DEVICE_SIZE = 2;
38 const std::string TEST_DEVICE_ID = "test deviceId";
39 const std::string EMPTY_DEVICE_ID = "";
40 const std::string CALLBACK_TYPE1 = "deviceSelected";
41 const std::string CALLBACK_TYPE2 = "deviceUnselected";
42 const std::string INVALID_CALLBACK_TYPE = "deviceCancel";
43 const std::string SELECTED_DEVICE_ID1 = "selected deviceId1";
44 const std::string SELECTED_DEVICE_ID2 = "selected deviceId2";
45 const std::string SELECTED_DEVICE_ID3 = "selected deviceId3";
46 const std::string SELECTED_DEVICE_TYPE1 = "selected deviceType1";
47 const std::string SELECTED_DEVICE_TYPE2 = "selected deviceType2";
48 const std::string SELECTED_DEVICE_NAME1 = "selected deviceName1";
49 const std::string SELECTED_DEVICE_NAME2 = "selected deviceName2";
50 const std::string UNSELECTED_DEVICE_ID1 = "unselected deviceId1";
51 const std::string UNSELECTED_DEVICE_ID2 = "unselected deviceId2";
52 const std::string UNSELECTED_DEVICE_ID3 = "unselected deviceId3";
53 const std::string TEST_DEVICE_TYPE = "test deviceType";
54 const std::string TEST_TARGETBUNDLE = "test targetBundle";
55 const std::string TEST_DESCRIPTION = "test description";
56 const std::string TEST_FILTER = "test filter";
57 const std::string TEST_AUTHINFO = "test authInfo";
58 const std::u16string TEST_INPUT1 = u"test input1";
59 const std::u16string TEST_INPUT2 = u"test input2";
60 const std::u16string TEST_INVALID_REMOTEDESCRIPTOR = u"invalid remoteDescriptor";
61 const std::string TEST_INPUT3 = "test input1";
62 const std::string TEST_INPUT4 = "test input2";
63 const std::uint32_t INVALID_EVENT_DEVICE_CODE = 0;
64 }
65
OnDeviceConnect(const std::vector<ContinuationResult> & continuationResults)66 void DeviceSelectionNotifierTest::OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults)
67 {
68 EXPECT_EQ(SELECTED_DEVICE_SIZE, continuationResults.size());
69 for (size_t i = 0; i < continuationResults.size(); ++i) {
70 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceConnect selected deviceId:"<<
71 continuationResults[i].GetDeviceId() << std::endl;
72 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceConnect selected deviceType:" <<
73 continuationResults[i].GetDeviceType() << std::endl;
74 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceConnect selected deviceNane:" <<
75 continuationResults[i].GetDeviceName() << std::endl;
76 }
77 }
78
OnDeviceDisconnect(const std::vector<ContinuationResult> & continuationResults)79 void DeviceSelectionNotifierTest::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
80 {
81 EXPECT_EQ(UNSELECTED_DEVICE_SIZE, continuationResults.size());
82 for (size_t i = 0; i < continuationResults.size(); ++i) {
83 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceDisconnect selected deviceId:"<<
84 continuationResults[i].GetDeviceId() << std::endl;
85 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceDisconnect selected deviceType:" <<
86 continuationResults[i].GetDeviceType() << std::endl;
87 DTEST_LOG << "DeviceSelectionNotifierTest::OnDeviceDisconnect selected deviceNane:" <<
88 continuationResults[i].GetDeviceName() << std::endl;
89 }
90 }
91
SetUpTestCase()92 void ContinuationManagerTest::SetUpTestCase()
93 {
94 DTEST_LOG << "ContinuationManagerTest::SetUpTestCase" << std::endl;
95 }
96
TearDownTestCase()97 void ContinuationManagerTest::TearDownTestCase()
98 {
99 DTEST_LOG << "ContinuationManagerTest::TearDownTestCase" << std::endl;
100 }
101
SetUp()102 void ContinuationManagerTest::SetUp()
103 {
104 dtbabilitymgrService_ = new DistributedAbilityManagerService();
105 DTEST_LOG << "ContinuationManagerTest::SetUp" << std::endl;
106 }
107
TearDown()108 void ContinuationManagerTest::TearDown()
109 {
110 DTEST_LOG << "ContinuationManagerTest::TearDown" << std::endl;
111 }
112
113 /**
114 * @tc.name: RegisterTest_001
115 * @tc.desc: test register token
116 * @tc.type: FUNC
117 */
118 HWTEST_F(ContinuationManagerTest, RegisterTest_001, TestSize.Level1)
119 {
120 DTEST_LOG << "ContinuationManagerTest RegisterTest_001 start" << std::endl;
121 DistributedSchedUtil::MockPermission();
122 int32_t token1 = -1;
123 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token1);
124 DTEST_LOG << "result1:" << result1 << std::endl;
125 int32_t token2 = -1;
126 int32_t result2 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token2);
127 DTEST_LOG << "result2:" << result2 << std::endl;
128 EXPECT_EQ(ERR_OK, result1);
129 EXPECT_EQ(ERR_OK, result2);
130 EXPECT_EQ(1, token2 - token1);
131 DTEST_LOG << "ContinuationManagerTest RegisterTest_001 end" << std::endl;
132 }
133
134 /**
135 * @tc.name: RegisterTest_002
136 * @tc.desc: test register token with extra param
137 * @tc.type: FUNC
138 */
139 HWTEST_F(ContinuationManagerTest, RegisterTest_002, TestSize.Level1)
140 {
141 DTEST_LOG << "ContinuationManagerTest RegisterTest_002 start" << std::endl;
142 std::shared_ptr<ContinuationExtraParams> continuationExtraParams =
143 std::make_shared<ContinuationExtraParams>();
144 int32_t token1 = -1;
145 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(continuationExtraParams, token1);
146 DTEST_LOG << "result1:" << result1 << std::endl;
147 int32_t token2 = -1;
148 int32_t result2 = DistributedAbilityManagerClient::GetInstance().Register(continuationExtraParams, token2);
149 DTEST_LOG << "result2:" << result2 << std::endl;
150 EXPECT_EQ(ERR_OK, result1);
151 EXPECT_EQ(ERR_OK, result2);
152 EXPECT_EQ(1, token2 - token1);
153 DTEST_LOG << "ContinuationManagerTest RegisterTest_002 end" << std::endl;
154 }
155
156 /**
157 * @tc.name: UnregisterTest_001
158 * @tc.desc: test unregister token
159 * @tc.type: FUNC
160 */
161 HWTEST_F(ContinuationManagerTest, UnregisterTest_001, TestSize.Level1)
162 {
163 DTEST_LOG << "ContinuationManagerTest UnregisterTest_001 start" << std::endl;
164 int32_t token = -1;
165 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
166 DTEST_LOG << "result1:" << result1 << std::endl;
167 int32_t result2 = DistributedAbilityManagerClient::GetInstance().Unregister(token);
168 DTEST_LOG << "result2:" << result2 << std::endl;
169 EXPECT_EQ(ERR_OK, result1);
170 EXPECT_EQ(ERR_OK, result2);
171 DTEST_LOG << "ContinuationManagerTest UnregisterTest_001 end" << std::endl;
172 }
173
174 /**
175 * @tc.name: UnregisterTest_002
176 * @tc.desc: test unregister token with invalid token
177 * @tc.type: FUNC
178 */
179 HWTEST_F(ContinuationManagerTest, UnregisterTest_002, TestSize.Level1)
180 {
181 DTEST_LOG << "ContinuationManagerTest UnregisterTest_002 start" << std::endl;
182 int32_t result = DistributedAbilityManagerClient::GetInstance().Unregister(UNREGISTER_TOKEN);
183 DTEST_LOG << "result:" << result << std::endl;
184 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result);
185 DTEST_LOG << "ContinuationManagerTest UnregisterTest_002 end" << std::endl;
186 }
187
188 /**
189 * @tc.name: RegisterDeviceSelectionCallbackTest_001
190 * @tc.desc: test register device selection callback
191 * @tc.type: FUNC
192 */
193 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_001, TestSize.Level1)
194 {
195 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_001 start" << std::endl;
196 int32_t token = -1;
197 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
198 DTEST_LOG << "result1:" << result1 << std::endl;
199 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
200 int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
201 token, CALLBACK_TYPE1, notifier);
202 DTEST_LOG << "result2:" << result2 << std::endl;
203 int32_t result3 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
204 token, CALLBACK_TYPE2, notifier);
205 DTEST_LOG << "result3:" << result3 << std::endl;
206 EXPECT_EQ(ERR_OK, result1);
207 EXPECT_EQ(ERR_OK, result2);
208 EXPECT_EQ(ERR_OK, result3);
209 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_001 end" << std::endl;
210 }
211
212 /**
213 * @tc.name: RegisterDeviceSelectionCallbackTest_002
214 * @tc.desc: test register device selection callback with invalid token
215 * @tc.type: FUNC
216 */
217 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_002, TestSize.Level1)
218 {
219 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_002 start" << std::endl;
220 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
221 int32_t result1 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
222 UNREGISTER_TOKEN, CALLBACK_TYPE1, notifier);
223 DTEST_LOG << "result1:" << result1 << std::endl;
224 int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
225 UNREGISTER_TOKEN, CALLBACK_TYPE2, notifier);
226 DTEST_LOG << "result2:" << result2 << std::endl;
227 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result1);
228 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result2);
229 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_002 end" << std::endl;
230 }
231
232 /**
233 * @tc.name: RegisterDeviceSelectionCallbackTest_003
234 * @tc.desc: test register device selection callback with invalid callback type
235 * @tc.type: FUNC
236 */
237 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_003, TestSize.Level1)
238 {
239 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_003 start" << std::endl;
240 int32_t token = -1;
241 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
242 DTEST_LOG << "result1:" << result1 << std::endl;
243 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
244 int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
245 token, INVALID_CALLBACK_TYPE, notifier);
246 DTEST_LOG << "result2:" << result2 << std::endl;
247 int32_t result3 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
248 token, "", notifier);
249 DTEST_LOG << "result3:" << result3 << std::endl;
250 int32_t result4 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
251 token, INVALID_CALLBACK_TYPE, nullptr);
252 DTEST_LOG << "result4:" << result4 << std::endl;
253 EXPECT_EQ(ERR_OK, result1);
254 EXPECT_EQ(UNKNOWN_CALLBACK_TYPE, result2);
255 EXPECT_EQ(ERR_NULL_OBJECT, result3);
256 EXPECT_EQ(ERR_NULL_OBJECT, result4);
257 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_003 end" << std::endl;
258 }
259
260 /**
261 * @tc.name: RegisterDeviceSelectionCallbackTest_004
262 * @tc.desc: test dms deviceSelected callback called when device selection callback has registered.
263 * @tc.type: FUNC
264 */
265 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_004, TestSize.Level1)
266 {
267 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_004 start" << std::endl;
268 if (dtbabilitymgrService_ == nullptr) {
269 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
270 return;
271 }
272 int32_t token = -1;
273 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
274 DTEST_LOG << "result1:" << result1 << std::endl;
275 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
276 int32_t result2 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
277 token, CALLBACK_TYPE1, notifier);
278 DTEST_LOG << "result2:" << result2 << std::endl;
279 std::vector<ContinuationResult> continuationResults;
280 ContinuationResult continuationResult1;
281 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
282 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
283 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
284 ContinuationResult continuationResult2;
285 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
286 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
287 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
288 continuationResults.emplace_back(continuationResult1);
289 continuationResults.emplace_back(continuationResult2);
290 int32_t result3 = dtbabilitymgrService_->OnDeviceConnect(token, continuationResults);
291 DTEST_LOG << "result3:" << result3 << std::endl;
292 EXPECT_EQ(ERR_OK, result1);
293 EXPECT_EQ(ERR_OK, result2);
294 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
295 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_004 end" << std::endl;
296 }
297
298 /**
299 * @tc.name: RegisterDeviceSelectionCallbackTest_005
300 * @tc.desc: test dms deviceSelected callback called when device selection callback has not registered.
301 * @tc.type: FUNC
302 */
303 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_005, TestSize.Level1)
304 {
305 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_005 start" << std::endl;
306 if (dtbabilitymgrService_ == nullptr) {
307 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
308 return;
309 }
310 int32_t token = -1;
311 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
312 DTEST_LOG << "result1:" << result1 << std::endl;
313 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
314 int32_t result2 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
315 token, CALLBACK_TYPE2, notifier);
316 DTEST_LOG << "result2:" << result2 << std::endl;
317 std::vector<ContinuationResult> continuationResults;
318 ContinuationResult continuationResult1;
319 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
320 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
321 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
322 ContinuationResult continuationResult2;
323 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
324 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
325 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
326 continuationResults.emplace_back(continuationResult1);
327 continuationResults.emplace_back(continuationResult2);
328 int32_t result3 = dtbabilitymgrService_->OnDeviceConnect(token, continuationResults);
329 DTEST_LOG << "result3:" << result3 << std::endl;
330 EXPECT_EQ(ERR_OK, result1);
331 EXPECT_EQ(ERR_OK, result2);
332 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
333 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_005 end" << std::endl;
334 }
335
336 /**
337 * @tc.name: RegisterDeviceSelectionCallbackTest_006
338 * @tc.desc: test dms deviceUnselected callback called when device selection callback has registered.
339 * @tc.type: FUNC
340 */
341 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_006, TestSize.Level1)
342 {
343 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_006 start" << std::endl;
344 if (dtbabilitymgrService_ == nullptr) {
345 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
346 return;
347 }
348 int32_t token = -1;
349 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
350 DTEST_LOG << "result1:" << result1 << std::endl;
351 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
352 int32_t result2 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
353 token, CALLBACK_TYPE2, notifier);
354 DTEST_LOG << "result2:" << result2 << std::endl;
355 std::vector<ContinuationResult> continuationResults;
356 ContinuationResult continuationResult1;
357 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
358 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
359 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
360 ContinuationResult continuationResult2;
361 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
362 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
363 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
364 continuationResults.emplace_back(continuationResult1);
365 continuationResults.emplace_back(continuationResult2);
366 int32_t result3 = dtbabilitymgrService_->OnDeviceDisconnect(token, continuationResults);
367 DTEST_LOG << "result3:" << result3 << std::endl;
368 EXPECT_EQ(ERR_OK, result1);
369 EXPECT_EQ(ERR_OK, result2);
370 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
371 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_006 end" << std::endl;
372 }
373
374 /**
375 * @tc.name: RegisterDeviceSelectionCallbackTest_007
376 * @tc.desc: test dms deviceUnselected callback called when device selection callback has not registered.
377 * @tc.type: FUNC
378 */
379 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_007, TestSize.Level1)
380 {
381 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_007 start" << std::endl;
382 if (dtbabilitymgrService_ == nullptr) {
383 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
384 return;
385 }
386 int32_t token = -1;
387 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
388 DTEST_LOG << "result1:" << result1 << std::endl;
389 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
390 int32_t result2 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
391 token, CALLBACK_TYPE1, notifier);
392 DTEST_LOG << "result2:" << result2 << std::endl;
393 std::vector<ContinuationResult> continuationResults;
394 ContinuationResult continuationResult1;
395 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
396 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
397 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
398 ContinuationResult continuationResult2;
399 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
400 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
401 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
402 continuationResults.emplace_back(continuationResult1);
403 continuationResults.emplace_back(continuationResult2);
404 int32_t result3 = dtbabilitymgrService_->OnDeviceDisconnect(token, continuationResults);
405 DTEST_LOG << "result3:" << result3 << std::endl;
406 EXPECT_EQ(ERR_OK, result1);
407 EXPECT_EQ(ERR_OK, result2);
408 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
409 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_007 end" << std::endl;
410 }
411
412 /**
413 * @tc.name: RegisterDeviceSelectionCallbackTest_008
414 * @tc.desc: test dms callback called when device selection callback has not registered.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_008, TestSize.Level1)
418 {
419 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_008 start" << std::endl;
420 if (dtbabilitymgrService_ == nullptr) {
421 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
422 return;
423 }
424 int32_t token = -1;
425 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
426 DTEST_LOG << "result1:" << result1 << std::endl;
427 std::vector<ContinuationResult> continuationResults;
428 ContinuationResult continuationResult1;
429 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
430 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
431 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
432 ContinuationResult continuationResult2;
433 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
434 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
435 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
436 continuationResults.emplace_back(continuationResult1);
437 continuationResults.emplace_back(continuationResult2);
438 int32_t result2 = dtbabilitymgrService_->OnDeviceConnect(token, continuationResults);
439 DTEST_LOG << "result2:" << result2 << std::endl;
440 int32_t result3 = dtbabilitymgrService_->OnDeviceDisconnect(token, continuationResults);
441 DTEST_LOG << "result3:" << result3 << std::endl;
442 EXPECT_EQ(ERR_OK, result1);
443 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result2);
444 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
445 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_008 end" << std::endl;
446 }
447
448 /**
449 * @tc.name: RegisterDeviceSelectionCallbackTest_009
450 * @tc.desc: test dms callback called when token has not registered.
451 * @tc.type: FUNC
452 */
453 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_009, TestSize.Level1)
454 {
455 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_009 start" << std::endl;
456 if (dtbabilitymgrService_ == nullptr) {
457 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
458 return;
459 }
460 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
461 int32_t result1 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
462 UNREGISTER_TOKEN, CALLBACK_TYPE1, notifier);
463 DTEST_LOG << "result1:" << result1 << std::endl;
464 int32_t result2 = dtbabilitymgrService_->RegisterDeviceSelectionCallback(
465 UNREGISTER_TOKEN, CALLBACK_TYPE2, notifier);
466 DTEST_LOG << "result2:" << result2 << std::endl;
467 std::vector<ContinuationResult> continuationResults;
468 ContinuationResult continuationResult1;
469 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
470 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
471 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
472 ContinuationResult continuationResult2;
473 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
474 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
475 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
476 continuationResults.emplace_back(continuationResult1);
477 continuationResults.emplace_back(continuationResult2);
478 int32_t result3 = dtbabilitymgrService_->OnDeviceConnect(
479 UNREGISTER_TOKEN, continuationResults);
480 DTEST_LOG << "result3:" << result3 << std::endl;
481 int32_t result4 = dtbabilitymgrService_->OnDeviceDisconnect(UNREGISTER_TOKEN, continuationResults);
482 DTEST_LOG << "result4:" << result4 << std::endl;
483 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result1);
484 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result2);
485 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result3);
486 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result4);
487 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_009 end" << std::endl;
488 }
489
490 /**
491 * @tc.name: RegisterDeviceSelectionCallbackTest_010
492 * @tc.desc: test dms callback called when token and device selection callback has not registered.
493 * @tc.type: FUNC
494 */
495 HWTEST_F(ContinuationManagerTest, RegisterDeviceSelectionCallbackTest_010, TestSize.Level1)
496 {
497 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_010 start" << std::endl;
498 if (dtbabilitymgrService_ == nullptr) {
499 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
500 return;
501 }
502 std::vector<ContinuationResult> continuationResults;
503 ContinuationResult continuationResult1;
504 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
505 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
506 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
507 ContinuationResult continuationResult2;
508 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
509 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
510 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
511 continuationResults.emplace_back(continuationResult1);
512 continuationResults.emplace_back(continuationResult2);
513 int32_t result1 = dtbabilitymgrService_->OnDeviceConnect(
514 UNREGISTER_TOKEN, continuationResults);
515 DTEST_LOG << "result1:" << result1 << std::endl;
516 int32_t result2 = dtbabilitymgrService_->OnDeviceDisconnect(UNREGISTER_TOKEN, continuationResults);
517 DTEST_LOG << "result2:" << result2 << std::endl;
518 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result1);
519 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, result2);
520 DTEST_LOG << "ContinuationManagerTest RegisterDeviceSelectionCallbackTest_010 end" << std::endl;
521 }
522
523 /**
524 * @tc.name: UnregisterDeviceSelectionCallbackTest_001
525 * @tc.desc: test unregister device selection callback
526 * @tc.type: FUNC
527 */
528 HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_001, TestSize.Level1)
529 {
530 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_001 start" << std::endl;
531 int32_t token = -1;
532 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
533 DTEST_LOG << "result1:" << result1 << std::endl;
534 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
535 int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
536 token, CALLBACK_TYPE1, notifier);
537 DTEST_LOG << "result2:" << result2 << std::endl;
538 int32_t result3 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
539 token, CALLBACK_TYPE2, notifier);
540 DTEST_LOG << "result3:" << result3 << std::endl;
541 int32_t result4 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
542 token, CALLBACK_TYPE1);
543 DTEST_LOG << "result4:" << result4 << std::endl;
544 int32_t result5 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
545 token, CALLBACK_TYPE2);
546 DTEST_LOG << "result5:" << result5 << std::endl;
547 EXPECT_EQ(ERR_OK, result1);
548 EXPECT_EQ(ERR_OK, result2);
549 EXPECT_EQ(ERR_OK, result3);
550 EXPECT_EQ(ERR_OK, result4);
551 EXPECT_EQ(ERR_OK, result5);
552 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_001 end" << std::endl;
553 }
554
555 /**
556 * @tc.name: UnregisterDeviceSelectionCallbackTest_002
557 * @tc.desc: test unregister device selection callback that has not been registered
558 * @tc.type: FUNC
559 */
560 HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_002, TestSize.Level1)
561 {
562 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_002 start" << std::endl;
563 int32_t token = -1;
564 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
565 DTEST_LOG << "result1:" << result1 << std::endl;
566 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
567 token, CALLBACK_TYPE1);
568 DTEST_LOG << "result2:" << result2 << std::endl;
569 int32_t result3 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
570 token, CALLBACK_TYPE2);
571 DTEST_LOG << "result3:" << result3 << std::endl;
572 EXPECT_EQ(ERR_OK, result1);
573 EXPECT_EQ(CALLBACK_HAS_NOT_REGISTERED, result2);
574 EXPECT_EQ(CALLBACK_HAS_NOT_REGISTERED, result3);
575 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_002 end" << std::endl;
576 }
577
578 /**
579 * @tc.name: UnregisterDeviceSelectionCallbackTest_003
580 * @tc.desc: test register device selection callback with invalid token
581 * @tc.type: FUNC
582 */
583 HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_003, TestSize.Level1)
584 {
585 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_003 start" << std::endl;
586 int32_t result1 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
587 UNREGISTER_TOKEN, CALLBACK_TYPE1);
588 DTEST_LOG << "result1:" << result1 << std::endl;
589 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
590 UNREGISTER_TOKEN, CALLBACK_TYPE2);
591 DTEST_LOG << "result2:" << result2 << std::endl;
592 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result1);
593 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result2);
594 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_003 end" << std::endl;
595 }
596
597 /**
598 * @tc.name: UnregisterDeviceSelectionCallbackTest_004
599 * @tc.desc: test register device selection callback with invalid callback type
600 * @tc.type: FUNC
601 */
602 HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_004, TestSize.Level1)
603 {
604 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_004 start" << std::endl;
605 int32_t token = -1;
606 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
607 DTEST_LOG << "result1:" << result1 << std::endl;
608 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
609 token, INVALID_CALLBACK_TYPE);
610 DTEST_LOG << "result2:" << result2 << std::endl;
611 EXPECT_EQ(ERR_OK, result1);
612 EXPECT_EQ(UNKNOWN_CALLBACK_TYPE, result2);
613 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_004 end" << std::endl;
614 }
615
616 /**
617 * @tc.name: UnregisterDeviceSelectionCallbackTest_005
618 * @tc.desc: test register device selection callback with invalid param
619 * @tc.type: FUNC
620 */
621 HWTEST_F(ContinuationManagerTest, UnregisterDeviceSelectionCallbackTest_005, TestSize.Level1)
622 {
623 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_005 start" << std::endl;
624 int32_t token = -1;
625 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
626 DTEST_LOG << "result1:" << result1 << std::endl;
627 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UnregisterDeviceSelectionCallback(
628 token, "");
629 DTEST_LOG << "result2:" << result2 << std::endl;
630 EXPECT_EQ(ERR_OK, result1);
631 EXPECT_EQ(ERR_NULL_OBJECT, result2);
632 DTEST_LOG << "ContinuationManagerTest UnregisterDeviceSelectionCallbackTest_005 end" << std::endl;
633 }
634
635
636 /**
637 * @tc.name: StartDeviceManagerTest_001
638 * @tc.desc: test start device manager
639 * @tc.type: FUNC
640 */
641 HWTEST_F(ContinuationManagerTest, StartDeviceManagerTest_001, TestSize.Level1)
642 {
643 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_001 start" << std::endl;
644 if (dtbabilitymgrService_ == nullptr) {
645 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
646 return;
647 }
648 int32_t token = -1;
649 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
650 DTEST_LOG << "result1:" << result1 << std::endl;
651 int32_t result2 = dtbabilitymgrService_->StartDeviceManager(token);
652 DTEST_LOG << "result2:" << result2 << std::endl;
653 EXPECT_EQ(ERR_OK, result1);
654 EXPECT_EQ(CALLBACK_HAS_NOT_REGISTERED, result2);
655 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_001 end" << std::endl;
656 }
657
658 /**
659 * @tc.name: StartDeviceManagerTest_002
660 * @tc.desc: test start device manager with extra param
661 * @tc.type: FUNC
662 */
663 HWTEST_F(ContinuationManagerTest, StartDeviceManagerTest_002, TestSize.Level1)
664 {
665 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_002 start" << std::endl;
666 if (dtbabilitymgrService_ == nullptr) {
667 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
668 return;
669 }
670 int32_t token = -1;
671 int32_t result1 = dtbabilitymgrService_->Register(nullptr, token);
672 DTEST_LOG << "result1:" << result1 << std::endl;
673 std::shared_ptr<ContinuationExtraParams> continuationExtraParams =
674 std::make_shared<ContinuationExtraParams>();
675 int32_t result2 = dtbabilitymgrService_->StartDeviceManager(
676 token, continuationExtraParams);
677 DTEST_LOG << "result2:" << result2 << std::endl;
678 EXPECT_EQ(ERR_OK, result1);
679 EXPECT_EQ(CALLBACK_HAS_NOT_REGISTERED, result2);
680 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_002 end" << std::endl;
681 }
682
683 /**
684 * @tc.name: StartDeviceManagerTest_003
685 * @tc.desc: test start device manager with invalid token
686 * @tc.type: FUNC
687 */
688 HWTEST_F(ContinuationManagerTest, StartDeviceManagerTest_003, TestSize.Level1)
689 {
690 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_003 start" << std::endl;
691 int32_t result1 = DistributedAbilityManagerClient::GetInstance().StartDeviceManager(UNREGISTER_TOKEN);
692 DTEST_LOG << "result1:" << result1 << std::endl;
693 std::shared_ptr<ContinuationExtraParams> continuationExtraParams =
694 std::make_shared<ContinuationExtraParams>();
695 int32_t result2 = DistributedAbilityManagerClient::GetInstance().StartDeviceManager(
696 UNREGISTER_TOKEN, continuationExtraParams);
697 DTEST_LOG << "result2:" << result2 << std::endl;
698 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result1);
699 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result2);
700 DTEST_LOG << "ContinuationManagerTest StartDeviceManagerTest_003 end" << std::endl;
701 }
702
703 /**
704 * @tc.name: UpdateConnectStatusTest_001
705 * @tc.desc: test update connect status when device selection callback has registered.
706 * @tc.type: FUNC
707 */
708 HWTEST_F(ContinuationManagerTest, UpdateConnectStatusTest_001, TestSize.Level1)
709 {
710 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_001 start" << std::endl;
711 int32_t token = -1;
712 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
713 DTEST_LOG << "result1:" << result1 << std::endl;
714 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
715 int32_t result2 = DistributedAbilityManagerClient::GetInstance().RegisterDeviceSelectionCallback(
716 token, CALLBACK_TYPE1, notifier);
717 DTEST_LOG << "result2:" << result2 << std::endl;
718 std::string deviceId = TEST_DEVICE_ID;
719 DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
720 int32_t result3 = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
721 token, deviceId, deviceConnectStatus);
722 DTEST_LOG << "result3:" << result3 << std::endl;
723 EXPECT_EQ(ERR_OK, result1);
724 EXPECT_EQ(ERR_OK, result2);
725 EXPECT_EQ(ERR_OK, result3);
726 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_001 end" << std::endl;
727 }
728
729 /**
730 * @tc.name: UpdateConnectStatusTest_002
731 * @tc.desc: test update connect status when device selection callback has not registered.
732 * @tc.type: FUNC
733 */
734 HWTEST_F(ContinuationManagerTest, UpdateConnectStatusTest_002, TestSize.Level1)
735 {
736 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_002 start" << std::endl;
737 int32_t token = -1;
738 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
739 DTEST_LOG << "result1:" << result1 << std::endl;
740 std::string deviceId = TEST_DEVICE_ID;
741 DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
742 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
743 token, deviceId, deviceConnectStatus);
744 DTEST_LOG << "result2:" << result2 << std::endl;
745 EXPECT_EQ(ERR_OK, result1);
746 EXPECT_EQ(CALLBACK_HAS_NOT_REGISTERED, result2);
747 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_002 end" << std::endl;
748 }
749
750 /**
751 * @tc.name: UpdateConnectStatusTest_003
752 * @tc.desc: test update connect status with invalid token
753 * @tc.type: FUNC
754 */
755 HWTEST_F(ContinuationManagerTest, UpdateConnectStatusTest_003, TestSize.Level1)
756 {
757 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_003 start" << std::endl;
758 std::string deviceId = TEST_DEVICE_ID;
759 DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
760 int32_t result = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
761 UNREGISTER_TOKEN, deviceId, deviceConnectStatus);
762 DTEST_LOG << "result:" << result << std::endl;
763 EXPECT_EQ(TOKEN_HAS_NOT_REGISTERED, result);
764 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_003 end" << std::endl;
765 }
766
767 /**
768 * @tc.name: UpdateConnectStatusTest_004
769 * @tc.desc: test update connect status with empty deviceId
770 * @tc.type: FUNC
771 */
772 HWTEST_F(ContinuationManagerTest, UpdateConnectStatusTest_004, TestSize.Level1)
773 {
774 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_004 start" << std::endl;
775 int32_t token = -1;
776 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
777 DTEST_LOG << "result1:" << result1 << std::endl;
778 std::string deviceId = EMPTY_DEVICE_ID;
779 DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
780 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
781 token, deviceId, deviceConnectStatus);
782 DTEST_LOG << "result2:" << result2 << std::endl;
783 EXPECT_EQ(ERR_OK, result1);
784 EXPECT_EQ(ERR_NULL_OBJECT, result2);
785 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_004 end" << std::endl;
786 }
787
788 /**
789 * @tc.name: UpdateConnectStatusTest_005
790 * @tc.desc: test update connect status with invalid status
791 * @tc.type: FUNC
792 */
793 HWTEST_F(ContinuationManagerTest, UpdateConnectStatusTest_005, TestSize.Level1)
794 {
795 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_005 start" << std::endl;
796 int32_t token = -1;
797 int32_t result1 = DistributedAbilityManagerClient::GetInstance().Register(nullptr, token);
798 DTEST_LOG << "result1:" << result1 << std::endl;
799 std::string deviceId = TEST_DEVICE_ID;
800 int32_t result2 = DistributedAbilityManagerClient::GetInstance().UpdateConnectStatus(
801 token, deviceId, static_cast<DeviceConnectStatus>(ERROR_CONNECT_STATUS));
802 DTEST_LOG << "result2:" << result2 << std::endl;
803 EXPECT_EQ(ERR_OK, result1);
804 EXPECT_EQ(INVALID_CONNECT_STATUS, result2);
805 DTEST_LOG << "ContinuationManagerTest UpdateConnectStatusTest_005 end" << std::endl;
806 }
807
808 /**
809 * @tc.name: IsExceededRegisterMaxNumTest_001
810 * @tc.desc: test IsExceededRegisterMaxNum function.
811 * @tc.type: FUNC
812 */
813 HWTEST_F(ContinuationManagerTest, IsExceededRegisterMaxNumTest_001, TestSize.Level1)
814 {
815 DTEST_LOG << "ContinuationManagerTest IsExceededRegisterMaxNumTest_001 start" << std::endl;
816 if (dtbabilitymgrService_ == nullptr) {
817 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
818 return;
819 }
820 std::vector<int32_t> tokenVec;
821 tokenVec.emplace_back(TEST_TOKEN);
822 uint32_t accessToken = TEST_ACCESS_TOKEN;
823 dtbabilitymgrService_->tokenMap_[accessToken] = tokenVec;
824 bool result = dtbabilitymgrService_->IsExceededRegisterMaxNum(TEST_ACCESS_TOKEN);
825 DTEST_LOG << "result:" << result << std::endl;
826 EXPECT_EQ(false, result);
827 DTEST_LOG << "ContinuationManagerTest IsExceededRegisterMaxNumTest_001 end" << std::endl;
828 }
829
830 /**
831 * @tc.name: IsContinuationModeValidTest_001
832 * @tc.desc: test IsContinuationModeValid function with invalid continuation mode.
833 * @tc.type: FUNC
834 */
835 HWTEST_F(ContinuationManagerTest, IsContinuationModeValidTest_001, TestSize.Level1)
836 {
837 DTEST_LOG << "ContinuationManagerTest IsContinuationModeValidTest_001 start" << std::endl;
838 if (dtbabilitymgrService_ == nullptr) {
839 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
840 return;
841 }
842 ContinuationMode continuationMode = static_cast<ContinuationMode>(ERROR_CONTINUATION_MODE);
843 bool result = dtbabilitymgrService_->IsContinuationModeValid(continuationMode);
844 DTEST_LOG << "result:" << result << std::endl;
845 EXPECT_EQ(false, result);
846 DTEST_LOG << "ContinuationManagerTest IsContinuationModeValidTest_001 end" << std::endl;
847 }
848
849 /**
850 * @tc.name: IsContinuationModeValidTest_002
851 * @tc.desc: test IsContinuationModeValid function with correct continuation mode.
852 * @tc.type: FUNC
853 */
854 HWTEST_F(ContinuationManagerTest, IsContinuationModeValidTest_002, TestSize.Level1)
855 {
856 DTEST_LOG << "ContinuationManagerTest IsContinuationModeValidTest_002 start" << std::endl;
857 if (dtbabilitymgrService_ == nullptr) {
858 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
859 return;
860 }
861 ContinuationMode continuationMode = ContinuationMode::COLLABORATION_MUTIPLE;
862 bool result = dtbabilitymgrService_->IsContinuationModeValid(continuationMode);
863 DTEST_LOG << "result:" << result << std::endl;
864 EXPECT_EQ(true, result);
865 DTEST_LOG << "ContinuationManagerTest IsContinuationModeValidTest_002 end" << std::endl;
866 }
867
868 /**
869 * @tc.name: IsConnectStatusValidTest_001
870 * @tc.desc: test IsConnectStatusValid function with invalid connect status.
871 * @tc.type: FUNC
872 */
873 HWTEST_F(ContinuationManagerTest, IsConnectStatusValidTest_001, TestSize.Level1)
874 {
875 DTEST_LOG << "ContinuationManagerTest IsConnectStatusValidTest_001 start" << std::endl;
876 if (dtbabilitymgrService_ == nullptr) {
877 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
878 return;
879 }
880 DeviceConnectStatus deviceConnectStatus = static_cast<DeviceConnectStatus>(ERROR_CONNECT_STATUS);
881 bool result = dtbabilitymgrService_->IsConnectStatusValid(deviceConnectStatus);
882 DTEST_LOG << "result:" << result << std::endl;
883 EXPECT_EQ(false, result);
884 DTEST_LOG << "ContinuationManagerTest IsConnectStatusValidTest_001 end" << std::endl;
885 }
886
887 /**
888 * @tc.name: IsConnectStatusValidTest_002
889 * @tc.desc: test IsConnectStatusValid function with correct connect status.
890 * @tc.type: FUNC
891 */
892 HWTEST_F(ContinuationManagerTest, IsConnectStatusValidTest_002, TestSize.Level1)
893 {
894 DTEST_LOG << "ContinuationManagerTest IsConnectStatusValidTest_002 start" << std::endl;
895 if (dtbabilitymgrService_ == nullptr) {
896 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
897 return;
898 }
899 DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
900 bool result = dtbabilitymgrService_->IsConnectStatusValid(deviceConnectStatus);
901 DTEST_LOG << "result:" << result << std::endl;
902 EXPECT_EQ(true, result);
903 DTEST_LOG << "ContinuationManagerTest IsConnectStatusValidTest_002 end" << std::endl;
904 }
905
906 /**
907 * @tc.name: IsTokenRegisteredTest_001
908 * @tc.desc: test IsTokenRegistered function with invalid token.
909 * @tc.type: FUNC
910 */
911 HWTEST_F(ContinuationManagerTest, IsTokenRegisteredTest_001, TestSize.Level1)
912 {
913 DTEST_LOG << "ContinuationManagerTest IsTokenRegisteredTest_002 start" << std::endl;
914 if (dtbabilitymgrService_ == nullptr) {
915 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
916 return;
917 }
918 std::vector<int32_t> tokenVec;
919 uint32_t accessToken = TEST_ACCESS_TOKEN;
920 dtbabilitymgrService_->tokenMap_[accessToken] = tokenVec;
921 bool result = dtbabilitymgrService_->IsTokenRegistered(TEST_ACCESS_TOKEN, TEST_TOKEN);
922 DTEST_LOG << "result:" << result << std::endl;
923 EXPECT_EQ(false, result);
924 DTEST_LOG << "ContinuationManagerTest IsTokenRegisteredTest_002 end" << std::endl;
925 }
926
927 /**
928 * @tc.name: IsTokenRegisteredTest_002
929 * @tc.desc: test IsTokenRegistered function with correct token.
930 * @tc.type: FUNC
931 */
932 HWTEST_F(ContinuationManagerTest, IsTokenRegisteredTest_002, TestSize.Level1)
933 {
934 DTEST_LOG << "ContinuationManagerTest IsTokenRegisteredTest_002 start" << std::endl;
935 if (dtbabilitymgrService_ == nullptr) {
936 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
937 return;
938 }
939 std::vector<int32_t> tokenVec;
940 tokenVec.emplace_back(TEST_TOKEN);
941 uint32_t accessToken = TEST_ACCESS_TOKEN;
942 dtbabilitymgrService_->tokenMap_[accessToken] = tokenVec;
943 bool result = dtbabilitymgrService_->IsTokenRegistered(TEST_ACCESS_TOKEN, TEST_TOKEN);
944 DTEST_LOG << "result:" << result << std::endl;
945 EXPECT_EQ(true, result);
946 DTEST_LOG << "ContinuationManagerTest IsTokenRegisteredTest_002 end" << std::endl;
947 }
948
949 /**
950 * @tc.name: IsNotifierRegisteredTest_001
951 * @tc.desc: test IsNotifierRegistered function with invalid token.
952 * @tc.type: FUNC
953 */
954 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredTest_001, TestSize.Level1)
955 {
956 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredTest_001 start" << std::endl;
957 if (dtbabilitymgrService_ == nullptr) {
958 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
959 return;
960 }
961 bool result = dtbabilitymgrService_->IsNotifierRegistered(TEST_TOKEN);
962 DTEST_LOG << "result:" << result << std::endl;
963 EXPECT_EQ(false, result);
964 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredTest_001 end" << std::endl;
965 }
966
967 /**
968 * @tc.name: IsNotifierRegisteredLockedTest_002
969 * @tc.desc: test IsNotifierRegisteredLocked function with invalid token.
970 * @tc.type: FUNC
971 */
972 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredLockedTest_002, TestSize.Level1)
973 {
974 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_002 start" << std::endl;
975 if (dtbabilitymgrService_ == nullptr) {
976 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
977 return;
978 }
979 bool result = dtbabilitymgrService_->IsNotifierRegisteredLocked(TEST_TOKEN, CALLBACK_TYPE1);
980 DTEST_LOG << "result:" << result << std::endl;
981 EXPECT_EQ(false, result);
982 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_002 end" << std::endl;
983 }
984
985 /**
986 * @tc.name: IsNotifierRegisteredLockedTest_003
987 * @tc.desc: test IsNotifierRegisteredLocked function with invalid callback type.
988 * @tc.type: FUNC
989 */
990 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredLockedTest_003, TestSize.Level1)
991 {
992 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_003 start" << std::endl;
993 if (dtbabilitymgrService_ == nullptr) {
994 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
995 return;
996 }
997 bool result = dtbabilitymgrService_->IsNotifierRegisteredLocked(TEST_TOKEN, INVALID_CALLBACK_TYPE);
998 DTEST_LOG << "result:" << result << std::endl;
999 EXPECT_EQ(false, result);
1000 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_003 end" << std::endl;
1001 }
1002
1003 /**
1004 * @tc.name: IsNotifierRegisteredTest_004
1005 * @tc.desc: test IsNotifierRegistered function with correct token.
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredTest_004, TestSize.Level1)
1009 {
1010 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredTest_004 start" << std::endl;
1011 if (dtbabilitymgrService_ == nullptr) {
1012 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1013 return;
1014 }
1015 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1016 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1017 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1018 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1019 bool result = dtbabilitymgrService_->IsNotifierRegistered(TEST_TOKEN);
1020 DTEST_LOG << "result:" << result << std::endl;
1021 EXPECT_EQ(true, result);
1022 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredTest_004 end" << std::endl;
1023 }
1024
1025 /**
1026 * @tc.name: IsNotifierRegisteredLockedTest_005
1027 * @tc.desc: test IsNotifierRegisteredLocked function with incorrect callback type.
1028 * @tc.type: FUNC
1029 */
1030 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredLockedTest_005, TestSize.Level1)
1031 {
1032 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_005 start" << std::endl;
1033 if (dtbabilitymgrService_ == nullptr) {
1034 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1035 return;
1036 }
1037 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1038 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1039 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1040 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1041 bool result = dtbabilitymgrService_->IsNotifierRegisteredLocked(TEST_TOKEN, CALLBACK_TYPE2);
1042 DTEST_LOG << "result:" << result << std::endl;
1043 EXPECT_EQ(false, result);
1044 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_005 end" << std::endl;
1045 }
1046
1047 /**
1048 * @tc.name: IsNotifierRegisteredLockedTest_006
1049 * @tc.desc: test IsNotifierRegisteredLocked function with incorrect token.
1050 * @tc.type: FUNC
1051 */
1052 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredLockedTest_006, TestSize.Level1)
1053 {
1054 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_006 start" << std::endl;
1055 if (dtbabilitymgrService_ == nullptr) {
1056 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1057 return;
1058 }
1059 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1060 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1061 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1062 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1063 bool result = dtbabilitymgrService_->IsNotifierRegisteredLocked(UNREGISTER_TOKEN, CALLBACK_TYPE1);
1064 DTEST_LOG << "result:" << result << std::endl;
1065 EXPECT_EQ(false, result);
1066 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_006 end" << std::endl;
1067 }
1068
1069 /**
1070 * @tc.name: IsNotifierRegisteredLockedTest_007
1071 * @tc.desc: test IsNotifierRegisteredLocked function with correct token and callback type.
1072 * @tc.type: FUNC
1073
1074 */
1075 HWTEST_F(ContinuationManagerTest, IsNotifierRegisteredLockedTest_007, TestSize.Level1)
1076 {
1077 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_007 start" << std::endl;
1078 if (dtbabilitymgrService_ == nullptr) {
1079 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1080 return;
1081 }
1082 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1083 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1084 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1085 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1086 bool result = dtbabilitymgrService_->IsNotifierRegisteredLocked(TEST_TOKEN, CALLBACK_TYPE1);
1087 DTEST_LOG << "result:" << result << std::endl;
1088 EXPECT_EQ(true, result);
1089 DTEST_LOG << "ContinuationManagerTest IsNotifierRegisteredLockedTest_007 end" << std::endl;
1090 }
1091
1092 /**
1093 * @tc.name: QueryTokenByNotifier_001
1094 * @tc.desc: test QueryTokenByNotifier function with incorrect notifier.
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F(ContinuationManagerTest, QueryTokenByNotifier_001, TestSize.Level1)
1098 {
1099 DTEST_LOG << "ContinuationManagerTest QueryTokenByNotifier_001 start" << std::endl;
1100 if (dtbabilitymgrService_ == nullptr) {
1101 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1102 return;
1103 }
1104 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1105 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1106 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1107 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1108 int32_t token = -1;
1109 bool result = dtbabilitymgrService_->QueryTokenByNotifier(nullptr, token);
1110 DTEST_LOG << "result:" << result << std::endl;
1111 EXPECT_EQ(false, result);
1112 DTEST_LOG << "ContinuationManagerTest QueryTokenByNotifier_001 end" << std::endl;
1113 }
1114
1115 /**
1116 * @tc.name: QueryTokenByNotifier_002
1117 * @tc.desc: test QueryTokenByNotifier function with correct notifier.
1118 * @tc.type: FUNC
1119 */
1120 HWTEST_F(ContinuationManagerTest, QueryTokenByNotifier_002, TestSize.Level1)
1121 {
1122 DTEST_LOG << "ContinuationManagerTest QueryTokenByNotifier_002 start" << std::endl;
1123 if (dtbabilitymgrService_ == nullptr) {
1124 DTEST_LOG << "dtbabilitymgrService_ is nullptr" << std::endl;
1125 return;
1126 }
1127 std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1128 sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1129 notifierInfo->SetNotifier(CALLBACK_TYPE1, notifier);
1130 dtbabilitymgrService_->callbackMap_[TEST_TOKEN] = std::move(notifierInfo);
1131 int32_t token = -1;
1132 bool result = dtbabilitymgrService_->QueryTokenByNotifier(notifier, token);
1133 DTEST_LOG << "result:" << result << std::endl;
1134 EXPECT_EQ(true, result);
1135 EXPECT_EQ(TEST_TOKEN, token);
1136 DTEST_LOG << "ContinuationManagerTest QueryTokenByNotifier_002 end" << std::endl;
1137 }
1138
1139 /**
1140 * @tc.name: GetSetDeviceInfo_001
1141 * @tc.desc: test SetDeviceId SetDeviceType SetDeviceName GetDeviceId GetDeviceType GetDeviceName function.
1142 * @tc.type: FUNC
1143 * @tc.require: I5M4CD
1144 */
1145 HWTEST_F(ContinuationManagerTest, GetSetDeviceInfo_001, TestSize.Level3)
1146 {
1147 DTEST_LOG << "ContinuationManagerTest GetSetDeviceInfo_001 start" << std::endl;
1148
1149 ContinuationResult continuationResult;
1150 continuationResult.SetDeviceId(SELECTED_DEVICE_ID1);
1151 continuationResult.SetDeviceType(SELECTED_DEVICE_TYPE1);
1152 continuationResult.SetDeviceName(SELECTED_DEVICE_NAME1);
1153
1154 string deviceId1 = continuationResult.GetDeviceId();
1155 string deviceType1 = continuationResult.GetDeviceType();
1156 string deviceName1 = continuationResult.GetDeviceName();
1157
1158 EXPECT_EQ(SELECTED_DEVICE_ID1, deviceId1);
1159 EXPECT_EQ(SELECTED_DEVICE_TYPE1, deviceType1);
1160 EXPECT_EQ(SELECTED_DEVICE_NAME1, deviceName1);
1161
1162 DTEST_LOG << "ContinuationManagerTest GetSetDeviceInfo_001 end" << std::endl;
1163 }
1164
1165 /**
1166 * @tc.name: MarshallingUnmarshalling_001
1167 * @tc.desc: test Marshalling and Unmarshalling function.
1168 * @tc.type: FUNC
1169 * @tc.require: I5M4CD
1170 */
1171 HWTEST_F(ContinuationManagerTest, MarshallingUnmarshalling_001, TestSize.Level3)
1172 {
1173 DTEST_LOG << "ContinuationManagerTest MarshallingUnmarshalling_001 start" << std::endl;
1174
1175 ContinuationResult continuationResult1;
1176 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
1177 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
1178 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
1179
1180 Parcel parcel;
1181 bool result1 = continuationResult1.Marshalling(parcel);
1182 if (!result1) {
1183 DTEST_LOG << " Marshalling failed" << std::endl;
1184 return;
1185 }
1186 DTEST_LOG << "result1:" << result1 << endl;
1187
1188 sptr<ContinuationResult> continuationResult2 = continuationResult1.Unmarshalling(parcel);
1189 if (continuationResult2 == nullptr) {
1190 DTEST_LOG << "continuationResult is nullptr" << endl;
1191 return;
1192 }
1193
1194 string deviceId1 = continuationResult2->GetDeviceId();
1195 string deviceType1 = continuationResult2->GetDeviceType();
1196 string deviceName1 = continuationResult2->GetDeviceName();
1197 EXPECT_EQ(true, result1);
1198 EXPECT_EQ(SELECTED_DEVICE_ID1, deviceId1);
1199 EXPECT_EQ(SELECTED_DEVICE_TYPE1, deviceType1);
1200 EXPECT_EQ(SELECTED_DEVICE_NAME1, deviceName1);
1201
1202 DTEST_LOG << "ContinuationManagerTest MarshallingUnmarshalling_001 end" << std::endl;
1203 }
1204
1205 /**
1206 * @tc.name: ReadFromParcel_001
1207 * @tc.desc: test ReadFromParcel function.
1208 * @tc.type: FUNC
1209 * @tc.require: I5M4CD
1210 */
1211 HWTEST_F(ContinuationManagerTest, ReadFromParcel_001, TestSize.Level3)
1212 {
1213 DTEST_LOG << "ContinuationManagerTest ReadFromParcel_001 start" << std::endl;
1214 ContinuationResult continuationResult;
1215 continuationResult.SetDeviceId(SELECTED_DEVICE_ID1);
1216 continuationResult.SetDeviceType(SELECTED_DEVICE_TYPE1);
1217 continuationResult.SetDeviceName(SELECTED_DEVICE_NAME1);
1218
1219 Parcel parcel;
1220 bool result1 = continuationResult.Marshalling(parcel);
1221 if (!result1) {
1222 DTEST_LOG << "Marshalling failed" << std::endl;
1223 return;
1224 }
1225 bool result2 = continuationResult.ReadFromParcel(parcel);
1226 if (!result2) {
1227 DTEST_LOG << "ReadFromParcel failed" << std::endl;
1228 return;
1229 }
1230
1231 string deviceId1 = continuationResult.GetDeviceId();
1232 string deviceType1 = continuationResult.GetDeviceType();
1233 string deviceName1 = continuationResult.GetDeviceName();
1234 EXPECT_EQ(true, result1);
1235 EXPECT_EQ(true, result2);
1236 EXPECT_EQ(SELECTED_DEVICE_ID1, deviceId1);
1237 EXPECT_EQ(SELECTED_DEVICE_TYPE1, deviceType1);
1238 EXPECT_EQ(SELECTED_DEVICE_NAME1, deviceName1);
1239
1240 DTEST_LOG << "ContinuationManagerTest ReadFromParcel_001 end" << std::endl;
1241 }
1242
1243 /**
1244 * @tc.name: Write_Read_ContinuationResultsFromParcel_001
1245 * @tc.desc: test WriteContinuationResultsToParcel and ReadContinuationResultsFromParcel function.
1246 * @tc.type: FUNC
1247 * @tc.require: I5M4CD
1248 */
1249 HWTEST_F(ContinuationManagerTest, Write_Read_ContinuationResultsFromParcel_001, TestSize.Level3)
1250 {
1251 DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsFromParcel_001 start" << std::endl;
1252
1253 std::vector<ContinuationResult> continuationResults1;
1254 ContinuationResult continuationResult1;
1255 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
1256 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
1257 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
1258 ContinuationResult continuationResult2;
1259 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
1260 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
1261 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
1262 continuationResults1.emplace_back(continuationResult1);
1263 continuationResults1.emplace_back(continuationResult2);
1264
1265 Parcel parcel;
1266 std::vector<ContinuationResult> continuationResults2;
1267 bool result1 = ContinuationResult::WriteContinuationResultsToParcel(parcel, continuationResults1);
1268 if (!result1) {
1269 DTEST_LOG << "WriteContinuationResultsToParcel failed" << std::endl;
1270 return;
1271 }
1272 bool result2 = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults2);
1273 if (!result2) {
1274 DTEST_LOG << "ReadContinuationResultsFromParcel failed" << std::endl;
1275 return;
1276 }
1277
1278 size_t size1 = continuationResults1.size();
1279 size_t size2 = continuationResults2.size();
1280 if (size1 != size2) {
1281 DTEST_LOG << "continuationResults1.size != continuationResults2.size" << std::endl;
1282 return;
1283 }
1284
1285 EXPECT_EQ(true, result1);
1286 EXPECT_EQ(true, result2);
1287 for (size_t i = 0; i < size1; ++i) {
1288 EXPECT_EQ(continuationResults1[i].GetDeviceId(), continuationResults2[i].GetDeviceId());
1289 EXPECT_EQ(continuationResults1[i].GetDeviceType(), continuationResults2[i].GetDeviceType());
1290 EXPECT_EQ(continuationResults1[i].GetDeviceName(), continuationResults2[i].GetDeviceName());
1291 }
1292
1293 DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsFromParcel_001 end" << std::endl;
1294 }
1295
1296 /**
1297 * @tc.name: ReadContinuationResultsFromParcel_001
1298 * @tc.desc: test ReadContinuationResultsFromParcel when len is less than 0.
1299 * @tc.type: FUNC
1300 */
1301 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_001, TestSize.Level3)
1302 {
1303 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 start" << std::endl;
1304 Parcel parcel;
1305 std::vector<ContinuationResult> continuationResults;
1306 parcel.WriteInt32(VALUE_OBJECT);
1307 parcel.WriteInt32(-1);
1308 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1309 EXPECT_FALSE(result);
1310 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 end" << std::endl;
1311 }
1312
1313 /**
1314 * @tc.name: ReadContinuationResultsFromParcel_002
1315 * @tc.desc: test ReadContinuationResultsFromParcel when size > parcel.GetReadableBytes().
1316 * @tc.type: FUNC
1317 */
1318 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_002, TestSize.Level3)
1319 {
1320 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 start" << std::endl;
1321 Parcel parcel;
1322 std::vector<ContinuationResult> continuationResults;
1323 parcel.WriteInt32(VALUE_OBJECT);
1324 parcel.WriteInt32(parcel.GetReadableBytes() + 1);
1325 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1326 EXPECT_FALSE(result);
1327 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 end" << std::endl;
1328 }
1329
1330 /**
1331 * @tc.name: ReadContinuationResultsFromParcel_003
1332 * @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() < size.
1333 * @tc.type: FUNC
1334 */
1335 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_003, TestSize.Level3)
1336 {
1337 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 start" << std::endl;
1338 Parcel parcel;
1339 std::vector<ContinuationResult> continuationResults;
1340 parcel.WriteInt32(VALUE_OBJECT);
1341 parcel.WriteInt32(continuationResults.max_size() + 1);
1342 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1343 EXPECT_FALSE(result);
1344 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 end" << std::endl;
1345 }
1346
1347 /**
1348 * @tc.name: ReadContinuationResultsFromParcel_004
1349 * @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() > size.
1350 * @tc.type: FUNC
1351 */
1352 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_004, TestSize.Level3)
1353 {
1354 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 start" << std::endl;
1355 Parcel parcel;
1356 std::vector<ContinuationResult> continuationResults;
1357 parcel.WriteInt32(VALUE_OBJECT);
1358 parcel.WriteInt32(continuationResults.max_size() - 1);
1359 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1360 EXPECT_FALSE(result);
1361 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 end" << std::endl;
1362 }
1363
1364 /**
1365 * @tc.name: ReadContinuationResultsFromParcel_005
1366 * @tc.desc: test ReadContinuationResultsFromParcel when continuationResult is nullptr.
1367 * @tc.type: FUNC
1368 */
1369 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_005, TestSize.Level3)
1370 {
1371 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 start" << std::endl;
1372 Parcel parcel;
1373 ContinuationResult *continuationResult = nullptr;
1374 std::vector<ContinuationResult> continuationResults;
1375 parcel.WriteInt32(VALUE_OBJECT);
1376 parcel.WriteInt32(1);
1377 parcel.WriteParcelable(continuationResult);
1378 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1379 EXPECT_FALSE(result);
1380 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 end" << std::endl;
1381 }
1382
1383 /**
1384 * @tc.name: ReadContinuationResultsFromParcel_006
1385 * @tc.desc: test ReadContinuationResultsFromParcel when size <= parcel.GetReadableBytes().
1386 * @tc.type: FUNC
1387 * @tc.require: I621C1
1388 */
1389 HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_006, TestSize.Level3)
1390 {
1391 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_006 start" << std::endl;
1392 Parcel parcel;
1393 std::vector<ContinuationResult> continuationResults;
1394 parcel.WriteInt32(VALUE_OBJECT);
1395 parcel.WriteInt32(parcel.GetReadableBytes());
1396 bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
1397 EXPECT_FALSE(result);
1398 DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_006 end" << std::endl;
1399 }
1400
1401 /**
1402 * @tc.name: WriteContinuationResultsToParcel_001
1403 * @tc.desc: test WriteContinuationResultsToParcel when size == 0.
1404 * @tc.type: FUNC
1405 */
1406 HWTEST_F(ContinuationManagerTest, WriteContinuationResultsToParcel_001, TestSize.Level3)
1407 {
1408 DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 start" << std::endl;
1409 Parcel parcel;
1410 std::vector<ContinuationResult> continuationResults;
1411 bool result = ContinuationResult::WriteContinuationResultsToParcel(parcel, continuationResults);
1412 EXPECT_TRUE(result);
1413 DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 end" << std::endl;
1414 }
1415
1416 /**
1417 * @tc.name: Str16VecToStr8Vec_001
1418 * @tc.desc: test Str16VecToStr8Vec function.
1419 * @tc.type: FUNC
1420 * @tc.require: I5M4CD
1421 */
1422 HWTEST_F(ContinuationManagerTest, Str16VecToStr8Vec_001, TestSize.Level3)
1423 {
1424 DTEST_LOG << "ContinuationManagerTest Str16VecToStr8Vec_001 start" << std::endl;
1425
1426 std::vector<std::u16string> input1;
1427 input1.emplace_back(TEST_INPUT1);
1428 input1.emplace_back(TEST_INPUT2);
1429 std::vector<std::string> input2;
1430 input2.emplace_back(TEST_INPUT3);
1431 input2.emplace_back(TEST_INPUT4);
1432
1433 std::vector<std::string> input3 = ContinationManagerUtils::Str16VecToStr8Vec(input1);
1434
1435 size_t size1 = input2.size();
1436 size_t size2 = input3.size();
1437 if (size1 != size2) {
1438 DTEST_LOG << "input2.size != input3.size" << std::endl;
1439 return;
1440 }
1441 for (size_t i = 0; i < size1; ++i) {
1442 EXPECT_EQ(input2[i], input3[i]);
1443 }
1444
1445 DTEST_LOG << "ContinuationManagerTest Str16VecToStr8Vec_001 end" << std::endl;
1446 }
1447
1448 /**
1449 * @tc.name: SetFunction_001
1450 * @tc.desc: test SetFunction function.
1451 * @tc.type: FUNC
1452 * @tc.require: I5M4CD
1453 */
1454 HWTEST_F(ContinuationManagerTest, SetFunction_001, TestSize.Level3)
1455 {
1456 DTEST_LOG << "ContinuationManagerTest SetFunction_001 start" << std::endl;
1457 ContinuationExtraParams continuationExtraParams;
1458
1459 std::vector<std::string> deviceTypeVec1;
1460 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE1);
1461 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE2);
1462 ContinuationMode continuationMode = ContinuationMode::COLLABORATION_MUTIPLE;
1463
1464 continuationExtraParams.SetDeviceType(deviceTypeVec1);
1465 continuationExtraParams.SetTargetBundle(TEST_TARGETBUNDLE);
1466 continuationExtraParams.SetDescription(TEST_DESCRIPTION);
1467 continuationExtraParams.SetFilter(TEST_FILTER);
1468 continuationExtraParams.SetContinuationMode(continuationMode);
1469 continuationExtraParams.SetAuthInfo(TEST_AUTHINFO);
1470
1471 std::vector<std::string> deviceTypeVec2 = continuationExtraParams.GetDeviceType();
1472 size_t size1 = deviceTypeVec1.size();
1473 size_t size2 = deviceTypeVec2.size();
1474 if (size1 != size2) {
1475 DTEST_LOG << "deviceTypeVec1.size != deviceTypeVec2.size" << std::endl;
1476 return;
1477 }
1478 for (size_t i = 0; i < size1; ++i) {
1479 EXPECT_EQ(deviceTypeVec1[i], deviceTypeVec2[i]);
1480 }
1481 EXPECT_EQ(TEST_TARGETBUNDLE, continuationExtraParams.GetTargetBundle());
1482 EXPECT_EQ(TEST_DESCRIPTION, continuationExtraParams.GetDescription());
1483 EXPECT_EQ(TEST_FILTER, continuationExtraParams.GetFilter());
1484 EXPECT_EQ(continuationMode, continuationExtraParams.GetContinuationMode());
1485 EXPECT_EQ(TEST_AUTHINFO, continuationExtraParams.GetAuthInfo());
1486
1487 DTEST_LOG << "ContinuationManagerTest SetFunction_001 end" << std::endl;
1488 }
1489
1490 /**
1491 * @tc.name: ReadFromParcel_002
1492 * @tc.desc: test ContinuationExtraParams::ReadFromParcel function.
1493 * @tc.type: FUNC
1494 * @tc.require: I5M4CD
1495 */
1496 HWTEST_F(ContinuationManagerTest, ReadFromParcel_002, TestSize.Level3)
1497 {
1498 DTEST_LOG << "ContinuationManagerTest ReadFromParcel_002 start" << std::endl;
1499 ContinuationExtraParams continuationExtraParams;
1500
1501 std::vector<std::string> deviceTypeVec1;
1502 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE1);
1503 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE2);
1504 ContinuationMode continuationMode = ContinuationMode::COLLABORATION_MUTIPLE;
1505
1506 continuationExtraParams.SetDeviceType(deviceTypeVec1);
1507 continuationExtraParams.SetTargetBundle(TEST_TARGETBUNDLE);
1508 continuationExtraParams.SetDescription(TEST_DESCRIPTION);
1509 continuationExtraParams.SetFilter(TEST_FILTER);
1510 continuationExtraParams.SetContinuationMode(continuationMode);
1511 continuationExtraParams.SetAuthInfo(TEST_AUTHINFO);
1512
1513 Parcel parcel;
1514 bool result1 = continuationExtraParams.Marshalling(parcel);
1515 if (!result1) {
1516 DTEST_LOG << "Marshalling failed" << std::endl;
1517 return;
1518 }
1519 bool result2 = continuationExtraParams.ReadFromParcel(parcel);
1520 if (!result2) {
1521 DTEST_LOG << "ReadFromParcel failed" << std::endl;
1522 return;
1523 }
1524
1525 EXPECT_EQ(true, result1);
1526 EXPECT_EQ(true, result2);
1527 std::vector<std::string> deviceTypeVec2 = continuationExtraParams.GetDeviceType();
1528 size_t size1 = deviceTypeVec1.size();
1529 size_t size2 = deviceTypeVec2.size();
1530 if (size1 != size2) {
1531 DTEST_LOG << "deviceTypeVec1.size != deviceTypeVec2.size" << std::endl;
1532 return;
1533 }
1534 for (size_t i = 0; i < size1; ++i) {
1535 EXPECT_EQ(deviceTypeVec1[i], deviceTypeVec2[i]);
1536 }
1537 EXPECT_EQ(TEST_TARGETBUNDLE, continuationExtraParams.GetTargetBundle());
1538 EXPECT_EQ(TEST_DESCRIPTION, continuationExtraParams.GetDescription());
1539 EXPECT_EQ(TEST_FILTER, continuationExtraParams.GetFilter());
1540 EXPECT_EQ(continuationMode, continuationExtraParams.GetContinuationMode());
1541 EXPECT_EQ(TEST_AUTHINFO, continuationExtraParams.GetAuthInfo());
1542
1543 DTEST_LOG << "ContinuationManagerTest ReadFromParcel_002 end" << std::endl;
1544 }
1545
1546 /**
1547 * @tc.name: Unmarshalling_001
1548 * @tc.desc: test Unmarshalling_001 function.
1549 * @tc.type: FUNC
1550 * @tc.require: I5M4CD
1551 */
1552 HWTEST_F(ContinuationManagerTest, Unmarshalling_001, TestSize.Level3)
1553 {
1554 DTEST_LOG << "ContinuationManagerTest Unmarshalling_001 start" << std::endl;
1555 ContinuationExtraParams continuationExtraParams1;
1556
1557 std::vector<std::string> deviceTypeVec1;
1558 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE1);
1559 deviceTypeVec1.emplace_back(SELECTED_DEVICE_TYPE2);
1560 ContinuationMode continuationMode = ContinuationMode::COLLABORATION_MUTIPLE;
1561
1562 continuationExtraParams1.SetDeviceType(deviceTypeVec1);
1563 continuationExtraParams1.SetTargetBundle(TEST_TARGETBUNDLE);
1564 continuationExtraParams1.SetDescription(TEST_DESCRIPTION);
1565 continuationExtraParams1.SetFilter(TEST_FILTER);
1566 continuationExtraParams1.SetContinuationMode(continuationMode);
1567 continuationExtraParams1.SetAuthInfo(TEST_AUTHINFO);
1568
1569 Parcel parcel;
1570
1571 bool result1 = continuationExtraParams1.Marshalling(parcel);
1572 if (!result1) {
1573 DTEST_LOG << "Marshalling failed" << std::endl;
1574 return;
1575 }
1576 sptr<ContinuationExtraParams> continuationExtraParams2 = continuationExtraParams1.Unmarshalling(parcel);
1577 if (continuationExtraParams2 == nullptr) {
1578 DTEST_LOG << "continuationExtraParams is nullptr" << std::endl;
1579 return;
1580 }
1581
1582 std::vector<std::string> deviceTypeVec2 = continuationExtraParams2->GetDeviceType();
1583
1584 EXPECT_EQ(true, result1);
1585 size_t size1 = deviceTypeVec1.size();
1586 size_t size2 = deviceTypeVec2.size();
1587 if (size1 != size2) {
1588 DTEST_LOG << "deviceTypeVec1.size != deviceTypeVec2.size" << std::endl;
1589 return;
1590 }
1591 for (size_t i = 0; i < size1; ++i) {
1592 EXPECT_EQ(deviceTypeVec1[i], deviceTypeVec2[i]);
1593 }
1594 EXPECT_EQ(TEST_TARGETBUNDLE, continuationExtraParams2->GetTargetBundle());
1595 EXPECT_EQ(TEST_DESCRIPTION, continuationExtraParams2->GetDescription());
1596 EXPECT_EQ(TEST_FILTER, continuationExtraParams2->GetFilter());
1597 EXPECT_EQ(continuationMode, continuationExtraParams2->GetContinuationMode());
1598 EXPECT_EQ(TEST_AUTHINFO, continuationExtraParams2->GetAuthInfo());
1599
1600 DTEST_LOG << "ContinuationManagerTest Unmarshalling_001 end" << std::endl;
1601 }
1602
1603 /**
1604 * @tc.name: Unmarshalling_002
1605 * @tc.desc: test Unmarshalling_002 when ontinuationExtraParams->ReadFromParcel failed;
1606 * @tc.type: FUNC
1607 * @tc.require: I621C1
1608 */
1609 HWTEST_F(ContinuationManagerTest, Unmarshalling_002, TestSize.Level3)
1610 {
1611 DTEST_LOG << "ContinuationManagerTest Unmarshalling_002 start" << std::endl;
1612 ContinuationExtraParams continuationExtraParams;
1613 Parcel parcel;
1614 parcel.WriteInt32(INVALID_LEN);
1615 ContinuationExtraParams* result = continuationExtraParams.Unmarshalling(parcel);
1616 EXPECT_EQ(nullptr, result);
1617 DTEST_LOG << "ContinuationManagerTest Unmarshalling_002 end" << std::endl;
1618 }
1619
1620 /**
1621 * @tc.name: OnRemoteRequest_001
1622 * @tc.desc: test OnRemoteRequest, invalid interface token.
1623 * @tc.type: FUNC
1624 * @tc.require: I5M4CD
1625 */
1626 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_001, TestSize.Level3)
1627 {
1628 MessageParcel data;
1629 MessageParcel reply;
1630 MessageOption option;
1631 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1632 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1633 (IDRequestInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
1634 EXPECT_EQ(ERR_INVALID_VALUE, result);
1635 }
1636
1637 /**
1638 * @tc.name: OnRemoteRequest_002
1639 * @tc.desc: test OnRemoteRequest, invalid code.
1640 * @tc.type: FUNC
1641 * @tc.require: I5M4CD
1642 */
1643 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_002, TestSize.Level3)
1644 {
1645 MessageParcel data;
1646 data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
1647 MessageParcel reply;
1648 MessageOption option;
1649 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1650 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(INVALID_EVENT_DEVICE_CODE,
1651 data, reply, option);
1652 EXPECT_NE(ERR_OK, result);
1653 }
1654
1655 /**
1656 * @tc.name: OnRemoteRequest_003
1657 * @tc.desc: test OnRemoteRequest, code = EVENT_DEVICE_CONNECT
1658 * @tc.type: FUNC
1659 * @tc.require: I5M4CD
1660 */
1661 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_003, TestSize.Level3)
1662 {
1663 MessageParcel data;
1664 data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
1665 std::vector<ContinuationResult> continuationResults;
1666 ContinuationResult continuationResult1;
1667 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
1668 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
1669 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
1670 ContinuationResult continuationResult2;
1671 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
1672 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
1673 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
1674 continuationResults.emplace_back(continuationResult1);
1675 continuationResults.emplace_back(continuationResult2);
1676
1677 bool result1 = ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults);
1678 if (!result1) {
1679 DTEST_LOG << "WriteContinuationResultsToParcel failed" << std::endl;
1680 return;
1681 }
1682
1683 MessageParcel reply;
1684 MessageOption option;
1685 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1686 int32_t result2 = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1687 (IDRequestInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
1688
1689 EXPECT_EQ(true, result1);
1690 EXPECT_EQ(ERR_OK, result2);
1691 }
1692
1693 /**
1694 * @tc.name: OnRemoteRequest_004
1695 * @tc.desc: test OnRemoteRequest, invalid interface token.
1696 * @tc.type: FUNC
1697 * @tc.require: I5M4CD
1698 */
1699 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_004, TestSize.Level3)
1700 {
1701 /**
1702 * @tc.steps: step1. test OnRemoteRequest with invalid interface token.
1703 */
1704 MessageParcel data;
1705 MessageParcel reply;
1706 MessageOption option;
1707 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1708 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1709 (IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
1710 EXPECT_EQ(ERR_INVALID_VALUE, result);
1711 /**
1712 * @tc.steps: step2. test OnRemoteDied when dmsNotifier_ == nullptr.
1713 */
1714 NotifierDeathRecipient notifierDeathRecipient;
1715 wptr<IRemoteObject> remote = nullptr;
1716 notifierDeathRecipient.OnRemoteDied(remote);
1717 }
1718
1719 /**
1720 * @tc.name: OnRemoteRequest_005
1721 * @tc.desc: test OnRemoteRequest, code = EVENT_DEVICE_DISCONNECT
1722 * @tc.type: FUNC
1723 * @tc.require: I5M4CD
1724 */
1725 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_005, TestSize.Level3)
1726 {
1727 MessageParcel data;
1728 data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
1729 std::vector<ContinuationResult> continuationResults;
1730 ContinuationResult continuationResult1;
1731 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
1732 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
1733 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
1734 ContinuationResult continuationResult2;
1735 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
1736 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
1737 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
1738 continuationResults.emplace_back(continuationResult1);
1739 continuationResults.emplace_back(continuationResult2);
1740
1741 bool result1 = ContinuationResult::WriteContinuationResultsToParcel(data, continuationResults);
1742 if (!result1) {
1743 DTEST_LOG << "WriteContinuationResultsToParcel failed" << std::endl;
1744 return;
1745 }
1746
1747 MessageParcel reply;
1748 MessageOption option;
1749 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1750 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1751 (IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
1752
1753 EXPECT_EQ(ERR_OK, result);
1754 }
1755
1756 /**
1757 * @tc.name: OnRemoteRequest_006
1758 * @tc.desc: test OnRemoteRequest, code = EVENT_DEVICE_CONNECT but read from parcel failed
1759 * @tc.type: FUNC
1760 * @tc.require: I621C1
1761 */
1762 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_006, TestSize.Level3)
1763 {
1764 MessageParcel data;
1765 data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
1766 data.WriteInt32(VALUE_OBJECT);
1767 data.WriteInt32(INVALID_LEN);
1768 MessageParcel reply;
1769 MessageOption option;
1770 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1771 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1772 (IDRequestInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
1773 EXPECT_EQ(ERR_FLATTEN_OBJECT, result);
1774 }
1775
1776 /**
1777 * @tc.name: OnRemoteRequest_007
1778 * @tc.desc: test OnRemoteRequest, code = EVENT_DEVICE_DISCONNECT but read from parcel failed
1779 * @tc.type: FUNC
1780 * @tc.require: I621C1
1781 */
1782 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_007, TestSize.Level3)
1783 {
1784 MessageParcel data;
1785 data.WriteInterfaceToken(IDeviceSelectionNotifier::GetDescriptor());
1786 data.WriteInt32(VALUE_OBJECT);
1787 data.WriteInt32(INVALID_LEN);
1788 MessageParcel reply;
1789 MessageOption option;
1790 DeviceSelectionNotifierTest deviceSelectionNotifierTest;
1791 int32_t result = deviceSelectionNotifierTest.OnRemoteRequest(static_cast<uint32_t>
1792 (IDRequestInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
1793 EXPECT_EQ(ERR_FLATTEN_OBJECT, result);
1794 }
1795
1796 /**
1797 * @tc.name: OnRemoteRequest_008
1798 * @tc.desc: test OnRemoteRequest when descriptor != remoteDescriptor.
1799 * @tc.type: FUNC
1800 * @tc.require: I5M4CD
1801 */
1802 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_008, TestSize.Level3)
1803 {
1804 AppDeviceCallbackStub appDeviceCallbackStub;
1805 MessageParcel data;
1806 MessageParcel reply;
1807 MessageOption option;
1808 data.WriteInterfaceToken(TEST_INVALID_REMOTEDESCRIPTOR);
1809 /**
1810 * @tc.steps: step1. AppDeviceCallbackStub::OnRemoteRequest
1811 */
1812 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(1, data, reply, option);
1813 EXPECT_EQ(ERR_INVALID_STATE, ret);
1814 /**
1815 * @tc.steps: step2. DeviceSelectionNotifierProxy::OnDeviceConnect when continuationResults is nullptr.
1816 */
1817 sptr<IRemoteObject> impl(new MockRemoteStub());
1818 DeviceSelectionNotifierProxy deviceSelectionNotifierProxy(impl);
1819 std::vector<ContinuationResult> continuationResults;
1820 deviceSelectionNotifierProxy.OnDeviceConnect(continuationResults);
1821 /**
1822 * @tc.steps: step3. DeviceSelectionNotifierProxy::OnDeviceDisconnect when continuationResults is nullptr.
1823 */
1824 deviceSelectionNotifierProxy.OnDeviceDisconnect(continuationResults);
1825
1826 ContinuationResult continuationResult1;
1827 continuationResult1.SetDeviceId(SELECTED_DEVICE_ID1);
1828 continuationResult1.SetDeviceType(SELECTED_DEVICE_TYPE1);
1829 continuationResult1.SetDeviceName(SELECTED_DEVICE_NAME1);
1830 ContinuationResult continuationResult2;
1831 continuationResult2.SetDeviceId(SELECTED_DEVICE_ID2);
1832 continuationResult2.SetDeviceType(SELECTED_DEVICE_TYPE2);
1833 continuationResult2.SetDeviceName(SELECTED_DEVICE_NAME2);
1834 continuationResults.emplace_back(continuationResult1);
1835 continuationResults.emplace_back(continuationResult2);
1836 /**
1837 * @tc.steps: step4. DeviceSelectionNotifierProxy::OnDeviceConnect.
1838 */
1839 deviceSelectionNotifierProxy.OnDeviceConnect(continuationResults);
1840 /**
1841 * @tc.steps: step5. DeviceSelectionNotifierProxy::OnDeviceDisconnect.
1842 */
1843 deviceSelectionNotifierProxy.OnDeviceDisconnect(continuationResults);
1844 }
1845
1846 /**
1847 * @tc.name: OnRemoteRequest_009
1848 * @tc.desc: test OnRemoteRequest when code = static_cast<uint32_t>
1849 * (IDRequestCallbackInterfaceCode::EVENT_DEVICE_CONNECT).
1850 * @tc.type: FUNC
1851 * @tc.require: I621C1
1852 */
1853 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_009, TestSize.Level3)
1854 {
1855 AppDeviceCallbackStub appDeviceCallbackStub;
1856 MessageParcel data;
1857 MessageParcel reply;
1858 MessageOption option;
1859 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1860 data.WriteInt32(TEST_TOKEN);
1861 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
1862 static_cast<uint32_t>(IDRequestCallbackInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
1863 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1864 }
1865
1866 /**
1867 * @tc.name: OnRemoteRequest_010
1868 * @tc.desc: test OnRemoteRequest when ContinuationResult read from parcel failed.
1869 * @tc.type: FUNC
1870 * @tc.require: I621C1
1871 */
1872 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_010, TestSize.Level3)
1873 {
1874 AppDeviceCallbackStub appDeviceCallbackStub;
1875 MessageParcel data;
1876 MessageParcel reply;
1877 MessageOption option;
1878 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1879 data.WriteInt32(TEST_TOKEN);
1880 data.WriteInt32(VALUE_OBJECT);
1881 data.WriteInt32(INVALID_LEN);
1882 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
1883 static_cast<uint32_t>(IDRequestCallbackInterfaceCode::EVENT_DEVICE_CONNECT), data, reply, option);
1884 EXPECT_EQ(ERR_FLATTEN_OBJECT, ret);
1885 }
1886
1887 /**
1888 * @tc.name: OnRemoteRequest_011
1889 * @tc.desc: test OnRemoteRequest when code = static_cast<uint32_t>
1890 * (IDRequestCallbackInterfaceCode::EVENT_DEVICE_DISCONNECT).
1891 * @tc.type: FUNC
1892 * @tc.require: I621C1
1893 */
1894 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_011, TestSize.Level3)
1895 {
1896 AppDeviceCallbackStub appDeviceCallbackStub;
1897 MessageParcel data;
1898 MessageParcel reply;
1899 MessageOption option;
1900 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1901 data.WriteInt32(TEST_TOKEN);
1902 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
1903 static_cast<uint32_t>(IDRequestCallbackInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
1904 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1905 }
1906
1907 /**
1908 * @tc.name: OnRemoteRequest_012
1909 * @tc.desc: test OnRemoteRequest when ContinuationResult read from parcel failed.
1910 * @tc.type: FUNC
1911 * @tc.require: I621C1
1912 */
1913 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_012, TestSize.Level3)
1914 {
1915 AppDeviceCallbackStub appDeviceCallbackStub;
1916 MessageParcel data;
1917 MessageParcel reply;
1918 MessageOption option;
1919 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1920 data.WriteInt32(TEST_TOKEN);
1921 data.WriteInt32(VALUE_OBJECT);
1922 data.WriteInt32(INVALID_LEN);
1923 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
1924 static_cast<uint32_t>(IDRequestCallbackInterfaceCode::EVENT_DEVICE_DISCONNECT), data, reply, option);
1925 EXPECT_EQ(ERR_FLATTEN_OBJECT, ret);
1926 }
1927
1928 /**
1929 * @tc.name: OnRemoteRequest_013
1930 * @tc.desc: test OnRemoteRequest when code = static_cast<uint32_t>
1931 * (IDRequestCallbackInterfaceCode::EVENT_DEVICE_CANCEL).
1932 * @tc.type: FUNC
1933 * @tc.require: I621C1
1934 */
1935 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_013, TestSize.Level3)
1936 {
1937 AppDeviceCallbackStub appDeviceCallbackStub;
1938 MessageParcel data;
1939 MessageParcel reply;
1940 MessageOption option;
1941 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1942 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(
1943 static_cast<uint32_t>(IDRequestCallbackInterfaceCode::EVENT_DEVICE_CANCEL), data, reply, option);
1944 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1945 }
1946
1947 /**
1948 * @tc.name: OnRemoteRequest_014
1949 * @tc.desc: test OnRemoteRequest when code = INVALID_EVENT_DEVICE_CODE.
1950 * @tc.type: FUNC
1951 * @tc.require: I621C1
1952 */
1953 HWTEST_F(ContinuationManagerTest, OnRemoteRequest_014, TestSize.Level3)
1954 {
1955 AppDeviceCallbackStub appDeviceCallbackStub;
1956 MessageParcel data;
1957 MessageParcel reply;
1958 MessageOption option;
1959 data.WriteInterfaceToken(AppDeviceCallbackInterface::GetDescriptor());
1960 int32_t ret = appDeviceCallbackStub.OnRemoteRequest(INVALID_EVENT_DEVICE_CODE, data, reply, option);
1961 EXPECT_NE(ERR_NONE, ret);
1962 }
1963
1964 /**
1965 * @tc.name: OnDeviceEvent_001
1966 * @tc.desc: test OnDeviceConnect, OnDeviceDisconnect and OnDeviceCancel.
1967 * @tc.type: FUNC
1968 * @tc.require: I621C1
1969 */
1970 HWTEST_F(ContinuationManagerTest, OnDeviceEvent_001, TestSize.Level3)
1971 {
1972 AppDeviceCallbackStub appDeviceCallbackStub;
1973 std::vector<ContinuationResult> continuationResults;
1974 /**
1975 * @tc.steps: step1. test OnDeviceConnect
1976 */
1977 int32_t ret = appDeviceCallbackStub.OnDeviceConnect(TEST_TOKEN, continuationResults);
1978 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1979 /**
1980 * @tc.steps: step2. test OnDeviceDisconnect
1981 */
1982 ret = appDeviceCallbackStub.OnDeviceDisconnect(TEST_TOKEN, continuationResults);
1983 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1984 /**
1985 * @tc.steps: step3. test OnDeviceCancel
1986 */
1987 ret = appDeviceCallbackStub.OnDeviceCancel();
1988 EXPECT_EQ(DISCONNECT_ABILITY_FAILED, ret);
1989 }
1990
1991 /**
1992 * @tc.name: GetConnectStatusInfo_001
1993 * @tc.desc: test GetConnectStatusInfo
1994 * @tc.type: FUNC
1995 * @tc.require: I621C1
1996 */
1997 HWTEST_F(ContinuationManagerTest, GetConnectStatusInfo_001, TestSize.Level3)
1998 {
1999 NotifierInfo notifierInfo;
2000 /**
2001 * @tc.steps: step1. test DeleteNotifier when cbType is not in notifierMap_
2002 */
2003 notifierInfo.notifierMap_.clear();
2004 notifierInfo.DeleteNotifier(INVALID_CALLBACK_TYPE);
2005 /**
2006 * @tc.steps: step2. test RemoveDeathRecipient when cbType is not in notifierMap_
2007 */
2008 sptr<IRemoteObject::DeathRecipient> deathRecipient = nullptr;
2009 notifierInfo.RemoveDeathRecipient(deathRecipient, INVALID_CALLBACK_TYPE);
2010 /**
2011 * @tc.steps: step3. test GetConnectStatusInfo
2012 */
2013 notifierInfo.connectStatusInfo_ = nullptr;
2014 std::shared_ptr<ConnectStatusInfo> result = notifierInfo.GetConnectStatusInfo();
2015 EXPECT_EQ(nullptr, result);
2016 }
2017 } // namespace DistributedSchedule
2018 } // namespace OHOS
2019