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