From 7c70cf9f47f559062dd4b346f869c6269aaa7c96 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 5 Jan 2023 06:34:55 +0000 Subject: [PATCH] add ans test Signed-off-by: liuyanzhi Change-Id: I460b86c7b6bf6ad79de0357ecc24254203ab8d0f --- services/ans/test/unittest/BUILD.gn | 57 ++ .../mock_distributed_kv_data_manager.cpp | 54 + .../mock_single_kv_store.cpp | 244 +++++ ...ation_preferences_database_branch_test.cpp | 943 ++++++++++++++++++ 4 files changed, 1298 insertions(+) create mode 100755 services/ans/test/unittest/notification_preferences_database_branch_test/mock_distributed_kv_data_manager.cpp create mode 100755 services/ans/test/unittest/notification_preferences_database_branch_test/mock_single_kv_store.cpp create mode 100755 services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 150217b7d..c08ae5517 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -367,6 +367,61 @@ ohos_unittest("notification_subscriber_manager_branch_test") { part_name = "${component_name}" } +ohos_unittest("notification_preferences_database_branch_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "//commonlibrary/c_utils/base/include", + "//utils/system/safwk/native/include", + "/${services_path}/ans/include", + "${services_path}/ans/test/unittest/mock/include", + ] + + sources = [ + "notification_preferences_database_branch_test/mock_distributed_kv_data_manager.cpp", + "notification_preferences_database_branch_test/mock_single_kv_store.cpp", + "notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp", + ] + + deps = [ + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", + "//foundation/arkui/ace_engine/interfaces/inner_api/ui_service_manager:ui_service_mgr", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hitrace_native:libhitracechain", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "multimedia_image_framework:image_native", + "multimedia_player_framework:media_client", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + group("unittest") { testonly = true deps = [] @@ -380,4 +435,6 @@ group("unittest") { deps += [ ":bundle_manager_helper_branch_test" ] deps += [ ":notification_subscriber_manager_branch_test" ] + + deps += [ ":notification_preferences_database_branch_test" ] } diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/mock_distributed_kv_data_manager.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_distributed_kv_data_manager.cpp new file mode 100755 index 000000000..f534c0792 --- /dev/null +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_distributed_kv_data_manager.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "DistributedKvDataManager" + +#include "distributed_kv_data_manager.h" + +namespace { + bool g_mockGetSingleKvStoreRet = true; +} + +void MockGetSingleKvStore(bool mockRet) +{ + g_mockGetSingleKvStoreRet = mockRet; +} + +namespace OHOS { +namespace DistributedKv { +DistributedKvDataManager::DistributedKvDataManager() +{} + +DistributedKvDataManager::~DistributedKvDataManager() +{} + +Status DistributedKvDataManager::GetSingleKvStore(const Options &options, const AppId &appId, const StoreId &storeId, + std::shared_ptr &singleKvStore) +{ + if (false == g_mockGetSingleKvStoreRet) { + return Status::INVALID_ARGUMENT; + } + return Status::SUCCESS; +} + +void DistributedKvDataManager::RegisterKvStoreServiceDeathRecipient( + std::shared_ptr kvStoreDeathRecipient) +{} + +void DistributedKvDataManager::UnRegisterKvStoreServiceDeathRecipient( + std::shared_ptr kvStoreDeathRecipient) +{} +} // namespace DistributedKv +} // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/mock_single_kv_store.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_single_kv_store.cpp new file mode 100755 index 000000000..bf28260a5 --- /dev/null +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/mock_single_kv_store.cpp @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mock_single_kv_store.h" +#include "types.h" + +namespace { + bool g_mockGetRet = true; + bool g_mockPutBatchRet = true; + bool g_mockGetEntriesRet = true; + bool g_mockDeleteBatchRet = true; + bool g_mockPutRet = true; + bool g_mockDeleteRet = true; +} + +void MockGet(bool mockRet) +{ + g_mockGetRet = mockRet; +} + +void MockPutBatch(bool mockRet) +{ + g_mockPutBatchRet = mockRet; +} + +void MockGetEntries(bool mockRet) +{ + g_mockGetEntriesRet = mockRet; +} + +void MockDeleteBatch(bool mockRet) +{ + g_mockDeleteBatchRet = mockRet; +} + +void MockPut(bool mockRet) +{ + g_mockPutRet = mockRet; +} + +void MockDelete(bool mockRet) +{ + g_mockDeleteRet = mockRet; +} + +namespace OHOS { +namespace DistributedKv { +Status MockSingleKvStore::GetEntries(const Key &prefixKey, std::vector &entries) const +{ + if (g_mockGetEntriesRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetEntries(const DataQuery &query, std::vector &entries) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetResultSet(const Key &prefixKey, std::shared_ptr &resultSet) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetResultSet(const DataQuery &query, std::shared_ptr &resultSet) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::CloseResultSet(std::shared_ptr &resultSet) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetCount(const DataQuery &query, int &result) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Sync(const std::vector &deviceIds, SyncMode mode, uint32_t delayMs) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::RemoveDeviceData(const std::string &device) +{ + return Status::SUCCESS; +} + +StoreId MockSingleKvStore::GetStoreId() const +{ + StoreId storeId; + storeId.storeId = ""; + return storeId; +} + +Status MockSingleKvStore::Delete(const Key &key) +{ + if (g_mockDeleteRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::SUCCESS; +} + +Status MockSingleKvStore::Put(const Key &key, const Value &value) +{ + if (g_mockPutRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::SUCCESS; +} + +Status MockSingleKvStore::Get(const Key &key, Value &value) +{ + if (g_mockGetRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::INVALID_ARGUMENT; +} + +Status MockSingleKvStore::SubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::UnSubscribeKvStore(SubscribeType subscribeType, std::shared_ptr observer) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::RegisterSyncCallback(std::shared_ptr callback) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::UnRegisterSyncCallback() +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::PutBatch(const std::vector &entries) +{ + if (g_mockPutBatchRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::SUCCESS; +} + +Status MockSingleKvStore::DeleteBatch(const std::vector &keys) +{ + if (g_mockDeleteBatchRet == false) { + return Status::KEY_NOT_FOUND; + } + return Status::SUCCESS; +} + +Status MockSingleKvStore::StartTransaction() +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Commit() +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Rollback() +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::SetSyncParam(const KvSyncParam &syncParam) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetSyncParam(KvSyncParam &syncParam) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::SetCapabilityEnabled(bool enabled) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::SetCapabilityRange( + const std::vector &localLabels, const std::vector &remoteSupportLabels) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::GetSecurityLevel(SecurityLevel &securityLevel) const +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Sync(const std::vector &deviceIds, SyncMode mode, const DataQuery &query, + std::shared_ptr syncCallback) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::SubscribeWithQuery(const std::vector &deviceIds, const DataQuery &query) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::UnsubscribeWithQuery(const std::vector &deviceIds, const DataQuery &query) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Backup(const std::string &file, const std::string &baseDir) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::Restore(const std::string &file, const std::string &baseDir) +{ + return Status::SUCCESS; +} + +Status MockSingleKvStore::DeleteBackup( + const std::vector &files, const std::string &baseDir, + std::map &status) +{ + return Status::SUCCESS; +} +} // namespace DistributedKv +} // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp new file mode 100755 index 000000000..aa9e6db01 --- /dev/null +++ b/services/ans/test/unittest/notification_preferences_database_branch_test/notification_preferences_database_branch_test.cpp @@ -0,0 +1,943 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define private public +#include + +#define private public +#define protected public +#include "notification_preferences_database.h" +#undef private +#undef protected +#include "mock_single_kv_store.h" + +extern void MockGetSingleKvStore(bool mockRet); +extern void MockGet(bool mockRet); +extern void MockPutBatch(bool mockRet); +extern void MockGetEntries(bool mockRet); +extern void MockDeleteBatch(bool mockRet); +extern void MockPut(bool mockRet); +extern void MockDelete(bool mockRet); + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class NotificationPreferencesDatabaseBranchTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + + std::unique_ptr preferncesDB_ = + std::make_unique(); +}; + +/** + * @tc.name : NotificationPreferences_00100 + * @tc.number : + * @tc.desc : test GetKvStore function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00100, Function | SmallTest | Level1) +{ + MockGetSingleKvStore(false); + EXPECT_EQ(preferncesDB_->GetKvStore(), DistributedKv::Status::INVALID_ARGUMENT); +} + +/** + * @tc.name : NotificationPreferences_00200 + * @tc.number : + * @tc.desc : test TryTwice function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00200, Function | SmallTest | Level1) +{ + MockGetSingleKvStore(false); + // test TryTwice function + NotificationPreferencesDatabase notificationPreferencesDatabase; +} + +/** + * @tc.name : NotificationPreferences_00300 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_00400 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and status is DistributedKv::Status::KEY_NOT_FOUND + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::KEY_NOT_FOUND + MockGet(false); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleInfo), true); +} + +/** + * @tc.name : NotificationPreferences_00500 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and status is DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_00600 + * @tc.number : + * @tc.desc : test CheckBundle function and status is DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test CheckBundle function + std::string bundleName = ""; + int32_t bundleUid = 1; + EXPECT_EQ(preferncesDB_->CheckBundle(bundleName, bundleUid), false); +} + +/** + * @tc.name : NotificationPreferences_00700 + * @tc.number : + * @tc.desc : test PutShowBadge function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutShowBadge function + bool enable = true; + EXPECT_EQ(preferncesDB_->PutShowBadge(bundleInfo, enable), false); +} + +/** + * @tc.name : NotificationPreferences_00800 + * @tc.number : + * @tc.desc : test PutImportance function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutImportance function + int32_t importance = 1; + EXPECT_EQ(preferncesDB_->PutImportance(bundleInfo, importance), false); +} + +/** + * @tc.name : NotificationPreferences_00900 + * @tc.number : + * @tc.desc : test PutTotalBadgeNums function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_00900, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutTotalBadgeNums function + int32_t totalBadgeNum = 1; + EXPECT_EQ(preferncesDB_->PutTotalBadgeNums(bundleInfo, totalBadgeNum), false); +} + +/** + * @tc.name : NotificationPreferences_01000 + * @tc.number : + * @tc.desc : test PutPrivateNotificationsAllowed function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01000, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutPrivateNotificationsAllowed function + bool allow = true; + EXPECT_EQ(preferncesDB_->PutPrivateNotificationsAllowed(bundleInfo, allow), false); +} + +/** + * @tc.name : NotificationPreferences_01100 + * @tc.number : + * @tc.desc : test PutNotificationsEnabledForBundle function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutNotificationsEnabledForBundle function + bool enabled = true; + EXPECT_EQ(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, enabled), false); +} + +/** + * @tc.name : NotificationPreferences_01200 + * @tc.number : + * @tc.desc : test PutNotificationsEnabled function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01200, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = nullptr; + // test PutNotificationsEnabled function + int32_t userId = 1; + bool enabled = true; + EXPECT_EQ(preferncesDB_->PutNotificationsEnabled(userId, enabled), false); +} + +/** + * @tc.name : NotificationPreferences_01300 + * @tc.number : + * @tc.desc : test PutHasPoppedDialog function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutHasPoppedDialog function + bool hasPopped = true; + EXPECT_EQ(preferncesDB_->PutHasPoppedDialog(bundleInfo, hasPopped), false); +} + +/** + * @tc.name : NotificationPreferences_01400 + * @tc.number : + * @tc.desc : test PutDoNotDisturbDate function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01400, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test PutDoNotDisturbDate function + int32_t userId = 1; + sptr date = new NotificationDoNotDisturbDate(); + EXPECT_EQ(preferncesDB_->PutDoNotDisturbDate(userId, date), false); +} + +/** + * @tc.name : NotificationPreferences_01500 + * @tc.number : + * @tc.desc : test GetValueFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01500, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test GetValueFromDisturbeDB function + std::string key = ""; + preferncesDB_->GetValueFromDisturbeDB(key, [&](DistributedKv::Value &value) {}); +} + +/** + * @tc.name : NotificationPreferences_01600 + * @tc.number : + * @tc.desc : test GetValueFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01600, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test GetValueFromDisturbeDB function + std::string key = ""; + preferncesDB_->GetValueFromDisturbeDB(key, [&](DistributedKv::Value &value) {}); +} + +/** + * @tc.name : NotificationPreferences_01700 + * @tc.number : + * @tc.desc : test GetValueFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01700, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test GetValueFromDisturbeDB function + std::string key = ""; + preferncesDB_->GetValueFromDisturbeDB( + key, [&](const DistributedKv::Status &status, DistributedKv::Value &value) {}); +} + +/** + * @tc.name : NotificationPreferences_01800 + * @tc.number : + * @tc.desc : test PutBundlePropertyValueToDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01800, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test PutBundlePropertyValueToDisturbeDB function + NotificationPreferencesInfo::BundleInfo bundleInfo; + EXPECT_EQ(preferncesDB_->PutBundlePropertyValueToDisturbeDB(bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_01900 + * @tc.number : + * @tc.desc : test PutBundlePropertyValueToDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_01900, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockPutBatch(false); + // test PutBundlePropertyValueToDisturbeDB function + NotificationPreferencesInfo::BundleInfo bundleInfo; + EXPECT_EQ(preferncesDB_->PutBundlePropertyValueToDisturbeDB(bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_02000 + * @tc.number : + * @tc.desc : test ParseFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02000, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test ParseFromDisturbeDB function + NotificationPreferencesInfo info; + EXPECT_EQ(preferncesDB_->ParseFromDisturbeDB(info), false); +} + +/** + * @tc.name : NotificationPreferences_02100 + * @tc.number : + * @tc.desc : test ParseFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02100, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockGetEntries(false); + // test ParseFromDisturbeDB function + NotificationPreferencesInfo info; + EXPECT_EQ(preferncesDB_->ParseFromDisturbeDB(info), false); +} + +/** + * @tc.name : NotificationPreferences_02200 + * @tc.number : + * @tc.desc : test RemoveAllDataFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02200, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + EXPECT_EQ(preferncesDB_->RemoveAllDataFromDisturbeDB(), false); +} + +/** + * @tc.name : NotificationPreferences_02300 + * @tc.number : + * @tc.desc : test RemoveBundleFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02300, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->RemoveBundleFromDisturbeDB(bundleKey), false); +} + +/** + * @tc.name : NotificationPreferences_02400 + * @tc.number : + * @tc.desc : test RemoveBundleFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02400, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockGetEntries(false); + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->RemoveBundleFromDisturbeDB(bundleKey), false); +} + +/** + * @tc.name : NotificationPreferences_02500 + * @tc.number : + * @tc.desc : test RemoveBundleFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02500, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status == DistributedKv::Status::SUCCESS + MockGetEntries(true); + // set status != DistributedKv::Status::SUCCESS + MockDeleteBatch(false); + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->RemoveBundleFromDisturbeDB(bundleKey), false); +} + +/** + * @tc.name : NotificationPreferences_02600 + * @tc.number : + * @tc.desc : test RemoveSlotFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02600, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test RemoveSlotFromDisturbeDB function + std::string bundleKey = ""; + NotificationConstant::SlotType type = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + EXPECT_EQ(preferncesDB_->RemoveSlotFromDisturbeDB(bundleKey, type), false); +} + +/** + * @tc.name : NotificationPreferences_02700 + * @tc.number : + * @tc.desc : test RemoveSlotFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02700, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockGetEntries(false); + // test RemoveSlotFromDisturbeDB function + std::string bundleKey = ""; + NotificationConstant::SlotType type = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + EXPECT_EQ(preferncesDB_->RemoveSlotFromDisturbeDB(bundleKey, type), false); +} + +/** + * @tc.name : NotificationPreferences_02800 + * @tc.number : + * @tc.desc : test RemoveSlotFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02800, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status == DistributedKv::Status::SUCCESS + MockGetEntries(true); + // set status != DistributedKv::Status::SUCCESS + MockDeleteBatch(false); + // test RemoveSlotFromDisturbeDB function + std::string bundleKey = ""; + NotificationConstant::SlotType type = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + EXPECT_EQ(preferncesDB_->RemoveSlotFromDisturbeDB(bundleKey, type), false); +} + +/** + * @tc.name : NotificationPreferences_02900 + * @tc.number : + * @tc.desc : test RemoveAllSlotsFromDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_02900, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test RemoveAllSlotsFromDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->RemoveAllSlotsFromDisturbeDB(bundleKey), false); +} + +/** + * @tc.name : NotificationPreferences_03000 + * @tc.number : + * @tc.desc : test RemoveAllSlotsFromDisturbeDB function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03000, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockGetEntries(false); + // test RemoveAllSlotsFromDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->RemoveAllSlotsFromDisturbeDB(bundleKey), false); +} + +/** + * @tc.name : NotificationPreferences_03100 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_BADGE_TOTAL_NUM_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03100, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_BADGE_TOTAL_NUM_TYPE + BundleType type = BundleType::BUNDLE_BADGE_TOTAL_NUM_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03200 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_IMPORTANCE_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03200, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_BADGE_TOTAL_NUM_TYPE + BundleType type = BundleType::BUNDLE_IMPORTANCE_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03300 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_SHOW_BADGE_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03300, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_SHOW_BADGE_TYPE + BundleType type = BundleType::BUNDLE_SHOW_BADGE_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03400 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_PRIVATE_ALLOWED_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03400, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_PRIVATE_ALLOWED_TYPE + BundleType type = BundleType::BUNDLE_PRIVATE_ALLOWED_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03500 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_ENABLE_NOTIFICATION_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03500, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_ENABLE_NOTIFICATION_TYPE + BundleType type = BundleType::BUNDLE_ENABLE_NOTIFICATION_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03600 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_POPPED_DIALOG_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03600, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_POPPED_DIALOG_TYPE + BundleType type = BundleType::BUNDLE_POPPED_DIALOG_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03700 + * @tc.number : + * @tc.desc : test PutBundlePropertyToDisturbeDB function and type is BUNDLE_NAME_TYPE + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03700, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // set type is BUNDLE_NAME_TYPE + BundleType type = BundleType::BUNDLE_NAME_TYPE; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + EXPECT_EQ(preferncesDB_->PutBundlePropertyToDisturbeDB(bundleKey, type, true), DistributedKv::Status::ERROR); +} + +/** + * @tc.name : NotificationPreferences_03800 + * @tc.number : + * @tc.desc : test PutBundleToDisturbeDB function and put is not SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03800, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set put != SUCCESS + MockPut(false); + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + NotificationPreferencesInfo::BundleInfo bundleInfo; + EXPECT_EQ(preferncesDB_->PutBundleToDisturbeDB(bundleKey, bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_03900 + * @tc.number : + * @tc.desc : test PutBundleToDisturbeDB function and PutBundlePropertyValueToDisturbeDB is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_03900, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set put == SUCCESS + MockPut(true); + // set PutBundlePropertyValueToDisturbeDB is false + MockPutBatch(false); + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + NotificationPreferencesInfo::BundleInfo bundleInfo; + EXPECT_EQ(preferncesDB_->PutBundleToDisturbeDB(bundleKey, bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_04000 + * @tc.number : + * @tc.desc : test PutBundleToDisturbeDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04000, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test PutBundlePropertyToDisturbeDB function + std::string bundleKey = ""; + NotificationPreferencesInfo::BundleInfo bundleInfo; + EXPECT_EQ(preferncesDB_->PutBundleToDisturbeDB(bundleKey, bundleInfo), false); +} + +/** + * @tc.name : NotificationPreferences_04100 + * @tc.number : + * @tc.desc : test SlotToEntry function and CheckBundle is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04100, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test SlotToEntry function + std::string bundleName = ""; + int32_t bundleUid = 1; + sptr slot = new NotificationSlot(); + std::vector entries; + EXPECT_EQ(preferncesDB_->SlotToEntry(bundleName, bundleUid, slot, entries), false); +} + +/** + * @tc.name : NotificationPreferences_04200 + * @tc.number : + * @tc.desc : test PutSlotsToDisturbeDB function and result is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04200, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + std::string name = ""; + bundleInfo.SetBundleName(name); + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test PutSlotsToDisturbeDB function + std::string bundleName = ""; + int32_t bundleUid = 1; + sptr slot = new NotificationSlot(); + std::vector> slots; + slots.emplace_back(slot); + EXPECT_EQ(preferncesDB_->PutSlotsToDisturbeDB(bundleName, bundleUid, slots), false); +} + +/** + * @tc.name : NotificationPreferences_04300 + * @tc.number : + * @tc.desc : test ParseBundleFromDistureDB function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04300, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = nullptr; + NotificationPreferencesInfo info; + std::vector entries; + preferncesDB_->ParseBundleFromDistureDB(info, entries); +} + +/** + * @tc.name : NotificationPreferences_04400 + * @tc.number : + * @tc.desc : test FindLastString function and pos == std::string::npos + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04400, Function | SmallTest | Level1) +{ + std::string findString = ""; + std::string inputString = ""; + EXPECT_EQ(preferncesDB_->FindLastString(findString, inputString), ""); +} + +/** + * @tc.name : NotificationPreferences_04500 + * @tc.number : + * @tc.desc : test StringToInt function and str is empty + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04500, Function | SmallTest | Level1) +{ + std::string str = ""; + EXPECT_EQ(preferncesDB_->StringToInt(str), 0); +} + +/** + * @tc.name : NotificationPreferences_04600 + * @tc.number : + * @tc.desc : test StringToInt64 function and str is empty + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04600, Function | SmallTest | Level1) +{ + std::string str = ""; + EXPECT_EQ(preferncesDB_->StringToInt64(str), 0); +} + +/** + * @tc.name : NotificationPreferences_04700 + * @tc.number : + * @tc.desc : test GetDoNotDisturbType function and status == DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04700, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test GetDoNotDisturbType function + NotificationPreferencesInfo info; + int32_t userId = 1; + preferncesDB_->GetDoNotDisturbType(info, userId); +} + +/** + * @tc.name : NotificationPreferences_04800 + * @tc.number : + * @tc.desc : test GetDoNotDisturbBeginDate function and status == DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04800, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test GetDoNotDisturbBeginDate function + NotificationPreferencesInfo info; + int32_t userId = 1; + preferncesDB_->GetDoNotDisturbBeginDate(info, userId); +} + +/** + * @tc.name : NotificationPreferences_04900 + * @tc.number : + * @tc.desc : test GetDoNotDisturbEndDate function and status == DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_04900, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test GetDoNotDisturbEndDate function + NotificationPreferencesInfo info; + int32_t userId = 1; + preferncesDB_->GetDoNotDisturbEndDate(info, userId); +} + +/** + * @tc.name : NotificationPreferences_05000 + * @tc.number : + * @tc.desc : test GetEnableAllNotification function and status == DistributedKv::Status::INVALID_ARGUMENT + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05000, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status is DistributedKv::Status::INVALID_ARGUMENT + MockGet(true); + // test GetEnableAllNotification function + NotificationPreferencesInfo info; + int32_t userId = 1; + preferncesDB_->GetEnableAllNotification(info, userId); +} + +/** + * @tc.name : NotificationPreferences_05100 + * @tc.number : + * @tc.desc : test RemoveNotificationEnable function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05100, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test RemoveNotificationEnable function + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveNotificationEnable(userId), false); +} + +/** + * @tc.name : NotificationPreferences_05200 + * @tc.number : + * @tc.desc : test RemoveNotificationEnable function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05200, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockDelete(false); + // test RemoveNotificationEnable function + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveNotificationEnable(userId), false); +} + +/** + * @tc.name : NotificationPreferences_05300 + * @tc.number : + * @tc.desc : test RemoveDoNotDisturbDate function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05300, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test RemoveDoNotDisturbDate function + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveDoNotDisturbDate(userId), false); +} + +/** + * @tc.name : NotificationPreferences_05400 + * @tc.number : + * @tc.desc : test RemoveDoNotDisturbDate function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05400, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockDeleteBatch(false); + // test RemoveDoNotDisturbDate function + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveDoNotDisturbDate(userId), false); +} + +/** + * @tc.name : NotificationPreferences_05500 + * @tc.number : + * @tc.desc : test RemoveAnsBundleDbInfo function and CheckKvStore is false + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05500, Function | SmallTest | Level1) +{ + // set CheckKvStore is false + preferncesDB_->kvStorePtr_ = nullptr; + // test RemoveAnsBundleDbInfo function + std::string bundleName = ""; + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveAnsBundleDbInfo(bundleName, userId), false); +} + +/** + * @tc.name : NotificationPreferences_05600 + * @tc.number : + * @tc.desc : test RemoveAnsBundleDbInfo function and status != DistributedKv::Status::SUCCESS + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, NotificationPreferences_05600, Function | SmallTest | Level1) +{ + // set CheckKvStore is true + preferncesDB_->kvStorePtr_ = std::make_shared(); + // set status != DistributedKv::Status::SUCCESS + MockDelete(false); + // test RemoveAnsBundleDbInfo function + std::string bundleName = ""; + int32_t userId = 1; + EXPECT_EQ(preferncesDB_->RemoveAnsBundleDbInfo(bundleName, userId), false); +} +} // namespace Notification +} // namespace OHOS -- Gitee