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