From f4fe1730c34b4e3ae4918e3501467c07ad34abdd Mon Sep 17 00:00:00 2001 From: songbao1 Date: Wed, 2 Apr 2025 16:08:36 +0800 Subject: [PATCH] =?UTF-8?q?tdd=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../advanced_datashare_helper_test.cpp | 19 +++ .../advanced_notification_service_test.cpp | 27 +++- ...nced_notification_service_publish_test.cpp | 117 ++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/services/ans/test/unittest/advanced_datashare_helper_test.cpp b/services/ans/test/unittest/advanced_datashare_helper_test.cpp index 67195fb78..d16a5151e 100644 --- a/services/ans/test/unittest/advanced_datashare_helper_test.cpp +++ b/services/ans/test/unittest/advanced_datashare_helper_test.cpp @@ -155,6 +155,25 @@ HWTEST_F(AdvancedDatashareHelperTest, QueryContact_0003, Function | SmallTest | EXPECT_EQ(ret, -1); } +// Test cases +HWTEST_F(AdvancedDatashareHelperTest, QueryContact_0004, Function | SmallTest | Level1) +{ + MockGetSystemAbilityManager(false); + MockSetRowCount(1); + MockIsFailedToCreateDataShareHelper(false); + MockIsFailedGoToFirstRow(0); + MockGoToGetNextRow(-1); + + AdvancedDatashareHelper advancedDatashareHelper; + std::string uri = "datashare:///com.ohos.contactsdataability/contacts/contact_data?Proxy=true"; + Uri contactUri(uri); + std::string phoneNumber = "1111"; + + bool ret = advancedDatashareHelper.QueryContact( + contactUri, phoneNumber, "4", "1", "true"); + EXPECT_EQ(ret, 1); +} + HWTEST_F(AdvancedDatashareHelperTest, isRepeatCall_0001, Function | SmallTest | Level1) { MockGetSystemAbilityManager(false); diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 21e3e1bb3..6e75f45b0 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -4203,7 +4203,7 @@ HWTEST_F(AdvancedNotificationServiceTest, Dialog_00005, Function | SmallTest | L } /** - * @tc.name : Dialog_00005 + * @tc.name : Dialog_00006 * @tc.number : * @tc.desc : test dialogEventSubscriber.OnReceiveEvent */ @@ -4228,6 +4228,31 @@ HWTEST_F(AdvancedNotificationServiceTest, Dialog_00006, Function | SmallTest | L ASSERT_EQ(enable, false); } +/** + * @tc.name : Dialog_00007 + * @tc.number : + * @tc.desc : test dialogEventSubscriber.SetHasPoppedDialog + */ +HWTEST_F(AdvancedNotificationServiceTest, Dialog_00007, Function | SmallTest | Level1) +{ + advancedNotificationService_->CreateDialogManager(); + sptr bundleOption = nullptr; + ASSERT_EQ(advancedNotificationService_->dialogManager_->SetHasPoppedDialog(bundleOption, true), false); +} + +/** + * @tc.name : Dialog_00008 + * @tc.number : + * @tc.desc : test dialogEventSubscriber.SetHasPoppedDialog + */ +HWTEST_F(AdvancedNotificationServiceTest, Dialog_00008, Function | SmallTest | Level1) +{ + advancedNotificationService_->CreateDialogManager(); + sptr bundleOption = nullptr; + ASSERT_EQ(advancedNotificationService_->dialogManager_->HandleOneDialogClosed( + bundleOption, EnabledDialogStatus::ALLOW_CLICKED), false); +} + /** * @tc.name : SetNotificationRemindType_00001 * @tc.number : diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp index 3b0a24054..9149dd83f 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp @@ -1559,5 +1559,122 @@ HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0800, Function | SmallT NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, enable); ASSERT_EQ(enable, true); } + +/** + * @tc.number : OnReceiveEvent_0900 + * @tc.name : OnReceiveEvent_0900 + * @tc.desc : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_0900, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + MockSetBundleInfoEnabled(true); + EventFwk::Want want; + EventFwk::CommonEventData data; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED); + data.SetWant(want); + data.SetCode(0); + advancedNotificationService.systemEventObserver_->callbacks_.onBootSystemCompleted = nullptr; + advancedNotificationService.systemEventObserver_->OnReceiveEvent(data); + + SleepForFC(); + sptr bundle = new NotificationBundleOption("test", 1); + bool enable = false; + NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, enable); + ASSERT_EQ(enable, false); +} + +/** + * @tc.number : OnReceiveEvent_1000 + * @tc.name : OnReceiveEvent_1000 + * @tc.desc : Test OnReceiveEvent COMMON_EVENT_PACKAGE_REMOVED + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1000, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + MockSetBundleInfoEnabled(true); + EventFwk::Want want; + EventFwk::CommonEventData data; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) + .SetElementName("test", "") + .SetParam("uid", 1); + data.SetWant(want); + data.SetCode(0); + advancedNotificationService.systemEventObserver_->callbacks_.onBundleAdd = nullptr; + advancedNotificationService.systemEventObserver_->OnReceiveEvent(data); + + sptr bundle = new NotificationBundleOption("test", 1); + SleepForFC(); + bool enable = false; + NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, enable); + ASSERT_EQ(enable, false); +} + +/** + * @tc.number : OnReceiveEvent_1100 + * @tc.name : OnReceiveEvent_1100 + * @tc.desc : Test OnReceiveEvent COMMON_EVENT_PACKAGE_CHANGED + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1100, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + MockSetBundleInfoEnabled(true); + EventFwk::Want want; + EventFwk::CommonEventData data; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) + .SetElementName("test", "") + .SetParam("uid", 1); + data.SetWant(want); + data.SetCode(0); + advancedNotificationService.systemEventObserver_->callbacks_.onBundleUpdate = nullptr; + advancedNotificationService.systemEventObserver_->OnReceiveEvent(data); + + sptr bundle = new NotificationBundleOption("test", 1); + SleepForFC(); + bool enable = false; + NotificationPreferences::GetInstance()->GetNotificationsEnabledForBundle(bundle, enable); + ASSERT_EQ(enable, false); +} + +/** + * @tc.number : OnReceiveEvent_1200 + * @tc.name : OnReceiveEvent_1200 + * @tc.desc : Test OnReceiveEvent COMMON_EVENT_SCREEN + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1200, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + MockSetBundleInfoEnabled(true); + EventFwk::Want want; + EventFwk::CommonEventData data; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON); + data.SetWant(want); + data.SetCode(0); + advancedNotificationService.systemEventObserver_->OnReceiveEvent(data); + ASSERT_EQ(advancedNotificationService.localScreenOn_, true); +} + +/** + * @tc.number : OnReceiveEvent_1300 + * @tc.name : OnReceiveEvent_1300 + * @tc.desc : Test OnReceiveEvent COMMON_EVENT_SCREEN + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1300, Function | SmallTest | Level1) +{ + AdvancedNotificationService advancedNotificationService; + MockSetBundleInfoEnabled(true); + EventFwk::Want want; + EventFwk::CommonEventData data; + want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF); + data.SetWant(want); + data.SetCode(0); + advancedNotificationService.systemEventObserver_->OnReceiveEvent(data); + ASSERT_EQ(advancedNotificationService.localScreenOn_, false); +} } // namespace Notification } // namespace OHOS -- Gitee