diff --git a/services/ans/test/unittest/advanced_notification_flow_control_service_test.cpp b/services/ans/test/unittest/advanced_notification_flow_control_service_test.cpp index d8e39292d9f64a5a87aef36787f3b1f706ac4865..04962ac6bf5ab12d7ead602ef8762ca7fe65672c 100644 --- a/services/ans/test/unittest/advanced_notification_flow_control_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_flow_control_service_test.cpp @@ -13,12 +13,18 @@ * limitations under the License. */ -#include "advanced_notification_flow_control_service.h" - #include "gtest/gtest.h" + +#define private public + +#define private public +#define protected public +#include "advanced_notification_flow_control_service.h" #include "ans_const_define.h" #include "ans_inner_errors.h" +#undef private +#undef protected using namespace testing::ext; @@ -99,5 +105,155 @@ HWTEST_F(FlowControlServiceTest, FlowControl_00001, Function | SmallTest | Level result = FlowControlService::GetInstance()->FlowControl(record, callingUid, true); ASSERT_EQ(result, (int)ERR_ANS_OVER_MAX_UPDATE_PERSECOND); } + +/** + * @tc.name: FlowControl_0002 + * @tc.desc: Test FlowControl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, FlowControl_0002, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isNeedFlowCtrl = false; + auto result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, false); + ASSERT_EQ(result, ERR_OK); +} + +/** + * @tc.name: FlowControl_0003 + * @tc.desc: Test FlowControl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, FlowControl_0003, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isNeedFlowCtrl = true; + + sptr req(new NotificationRequest(1)); + req->SetUpdateOnly(true); + record->request = req; + + ErrCode result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, false); + ASSERT_EQ(result, ERR_ANS_NOTIFICATION_NOT_EXISTS); +} + +/** + * @tc.name: PublishFlowCtrl_0001 + * @tc.desc: Test PublishFlowCtrl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, PublishFlowCtrl_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isNeedFlowCtrl = false; + bool result = FlowControlService::GetInstance()->PublishFlowCtrl(record, DEFAULT_UID); + ASSERT_EQ(result, ERR_OK); +} + +/** + * @tc.name: PublishGlobalFlowCtrl_0001 + * @tc.desc: Test PublishGlobalFlowCtrl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, PublishGlobalFlowCtrl_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + + sptr req(new NotificationRequest(1)); + record->isThirdparty = true; + record->request = req; + + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + ErrCode result = ERR_OK; + for (int i = 0; i < MAX_CREATE_NUM_PERSECOND_PERAPP; i++) { + result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, false); + } + + result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, false); + ASSERT_EQ(result, ERR_ANS_OVER_MAX_ACTIVE_PERSECOND); +} + +/** + * @tc.name: PublishRecordTimestamp_0001 + * @tc.desc: Test FlowControl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, PublishRecordTimestamp_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isThirdparty = true; + + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + FlowControlService::GetInstance()->PublishRecordTimestamp( + record, now, DEFAULT_UID); + + auto size = FlowControlService::GetInstance()->flowControlPublishTimestampList_.size(); + ASSERT_EQ(size, 1); + FlowControlService::GetInstance()->flowControlPublishTimestampList_.clear(); +} + +/** + * @tc.name: UpdateFlowCtrl_0001 + * @tc.desc: Test UpdateFlowCtrl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, UpdateFlowCtrl_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isNeedFlowCtrl = false; + auto result = FlowControlService::GetInstance()->UpdateFlowCtrl(record, DEFAULT_UID); + ASSERT_EQ(result, ERR_OK); +} + +/** + * @tc.name: UpdateGlobalFlowCtrl_0001 + * @tc.desc: Test UpdateGlobalFlowCtrl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, UpdateGlobalFlowCtrl_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isThirdparty = true; + + sptr req(new NotificationRequest(1)); + req->SetUpdateOnly(true); + record->request = req; + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + + ErrCode result = ERR_OK; + for (int i = 0; i < MAX_UPDATE_NUM_PERSECOND_PERAPP; i++) { + result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, true); + } + + result = FlowControlService::GetInstance()->FlowControl(record, DEFAULT_UID, true); + ASSERT_EQ(result, ERR_ANS_OVER_MAX_UPDATE_PERSECOND); +} + +/** + * @tc.name: UpdateRecordTimestamp_0001 + * @tc.desc: Test FlowControl + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(FlowControlServiceTest, UpdateRecordTimestamp_0001, Function | SmallTest | Level1) +{ + std::shared_ptr record = std::make_shared(); + record->isThirdparty = true; + + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + FlowControlService::GetInstance()->UpdateRecordTimestamp( + record, now, DEFAULT_UID); + + auto size = FlowControlService::GetInstance()->flowControlUpdateTimestampList_.size(); + ASSERT_EQ(1, size); + FlowControlService::GetInstance()->flowControlUpdateTimestampList_.clear(); +} } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index 810774ed4e38e5be4f76a1807e8d4668ce39f234..f67b7ded26075580cebfde9edaa49791b48ef52b 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -469,6 +469,43 @@ HWTEST_F(AnsBranchTest, AnsBranchTest_241000, Function | SmallTest | Level1) ASSERT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_ANS_PERMISSION_DENIED); } +/** + * @tc.number : SubscribeSelf_279001 + * @tc.require : issue + */ +HWTEST_F(AnsBranchTest, SubscribeSelf_279001, Function | SmallTest | Level1) +{ + auto res = advancedNotificationService_->SubscribeSelf(nullptr); + ASSERT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : SubscribeSelf_279002 + * @tc.require : issue + */ +HWTEST_F(AnsBranchTest, SubscribeSelf_279002, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(false); + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_ANS_NON_SYSTEM_APP); +} + +/** + * @tc.number : SubscribeSelf_279003 + * @tc.require : issue + */ +HWTEST_F(AnsBranchTest, SubscribeSelf_279003, Function | SmallTest | Level1) +{ + MockIsSystemApp(true); + + auto subscriber = new TestAnsSubscriber(); + sptr info = new NotificationSubscribeInfo(); + ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_ANS_TASK_ERR); +} + /** * @tc.number : AnsBranchTest_242000 * @tc.name : GetAllActiveNotifications_1000 diff --git a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp index 292da8ae8f1ba84637178daacd317d3eb7b0e377..462526c354f96ad03c11c1dda7b1e61bbee4ab43 100644 --- a/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_local_live_view_subscriber_manager_test.cpp @@ -83,6 +83,11 @@ void NotificationLocalLiveViewSubscriberManagerTest::SetUp() void NotificationLocalLiveViewSubscriberManagerTest::TearDown() { notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(subscriber_, nullptr); + if (notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ == nullptr) { + notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ = + std::make_shared("NotificationLocalLiveViewMgr"); + } + notificationLocalLiveViewSubscriberManager_->buttonRecordList_.clear(); } /** @@ -126,5 +131,103 @@ HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, sptr notification = new Notification(request); notificationLocalLiveViewSubscriberManager_->NotifyTriggerResponse(notification, buttonOption); } + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_004 + * @tc.name : ANS_AddSubscriber_004 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + NotificationLocalLiveViewSubscriberManagerTest_004, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + auto res = notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(nullptr, info); + ASSERT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : NotificationLocalLiveViewSubscriberManagerTest_005 + * @tc.name : ANS_AddSubscriber_005 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + NotificationLocalLiveViewSubscriberManagerTest_005, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ = nullptr; + auto res = notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info); + + ASSERT_EQ(res, ERR_ANS_TASK_ERR); +} + +/** + * @tc.number : RemoveLocalLiveViewSubscriberTest_001 + * @tc.name : RemoveLocalLiveViewSubscriberTest_001 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + RemoveLocalLiveViewSubscriberTest_001, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + auto res = notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(nullptr, info); + ASSERT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : RemoveLocalLiveViewSubscriberTest_002 + * @tc.name : RemoveLocalLiveViewSubscriberTest_002 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, + RemoveLocalLiveViewSubscriberTest_002, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ = nullptr; + auto res = notificationLocalLiveViewSubscriberManager_->RemoveLocalLiveViewSubscriber(subscriber_, info); + ASSERT_EQ(res, ERR_ANS_TASK_ERR); +} + +/** + * @tc.number : OnRemoteDied_001 + * @tc.name : OnRemoteDied_001 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, OnRemoteDied_001, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + ASSERT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); + + auto size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); + ASSERT_EQ(size, 1); + + wptr obj = subscriber_->AsObject(); + notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj); + + size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); + ASSERT_EQ(size, 0); +} + +/** + * @tc.number : OnRemoteDied_002 + * @tc.name : OnRemoteDied_002 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, OnRemoteDied_002, Function | SmallTest | Level1) +{ + sptr info = new NotificationSubscribeInfo(); + ASSERT_EQ(notificationLocalLiveViewSubscriberManager_->AddLocalLiveViewSubscriber(subscriber_, info), (int)ERR_OK); + auto size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); + ASSERT_EQ(size, 1); + + notificationLocalLiveViewSubscriberManager_->notificationButtonQueue_ = nullptr; + wptr obj = subscriber_->AsObject(); + notificationLocalLiveViewSubscriberManager_->OnRemoteDied(obj); + size = notificationLocalLiveViewSubscriberManager_->buttonRecordList_.size(); + ASSERT_EQ(size, 1); +} + +/** + * @tc.number : IsSystemUser_001 + * @tc.name : IsSystemUser_001 + */ +HWTEST_F(NotificationLocalLiveViewSubscriberManagerTest, IsSystemUser_001, Function | SmallTest | Level1) +{ + auto res = notificationLocalLiveViewSubscriberManager_->IsSystemUser(100); + ASSERT_FALSE(res); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_preferences_database_test.cpp b/services/ans/test/unittest/notification_preferences_database_test.cpp index f4a2fd5eaaa8473c2dc094f16a373c5977c53417..0e5cd22db5770a2d8800e3ecda711d5bea7c6e11 100644 --- a/services/ans/test/unittest/notification_preferences_database_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_test.cpp @@ -200,6 +200,20 @@ HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabledForBundle_0 EXPECT_FALSE(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, false)); } +/** + * @tc.name : PutNotificationsEnabledForBundle_00300 + * @tc.number : + * @tc.desc : Put bundle enable into disturbe DB when bundle name is null, return is false. + */ +HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabledForBundle_00300, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + ASSERT_TRUE(preferncesDB_->PutNotificationsEnabledForBundle(bundleInfo, true)); + ASSERT_TRUE(preferncesDB_->RemoveEnabledDbByBundleName(bundleName_, bundleUid_)); +} + /** * @tc.number : PutNotificationsEnabled_00100 * @tc.name : @@ -587,6 +601,44 @@ HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_ preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); } +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_00900 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_00900, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_showBadgeEnable"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); + auto show = bundleInfo.GetIsShowBadge(); + ASSERT_TRUE(show); +} + +/** + * @tc.number : ParseBundlePropertyFromDisturbeDB_01000 + * @tc.name : ParseBundlePropertyFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundlePropertyFromDisturbeDB_01000, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_bundleReminderFlagsType"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseBundlePropertyFromDisturbeDB(bundleInfo, bundleKey, entry); + auto show = bundleInfo.GetSlotFlags(); + ASSERT_EQ(show, 1); +} + /** * @tc.number : ParseSlotFromDisturbeDB_00100 * @tc.name : ParseSlotFromDisturbeDB @@ -808,6 +860,91 @@ HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01300, Fun preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); } +/** + * @tc.number : ParseSlotFromDisturbeDB_01400 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01400, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_slot_type_1_reminderFlagsType"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01500 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01500, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_slot_type_1_authorizedStatus"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01600 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01600, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_slot_type_1_authHintCnt"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01700 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01700, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_slot_type_1_reminderMode"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); +} + +/** + * @tc.number : ParseSlotFromDisturbeDB_01800 + * @tc.name : ParseSlotFromDisturbeDB + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseSlotFromDisturbeDB_01800, Function | SmallTest | Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(bundleName_); + bundleInfo.SetBundleUid(bundleUid_); + std::string bundleKey = "bundleKey"; + std::pair entry; + entry.first = "ans_bundle_bundleKey_slot_type_1_vibrationSytle"; + entry.second = "1"; + ASSERT_NE(nullptr, preferncesDB_); + preferncesDB_->ParseSlotFromDisturbeDB(bundleInfo, bundleKey, entry, -1); +} + /** * @tc.name : PutHasPoppedDialog_00100 * @tc.number : @@ -935,6 +1072,19 @@ HWTEST_F(NotificationPreferencesDatabaseTest, GenerateBundleLablel_0100, TestSiz ASSERT_EQ(ret, "enabledDistributedNotification-name-1-test"); } +/** + * @tc.name: GenerateBundleLablel_0100 + * @tc.desc: test GenerateBundleLablel + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, GenerateBundleLablel_0200, TestSize.Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + std::string deviceType = "test"; + auto res = preferncesDB_->GenerateBundleLablel(slotType, deviceType, userId); + ASSERT_EQ(res, "enabledSlotDistributedNotification-test-0-100"); +} + /** * @tc.name: PutDistributedEnabledForBundle_0100 * @tc.desc: test PutDistributedEnabledForBundle with parameters @@ -1023,6 +1173,20 @@ HWTEST_F(NotificationPreferencesDatabaseTest, AddDoNotDisturbProfiles_0100, Test ASSERT_EQ(res, true); } +/** + * @tc.name: AddDoNotDisturbProfiles_0200 + * @tc.desc: test AddDoNotDisturbProfiles + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, AddDoNotDisturbProfiles_0200, TestSize.Level1) +{ + std::vector> profiles; + sptr profile = nullptr; + profiles.push_back(profile); + auto ret = preferncesDB_->AddDoNotDisturbProfiles(userId, profiles); + ASSERT_FALSE(ret); +} + /** * @tc.name: RemoveDoNotDisturbProfiles_0100 * @tc.desc: test RemoveDoNotDisturbProfiles run success. @@ -1048,6 +1212,20 @@ HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbProfiles_0100, T ASSERT_EQ(res, true); } +/** + * @tc.name: RemoveDoNotDisturbProfiles_0200 + * @tc.desc: test RemoveDoNotDisturbProfiles + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, RemoveDoNotDisturbProfiles_0200, TestSize.Level1) +{ + std::vector> profiles; + sptr profile = nullptr; + profiles.push_back(profile); + auto ret = preferncesDB_->RemoveDoNotDisturbProfiles(userId, profiles); + ASSERT_FALSE(ret); +} + /** * @tc.name: GetDoNotDisturbProfiles_0100 * @tc.desc: test GetDoNotDisturbProfiles return of QueryData is not zero. @@ -1215,5 +1393,160 @@ HWTEST_F(NotificationPreferencesDatabaseTest, GetSubscriberExistFlag_0100, TestS auto ret = preferncesDB_->GetSubscriberExistFlag(deviceType, enabled); EXPECT_TRUE(ret); } + +/** + * @tc.name: IsNotificationSlotFlagsExists_0100 + * @tc.desc: test IsNotificationSlotFlagsExists + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, IsNotificationSlotFlagsExists_0100, TestSize.Level1) +{ + sptr bundleOption = nullptr; + auto ret = preferncesDB_->IsNotificationSlotFlagsExists(bundleOption); + ASSERT_FALSE(ret); +} + +/** + * @tc.name: ParseFromDisturbeDB_0100 + * @tc.desc: test ParseFromDisturbeDB + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseFromDisturbeDB_0100, TestSize.Level1) +{ + NotificationPreferencesInfo preferencesInfo; + auto ret = preferncesDB_->ParseFromDisturbeDB(preferencesInfo, userId); + ASSERT_TRUE(ret); +} + +/** + * @tc.name: ParseBundleFromDistureDB_0100 + * @tc.desc: test ParseBundleFromDistureDB + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, ParseBundleFromDistureDB_0100, TestSize.Level1) +{ + NotificationPreferencesInfo preferencesInfo; + std::unordered_map values; + values["test"] = "test"; + preferncesDB_->ParseBundleFromDistureDB(preferencesInfo, values, userId); + ASSERT_EQ(1, preferencesInfo.infos_.size()); + preferencesInfo.infos_.clear(); +} + +/** + * @tc.name: StringToVector_0100 + * @tc.desc: test StringToVector + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, StringToVector_0100, TestSize.Level1) +{ + std::string str = ""; + std::vector data; + preferncesDB_->StringToVector(str, data); + ASSERT_EQ(0, data.size()); +} + +/** + * @tc.name: StringToVector_0200 + * @tc.desc: test StringToVector + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, StringToVector_0200, TestSize.Level1) +{ + std::string str = "1_2_3"; + std::vector data; + preferncesDB_->StringToVector(str, data); + ASSERT_EQ(2, data.size()); +} + +/** + * @tc.name: GetByteFromDb_0100 + * @tc.desc: test GetByteFromDb + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, GetByteFromDb_0100, TestSize.Level1) +{ + std::string key; + std::vector value; + auto res = preferncesDB_->GetByteFromDb(key, value, userId); + ASSERT_NE(res, ERR_OK); +} + +/** + * @tc.name: DeleteBatchKvFromDb_0100 + * @tc.desc: test DeleteBatchKvFromDb + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, DeleteBatchKvFromDb_0100, TestSize.Level1) +{ + std::vector keys; + auto res = preferncesDB_->DeleteBatchKvFromDb(keys, userId); + ASSERT_EQ(res, ERR_OK); +} + +/** + * @tc.name: SetDistributedEnabledBySlot_0100 + * @tc.desc: test SetDistributedEnabledBySlot + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, SetDistributedEnabledBySlot_0100, TestSize.Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + std::string deviceType = "test1"; + + auto res = preferncesDB_->SetDistributedEnabledBySlot(slotType, deviceType, true); + ASSERT_EQ(res, true); + + bool enabled = false; + res = preferncesDB_->IsDistributedEnabledBySlot(slotType, deviceType, enabled); + ASSERT_EQ(res, true); + ASSERT_EQ(enabled, true); +} + +/** + * @tc.name: SetDistributedEnabledBySlot_0200 + * @tc.desc: test SetDistributedEnabledBySlot + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, SetDistributedEnabledBySlot_0200, TestSize.Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; + std::string deviceType = "test2"; + + bool enabled = false; + auto res = preferncesDB_->IsDistributedEnabledBySlot(slotType, deviceType, enabled); + ASSERT_EQ(res, true); + ASSERT_EQ(enabled, true); +} + +/** + * @tc.name: UpdateBundlePropertyToDisturbeDB_0100 + * @tc.desc: test UpdateBundlePropertyToDisturbeDB + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, UpdateBundlePropertyToDisturbeDB_0100, TestSize.Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName("test1"); + bundleInfo.SetBundleUid(1000); + + auto res = preferncesDB_->UpdateBundlePropertyToDisturbeDB(userId, bundleInfo); + ASSERT_EQ(res, true); +} + +/** + * @tc.name: UpdateBundlePropertyToDisturbeDB_0200 + * @tc.desc: test UpdateBundlePropertyToDisturbeDB + * @tc.type: FUNC + */ +HWTEST_F(NotificationPreferencesDatabaseTest, UpdateBundlePropertyToDisturbeDB_0200, TestSize.Level1) +{ + NotificationPreferencesInfo::BundleInfo bundleInfo; + bundleInfo.SetBundleName(""); + bundleInfo.SetBundleUid(1000); + + auto res = preferncesDB_->UpdateBundlePropertyToDisturbeDB(userId, bundleInfo); + ASSERT_EQ(res, false); +} } // 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 9b59c71b46a882a3e17ff9abd33590f338e12bda..a4ffc4433a7c725daa91569a3c09e1c4f00f2138 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -28,6 +28,8 @@ using namespace testing::ext; namespace OHOS { namespace Notification { +extern void MockIsVerfyPermisson(bool isVerify); + class NotificationPreferencesTest : public testing::Test { public: static void SetUpTestCase() {}; @@ -1679,5 +1681,302 @@ HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledForBundle_0300, TestS EXPECT_EQ(ret, true); EXPECT_EQ(isDistributedEnabled, true); } + +/** + * @tc.number : UpdateProfilesUtil_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, UpdateProfilesUtil_00100, Function | SmallTest | Level1) +{ + NotificationBundleOption bundleOne; + bundleOne.SetBundleName("test1"); + bundleOne.SetUid(100); + NotificationBundleOption bundleTwo; + std::vector bundleList; + bundleList.push_back(bundleOne); + bundleList.push_back(bundleTwo); + std::vector trustList; + trustList.push_back(bundleOne); + NotificationPreferences::GetInstance()->UpdateProfilesUtil(trustList, bundleList); + ASSERT_EQ(bundleList.size(), trustList.size()); +} + +/** + * @tc.number : UpdateDoNotDisturbProfiles_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00100, Function | SmallTest | Level1) +{ + int32_t profileId = 3; + int32_t userId = 100; + std::string name = "testProfile"; + std::vector bundleList; + + NotificationBundleOption bundleOne; + bundleOne.SetBundleName("test1"); + bundleOne.SetUid(100); + bundleList.push_back(bundleOne); + + NotificationCloneBundleInfo cloneBundleInfo; + NotificationPreferences::GetInstance()->UpdateCloneBundleInfo( + userId, cloneBundleInfo); + + auto res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles( + userId, profileId, name, bundleList); + ASSERT_EQ(res, ERR_OK); +} + +/** + * @tc.number : UpdateDoNotDisturbProfiles_00200 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, UpdateDoNotDisturbProfiles_00200, Function | SmallTest | Level1) +{ + int32_t profileId = 0; + int32_t userId = 100; + std::string name = "testProfile"; + std::vector bundleList; + + NotificationBundleOption bundleOne; + bundleOne.SetBundleName("test1"); + bundleOne.SetUid(100); + bundleList.push_back(bundleOne); + + auto res = NotificationPreferences::GetInstance()->UpdateDoNotDisturbProfiles( + userId, profileId, name, bundleList); + ASSERT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : GetTemplateSupported_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, GetTemplateSupported_00100, Function | SmallTest | Level1) +{ + bool support = false; + auto res = NotificationPreferences::GetInstance()->GetTemplateSupported( + "", support); + ASSERT_EQ(res, ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : SetDistributedEnabledBySlot_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, SetDistributedEnabledBySlot_00100, Function | SmallTest | Level1) +{ + NotificationConstant::SlotType slotType = NotificationConstant::SlotType::LIVE_VIEW; + auto res = NotificationPreferences::GetInstance()->SetDistributedEnabledBySlot( + slotType, "test", true); + ASSERT_EQ(res, ERR_OK); + + bool enabled = false; + res = NotificationPreferences::GetInstance()->IsDistributedEnabledBySlot( + slotType, "test", enabled); + ASSERT_EQ(res, ERR_OK); + ASSERT_EQ(enabled, true); +} + + +/** + * @tc.number : GetByteFromDb_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, GetByteFromDb_00100, Function | SmallTest | Level1) +{ + std::vector value; + auto res = NotificationPreferences::GetInstance()->GetByteFromDb( + "test", value, 100); + ASSERT_NE(res, ERR_OK); +} + +/** + * @tc.number : DeleteBatchKvFromDb_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, DeleteBatchKvFromDb_00100, Function | SmallTest | Level1) +{ + std::vector keys; + auto res = NotificationPreferences::GetInstance()->DeleteBatchKvFromDb( + keys, 100); + ASSERT_EQ(res, ERR_OK); +} + +/** + * @tc.number : IsAgentRelationship_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, IsAgentRelationship_00100, Function | SmallTest | Level1) +{ + MockIsVerfyPermisson(true); + auto res = NotificationPreferences::GetInstance()->IsAgentRelationship( + "test1", "test2"); + ASSERT_EQ(res, true); +} + +/** + * @tc.number : GetAdditionalConfig_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, GetAdditionalConfig_00100, Function | SmallTest | Level1) +{ + auto res = NotificationPreferences::GetInstance()->GetAdditionalConfig("test"); + ASSERT_EQ(res, ""); +} + +/** + * @tc.number : DelCloneProfileInfo_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, DelCloneProfileInfo_00100, Function | SmallTest | Level1) +{ + sptr info(new NotificationDoNotDisturbProfile()); + info->SetProfileId(1); + info->SetProfileName("TestName"); + + NotificationBundleOption bundleOption; + bundleOption.SetBundleName("bundleName"); + bundleOption.SetUid(100); + + std::vector trustList; + trustList.push_back(bundleOption); + info->SetProfileTrustList(trustList); + + auto res = NotificationPreferences::GetInstance()->DelCloneProfileInfo( + 100, info); + ASSERT_EQ(res, true); +} + +/** + * @tc.number : UpdateBatchCloneProfileInfo_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, UpdateBatchCloneProfileInfo_00100, Function | SmallTest | Level1) +{ + std::vector> infos; + + sptr info(new NotificationDoNotDisturbProfile()); + info->SetProfileId(1); + info->SetProfileName("TestName"); + infos.push_back(info); + + NotificationBundleOption bundleOption; + bundleOption.SetBundleName("bundleName"); + bundleOption.SetUid(100); + + std::vector trustList; + trustList.push_back(bundleOption); + info->SetProfileTrustList(trustList); + + + auto res = NotificationPreferences::GetInstance()->UpdateBatchCloneProfileInfo( + 100, infos); + ASSERT_EQ(res, true); +} + +/** + * @tc.number : UpdateBatchCloneBundleInfo_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, UpdateBatchCloneBundleInfo_00100, Function | SmallTest | Level1) +{ + std::vector cloneBundleInfos; + NotificationCloneBundleInfo cloneBundleInfo; + cloneBundleInfos.push_back(cloneBundleInfo); + auto res = NotificationPreferences::GetInstance()->UpdateBatchCloneBundleInfo( + 100, cloneBundleInfos); + ASSERT_EQ(res, true); + + std::vector cloneBundleInfoRes; + NotificationPreferences::GetInstance()->GetAllCloneBundleInfo( + 100, cloneBundleInfoRes); + ASSERT_EQ(cloneBundleInfoRes.size(), cloneBundleInfos.size()); + + std::vector> profilesInfos; + NotificationPreferences::GetInstance()->GetAllCloneProfileInfo( + 100, profilesInfos); + ASSERT_EQ(0, profilesInfos.size()); +} + +/** + * @tc.number : DelCloneBundleInfo_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, DelCloneBundleInfo_00100, Function | SmallTest | Level1) +{ + NotificationCloneBundleInfo cloneBundleInfo; + auto res = NotificationPreferences::GetInstance()->DelCloneBundleInfo( + 100, cloneBundleInfo); + ASSERT_EQ(res, true); +} + +/** + * @tc.number : DelBatchCloneProfileInfo_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, DelBatchCloneProfileInfo_00100, Function | SmallTest | Level1) +{ + sptr profileInfo(new NotificationDoNotDisturbProfile()); + + std::vector> profileInfos; + profileInfos.push_back(profileInfo); + + auto res = NotificationPreferences::GetInstance()->DelBatchCloneProfileInfo( + 100, profileInfos); + ASSERT_EQ(res, true); +} + +/** + * @tc.number : GetAllLiveViewEnabledBundles_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, GetAllLiveViewEnabledBundles_00100, Function | SmallTest | Level1) +{ + std::vector bundleOption; + auto res = NotificationPreferences::GetInstance()->GetAllLiveViewEnabledBundles( + 100, bundleOption); + ASSERT_EQ(res, ERR_OK); +} + +/** + * @tc.number : GetAllDistribuedEnabledBundles_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, GetAllDistribuedEnabledBundles_00100, Function | SmallTest | Level1) +{ + std::vector bundleOption; + std::string deviceType = "testType"; + auto res = NotificationPreferences::GetInstance()->GetAllDistribuedEnabledBundles( + 100, deviceType, bundleOption); + ASSERT_EQ(res, ERR_OK); +} + +/** + * @tc.number : SetHashCodeRule_00100 + * @tc.name : + * @tc.desc : + */ +HWTEST_F(NotificationPreferencesTest, SetHashCodeRule_00100, Function | SmallTest | Level1) +{ + auto res = NotificationPreferences::GetInstance()->SetHashCodeRule( + 100, 1); + ASSERT_EQ(res, ERR_OK); +} } // namespace Notification } // namespace OHOS