• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <functional>
16 #include <gtest/gtest.h>
17 
18 #include "mock_ipc_skeleton.h"
19 #include "notification_preferences.h"
20 #define private public
21 #include "accesstoken_kit.h"
22 #include "advanced_notification_service.h"
23 #include "notification_subscriber.h"
24 
25 using namespace testing::ext;
26 using namespace OHOS::Security::AccessToken;
27 
28 namespace OHOS {
29 namespace Notification {
30 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
31 
32 typedef std::function<void(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>)>
33     ConsumedFunc;
34 typedef std::function<void(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>, int)>
35     CanceledFunc;
36 
37 bool passed = false;
38 class TestAnsSubscriber : public NotificationSubscriber {
39 public:
OnConnected()40     void OnConnected() override
41     {
42         if (subscriberCb_ != nullptr) {
43             subscriberCb_();
44         }
45     }
OnDisconnected()46     void OnDisconnected() override
47     {
48         if (unSubscriberCb_ != nullptr) {
49             unSubscriberCb_();
50         }
51     }
OnDied()52     void OnDied() override
53     {}
OnUpdate(const std::shared_ptr<NotificationSortingMap> & sortingMap)54     void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override
55     {}
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)56     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
57     {}
OnEnabledNotificationChanged(const std::shared_ptr<EnabledNotificationCallbackData> & callbackData)58     void OnEnabledNotificationChanged(
59         const std::shared_ptr<EnabledNotificationCallbackData> &callbackData) override
60     {}
OnCanceled(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap,int deleteReason)61     void OnCanceled(const std::shared_ptr<Notification> &request,
62         const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) override
63     {
64         if (canceledCb_ != nullptr) {
65             canceledCb_(request, sortingMap, deleteReason);
66         }
67     }
OnConsumed(const std::shared_ptr<Notification> & request,const std::shared_ptr<NotificationSortingMap> & sortingMap)68     void OnConsumed(const std::shared_ptr<Notification> &request,
69         const std::shared_ptr<NotificationSortingMap> &sortingMap) override
70     {
71         if (consumedCb_ != nullptr) {
72             consumedCb_(request, sortingMap);
73         }
74     }
OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> & badgeData)75     void OnBadgeChanged(const std::shared_ptr<BadgeNumberCallbackData> &badgeData) override
76     {}
77 
78     ConsumedFunc consumedCb_ = nullptr;
79     CanceledFunc canceledCb_ = nullptr;
80     std::function<void()> unSubscriberCb_ = nullptr;
81     std::function<void()> subscriberCb_ = nullptr;
82 };
83 
84 class AnsModuleTest : public testing::Test {
85 public:
86     static void SetUpTestCase();
87     static void TearDownTestCase();
88     void SetUp();
89     void TearDown();
90     void TestAddSlots();
91 
92     static sptr<AdvancedNotificationService> g_advancedNotificationService;
93 };
94 
95 sptr<AdvancedNotificationService> AnsModuleTest::g_advancedNotificationService;
SetUpTestCase()96 void AnsModuleTest::SetUpTestCase()
97 {
98     passed = false;
99     NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
100     g_advancedNotificationService = OHOS::Notification::AdvancedNotificationService::GetInstance();
101 }
102 
TearDownTestCase()103 void AnsModuleTest::TearDownTestCase()
104 {
105     passed = false;
106     NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
107     if (g_advancedNotificationService != nullptr) {
108         g_advancedNotificationService->SelfClean();
109     }
110 }
111 
SetUp()112 void AnsModuleTest::SetUp()
113 {
114     passed = false;
115     NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
116 }
117 
TearDown()118 void AnsModuleTest::TearDown()
119 {
120     NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
121     passed = false;
122 }
123 
TestAddSlots()124 void AnsModuleTest::TestAddSlots()
125 {
126     std::vector<sptr<NotificationSlot>> slots;
127     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
128     slots.push_back(slot0);
129     g_advancedNotificationService->AddSlots(slots);
130 }
131 
132 /**
133  * @tc.number    : AnsModuleTest_001
134  * @tc.name      : ANS_Subscribe_Publish_0100
135  * @tc.desc      : Test the functions of subscribing all notifications, publishing, and canceling
136  */
137 HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1)
138 {
139     TestAddSlots();
140     std::string label = "testLabel";
141     auto subscriber = new TestAnsSubscriber();
__anon9bfc377f0102(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 142     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
143         passed = true;
144     };
145     sptr<NotificationRequest> req = new NotificationRequest(2);
146     sptr<NotificationRequest> req1 = new NotificationRequest(1);
147     req1->SetLabel(label);
148     sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
149     info->AddAppName("bundleName");
150     info->AddAppUserId(SUBSCRIBE_USER_ALL);
151     EXPECT_EQ((int)g_advancedNotificationService->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK);
152     EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req), (int)ERR_OK);
153     EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req1), (int)ERR_OK);
154     EXPECT_EQ((int)g_advancedNotificationService->Cancel(1, label), (int)ERR_OK);
155     EXPECT_TRUE(passed);
156     g_advancedNotificationService->CancelAll();
157     EXPECT_EQ((int)g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), info), (int)ERR_OK);
158     passed = false;
159 }
160 
161 /**
162  * @tc.number    : AnsModuleTest_002
163  * @tc.name      : ANS_Module_Test_0200
164  * @tc.desc      : Test the function of getting notifications and getting all notifications
165  */
166 HWTEST_F(AnsModuleTest, AnsModuleTest_002, Function | SmallTest | Level1)
167 {
168     TestAddSlots();
169     std::string label = "testLabel";
170     sptr<NotificationRequest> req = new NotificationRequest(0);
171     req->SetLabel(label);
172     sptr<NotificationRequest> req1 = new NotificationRequest(1);
173     req1->SetLabel(label);
174     sptr<NotificationRequest> req2 = new NotificationRequest(2);
175     req2->SetLabel("testLabel1");
176     sptr<NotificationSubscribeInfo> info = new NotificationSubscribeInfo();
177     info->AddAppName("bundleName");
178     std::vector<sptr<NotificationRequest>> notificationsReqs;
179     std::vector<sptr<Notification>> notifications;
180     EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req), (int)ERR_OK);
181     EXPECT_EQ((int)g_advancedNotificationService->Publish(label, req1), (int)ERR_OK);
182     EXPECT_EQ((int)g_advancedNotificationService->Publish("testLabel1", req2), (int)ERR_OK);
183     EXPECT_EQ((int)g_advancedNotificationService->GetActiveNotifications(notificationsReqs), (int)ERR_OK);
184     uint64_t num;
185     g_advancedNotificationService->GetActiveNotificationNums(num);
186     EXPECT_EQ(num, 3);
187     EXPECT_EQ((int)g_advancedNotificationService->Cancel(2, "testLabel1"), (int)ERR_OK);
188     EXPECT_EQ((int)g_advancedNotificationService->GetAllActiveNotifications(notifications), (int)ERR_OK);
189     EXPECT_EQ((int)notifications.size(), (int)2);
190     EXPECT_EQ((int)g_advancedNotificationService->CancelAll(), (int)ERR_OK);
191 }
192 
193 /**
194  * @tc.number    : AnsModuleTest_003
195  * @tc.name      : ANS_Module_Test_0300
196  * @tc.desc      : Test publish notifications when slot not found, add it.
197  */
198 HWTEST_F(AnsModuleTest, AnsModuleTest_003, Function | SmallTest | Level1)
199 {
200     // subscriber
201     auto subscriber = new TestAnsSubscriber();
202     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
__anon9bfc377f0202(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 203     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
204         passed = true;
205     };
206     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
207 
208     // add slot
209     std::vector<sptr<NotificationSlot>> slots;
210     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
211     slots.push_back(slot0);
212     g_advancedNotificationService->AddSlots(slots);
213 
214     // create request
215     std::string label = "testLabel";
216     sptr<NotificationRequest> req = new NotificationRequest(0);
217     req->SetLabel(label);
218     req->SetStatusBarText("text");
219 
220     g_advancedNotificationService->SetNotificationsEnabledForBundle("", false);
221 
222     g_advancedNotificationService->Publish(label, req);
223     std::this_thread::sleep_for(std::chrono::milliseconds(200));
224     EXPECT_EQ(true, passed);
225     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
226 }
227 
228 /**
229  * @tc.number    : AnsModuleTest_005
230  * @tc.name      : ANS_Module_Test_0500
231  * @tc.desc      : Test publish notification when slot type is SERVICE_REMINDER.
232  */
233 HWTEST_F(AnsModuleTest, AnsModuleTest_005, Function | SmallTest | Level1)
234 {
235     // subscriber
236     auto subscriber = new TestAnsSubscriber();
237     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
238     subscriberInfo->AddAppName("bundleName");
239     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
240     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
241     subscriber->consumedCb_ =
__anon9bfc377f0302(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 242         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
243             std::vector<std::string> sortingKey = sortingMap->GetKey();
244 
245             NotificationSorting sorting1;
246             NotificationSorting sorting2;
247             if (sortingKey.size() == 2) {
248                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
249                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
250             }
251             if (sorting1.GetRanking() < sorting2.GetRanking()) {
252                 passed = true;
253             }
254         };
255 
256     // add slot
257     std::vector<sptr<NotificationSlot>> slots;
258     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
259     slots.push_back(slot0);
260     g_advancedNotificationService->AddSlots(slots);
261 
262     // create request
263     std::string label = "testLabel";
264     sptr<NotificationRequest> req = new NotificationRequest(0);
265     sptr<NotificationRequest> req1 = new NotificationRequest(1);
266     req->SetLabel(label);
267     req1->SetLabel(label);
268 
269     // publish request
270     g_advancedNotificationService->Publish(label, req);
271     g_advancedNotificationService->Publish(label, req1);
272     EXPECT_TRUE(passed);
273     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
274 }
275 
276 /**
277  * @tc.number    : AnsModuleTest_006
278  * @tc.name      : ANS_Module_Test_0600
279  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
280  */
281 HWTEST_F(AnsModuleTest, AnsModuleTest_006, Function | SmallTest | Level1)
282 {
283     // subscriber
284     auto subscriber = new TestAnsSubscriber();
285     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
286     subscriberInfo->AddAppName("bundleName");
287     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
288     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0402(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 289     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
290         passed = true;
291     };
292 
293     // add slot
294     std::vector<sptr<NotificationSlot>> slots;
295     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
296     slots.push_back(slot0);
297     g_advancedNotificationService->AddSlots(slots);
298 
299     // create request
300     std::string label = "testLabel";
301     sptr<NotificationRequest> req = new NotificationRequest(0);
302     req->SetLabel(label);
303 
304     // publish request
305     g_advancedNotificationService->Publish(label, req);
306     std::this_thread::sleep_for(std::chrono::milliseconds(200));
307     EXPECT_TRUE(passed);
308     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
309 }
310 
311 /**
312  * @tc.number    : AnsModuleTest_007
313  * @tc.name      : ANS_Module_Test_0700
314  * @tc.desc      : Test publish notification when slot type is OTHER.
315  */
316 HWTEST_F(AnsModuleTest, AnsModuleTest_007, Function | SmallTest | Level1)
317 {
318     // subscriber
319     auto subscriber = new TestAnsSubscriber();
320     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
321     subscriberInfo->AddAppName("bundleName");
322     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
323     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
324     subscriber->consumedCb_ =
__anon9bfc377f0502(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 325         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
326             std::vector<std::string> sortingKey = sortingMap->GetKey();
327 
328             NotificationSorting sorting1;
329             NotificationSorting sorting2;
330             if (sortingKey.size() == 2) {
331                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
332                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
333             }
334             if (sorting1.GetRanking() < sorting2.GetRanking()) {
335                 passed = true;
336             }
337         };
338 
339     // add slot
340     std::vector<sptr<NotificationSlot>> slots;
341     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
342     slots.push_back(slot0);
343     g_advancedNotificationService->AddSlots(slots);
344 
345     // create request
346     std::string label = "testLabel";
347     sptr<NotificationRequest> req = new NotificationRequest(0);
348     sptr<NotificationRequest> req1 = new NotificationRequest(1);
349     req->SetLabel(label);
350     req1->SetLabel(label);
351 
352     // publish request
353     g_advancedNotificationService->Publish(label, req);
354     g_advancedNotificationService->Publish(label, req1);
355     EXPECT_TRUE(passed);
356     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
357 }
358 
359 /**
360  * @tc.number    : AnsModuleTest_0013
361  * @tc.name      : ANS_Module_Test_01300
362  * @tc.desc      : Test publish notification when slot type is SOCIAL_COMMUNICATION.
363  */
364 HWTEST_F(AnsModuleTest, AnsModuleTest_0013, Function | SmallTest | Level1)
365 {
366     // subscriber
367     auto subscriber = new TestAnsSubscriber();
368     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
369     subscriberInfo->AddAppName("bundleName");
370     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
371     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0602(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 372     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
373         passed = true;
374     };
375 
376     // add slot
377     std::vector<sptr<NotificationSlot>> slots;
378     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
379     slots.push_back(slot0);
380     g_advancedNotificationService->AddSlots(slots);
381 
382     // create request
383     std::string label = "testLabel";
384     sptr<NotificationRequest> req = new NotificationRequest(0);
385     req->SetLabel(label);
386 
387     // publish request
388     g_advancedNotificationService->Publish(label, req);
389     std::this_thread::sleep_for(std::chrono::milliseconds (200));
390     EXPECT_TRUE(passed);
391     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
392 }
393 
394 /**
395  * @tc.number    : AnsModuleTest_0014
396  * @tc.name      : ANS_Module_Test_01400
397  * @tc.desc      : Test publish notification when slot type is SOCIAL_COMMUNICATION.
398  */
399 HWTEST_F(AnsModuleTest, AnsModuleTest_0014, Function | SmallTest | Level1)
400 {
401     // subscriber
402     auto subscriber = new TestAnsSubscriber();
403     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
404     subscriberInfo->AddAppName("bundleName");
405     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
406     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0702(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 407     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
408         passed = true;
409     };
410 
411     // add slot
412     std::vector<sptr<NotificationSlot>> slots;
413     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
414     slots.push_back(slot0);
415     g_advancedNotificationService->AddSlots(slots);
416 
417     // create request
418     std::string label = "testLabel";
419     sptr<NotificationRequest> req = new NotificationRequest(0);
420     req->SetLabel(label);
421     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
422     normalContent->SetText("1");
423     normalContent->SetTitle("1");
424     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
425     req->SetContent(content);
426 
427     // publish request
428     g_advancedNotificationService->Publish(label, req);
429     std::this_thread::sleep_for(std::chrono::milliseconds(200));
430     EXPECT_TRUE(passed);
431     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
432 }
433 
434 /**
435  * @tc.number    : AnsModuleTest_0015
436  * @tc.name      : ANS_Module_Test_01500
437  * @tc.desc      : Test publish notification when slot type is SOCIAL_COMMUNICATION.
438  */
439 HWTEST_F(AnsModuleTest, AnsModuleTest_0015, Function | SmallTest | Level1)
440 {
441     // subscriber
442     auto subscriber = new TestAnsSubscriber();
443     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
444     subscriberInfo->AddAppName("bundleName");
445     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
446     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0802(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 447     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
448         passed = true;
449     };
450 
451     // add slot
452     std::vector<sptr<NotificationSlot>> slots;
453     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
454     slots.push_back(slot0);
455     g_advancedNotificationService->AddSlots(slots);
456 
457     // create request
458     std::string label = "testLabel";
459     sptr<NotificationRequest> req = new NotificationRequest(0);
460     req->SetLabel(label);
461     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
462     normalContent->SetText("1");
463     normalContent->SetTitle("1");
464     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
465     req->SetContent(content);
466 
467     // publish request
468     g_advancedNotificationService->Publish(label, req);
469     std::this_thread::sleep_for(std::chrono::milliseconds(200));
470     EXPECT_TRUE(passed);
471     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
472 }
473 
474 /**
475  * @tc.number    : AnsModuleTest_0017
476  * @tc.name      : ANS_Module_Test_01700
477  * @tc.desc      : Test publish notification when slot type is SOCIAL_COMMUNICATION.
478  */
479 HWTEST_F(AnsModuleTest, AnsModuleTest_0017, Function | SmallTest | Level1)
480 {
481     // subscriber
482     auto subscriber = new TestAnsSubscriber();
483     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
484     subscriberInfo->AddAppName("bundleName");
485     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
486     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0902(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 487     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
488         passed = true;
489     };
490 
491     // add slot
492     std::vector<sptr<NotificationSlot>> slots;
493     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
494     slots.push_back(slot0);
495     g_advancedNotificationService->AddSlots(slots);
496 
497     // create request
498     std::string label = "testLabel";
499     sptr<NotificationRequest> req = new NotificationRequest(0);
500     req->SetLabel(label);
501     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
502     normalContent->SetText("1");
503     normalContent->SetTitle("1");
504     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
505     req->SetContent(content);
506 
507     // publish request
508     g_advancedNotificationService->Publish(label, req);
509     std::this_thread::sleep_for(std::chrono::milliseconds(200));
510     EXPECT_TRUE(passed);
511     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
512 }
513 
514 /**
515  * @tc.number    : AnsModuleTest_0019
516  * @tc.name      : ANS_Module_Test_01900
517  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
518  */
519 HWTEST_F(AnsModuleTest, AnsModuleTest_0019, Function | SmallTest | Level1)
520 {
521     // subscriber
522     auto subscriber = new TestAnsSubscriber();
523     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
524     subscriberInfo->AddAppName("bundleName");
525     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
526     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0a02(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 527     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
528         passed = true;
529     };
530 
531     // add slot
532     std::vector<sptr<NotificationSlot>> slots;
533     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
534     slots.push_back(slot0);
535     g_advancedNotificationService->AddSlots(slots);
536 
537     // create request
538     std::string label = "testLabel";
539     sptr<NotificationRequest> req = new NotificationRequest(0);
540     req->SetLabel(label);
541     std::shared_ptr<NotificationLongTextContent> longTextContent = std::make_shared<NotificationLongTextContent>();
542     longTextContent->SetText("1");
543     longTextContent->SetTitle("1");
544     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(longTextContent);
545     req->SetContent(content);
546 
547     // publish request
548     g_advancedNotificationService->Publish(label, req);
549     std::this_thread::sleep_for(std::chrono::milliseconds(200));
550     EXPECT_TRUE(passed);
551     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
552 }
553 
554 /**
555  * @tc.number    : AnsModuleTest_0021
556  * @tc.name      : ANS_Module_Test_02100
557  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
558  */
559 HWTEST_F(AnsModuleTest, AnsModuleTest_0021, Function | SmallTest | Level1)
560 {
561     // subscriber
562     auto subscriber = new TestAnsSubscriber();
563     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
564     subscriberInfo->AddAppName("bundleName");
565     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
566     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
567     subscriber->consumedCb_ =
__anon9bfc377f0b02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 568         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
569             std::vector<std::string> sortingKey = sortingMap->GetKey();
570 
571             NotificationSorting sorting1;
572             NotificationSorting sorting2;
573             if (sortingKey.size() == 2) {
574                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
575                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
576             }
577             if (sorting1.GetRanking() < sorting2.GetRanking()) {
578                 passed = true;
579             }
580         };
581 
582     // add slot
583     std::vector<sptr<NotificationSlot>> slots;
584     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
585     slots.push_back(slot0);
586     g_advancedNotificationService->AddSlots(slots);
587 
588     // create request
589     std::string label = "testLabel";
590     sptr<NotificationRequest> req = new NotificationRequest(0);
591     sptr<NotificationRequest> req1 = new NotificationRequest(1);
592     req->SetLabel(label);
593     req1->SetLabel(label);
594     std::shared_ptr<NotificationPictureContent> pictureContent = std::make_shared<NotificationPictureContent>();
595     pictureContent->SetText("1");
596     pictureContent->SetTitle("1");
597     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(pictureContent);
598     req->SetContent(content);
599     req1->SetContent(content);
600 
601     // publish request
602     g_advancedNotificationService->Publish(label, req);
603     g_advancedNotificationService->Publish(label, req1);
604     EXPECT_TRUE(passed);
605     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
606 }
607 
608 /**
609  * @tc.number    : AnsModuleTest_0023
610  * @tc.name      : ANS_Module_Test_02300
611  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
612  */
613 HWTEST_F(AnsModuleTest, AnsModuleTest_0023, Function | SmallTest | Level1)
614 {
615     // subscriber
616     auto subscriber = new TestAnsSubscriber();
617     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
618     subscriberInfo->AddAppName("bundleName");
619     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
620     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f0c02(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 621     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
622         passed = true;
623     };
624 
625     // add slot
626     std::vector<sptr<NotificationSlot>> slots;
627     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
628     slots.push_back(slot0);
629     g_advancedNotificationService->AddSlots(slots);
630 
631     // create request
632     std::string label = "testLabel";
633     sptr<NotificationRequest> req = new NotificationRequest(0);
634     req->SetLabel(label);
635     std::shared_ptr<NotificationMultiLineContent> contentImpl = std::make_shared<NotificationMultiLineContent>();
636     contentImpl->SetText("1");
637     contentImpl->SetTitle("1");
638     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
639     req->SetContent(content);
640 
641     // publish request
642     g_advancedNotificationService->Publish(label, req);
643     std::this_thread::sleep_for(std::chrono::milliseconds(200));
644     EXPECT_TRUE(passed);
645     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
646 }
647 
648 /**
649  * @tc.number    : AnsModuleTest_0031
650  * @tc.name      : ANS_Module_Test_03100
651  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
652  */
653 HWTEST_F(AnsModuleTest, AnsModuleTest_0031, Function | SmallTest | Level1)
654 {
655     // subscriber
656     auto subscriber = new TestAnsSubscriber();
657     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
658     subscriberInfo->AddAppName("bundleName");
659     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
660     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
661     subscriber->consumedCb_ =
__anon9bfc377f0d02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 662         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
663             std::vector<std::string> sortingKey = sortingMap->GetKey();
664 
665             NotificationSorting sorting1;
666             NotificationSorting sorting2;
667             if (sortingKey.size() == 2) {
668                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
669                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
670             }
671             if (sorting1.GetRanking() < sorting2.GetRanking()) {
672                 passed = true;
673             }
674         };
675 
676     // add slot
677     std::vector<sptr<NotificationSlot>> slots;
678     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
679     slots.push_back(slot0);
680     g_advancedNotificationService->AddSlots(slots);
681 
682     // create request
683     std::string label = "testLabel";
684     sptr<NotificationRequest> req = new NotificationRequest(0);
685     sptr<NotificationRequest> req1 = new NotificationRequest(1);
686     req->SetLabel(label);
687     req1->SetLabel(label);
688     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
689     contentImpl->SetText("1");
690     contentImpl->SetTitle("1");
691     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
692     req->SetContent(content);
693     req1->SetContent(content);
694 
695     // publish request
696     g_advancedNotificationService->Publish(label, req);
697     g_advancedNotificationService->Publish(label, req1);
698     EXPECT_TRUE(passed);
699     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
700 }
701 
702 /**
703  * @tc.number    : AnsModuleTest_0033
704  * @tc.name      : ANS_Module_Test_03300
705  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
706  */
707 HWTEST_F(AnsModuleTest, AnsModuleTest_0033, Function | SmallTest | Level1)
708 {
709     // subscriber
710     auto subscriber = new TestAnsSubscriber();
711     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
712     subscriberInfo->AddAppName("bundleName");
713     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
714     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
715     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f0e02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 716                                   const std::shared_ptr<NotificationSortingMap>) {
717         if (notification->EnableVibrate()) {
718             passed = true;
719         }
720     };
721 
722     // add slot
723     std::vector<sptr<NotificationSlot>> slots;
724     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
725     slot->SetEnableVibration(true);
726     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
727     slots.push_back(slot);
728     g_advancedNotificationService->AddSlots(slots);
729 
730     // create request
731     std::string label = "testLabel";
732     sptr<NotificationRequest> req = new NotificationRequest(0);
733     req->SetLabel(label);
734     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
735     contentImpl->SetText("1");
736     contentImpl->SetTitle("1");
737     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
738     req->SetContent(content);
739     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
740 
741     // publish request
742     g_advancedNotificationService->Publish(label, req);
743     std::this_thread::sleep_for(std::chrono::milliseconds(200));
744     EXPECT_TRUE(passed);
745     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
746 }
747 
748 /**
749  * @tc.number    : AnsModuleTest_0034
750  * @tc.name      : ANS_Module_Test_03400
751  * @tc.desc      : Test publish notification when slot type is SOCIAL_COMMUNICATION.
752  */
753 HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1)
754 {
755     // subscriber
756     auto subscriber = new TestAnsSubscriber();
757     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
758     subscriberInfo->AddAppName("bundleName");
759     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
760     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
761     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f0f02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 762                                   const std::shared_ptr<NotificationSortingMap>) {
763         if (notification->EnableSound()) {
764             passed = true;
765         }
766     };
767 
768     // add slot
769     std::vector<sptr<NotificationSlot>> slots;
770     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
771     slot->SetEnableVibration(true);
772     slot->SetSound(Uri("/sound/test.mp3"));
773     slots.push_back(slot);
774     g_advancedNotificationService->AddSlots(slots);
775 
776     // create request
777     std::string label = "testLabel";
778     sptr<NotificationRequest> req = new NotificationRequest(0);
779     req->SetLabel(label);
780     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
781     contentImpl->SetText("1");
782     contentImpl->SetTitle("1");
783     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
784     req->SetContent(content);
785     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
786 
787     // publish request
788     g_advancedNotificationService->Publish(label, req);
789     std::this_thread::sleep_for(std::chrono::milliseconds(200));
790     EXPECT_TRUE(passed);
791     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
792 }
793 
794 /**
795  * @tc.number    : AnsModuleTest_0035
796  * @tc.name      : ANS_Module_Test_03500
797  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
798  */
799 HWTEST_F(AnsModuleTest, AnsModuleTest_0035, Function | SmallTest | Level1)
800 {
801     // subscriber
802     auto subscriber = new TestAnsSubscriber();
803     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
804     subscriberInfo->AddAppName("bundleName");
805     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
806     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
807     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
808                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f1002(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 809                                   int deleteReason) { passed = true; };
810 
811     // add slot
812     std::vector<sptr<NotificationSlot>> slots;
813     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
814     slot->SetEnableVibration(true);
815     slots.push_back(slot);
816     g_advancedNotificationService->AddSlots(slots);
817 
818     // create request
819     std::string label = "testLabel";
820     sptr<NotificationRequest> req = new NotificationRequest(0);
821     req->SetLabel(label);
822     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
823     contentImpl->SetText("1");
824     contentImpl->SetTitle("1");
825     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
826     req->SetContent(content);
827 
828     // publish request
829     g_advancedNotificationService->Publish(label, req);
830     g_advancedNotificationService->Cancel(0, label);
831     std::this_thread::sleep_for(std::chrono::milliseconds(200));
832     EXPECT_TRUE(passed);
833     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
834 }
835 
836 /**
837  * @tc.number    : AnsModuleTest_0036
838  * @tc.name      : ANS_Module_Test_03600
839  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
840  */
841 HWTEST_F(AnsModuleTest, AnsModuleTest_0036, Function | SmallTest | Level1)
842 {
843     // subscriber
844     auto subscriber = new TestAnsSubscriber();
845     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
846     subscriberInfo->AddAppName("bundleName");
847     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
848     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
849     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
850                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f1102(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 851                                   int deleteReason) { passed = true; };
852 
853     // add slot
854     std::vector<sptr<NotificationSlot>> slots;
855     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
856     slot->SetEnableVibration(true);
857     slots.push_back(slot);
858     g_advancedNotificationService->AddSlots(slots);
859 
860     // create request
861     std::string label = "testLabel";
862     sptr<NotificationRequest> req = new NotificationRequest(0);
863     req->SetLabel(label);
864     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
865     contentImpl->SetText("1");
866     contentImpl->SetTitle("1");
867     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
868     req->SetContent(content);
869 
870     // publish request
871     g_advancedNotificationService->Publish(label, req);
872     g_advancedNotificationService->CancelAll();
873     EXPECT_TRUE(passed);
874     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
875 }
876 
877 /**
878  * @tc.number    : AnsModuleTest_0039
879  * @tc.name      : ANS_Module_Test_03900
880  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
881  */
882 HWTEST_F(AnsModuleTest, AnsModuleTest_0039, Function | SmallTest | Level1)
883 {
884     // subscriber
885     auto subscriber = new TestAnsSubscriber();
886     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
887     subscriberInfo->AddAppName("bundleName");
888     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
889     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
890     subscriber->consumedCb_ =
__anon9bfc377f1202(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 891         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
892             std::vector<std::string> sortingKey = sortingMap->GetKey();
893 
894             NotificationSorting sorting1;
895             NotificationSorting sorting2;
896             if (sortingKey.size() == 2) {
897                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
898                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
899             }
900             if (sorting1.GetRanking() < sorting2.GetRanking()) {
901                 passed = true;
902             }
903         };
904 
905     // add slot
906     std::vector<sptr<NotificationSlot>> slots;
907     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
908     slot->SetEnableVibration(true);
909     slots.push_back(slot);
910     g_advancedNotificationService->AddSlots(slots);
911 
912     // create request
913     std::string label = "testLabel";
914     sptr<NotificationRequest> req = new NotificationRequest(0);
915     sptr<NotificationRequest> req1 = new NotificationRequest(1);
916     req->SetLabel(label);
917     req1->SetLabel(label);
918     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
919     contentImpl->SetText("1");
920     contentImpl->SetTitle("1");
921     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
922     req->SetContent(content);
923     req1->SetContent(content);
924 
925     // publish request
926     g_advancedNotificationService->Publish(label, req);
927     g_advancedNotificationService->Publish(label, req1);
928     EXPECT_TRUE(passed);
929     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
930 }
931 
932 /**
933  * @tc.number    : AnsModuleTest_0040
934  * @tc.name      : ANS_Module_Test_04000
935  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
936  */
937 HWTEST_F(AnsModuleTest, AnsModuleTest_0040, Function | SmallTest | Level1)
938 {
939     // subscriber
940     auto subscriber = new TestAnsSubscriber();
941     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
942     subscriberInfo->AddAppName("bundleName");
943     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
944     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
945     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f1302(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 946                                   const std::shared_ptr<NotificationSortingMap>) { passed = true; };
947 
948     // add slot
949     std::vector<sptr<NotificationSlot>> slots;
950     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
951     slot->SetEnableVibration(true);
952     slots.push_back(slot);
953     g_advancedNotificationService->AddSlots(slots);
954 
955     // create request
956     std::string label = "testLabel";
957     sptr<NotificationRequest> req = new NotificationRequest(0);
958     req->SetLabel(label);
959     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
960     contentImpl->SetText("1");
961     contentImpl->SetTitle("1");
962     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
963     req->SetContent(content);
964 
965     // publish request
966     g_advancedNotificationService->Publish(label, req);
967     std::this_thread::sleep_for(std::chrono::milliseconds(200));
968     EXPECT_TRUE(passed);
969     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
970 }
971 
972 /**
973  * @tc.number    : AnsModuleTest_0041
974  * @tc.name      : ANS_Module_Test_04100
975  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
976  */
977 HWTEST_F(AnsModuleTest, AnsModuleTest_0041, Function | SmallTest | Level1)
978 {
979     // subscriber
980     auto subscriber = new TestAnsSubscriber();
981     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
982     subscriberInfo->AddAppName("bundleName");
983     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
984     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
985     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f1402(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 986                                   const std::shared_ptr<NotificationSortingMap>) { passed = true; };
987 
988     // add slot
989     std::vector<sptr<NotificationSlot>> slots;
990     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
991     slot->SetEnableVibration(true);
992     slots.push_back(slot);
993     g_advancedNotificationService->AddSlots(slots);
994 
995     // create request
996     std::string label = "testLabel";
997     sptr<NotificationRequest> req = new NotificationRequest(0);
998     req->SetLabel(label);
999     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
1000     contentImpl->SetText("1");
1001     contentImpl->SetTitle("1");
1002     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
1003     req->SetContent(content);
1004 
1005     // publish request
1006     g_advancedNotificationService->Publish(label, req);
1007     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1008     EXPECT_TRUE(passed);
1009     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1010 }
1011 
1012 /**
1013  * @tc.number    : AnsModuleTest_0042
1014  * @tc.name      : ANS_Module_Test_04200
1015  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1016  */
1017 HWTEST_F(AnsModuleTest, AnsModuleTest_0042, Function | SmallTest | Level1)
1018 {
1019     // subscriber
1020     auto subscriber = new TestAnsSubscriber();
1021     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1022     subscriberInfo->AddAppName("bundleName");
1023     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1024     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1025     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f1502(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 1026                                   const std::shared_ptr<NotificationSortingMap>) { passed = true; };
1027 
1028     // add slot
1029     std::vector<sptr<NotificationSlot>> slots;
1030     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1031     slot->SetEnableVibration(true);
1032     slots.push_back(slot);
1033     g_advancedNotificationService->AddSlots(slots);
1034 
1035     // create request
1036     std::string label = "testLabel";
1037     sptr<NotificationRequest> req = new NotificationRequest(0);
1038     req->SetLabel(label);
1039     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
1040     contentImpl->SetText("1");
1041     contentImpl->SetTitle("1");
1042     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
1043     req->SetContent(content);
1044 
1045     // publish request
1046     g_advancedNotificationService->Publish(label, req);
1047     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1048     EXPECT_TRUE(passed);
1049     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1050 }
1051 
1052 /**
1053  * @tc.number    : AnsModuleTest_0043
1054  * @tc.name      : ANS_Module_Test_04300
1055  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1056  */
1057 HWTEST_F(AnsModuleTest, AnsModuleTest_0043, Function | SmallTest | Level1)
1058 {
1059     // subscriber
1060     auto subscriber = new TestAnsSubscriber();
1061     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1062     subscriberInfo->AddAppName("bundleName");
1063     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1064     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1065     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
__anon9bfc377f1602(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap>) 1066                                   const std::shared_ptr<NotificationSortingMap>) { passed = true; };
1067 
1068     // add slot
1069     std::vector<sptr<NotificationSlot>> slots;
1070     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM);
1071     slot->SetEnableVibration(true);
1072     slots.push_back(slot);
1073     g_advancedNotificationService->AddSlots(slots);
1074 
1075     // create request
1076     std::string label = "testLabel";
1077     sptr<NotificationRequest> req = new NotificationRequest(0);
1078     req->SetLabel(label);
1079     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
1080     contentImpl->SetText("1");
1081     contentImpl->SetTitle("1");
1082     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
1083     req->SetContent(content);
1084 
1085     // publish request
1086     g_advancedNotificationService->Publish(label, req);
1087     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1088     EXPECT_TRUE(passed);
1089     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1090 }
1091 
1092 /**
1093  * @tc.number    : AnsModuleTest_0049
1094  * @tc.name      : ANS_Module_Test_04900
1095  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1096  */
1097 HWTEST_F(AnsModuleTest, AnsModuleTest_0049, Function | SmallTest | Level1)
1098 {
1099     // add slot
1100     std::vector<sptr<NotificationSlot>> slots;
1101     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1102     sptr<NotificationSlot> reminderSlot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
1103     sptr<NotificationSlot> contentSlot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1104     sptr<NotificationSlot> otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1105     slots.push_back(socialSlot);
1106     slots.push_back(reminderSlot);
1107     slots.push_back(contentSlot);
1108     slots.push_back(otherSlot);
1109 
1110     ASSERT_NE(nullptr, g_advancedNotificationService);
1111     g_advancedNotificationService->AddSlots(slots);
1112 }
1113 
1114 /**
1115  * @tc.number    : AnsModuleTest_0051
1116  * @tc.name      : ANS_Module_Test_05100
1117  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1118  */
1119 HWTEST_F(AnsModuleTest, AnsModuleTest_0051, Function | SmallTest | Level1)
1120 {
1121     // add slot
1122     std::vector<sptr<NotificationSlot>> slots;
1123     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1124     std::string slotId = slot->GetId();
1125     slots.push_back(slot);
1126     g_advancedNotificationService->AddSlots(slots);
1127 
1128     std::vector<sptr<NotificationSlot>> slotsRef {};
1129     g_advancedNotificationService->GetSlots(slotsRef);
1130     EXPECT_EQ(1, static_cast<int>(slotsRef.size()));
1131     std::vector<std::string> slotsId {};
1132     for (const auto &i : slotsRef) {
1133         slotsId.push_back(i->GetId());
1134     }
1135     g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1136     g_advancedNotificationService->GetSlots(slotsRef);
1137     EXPECT_EQ(0, static_cast<int>(slotsRef.size()));
1138 }
1139 
1140 /**
1141  * @tc.number    : AnsModuleTest_0052
1142  * @tc.name      : ANS_Module_Test_05200
1143  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1144  */
1145 HWTEST_F(AnsModuleTest, AnsModuleTest_0052, Function | SmallTest | Level1)
1146 {
1147     // add slot
1148     std::vector<sptr<NotificationSlot>> slots;
1149     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1150     slots.push_back(slot);
1151     g_advancedNotificationService->AddSlots(slots);
1152 
1153     std::vector<sptr<NotificationSlot>> slotsRef {};
1154     g_advancedNotificationService->GetSlots(slotsRef);
1155     std::vector<std::string> slotsId {};
1156     for (const auto &i : slotsRef) {
1157         slotsId.push_back(i->GetId());
1158     }
1159     g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1160     g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1161     g_advancedNotificationService->GetSlots(slotsRef);
1162     EXPECT_EQ(0, static_cast<int>(slotsRef.size()));
1163 }
1164 
1165 /**
1166  * @tc.number    : AnsModuleTest_0054
1167  * @tc.name      : ANS_Module_Test_05400
1168  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1169  */
1170 HWTEST_F(AnsModuleTest, AnsModuleTest_0054, Function | SmallTest | Level1)
1171 {
1172     // add slot
1173     std::vector<sptr<NotificationSlot>> slots;
1174     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1175     sptr<NotificationSlot> reminderSlot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
1176     sptr<NotificationSlot> contentSlot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1177     sptr<NotificationSlot> otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1178 
1179     slots.push_back(socialSlot);
1180     slots.push_back(reminderSlot);
1181     slots.push_back(contentSlot);
1182     slots.push_back(otherSlot);
1183 
1184     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
1185 }
1186 
1187 /**
1188  * @tc.number    : AnsModuleTest_0055
1189  * @tc.name      : ANS_Module_Test_05500
1190  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1191  */
1192 HWTEST_F(AnsModuleTest, AnsModuleTest_0055, Function | SmallTest | Level1)
1193 {
1194     // add slot
1195     std::vector<sptr<NotificationSlot>> slots;
1196     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1197     slots.push_back(socialSlot);
1198     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
1199 
1200     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION), 0);
1201 }
1202 
1203 /**
1204  * @tc.number    : AnsModuleTest_0056
1205  * @tc.name      : ANS_Module_Test_05600
1206  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1207  */
1208 HWTEST_F(AnsModuleTest, AnsModuleTest_0056, Function | SmallTest | Level1)
1209 {
1210     // add slot
1211     std::vector<sptr<NotificationSlot>> slots;
1212     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1213     slots.push_back(socialSlot);
1214     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
1215     // remove slot group
1216     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION), 0);
1217 }
1218 
1219 /**
1220  * @tc.number    : AnsModuleTest_0058
1221  * @tc.name      : ANS_Module_Test_05800
1222  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1223  */
1224 HWTEST_F(AnsModuleTest, AnsModuleTest_0058, Function | SmallTest | Level1)
1225 {
1226     // subscriber
1227     auto subscriber = new TestAnsSubscriber();
1228     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1229     subscriberInfo->AddAppName("bundleName");
1230     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
__anon9bfc377f1702(const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) 1231     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) {
1232         if (r->GetNotificationRequest().GetBadgeNumber() == 1) {
1233             passed = true;
1234         }
1235     };
1236     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1237 
1238     // add slot
1239     std::vector<sptr<NotificationSlot>> slots;
1240     sptr<NotificationSlot> slot = new NotificationSlot();
1241     slot->EnableBadge(true);
1242     slots.push_back(slot);
1243     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
1244 
1245     // create request
1246     std::string label = "testLabel";
1247     sptr<NotificationRequest> req = new NotificationRequest(0);
1248     req->SetLabel(label);
1249     req->SetStatusBarText("text");
1250     req->SetBadgeNumber(1);
1251 
1252     // SetShowBadgeEnabledForBundle true
1253     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption("bundleName", 0);
1254     g_advancedNotificationService->SetShowBadgeEnabledForBundle(bundleOption, true);
1255 
1256     g_advancedNotificationService->Publish(label, req);
1257     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1258     EXPECT_EQ(true, passed);
1259     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1260 }
1261 
1262 /**
1263  * @tc.number    : AnsModuleTest_0060
1264  * @tc.name      : ANS_Module_Test_06000
1265  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1266  */
1267 HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1)
1268 {
1269     // subscriber
1270     auto subscriber = new TestAnsSubscriber();
1271     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1272     subscriberInfo->AddAppName("bundleName");
1273     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
__anon9bfc377f1802(const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) 1274     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) {
1275         passed = true;
1276     };
1277     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1278 
1279     // add slot
1280     std::vector<sptr<NotificationSlot>> slots;
1281     sptr<NotificationSlot> slot = new NotificationSlot();
1282     slot->EnableBadge(true);
1283     slots.push_back(slot);
1284     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), ERR_OK);
1285 
1286     // create request
1287     std::string label = "testLabel";
1288     sptr<NotificationRequest> req = new NotificationRequest(0);
1289     req->SetLabel(label);
1290     req->SetStatusBarText("text");
1291     req->SetBadgeNumber(1);
1292 
1293     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption("bundleName", 1);
1294     ASSERT_NE(bundleOption, nullptr);
1295 
1296     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1297     // not allow publish notification
1298     g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, false);
1299     g_advancedNotificationService->Publish(label, req);
1300     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1301     EXPECT_FALSE(passed);
1302 
1303     passed = false;
1304     // allow publish
1305     g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, true);
1306     g_advancedNotificationService->Publish(label, req);
1307     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1308     EXPECT_TRUE(passed);
1309 
1310     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1311 }
1312 
1313 /**
1314  * @tc.number    : AnsModuleTest_0061
1315  * @tc.name      : ANS_Module_Test_06100
1316  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1317  */
1318 HWTEST_F(AnsModuleTest, AnsModuleTest_0061, Function | SmallTest | Level1)
1319 {
1320     // subscriber
1321     auto subscriber = new TestAnsSubscriber();
1322     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1323     subscriberInfo->AddAppName("bundleName");
1324     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
__anon9bfc377f1902(const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) 1325     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> r, const std::shared_ptr<NotificationSortingMap>) {
1326         passed = true;
1327     };
1328     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1329 
1330     // add slot
1331     std::vector<sptr<NotificationSlot>> slots;
1332     sptr<NotificationSlot> slot = new NotificationSlot();
1333     slot->EnableBadge(true);
1334     slots.push_back(slot);
1335     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
1336 
1337     // create request
1338     std::string label = "testLabel";
1339     sptr<NotificationRequest> req = new NotificationRequest(0);
1340     req->SetLabel(label);
1341     req->SetStatusBarText("text");
1342     req->SetBadgeNumber(1);
1343 
1344     sptr<NotificationBundleOption> bundleOption = new NotificationBundleOption("bundleName", 1);
1345     ASSERT_NE(bundleOption, nullptr);
1346 
1347     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
1348     // allow publish notification
1349     g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, true);
1350     g_advancedNotificationService->Publish(label, req);
1351     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1352     EXPECT_TRUE(passed);
1353 
1354     // not allow publish
1355     passed = false;
1356     g_advancedNotificationService->SetNotificationsEnabledForSpecialBundle("", bundleOption, false);
1357     g_advancedNotificationService->Publish(label, req);
1358     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1359     EXPECT_FALSE(passed);
1360 
1361     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1362 }
1363 
1364 /**
1365  * @tc.number    : AnsModuleTest_062
1366  * @tc.name      : ANS_Module_Test_06200
1367  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1368  */
1369 HWTEST_F(AnsModuleTest, AnsModuleTest_0062, Function | SmallTest | Level1)
1370 {
1371     // subscriber
1372     auto subscriber = new TestAnsSubscriber();
1373     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1374     subscriberInfo->AddAppName("bundleName");
1375     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1376     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1377     subscriber->consumedCb_ =
__anon9bfc377f1a02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1378         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1379             std::vector<std::string> sortingKey = sortingMap->GetKey();
1380 
1381             NotificationSorting sorting1;
1382             NotificationSorting sorting2;
1383             if (sortingKey.size() == 2) {
1384                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
1385                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
1386             }
1387             if (sorting1.GetRanking() < sorting2.GetRanking()) {
1388                 passed = true;
1389             }
1390         };
1391 
1392     // add slot
1393     std::vector<sptr<NotificationSlot>> slots;
1394     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1395     slots.push_back(slot0);
1396     g_advancedNotificationService->AddSlots(slots);
1397 
1398     // create request
1399     std::string label = "testLabel";
1400     sptr<NotificationRequest> req = new NotificationRequest(0);
1401     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1402     req->SetLabel(label);
1403     req1->SetLabel(label);
1404 
1405     // publish request
1406     g_advancedNotificationService->Publish(label, req);
1407     g_advancedNotificationService->Publish(label, req1);
1408     EXPECT_TRUE(passed);
1409     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1410 }
1411 
1412 /**
1413  * @tc.number    : AnsModuleTest_063
1414  * @tc.name      : ANS_Module_Test_06300
1415  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1416  */
1417 HWTEST_F(AnsModuleTest, AnsModuleTest_0063, Function | SmallTest | Level1)
1418 {
1419     // subscriber
1420     auto subscriber = new TestAnsSubscriber();
1421     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
1422     subscriber->consumedCb_ =
__anon9bfc377f1b02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1423         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1424             std::vector<std::string> sortingKey = sortingMap->GetKey();
1425 
1426             NotificationSorting sorting1;
1427             NotificationSorting sorting2;
1428             if (sortingKey.size() == 2) {
1429                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
1430                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
1431             }
1432             if (sorting1.GetRanking() < sorting2.GetRanking()) {
1433                 passed = true;
1434             }
1435         };
1436 
1437     // add slot
1438     std::vector<sptr<NotificationSlot>> slots;
1439     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1440     slots.push_back(slot0);
1441     g_advancedNotificationService->AddSlots(slots);
1442 
1443     // create request
1444     std::string label = "testLabel";
1445     sptr<NotificationRequest> req = new NotificationRequest(0);
1446     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1447     req->SetLabel(label);
1448     req1->SetLabel(label);
1449 
1450     // publish request
1451     g_advancedNotificationService->Publish(label, req);
1452     g_advancedNotificationService->Publish(label, req1);
1453     EXPECT_TRUE(passed);
1454     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
1455 }
1456 
1457 /**
1458  * @tc.number    : AnsModuleTest_064
1459  * @tc.name      : ANS_Module_Test_06400
1460  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1461  */
1462 HWTEST_F(AnsModuleTest, AnsModuleTest_0064, Function | SmallTest | Level1)
1463 {
1464     // subscriber
1465     auto subscriber = new TestAnsSubscriber();
1466     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1467     subscriberInfo->AddAppName("bundleName");
1468     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f1c02() 1469     subscriber->unSubscriberCb_ = []() { passed = true; };
1470     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1471     EXPECT_TRUE(passed);
1472 }
1473 
1474 /**
1475  * @tc.number    : AnsModuleTest_065
1476  * @tc.name      : ANS_Module_Test_06500
1477  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1478  */
1479 HWTEST_F(AnsModuleTest, AnsModuleTest_0065, Function | SmallTest | Level1)
1480 {
1481     // subscriber
1482     auto subscriber = new TestAnsSubscriber();
1483     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
__anon9bfc377f1d02() 1484     subscriber->unSubscriberCb_ = []() { passed = true; };
1485     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
1486     EXPECT_TRUE(passed);
1487 }
1488 
1489 /**
1490  * @tc.number    : AnsModuleTest_066
1491  * @tc.name      : ANS_Module_Test_06600
1492  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1493  */
1494 HWTEST_F(AnsModuleTest, AnsModuleTest_0066, Function | SmallTest | Level1)
1495 {
1496     // subscriber
1497     auto subscriber = new TestAnsSubscriber();
1498     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
1499     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
1500                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f1e02(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 1501                                   int deleteReason) { passed = true; };
1502 
1503     // create request
1504     std::string label = "testLabel";
1505     sptr<NotificationRequest> req = new NotificationRequest(0);
1506     req->SetLabel(label);
1507 
1508     // publish request
1509     g_advancedNotificationService->Publish(label, req);
1510 
1511     // remove request
1512     g_advancedNotificationService->Delete("_1_testLabel_0", NotificationConstant::CANCEL_REASON_DELETE);
1513     EXPECT_TRUE(passed);
1514     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
1515 }
1516 
1517 /**
1518  * @tc.number    : AnsModuleTest_100
1519  * @tc.name      : ANS_Module_Test_10000
1520  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1521  */
1522 HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1)
1523 {
1524     // create wantagent
1525     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> agent =
1526         std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1527 
1528     // subscriber
1529     auto subscriber = new TestAnsSubscriber();
1530     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1531     subscriberInfo->AddAppName("bundleName");
1532     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1533     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
1534                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f1f02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1535                                       sortingMap) { passed = true; };
1536 
1537     // add slot
1538     std::vector<sptr<NotificationSlot>> slots;
1539     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1540     slots.push_back(slot0);
1541     g_advancedNotificationService->AddSlots(slots);
1542 
1543     // create request
1544     std::string label = "testLabel";
1545     sptr<NotificationRequest> req = new NotificationRequest(0);
1546     req->SetLabel(label);
1547 
1548     // set content
1549     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1550     normalContent->SetText("1");
1551     normalContent->SetTitle("1");
1552     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1553     req->SetContent(content);
1554 
1555     // publish request
1556     g_advancedNotificationService->Publish(label, req);
1557     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1558     EXPECT_TRUE(passed);
1559     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1560 }
1561 
1562 /**
1563  * @tc.number    : AnsModuleTest_101
1564  * @tc.name      : ANS_Module_Test_10100
1565  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1566  */
1567 HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1)
1568 {
1569     // create wantagent
1570     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> agent =
1571         std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1572 
1573     // subscriber
1574     auto subscriber = new TestAnsSubscriber();
1575     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1576     subscriberInfo->AddAppName("bundleName");
1577     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1578     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
1579                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f2002(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1580                                       sortingMap) { passed = true; };
1581 
1582     // create request
1583     std::string label = "testLabel";
1584     sptr<NotificationRequest> req = new NotificationRequest(0);
1585     req->SetLabel(label);
1586     req->SetWantAgent(agent);
1587 
1588     // publish request
1589     g_advancedNotificationService->Publish(label, req);
1590     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1591     EXPECT_TRUE(passed);
1592     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1593 }
1594 
1595 /**
1596  * @tc.number    : AnsModuleTest_102
1597  * @tc.name      : ANS_Module_Test_10200
1598  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1599  */
1600 HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1)
1601 {
1602     // create wantagent
1603     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> agent =
1604         std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1605 
1606     // subscriber
1607     auto subscriber = new TestAnsSubscriber();
1608     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1609     subscriberInfo->AddAppName("bundleName");
1610     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1611     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
1612                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f2102(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1613                                       sortingMap) { passed = true; };
1614 
1615     // create request
1616     std::string label = "testLabel";
1617     sptr<NotificationRequest> req = new NotificationRequest(0);
1618     req->SetLabel(label);
1619     req->SetWantAgent(agent);
1620 
1621     // publish request
1622     g_advancedNotificationService->Publish(label, req);
1623     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1624     EXPECT_TRUE(passed);
1625     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1626 }
1627 
1628 /**
1629  * @tc.number    : AnsModuleTest_103
1630  * @tc.name      : ANS_Module_Test_10300
1631  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1632  */
1633 HWTEST_F(AnsModuleTest, AnsModuleTest_0103, Function | SmallTest | Level1)
1634 {
1635     // create wantagent
1636     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> agent =
1637         std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1638 
1639     // subscriber
1640     auto subscriber = new TestAnsSubscriber();
1641     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1642     subscriberInfo->AddAppName("a");
1643     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1644     subscriber->consumedCb_ = [](const std::shared_ptr<Notification> notification,
1645                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f2202(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1646                                       sortingMap) { passed = true; };
1647 
1648     // create request
1649     std::string label = "testLabel";
1650     sptr<NotificationRequest> req = new NotificationRequest(0);
1651     req->SetLabel(label);
1652     req->SetWantAgent(agent);
1653 
1654     // publish request
1655     g_advancedNotificationService->Publish(label, req);
1656     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1657     EXPECT_EQ(passed, true);
1658     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1659 }
1660 
1661 /**
1662  * @tc.number    : AnsModuleTest_105
1663  * @tc.name      : ANS_Module_Test_10500
1664  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1665  */
1666 HWTEST_F(AnsModuleTest, AnsModuleTest_0105, Function | SmallTest | Level1)
1667 {
1668     std::vector<sptr<NotificationSlot>> slots;
1669     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1670     sptr<NotificationSlot> reminderSlot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
1671     sptr<NotificationSlot> contentSlot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1672     sptr<NotificationSlot> otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1673     sptr<NotificationSlot> customSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM);
1674 
1675     slots.push_back(socialSlot);
1676     slots.push_back(reminderSlot);
1677     slots.push_back(contentSlot);
1678     slots.push_back(otherSlot);
1679     slots.push_back(customSlot);
1680 
1681     g_advancedNotificationService->AddSlots(slots);
1682     EXPECT_EQ(0, g_advancedNotificationService->AddSlots(slots));
1683 }
1684 
1685 /**
1686  * @tc.number    : AnsModuleTest_106
1687  * @tc.name      : ANS_Module_Test_10600
1688  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1689  */
1690 HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1)
1691 {
1692     // create wantagent
1693     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> agent =
1694         std::make_shared<AbilityRuntime::WantAgent::WantAgent>();
1695 
1696     // subscriber
1697     auto subscriber = new TestAnsSubscriber();
1698     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1699     subscriberInfo->AddAppName("bundleName");
1700     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1701     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1702     subscriber->consumedCb_ =
__anon9bfc377f2302(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1703         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1704             passed = true;
1705         };
1706 
1707     // set disturb mode
1708     g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", false);
1709 
1710     // create request
1711     std::string label = "testLabel";
1712     sptr<NotificationRequest> req = new NotificationRequest(0);
1713     req->SetLabel(label);
1714     req->SetWantAgent(agent);
1715 
1716     // publish request
1717     g_advancedNotificationService->Publish(label, req);
1718     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1719     EXPECT_TRUE(passed);
1720     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1721 }
1722 
1723 /**
1724  * @tc.number    : AnsModuleTest_107
1725  * @tc.name      : ANS_Module_Test_10700
1726  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1727  */
1728 HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1)
1729 {
1730     // subscriber
1731     auto subscriber = new TestAnsSubscriber();
1732     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1733     subscriberInfo->AddAppName("bundleName");
1734     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1735     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1736 
1737     // add slot
1738     std::vector<sptr<NotificationSlot>> slots;
1739     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1740     slots.push_back(slot0);
1741     g_advancedNotificationService->AddSlots(slots);
1742 
1743     // create request
1744     std::string label = "testLabel";
1745     sptr<NotificationRequest> req = new NotificationRequest(0);
1746     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1747     req->SetLabel(label);
1748     req1->SetLabel(label);
1749 
1750     // set content
1751     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1752     normalContent->SetText("1");
1753     normalContent->SetTitle("1");
1754     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1755     req->SetContent(content);
1756     req1->SetContent(content);
1757 
1758     // publish request
1759     g_advancedNotificationService->Publish(label, req);
1760     g_advancedNotificationService->Publish(label, req1);
1761 
1762     // remove request
1763     g_advancedNotificationService->Delete("_0_1_testLabel_0", NotificationConstant::CANCEL_REASON_DELETE);
1764     g_advancedNotificationService->Delete("_0_1_testLabel_1", NotificationConstant::CANCEL_REASON_DELETE);
1765     uint64_t nums = 0;
1766     g_advancedNotificationService->GetActiveNotificationNums(nums);
1767     EXPECT_EQ(nums, 0);
1768     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1769 }
1770 
1771 /**
1772  * @tc.number    : AnsModuleTest_108
1773  * @tc.name      : ANS_Module_Test_10800
1774  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1775  */
1776 HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1)
1777 {
1778     // subscriber
1779     auto subscriber = new TestAnsSubscriber();
1780     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1781     subscriberInfo->AddAppName("bundleName");
1782     subscriberInfo->AddAppUserId(SUBSCRIBE_USER_ALL);
1783     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1784 
1785     // add slot
1786     std::vector<sptr<NotificationSlot>> slots;
1787     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1788     slots.push_back(slot0);
1789     g_advancedNotificationService->AddSlots(slots);
1790 
1791     // create request
1792     std::string label = "testLabel";
1793     sptr<NotificationRequest> req = new NotificationRequest(0);
1794     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1795     req->SetLabel(label);
1796     req1->SetLabel(label);
1797     req->SetNotificationId(0);
1798     req1->SetNotificationId(1);
1799 
1800     // set content
1801     std::shared_ptr<NotificationNormalContent> normalContent = std::make_shared<NotificationNormalContent>();
1802     normalContent->SetText("1");
1803     normalContent->SetTitle("1");
1804     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(normalContent);
1805     req->SetContent(content);
1806     req1->SetContent(content);
1807 
1808     // publish request
1809     g_advancedNotificationService->Publish(label, req);
1810     g_advancedNotificationService->Publish(label, req1);
1811 
1812     // remove request
1813     g_advancedNotificationService->DeleteAllByUser(0);
1814     uint64_t nums = 0;
1815     g_advancedNotificationService->GetActiveNotificationNums(nums);
1816     EXPECT_EQ(nums, 0);
1817     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1818 }
1819 
1820 /**
1821  * @tc.number    : AnsModuleTest_110
1822  * @tc.name      : ANS_Module_Test_11000
1823  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1824  */
1825 HWTEST_F(AnsModuleTest, AnsModuleTest_0110, Function | SmallTest | Level1)
1826 {
1827     // subscriber
1828     auto subscriber = new TestAnsSubscriber();
1829     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1830     subscriberInfo->AddAppName("bundleName");
__anon9bfc377f2402() 1831     subscriber->unSubscriberCb_ = []() { passed = true; };
1832     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1833 
1834     // unsubscriber
1835     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1836     EXPECT_EQ(passed, true);
1837 }
1838 
1839 /**
1840  * @tc.number    : AnsModuleTest_111
1841  * @tc.name      : ANS_Module_Test_11100
1842  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1843  */
1844 HWTEST_F(AnsModuleTest, AnsModuleTest_0111, Function | SmallTest | Level1)
1845 {
1846     // subscriber
1847     auto subscriber = new TestAnsSubscriber();
1848     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
1849     subscriberInfo->AddAppName("bundleName");
__anon9bfc377f2502() 1850     subscriber->subscriberCb_ = []() { passed = true; };
1851     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
1852     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
1853     EXPECT_EQ(passed, true);
1854 }
1855 
1856 /**
1857  * @tc.number    : AnsModuleTest_112
1858  * @tc.name      : ANS_Module_Test_11200
1859  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1860  */
1861 HWTEST_F(AnsModuleTest, AnsModuleTest_0112, Function | SmallTest | Level1)
1862 {
1863     // subscriber
1864     auto subscriber = new TestAnsSubscriber();
1865     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
1866     subscriber->consumedCb_ =
__anon9bfc377f2602(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1867         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1868             std::vector<std::string> sortingKey = sortingMap->GetKey();
1869 
1870             NotificationSorting sorting1;
1871             NotificationSorting sorting2;
1872             if (sortingKey.size() == 2) {
1873                 sortingMap->GetNotificationSorting("_0_1_testLabel_0", sorting1);
1874                 sortingMap->GetNotificationSorting("_0_1_testLabel_1", sorting2);
1875             }
1876 
1877             if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() &&
1878                 notification->EnableSound() && notification->EnableVibrate()) {
1879                 passed = true;
1880             }
1881         };
1882 
1883     // add slot
1884     std::vector<sptr<NotificationSlot>> slots;
1885     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1886     slot->SetSound(Uri("."));
1887     slot->SetEnableLight(true);
1888     slot->SetEnableVibration(true);
1889     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
1890     slot->SetLedLightColor(1);
1891     slots.push_back(slot);
1892     g_advancedNotificationService->AddSlots(slots);
1893 
1894     // create request
1895     std::string label = "testLabel";
1896     sptr<NotificationRequest> req = new NotificationRequest(0);
1897     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1898     req->SetLabel(label);
1899     req1->SetLabel(label);
1900     std::shared_ptr<NotificationMultiLineContent> contentImpl = std::make_shared<NotificationMultiLineContent>();
1901     contentImpl->SetText("1");
1902     contentImpl->SetTitle("1");
1903     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
1904     req->SetContent(content);
1905     req1->SetContent(content);
1906     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1907     req1->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1908 
1909     // publish request
1910     g_advancedNotificationService->Publish(label, req);
1911     g_advancedNotificationService->Publish(label, req1);
1912     EXPECT_TRUE(passed);
1913     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
1914 }
1915 
1916 /**
1917  * @tc.number    : AnsModuleTest_113
1918  * @tc.name      : ANS_Module_Test_11300
1919  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1920  */
1921 HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1)
1922 {
1923     // subscriber
1924     auto subscriber = new TestAnsSubscriber();
1925     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
1926     subscriber->consumedCb_ =
__anon9bfc377f2702(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1927         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1928             std::vector<std::string> sortingKey = sortingMap->GetKey();
1929 
1930             NotificationSorting sorting1;
1931             NotificationSorting sorting2;
1932             if (sortingKey.size() == 2) {
1933                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
1934                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
1935             }
1936             if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() &&
1937                 notification->EnableSound() && notification->EnableVibrate()) {
1938                 passed = true;
1939             }
1940         };
1941 
1942     // add slot
1943     std::vector<sptr<NotificationSlot>> slots;
1944     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1945     slot->SetSound(Uri("."));
1946     slot->SetEnableLight(true);
1947     slot->SetEnableVibration(true);
1948     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
1949     slot->SetLedLightColor(1);
1950     slots.push_back(slot);
1951     g_advancedNotificationService->AddSlots(slots);
1952 
1953     // create request
1954     std::string label = "testLabel";
1955     sptr<NotificationRequest> req = new NotificationRequest(0);
1956     sptr<NotificationRequest> req1 = new NotificationRequest(1);
1957     req->SetLabel(label);
1958     req1->SetLabel(label);
1959     std::shared_ptr<NotificationLongTextContent> contentImpl = std::make_shared<NotificationLongTextContent>();
1960     contentImpl->SetText("1");
1961     contentImpl->SetTitle("1");
1962     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
1963     req->SetContent(content);
1964     req1->SetContent(content);
1965     req->SetSlotType(NotificationConstant::SlotType::OTHER);
1966     req1->SetSlotType(NotificationConstant::SlotType::OTHER);
1967 
1968     // publish request
1969     g_advancedNotificationService->Publish(label, req);
1970     g_advancedNotificationService->Publish(label, req1);
1971     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
1972     EXPECT_TRUE(passed);
1973 }
1974 
1975 /**
1976  * @tc.number    : AnsModuleTest_114
1977  * @tc.name      : ANS_Module_Test_11400
1978  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
1979  */
1980 HWTEST_F(AnsModuleTest, AnsModuleTest_0114, Function | SmallTest | Level1)
1981 {
1982     // subscriber
1983     auto subscriber = new TestAnsSubscriber();
1984     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
1985     subscriber->consumedCb_ =
__anon9bfc377f2802(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 1986         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
1987             std::vector<std::string> sortingKey = sortingMap->GetKey();
1988 
1989             NotificationSorting sorting1;
1990             NotificationSorting sorting2;
1991             if (sortingKey.size() == 2) {
1992                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
1993                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
1994             }
1995             if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() &&
1996                 notification->EnableSound() && notification->EnableVibrate()) {
1997                 passed = true;
1998             }
1999         };
2000 
2001     // add slot
2002     std::vector<sptr<NotificationSlot>> slots;
2003     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
2004     slot->SetSound(Uri("."));
2005     slot->SetEnableLight(true);
2006     slot->SetEnableVibration(true);
2007     slot->SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
2008     slot->SetLedLightColor(1);
2009     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
2010     slots.push_back(slot);
2011     g_advancedNotificationService->AddSlots(slots);
2012 
2013     // create request
2014     std::string label = "testLabel";
2015     sptr<NotificationRequest> req = new NotificationRequest(0);
2016     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2017     req->SetLabel(label);
2018     req1->SetLabel(label);
2019     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
2020     contentImpl->SetText("1");
2021     contentImpl->SetTitle("1");
2022     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2023     req->SetContent(content);
2024     req1->SetContent(content);
2025     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
2026     req1->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
2027     // publish request
2028     g_advancedNotificationService->Publish(label, req);
2029     g_advancedNotificationService->Publish(label, req1);
2030     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2031     EXPECT_TRUE(passed);
2032 }
2033 
2034 /**
2035  * @tc.number    : AnsModuleTest_116
2036  * @tc.name      : ANS_Module_Test_11600
2037  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2038  */
2039 HWTEST_F(AnsModuleTest, AnsModuleTest_0116, Function | SmallTest | Level1)
2040 {
2041     // subscriber
2042     auto subscriber = new TestAnsSubscriber();
2043     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2044     subscriber->consumedCb_ =
__anon9bfc377f2902(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2045         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2046             std::vector<std::string> sortingKey = sortingMap->GetKey();
2047 
2048             NotificationSorting sorting1;
2049             NotificationSorting sorting2;
2050             if (sortingKey.size() == 2) {
2051                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
2052                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
2053             }
2054             if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() &&
2055                 notification->EnableSound() && notification->EnableVibrate()) {
2056                 passed = true;
2057             }
2058         };
2059 
2060     // add slot
2061     std::vector<sptr<NotificationSlot>> slots;
2062     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
2063     slot->SetSound(Uri("."));
2064     slot->SetEnableLight(true);
2065     slot->SetEnableVibration(true);
2066     slot->SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
2067     slot->SetLedLightColor(1);
2068     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
2069     slots.push_back(slot);
2070     g_advancedNotificationService->AddSlots(slots);
2071 
2072     // create request
2073     std::string label = "testLabel";
2074     sptr<NotificationRequest> req = new NotificationRequest(0);
2075     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2076     req->SetLabel(label);
2077     req1->SetLabel(label);
2078     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
2079     contentImpl->SetText("1");
2080     contentImpl->SetTitle("1");
2081     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2082     req->SetContent(content);
2083     req1->SetContent(content);
2084     req->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
2085     req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
2086 
2087     // publish request
2088     g_advancedNotificationService->Publish(label, req);
2089     g_advancedNotificationService->Publish(label, req1);
2090     EXPECT_TRUE(passed);
2091     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2092 }
2093 
2094 /**
2095  * @tc.number    : AnsModuleTest_117
2096  * @tc.name      : ANS_Module_Test_11700
2097  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2098  */
2099 HWTEST_F(AnsModuleTest, AnsModuleTest_0117, Function | SmallTest | Level1)
2100 {
2101     // subscriber
2102     auto subscriber = new TestAnsSubscriber();
2103     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2104     subscriber->consumedCb_ =
__anon9bfc377f2a02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2105         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2106             std::vector<std::string> sortingKey = sortingMap->GetKey();
2107 
2108             NotificationSorting sorting1;
2109             NotificationSorting sorting2;
2110             if (sortingKey.size() == 2) {
2111                 sortingMap->GetNotificationSorting("_1_testLabel_0", sorting1);
2112                 sortingMap->GetNotificationSorting("_1_testLabel_1", sorting2);
2113             }
2114             if (sorting1.GetRanking() < sorting2.GetRanking() && notification->EnableLight() &&
2115                 notification->EnableSound() && notification->EnableVibrate()) {
2116                 passed = true;
2117             }
2118         };
2119 
2120     // add slot
2121     std::vector<sptr<NotificationSlot>> slots;
2122     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2123     slot->SetSound(Uri("."));
2124     slot->SetEnableLight(true);
2125     slot->SetEnableVibration(true);
2126     slot->SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
2127     slot->SetLedLightColor(1);
2128     slot->SetVibrationStyle(std::vector<int64_t>(1, 1));
2129     slots.push_back(slot);
2130     g_advancedNotificationService->AddSlots(slots);
2131 
2132     // create request
2133     std::string label = "testLabel";
2134     sptr<NotificationRequest> req = new NotificationRequest(0);
2135     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2136     req->SetLabel(label);
2137     req1->SetLabel(label);
2138     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
2139     contentImpl->SetText("1");
2140     contentImpl->SetTitle("1");
2141     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2142     req->SetContent(content);
2143     req1->SetContent(content);
2144     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2145     req1->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2146 
2147     // publish request
2148     g_advancedNotificationService->Publish(label, req);
2149     g_advancedNotificationService->Publish(label, req1);
2150     EXPECT_TRUE(passed);
2151     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2152 }
2153 
2154 /**
2155  * @tc.number    : AnsModuleTest_120
2156  * @tc.name      : ANS_Module_Test_12000
2157  * @tc.desc      : Test publish notifications when Disturb are not allowed publish.
2158  */
2159 HWTEST_F(AnsModuleTest, AnsModuleTest_0120, Function | SmallTest | Level1)
2160 {
2161     // subscriber
2162     auto subscriber = new TestAnsSubscriber();
2163     sptr<NotificationSubscribeInfo> subscriberInfo = new NotificationSubscribeInfo();
2164     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo);
__anon9bfc377f2b02(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 2165     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
2166         passed = true;
2167     };
2168 
2169     // add slot
2170     std::vector<sptr<NotificationSlot>> slots;
2171     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2172     slots.push_back(slot0);
2173     g_advancedNotificationService->AddSlots(slots);
2174 
2175     // create request
2176     std::string label = "testLabel";
2177     sptr<NotificationRequest> req = new NotificationRequest(0);
2178     req->SetLabel(label);
2179     req->SetStatusBarText("text");
2180     std::shared_ptr<NotificationNormalContent> contentImpl = std::make_shared<NotificationNormalContent>();
2181     contentImpl->SetText("1");
2182     contentImpl->SetTitle("1");
2183     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2184     req->SetContent(content);
2185     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2186 
2187     g_advancedNotificationService->SetNotificationsEnabledForBundle("bundleName", false);
2188 
2189     g_advancedNotificationService->Publish(label, req);
2190     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2191     EXPECT_EQ(true, passed);
2192     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo);
2193 }
2194 
2195 /**
2196  * @tc.number    : AnsModuleTest_0121
2197  * @tc.name      : ANS_Module_Test_12100
2198  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2199  */
2200 HWTEST_F(AnsModuleTest, AnsModuleTest_0121, Function | SmallTest | Level1)
2201 {
2202     // add slot
2203     std::vector<sptr<NotificationSlot>> slots;
2204     sptr<NotificationSlot> socialSlot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2205     sptr<NotificationSlot> reminderSlot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
2206     sptr<NotificationSlot> contentSlot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
2207     sptr<NotificationSlot> otherSlot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2208     sptr<NotificationSlot> customSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM);
2209 
2210     slots.push_back(socialSlot);
2211     slots.push_back(reminderSlot);
2212     slots.push_back(contentSlot);
2213     slots.push_back(otherSlot);
2214     slots.push_back(customSlot);
2215 
2216     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
2217     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION), 0);
2218     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SERVICE_REMINDER), 0);
2219     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::CONTENT_INFORMATION), 0);
2220     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::OTHER), 0);
2221     EXPECT_EQ(g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::CUSTOM), 0);
2222 }
2223 
2224 /**
2225  * @tc.number    : AnsModuleTest_0122
2226  * @tc.name      : ANS_Module_Test_12200
2227  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2228  */
2229 HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1)
2230 {
2231     // subscriber
2232     auto subscriber = new TestAnsSubscriber();
2233     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2234     subscriber->consumedCb_ =
__anon9bfc377f2c02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2235         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2236             passed = true;
2237         };
2238 
2239     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
2240                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f2d02(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 2241                                   int deleteReason) { passed = true; };
2242 
2243     // add slot
2244     std::vector<sptr<NotificationSlot>> slots;
2245     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2246     slots.push_back(slot);
2247     g_advancedNotificationService->AddSlots(slots);
2248 
2249     // create request
2250     std::string label = "testLabel";
2251     sptr<NotificationRequest> req = new NotificationRequest(0);
2252     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2253     req->SetLabel(label);
2254     req1->SetLabel(label);
2255     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2256     req1->SetSlotType(NotificationConstant::SlotType::OTHER);
2257 
2258     // publish request
2259 
2260     // remove social slot
2261     EXPECT_EQ(0, g_advancedNotificationService->RemoveSlotByType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION));
2262 
2263     // add slot
2264     std::vector<sptr<NotificationSlot>> otherSlots;
2265     slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2266     otherSlots.push_back(slot);
2267     EXPECT_EQ(0, g_advancedNotificationService->AddSlots(otherSlots));
2268 
2269     EXPECT_FALSE(passed);
2270     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2271 }
2272 
2273 /**
2274  * @tc.number    : AnsModuleTest_0123
2275  * @tc.name      : ANS_Module_Test_12300
2276  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2277  */
2278 HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1)
2279 {
2280     int ret = 0;
2281     auto subscriber = new TestAnsSubscriber();
2282     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2283     subscriber->consumedCb_ = [&ret](const std::shared_ptr<Notification> notification,
2284                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f2e02(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2285                                       sortingMap) { ret++; };
2286     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
2287                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f2f02(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 2288                                   int deleteReason) { passed = true; };
2289     std::vector<sptr<NotificationSlot>> slots;
2290     slots.push_back(new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION));
2291     slots.push_back(new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER));
2292     slots.push_back(new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION));
2293     slots.push_back(new NotificationSlot(NotificationConstant::SlotType::OTHER));
2294     slots.push_back(new NotificationSlot(NotificationConstant::SlotType::CUSTOM));
2295     EXPECT_EQ(g_advancedNotificationService->AddSlots(slots), 0);
2296     sptr<NotificationRequest> req = new NotificationRequest(0);
2297     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2298     sptr<NotificationRequest> req2 = new NotificationRequest(2);
2299     sptr<NotificationRequest> req3 = new NotificationRequest(3);
2300     sptr<NotificationRequest> req4 = new NotificationRequest(4);
2301     req->SetLabel("testLabel");
2302     req1->SetLabel("testLabel");
2303     req2->SetLabel("testLabel");
2304     req3->SetLabel("testLabel");
2305     req4->SetLabel("testLabel");
2306 
2307     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2308     req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
2309     req2->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
2310     req3->SetSlotType(NotificationConstant::SlotType::OTHER);
2311     req4->SetSlotType(NotificationConstant::SlotType::CUSTOM);
2312 
2313     g_advancedNotificationService->Publish("testLabel", req);
2314     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2315     EXPECT_EQ(ret, 1);
2316     g_advancedNotificationService->Publish("testLabel", req1);
2317     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2318     EXPECT_EQ(ret, 2);
2319     g_advancedNotificationService->Publish("testLabel", req2);
2320     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2321     EXPECT_EQ(ret, 3);
2322     g_advancedNotificationService->Publish("testLabel", req3);
2323     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2324     EXPECT_EQ(ret, 4);
2325     g_advancedNotificationService->Publish("testLabel", req4);
2326     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2327     EXPECT_EQ(ret, 5);
2328     g_advancedNotificationService->DeleteAll();
2329     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2330     std::this_thread::sleep_for(std::chrono::milliseconds(200));
2331     EXPECT_TRUE(passed);
2332 }
2333 
2334 /**
2335  * @tc.number    : AnsModuleTest_0124
2336  * @tc.name      : ANS_Module_Test_12400
2337  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2338  */
2339 HWTEST_F(AnsModuleTest, AnsModuleTest_0124, Function | SmallTest | Level1)
2340 {
2341     // subscriber
2342     auto subscriber = new TestAnsSubscriber();
2343     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2344     subscriber->consumedCb_ =
__anon9bfc377f3002(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2345         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2346             passed = true;
2347         };
2348 
2349     // add slot
2350     std::vector<sptr<NotificationSlot>> slots;
2351     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
2352     slots.push_back(slot);
2353     g_advancedNotificationService->AddSlots(slots);
2354 
2355     // create request
2356     std::string label = "testLabel";
2357     sptr<NotificationRequest> req = new NotificationRequest(0);
2358     req->SetLabel(label);
2359     std::shared_ptr<NotificationMediaContent> contentImpl = std::make_shared<NotificationMediaContent>();
2360     contentImpl->SetText("1");
2361     contentImpl->SetTitle("1");
2362     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2363     req->SetContent(content);
2364     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
2365 
2366     // publish request
2367     g_advancedNotificationService->Publish(label, req);
2368     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2369     EXPECT_TRUE(passed);
2370 }
2371 
2372 /**
2373  * @tc.number    : AnsModuleTest_0125
2374  * @tc.name      : ANS_Module_Test_12500
2375  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2376  */
2377 HWTEST_F(AnsModuleTest, AnsModuleTest_0125, Function | SmallTest | Level1)
2378 {
2379     // subscriber
2380     auto subscriber = new TestAnsSubscriber();
2381     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2382     subscriber->consumedCb_ =
__anon9bfc377f3102(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2383         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2384             passed = true;
2385         };
2386 
2387     // add slot
2388     std::vector<sptr<NotificationSlot>> slots;
2389     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2390     slots.push_back(slot);
2391     g_advancedNotificationService->AddSlots(slots);
2392 
2393     // create request
2394     std::string label = "testLabel";
2395     sptr<NotificationRequest> req = new NotificationRequest(0);
2396     req->SetLabel(label);
2397     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2398 
2399     // publish request
2400     g_advancedNotificationService->Publish(label, req);
2401     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2402     EXPECT_TRUE(passed);
2403 }
2404 
2405 /**
2406  * @tc.number    : AnsModuleTest_0126
2407  * @tc.name      : ANS_Module_Test_12600
2408  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2409  */
2410 HWTEST_F(AnsModuleTest, AnsModuleTest_0126, Function | SmallTest | Level1)
2411 {
2412     // subscriber
2413     auto subscriber = new TestAnsSubscriber();
2414     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2415     subscriber->consumedCb_ =
__anon9bfc377f3202(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2416         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2417             passed = true;
2418         };
2419 
2420     // add slot
2421     std::vector<sptr<NotificationSlot>> slots;
2422     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
2423     slots.push_back(slot);
2424     g_advancedNotificationService->AddSlots(slots);
2425 
2426     // create request
2427     std::string label = "testLabel";
2428     sptr<NotificationRequest> req = new NotificationRequest(0);
2429     req->SetLabel(label);
2430     std::shared_ptr<NotificationPictureContent> contentImpl = std::make_shared<NotificationPictureContent>();
2431     contentImpl->SetText("1");
2432     contentImpl->SetTitle("1");
2433     std::shared_ptr<NotificationContent> content = std::make_shared<NotificationContent>(contentImpl);
2434     req->SetContent(content);
2435     req->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
2436 
2437     // publish request
2438     g_advancedNotificationService->Publish(label, req);
2439     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2440     EXPECT_TRUE(passed);
2441 }
2442 
2443 /**
2444  * @tc.number    : AnsModuleTest_0127
2445  * @tc.name      : ANS_Module_Test_12700
2446  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2447  */
2448 HWTEST_F(AnsModuleTest, AnsModuleTest_0127, Function | SmallTest | Level1)
2449 {
2450     const int EXPECT_REQUST_NUM = 2;
2451 
2452     int ret = 0;
2453     // subscriber
2454     auto subscriber = new TestAnsSubscriber();
2455     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2456     subscriber->consumedCb_ = [&ret](const std::shared_ptr<Notification> notification,
2457                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f3302(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2458                                       sortingMap) { ret++; };
2459 
2460     // add slot
2461     std::vector<sptr<NotificationSlot>> slots;
2462     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2463     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
2464     slots.push_back(slot);
2465     slots.push_back(slot1);
2466     g_advancedNotificationService->AddSlots(slots);
2467 
2468     // create content
2469     std::shared_ptr<NotificationPictureContent> contentImpl = std::make_shared<NotificationPictureContent>();
2470     contentImpl->SetText("1");
2471     contentImpl->SetTitle("1");
2472     std::shared_ptr<NotificationContent> pictureContent = std::make_shared<NotificationContent>(contentImpl);
2473 
2474     std::shared_ptr<NotificationLongTextContent> contentImpl1 = std::make_shared<NotificationLongTextContent>();
2475     contentImpl->SetText("1");
2476     contentImpl->SetTitle("1");
2477     std::shared_ptr<NotificationContent> longTextContent = std::make_shared<NotificationContent>(contentImpl);
2478 
2479     // create request
2480     std::string label = "testLabel";
2481     sptr<NotificationRequest> req = new NotificationRequest(0);
2482     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2483     req->SetLabel(label);
2484     req->SetContent(pictureContent);
2485     req1->SetLabel(label);
2486     req1->SetContent(longTextContent);
2487     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2488     req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER);
2489 
2490     // publish
2491     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2492     EXPECT_EQ(g_advancedNotificationService->Publish(label, req1), ERR_OK);
2493     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2494     EXPECT_EQ(ret, EXPECT_REQUST_NUM);
2495 }
2496 
2497 /**
2498  * @tc.number    : AnsModuleTest_0128
2499  * @tc.name      : ANS_Module_Test_12800
2500  * @tc.desc      : Test publish notification when slot type is CONTENT_INFORMATION.
2501  */
2502 HWTEST_F(AnsModuleTest, AnsModuleTest_0128, Function | SmallTest | Level1)
2503 {
2504     const int EXPECT_REQUST_NUM = 2;
2505 
2506     int ret = 0;
2507     // subscriber
2508     auto subscriber = new TestAnsSubscriber();
2509     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2510     subscriber->consumedCb_ = [&ret](const std::shared_ptr<Notification> notification,
2511                                   const std::shared_ptr<NotificationSortingMap>
__anon9bfc377f3402(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2512                                       sortingMap) { ret++; };
2513 
2514     // add slot
2515     std::vector<sptr<NotificationSlot>> slots;
2516     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
2517     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2518     slots.push_back(slot);
2519     slots.push_back(slot1);
2520     g_advancedNotificationService->AddSlots(slots);
2521 
2522     // create content
2523     std::shared_ptr<NotificationPictureContent> contentImpl = std::make_shared<NotificationPictureContent>();
2524     contentImpl->SetText("1");
2525     contentImpl->SetTitle("1");
2526     std::shared_ptr<NotificationContent> pictureContent = std::make_shared<NotificationContent>(contentImpl);
2527 
2528     std::shared_ptr<NotificationLongTextContent> contentImpl1 = std::make_shared<NotificationLongTextContent>();
2529     contentImpl->SetText("1");
2530     contentImpl->SetTitle("1");
2531     std::shared_ptr<NotificationContent> longTextContent = std::make_shared<NotificationContent>(contentImpl);
2532 
2533     // create request
2534     std::string label = "testLabel";
2535     sptr<NotificationRequest> req = new NotificationRequest(0);
2536     sptr<NotificationRequest> req1 = new NotificationRequest(1);
2537     req->SetLabel(label);
2538     req->SetContent(pictureContent);
2539     req1->SetLabel(label);
2540     req1->SetContent(longTextContent);
2541     req->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
2542     req1->SetSlotType(NotificationConstant::SlotType::OTHER);
2543 
2544     // publish
2545     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2546     EXPECT_EQ(g_advancedNotificationService->Publish(label, req1), ERR_OK);
2547     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2548     EXPECT_EQ(ret, EXPECT_REQUST_NUM);
2549 }
2550 
2551 /**
2552  * @tc.number    : AnsModuleTest_0130
2553  * @tc.name      : ANS_Module_Test_13000
2554  * @tc.desc      : Test publish notification when slot type is OTHER.
2555  */
2556 HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1)
2557 {
2558     // subscriber
2559     auto subscriber = new TestAnsSubscriber();
2560     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2561     subscriber->consumedCb_ =
__anon9bfc377f3502(const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) 2562         [](const std::shared_ptr<Notification> notification, const std::shared_ptr<NotificationSortingMap> sortingMap) {
2563             EXPECT_FALSE(notification->EnableVibrate());
2564             EXPECT_FALSE(notification->EnableSound());
2565         };
2566 
2567     // add slot
2568     std::vector<sptr<NotificationSlot>> slots;
2569     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2570     slots.push_back(slot);
2571     slot->SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
2572     slot->SetEnableVibration(true);
2573 
2574     // create request
2575     std::string label = "testLabel";
2576     sptr<NotificationRequest> req = new NotificationRequest(0);
2577     req->SetSlotType(NotificationConstant::SlotType::OTHER);
2578     req->SetLabel(label);
2579     // publish
2580     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2581     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2582 }
2583 
2584 /**
2585  * @tc.number    : AnsModuleTest_0131
2586  * @tc.name      : ANS_Module_Test_13100
2587  * @tc.desc      : Test publish notification when cancel a  notification.
2588  */
2589 HWTEST_F(AnsModuleTest, AnsModuleTest_0131, Function | SmallTest | Level1)
2590 {
2591     // subscriber
2592     auto subscriber = new TestAnsSubscriber();
2593     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
2594     subscriber->canceledCb_ = [](const std::shared_ptr<Notification> &request,
2595                                   const std::shared_ptr<NotificationSortingMap> &sortingMap,
__anon9bfc377f3602(const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) 2596                                   int deleteReason) { passed = true; };
2597     g_advancedNotificationService->Cancel(1, "1");
2598     g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr);
2599     EXPECT_EQ(false, passed);
2600 }
2601 
2602 /**
2603  * @tc.number    : AnsModuleTest_0132
2604  * @tc.name      : ANS_Module_Test_13200
2605  * @tc.desc      : Test publish notifications when Dnd type is NONE.
2606  */
2607 HWTEST_F(AnsModuleTest, AnsModuleTest_0132, Function | SmallTest | Level1)
2608 {
2609     // subscriber
2610     auto subscriber = new TestAnsSubscriber();
2611     EXPECT_EQ(g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr), ERR_OK);
__anon9bfc377f3702(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 2612     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
2613         passed = true;
2614     };
2615 
2616     // add slot
2617     std::vector<sptr<NotificationSlot>> slots;
2618     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2619     slots.push_back(slot0);
2620     g_advancedNotificationService->AddSlots(slots);
2621 
2622     // create request
2623     std::string label = "testLabel";
2624     sptr<NotificationRequest> req = new NotificationRequest(0);
2625     req->SetLabel(label);
2626     req->SetStatusBarText("text");
2627 
2628     sptr<NotificationDoNotDisturbDate> date =
2629         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
2630     EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK);
2631 
2632     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2633     EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK);
2634     EXPECT_TRUE(passed);
2635 }
2636 
2637 /**
2638  * @tc.number    : AnsModuleTest_0133
2639  * @tc.name      : ANS_Module_Test_13300
2640  * @tc.desc      : Test publish notifications when Dnd type is ONCE.
2641  */
2642 HWTEST_F(AnsModuleTest, AnsModuleTest_0133, Function | SmallTest | Level1)
2643 {
2644     // subscriber
2645     auto subscriber = new TestAnsSubscriber();
2646     EXPECT_EQ(g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr), ERR_OK);
__anon9bfc377f3802(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 2647     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
2648         passed = true;
2649     };
2650 
2651     // add slot
2652     std::vector<sptr<NotificationSlot>> slots;
2653     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2654     slots.push_back(slot0);
2655     g_advancedNotificationService->AddSlots(slots);
2656 
2657     // create request
2658     std::string label = "testLabel";
2659     sptr<NotificationRequest> req = new NotificationRequest(0);
2660     req->SetLabel(label);
2661     req->SetStatusBarText("text");
2662     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2663 
2664     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
2665     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2666     int64_t beginDate = beginDuration.count();
2667     timePoint += std::chrono::hours(1);
2668     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2669     int64_t endDate = endDuration.count();
2670     sptr<NotificationDoNotDisturbDate> date =
2671         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
2672     EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK);
2673 
2674     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2675     EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK);
2676     EXPECT_TRUE(passed);
2677 }
2678 
2679 /**
2680  * @tc.number    : AnsModuleTest_0134
2681  * @tc.name      : ANS_Module_Test_13400
2682  * @tc.desc      : Test publish notifications when Dnd type is DAILY.
2683  */
2684 HWTEST_F(AnsModuleTest, AnsModuleTest_0134, Function | SmallTest | Level1)
2685 {
2686     // subscriber
2687     auto subscriber = new TestAnsSubscriber();
2688     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
__anon9bfc377f3902(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 2689     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
2690         passed = true;
2691     };
2692 
2693     // add slot
2694     std::vector<sptr<NotificationSlot>> slots;
2695     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2696     slots.push_back(slot0);
2697     g_advancedNotificationService->AddSlots(slots);
2698 
2699     // create request
2700     std::string label = "testLabel";
2701     sptr<NotificationRequest> req = new NotificationRequest(0);
2702     req->SetLabel(label);
2703     req->SetStatusBarText("text");
2704     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2705 
2706     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
2707     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2708     int64_t beginDate = beginDuration.count();
2709     timePoint += std::chrono::hours(1);
2710     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2711     int64_t endDate = endDuration.count();
2712     sptr<NotificationDoNotDisturbDate> date =
2713         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
2714     EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK);
2715 
2716     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2717     EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK);
2718     EXPECT_TRUE(passed);
2719 }
2720 
2721 /**
2722  * @tc.number    : AnsModuleTest_0135
2723  * @tc.name      : ANS_Module_Test_13500
2724  * @tc.desc      : Test publish notifications when Dnd type is CLEARLY.
2725  */
2726 HWTEST_F(AnsModuleTest, AnsModuleTest_0135, Function | SmallTest | Level1)
2727 {
2728     // subscriber
2729     auto subscriber = new TestAnsSubscriber();
2730     g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr);
__anon9bfc377f3a02(const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) 2731     subscriber->consumedCb_ = [](const std::shared_ptr<Notification>, const std::shared_ptr<NotificationSortingMap>) {
2732         passed = true;
2733     };
2734 
2735     // add slot
2736     std::vector<sptr<NotificationSlot>> slots;
2737     sptr<NotificationSlot> slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2738     slots.push_back(slot0);
2739     g_advancedNotificationService->AddSlots(slots);
2740 
2741     // create request
2742     std::string label = "testLabel";
2743     sptr<NotificationRequest> req = new NotificationRequest(0);
2744     req->SetLabel(label);
2745     req->SetStatusBarText("text");
2746     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
2747 
2748     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
2749     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2750     int64_t beginDate = beginDuration.count();
2751     timePoint += std::chrono::hours(1);
2752     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2753     int64_t endDate = endDuration.count();
2754     sptr<NotificationDoNotDisturbDate> date =
2755         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate);
2756     EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(100, date), ERR_OK);
2757 
2758     EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK);
2759     EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK);
2760     EXPECT_TRUE(passed);
2761 }
2762 } // namespace Notification
2763 } // namespace OHOS
2764