From 131d5872ab20e0741bdefe2660ef4e7ad4faf968 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Mon, 24 Jun 2024 17:55:09 +0800 Subject: [PATCH 1/2] Ans TDD add Signed-off-by: z30053788 Change-Id: I05fe14be9dcee92b3109ca0c70c8e6060ad19034 --- .../advanced_notification_service_test.cpp | 132 ++++++++++++++++++ ...ation_preferences_database_branch_test.cpp | 24 ++++ 2 files changed, 156 insertions(+) diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index f0c9d180a..19be9798b 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -13,8 +13,10 @@ * limitations under the License. */ +#include "errors.h" #include "notification_content.h" #include "notification_record.h" +#include "notification_request.h" #include #include #include @@ -680,6 +682,99 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02900, ASSERT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications, 0), (int)ERR_OK); } +/** + * @tc.number : AdvancedNotificationServiceTest_03000 + * @tc.name : ANS_SetTargetDeviceStatus_0100 + * @tc.desc : Test SetTargetDeviceStatus function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03000, Function | SmallTest | Level1) +{ + const std::string device = "current"; + const uint32_t status = 1; + ASSERT_EQ((int)advancedNotificationService_->SetTargetDeviceStatus(device, status), + (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03100 + * @tc.name : ANS_ClearAllNotificationGroupInfo_0100 + * @tc.desc : Test ClearAllNotificationGroupInfo function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03100, Function | SmallTest | Level1) +{ + const std::string localSwitch = "current"; + advancedNotificationService_->ClearAllNotificationGroupInfo(localSwitch); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03200 + * @tc.name : ANS_UpdateUnifiedGroupInfo_0100 + * @tc.desc : Test UpdateUnifiedGroupInfo function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03200, Function | SmallTest | Level1) +{ + const std::string key = "key"; + std::shared_ptr groupInfo; + advancedNotificationService_->UpdateUnifiedGroupInfo(key, groupInfo); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03300 + * @tc.name : ANS_RemoveSystemLiveViewNotificationsOfSa_0100 + * @tc.desc : Test RemoveSystemLiveViewNotificationsOfSa function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03300, Function | SmallTest | Level1) +{ + sptr request = new (std::nothrow) NotificationRequest(); + sptr notification = new (std::nothrow) Notification(request); + auto record = std::make_shared(); + record->request = request; + record->notification = notification; + advancedNotificationService_->notificationList_.push_back(record); + int32_t uid = 0; + ASSERT_EQ((int)advancedNotificationService_->RemoveSystemLiveViewNotificationsOfSa(uid), + (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03400 + * @tc.name : ANS_IsAllowedNotifyForBundle_0100 + * @tc.desc : Test IsAllowedNotifyForBundle function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03400, Function | SmallTest | Level1) +{ + bool allowed = false; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + auto ret = advancedNotificationService_->IsAllowedNotifyForBundle(bundleOption, allowed); + ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03500 + * @tc.name : ANS_CancelAsBundleWithAgent_0100 + * @tc.desc : Test CancelAsBundleWithAgent function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03500, Function | SmallTest | Level1) +{ + int32_t id = 0; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(); + auto ret = advancedNotificationService_->CancelAsBundleWithAgent(bundleOption, id); + ASSERT_EQ(ret, (int)ERR_ANS_NO_AGENT_SETTING); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_03600 + * @tc.name : ANS_AddDoNotDisturbProfiles_0100 + * @tc.desc : Test AddDoNotDisturbProfiles function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03600, Function | SmallTest | Level1) +{ + sptr date = nullptr; + std::vector> profiles = { date }; + auto ret = advancedNotificationService_->AddDoNotDisturbProfiles(profiles); + ASSERT_EQ(ret, (int)ERR_OK); +} + /** * @tc.number : AdvancedNotificationServiceTest_03700 * @tc.name : ANS_Delete_0100 @@ -767,6 +862,43 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04100, SleepForFC(); } +/** + * @tc.number : AdvancedNotificationServiceTest_04200 + * @tc.name : ANS_AddDoNotDisturbProfiles_0100 + * @tc.desc : Test AddDoNotDisturbProfiles function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04200, Function | SmallTest | Level1) +{ + sptr date = nullptr; + std::vector> profiles = { date }; + auto ret = advancedNotificationService_->RemoveDoNotDisturbProfiles(profiles); + ASSERT_EQ(ret, (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_04300 + * @tc.name : ANS_AddDoNotDisturbProfiles_0100 + * @tc.desc : Test AddDoNotDisturbProfiles function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04300, Function | SmallTest | Level1) +{ + sptr request(new NotificationRequest()); + std::string bundleName = "bundleName"; + advancedNotificationService_->SetAgentNotification(request, bundleName); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_04400 + * @tc.name : ANS_AddDoNotDisturbProfiles_0100 + * @tc.desc : Test AddDoNotDisturbProfiles function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04400, Function | SmallTest | Level1) +{ + std::string enable = "enable"; + auto ret = advancedNotificationService_->GetUnifiedGroupInfoFromDb(enable); + ASSERT_EQ(ret, -1); +} + /** * @tc.number : AdvancedNotificationServiceTest_04600 * @tc.name : ANS_Publish_0500 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 index a3f79eee7..4b6f9574e 100755 --- 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 @@ -1029,5 +1029,29 @@ HWTEST_F(NotificationPreferencesDatabaseBranchTest, PutSlotFlags_00100, Function NotificationPreferencesInfo::BundleInfo bundleInfo; ASSERT_EQ(preferncesDB_->PutSlotFlags(bundleInfo, 0), true); } + +/** + * @tc.name : IsAgentRelationship_00100 + * @tc.number : IsAgentRelationship_00100 + * @tc.desc : test IsAgentRelationship. + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, IsAgentRelationship_00100, Function | SmallTest | Level1) +{ + std::string agent = "agent"; + std::string source = "source"; + ASSERT_EQ(preferncesDB_->IsAgentRelationship(agent, source), false); +} + +/** + * @tc.name : GetAdditionalConfig_00100 + * @tc.number : GetAdditionalConfig_00100 + * @tc.desc : test GetAdditionalConfig. + */ +HWTEST_F(NotificationPreferencesDatabaseBranchTest, GetAdditionalConfig_00100, Function | SmallTest | Level1) +{ + std::string key = "key"; + ASSERT_EQ(preferncesDB_->GetAdditionalConfig(key), ""); +} + } // namespace Notification } // namespace OHOS -- Gitee From 384e5b6ef8c6d51bb4573dd6a75b1ee5eea87cc9 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Mon, 24 Jun 2024 18:39:09 +0800 Subject: [PATCH 2/2] update Signed-off-by: z30053788 Change-Id: Ie58b6ea8fef115ac4ecd17923f1f95489e559611 --- services/ans/src/advanced_notification_publish_service.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/ans/src/advanced_notification_publish_service.cpp b/services/ans/src/advanced_notification_publish_service.cpp index 5a8bea7b4..8cbf81b23 100644 --- a/services/ans/src/advanced_notification_publish_service.cpp +++ b/services/ans/src/advanced_notification_publish_service.cpp @@ -1908,7 +1908,9 @@ ErrCode AdvancedNotificationService::PublishNotificationBySa(const sptr( + record->request->GetContent()->GetNotificationContent())->GetType() == TYPE_CODE_DOWNLOAD)) { result = SaPublishSystemLiveViewAsBundle(record); if (result == ERR_OK) { SendLiveViewUploadHiSysEvent(record, UploadStatus::CREATE); -- Gitee