• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "distributed_ability_manager_service_test.h"
16 
17 #include <thread>
18 #include "distributed_sched_test_util.h"
19 #include "dtbschedmgr_log.h"
20 #define private public
21 #include "continuation_extra_params.h"
22 #include "continuation_manager/app_connection_stub.h"
23 #include "continuation_manager/notifier_info.h"
24 #include "mission/distributed_sched_mission_manager.h"
25 #undef private
26 #include "test_log.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace DistributedSchedule {
33 namespace {
34 constexpr int32_t REGISTER = 500;
35 constexpr int32_t UPDATE_CONNECT_STATUS = 504;
36 constexpr int32_t INVALID_CODE = -1;
37 constexpr int32_t MAX_REGISTER_NUM = 600;
38 constexpr int32_t MAX_WAIT_TIME = 10000;
39 constexpr uint32_t TEST_UINT32_T = 0;
40 const std::u16string DMS_STUB_INTERFACE_TOKEN = u"OHOS.DistributedSchedule.IDistributedAbilityManager";
41 const std::u16string TEST_U16STRING = u"test u16string";
42 const std::string DEVICE_ID = "testDeviceId";
43 }
44 
45 sptr<DistributedAbilityManagerService>  DistributedAbilityManagerServiceTest::dtbabilitymgrService_;
46 int32_t DistributedAbilityManagerServiceTest::startTaskNum_ = 1;
47 std::mutex DistributedAbilityManagerServiceTest::caseDoneLock_;
48 std::condition_variable DistributedAbilityManagerServiceTest::caseDoneCondition_;
49 
OnDeviceConnect(const std::vector<ContinuationResult> & continuationResults)50 void DeviceSelectionNotifierTest::OnDeviceConnect(const std::vector<ContinuationResult>& continuationResults)
51 {
52 }
53 
OnDeviceDisconnect(const std::vector<ContinuationResult> & continuationResults)54 void DeviceSelectionNotifierTest::OnDeviceDisconnect(const std::vector<ContinuationResult>& continuationResults)
55 {
56 }
57 
SetUpTestCase()58 void DistributedAbilityManagerServiceTest::SetUpTestCase()
59 {
60     dtbabilitymgrService_ = new DistributedAbilityManagerService();
61     DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUpTestCase" << std::endl;
62 }
63 
TearDownTestCase()64 void DistributedAbilityManagerServiceTest::TearDownTestCase()
65 {
66     // Wait until all async tasks are completed before exiting the test suite
67     auto caseDoneNotifyTask = []() {
68         std::lock_guard<std::mutex> autoLock(caseDoneLock_);
69         --startTaskNum_;
70         caseDoneCondition_.notify_one();
71     };
72     if (dtbabilitymgrService_ != nullptr && dtbabilitymgrService_->continuationHandler_ != nullptr) {
73         dtbabilitymgrService_->continuationHandler_->submit(caseDoneNotifyTask);
74     }
75     std::unique_lock<std::mutex> lock(caseDoneLock_);
76     caseDoneCondition_.wait_for(lock, std::chrono::milliseconds(MAX_WAIT_TIME),
77         [&] () { return startTaskNum_ == 0; });
78     DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDownTestCase" << std::endl;
79 }
80 
SetUp()81 void DistributedAbilityManagerServiceTest::SetUp()
82 {
83     DTEST_LOG << "DistributedAbilityManagerServiceTest::SetUp" << std::endl;
84 }
85 
TearDown()86 void DistributedAbilityManagerServiceTest::TearDown()
87 {
88     DTEST_LOG << "DistributedAbilityManagerServiceTest::TearDown" << std::endl;
89 }
90 
91 /**
92  * @tc.name: Dump_001
93  * @tc.desc: test Dump when args is not empty.
94  * @tc.type: FUNC
95  * @tc.require: I6NMR8
96  */
97 HWTEST_F(DistributedAbilityManagerServiceTest, Dump_001, TestSize.Level3)
98 {
99     DTEST_LOG << "DistributedAbilityManagerServiceTest Dump_001 start" << std::endl;
100     ASSERT_NE(nullptr, dtbabilitymgrService_);
101     /**
102      * @tc.steps: step1. test Dump when args is not empty.
103      */
104     std::vector<std::u16string> args;
105     args.push_back(TEST_U16STRING);
106     int32_t result = dtbabilitymgrService_->Dump(INVALID_CODE, args);
107     EXPECT_EQ(result, DMS_WRITE_FILE_FAILED_ERR);
108     /**
109      * @tc.steps: step2. test DumpAppRegisterInfo when tokenMap_ is not empty.
110      */
111     std::string info;
112     std::vector<int32_t> tokenMapValue;
113     {
114         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->tokenMapMutex_);
115         dtbabilitymgrService_->tokenMap_.clear();
116         tokenMapValue.push_back(INVALID_CODE);
117         dtbabilitymgrService_->tokenMap_[TEST_UINT32_T] = tokenMapValue;
118     }
119     dtbabilitymgrService_->DumpAppRegisterInfo(info);
120     {
121         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->tokenMapMutex_);
122         dtbabilitymgrService_->tokenMap_.clear();
123     }
124     DTEST_LOG << "DistributedAbilityManagerServiceTest Dump_001 end" << std::endl;
125 }
126 
127 /**
128  * @tc.name: OnRemoteRequest_001
129  * @tc.desc: test OnRemoteRequest to start Register
130  * @tc.type: FUNC
131  * @tc.require: I5NOA1
132  */
133 HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_001, TestSize.Level3)
134 {
135     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 start" << std::endl;
136     ASSERT_NE(nullptr, dtbabilitymgrService_);
137     MessageParcel data;
138     MessageParcel reply;
139     MessageOption option;
140     data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
141     int32_t result = dtbabilitymgrService_->OnRemoteRequest(REGISTER, data, reply, option);
142     EXPECT_EQ(ERR_INVALID_DATA, result);
143     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_001 end" << std::endl;
144 }
145 
146 /**
147  * @tc.name: OnRemoteRequest_002
148  * @tc.desc: test OnRemoteRequest with invalid code
149  * @tc.type: FUNC
150  * @tc.require: I5NOA1
151  */
152 HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_002, TestSize.Level3)
153 {
154     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 start" << std::endl;
155     ASSERT_NE(nullptr, dtbabilitymgrService_);
156     MessageParcel data;
157     MessageParcel reply;
158     MessageOption option;
159     data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
160     int32_t result = dtbabilitymgrService_->OnRemoteRequest(INVALID_CODE, data, reply, option);
161     EXPECT_NE(ERR_NONE, result);
162     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_002 end" << std::endl;
163 }
164 
165 /**
166  * @tc.name: OnRemoteRequest_003
167  * @tc.desc: test OnRemoteRequest to start funcsMap_ without token
168  * @tc.type: FUNC
169  * @tc.require: I5NOA1
170  */
171 HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_003, TestSize.Level3)
172 {
173     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 start" << std::endl;
174     ASSERT_NE(nullptr, dtbabilitymgrService_);
175     MessageParcel data;
176     MessageParcel reply;
177     MessageOption option;
178     int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
179     EXPECT_EQ(ERR_TRANSACTION_FAILED, result);
180     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_003 end" << std::endl;
181 }
182 
183 /**
184  * @tc.name: OnRemoteRequest_004
185  * @tc.desc: test OnRemoteRequest to start funcsMap_ without DATASYNC permission
186  * @tc.type: FUNC
187  * @tc.require: I5NOA1
188  */
189 HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_004, TestSize.Level3)
190 {
191     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 start" << std::endl;
192     ASSERT_NE(nullptr, dtbabilitymgrService_);
193     MessageParcel data;
194     MessageParcel reply;
195     MessageOption option;
196     data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
197     int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
198     EXPECT_EQ(ERR_INVALID_DATA, result);
199     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_004 end" << std::endl;
200 }
201 
202 /**
203  * @tc.name: OnRemoteRequest_005
204  * @tc.desc: test OnRemoteRequest to start funcsMap_ with DATASYNC permission
205  * @tc.type: FUNC
206  */
207 HWTEST_F(DistributedAbilityManagerServiceTest, OnRemoteRequest_005, TestSize.Level3)
208 {
209     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 start" << std::endl;
210     ASSERT_NE(nullptr, dtbabilitymgrService_);
211     DistributedSchedUtil::MockPermission();
212     MessageParcel data;
213     MessageParcel reply;
214     MessageOption option;
215     data.WriteInterfaceToken(DMS_STUB_INTERFACE_TOKEN);
216     int32_t result = dtbabilitymgrService_->OnRemoteRequest(UPDATE_CONNECT_STATUS, data, reply, option);
217     EXPECT_NE(ERR_NONE, result);
218     DTEST_LOG << "DistributedAbilityManagerServiceTest OnRemoteRequest_005 end" << std::endl;
219 }
220 
221 /**
222  * @tc.name: Register_001
223  * @tc.desc: test Register when continuationExtraParams != nullptr.
224  * @tc.type: FUNC
225  * @tc.require: I6NMR8
226  */
227 HWTEST_F(DistributedAbilityManagerServiceTest, Register_001, TestSize.Level3)
228 {
229     DTEST_LOG << "DistributedAbilityManagerServiceTest Register_001 start" << std::endl;
230     ASSERT_NE(nullptr, dtbabilitymgrService_);
231     /**
232      * @tc.steps: step1. test DumpNotifierLocked when callbackMap_ is not empty.
233      */
234     std::vector<int32_t> tokenVec;
235     std::string info;
236     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
237     {
238         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
239         dtbabilitymgrService_->callbackMap_.clear();
240         dtbabilitymgrService_->callbackMap_[INVALID_CODE] = std::move(notifierInfo);;
241     }
242     tokenVec.push_back(INVALID_CODE);
243     dtbabilitymgrService_->DumpNotifierLocked(tokenVec, info);
244     /**
245      * @tc.steps: step2. test Register when register max num.
246      */
247     int32_t token = 0;
248     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
249     for (int32_t i = 0; i < MAX_REGISTER_NUM; i++) {
250         dtbabilitymgrService_->Register(continuationExtraParams, token);
251     }
252     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
253     EXPECT_EQ(ret, REGISTER_EXCEED_MAX_TIMES);
254     {
255         std::lock_guard<std::mutex> tokenLock(dtbabilitymgrService_->tokenMutex_);
256         dtbabilitymgrService_->tokenMap_.clear();
257     }
258     DTEST_LOG << "DistributedAbilityManagerServiceTest Register_001 end" << std::endl;
259 }
260 
261 /**
262  * @tc.name: Unregister_001
263  * @tc.desc: test Unregister
264  * @tc.type: FUNC
265  * @tc.require: I5NOA1
266  */
267 HWTEST_F(DistributedAbilityManagerServiceTest, Unregister_001, TestSize.Level3)
268 {
269     DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_001 start" << std::endl;
270     ASSERT_NE(nullptr, dtbabilitymgrService_);
271     /**
272      * @tc.steps: step1. test Unregister when permission check failed.
273      */
274     DistributedSchedUtil::MockBundlePermission();
275     int32_t ret = dtbabilitymgrService_->Unregister(INVALID_CODE);
276     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
277     /**
278      * @tc.steps: step2. test Unregister when token is not registered.
279      */
280     DistributedSchedUtil::MockPermission();
281     ret = dtbabilitymgrService_->Unregister(INVALID_CODE);
282     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
283     /**
284      * @tc.steps: step3. test Unregister when notifier is not registered.
285      */
286     {
287         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
288         dtbabilitymgrService_->callbackMap_.clear();
289     }
290     int32_t token = 0;
291     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
292     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
293     EXPECT_EQ(ret, ERR_OK);
294     ret = dtbabilitymgrService_->Unregister(token);
295     EXPECT_EQ(ret, ERR_OK);
296     /**
297      * @tc.steps: step4. test Unregister when notifier is registered.
298      */
299     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
300     EXPECT_EQ(ret, ERR_OK);
301     {
302         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
303         std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
304         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
305     }
306     ret = dtbabilitymgrService_->Unregister(token);
307     EXPECT_EQ(ret, ERR_OK);
308     {
309         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
310         dtbabilitymgrService_->callbackMap_.clear();
311     }
312     DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_001 end" << std::endl;
313 }
314 
315 /**
316  * @tc.name: Unregister_002
317  * @tc.desc: test Unregister when iter->second is not empty.
318  * @tc.type: FUNC
319  * @tc.require: I5NOA1
320  */
321 HWTEST_F(DistributedAbilityManagerServiceTest, Unregister_002, TestSize.Level3)
322 {
323     DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_002 start" << std::endl;
324     ASSERT_NE(nullptr, dtbabilitymgrService_);
325     /**
326      * @tc.steps: step1. test Unregister when iter->second is not empty.
327      */
328     int32_t token = 0;
329     int32_t tokenBackup = 0;
330     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
331     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
332     EXPECT_EQ(ret, ERR_OK);
333     ret = dtbabilitymgrService_->Register(continuationExtraParams, tokenBackup);
334     EXPECT_EQ(ret, ERR_OK);
335     {
336         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
337         std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
338         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
339     }
340     ret = dtbabilitymgrService_->Unregister(token);
341     EXPECT_EQ(ret, ERR_OK);
342     ret = dtbabilitymgrService_->Unregister(tokenBackup);
343     EXPECT_EQ(ret, ERR_OK);
344     {
345         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
346         dtbabilitymgrService_->callbackMap_.clear();
347     }
348     DTEST_LOG << "DistributedAbilityManagerServiceTest Unregister_002 end" << std::endl;
349 }
350 
351 /**
352  * @tc.name: RegisterDeviceSelectionCallback_001
353  * @tc.desc: test RegisterDeviceSelectionCallback
354  * @tc.type: FUNC
355  * @tc.require: I5NOA1
356  */
357 HWTEST_F(DistributedAbilityManagerServiceTest, RegisterDeviceSelectionCallback_001, TestSize.Level3)
358 {
359     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_001 start" << std::endl;
360     ASSERT_NE(nullptr, dtbabilitymgrService_);
361     /**
362      * @tc.steps: step1. test RegisterDeviceSelectionCallback when permission check failed.
363      */
364     DistributedSchedUtil::MockBundlePermission();
365     int32_t ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(INVALID_CODE, "", nullptr);
366     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
367     /**
368      * @tc.steps: step2. test RegisterDeviceSelectionCallback when cbType is invalid.
369      */
370     DistributedSchedUtil::MockPermission();
371     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(INVALID_CODE, "", nullptr);
372     EXPECT_EQ(ret, UNKNOWN_CALLBACK_TYPE);
373     /**
374      * @tc.steps: step3. test RegisterDeviceSelectionCallback when cbType has registered.
375      */
376     int32_t token = 0;
377     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
378     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
379     EXPECT_EQ(ret, ERR_OK);
380     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
381     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
382     EXPECT_EQ(ret, ERR_OK);
383     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
384     EXPECT_EQ(ret, CALLBACK_HAS_REGISTERED);
385 
386     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
387     EXPECT_EQ(ret, ERR_OK);
388     ret = dtbabilitymgrService_->Unregister(token);
389     EXPECT_EQ(ret, ERR_OK);
390     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_001 end" << std::endl;
391 }
392 
393 /**
394  * @tc.name: RegisterDeviceSelectionCallback_002
395  * @tc.desc: test RegisterDeviceSelectionCallback
396  * @tc.type: FUNC
397  * @tc.require: I5NOA1
398  */
399 HWTEST_F(DistributedAbilityManagerServiceTest, RegisterDeviceSelectionCallback_002, TestSize.Level3)
400 {
401     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_002 start" << std::endl;
402     ASSERT_NE(nullptr, dtbabilitymgrService_);
403     /**
404      * @tc.steps: step1. test RegisterDeviceSelectionCallback when iter->second != nullptr.
405      */
406     int32_t token = 0;
407     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
408     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
409     EXPECT_EQ(ret, ERR_OK);
410     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
411     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
412     EXPECT_EQ(ret, ERR_OK);
413     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_DISCONNECT, notifier);
414     EXPECT_EQ(ret, ERR_OK);
415 
416     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
417     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_DISCONNECT);
418     EXPECT_EQ(ret, ERR_OK);
419     ret = dtbabilitymgrService_->Unregister(token);
420     EXPECT_EQ(ret, ERR_OK);
421     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_002 end" << std::endl;
422 }
423 
424 /**
425  * @tc.name: RegisterDeviceSelectionCallback_003
426  * @tc.desc: test RegisterDeviceSelectionCallback
427  * @tc.type: FUNC
428  * @tc.require: I5NOA1
429  */
430 HWTEST_F(DistributedAbilityManagerServiceTest, RegisterDeviceSelectionCallback_003, TestSize.Level3)
431 {
432     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_002 start" << std::endl;
433     ASSERT_NE(nullptr, dtbabilitymgrService_);
434     /**
435      * @tc.steps: step1. test RegisterDeviceSelectionCallback when iter->second != nullptr.
436      */
437     int32_t token = 0;
438     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
439     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
440     EXPECT_EQ(ret, ERR_OK);
441     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
442     {
443         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
444         dtbabilitymgrService_->callbackMap_[token] = nullptr;
445     }
446     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
447     EXPECT_EQ(ret, ERR_NULL_OBJECT);
448     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterDeviceSelectionCallback_003 end" << std::endl;
449 }
450 
451 /**
452  * @tc.name: IsTokenRegistered_001
453  * @tc.desc: test IsTokenRegistered
454  * @tc.type: FUNC
455  * @tc.require: I5NOA1
456  */
457 HWTEST_F(DistributedAbilityManagerServiceTest, IsTokenRegistered_001, TestSize.Level3)
458 {
459     DTEST_LOG << "DistributedAbilityManagerServiceTest IsTokenRegistered_001 start" << std::endl;
460     ASSERT_NE(nullptr, dtbabilitymgrService_);
461     /**
462      * @tc.steps: step1. test RegisterDeviceSelectionCallback when iter->second != nullptr.
463      */
464     int32_t token = 0;
465     {
466         std::lock_guard<std::mutex> tokenMapLock(dtbabilitymgrService_->tokenMapMutex_);
467         dtbabilitymgrService_->tokenMap_.clear();
468         std::vector<int32_t> vec;
469         for (int32_t i = 0; i < MAX_REGISTER_NUM; ++i) {
470             vec.push_back(INVALID_CODE);
471         }
472         dtbabilitymgrService_->tokenMap_[TEST_UINT32_T] = vec;
473     }
474     int32_t ret = dtbabilitymgrService_->IsTokenRegistered(TEST_UINT32_T, token);
475     EXPECT_EQ(ret, ERR_OK);
476     DTEST_LOG << "DistributedAbilityManagerServiceTest IsTokenRegistered_001 end" << std::endl;
477 }
478 
479 /**
480  * @tc.name: UnregisterDeviceSelectionCallback_001
481  * @tc.desc: test UnregisterDeviceSelectionCallback
482  * @tc.type: FUNC
483  * @tc.require: I5NOA1
484  */
485 HWTEST_F(DistributedAbilityManagerServiceTest, UnregisterDeviceSelectionCallback_001, TestSize.Level3)
486 {
487     DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_001 start" << std::endl;
488     ASSERT_NE(nullptr, dtbabilitymgrService_);
489     /**
490      * @tc.steps: step1. test UnregisterDeviceSelectionCallback when cbType is invalid.
491      */
492     int32_t ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, "");
493     EXPECT_EQ(ret, UNKNOWN_CALLBACK_TYPE);
494     /**
495      * @tc.steps: step2. test UnregisterDeviceSelectionCallback when cbType == EVENT_CONNECT.
496      */
497     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, EVENT_CONNECT);
498     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
499     /**
500      * @tc.steps: step3. test UnregisterDeviceSelectionCallback when cbType == EVENT_DISCONNECT.
501      */
502     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(INVALID_CODE, EVENT_DISCONNECT);
503     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
504     /**
505      * @tc.steps: step4. test UnregisterDeviceSelectionCallback when token is registered.
506      */
507     int32_t token = 0;
508     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
509     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
510     EXPECT_EQ(ret, ERR_OK);
511     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
512     EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
513     /**
514      * @tc.steps: step5. test UnregisterDeviceSelectionCallback when callback is registered.
515      */
516     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
517     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
518     EXPECT_EQ(ret, ERR_OK);
519 
520     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
521     EXPECT_EQ(ret, ERR_OK);
522     ret = dtbabilitymgrService_->Unregister(token);
523     EXPECT_EQ(ret, ERR_OK);
524     DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_001 end" << std::endl;
525 }
526 
527 /**
528  * @tc.name: UnregisterDeviceSelectionCallback_002
529  * @tc.desc: test UnregisterDeviceSelectionCallback when callback is registered.
530  * @tc.type: FUNC
531  * @tc.require: I5NOA1
532  */
533 HWTEST_F(DistributedAbilityManagerServiceTest, UnregisterDeviceSelectionCallback_002, TestSize.Level3)
534 {
535     DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_002 start" << std::endl;
536     ASSERT_NE(nullptr, dtbabilitymgrService_);
537     /**
538      * @tc.steps: step1. test UnregisterDeviceSelectionCallback when callback is registered.
539      */
540     int32_t token = 0;
541     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
542     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
543     EXPECT_EQ(ret, ERR_OK);
544     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
545     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
546     EXPECT_EQ(ret, ERR_OK);
547     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_DISCONNECT, notifier);
548     EXPECT_EQ(ret, ERR_OK);
549 
550     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
551     EXPECT_EQ(ret, ERR_OK);
552     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_DISCONNECT);
553     EXPECT_EQ(ret, ERR_OK);
554     ret = dtbabilitymgrService_->Unregister(token);
555     EXPECT_EQ(ret, ERR_OK);
556     DTEST_LOG << "DistributedAbilityManagerServiceTest UnregisterDeviceSelectionCallback_002 end" << std::endl;
557 }
558 
559 /**
560  * @tc.name: UpdateConnectStatus_001
561  * @tc.desc: test UpdateConnectStatus
562  * @tc.type: FUNC
563  * @tc.require: I5NOA1
564  */
565 HWTEST_F(DistributedAbilityManagerServiceTest, UpdateConnectStatus_001, TestSize.Level3)
566 {
567     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_001 start" << std::endl;
568     ASSERT_NE(nullptr, dtbabilitymgrService_);
569     /**
570      * @tc.steps: step1. test UpdateConnectStatus when permission check failed.
571      */
572     DistributedSchedUtil::MockBundlePermission();
573     int32_t ret = dtbabilitymgrService_->UpdateConnectStatus(INVALID_CODE, "", DeviceConnectStatus::IDLE);
574     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
575     /**
576      * @tc.steps: step2. test UpdateConnectStatus when deviceId is empty.
577      */
578     DistributedSchedUtil::MockPermission();
579     ret = dtbabilitymgrService_->UpdateConnectStatus(INVALID_CODE, "", DeviceConnectStatus::IDLE);
580     EXPECT_EQ(ret, ERR_NULL_OBJECT);
581     /**
582      * @tc.steps: step3. test UpdateConnectStatus when token is not registered.
583      */
584     ret = dtbabilitymgrService_->UpdateConnectStatus(INVALID_CODE, DEVICE_ID, DeviceConnectStatus::IDLE);
585     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
586     /**
587      * @tc.steps: step4. test UpdateConnectStatus when callback is not registered.
588      */
589     int32_t token = 0;
590     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
591     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
592     EXPECT_EQ(ret, ERR_OK);
593     ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
594     EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
595     /**
596      * @tc.steps: step5. test UpdateConnectStatus when callback is registered.
597      */
598     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
599     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
600     EXPECT_EQ(ret, ERR_OK);
601     ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
602     EXPECT_EQ(ret, ERR_OK);
603     /**
604      * @tc.steps: step6. test UpdateConnectStatus when appProxy_ is nullptr.
605      */
606     {
607         std::lock_guard<std::mutex> appProxyLock(dtbabilitymgrService_->appProxyMutex_);
608         dtbabilitymgrService_->appProxy_ = nullptr;
609     }
610     ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
611     EXPECT_EQ(ret, ERR_OK);
612 
613     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
614     EXPECT_EQ(ret, ERR_OK);
615     ret = dtbabilitymgrService_->Unregister(token);
616     EXPECT_EQ(ret, ERR_OK);
617     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_001 end" << std::endl;
618 }
619 
620 /**
621  * @tc.name: ConnectAbility
622  * @tc.desc: test ConnectAbility
623  * @tc.type: FUNC
624  */
625 HWTEST_F(DistributedAbilityManagerServiceTest, ConnectAbility_001, TestSize.Level3)
626 {
627     DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 start" << std::endl;
628     ASSERT_NE(nullptr, dtbabilitymgrService_);
629     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
630     int32_t ret = dtbabilitymgrService_->ConnectAbility(1, continuationExtraParams);
631     EXPECT_NE(ret, true);
632     DTEST_LOG << "DistributedAbilityManagerServiceTest ConnectAbility_001 end" << std::endl;
633 }
634 
635 /**
636  * @tc.name: OnDeviceDisconnect_001
637  * @tc.desc: test OnDeviceDisconnect
638  * @tc.type: FUNC
639  * @tc.require: I5NOA1
640  */
641 HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceDisconnect_001, TestSize.Level3)
642 {
643     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceDisconnect_001 start" << std::endl;
644     ASSERT_NE(nullptr, dtbabilitymgrService_);
645     /**
646      * @tc.steps: step1. test OnDeviceDisconnect when callback has not registered.
647      */
648     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
649         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
650     }
651     std::vector<ContinuationResult> continuationResults;
652     int32_t ret = dtbabilitymgrService_->OnDeviceDisconnect(INVALID_CODE, continuationResults);
653     EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
654     /**
655      * @tc.steps: step2. test OnDeviceDisconnect when callback has registered.
656      */
657     int32_t token = 0;
658     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
659     ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
660     EXPECT_EQ(ret, ERR_OK);
661     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
662     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_DISCONNECT, notifier);
663     EXPECT_EQ(ret, ERR_OK);
664     ret = dtbabilitymgrService_->OnDeviceDisconnect(token, continuationResults);
665     EXPECT_EQ(ret, ERR_OK);
666 
667     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_DISCONNECT);
668     EXPECT_EQ(ret, ERR_OK);
669     ret = dtbabilitymgrService_->Unregister(token);
670     EXPECT_EQ(ret, ERR_OK);
671     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceDisconnect_001 end" << std::endl;
672 }
673 
674 /**
675  * @tc.name: IsExceededRegisterMaxNum_001
676  * @tc.desc: test IsExceededRegisterMaxNum when IsExceededRegisterMaxNum returns true.
677  * @tc.type: FUNC
678  * @tc.require: I5NOA1
679  */
680 HWTEST_F(DistributedAbilityManagerServiceTest, IsExceededRegisterMaxNum_001, TestSize.Level3)
681 {
682     DTEST_LOG << "DistributedAbilityManagerServiceTest IsExceededRegisterMaxNum_001 start" << std::endl;
683     ASSERT_NE(nullptr, dtbabilitymgrService_);
684     {
685         std::lock_guard<std::mutex> tokenMapLock(dtbabilitymgrService_->tokenMapMutex_);
686         dtbabilitymgrService_->tokenMap_.clear();
687         std::vector<int32_t> vec;
688         for (int32_t i = 0; i < MAX_REGISTER_NUM; ++i) {
689             vec.push_back(INVALID_CODE);
690         }
691         dtbabilitymgrService_->tokenMap_[TEST_UINT32_T] = vec;
692     }
693     bool ret = dtbabilitymgrService_->IsExceededRegisterMaxNum(TEST_UINT32_T);
694     EXPECT_EQ(ret, true);
695     DTEST_LOG << "DistributedAbilityManagerServiceTest IsExceededRegisterMaxNum_001 end" << std::endl;
696 }
697 
698 /**
699  * @tc.name: IsNotifierRegistered_001
700  * @tc.desc: test IsNotifierRegistered when callbackMap_[token] = nullptr.
701  * @tc.type: FUNC
702  * @tc.require: I5NOA1
703  */
704 HWTEST_F(DistributedAbilityManagerServiceTest, IsNotifierRegistered_001, TestSize.Level3)
705 {
706     DTEST_LOG << "DistributedAbilityManagerServiceTest IsNotifierRegistered_001 start" << std::endl;
707     ASSERT_NE(nullptr, dtbabilitymgrService_);
708     {
709         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
710         dtbabilitymgrService_->callbackMap_[INVALID_CODE] = nullptr;
711     }
712     bool ret = dtbabilitymgrService_->IsNotifierRegistered(INVALID_CODE);
713     EXPECT_EQ(ret, false);
714     DTEST_LOG << "DistributedAbilityManagerServiceTest IsNotifierRegistered_001 end" << std::endl;
715 }
716 
717 /**
718  * @tc.name: HandleDeviceConnect_002
719  * @tc.desc: test HandleDeviceConnect when continuationHandler_ == nullptr.
720  * @tc.type: FUNC
721  * @tc.require: I5NOA1
722  */
723 HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_002, TestSize.Level3)
724 {
725     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_002 start" << std::endl;
726     ASSERT_NE(nullptr, dtbabilitymgrService_);
727     dtbabilitymgrService_->continuationHandler_ = nullptr;
728     std::vector<ContinuationResult> continuationResults;
729     bool ret = dtbabilitymgrService_->HandleDeviceConnect(nullptr, continuationResults);
730     EXPECT_EQ(ret, false);
731     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_002 end" << std::endl;
732 }
733 
734 /**
735  * @tc.name: HandleDeviceDisconnect
736  * @tc.desc: test HandleDeviceDisconnect
737  * @tc.type: FUNC
738  */
739 HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_001, TestSize.Level3)
740 {
741     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_001 start" << std::endl;
742     ASSERT_NE(nullptr, dtbabilitymgrService_);
743     std::vector<ContinuationResult> continuationResults;
744     bool ret = dtbabilitymgrService_->HandleDeviceDisconnect(dtbabilitymgrService_, continuationResults);
745     EXPECT_NE(ret, true);
746     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
747     dtbabilitymgrService_->ScheduleStartDeviceManager(nullptr, 1, continuationExtraParams);
748     dtbabilitymgrService_->ScheduleStartDeviceManager(dtbabilitymgrService_, 1, continuationExtraParams);
749     dtbabilitymgrService_->HandleStartDeviceManager(1, continuationExtraParams);
750     dtbabilitymgrService_->HandleStartDeviceManager(1, nullptr);
751     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
752         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
753     }
754     bool result = dtbabilitymgrService_->HandleDeviceConnect(dtbabilitymgrService_, continuationResults);
755     dtbabilitymgrService_->HandleStartDeviceManager(1, continuationExtraParams);
756     dtbabilitymgrService_->HandleStartDeviceManager(1, nullptr);
757     EXPECT_EQ(result, true);
758     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_001 end" << std::endl;
759 }
760 
761 /**
762  * @tc.name: HandleDeviceDisconnect_002
763  * @tc.desc: test HandleDeviceDisconnect when continuationHandler_ != nullptr.
764  * @tc.type: FUNC
765  * @tc.require: I5NOA1
766  */
767 HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceDisconnect_002, TestSize.Level3)
768 {
769     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_002 start" << std::endl;
770     ASSERT_NE(nullptr, dtbabilitymgrService_);
771     /**
772      * @tc.steps: step1. test HandleUpdateConnectStatus when continuationHandler_ is nullptr.
773      */
774     dtbabilitymgrService_->continuationHandler_ = nullptr;
775     dtbabilitymgrService_->HandleUpdateConnectStatus(INVALID_CODE, DEVICE_ID, DeviceConnectStatus::CONNECTED);
776     /**
777      * @tc.steps: step2. test HandleDeviceConnect when continuationHandler_ is not nullptr.
778      */
779     dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
780     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
781     std::vector<ContinuationResult> continuationResults;
782     bool ret = dtbabilitymgrService_->HandleDeviceDisconnect(notifier, continuationResults);
783     EXPECT_EQ(ret, true);
784     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceDisconnect_002 end" << std::endl;
785 }
786 
787 /**
788  * @tc.name: HandleDeviceConnect
789  * @tc.desc: test HandleDeviceConnect
790  * @tc.type: FUNC
791  */
792 HWTEST_F(DistributedAbilityManagerServiceTest, HandleDeviceConnect_001, TestSize.Level3)
793 {
794     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_001 start" << std::endl;
795     ASSERT_NE(nullptr, dtbabilitymgrService_);
796     std::vector<ContinuationResult> continuationResults;
797     int32_t ret = dtbabilitymgrService_->HandleDeviceConnect(dtbabilitymgrService_, continuationResults);
798     EXPECT_EQ(ret, true);
799     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleDeviceConnect_001 end" << std::endl;
800 }
801 
802 /**
803  * @tc.name: QueryTokenByNotifier_001
804  * @tc.desc: test QueryTokenByNotifier when iter->second == nullptr.
805  * @tc.type: FUNC
806  * @tc.require: I5NOA1
807  */
808 HWTEST_F(DistributedAbilityManagerServiceTest, QueryTokenByNotifier_001, TestSize.Level3)
809 {
810     DTEST_LOG << "DistributedAbilityManagerServiceTest QueryTokenByNotifier_001 start" << std::endl;
811     ASSERT_NE(nullptr, dtbabilitymgrService_);
812     /**
813      * @tc.steps: step1. test QueryTokenByNotifier when iter->second == nullptr.
814      */
815     {
816         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
817         dtbabilitymgrService_->callbackMap_.clear();
818         dtbabilitymgrService_->callbackMap_[INVALID_CODE] = nullptr;
819     }
820     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
821     int32_t token;
822     bool ret = dtbabilitymgrService_->QueryTokenByNotifier(notifier, token);
823     EXPECT_FALSE(ret);
824     {
825         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
826         dtbabilitymgrService_->callbackMap_.clear();
827     }
828     /**
829      * @tc.steps: step2. test ProcessNotifierDied when notifier != nullptr.
830      */
831     dtbabilitymgrService_->ProcessNotifierDied(notifier);
832     /**
833      * @tc.steps: step3. test HandleNotifierDied when continuationHandler_ == nullptr.
834      */
835     dtbabilitymgrService_->continuationHandler_ = nullptr;
836     dtbabilitymgrService_->HandleNotifierDied(nullptr);
837     /**
838      * @tc.steps: step4. test HandleNotifierDied when QueryTokenByNotifier returns true.
839      */
840     dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
841     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
842     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
843     {
844         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
845         dtbabilitymgrService_->callbackMap_[INVALID_CODE] = std::move(notifierInfo);;
846     }
847     dtbabilitymgrService_->HandleNotifierDied(notifier);
848     DTEST_LOG << "DistributedAbilityManagerServiceTest QueryTokenByNotifier_001 end" << std::endl;
849 }
850 
851 /**
852  * @tc.name: HandleNotifierDied_001
853  * @tc.desc: test HandleNotifierDied
854  * @tc.type: FUNC
855  */
856 HWTEST_F(DistributedAbilityManagerServiceTest, HandleNotifierDied_001, TestSize.Level3)
857 {
858     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_001 start" << std::endl;
859     ASSERT_NE(nullptr, dtbabilitymgrService_);
860     /**
861      * @tc.steps: step1. test HandleNotifierDied.
862      */
863     std::vector<ContinuationResult> continuationResults;
864     dtbabilitymgrService_->HandleNotifierDied(dtbabilitymgrService_);
865     /**
866      * @tc.steps: step2. test HandleNotifierDied when IsNotifierRegistered returns true.
867      */
868     int32_t token = 0;
869     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
870     int32_t res = dtbabilitymgrService_->Register(continuationExtraParams, token);
871     EXPECT_EQ(res, ERR_OK);
872     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
873     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
874     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
875     {
876         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
877         dtbabilitymgrService_->callbackMap_.clear();
878         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
879     }
880     dtbabilitymgrService_->HandleNotifierDied(notifier);
881     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_001 end" << std::endl;
882 }
883 
884 /**
885  * @tc.name: OnDeviceCancel_001
886  * @tc.desc: test OnDeviceCancel
887  * @tc.type: FUNC
888  */
889 HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceCancel_001, TestSize.Level3)
890 {
891     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceCancel_001 start" << std::endl;
892     ASSERT_NE(nullptr, dtbabilitymgrService_);
893     int32_t ret = dtbabilitymgrService_->OnDeviceCancel();
894     EXPECT_NE(ret, true);
895     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceCancel_001 end" << std::endl;
896 }
897 
898 /**
899  * @tc.name: HandleUpdateConnectStatus
900  * @tc.desc: test HandleUpdateConnectStatus
901  * @tc.type: FUNC
902  */
903 HWTEST_F(DistributedAbilityManagerServiceTest, HandleUpdateConnectStatus_001, TestSize.Level3)
904 {
905     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleUpdateConnectStatus_001 start" << std::endl;
906     ASSERT_NE(nullptr, dtbabilitymgrService_);
907     DeviceConnectStatus deviceConnectStatus = DeviceConnectStatus::CONNECTING;
908     dtbabilitymgrService_->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
909     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
910         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
911     }
912     dtbabilitymgrService_->HandleUpdateConnectStatus(1, DEVICE_ID, deviceConnectStatus);
913     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleUpdateConnectStatus_001 end" << std::endl;
914 }
915 
916 /**
917  * @tc.name: DumpNotifierLocked_002
918  * @tc.desc: test DumpNotifierLocked
919  * @tc.type: FUNC
920  * @tc.require: I76U22
921  */
922 HWTEST_F(DistributedAbilityManagerServiceTest, DumpNotifierLocked_002, TestSize.Level3)
923 {
924     DTEST_LOG << "DistributedAbilityManagerServiceTest DumpNotifierLocked_002 start" << std::endl;
925     ASSERT_NE(nullptr, dtbabilitymgrService_);
926     /**
927      * @tc.steps: step1. test DumpNotifierLocked when callbackMap_ is not empty.
928      */
929     std::vector<int32_t> tokenVec;
930     std::string info;
931     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
932     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
933     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
934     {
935         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
936         dtbabilitymgrService_->callbackMap_.clear();
937         dtbabilitymgrService_->callbackMap_[INVALID_CODE] = std::move(notifierInfo);;
938     }
939     tokenVec.push_back(INVALID_CODE);
940     dtbabilitymgrService_->DumpNotifierLocked(tokenVec, info);
941     EXPECT_NE(dtbabilitymgrService_, nullptr);
942     {
943         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
944         dtbabilitymgrService_->callbackMap_.clear();
945     }
946     DTEST_LOG << "DistributedAbilityManagerServiceTest DumpNotifierLocked_002 end" << std::endl;
947 }
948 
949 /**
950  * @tc.name: Register_002
951  * @tc.desc: test Register when continuationExtraParams != nullptr.
952  * @tc.type: FUNC
953  * @tc.require: I76U22
954  */
955 HWTEST_F(DistributedAbilityManagerServiceTest, Register_002, TestSize.Level3)
956 {
957     DTEST_LOG << "DistributedAbilityManagerServiceTest Register_002 start" << std::endl;
958     ASSERT_NE(nullptr, dtbabilitymgrService_);
959 
960     int32_t token = 0;
961     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
962     ContinuationMode continuationMode = static_cast<ContinuationMode>(-1);
963     continuationExtraParams->SetContinuationMode(continuationMode);
964     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
965     EXPECT_EQ(ret, INVALID_CONTINUATION_MODE);
966     {
967         std::lock_guard<std::mutex> tokenLock(dtbabilitymgrService_->tokenMutex_);
968         dtbabilitymgrService_->tokenMap_.clear();
969     }
970     DTEST_LOG << "DistributedAbilityManagerServiceTest Register_002 end" << std::endl;
971 }
972 
973 /**
974  * @tc.name: UpdateConnectStatus_002
975  * @tc.desc: test UpdateConnectStatus
976  * @tc.type: FUNC
977  * @tc.require: I76U22
978  */
979 HWTEST_F(DistributedAbilityManagerServiceTest, UpdateConnectStatus_002, TestSize.Level3)
980 {
981     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_002 start" << std::endl;
982     ASSERT_NE(nullptr, dtbabilitymgrService_);
983 
984     int32_t token = 0;
985     DeviceConnectStatus deviceConnectStatus = static_cast<DeviceConnectStatus>(-1);
986     int32_t ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, deviceConnectStatus);
987     EXPECT_EQ(ret, INVALID_CONNECT_STATUS);
988     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_002 end" << std::endl;
989 }
990 
991 /**
992  * @tc.name: UpdateConnectStatus_003
993  * @tc.desc: test UpdateConnectStatus
994  * @tc.type: FUNC
995  * @tc.require: I5NOA1
996  */
997 HWTEST_F(DistributedAbilityManagerServiceTest, UpdateConnectStatus_003, TestSize.Level3)
998 {
999     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_003 start" << std::endl;
1000     ASSERT_NE(nullptr, dtbabilitymgrService_);
1001     int32_t token = 0;
1002     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1003     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
1004     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1005     ret = dtbabilitymgrService_->RegisterDeviceSelectionCallback(token, EVENT_CONNECT, notifier);
1006     EXPECT_EQ(ret, ERR_OK);
1007     dtbabilitymgrService_->ScheduleStartDeviceManager(dtbabilitymgrService_, 1, continuationExtraParams);
1008     ret = dtbabilitymgrService_->UpdateConnectStatus(token, DEVICE_ID, DeviceConnectStatus::IDLE);
1009     EXPECT_EQ(ret, ERR_OK);
1010     ret = dtbabilitymgrService_->UnregisterDeviceSelectionCallback(token, EVENT_CONNECT);
1011     EXPECT_EQ(ret, ERR_OK);
1012     ret = dtbabilitymgrService_->Unregister(token);
1013     EXPECT_EQ(ret, ERR_OK);
1014     DTEST_LOG << "DistributedAbilityManagerServiceTest UpdateConnectStatus_003 end" << std::endl;
1015 }
1016 
1017 /**
1018  * @tc.name: StartDeviceManager_001
1019  * @tc.desc: test StartDeviceManager when continuationExtraParams != nullptr.
1020  * @tc.type: FUNC
1021  * @tc.require: I76U22
1022  */
1023 HWTEST_F(DistributedAbilityManagerServiceTest, StartDeviceManager_001, TestSize.Level3)
1024 {
1025     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_001 start" << std::endl;
1026     ASSERT_NE(nullptr, dtbabilitymgrService_);
1027 
1028     int32_t token = 0;
1029     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1030     ContinuationMode continuationMode = static_cast<ContinuationMode>(-1);
1031     continuationExtraParams->SetContinuationMode(continuationMode);
1032     int32_t ret = dtbabilitymgrService_->StartDeviceManager(token, continuationExtraParams);
1033     EXPECT_EQ(ret, INVALID_CONTINUATION_MODE);
1034     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_001 end" << std::endl;
1035 }
1036 
1037 /**
1038  * @tc.name: StartDeviceManager_002
1039  * @tc.desc: test StartDeviceManager when continuationExtraParams != nullptr.
1040  * @tc.type: FUNC
1041  * @tc.require: I76U22
1042  */
1043 HWTEST_F(DistributedAbilityManagerServiceTest, StartDeviceManager_002, TestSize.Level3)
1044 {
1045     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_002 start" << std::endl;
1046     ASSERT_NE(nullptr, dtbabilitymgrService_);
1047 
1048     int32_t token = 0;
1049     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1050     DistributedSchedUtil::MockBundlePermission();
1051     int32_t ret = dtbabilitymgrService_->StartDeviceManager(token, continuationExtraParams);
1052     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1053     DistributedSchedUtil::MockPermission();
1054     ret = dtbabilitymgrService_->StartDeviceManager(token, continuationExtraParams);
1055     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
1056     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_002 end" << std::endl;
1057 }
1058 
1059 /**
1060  * @tc.name: StartDeviceManager_003
1061  * @tc.desc: test StartDeviceManager when continuationExtraParams != nullptr.
1062  * @tc.type: FUNC
1063  * @tc.require: I76U22
1064  */
1065 HWTEST_F(DistributedAbilityManagerServiceTest, StartDeviceManager_003, TestSize.Level3)
1066 {
1067     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_003 start" << std::endl;
1068     ASSERT_NE(nullptr, dtbabilitymgrService_);
1069 
1070     int32_t token = 0;
1071     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1072     int32_t res = dtbabilitymgrService_->Register(continuationExtraParams, token);
1073     EXPECT_EQ(res, ERR_OK);
1074 
1075     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1076     {
1077         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1078         dtbabilitymgrService_->callbackMap_.clear();
1079         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);
1080     }
1081     int32_t ret = dtbabilitymgrService_->StartDeviceManager(token, continuationExtraParams);
1082     EXPECT_EQ(ret, ERR_OK);
1083     {
1084         std::lock_guard<std::mutex> tokenLock(dtbabilitymgrService_->tokenMutex_);
1085         dtbabilitymgrService_->tokenMap_.clear();
1086     }
1087     {
1088         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1089         dtbabilitymgrService_->callbackMap_.clear();
1090     }
1091     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManager_003 end" << std::endl;
1092 }
1093 
1094 /**
1095  * @tc.name: DisconnectAbility_001
1096  * @tc.desc: test DisconnectAbility when continuationExtraParams != nullptr.
1097  * @tc.type: FUNC
1098  * @tc.require: I76U22
1099  */
1100 HWTEST_F(DistributedAbilityManagerServiceTest, DisconnectAbility_001, TestSize.Level3)
1101 {
1102     DTEST_LOG << "DistributedAbilityManagerServiceTest DisconnectAbility_001 start" << std::endl;
1103     ASSERT_NE(nullptr, dtbabilitymgrService_);
1104     int32_t token = 0;
1105     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1106     dtbabilitymgrService_->connect_ = new AppConnectionStub(token, continuationExtraParams);
1107     int32_t ret = dtbabilitymgrService_->DisconnectAbility();
1108     EXPECT_NE(ret, ERR_OK);
1109     DTEST_LOG << "DistributedAbilityManagerServiceTest DisconnectAbility_001 end" << std::endl;
1110 }
1111 
1112 /**
1113  * @tc.name: OnDeviceConnect_001
1114  * @tc.desc: test OnDeviceConnect when continuationHandler_ != nullptr.
1115  * @tc.type: FUNC
1116  * @tc.require: I76U22
1117  */
1118 HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceConnect_001, TestSize.Level3)
1119 {
1120     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceConnect_001 start" << std::endl;
1121     ASSERT_NE(nullptr, dtbabilitymgrService_);
1122     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
1123         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
1124     }
1125     int32_t token = 0;
1126     std::vector<ContinuationResult> continuationResults;
1127     int32_t ret = dtbabilitymgrService_->OnDeviceConnect(token, continuationResults);
1128     EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
1129     DTEST_LOG << "DistributedAbilityManagerServiceTest DisconnectAbility_001 end" << std::endl;
1130 }
1131 
1132 /**
1133  * @tc.name: OnDeviceConnect_002
1134  * @tc.desc: test OnDeviceConnect when continuationHandler_ != nullptr.
1135  * @tc.type: FUNC
1136  * @tc.require: I76U22
1137  */
1138 HWTEST_F(DistributedAbilityManagerServiceTest, OnDeviceConnect_002, TestSize.Level3)
1139 {
1140     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceConnect_002 start" << std::endl;
1141     ASSERT_NE(nullptr, dtbabilitymgrService_);
1142     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
1143         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
1144     }
1145     int32_t token = 0;
1146     std::vector<ContinuationResult> continuationResults;
1147     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1148     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1149     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
1150     {
1151         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1152         dtbabilitymgrService_->callbackMap_.clear();
1153         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);
1154     }
1155     int32_t ret = dtbabilitymgrService_->OnDeviceConnect(token, continuationResults);
1156     {
1157         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1158         dtbabilitymgrService_->callbackMap_.clear();
1159     }
1160     EXPECT_EQ(ret, ERR_OK);
1161     DTEST_LOG << "DistributedAbilityManagerServiceTest OnDeviceConnect_002 end" << std::endl;
1162 }
1163 
1164 /**
1165  * @tc.name: HandleStartDeviceManager_001
1166  * @tc.desc: test HandleStartDeviceManager
1167  * @tc.type: FUNC
1168  * @tc.require: I76U22
1169  */
1170 HWTEST_F(DistributedAbilityManagerServiceTest, HandleStartDeviceManager_001, TestSize.Level3)
1171 {
1172     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleStartDeviceManager_001 start" << std::endl;
1173     ASSERT_NE(nullptr, dtbabilitymgrService_);
1174     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
1175         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
1176     }
1177     int32_t token = 0;
1178     dtbabilitymgrService_->HandleStartDeviceManager(token, nullptr);
1179     EXPECT_NE(dtbabilitymgrService_, nullptr);
1180     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleStartDeviceManager_001 end" << std::endl;
1181 }
1182 
1183 /**
1184  * @tc.name: HandleStartDeviceManager_002
1185  * @tc.desc: test HandleStartDeviceManager
1186  * @tc.type: FUNC
1187  * @tc.require: I76U22
1188  */
1189 HWTEST_F(DistributedAbilityManagerServiceTest, HandleStartDeviceManager_002, TestSize.Level3)
1190 {
1191     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleStartDeviceManager_002 start" << std::endl;
1192     ASSERT_NE(nullptr, dtbabilitymgrService_);
1193     if (dtbabilitymgrService_->continuationHandler_ == nullptr) {
1194         dtbabilitymgrService_->continuationHandler_ = std::make_shared<ffrt::queue>("ContinuationMgr");
1195     }
1196     int32_t token = 0;
1197     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1198     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1199     {
1200         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1201         dtbabilitymgrService_->callbackMap_.clear();
1202         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);
1203     }
1204     dtbabilitymgrService_->HandleStartDeviceManager(token, continuationExtraParams);
1205     {
1206         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1207         dtbabilitymgrService_->callbackMap_.clear();
1208     }
1209     EXPECT_NE(dtbabilitymgrService_, nullptr);
1210     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleStartDeviceManager_002 end" << std::endl;
1211 }
1212 
1213 /**
1214  * @tc.name: HandleNotifierDied_002
1215  * @tc.desc: test HandleNotifierDied
1216  * @tc.type: FUNC
1217  * @tc.require: I76U22
1218  */
1219 HWTEST_F(DistributedAbilityManagerServiceTest, HandleNotifierDied_002, TestSize.Level3)
1220 {
1221     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_002 start" << std::endl;
1222     ASSERT_NE(nullptr, dtbabilitymgrService_);
1223     int32_t token = 0;
1224     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1225     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1226     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
1227     {
1228         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
1229         dtbabilitymgrService_->callbackMap_.clear();
1230         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);;
1231     }
1232     dtbabilitymgrService_->HandleNotifierDied(dtbabilitymgrService_);
1233     {
1234         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1235         dtbabilitymgrService_->callbackMap_.clear();
1236     }
1237     EXPECT_NE(dtbabilitymgrService_, nullptr);
1238     DTEST_LOG << "DistributedAbilityManagerServiceTest HandleNotifierDied_002 end" << std::endl;
1239 }
1240 
1241 /**
1242  * @tc.name: RegisterWithoutExtraParam_001
1243  * @tc.desc: test RegisterWithoutExtraParam when callback is registered.
1244  * @tc.type: FUNC
1245  * @tc.require: I5NOA1
1246  */
1247 HWTEST_F(DistributedAbilityManagerServiceTest, RegisterWithoutExtraParam_001, TestSize.Level3)
1248 {
1249     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterWithoutExtraParam_001 start" << std::endl;
1250     ASSERT_NE(nullptr, dtbabilitymgrService_);
1251 
1252     int32_t token = 0;
1253     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1254     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1255     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1256     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
1257     {
1258         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
1259         dtbabilitymgrService_->callbackMap_.clear();
1260         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);
1261     }
1262     int32_t ret = dtbabilitymgrService_->Register(continuationExtraParams, token);
1263     EXPECT_EQ(ret, ERR_OK);
1264 
1265     ret = dtbabilitymgrService_->RegisterWithoutExtraParam(token);
1266     EXPECT_EQ(ret, ERR_OK);
1267 
1268     {
1269         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
1270         dtbabilitymgrService_->callbackMap_[token] = nullptr;
1271     }
1272     ret = dtbabilitymgrService_->RegisterWithoutExtraParam(token);
1273     {
1274         std::lock_guard<std::mutex> autoLock(dtbabilitymgrService_->callbackMapMutex_);
1275         dtbabilitymgrService_->callbackMap_.clear();
1276     }
1277     EXPECT_EQ(ret, ERR_OK);
1278     DTEST_LOG << "DistributedAbilityManagerServiceTest RegisterWithoutExtraParam_001 end" << std::endl;
1279 }
1280 
1281 /**
1282  * @tc.name: StartDeviceManagerWithoutExtraParam_001
1283  * @tc.desc: test StartDeviceManagerWithoutExtraParam when callback is registered.
1284  * @tc.type: FUNC
1285  * @tc.require: I5NOA1
1286  */
1287 HWTEST_F(DistributedAbilityManagerServiceTest, StartDeviceManagerWithoutExtraParam_001, TestSize.Level3)
1288 {
1289     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManagerWithoutExtraParam_001 start" << std::endl;
1290     ASSERT_NE(nullptr, dtbabilitymgrService_);
1291 
1292     int32_t token = 0;
1293     sptr<DeviceSelectionNotifierTest> notifier(new DeviceSelectionNotifierTest());
1294     std::unique_ptr<NotifierInfo> notifierInfo = std::make_unique<NotifierInfo>();
1295     notifierInfo->SetNotifier(EVENT_CONNECT, notifier);
1296     DistributedSchedUtil::MockBundlePermission();
1297     int32_t ret = dtbabilitymgrService_->StartDeviceManagerWithoutExtraParam(token);
1298     EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1299     DistributedSchedUtil::MockPermission();
1300     ret = dtbabilitymgrService_->StartDeviceManagerWithoutExtraParam(token);
1301     EXPECT_EQ(ret, TOKEN_HAS_NOT_REGISTERED);
1302 
1303     std::shared_ptr<ContinuationExtraParams> continuationExtraParams = std::make_shared<ContinuationExtraParams>();
1304     int32_t res = dtbabilitymgrService_->Register(continuationExtraParams, token);
1305     EXPECT_EQ(res, ERR_OK);
1306     ret = dtbabilitymgrService_->StartDeviceManagerWithoutExtraParam(token);
1307     EXPECT_EQ(ret, CALLBACK_HAS_NOT_REGISTERED);
1308 
1309     {
1310         std::lock_guard<std::mutex> callbackMapLock(dtbabilitymgrService_->callbackMapMutex_);
1311         dtbabilitymgrService_->callbackMap_.clear();
1312         dtbabilitymgrService_->callbackMap_[token] = std::move(notifierInfo);
1313     }
1314     ret = dtbabilitymgrService_->StartDeviceManagerWithoutExtraParam(token);
1315     EXPECT_EQ(ret, ERR_OK);
1316     DTEST_LOG << "DistributedAbilityManagerServiceTest StartDeviceManagerWithoutExtraParam_001 end" << std::endl;
1317 }
1318 }
1319 }
1320