diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 60b4a295f89f22f88bb5f1cbdee752f039acf396..5c973860715ebba9b0e6da6eadc3763c7c495a38 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1996,6 +1996,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15300, Function | SmallTest | Level1) { + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); std::string cmd = "CMD"; std::string bundle = "Bundle"; int32_t userId = 4; @@ -2015,5 +2016,79 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15400, std::vector args; EXPECT_EQ(advancedNotificationService_->Dump(fd, args), (int)ERR_OK); } + +/** + * @tc.number : AdvancedNotificationServiceTest_15500 + * @tc.name : OnReceiveEvent_0100 + * @tc.desc : Test OnReceiveEvent function userid req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish'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); + req->SetCreatorUserId(DEFAULT_USER_ID); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK); + SleepForFC(); + + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + data.SetCode(50); + advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data); + + std::stringstream key; + key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_" + << req->GetLabel() << "_" << req->GetNotificationId(); + + EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_15600 + * @tc.name : OnReceiveEvent_0200 + * @tc.desc : Test OnReceiveEvent function when userid>DEFAULT_USER_ID + * @tc.require : I5TIQR + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_15600, Function | SmallTest | Level1) +{ + sptr req = new (std::nothrow) NotificationRequest(1); + EXPECT_NE(req, nullptr); + req->SetSlotType(NotificationConstant::SlotType::OTHER); + req->SetLabel("req's label"); + std::string label = "publish'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); + req->SetCreatorUserId(DEFAULT_USER_ID); + EXPECT_EQ(advancedNotificationService_->Publish(label, req), ERR_OK); + SleepForFC(); + + EventFwk::Want want; + EventFwk::CommonEventData data; + data.SetWant(want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED)); + data.SetCode(200); + advancedNotificationService_->systemEventObserver_->OnReceiveEvent(data); + + std::stringstream key; + key << "_" << req->GetCreatorUserId() << "_" << req->GetCreatorUid() << "_" + << req->GetLabel() << "_" << req->GetNotificationId(); + + EXPECT_EQ(advancedNotificationService_->IsNotificationExists(key.str()), true); +} } // namespace Notification } // namespace OHOS \ No newline at end of file