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