• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <gtest/gtest.h>
17 
18 #include "ans_inner_errors.h"
19 #include "ans_ut_constant.h"
20 #define private public
21 #define protected public
22 #include "notification_preferences.h"
23 #include "advanced_notification_service.h"
24 #undef private
25 #undef protected
26 
27 using namespace testing::ext;
28 namespace OHOS {
29 namespace Notification {
30 class NotificationPreferencesTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {};
TearDownTestCase()33     static void TearDownTestCase()
34     {
35         if (advancedNotificationService_ != nullptr) {
36             advancedNotificationService_->SelfClean();
37         }
38     }
39 
SetUp()40     void SetUp() {};
41     void TearDown();
42 
43     void TestAddNotificationSlot();
44     void TestAddNotificationSlot(NotificationPreferencesInfo &info);
45 
46     static sptr<NotificationBundleOption> bundleOption_;
47     static sptr<NotificationBundleOption> noExsitbundleOption_;
48     static sptr<NotificationBundleOption> bundleEmptyOption_;
49 
50 protected:
51     static sptr<AdvancedNotificationService> advancedNotificationService_;
52 };
53 
54 sptr<NotificationBundleOption> NotificationPreferencesTest::bundleOption_ =
55     new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
56 sptr<NotificationBundleOption> NotificationPreferencesTest::noExsitbundleOption_ =
57     new NotificationBundleOption(std::string("notExsitBundleName"), NON_SYSTEM_APP_UID);
58 sptr<NotificationBundleOption> NotificationPreferencesTest::bundleEmptyOption_ =
59     new NotificationBundleOption(std::string(), NON_SYSTEM_APP_UID);
60 sptr<AdvancedNotificationService> NotificationPreferencesTest::advancedNotificationService_ =
61     AdvancedNotificationService::GetInstance();
62 
TearDown()63 void NotificationPreferencesTest::TearDown()
64 {
65     NotificationPreferences::GetInstance().ClearNotificationInRestoreFactorySettings();
66 }
67 
TestAddNotificationSlot()68 void NotificationPreferencesTest::TestAddNotificationSlot()
69 {
70     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
71     std::vector<sptr<NotificationSlot>> slots;
72     slots.push_back(slot);
73     NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots);
74 }
75 
TestAddNotificationSlot(NotificationPreferencesInfo & info)76 void NotificationPreferencesTest::TestAddNotificationSlot(NotificationPreferencesInfo &info)
77 {
78     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
79     NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info);
80 }
81 
82 /**
83  * @tc.number    : AddNotificationSlots_00100
84  * @tc.name      :
85  * @tc.desc      : Add a notification slot into distrube DB , return is ERR_OK.
86  */
87 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00100, Function | SmallTest | Level1)
88 {
89     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
90     std::vector<sptr<NotificationSlot>> slots;
91     slots.push_back(slot);
92     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
93 }
94 
95 /**
96  * @tc.number    : AddNotificationSlots_00200
97  * @tc.name      :
98  * @tc.desc      : Add a notification slot into distrube DB when bundleName is null, return is ERR_ANS_INVALID_PARAM.
99  */
100 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00200, Function | SmallTest | Level1)
101 {
102     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
103     std::vector<sptr<NotificationSlot>> slots;
104     slots.push_back(slot);
105     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleEmptyOption_, slots),
106         (int)ERR_ANS_INVALID_PARAM);
107 }
108 
109 /**
110  * @tc.number    : AddNotificationSlots_00300
111  * @tc.name      :
112  * @tc.desc      : Add a notification slot into distrube DB when slots is null, return is ERR_ANS_INVALID_PARAM.
113  */
114 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00300, Function | SmallTest | Level1)
115 {
116     std::vector<sptr<NotificationSlot>> slots;
117     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots),
118         (int)ERR_ANS_INVALID_PARAM);
119 }
120 
121 /**
122  * @tc.number    : AddNotificationSlots_00400
123  * @tc.name      :
124  * @tc.desc      : Add a notification slot into distrube DB when slot is nullptr in vector, return is
125  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST.
126  */
127 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00400, Function | SmallTest | Level1)
128 {
129     sptr<NotificationSlot> slot = nullptr;
130     std::vector<sptr<NotificationSlot>> slots;
131     slots.push_back(slot);
132     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots),
133         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST);
134 }
135 
136 /**
137  * @tc.number    : AddNotificationSlots_00500
138  * @tc.name      :
139  * @tc.desc      : Add a notification slot into distrube DB when slots is same, return is ERR_OK.
140  */
141 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | SmallTest | Level1)
142 {
143     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
144     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
145 
146     std::vector<sptr<NotificationSlot>> slots;
147     slots.push_back(slot1);
148     slots.push_back(slot2);
149 
150     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
151 }
152 
153 /**
154  * @tc.number    : AddNotificationSlots_00600
155  * @tc.name      :
156  * @tc.desc      : Add a notification slot into distrube DB , return is ERR_ANS_INVALID_PARAM.
157  */
158 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1)
159 {
160     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
161     std::vector<sptr<NotificationSlot>> slots;
162     slots.push_back(slot);
163     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(nullptr, slots),
164         (int)ERR_ANS_INVALID_PARAM);
165 }
166 
167 
168 
169 /**
170  * @tc.number    : RemoveNotificationSlot_00100
171  * @tc.name      :
172  * @tc.desc      : Remove a notification slot from disturbe DB , return is ERR_OK
173  */
174 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00100, Function | SmallTest | Level1)
175 {
176     TestAddNotificationSlot();
177     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot(
178                   bundleOption_, NotificationConstant::SlotType::OTHER),
179         (int)ERR_OK);
180 }
181 
182 /**
183  * @tc.number    : RemoveNotificationSlot_00200
184  * @tc.name      :
185  * @tc.desc      : Remove a notification slot from disturbe DB when bundle name is null, return is ERR_OK
186  */
187 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00200, Function | SmallTest | Level1)
188 {
189     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot(
190                   bundleEmptyOption_, NotificationConstant::SlotType::OTHER),
191         (int)ERR_ANS_INVALID_PARAM);
192 }
193 
194 /**
195  * @tc.number    : RemoveNotificationSlot_00300
196  * @tc.name      :
197  * @tc.desc      : Remove a notification slot from disturbe DB when bundle name does not exsit, return is
198  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
199  */
200 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00300, Function | SmallTest | Level1)
201 {
202     TestAddNotificationSlot();
203     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot(
204                   noExsitbundleOption_, NotificationConstant::SlotType::OTHER),
205         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
206 }
207 
208 /**
209  * @tc.number    : RemoveNotificationSlot_00400
210  * @tc.name      :
211  * @tc.desc      : Remove a notification slot from disturbe DB when slot type does not exsit, return is
212  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST
213  */
214 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00400, Function | SmallTest | Level1)
215 {
216     TestAddNotificationSlot();
217     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot(
218                   bundleOption_, NotificationConstant::SlotType::SERVICE_REMINDER),
219         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
220 }
221 
222 /**
223  * @tc.number    : RemoveNotificationSlot_00500
224  * @tc.name      :
225  * @tc.desc      : Remove a notification slot from disturbe DB , return is ERR_OK
226  */
227 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | SmallTest | Level1)
228 {
229     TestAddNotificationSlot();
230     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot(
231                   nullptr, NotificationConstant::SlotType::OTHER),
232         (int)ERR_ANS_INVALID_PARAM);
233 }
234 
235 /**
236  * @tc.number    : RemoveNotificationForBundle_00100
237  * @tc.name      :
238  * @tc.desc      : Remove notification for bundle from disturbe DB, return is ERR_OK;
239  */
240 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00100, Function | SmallTest | Level1)
241 {
242     TestAddNotificationSlot();
243     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(bundleOption_), (int)ERR_OK);
244     advancedNotificationService_->OnBundleRemoved(bundleOption_);
245 }
246 
247 /**
248  * @tc.number    : RemoveNotificationForBundle_00200
249  * @tc.name      :
250  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
251  * ERR_ANS_INVALID_PARAM;
252  */
253 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00200, Function | SmallTest | Level1)
254 {
255     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(bundleEmptyOption_),
256         (int)ERR_ANS_INVALID_PARAM);
257 }
258 
259 /**
260  * @tc.number    : RemoveNotificationForBundle_00300
261  * @tc.name      :
262  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
263  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST;
264  */
265 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00300, Function | SmallTest | Level1)
266 {
267     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(noExsitbundleOption_),
268         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
269 }
270 
271 /**
272  * @tc.number    : RemoveNotificationForBundle_00400
273  * @tc.name      :
274  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
275  * ERR_ANS_INVALID_PARAM;
276  */
277 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Function | SmallTest | Level1)
278 {
279     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(nullptr),
280         (int)ERR_ANS_INVALID_PARAM);
281 }
282 
283 /**
284  * @tc.number    : UpdateNotificationSlots_00100
285  * @tc.name      :
286  * @tc.desc      : Update notification slot into disturbe DB, return is ERR_OK
287  */
288 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00100, Function | SmallTest | Level1)
289 {
290     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
291     std::vector<sptr<NotificationSlot>> slots;
292     slots.push_back(slot);
293     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
294     std::string des("This is a description.");
295     slot->SetDescription(des);
296     slots.clear();
297     slots.push_back(slot);
298     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(bundleOption_, slots), (int)ERR_OK);
299 }
300 
301 /**
302  * @tc.number    : UpdateNotificationSlots_00200
303  * @tc.name      :
304  * @tc.desc      : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM
305  */
306 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00200, Function | SmallTest | Level1)
307 {
308     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
309     std::vector<sptr<NotificationSlot>> slots;
310     slots.push_back(slot);
311     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(bundleEmptyOption_, slots),
312         (int)ERR_ANS_INVALID_PARAM);
313 }
314 
315 /**
316  * @tc.number    : UpdateNotificationSlots_00300
317  * @tc.name      :
318  * @tc.desc      : Update notification slot into disturbe DB when slots is null, return is ERR_ANS_INVALID_PARAM
319  */
320 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00300, Function | SmallTest | Level1)
321 {
322     std::vector<sptr<NotificationSlot>> slots;
323     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(bundleOption_, slots),
324         (int)ERR_ANS_INVALID_PARAM);
325 }
326 
327 /**
328  * @tc.number    : UpdateNotificationSlots_00400
329  * @tc.name      :
330  * @tc.desc      : Update notification slot into disturbe DB when bundle does not exsit, return is
331  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
332  */
333 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00400, Function | SmallTest | Level1)
334 {
335     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
336     std::vector<sptr<NotificationSlot>> slots;
337     slots.push_back(slot);
338     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(noExsitbundleOption_, slots),
339         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
340 }
341 
342 /**
343  * @tc.number    : UpdateNotificationSlots_00500
344  * @tc.name      :
345  * @tc.desc      : Update notification slot into disturbe DB when slot type does not exsit, return is
346  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
347  */
348 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | SmallTest | Level1)
349 {
350     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
351     std::vector<sptr<NotificationSlot>> slots;
352     slots.push_back(slot);
353     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(noExsitbundleOption_, slots),
354         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
355 }
356 
357 /**
358  * @tc.number    : UpdateNotificationSlots_00600
359  * @tc.name      :
360  * @tc.desc      : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM
361  */
362 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1)
363 {
364     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
365     std::vector<sptr<NotificationSlot>> slots;
366     slots.push_back(slot);
367     EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(nullptr, slots),
368         (int)ERR_ANS_INVALID_PARAM);
369 }
370 
371 /**
372  * @tc.number    : GetNotificationSlot_00100
373  * @tc.name      :
374  * @tc.desc      : Update notification slot group into disturbe DB, return is ERR_OK
375  */
376 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00100, Function | SmallTest | Level1)
377 {
378     TestAddNotificationSlot();
379     sptr<NotificationSlot> slot;
380     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot(
381                   bundleOption_, NotificationConstant::SlotType::OTHER, slot),
382         (int)ERR_OK);
383 }
384 
385 /**
386  * @tc.number    : GetNotificationSlot_00200
387  * @tc.name      :
388  * @tc.desc      : Update notification slot group into disturbe DB when bundle name is null, return is
389  * ERR_ANS_INVALID_PARAM
390  */
391 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00200, Function | SmallTest | Level1)
392 {
393     sptr<NotificationSlot> slot;
394     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot(
395                   bundleEmptyOption_, NotificationConstant::SlotType::OTHER, slot),
396         (int)ERR_ANS_INVALID_PARAM);
397 }
398 
399 /**
400  * @tc.number    : GetNotificationSlot_00300
401  * @tc.name      :
402  * @tc.desc      : Update notification slot group into disturbe DB when slot type does not exsit, return is
403  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST
404  */
405 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00300, Function | SmallTest | Level1)
406 {
407     TestAddNotificationSlot();
408     sptr<NotificationSlot> slot;
409     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot(
410                   bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, slot),
411         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
412 }
413 
414 /**
415  * @tc.number    : GetNotificationSlot_00400
416  * @tc.name      :
417  * @tc.desc      : Update notification slot group into disturbe DB when bundle name does not exsit, return is
418  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
419  */
420 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | SmallTest | Level1)
421 {
422     TestAddNotificationSlot();
423     sptr<NotificationSlot> slot;
424     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot(
425                   noExsitbundleOption_, NotificationConstant::SlotType::OTHER, slot),
426         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
427 }
428 
429 /**
430  * @tc.number    : GetNotificationSlot_00500
431  * @tc.name      :
432  * @tc.desc      : Update notification slot group into disturbe DB when bundleOption is null, return is
433  * ERR_ANS_INVALID_PARAM
434  */
435 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | SmallTest | Level1)
436 {
437     sptr<NotificationSlot> slot;
438     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot(
439                   nullptr, NotificationConstant::SlotType::OTHER, slot),
440         (int)ERR_ANS_INVALID_PARAM);
441 }
442 
443 /**
444  * @tc.number    : GetNotificationAllSlots_00100
445  * @tc.name      :
446  * @tc.desc      : Get all notification slots from disturbe DB after add a notification slot, return is ERR_OK, get all
447  * notifications size is 1.
448  */
449 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00100, Function | SmallTest | Level1)
450 {
451     TestAddNotificationSlot();
452     std::vector<sptr<NotificationSlot>> slotsResult;
453     EXPECT_EQ(
454         (int)NotificationPreferences::GetInstance().GetNotificationAllSlots(bundleOption_, slotsResult), (int)ERR_OK);
455     EXPECT_EQ((int)slotsResult.size(), 1);
456 }
457 
458 /**
459  * @tc.number    : GetNotificationAllSlots_00200
460  * @tc.name      :
461  * @tc.desc      : Get all notification slots from disturbe DB after add some notification slot, return is ERR_OK, get
462  * all notifications size is the same of adding notifications size.
463  */
464 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00200, Function | SmallTest | Level1)
465 {
466     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
467     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
468     std::vector<sptr<NotificationSlot>> slots;
469     slots.push_back(slot1);
470     slots.push_back(slot2);
471     NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots);
472 
473     std::vector<sptr<NotificationSlot>> slotsResult;
474     EXPECT_EQ(
475         (int)NotificationPreferences::GetInstance().GetNotificationAllSlots(bundleOption_, slotsResult), (int)ERR_OK);
476     EXPECT_EQ((int)slotsResult.size(), 2);
477 }
478 
479 /**
480  * @tc.number    : GetNotificationAllSlots_00300
481  * @tc.name      :
482  * @tc.desc      : Get all notification slots from disturbe DB when bundle name is null, return is
483  * ERR_ANS_INVALID_PARAM
484  */
485 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00300, Function | SmallTest | Level1)
486 {
487     std::vector<sptr<NotificationSlot>> slotsResult;
488     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(bundleEmptyOption_, slotsResult),
489         (int)ERR_ANS_INVALID_PARAM);
490     EXPECT_EQ((int)slotsResult.size(), 0);
491 }
492 
493 /**
494  * @tc.number    : GetNotificationAllSlots_00400
495  * @tc.name      :
496  * @tc.desc      : Get all notification slots from disturbe DB when bundle name does not exsit, return is
497  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
498  */
499 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00400, Function | SmallTest | Level1)
500 {
501     std::vector<sptr<NotificationSlot>> slotsResult;
502     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(noExsitbundleOption_, slotsResult),
503         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
504     EXPECT_EQ((int)slotsResult.size(), 0);
505     ErrCode result = advancedNotificationService_->GetSlots(slotsResult);
506     EXPECT_EQ(result, ERR_OK);
507 }
508 
509 /**
510  * @tc.number    : GetNotificationAllSlots_00500
511  * @tc.name      :
512  * @tc.desc      : Get all notification slots from disturbe DB when bundleOption is null, return is
513  * ERR_ANS_INVALID_PARAM
514  */
515 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00500, Function | SmallTest | Level1)
516 {
517     std::vector<sptr<NotificationSlot>> slotsResult;
518     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(nullptr, slotsResult),
519         (int)ERR_ANS_INVALID_PARAM);
520     EXPECT_EQ((int)slotsResult.size(), 0);
521 }
522 
523 /**
524  * @tc.number    : SetShowBadge_00100
525  * @tc.name      :
526  * @tc.desc      : Set bundle show badge into disturbe DB, return is ERR_OK.
527  */
528 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00100, Function | SmallTest | Level1)
529 {
530     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetShowBadge(bundleOption_, true), (int)ERR_OK);
531 }
532 
533 /**
534  * @tc.number    : SetShowBadge_00200
535  * @tc.name      :
536  * @tc.desc      : Set bundle show badge into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
537  */
538 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00200, Function | SmallTest | Level1)
539 {
540     EXPECT_EQ(
541         (int)NotificationPreferences::GetInstance().SetShowBadge(bundleEmptyOption_, true), (int)ERR_ANS_INVALID_PARAM);
542     auto result = bundleEmptyOption_->GetBundleName();
543     EXPECT_EQ(result, "");
544 }
545 
546 /**
547  * @tc.number    : SetShowBadge_00300
548  * @tc.name      :
549  * @tc.desc      : Set bundle show badge into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
550  */
551 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00300, Function | SmallTest | Level1)
552 {
553     EXPECT_EQ(
554         (int)NotificationPreferences::GetInstance().SetShowBadge(nullptr, true), (int)ERR_ANS_INVALID_PARAM);
555 }
556 
557 /**
558  * @tc.number    : IsShowBadge_00100
559  * @tc.name      :
560  * @tc.desc      : Get bunlde show badge from disturbe DB , return is ERR_OK and show badge is true.
561  */
562 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00100, Function | SmallTest | Level1)
563 {
564     bool enable = false;
565     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetShowBadge(bundleOption_, true), (int)ERR_OK);
566     EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(bundleOption_, enable), (int)ERR_OK);
567     EXPECT_TRUE(enable);
568 }
569 
570 /**
571  * @tc.number    : IsShowBadge_00200
572  * @tc.name      :
573  * @tc.desc      : Get bunlde show badge from disturbe DB when bundle name is null, return is ERR_OK and show badge is
574  * true.
575  */
576 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00200, Function | SmallTest | Level1)
577 {
578     bool enable = false;
579     EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(bundleEmptyOption_, enable),
580         (int)ERR_ANS_INVALID_PARAM);
581 }
582 
583 /**
584  * @tc.number    : IsShowBadge_00300
585  * @tc.name      :
586  * @tc.desc      : Get bunlde show badge from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
587  */
588 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00300, Function | SmallTest | Level1)
589 {
590     bool enable = false;
591     EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(nullptr, enable),
592         (int)ERR_ANS_INVALID_PARAM);
593 }
594 
595 /**
596  * @tc.number    : SetImportance_00100
597  * @tc.name      :
598  * @tc.desc      : Set bundle importance into disturbe DB, return is ERR_OK.
599  */
600 HWTEST_F(NotificationPreferencesTest, SetImportance_00100, Function | SmallTest | Level1)
601 {
602     int importance = 1;
603     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(bundleOption_, importance), (int)ERR_OK);
604 }
605 
606 /**
607  * @tc.number    : SetImportance_00200
608  * @tc.name      :
609  * @tc.desc      : Set bundle importance into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
610  */
611 HWTEST_F(NotificationPreferencesTest, SetImportance_00200, Function | SmallTest | Level1)
612 {
613     int importance = 1;
614     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(bundleEmptyOption_, importance),
615         (int)ERR_ANS_INVALID_PARAM);
616 }
617 
618 /**
619  * @tc.number    : SetImportance_00300
620  * @tc.name      :
621  * @tc.desc      : Set bundle importance into disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
622  */
623 HWTEST_F(NotificationPreferencesTest, SetImportance_00300, Function | SmallTest | Level1)
624 {
625     int importance = 1;
626     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(nullptr, importance),
627         (int)ERR_ANS_INVALID_PARAM);
628 }
629 
630 /**
631  * @tc.number    : GetImportance_00100
632  * @tc.name      :
633  * @tc.desc      : Get bundle importance from disturbe DB, return is ERR_OK.
634  */
635 HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest | Level1)
636 {
637     int importance = 1;
638     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(bundleOption_, importance), (int)ERR_OK);
639     int getImportance = 0;
640 
641     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleOption_, getImportance), (int)ERR_OK);
642     EXPECT_EQ(getImportance, 1);
643 }
644 
645 /**
646  * @tc.number    : GetImportance_00200
647  * @tc.name      :
648  * @tc.desc      : Get bundle importance from disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
649  */
650 HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest | Level1)
651 {
652     int getImportance = 0;
653     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(bundleEmptyOption_, getImportance),
654         (int)ERR_ANS_INVALID_PARAM);
655 }
656 
657 /**
658  * @tc.number    : GetImportance_00300
659  * @tc.name      :
660  * @tc.desc      : Get bundle importance from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
661  */
662 HWTEST_F(NotificationPreferencesTest, GetImportance_00300, Function | SmallTest | Level1)
663 {
664     int getImportance = 0;
665     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(nullptr, getImportance),
666         (int)ERR_ANS_INVALID_PARAM);
667 }
668 
669 /**
670  * @tc.number    : SetTotalBadgeNums_00100
671  * @tc.name      :
672  * @tc.desc      : Set total badge nums into disturbe DB, return is ERR_OK.
673  */
674 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00100, Function | SmallTest | Level1)
675 {
676     int num = 1;
677     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleOption_, num), (int)ERR_OK);
678 }
679 
680 /**
681  * @tc.number    : SetTotalBadgeNums_00200
682  * @tc.name      :
683  * @tc.desc      : Set total badge nums into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
684  */
685 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00200, Function | SmallTest | Level1)
686 {
687     int num = 1;
688     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleEmptyOption_, num),
689         (int)ERR_ANS_INVALID_PARAM);
690 }
691 
692 /**
693  * @tc.number    : SetTotalBadgeNums_00300
694  * @tc.name      :
695  * @tc.desc      : Set total badge nums into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
696  */
697 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00300, Function | SmallTest | Level1)
698 {
699     int num = 1;
700     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetTotalBadgeNums(nullptr, num),
701         (int)ERR_ANS_INVALID_PARAM);
702 }
703 
704 /**
705  * @tc.number    : GetTotalBadgeNums_00100
706  * @tc.name      :
707  * @tc.desc      : Get total badge nums from disturbe DB, return is ERR_OK.
708  */
709 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00100, Function | SmallTest | Level1)
710 {
711     int num = 1;
712     NotificationPreferences::GetInstance().SetTotalBadgeNums(bundleOption_, num);
713     int totalBadgeNum = 0;
714     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(bundleOption_, totalBadgeNum), (int)ERR_OK);
715     EXPECT_EQ(totalBadgeNum, num);
716 }
717 
718 /**
719  * @tc.number    : GetTotalBadgeNums_00200
720  * @tc.name      :
721  * @tc.desc      : Get total badge nums from disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
722  */
723 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallTest | Level1)
724 {
725     int totalBadgeNum = 0;
726     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(bundleEmptyOption_, totalBadgeNum),
727         (int)ERR_ANS_INVALID_PARAM);
728 }
729 
730 /**
731  * @tc.number    : GetTotalBadgeNums_00300
732  * @tc.name      :
733  * @tc.desc      : Get total badge nums from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
734  */
735 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00300, Function | SmallTest | Level1)
736 {
737     int totalBadgeNum = 0;
738     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(nullptr, totalBadgeNum),
739         (int)ERR_ANS_INVALID_PARAM);
740 }
741 
742 /**
743  * @tc.number    : SetNotificationsEnabledForBundle_00100
744  * @tc.name      :
745  * @tc.desc      : Set notification enable for bundle into disturbe DB, return is ERR_OK.
746  */
747 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1)
748 {
749     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleOption_, false),
750         (int)ERR_OK);
751 }
752 
753 /**
754  * @tc.number    : SetNotificationsEnabledForBundle_00200
755  * @tc.name      :
756  * @tc.desc      : Set notification enable for bundle into disturbe DB when bundle name is null, return is
757  * ERR_ANS_INVALID_PARAM.
758  */
759 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1)
760 {
761     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleEmptyOption_, false),
762         (int)ERR_ANS_INVALID_PARAM);
763 }
764 
765 /**
766  * @tc.number    : SetNotificationsEnabledForBundle_00300
767  * @tc.name      :
768  * @tc.desc      : Set notification enable for bundle into disturbe DB when bundleOption is null, return is
769  * ERR_ANS_INVALID_PARAM.
770  */
771 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1)
772 {
773     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(nullptr, false),
774         (int)ERR_ANS_INVALID_PARAM);
775 }
776 
777 /**
778  * @tc.number    : GetNotificationsEnabledForBundle_00100
779  * @tc.name      :
780  * @tc.desc      : Get notification enable for bundle from disturbe DB, return is ERR_OK.
781  */
782 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1)
783 {
784     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleOption_, false),
785         (int)ERR_OK);
786     bool enabled = false;
787     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleOption_, enabled),
788         (int)ERR_OK);
789     EXPECT_FALSE(enabled);
790 }
791 
792 /**
793  * @tc.number    : GetNotificationsEnabledForBundle_00200
794  * @tc.name      :
795  * @tc.desc      : Get notification enable for bundle from disturbe DB when bundle name is null, return is
796  * ERR_ANS_INVALID_PARAM.
797  */
798 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1)
799 {
800     bool enabled = false;
801     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleEmptyOption_, enabled),
802         (int)ERR_ANS_INVALID_PARAM);
803 }
804 
805 /**
806  * @tc.number    : GetNotificationsEnabledForBundle_00300
807  * @tc.name      :
808  * @tc.desc      : Get notification enable for bundle from disturbe DB when bundleOption is null, return is
809  * ERR_ANS_INVALID_PARAM.
810  */
811 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1)
812 {
813     bool enabled = false;
814     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(nullptr, enabled),
815         (int)ERR_ANS_INVALID_PARAM);
816 }
817 
818 /**
819  * @tc.number    : SetNotificationsEnabled_00100
820  * @tc.name      :
821  * @tc.desc      : Set enable notification into disturbe DB, return is ERR_OK
822  */
823 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00100, Function | SmallTest | Level1)
824 {
825     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK);
826 }
827 
828 /**
829  * @tc.number    : SetNotificationsEnabled_00200
830  * @tc.name      :
831  * @tc.desc      : Set enable notification into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
832  */
833 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00200, Function | SmallTest | Level1)
834 {
835     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, true),
836         (int)ERR_ANS_INVALID_PARAM);
837 }
838 
839 /**
840  * @tc.number    : GetNotificationsEnabled_00100
841  * @tc.name      :
842  * @tc.desc      : Get enable notification from disturbe DB, return is ERR_OK
843  */
844 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | SmallTest | Level1)
845 {
846     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK);
847     bool enable = false;
848     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK);
849     EXPECT_TRUE(enable);
850 }
851 
852 /**
853  * @tc.number    : GetNotificationsEnabled_00200
854  * @tc.name      :
855  * @tc.desc      : Same user can get enable setting, different user can not get.
856  */
857 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1)
858 {
859     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK);
860     bool enable = false;
861     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK);
862     EXPECT_TRUE(enable);
863 
864     enable = false;
865     EXPECT_EQ(
866         (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM);
867     EXPECT_FALSE(enable);
868 }
869 
870 /**
871  * @tc.number    : GetNotificationsEnabled_00300
872  * @tc.name      :
873  * @tc.desc      : Get enable notification from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
874  */
875 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00300, Function | SmallTest | Level1)
876 {
877     bool enable = false;
878     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, enable),
879         (int)ERR_ANS_INVALID_PARAM);
880 }
881 
882 /**
883  * @tc.number    : SetDoNotDisturbDate_00100
884  * @tc.name      :
885  * @tc.desc      : Set disturbe mode into disturbe DB, return is ERR_OK
886  */
887 HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | SmallTest | Level1)
888 {
889     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
890     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
891     int64_t beginDate = beginDuration.count();
892     timePoint += std::chrono::hours(1);
893     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
894     int64_t endDate = endDuration.count();
895     sptr<NotificationDoNotDisturbDate> date =
896         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
897 
898     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
899 }
900 
901 /**
902  * @tc.number    : SetDoNotDisturbDate_00200
903  * @tc.name      :
904  * @tc.desc      : Set disturbe mode into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
905  */
906 HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00200, Function | SmallTest | Level1)
907 {
908     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
909     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
910     int64_t beginDate = beginDuration.count();
911     timePoint += std::chrono::hours(1);
912     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
913     int64_t endDate = endDuration.count();
914     sptr<NotificationDoNotDisturbDate> date =
915         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
916 
917     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, date),
918         (int)ERR_ANS_INVALID_PARAM);
919 }
920 
921 /**
922  * @tc.number    : GetDoNotDisturbDate_00100
923  * @tc.name      :
924  * @tc.desc      : Get disturbe mode from disturbe DB, return is ERR_OK
925  */
926 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | SmallTest | Level1)
927 {
928     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
929     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
930     int64_t beginDate = beginDuration.count();
931     timePoint += std::chrono::hours(1);
932     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
933     int64_t endDate = endDuration.count();
934     sptr<NotificationDoNotDisturbDate> date =
935         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
936     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
937 
938     sptr<NotificationDoNotDisturbDate> getDate;
939     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(SYSTEM_APP_UID, getDate), (int)ERR_OK);
940     EXPECT_EQ(getDate->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY);
941     EXPECT_EQ(getDate->GetBeginDate(), beginDate);
942     EXPECT_EQ(getDate->GetEndDate(), endDate);
943 }
944 
945 /**
946  * @tc.number    : GetDoNotDisturbDate_00200
947  * @tc.name      :
948  * @tc.desc      : Same user can get DoNotDisturbDate setting, different user can not get.
949  */
950 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00200, Function | SmallTest | Level1)
951 {
952     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
953     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
954     int64_t beginDate = beginDuration.count();
955     timePoint += std::chrono::hours(1);
956     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
957     int64_t endDate = endDuration.count();
958     sptr<NotificationDoNotDisturbDate> date =
959         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
960     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
961 
962     sptr<NotificationDoNotDisturbDate> getDate;
963     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(SYSTEM_APP_UID, getDate), (int)ERR_OK);
964     EXPECT_EQ(getDate->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY);
965     EXPECT_EQ(getDate->GetBeginDate(), beginDate);
966     EXPECT_EQ(getDate->GetEndDate(), endDate);
967 
968     sptr<NotificationDoNotDisturbDate> getExsitDate;
969     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(
970         NON_SYSTEM_APP_UID, getExsitDate), (int)ERR_ANS_INVALID_PARAM);
971 }
972 
973 /**
974  * @tc.number    : GetDoNotDisturbDate_00300
975  * @tc.name      :
976  * @tc.desc      : Get disturbe mode from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
977  */
978 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00300, Function | SmallTest | Level1)
979 {
980     sptr<NotificationDoNotDisturbDate> getDate;
981     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, getDate),
982         (int)ERR_ANS_INVALID_PARAM);
983 }
984 
985 /**
986  * @tc.number    : SetHasPoppedDialog_00100
987  * @tc.name      :
988  * @tc.desc      : Set has popped dialog into disturbe DB, return is ERR_OK
989  */
990 HWTEST_F(NotificationPreferencesTest, SetHasPoppedDialog_00100, Function | SmallTest | Level1)
991 {
992     bool hasPopped = false;
993 
994     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetHasPoppedDialog(bundleOption_, hasPopped), (int)ERR_OK);
995 }
996 
997 /**
998  * @tc.number    : GetHasPoppedDialog_00100
999  * @tc.name      :
1000  * @tc.desc      : Get has popped dialog from disturbe DB, return is ERR_OK
1001  */
1002 HWTEST_F(NotificationPreferencesTest, GetHasPoppedDialog_00100, Function | SmallTest | Level1)
1003 {
1004     bool popped = true;
1005 
1006     EXPECT_EQ((int)NotificationPreferences::GetInstance().SetHasPoppedDialog(bundleOption_, popped), (int)ERR_OK);
1007 
1008     bool hasPopped = false;
1009     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetHasPoppedDialog(bundleOption_, hasPopped), (int)ERR_OK);
1010     EXPECT_TRUE(hasPopped);
1011 }
1012 
1013 /**
1014  * @tc.number    : AddNotificationBundleProperty_00100
1015  * @tc.name      : AddNotificationBundleProperty
1016  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundleOption is null,
1017  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED.
1018  * @tc.require   : issueI5SR8J
1019  */
1020 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00100, Function | SmallTest | Level1)
1021 {
1022     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(bundleOption_),
1023         (int)ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1024 }
1025 
1026 /**
1027  * @tc.number    : AddNotificationBundleProperty_00200
1028  * @tc.name      : AddNotificationBundleProperty
1029  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundlename is null,
1030  *                 return is ERR_ANS_INVALID_PARAM.
1031  * @tc.require   : issueI5SR8J
1032  */
1033 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00200, Function | SmallTest | Level1)
1034 {
1035     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(bundleEmptyOption_),
1036         (int)ERR_ANS_INVALID_PARAM);
1037 }
1038 
1039 /**
1040  * @tc.number    : AddNotificationBundleProperty_00300
1041  * @tc.name      : AddNotificationBundleProperty
1042  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundlename is null,
1043  *                 return is ERR_ANS_INVALID_PARAM.
1044  * @tc.require   : issueI5SR8J
1045  */
1046 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00300, Function | SmallTest | Level1)
1047 {
1048     EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(nullptr),
1049         (int)ERR_ANS_INVALID_PARAM);
1050 }
1051 
1052 /**
1053  * @tc.number    : RemoveNotificationAllSlots_00100
1054  * @tc.name      : RemoveNotificationAllSlots
1055  * @tc.desc      : Test RemoveNotificationAllSlots function when bundlename is null,
1056  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1057  * @tc.require   : issueI5SR8J
1058  */
1059 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00100, Function | SmallTest | Level1)
1060 {
1061     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(bundleOption_),
1062         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1063 }
1064 
1065 /**
1066  * @tc.number    : RemoveNotificationAllSlots_00200
1067  * @tc.name      : RemoveNotificationAllSlots
1068  * @tc.desc      : Test RemoveNotificationAllSlots function when bundleOption is null,
1069  *                 return is ERR_ANS_INVALID_PARAM.
1070  * @tc.require   : issueI5SR8J
1071  */
1072 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00200, Function | SmallTest | Level1)
1073 {
1074     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(bundleEmptyOption_),
1075         (int)ERR_ANS_INVALID_PARAM);
1076 }
1077 
1078 /**
1079  * @tc.number    : RemoveNotificationAllSlots_00300
1080  * @tc.name      : RemoveNotificationAllSlots
1081  * @tc.desc      : Test RemoveNotificationAllSlots function when bundleOption is null,
1082  *                 return is ERR_ANS_INVALID_PARAM.
1083  * @tc.require   : issueI5SR8J
1084  */
1085 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00300, Function | SmallTest | Level1)
1086 {
1087     EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(nullptr),
1088         (int)ERR_ANS_INVALID_PARAM);
1089 }
1090 
1091 /**
1092  * @tc.number    : GetNotificationSlotsNumForBundle_00100
1093  * @tc.name      : GetNotificationSlotsNumForBundle
1094  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundlename is null,
1095  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1096  * @tc.require   : issueI5SR8J
1097  */
1098 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00100, Function | SmallTest | Level1)
1099 {
1100     uint64_t num = 1;
1101     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundleOption_, num),
1102         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1103 }
1104 
1105 /**
1106  * @tc.number    : GetNotificationSlotsNumForBundle_00200
1107  * @tc.name      : GetNotificationSlotsNumForBundle
1108  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundleOption is null,
1109  *                 return is ERR_ANS_INVALID_PARAM.
1110  * @tc.require   : issueI5SR8J
1111  */
1112 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00200, Function | SmallTest | Level1)
1113 {
1114     uint64_t num = 2;
1115     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundleEmptyOption_, num),
1116         (int)ERR_ANS_INVALID_PARAM);
1117 }
1118 
1119 /**
1120  * @tc.number    : GetNotificationSlotsNumForBundle_00300
1121  * @tc.name      : GetNotificationSlotsNumForBundle
1122  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundleOption is null,
1123  *                 return is ERR_ANS_INVALID_PARAM.
1124  * @tc.require   : issueI5SR8J
1125  */
1126 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Function | SmallTest | Level1)
1127 {
1128     uint64_t num = 2;
1129     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(nullptr, num),
1130         (int)ERR_ANS_INVALID_PARAM);
1131 }
1132 
1133 /**
1134  * @tc.number    : CheckSlotForCreateSlot_00100
1135  * @tc.name      : CheckSlotForCreateSlot
1136  * @tc.desc      : Test CheckSlotForCreateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM.
1137  * @tc.require   : issueI5SR8J
1138  */
1139 HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1)
1140 {
1141     NotificationPreferencesInfo info;
1142     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1143     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info),
1144         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST);
1145 }
1146 
1147 /**
1148  * @tc.number    : CheckSlotForCreateSlot_00200
1149  * @tc.name      : CheckSlotForCreateSlot
1150  * @tc.desc      : Test CheckSlotForCreateSlot function, return ERR_OK.
1151  * @tc.require   : issueI5SR8J
1152  */
1153 HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1)
1154 {
1155     NotificationPreferencesInfo info;
1156     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1157     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info),
1158         (int)ERR_OK);
1159 }
1160 
1161 /**
1162  * @tc.number    : CheckSlotForRemoveSlot_00100
1163  * @tc.name      : CheckSlotForRemoveSlot
1164  * @tc.desc      : Test CheckSlotForRemoveSlot function after add a notification slot,
1165  * return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1166  * @tc.require   : issueI5SR8J
1167  */
1168 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1)
1169 {
1170     NotificationPreferencesInfo info;
1171     TestAddNotificationSlot(info);
1172     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot(
1173         bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_OK);
1174 }
1175 
1176 /**
1177  * @tc.number    : CheckSlotForRemoveSlot_00200
1178  * @tc.name      : CheckSlotForRemoveSlot
1179  * @tc.desc      : Test CheckSlotForRemoveSlot function, return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST,
1180  * @tc.require   : issueI5SR8J
1181  */
1182 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1)
1183 {
1184     NotificationPreferencesInfo info;
1185     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot(
1186         bundleOption_, NotificationConstant::SlotType::OTHER, info),
1187         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1188 }
1189 
1190 /**
1191  * @tc.number    : CheckSlotForRemoveSlot_00300
1192  * @tc.name      : CheckSlotForRemoveSlot
1193  * @tc.desc      : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK.
1194  * @tc.require   : issueI5SR8J
1195  */
1196 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1)
1197 {
1198     NotificationPreferencesInfo info;
1199     TestAddNotificationSlot(info);
1200     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot(
1201         bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info),
1202         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
1203 }
1204 
1205 /**
1206  * @tc.number    : CheckSlotForUpdateSlot_00100
1207  * @tc.name      : CheckSlotForUpdateSlot
1208  * @tc.desc      : Test CheckSlotForUpdateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM.
1209  * @tc.require   : issueI5SR8J
1210  */
1211 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1)
1212 {
1213     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1214     NotificationPreferencesInfo info;
1215     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info),
1216         (int)ERR_ANS_INVALID_PARAM);
1217 }
1218 
1219 /**
1220  * @tc.number    : CheckSlotForUpdateSlot_00200
1221  * @tc.name      : CheckSlotForUpdateSlot
1222  * @tc.desc      : Test CheckSlotForUpdateSlot function when bundle not existed, return is
1223  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1224  * @tc.require   : issueI5SR8J
1225  */
1226 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1)
1227 {
1228     NotificationPreferencesInfo info;
1229     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1230     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info),
1231         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1232 }
1233 
1234 /**
1235  * @tc.number    : CheckSlotForUpdateSlot_00300
1236  * @tc.name      : CheckSlotForUpdateSlot
1237  * @tc.desc      : Test CheckSlotForUpdateSlot function when slot is different type, return is
1238  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST.
1239  * @tc.require   : issueI5SR8J
1240  */
1241 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1)
1242 {
1243     NotificationPreferencesInfo info;
1244     TestAddNotificationSlot(info);
1245     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1246     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info),
1247         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
1248 }
1249 
1250 /**
1251  * @tc.number    : CheckSlotForUpdateSlot_00400
1252  * @tc.name      : CheckSlotForUpdateSlot
1253  * @tc.desc      : Test CheckSlotForUpdateSlot function after add notification slot, return is ERR_OK.
1254  * @tc.require   : issueI5SR8J
1255  */
1256 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1)
1257 {
1258     NotificationPreferencesInfo info;
1259     TestAddNotificationSlot(info);
1260     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1261     EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info),
1262         (int)ERR_OK);
1263 }
1264 
1265 /**
1266  * @tc.number    : GetTemplateSupported_00100
1267  * @tc.name      : GetTemplateSupported
1268  * @tc.desc      : Test GetTemplateSupported function
1269  * @tc.require   : issueI5SR8J
1270  */
1271 HWTEST_F(NotificationPreferencesTest, GetTemplateSupported_00100, Function | SmallTest | Level1)
1272 {
1273     NotificationPreferences::GetInstance().OnDistributedKvStoreDeathRecipient();
1274     std::string templateName = "";
1275     bool support = true;
1276     EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTemplateSupported(templateName, support),
1277         (int)ERR_ANS_INVALID_PARAM);
1278 }
1279 }  // namespace Notification
1280 }  // namespace OHOS
1281