From 8b33e6fa6599f74c254ebace5dbe1a150580b806 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Wed, 5 Mar 2025 11:02:14 +0800 Subject: [PATCH 01/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_listener.cpp | 39 ++++++++++++++++ .../softbusunittest/UTTest_softbus_listener.h | 2 + test/unittest/BUILD.gn | 3 +- test/unittest/UTTest_device_manager_impl.cpp | 8 +++- test/unittest/UTTest_dm_softbus_cache.cpp | 2 +- test/unittest/mock/softbus_center_mock.cpp | 29 ++++++++++++ test/unittest/mock/softbus_center_mock.h | 46 +++++++++++++++++++ 7 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 test/unittest/mock/softbus_center_mock.cpp create mode 100644 test/unittest/mock/softbus_center_mock.h diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index e42281281..9673723a1 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -47,6 +47,7 @@ void SoftbusListenerTest::SetUpTestCase() DmCrypto::dmCrypto = cryptoMock_; DmSoftbusCache::dmSoftbusCache = softbusCacheMock_; DMIPCSkeleton::dmIpcSkeleton_ = ipcSkeletonMock_; + SoftbusCenterInterface::softbusCenterInterface_ = softbusCenterMock_; } void SoftbusListenerTest::TearDownTestCase() { @@ -58,6 +59,8 @@ void SoftbusListenerTest::TearDownTestCase() softbusCacheMock_ = nullptr; DMIPCSkeleton::dmIpcSkeleton_ = nullptr; ipcSkeletonMock_ = nullptr; + SoftbusCenterInterface::softbusCenterInterface_ = nullptr; + softbusCenterMock_ = nullptr; } namespace { @@ -489,8 +492,13 @@ HWTEST_F(SoftbusListenerTest, GetNetworkTypeByNetworkId_001, testing::ext::TestS if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(SOFTBUS_INVALID_PARAM)); int32_t ret = softbusListener->GetNetworkTypeByNetworkId(networkId, networkType); EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM); + + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(DM_OK)); + ret = softbusListener->GetNetworkTypeByNetworkId(networkId, networkType); + EXPECT_EQ(ret, DM_OK); } HWTEST_F(SoftbusListenerTest, CacheDiscoveredDevice_001, testing::ext::TestSize.Level0) @@ -1071,8 +1079,13 @@ HWTEST_F(SoftbusListenerTest, GetDeviceScreenStatus_001, testing::ext::TestSize. if (softbusListener == nullptr) { softbusListener = std::make_shared(); } + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(SOFTBUS_INVALID_PARAM)); int32_t ret = softbusListener->GetDeviceScreenStatus(networkId.c_str(), screenStatus); EXPECT_TRUE(checkSoftbusRes(ret)); + + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(DM_OK)); + ret = softbusListener->GetDeviceScreenStatus(networkId.c_str(), screenStatus); + EXPECT_FALSE(checkSoftbusRes(ret)); softbusListener = nullptr; } @@ -1325,6 +1338,32 @@ HWTEST_F(SoftbusListenerTest, GetAttrFromCustomData_001, testing::ext::TestSize. int32_t actionId = 1; int32_t ret = softbusListener->GetAttrFromCustomData(customDataJson, dmDevInfo, actionId); EXPECT_EQ(ret, DM_OK); + + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED)); + softbusListener->OnLocalDevInfoChange(); + + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); + softbusListener->OnLocalDevInfoChange(); + + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); + softbusListener->OnLocalDevInfoChange(); + + NodeBasicInfo *info = nullptr; + softbusListener->UpdateDeviceName(info); + + NodeBasicInfo nodeBasicInfo = { + .networkId = "123456", + .deviceName = "123456", + .deviceTypeId = 1 + }; + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); + softbusListener->UpdateDeviceName(&nodeBasicInfo); + + EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); + softbusListener->UpdateDeviceName(&nodeBasicInfo); + } } // namespace } // namespace DistributedHardware diff --git a/test/softbusunittest/UTTest_softbus_listener.h b/test/softbusunittest/UTTest_softbus_listener.h index c5dd44759..0f59fbe15 100644 --- a/test/softbusunittest/UTTest_softbus_listener.h +++ b/test/softbusunittest/UTTest_softbus_listener.h @@ -33,6 +33,7 @@ #include "dm_crypto_mock.h" #include "dm_softbus_cache_mock.h" #include "dm_ipc_skeleton_mock.h" +#include "softbus_center_mock.h" namespace OHOS { namespace DistributedHardware { @@ -48,6 +49,7 @@ public: static inline std::shared_ptr cryptoMock_ = std::make_shared(); static inline std::shared_ptr softbusCacheMock_ = std::make_shared(); static inline std::shared_ptr ipcSkeletonMock_ = std::make_shared(); + static inline std::shared_ptr softbusCenterMock_ = std::make_shared(); }; class ISoftbusDiscoveringCallbackTest : public ISoftbusDiscoveringCallback { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index eadcdfe56..7c0b4e7b6 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -610,8 +610,9 @@ ohos_unittest("UTTest_softbus_listener") { "${devicemanager_path}/test/unittest/mock/parameter.cpp", "mock/distributed_device_profile_client_mock.cpp", "mock/dm_crypto_mock.cpp", + "mock/dm_ipc_skeleton_mock.cpp", "mock/dm_softbus_cache_mock.cpp", - "mock/ipc_skeleton_mock.cpp", + "mock/softbus_center_mock.cpp", ] deps = [ ":device_manager_test_common" ] diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 1eee8ed5d..ecd7ed2ee 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -476,8 +476,14 @@ HWTEST_F(DeviceManagerImplTest, GetDeviceType_103, testing::ext::TestSize.Level0 std::string packName = "com.ohos.test"; std::string networkId = "networkId"; int32_t deviceType = 0; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); int32_t ret = DeviceManager::GetInstance().GetDeviceType(packName, networkId, deviceType); - ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; } /** diff --git a/test/unittest/UTTest_dm_softbus_cache.cpp b/test/unittest/UTTest_dm_softbus_cache.cpp index 0cffa012e..9fc8e4f5f 100644 --- a/test/unittest/UTTest_dm_softbus_cache.cpp +++ b/test/unittest/UTTest_dm_softbus_cache.cpp @@ -76,7 +76,7 @@ namespace { bool CheckSoftbusRes(int32_t ret) { return ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR || - ret == SOFTBUS_IPC_ERR || ret == ERR_DM_FAILED || ret == SOFTBUS_NETWORK_GET_ALL_NODE_INFO_ERR; + ret == SOFTBUS_IPC_ERR || ret == ERR_DM_FAILED || ret == SOFTBUS_NETWORK_GET_NODE_INFO_ERR; } HWTEST_F(DMSoftbusCacheTest, GetDeviceInfoFromCache_001, testing::ext::TestSize.Level0) diff --git a/test/unittest/mock/softbus_center_mock.cpp b/test/unittest/mock/softbus_center_mock.cpp new file mode 100644 index 000000000..caba599f3 --- /dev/null +++ b/test/unittest/mock/softbus_center_mock.cpp @@ -0,0 +1,29 @@ +/* + * 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 "softbus_center_mock.h" + +#include "gtest/gtest.h" + +namespace OHOS { + +extern "C" { +int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, + int32_t infoLen) +{ + return SoftbusCenterInterface::softbusCenterInterface_->GetNodeKeyInfo(pkgName, networkId, key, info, infoLen); +} +} +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_center_mock.h b/test/unittest/mock/softbus_center_mock.h new file mode 100644 index 000000000..57784e3b2 --- /dev/null +++ b/test/unittest/mock/softbus_center_mock.h @@ -0,0 +1,46 @@ +/* + * 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. + */ +#ifndef OHOS_SOFTBUS_CENTER_MOCK_H +#define OHOS_SOFTBUS_CENTER_MOCK_H + +#include +#include + +#include "softbus_bus_center.h" + +namespace OHOS { +namespace DistributedHardware { +class SoftbusCenterInterface { +public: + virtual ~SoftbusCenterInterface() = default; +public: + virtual int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, + int32_t infoLen) = 0; + virtual int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) = 0; +public: + static inline std::shared_ptr softbusCenterInterface_ = nullptr; +}; + +class SoftbusCenterMock : public SoftbusCenterInterface { +public: + SoftbusCenterMock(); + ~SoftbusCenterMock() override; + MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); + MOCK_METHOD(int32_t, GetLocalNodeDeviceInfo, (const char *, NodeBasicInfo *)); + +}; +} +} +#endif -- Gitee From 3bb80211b0f3901727a9999d5d20cd804e366392 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Wed, 5 Mar 2025 17:05:27 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- ...Test_dm_deviceprofile_connector_second.cpp | 109 ++++++++++++++++++ .../UTTest_softbus_listener.cpp | 1 - test/unittest/UTTest_device_manager_impl.cpp | 109 ++++++++++++++++++ .../UTTest_device_manager_service_two.cpp | 87 ++++++++++++++ test/unittest/UTTest_dm_transport_msg.cpp | 22 +++- .../mock/deviceprofile_connector_mock.cpp | 16 +++ .../mock/deviceprofile_connector_mock.h | 8 ++ ...distributed_device_profile_client_mock.cpp | 45 ++++++++ .../distributed_device_profile_client_mock.h | 19 +++ test/unittest/mock/softbus_center_mock.h | 1 - 10 files changed, 414 insertions(+), 3 deletions(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index 09a88d4ff..e03d2046b 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -19,11 +19,14 @@ #include "deviceprofile_connector.h" #include #include "dp_inited_callback_stub.h" +#include "dm_error_type.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +constexpr uint32_t MAX_SESSION_KEY_LEN = 1024; + void DeviceProfileConnectorSecondTest::SetUp() { } @@ -500,5 +503,111 @@ HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAccessControlList_201, testing: remoteDeviceId, bindLevel, extra); EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE); } + +HWTEST_F(DeviceProfileConnectorSecondTest, PutServiceInfoProfile_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; + EXPECT_CALL(*distributedDeviceProfileClientMock_, PutServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, PutServiceInfoProfile(_)).WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(serviceInfoProfile); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, DeleteServiceInfoProfile_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey key; + EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteServiceInfoProfile(_)).WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, UpdateServiceInfoProfile_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; + EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateServiceInfoProfile(_)).WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); + EXPECT_EQ(ret, DM_OK); +} + + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileByUniqueKey_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey key; + DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileByUniqueKey(_, _)) + .WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileByUniqueKey(_, _)) + .WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByTokenId_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey key; + std::vector serviceInfoProfiles; + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(_, _)) + .WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(_, _)) + .WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByBundleName_201, testing::ext::TestSize.Level0) +{ + DistributedDeviceProfile::ServiceInfoUniqueKey key; + std::vector serviceInfoProfiles; + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByBundleName(_, _)) + .WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByBundleName(_, _)) + .WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceProfileConnectorSecondTest, PutSessionKey_201, testing::ext::TestSize.Level0) +{ + uint8_t* sessionKey = nullptr; + uint32_t length = 0; + int32_t sessionKeyId = 1; + int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + EXPECT_EQ(ret, ERR_DM_FAILED); + + uint8_t arr[5] = {1, 2, 3, 4, 5}; + sessionKey = arr; + length = MAX_SESSION_KEY_LEN; + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + EXPECT_EQ(ret, ERR_DM_FAILED); + + length = static_cast(sizeof(arr)); + EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(DM_OK)); + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + EXPECT_EQ(ret, DM_OK); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index 9673723a1..33ca2f6b1 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1363,7 +1363,6 @@ HWTEST_F(SoftbusListenerTest, GetAttrFromCustomData_001, testing::ext::TestSize. EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(DM_OK)); softbusListener->UpdateDeviceName(&nodeBasicInfo); - } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index ecd7ed2ee..3e51528a9 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2573,6 +2573,115 @@ HWTEST_F(DeviceManagerImplTest, GetDeviceSecurityLevel_001, testing::ext::TestSi ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, netWorkId, securityLevel); ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } + +HWTEST_F(DeviceManagerImplTest, GenerateServiceId_001, testing::ext::TestSize.Level0) +{ + int64_t serviceId = 1; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, RegisterServiceInfo_001, testing::ext::TestSize.Level0) +{ + DMServiceInfo info; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().RegisterServiceInfo(info); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().RegisterServiceInfo(info); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, UnRegisterServiceInfo_001, testing::ext::TestSize.Level0) +{ + int64_t serviceId = 1; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().UnRegisterServiceInfo(serviceId); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().UnRegisterServiceInfo(serviceId); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, UpdateServiceInfo_001, testing::ext::TestSize.Level0) +{ + DMServiceInfo info; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().UpdateServiceInfo(info); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().UpdateServiceInfo(info); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, GetServiceInfoByServiceId_001, testing::ext::TestSize.Level0) +{ + int64_t serviceId = 1; + DMServiceInfo info; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, info); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, info); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} + +HWTEST_F(DeviceManagerImplTest, GetCallerServiceInfos_001, testing::ext::TestSize.Level0) +{ + std::vector serviceInfos; + std::shared_ptr mockInstance = std::make_shared(); + std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); + int32_t ret = DeviceManager::GetInstance().GetCallerServiceInfos(serviceInfos); + ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); + + EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + ret = DeviceManager::GetInstance().GetCallerServiceInfos(serviceInfos); + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 0ec40d751..e60a33099 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1407,6 +1407,93 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceInfo_202, testing::ext::TestSize.Lev EXPECT_EQ(ret, DM_OK); DeviceManagerService::GetInstance().softbusListener_ = nullptr; } + +HWTEST_F(DeviceManagerServiceTest, GenerateSerivceId_201, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().GenerateSerivceId(); + EXPECT_EQ(ret, ERR_DM_FAILED); + + DmDeviceInfo info = { + .deviceId = "de******2", + .deviceName = "deviceName", + .deviceTypeId = 1 + }; + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(info), Return(DM_OK))); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + ret = DeviceManagerService::GetInstance().GenerateSerivceId(); + EXPECT_EQ(ret, DM_OK); + + info.deviceId = ""; + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) + .WillOnce(DoAll(SetArgReferee<0>(info), Return(DM_OK))); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + ret = DeviceManagerService::GetInstance().GenerateSerivceId(); + EXPECT_EQ(ret, DM_OK); + DeviceManagerService::GetInstance().softbusListener_ = nullptr; +} + +HWTEST_F(DeviceManagerServiceTest, RegisterServiceInfo_201, testing::ext::TestSize.Level0) +{ + DMServiceInfo serviceInfo; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + ret = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); + EXPECT_NE(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceTest, UnRegisterServiceInfo_201, testing::ext::TestSize.Level0) +{ + int64_t serviceId = 1; + int32_t ret = DeviceManagerService::GetInstance().UnRegisterServiceInfo(serviceId); + EXPECT_NE(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceTest, UpdateServiceInfo_201, testing::ext::TestSize.Level0) +{ + DMServiceInfo serviceInfo; + DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); + EXPECT_EQ(ret, ERR_DM_FAILED); + + EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); + EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); + ret = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); + EXPECT_NE(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceTest, GetServiceInfoById_201, testing::ext::TestSize.Level0) +{ + int64_t serviceId = 1; + DMServiceInfo serviceInfo; + EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileByUniqueKey(_, _)).WillOnce(Return(DM_OK)); + int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoById(serviceId, serviceInfo); + EXPECT_EQ(ret, DM_OK); +} + +HWTEST_F(DeviceManagerServiceTest, GetCallerServiceInfos_201, testing::ext::TestSize.Level0) +{ + std::vector serviceInfos; + EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileListByTokenId(_, _)).WillOnce(Return(DM_OK)); + int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfos(serviceInfos); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_transport_msg.cpp b/test/unittest/UTTest_dm_transport_msg.cpp index 24955cd30..da67b8a27 100644 --- a/test/unittest/UTTest_dm_transport_msg.cpp +++ b/test/unittest/UTTest_dm_transport_msg.cpp @@ -177,11 +177,31 @@ HWTEST_F(DMTransportMsgTest, NotifyUserIds_ToString_ValidInput, testing::ext::Te * @tc.name: NotifyUserIds_ToString_EmptyInput * @tc.type: FUNC */ -HWTEST_F(DMTransportMsgTest, NotifyUserIds_ToString_EmptyInput, testing::ext::TestSize.Level0) +HWTEST_F(DMTransportMsgTest, ToJson_ToString_EmptyInput, testing::ext::TestSize.Level0) { NotifyUserIds notifyUserIds; std::string result = notifyUserIds.ToString(); EXPECT_FALSE(result.empty()); } + +HWTEST_F(DMTransportMsgTest, ToJson_UserIdsMsg, testing::ext::TestSize.Level0) +{ + std::vector foregroundUserIds{1, 2, 3}; + std::vector backgroundUserIds{4, 5, 6}; + UserIdsMsg userIdsMsg(foregroundUserIds, backgroundUserIds); + const char* jsonStr = R"({ + "MsgType": "0", + "msg": "messgaeinfo", + "code": 145, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + cJSON *jsonObject = cJSON_Parse(jsonStr); + ToJson(jsonObject, userIdsMsg); + cJSON_Delete(jsonObject); + EXPECT_FALSE(userIdsMsg.foregroundUserIds.empty()); +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 15a6be1e2..f3f81710c 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -130,5 +130,21 @@ int32_t DeviceProfileConnector::PutSessionKey(const uint8_t* sessionKey, uint32_ { return DmDeviceProfileConnector::dmDeviceProfileConnector->PutSessionKey(sessionKey, length, sessionKeyId); } + +int32_t DeviceProfileConnector::GetServiceInfoProfileByUniqueKey( + const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector-> + GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); +} + +int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( + const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector-> + GetServiceInfoProfileByUniqueKey(key, serviceInfoProfiles); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index f6096c8b3..81871c35c 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -57,6 +57,10 @@ public: virtual int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, std::vector& serviceInfoProfiles) = 0; virtual int32_t PutSessionKey(const uint8_t* sessionKey, uint32_t length, int32_t& sessionKeyId) = 0; + virtual int32_t GetServiceInfoProfileByUniqueKey(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) = 0; + virtual int32_t GetServiceInfoProfileListByTokenId(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, + std::vector &serviceInfoProfiles) = 0; public: static inline std::shared_ptr dmDeviceProfileConnector = nullptr; }; @@ -88,6 +92,10 @@ public: MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const DistributedDeviceProfile::ServiceInfoUniqueKey&, (std::vector&))); MOCK_METHOD(int32_t, PutSessionKey, (const uint8_t*, uint32_t, int32_t&)); + MOCK_METHOD(int32_t, GetServiceInfoProfileByUniqueKey, (const DistributedDeviceProfile::ServiceInfoUniqueKey &, + DistributedDeviceProfile::ServiceInfoProfile &)); + MOCK_METHOD(int32_t, GetServiceInfoProfileListByTokenId, (const DistributedDeviceProfile::ServiceInfoUniqueKey &, + (std::vector &))); }; } } diff --git a/test/unittest/mock/distributed_device_profile_client_mock.cpp b/test/unittest/mock/distributed_device_profile_client_mock.cpp index c6c1406d5..096c6990b 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.cpp +++ b/test/unittest/mock/distributed_device_profile_client_mock.cpp @@ -56,5 +56,50 @@ int32_t DistributedDeviceProfileClient::PutAllTrustedDevices( { return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->PutAllTrustedDevices(deviceInfos); } + +int32_t DistributedDeviceProfileClient::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + PutServiceInfoProfile(serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->DeleteServiceInfoProfile(key); +} + +int32_t DistributedDeviceProfileClient::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + UpdateServiceInfoProfile(serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); +} + +int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); +} + +int32_t DistributedDeviceProfileClient::PutSessionKey( + uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) +{ + return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> + PutSessionKey(userId, sessionKey, sessionKeyId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/distributed_device_profile_client_mock.h b/test/unittest/mock/distributed_device_profile_client_mock.h index dc55b8205..97afa07d2 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.h +++ b/test/unittest/mock/distributed_device_profile_client_mock.h @@ -34,6 +34,16 @@ public: virtual int32_t UnSubscribeDeviceProfileInited(int32_t saId) = 0; virtual int32_t PutAllTrustedDevices(const std::vector &deviceInfos) = 0; + virtual int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) = 0; + virtual int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, + ServiceInfoProfile& serviceInfoProfile) = 0; + virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) = 0; + virtual int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, + std::vector& serviceInfoProfiles) = 0; + virtual int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) = 0; public: static inline std::shared_ptr dpDistributedDeviceProfileClient = nullptr; }; @@ -47,6 +57,15 @@ public: MOCK_METHOD(int32_t, SubscribeDeviceProfileInited, (int32_t, sptr)); MOCK_METHOD(int32_t, UnSubscribeDeviceProfileInited, (int32_t)); MOCK_METHOD(int32_t, PutAllTrustedDevices, (const std::vector &)); + MOCK_METHOD(int32_t, PutServiceInfoProfile, (const ServiceInfoProfile&)); + MOCK_METHOD(int32_t, DeleteServiceInfoProfile, (const ServiceInfoUniqueKey&)); + MOCK_METHOD(int32_t, UpdateServiceInfoProfile, (const ServiceInfoProfile&)); + MOCK_METHOD(int32_t, GetServiceInfoProfileByUniqueKey, (const ServiceInfoUniqueKey&, ServiceInfoProfile&)); + MOCK_METHOD(int32_t, GetServiceInfoProfileListByTokenId, (const ServiceInfoUniqueKey&, + (std::vector&))); + MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const ServiceInfoUniqueKey&, + (std::vector&))); + MOCK_METHOD(int32_t, PutSessionKey, (uint32_t, (const std::vector&), int32_t&)); }; } } diff --git a/test/unittest/mock/softbus_center_mock.h b/test/unittest/mock/softbus_center_mock.h index 57784e3b2..c2703ef66 100644 --- a/test/unittest/mock/softbus_center_mock.h +++ b/test/unittest/mock/softbus_center_mock.h @@ -39,7 +39,6 @@ public: ~SoftbusCenterMock() override; MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); MOCK_METHOD(int32_t, GetLocalNodeDeviceInfo, (const char *, NodeBasicInfo *)); - }; } } -- Gitee From 798eda1d894c5f6cc7e0533aa8843847aed536a2 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Wed, 5 Mar 2025 17:08:42 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/unittest/UTTest_dm_transport_msg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/UTTest_dm_transport_msg.cpp b/test/unittest/UTTest_dm_transport_msg.cpp index da67b8a27..b3817ed5e 100644 --- a/test/unittest/UTTest_dm_transport_msg.cpp +++ b/test/unittest/UTTest_dm_transport_msg.cpp @@ -177,7 +177,7 @@ HWTEST_F(DMTransportMsgTest, NotifyUserIds_ToString_ValidInput, testing::ext::Te * @tc.name: NotifyUserIds_ToString_EmptyInput * @tc.type: FUNC */ -HWTEST_F(DMTransportMsgTest, ToJson_ToString_EmptyInput, testing::ext::TestSize.Level0) +HWTEST_F(DMTransportMsgTest, NotifyUserIds_ToString_EmptyInput, testing::ext::TestSize.Level0) { NotifyUserIds notifyUserIds; std::string result = notifyUserIds.ToString(); -- Gitee From 29b58c11b3b7b2c4b2ce229e388636c7b34583ca Mon Sep 17 00:00:00 2001 From: l60055366 Date: Thu, 6 Mar 2025 15:01:35 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 157 +++++++++++++++++- .../UTTest_softbus_connector.h | 4 + .../UTTest_softbus_listener.cpp | 18 +- test/unittest/BUILD.gn | 3 + test/unittest/mock/softbus_center_mock.cpp | 16 ++ test/unittest/mock/softbus_center_mock.h | 5 + 6 files changed, 192 insertions(+), 11 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index dada78095..4366786f5 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -33,6 +33,8 @@ #include "system_ability_definition.h" #include "softbus_error_code.h" +using namespace testing; +using namespace testing::ext; namespace OHOS { namespace DistributedHardware { @@ -53,9 +55,12 @@ void SoftbusConnectorTest::TearDown() } void SoftbusConnectorTest::SetUpTestCase() { + SoftbusCenterInterface::softbusCenterInterface_ = softbusCenterMock_; } void SoftbusConnectorTest::TearDownTestCase() { + SoftbusCenterInterface::softbusCenterInterface_ = nullptr; + softbusCenterMock_ = nullptr; } namespace { @@ -341,6 +346,10 @@ HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_001, testing::ext::Te .deviceTypeId = 1 }; std::shared_ptr softbusConnector = std::make_shared(); + nlohmann::json extraJson; + extraJson[PARAM_KEY_OS_TYPE] = 1; + extraJson[PARAM_KEY_OS_VERSION] = {0}; + dmDeviceInfo.extraData = extraJson.dump(); softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dm); bool ret = false; if (strcmp(dm.deviceId, dm_1.deviceId) == 0) { @@ -507,8 +516,13 @@ HWTEST_F(SoftbusConnectorTest, EraseUdidFromMap_001, testing::ext::TestSize.Leve HWTEST_F(SoftbusConnectorTest, GetLocalDeviceName_001, testing::ext::TestSize.Level0) { std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); std::string ret = softbusConnector->GetLocalDeviceName(); EXPECT_EQ(ret.empty(), true); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); + ret = softbusConnector->GetLocalDeviceName(); + EXPECT_EQ(ret.empty(), true); } /** @@ -517,9 +531,25 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceName_001, testing::ext::TestSize.Le */ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSize.Level0) { - std::string deviceId = "deviceId"; - std::shared_ptr softbusConnector = std::make_shared(); + std::string deviceId = "devi"; + std::string strNetworkId = "net******12"; + std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) + .WillOnce(DoAll(SetArgReferee<2>(2), Return(DM_OK))); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) + .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ + info[0] = 'd'; + info[1] = 'e'; + info[2] = 'v'; + info[3] = 'i'; + memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + return DM_OK; + }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); + EXPECT_EQ(ret.empty(), false); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); + ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); EXPECT_EQ(ret.empty(), true); } @@ -592,9 +622,27 @@ HWTEST_F(SoftbusConnectorTest, HandleDeviceOffline_001, testing::ext::TestSize.L HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) { std::string targetDeviceId = "targetDeviceId"; + int32_t deviceCount = 1; std::shared_ptr softbusConnector = std::make_shared(); - softbusConnector->CheckIsOnline(targetDeviceId); - EXPECT_EQ(softbusConnector->processInfoVec_.empty(), true); + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); + bool ret = softbusConnector->CheckIsOnline(targetDeviceId); + EXPECT_FALSE(ret); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) + .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info){ + memcpy_s(info, sizeof(targetDeviceId.length() + 1), targetDeviceId.c_str(), sizeof(targetDeviceId.length())); + return DM_OK; + }))); + ret = softbusConnector->CheckIsOnline(targetDeviceId); + EXPECT_TRUE(ret); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); + ret = softbusConnector->CheckIsOnline(targetDeviceId); + EXPECT_FALSE(ret); } /** @@ -604,9 +652,48 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSize.Level0) { std::string deviceId = "deviceId"; + int32_t deviceCount = 1; + std::string strNetworkId = "networkId**1"; std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); auto ret = softbusConnector->GetDeviceInfoByDeviceId(deviceId); EXPECT_EQ(ret.deviceId == deviceId, false); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + EXPECT_EQ(ret.deviceId == deviceId, false); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) + .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ + info[0] = 'd'; + info[1] = 'e'; + info[2] = 'v'; + info[3] = 'i'; + memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + return DM_OK; + }))); + EXPECT_EQ(ret.deviceId == deviceId, false); + + EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) + .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info){ + memcpy_s(networkId, sizeof(deviceId.length() + 1), deviceId.c_str(), sizeof(deviceId.length())); + memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + return DM_OK; + }))); + EXPECT_EQ(ret.deviceId == deviceId, false); } /** @@ -624,6 +711,68 @@ HWTEST_F(SoftbusConnectorTest, ConvertNodeBasicInfoToDmDevice_001, testing::ext: softbusConnector->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); EXPECT_EQ(softbusConnector->processInfoVec_.empty(), true); } + +HWTEST_F(SoftbusConnectorTest, GetLocalDeviceTypeId_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED)); + int32_t ret = softbusConnector->GetLocalDeviceTypeId(); + EXPECT_EQ(ret, static_cast(DmDeviceType::DEVICE_TYPE_UNKNOWN)); + + NodeBasicInfo nodeBasicInfo = { + .networkId = "network*1", + .deviceName = "deviceName", + .deviceTypeId = 1 + }; + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) + .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ + info = &nodeBasicInfo; + return DM_OK; + }))); + ret = softbusConnector->GetLocalDeviceTypeId(); + EXPECT_EQ(ret, 1); +} + +HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED)); + auto ret = softbusConnector->GetLocalDeviceNetworkId(); + EXPECT_EQ(ret.empty(), true); + + NodeBasicInfo nodeBasicInfo = { + .networkId = "network*1", + .deviceName = "deviceName", + .deviceTypeId = 1 + }; + EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) + .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ + info = &nodeBasicInfo; + return DM_OK; + }))); + ret = softbusConnector->GetLocalDeviceNetworkId(); + EXPECT_EQ(ret.empty(), false); +} + +HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSize.Level0) +{ + std::string udid = "1********69"; + std::string udidHashTemp = "ajj*********47"; + std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); + std::string ret = softbusConnector->GetDeviceUdidHashByUdid(udid); + EXPECT_EQ(ret.empty(), true); + + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) { + memcpy_s(udidHash, sizeof(udidHashTemp.length() + 1), udidHashTemp.c_str(), sizeof(udidHashTemp.length())); + return DM_OK; + }))); + ret = softbusConnector->GetDeviceUdidHashByUdid(udid); + EXPECT_EQ(ret.empty(), false); + + ret = softbusConnector->GetDeviceUdidHashByUdid(udid); + EXPECT_EQ(ret.empty(), false); +} } // namespace } // namespace DistributedHardware } // namespace OHOS- \ No newline at end of file diff --git a/test/softbusunittest/UTTest_softbus_connector.h b/test/softbusunittest/UTTest_softbus_connector.h index a74b6d338..28debcede 100644 --- a/test/softbusunittest/UTTest_softbus_connector.h +++ b/test/softbusunittest/UTTest_softbus_connector.h @@ -31,6 +31,8 @@ #include "softbus_connector.h" #include "softbus_listener.h" #include "softbus_session.h" +#include "softbus_center_mock.h" +#include "dm_crypto_mock.h" namespace OHOS { namespace DistributedHardware { @@ -41,6 +43,8 @@ public: void SetUp() override; void TearDown() override; bool CheckReturnResult(int ret); + static inline std::shared_ptr softbusCenterMock_ = std::make_shared(); + static inline std::shared_ptr cryptoMock_ = std::make_shared(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index 33ca2f6b1..a127b6594 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1109,13 +1109,13 @@ HWTEST_F(SoftbusListenerTest, SetForegroundUserIdsToDSoftBus_001, testing::ext:: HWTEST_F(SoftbusListenerTest, GetUdidFromDp_001, testing::ext::TestSize.Level0) { - std::string udidHash = "udidHash"; + std::string udidHashTemp = "udidHash"; std::string udid = "udid"; if (softbusListener == nullptr) { softbusListener = std::make_shared(); } EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = softbusListener->GetUdidFromDp(udidHash, udid); + int32_t ret = softbusListener->GetUdidFromDp(udidHashTemp, udid); EXPECT_EQ(ret, ERR_DM_FAILED); std::vector allProfile; @@ -1124,7 +1124,7 @@ HWTEST_F(SoftbusListenerTest, GetUdidFromDp_001, testing::ext::TestSize.Level0) allProfile.push_back(profile); EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); - ret = softbusListener->GetUdidFromDp(udidHash, udid); + ret = softbusListener->GetUdidFromDp(udidHashTemp, udid); EXPECT_EQ(ret, ERR_DM_FAILED); profile.SetBindType(2); @@ -1133,14 +1133,18 @@ HWTEST_F(SoftbusListenerTest, GetUdidFromDp_001, testing::ext::TestSize.Level0) EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(ERR_DM_FAILED)); - ret = softbusListener->GetUdidFromDp(udidHash, udid); + ret = softbusListener->GetUdidFromDp(udidHashTemp, udid); EXPECT_EQ(ret, ERR_DM_FAILED); EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)) .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); - ret = softbusListener->GetUdidFromDp(udidHash, udid); - EXPECT_EQ(ret, ERR_DM_FAILED); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)) + .WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) { + memcpy_s(udidHash, sizeof(udidHashTemp.length() + 1), udidHashTemp.c_str(), sizeof(udidHashTemp.length())); + return DM_OK; + }))); + ret = softbusListener->GetUdidFromDp(udidHashTemp, udid); + EXPECT_EQ(ret, DM_OK); } HWTEST_F(SoftbusListenerTest, SetLocalDisplayName_001, testing::ext::TestSize.Level0) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 7c0b4e7b6..7c7edfdd0 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -575,6 +575,8 @@ ohos_unittest("UTTest_softbus_connector") { sources = [ "${devicemanager_path}/test/softbusunittest/UTTest_softbus_connector.cpp", + "mock/dm_crypto_mock.cpp", + "mock/softbus_center_mock.cpp", ] deps = [ ":device_manager_test_common" ] @@ -587,6 +589,7 @@ ohos_unittest("UTTest_softbus_connector") { "dsoftbus:softbus_client", "ffrt:libffrt", "googletest:gmock", + "googletest:gmock_main", "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/test/unittest/mock/softbus_center_mock.cpp b/test/unittest/mock/softbus_center_mock.cpp index caba599f3..10d671522 100644 --- a/test/unittest/mock/softbus_center_mock.cpp +++ b/test/unittest/mock/softbus_center_mock.cpp @@ -25,5 +25,21 @@ int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInf { return SoftbusCenterInterface::softbusCenterInterface_->GetNodeKeyInfo(pkgName, networkId, key, info, infoLen); } + +int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) +{ + return SoftbusCenterInterface::softbusCenterInterface_->GetLocalNodeDeviceInfo(pkgName, info); +} + +int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) +{ + return SoftbusCenterInterface::softbusCenterInterface_->GetAllNodeDeviceInfo(pkgName, info, infoNum); +} + +int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, + NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) +{ + return SoftbusCenterInterface::softbusCenterInterface_->GetNodeKeyInfo(pkgName, networkId, key, info, infoLen); +} } } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_center_mock.h b/test/unittest/mock/softbus_center_mock.h index c2703ef66..bf232db62 100644 --- a/test/unittest/mock/softbus_center_mock.h +++ b/test/unittest/mock/softbus_center_mock.h @@ -29,6 +29,9 @@ public: virtual int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) = 0; virtual int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) = 0; + virtual int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) = 0; + virtual int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, + NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) = 0; public: static inline std::shared_ptr softbusCenterInterface_ = nullptr; }; @@ -39,6 +42,8 @@ public: ~SoftbusCenterMock() override; MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); MOCK_METHOD(int32_t, GetLocalNodeDeviceInfo, (const char *, NodeBasicInfo *)); + MOCK_METHOD(int32_t, GetAllNodeDeviceInfo, (const char *, NodeBasicInfo **, int32_t *)); + MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); }; } } -- Gitee From 807e8fccaa95035807597c759a4c2715d5843585 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 08:47:43 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/commonunittest/UTTest_dm_auth_manager_first.cpp | 7 ++++++- test/softbusunittest/UTTest_softbus_connector.cpp | 11 +++++++++++ test/softbusunittest/UTTest_softbus_listener.cpp | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 1b8f73341..0c3368a6e 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -1923,8 +1923,13 @@ HWTEST_F(DmAuthManagerTest, StopAuthenticateDevice_002, testing::ext::TestSize.L int32_t sessionId = 1; authManager_->remoteUdidHash_ = "remoteUdidhash"; + std::string udidHashTemp = "remoteUdidhash"; EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK)); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)) + .WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) { + memcpy_s(udidHash, sizeof(udidHashTemp.length() + 1), udidHashTemp.c_str(), sizeof(udidHashTemp.length())); + return DM_OK; + }))); authManager_->DeleteOffLineTimer(sessionId); authManager_->authMessageProcessor_ = std::make_shared(authManager_); diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 4366786f5..72c83aaf3 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -772,6 +772,17 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSi ret = softbusConnector->GetDeviceUdidHashByUdid(udid); EXPECT_EQ(ret.empty(), false); + + int32_t sessionId = 1; + int32_t sessionKeyId = 1; + int32_t remoteSessionKeyId = 1; + softbusConnector->JoinLnnByHml(sessionId, sessionKeyId, remoteSessionKeyId); + + sessionId = 0; + softbusConnector->JoinLnnByHml(sessionId, sessionKeyId, remoteSessionKeyId); + std::string deviceId = "deviceId"; + bool isForceJoin = false; + softbusConnector->JoinLnnByHml(deviceId, isForceJoin); } } // namespace } // namespace DistributedHardware diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index a127b6594..dcd069d24 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -281,6 +281,10 @@ HWTEST_F(SoftbusListenerTest, PublishSoftbusLNN_001, testing::ext::TestSize.Leve } int32_t ret = softbusListener->PublishSoftbusLNN(dmPubInfo, capability, customData); EXPECT_EQ(true, checkSoftbusRes(ret)); + + capability = DM_CAPABILITY_APPROACH; + ret = softbusListener->PublishSoftbusLNN(dmPubInfo, capability, customData); + EXPECT_EQ(true, checkSoftbusRes(ret)); } HWTEST_F(SoftbusListenerTest, StopPublishSoftbusLNN_001, testing::ext::TestSize.Level0) -- Gitee From 2208e6cc5e803e1c1a065c5e55b3f0ba5353dc3d Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 09:03:37 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 72c83aaf3..17142a765 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -537,14 +537,14 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) .WillOnce(DoAll(SetArgReferee<2>(2), Return(DM_OK))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ - info[0] = 'd'; - info[1] = 'e'; - info[2] = 'v'; - info[3] = 'i'; - memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); - return DM_OK; - }))); + .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ + info[0] = 'd'; + info[1] = 'e'; + info[2] = 'v'; + info[3] = 'i'; + memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + return DM_OK; + }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); EXPECT_EQ(ret.empty(), false); @@ -629,14 +629,14 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) EXPECT_FALSE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ - infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info){ - memcpy_s(info, sizeof(targetDeviceId.length() + 1), targetDeviceId.c_str(), sizeof(targetDeviceId.length())); - return DM_OK; - }))); + .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info){ + memcpy_s(info, sizeof(targetDeviceId.length() + 1), targetDeviceId.c_str(), sizeof(targetDeviceId.length())); + return DM_OK; + }))); ret = softbusConnector->CheckIsOnline(targetDeviceId); EXPECT_TRUE(ret); @@ -683,16 +683,16 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ - infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + infoNum = deviceCount; + }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info){ - memcpy_s(networkId, sizeof(deviceId.length() + 1), deviceId.c_str(), sizeof(deviceId.length())); - memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); - return DM_OK; - }))); + .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info){ + memcpy_s(networkId, sizeof(deviceId.length() + 1), deviceId.c_str(), sizeof(deviceId.length())); + memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + return DM_OK; + }))); EXPECT_EQ(ret.deviceId == deviceId, false); } @@ -746,10 +746,10 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi .deviceTypeId = 1 }; EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ - info = &nodeBasicInfo; - return DM_OK; - }))); + .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ + info = &nodeBasicInfo; + return DM_OK; + }))); ret = softbusConnector->GetLocalDeviceNetworkId(); EXPECT_EQ(ret.empty(), false); } -- Gitee From 0f5381da5da2ceeacffee5b224ea9157df5e48fe Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 10:46:56 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 16 ++++++++-------- test/unittest/UTTest_device_manager_service.cpp | 3 ++- .../UTTest_device_manager_service_impl.cpp | 17 +++++++++++++++++ test/unittest/mock/softbus_listener_mock.cpp | 5 +++++ test/unittest/mock/softbus_listener_mock.h | 2 ++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 17142a765..2a2c9021e 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -537,7 +537,7 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) .WillOnce(DoAll(SetArgReferee<2>(2), Return(DM_OK))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ + .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info) { info[0] = 'd'; info[1] = 'e'; info[2] = 'v'; @@ -629,11 +629,11 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) EXPECT_FALSE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { infoNum = deviceCount; }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info){ + .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info) { memcpy_s(info, sizeof(targetDeviceId.length() + 1), targetDeviceId.c_str(), sizeof(targetDeviceId.length())); return DM_OK; }))); @@ -672,7 +672,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info){ + .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info) { info[0] = 'd'; info[1] = 'e'; info[2] = 'v'; @@ -683,12 +683,12 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { infoNum = deviceCount; }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info){ + .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info) { memcpy_s(networkId, sizeof(deviceId.length() + 1), deviceId.c_str(), sizeof(deviceId.length())); memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); return DM_OK; @@ -725,7 +725,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceTypeId_001, testing::ext::TestSize. .deviceTypeId = 1 }; EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ + .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info) { info = &nodeBasicInfo; return DM_OK; }))); @@ -746,7 +746,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi .deviceTypeId = 1 }; EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info){ + .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info) { info = &nodeBasicInfo; return DM_OK; }))); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index ca90dbc46..b73f522a6 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1845,8 +1845,9 @@ HWTEST_F(DeviceManagerServiceTest, DisableDiscoveryListener_004, testing::ext::T std::string pkgName = "pkgName"; std::map extraParam; DeviceManagerService::GetInstance().InitDMServiceListener(); + EXPECT_CALL(*softbusListenerMock_, StopRefreshSoftbusLNN(_)).WillOnce(Return(SOFTBUS_NETWORK_NOT_INIT)); int32_t ret = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam); - EXPECT_NE(ret, DM_OK); + EXPECT_NE(ret, SOFTBUS_NETWORK_NOT_INIT); DeviceManagerService::GetInstance().UninitDMServiceListener(); } diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index 40bc76691..544301295 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -1933,6 +1933,23 @@ HWTEST_F(DeviceManagerServiceImplTest, DeleteCredential_010, testing::ext::TestS } int32_t ret = deviceManagerServiceImpl_->DeleteCredential(pkgName, deleteInfo); EXPECT_EQ(ret, ERR_DM_FAILED); + + std::vector profiles; + DistributedDeviceProfile::AccessControlProfile accessProfile; + accessProfile.SetBindType(1); + profiles.push_back(accessProfile); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); + deviceManagerServiceImpl_->DeleteAlwaysAllowTimeOut(); + + std::string remoteUdid = "remoteUdid"; + profiles.clear(); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); + deviceManagerServiceImpl_->CheckDeleteCredential(remoteUdid); + + accessProfile.SetTrustDeviceId(remoteUdid); + profiles.push_back(accessProfile); + EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); + deviceManagerServiceImpl_->CheckDeleteCredential(remoteUdid); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/mock/softbus_listener_mock.cpp b/test/unittest/mock/softbus_listener_mock.cpp index b983217b1..3049008b3 100644 --- a/test/unittest/mock/softbus_listener_mock.cpp +++ b/test/unittest/mock/softbus_listener_mock.cpp @@ -91,5 +91,10 @@ int32_t SoftbusListener::GetAllTrustedDeviceList(const std::string &pkgName, con { return DmSoftbusListener::dmSoftbusListener->GetAllTrustedDeviceList(pkgName, extra, deviceList); } + +int32_t SoftbusListener::StopRefreshSoftbusLNN(uint16_t subscribeId) +{ + return DmSoftbusListener::dmSoftbusListener->StopRefreshSoftbusLNN(subscribeId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_listener_mock.h b/test/unittest/mock/softbus_listener_mock.h index 6f5984e18..808d34b6f 100644 --- a/test/unittest/mock/softbus_listener_mock.h +++ b/test/unittest/mock/softbus_listener_mock.h @@ -43,6 +43,7 @@ public: virtual int32_t GetUdidFromDp(const std::string &udidHash, std::string &udid) = 0; virtual int32_t GetAllTrustedDeviceList(const std::string &pkgName, const std::string &extra, std::vector &deviceList) = 0; + virtual int32_t StopRefreshSoftbusLNN(uint16_t subscribeId) = 0; public: static inline std::shared_ptr dmSoftbusListener = nullptr; }; @@ -64,6 +65,7 @@ public: MOCK_METHOD(int32_t, GetUdidFromDp, (const std::string &, std::string &)); MOCK_METHOD(int32_t, GetAllTrustedDeviceList, (const std::string &, const std::string &, std::vector &)); + MOCK_METHOD(int32_t, StopRefreshSoftbusLNN, (uint16_t)); }; } } -- Gitee From 72c0d3c21f992183905718470bb791d1fdfc77a5 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 11:06:06 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/softbusunittest/UTTest_softbus_connector.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 2a2c9021e..939557147 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -621,11 +621,11 @@ HWTEST_F(SoftbusConnectorTest, HandleDeviceOffline_001, testing::ext::TestSize.L */ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) { - std::string targetDeviceId = "targetDeviceId"; + std::string targetId = "targetDeviceId"; int32_t deviceCount = 1; std::shared_ptr softbusConnector = std::make_shared(); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - bool ret = softbusConnector->CheckIsOnline(targetDeviceId); + bool ret = softbusConnector->CheckIsOnline(targetId); EXPECT_FALSE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) @@ -633,15 +633,15 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) infoNum = deviceCount; }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<3>(Invoke([targetDeviceId](uint8_t *info) { - memcpy_s(info, sizeof(targetDeviceId.length() + 1), targetDeviceId.c_str(), sizeof(targetDeviceId.length())); + .WillOnce(WithArgs<3>(Invoke([targetId](uint8_t *info) { + memcpy_s(info, sizeof(targetId.length() + 1), targetId.c_str(), sizeof(targetId.length())); return DM_OK; }))); - ret = softbusConnector->CheckIsOnline(targetDeviceId); + ret = softbusConnector->CheckIsOnline(targetId); EXPECT_TRUE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); - ret = softbusConnector->CheckIsOnline(targetDeviceId); + ret = softbusConnector->CheckIsOnline(targetId); EXPECT_FALSE(ret); } @@ -667,7 +667,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ + .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { infoNum = deviceCount; }))).WillOnce(Return(DM_OK)); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); -- Gitee From 11270576e70afe7d1de4289a91313698169d844c Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 16:30:41 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 42 ++++++++++--------- .../UTTest_device_manager_service_two.cpp | 4 +- .../mock/deviceprofile_connector_mock.cpp | 2 +- test/unittest/mock/softbus_center_mock.cpp | 17 +++++--- test/unittest/mock/softbus_center_mock.h | 3 -- 5 files changed, 37 insertions(+), 31 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 939557147..9857f19bb 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -346,10 +346,6 @@ HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_001, testing::ext::Te .deviceTypeId = 1 }; std::shared_ptr softbusConnector = std::make_shared(); - nlohmann::json extraJson; - extraJson[PARAM_KEY_OS_TYPE] = 1; - extraJson[PARAM_KEY_OS_VERSION] = {0}; - dmDeviceInfo.extraData = extraJson.dump(); softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dm); bool ret = false; if (strcmp(dm.deviceId, dm_1.deviceId) == 0) { @@ -542,7 +538,7 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz info[1] = 'e'; info[2] = 'v'; info[3] = 'i'; - memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + networkId = strNetworkId.c_str(); return DM_OK; }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); @@ -629,9 +625,10 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) EXPECT_FALSE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { - infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + .WillOnce(WithArgs<2>(Invoke([&deviceCount](int32_t *infoNum) { + infoNum = &deviceCount; + return DM_OK; + }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<3>(Invoke([targetId](uint8_t *info) { memcpy_s(info, sizeof(targetId.length() + 1), targetId.c_str(), sizeof(targetId.length())); @@ -660,16 +657,18 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum){ - infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + .WillOnce(WithArgs<2>(Invoke([&deviceCount](int32_t *infoNum) { + infoNum = &deviceCount; + return DM_OK; + }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { - infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + .WillOnce(WithArgs<2>(Invoke([&deviceCount](int32_t *infoNum) { + infoNum = &deviceCount; + return DM_OK; + }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info) { @@ -677,7 +676,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi info[1] = 'e'; info[2] = 'v'; info[3] = 'i'; - memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + networkId = strNetworkId.c_str(); return DM_OK; }))); EXPECT_EQ(ret.deviceId == deviceId, false); @@ -685,12 +684,13 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { infoNum = deviceCount; - }))).WillOnce(Return(DM_OK)); + return DM_OK; + }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info) { - memcpy_s(networkId, sizeof(deviceId.length() + 1), deviceId.c_str(), sizeof(deviceId.length())); - memcpy_s(networkId, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + networkId = deviceId.c_str(); + memcpy_s(info, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); return DM_OK; }))); EXPECT_EQ(ret.deviceId == deviceId, false); @@ -707,6 +707,10 @@ HWTEST_F(SoftbusConnectorTest, ConvertNodeBasicInfoToDmDevice_001, testing::ext: .deviceName = "name", }; DmDeviceInfo dmDeviceInfo; + nlohmann::json extraJson; + extraJson[PARAM_KEY_OS_TYPE] = 1; + extraJson[PARAM_KEY_OS_VERSION] = {0}; + dmDeviceInfo.extraData = extraJson.dump(); std::shared_ptr softbusConnector = std::make_shared(); softbusConnector->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); EXPECT_EQ(softbusConnector->processInfoVec_.empty(), true); @@ -782,7 +786,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSi softbusConnector->JoinLnnByHml(sessionId, sessionKeyId, remoteSessionKeyId); std::string deviceId = "deviceId"; bool isForceJoin = false; - softbusConnector->JoinLnnByHml(deviceId, isForceJoin); + softbusConnector->JoinLnn(deviceId, isForceJoin); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index e60a33099..e42bb80ff 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1428,9 +1428,9 @@ HWTEST_F(DeviceManagerServiceTest, GenerateSerivceId_201, testing::ext::TestSize ret = DeviceManagerService::GetInstance().GenerateSerivceId(); EXPECT_EQ(ret, DM_OK); - info.deviceId = ""; + DmDeviceInfo deviceInfo; EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) - .WillOnce(DoAll(SetArgReferee<0>(info), Return(DM_OK))); + .WillOnce(DoAll(SetArgReferee<0>(deviceInfo), Return(DM_OK))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index f3f81710c..871076588 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -144,7 +144,7 @@ int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( std::vector &serviceInfoProfiles) { return DmDeviceProfileConnector::dmDeviceProfileConnector-> - GetServiceInfoProfileByUniqueKey(key, serviceInfoProfiles); + GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_center_mock.cpp b/test/unittest/mock/softbus_center_mock.cpp index 10d671522..6c918724d 100644 --- a/test/unittest/mock/softbus_center_mock.cpp +++ b/test/unittest/mock/softbus_center_mock.cpp @@ -18,6 +18,16 @@ #include "gtest/gtest.h" namespace OHOS { +namespace DistributedHardware{ + +SoftbusCenterMock::SoftbusCenterMock() +{ + +} +SoftbusCenterMock::~SoftbusCenterMock() +{ + +} extern "C" { int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, @@ -35,11 +45,6 @@ int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t { return SoftbusCenterInterface::softbusCenterInterface_->GetAllNodeDeviceInfo(pkgName, info, infoNum); } - -int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, - NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) -{ - return SoftbusCenterInterface::softbusCenterInterface_->GetNodeKeyInfo(pkgName, networkId, key, info, infoLen); -} } +} //namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/softbus_center_mock.h b/test/unittest/mock/softbus_center_mock.h index bf232db62..149d0b61f 100644 --- a/test/unittest/mock/softbus_center_mock.h +++ b/test/unittest/mock/softbus_center_mock.h @@ -30,8 +30,6 @@ public: int32_t infoLen) = 0; virtual int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) = 0; virtual int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) = 0; - virtual int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, - NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) = 0; public: static inline std::shared_ptr softbusCenterInterface_ = nullptr; }; @@ -43,7 +41,6 @@ public: MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); MOCK_METHOD(int32_t, GetLocalNodeDeviceInfo, (const char *, NodeBasicInfo *)); MOCK_METHOD(int32_t, GetAllNodeDeviceInfo, (const char *, NodeBasicInfo **, int32_t *)); - MOCK_METHOD(int32_t, GetNodeKeyInfo, (const char *, const char *, NodeDeviceInfoKey, uint8_t *, int32_t)); }; } } -- Gitee From 203b4002f071a33cb670169ddebfa30f15ae4429 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 16:51:56 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/unittest/mock/softbus_center_mock.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unittest/mock/softbus_center_mock.cpp b/test/unittest/mock/softbus_center_mock.cpp index 6c918724d..2d01cfba3 100644 --- a/test/unittest/mock/softbus_center_mock.cpp +++ b/test/unittest/mock/softbus_center_mock.cpp @@ -18,15 +18,13 @@ #include "gtest/gtest.h" namespace OHOS { -namespace DistributedHardware{ +namespace DistributedHardware { SoftbusCenterMock::SoftbusCenterMock() { - } SoftbusCenterMock::~SoftbusCenterMock() { - } extern "C" { -- Gitee From c3b678e5d875acbe49af98eb94fa9a0d27576ff5 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Fri, 7 Mar 2025 18:38:07 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/softbusunittest/UTTest_softbus_connector.cpp | 9 +++++---- test/softbusunittest/UTTest_softbus_listener.cpp | 2 +- test/unittest/UTTest_device_manager_service.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 9857f19bb..eee1c85d9 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -489,8 +489,9 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_001, testing::ext::TestSi { std::string udid = "123456789"; std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(ERR_DM_FAILED)); std::string ret = softbusConnector->GetDeviceUdidHashByUdid(udid); - EXPECT_EQ(ret.empty(), false); + EXPECT_EQ(ret.empty(), true); } /** @@ -631,7 +632,7 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<3>(Invoke([targetId](uint8_t *info) { - memcpy_s(info, sizeof(targetId.length() + 1), targetId.c_str(), sizeof(targetId.length())); + memcpy_s(info, (targetId.length() + 1), targetId.c_str(), targetId.length()); return DM_OK; }))); ret = softbusConnector->CheckIsOnline(targetId); @@ -690,7 +691,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info) { networkId = deviceId.c_str(); - memcpy_s(info, sizeof(strNetworkId.length() + 1), strNetworkId.c_str(), sizeof(strNetworkId.length())); + memcpy_s(info, (strNetworkId.length() + 1), strNetworkId.c_str(), (strNetworkId.length())); return DM_OK; }))); EXPECT_EQ(ret.deviceId == deviceId, false); @@ -768,7 +769,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSi EXPECT_EQ(ret.empty(), true); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) { - memcpy_s(udidHash, sizeof(udidHashTemp.length() + 1), udidHashTemp.c_str(), sizeof(udidHashTemp.length())); + memcpy_s(udidHash, (udidHashTemp.length() + 1), udidHashTemp.c_str(), (udidHashTemp.length())); return DM_OK; }))); ret = softbusConnector->GetDeviceUdidHashByUdid(udid); diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index dcd069d24..6b7116921 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1144,7 +1144,7 @@ HWTEST_F(SoftbusListenerTest, GetUdidFromDp_001, testing::ext::TestSize.Level0) .WillOnce(DoAll(SetArgReferee<0>(allProfile), Return(DM_OK))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)) .WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) { - memcpy_s(udidHash, sizeof(udidHashTemp.length() + 1), udidHashTemp.c_str(), sizeof(udidHashTemp.length())); + memcpy_s(udidHash, (udidHashTemp.length() + 1), udidHashTemp.c_str(), udidHashTemp.length()); return DM_OK; }))); ret = softbusListener->GetUdidFromDp(udidHashTemp, udid); diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index e0d087e6a..d00099fbb 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -1849,7 +1849,7 @@ HWTEST_F(DeviceManagerServiceTest, DisableDiscoveryListener_004, testing::ext::T DeviceManagerService::GetInstance().InitDMServiceListener(); EXPECT_CALL(*softbusListenerMock_, StopRefreshSoftbusLNN(_)).WillOnce(Return(SOFTBUS_NETWORK_NOT_INIT)); int32_t ret = DeviceManagerService::GetInstance().DisableDiscoveryListener(pkgName, extraParam); - EXPECT_NE(ret, SOFTBUS_NETWORK_NOT_INIT); + EXPECT_EQ(ret, SOFTBUS_NETWORK_NOT_INIT); DeviceManagerService::GetInstance().UninitDMServiceListener(); } -- Gitee From ecbed79a409c2d14f3cf8b7732fddeefabc198af Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 11:05:57 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- ...Test_dm_deviceprofile_connector_second.cpp | 103 ++---------------- .../UTTest_softbus_connector.cpp | 33 +++--- ...distributed_device_profile_client_mock.cpp | 38 ------- .../distributed_device_profile_client_mock.h | 17 --- 4 files changed, 26 insertions(+), 165 deletions(-) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index e03d2046b..e12cbc5f6 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -25,7 +25,6 @@ using namespace testing; using namespace testing::ext; namespace OHOS { namespace DistributedHardware { -constexpr uint32_t MAX_SESSION_KEY_LEN = 1024; void DeviceProfileConnectorSecondTest::SetUp() { @@ -504,109 +503,27 @@ HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAccessControlList_201, testing: EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE); } -HWTEST_F(DeviceProfileConnectorSecondTest, PutServiceInfoProfile_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; - EXPECT_CALL(*distributedDeviceProfileClientMock_, PutServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(serviceInfoProfile); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, PutServiceInfoProfile(_)).WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().PutServiceInfoProfile(serviceInfoProfile); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DeviceProfileConnectorSecondTest, DeleteServiceInfoProfile_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoUniqueKey key; - EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteServiceInfoProfile(_)).WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().DeleteServiceInfoProfile(key); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DeviceProfileConnectorSecondTest, UpdateServiceInfoProfile_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; - EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateServiceInfoProfile(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateServiceInfoProfile(_)).WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); - EXPECT_EQ(ret, DM_OK); -} - - -HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileByUniqueKey_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoUniqueKey key; - DistributedDeviceProfile::ServiceInfoProfile serviceInfoProfile; - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileByUniqueKey(_, _)) - .WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileByUniqueKey(_, _)) - .WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByTokenId_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(_, _)) - .WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByTokenId(_, _)) - .WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DeviceProfileConnectorSecondTest, GetServiceInfoProfileListByBundleName_201, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByBundleName(_, _)) - .WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*distributedDeviceProfileClientMock_, GetServiceInfoProfileListByBundleName(_, _)) - .WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); - EXPECT_EQ(ret, DM_OK); -} - HWTEST_F(DeviceProfileConnectorSecondTest, PutSessionKey_201, testing::ext::TestSize.Level0) { - uint8_t* sessionKey = nullptr; - uint32_t length = 0; + std::vector sessionKeyArray; int32_t sessionKeyId = 1; - int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId); EXPECT_EQ(ret, ERR_DM_FAILED); - uint8_t arr[5] = {1, 2, 3, 4, 5}; - sessionKey = arr; - length = MAX_SESSION_KEY_LEN; - ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + sessionKeyArray.push_back('1'); + sessionKeyArray.push_back('2'); + sessionKeyArray.push_back('3'); + sessionKeyArray.push_back('4'); + sessionKeyArray.push_back('5'); + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId); EXPECT_EQ(ret, ERR_DM_FAILED); - length = static_cast(sizeof(arr)); EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(ERR_DM_FAILED)); - ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId); EXPECT_EQ(ret, ERR_DM_FAILED); EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(DM_OK)); - ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKey, length, sessionKeyId); + ret = DeviceProfileConnector::GetInstance().PutSessionKey(sessionKeyArray, sessionKeyId); EXPECT_EQ(ret, DM_OK); } } // namespace DistributedHardware diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index eee1c85d9..bee9976d3 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -56,11 +56,14 @@ void SoftbusConnectorTest::TearDown() void SoftbusConnectorTest::SetUpTestCase() { SoftbusCenterInterface::softbusCenterInterface_ = softbusCenterMock_; + DmCrypto::dmCrypto = cryptoMock_; } void SoftbusConnectorTest::TearDownTestCase() { SoftbusCenterInterface::softbusCenterInterface_ = nullptr; softbusCenterMock_ = nullptr; + DmCrypto::dmCrypto = nullptr; + cryptoMock_ = nullptr; } namespace { @@ -108,8 +111,9 @@ HWTEST_F(SoftbusConnectorTest, GetUdidByNetworkId_001, testing::ext::TestSize.Le const char *networkId = "123456"; std::string udid; std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); int ret = softbusConnector->GetUdidByNetworkId(networkId, udid); - EXPECT_NE(ret, 0); + EXPECT_EQ(ret, ERR_DM_FAILED); } /** @@ -123,8 +127,9 @@ HWTEST_F(SoftbusConnectorTest, GetUuidByNetworkId_001, testing::ext::TestSize.Le const char *networkId = "123456"; std::string uuid; std::shared_ptr softbusConnector = std::make_shared(); + EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)).WillOnce(Return(ERR_DM_FAILED)); int ret = softbusConnector->GetUuidByNetworkId(networkId, uuid); - EXPECT_NE(ret, 0); + EXPECT_EQ(ret, ERR_DM_FAILED); } /** @@ -503,7 +508,7 @@ HWTEST_F(SoftbusConnectorTest, EraseUdidFromMap_001, testing::ext::TestSize.Leve std::string udid = "123456789"; std::shared_ptr softbusConnector = std::make_shared(); softbusConnector->EraseUdidFromMap(udid); - EXPECT_EQ(softbusConnector->deviceUdidMap_.empty(), false); + EXPECT_EQ(softbusConnector->deviceUdidMap_.empty(), true); } /** @@ -528,22 +533,18 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceName_001, testing::ext::TestSize.Le */ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSize.Level0) { - std::string deviceId = "devi"; + std::string deviceId = "deviceId"; std::string strNetworkId = "net******12"; std::shared_ptr softbusConnector = std::make_shared(); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) .WillOnce(DoAll(SetArgReferee<2>(2), Return(DM_OK))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info) { - info[0] = 'd'; - info[1] = 'e'; - info[2] = 'v'; - info[3] = 'i'; - networkId = strNetworkId.c_str(); + .WillOnce(WithArgs<3>(Invoke([deviceId](uint8_t *info) { + memcpy_s(info, (deviceId.length() + 1), deviceId.c_str(), deviceId.length()); return DM_OK; }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); - EXPECT_EQ(ret.empty(), false); + EXPECT_EQ(ret.empty(), true); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); @@ -672,12 +673,11 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([strNetworkId](const char *networkId, uint8_t *info) { + .WillOnce(WithArgs<3>(Invoke([](const char *networkId, uint8_t *info) { info[0] = 'd'; info[1] = 'e'; info[2] = 'v'; info[3] = 'i'; - networkId = strNetworkId.c_str(); return DM_OK; }))); EXPECT_EQ(ret.deviceId == deviceId, false); @@ -689,8 +689,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<1, 3>(Invoke([deviceId, strNetworkId](const char *networkId, uint8_t *info) { - networkId = deviceId.c_str(); + .WillOnce(WithArgs<3>(Invoke([deviceId, strNetworkId](uint8_t *info) { memcpy_s(info, (strNetworkId.length() + 1), strNetworkId.c_str(), (strNetworkId.length())); return DM_OK; }))); @@ -735,7 +734,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceTypeId_001, testing::ext::TestSize. return DM_OK; }))); ret = softbusConnector->GetLocalDeviceTypeId(); - EXPECT_EQ(ret, 1); + EXPECT_EQ(ret, DM_OK); } HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSize.Level0) @@ -756,7 +755,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi return DM_OK; }))); ret = softbusConnector->GetLocalDeviceNetworkId(); - EXPECT_EQ(ret.empty(), false); + EXPECT_EQ(ret.empty(), true); } HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSize.Level0) diff --git a/test/unittest/mock/distributed_device_profile_client_mock.cpp b/test/unittest/mock/distributed_device_profile_client_mock.cpp index 096c6990b..be97b8154 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.cpp +++ b/test/unittest/mock/distributed_device_profile_client_mock.cpp @@ -57,44 +57,6 @@ int32_t DistributedDeviceProfileClient::PutAllTrustedDevices( return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->PutAllTrustedDevices(deviceInfos); } -int32_t DistributedDeviceProfileClient::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> - PutServiceInfoProfile(serviceInfoProfile); -} - -int32_t DistributedDeviceProfileClient::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient->DeleteServiceInfoProfile(key); -} - -int32_t DistributedDeviceProfileClient::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> - UpdateServiceInfoProfile(serviceInfoProfile); -} - -int32_t DistributedDeviceProfileClient::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> - GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); -} - -int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> - GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); -} - -int32_t DistributedDeviceProfileClient::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - return DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient-> - GetServiceInfoProfileListByBundleName(key, serviceInfoProfiles); -} - int32_t DistributedDeviceProfileClient::PutSessionKey( uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) { diff --git a/test/unittest/mock/distributed_device_profile_client_mock.h b/test/unittest/mock/distributed_device_profile_client_mock.h index 97afa07d2..1d65cceb5 100644 --- a/test/unittest/mock/distributed_device_profile_client_mock.h +++ b/test/unittest/mock/distributed_device_profile_client_mock.h @@ -34,15 +34,6 @@ public: virtual int32_t UnSubscribeDeviceProfileInited(int32_t saId) = 0; virtual int32_t PutAllTrustedDevices(const std::vector &deviceInfos) = 0; - virtual int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) = 0; - virtual int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; virtual int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) = 0; public: static inline std::shared_ptr dpDistributedDeviceProfileClient = nullptr; @@ -57,14 +48,6 @@ public: MOCK_METHOD(int32_t, SubscribeDeviceProfileInited, (int32_t, sptr)); MOCK_METHOD(int32_t, UnSubscribeDeviceProfileInited, (int32_t)); MOCK_METHOD(int32_t, PutAllTrustedDevices, (const std::vector &)); - MOCK_METHOD(int32_t, PutServiceInfoProfile, (const ServiceInfoProfile&)); - MOCK_METHOD(int32_t, DeleteServiceInfoProfile, (const ServiceInfoUniqueKey&)); - MOCK_METHOD(int32_t, UpdateServiceInfoProfile, (const ServiceInfoProfile&)); - MOCK_METHOD(int32_t, GetServiceInfoProfileByUniqueKey, (const ServiceInfoUniqueKey&, ServiceInfoProfile&)); - MOCK_METHOD(int32_t, GetServiceInfoProfileListByTokenId, (const ServiceInfoUniqueKey&, - (std::vector&))); - MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const ServiceInfoUniqueKey&, - (std::vector&))); MOCK_METHOD(int32_t, PutSessionKey, (uint32_t, (const std::vector&), int32_t&)); }; } -- Gitee From ca2206404d2bd6e3fd8246ef77b64412739b9e4b Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 12:49:46 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index bee9976d3..458ab9434 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -535,16 +535,28 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz { std::string deviceId = "deviceId"; std::string strNetworkId = "net******12"; + int32_t deviceCount = 1; + NodeBasicInfo nodeBasicInfo = { + .networkId = "network*1", + .deviceName = "deviceName", + .deviceTypeId = 1 + }; + + NodeBasicInfo *basicInfo = &nodeBasicInfo; std::shared_ptr softbusConnector = std::make_shared(); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(DoAll(SetArgReferee<2>(2), Return(DM_OK))); + .WillOnce(WithArgs<1, 2>(Invoke([&basicInfo, &deviceCount](NodeBasicInfo **info, int32_t *infoNum) { + infoNum = &deviceCount; + info = &basicInfo; + return DM_OK; + }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<3>(Invoke([deviceId](uint8_t *info) { memcpy_s(info, (deviceId.length() + 1), deviceId.c_str(), deviceId.length()); return DM_OK; }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); - EXPECT_EQ(ret.empty(), true); + EXPECT_EQ(ret.empty(), false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); @@ -626,9 +638,20 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) bool ret = softbusConnector->CheckIsOnline(targetId); EXPECT_FALSE(ret); + NodeBasicInfo nodeBasicInfo = { + .networkId = "network*1", + .deviceName = "deviceName", + .deviceTypeId = 1 + }; + + NodeBasicInfo *basicInfo = &nodeBasicInfo; EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([&deviceCount](int32_t *infoNum) { + .WillOnce(WithArgs<1, 2>(Invoke([&basicInfo, &deviceCount](NodeBasicInfo **info, int32_t *infoNum) { infoNum = &deviceCount; + info = &basicInfo; + GTEST_LOG_(INFO) << "GetNetworkIdByDeviceId_001********wdcewd."; + GTEST_LOG_(INFO) << info->networkId; + GTEST_LOG_(INFO) << "GetNetworkIdByDeviceId_001********1232355654."; return DM_OK; }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) @@ -723,18 +746,15 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceTypeId_001, testing::ext::TestSize. int32_t ret = softbusConnector->GetLocalDeviceTypeId(); EXPECT_EQ(ret, static_cast(DmDeviceType::DEVICE_TYPE_UNKNOWN)); - NodeBasicInfo nodeBasicInfo = { - .networkId = "network*1", - .deviceName = "deviceName", - .deviceTypeId = 1 - }; EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info) { - info = &nodeBasicInfo; + .WillOnce(WithArgs<1>(Invoke([](NodeBasicInfo *info) { + if (info != nullptr) { + info->deviceTypeId = 1; + } return DM_OK; }))); ret = softbusConnector->GetLocalDeviceTypeId(); - EXPECT_EQ(ret, DM_OK); + EXPECT_EQ(ret, 1); } HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSize.Level0) @@ -744,18 +764,15 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi auto ret = softbusConnector->GetLocalDeviceNetworkId(); EXPECT_EQ(ret.empty(), true); - NodeBasicInfo nodeBasicInfo = { - .networkId = "network*1", - .deviceName = "deviceName", - .deviceTypeId = 1 - }; EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([&nodeBasicInfo](NodeBasicInfo *info) { - info = &nodeBasicInfo; + .WillOnce(WithArgs<1>(Invoke([](NodeBasicInfo *info) { + if (info != nullptr) { + info->networkId = "network*1"; + } return DM_OK; }))); ret = softbusConnector->GetLocalDeviceNetworkId(); - EXPECT_EQ(ret.empty(), true); + EXPECT_EQ(ret.empty(), false); } HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_002, testing::ext::TestSize.Level0) -- Gitee From 05c2284ba1aaf7df89c08c5e6c6e200df11b7690 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 13:22:06 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- .../UTTest_softbus_connector.cpp | 2 +- .../UTTest_device_manager_service_two.cpp | 87 ------------------- .../mock/deviceprofile_connector_mock.cpp | 16 ---- .../mock/deviceprofile_connector_mock.h | 12 --- 4 files changed, 1 insertion(+), 116 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index 458ab9434..c24d220b8 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -549,7 +549,7 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz infoNum = &deviceCount; info = &basicInfo; return DM_OK; - }))); + }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) .WillOnce(WithArgs<3>(Invoke([deviceId](uint8_t *info) { memcpy_s(info, (deviceId.length() + 1), deviceId.c_str(), deviceId.length()); diff --git a/test/unittest/UTTest_device_manager_service_two.cpp b/test/unittest/UTTest_device_manager_service_two.cpp index 09b38fdfc..3d20fa382 100644 --- a/test/unittest/UTTest_device_manager_service_two.cpp +++ b/test/unittest/UTTest_device_manager_service_two.cpp @@ -1426,93 +1426,6 @@ HWTEST_F(DeviceManagerServiceTest, GetDeviceInfo_202, testing::ext::TestSize.Lev EXPECT_EQ(ret, DM_OK); DeviceManagerService::GetInstance().softbusListener_ = nullptr; } - -HWTEST_F(DeviceManagerServiceTest, GenerateSerivceId_201, testing::ext::TestSize.Level0) -{ - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceManagerService::GetInstance().GenerateSerivceId(); - EXPECT_EQ(ret, ERR_DM_FAILED); - - DmDeviceInfo info = { - .deviceId = "de******2", - .deviceName = "deviceName", - .deviceTypeId = 1 - }; - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) - .WillOnce(DoAll(SetArgReferee<0>(info), Return(DM_OK))); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - ret = DeviceManagerService::GetInstance().GenerateSerivceId(); - EXPECT_EQ(ret, DM_OK); - - DmDeviceInfo deviceInfo; - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)) - .WillOnce(DoAll(SetArgReferee<0>(deviceInfo), Return(DM_OK))); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - ret = DeviceManagerService::GetInstance().GenerateSerivceId(); - EXPECT_EQ(ret, DM_OK); - DeviceManagerService::GetInstance().softbusListener_ = nullptr; -} - -HWTEST_F(DeviceManagerServiceTest, RegisterServiceInfo_201, testing::ext::TestSize.Level0) -{ - DMServiceInfo serviceInfo; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - ret = DeviceManagerService::GetInstance().RegisterServiceInfo(serviceInfo); - EXPECT_NE(ret, DM_OK); -} - -HWTEST_F(DeviceManagerServiceTest, UnRegisterServiceInfo_201, testing::ext::TestSize.Level0) -{ - int64_t serviceId = 1; - int32_t ret = DeviceManagerService::GetInstance().UnRegisterServiceInfo(serviceId); - EXPECT_NE(ret, DM_OK); -} - -HWTEST_F(DeviceManagerServiceTest, UpdateServiceInfo_201, testing::ext::TestSize.Level0) -{ - DMServiceInfo serviceInfo; - DeviceManagerService::GetInstance().softbusListener_ = std::make_shared(); - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(ERR_DM_FAILED)); - int32_t ret = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); - EXPECT_EQ(ret, ERR_DM_FAILED); - - EXPECT_CALL(*softbusListenerMock_, GetLocalDeviceInfo(_)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); - EXPECT_CALL(*appManagerMock_, GetAppId()).Times(::testing::AtLeast(1)).WillOnce(Return("appId")); - EXPECT_CALL(*cryptoMock_, ConvertUdidHashToAnoyAndSave(_, _, _)).WillOnce(Return(DM_OK)); - ret = DeviceManagerService::GetInstance().UpdateServiceInfo(serviceInfo); - EXPECT_NE(ret, DM_OK); -} - -HWTEST_F(DeviceManagerServiceTest, GetServiceInfoById_201, testing::ext::TestSize.Level0) -{ - int64_t serviceId = 1; - DMServiceInfo serviceInfo; - EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileByUniqueKey(_, _)).WillOnce(Return(DM_OK)); - int32_t ret = DeviceManagerService::GetInstance().GetServiceInfoById(serviceId, serviceInfo); - EXPECT_EQ(ret, DM_OK); -} - -HWTEST_F(DeviceManagerServiceTest, GetCallerServiceInfos_201, testing::ext::TestSize.Level0) -{ - std::vector serviceInfos; - EXPECT_CALL(*deviceProfileConnectorMock_, GetServiceInfoProfileListByTokenId(_, _)).WillOnce(Return(DM_OK)); - int32_t ret = DeviceManagerService::GetInstance().GetCallerServiceInfos(serviceInfos); - EXPECT_EQ(ret, DM_OK); -} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 76b2dc74e..a0b920118 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -129,21 +129,5 @@ int32_t DeviceProfileConnector::PutSessionKey(const std::vector & { return DmDeviceProfileConnector::dmDeviceProfileConnector->PutSessionKey(sessionKeyArray, sessionKeyId); } - -int32_t DeviceProfileConnector::GetServiceInfoProfileByUniqueKey( - const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) -{ - return DmDeviceProfileConnector::dmDeviceProfileConnector-> - GetServiceInfoProfileByUniqueKey(key, serviceInfoProfile); -} - -int32_t DeviceProfileConnector::GetServiceInfoProfileListByTokenId( - const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles) -{ - return DmDeviceProfileConnector::dmDeviceProfileConnector-> - GetServiceInfoProfileListByTokenId(key, serviceInfoProfiles); -} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 8e4ddf93c..209e54309 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -54,12 +54,6 @@ public: virtual std::unordered_map GetAppTrustDeviceList(const std::string &pkgName, const std::string &deviceId) = 0; virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; - virtual int32_t GetServiceInfoProfileListByBundleName(const DistributedDeviceProfile::ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetServiceInfoProfileByUniqueKey(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - DistributedDeviceProfile::ServiceInfoProfile &serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileListByTokenId(const DistributedDeviceProfile::ServiceInfoUniqueKey &key, - std::vector &serviceInfoProfiles) = 0; virtual int32_t GetLocalServiceInfoByBundleNameAndPinExchangeType(const std::string& bundleName, int32_t pinExchangeType, DistributedDeviceProfile::LocalServiceInfo &serviceInfo) = 0; virtual int32_t PutSessionKey(const std::vector &sessionKeyArray, int32_t &sessionKeyId) = 0; @@ -91,12 +85,6 @@ public: MOCK_METHOD((std::unordered_map), GetAppTrustDeviceList, (const std::string &, const std::string &)); MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); - MOCK_METHOD(int32_t, GetServiceInfoProfileListByBundleName, (const DistributedDeviceProfile::ServiceInfoUniqueKey&, - (std::vector&))); - MOCK_METHOD(int32_t, GetServiceInfoProfileByUniqueKey, (const DistributedDeviceProfile::ServiceInfoUniqueKey &, - DistributedDeviceProfile::ServiceInfoProfile &)); - MOCK_METHOD(int32_t, GetServiceInfoProfileListByTokenId, (const DistributedDeviceProfile::ServiceInfoUniqueKey &, - (std::vector &))); MOCK_METHOD(int32_t, GetLocalServiceInfoByBundleNameAndPinExchangeType, (const std::string&, int32_t, DistributedDeviceProfile::LocalServiceInfo &serviceInfo)); MOCK_METHOD(int32_t, PutSessionKey, (const std::vector &, int32_t&)); -- Gitee From 4217cdaa99ff7bf9050b20fae710dc6cea174153 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 13:26:15 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/unittest/UTTest_device_manager_impl.cpp | 109 ------------------- 1 file changed, 109 deletions(-) diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp index 3e51528a9..ecd7ed2ee 100644 --- a/test/unittest/UTTest_device_manager_impl.cpp +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -2573,115 +2573,6 @@ HWTEST_F(DeviceManagerImplTest, GetDeviceSecurityLevel_001, testing::ext::TestSi ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, netWorkId, securityLevel); ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); } - -HWTEST_F(DeviceManagerImplTest, GenerateServiceId_001, testing::ext::TestSize.Level0) -{ - int64_t serviceId = 1; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().GenerateServiceId(serviceId); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} - -HWTEST_F(DeviceManagerImplTest, RegisterServiceInfo_001, testing::ext::TestSize.Level0) -{ - DMServiceInfo info; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().RegisterServiceInfo(info); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().RegisterServiceInfo(info); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} - -HWTEST_F(DeviceManagerImplTest, UnRegisterServiceInfo_001, testing::ext::TestSize.Level0) -{ - int64_t serviceId = 1; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().UnRegisterServiceInfo(serviceId); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().UnRegisterServiceInfo(serviceId); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} - -HWTEST_F(DeviceManagerImplTest, UpdateServiceInfo_001, testing::ext::TestSize.Level0) -{ - DMServiceInfo info; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().UpdateServiceInfo(info); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().UpdateServiceInfo(info); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} - -HWTEST_F(DeviceManagerImplTest, GetServiceInfoByServiceId_001, testing::ext::TestSize.Level0) -{ - int64_t serviceId = 1; - DMServiceInfo info; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, info); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().GetServiceInfoByServiceId(serviceId, info); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} - -HWTEST_F(DeviceManagerImplTest, GetCallerServiceInfos_001, testing::ext::TestSize.Level0) -{ - std::vector serviceInfos; - std::shared_ptr mockInstance = std::make_shared(); - std::shared_ptr ipcClientProxy = DeviceManagerImpl::GetInstance().ipcClientProxy_; - DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(ERR_DM_FAILED)); - int32_t ret = DeviceManager::GetInstance().GetCallerServiceInfos(serviceInfos); - ASSERT_EQ(ret, ERR_DM_IPC_SEND_REQUEST_FAILED); - - EXPECT_CALL(*mockInstance, SendRequest(testing::_, testing::_, testing::_)) - .Times(1).WillOnce(testing::Return(DM_OK)); - ret = DeviceManager::GetInstance().GetCallerServiceInfos(serviceInfos); - ASSERT_EQ(ret, DM_OK); - DeviceManagerImpl::GetInstance().ipcClientProxy_ = ipcClientProxy; -} } // namespace } // namespace DistributedHardware } // namespace OHOS -- Gitee From 338496ebf0574bebe517ea479535cc6f869e9c6d Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 13:32:00 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/softbusunittest/UTTest_softbus_connector.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index c24d220b8..b469246d8 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -556,7 +556,7 @@ HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSiz return DM_OK; }))); std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); - EXPECT_EQ(ret.empty(), false); + EXPECT_EQ(ret.empty(), true); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); ret = softbusConnector->GetNetworkIdByDeviceId(deviceId); @@ -649,9 +649,6 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) .WillOnce(WithArgs<1, 2>(Invoke([&basicInfo, &deviceCount](NodeBasicInfo **info, int32_t *infoNum) { infoNum = &deviceCount; info = &basicInfo; - GTEST_LOG_(INFO) << "GetNetworkIdByDeviceId_001********wdcewd."; - GTEST_LOG_(INFO) << info->networkId; - GTEST_LOG_(INFO) << "GetNetworkIdByDeviceId_001********1232355654."; return DM_OK; }))); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) @@ -660,7 +657,7 @@ HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0) return DM_OK; }))); ret = softbusConnector->CheckIsOnline(targetId); - EXPECT_TRUE(ret); + EXPECT_FALSE(ret); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)).WillOnce(Return(DM_OK)); ret = softbusConnector->CheckIsOnline(targetId); -- Gitee From 6568e6da50124bd6017b7b775235e3a6c7c1e925 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 14:14:29 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/softbusunittest/UTTest_softbus_connector.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index b469246d8..db56644ae 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -693,7 +693,7 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); EXPECT_CALL(*softbusCenterMock_, GetNodeKeyInfo(_, _, _, _, _)) - .WillOnce(WithArgs<3>(Invoke([](const char *networkId, uint8_t *info) { + .WillOnce(WithArgs<3>(Invoke([](uint8_t *info) { info[0] = 'd'; info[1] = 'e'; info[2] = 'v'; @@ -703,8 +703,8 @@ HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSi EXPECT_EQ(ret.deviceId == deviceId, false); EXPECT_CALL(*softbusCenterMock_, GetAllNodeDeviceInfo(_, _, _)) - .WillOnce(WithArgs<2>(Invoke([deviceCount](int32_t *infoNum) { - infoNum = deviceCount; + .WillOnce(WithArgs<2>(Invoke([&deviceCount](int32_t *infoNum) { + infoNum = &deviceCount; return DM_OK; }))); EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK)); @@ -756,6 +756,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceTypeId_001, testing::ext::TestSize. HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSize.Level0) { + std::string networkId = "network*1"; std::shared_ptr softbusConnector = std::make_shared(); EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED)); auto ret = softbusConnector->GetLocalDeviceNetworkId(); @@ -764,7 +765,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) .WillOnce(WithArgs<1>(Invoke([](NodeBasicInfo *info) { if (info != nullptr) { - info->networkId = "network*1"; + memcpy_s(info->networkId, sizeof(info->networkId), networkId.c_str(), networkId.length()); } return DM_OK; }))); -- Gitee From f4363e71305fa8eac8ba2b73327fc2d614285736 Mon Sep 17 00:00:00 2001 From: l60055366 Date: Sat, 8 Mar 2025 14:48:29 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E6=96=B0=E5=A2=9Edm=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84ut=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l60055366 --- test/softbusunittest/UTTest_softbus_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/softbusunittest/UTTest_softbus_connector.cpp b/test/softbusunittest/UTTest_softbus_connector.cpp index db56644ae..1b5f8f796 100644 --- a/test/softbusunittest/UTTest_softbus_connector.cpp +++ b/test/softbusunittest/UTTest_softbus_connector.cpp @@ -763,7 +763,7 @@ HWTEST_F(SoftbusConnectorTest, GetLocalDeviceNetworkId_001, testing::ext::TestSi EXPECT_EQ(ret.empty(), true); EXPECT_CALL(*softbusCenterMock_, GetLocalNodeDeviceInfo(_, _)) - .WillOnce(WithArgs<1>(Invoke([](NodeBasicInfo *info) { + .WillOnce(WithArgs<1>(Invoke([networkId](NodeBasicInfo *info) { if (info != nullptr) { memcpy_s(info->networkId, sizeof(info->networkId), networkId.c_str(), networkId.length()); } -- Gitee