From dafe109b6cd3c30aac9fbe813bf21763a012267c Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Thu, 30 Jun 2022 15:52:04 +0800 Subject: [PATCH] IssueNo:#I582Y4 Description:Supply testcase for hisysevent. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: If831fe4ed88fc2eaa446aacec9f82511cd468579 --- services/ans/test/unittest/BUILD.gn | 7 +- .../advanced_notification_service_test.cpp | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index e2c5fbb79..3bc643f9f 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -89,7 +89,6 @@ ohos_unittest("ans_unit_test") { "common_event_service:cesfwk_innerkits", "distributeddatamgr:distributeddata_inner", "eventhandler:libeventhandler", - "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", @@ -107,6 +106,12 @@ ohos_unittest("ans_unit_test") { defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] } + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent_native:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + subsystem_name = "${subsystem_name}" part_name = "${component_name}" } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 26c4c0c17..e0e43a51e 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1108,6 +1108,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); EXPECT_EQ((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM); EXPECT_EQ((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); } @@ -1652,5 +1653,89 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, EXPECT_EQ( advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); } + +/** + * @tc.name: AdvancedNotificationServiceTest_12000 + * @tc.desc: Send enable notification hisysevent and enable notification error hisysevent. + * @tc.type: FUNC + * @tc.require: I582Y4 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12000, Function | SmallTest | Level1) +{ + // bundleName is empty + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( + std::string(), new NotificationBundleOption(std::string(), -1), true), + (int)ERR_ANS_INVALID_PARAM); + + TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + req->SetLabel("req's label"); + std::string label = "enable's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + EXPECT_EQ(advancedNotificationService_->SetNotificationsEnabledForSpecialBundle( + std::string(), new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), false), + (int)ERR_OK); + + EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NOT_ALLOWED); + SleepForFC(); +} + +/** + * @tc.name: AdvancedNotificationServiceTest_12100 + * @tc.desc: Send enable notification slot hisysevent. + * @tc.type: FUNC + * @tc.require: I582Y4 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12100, Function | SmallTest | Level1) +{ + TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + sptr req = new NotificationRequest(); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + req->SetLabel("req's label"); + std::string label = "enable's label"; + std::shared_ptr normalContent = std::make_shared(); + EXPECT_NE(normalContent, nullptr); + normalContent->SetText("normalContent's text"); + normalContent->SetTitle("normalContent's title"); + std::shared_ptr content = std::make_shared(normalContent); + EXPECT_NE(content, nullptr); + req->SetContent(content); + auto result = advancedNotificationService_->SetEnabledForBundleSlot( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), + NotificationConstant::SlotType::SOCIAL_COMMUNICATION, + false); + EXPECT_EQ(result, (int)ERR_OK); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED); + SleepForFC(); +} + +/** + * @tc.name: AdvancedNotificationServiceTest_12200 + * @tc.desc: Send remove notification hisysevent. + * @tc.type: FUNC + * @tc.require: I582Y4 + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12200, Function | SmallTest | Level1) +{ + TestAddSlot(NotificationConstant::SlotType::OTHER); + int32_t notificationId = 1; + std::string label = "testRemove"; + sptr req = new NotificationRequest(notificationId); + req->SetSlotType(NotificationConstant::OTHER); + req->SetLabel(label); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_OK); + auto result = advancedNotificationService_->RemoveNotification( + new NotificationBundleOption(TEST_DEFUALT_BUNDLE, SYSTEM_APP_UID), notificationId, label); + EXPECT_EQ(result, (int)ERR_OK); +} } // namespace Notification } // namespace OHOS \ No newline at end of file -- Gitee