From f327e895419137cea2df7cb960b5197958b626cc Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 9 Nov 2022 15:54:53 +0800 Subject: [PATCH] notification_preferences add TDD testcase Signed-off-by: raul Change-Id: If30c0e32be03f4421d44b16036bf387407b431e0 --- services/ans/test/unittest/ans_ut_constant.h | 1 + .../notification_preferences_test.cpp | 457 +++++++++++++++++- 2 files changed, 436 insertions(+), 22 deletions(-) diff --git a/services/ans/test/unittest/ans_ut_constant.h b/services/ans/test/unittest/ans_ut_constant.h index 2e8a9b906..c13d7d004 100644 --- a/services/ans/test/unittest/ans_ut_constant.h +++ b/services/ans/test/unittest/ans_ut_constant.h @@ -27,6 +27,7 @@ constexpr int32_t SYSTEM_APP_UID = 100; constexpr int32_t NON_SYSTEM_APP_UID = 1000; constexpr int32_t NON_BUNDLE_NAME_UID = 2000; const std::string TEST_DEFUALT_BUNDLE = "bundleName"; +constexpr int32_t TEST_SUBSCRIBE_USER_INIT = -1; } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index fed80303f..33bd1bcdd 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -17,7 +17,11 @@ #include "ans_inner_errors.h" #include "ans_ut_constant.h" +#define private public +#define protected public #include "notification_preferences.h" +#undef private +#undef protected using namespace testing::ext; namespace OHOS { @@ -127,6 +131,21 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00500, Function | Sma EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(bundleOption_, slots), (int)ERR_OK); } +/** + * @tc.number : AddNotificationSlots_00600 + * @tc.name : + * @tc.desc : Add a notification slot into distrube DB , return is ERR_OK. + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationSlots(nullptr, slots), (int)ERR_OK); +} + + + /** * @tc.number : RemoveNotificationSlot_00100 * @tc.name : @@ -180,6 +199,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00400, Function | S (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationSlot_00500 + * @tc.name : + * @tc.desc : Remove a notification slot from disturbe DB , return is ERR_OK + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationSlot_00500, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER), + (int)ERR_OK); +} + /** * @tc.number : RemoveNotificationForBundle_00100 * @tc.name : @@ -215,6 +247,18 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00300, Functio (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : RemoveNotificationForBundle_00400 + * @tc.name : + * @tc.desc : Remove notification for bundle from disturbe DB when bundle name is null, return is + * ERR_ANS_INVALID_PARAM; + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationForBundle_00400, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationForBundle(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : UpdateNotificationSlots_00100 * @tc.name : @@ -289,6 +333,20 @@ HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00500, Function | (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : UpdateNotificationSlots_00600 + * @tc.name : + * @tc.desc : Update notification slot into disturbe DB when bundleName is null, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, UpdateNotificationSlots_00600, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + std::vector> slots; + slots.push_back(slot); + EXPECT_EQ((int)NotificationPreferences::GetInstance().UpdateNotificationSlots(nullptr, slots), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlot_00100 * @tc.name : @@ -347,6 +405,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00400, Function | Smal (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); } +/** + * @tc.number : GetNotificationSlot_00500 + * @tc.name : + * @tc.desc : Update notification slot group into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlot_00500, Function | SmallTest | Level1) +{ + sptr slot; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlot( + nullptr, NotificationConstant::SlotType::OTHER, slot), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationAllSlots_00100 * @tc.name : @@ -411,6 +483,20 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00400, Function | EXPECT_EQ((int)slotsResult.size(), 0); } +/** + * @tc.number : GetNotificationAllSlots_00500 + * @tc.name : + * @tc.desc : Get all notification slots from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationAllSlots_00500, Function | SmallTest | Level1) +{ + std::vector> slotsResult; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationAllSlots(nullptr, slotsResult), + (int)ERR_ANS_INVALID_PARAM); + EXPECT_EQ((int)slotsResult.size(), 0); +} + /** * @tc.number : SetShowBadge_00100 * @tc.name : @@ -458,6 +544,18 @@ HWTEST_F(NotificationPreferencesTest, IsShowBadge_00200, Function | SmallTest | (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : IsShowBadge_00300 + * @tc.name : + * @tc.desc : Get bunlde show badge from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, IsShowBadge_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().IsShowBadge(nullptr, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetImportance_00100 * @tc.name : @@ -481,6 +579,18 @@ HWTEST_F(NotificationPreferencesTest, SetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetImportance_00300 + * @tc.name : + * @tc.desc : Set bundle importance into disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetImportance_00300, Function | SmallTest | Level1) +{ + int importance = 1; + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetImportance(nullptr, importance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetImportance_00100 * @tc.name : @@ -508,6 +618,18 @@ HWTEST_F(NotificationPreferencesTest, GetImportance_00200, Function | SmallTest (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetImportance_00300 + * @tc.name : + * @tc.desc : Get bundle importance from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetImportance_00300, Function | SmallTest | Level1) +{ + int getImportance = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetImportance(nullptr, getImportance), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetTotalBadgeNums_00100 * @tc.name : @@ -557,6 +679,18 @@ HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00200, Function | SmallT (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetTotalBadgeNums_00300 + * @tc.name : + * @tc.desc : Get total badge nums from disturbe DB when bundleOption is null, return is ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetTotalBadgeNums_00300, Function | SmallTest | Level1) +{ + int totalBadgeNum = 0; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetTotalBadgeNums(nullptr, totalBadgeNum), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetPrivateNotificationsAllowed_00100 * @tc.name : @@ -580,6 +714,18 @@ HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Set private notification allowed badge nums into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetPrivateNotificationsAllowed(nullptr, true), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetPrivateNotificationsAllowed_00100 * @tc.name : @@ -608,6 +754,19 @@ HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00200, Func (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetPrivateNotificationsAllowed_00300 + * @tc.name : + * @tc.desc : Get private notification allowed badge nums from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetPrivateNotificationsAllowed_00300, Function | SmallTest | Level1) +{ + bool allow = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetPrivateNotificationsAllowed(nullptr, allow), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabledForBundle_00100 * @tc.name : @@ -631,12 +790,24 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00200, Fu (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : SetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Set notification enable for bundle into disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(nullptr, false), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationsEnabledForBundle_00100 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB, return is ERR_OK. */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00100, Function | SmallTest | Level1) { EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabledForBundle(bundleOption_, false), (int)ERR_OK); @@ -647,18 +818,31 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_02900, Fu } /** - * @tc.number : GetNotificationsEnabledForBundle_00100 + * @tc.number : GetNotificationsEnabledForBundle_00200 * @tc.name : * @tc.desc : Get notification enable for bundle from disturbe DB when bundle name is null, return is * ERR_ANS_INVALID_PARAM. */ -HWTEST_F(NotificationPreferencesTest, NotificationPreferencesTest_02900, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00200, Function | SmallTest | Level1) { bool enabled = false; EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(bundleEmptyOption_, enabled), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetNotificationsEnabledForBundle_00300 + * @tc.name : + * @tc.desc : Get notification enable for bundle from disturbe DB when bundleOption is null, return is + * ERR_ANS_INVALID_PARAM. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + bool enabled = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(nullptr, enabled), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetNotificationsEnabled_00100 * @tc.name : @@ -670,7 +854,18 @@ HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00100, Function | } /** - * @tc.number : GetNotificationsEnabled + * @tc.number : SetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Set enable notification into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, true), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : GetNotificationsEnabled_00100 * @tc.name : * @tc.desc : Get enable notification from disturbe DB, return is ERR_OK */ @@ -682,6 +877,36 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | EXPECT_TRUE(enable); } +/** + * @tc.number : GetNotificationsEnabled_00200 + * @tc.name : + * @tc.desc : Same user can get enable setting, different user can not get. + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); + EXPECT_TRUE(enable); + + enable = false; + EXPECT_EQ( + (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); + EXPECT_FALSE(enable); +} + +/** + * @tc.number : GetNotificationsEnabled_00300 + * @tc.name : + * @tc.desc : Get enable notification from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00300, Function | SmallTest | Level1) +{ + bool enable = false; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(TEST_SUBSCRIBE_USER_INIT, enable), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetDoNotDisturbDate_00100 * @tc.name : @@ -701,6 +926,26 @@ HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(SYSTEM_APP_UID, date), (int)ERR_OK); } +/** + * @tc.number : SetDoNotDisturbDate_00200 + * @tc.name : + * @tc.desc : Set disturbe mode into disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00200, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, date), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetDoNotDisturbDate_00100 * @tc.name : @@ -725,24 +970,6 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | Smal EXPECT_EQ(getDate->GetEndDate(), endDate); } -/** - * @tc.number : GetNotificationsEnabled_00200 - * @tc.name : - * @tc.desc : Same user can get enable setting, different user can not get. - */ -HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00200, Function | SmallTest | Level1) -{ - EXPECT_EQ((int)NotificationPreferences::GetInstance().SetNotificationsEnabled(100, true), (int)ERR_OK); - bool enable = false; - EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationsEnabled(100, enable), (int)ERR_OK); - EXPECT_TRUE(enable); - - enable = false; - EXPECT_EQ( - (int)NotificationPreferences::GetInstance().GetNotificationsEnabled(101, enable), (int)ERR_ANS_INVALID_PARAM); - EXPECT_FALSE(enable); -} - /** * @tc.number : GetDoNotDisturbDate_00200 * @tc.name : @@ -771,6 +998,18 @@ HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00200, Function | Smal NON_SYSTEM_APP_UID, getExsitDate), (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : GetDoNotDisturbDate_00300 + * @tc.name : + * @tc.desc : Get disturbe mode from disturbe DB, when userId is -1, return is ERR_ANS_INVALID_PARAM + */ +HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00300, Function | SmallTest | Level1) +{ + sptr getDate; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(TEST_SUBSCRIBE_USER_INIT, getDate), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : SetHasPoppedDialog_00100 * @tc.name : @@ -825,6 +1064,19 @@ HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00200, Funct (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : AddNotificationBundleProperty_00300 + * @tc.name : AddNotificationBundleProperty + * @tc.desc : Add a notification BundleProperty into distrube DB when bundlename is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, AddNotificationBundleProperty_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().AddNotificationBundleProperty(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : RemoveNotificationAllSlots_00100 * @tc.name : RemoveNotificationAllSlots @@ -851,6 +1103,19 @@ HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00200, Function (int)ERR_ANS_INVALID_PARAM); } +/** + * @tc.number : RemoveNotificationAllSlots_00300 + * @tc.name : RemoveNotificationAllSlots + * @tc.desc : Test RemoveNotificationAllSlots function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, RemoveNotificationAllSlots_00300, Function | SmallTest | Level1) +{ + EXPECT_EQ((int)NotificationPreferences::GetInstance().RemoveNotificationAllSlots(nullptr), + (int)ERR_ANS_INVALID_PARAM); +} + /** * @tc.number : GetNotificationSlotsNumForBundle_00100 * @tc.name : GetNotificationSlotsNumForBundle @@ -878,5 +1143,153 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00200, Fu EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(bundleEmptyOption_, num), (int)ERR_ANS_INVALID_PARAM); } + +/** + * @tc.number : GetNotificationSlotsNumForBundle_00300 + * @tc.name : GetNotificationSlotsNumForBundle + * @tc.desc : Test GetNotificationSlotsNumForBundle function when bundleOption is null, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, GetNotificationSlotsNumForBundle_00300, Function | SmallTest | Level1) +{ + uint64_t num = 2; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetNotificationSlotsNumForBundle(nullptr, num), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00100 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForCreateSlot_00200 + * @tc.name : CheckSlotForCreateSlot + * @tc.desc : Test CheckSlotForCreateSlot function, return ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForCreateSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForCreateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00100 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00100, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00200 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function, return is ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::OTHER, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForRemoveSlot_00300 + * @tc.name : CheckSlotForRemoveSlot + * @tc.desc : Test CheckSlotForRemoveSlot function after add a notification slot, return is ERR_OK, + * return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForRemoveSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForRemoveSlot( + bundleOption_, NotificationConstant::SlotType::CONTENT_INFORMATION, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00100 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is null, return is ERR_ANS_INVALID_PARAM. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00100, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, nullptr, info), + (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00200 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when bundle not existed, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00200, Function | SmallTest | Level1) +{ + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00300 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function when slot is different type, return is + * ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00300, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::CONTENT_INFORMATION); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST); +} + +/** + * @tc.number : CheckSlotForUpdateSlot_00400 + * @tc.name : CheckSlotForUpdateSlot + * @tc.desc : Test CheckSlotForUpdateSlot function after add notification slot, return is ERR_OK. + * @tc.require : issueI5SR8J + */ +HWTEST_F(NotificationPreferencesTest, CheckSlotForUpdateSlot_00400, Function | SmallTest | Level1) +{ + TestAddNotificationSlot(); + sptr slot = new NotificationSlot(NotificationConstant::SlotType::OTHER); + NotificationPreferencesInfo info{}; + EXPECT_EQ((int)NotificationPreferences::GetInstance().CheckSlotForUpdateSlot(bundleOption_, slot, info), + (int)ERR_OK); +} } // namespace Notification } // namespace OHOS -- Gitee