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