diff --git a/services/ans/test/unittest/advanced_datashare_helper_test.cpp b/services/ans/test/unittest/advanced_datashare_helper_test.cpp index 67195fb78a90638698d7d7ffac5e213c5262216d..d16a5151eac1c10be4bbb9184180765846782226 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 21e3e1bb3a12950602c1e00bb383c5242a06b253..6e75f45b0d79d23ee81092b4ac710689f79cf981 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 3b0a24054fb4789ddceebfd561f5e9cc7bf67302..9149dd83f9503c1bbb51fe6df6543362ceaa97c1 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