• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "notification_preferences_database.h"
24 #include "advanced_notification_service.h"
25 #undef private
26 #undef protected
27 
28 using namespace testing::ext;
29 namespace OHOS {
30 namespace Notification {
31 extern void MockIsVerfyPermisson(bool isVerify);
32 
33 class NotificationPreferencesTest : public testing::Test {
34 public:
SetUpTestCase()35     static void SetUpTestCase() {};
TearDownTestCase()36     static void TearDownTestCase()
37     {
38         if (advancedNotificationService_ != nullptr) {
39             advancedNotificationService_->SelfClean();
40         }
41     }
42 
SetUp()43     void SetUp() {};
44     void TearDown();
45 
46     void TestAddNotificationSlot();
47     void TestAddNotificationSlot(NotificationPreferencesInfo &info);
48 
49     static sptr<NotificationBundleOption> bundleOption_;
50     static sptr<NotificationBundleOption> noExsitbundleOption_;
51     static sptr<NotificationBundleOption> bundleEmptyOption_;
52 
53 protected:
54     static sptr<AdvancedNotificationService> advancedNotificationService_;
55 };
56 
57 sptr<NotificationBundleOption> NotificationPreferencesTest::bundleOption_ =
58     new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID);
59 sptr<NotificationBundleOption> NotificationPreferencesTest::noExsitbundleOption_ =
60     new NotificationBundleOption(std::string("notExsitBundleName"), NON_SYSTEM_APP_UID);
61 sptr<NotificationBundleOption> NotificationPreferencesTest::bundleEmptyOption_ =
62     new NotificationBundleOption(std::string(), NON_SYSTEM_APP_UID);
63 sptr<AdvancedNotificationService> NotificationPreferencesTest::advancedNotificationService_ =
64     AdvancedNotificationService::GetInstance();
65 
TearDown()66 void NotificationPreferencesTest::TearDown()
67 {
68     NotificationPreferences::GetInstance()->ClearNotificationInRestoreFactorySettings();
69 }
70 
TestAddNotificationSlot()71 void NotificationPreferencesTest::TestAddNotificationSlot()
72 {
73     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
74     std::vector<sptr<NotificationSlot>> slots;
75     slots.push_back(slot);
76     NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots);
77 }
78 
TestAddNotificationSlot(NotificationPreferencesInfo & info)79 void NotificationPreferencesTest::TestAddNotificationSlot(NotificationPreferencesInfo &info)
80 {
81     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
82     NotificationPreferences::GetInstance()->CheckSlotForCreateSlot(bundleOption_, slot, info);
83 }
84 
85 /**
86  * @tc.number    : AddNotificationSlots_00100
87  * @tc.name      :
88  * @tc.desc      : Add a notification slot into distrube DB , return is ERR_OK.
89  */
90 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00100, Function | SmallTest | Level1)
91 {
92     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
93     std::vector<sptr<NotificationSlot>> slots;
94     slots.push_back(slot);
95     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
96 }
97 
98 /**
99  * @tc.number    : AddNotificationSlots_00200
100  * @tc.name      :
101  * @tc.desc      : Add a notification slot into distrube DB when bundleName is null, return is ERR_ANS_INVALID_PARAM.
102  */
103 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00200, Function | SmallTest | Level1)
104 {
105     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
106     std::vector<sptr<NotificationSlot>> slots;
107     slots.push_back(slot);
108     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleEmptyOption_, slots),
109         (int)ERR_ANS_INVALID_PARAM);
110 }
111 
112 /**
113  * @tc.number    : AddNotificationSlots_00300
114  * @tc.name      :
115  * @tc.desc      : Add a notification slot into distrube DB when slots is null, return is ERR_ANS_INVALID_PARAM.
116  */
117 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00300, Function | SmallTest | Level1)
118 {
119     std::vector<sptr<NotificationSlot>> slots;
120     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots),
121         (int)ERR_ANS_INVALID_PARAM);
122 }
123 
124 /**
125  * @tc.number    : AddNotificationSlots_00400
126  * @tc.name      :
127  * @tc.desc      : Add a notification slot into distrube DB when slot is nullptr in vector, return is
128  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST.
129  */
130 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00400, Function | SmallTest | Level1)
131 {
132     sptr<NotificationSlot> slot = nullptr;
133     std::vector<sptr<NotificationSlot>> slots;
134     slots.push_back(slot);
135     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots),
136         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST);
137 }
138 
139 /**
140  * @tc.number    : AddNotificationSlots_00500
141  * @tc.name      :
142  * @tc.desc      : Add a notification slot into distrube DB when slots is same, return is ERR_OK.
143  */
144 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | SmallTest | Level1)
145 {
146     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
147     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
148 
149     std::vector<sptr<NotificationSlot>> slots;
150     slots.push_back(slot1);
151     slots.push_back(slot2);
152 
153     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
154 }
155 
156 /**
157  * @tc.number    : AddNotificationSlots_00600
158  * @tc.name      :
159  * @tc.desc      : Add a notification slot into distrube DB , return is ERR_ANS_INVALID_PARAM.
160  */
161 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1)
162 {
163     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
164     std::vector<sptr<NotificationSlot>> slots;
165     slots.push_back(slot);
166     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(nullptr, slots),
167         (int)ERR_ANS_INVALID_PARAM);
168 }
169 
170 /**
171  * @tc.number    : RemoveNotificationSlot_00100
172  * @tc.name      :
173  * @tc.desc      : Remove a notification slot from disturbe DB , return is ERR_OK
174  */
175 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00100, Function | SmallTest | Level1)
176 {
177     TestAddNotificationSlot();
178     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationSlot(
179                   bundleOption_, NotificationConstant::SlotType::OTHER),
180         (int)ERR_OK);
181 }
182 
183 /**
184  * @tc.number    : RemoveNotificationSlot_00200
185  * @tc.name      :
186  * @tc.desc      : Remove a notification slot from disturbe DB when bundle name is null, return is ERR_OK
187  */
188 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00200, Function | SmallTest | Level1)
189 {
190     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationSlot(
191                   bundleEmptyOption_, NotificationConstant::SlotType::OTHER),
192         (int)ERR_ANS_INVALID_PARAM);
193 }
194 
195 /**
196  * @tc.number    : RemoveNotificationSlot_00300
197  * @tc.name      :
198  * @tc.desc      : Remove a notification slot from disturbe DB when bundle name does not exsit, return is
199  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
200  */
201 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00300, Function | SmallTest | Level1)
202 {
203     TestAddNotificationSlot();
204     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationSlot(
205                   noExsitbundleOption_, NotificationConstant::SlotType::OTHER),
206         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
207 }
208 
209 /**
210  * @tc.number    : RemoveNotificationSlot_00400
211  * @tc.name      :
212  * @tc.desc      : Remove a notification slot from disturbe DB when slot type does not exsit, return is
213  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST
214  */
215 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00400, Function | SmallTest | Level1)
216 {
217     TestAddNotificationSlot();
218     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationSlot(
219                   bundleOption_, NotificationConstant::SlotType::SERVICE_REMINDER),
220         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
221 }
222 
223 /**
224  * @tc.number    : RemoveNotificationSlot_00500
225  * @tc.name      :
226  * @tc.desc      : Remove a notification slot from disturbe DB , return is ERR_OK
227  */
228 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | SmallTest | Level1)
229 {
230     TestAddNotificationSlot();
231     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationSlot(
232                   nullptr, NotificationConstant::SlotType::OTHER),
233         (int)ERR_ANS_INVALID_PARAM);
234 }
235 
236 /**
237  * @tc.number    : RemoveNotificationForBundle_00100
238  * @tc.name      :
239  * @tc.desc      : Remove notification for bundle from disturbe DB, return is ERR_OK;
240  */
241 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00100, Function | SmallTest | Level1)
242 {
243     TestAddNotificationSlot();
244     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationForBundle(bundleOption_), (int)ERR_OK);
245     advancedNotificationService_->OnBundleRemoved(bundleOption_);
246 }
247 
248 /**
249  * @tc.number    : RemoveNotificationForBundle_00200
250  * @tc.name      :
251  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
252  * ERR_ANS_INVALID_PARAM;
253  */
254 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00200, Function | SmallTest | Level1)
255 {
256     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationForBundle(bundleEmptyOption_),
257         (int)ERR_ANS_INVALID_PARAM);
258 }
259 
260 /**
261  * @tc.number    : RemoveNotificationForBundle_00300
262  * @tc.name      :
263  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
264  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST;
265  */
266 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00300, Function | SmallTest | Level1)
267 {
268     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationForBundle(noExsitbundleOption_),
269         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
270 }
271 
272 /**
273  * @tc.number    : RemoveNotificationForBundle_00400
274  * @tc.name      :
275  * @tc.desc      :  Remove notification for bundle from disturbe DB when bundle name is null, return is
276  * ERR_ANS_INVALID_PARAM;
277  */
278 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Function | SmallTest | Level1)
279 {
280     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationForBundle(nullptr),
281         (int)ERR_ANS_INVALID_PARAM);
282 }
283 
284 /**
285  * @tc.number    : UpdateNotificationSlots_00100
286  * @tc.name      :
287  * @tc.desc      : Update notification slot into disturbe DB, return is ERR_OK
288  */
289 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00100, Function | SmallTest | Level1)
290 {
291     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
292     std::vector<sptr<NotificationSlot>> slots;
293     slots.push_back(slot);
294     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots), (int)ERR_OK);
295     std::string des("This is a description.");
296     slot->SetDescription(des);
297     slots.clear();
298     slots.push_back(slot);
299     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(bundleOption_, slots), (int)ERR_OK);
300 }
301 
302 /**
303  * @tc.number    : UpdateNotificationSlots_00200
304  * @tc.name      :
305  * @tc.desc      : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM
306  */
307 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00200, Function | SmallTest | Level1)
308 {
309     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
310     std::vector<sptr<NotificationSlot>> slots;
311     slots.push_back(slot);
312     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(bundleEmptyOption_, slots),
313         (int)ERR_ANS_INVALID_PARAM);
314 }
315 
316 /**
317  * @tc.number    : UpdateNotificationSlots_00300
318  * @tc.name      :
319  * @tc.desc      : Update notification slot into disturbe DB when slots is null, return is ERR_ANS_INVALID_PARAM
320  */
321 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00300, Function | SmallTest | Level1)
322 {
323     std::vector<sptr<NotificationSlot>> slots;
324     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(bundleOption_, slots),
325         (int)ERR_ANS_INVALID_PARAM);
326 }
327 
328 /**
329  * @tc.number    : UpdateNotificationSlots_00400
330  * @tc.name      :
331  * @tc.desc      : Update notification slot into disturbe DB when bundle does not exsit, return is
332  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
333  */
334 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00400, Function | SmallTest | Level1)
335 {
336     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
337     std::vector<sptr<NotificationSlot>> slots;
338     slots.push_back(slot);
339     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(noExsitbundleOption_, slots),
340         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
341 }
342 
343 /**
344  * @tc.number    : UpdateNotificationSlots_00500
345  * @tc.name      :
346  * @tc.desc      : Update notification slot into disturbe DB when slot type does not exsit, return is
347  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
348  */
349 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, 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     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(noExsitbundleOption_, slots),
355         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
356 }
357 
358 /**
359  * @tc.number    : UpdateNotificationSlots_00600
360  * @tc.name      :
361  * @tc.desc      : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM
362  */
363 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1)
364 {
365     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
366     std::vector<sptr<NotificationSlot>> slots;
367     slots.push_back(slot);
368     ASSERT_EQ((int)NotificationPreferences::GetInstance()->UpdateNotificationSlots(nullptr, slots),
369         (int)ERR_ANS_INVALID_PARAM);
370 }
371 
372 /**
373  * @tc.number    : GetNotificationSlot_00100
374  * @tc.name      :
375  * @tc.desc      : Update notification slot group into disturbe DB, return is ERR_OK
376  */
377 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00100, Function | SmallTest | Level1)
378 {
379     TestAddNotificationSlot();
380     sptr<NotificationSlot> slot;
381     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlot(
382                   bundleOption_, NotificationConstant::SlotType::OTHER, slot),
383         (int)ERR_OK);
384 }
385 
386 /**
387  * @tc.number    : GetNotificationSlot_00200
388  * @tc.name      :
389  * @tc.desc      : Update notification slot group into disturbe DB when bundle name is null, return is
390  * ERR_ANS_INVALID_PARAM
391  */
392 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00200, Function | SmallTest | Level1)
393 {
394     sptr<NotificationSlot> slot;
395     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlot(
396                   bundleEmptyOption_, NotificationConstant::SlotType::OTHER, slot),
397         (int)ERR_ANS_INVALID_PARAM);
398 }
399 
400 /**
401  * @tc.number    : GetNotificationSlot_00300
402  * @tc.name      :
403  * @tc.desc      : Update notification slot group into disturbe DB when slot type does not exsit, return is
404  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST
405  */
406 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00300, Function | SmallTest | Level1)
407 {
408     TestAddNotificationSlot();
409     sptr<NotificationSlot> slot;
410     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlot(
411                   bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, slot),
412         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
413 }
414 
415 /**
416  * @tc.number    : GetNotificationSlot_00400
417  * @tc.name      :
418  * @tc.desc      : Update notification slot group into disturbe DB when bundle name does not exsit, return is
419  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST
420  */
421 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | SmallTest | Level1)
422 {
423     TestAddNotificationSlot();
424     sptr<NotificationSlot> slot;
425     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlot(
426                   noExsitbundleOption_, NotificationConstant::SlotType::OTHER, slot),
427         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
428 }
429 
430 /**
431  * @tc.number    : GetNotificationSlot_00500
432  * @tc.name      :
433  * @tc.desc      : Update notification slot group into disturbe DB when bundleOption is null, return is
434  * ERR_ANS_INVALID_PARAM
435  */
436 HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | SmallTest | Level1)
437 {
438     sptr<NotificationSlot> slot;
439     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlot(
440                   nullptr, NotificationConstant::SlotType::OTHER, slot),
441         (int)ERR_ANS_INVALID_PARAM);
442 }
443 
444 /**
445  * @tc.number    : GetNotificationAllSlots_00100
446  * @tc.name      :
447  * @tc.desc      : Get all notification slots from disturbe DB after add a notification slot, return is ERR_OK, get all
448  * notifications size is 1.
449  */
450 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00100, Function | SmallTest | Level1)
451 {
452     TestAddNotificationSlot();
453     std::vector<sptr<NotificationSlot>> slotsResult;
454     ASSERT_EQ(
455         (int)NotificationPreferences::GetInstance()->GetNotificationAllSlots(bundleOption_, slotsResult), (int)ERR_OK);
456     ASSERT_EQ((int)slotsResult.size(), 1);
457 }
458 
459 /**
460  * @tc.number    : GetNotificationAllSlots_00200
461  * @tc.name      :
462  * @tc.desc      : Get all notification slots from disturbe DB after add some notification slot, return is ERR_OK, get
463  * all notifications size is the same of adding notifications size.
464  */
465 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00200, Function | SmallTest | Level1)
466 {
467     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
468     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
469     std::vector<sptr<NotificationSlot>> slots;
470     slots.push_back(slot1);
471     slots.push_back(slot2);
472     NotificationPreferences::GetInstance()->AddNotificationSlots(bundleOption_, slots);
473 
474     std::vector<sptr<NotificationSlot>> slotsResult;
475     ASSERT_EQ(
476         (int)NotificationPreferences::GetInstance()->GetNotificationAllSlots(bundleOption_, slotsResult), (int)ERR_OK);
477     ASSERT_EQ((int)slotsResult.size(), 2);
478 }
479 
480 /**
481  * @tc.number    : GetNotificationAllSlots_00300
482  * @tc.name      :
483  * @tc.desc      : Get all notification slots from disturbe DB when bundle name is null, return is
484  * ERR_ANS_INVALID_PARAM
485  */
486 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00300, Function | SmallTest | Level1)
487 {
488     std::vector<sptr<NotificationSlot>> slotsResult;
489     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationAllSlots(bundleEmptyOption_, slotsResult),
490         (int)ERR_ANS_INVALID_PARAM);
491     ASSERT_EQ((int)slotsResult.size(), 0);
492 }
493 
494 /**
495  * @tc.number    : GetNotificationAllSlots_00400
496  * @tc.name      :
497  * @tc.desc      : Get all notification slots from disturbe DB when bundle name does not exsit, return is
498  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
499  */
500 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00400, Function | SmallTest | Level1)
501 {
502     std::vector<sptr<NotificationSlot>> slotsResult;
503     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationAllSlots(noExsitbundleOption_, slotsResult),
504         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
505     ASSERT_EQ((int)slotsResult.size(), 0);
506     ErrCode result = advancedNotificationService_->GetSlots(slotsResult);
507     EXPECT_NE(result, ERR_OK);
508 }
509 
510 /**
511  * @tc.number    : GetNotificationAllSlots_00500
512  * @tc.name      :
513  * @tc.desc      : Get all notification slots from disturbe DB when bundleOption is null, return is
514  * ERR_ANS_INVALID_PARAM
515  */
516 HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00500, Function | SmallTest | Level1)
517 {
518     std::vector<sptr<NotificationSlot>> slotsResult;
519     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationAllSlots(nullptr, slotsResult),
520         (int)ERR_ANS_INVALID_PARAM);
521     ASSERT_EQ((int)slotsResult.size(), 0);
522 }
523 
524 /**
525  * @tc.number    : SetShowBadge_00100
526  * @tc.name      :
527  * @tc.desc      : Set bundle show badge into disturbe DB, return is ERR_OK.
528  */
529 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00100, Function | SmallTest | Level1)
530 {
531     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetShowBadge(bundleOption_, true), (int)ERR_OK);
532 }
533 
534 /**
535  * @tc.number    : SetShowBadge_00200
536  * @tc.name      :
537  * @tc.desc      : Set bundle show badge into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
538  */
539 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00200, Function | SmallTest | Level1)
540 {
541     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetShowBadge(bundleEmptyOption_, true),
542         (int)ERR_ANS_INVALID_PARAM);
543     auto result = bundleEmptyOption_->GetBundleName();
544     ASSERT_EQ(result, "");
545 }
546 
547 /**
548  * @tc.number    : SetShowBadge_00300
549  * @tc.name      :
550  * @tc.desc      : Set bundle show badge into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
551  */
552 HWTEST_F(NotificationPreferencesTest, SetShowBadge_00300, Function | SmallTest | Level1)
553 {
554     ASSERT_EQ(
555         (int)NotificationPreferences::GetInstance()->SetShowBadge(nullptr, true), (int)ERR_ANS_INVALID_PARAM);
556 }
557 
558 /**
559  * @tc.number    : IsShowBadge_00100
560  * @tc.name      :
561  * @tc.desc      : Get bunlde show badge from disturbe DB , return is ERR_OK and show badge is true.
562  */
563 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00100, Function | SmallTest | Level1)
564 {
565     bool enable = false;
566     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetShowBadge(bundleOption_, true), (int)ERR_OK);
567     ASSERT_EQ((int)NotificationPreferences::GetInstance()->IsShowBadge(bundleOption_, enable), (int)ERR_OK);
568     EXPECT_TRUE(enable);
569 }
570 
571 /**
572  * @tc.number    : IsShowBadge_00200
573  * @tc.name      :
574  * @tc.desc      : Get bunlde show badge from disturbe DB when bundle name is null, return is ERR_OK and show badge is
575  * true.
576  */
577 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00200, Function | SmallTest | Level1)
578 {
579     bool enable = false;
580     ASSERT_EQ((int)NotificationPreferences::GetInstance()->IsShowBadge(bundleEmptyOption_, enable),
581         (int)ERR_ANS_INVALID_PARAM);
582 }
583 
584 /**
585  * @tc.number    : IsShowBadge_00300
586  * @tc.name      :
587  * @tc.desc      : Get bunlde show badge from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
588  */
589 HWTEST_F(NotificationPreferencesTest, IsShowBadge_00300, Function | SmallTest | Level1)
590 {
591     bool enable = false;
592     ASSERT_EQ((int)NotificationPreferences::GetInstance()->IsShowBadge(nullptr, enable),
593         (int)ERR_ANS_INVALID_PARAM);
594 }
595 
596 /**
597  * @tc.number    : SetImportance_00100
598  * @tc.name      :
599  * @tc.desc      : Set bundle importance into disturbe DB, return is ERR_OK.
600  */
601 HWTEST_F(NotificationPreferencesTest, SetImportance_00100, Function | SmallTest | Level1)
602 {
603     int importance = 1;
604     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetImportance(bundleOption_, importance), (int)ERR_OK);
605 }
606 
607 /**
608  * @tc.number    : SetImportance_00200
609  * @tc.name      :
610  * @tc.desc      : Set bundle importance into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
611  */
612 HWTEST_F(NotificationPreferencesTest, SetImportance_00200, Function | SmallTest | Level1)
613 {
614     int importance = 1;
615     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetImportance(bundleEmptyOption_, importance),
616         (int)ERR_ANS_INVALID_PARAM);
617 }
618 
619 /**
620  * @tc.number    : SetImportance_00300
621  * @tc.name      :
622  * @tc.desc      : Set bundle importance into disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
623  */
624 HWTEST_F(NotificationPreferencesTest, SetImportance_00300, Function | SmallTest | Level1)
625 {
626     int importance = 1;
627     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetImportance(nullptr, importance),
628         (int)ERR_ANS_INVALID_PARAM);
629 }
630 
631 /**
632  * @tc.number    : GetImportance_00100
633  * @tc.name      :
634  * @tc.desc      : Get bundle importance from disturbe DB, return is ERR_OK.
635  */
636 HWTEST_F(NotificationPreferencesTest, GetImportance_00100, Function | SmallTest | Level1)
637 {
638     int importance = 1;
639     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetImportance(bundleOption_, importance), (int)ERR_OK);
640     int getImportance = 0;
641 
642     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetImportance(bundleOption_, getImportance), (int)ERR_OK);
643     ASSERT_EQ(getImportance, 1);
644 }
645 
646 /**
647  * @tc.number    : GetImportance_00200
648  * @tc.name      :
649  * @tc.desc      : Get bundle importance from disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
650  */
651 HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest | Level1)
652 {
653     int getImportance = 0;
654     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetImportance(bundleEmptyOption_, getImportance),
655         (int)ERR_ANS_INVALID_PARAM);
656 }
657 
658 /**
659  * @tc.number    : GetImportance_00300
660  * @tc.name      :
661  * @tc.desc      : Get bundle importance from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
662  */
663 HWTEST_F(NotificationPreferencesTest, GetImportance_00300, Function | SmallTest | Level1)
664 {
665     int getImportance = 0;
666     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetImportance(nullptr, getImportance),
667         (int)ERR_ANS_INVALID_PARAM);
668 }
669 
670 /**
671  * @tc.number    : SetTotalBadgeNums_00100
672  * @tc.name      :
673  * @tc.desc      : Set total badge nums into disturbe DB, return is ERR_OK.
674  */
675 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00100, Function | SmallTest | Level1)
676 {
677     int num = 1;
678     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetTotalBadgeNums(bundleOption_, num), (int)ERR_OK);
679 }
680 
681 /**
682  * @tc.number    : SetTotalBadgeNums_00200
683  * @tc.name      :
684  * @tc.desc      : Set total badge nums into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
685  */
686 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00200, Function | SmallTest | Level1)
687 {
688     int num = 1;
689     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetTotalBadgeNums(bundleEmptyOption_, num),
690         (int)ERR_ANS_INVALID_PARAM);
691 }
692 
693 /**
694  * @tc.number    : SetTotalBadgeNums_00300
695  * @tc.name      :
696  * @tc.desc      : Set total badge nums into disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
697  */
698 HWTEST_F(NotificationPreferencesTest, SetTotalBadgeNums_00300, Function | SmallTest | Level1)
699 {
700     int num = 1;
701     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetTotalBadgeNums(nullptr, num),
702         (int)ERR_ANS_INVALID_PARAM);
703 }
704 
705 /**
706  * @tc.number    : GetTotalBadgeNums_00100
707  * @tc.name      :
708  * @tc.desc      : Get total badge nums from disturbe DB, return is ERR_OK.
709  */
710 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00100, Function | SmallTest | Level1)
711 {
712     int num = 1;
713     NotificationPreferences::GetInstance()->SetTotalBadgeNums(bundleOption_, num);
714     int totalBadgeNum = 0;
715     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetTotalBadgeNums(bundleOption_, totalBadgeNum),
716         (int)ERR_OK);
717     ASSERT_EQ(totalBadgeNum, num);
718 }
719 
720 /**
721  * @tc.number    : GetTotalBadgeNums_00200
722  * @tc.name      :
723  * @tc.desc      : Get total badge nums from disturbe DB when bundle name is null, return is ERR_ANS_INVALID_PARAM.
724  */
725 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallTest | Level1)
726 {
727     int totalBadgeNum = 0;
728     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetTotalBadgeNums(bundleEmptyOption_, totalBadgeNum),
729         (int)ERR_ANS_INVALID_PARAM);
730 }
731 
732 /**
733  * @tc.number    : GetTotalBadgeNums_00300
734  * @tc.name      :
735  * @tc.desc      : Get total badge nums from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM.
736  */
737 HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00300, Function | SmallTest | Level1)
738 {
739     int totalBadgeNum = 0;
740     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetTotalBadgeNums(nullptr, totalBadgeNum),
741         (int)ERR_ANS_INVALID_PARAM);
742 }
743 
744 /**
745  * @tc.number    : SetNotificationsEnabledForBundle_00100
746  * @tc.name      :
747  * @tc.desc      : Set notification enable for bundle into disturbe DB, return is ERR_OK.
748  */
749 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1)
750 {
751     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle(bundleOption_,
752         static_cast<NotificationConstant::SWITCH_STATE>(0)), (int)ERR_OK);
753 }
754 
755 /**
756  * @tc.number    : SetNotificationsEnabledForBundle_00200
757  * @tc.name      :
758  * @tc.desc      : Set notification enable for bundle into disturbe DB when bundle name is null, return is
759  * ERR_ANS_INVALID_PARAM.
760  */
761 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1)
762 {
763     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle(bundleEmptyOption_,
764         static_cast<NotificationConstant::SWITCH_STATE>(0)), (int)ERR_ANS_INVALID_PARAM);
765 }
766 
767 /**
768  * @tc.number    : SetNotificationsEnabledForBundle_00300
769  * @tc.name      :
770  * @tc.desc      : Set notification enable for bundle into disturbe DB when bundleOption is null, return is
771  * ERR_ANS_INVALID_PARAM.
772  */
773 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1)
774 {
775     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle(nullptr,
776         static_cast<NotificationConstant::SWITCH_STATE>(0)), (int)ERR_ANS_INVALID_PARAM);
777 }
778 
779 /**
780  * @tc.number    : GetNotificationsEnabledForBundle_00100
781  * @tc.name      :
782  * @tc.desc      : Get notification enable for bundle from disturbe DB, return is ERR_OK.
783  */
784 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1)
785 {
786     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabledForBundle(bundleOption_,
787         static_cast<NotificationConstant::SWITCH_STATE>(0)), (int)ERR_OK);
788 
789     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
790     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundleOption_, state),
791         (int)ERR_OK);
792     ASSERT_EQ(static_cast<int32_t>(state), 0);
793 }
794 
795 /**
796  * @tc.number    : GetNotificationsEnabledForBundle_00200
797  * @tc.name      :
798  * @tc.desc      : Get notification enable for bundle from disturbe DB when bundle name is null, return is
799  * ERR_ANS_INVALID_PARAM.
800  */
801 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1)
802 {
803     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
804     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundleEmptyOption_,
805         state), (int)ERR_ANS_INVALID_PARAM);
806 }
807 
808 /**
809  * @tc.number    : GetNotificationsEnabledForBundle_00300
810  * @tc.name      :
811  * @tc.desc      : Get notification enable for bundle from disturbe DB when bundleOption is null, return is
812  * ERR_ANS_INVALID_PARAM.
813  */
814 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1)
815 {
816     NotificationConstant::SWITCH_STATE state = NotificationConstant::SWITCH_STATE::USER_MODIFIED_OFF;
817     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(nullptr, state),
818         (int)ERR_ANS_INVALID_PARAM);
819 }
820 
821 /**
822  * @tc.number    : SetNotificationsEnabled_00100
823  * @tc.name      :
824  * @tc.desc      : Set enable notification into disturbe DB, return is ERR_OK
825  */
826 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00100, Function | SmallTest | Level1)
827 {
828     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabled(100, true), (int)ERR_OK);
829 }
830 
831 /**
832  * @tc.number    : SetNotificationsEnabled_00200
833  * @tc.name      :
834  * @tc.desc      : Set enable notification into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
835  */
836 HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00200, Function | SmallTest | Level1)
837 {
838     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, true),
839         (int)ERR_ANS_INVALID_PARAM);
840 }
841 
842 /**
843  * @tc.number    : GetNotificationsEnabled_00100
844  * @tc.name      :
845  * @tc.desc      : Get enable notification from disturbe DB, return is ERR_OK
846  */
847 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | SmallTest | Level1)
848 {
849     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabled(100, true), (int)ERR_OK);
850     bool enable = false;
851     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabled(100, enable), (int)ERR_OK);
852     EXPECT_TRUE(enable);
853 }
854 
855 /**
856  * @tc.number    : GetNotificationsEnabled_00200
857  * @tc.name      :
858  * @tc.desc      : Same user can get enable setting, different user can not get.
859  */
860 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1)
861 {
862     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetNotificationsEnabled(100, true), (int)ERR_OK);
863     bool enable = false;
864     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabled(100, enable), (int)ERR_OK);
865     EXPECT_TRUE(enable);
866 
867     enable = false;
868     ASSERT_EQ(
869         (int)NotificationPreferences::GetInstance()->GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM);
870     EXPECT_FALSE(enable);
871 }
872 
873 /**
874  * @tc.number    : GetNotificationsEnabled_00300
875  * @tc.name      :
876  * @tc.desc      : Get enable notification from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
877  */
878 HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00300, Function | SmallTest | Level1)
879 {
880     bool enable = false;
881     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, enable),
882         (int)ERR_ANS_INVALID_PARAM);
883 }
884 
885 /**
886  * @tc.number    : SetDoNotDisturbDate_00100
887  * @tc.name      :
888  * @tc.desc      : Set disturbe mode into disturbe DB, return is ERR_OK
889  */
890 HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | SmallTest | Level1)
891 {
892     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
893     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
894     int64_t beginDate = beginDuration.count();
895     timePoint += std::chrono::hours(1);
896     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
897     int64_t endDate = endDuration.count();
898     sptr<NotificationDoNotDisturbDate> date =
899         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
900 
901     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
902 }
903 
904 /**
905  * @tc.number    : SetDoNotDisturbDate_00200
906  * @tc.name      :
907  * @tc.desc      : Set disturbe mode into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
908  */
909 HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00200, Function | SmallTest | Level1)
910 {
911     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
912     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
913     int64_t beginDate = beginDuration.count();
914     timePoint += std::chrono::hours(1);
915     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
916     int64_t endDate = endDuration.count();
917     sptr<NotificationDoNotDisturbDate> date =
918         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
919 
920     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, date),
921         (int)ERR_ANS_INVALID_PARAM);
922 }
923 
924 /**
925  * @tc.number    : GetDoNotDisturbDate_00100
926  * @tc.name      :
927  * @tc.desc      : Get disturbe mode from disturbe DB, return is ERR_OK
928  */
929 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | SmallTest | Level1)
930 {
931     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
932     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
933     int64_t beginDate = beginDuration.count();
934     timePoint += std::chrono::hours(1);
935     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
936     int64_t endDate = endDuration.count();
937     sptr<NotificationDoNotDisturbDate> date =
938         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
939     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
940 
941     sptr<NotificationDoNotDisturbDate> getDate;
942     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetDoNotDisturbDate(SYSTEM_APP_UID, getDate), (int)ERR_OK);
943     ASSERT_EQ(getDate->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY);
944     ASSERT_EQ(getDate->GetBeginDate(), beginDate);
945     ASSERT_EQ(getDate->GetEndDate(), endDate);
946 }
947 
948 /**
949  * @tc.number    : GetDoNotDisturbDate_00200
950  * @tc.name      :
951  * @tc.desc      : Same user can get DoNotDisturbDate setting, different user can not get.
952  */
953 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00200, Function | SmallTest | Level1)
954 {
955     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
956     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
957     int64_t beginDate = beginDuration.count();
958     timePoint += std::chrono::hours(1);
959     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
960     int64_t endDate = endDuration.count();
961     sptr<NotificationDoNotDisturbDate> date =
962         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
963     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK);
964 
965     sptr<NotificationDoNotDisturbDate> getDate;
966     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetDoNotDisturbDate(SYSTEM_APP_UID, getDate), (int)ERR_OK);
967     ASSERT_EQ(getDate->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY);
968     ASSERT_EQ(getDate->GetBeginDate(), beginDate);
969     ASSERT_EQ(getDate->GetEndDate(), endDate);
970 
971     sptr<NotificationDoNotDisturbDate> getExsitDate;
972     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetDoNotDisturbDate(
973         NON_SYSTEM_APP_UID, getExsitDate), (int)ERR_ANS_INVALID_PARAM);
974 }
975 
976 /**
977  * @tc.number    : GetDoNotDisturbDate_00300
978  * @tc.name      :
979  * @tc.desc      : Get disturbe mode from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM
980  */
981 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00300, Function | SmallTest | Level1)
982 {
983     sptr<NotificationDoNotDisturbDate> getDate;
984     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, getDate),
985         (int)ERR_ANS_INVALID_PARAM);
986 }
987 
988 /**
989  * @tc.number    : SetHasPoppedDialog_00100
990  * @tc.name      :
991  * @tc.desc      : Set has popped dialog into disturbe DB, return is ERR_OK
992  */
993 HWTEST_F(NotificationPreferencesTest, SetHasPoppedDialog_00100, Function | SmallTest | Level1)
994 {
995     bool hasPopped = false;
996 
997     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetHasPoppedDialog(bundleOption_, hasPopped), (int)ERR_OK);
998 
999     auto res = NotificationPreferences::GetInstance()->SetHasPoppedDialog(nullptr, hasPopped);
1000     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
1001 }
1002 
1003 /**
1004  * @tc.number    : GetHasPoppedDialog_00100
1005  * @tc.name      :
1006  * @tc.desc      : Get has popped dialog from disturbe DB, return is ERR_OK
1007  */
1008 HWTEST_F(NotificationPreferencesTest, GetHasPoppedDialog_00100, Function | SmallTest | Level1)
1009 {
1010     bool popped = true;
1011 
1012     ASSERT_EQ((int)NotificationPreferences::GetInstance()->SetHasPoppedDialog(bundleOption_, popped), (int)ERR_OK);
1013 
1014     bool hasPopped = false;
1015     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetHasPoppedDialog(bundleOption_, hasPopped), (int)ERR_OK);
1016     EXPECT_TRUE(hasPopped);
1017 }
1018 
1019 /**
1020  * @tc.number    : AddNotificationBundleProperty_00100
1021  * @tc.name      : AddNotificationBundleProperty
1022  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundleOption is null,
1023  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED.
1024  * @tc.require   : issueI5SR8J
1025  */
1026 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00100, Function | SmallTest | Level1)
1027 {
1028     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationBundleProperty(bundleOption_),
1029         (int)ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1030 }
1031 
1032 /**
1033  * @tc.number    : AddNotificationBundleProperty_00200
1034  * @tc.name      : AddNotificationBundleProperty
1035  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundlename is null,
1036  *                 return is ERR_ANS_INVALID_PARAM.
1037  * @tc.require   : issueI5SR8J
1038  */
1039 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00200, Function | SmallTest | Level1)
1040 {
1041     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationBundleProperty(bundleEmptyOption_),
1042         (int)ERR_ANS_INVALID_PARAM);
1043 }
1044 
1045 /**
1046  * @tc.number    : AddNotificationBundleProperty_00300
1047  * @tc.name      : AddNotificationBundleProperty
1048  * @tc.desc      : Add a notification BundleProperty into distrube DB when bundlename is null,
1049  *                 return is ERR_ANS_INVALID_PARAM.
1050  * @tc.require   : issueI5SR8J
1051  */
1052 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00300, Function | SmallTest | Level1)
1053 {
1054     ASSERT_EQ((int)NotificationPreferences::GetInstance()->AddNotificationBundleProperty(nullptr),
1055         (int)ERR_ANS_INVALID_PARAM);
1056 }
1057 
1058 /**
1059  * @tc.number    : RemoveNotificationAllSlots_00100
1060  * @tc.name      : RemoveNotificationAllSlots
1061  * @tc.desc      : Test RemoveNotificationAllSlots function when bundlename is null,
1062  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1063  * @tc.require   : issueI5SR8J
1064  */
1065 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00100, Function | SmallTest | Level1)
1066 {
1067     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationAllSlots(bundleOption_),
1068         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1069 }
1070 
1071 /**
1072  * @tc.number    : RemoveNotificationAllSlots_00200
1073  * @tc.name      : RemoveNotificationAllSlots
1074  * @tc.desc      : Test RemoveNotificationAllSlots function when bundleOption is null,
1075  *                 return is ERR_ANS_INVALID_PARAM.
1076  * @tc.require   : issueI5SR8J
1077  */
1078 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00200, Function | SmallTest | Level1)
1079 {
1080     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationAllSlots(bundleEmptyOption_),
1081         (int)ERR_ANS_INVALID_PARAM);
1082 }
1083 
1084 /**
1085  * @tc.number    : RemoveNotificationAllSlots_00300
1086  * @tc.name      : RemoveNotificationAllSlots
1087  * @tc.desc      : Test RemoveNotificationAllSlots function when bundleOption is null,
1088  *                 return is ERR_ANS_INVALID_PARAM.
1089  * @tc.require   : issueI5SR8J
1090  */
1091 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00300, Function | SmallTest | Level1)
1092 {
1093     ASSERT_EQ((int)NotificationPreferences::GetInstance()->RemoveNotificationAllSlots(nullptr),
1094         (int)ERR_ANS_INVALID_PARAM);
1095 }
1096 
1097 /**
1098  * @tc.number    : GetNotificationSlotsNumForBundle_00100
1099  * @tc.name      : GetNotificationSlotsNumForBundle
1100  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundlename is null,
1101  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1102  * @tc.require   : issueI5SR8J
1103  */
1104 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00100, Function | SmallTest | Level1)
1105 {
1106     uint64_t num = 1;
1107     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlotsNumForBundle(bundleOption_, num),
1108         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1109 }
1110 
1111 /**
1112  * @tc.number    : GetNotificationSlotsNumForBundle_00200
1113  * @tc.name      : GetNotificationSlotsNumForBundle
1114  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundleOption is null,
1115  *                 return is ERR_ANS_INVALID_PARAM.
1116  * @tc.require   : issueI5SR8J
1117  */
1118 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00200, Function | SmallTest | Level1)
1119 {
1120     uint64_t num = 2;
1121     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlotsNumForBundle(bundleEmptyOption_, num),
1122         (int)ERR_ANS_INVALID_PARAM);
1123 }
1124 
1125 /**
1126  * @tc.number    : GetNotificationSlotsNumForBundle_00300
1127  * @tc.name      : GetNotificationSlotsNumForBundle
1128  * @tc.desc      : Test GetNotificationSlotsNumForBundle function when bundleOption is null,
1129  *                 return is ERR_ANS_INVALID_PARAM.
1130  * @tc.require   : issueI5SR8J
1131  */
1132 HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Function | SmallTest | Level1)
1133 {
1134     uint64_t num = 2;
1135     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetNotificationSlotsNumForBundle(nullptr, num),
1136         (int)ERR_ANS_INVALID_PARAM);
1137 }
1138 
1139 /**
1140  * @tc.number    : CheckSlotForCreateSlot_00100
1141  * @tc.name      : CheckSlotForCreateSlot
1142  * @tc.desc      : Test CheckSlotForCreateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM.
1143  * @tc.require   : issueI5SR8J
1144  */
1145 HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1)
1146 {
1147     NotificationPreferencesInfo info;
1148     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1149     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForCreateSlot(bundleOption_, nullptr, info),
1150         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST);
1151 }
1152 
1153 /**
1154  * @tc.number    : CheckSlotForCreateSlot_00200
1155  * @tc.name      : CheckSlotForCreateSlot
1156  * @tc.desc      : Test CheckSlotForCreateSlot function, return ERR_OK.
1157  * @tc.require   : issueI5SR8J
1158  */
1159 HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1)
1160 {
1161     NotificationPreferencesInfo info;
1162     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1163     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForCreateSlot(bundleOption_, slot, info),
1164         (int)ERR_OK);
1165 }
1166 
1167 /**
1168  * @tc.number    : CheckSlotForRemoveSlot_00100
1169  * @tc.name      : CheckSlotForRemoveSlot
1170  * @tc.desc      : Test CheckSlotForRemoveSlot function after add a notification slot,
1171  * return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1172  * @tc.require   : issueI5SR8J
1173  */
1174 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1)
1175 {
1176     NotificationPreferencesInfo info;
1177     TestAddNotificationSlot(info);
1178     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForRemoveSlot(
1179         bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_OK);
1180 }
1181 
1182 /**
1183  * @tc.number    : CheckSlotForRemoveSlot_00200
1184  * @tc.name      : CheckSlotForRemoveSlot
1185  * @tc.desc      : Test CheckSlotForRemoveSlot function, return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST,
1186  * @tc.require   : issueI5SR8J
1187  */
1188 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1)
1189 {
1190     NotificationPreferencesInfo info;
1191     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForRemoveSlot(
1192         bundleOption_, NotificationConstant::SlotType::OTHER, info),
1193         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1194 }
1195 
1196 /**
1197  * @tc.number    : CheckSlotForRemoveSlot_00300
1198  * @tc.name      : CheckSlotForRemoveSlot
1199  * @tc.desc      : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK.
1200  * @tc.require   : issueI5SR8J
1201  */
1202 HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1)
1203 {
1204     NotificationPreferencesInfo info;
1205     TestAddNotificationSlot(info);
1206     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForRemoveSlot(
1207         bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info),
1208         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
1209 }
1210 
1211 /*
1212  * @tc.name: SetSmartReminderEnabled_0100
1213  * @tc.desc: test SetSmartReminderEnabled with parameters
1214  * @tc.type: FUNC
1215  */
1216 HWTEST_F(NotificationPreferencesTest, SetSmartReminderEnabled_0100, TestSize.Level1)
1217 {
1218     ErrCode res = NotificationPreferences::GetInstance()->SetSmartReminderEnabled("testDeviceType",
1219         true);
1220     ASSERT_EQ(res, ERR_OK);
1221 }
1222 
1223 /*
1224  * @tc.name: SetSmartReminderEnabled_0200
1225  * @tc.desc: test SetSmartReminderEnabled with parameters, expect errorCode ERR_ANS_INVALID_PARAM.
1226  * @tc.type: FUNC
1227  */
1228 HWTEST_F(NotificationPreferencesTest, SetSmartReminderEnabled_0200, TestSize.Level1)
1229 {
1230     ErrCode res = NotificationPreferences::GetInstance()->SetSmartReminderEnabled("", true);
1231     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
1232 }
1233 
1234 /**
1235  * @tc.name: IsSmartReminderEnabled_0100
1236  * @tc.desc: test IsSmartReminderEnabled with parameters
1237  * @tc.type: FUNC
1238  */
1239 HWTEST_F(NotificationPreferencesTest, IsSmartReminderEnabled_0100, TestSize.Level1)
1240 {
1241     bool enable = true;
1242     ErrCode result = NotificationPreferences::GetInstance()->IsSmartReminderEnabled("testDeviceType1",
1243         enable);
1244     ASSERT_EQ(result, ERR_OK);
1245 }
1246 
1247 /**
1248  * @tc.name: IsSmartReminderEnabled_0200
1249  * @tc.desc: test IsSmartReminderEnabled with parameters, expect errorCode ERR_ANS_INVALID_PARAM.
1250  * @tc.type: FUNC
1251  */
1252 HWTEST_F(NotificationPreferencesTest, IsSmartReminderEnabled_0200, TestSize.Level1)
1253 {
1254     bool enable = true;
1255     ErrCode result = NotificationPreferences::GetInstance()->IsSmartReminderEnabled("", enable);
1256     ASSERT_EQ(result, ERR_ANS_INVALID_PARAM);
1257 }
1258 
1259 /**
1260  * @tc.number    : CheckSlotForUpdateSlot_00100
1261  * @tc.name      : CheckSlotForUpdateSlot
1262  * @tc.desc      : Test CheckSlotForUpdateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM.
1263  * @tc.require   : issueI5SR8J
1264  */
1265 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1)
1266 {
1267     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1268     NotificationPreferencesInfo info;
1269     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForUpdateSlot(bundleOption_, nullptr, info),
1270         (int)ERR_ANS_INVALID_PARAM);
1271 }
1272 
1273 /**
1274  * @tc.number    : CheckSlotForUpdateSlot_00200
1275  * @tc.name      : CheckSlotForUpdateSlot
1276  * @tc.desc      : Test CheckSlotForUpdateSlot function when bundle not existed, return is
1277  * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST.
1278  * @tc.require   : issueI5SR8J
1279  */
1280 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1)
1281 {
1282     NotificationPreferencesInfo info;
1283     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1284     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForUpdateSlot(bundleOption_, slot, info),
1285         (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST);
1286 }
1287 
1288 /**
1289  * @tc.number    : CheckSlotForUpdateSlot_00300
1290  * @tc.name      : CheckSlotForUpdateSlot
1291  * @tc.desc      : Test CheckSlotForUpdateSlot function when slot is different type, return is
1292  * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST.
1293  * @tc.require   : issueI5SR8J
1294  */
1295 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1)
1296 {
1297     NotificationPreferencesInfo info;
1298     TestAddNotificationSlot(info);
1299     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
1300     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForUpdateSlot(bundleOption_, slot, info),
1301         (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST);
1302 }
1303 
1304 /**
1305  * @tc.number    : GetAllNotificationEnabledBundles_00100
1306  * @tc.name      : GetAllNotificationEnabledBundles
1307  * @tc.desc      : Get all notification enable bundle in DB when db is null,
1308  *                 return is ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED.
1309  * @tc.require   : issueI92VGR
1310  */
1311 HWTEST_F(NotificationPreferencesTest, GetAllNotificationEnabledBundles_00100, Function | SmallTest | Level1)
1312 {
1313     std::vector<NotificationBundleOption> bundleOption;
1314     ASSERT_EQ((int)NotificationPreferences::GetInstance()->GetAllNotificationEnabledBundles(bundleOption),
1315         (int)ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1316 }
1317 
1318 /**
1319  * @tc.number    : CheckSlotForUpdateSlot_00400
1320  * @tc.name      : CheckSlotForUpdateSlot
1321  * @tc.desc      : Test CheckSlotForUpdateSlot function after add notification slot, return is ERR_OK.
1322  * @tc.require   : issueI5SR8J
1323  */
1324 HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1)
1325 {
1326     NotificationPreferencesInfo info;
1327     TestAddNotificationSlot(info);
1328     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
1329     ASSERT_EQ((int)NotificationPreferences::GetInstance()->CheckSlotForUpdateSlot(bundleOption_, slot, info),
1330         (int)ERR_OK);
1331 }
1332 
1333 /*
1334  * @tc.name: SetDistributedEnabledByBundle_0100
1335  * @tc.desc: test SetDistributedEnabledByBundle with parameters
1336  * @tc.type: FUNC
1337  */
1338 HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledByBundle_0100, TestSize.Level1)
1339 {
1340     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
1341     std::string deviceType = "testDeviceType";
1342 
1343     ErrCode res = NotificationPreferences::GetInstance()->SetDistributedEnabledByBundle(bundleOption, deviceType, true);
1344     ASSERT_EQ(res, ERR_OK);
1345 }
1346 
1347 /*
1348  * @tc.name: SetDistributedEnabledByBundle_0200
1349  * @tc.desc: test SetDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM.
1350  * @tc.type: FUNC
1351  */
1352 HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledByBundle_0200, TestSize.Level1)
1353 {
1354     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("", 1));
1355     std::string deviceType = "testDeviceType";
1356 
1357     ErrCode res = NotificationPreferences::GetInstance()->SetDistributedEnabledByBundle(bundleOption,
1358         deviceType, true);
1359     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
1360 }
1361 
1362 /**
1363  * @tc.name: IsDistributedEnabledByBundle_0100
1364  * @tc.desc: test IsDistributedEnabledByBundle with parameters
1365  * @tc.type: FUNC
1366  */
1367 HWTEST_F(NotificationPreferencesTest, IsDistributedEnabledByBundle_0100, TestSize.Level1)
1368 {
1369     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
1370     std::string deviceType = "testDeviceType1111";
1371     bool enable = true;
1372     ErrCode result = NotificationPreferences::GetInstance()->IsDistributedEnabledByBundle(bundleOption,
1373         deviceType, enable);
1374     ASSERT_EQ(result, ERR_OK);
1375 }
1376 
1377 /**
1378  * @tc.name: IsDistributedEnabledByBundle_0200
1379  * @tc.desc: test IsDistributedEnabledByBundle with parameters, expect errorCode ERR_ANS_INVALID_PARAM.
1380  * @tc.type: FUNC
1381  */
1382 HWTEST_F(NotificationPreferencesTest, IsDistributedEnabledByBundle_0200, TestSize.Level1)
1383 {
1384     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("", 1));
1385     std::string deviceType = "testDeviceType1111";
1386     bool enable = true;
1387     ErrCode result = NotificationPreferences::GetInstance()->IsDistributedEnabledByBundle(bundleOption,
1388         deviceType, enable);
1389     ASSERT_EQ(result, ERR_ANS_INVALID_PARAM);
1390 }
1391 
1392 /**
1393  * @tc.name: AddDoNotDisturbProfiles_0100
1394  * @tc.desc: test AddDoNotDisturbProfiles id of profile out of range.
1395  * @tc.type: FUNC
1396  */
1397 HWTEST_F(NotificationPreferencesTest, AddDoNotDisturbProfiles_0100, TestSize.Level1)
1398 {
1399     int32_t userId = 1;
1400     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1401     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1402     profile->SetProfileId(0);
1403     profiles.emplace_back(profile);
1404     auto res = NotificationPreferences::GetInstance()->AddDoNotDisturbProfiles(userId, profiles);
1405     ASSERT_EQ(res, ERR_OK);
1406 }
1407 
1408 /**
1409  * @tc.name: AddDoNotDisturbProfiles_0200
1410  * @tc.desc: test AddDoNotDisturbProfiles when AddDoNotDisturbProfiles of preferncesDB_ return false.
1411  * @tc.type: FUNC
1412  */
1413 HWTEST_F(NotificationPreferencesTest, AddDoNotDisturbProfiles_0200, TestSize.Level1)
1414 {
1415     int32_t userId = 1;
1416     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1417     profiles.clear();
1418     auto res = NotificationPreferences::GetInstance()->AddDoNotDisturbProfiles(userId, profiles);
1419     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1420 }
1421 
1422 /**
1423  * @tc.name: AddDoNotDisturbProfiles_0300
1424  * @tc.desc: test AddDoNotDisturbProfiles success.
1425  * @tc.type: FUNC
1426  */
1427 HWTEST_F(NotificationPreferencesTest, AddDoNotDisturbProfiles_0300, TestSize.Level1)
1428 {
1429     int32_t userId = 1;
1430     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1431     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1432     profile->SetProfileId(1);
1433     profiles.emplace_back(profile);
1434     auto res = NotificationPreferences::GetInstance()->AddDoNotDisturbProfiles(userId, profiles);
1435     ASSERT_EQ(res, ERR_OK);
1436 }
1437 
1438 /**
1439  * @tc.name: RemoveDoNotDisturbProfiles_0100
1440  * @tc.desc: test RemoveDoNotDisturbProfiles id of profile out of range.
1441  * @tc.type: FUNC
1442  */
1443 HWTEST_F(NotificationPreferencesTest, RemoveDoNotDisturbProfiles_0100, TestSize.Level1)
1444 {
1445     int32_t userId = 1;
1446     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1447     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1448     profile->SetProfileId(0);
1449     profiles.emplace_back(profile);
1450     auto res = NotificationPreferences::GetInstance()->RemoveDoNotDisturbProfiles(userId, profiles);
1451     ASSERT_EQ(res, ERR_OK);
1452 }
1453 
1454 /**
1455  * @tc.name: RemoveDoNotDisturbProfiles_0200
1456  * @tc.desc: test RemoveDoNotDisturbProfiles_0100 when RemoveDoNotDisturbProfiles
1457  *       of preferncesDB_ return false.
1458  * @tc.type: FUNC
1459  */
1460 HWTEST_F(NotificationPreferencesTest, RemoveDoNotDisturbProfiles_0200, TestSize.Level1)
1461 {
1462     int32_t userId = 1;
1463     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1464     profiles.clear();
1465     auto res = NotificationPreferences::GetInstance()->RemoveDoNotDisturbProfiles(userId, profiles);
1466     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1467 }
1468 
1469 /**
1470  * @tc.name: RemoveDoNotDisturbProfiles_0300
1471  * @tc.desc: test RemoveDoNotDisturbProfiles success.
1472  * @tc.type: FUNC
1473  */
1474 HWTEST_F(NotificationPreferencesTest, RemoveDoNotDisturbProfiles_0300, TestSize.Level1)
1475 {
1476     int32_t userId = 1;
1477     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1478     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1479     profile->SetProfileId(1);
1480     profiles.emplace_back(profile);
1481     auto res = NotificationPreferences::GetInstance()->RemoveDoNotDisturbProfiles(userId, profiles);
1482     ASSERT_EQ(res, ERR_OK);
1483 }
1484 
1485 /**
1486  * @tc.name: GetDoNotDisturbProfile_0200
1487  * @tc.desc: test GetDoNotDisturbProfile when GetDoNotDisturbProfiles of preferncesDB_ return false.
1488  * @tc.type: FUNC
1489  */
1490 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbProfile_0200, TestSize.Level1)
1491 {
1492     int32_t profileId = 1;
1493     int32_t userId = 1;
1494     sptr<NotificationDoNotDisturbProfile> profile;
1495     auto res = NotificationPreferences::GetInstance()->GetDoNotDisturbProfile(profileId, userId, profile);
1496     ASSERT_EQ(res, ERR_ANS_NO_PROFILE_TEMPLATE);
1497 }
1498 
1499 /**
1500  * @tc.name: GetDoNotDisturbProfile_0300
1501  * @tc.desc: test GetDoNotDisturbProfile when GetDoNotDisturbProfiles of preferncesDB_ return true.
1502  * @tc.type: FUNC
1503  */
1504 HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbProfile_0300, TestSize.Level1)
1505 {
1506     int32_t userId = 1;
1507     int32_t profileId = 1;
1508     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1509     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1510     profile->SetProfileId(profileId);
1511     profiles.emplace_back(profile);
1512     NotificationPreferences::GetInstance()->AddDoNotDisturbProfiles(userId, profiles);
1513     auto res = NotificationPreferences::GetInstance()->GetDoNotDisturbProfile(profileId, userId, profile);
1514     ASSERT_EQ(res, ERR_OK);
1515 }
1516 
1517 /**
1518  * @tc.name: GetBundleSoundPermission_0100
1519  * @tc.desc: test GetBundleSoundPermission.
1520  * @tc.type: FUNC
1521  */
1522 HWTEST_F(NotificationPreferencesTest, GetBundleSoundPermission_0100, TestSize.Level1)
1523 {
1524     bool allPackage = true;
1525     std::set<std::string> bundleNames = {};
1526     auto res = NotificationPreferences::GetInstance()->GetBundleSoundPermission(allPackage, bundleNames);
1527     ASSERT_EQ(res, ERR_OK);
1528 }
1529 
1530 /**
1531  * @tc.name: SetDisableNotificationInfo_0100
1532  * @tc.desc: test SetDisableNotificationInfo.
1533  * @tc.type: FUNC
1534  */
1535 HWTEST_F(NotificationPreferencesTest, SetDisableNotificationInfo_0100, TestSize.Level1)
1536 {
1537     sptr<NotificationDisable> notificationDisable = new (std::nothrow) NotificationDisable();
1538     notificationDisable->SetDisabled(true);
1539     notificationDisable->SetBundleList({ "com.example.app" });
1540     auto res = NotificationPreferences::GetInstance()->SetDisableNotificationInfo(notificationDisable);
1541     ASSERT_EQ(res, ERR_OK);
1542 }
1543 
1544 /**
1545  * @tc.name: SetDisableNotificationInfo_0200
1546  * @tc.desc: test SetDisableNotificationInfo.
1547  * @tc.type: FUNC
1548  */
1549 HWTEST_F(NotificationPreferencesTest, SetDisableNotificationInfo_0200, TestSize.Level1)
1550 {
1551     auto res = NotificationPreferences::GetInstance()->SetDisableNotificationInfo(nullptr);
1552     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1553 }
1554 
1555 /**
1556  * @tc.name: GetDisableNotificationInfo_0100
1557  * @tc.desc: test GetDisableNotificationInfo.
1558  * @tc.type: FUNC
1559  */
1560 HWTEST_F(NotificationPreferencesTest, GetDisableNotificationInfo_0100, TestSize.Level1)
1561 {
1562     NotificationPreferences notificationPreferences;
1563     NotificationDisable notificationDisable;
1564     auto res = notificationPreferences.GetDisableNotificationInfo(notificationDisable);
1565     EXPECT_FALSE(res);
1566 }
1567 
1568 /**
1569  * @tc.name: GetDisableNotificationInfo_0200
1570  * @tc.desc: test GetDisableNotificationInfo.
1571  * @tc.type: FUNC
1572  */
1573 HWTEST_F(NotificationPreferencesTest, GetDisableNotificationInfo_0200, TestSize.Level1)
1574 {
1575     NotificationPreferences notificationPreferences;
1576     sptr<NotificationDisable> notificationDisable = new (std::nothrow) NotificationDisable();
1577     notificationDisable->SetDisabled(true);
1578     notificationDisable->SetBundleList({ "com.example.app" });
1579     notificationPreferences.SetDisableNotificationInfo(notificationDisable);
1580     NotificationDisable disable;
1581     auto res = notificationPreferences.GetDisableNotificationInfo(disable);
1582     EXPECT_TRUE(res);
1583 }
1584 
1585 /**
1586  * @tc.name: SetSubscriberExistFlag_0100
1587  * @tc.desc: test SetSubscriberExistFlag.
1588  * @tc.type: FUNC
1589  */
1590 HWTEST_F(NotificationPreferencesTest, SetSubscriberExistFlag_0100, TestSize.Level1)
1591 {
1592     NotificationPreferences notificationPreferences;
1593     auto ret = notificationPreferences.SetSubscriberExistFlag(DEVICE_TYPE_HEADSET, false);
1594     ASSERT_EQ(ret, ERR_OK);
1595     bool existFlag = true;
1596     ret = notificationPreferences.GetSubscriberExistFlag(DEVICE_TYPE_HEADSET, existFlag);
1597     ASSERT_EQ(ret, ERR_OK);
1598     EXPECT_FALSE(existFlag);
1599 }
1600 
1601 /**
1602  * @tc.name: GetSubscriberExistFlag_0100
1603  * @tc.desc: test GetSubscriberExistFlag.
1604  * @tc.type: FUNC
1605  */
1606 HWTEST_F(NotificationPreferencesTest, GetSubscriberExistFlag_0100, TestSize.Level1)
1607 {
1608     NotificationPreferences notificationPreferences;
1609     auto ret = notificationPreferences.SetSubscriberExistFlag(DEVICE_TYPE_HEADSET, true);
1610     ASSERT_EQ(ret, ERR_OK);
1611     bool existFlag = false;
1612     ret = notificationPreferences.GetSubscriberExistFlag(DEVICE_TYPE_HEADSET, existFlag);
1613     ASSERT_EQ(ret, ERR_OK);
1614     EXPECT_TRUE(existFlag);
1615 }
1616 
1617 /**
1618  * @tc.name: SetDistributedEnabledForBundle_0100
1619  * @tc.desc: test SetDistributedEnabledForBundle.
1620  * @tc.type: FUNC
1621  */
1622 HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledForBundle_0100, TestSize.Level1)
1623 {
1624     NotificationPreferences notificationPreferences;
1625     NotificationPreferencesInfo::BundleInfo bundleInfo;
1626     notificationPreferences.SetDistributedEnabledForBundle(bundleInfo);
1627     notificationPreferences.isCachedMirrorNotificationEnabledStatus_ = true;
1628     notificationPreferences.mirrorNotificationEnabledStatus_.clear();
1629     notificationPreferences.SetDistributedEnabledForBundle(bundleInfo);
1630     EXPECT_EQ(notificationPreferences.mirrorNotificationEnabledStatus_.size(), 0);
1631     std::string deviceType = "deviceTypeA";
1632     notificationPreferences.mirrorNotificationEnabledStatus_.push_back(deviceType);
1633     notificationPreferences.preferncesDB_ = nullptr;
1634     notificationPreferences.SetDistributedEnabledForBundle(bundleInfo);
1635     NotificationPreferences otherNotificationPreferences;
1636     auto ret = otherNotificationPreferences.preferncesDB_->IsDistributedEnabledEmptyForBundle(deviceType, bundleInfo);
1637     EXPECT_TRUE(ret);
1638 }
1639 
1640 /**
1641  * @tc.name: SetDistributedEnabledForBundle_0200
1642  * @tc.desc: test SetDistributedEnabledForBundle.
1643  * @tc.type: FUNC
1644  */
1645 HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledForBundle_0200, TestSize.Level1)
1646 {
1647     NotificationPreferences notificationPreferences;
1648     NotificationPreferencesInfo::BundleInfo bundleInfo;
1649     bundleInfo.SetBundleName("testBundleName");
1650     bundleInfo.SetBundleUid(1000);
1651     notificationPreferences.isCachedMirrorNotificationEnabledStatus_ = true;
1652     std::string deviceType = "deviceTypeC";
1653     notificationPreferences.mirrorNotificationEnabledStatus_.push_back(deviceType);
1654     notificationPreferences.SetDistributedEnabledForBundle(bundleInfo);
1655     bool isDistributedEnabled = false;
1656     auto ret = notificationPreferences.preferncesDB_->GetDistributedEnabledForBundle(
1657         deviceType, bundleInfo, isDistributedEnabled);
1658     EXPECT_TRUE(ret);
1659     EXPECT_TRUE(isDistributedEnabled);
1660 }
1661 
1662 /**
1663  * @tc.number    : UpdateProfilesUtil_00100
1664  * @tc.name      :
1665  * @tc.desc      :
1666  */
1667 HWTEST_F(NotificationPreferencesTest, UpdateProfilesUtil_00100, Function | SmallTest | Level1)
1668 {
1669     NotificationBundleOption bundleOne;
1670     bundleOne.SetBundleName("test1");
1671     bundleOne.SetUid(100);
1672     NotificationBundleOption bundleTwo;
1673     std::vector<NotificationBundleOption> bundleList;
1674     bundleList.push_back(bundleOne);
1675     bundleList.push_back(bundleTwo);
1676     std::vector<NotificationBundleOption> trustList;
1677     trustList.push_back(bundleOne);
1678     NotificationPreferences::GetInstance()->UpdateProfilesUtil(trustList, bundleList);
1679     ASSERT_EQ(bundleList.size(), trustList.size());
1680 }
1681 
1682 /**
1683  * @tc.number    : UpdateDoNotDisturbProfiles_00100
1684  * @tc.name      :
1685  * @tc.desc      :
1686  */
1687 HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00100, Function | SmallTest | Level1)
1688 {
1689     int32_t profileId = 3;
1690     int32_t userId = 100;
1691     std::string name = "testProfile";
1692     std::vector<NotificationBundleOption> bundleList;
1693 
1694     NotificationBundleOption bundleOne;
1695     bundleOne.SetBundleName("test1");
1696     bundleOne.SetUid(100);
1697     bundleList.push_back(bundleOne);
1698 
1699     NotificationCloneBundleInfo cloneBundleInfo;
1700     NotificationPreferences::GetInstance()->UpdateCloneBundleInfo(
1701         userId, cloneBundleInfo);
1702 
1703     auto res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles(
1704         userId, profileId, name, bundleList);
1705     ASSERT_EQ(res, ERR_OK);
1706 }
1707 
1708 /**
1709  * @tc.number    : UpdateDoNotDisturbProfiles_00200
1710  * @tc.name      :
1711  * @tc.desc      :
1712  */
1713 HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00200, Function | SmallTest | Level1)
1714 {
1715     int32_t profileId = 0;
1716     int32_t userId = 100;
1717     std::string name = "testProfile";
1718     std::vector<NotificationBundleOption> bundleList;
1719 
1720     NotificationBundleOption bundleOne;
1721     bundleOne.SetBundleName("test1");
1722     bundleOne.SetUid(100);
1723     bundleList.push_back(bundleOne);
1724 
1725     auto res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles(
1726         userId, profileId, name, bundleList);
1727     ASSERT_EQ(res, ERR_OK);
1728 }
1729 
1730 /**
1731  * @tc.number    : UpdateDoNotDisturbProfiles_00300
1732  * @tc.name      : UpdateDoNotDisturbProfiles_00300
1733  * @tc.desc      : Test UpdateDoNotDisturbProfiles
1734  */
1735 HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00300, Function | SmallTest | Level1)
1736 {
1737     int32_t profileId = 3;
1738     int32_t userId = 100;
1739     std::string name = "testProfile";
1740     std::vector<NotificationBundleOption> bundleList;
1741 
1742     NotificationCloneBundleInfo cloneBundleInfo;
1743     NotificationPreferences notificationPreferences;
1744     notificationPreferences.UpdateCloneBundleInfo(userId, cloneBundleInfo);
1745     auto res =notificationPreferences.UpdateDoNotDisturbProfiles(userId, profileId, name, bundleList);
1746     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
1747 
1748     NotificationBundleOption bundleOne;
1749     bundleOne.SetBundleName("test1");
1750     bundleOne.SetUid(100);
1751     bundleList.push_back(bundleOne);
1752 
1753     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
1754     res = notificationPreferences.UpdateDoNotDisturbProfiles(userId, profileId, name, bundleList);
1755     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
1756 
1757     notificationPreferences.preferncesDB_ = nullptr;
1758     res = notificationPreferences.UpdateDoNotDisturbProfiles(userId, profileId, name, bundleList);
1759     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
1760 }
1761 
1762  /**
1763  * @tc.name: UpdateDoNotDisturbProfiles_00400
1764  * @tc.desc: Test UpdateDoNotDisturbProfile
1765  * 1. Call the UpdateDoNotDisturbProfiles, assert the result of the method call is ERR_OK
1766  * 2. Call the UpdateDoNotDisturbProfiles method again with the updated parameters
1767  * 3. The method of GetDoNotDisturbProfiles will return true
1768  * 3. Assert that the result is also ERR_OK
1769  * @tc.type: FUNC
1770  */
1771 HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00400, Function | SmallTest | Level1)
1772 {
1773     int32_t userId = 100;
1774     int32_t profileId = 0;
1775     std::string name = "testProfile";
1776     std::vector<NotificationBundleOption> bundleList;
1777 
1778     NotificationBundleOption bundleOne;
1779     bundleOne.SetBundleName("test1");
1780     bundleOne.SetUid(100);
1781     bundleList.push_back(bundleOne);
1782 
1783     auto res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles(
1784         userId, profileId, name, bundleList);
1785     ASSERT_EQ(res, ERR_OK);
1786 
1787     name = "testProfile2";
1788     bundleOne.SetBundleName("test2");
1789     bundleOne.SetUid(100);
1790     bundleList.push_back(bundleOne);
1791 
1792     res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles(
1793             userId, profileId, name, bundleList);
1794     ASSERT_EQ(res, ERR_OK);
1795 }
1796 
1797 /**
1798  * @tc.number    : GetTemplateSupported_00100
1799  * @tc.name      :
1800  * @tc.desc      :
1801  */
1802 HWTEST_F(NotificationPreferencesTest, GetTemplateSupported_00100, Function | SmallTest | Level1)
1803 {
1804     bool support = false;
1805     auto res = NotificationPreferences::GetInstance()->GetTemplateSupported(
1806         "", support);
1807     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
1808 }
1809 
1810 /**
1811  * @tc.number    : SetDistributedEnabledBySlot_00100
1812  * @tc.name      :
1813  * @tc.desc      :
1814  */
1815 HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledBySlot_00100, Function | SmallTest | Level1)
1816 {
1817     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
1818     auto res = NotificationPreferences::GetInstance()->SetDistributedEnabledBySlot(
1819         slotType, "test", true);
1820     ASSERT_EQ(res, ERR_OK);
1821 
1822     bool enabled = false;
1823     res = NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot(
1824         slotType, "test", enabled);
1825     ASSERT_EQ(res, ERR_OK);
1826     ASSERT_EQ(enabled, true);
1827 }
1828 
1829 
1830 /**
1831  * @tc.number    : GetByteFromDb_00100
1832  * @tc.name      :
1833  * @tc.desc      :
1834  */
1835 HWTEST_F(NotificationPreferencesTest, GetByteFromDb_00100, Function | SmallTest | Level1)
1836 {
1837     std::vector<uint8_t> value;
1838     auto res = NotificationPreferences::GetInstance()->GetByteFromDb(
1839         "test", value, 100);
1840     ASSERT_NE(res, ERR_OK);
1841 }
1842 
1843 /**
1844  * @tc.number    : DeleteBatchKvFromDb_00100
1845  * @tc.name      :
1846  * @tc.desc      :
1847  */
1848 HWTEST_F(NotificationPreferencesTest, DeleteBatchKvFromDb_00100, Function | SmallTest | Level1)
1849 {
1850     std::vector<string> keys;
1851     auto res = NotificationPreferences::GetInstance()->DeleteBatchKvFromDb(
1852         keys, 100);
1853     ASSERT_EQ(res, ERR_OK);
1854 }
1855 
1856 /**
1857  * @tc.number    : IsAgentRelationship_00100
1858  * @tc.name      :
1859  * @tc.desc      :
1860  */
1861 HWTEST_F(NotificationPreferencesTest, IsAgentRelationship_00100, Function | SmallTest | Level1)
1862 {
1863     MockIsVerfyPermisson(true);
1864     auto res = NotificationPreferences::GetInstance()->IsAgentRelationship(
1865         "test1", "test2");
1866     ASSERT_EQ(res, true);
1867 }
1868 
1869 /**
1870  * @tc.number    : GetAdditionalConfig_00100
1871  * @tc.name      :
1872  * @tc.desc      :
1873  */
1874 HWTEST_F(NotificationPreferencesTest, GetAdditionalConfig_00100, Function | SmallTest | Level1)
1875 {
1876     auto res = NotificationPreferences::GetInstance()->GetAdditionalConfig("test");
1877     ASSERT_EQ(res, "");
1878 }
1879 
1880 /**
1881  * @tc.number    : DelCloneProfileInfo_00100
1882  * @tc.name      :
1883  * @tc.desc      :
1884  */
1885 HWTEST_F(NotificationPreferencesTest, DelCloneProfileInfo_00100, Function | SmallTest | Level1)
1886 {
1887     sptr<NotificationDoNotDisturbProfile> info(new NotificationDoNotDisturbProfile());
1888     info->SetProfileId(1);
1889     info->SetProfileName("TestName");
1890 
1891     NotificationBundleOption bundleOption;
1892     bundleOption.SetBundleName("bundleName");
1893     bundleOption.SetUid(100);
1894 
1895     std::vector<NotificationBundleOption> trustList;
1896     trustList.push_back(bundleOption);
1897     info->SetProfileTrustList(trustList);
1898 
1899     auto res = NotificationPreferences::GetInstance()->DelCloneProfileInfo(
1900         100, info);
1901     ASSERT_EQ(res, true);
1902 }
1903 
1904 /**
1905  * @tc.number    : UpdateBatchCloneProfileInfo_00100
1906  * @tc.name      :
1907  * @tc.desc      :
1908  */
1909 HWTEST_F(NotificationPreferencesTest, UpdateBatchCloneProfileInfo_00100, Function | SmallTest | Level1)
1910 {
1911     std::vector<sptr<NotificationDoNotDisturbProfile>> infos;
1912 
1913     sptr<NotificationDoNotDisturbProfile> info(new NotificationDoNotDisturbProfile());
1914     info->SetProfileId(1);
1915     info->SetProfileName("TestName");
1916     infos.push_back(info);
1917 
1918     NotificationBundleOption bundleOption;
1919     bundleOption.SetBundleName("bundleName");
1920     bundleOption.SetUid(100);
1921 
1922     std::vector<NotificationBundleOption> trustList;
1923     trustList.push_back(bundleOption);
1924     info->SetProfileTrustList(trustList);
1925 
1926 
1927     auto res = NotificationPreferences::GetInstance()->UpdateBatchCloneProfileInfo(
1928         100, infos);
1929     ASSERT_EQ(res, true);
1930 }
1931 
1932 /**
1933  * @tc.number    : UpdateBatchCloneBundleInfo_00100
1934  * @tc.name      :
1935  * @tc.desc      :
1936  */
1937 HWTEST_F(NotificationPreferencesTest, UpdateBatchCloneBundleInfo_00100, Function | SmallTest | Level1)
1938 {
1939     std::vector<NotificationCloneBundleInfo> cloneBundleInfos;
1940     NotificationCloneBundleInfo cloneBundleInfo;
1941     cloneBundleInfos.push_back(cloneBundleInfo);
1942     auto res = NotificationPreferences::GetInstance()->UpdateBatchCloneBundleInfo(
1943         100, cloneBundleInfos);
1944     ASSERT_EQ(res, true);
1945 
1946     std::vector<NotificationCloneBundleInfo> cloneBundleInfoRes;
1947     NotificationPreferences::GetInstance()->GetAllCloneBundleInfo(
1948         100, cloneBundleInfoRes);
1949     ASSERT_EQ(cloneBundleInfoRes.size(), cloneBundleInfos.size());
1950 
1951     std::vector<sptr<NotificationDoNotDisturbProfile>> profilesInfos;
1952     NotificationPreferences::GetInstance()->GetAllCloneProfileInfo(
1953         100, profilesInfos);
1954     ASSERT_EQ(0, profilesInfos.size());
1955 }
1956 
1957 /**
1958  * @tc.number    : DelCloneBundleInfo_00100
1959  * @tc.name      :
1960  * @tc.desc      :
1961  */
1962 HWTEST_F(NotificationPreferencesTest, DelCloneBundleInfo_00100, Function | SmallTest | Level1)
1963 {
1964     NotificationCloneBundleInfo cloneBundleInfo;
1965     auto res = NotificationPreferences::GetInstance()->DelCloneBundleInfo(
1966         100, cloneBundleInfo);
1967     ASSERT_EQ(res, true);
1968 }
1969 
1970 /**
1971  * @tc.number    : DelBatchCloneProfileInfo_00100
1972  * @tc.name      :
1973  * @tc.desc      :
1974  */
1975 HWTEST_F(NotificationPreferencesTest, DelBatchCloneProfileInfo_00100, Function | SmallTest | Level1)
1976 {
1977     sptr<NotificationDoNotDisturbProfile> profileInfo(new NotificationDoNotDisturbProfile());
1978 
1979     std::vector<sptr<NotificationDoNotDisturbProfile>> profileInfos;
1980     profileInfos.push_back(profileInfo);
1981 
1982     auto res = NotificationPreferences::GetInstance()->DelBatchCloneProfileInfo(
1983         100, profileInfos);
1984     ASSERT_EQ(res, true);
1985 }
1986 
1987 /**
1988  * @tc.number    : GetAllLiveViewEnabledBundles_00100
1989  * @tc.name      :
1990  * @tc.desc      :
1991  */
1992 HWTEST_F(NotificationPreferencesTest, GetAllLiveViewEnabledBundles_00100, Function | SmallTest | Level1)
1993 {
1994     std::vector<NotificationBundleOption> bundleOption;
1995     auto res = NotificationPreferences::GetInstance()->GetAllLiveViewEnabledBundles(
1996         100, bundleOption);
1997     ASSERT_EQ(res, ERR_OK);
1998 }
1999 
2000 /**
2001  * @tc.number    : GetAllDistribuedEnabledBundles_00100
2002  * @tc.name      :
2003  * @tc.desc      :
2004  */
2005 HWTEST_F(NotificationPreferencesTest, GetAllDistribuedEnabledBundles_00100, Function | SmallTest | Level1)
2006 {
2007     std::vector<NotificationBundleOption> bundleOption;
2008     std::string deviceType = "testType";
2009     auto res = NotificationPreferences::GetInstance()->GetAllDistribuedEnabledBundles(
2010         100, deviceType, bundleOption);
2011     ASSERT_EQ(res, ERR_OK);
2012 }
2013 
2014 /**
2015  * @tc.number    : SetHashCodeRule_00100
2016  * @tc.name      :
2017  * @tc.desc      :
2018  */
2019 HWTEST_F(NotificationPreferencesTest, SetHashCodeRule_00100, Function | SmallTest | Level1)
2020 {
2021     auto res = NotificationPreferences::GetInstance()->SetHashCodeRule(
2022         100, 1);
2023     ASSERT_EQ(res, ERR_OK);
2024 }
2025 
2026 /**
2027  * @tc.name: AddDoNotDisturbProfiles_0400
2028  * @tc.desc:
2029  * @tc.type:
2030  */
2031 HWTEST_F(NotificationPreferencesTest, AddDoNotDisturbProfiles_0400, TestSize.Level1)
2032 {
2033     NotificationPreferences notificationPreferences;
2034 
2035     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
2036     profiles.emplace_back(nullptr);
2037     int32_t userId = 1;
2038     auto res = notificationPreferences.AddDoNotDisturbProfiles(userId, profiles);
2039     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2040     profiles.clear();
2041 
2042     sptr<NotificationDoNotDisturbProfile> profile(new (std::nothrow) NotificationDoNotDisturbProfile());
2043     profile->SetProfileId(1);
2044 
2045     std::vector<NotificationBundleOption> trustList;
2046     NotificationBundleOption bundle;
2047     bundle.SetBundleName("test");
2048     bundle.SetUid(100);
2049     profile->SetProfileTrustList(trustList);
2050     profiles.emplace_back(profile);
2051 
2052     notificationPreferences.preferncesDB_ = nullptr;
2053     res = notificationPreferences.AddDoNotDisturbProfiles(userId, profiles);
2054     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2055 }
2056 
2057 /**
2058  * @tc.name: IsNotificationSlotFlagsExists_0400
2059  * @tc.desc:
2060  * @tc.type:
2061  */
2062 HWTEST_F(NotificationPreferencesTest, IsNotificationSlotFlagsExists_0400, TestSize.Level1)
2063 {
2064     auto res = NotificationPreferences::GetInstance()->IsNotificationSlotFlagsExists(nullptr);
2065     ASSERT_FALSE(res);
2066 }
2067 
2068 /**
2069  * @tc.name: RemoveDoNotDisturbProfiles_0400
2070  * @tc.desc:
2071  * @tc.type:
2072  */
2073 HWTEST_F(NotificationPreferencesTest, RemoveDoNotDisturbProfiles_0400, TestSize.Level1)
2074 {
2075     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
2076     profiles.emplace_back(nullptr);
2077     int32_t userId = 1;
2078     NotificationPreferences notificationPreferences;
2079     auto res = notificationPreferences.RemoveDoNotDisturbProfiles(userId, profiles);
2080     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2081     profiles.clear();
2082 
2083     notificationPreferences.preferncesDB_ = nullptr;
2084     res = notificationPreferences.RemoveDoNotDisturbProfiles(userId, profiles);
2085     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2086 }
2087 
2088 /**
2089  * @tc.number    : RemoveNotificationAllSlots_00400
2090  * @tc.name      : RemoveNotificationAllSlots
2091  * @tc.require   :
2092  */
2093 HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00400, Function | SmallTest | Level1)
2094 {
2095     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2096     std::vector<sptr<NotificationSlot>> slots;
2097     slots.push_back(slot);
2098 
2099     NotificationPreferences notificationPreferences;
2100     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2101     ASSERT_EQ(res, ERR_OK);
2102 
2103     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2104     res = notificationPreferences.RemoveNotificationAllSlots(bundleOption_);
2105     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2106 }
2107 
2108 
2109 /**
2110  * @tc.number    : AddNotificationBundleProperty_00400
2111  * @tc.name      : AddNotificationBundleProperty
2112  * @tc.require   :
2113  */
2114 HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00400, Function | SmallTest | Level1)
2115 {
2116     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2117     std::vector<sptr<NotificationSlot>> slots;
2118     slots.push_back(slot);
2119 
2120     NotificationPreferences notificationPreferences;
2121     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2122     ASSERT_EQ(res, ERR_OK);
2123 
2124     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2125     res = notificationPreferences.AddNotificationBundleProperty(bundleOption_);
2126     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2127 }
2128 
2129 /**
2130  * @tc.number    : SetDoNotDisturbDate_00300
2131  * @tc.name      :
2132  * @tc.desc      :
2133  */
2134 HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00300, Function | SmallTest | Level1)
2135 {
2136     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
2137     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2138     int64_t beginDate = beginDuration.count();
2139     timePoint += std::chrono::hours(1);
2140     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
2141     int64_t endDate = endDuration.count();
2142     sptr<NotificationDoNotDisturbDate> date =
2143         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
2144 
2145     NotificationPreferences notificationPreferences;
2146     auto res = notificationPreferences.SetDoNotDisturbDate(SYSTEM_APP_UID, date);
2147     ASSERT_EQ(res, ERR_OK);
2148     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2149     res = notificationPreferences.SetDoNotDisturbDate(SYSTEM_APP_UID, date);
2150     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2151 }
2152 
2153 /**
2154  * @tc.number    : UpdateNotificationSlots_00700
2155  * @tc.name      :
2156  * @tc.desc      :
2157  */
2158 HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00700, Function | SmallTest | Level1)
2159 {
2160     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2161     std::vector<sptr<NotificationSlot>> slots;
2162     slots.push_back(slot);
2163 
2164     NotificationPreferences notificationPreferences;
2165     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2166     ASSERT_EQ(res, ERR_OK);
2167     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2168     std::string des("This is a description.");
2169     slot->SetDescription(des);
2170     slots.clear();
2171     slots.push_back(slot);
2172     res = notificationPreferences.UpdateNotificationSlots(bundleOption_, slots);
2173     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2174 }
2175 
2176 /**
2177  * @tc.number    : SetNotificationSlotFlagsForBundle_00100
2178  * @tc.name      :
2179  * @tc.desc      :
2180  */
2181 HWTEST_F(NotificationPreferencesTest, SetNotificationSlotFlagsForBundle_00100, Function | SmallTest | Level1)
2182 {
2183     auto res = NotificationPreferences::GetInstance()->SetNotificationSlotFlagsForBundle(nullptr, 63);
2184     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2185 }
2186 
2187 
2188 /**
2189  * @tc.number    : AddNotificationSlots_00700
2190  * @tc.name      :
2191  * @tc.desc      :
2192  */
2193 HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00700, Function | SmallTest | Level1)
2194 {
2195     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2196     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION);
2197     std::vector<sptr<NotificationSlot>> slots;
2198     slots.push_back(slot1);
2199     slots.push_back(slot2);
2200     NotificationPreferences notificationPreferences;
2201     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2202     ASSERT_EQ(res, ERR_OK);
2203     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2204     res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2205     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2206 }
2207 
2208 /**
2209  * @tc.number    : RemoveNotificationSlot_00600
2210  * @tc.name      :
2211  * @tc.desc      :
2212  */
2213 HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00600, Function | SmallTest | Level1)
2214 {
2215     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2216     std::vector<sptr<NotificationSlot>> slots;
2217     slots.push_back(slot);
2218 
2219     NotificationPreferences notificationPreferences;
2220     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2221     ASSERT_EQ(res, ERR_OK);
2222 
2223     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2224     res = notificationPreferences.RemoveNotificationSlot(bundleOption_,
2225         NotificationConstant::SlotType::OTHER);
2226     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2227 }
2228 
2229 /**
2230  * @tc.number    : RemoveNotificationForBundle_00500
2231  * @tc.name      :
2232  * @tc.desc      :
2233  */
2234 HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00500, Function | SmallTest | Level1)
2235 {
2236     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::OTHER);
2237     std::vector<sptr<NotificationSlot>> slots;
2238     slots.push_back(slot);
2239 
2240     NotificationPreferences notificationPreferences;
2241     auto res = notificationPreferences.AddNotificationSlots(bundleOption_, slots);
2242     ASSERT_EQ(res, ERR_OK);
2243 
2244     notificationPreferences.preferncesDB_->rdbDataManager_ = nullptr;
2245     res = notificationPreferences.RemoveNotificationForBundle(bundleOption_);
2246     ASSERT_EQ(res, ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED);
2247 }
2248 
2249 /**
2250  * @tc.name: NullDeviceTypeTest_001
2251  * @tc.desc: Test NullDeviceType
2252  * 1. Declare a string variable deviceType and leave it empty
2253  * 2. Call the SetDistributedEnabledBySlot/IsDistributedEnabledBySlot/SetSubscriberExistFlag/GetSubscriberExistFlag
2254  * 3. Assert that res is equal to ERR_ANS_INVALID_PARAM
2255  * @tc.type: FUNC
2256  */
2257 HWTEST_F(NotificationPreferencesTest, NullDeviceTypeTest_001, Function | SmallTest | Level1)
2258 {
2259     int32_t res;
2260     bool flag = true;
2261     std::string deviceType = "";
2262     NotificationPreferences notificationPreferences;
2263     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
2264 
2265     res = notificationPreferences.SetDistributedEnabledBySlot(slotType, deviceType, flag);
2266     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2267     res = notificationPreferences.IsDistributedEnabledBySlot(slotType, deviceType, flag);
2268     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2269     res = notificationPreferences.SetSubscriberExistFlag(deviceType, flag);
2270     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2271     res = notificationPreferences.GetSubscriberExistFlag(deviceType, flag);
2272     ASSERT_EQ(res, ERR_ANS_INVALID_PARAM);
2273 }
2274 
2275 /**
2276  * @tc.name: NullPreferncesDBTest_001
2277  * @tc.desc: Test preferncesDB_
2278  * 1. Create an instance of NotificationPreferences and set preferncesDB_ to nullptr
2279  * 2. Call the related methods
2280  * 3. Assert that the result is as expected
2281  * @tc.type: FUNC
2282  */
2283  HWTEST_F(NotificationPreferencesTest, NullPreferncesDBTest_001, TestSize.Level1)
2284 {
2285     int32_t res;
2286     std::string resStr;
2287     std::string key = "notification";
2288     std::vector<std::string> keys;
2289     std::string value = "test";
2290     std::vector<uint8_t> vecValue;
2291     std::unordered_map<std::string, std::string> mapValue;
2292     int32_t userId = 101;
2293     NotificationPreferences notificationPreferences;
2294     notificationPreferences.preferncesDB_ = nullptr;
2295     sptr<NotificationDoNotDisturbProfile> info(new NotificationDoNotDisturbProfile());
2296     info->SetProfileId(1);
2297     info->SetProfileName("test");
2298 
2299     res = notificationPreferences.SetKvToDb(key, value, userId);
2300     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2301 
2302     res = notificationPreferences.SetByteToDb(key, vecValue, userId);
2303     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2304 
2305     res = notificationPreferences.GetKvFromDb(key, value, userId);
2306     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2307 
2308     res = notificationPreferences.GetByteFromDb(key, vecValue, userId);
2309     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2310 
2311     res = notificationPreferences.GetBatchKvsFromDbContainsKey(key, mapValue, userId);
2312     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2313 
2314     res = notificationPreferences.GetBatchKvsFromDb(key, mapValue, userId);
2315     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2316 
2317     res = notificationPreferences.DeleteKvFromDb(key, userId);
2318     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2319 
2320     res = notificationPreferences.DeleteBatchKvFromDb(keys, userId);
2321     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2322 
2323     resStr = notificationPreferences.GetAdditionalConfig(key);
2324     ASSERT_EQ(resStr.size(), 0);
2325 
2326     res = notificationPreferences.DelCloneProfileInfo(userId, info);
2327     ASSERT_EQ(res, false);
2328 }
2329 /**
2330  * @tc.name: NullPreferncesDBTest_002
2331  * @tc.desc: Test preferncesDB_
2332  * 1. Create an instance of NotificationPreferences and set preferncesDB_ to nullptr
2333  * 2. Call the related methods
2334  * 3. Assert that the result is as expected
2335  * @tc.type: FUNC
2336  */
2337 HWTEST_F(NotificationPreferencesTest, NullPreferncesDBTest_002, TestSize.Level1)
2338 {
2339     int32_t res;
2340     bool flag = true;
2341     int32_t userId = 101;
2342     NotificationPreferences notificationPreferences;
2343     notificationPreferences.preferncesDB_ = nullptr;
2344     std::vector<NotificationCloneBundleInfo> cloneBundleInfos;
2345     NotificationCloneBundleInfo cloneBundleInfo;
2346     std::vector<sptr<NotificationDoNotDisturbProfile>> infos;
2347     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
2348     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
2349     cloneBundleInfos.push_back(cloneBundleInfo);
2350     NotificationDisable disable;
2351     sptr<NotificationDisable> notificationDisable = new (std::nothrow) NotificationDisable();
2352     notificationDisable->SetDisabled(true);
2353     notificationDisable->SetBundleList({ "com.example.app" });
2354 
2355     res = notificationPreferences.UpdateBatchCloneProfileInfo(userId, infos);
2356     ASSERT_EQ(res, false);
2357 
2358     notificationPreferences.GetAllCloneProfileInfo(userId, infos);
2359     notificationPreferences.GetAllCloneBundleInfo(userId, cloneBundleInfos);
2360 
2361     res = notificationPreferences.UpdateBatchCloneBundleInfo(userId, cloneBundleInfos);
2362     ASSERT_EQ(res, false);
2363 
2364     res = notificationPreferences.DelCloneBundleInfo(userId, cloneBundleInfo);
2365     ASSERT_EQ(res, false);
2366 
2367     res = notificationPreferences.DelBatchCloneProfileInfo(userId, infos);
2368     ASSERT_EQ(res, false);
2369 
2370     res = notificationPreferences.DelBatchCloneBundleInfo(userId, cloneBundleInfos);
2371     ASSERT_EQ(res, false);
2372 
2373     res = notificationPreferences.GetDisableNotificationInfo(disable);
2374     ASSERT_EQ(res, false);
2375 
2376     res = notificationPreferences.SetDisableNotificationInfo(notificationDisable);
2377     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2378 
2379     res = notificationPreferences.SetSubscriberExistFlag(DEVICE_TYPE_HEADSET, flag);
2380     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2381 
2382     res = notificationPreferences.GetSubscriberExistFlag(DEVICE_TYPE_HEADSET, flag);
2383     ASSERT_EQ(res, ERR_ANS_SERVICE_NOT_READY);
2384 
2385     res = notificationPreferences.GetBundleRemoveFlag(bundleOption, slotType, 0);
2386     ASSERT_EQ(res, true);
2387 
2388     res = notificationPreferences.SetBundleRemoveFlag(bundleOption, slotType, 0);
2389     ASSERT_EQ(res, false);
2390 }
2391 
2392 /**
2393  * @tc.name: GetBundleRemoveFlag_001
2394  * @tc.desc: Test GetBundleRemoveFlag And SetBundleRemoveFlag
2395  * 1. Calls SetBundleRemoveFlag with bundleOption, slotType and sourceType, expects the result to be true
2396  * 2. Calls GetBundleRemoveFlag with the same paras to retrieve the previously set flag, expects the result to be true
2397  * @tc.type: FUNC
2398  */
2399 HWTEST_F(NotificationPreferencesTest, GetBundleRemoveFlag_001, Function | SmallTest | Level1)
2400 {
2401     int32_t res;
2402     NotificationPreferences notificationPreferences;
2403     sptr<NotificationBundleOption> bundleOption(new NotificationBundleOption("bundleName", 1));
2404     NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW;
2405 
2406     res = notificationPreferences.SetBundleRemoveFlag(bundleOption, slotType, 0);
2407     ASSERT_EQ(res, true);
2408 
2409     res = notificationPreferences.GetBundleRemoveFlag(bundleOption, slotType, 0);
2410     ASSERT_EQ(res, true);
2411 }
2412 
2413 /**
2414  * @tc.name: SetKioskModeStatus_001
2415  * @tc.desc: Test SetKioskModeStatus
2416  * @tc.type: FUNC
2417  */
2418 HWTEST_F(NotificationPreferencesTest, SetKioskModeStatus_001, Function | SmallTest | Level1)
2419 {
2420     bool isKioskMode = true;
2421     NotificationPreferences notificationPreferences;
2422     notificationPreferences.SetKioskModeStatus(isKioskMode);
2423     ASSERT_EQ(notificationPreferences.isKioskMode_, true);
2424 }
2425 
2426 /**
2427  * @tc.name: IsKioskMode_001
2428  * @tc.desc: Test IsKioskMode
2429  * @tc.type: FUNC
2430  */
2431 HWTEST_F(NotificationPreferencesTest, IsKioskMode_001, Function | SmallTest | Level1)
2432 {
2433     NotificationPreferences notificationPreferences;
2434     notificationPreferences.isKioskMode_ = true;
2435     auto ret = notificationPreferences.IsKioskMode();
2436     ASSERT_EQ(ret, true);
2437     notificationPreferences.isKioskMode_ = false;
2438     ret = notificationPreferences.IsKioskMode();
2439     ASSERT_EQ(ret, false);
2440 }
2441 
2442 /**
2443  * @tc.name: GetkioskAppTrustList_001
2444  * @tc.desc: Test GetkioskAppTrustList
2445  * @tc.type: FUNC
2446  */
2447 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_001, Function | SmallTest | Level1)
2448 {
2449     NotificationPreferences notificationPreferences;
2450     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2451     notificationPreferences.isKioskTrustListUpdate_ = false;
2452     std::vector<std::string> kioskAppTrustList;
2453     kioskAppTrustList.push_back("testBundleName1");
2454     kioskAppTrustList.push_back("testBundleName2");
2455     notificationPreferences.preferencesInfo_.SetkioskAppTrustList(kioskAppTrustList);
2456     std::vector<std::string> resultList;
2457     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2458     ASSERT_EQ(ret, true);
2459 }
2460 
2461 /**
2462  * @tc.name: GetkioskAppTrustList_002
2463  * @tc.desc: Test GetkioskAppTrustList
2464  * @tc.type: FUNC
2465  */
2466 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_002, Function | SmallTest | Level1)
2467 {
2468     NotificationPreferences notificationPreferences;
2469     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2470     std::vector<std::string> resultList;
2471     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2472     ASSERT_EQ(ret, false);
2473 }
2474 
2475 /**
2476  * @tc.name: GetkioskAppTrustList_003
2477  * @tc.desc: Test GetkioskAppTrustList
2478  * @tc.type: FUNC
2479  */
2480 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_003, Function | SmallTest | Level1)
2481 {
2482     NotificationPreferences notificationPreferences;
2483     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2484 
2485     std::string key = "kiosk_app_trust_list";
2486     std::string value = "";
2487     int32_t userId = -1;
2488     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2489     ASSERT_EQ(result, ERR_OK);
2490     std::vector<std::string> resultList;
2491     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2492     ASSERT_EQ(ret, false);
2493 }
2494 
2495 /**
2496  * @tc.name: GetkioskAppTrustList_004
2497  * @tc.desc: Test GetkioskAppTrustList
2498  * @tc.type: FUNC
2499  */
2500 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_004, Function | SmallTest | Level1)
2501 {
2502     NotificationPreferences notificationPreferences;
2503     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2504 
2505     std::string key = "kiosk_app_trust_list";
2506     std::string value = "invalid json string";
2507     int32_t userId = -1;
2508     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2509     ASSERT_EQ(result, ERR_OK);
2510     std::vector<std::string> resultList;
2511     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2512     ASSERT_EQ(ret, false);
2513 }
2514 
2515 /**
2516  * @tc.name: GetkioskAppTrustList_005
2517  * @tc.desc: Test GetkioskAppTrustList
2518  * @tc.type: FUNC
2519  */
2520 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_005, Function | SmallTest | Level1)
2521 {
2522     NotificationPreferences notificationPreferences;
2523     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2524 
2525     std::string key = "kiosk_app_trust_list";
2526     std::string value = "null";
2527     int32_t userId = -1;
2528     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2529     ASSERT_EQ(result, ERR_OK);
2530     std::vector<std::string> resultList;
2531     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2532     ASSERT_EQ(ret, false);
2533 }
2534 
2535 /**
2536  * @tc.name: GetkioskAppTrustList_006
2537  * @tc.desc: Test GetkioskAppTrustList
2538  * @tc.type: FUNC
2539  */
2540 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_006, Function | SmallTest | Level1)
2541 {
2542     NotificationPreferences notificationPreferences;
2543     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2544 
2545     std::string key = "kiosk_app_trust_list";
2546     std::string value = "[]";
2547     int32_t userId = -1;
2548     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2549     ASSERT_EQ(result, ERR_OK);
2550     std::vector<std::string> resultList;
2551     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2552     ASSERT_EQ(ret, false);
2553 }
2554 
2555 /**
2556  * @tc.name: GetkioskAppTrustList_007
2557  * @tc.desc: Test GetkioskAppTrustList
2558  * @tc.type: FUNC
2559  */
2560 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_007, Function | SmallTest | Level1)
2561 {
2562     NotificationPreferences notificationPreferences;
2563     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2564 
2565     std::string key = "kiosk_app_trust_list";
2566     std::string value = R"({"key": "value"})";
2567     int32_t userId = -1;
2568     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2569     ASSERT_EQ(result, ERR_OK);
2570     std::vector<std::string> resultList;
2571     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2572     ASSERT_EQ(ret, false);
2573 }
2574 
2575 /**
2576  * @tc.name: GetkioskAppTrustList_008
2577  * @tc.desc: Test GetkioskAppTrustList
2578  * @tc.type: FUNC
2579  */
2580 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_008, Function | SmallTest | Level1)
2581 {
2582     NotificationPreferences notificationPreferences;
2583     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2584 
2585     std::string key = "kiosk_app_trust_list";
2586     std::string value = R"(["com.example.app1", "com.example.app2", "com.example.app3"])";
2587     int32_t userId = -1;
2588     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2589     ASSERT_EQ(result, ERR_OK);
2590     std::vector<std::string> resultList;
2591     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2592     ASSERT_EQ(ret, true);
2593 }
2594 
2595 /**
2596  * @tc.name: GetkioskAppTrustList_009
2597  * @tc.desc: Test GetkioskAppTrustList
2598  * @tc.type: FUNC
2599  */
2600 HWTEST_F(NotificationPreferencesTest, GetkioskAppTrustList_009, Function | SmallTest | Level1)
2601 {
2602     NotificationPreferences notificationPreferences;
2603     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2604     notificationPreferences.isKioskTrustListUpdate_ = false;
2605 
2606     std::string key = "kiosk_app_trust_list";
2607     std::string value = R"(["com.example.app1", "com.example.app2", "com.example.app3"])";
2608     int32_t userId = -1;
2609     auto result = notificationPreferences.SetKvToDb(key, value, userId);
2610     ASSERT_EQ(result, ERR_OK);
2611     ASSERT_EQ(notificationPreferences.isKioskTrustListUpdate_, true);
2612     std::vector<std::string> resultList;
2613     auto ret = notificationPreferences.GetkioskAppTrustList(resultList);
2614     ASSERT_EQ(ret, true);
2615 }
2616 
2617 /**
2618  * @tc.name: GetUserDisableNotificationInfo_001
2619  * @tc.desc: test GetUserDisableNotificationInfo.
2620  * @tc.type: FUNC
2621  */
2622 HWTEST_F(NotificationPreferencesTest, GetUserDisableNotificationInfo_001, Function | SmallTest | Level1)
2623 {
2624     NotificationPreferences notificationPreferences;
2625     notificationPreferences.preferencesInfo_ = NotificationPreferencesInfo();
2626     NotificationDisable disable;
2627     bool ret = NotificationPreferences::GetInstance()->GetUserDisableNotificationInfo(105, disable);
2628     EXPECT_FALSE(ret);
2629     notificationPreferences.preferncesDB_ = nullptr;
2630     ret = notificationPreferences.GetUserDisableNotificationInfo(105, disable);
2631     EXPECT_FALSE(ret);
2632 }
2633 }  // namespace Notification
2634 }  // namespace OHOS
2635