1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <chrono>
17 #include <functional>
18 #include <memory>
19 #include <thread>
20 
21 #include "gtest/gtest.h"
22 
23 #define private public
24 #include "advanced_notification_service.h"
25 #include "ability_manager_errors.h"
26 #include "ans_inner_errors.h"
27 #include "ans_log_wrapper.h"
28 #include "accesstoken_kit.h"
29 #include "notification_preferences.h"
30 #include "notification_constant.h"
31 #include "ans_ut_constant.h"
32 #include "ans_dialog_host_client.h"
33 #include "mock_push_callback_stub.h"
34 
35 extern void MockIsOsAccountExists(bool exists);
36 
37 using namespace testing::ext;
38 using namespace OHOS::Security::AccessToken;
39 
40 namespace OHOS {
41 namespace Notification {
42 extern void MockIsVerfyPermisson(bool isVerify);
43 extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet);
44 extern void MockIsSystemApp(bool isSystemApp);
45 class AnsPublishServiceTest : public testing::Test {
46 public:
47     static void SetUpTestCase();
48     static void TearDownTestCase();
49     void SetUp();
50     void TearDown();
51 
52 private:
53     void TestAddNotification(int notificationId, const sptr<NotificationBundleOption> &bundle);
54     void RegisterPushCheck();
55 
56 private:
57     static sptr<AdvancedNotificationService> advancedNotificationService_;
58 };
59 
60 sptr<AdvancedNotificationService> AnsPublishServiceTest::advancedNotificationService_ = nullptr;
61 
SetUpTestCase()62 void AnsPublishServiceTest::SetUpTestCase() {}
63 
TearDownTestCase()64 void AnsPublishServiceTest::TearDownTestCase() {}
65 
SetUp()66 void AnsPublishServiceTest::SetUp()
67 {
68     GTEST_LOG_(INFO) << "SetUp start";
69 
70     advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService();
71     NotificationPreferences::GetInstance()->ClearNotificationInRestoreFactorySettings();
72     advancedNotificationService_->CancelAll(0);
73     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE);
74     MockIsSystemApp(true);
75     GTEST_LOG_(INFO) << "SetUp end";
76 }
77 
TearDown()78 void AnsPublishServiceTest::TearDown()
79 {
80     delete advancedNotificationService_;
81     advancedNotificationService_ = nullptr;
82     GTEST_LOG_(INFO) << "TearDown";
83 }
84 
TestAddNotification(int notificationId,const sptr<NotificationBundleOption> & bundle)85 void AnsPublishServiceTest::TestAddNotification(int notificationId, const sptr<NotificationBundleOption> &bundle)
86 {
87     auto slotType = NotificationConstant::SlotType::LIVE_VIEW;
88     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
89     request->SetSlotType(slotType);
90     request->SetOwnerUserId(1);
91     request->SetCreatorUserId(1);
92     request->SetOwnerBundleName("test");
93     request->SetOwnerUid(0);
94     request->SetNotificationId(notificationId);
95     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
96     auto ret = advancedNotificationService_->AssignToNotificationList(record);
97 }
98 
RegisterPushCheck()99 void AnsPublishServiceTest::RegisterPushCheck()
100 {
101     auto pushCallbackProxy = new (std::nothrow)MockPushCallBackStub();
102     EXPECT_NE(pushCallbackProxy, nullptr);
103     sptr<IRemoteObject> pushCallback = pushCallbackProxy->AsObject();
104     sptr<NotificationCheckRequest> checkRequest = new (std::nothrow) NotificationCheckRequest();
105     checkRequest->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
106     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
107     MockIsSystemApp(true);
108     MockIsVerfyPermisson(true);
109     ASSERT_EQ(advancedNotificationService_->RegisterPushCallback(pushCallback, checkRequest), ERR_OK);
110 }
111 
112 /**
113  * @tc.name: Publish_00001
114  * @tc.desc: Test Publish
115  * @tc.type: FUNC
116  * @tc.require: issue
117  */
118 HWTEST_F(AnsPublishServiceTest, Publish_00001, Function | SmallTest | Level1)
119 {
120     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
121     std::string label = "";
122     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
123     auto localLiveContent = std::make_shared<NotificationLocalLiveViewContent>();
124     auto content = std::make_shared<NotificationContent>(localLiveContent);
125     request->SetContent(content);
126     request->SetCreatorUid(1);
127     request->SetOwnerUid(1);
128     MockIsOsAccountExists(true);
129 
130     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
131     MockIsSystemApp(false);
132     auto ret = advancedNotificationService_->Publish(label, request);
133     ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
134 }
135 
136 /**
137  * @tc.name: Publish_00002
138  * @tc.desc: Test Publish
139  * @tc.type: FUNC
140  * @tc.require: issue
141  */
142 HWTEST_F(AnsPublishServiceTest, Publish_00002, Function | SmallTest | Level1)
143 {
144     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
145     std::string label = "";
146     request->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION);
147     request->SetRemoveAllowed(false);
148     request->SetInProgress(true);
149     auto normalContent = std::make_shared<NotificationNormalContent>();
150     auto content = std::make_shared<NotificationContent>(normalContent);
151     request->SetContent(content);
152 
153     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
154     MockIsSystemApp(true);
155     MockIsVerfyPermisson(false);
156 
157     auto ret = advancedNotificationService_->Publish(label, request);
158     ASSERT_EQ(ret, (int)ERR_OK);
159 }
160 
161 
162 /**
163  * @tc.name: Publish_00003
164  * @tc.desc: Publish live_view notification once
165  * @tc.type: FUNC
166  * @tc.require: issue
167  */
168 HWTEST_F(AnsPublishServiceTest, Publish_00003, Function | SmallTest | Level1)
169 {
170     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
171     std::string label = "";
172     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
173     request->SetNotificationId(1);
174     auto liveContent = std::make_shared<NotificationLiveViewContent>();
175     auto content = std::make_shared<NotificationContent>(liveContent);
176     request->SetContent(content);
177     RegisterPushCheck();
178     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
179     MockIsSystemApp(true);
180     MockIsVerfyPermisson(false);
181 
182     auto ret = advancedNotificationService_->Publish(label, request);
183     ASSERT_EQ(ret, (int)ERR_OK);
184 
185     sptr<NotificationSlot> slot;
186     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
187     ret = advancedNotificationService_->GetSlotByType(slotType, slot);
188     ASSERT_EQ(ret, (int)ERR_OK);
189     ASSERT_EQ(1, slot->GetAuthorizedStatus());
190     ASSERT_EQ(1, slot->GetAuthHintCnt());
191 }
192 
193 /**
194  * @tc.name: Publish_00004
195  * @tc.desc: Publish live_view notification twice
196  * @tc.type: FUNC
197  * @tc.require: issue
198  */
199 HWTEST_F(AnsPublishServiceTest, Publish_00004, Function | SmallTest | Level1)
200 {
201     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
202     std::string label = "";
203     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
204     request->SetNotificationId(1);
205     auto liveContent = std::make_shared<NotificationLiveViewContent>();
206     auto content = std::make_shared<NotificationContent>(liveContent);
207     request->SetContent(content);
208     RegisterPushCheck();
209 
210     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
211     MockIsSystemApp(true);
212     MockIsVerfyPermisson(false);
213 
214     auto ret = advancedNotificationService_->Publish(label, request);
215     ASSERT_EQ(ret, (int)ERR_OK);
216 
217     sptr<NotificationRequest> request2 = new (std::nothrow) NotificationRequest();
218     request2->SetNotificationId(2);
219     request2->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
220     request2->SetContent(content);
221     ret = advancedNotificationService_->Publish(label, request2);
222     ASSERT_EQ(ret, (int)ERR_OK);
223 
224     sptr<NotificationSlot> slot;
225     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
226     ret = advancedNotificationService_->GetSlotByType(slotType, slot);
227     ASSERT_EQ(ret, (int)ERR_OK);
228     ASSERT_EQ(0, slot->GetAuthorizedStatus());
229     ASSERT_EQ(2, slot->GetAuthHintCnt());
230 }
231 
232 /**
233  * @tc.name: Publish_00005
234  * @tc.desc: Publish test receiver user and checkUserExists is true
235  * @tc.type: FUNC
236  * @tc.require: issue
237  */
238 HWTEST_F(AnsPublishServiceTest, Publish_00005, Function | SmallTest | Level1)
239 {
240     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
241     std::string label = "";
242     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
243     request->SetNotificationId(1);
244     request->SetReceiverUserId(101);
245     auto liveContent = std::make_shared<NotificationLiveViewContent>();
246     auto content = std::make_shared<NotificationContent>(liveContent);
247     request->SetContent(content);
248     RegisterPushCheck();
249     MockIsOsAccountExists(true);
250     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
251     MockIsSystemApp(true);
252     MockIsVerfyPermisson(true);
253 
254     auto ret = advancedNotificationService_->Publish(label, request);
255     ASSERT_EQ(ret, (int)ERR_OK);
256 }
257 
258 /**
259  * @tc.name: Publish_00006
260  * @tc.desc: Publish test receiver user and checkUserExists is false
261  * @tc.type: FUNC
262  * @tc.require: issue
263  */
264 HWTEST_F(AnsPublishServiceTest, Publish_00006, Function | SmallTest | Level1)
265 {
266     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
267     std::string label = "";
268     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
269     request->SetNotificationId(1);
270     request->SetReceiverUserId(101);
271     auto liveContent = std::make_shared<NotificationLiveViewContent>();
272     auto content = std::make_shared<NotificationContent>(liveContent);
273     request->SetContent(content);
274     MockIsOsAccountExists(false);
275 
276     auto ret = advancedNotificationService_->Publish(label, request);
277     ASSERT_EQ(ret, (int)ERROR_USER_NOT_EXIST);
278 }
279 
280 /**
281  * @tc.name: DeleteByBundle_00001
282  * @tc.desc: Test DeleteByBundle
283  * @tc.type: FUNC
284  * @tc.require: issue
285  */
286 HWTEST_F(AnsPublishServiceTest, DeleteByBundle_00001, Function | SmallTest | Level1)
287 {
288     sptr<NotificationBundleOption> bundleOption = nullptr;
289     auto ret = advancedNotificationService_->DeleteByBundle(bundleOption);
290     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
291 }
292 
293 /**
294  * @tc.name: DeleteByBundle_00002
295  * @tc.desc: Test DeleteByBundle
296  * @tc.type: FUNC
297  * @tc.require: issue
298  */
299 HWTEST_F(AnsPublishServiceTest, DeleteByBundle_00002, Function | SmallTest | Level1)
300 {
301     sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
302     advancedNotificationService_->notificationSvrQueue_ = nullptr;
303     auto ret = advancedNotificationService_->DeleteByBundle(bundle);
304     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
305 }
306 
307 /**
308  * @tc.name: DeleteByBundle_00003
309  * @tc.desc: Test DeleteByBundle
310  * @tc.type: FUNC
311  * @tc.require: issue
312  */
313 HWTEST_F(AnsPublishServiceTest, DeleteByBundle_00003, Function | SmallTest | Level1)
314 {
315     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
316     TestAddNotification(1, bundle);
317     auto ret = advancedNotificationService_->DeleteByBundle(bundle);
318     ASSERT_EQ(ret, (int)ERR_OK);
319     ASSERT_EQ(advancedNotificationService_->notificationList_.size(), 0);
320 }
321 
322 /**
323  * @tc.name: DeleteAll_00001
324  * @tc.desc: Test DeleteAll
325  * @tc.type: FUNC
326  * @tc.require: issue
327  */
328 HWTEST_F(AnsPublishServiceTest, DeleteAll_00001, Function | SmallTest | Level1)
329 {
330     advancedNotificationService_->notificationSvrQueue_ = nullptr;
331     auto ret = advancedNotificationService_->DeleteAll();
332     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
333 }
334 
335 /**
336  * @tc.name: SetShowBadgeEnabledForBundle_00001
337  * @tc.desc: Test SetShowBadgeEnabledForBundle
338  * @tc.type: FUNC
339  * @tc.require: issue
340  */
341 HWTEST_F(AnsPublishServiceTest, SetShowBadgeEnabledForBundle_00001, Function | SmallTest | Level1)
342 {
343     sptr<NotificationBundleOption> bundleOption = nullptr;
344     auto ret = advancedNotificationService_->SetShowBadgeEnabledForBundle(bundleOption, true);
345     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
346 
347     bool enabled = false;
348     ret = advancedNotificationService_->GetShowBadgeEnabledForBundle(bundleOption, enabled);
349     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
350 }
351 
352 /**
353  * @tc.name: SetShowBadgeEnabledForBundle_00002
354  * @tc.desc: Test SetShowBadgeEnabledForBundle
355  * @tc.type: FUNC
356  * @tc.require: issue
357  */
358 HWTEST_F(AnsPublishServiceTest, SetShowBadgeEnabledForBundle_00002, Function | SmallTest | Level1)
359 {
360     sptr<NotificationBundleOption> bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
361     advancedNotificationService_->notificationSvrQueue_ = nullptr;
362     auto ret = advancedNotificationService_->SetShowBadgeEnabledForBundle(bundle, true);
363     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
364 
365     bool enabled = false;
366     ret = advancedNotificationService_->GetShowBadgeEnabledForBundle(bundle, enabled);
367     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
368 }
369 
370 /**
371  * @tc.name: GetShowBadgeEnabled_00001
372  * @tc.desc: Test GetShowBadgeEnabled
373  * @tc.type: FUNC
374  * @tc.require: issue
375  */
376 HWTEST_F(AnsPublishServiceTest, GetShowBadgeEnabled_00001, Function | SmallTest | Level1)
377 {
378     advancedNotificationService_->notificationSvrQueue_ = nullptr;
379     bool enabled = false;
380     auto ret = advancedNotificationService_->GetShowBadgeEnabled(enabled);
381     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
382 }
383 
384 /**
385  * @tc.name: GetShowBadgeEnabled_00002
386  * @tc.desc: Test GetShowBadgeEnabled
387  * @tc.type: FUNC
388  * @tc.require: issue
389  */
390 HWTEST_F(AnsPublishServiceTest, GetShowBadgeEnabled_00002, Function | SmallTest | Level1)
391 {
392     bool enabled = true;
393     MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP);
394     MockIsSystemApp(true);
395     MockIsVerfyPermisson(true);
396     auto ret = advancedNotificationService_->GetShowBadgeEnabled(enabled);
397     ASSERT_EQ(ret, (int)ERR_OK);
398     ASSERT_EQ(enabled, true);
399 }
400 
401 /**
402  * @tc.name: RequestEnableNotification_00001
403  * @tc.desc: Test RequestEnableNotification
404  * @tc.type: FUNC
405  * @tc.require: issue
406  */
407 HWTEST_F(AnsPublishServiceTest, RequestEnableNotification_00001, Function | SmallTest | Level1)
408 {
409     std::string deviceId = "deviceId";
410     sptr<AnsDialogHostClient> client = nullptr;
411     AnsDialogHostClient::CreateIfNullptr(client);
412     client = AnsDialogHostClient::GetInstance();
413     sptr<IRemoteObject> callerToken = nullptr;
414 
415     auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), false);
416     ASSERT_EQ(ret, (int)ERR_OK);
417 
418     ret = advancedNotificationService_->RequestEnableNotification(deviceId, client, callerToken);
419     ASSERT_EQ(ret, (int)ERROR_INTERNAL_ERROR);
420 }
421 
422 /**
423  * @tc.name: RequestEnableNotification_00002
424  * @tc.desc: Test RequestEnableNotification
425  * @tc.type: FUNC
426  * @tc.require: issue
427  */
428 HWTEST_F(AnsPublishServiceTest, RequestEnableNotification_00002, Function | SmallTest | Level1)
429 {
430     std::string deviceId = "deviceId";
431     sptr<AnsDialogHostClient> client = nullptr;
432     AnsDialogHostClient::CreateIfNullptr(client);
433     client = AnsDialogHostClient::GetInstance();
434     sptr<IRemoteObject> callerToken = nullptr;
435 
436     auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), true);
437     ASSERT_EQ(ret, (int)ERR_OK);
438 
439     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
440     ret = advancedNotificationService_->RequestEnableNotification(deviceId, client, callerToken);
441     ASSERT_EQ(ret, (int)ERR_OK);
442 }
443 
444 /**
445  * @tc.name: RequestEnableNotification_00003
446  * @tc.desc: Test RequestEnableNotification
447  * @tc.type: FUNC
448  * @tc.require: issue
449  */
450 HWTEST_F(AnsPublishServiceTest, RequestEnableNotification_00003, Function | SmallTest | Level1)
451 {
452     std::string deviceId = "deviceId";
453     sptr<AnsDialogHostClient> client = nullptr;
454     AnsDialogHostClient::CreateIfNullptr(client);
455     client = AnsDialogHostClient::GetInstance();
456     sptr<IRemoteObject> callerToken = nullptr;
457 
458     auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles(std::string(), false);
459     ASSERT_EQ(ret, (int)ERR_OK);
460 
461     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
462 
463     auto bundle = advancedNotificationService_->GenerateBundleOption();
464     NotificationPreferences::GetInstance()->SetHasPoppedDialog(bundle, true);
465 
466     ret = advancedNotificationService_->RequestEnableNotification(deviceId, client, callerToken);
467     ASSERT_EQ(ret, (int)ERR_ANS_NOT_ALLOWED);
468 
469     NotificationPreferences::GetInstance()->SetHasPoppedDialog(bundle, false);
470     ret = advancedNotificationService_->RequestEnableNotification(deviceId, client, callerToken);
471     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
472 }
473 
474 /**
475  * @tc.name: SetNotificationsEnabledForAllBundles_00001
476  * @tc.desc: Test SetNotificationsEnabledForAllBundles
477  * @tc.type: FUNC
478  * @tc.require: issue
479  */
480 HWTEST_F(AnsPublishServiceTest, SetNotificationsEnabledForAllBundles_00001, Function | SmallTest | Level1)
481 {
482     advancedNotificationService_->notificationSvrQueue_ = nullptr;
483     bool enabled = false;
484     auto ret = advancedNotificationService_->SetNotificationsEnabledForAllBundles("", enabled);
485     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
486 }
487 
488 /**
489  * @tc.name: SetNotificationsEnabledForSpecialBundle_00001
490  * @tc.desc: Test SetNotificationsEnabledForSpecialBundle
491  * @tc.type: FUNC
492  * @tc.require: issue
493  */
494 HWTEST_F(AnsPublishServiceTest, SetNotificationsEnabledForSpecialBundle_00001, Function | SmallTest | Level1)
495 {
496     sptr<NotificationBundleOption> bundle = nullptr;
497     bool enabled = false;
498     std::string deviceId = "deviceId";
499     auto ret = advancedNotificationService_->SetNotificationsEnabledForSpecialBundle(deviceId, bundle, enabled);
500     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
501 }
502 
503 /**
504  * @tc.name: IsAllowedNotify_00001
505  * @tc.desc: Test IsAllowedNotify
506  * @tc.type: FUNC
507  * @tc.require: issue
508  */
509 HWTEST_F(AnsPublishServiceTest, IsAllowedNotify_00001, Function | SmallTest | Level1)
510 {
511     advancedNotificationService_->notificationSvrQueue_ = nullptr;
512     bool allowed = false;
513     auto ret = advancedNotificationService_->IsAllowedNotify(allowed);
514     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
515 }
516 
517 /**
518  * @tc.name: IsAllowedNotifyForBundle_00001
519  * @tc.desc: Test IsAllowedNotifyForBundle
520  * @tc.type: FUNC
521  * @tc.require: issue
522  */
523 HWTEST_F(AnsPublishServiceTest, IsAllowedNotifyForBundle_00001, Function | SmallTest | Level1)
524 {
525     bool allowed = false;
526     sptr<NotificationBundleOption> bundle = nullptr;
527     auto ret = advancedNotificationService_->IsAllowedNotifyForBundle(bundle, allowed);
528     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
529 }
530 
531 /**
532  * @tc.name: TriggerLocalLiveView_00001
533  * @tc.desc: Test TriggerLocalLiveView
534  * @tc.type: FUNC
535  * @tc.require: issue
536  */
537 HWTEST_F(AnsPublishServiceTest, TriggerLocalLiveView_00001, Function | SmallTest | Level1)
538 {
539     int notificationId = 1;
540     sptr<NotificationBundleOption> bundle = nullptr;
541     sptr<NotificationButtonOption> buttonOption = nullptr;
542 
543     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
544     MockIsSystemApp(false);
545     MockIsVerfyPermisson(false);
546 
547     auto ret = advancedNotificationService_->TriggerLocalLiveView(bundle, notificationId, buttonOption);
548     ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
549 
550     MockIsSystemApp(true);
551     ret = advancedNotificationService_->TriggerLocalLiveView(bundle, notificationId, buttonOption);
552     ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
553 
554     MockIsVerfyPermisson(true);
555     ret = advancedNotificationService_->TriggerLocalLiveView(bundle, notificationId, buttonOption);
556     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
557 }
558 
559 /**
560  * @tc.name: RemoveNotification_00001
561  * @tc.desc: Test RemoveNotification
562  * @tc.type: FUNC
563  * @tc.require: issue
564  */
565 HWTEST_F(AnsPublishServiceTest, RemoveNotification_00001, Function | SmallTest | Level1)
566 {
567     advancedNotificationService_->notificationSvrQueue_ = nullptr;
568     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
569     std::string label = "label";
570     int notificationId = 1;
571     auto ret = advancedNotificationService_->RemoveNotification(bundle, notificationId, label, 0);
572 
573     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
574 }
575 
576 /**
577  * @tc.name: RemoveNotifications_00001
578  * @tc.desc: Test RemoveNotifications
579  * @tc.type: FUNC
580  * @tc.require: issue
581  */
582 HWTEST_F(AnsPublishServiceTest, RemoveNotifications_00001, Function | SmallTest | Level1)
583 {
584     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
585     MockIsSystemApp(false);
586     std::vector<std::string> keys;
587     int removeReason = 1;
588     auto ret = advancedNotificationService_->RemoveNotifications(keys, removeReason);
589     ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
590 
591     MockIsSystemApp(true);
592     MockIsVerfyPermisson(false);
593     ret = advancedNotificationService_->RemoveNotifications(keys, removeReason);
594     ASSERT_EQ(ret, (int)ERR_ANS_PERMISSION_DENIED);
595 
596     advancedNotificationService_->notificationSvrQueue_ = nullptr;
597     MockIsVerfyPermisson(true);
598     ret = advancedNotificationService_->RemoveNotifications(keys, removeReason);
599     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
600 }
601 
602 /**
603  * @tc.name: RemoveNotifications_00002
604  * @tc.desc: Test RemoveNotifications
605  * @tc.type: FUNC
606  * @tc.require: issue
607  */
608 HWTEST_F(AnsPublishServiceTest, RemoveNotifications_00002, Function | SmallTest | Level1)
609 {
610     std::vector<std::string> keys;
611     int removeReason = 1;
612 
613     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
614     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest();
615     req->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
616     req->SetOwnerUserId(1);
617     req->SetOwnerBundleName(TEST_DEFUALT_BUNDLE);
618     req->SetNotificationId(1);
619     auto record = advancedNotificationService_->MakeNotificationRecord(req, bundle);
620     auto ret = advancedNotificationService_->AssignToNotificationList(record);
621     keys.emplace_back(record->notification->GetKey());
622 
623     ret = advancedNotificationService_->RemoveNotifications(keys, removeReason);
624     ASSERT_EQ(ret, (int)ERR_OK);
625 }
626 
627 /**
628  * @tc.name: RemoveNotificationBySlot_00001
629  * @tc.desc: Test RemoveNotificationBySlot
630  * @tc.type: FUNC
631  * @tc.require: issue
632  */
633 HWTEST_F(AnsPublishServiceTest, RemoveNotificationBySlot_00001, Function | SmallTest | Level1)
634 {
635     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
636     MockIsSystemApp(false);
637     sptr<NotificationBundleOption> bundle = nullptr;
638     sptr<NotificationSlot> slot = nullptr;
639     auto ret = advancedNotificationService_->RemoveNotificationBySlot(bundle, slot,
640         NotificationConstant::DEFAULT_REASON_DELETE);
641     ASSERT_EQ(ret, (int)ERR_ANS_NON_SYSTEM_APP);
642 
643     MockIsSystemApp(true);
644     MockIsVerfyPermisson(false);
645     ret = advancedNotificationService_->RemoveNotificationBySlot(bundle, slot,
646         NotificationConstant::DEFAULT_REASON_DELETE);
647     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_BUNDLE);
648 }
649 
650 /**
651  * @tc.name: RemoveNotificationBySlot_00002
652  * @tc.desc: Test RemoveNotificationBySlot
653  * @tc.type: FUNC
654  * @tc.require: issue
655  */
656 HWTEST_F(AnsPublishServiceTest, RemoveNotificationBySlot_00002, Function | SmallTest | Level1)
657 {
658     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
659     sptr<NotificationRequest> req = new (std::nothrow) NotificationRequest();
660     req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
661     req->SetOwnerUserId(1);
662     req->SetOwnerBundleName(TEST_DEFUALT_BUNDLE);
663     req->SetNotificationId(1);
664     auto multiLineContent = std::make_shared<NotificationMultiLineContent>();
665     auto content = std::make_shared<NotificationContent>(multiLineContent);
666     req->SetContent(content);
667     auto record = advancedNotificationService_->MakeNotificationRecord(req, bundle);
668     auto ret = advancedNotificationService_->AssignToNotificationList(record);
669     auto slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
670 
671     ret = advancedNotificationService_->RemoveNotificationBySlot(bundle, slot,
672         NotificationConstant::DEFAULT_REASON_DELETE);
673     ASSERT_EQ(ret, (int)ERR_OK);
674 }
675 
676 /**
677  * @tc.name: NotificationSvrQueue_00001
678  * @tc.desc: Test notificationSvrQueue is nullptr
679  * @tc.type: FUNC
680  * @tc.require: issue
681  */
682 HWTEST_F(AnsPublishServiceTest, NotificationSvrQueue_00001, Function | SmallTest | Level1)
683 {
684     MockIsSystemApp(true);
685     MockIsVerfyPermisson(true);
686     advancedNotificationService_->notificationSvrQueue_ = nullptr;
687     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
688 
689     auto ret = advancedNotificationService_->CancelAll(0);
690     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
691 
692     ret = advancedNotificationService_->Delete("", 1);
693     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
694 
695     ret = advancedNotificationService_->CancelGroup("group", 0);
696     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
697 
698     ret = advancedNotificationService_->RemoveGroupByBundle(bundle, "group");
699     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
700 
701     bool allowed = false;
702     ret = advancedNotificationService_->IsSpecialUserAllowedNotify(1, allowed);
703     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
704 
705     ret = advancedNotificationService_->SetNotificationsEnabledByUser(1, false);
706     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
707 
708     ret = advancedNotificationService_->SetBadgeNumber(1, 0);
709     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
710 
711     ret = advancedNotificationService_->SubscribeLocalLiveView(nullptr, nullptr, true);
712     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
713 }
714 
715 /*
716  * @tc.name: SetDistributedEnabledByBundle_0100
717  * @tc.desc: test SetDistributedEnabledByBundle with parameters
718  * @tc.type: FUNC
719  */
720 HWTEST_F(AnsPublishServiceTest, SetDistributedEnabledByBundle_0100, TestSize.Level1)
721 {
722     MockIsSystemApp(true);
723     MockIsVerfyPermisson(true);
724     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
725     std::string deviceType = "testDeviceType";
726 
727     ErrCode res = advancedNotificationService_->SetDistributedEnabledByBundle(bundleOption, deviceType, true);
728     ASSERT_EQ(res, ERR_OK);
729 }
730 
731 /*
732  * @tc.name: SetDistributedEnabledByBundle_0200
733  * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_NON_SYSTEM_APP.
734  * @tc.type: FUNC
735  */
736 HWTEST_F(AnsPublishServiceTest, SetDistributedEnabledByBundle_0200, TestSize.Level1)
737 {
738     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
739     MockIsSystemApp(false);
740     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
741     std::string deviceType = "testDeviceType";
742 
743     ErrCode res = advancedNotificationService_->SetDistributedEnabledByBundle(bundleOption, deviceType, true);
744     ASSERT_EQ(res, ERR_ANS_NON_SYSTEM_APP);
745 }
746 
747 /*
748  * @tc.name: SetDistributedEnabledByBundle_0300
749  * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_PERMISSION_DENIED.
750  * @tc.type: FUNC
751  */
752 HWTEST_F(AnsPublishServiceTest, SetDistributedEnabledByBundle_0300, TestSize.Level1)
753 {
754     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
755     MockIsSystemApp(true);
756     MockIsVerfyPermisson(false);
757     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
758     std::string deviceType = "testDeviceType";
759 
760     ErrCode res = advancedNotificationService_->SetDistributedEnabledByBundle(bundleOption, deviceType, true);
761     ASSERT_EQ(res, ERR_ANS_PERMISSION_DENIED);
762 }
763 
764 
765 /**
766  * @tc.name: IsDistributedEnabledByBundle_0100
767  * @tc.desc: test IsDistributedEnabledByBundle with parameters
768  * @tc.type: FUNC
769  */
770 HWTEST_F(AnsPublishServiceTest, IsDistributedEnabledByBundle_0100, TestSize.Level1)
771 {
772     MockIsSystemApp(true);
773     MockIsVerfyPermisson(true);
774     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
775     std::string deviceType = "testDeviceType1111";
776     bool enable = true;
777     ErrCode result = advancedNotificationService_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable);
778     ASSERT_EQ(result, ERR_OK);
779 }
780 
781 /**
782  * @tc.name: IsDistributedEnabledByBundle_0200
783  * @tc.desc: test IsDistributedEnabledByBundle with parameters
784  * @tc.type: FUNC
785  */
786 HWTEST_F(AnsPublishServiceTest, IsDistributedEnabledByBundle_0200, TestSize.Level1)
787 {
788     MockIsSystemApp(true);
789     MockIsVerfyPermisson(true);
790     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
791     std::string deviceType = "testDeviceType";
792 
793     ErrCode ret = advancedNotificationService_->SetDistributedEnabledByBundle(bundleOption, deviceType, true);
794     ASSERT_EQ(ret, ERR_OK);
795     bool enable = false;
796     ret = advancedNotificationService_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable);
797     ASSERT_EQ(ret, ERR_OK);
798     ASSERT_EQ(enable, true);
799 }
800 
801 /**
802  * @tc.name: IsDistributedEnabledByBundle_0300
803  * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_NON_SYSTEM_APP.
804  * @tc.type: FUNC
805  */
806 HWTEST_F(AnsPublishServiceTest, IsDistributedEnabledByBundle_0300, TestSize.Level1)
807 {
808     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
809     MockIsSystemApp(false);
810     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
811     std::string deviceType = "testDeviceType1111";
812     bool enable = true;
813     ErrCode result = advancedNotificationService_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable);
814     ASSERT_EQ(result, ERR_ANS_NON_SYSTEM_APP);
815 }
816 
817 /**
818  * @tc.name: IsDistributedEnabledByBundle_0400
819  * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_PERMISSION_DENIED.
820  * @tc.type: FUNC
821  */
822 HWTEST_F(AnsPublishServiceTest, IsDistributedEnabledByBundle_0400, TestSize.Level1)
823 {
824     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
825     MockIsSystemApp(true);
826     MockIsVerfyPermisson(false);
827     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
828     std::string deviceType = "testDeviceType1111";
829     bool enable = true;
830     ErrCode result = advancedNotificationService_->IsDistributedEnabledByBundle(bundleOption, deviceType, enable);
831     ASSERT_EQ(result, ERR_ANS_PERMISSION_DENIED);
832 }
833 
834 /**
835  * @tc.name: DuplicateMsgControl_00001
836  * @tc.desc: Test DuplicateMsgControl
837  * @tc.type: FUNC
838  * @tc.require: issue
839  */
840 HWTEST_F(AnsPublishServiceTest, DuplicateMsgControl_00001, Function | SmallTest | Level1)
841 {
842     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
843     request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW);
844     auto liveViewContent = std::make_shared<NotificationLiveViewContent>();
845     auto content = std::make_shared<NotificationContent>(liveViewContent);
846     request->SetContent(content);
847 
848     auto ret = advancedNotificationService_->DuplicateMsgControl(request);
849     ASSERT_EQ(ret, (int)ERR_OK);
850 }
851 
852 /**
853  * @tc.name: DuplicateMsgControl_00002
854  * @tc.desc: Test DuplicateMsgControl
855  * @tc.type: FUNC
856  * @tc.require: issue
857  */
858 HWTEST_F(AnsPublishServiceTest, DuplicateMsgControl_00002, Function | SmallTest | Level1)
859 {
860     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
861     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
862     request->SetAppMessageId("test1");
863     auto uniqueKey = request->GenerateUniqueKey();
864     advancedNotificationService_->uniqueKeyList_.emplace_back(
865         std::make_pair(std::chrono::steady_clock::now(), uniqueKey));
866 
867     auto ret = advancedNotificationService_->DuplicateMsgControl(request);
868     ASSERT_EQ(ret, (int)ERR_ANS_DUPLICATE_MSG);
869 }
870 
871 /**
872  * @tc.name: DuplicateMsgControl_00003
873  * @tc.desc: Test DuplicateMsgControl
874  * @tc.type: FUNC
875  * @tc.require: issue
876  */
877 HWTEST_F(AnsPublishServiceTest, DuplicateMsgControl_00003, Function | SmallTest | Level1)
878 {
879     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
880     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
881     request->SetAppMessageId("test2");
882 
883     auto ret = advancedNotificationService_->DuplicateMsgControl(request);
884     ASSERT_EQ(ret, (int)ERR_OK);
885     ASSERT_EQ(advancedNotificationService_->uniqueKeyList_.size(), 1);
886 }
887 
888 /**
889  * @tc.name: IsDuplicateMsg_00001
890  * @tc.desc: Test IsDuplicateMsg
891  * @tc.type: FUNC
892  * @tc.require: issue
893  */
894 HWTEST_F(AnsPublishServiceTest, IsDuplicateMsg_00001, Function | SmallTest | Level1)
895 {
896     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
897     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
898     request->SetAppMessageId("test2");
899     auto uniqueKey = request->GenerateUniqueKey();
900 
901     auto ret = advancedNotificationService_->IsDuplicateMsg(uniqueKey);
902     ASSERT_EQ(ret, false);
903 }
904 
905 /**
906  * @tc.name: IsDuplicateMsg_00002
907  * @tc.desc: Test IsDuplicateMsg
908  * @tc.type: FUNC
909  * @tc.require: issue
910  */
911 HWTEST_F(AnsPublishServiceTest, IsDuplicateMsg_00002, Function | SmallTest | Level1)
912 {
913     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
914     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
915     request->SetAppMessageId("test2");
916     auto uniqueKey = request->GenerateUniqueKey();
917     advancedNotificationService_->uniqueKeyList_.emplace_back(
918         std::make_pair(std::chrono::steady_clock::now(), uniqueKey));
919 
920     auto ret = advancedNotificationService_->IsDuplicateMsg(uniqueKey);
921     ASSERT_EQ(ret, true);
922 }
923 
924 /**
925  * @tc.name: RemoveExpiredUniqueKey_00001
926  * @tc.desc: Test RemoveExpiredUniqueKey
927  * @tc.type: FUNC
928  * @tc.require: issue
929  */
930 HWTEST_F(AnsPublishServiceTest, RemoveExpiredUniqueKey_00001, Function | SmallTest | Level1)
931 {
932     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
933     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
934     request->SetAppMessageId("test2");
935     auto uniqueKey = request->GenerateUniqueKey();
936     advancedNotificationService_->uniqueKeyList_.emplace_back(
937         std::make_pair(std::chrono::steady_clock::now() - std::chrono::hours(24), uniqueKey));
938 
939     sleep(1);
940     ASSERT_EQ(advancedNotificationService_->uniqueKeyList_.size(), 1);
941     advancedNotificationService_->RemoveExpiredUniqueKey();
942     ASSERT_EQ(advancedNotificationService_->uniqueKeyList_.size(), 0);
943 }
944 
945 /*
946  * @tc.name: SetSmartReminderEnabled_0100
947  * @tc.desc: test SetSmartReminderEnabled with parameters
948  * @tc.type: FUNC
949  */
950 HWTEST_F(AnsPublishServiceTest, SetSmartReminderEnabled_0100, TestSize.Level1)
951 {
952     MockIsSystemApp(true);
953     MockIsVerfyPermisson(true);
954     ErrCode res = advancedNotificationService_->SetSmartReminderEnabled("testDeviceType", true);
955     ASSERT_EQ(res, ERR_OK);
956 }
957 
958 /*
959  * @tc.name: SetSmartReminderEnabled_0200
960  * @tc.desc: test SetSmartReminderEnabled with parameters, expect errorCode ERR_ANS_NON_SYSTEM_APP.
961  * @tc.type: FUNC
962  */
963 HWTEST_F(AnsPublishServiceTest, SetSmartReminderEnabled_0200, TestSize.Level1)
964 {
965     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
966     MockIsSystemApp(false);
967 
968     ErrCode res = advancedNotificationService_->SetSmartReminderEnabled("testDeviceType", true);
969     ASSERT_EQ(res, ERR_ANS_NON_SYSTEM_APP);
970 }
971 
972 /*
973  * @tc.name: SetSmartReminderEnabled_0300
974  * @tc.desc: test SetSmartReminderEnabled with parameters, expect errorCode ERR_ANS_PERMISSION_DENIED.
975  * @tc.type: FUNC
976  */
977 HWTEST_F(AnsPublishServiceTest, SetSmartReminderEnabled_0300, TestSize.Level1)
978 {
979     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
980     MockIsSystemApp(true);
981     MockIsVerfyPermisson(false);
982 
983     ErrCode res = advancedNotificationService_->SetSmartReminderEnabled("testDeviceType", true);
984     ASSERT_EQ(res, ERR_ANS_PERMISSION_DENIED);
985 }
986 
987 
988 /**
989  * @tc.name: IsSmartReminderEnabled_0100
990  * @tc.desc: test IsSmartReminderEnabled with parameters
991  * @tc.type: FUNC
992  */
993 HWTEST_F(AnsPublishServiceTest, IsSmartReminderEnabled_0100, TestSize.Level1)
994 {
995     MockIsSystemApp(true);
996     MockIsVerfyPermisson(true);
997     bool enable = true;
998     ErrCode result = advancedNotificationService_->IsSmartReminderEnabled("testDeviceType1111", enable);
999     ASSERT_EQ(result, ERR_OK);
1000 }
1001 
1002 /**
1003  * @tc.name: IsSmartReminderEnabled_0200
1004  * @tc.desc: test IsSmartReminderEnabled with parameters
1005  * @tc.type: FUNC
1006  */
1007 HWTEST_F(AnsPublishServiceTest, IsSmartReminderEnabled_0200, TestSize.Level1)
1008 {
1009     MockIsSystemApp(true);
1010     MockIsVerfyPermisson(true);
1011     ErrCode ret = advancedNotificationService_->SetSmartReminderEnabled("testDeviceType", true);
1012     ASSERT_EQ(ret, ERR_OK);
1013     bool enable = false;
1014     ret = advancedNotificationService_->IsSmartReminderEnabled("testDeviceType", enable);
1015     ASSERT_EQ(ret, ERR_OK);
1016     ASSERT_EQ(enable, true);
1017 }
1018 
1019 /**
1020  * @tc.name: IsSmartReminderEnabled_0300
1021  * @tc.desc: test IsSmartReminderEnabled with parameters, expect errorCode ERR_ANS_NON_SYSTEM_APP.
1022  * @tc.type: FUNC
1023  */
1024 HWTEST_F(AnsPublishServiceTest, IsSmartReminderEnabled_0300, TestSize.Level1)
1025 {
1026     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1027     MockIsSystemApp(false);
1028     bool enable = true;
1029     ErrCode result = advancedNotificationService_->IsSmartReminderEnabled("testDeviceType1111", enable);
1030     ASSERT_EQ(result, ERR_ANS_NON_SYSTEM_APP);
1031 }
1032 
1033 /**
1034  * @tc.name: IsSmartReminderEnabled_0400
1035  * @tc.desc: test IsSmartReminderEnabled with parameters, expect errorCode ERR_ANS_PERMISSION_DENIED.
1036  * @tc.type: FUNC
1037  */
1038 HWTEST_F(AnsPublishServiceTest, IsSmartReminderEnabled_0400, TestSize.Level1)
1039 {
1040     MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP);
1041     MockIsSystemApp(true);
1042     MockIsVerfyPermisson(false);
1043     bool enable = true;
1044     ErrCode result = advancedNotificationService_->IsSmartReminderEnabled("testDeviceType1111", enable);
1045     ASSERT_EQ(result, ERR_ANS_PERMISSION_DENIED);
1046 }
1047 
1048 /**
1049  * @tc.name: PublishRemoveDuplicateEvent_00001
1050  * @tc.desc: Test PublishRemoveDuplicateEvent
1051  * @tc.type: FUNC
1052  * @tc.require: issue
1053  */
1054 HWTEST_F(AnsPublishServiceTest, PublishRemoveDuplicateEvent_00001, Function | SmallTest | Level1)
1055 {
1056     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1057     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1058     request->SetAppMessageId("test2");
1059     request->SetNotificationId(1);
1060     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
1061     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
1062 
1063     auto ret = advancedNotificationService_->PublishRemoveDuplicateEvent(record);
1064     ASSERT_EQ(ret, (int)ERR_OK);
1065 }
1066 
1067 /**
1068  * @tc.name: PublishRemoveDuplicateEvent_00002
1069  * @tc.desc: Test PublishRemoveDuplicateEvent
1070  * @tc.type: FUNC
1071  * @tc.require: issue
1072  */
1073 HWTEST_F(AnsPublishServiceTest, PublishRemoveDuplicateEvent_00002, Function | SmallTest | Level1)
1074 {
1075     std::shared_ptr<NotificationRecord> record= nullptr;
1076     auto ret = advancedNotificationService_->PublishRemoveDuplicateEvent(record);
1077     ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM);
1078 }
1079 
1080 /**
1081  * @tc.name: PublishRemoveDuplicateEvent_00003
1082  * @tc.desc: Test PublishRemoveDuplicateEvent
1083  * @tc.type: FUNC
1084  * @tc.require: issue
1085  */
1086 HWTEST_F(AnsPublishServiceTest, PublishRemoveDuplicateEvent_00003, Function | SmallTest | Level1)
1087 {
1088     sptr<NotificationRequest> request = new (std::nothrow) NotificationRequest();
1089     request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
1090     request->SetAppMessageId("test2");
1091     request->SetNotificationId(1);
1092     request->SetIsAgentNotification(true);
1093     auto normalContent = std::make_shared<NotificationNormalContent>();
1094     auto content = std::make_shared<NotificationContent>(normalContent);
1095     request->SetContent(content);
1096     auto bundle = new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
1097     auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle);
1098 
1099     auto ret = advancedNotificationService_->PublishRemoveDuplicateEvent(record);
1100     ASSERT_EQ(ret, (int)ERR_OK);
1101 }
1102 
1103 /**
1104  * @tc.name: CanPopEnableNotificationDialog_001
1105  * @tc.desc: Test CanPopEnableNotificationDialog
1106  * @tc.type: FUNC
1107  * @tc.require: issue
1108  */
1109 HWTEST_F(AnsPublishServiceTest, CanPopEnableNotificationDialog_001, Function | SmallTest | Level1)
1110 {
1111     sptr<AnsDialogCallback> callback = nullptr;
1112     bool canPop = false;
1113     std::string bundleName = "";
1114     ErrCode result = advancedNotificationService_->CanPopEnableNotificationDialog(callback, canPop, bundleName);
1115     ASSERT_EQ(result, ERROR_INTERNAL_ERROR);
1116 }
1117 
1118 }  // namespace Notification
1119 }  // namespace OHOS
1120