From 504e222a1887061eca339336305d75ef3819fa86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=88=E7=9A=93=E6=9D=B0?= Date: Tue, 19 Nov 2024 16:51:02 +0800 Subject: [PATCH] add service ut MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 师皓杰 --- .../distributed_sched_service_second_test.cpp | 99 +++++++++++++++++++ .../dtbschedmgr_device_info_storage_test.cpp | 62 +++++++++++- .../mission/dms_continue_manager_test.cpp | 6 ++ 3 files changed, 165 insertions(+), 2 deletions(-) diff --git a/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp b/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp index 8671e234..df526a6a 100644 --- a/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp +++ b/services/dtbschedmgr/test/unittest/distributed_sched_service_second_test.cpp @@ -1617,5 +1617,104 @@ HWTEST_F(DistributedSchedServiceSecondTest, NotifyDSchedEventResultFromRemote_00 EXPECT_EQ(ret, ERR_OK); DTEST_LOG << "DistributedSchedServiceSecondTest NotifyDSchedEventResultFromRemote_001 end" << std::endl; } + +/** + * @tc.name: ContinueLocalMission_001 + * @tc.desc: ContinueLocalMission + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, ContinueLocalMission_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 start" << std::endl; + std::string dstDeviceId; + int32_t missionId = 0; + OHOS::AAFwk::WantParams wantParams; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().ContinueLocalMission( + dstDeviceId, missionId, nullptr, wantParams); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().ContinueAbilityWithTimeout( + dstDeviceId, missionId, nullptr, 0); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().NotifyDSchedEventCallbackResult(FOREGROUND); + + ret = DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote( + FOREGROUND, true, dstDeviceId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest ContinueLocalMission_001 end" << std::endl; +} + +/** + * @tc.name: GetContinueInfo_001 + * @tc.desc: GetContinueInfo + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, GetContinueInfo_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 start" << std::endl; + std::string dstNetworkId; + std::string srcNetworkId; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + ret = DistributedSchedService::GetInstance().GetContinueInfo(dstNetworkId, srcNetworkId); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest GetContinueInfo_001 end" << std::endl; +} + +/** + * @tc.name: GetDSchedEventInfo_001 + * @tc.desc: GetDSchedEventInfo + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, GetDSchedEventInfo_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 start" << std::endl; + std::vector events; + int32_t ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_CONTINUE, events); + EXPECT_EQ(ret, ERR_OK); + + ret = DistributedSchedService::GetInstance().GetDSchedEventInfo(DMS_ALL, events); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest GetDSchedEventInfo_001 end" << std::endl; +} + +/** + * @tc.name: RegisterDSchedEventListener_001 + * @tc.desc: RegisterDSchedEventListener + * @tc.type: FUNC + */ +HWTEST_F(DistributedSchedServiceSecondTest, RegisterDSchedEventListener_001, TestSize.Level3) +{ + DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 start" << std::endl; + DistributedSchedService::GetInstance().dschedContinuation_ = nullptr; + DistributedSchedService::GetInstance().collaborateCbMgr_ = nullptr; + int32_t ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().dschedContinuation_ = std::make_shared(); + ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_CONTINUE, nullptr); + EXPECT_EQ(ret, INVALID_PARAMETERS_ERR); + + DistributedSchedService::GetInstance().collaborateCbMgr_ = std::make_shared(); + DistributedSchedService::GetInstance().collaborateCbMgr_->Init(); + auto callback = GetDSchedService(); + ret = DistributedSchedService::GetInstance().RegisterDSchedEventListener(DMS_COLLABORATION, callback); + EXPECT_EQ(ret, ERR_OK); + + ret = DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DMS_COLLABORATION, callback); + EXPECT_EQ(ret, ERR_OK); + DTEST_LOG << "DistributedSchedServiceSecondTest RegisterDSchedEventListener_001 end" << std::endl; +} } } diff --git a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp index f8769e44..fce16534 100644 --- a/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp +++ b/services/dtbschedmgr/test/unittest/dtbschedmgr_device_info_storage_test.cpp @@ -444,12 +444,70 @@ HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetNetworkIdList_001, TestSize.Level3 std::string netWorkId = "netWorkId"; devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); EXPECT_EQ(devices.empty(), true); - - std::shared_ptr deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); + + std::shared_ptr deviceInfo = nullptr; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); + EXPECT_EQ(devices.empty(), true); + + deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; devices = DtbschedmgrDeviceInfoStorage::GetInstance().GetNetworkIdList(); EXPECT_EQ(devices.empty(), false); DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetNetworkIdList_001 end" << std::endl; } + +/** + * @tc.name: InitNetworkIdManager_001 + * @tc.desc: test InitNetworkIdManager + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, InitNetworkIdManager_001, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManager_001 start" << std::endl; + bool ret = DtbschedmgrDeviceInfoStorage::GetInstance().InitNetworkIdManager(nullptr); + EXPECT_EQ(ret, false); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest InitNetworkIdManager_001 end" << std::endl; +} + +/** + * @tc.name: RegisterUuidNetworkIdMap_001 + * @tc.desc: test RegisterUuidNetworkIdMap + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, RegisterUuidNetworkIdMap_001, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest RegisterUuidNetworkIdMap_001 start" << std::endl; + std::string networkId = "networkId"; + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().RegisterUuidNetworkIdMap(networkId)); + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().UnregisterUuidNetworkIdMap(networkId)); + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOnlineNotify(nullptr)); + networkId = ""; + EXPECT_NO_FATAL_FAILURE(DtbschedmgrDeviceInfoStorage::GetInstance().DeviceOfflineNotify(networkId)); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest RegisterUuidNetworkIdMap_001 end" << std::endl; +} + +/** + * @tc.name: GetDeviceName_002 + * @tc.desc: test GetDeviceName + * @tc.type: FUNC + */ +HWTEST_F(DtbschedmgrDeviceInfoStorageTest, GetDeviceName_002, TestSize.Level3) +{ + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceName_002 start" << std::endl; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear(); + std::string netWorkId = "netWorkId"; + std::shared_ptr deviceInfo = nullptr; + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + std::string str = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceName(netWorkId); + EXPECT_EQ(str, ""); + + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear(); + deviceInfo = std::make_shared("deviceName", 0, "netWorkId"); + DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_[netWorkId] = deviceInfo; + str = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceName(netWorkId); + EXPECT_EQ(str, "deviceName"); + DTEST_LOG << "DtbschedmgrDeviceInfoStorageTest GetDeviceName_002 end" << std::endl; +} } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp index 481c2ecf..1e0cde3a 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_continue_manager_test.cpp @@ -23,6 +23,7 @@ #include "mission/dms_continue_recv_manager.h" #undef private #include "multi_user_manager.h" +#include "softbus_adapter/softbus_adapter.h" #include "test_log.h" using namespace testing; @@ -49,6 +50,11 @@ constexpr int32_t DBMS_RETRY_MAX_TIME = 5; constexpr uint8_t DMS_FOCUSED_TYPE = 0x00; } +int32_t SoftbusAdapter::SendSoftbusEvent(std::shared_ptr buffer) +{ + return CAN_NOT_FOUND_ABILITY_ERR; +} + void DMSContinueManagerTest::SetUpTestCase() { }