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