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