From fd63935b4c041d4b0f5821995b5c87a41adaf856 Mon Sep 17 00:00:00 2001 From: "yangjun (CI)" Date: Sun, 15 Jun 2025 14:42:04 +0800 Subject: [PATCH] add smart reminder center's coverage of unit test Signed-off-by: yangjun --- .../unittest/smart_reminder_center_test.cpp | 490 ++++++++++++++++++ 1 file changed, 490 insertions(+) diff --git a/services/ans/test/unittest/smart_reminder_center_test.cpp b/services/ans/test/unittest/smart_reminder_center_test.cpp index 565a8dcfe..b8fc1c802 100644 --- a/services/ans/test/unittest/smart_reminder_center_test.cpp +++ b/services/ans/test/unittest/smart_reminder_center_test.cpp @@ -212,6 +212,496 @@ HWTEST_F(SmartReminderCenterTest, InitValidDevices_00002, Function | SmallTest | smartReminderCenter_->InitValidDevices(validDevices, smartDevices, statusMap, request); ASSERT_EQ(request->GetNotificationControlFlags(), 0); } +/** + * @tc.name: InitPcPadDevices_100 + * @tc.desc: Test InitPcPadDevices + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, InitPcPadDevices_100, Function | SmallTest | Level1) +{ + std::string deviceType = NotificationConstant::PC_DEVICE_TYPE; + set validDevices; + set smartDevices; + sptr request(new NotificationRequest(1)); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + map> statusMap; + + smartReminderCenter_->InitPcPadDevices(deviceType, validDevices, smartDevices, statusMap, request); + + ASSERT_EQ(validDevices.size(), 0); + ASSERT_EQ(smartDevices.size(), 0); +} + +/** + * @tc.name: InitPcPadDevices_200 + * @tc.desc: Test InitPcPadDevices when CURRENT DEVICE with live view slot type + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, InitPcPadDevices_200, Function | SmallTest | Level1) +{ + std::string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + set validDevices; + set smartDevices; + sptr request(new NotificationRequest(1)); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + map> statusMap; + + smartReminderCenter_->InitPcPadDevices(deviceType, validDevices, smartDevices, statusMap, request); + + ASSERT_EQ(validDevices.size(), 0); + ASSERT_EQ(smartDevices.size(), 0); +} + +/** + * @tc.name: FillRequestExtendInfo_100 + * @tc.desc: Test FillRequestExtendInfo + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, FillRequestExtendInfo_100, Function | SmallTest | Level1) +{ + std::string deviceType = "testType"; + std::string deviceId = "testId"; + DeviceStatus deviceStatus(deviceType, deviceId); + sptr request(new NotificationRequest(1)); + + smartReminderCenter_->FillRequestExtendInfo(deviceType, deviceStatus, request); + + ASSERT_EQ(request->GetExtendInfo(), nullptr); +} + +/** + * @tc.name: FillRequestExtendInfo_200 + * @tc.desc: Test FillRequestExtendInfo + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, FillRequestExtendInfo_200, Function | SmallTest | Level1) +{ + std::string deviceType = "testType"; + std::string deviceId = "testId"; + DeviceStatus deviceStatus(deviceType, deviceId); + sptr request(new NotificationRequest(1)); + request->SetOwnerBundleName("com.ohos.sceneboard"); + request->SetOwnerUserId(100); + + smartReminderCenter_->FillRequestExtendInfo(deviceType, deviceStatus, request); + + ASSERT_EQ(request->GetExtendInfo(), nullptr); +} + +/** + * @tc.name: HandleReminderMethods_100 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_100, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + request->SetClassification("ANS_VOIP"); + set syncDevices; + set smartDevices; + shared_ptr defaultFlag = nullptr; + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_EQ(syncDevices.find(deviceType), syncDevices.end()); +} + +/** + * @tc.name: HandleReminderMethods_200 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_200, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + auto defaultFlag = std::make_shared(); + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_EQ(smartDevices.find(deviceType), smartDevices.end()); +} + +/** + * @tc.name: HandleReminderMethods_300 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_300, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + shared_ptr defaultFlag = make_shared();; + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_NE(notificationFlagsOfDevices->find(deviceType), notificationFlagsOfDevices->end()); +} + +/** + * @tc.name: HandleReminderMethods_400 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_400, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + shared_ptr defaultFlag = make_shared();; + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_EQ(statusMap.find(deviceType), statusMap.end()); +} + +/** + * @tc.name: HandleReminderMethods_500 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_500, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + smartDevices.insert("headset"); + shared_ptr defaultFlag = make_shared();; + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_EQ(statusMap.find(deviceType), statusMap.end()); +} + +/** + * @tc.name: HandleReminderMethods_600 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_600, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + vector> reminderAffecteds = { nullptr }; + std::string key = "5"; + reminderFilterDevice[key] = reminderAffecteds; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + smartDevices.insert("headset"); + shared_ptr defaultFlag = make_shared();; + map> statusMap{}; + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + ASSERT_EQ(statusMap.find(deviceType), statusMap.end()); +} + +/** + * @tc.name: HandleReminderMethods_700 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_700, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + auto reminderAffected = std::make_shared(); + reminderAffected->status_ = "1111"; + vector> reminderAffecteds = { reminderAffected }; + std::string key = "5"; + reminderFilterDevice[key] = reminderAffecteds; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + smartDevices.insert("headset"); + shared_ptr defaultFlag = make_shared();; + map> statusMap = {}; + statusMap.insert(pair>("1111", bitset(0))); + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + auto bitStatus = bitset(0); + ASSERT_FALSE(smartReminderCenter_->CompareStatus(reminderAffected->status_, bitStatus)); +} + +/** + * @tc.name: HandleReminderMethods_800 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_800, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + auto reminderAffected = std::make_shared(); + reminderAffected->status_ = "0000"; + vector> reminderAffecteds = { reminderAffected }; + std::string key = "5"; + reminderFilterDevice[key] = reminderAffecteds; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + smartDevices.insert("headset"); + shared_ptr defaultFlag = make_shared();; + map> statusMap = {}; + statusMap.insert(pair>("1111", bitset(0))); + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + auto bitStatus = bitset(0); + ASSERT_TRUE(smartReminderCenter_->CompareStatus(reminderAffected->status_, bitStatus)); + ASSERT_EQ(reminderAffected->affectedBy_.size(), 0); +} + +/** + * @tc.name: HandleReminderMethods_900 + * @tc.desc: Test HandleReminderMethods + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, HandleReminderMethods_900, Function | SmallTest | Level1) +{ + string deviceType = NotificationConstant::CURRENT_DEVICE_TYPE; + map>> reminderFilterDevice{}; + auto reminderAffected = std::make_shared(); + reminderAffected->status_ = "0000"; + reminderAffected->affectedBy_ = { std::make_pair("test111", "0000") }; + vector> reminderAffecteds = { reminderAffected }; + std::string key = "5"; + reminderFilterDevice[key] = reminderAffecteds; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + set syncDevices; + syncDevices.insert(deviceType); + set smartDevices; + smartDevices.insert(deviceType); + smartDevices.insert("headset"); + shared_ptr defaultFlag = make_shared();; + map> statusMap = {}; + statusMap.insert(pair>("1111", bitset(0))); + shared_ptr>> notificationFlagsOfDevices = + make_shared>>(); + + smartReminderCenter_->HandleReminderMethods(deviceType, reminderFilterDevice, request, syncDevices, + smartDevices, defaultFlag, statusMap, notificationFlagsOfDevices); + + auto bitStatus = bitset(0); + ASSERT_TRUE(smartReminderCenter_->CompareStatus(reminderAffected->status_, bitStatus)); + ASSERT_NE(reminderAffected->affectedBy_.size(), 0); +} + +/** + * @tc.name: GetAppSwitch_100 + * @tc.desc: Test GetAppSwitch + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetAppSwitch_100, Function | SmallTest | Level1) +{ + const string deviceType = NotificationConstant::WEARABLE_DEVICE_TYPE; + const string ownerBundleName = "testBundle"; + int32_t ownerUid = 0; + + auto ret = smartReminderCenter_->GetAppSwitch(deviceType, ownerBundleName, ownerUid); + + ASSERT_FALSE(ret); +} + +/** + * @tc.name: GetSmartSwitch_100 + * @tc.desc: Test GetSmartSwitch + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetSmartSwitch_100, Function | SmallTest | Level1) +{ + const string deviceType = NotificationConstant::WEARABLE_DEVICE_TYPE; + + auto ret = smartReminderCenter_->GetSmartSwitch(deviceType); + + ASSERT_FALSE(ret); +} + +/** + * @tc.name: GetReminderAffecteds_100 + * @tc.desc: Test GetReminderAffecteds + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetReminderAffecteds_100, Function | SmallTest | Level1) +{ + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + vector> reminderAffecteds; + + smartReminderCenter_->GetReminderAffecteds(reminderFilterDevice, request, reminderAffecteds); + + std::string key = "5#7#0"; + ASSERT_EQ(reminderFilterDevice.find(key), reminderFilterDevice.end()); +} + +/** + * @tc.name: GetReminderAffecteds_200 + * @tc.desc: Test GetReminderAffecteds + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetReminderAffecteds_200, Function | SmallTest | Level1) +{ + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + vector> reminderAffecteds; + + smartReminderCenter_->GetReminderAffecteds(reminderFilterDevice, request, reminderAffecteds); + + std::string key = "5#7#0"; + ASSERT_EQ(reminderFilterDevice.find(key), reminderFilterDevice.end()); +} + +/** + * @tc.name: GetReminderAffecteds_300 + * @tc.desc: Test GetReminderAffecteds + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetReminderAffecteds_300, Function | SmallTest | Level1) +{ + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + vector> reminderAffecteds; + std::string key = "5#7#0"; + reminderFilterDevice[key] = reminderAffecteds; + + smartReminderCenter_->GetReminderAffecteds(reminderFilterDevice, request, reminderAffecteds); + + std::string key1 = "5#7"; + ASSERT_EQ(reminderFilterDevice.find(key1), reminderFilterDevice.end()); +} + +/** + * @tc.name: GetReminderAffecteds_400 + * @tc.desc: Test GetReminderAffecteds + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetReminderAffecteds_400, Function | SmallTest | Level1) +{ + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + vector> reminderAffecteds; + std::string key = "5#7"; + reminderFilterDevice[key] = reminderAffecteds; + + smartReminderCenter_->GetReminderAffecteds(reminderFilterDevice, request, reminderAffecteds); + + std::string key1 = "5"; + ASSERT_EQ(reminderFilterDevice.find(key1), reminderFilterDevice.end()); +} + +/** + * @tc.name: GetReminderAffecteds_500 + * @tc.desc: Test GetReminderAffecteds + * @tc.type: FUNC + */ +HWTEST_F(SmartReminderCenterTest, GetReminderAffecteds_500, Function | SmallTest | Level1) +{ + map>> reminderFilterDevice{}; + sptr request(new NotificationRequest(1)); + auto localLiveViewContent = std::make_shared(); + auto content = std::make_shared(localLiveViewContent); + request->SetContent(content); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + vector> reminderAffecteds; + vector> reminderAffecteds1 = { nullptr }; + std::string key = "5"; + reminderFilterDevice[key] = reminderAffecteds1; + + smartReminderCenter_->GetReminderAffecteds(reminderFilterDevice, request, reminderAffecteds); + + ASSERT_EQ(reminderAffecteds.size(), 1); +} } //namespace Notification } //namespace OHOS #endif \ No newline at end of file -- Gitee