diff --git a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp index 5aeb9ae386ebf6b43c659d3d5019522e11691da9..ea317d492f8175c8e983a6d1bd5bd1059bfda43d 100644 --- a/services/ans/test/unittest/advanced_notification_publish_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_publish_service_test.cpp @@ -1162,18 +1162,15 @@ HWTEST_F(AnsPublishServiceTest, IsNeedToControllerByDisableNotification_002, Fun */ HWTEST_F(AnsPublishServiceTest, PrePublishRequest_00001, Function | SmallTest | Level1) { - ANS_LOGE("start 1"); MockIsOsAccountExists(false); sptr request = new NotificationRequest(); request->SetReceiverUserId(-99); ASSERT_EQ(advancedNotificationService_->PrePublishRequest(request), (int)ERROR_USER_NOT_EXIST); - ANS_LOGE("start 2"); MockIsOsAccountExists(true); sptr request1 = new NotificationRequest(); request1->SetCreatorUid(0); request1->SetReceiverUserId(100); ASSERT_EQ(advancedNotificationService_->PrePublishRequest(request1), (int)ERR_ANS_INVALID_UID); - ANS_LOGE("start 3"); sptr request2 = new NotificationRequest(); request2->SetDeliveryTime(-1); request2->SetReceiverUserId(100); diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index a6826387745803f520966e806a7dd7130b174d70..2c9d76201ca12b277f2725f7bff32d9dbde9a566 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1787,6 +1787,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_19900, AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); ans.OnDistributedPublish(deviceId, bundleName, request); GTEST_LOG_(INFO) << "CheckDistributedNotificationType_0100 test end"; @@ -1811,6 +1812,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20000, AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); ans.OnDistributedUpdate(deviceId, bundleName, request); GTEST_LOG_(INFO) << "OnDistributedUpdate_0100 test end"; @@ -1933,6 +1935,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20600, AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); MockIsSystemApp(false); ans.OnResourceRemove(userId); MockIsSystemApp(true); @@ -1985,7 +1988,20 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_20900, recentNotification->notification = notification; advancedNotificationService_->recentInfo_->list.emplace_front(recentNotification); advancedNotificationService_->GetDumpInfo(args2, result); - + std::string resMsg = "error: unknown option.\n" + "The arguments are illegal and you can enter '-h' for help.notification list:\n" + "No.1\n" + "\tUserId: -1\n" + "\tCreatePid: 0\n" + "\tBundleName: \n" + "\tOwnerUid: 0\n" + "\tReceiverUserId: -1\n" + "\tDeliveryTime = 1970-01-01, 08:00:00\n" + "\tNotification:\n" + "\t\tId: 1\n" + "\t\tLabel: \n" + "\t\tSlotType = 5\n"; + ASSERT_EQ(result, resMsg); GTEST_LOG_(INFO) << "GetDumpInfo_0100 test end"; } diff --git a/services/ans/test/unittest/advanced_notification_utils_test.cpp b/services/ans/test/unittest/advanced_notification_utils_test.cpp index 8a5b60dc96fd375217150df26bdb3f17cb38ec3a..a085b6ac5c71bb57c5132de7b4046706288f981e 100644 --- a/services/ans/test/unittest/advanced_notification_utils_test.cpp +++ b/services/ans/test/unittest/advanced_notification_utils_test.cpp @@ -333,6 +333,7 @@ HWTEST_F(AnsUtilsTest, OnBundleDataCleared_00001, Function | SmallTest | Level1) AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); ans.OnBundleDataCleared(bundle); EXPECT_NE(advancedNotificationService_, nullptr); } @@ -345,6 +346,7 @@ HWTEST_F(AnsUtilsTest, OnBundleDataCleared_00001, Function | SmallTest | Level1) */ HWTEST_F(AnsUtilsTest, InitNotificationEnableList_00001, Function | SmallTest | Level1) { + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->InitNotificationEnableList(); } @@ -390,6 +392,7 @@ HWTEST_F(AnsUtilsTest, OnBundleRemoved_00002, Function | SmallTest | Level1) { AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); sptr bundle = new NotificationBundleOption("test", 1); ans.OnBundleRemoved(bundle); } @@ -438,7 +441,8 @@ HWTEST_F(AnsUtilsTest, OnBundleDataUpdate_00001, Function | SmallTest | Level1) */ HWTEST_F(AnsUtilsTest, GetBundlesOfActiveUser_00001, Function | SmallTest | Level1) { - advancedNotificationService_->GetBundlesOfActiveUser(); + auto vec = advancedNotificationService_->GetBundlesOfActiveUser(); + ASSERT_EQ(vec.size(), 0); } /** @@ -449,6 +453,7 @@ HWTEST_F(AnsUtilsTest, GetBundlesOfActiveUser_00001, Function | SmallTest | Leve */ HWTEST_F(AnsUtilsTest, ResetDistributedEnabled_00001, Function | SmallTest | Level1) { + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->ResetDistributedEnabled(); } @@ -466,7 +471,12 @@ HWTEST_F(AnsUtilsTest, UpdateCloneBundleInfo_00001, Function | SmallTest | Level cloneBundleInfo.SetIsShowBadge(true); cloneBundleInfo.SetEnableNotification(true); cloneBundleInfo.SetSlotFlags(63); + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->UpdateCloneBundleInfo(cloneBundleInfo); + AdvancedNotificationService ans; + ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); + ans.UpdateCloneBundleInfo(cloneBundleInfo); } /** @@ -495,6 +505,7 @@ HWTEST_F(AnsUtilsTest, ExecBatchCancel_00001, Function | SmallTest | Level1) } int reason = 28; advancedNotificationService_->ExecBatchCancel(notifications, reason); + ASSERT_EQ(notifications.size() == 0, true); } /** @@ -505,6 +516,7 @@ HWTEST_F(AnsUtilsTest, ExecBatchCancel_00001, Function | SmallTest | Level1) */ HWTEST_F(AnsUtilsTest, OnBootSystemCompleted_00001, Function | SmallTest | Level1) { + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->OnBootSystemCompleted(); } @@ -519,6 +531,7 @@ HWTEST_F(AnsUtilsTest, OnDistributedKvStoreDeathRecipient_00001, Function | Smal advancedNotificationService_->OnDistributedKvStoreDeathRecipient(); AdvancedNotificationService ans; ans.notificationSvrQueue_ = nullptr; + ASSERT_EQ(nullptr, ans.notificationSvrQueue_); ans.OnDistributedKvStoreDeathRecipient(); } @@ -550,6 +563,7 @@ HWTEST_F(AnsUtilsTest, SendNotificationsOnCanceled_00001, Function | SmallTest | sptr no = new Notification(request); notifications.push_back(no); advancedNotificationService_->SendNotificationsOnCanceled(notifications, nullptr, 1); + ASSERT_EQ(notifications.size() == 0, true); } /** @@ -576,6 +590,7 @@ HWTEST_F(AnsUtilsTest, OnRecoverLiveView_00001, Function | SmallTest | Level1) sptr notification = new Notification(request); keys.push_back(notification->GetKey()); } + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->OnRecoverLiveView(keys); } @@ -602,6 +617,7 @@ HWTEST_F(AnsUtilsTest, OnRecoverLiveView_00002, Function | SmallTest | Level1) sptr notification = new Notification(request); keys.push_back(notification->GetKey()); keys.push_back("no"); + ASSERT_NE(nullptr, advancedNotificationService_); advancedNotificationService_->OnRecoverLiveView(keys); } @@ -615,7 +631,7 @@ HWTEST_F(AnsUtilsTest, AllowUseReminder_00001, Function | SmallTest | Level1) { std::string str = "test1"; bool b = false; - advancedNotificationService_->AllowUseReminder(str, b); + ASSERT_EQ(advancedNotificationService_->AllowUseReminder(str, b), (int)ERR_OK); } /** @@ -636,9 +652,11 @@ HWTEST_F(AnsUtilsTest, CloseAlert_00001, Function | SmallTest | Level1) request->SetOwnerUid(0); request->SetNotificationId(222); auto flags = std::make_shared(); + flags->SetBannerEnabled(true); request->SetFlags(flags); auto record = advancedNotificationService_->MakeNotificationRecord(request, bundle); advancedNotificationService_->CloseAlert(record); + ASSERT_EQ(flags->GetReminderFlags(), 0); } } // namespace Notification } // namespace OHOS