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