• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #include "svc_distributed_connection_test.h"
17 #include "common_event_manager.h"
18 #include "device_manager.h"
19 #include "notification_bundle_option.h"
20 #include "notification_constant.h"
21 #include "notification_helper.h"
22 #include "notification_request.h"
23 #include "want_agent_helper.h"
24 #include "want_agent_info.h"
25 #include "cJSON.h"
26 
27 #include "test_log.h"
28 
29 using namespace testing;
30 using namespace testing::ext;
31 
32 namespace {
33 bool g_subscribeCommonEvent;
34 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> g_wantAgent;
35 std::shared_ptr<OHOS::Notification::NotificationActionButton> g_actionButton;
36 int32_t g_deviceName;
37 cJSON *json = nullptr;
38 cJSON *resJson = nullptr;
39 cJSON *key = nullptr;
40 cJSON *value = nullptr;
41 const int32_t INVAILD_RET = 5;
42 const int32_t ERR_OK = 0;
43 } // namespace
44 
cJSON_GetObjectItemCaseSensitive(const cJSON * const object,const char * const string)45 cJSON* cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string)
46 {
47     return resJson;
48 }
49 
cJSON_Parse(const char * value)50 cJSON* cJSON_Parse(const char *value)
51 {
52     return json;
53 }
54 
55 namespace OHOS::EventFwk {
SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)56 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
57 {
58     return g_subscribeCommonEvent;
59 }
60 } // namespace OHOS::EventFwk
61 
62 namespace OHOS::AbilityRuntime {
GetWantAgent(const WantAgentInfo & paramsInfo,int32_t userId,int32_t uid)63 std::shared_ptr<WantAgent::WantAgent> WantAgent::WantAgentHelper::GetWantAgent(const WantAgentInfo &paramsInfo,
64     int32_t userId, int32_t uid)
65 {
66     return g_wantAgent;
67 }
68 } // namespace OHOS::AbilityRuntime
69 
70 namespace OHOS::Notification {
Create(const std::shared_ptr<Media::PixelMap> & icon,const std::string & title,const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> & wantAgent,const std::shared_ptr<AAFwk::WantParams> & extras,NotificationConstant::SemanticActionButton semanticActionButton,bool autoCreatedReplies,const std::vector<std::shared_ptr<NotificationUserInput>> & mimeTypeOnlyInputs,const std::shared_ptr<NotificationUserInput> & userInput,bool isContextual)71 std::shared_ptr<NotificationActionButton> NotificationActionButton::Create(
72     const std::shared_ptr<Media::PixelMap> &icon, const std::string &title,
73     const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent,
74     const std::shared_ptr<AAFwk::WantParams> &extras, NotificationConstant::SemanticActionButton semanticActionButton,
75     bool autoCreatedReplies, const std::vector<std::shared_ptr<NotificationUserInput>> &mimeTypeOnlyInputs,
76     const std::shared_ptr<NotificationUserInput> &userInput, bool isContextual)
77 {
78     return g_actionButton;
79 }
80 } // namespace OHOS::Notification
81 
82 namespace OHOS::DistributedHardware {
GetDeviceName(const std::string & pkgName,const std::string & networkId,std::string & deviceName)83 int32_t DeviceManager::GetDeviceName(const std::string &pkgName, const std::string &networkId,
84     std::string &deviceName)
85 {
86     return g_deviceName;
87 }
88 }
89 
90 namespace OHOS {
91 namespace DistributedSchedule {
SetUpTestCase()92 void SvcDistributedConnectionTest::SetUpTestCase()
93 {
94     disconnectedCon_ = sptr(new SvcDistributedConnection("com.example.dms_extension"));
95     DTEST_LOG << "SvcDistributedConnectionTest::SetUpTestCase" << std::endl;
96 }
97 
TearDownTestCase()98 void SvcDistributedConnectionTest::TearDownTestCase()
99 {
100     disconnectedCon_ = nullptr;
101     DTEST_LOG << "SvcDistributedConnectionTest::TearDownTestCase" << std::endl;
102 }
103 
TearDown()104 void SvcDistributedConnectionTest::TearDown()
105 {
106     DTEST_LOG << "SvcDistributedConnectionTest::TearDown" << std::endl;
107 }
108 
SetUp()109 void SvcDistributedConnectionTest::SetUp()
110 {
111     DTEST_LOG << "SvcDistributedConnectionTest::SetUp" << std::endl;
112 }
113 
114 /**
115  * @tc.name: OnAbilityConnectDone_001
116  * @tc.desc: OnAbilityConnectDone
117  * @tc.type: FUNC
118  */
119 HWTEST_F(SvcDistributedConnectionTest, OnAbilityConnectDone_001, TestSize.Level3)
120 {
121     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 begin" << std::endl;
122     int resultCode = 0;
123     AppExecFwk::ElementName element;
124     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityConnectDone(element, nullptr, resultCode));
125     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 remoteObject is nullptr " << std::endl;
126 }
127 
128 /**
129  * @tc.name: OnAbilityConnectDone_002
130  * @tc.desc: OnAbilityConnectDone
131  * @tc.type: FUNC
132  */
133 HWTEST_F(SvcDistributedConnectionTest, OnAbilityConnectDone_002, TestSize.Level3)
134 {
135     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_001 begin" << std::endl;
136     int resultCode = 0;
137     AppExecFwk::ElementName element;
138     EXPECT_TRUE(disconnectedCon_ != nullptr);
139     sptr<IRemoteObject> remoteObject;
140 
141     string bundleName = "com.example.dms_extension";
142     element.SetBundleName(bundleName);
143     disconnectedCon_->OnAbilityConnectDone(element, remoteObject, resultCode);
144     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityConnectDone(element, remoteObject, resultCode));
145     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityConnectDone_002 end" << std::endl;
146 }
147 
148 /**
149  * @tc.name: OnAbilityDisconnectDone_001
150  * @tc.desc: OnAbilityDisconnectDone
151  * @tc.type: FUNC
152  */
153 HWTEST_F(SvcDistributedConnectionTest, OnAbilityDisconnectDone_001, TestSize.Level3)
154 {
155     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityDisconnectDone_001 begin" << std::endl;
156 
157     AppExecFwk::ElementName element;
158     string bundleName = "";
159     element.SetBundleName(bundleName);
160     int resultCode = 1;
161 
162     EXPECT_TRUE(disconnectedCon_ != nullptr);
163     disconnectedCon_->isConnectCalled_ = false;
164     disconnectedCon_->OnAbilityDisconnectDone(element, resultCode);
165     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityDisconnectDone(element, resultCode));
166     bool ret = disconnectedCon_->IsExtAbilityConnected();
167     EXPECT_FALSE(ret);
168 
169     disconnectedCon_->isConnectCalled_ = true;
170     bundleName = "com.example.dms_extension";
171     element.SetBundleName(bundleName);
172     disconnectedCon_->OnAbilityDisconnectDone(element, resultCode);
173     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->OnAbilityDisconnectDone(element, resultCode));
174     ret = disconnectedCon_->IsExtAbilityConnected();
175     EXPECT_FALSE(ret);
176 
177     DTEST_LOG << "SvcDistributedConnectionTest OnAbilityDisconnectDone_001 end" << std::endl;
178 }
179 
180 /**
181  * @tc.name: GetDistributedExtProxy_001
182  * @tc.desc: GetDistributedExtProxy
183  * @tc.type: FUNC
184  */
185 HWTEST_F(SvcDistributedConnectionTest, GetDistributedExtProxy_001, TestSize.Level3)
186 {
187     DTEST_LOG << "SvcDistributedConnectionTest GetDistributedExtProxy_001 begin" << std::endl;
188     EXPECT_TRUE(disconnectedCon_ != nullptr);
189     auto proxy = disconnectedCon_->GetDistributedExtProxy();
190     EXPECT_EQ(proxy, nullptr);
191     DTEST_LOG << "SvcDistributedConnectionTest GetDistributedExtProxy_001 end" << std::endl;
192 }
193 
194 /**
195  * @tc.name: UpdateResourceMap_001
196  * @tc.desc: Input Parameter is empty
197  * @tc.type: FUNC
198  */
199 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMap_001, TestSize.Level3)
200 {
201     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_001 begin" << std::endl;
202     std::string resourcePath = "";
203     UpdateResourceMap(resourcePath);
204     {
205         std::lock_guard<std::mutex> lock(g_resourceMutex);
206         EXPECT_EQ(g_resourceMap.size(), 0);
207     }
208     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_001 end" << std::endl;
209 }
210 
211 /**
212  * @tc.name: UpdateResourceMap_002
213  * @tc.desc: resJson is nullptr
214  * @tc.type: FUNC
215  */
216 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMap_002, TestSize.Level3)
217 {
218     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_002 begin" << std::endl;
219     std::string resourcePath = "system/etc/dmsfwk/resources/cn_ZH/element/string.json";
220 
221     cJSON *jsonObject = cJSON_CreateObject();
222     cJSON_AddStringToObject(jsonObject, "key1", "value1");
223     cJSON_AddNumberToObject(jsonObject, "key2", 123);
224     EXPECT_TRUE(disconnectedCon_ != nullptr);
225 
226     json = jsonObject;
227     UpdateResourceMap(resourcePath);
228     {
229         std::lock_guard<std::mutex> lock(g_resourceMutex);
230         EXPECT_EQ(g_resourceMap.size(), 0);
231     }
232     json = nullptr;
233 
234     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_002 end" << std::endl;
235 }
236 
237 /**
238  * @tc.name: UpdateResourceMap_003
239  * @tc.desc: resJson size > MAX_RES_VEC_LEN
240  * @tc.type: FUNC
241  */
242 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMap_003, TestSize.Level3)
243 {
244     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_003 begin" << std::endl;
245     std::string resourcePath = "system/etc/dmsfwk/resources/cn_ZH/element/string.json";
246 
247     EXPECT_TRUE(disconnectedCon_ != nullptr);
248     cJSON *jsonObject = cJSON_CreateObject();
249     cJSON_AddStringToObject(jsonObject, "key1", "value1");
250     cJSON_AddNumberToObject(jsonObject, "key2", 123);
251     EXPECT_TRUE(disconnectedCon_ != nullptr);
252     cJSON *stringArray = cJSON_CreateArray();
253     for (int i = 1; i <= 101; ++i) {
254         cJSON *item = cJSON_CreateObject();
255         cJSON_AddStringToObject(item, "name", ("key" + std::to_string(i)).c_str());
256         cJSON_AddStringToObject(item, "value", ("value" + std::to_string(i)).c_str());
257         cJSON_AddItemToArray(stringArray, item);
258     }
259 
260     json = jsonObject;
261     resJson = stringArray;
262     UpdateResourceMap(resourcePath);
263     {
264         std::lock_guard<std::mutex> lock(g_resourceMutex);
265         EXPECT_EQ(g_resourceMap.size(), 0);
266     }
267     json = nullptr;
268     resJson = nullptr;
269 
270     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_003 end" << std::endl;
271 }
272 
273 /**
274  * @tc.name: UpdateResourceMap_004
275  * @tc.desc: UpdateResourceMap
276  * @tc.type: FUNC
277  */
278 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMap_004, TestSize.Level3)
279 {
280     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_004 begin" << std::endl;
281     std::string resourcePath = "system/etc/dmsfwk/resources/cn_ZH/element/string.json";
282     cJSON *jsonObject = cJSON_CreateObject();
283     cJSON_AddStringToObject(jsonObject, "key1", "value1");
284     cJSON_AddNumberToObject(jsonObject, "key2", 123);
285     cJSON *value = cJSON_CreateObject();
286     value->type = cJSON_String;
287     value->valuestring = strdup("zh_CN");
288 
289     json = jsonObject;
290     resJson = value;
291     UpdateResourceMap(resourcePath);
292     {
293         std::lock_guard<std::mutex> lock(g_resourceMutex);
294         EXPECT_EQ(g_resourceMap.size(), 0);
295     }
296     json = nullptr;
297     resJson = nullptr;
298 
299     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMap_004 end" << std::endl;
300 }
301 
302 /**
303  * @tc.name: GetLanguageFilePath_001
304  * @tc.desc: json is nullptr
305  * @tc.type: FUNC
306  */
307 HWTEST_F(SvcDistributedConnectionTest, GetLanguageFilePath_001, TestSize.Level3)
308 {
309     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_001 begin" << std::endl;
310     std::string sysLanguage = "zh-Hant";
311     std::string sysRegion = "TW";
312     std::string result = GetLanguageFilePath(sysLanguage, sysRegion);
313     EXPECT_EQ(result, "zh_CN");
314 
315     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_001 end" << std::endl;
316 }
317 
318 /**
319  * @tc.name: GetLanguageFilePath_002
320  * @tc.desc: resJson is nullptr
321  * @tc.type: FUNC
322  */
323 HWTEST_F(SvcDistributedConnectionTest, GetLanguageFilePath_002, TestSize.Level3)
324 {
325     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_002 begin" << std::endl;
326     std::string sysLanguage = "zh-Hant";
327     std::string sysRegion = "TW";
328     cJSON *jsonObject = cJSON_CreateObject();
329     cJSON_AddStringToObject(jsonObject, "key1", "value1");
330     cJSON_AddNumberToObject(jsonObject, "key2", 123);
331 
332     json = jsonObject;
333     std::string result = GetLanguageFilePath(sysLanguage, sysRegion);
334     EXPECT_EQ(result, "zh_CN");
335     json = nullptr;
336 
337     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_002 end" << std::endl;
338 }
339 
340 /**
341  * @tc.name: GetLanguageFilePath_003
342  * @tc.desc: resJson is not array
343  * @tc.type: FUNC
344  */
345 HWTEST_F(SvcDistributedConnectionTest, GetLanguageFilePath_003, TestSize.Level3)
346 {
347     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_003 begin" << std::endl;
348     std::string sysLanguage = "zh-Hant";
349     std::string sysRegion = "TW";
350     cJSON *jsonObject = cJSON_CreateObject();
351     cJSON_AddStringToObject(jsonObject, "key1", "value1");
352     cJSON_AddNumberToObject(jsonObject, "key2", 123);
353     cJSON *value = cJSON_CreateObject();
354     value->type = cJSON_String;
355     value->valuestring = strdup("zh_CN");
356 
357     json = jsonObject;
358     resJson = value;
359     std::string result = GetLanguageFilePath(sysLanguage, sysRegion);
360     EXPECT_EQ(result, "zh_CN");
361     json = nullptr;
362     resJson = nullptr;
363 
364     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_003 end" << std::endl;
365 }
366 
367 /**
368  * @tc.name: GetLanguageFilePath_004
369  * @tc.desc: langguage is zh_TW
370  * @tc.type: FUNC
371  */
372 HWTEST_F(SvcDistributedConnectionTest, GetLanguageFilePath_004, TestSize.Level3)
373 {
374     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_004 begin" << std::endl;
375     std::string sysLanguage = "zh-Hant";
376     std::string sysRegion = "TW";
377     cJSON *jsonObject = cJSON_CreateObject();
378     cJSON_AddStringToObject(jsonObject, "key1", "value1");
379     cJSON_AddNumberToObject(jsonObject, "key2", 123);
380     cJSON *value = cJSON_CreateArray();
381     cJSON *arrayItem1 = cJSON_CreateString("zh_CN");
382     cJSON *arrayItem2 = cJSON_CreateString("en_US");
383     cJSON_AddItemToArray(value, arrayItem1);
384     cJSON_AddItemToArray(value, arrayItem2);
385 
386     json = jsonObject;
387     resJson = value;
388     std::string result = GetLanguageFilePath(sysLanguage, sysRegion);
389     EXPECT_EQ(result, "zh_TW");
390     json = nullptr;
391     resJson = nullptr;
392 
393     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_004 end" << std::endl;
394 }
395 
396 /**
397  * @tc.name: GetLanguageFilePath_005
398  * @tc.desc: GetLanguageFilePath
399  * @tc.type: FUNC
400  */
401 HWTEST_F(SvcDistributedConnectionTest, GetLanguageFilePath_005, TestSize.Level3)
402 {
403     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_005 begin" << std::endl;
404     std::string sysLanguage = "zh-Hans";
405     std::string sysRegion = "CN";
406     cJSON *jsonObject = cJSON_CreateObject();
407     cJSON_AddStringToObject(jsonObject, "key1", "value1");
408     cJSON_AddNumberToObject(jsonObject, "key2", 123);
409     cJSON *value = cJSON_CreateArray();
410     cJSON *arrayItem1 = cJSON_CreateString("zh_CN");
411     cJSON *arrayItem2 = cJSON_CreateString("en_US");
412     cJSON_AddItemToArray(value, arrayItem1);
413     cJSON_AddItemToArray(value, arrayItem2);
414 
415     json = jsonObject;
416     resJson = value;
417     std::string result = GetLanguageFilePath(sysLanguage, sysRegion);
418     EXPECT_EQ(result, "zh_CN");
419     json = nullptr;
420     resJson = nullptr;
421 
422     DTEST_LOG << "SvcDistributedConnectionTest GetLanguageFilePath_005 end" << std::endl;
423 }
424 
425 /**
426  * @tc.name: UpdateResourceMapByLanguage_001
427  * @tc.desc: UpdateResourceMapByLanguage
428  * @tc.type: FUNC
429  */
430 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMapByLanguage_001, TestSize.Level3)
431 {
432     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMapByLanguage_001 begin" << std::endl;
433     g_sysLanguage = "";
434     g_sysRegion = "";
435     UpdateResourceMapByLanguage();
436     EXPECT_EQ(g_sysLanguage, "zh-Hans");
437 
438     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMapByLanguage_001 end" << std::endl;
439 }
440 
441 /**
442  * @tc.name: UpdateResourceMapByLanguage_002
443  * @tc.desc: UpdateResourceMapByLanguage
444  * @tc.type: FUNC
445  */
446 HWTEST_F(SvcDistributedConnectionTest, UpdateResourceMapByLanguage_002, TestSize.Level3)
447 {
448     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMapByLanguage_002 begin" << std::endl;
449     g_sysLanguage = "zh-Hans";
450     g_sysRegion = "CN";
451     UpdateResourceMapByLanguage();
452     EXPECT_EQ(g_sysLanguage, "zh-Hans");
453 
454     DTEST_LOG << "SvcDistributedConnectionTest UpdateResourceMapByLanguage_002 end" << std::endl;
455 }
456 
457 /**
458  * @tc.name: EndTaskFunction_001
459  * @tc.desc: EndTaskFunction
460  * @tc.type: FUNC
461  */
462 HWTEST_F(SvcDistributedConnectionTest, EndTaskFunction_001, TestSize.Level3)
463 {
464     DTEST_LOG << "SvcDistributedConnectionTest EndTaskFunction_001 begin" << std::endl;
465     EXPECT_TRUE(disconnectedCon_ != nullptr);
466     disconnectedCon_->isConnected_.store(false);
467     disconnectedCon_->EndTaskFunction();
468     EXPECT_EQ(disconnectedCon_->isConnected_.load(), false);
469 
470     DTEST_LOG << "SvcDistributedConnectionTest EndTaskFunction_001 end" << std::endl;
471 }
472 
473 /**
474  * @tc.name: EndTaskFunction_002
475  * @tc.desc: EndTaskFunction
476  * @tc.type: FUNC
477  */
478 HWTEST_F(SvcDistributedConnectionTest, EndTaskFunction_002, TestSize.Level3)
479 {
480     DTEST_LOG << "SvcDistributedConnectionTest EndTaskFunction_002 begin" << std::endl;
481     EXPECT_TRUE(disconnectedCon_ != nullptr);
482     disconnectedCon_->isConnected_.store(true);
483     disconnectedCon_->EndTaskFunction();
484     EXPECT_EQ(disconnectedCon_->isConnectCalled_.load(), false);
485 
486     DTEST_LOG << "SvcDistributedConnectionTest EndTaskFunction_002 end" << std::endl;
487 }
488 
489 /**
490  * @tc.name: RegisterEventListener_001
491  * @tc.desc: RegisterEventListener
492  * @tc.type: FUNC
493  */
494 HWTEST_F(SvcDistributedConnectionTest, RegisterEventListener_001, TestSize.Level3)
495 {
496     DTEST_LOG << "SvcDistributedConnectionTest RegisterEventListener_001 begin" << std::endl;
497     EXPECT_TRUE(disconnectedCon_ != nullptr);
498     g_subscribeCommonEvent = true;
499     disconnectedCon_->RegisterEventListener();
500     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->RegisterEventListener());
501 
502     DTEST_LOG << "SvcDistributedConnectionTest RegisterEventListener_001 end" << std::endl;
503 }
504 
505 /**
506  * @tc.name: RegisterEventListener_002
507  * @tc.desc: RegisterEventListener
508  * @tc.type: FUNC
509  */
510 HWTEST_F(SvcDistributedConnectionTest, RegisterEventListener_002, TestSize.Level3)
511 {
512     DTEST_LOG << "SvcDistributedConnectionTest RegisterEventListener_002 begin" << std::endl;
513     EXPECT_TRUE(disconnectedCon_ != nullptr);
514     g_subscribeCommonEvent = false;
515     disconnectedCon_->RegisterEventListener();
516     EXPECT_NO_FATAL_FAILURE(disconnectedCon_->RegisterEventListener());
517 
518     DTEST_LOG << "SvcDistributedConnectionTest RegisterEventListener_002 end" << std::endl;
519 }
520 
521 /**
522  * @tc.name: SetEndTaskButton_001
523  * @tc.desc: wantAgent is nullptr
524  * @tc.type: FUNC
525  */
526 HWTEST_F(SvcDistributedConnectionTest, SetEndTaskButton_001, TestSize.Level3)
527 {
528     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_001 begin" << std::endl;
529     EXPECT_TRUE(disconnectedCon_ != nullptr);
530     Notification::NotificationRequest request;
531     g_wantAgent = nullptr;
532     SetEndTaskButton(request);
533     EXPECT_NO_FATAL_FAILURE(SetEndTaskButton(request));
534 
535     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_001 end" << std::endl;
536 }
537 
538 /**
539  * @tc.name: SetEndTaskButton_002
540  * @tc.desc: actionButton is nullptr
541  * @tc.type: FUNC
542  */
543 HWTEST_F(SvcDistributedConnectionTest, SetEndTaskButton_002, TestSize.Level3)
544 {
545     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_002 begin" << std::endl;
546     EXPECT_TRUE(disconnectedCon_ != nullptr);
547     Notification::NotificationRequest request;
548     auto pendingWant = std::make_shared<AbilityRuntime::WantAgent::PendingWant>();
549     g_wantAgent = std::make_shared<AbilityRuntime::WantAgent::WantAgent>(pendingWant);
550     g_actionButton = nullptr;
551 
552     SetEndTaskButton(request);
553     EXPECT_NO_FATAL_FAILURE(SetEndTaskButton(request));
554 
555     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_002 end" << std::endl;
556 }
557 
558 /**
559  * @tc.name: SetEndTaskButton_003
560  * @tc.desc: SetEndTaskButton
561  * @tc.type: FUNC
562  */
563 HWTEST_F(SvcDistributedConnectionTest, SetEndTaskButton_003, TestSize.Level3)
564 {
565     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_003 begin" << std::endl;
566     EXPECT_TRUE(disconnectedCon_ != nullptr);
567     Notification::NotificationRequest request;
568     auto pendingWant = std::make_shared<AbilityRuntime::WantAgent::PendingWant>();
569     g_wantAgent = std::make_shared<AbilityRuntime::WantAgent::WantAgent>(pendingWant);
570     g_actionButton = std::make_shared<Notification::NotificationActionButton>();
571 
572     SetEndTaskButton(request);
573     EXPECT_NO_FATAL_FAILURE(SetEndTaskButton(request));
574 
575     DTEST_LOG << "SvcDistributedConnectionTest SetEndTaskButton_003 end" << std::endl;
576 }
577 
578 /**
579  * @tc.name: PublishDExtensionNotification_001
580  * @tc.desc: Get device name failed
581  * @tc.type: FUNC
582  */
583 HWTEST_F(SvcDistributedConnectionTest, PublishDExtensionNotification_001, TestSize.Level3)
584 {
585     DTEST_LOG << "SvcDistributedConnectionTest PublishDExtensionNotification_001 begin" << std::endl;
586     EXPECT_TRUE(disconnectedCon_ != nullptr);
587     std::string deviceId = "deviceId";
588     std::string bundleName = "com.example.dms_extension";
589     int32_t userId = 0;
590     std::string networkId = "networkId";
591     AppExecFwk::BundleResourceInfo bundleResourceInfo;
592     g_deviceName = INVAILD_RET;
593 
594     disconnectedCon_->PublishDExtensionNotification(deviceId, bundleName, userId, networkId, bundleResourceInfo);
595     EXPECT_NO_FATAL_FAILURE(
596         disconnectedCon_->PublishDExtensionNotification(deviceId, bundleName, userId, networkId, bundleResourceInfo));
597 
598     DTEST_LOG << "SvcDistributedConnectionTest PublishDExtensionNotification_001 end" << std::endl;
599 }
600 
601 /**
602  * @tc.name: PublishDExtensionNotification_002
603  * @tc.desc: PublishDExtensionNotification
604  * @tc.type: FUNC
605  */
606 HWTEST_F(SvcDistributedConnectionTest, PublishDExtensionNotification_002, TestSize.Level3)
607 {
608     DTEST_LOG << "SvcDistributedConnectionTest PublishDExtensionNotification_002 begin" << std::endl;
609     EXPECT_TRUE(disconnectedCon_ != nullptr);
610     std::string deviceId = "deviceId";
611     std::string bundleName = "com.example.dms_extension";
612     int32_t userId = 0;
613     std::string networkId = "networkId";
614     AppExecFwk::BundleResourceInfo bundleResourceInfo;
615     g_deviceName = ERR_OK;
616 
617     disconnectedCon_->PublishDExtensionNotification(deviceId, bundleName, userId, networkId, bundleResourceInfo);
618     EXPECT_NO_FATAL_FAILURE(
619         disconnectedCon_->PublishDExtensionNotification(deviceId, bundleName, userId, networkId, bundleResourceInfo));
620 
621     DTEST_LOG << "SvcDistributedConnectionTest PublishDExtensionNotification_002 end" << std::endl;
622 }
623 }
624 }
625