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