1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #define private public
17 #include <gtest/gtest.h>
18 
19 #define private public
20 #define protected public
21 #include "notification_preferences_database.h"
22 #include "notification_rdb_data_mgr.h"
23 #undef private
24 #undef protected
25 
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace Notification {
29 class NotificationPreferencesDatabaseTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {};
TearDownTestCase()32     static void TearDownTestCase() {};
SetUp()33     void SetUp() {};
TearDown()34     void TearDown() {};
35 
36     const std::string bundleName_ = "bundleName";
37     const int bundleUid_ = 2001;
38     int32_t userId = 100;
39     std::unique_ptr<NotificationPreferencesDatabase> preferncesDB_ =
40         std::make_unique<NotificationPreferencesDatabase>();
41 };
42 
43 /**
44  * @tc.name      : PutSlotsToDisturbeDB_00100
45  * @tc.number    :
46  * @tc.desc      : Put slots into Disturbe DB, return is true.
47  */
48 HWTEST_F(NotificationPreferencesDatabaseTest, PutSlotsToDisturbeDB_00100, Function | SmallTest | Level1)
49 {
50     std::vector<sptr<NotificationSlot>> slots;
51     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
52     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
53     slots.push_back(slot1);
54     slots.push_back(slot2);
55     EXPECT_TRUE(preferncesDB_->PutSlotsToDisturbeDB(bundleName_, bundleUid_, slots));
56 }
57 
58 /**
59  * @tc.name      : PutSlotsToDisturbeDB_00200
60  * @tc.number    :
61  * @tc.desc      : Put slots into Disturbe DB when bundle name is null, return is true.
62  */
63 HWTEST_F(NotificationPreferencesDatabaseTest, PutSlotsToDisturbeDB_00200, Function | SmallTest | Level1)
64 {
65     std::vector<sptr<NotificationSlot>> slots;
66     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
67     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
68     slots.push_back(slot1);
69     slots.push_back(slot2);
70     EXPECT_FALSE(preferncesDB_->PutSlotsToDisturbeDB(std::string(), 0, slots));
71 }
72 
73 /**
74  * @tc.name      : PutSlotsToDisturbeDB_00300
75  * @tc.number    :
76  * @tc.desc      : Put slots into Disturbe DB when slots is null, return is false.
77  */
78 HWTEST_F(NotificationPreferencesDatabaseTest, PutSlotsToDisturbeDB_00300, Function | SmallTest | Level1)
79 {
80     std::vector<sptr<NotificationSlot>> slots;
81     EXPECT_FALSE(preferncesDB_->PutSlotsToDisturbeDB(bundleName_, bundleUid_, slots));
82 }
83 
84 /**
85  * @tc.name      : PutShowBadge_00100
86  * @tc.number    :
87  * @tc.desc      : Put bundle show badge into disturbe DB, return is true.
88  */
89 HWTEST_F(NotificationPreferencesDatabaseTest, PutShowBadge_00100, Function | SmallTest | Level1)
90 {
91     NotificationPreferencesInfo::BundleInfo bundleInfo;
92     bundleInfo.SetBundleName(bundleName_);
93     bundleInfo.SetBundleUid(bundleUid_);
94     EXPECT_TRUE(preferncesDB_->PutShowBadge(bundleInfo, true));
95     EXPECT_TRUE(preferncesDB_->PutShowBadge(bundleInfo, false));
96 }
97 
98 /**
99  * @tc.number    : PutShowBadge_00200
100  * @tc.name      :
101  * @tc.desc      : Put bundle show badge into disturbe DB when bundle name is null, return is false.
102  */
103 HWTEST_F(NotificationPreferencesDatabaseTest, PutShowBadge_00200, Function | SmallTest | Level1)
104 {
105     NotificationPreferencesInfo::BundleInfo bundleInfo;
106     bundleInfo.SetBundleName(std::string());
107     EXPECT_FALSE(preferncesDB_->PutShowBadge(bundleInfo, false));
108 }
109 
110 /**
111  * @tc.name      : PutImportance_00100
112  * @tc.number    :
113  * @tc.desc      : Put bundle importance into disturbe DB, return is true.
114  */
115 HWTEST_F(NotificationPreferencesDatabaseTest, PutImportance_00100, Function | SmallTest | Level1)
116 {
117     NotificationPreferencesInfo::BundleInfo bundleInfo;
118     bundleInfo.SetBundleName(bundleName_);
119     bundleInfo.SetBundleUid(bundleUid_);
120 
121     EXPECT_TRUE(
122         preferncesDB_->PutImportance(bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE));
123     EXPECT_TRUE(
124         preferncesDB_->PutImportance(bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_MIN));
125     EXPECT_TRUE(
126         preferncesDB_->PutImportance(bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_LOW));
127     EXPECT_TRUE(preferncesDB_->PutImportance(
128         bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_DEFAULT));
129     EXPECT_TRUE(
130         preferncesDB_->PutImportance(bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_HIGH));
131     EXPECT_TRUE(preferncesDB_->PutImportance(
132         bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_UNDEFINED));
133 }
134 
135 /**
136  * @tc.name      : PutImportance_00200
137  * @tc.number    :
138  * @tc.desc      : Put bundle importance into disturbe DB when bundle name is null, return is false.
139  */
140 HWTEST_F(NotificationPreferencesDatabaseTest, PutImportance_00200, Function | SmallTest | Level1)
141 {
142     NotificationPreferencesInfo::BundleInfo bundleInfo;
143     bundleInfo.SetBundleName(std::string());
144     bundleInfo.SetBundleUid(0);
145 
146     EXPECT_FALSE(
147         preferncesDB_->PutImportance(bundleInfo, OHOS::Notification::NotificationSlot::NotificationLevel::LEVEL_NONE));
148 }
149 
150 /**
151  * @tc.name      : PutTotalBadgeNums_00100
152  * @tc.number    :
153  * @tc.desc      : Put bundle total badge nums into disturbe DB, return is true.
154  */
155 HWTEST_F(NotificationPreferencesDatabaseTest, PutTotalBadgeNums_00100, Function | SmallTest | Level1)
156 {
157     NotificationPreferencesInfo::BundleInfo bundleInfo;
158     bundleInfo.SetBundleName(bundleName_);
159     bundleInfo.SetBundleUid(bundleUid_);
160     EXPECT_TRUE(preferncesDB_->PutTotalBadgeNums(bundleInfo, 0));
161 }
162 
163 /**
164  * @tc.number    : PutTotalBadgeNums_00200
165  * @tc.name      :
166  * @tc.desc      : Put bundle total badge nums into disturbe DB when bundle name is null, return is false.
167  */
168 HWTEST_F(NotificationPreferencesDatabaseTest, PutTotalBadgeNums_00200, Function | SmallTest | Level1)
169 {
170     NotificationPreferencesInfo::BundleInfo bundleInfo;
171     bundleInfo.SetBundleName(std::string());
172     bundleInfo.SetBundleUid(bundleUid_);
173     EXPECT_FALSE(preferncesDB_->PutTotalBadgeNums(bundleInfo, 0));
174 }
175 
176 /**
177  * @tc.name      : PutNotificationsEnabledForBundle_00100
178  * @tc.number    :
179  * @tc.desc      : Put bundle enable into disturbe DB, return is true.
180  */
181 HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabledForBundle_00100, Function | SmallTest | Level1)
182 {
183     NotificationPreferencesInfo::BundleInfo bundleInfo;
184     bundleInfo.SetBundleName(bundleName_);
185     bundleInfo.SetBundleUid(bundleUid_);
186     EXPECT_TRUE(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, true));
187     EXPECT_TRUE(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, false));
188 }
189 
190 /**
191  * @tc.name      : PutNotificationsEnabledForBundle_00200
192  * @tc.number    :
193  * @tc.desc      : Put bundle enable into disturbe DB when bundle name is null, return is false.
194  */
195 HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabledForBundle_00200, Function | SmallTest | Level1)
196 {
197     NotificationPreferencesInfo::BundleInfo bundleInfo;
198     bundleInfo.SetBundleName(std::string());
199     bundleInfo.SetBundleUid(bundleUid_);
200     EXPECT_FALSE(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, false));
201 }
202 
203 /**
204  * @tc.number    : PutNotificationsEnabled_00100
205  * @tc.name      :
206  * @tc.desc      : Put notification enable into disturbe DB, return is true.
207  */
208 HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabled_00100, Function | SmallTest | Level1)
209 {
210     EXPECT_TRUE(preferncesDB_->PutNotificationsEnabled(userId, true));
211     EXPECT_TRUE(preferncesDB_->PutNotificationsEnabled(userId, false));
212 }
213 
214 /**
215  * @tc.number    : PutDoNotDisturbDate_00100
216  * @tc.name      :
217  * @tc.desc      : Put disturbe mode into disturbe DB when DoNotDisturbType is NONE, return is true.
218  */
219 HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00100, Function | SmallTest | Level1)
220 {
221     sptr<NotificationDoNotDisturbDate> date =
222         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0);
223     EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(userId, date));
224 }
225 
226 /**
227  * @tc.number    : PutDoNotDisturbDate_00200
228  * @tc.name      :
229  * @tc.desc      : Put disturbe mode into disturbe DB when DoNotDisturbType is ONCE, return is true.
230  */
231 HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00200, Function | SmallTest | Level1)
232 {
233     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
234     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
235     int64_t beginDate = beginDuration.count();
236     timePoint += std::chrono::hours(1);
237     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
238     int64_t endDate = endDuration.count();
239     sptr<NotificationDoNotDisturbDate> date =
240         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate);
241     EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(userId, date));
242 }
243 
244 /**
245  * @tc.number    : PutDoNotDisturbDate_00300
246  * @tc.name      :
247  * @tc.desc      : Put disturbe mode into disturbe DB when DoNotDisturbType is DAILY, return is true.
248  */
249 HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00300, Function | SmallTest | Level1)
250 {
251     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
252     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
253     int64_t beginDate = beginDuration.count();
254     timePoint += std::chrono::hours(1);
255     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
256     int64_t endDate = endDuration.count();
257     sptr<NotificationDoNotDisturbDate> date =
258         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate);
259 
260     EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(userId, date));
261 }
262 
263 /**
264  * @tc.number    : PutDoNotDisturbDate_00400
265  * @tc.name      :
266  * @tc.desc      : Put disturbe mode into disturbe DB when DoNotDisturbType is CLEARLY, return is true.
267  */
268 HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00400, Function | SmallTest | Level1)
269 {
270     std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now();
271     auto beginDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
272     int64_t beginDate = beginDuration.count();
273     timePoint += std::chrono::hours(1);
274     auto endDuration = std::chrono::duration_cast<std::chrono::milliseconds>(timePoint.time_since_epoch());
275     int64_t endDate = endDuration.count();
276     sptr<NotificationDoNotDisturbDate> date =
277         new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate);
278 
279     EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(userId, date));
280 }
281 
282 /**
283  * @tc.name      : RemoveAllDataFromDisturbeDB_00100
284  * @tc.number    :
285  * @tc.desc      : Remove all bundle info from disturbe DB, return is true.
286  */
287 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveAllDataFromDisturbeDB_00100, Function | SmallTest | Level1)
288 {
289     EXPECT_TRUE(preferncesDB_->RemoveAllDataFromDisturbeDB());
290 }
291 
292 /**
293  * @tc.name      : RemoveBundleFromDisturbeDB_00100
294  * @tc.number    :
295  * @tc.desc      : Remove a bundle info from disturbe DB, return is true.
296  */
297 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveBundleFromDisturbeDB_00100, Function | SmallTest | Level1)
298 {
299     NotificationPreferencesInfo::BundleInfo bundleInfo;
300     bundleInfo.SetBundleName(bundleName_);
301     bundleInfo.SetBundleUid(bundleUid_);
302     const int32_t uid = -1;
303     EXPECT_TRUE(preferncesDB_->PutTotalBadgeNums(bundleInfo, 0));
304     ASSERT_EQ(true, preferncesDB_->RemoveBundleFromDisturbeDB(bundleName_, uid));
305 }
306 
307 /**
308  * @tc.name      : RemoveBundleFromDisturbeDB_00200
309  * @tc.number    :
310  * @tc.desc      : Remove a bundle info from disturbe DB when bundle name is null, return is true.
311  */
312 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveBundleFromDisturbeDB_00200, Function | SmallTest | Level1)
313 {
314     const int32_t uid = -1;
315     ASSERT_EQ(true, preferncesDB_->RemoveBundleFromDisturbeDB(std::string(), uid));
316 }
317 
318 /**
319  * @tc.name      : RemoveSlotFromDisturbeDB_00100
320  * @tc.number    :
321  * @tc.desc      : Remove slot from disturbe DB, return is true.
322  */
323 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveSlotFromDisturbeDB_00100, Function | SmallTest | Level1)
324 {
325     std::vector<sptr<NotificationSlot>> slots;
326     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
327     slots.push_back(slot1);
328     EXPECT_TRUE(preferncesDB_->PutSlotsToDisturbeDB(bundleName_, bundleUid_, slots));
329     EXPECT_TRUE(preferncesDB_->RemoveSlotFromDisturbeDB(
330         bundleName_ + std::to_string(bundleUid_),
331         OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION, -1));
332 }
333 
334 /**
335  * @tc.name      : RemoveSlotFromDisturbeDB_00200
336  * @tc.number    :
337  * @tc.desc      : Remove slot from disturbe DB when bundle name is null, return is false
338  */
339 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveSlotFromDisturbeDB_00200, Function | SmallTest | Level1)
340 {
341     EXPECT_FALSE(preferncesDB_->RemoveSlotFromDisturbeDB(
342         std::string(), OHOS::Notification::NotificationConstant::SlotType::SOCIAL_COMMUNICATION, -1));
343 }
344 
345 /**
346  * @tc.name      : CheckKvStore_00100
347  * @tc.number    :
348  * @tc.desc      : Check disturbe DB is exsit, return is true.
349  */
350 HWTEST_F(NotificationPreferencesDatabaseTest, CheckKvStore_00100, Function | SmallTest | Level1)
351 {
352     EXPECT_TRUE(preferncesDB_->CheckRdbStore());
353 }
354 
355 /**
356  * @tc.name      : CheckKvStore_00200
357  * @tc.number    :
358  * @tc.desc      : Check disturbe DB is exsit, return is false.
359  */
360 HWTEST_F(NotificationPreferencesDatabaseTest, CheckKvStore_00300, Function | SmallTest | Level1)
361 {
362     EXPECT_TRUE(preferncesDB_->CheckRdbStore());
363     std::vector<sptr<NotificationSlot>> slots;
364     sptr<NotificationSlot> slot1 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
365     sptr<NotificationSlot> slot2 = new NotificationSlot(NotificationConstant::SlotType::SERVICE_REMINDER);
366     slots.push_back(slot1);
367     slots.push_back(slot2);
368     EXPECT_TRUE(preferncesDB_->PutSlotsToDisturbeDB(bundleName_, bundleUid_, slots));
369 }
370 
371 /**
372  * @tc.name      : PutBundlePropertyValueToDisturbeDB_00100
373  * @tc.number    :
374  * @tc.desc      : Put bundle property value to disturbeDB, return is true.
375  */
376 HWTEST_F(NotificationPreferencesDatabaseTest, PutBundlePropertyValueToDisturbeDB_00100, Function | SmallTest | Level1)
377 {
378     NotificationPreferencesInfo::BundleInfo info;
379     ASSERT_EQ(true, preferncesDB_->PutBundlePropertyValueToDisturbeDB(info));
380 }
381 
382 /**
383  * @tc.number    : ChangeSlotToEntry_00100
384  * @tc.name      :
385  * @tc.desc      : Change slot to entry.
386  */
387 HWTEST_F(NotificationPreferencesDatabaseTest, ChangeSlotToEntry_00100, Function | SmallTest | Level1)
388 {
389     sptr<NotificationSlot> slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION);
390     std::unordered_map<std::string, std::string> values;
391     EXPECT_TRUE(preferncesDB_->SlotToEntry(bundleName_, bundleUid_, slot, values));
392 }
393 
394 /**
395  * @tc.name      : CheckBundle_00100
396  * @tc.number    :
397  * @tc.desc      :Check bundle is exsit, return true when exsiting, create a bundle when does not exsit.
398  */
399 HWTEST_F(NotificationPreferencesDatabaseTest, CheckBundle_00100, Function | SmallTest | Level1)
400 {
401     ASSERT_EQ(true, preferncesDB_->CheckBundle(bundleName_, bundleUid_));
402 }
403 
404 /**
405  * @tc.number    : PutBundlePropertyToDisturbeDB_00100
406  * @tc.name      : PutBundlePropertyToDisturbeDB
407  * @tc.desc      : Test PutBundlePropertyToDisturbeDB function return is true
408  * @tc.require   : issueI5S4VP
409  */
410 HWTEST_F(NotificationPreferencesDatabaseTest, PutBundlePropertyToDisturbeDB_00100, Function | SmallTest | Level1)
411 {
412     NotificationPreferencesInfo::BundleInfo bundleInfo;
413     bundleInfo.SetBundleName(bundleName_);
414     bundleInfo.SetBundleUid(bundleUid_);
415     ASSERT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleInfo), false);
416 }
417 
418 /**
419  * @tc.number    : RemoveAllSlotsFromDisturbeDB_00100
420  * @tc.name      : RemoveAllSlotsFromDisturbeDB
421  * @tc.desc      : Test RemoveAllSlotsFromDisturbeDB function return is true
422  * @tc.require   : issueI5S4VP
423  */
424 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveAllSlotsFromDisturbeDB_00100, Function | SmallTest | Level1)
425 {
426     std::string bundleKey = "BundleKey";
427     ASSERT_EQ(preferncesDB_->RemoveAllSlotsFromDisturbeDB(bundleKey, -1), true);
428 }
429 
430 /**
431  * @tc.number    : RemoveNotificationEnable_00100
432  * @tc.name      : RemoveNotificationEnable
433  * @tc.desc      : Test RemoveNotificationEnable function when parameter is normal return is true
434  * @tc.require   : issueI5SR8J
435  */
436 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveNotificationEnable_00100, Function | SmallTest | Level1)
437 {
438     int32_t userId = 1;
439     ASSERT_EQ(preferncesDB_->RemoveNotificationEnable(userId), true);
440 }
441 
442 /**
443  * @tc.number    : RemoveDoNotDisturbDate_00100
444  * @tc.name      : RemoveDoNotDisturbDate
445  * @tc.desc      : Test RemoveDoNotDisturbDate function when parameter is normal return is true
446  * @tc.require   : issueI5SR8J
447  */
448 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbDate_00100, Function | SmallTest | Level1)
449 {
450     int32_t userId = 1;
451     ASSERT_EQ(preferncesDB_->RemoveDoNotDisturbDate(userId), true);
452 }
453 
454 /**
455  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00100
456  * @tc.name      : ParseBundlePropertyFromDisturbeDB
457  */
458 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00100, Function | SmallTest | Level1)
459 {
460     NotificationPreferencesInfo::BundleInfo bundleInfo;
461     bundleInfo.SetBundleName(bundleName_);
462     bundleInfo.SetBundleUid(bundleUid_);
463     std::string bundleKey = "bundleKey";
464     std::pair<std::string, std::string> entry;
465     entry.first = "ans_bundle_bundleKey_name";
466     entry.second = "1";
467     ASSERT_NE(nullptr, preferncesDB_);
468     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
469 }
470 
471 /**
472  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00200
473  * @tc.name      : ParseBundlePropertyFromDisturbeDB
474  */
475 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00200, Function | SmallTest | Level1)
476 {
477     NotificationPreferencesInfo::BundleInfo bundleInfo;
478     bundleInfo.SetBundleName(bundleName_);
479     bundleInfo.SetBundleUid(bundleUid_);
480     std::string bundleKey = "bundleKey";
481     std::pair<std::string, std::string> entry;
482     entry.first = "ans_bundle_bundleKey_importance";
483     entry.second = "1";
484     ASSERT_NE(nullptr, preferncesDB_);
485     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
486 }
487 
488 /**
489  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00300
490  * @tc.name      : ParseBundlePropertyFromDisturbeDB
491  */
492 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00300, Function | SmallTest | Level1)
493 {
494     NotificationPreferencesInfo::BundleInfo bundleInfo;
495     bundleInfo.SetBundleName(bundleName_);
496     bundleInfo.SetBundleUid(bundleUid_);
497     std::string bundleKey = "bundleKey";
498     std::pair<std::string, std::string> entry;
499     entry.first = "ans_bundle_bundleKey_showBadge";
500     entry.second = "1";
501     ASSERT_NE(nullptr, preferncesDB_);
502     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
503 }
504 
505 /**
506  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00400
507  * @tc.name      : ParseBundlePropertyFromDisturbeDB
508  */
509 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00400, Function | SmallTest | Level1)
510 {
511     NotificationPreferencesInfo::BundleInfo bundleInfo;
512     bundleInfo.SetBundleName(bundleName_);
513     bundleInfo.SetBundleUid(bundleUid_);
514     std::string bundleKey = "bundleKey";
515     std::pair<std::string, std::string> entry;
516     entry.first = "ans_bundle_bundleKey_badgeTotalNum";
517     entry.second = "1";
518     ASSERT_NE(nullptr, preferncesDB_);
519     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
520 }
521 
522 /**
523  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00500
524  * @tc.name      : ParseBundlePropertyFromDisturbeDB
525  */
526 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00500, Function | SmallTest | Level1)
527 {
528     NotificationPreferencesInfo::BundleInfo bundleInfo;
529     bundleInfo.SetBundleName(bundleName_);
530     bundleInfo.SetBundleUid(bundleUid_);
531     std::string bundleKey = "bundleKey";
532     std::pair<std::string, std::string> entry;
533     entry.first = "ans_bundle_bundleKey_privateAllowed";
534     entry.second = "1";
535     ASSERT_NE(nullptr, preferncesDB_);
536     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
537 }
538 
539 /**
540  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00600
541  * @tc.name      : ParseBundlePropertyFromDisturbeDB
542  */
543 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00600, Function | SmallTest | Level1)
544 {
545     NotificationPreferencesInfo::BundleInfo bundleInfo;
546     bundleInfo.SetBundleName(bundleName_);
547     bundleInfo.SetBundleUid(bundleUid_);
548     std::string bundleKey = "bundleKey";
549     std::pair<std::string, std::string> entry;
550     entry.first = "ans_bundle_bundleKey_enabledNotification";
551     entry.second = "1";
552     ASSERT_NE(nullptr, preferncesDB_);
553     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
554 }
555 
556 /**
557  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00700
558  * @tc.name      : ParseBundlePropertyFromDisturbeDB
559  */
560 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00700, Function | SmallTest | Level1)
561 {
562     NotificationPreferencesInfo::BundleInfo bundleInfo;
563     bundleInfo.SetBundleName(bundleName_);
564     bundleInfo.SetBundleUid(bundleUid_);
565     std::string bundleKey = "bundleKey";
566     std::pair<std::string, std::string> entry;
567     entry.first = "ans_bundle_bundleKey_poppedDialog";
568     entry.second = "1";
569     ASSERT_NE(nullptr, preferncesDB_);
570     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
571 }
572 
573 /**
574  * @tc.number    : ParseBundlePropertyFromDisturbeDB_00800
575  * @tc.name      : ParseBundlePropertyFromDisturbeDB
576  */
577 HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00800, Function | SmallTest | Level1)
578 {
579     NotificationPreferencesInfo::BundleInfo bundleInfo;
580     bundleInfo.SetBundleName(bundleName_);
581     bundleInfo.SetBundleUid(bundleUid_);
582     std::string bundleKey = "bundleKey";
583     std::pair<std::string, std::string> entry;
584     entry.first = "ans_bundle_bundleKey_uid";
585     entry.second = "1";
586     ASSERT_NE(nullptr, preferncesDB_);
587     preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry);
588 }
589 
590 /**
591  * @tc.number    : ParseSlotFromDisturbeDB_00100
592  * @tc.name      : ParseSlotFromDisturbeDB
593  */
594 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00100, Function | SmallTest | Level1)
595 {
596     NotificationPreferencesInfo::BundleInfo bundleInfo;
597     bundleInfo.SetBundleName(bundleName_);
598     bundleInfo.SetBundleUid(bundleUid_);
599     std::string bundleKey = "bundleKey";
600     std::pair<std::string, std::string> entry;
601     entry.first = "ans_bundle_bundleKey_slot_type_1_id";
602     entry.second = "1";
603     ASSERT_NE(nullptr, preferncesDB_);
604     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
605 }
606 
607 /**
608  * @tc.number    : ParseSlotFromDisturbeDB_00200
609  * @tc.name      : ParseSlotFromDisturbeDB
610  */
611 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00200, Function | SmallTest | Level1)
612 {
613     NotificationPreferencesInfo::BundleInfo bundleInfo;
614     bundleInfo.SetBundleName(bundleName_);
615     bundleInfo.SetBundleUid(bundleUid_);
616     std::string bundleKey = "bundleKey";
617     std::pair<std::string, std::string> entry;
618     entry.first = "ans_bundle_bundleKey_slot_type_1_name";
619     entry.second = "1";
620     ASSERT_NE(nullptr, preferncesDB_);
621     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
622 }
623 
624 /**
625  * @tc.number    : ParseSlotFromDisturbeDB_00300
626  * @tc.name      : ParseSlotFromDisturbeDB
627  */
628 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00300, Function | SmallTest | Level1)
629 {
630     NotificationPreferencesInfo::BundleInfo bundleInfo;
631     bundleInfo.SetBundleName(bundleName_);
632     bundleInfo.SetBundleUid(bundleUid_);
633     std::string bundleKey = "bundleKey";
634     std::pair<std::string, std::string> entry;
635     entry.first = "ans_bundle_bundleKey_slot_type_1_description";
636     entry.second = "1";
637     ASSERT_NE(nullptr, preferncesDB_);
638     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
639 }
640 
641 /**
642  * @tc.number    : ParseSlotFromDisturbeDB_00400
643  * @tc.name      : ParseSlotFromDisturbeDB
644  */
645 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00400, Function | SmallTest | Level1)
646 {
647     NotificationPreferencesInfo::BundleInfo bundleInfo;
648     bundleInfo.SetBundleName(bundleName_);
649     bundleInfo.SetBundleUid(bundleUid_);
650     std::string bundleKey = "bundleKey";
651     std::pair<std::string, std::string> entry;
652     entry.first = "ans_bundle_bundleKey_slot_type_1_level";
653     entry.second = "1";
654     ASSERT_NE(nullptr, preferncesDB_);
655     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
656 }
657 
658 /**
659  * @tc.number    : ParseSlotFromDisturbeDB_00500
660  * @tc.name      : ParseSlotFromDisturbeDB
661  */
662 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00500, Function | SmallTest | Level1)
663 {
664     NotificationPreferencesInfo::BundleInfo bundleInfo;
665     bundleInfo.SetBundleName(bundleName_);
666     bundleInfo.SetBundleUid(bundleUid_);
667     std::string bundleKey = "bundleKey";
668     std::pair<std::string, std::string> entry;
669     entry.first = "ans_bundle_bundleKey_slot_type_1_showBadge";
670     entry.second = "1";
671     ASSERT_NE(nullptr, preferncesDB_);
672     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
673 }
674 
675 /**
676  * @tc.number    : ParseSlotFromDisturbeDB_00600
677  * @tc.name      : ParseSlotFromDisturbeDB
678  */
679 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00600, Function | SmallTest | Level1)
680 {
681     NotificationPreferencesInfo::BundleInfo bundleInfo;
682     bundleInfo.SetBundleName(bundleName_);
683     bundleInfo.SetBundleUid(bundleUid_);
684     std::string bundleKey = "bundleKey";
685     std::pair<std::string, std::string> entry;
686     entry.first = "ans_bundle_bundleKey_slot_type_1_enableLight";
687     entry.second = "1";
688     ASSERT_NE(nullptr, preferncesDB_);
689     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
690 }
691 
692 /**
693  * @tc.number    : ParseSlotFromDisturbeDB_00700
694  * @tc.name      : ParseSlotFromDisturbeDB
695  */
696 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00700, Function | SmallTest | Level1)
697 {
698     NotificationPreferencesInfo::BundleInfo bundleInfo;
699     bundleInfo.SetBundleName(bundleName_);
700     bundleInfo.SetBundleUid(bundleUid_);
701     std::string bundleKey = "bundleKey";
702     std::pair<std::string, std::string> entry;
703     entry.first = "ans_bundle_bundleKey_slot_type_1_enableVibration";
704     entry.second = "1";
705     ASSERT_NE(nullptr, preferncesDB_);
706     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
707 }
708 
709 /**
710  * @tc.number    : ParseSlotFromDisturbeDB_00800
711  * @tc.name      : ParseSlotFromDisturbeDB
712  */
713 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00800, Function | SmallTest | Level1)
714 {
715     NotificationPreferencesInfo::BundleInfo bundleInfo;
716     bundleInfo.SetBundleName(bundleName_);
717     bundleInfo.SetBundleUid(bundleUid_);
718     std::string bundleKey = "bundleKey";
719     std::pair<std::string, std::string> entry;
720     entry.first = "ans_bundle_bundleKey_slot_type_1_ledLightColor";
721     entry.second = "1";
722     ASSERT_NE(nullptr, preferncesDB_);
723     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
724 }
725 
726 /**
727  * @tc.number    : ParseSlotFromDisturbeDB_00900
728  * @tc.name      : ParseSlotFromDisturbeDB
729  */
730 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_00900, Function | SmallTest | Level1)
731 {
732     NotificationPreferencesInfo::BundleInfo bundleInfo;
733     bundleInfo.SetBundleName(bundleName_);
734     bundleInfo.SetBundleUid(bundleUid_);
735     std::string bundleKey = "bundleKey";
736     std::pair<std::string, std::string> entry;
737     entry.first = "ans_bundle_bundleKey_slot_type_1_lockscreenVisibleness";
738     entry.second = "1";
739     ASSERT_NE(nullptr, preferncesDB_);
740     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
741 }
742 
743 /**
744  * @tc.number    : ParseSlotFromDisturbeDB_01000
745  * @tc.name      : ParseSlotFromDisturbeDB
746  */
747 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01000, Function | SmallTest | Level1)
748 {
749     NotificationPreferencesInfo::BundleInfo bundleInfo;
750     bundleInfo.SetBundleName(bundleName_);
751     bundleInfo.SetBundleUid(bundleUid_);
752     std::string bundleKey = "bundleKey";
753     std::pair<std::string, std::string> entry;
754     entry.first = "ans_bundle_bundleKey_slot_type_1_sound";
755     entry.second = "1";
756     ASSERT_NE(nullptr, preferncesDB_);
757     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
758 }
759 
760 /**
761  * @tc.number    : ParseSlotFromDisturbeDB_01100
762  * @tc.name      : ParseSlotFromDisturbeDB
763  */
764 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01100, Function | SmallTest | Level1)
765 {
766     NotificationPreferencesInfo::BundleInfo bundleInfo;
767     bundleInfo.SetBundleName(bundleName_);
768     bundleInfo.SetBundleUid(bundleUid_);
769     std::string bundleKey = "bundleKey";
770     std::pair<std::string, std::string> entry;
771     entry.first = "ans_bundle_bundleKey_slot_type_1_vibrationSytle";
772     entry.second = "1";
773     ASSERT_NE(nullptr, preferncesDB_);
774     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
775 }
776 
777 /**
778  * @tc.number    : ParseSlotFromDisturbeDB_01200
779  * @tc.name      : ParseSlotFromDisturbeDB
780  */
781 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01200, Function | SmallTest | Level1)
782 {
783     NotificationPreferencesInfo::BundleInfo bundleInfo;
784     bundleInfo.SetBundleName(bundleName_);
785     bundleInfo.SetBundleUid(bundleUid_);
786     std::string bundleKey = "bundleKey";
787     std::pair<std::string, std::string> entry;
788     entry.first = "ans_bundle_bundleKey_slot_type_1_enableBypassDnd";
789     entry.second = "1";
790     ASSERT_NE(nullptr, preferncesDB_);
791     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
792 }
793 
794 /**
795  * @tc.number    : ParseSlotFromDisturbeDB_01300
796  * @tc.name      : ParseSlotFromDisturbeDB
797  */
798 HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01300, Function | SmallTest | Level1)
799 {
800     NotificationPreferencesInfo::BundleInfo bundleInfo;
801     bundleInfo.SetBundleName(bundleName_);
802     bundleInfo.SetBundleUid(bundleUid_);
803     std::string bundleKey = "bundleKey";
804     std::pair<std::string, std::string> entry;
805     entry.first = "ans_bundle_bundleKey_slot_type_1_enabled";
806     entry.second = "1";
807     ASSERT_NE(nullptr, preferncesDB_);
808     preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1);
809 }
810 
811 /**
812  * @tc.name      : PutHasPoppedDialog_00100
813  * @tc.number    :
814  * @tc.desc      : Put bundle total badge nums into disturbe DB, return is true.
815  * @tc.require   : issueI62SME
816  */
817 HWTEST_F(NotificationPreferencesDatabaseTest, PutHasPoppedDialog_00100, Function | SmallTest | Level1)
818 {
819     NotificationPreferencesInfo::BundleInfo bundleInfo;
820     bundleInfo.SetBundleName(bundleName_);
821     bundleInfo.SetBundleUid(bundleUid_);
822     EXPECT_TRUE(preferncesDB_->PutHasPoppedDialog(bundleInfo, 0));
823 }
824 
825 /**
826  * @tc.number    : PutHasPoppedDialog_00200
827  * @tc.name      :
828  * @tc.desc      : Put bundle total badge nums into disturbe DB when bundle name is null, return is false.
829  * @tc.require   : #issueI62SME
830  */
831 HWTEST_F(NotificationPreferencesDatabaseTest, PutHasPoppedDialog_00200, Function | SmallTest | Level1)
832 {
833     NotificationPreferencesInfo::BundleInfo bundleInfo;
834     bundleInfo.SetBundleName(std::string());
835     bundleInfo.SetBundleUid(bundleUid_);
836     EXPECT_FALSE(preferncesDB_->PutHasPoppedDialog(bundleInfo, 0));
837 }
838 
839 /**
840  * @tc.number    : PutDoNotDisturbDate_00500
841  * @tc.name      :
842  * @tc.desc      : Put disturbe mode into disturbe DB when date is nullptr, return is false.
843  * @tc.require   : #issueI62SME
844  */
845 HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00500, Function | SmallTest | Level1)
846 {
847     int32_t userId = 0;
848     ASSERT_EQ(preferncesDB_->PutDoNotDisturbDate(userId, nullptr), false);
849 }
850 
851 /**
852  * @tc.number    : RemoveAllSlotsFromDisturbeDB_00200
853  * @tc.name      : RemoveAllSlotsFromDisturbeDB
854  * @tc.desc      : Test RemoveAllSlotsFromDisturbeDB function return is true
855  * @tc.require   : #issueI62SME
856  */
857 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveAllSlotsFromDisturbeDB_00200, Function | SmallTest | Level1)
858 {
859     std::string bundleKey = "";
860     ASSERT_EQ(preferncesDB_->RemoveAllSlotsFromDisturbeDB(bundleKey, -1), false);
861 }
862 
863 /**
864  * @tc.number    : ChangeSlotToEntry_00200
865  * @tc.name      :
866  * @tc.desc      : Change slot to entry.
867  * @tc.require   : #issueI62SME
868  */
869 HWTEST_F(NotificationPreferencesDatabaseTest, ChangeSlotToEntry_00200, Function | SmallTest | Level1)
870 {
871     std::unordered_map<std::string, std::string> values;
872     ASSERT_EQ(preferncesDB_->SlotToEntry(bundleName_, bundleUid_, nullptr, values), false);
873 }
874 
875 /**
876  * @tc.name: SetSmartReminderEnabled_0100
877  * @tc.desc: test SetSmartReminderEnabled with parameters
878  * @tc.type: FUNC
879  */
880 HWTEST_F(NotificationPreferencesDatabaseTest, SetSmartReminderEnabled_0100, TestSize.Level1)
881 {
882     bool enable = true;
883     bool ret = preferncesDB_->SetSmartReminderEnabled("testDeviceType1111", enable);
884     ASSERT_EQ(ret, true);
885 }
886 
887 /**
888  * @tc.name: IsSmartReminderEnabled_0100
889  * @tc.desc: test IsSmartReminderEnabled with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED
890  * @tc.type: FUNC
891  */
892 HWTEST_F(NotificationPreferencesDatabaseTest, IsSmartReminderEnabled_0100, TestSize.Level1)
893 {
894     bool enable = true;
895     bool result = preferncesDB_->IsSmartReminderEnabled("testDeviceType1111", enable);
896     ASSERT_EQ(result, true);
897 }
898 
899 /**
900  * @tc.name      : GetAllNotificationEnabledBundles_00100
901  * @tc.number    : GetAllNotificationEnabledBundles
902  * @tc.desc      : Check func GetAllNotificationEnabledBundles,no data in db return false
903  */
904 HWTEST_F(NotificationPreferencesDatabaseTest, GetAllNotificationEnabledBundles_00100, Function | SmallTest | Level1)
905 {
906     std::vector<NotificationBundleOption> bundleOption;
907     ASSERT_EQ(true, preferncesDB_->GetAllNotificationEnabledBundles(bundleOption));
908 }
909 
910 /**
911  * @tc.number    : RemoveAnsBundleDbInfo_00200
912  * @tc.name      :
913  * @tc.desc      : Test RemoveAnsBundleDbInfo function.
914  * @tc.require   : #issueI62SME
915  */
916 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveAnsBundleDbInfo_00200, Function | SmallTest | Level1)
917 {
918     std::string bundleName = "bundleName";
919     int32_t uid = 1;
920     ASSERT_EQ(preferncesDB_->RemoveAnsBundleDbInfo(bundleName, uid), true);
921 }
922 
923 /**
924  * @tc.name: GenerateBundleLablel_0100
925  * @tc.desc: test GenerateBundleLablel with parameters
926  * @tc.type: FUNC
927  */
928 HWTEST_F(NotificationPreferencesDatabaseTest, GenerateBundleLablel_0100, TestSize.Level1)
929 {
930     NotificationPreferencesInfo::BundleInfo bundleInfo;
931     bundleInfo.SetBundleName("name");
932     bundleInfo.SetBundleUid(1);
933     std::string deviceType = "test";
934     auto ret = preferncesDB_->GenerateBundleLablel(bundleInfo, deviceType);
935     ASSERT_EQ(ret, "enabledDistributedNotification-name-1-test");
936 }
937 
938 /**
939  * @tc.name: PutDistributedEnabledForBundle_0100
940  * @tc.desc: test PutDistributedEnabledForBundle with parameters
941  * @tc.type: FUNC
942  */
943 HWTEST_F(NotificationPreferencesDatabaseTest, PutDistributedEnabledForBundle_0100, TestSize.Level1)
944 {
945     NotificationPreferencesInfo::BundleInfo bundleInfo;
946     bundleInfo.SetBundleName("name");
947     bundleInfo.SetBundleUid(1);
948     std::string deviceType = "testDeviceType1111";
949     bool enable = true;
950     bool ret = preferncesDB_->PutDistributedEnabledForBundle(deviceType, bundleInfo, enable);
951     ASSERT_EQ(ret, true);
952 }
953 
954 /**
955  * @tc.name: PutDistributedEnabledForBundle_0200
956  * @tc.desc: test PutDistributedEnabledForBundle with parameters
957  * @tc.type: FUNC
958  */
959 HWTEST_F(NotificationPreferencesDatabaseTest, PutDistributedEnabledForBundle_0200, TestSize.Level1)
960 {
961     NotificationPreferencesInfo::BundleInfo bundleInfo;
962     bundleInfo.SetBundleName("");
963     bundleInfo.SetBundleUid(1);
964     std::string deviceType = "testDeviceType1111";
965     bool enable = true;
966     bool ret = preferncesDB_->PutDistributedEnabledForBundle(deviceType, bundleInfo, enable);
967     ASSERT_EQ(ret, false);
968 }
969 
970 /**
971  * @tc.name: GetDistributedEnabledForBundle_0100
972  * @tc.desc: test GetDistributedEnabledForBundle with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED
973  * @tc.type: FUNC
974  */
975 HWTEST_F(NotificationPreferencesDatabaseTest, GetDistributedEnabledForBundle_0100, TestSize.Level1)
976 {
977     NotificationPreferencesInfo::BundleInfo bundleInfo;
978     bundleInfo.SetBundleName("name");
979     bundleInfo.SetBundleUid(1);
980     std::string deviceType = "testDeviceType1111";
981     bool enable = true;
982     bool result = preferncesDB_->GetDistributedEnabledForBundle(deviceType, bundleInfo, enable);
983     ASSERT_EQ(result, true);
984 }
985 
986 /**
987  * @tc.name: GetDistributedEnabledForBundle_0200
988  * @tc.desc: test GetDistributedEnabledForBundle with parameters, expect errorCode ERR_ANS_SERVICE_NOT_CONNECTED
989  * @tc.type: FUNC
990  */
991 HWTEST_F(NotificationPreferencesDatabaseTest, GetDistributedEnabledForBundle_0200, TestSize.Level1)
992 {
993     NotificationPreferencesInfo::BundleInfo bundleInfo;
994     bundleInfo.SetBundleName("");
995     bundleInfo.SetBundleUid(1);
996     std::string deviceType = "testDeviceType1111";
997     bool enable = true;
998     bool result = preferncesDB_->GetDistributedEnabledForBundle(deviceType, bundleInfo, enable);
999     ASSERT_EQ(result, false);
1000 }
1001 
1002 /**
1003  * @tc.name: AddDoNotDisturbProfiles_0100
1004  * @tc.desc: test AddDoNotDisturbProfiles run success.
1005  * @tc.type: FUNC
1006  */
1007 HWTEST_F(NotificationPreferencesDatabaseTest, AddDoNotDisturbProfiles_0100, TestSize.Level1)
1008 {
1009     int32_t userId = 1;
1010     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1011     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1012     profile->SetProfileId(1);
1013     profile->SetProfileName("Name");
1014     std::string bundleName = "bundleName";
1015     int32_t uid = 1;
1016     NotificationBundleOption notificationBundleOption(bundleName, uid);
1017     vector<NotificationBundleOption> trustlist;
1018     trustlist.emplace_back(notificationBundleOption);
1019     profile->SetProfileTrustList(trustlist);
1020     profiles.emplace_back(profile);
1021 
1022     auto res = preferncesDB_->AddDoNotDisturbProfiles(userId, profiles);
1023     ASSERT_EQ(res, true);
1024 }
1025 
1026 /**
1027  * @tc.name: RemoveDoNotDisturbProfiles_0100
1028  * @tc.desc: test RemoveDoNotDisturbProfiles run success.
1029  * @tc.type: FUNC
1030  */
1031 HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbProfiles_0100, TestSize.Level1)
1032 {
1033     int32_t userId = 1;
1034     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1035     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1036     profile->SetProfileId(1);
1037     profile->SetProfileName("Name");
1038     std::string bundleName = "bundleName";
1039     int32_t uid = 1;
1040     NotificationBundleOption notificationBundleOption(bundleName, uid);
1041     vector<NotificationBundleOption> trustlist;
1042     trustlist.emplace_back(notificationBundleOption);
1043     profile->SetProfileTrustList(trustlist);
1044     profiles.emplace_back(profile);
1045 
1046     preferncesDB_->AddDoNotDisturbProfiles(userId, profiles);
1047     auto res = preferncesDB_->RemoveDoNotDisturbProfiles(userId, profiles);
1048     ASSERT_EQ(res, true);
1049 }
1050 
1051 /**
1052  * @tc.name: GetDoNotDisturbProfiles_0100
1053  * @tc.desc: test GetDoNotDisturbProfiles return of QueryData is not zero.
1054  * @tc.type: FUNC
1055  */
1056 HWTEST_F(NotificationPreferencesDatabaseTest, GetDoNotDisturbProfiles_0100, TestSize.Level1)
1057 {
1058     int32_t userId = 1;
1059     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
1060     sptr<NotificationDoNotDisturbProfile> profile = new (std::nothrow) NotificationDoNotDisturbProfile();
1061     profiles.emplace_back(profile);
1062     preferncesDB_->AddDoNotDisturbProfiles(userId, profiles);
1063     std::string key;
1064     auto res = preferncesDB_->GetDoNotDisturbProfiles(key, profile, -1);
1065     ASSERT_EQ(res, false);
1066 }
1067 
1068 /**
1069  * @tc.name: GetDoNotDisturbProfile_0100
1070  * @tc.desc: test GetDoNotDisturbProfile when profiles is empty.
1071  * @tc.type: FUNC
1072  */
1073 HWTEST_F(NotificationPreferencesDatabaseTest, GetDoNotDisturbProfile_0100, TestSize.Level1)
1074 {
1075     NotificationPreferencesInfo info;
1076     int32_t userId = 1;
1077     preferncesDB_->GetDoNotDisturbProfile(info, userId);
1078     int32_t profileId = 1;
1079     sptr<NotificationDoNotDisturbProfile> profile;
1080     auto res = info.GetDoNotDisturbProfiles(profileId, userId, profile);
1081     auto infos = new (std::nothrow) NotificationPreferencesInfo();
1082     ASSERT_EQ(res, false);
1083 }
1084 }  // namespace Notification
1085 }  // namespace OHOS
1086