diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index 1c188c792120e4ff3e0e1fc73d2cee3d22f5eaf7..33a51584bd8a49b17d2e2f22d458f6745a564e6d 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -89,9 +89,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00100, Function | SmallTest | { struct tm nowTime; auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); - if (calendar == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, calendar); int32_t firstDesignateYear = calendar->GetActualTime(ReminderRequest::TimeTransferType::YEAR, nowTime.tm_year); EXPECT_TRUE(firstDesignateYear == calendar->GetFirstDesignateYear()) << "Set first designate year error."; } @@ -106,9 +104,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00200, Function | SmallTest | { struct tm nowTime; auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); - if (calendar == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, calendar); int firstDesignateMonth = calendar->GetActualTime(ReminderRequest::TimeTransferType::MONTH, nowTime.tm_mon); EXPECT_TRUE(firstDesignateMonth == calendar->GetFirstDesignageMonth()) << "Set first designate month error."; } @@ -123,9 +119,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00300, Function | SmallTest | { struct tm nowTime; auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); - if (calendar == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, calendar); int firstDesignateDay = nowTime.tm_mday; EXPECT_TRUE(firstDesignateDay == calendar->GetFirstDesignateDay()) << "Set first designate day error."; } @@ -141,9 +135,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | time_t now; (void)time(&now); // unit is seconds. tm *tmp = localtime(&now); - if (tmp == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, tmp); struct tm nowTime = *tmp; std::vector repeatMonths; @@ -186,9 +178,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | time_t now; time(&now); // unit is seconds. tm *tmp = localtime(&now); - if (tmp == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, tmp); tm nowTime = *tmp; nowTime.tm_year += 1; std::vector repeatMonths; @@ -219,9 +209,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | time_t now; (void)time(&now); // unit is seconds. tm *tmp = localtime(&now); - if (tmp == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, tmp); tm nowTime = *tmp; std::vector repeatMonths; std::vector repeatDays; @@ -263,9 +251,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | time_t now; (void)time(&now); // unit is seconds. tm *tmp = localtime(&now); - if (tmp == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, tmp); tm nowTime = *tmp; nowTime.tm_year += 1; std::vector repeatMonths; @@ -295,9 +281,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00800, Function | SmallTest | { struct tm nowTime; auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); - if (calendar == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, calendar); EXPECT_TRUE(1 == calendar->GetHour()) << "Set hour error."; } @@ -311,9 +295,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00900, Function | SmallTest | { struct tm nowTime; auto calendar = ReminderRequestCalendarTest::CreateCalendar(nowTime); - if (calendar == nullptr) { - EXPECT_TRUE(false) << "calendar is null"; - } + EXPECT_NE(nullptr, calendar); EXPECT_TRUE(1 == calendar->GetMinute()) << "Set minute error."; EXPECT_TRUE(0 == calendar->GetSecond()) << "Set seconds error."; } diff --git a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp index bdf631aa4fa4da0b02798e23b649479e88268430..fc44ecde1f7492ab1afe18bc5424a446e08f32b3 100644 --- a/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -80,27 +80,24 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00100, Fu sptr spSlot; EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot)); - if (spSlot == nullptr) { - GTEST_LOG_(INFO) << "get slot is empty"; - } else { - GTEST_LOG_(INFO) << "after get slot dump slot information:" << spSlot->Dump(); - EXPECT_EQ(true, spSlot->CanEnableLight()); - EXPECT_EQ(true, spSlot->CanVibrate()); - EXPECT_EQ("description", spSlot->GetDescription()); - EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetId()); - EXPECT_EQ(0, spSlot->GetLedLightColor()); - EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); - EXPECT_EQ(NotificationConstant::SOCIAL_COMMUNICATION, spSlot->GetType()); - EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness()); - EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetName()); - EXPECT_EQ(Uri("."), spSlot->GetSound()); - for (auto it : spSlot->GetVibrationStyle()) { - EXPECT_EQ(0, it); - } - EXPECT_EQ(Uri("."), spSlot->GetSound()); - EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); - EXPECT_EQ(true, spSlot->IsShowBadge()); + EXPECT_NE(nullptr, spSlot); + GTEST_LOG_(INFO) << "after get slot dump slot information:" << spSlot->Dump(); + EXPECT_EQ(true, spSlot->CanEnableLight()); + EXPECT_EQ(true, spSlot->CanVibrate()); + EXPECT_EQ("description", spSlot->GetDescription()); + EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetId()); + EXPECT_EQ(0, spSlot->GetLedLightColor()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); + EXPECT_EQ(NotificationConstant::SOCIAL_COMMUNICATION, spSlot->GetType()); + EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness()); + EXPECT_EQ("SOCIAL_COMMUNICATION", spSlot->GetName()); + EXPECT_EQ(Uri("."), spSlot->GetSound()); + for (auto it : spSlot->GetVibrationStyle()) { + EXPECT_EQ(0, it); } + EXPECT_EQ(Uri("."), spSlot->GetSound()); + EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); + EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION)); EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, NotificationHelper::GetNotificationSlot(NotificationConstant::SOCIAL_COMMUNICATION, spSlot)); @@ -129,26 +126,23 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00200, Fu sptr spSlot; EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot)); - if (spSlot == nullptr) { - GTEST_LOG_(INFO) << "get slot is empty"; - } else { - EXPECT_EQ(true, spSlot->CanEnableLight()); - EXPECT_EQ(true, spSlot->CanVibrate()); - EXPECT_EQ("description", spSlot->GetDescription()); - EXPECT_EQ("SERVICE_REMINDER", spSlot->GetId()); - EXPECT_EQ(0, spSlot->GetLedLightColor()); - EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); - EXPECT_EQ(NotificationConstant::SERVICE_REMINDER, spSlot->GetType()); - EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness()); - EXPECT_EQ("SERVICE_REMINDER", spSlot->GetName()); - EXPECT_EQ(Uri("."), spSlot->GetSound()); - for (auto it : spSlot->GetVibrationStyle()) { - EXPECT_EQ(0, it); - } - EXPECT_EQ(Uri("."), spSlot->GetSound()); - EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); - EXPECT_EQ(true, spSlot->IsShowBadge()); + EXPECT_NE(nullptr, spSlot); + EXPECT_EQ(true, spSlot->CanEnableLight()); + EXPECT_EQ(true, spSlot->CanVibrate()); + EXPECT_EQ("description", spSlot->GetDescription()); + EXPECT_EQ("SERVICE_REMINDER", spSlot->GetId()); + EXPECT_EQ(0, spSlot->GetLedLightColor()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); + EXPECT_EQ(NotificationConstant::SERVICE_REMINDER, spSlot->GetType()); + EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, spSlot->GetLockScreenVisibleness()); + EXPECT_EQ("SERVICE_REMINDER", spSlot->GetName()); + EXPECT_EQ(Uri("."), spSlot->GetSound()); + for (auto it : spSlot->GetVibrationStyle()) { + EXPECT_EQ(0, it); } + EXPECT_EQ(Uri("."), spSlot->GetSound()); + EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); + EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::SERVICE_REMINDER)); EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, NotificationHelper::GetNotificationSlot(NotificationConstant::SERVICE_REMINDER, spSlot)); @@ -178,26 +172,23 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00300, Fu sptr spSlot; EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot)); - if (spSlot == nullptr) { - GTEST_LOG_(INFO) << "get slot is empty"; - } else { - EXPECT_EQ(true, spSlot->CanEnableLight()); - EXPECT_EQ(true, spSlot->CanVibrate()); - EXPECT_EQ("description", spSlot->GetDescription()); - EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetId()); - EXPECT_EQ(0, spSlot->GetLedLightColor()); - EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); - EXPECT_EQ(NotificationConstant::CONTENT_INFORMATION, spSlot->GetType()); - EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); - EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetName()); - EXPECT_EQ(Uri("."), spSlot->GetSound()); - for (auto it : spSlot->GetVibrationStyle()) { - EXPECT_EQ(0, it); - } - EXPECT_EQ(Uri("."), spSlot->GetSound()); - EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); - EXPECT_EQ(true, spSlot->IsShowBadge()); + EXPECT_NE(nullptr, spSlot); + EXPECT_EQ(true, spSlot->CanEnableLight()); + EXPECT_EQ(true, spSlot->CanVibrate()); + EXPECT_EQ("description", spSlot->GetDescription()); + EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetId()); + EXPECT_EQ(0, spSlot->GetLedLightColor()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); + EXPECT_EQ(NotificationConstant::CONTENT_INFORMATION, spSlot->GetType()); + EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); + EXPECT_EQ("CONTENT_INFORMATION", spSlot->GetName()); + EXPECT_EQ(Uri("."), spSlot->GetSound()); + for (auto it : spSlot->GetVibrationStyle()) { + EXPECT_EQ(0, it); } + EXPECT_EQ(Uri("."), spSlot->GetSound()); + EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); + EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::CONTENT_INFORMATION)); EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, NotificationHelper::GetNotificationSlot(NotificationConstant::CONTENT_INFORMATION, spSlot)); @@ -226,26 +217,23 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00400, Fu sptr spSlot; EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); - if (spSlot == nullptr) { - GTEST_LOG_(INFO) << "get slot is empty"; - } else { - EXPECT_EQ(true, spSlot->CanEnableLight()); - EXPECT_EQ(true, spSlot->CanVibrate()); - EXPECT_EQ("description", spSlot->GetDescription()); - EXPECT_EQ("OTHER", spSlot->GetId()); - EXPECT_EQ(0, spSlot->GetLedLightColor()); - EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); - EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType()); - EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); - EXPECT_EQ("OTHER", spSlot->GetName()); - EXPECT_EQ(Uri("."), spSlot->GetSound()); - for (auto it : spSlot->GetVibrationStyle()) { - EXPECT_EQ(0, it); - } - EXPECT_EQ(Uri("."), spSlot->GetSound()); - EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); - EXPECT_EQ(true, spSlot->IsShowBadge()); + EXPECT_NE(nullptr, spSlot); + EXPECT_EQ(true, spSlot->CanEnableLight()); + EXPECT_EQ(true, spSlot->CanVibrate()); + EXPECT_EQ("description", spSlot->GetDescription()); + EXPECT_EQ("OTHER", spSlot->GetId()); + EXPECT_EQ(0, spSlot->GetLedLightColor()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); + EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType()); + EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); + EXPECT_EQ("OTHER", spSlot->GetName()); + EXPECT_EQ(Uri("."), spSlot->GetSound()); + for (auto it : spSlot->GetVibrationStyle()) { + EXPECT_EQ(0, it); } + EXPECT_EQ(Uri("."), spSlot->GetSound()); + EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); + EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER)); EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); @@ -276,28 +264,25 @@ HWTEST_F(AnsInnerKitsModuleSlotTest, ANS_Interface_MT_NotificationSlot_00500, Fu sptr spSlot; EXPECT_EQ(0, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); - if (spSlot == nullptr) { - GTEST_LOG_(INFO) << "get slot is empty"; - } else { - GTEST_LOG_(INFO) << "get slot is:" << spSlot->Dump(); - EXPECT_EQ(true, spSlot->CanEnableLight()); - EXPECT_EQ(true, spSlot->CanVibrate()); - std::string expecteDescription(1000, 'c'); - EXPECT_EQ(expecteDescription, spSlot->GetDescription()); - EXPECT_EQ("OTHER", spSlot->GetId()); - EXPECT_EQ(0, spSlot->GetLedLightColor()); - EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); - EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType()); - EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); - EXPECT_EQ("OTHER", spSlot->GetName()); - EXPECT_EQ(Uri("."), spSlot->GetSound()); - for (auto it : spSlot->GetVibrationStyle()) { - EXPECT_EQ(0, it); - } - EXPECT_EQ(Uri("."), spSlot->GetSound()); - EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); - EXPECT_EQ(true, spSlot->IsShowBadge()); + EXPECT_NE(nullptr, spSlot); + GTEST_LOG_(INFO) << "get slot is:" << spSlot->Dump(); + EXPECT_EQ(true, spSlot->CanEnableLight()); + EXPECT_EQ(true, spSlot->CanVibrate()); + std::string expecteDescription(1000, 'c'); + EXPECT_EQ(expecteDescription, spSlot->GetDescription()); + EXPECT_EQ("OTHER", spSlot->GetId()); + EXPECT_EQ(0, spSlot->GetLedLightColor()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, spSlot->GetLevel()); + EXPECT_EQ(NotificationConstant::OTHER, spSlot->GetType()); + EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, spSlot->GetLockScreenVisibleness()); + EXPECT_EQ("OTHER", spSlot->GetName()); + EXPECT_EQ(Uri("."), spSlot->GetSound()); + for (auto it : spSlot->GetVibrationStyle()) { + EXPECT_EQ(0, it); } + EXPECT_EQ(Uri("."), spSlot->GetSound()); + EXPECT_EQ(true, spSlot->IsEnableBypassDnd()); + EXPECT_EQ(true, spSlot->IsShowBadge()); EXPECT_EQ(0, NotificationHelper::RemoveNotificationSlot(NotificationConstant::OTHER)); EXPECT_EQ((int)ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST, NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index d93432c3c6b1a3d4219b1f700961b534a8131b12..73d40cb832a9b134e8d7b3e85c439c9d5782b3eb 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -94,100 +94,76 @@ void NotificationSubscriberManagerTest::TearDown() /** * @tc.number : NotificationSubscriberManagerTest_001 - * @tc.name : ANS_NotifyUpdated_0100 - * @tc.desc : Test NotifyUpdated function. + * @tc.name : ANS_AddSubscriber_0100 + * @tc.desc : Test AddSubscriber function, return is ERR_OK. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_001, Function | SmallTest | Level1) { + // Test NotifyUpdated function. const std::vector sortingList; sptr map = new NotificationSortingMap(sortingList); notificationSubscriberManager_->NotifyUpdated(map); + + // Test AddSubscriber function. + sptr info = new NotificationSubscribeInfo(); + info->AddAppName("test_bundle"); + EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(subscriber_, info), (int)ERR_OK); + EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(subscriber_, nullptr), (int)ERR_OK); } /** * @tc.number : NotificationSubscriberManagerTest_002 - * @tc.name : ANS_NotifyDisturbModeChanged_0100 - * @tc.desc : Test NotifyDisturbModeChanged function. + * @tc.name : ANS_AddSubscriber_0100 + * @tc.desc : Test AddSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_002, Function | SmallTest | Level1) { + // Test NotifyDisturbModeChanged function. sptr date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); notificationSubscriberManager_->NotifyDoNotDisturbDateChanged(date); + + // Test AddSubscriber function. + sptr info = new NotificationSubscribeInfo(); + EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(nullptr, info), (int)ERR_ANS_INVALID_PARAM); } /** * @tc.number : NotificationSubscriberManagerTest_003 - * @tc.name : ANS_NotifyConsumed_0100 - * @tc.desc : Test NotifyConsumed function. + * @tc.name : ANS_RemoveSubscriber_0100 + * @tc.desc : Test RemoveSubscriber function, return is ERR_OK. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_003, Function | SmallTest | Level1) { + // Test NotifyConsumed function. std::vector sortingList; sptr request = new NotificationRequest(); sptr notification = new Notification(request); sptr notificationMap = new NotificationSortingMap(sortingList); notificationSubscriberManager_->NotifyConsumed(notification, notificationMap); + + // Test RemoveSubscriber function. + sptr info = new NotificationSubscribeInfo(); + info->AddAppName("test_bundle"); + EXPECT_EQ(notificationSubscriberManager_->RemoveSubscriber(subscriber_, info), (int)ERR_OK); } /** * @tc.number : NotificationSubscriberManagerTest_004 - * @tc.name : ANS_NotifyCanceled_0100 - * @tc.desc : Test NotifyCanceled function. + * @tc.name : ANS_AddSubscriber_0100 + * @tc.desc : Test RemoveSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_004, Function | SmallTest | Level1) { + // Test NotifyCanceled function. std::vector sortingList; sptr request = new NotificationRequest(); sptr notification = new Notification(request); sptr notificationMap = new NotificationSortingMap(sortingList); int deleteReason = 0; notificationSubscriberManager_->NotifyCanceled(notification, notificationMap, deleteReason); -} - -/** - * @tc.number : NotificationSubscriberManagerTest_005 - * @tc.name : ANS_AddSubscriber_0100 - * @tc.desc : Test AddSubscriber function, return is ERR_OK. - */ -HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_005, Function | SmallTest | Level1) -{ - sptr info = new NotificationSubscribeInfo(); - info->AddAppName("test_bundle"); - EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(subscriber_, info), (int)ERR_OK); - EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(subscriber_, nullptr), (int)ERR_OK); -} - -/** - * @tc.number : NotificationSubscriberManagerTest_006 - * @tc.name : ANS_AddSubscriber_0100 - * @tc.desc : Test AddSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. - */ -HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_006, Function | SmallTest | Level1) -{ - sptr info = new NotificationSubscribeInfo(); - EXPECT_EQ(notificationSubscriberManager_->AddSubscriber(nullptr, info), (int)ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.number : NotificationSubscriberManagerTest_007 - * @tc.name : ANS_RemoveSubscriber_0100 - * @tc.desc : Test RemoveSubscriber function, return is ERR_OK. - */ -HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_007, Function | SmallTest | Level1) -{ - sptr info = new NotificationSubscribeInfo(); - info->AddAppName("test_bundle"); - EXPECT_EQ(notificationSubscriberManager_->RemoveSubscriber(subscriber_, info), (int)ERR_OK); -} -/** - * @tc.number : NotificationSubscriberManagerTest_006 - * @tc.name : ANS_AddSubscriber_0100 - * @tc.desc : Test RemoveSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. - */ -HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_008, Function | SmallTest | Level1) -{ + // Test RemoveSubscriber function. sptr info = new NotificationSubscribeInfo(); EXPECT_EQ(notificationSubscriberManager_->RemoveSubscriber(nullptr, info), (int)ERR_ANS_INVALID_PARAM); } diff --git a/services/ans/test/unittest/permission_filter_test.cpp b/services/ans/test/unittest/permission_filter_test.cpp index f1010e09320c16b8a054c734e50864c2334d8af9..ebfc27c78f5ed68fa236c7500d3a7c732e2b428c 100644 --- a/services/ans/test/unittest/permission_filter_test.cpp +++ b/services/ans/test/unittest/permission_filter_test.cpp @@ -46,34 +46,16 @@ void PermissionFilterTest::TearDown() /** * @tc.number : PermissionFilterTest_00100 - * @tc.name : ANS_OnStop_0100 - * @tc.desc : Test OnStart function + * @tc.name : + * @tc.desc : Test OnPublish function.Expect return ERR_OK */ HWTEST_F(PermissionFilterTest, PermissionFilterTest_00100, Function | SmallTest | Level1) { + // Test OnStart function. PermissionFilter permissionFilter; permissionFilter.OnStart(); -} - -/** - * @tc.number : PermissionFilterTest_00200 - * @tc.name : ANS_OnStop_0100 - * @tc.desc : Test OnStop function - */ -HWTEST_F(PermissionFilterTest, PermissionFilterTest_00200, Function | SmallTest | Level1) -{ - PermissionFilter permissionFilter; - permissionFilter.OnStop(); -} -/** - * @tc.number : PermissionFilterTest_00400 - * @tc.name : - * @tc.desc : Test OnPublish function.Expect return ERR_OK - */ -HWTEST_F(PermissionFilterTest, PermissionFilterTest_00400, Function | SmallTest | Level1) -{ - PermissionFilter permissionFilter; + // Test OnPublish function. sptr slot = new NotificationSlot(NotificationConstant::OTHER); std::vector> slots; slots.push_back(slot); @@ -89,13 +71,17 @@ HWTEST_F(PermissionFilterTest, PermissionFilterTest_00400, Function | SmallTest } /** - * @tc.number : PermissionFilterTest_00500 + * @tc.number : PermissionFilterTest_00200 * @tc.name : * @tc.desc : Test OnPublish function when NotificationsEnabled is false.Expect return ERR_ANS_NOT_ALLOWED */ -HWTEST_F(PermissionFilterTest, PermissionFilterTest_00500, Function | SmallTest | Level1) +HWTEST_F(PermissionFilterTest, PermissionFilterTest_00200, Function | SmallTest | Level1) { + // Test OnStop function. PermissionFilter permissionFilter; + permissionFilter.OnStop(); + + // Test OnPublish function. sptr slot = new NotificationSlot(NotificationConstant::OTHER); std::vector> slots; slots.push_back(slot);