diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 498f66e0a6ebf297a0603c0250918a6f3afee284..7ce503d466130962dab74baafff7a6b5c6255111 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -29,6 +29,8 @@ group("ans_unit_test") { ":distributed_preferences_branch_test", ":distributed_preferences_database_test", ":distributed_screen_status_manager_branch_test", + ":distributed_service_test", + ":distributed_subscriber_test", ] } } @@ -415,3 +417,177 @@ ohos_unittest("distributed_notification_manager_branch_test") { subsystem_name = "${subsystem_name}" part_name = "${component_name}" } + +ohos_unittest("distributed_service_test") { + module_out_path = "${component_name}/unittest" + include_dirs = [ + "/${services_path}/distributed/include", + "/${services_path}/distributed/include/soft_bus", + "/${services_path}/distributed/include/tlv_box", + "/${services_path}/distributed/include/helper", + "/${services_path}/ans/include", + ] + + sources = [ + "/${frameworks_path}/ans/src/notification_helper.cpp", + "/${services_path}/ans/src/common/notification_config_parse.cpp", + "/${services_path}/distributed/src/helper/bundle_resource_helper.cpp", + "/${services_path}/distributed/src/helper/distributed_preference.cpp", + "/${services_path}/distributed/src/helper/distributed_rdb_helper.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_client.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_cmd_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_liveview_all_scenarios_extension_wrapper.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_local_config.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_observer_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_publish_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_server.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_service_uitls.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_socket.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_subscribe_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_subscriber.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_timer_service.cpp", + "/${services_path}/distributed/src/tlv_box/batch_remove_box.cpp", + "/${services_path}/distributed/src/tlv_box/box_base.cpp", + "/${services_path}/distributed/src/tlv_box/bundle_icon_box.cpp", + "/${services_path}/distributed/src/tlv_box/match_box.cpp", + "/${services_path}/distributed/src/tlv_box/remove_box.cpp", + "/${services_path}/distributed/src/tlv_box/request_box.cpp", + "/${services_path}/distributed/src/tlv_box/response_box.cpp", + "/${services_path}/distributed/src/tlv_box/state_box.cpp", + "/${services_path}/distributed/src/tlv_box/tlv_box.cpp", + "distributed_service_test.cpp", + ] + + configs = [ + "${services_path}/distributed/:ans_distributed_config", + "${frameworks_module_ans_path}:ans_innerkits_public_config", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/distributed:libans_distributed", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:runtime", + "ability_runtime:uri_permission_mgr", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "device_manager:devicemanagersdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "power_manager:powermgr_client", + "relational_store:native_rdb", + "relational_store:native_rdb", + "samgr:samgr_proxy", + "screenlock_mgr:screenlock_client", + "time_service:time_client", + "zlib:libz", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} +ohos_unittest("distributed_subscriber_test") { + module_out_path = "${component_name}/unittest" + include_dirs = [ + "/${services_path}/distributed/include", + "/${services_path}/distributed/include/soft_bus", + "/${services_path}/distributed/include/tlv_box", + "/${services_path}/distributed/include/helper", + "/${services_path}/ans/include", + "/${interfaces_path}/inner_api", + ] + + sources = [ + "/${frameworks_path}/ans/src/notification_helper.cpp", + "/${services_path}/ans/src/common/notification_config_parse.cpp", + "/${services_path}/distributed/src/helper/bundle_resource_helper.cpp", + "/${services_path}/distributed/src/helper/distributed_preference.cpp", + "/${services_path}/distributed/src/helper/distributed_rdb_helper.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_client.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_cmd_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_liveview_all_scenarios_extension_wrapper.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_local_config.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_observer_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_publish_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_server.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_service_uitls.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_socket.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_subscribe_service.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_subscriber.cpp", + "/${services_path}/distributed/src/soft_bus/distributed_timer_service.cpp", + "/${services_path}/distributed/src/tlv_box/batch_remove_box.cpp", + "/${services_path}/distributed/src/tlv_box/box_base.cpp", + "/${services_path}/distributed/src/tlv_box/bundle_icon_box.cpp", + "/${services_path}/distributed/src/tlv_box/match_box.cpp", + "/${services_path}/distributed/src/tlv_box/remove_box.cpp", + "/${services_path}/distributed/src/tlv_box/request_box.cpp", + "/${services_path}/distributed/src/tlv_box/response_box.cpp", + "/${services_path}/distributed/src/tlv_box/state_box.cpp", + "/${services_path}/distributed/src/tlv_box/tlv_box.cpp", + "distributed_subscriber_test.cpp", + ] + + configs = [ + "${services_path}/distributed/:ans_distributed_config", + "${frameworks_module_ans_path}:ans_innerkits_public_config", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/distributed:libans_distributed", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:runtime", + "ability_runtime:uri_permission_mgr", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "device_manager:devicemanagersdk", + "dsoftbus:softbus_client", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "power_manager:powermgr_client", + "relational_store:native_rdb", + "relational_store:native_rdb", + "samgr:samgr_proxy", + "screenlock_mgr:screenlock_client", + "time_service:time_client", + "zlib:libz", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} diff --git a/services/distributed/test/unittest/distributed_service_test.cpp b/services/distributed/test/unittest/distributed_service_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77176da3a796ae462eedb8f4f544ac76b6fa673e --- /dev/null +++ b/services/distributed/test/unittest/distributed_service_test.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "gtest/gtest.h" +#define private public +#include "batch_remove_box.h" +#include "distributed_service.h" +#undef private +#include "remove_box.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Notification { + +class DistributedServiceTest : public testing::Test { +public: + void SetUp() override; + void TearDown() override; +}; + +void DistributedServiceTest::SetUp() {} + +void DistributedServiceTest::TearDown() {} + +/** + * @tc.name : DistributedServiceTest_00100 + * @tc.number : DistributedServiceTest_00100 + * @tc.desc : Test the RemoveNotification function with a null boxMessage. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00100, Function | SmallTest | Level1) +{ + std::shared_ptr boxMessage = nullptr; + DistributedService::GetInstance().RemoveNotification(boxMessage); + ASSERT_EQ(boxMessage, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_00200 + * @tc.number : DistributedServiceTest_00200 + * @tc.desc : Test the RemoveNotification function with a valid NotificationRemoveBox. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00200, Function | SmallTest | Level1) +{ + NotificationRemoveBox removeBox; + std::string notificationKey = "notificationId"; + removeBox.SetNotificationHashCode(notificationKey); + DistributedService::GetInstance().RemoveNotification(removeBox.box_); + ASSERT_NE(removeBox.box_, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_00300 + * @tc.number : DistributedServiceTest_00300 + * @tc.desc : Test the RemoveNotification function with empty notificationKey. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00300, Function | SmallTest | Level1) +{ + std::shared_ptr boxMessage = nullptr; + DistributedService::GetInstance().RemoveNotifications(boxMessage); + ASSERT_EQ(boxMessage, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_00400 + * @tc.number : DistributedServiceTest_00400 + * @tc.desc : Test the OnBatchCanceled function with an valid notifications. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00400, Function | SmallTest | Level1) +{ + BatchRemoveNotificationBox batchRemoveBox; + std::string hashCodes = "notificationId1 notificationId2"; + batchRemoveBox.SetNotificationHashCode(hashCodes); + DistributedService::GetInstance().RemoveNotifications(batchRemoveBox.box_); + ASSERT_NE(batchRemoveBox.box_, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_00500 + * @tc.number : DistributedServiceTest_00500 + * @tc.desc : Test the OnBatchCanceled function with a null serviceQueue_. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00500, Function | SmallTest | Level1) +{ + std::vector> notifications; + DistributedDeviceInfo peerDevice; + + std::shared_ptr serviceQueue = DistributedService::GetInstance().serviceQueue_; + DistributedService::GetInstance().serviceQueue_ = nullptr; + DistributedService::GetInstance().OnBatchCanceled(notifications, peerDevice); + + ASSERT_EQ(DistributedService::GetInstance().serviceQueue_, nullptr); + DistributedService::GetInstance().serviceQueue_ = serviceQueue; +} + +/** + * @tc.name : DistributedServiceTest_00600 + * @tc.number : DistributedServiceTest_00600 + * @tc.desc : Test the OnBatchCanceled function with valid notifications and peer device. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00600, Function | SmallTest | Level1) +{ + std::vector> notifications; + DistributedDeviceInfo peerDevice; + peerDevice.deviceId_ = 1; + peerDevice.deviceType_ = 1; + + std::shared_ptr notificationNull = nullptr; + sptr request = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(request); + notification->SetKey("notificationKey"); + notifications.push_back(notificationNull); + notifications.push_back(notification); + DistributedService::GetInstance().OnBatchCanceled(notifications, peerDevice); + ASSERT_EQ((notificationNull == nullptr && notification != nullptr), true); +} + +/** + * @tc.name : DistributedServiceTest_00700 + * @tc.number : DistributedServiceTest_00700 + * @tc.desc : Test the OnCanceled function with a valid notification and peer device. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00700, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(request); + notification->SetKey("notificationKey"); + DistributedDeviceInfo peerDevice; + peerDevice.deviceId_ = 1; + peerDevice.deviceType_ = 1; + + std::shared_ptr serviceQueue = DistributedService::GetInstance().serviceQueue_; + DistributedService::GetInstance().serviceQueue_ = nullptr; + DistributedService::GetInstance().OnCanceled(notification, peerDevice); + + ASSERT_EQ(DistributedService::GetInstance().serviceQueue_, nullptr); + DistributedService::GetInstance().serviceQueue_ = serviceQueue; +} + +/** + * @tc.name : DistributedServiceTest_00800 + * @tc.number : DistributedServiceTest_00800 + * @tc.desc : Test the OnCanceled function with a null notification. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00800, Function | SmallTest | Level1) +{ + std::shared_ptr notificationNull = nullptr; + DistributedDeviceInfo peerDevice; + DistributedService::GetInstance().OnCanceled(notificationNull, peerDevice); + ASSERT_EQ(notificationNull, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_00900 + * @tc.number : DistributedServiceTest_00900 + * @tc.desc : Test the OnCanceled function with a valid notification and null peer device. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_00900, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(request); + notification->SetKey("notificationKey"); + DistributedDeviceInfo peerDevice; + peerDevice.deviceId_ = 1; + peerDevice.deviceType_ = 1; + DistributedService::GetInstance().OnCanceled(notification, peerDevice); + ASSERT_NE(notification, nullptr); +} + +/** + * @tc.name : DistributedServiceTest_01000 + * @tc.number : DistributedServiceTest_01000 + * @tc.desc : Test the OnCanceled function with a null notification. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_01000, Function | SmallTest | Level1) +{ + std::shared_ptr notificationNull = nullptr; + std::string result = DistributedService::GetInstance().GetNotificationKey(notificationNull); + ASSERT_EQ(result, ""); +} + +/** + * @tc.name : DistributedServiceTest_01100 + * @tc.number : DistributedServiceTest_01100 + * @tc.desc : Test the OnCanceled function with a valid notification. + */ +HWTEST_F(DistributedServiceTest, DistributedServiceTest_01100, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(); + std::shared_ptr notification = std::make_shared(request); + notification->SetKey("_notificationKey"); + std::string result = DistributedService::GetInstance().GetNotificationKey(notification); + ASSERT_EQ(result, "ans_distributed_notificationKey"); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/distributed/test/unittest/distributed_subscriber_test.cpp b/services/distributed/test/unittest/distributed_subscriber_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54e8c664fae16e1ba260c34b6d8e4697c0ffaf68 --- /dev/null +++ b/services/distributed/test/unittest/distributed_subscriber_test.cpp @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "gtest/gtest.h" +#define private public +#include "distributed_service.h" +#include "distributed_subscriber.h" +#undef private +#include "notification_request.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Notification { +class DistribuedSubscriberTest : public testing::Test { +public: + void SetUp() override; + void TearDown() override; + +private: + std::unordered_set collaborativeDeleteTypes_; +}; + +void DistribuedSubscriberTest::SetUp() +{ + collaborativeDeleteTypes_ = DistributedService::GetInstance().localDevice_.collaborativeDeleteTypes_; + std::unordered_set collaborativeDeleteTypes({ "LIVE_VIEW" }); + DistributedService::GetInstance().localDevice_.collaborativeDeleteTypes_ = collaborativeDeleteTypes; +} + +void DistribuedSubscriberTest::TearDown() +{ + DistributedService::GetInstance().localDevice_.collaborativeDeleteTypes_ = collaborativeDeleteTypes_; +} + +/** + * @tc.name : DistribuedSubscriberTest_00100 + * @tc.number : DistribuedSubscriberTest_00100 + * @tc.desc : Test the CheckNeedCollaboration function with null notification. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00100, Function | SmallTest | Level1) +{ + std::shared_ptr notification = nullptr; + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00200 + * @tc.number : DistribuedSubscriberTest_00200 + * @tc.desc : Test the CheckNeedCollaboration function with null SlotType. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00200, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00300 + * @tc.number : DistribuedSubscriberTest_00300 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType SOCIAL_COMMUNICATION. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00300, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00400 + * @tc.number : DistribuedSubscriberTest_00400 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType SERVICE_REMINDER. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00400, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00500 + * @tc.number : DistribuedSubscriberTest_00500 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType CONTENT_INFORMATION. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00500, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00600 + * @tc.number : DistribuedSubscriberTest_00600 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType OTHER. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00600, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::OTHER); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00700 + * @tc.number : DistribuedSubscriberTest_00700 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType CUSTOM. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00700, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::CUSTOM); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_00800 + * @tc.number : DistribuedSubscriberTest_00800 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType LIVE_VIEW. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00800, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), true); +} + +/** + * @tc.name : DistribuedSubscriberTest_00900 + * @tc.number : DistribuedSubscriberTest_00900 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType CUSTOMER_SERVICE. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_00900, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::CUSTOMER_SERVICE); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_01000 + * @tc.number : DistribuedSubscriberTest_01000 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType EMERGENCY_INFORMATION. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01000, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::EMERGENCY_INFORMATION); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_01100 + * @tc.number : DistribuedSubscriberTest_01100 + * @tc.desc : Test the CheckNeedCollaboration function with SlotType ILLEGAL_TYPE. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01100, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::ILLEGAL_TYPE); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr subscriber = std::make_shared(); + EXPECT_EQ(subscriber->CheckNeedCollaboration(notification), false); +} + +/** + * @tc.name : DistribuedSubscriberTest_01200 + * @tc.number : DistribuedSubscriberTest_01200 + * @tc.desc : Test the OnBatchCanceled function with deleteReason DEFAULT_REASON_DELETE. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01200, Function | SmallTest | Level1) +{ + std::vector> requestList; + std::shared_ptr sortingMap; + int32_t deleteReason = 0; + + std::shared_ptr subscriber = std::make_shared(); + subscriber->OnBatchCanceled(requestList, sortingMap, deleteReason); + EXPECT_EQ(deleteReason == NotificationConstant::DISTRIBUTED_COLLABORATIVE_DELETE, false); +} + +/** + * @tc.name : DistribuedSubscriberTest_01300 + * @tc.number : DistribuedSubscriberTest_01300 + * @tc.desc : Test the OnBatchCanceled function with deleteReason LIVE_VIEW. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01300, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + std::shared_ptr notification = std::make_shared(request); + + std::vector> requestList; + requestList.push_back(notification); + std::shared_ptr sortingMap; + int32_t deleteReason = 32; + std::shared_ptr subscriber = std::make_shared(); + subscriber->OnBatchCanceled(requestList, sortingMap, deleteReason); + EXPECT_NE(requestList.size(), 0); +} + +/** + * @tc.name : DistribuedSubscriberTest_01400 + * @tc.number : DistribuedSubscriberTest_01400 + * @tc.desc : Test the OnCanceled function with deleteReason DEFAULT_REASON_DELETE. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01400, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr sortingMap; + int32_t deleteReason = 0; + std::shared_ptr subscriber = std::make_shared(); + subscriber->OnCanceled(notification, sortingMap, deleteReason); + EXPECT_EQ(deleteReason, 0); +} + +/** + * @tc.name : DistribuedSubscriberTest_01500 + * @tc.number : DistribuedSubscriberTest_01500 + * @tc.desc : Test the OnCanceled function with deleteReason LIVE_VIEW. + */ +HWTEST_F(DistribuedSubscriberTest, DistribuedSubscriberTest_01500, Function | SmallTest | Level1) +{ + sptr request = new NotificationRequest(1); + request->SetSlotType(NotificationConstant::SlotType::LIVE_VIEW); + std::shared_ptr notification = std::make_shared(request); + std::shared_ptr sortingMap; + int32_t deleteReason = 32; + + std::shared_ptr subscriber = std::make_shared(); + subscriber->OnCanceled(notification, sortingMap, deleteReason); + EXPECT_EQ(deleteReason, 32); +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file