diff --git a/test/commonunittest/UTTest_dm_device_state_manager.cpp b/test/commonunittest/UTTest_dm_device_state_manager.cpp index 80aaf0bbf38f2d751c39ed2c7ce3387082572af4..388e5e7a4a257b1bd1c19dc04147c8bada4e9856 100644 --- a/test/commonunittest/UTTest_dm_device_state_manager.cpp +++ b/test/commonunittest/UTTest_dm_device_state_manager.cpp @@ -252,6 +252,73 @@ HWTEST_F(DmDeviceStateManagerTest, ProcNotifyEvent_001, testing::ext::TestSize.L dmDeviceStateManager->ChangeDeviceInfo(info); EXPECT_EQ(ret, DM_OK); } + +HWTEST_F(DmDeviceStateManagerTest, HandleDeviceStatusChange_001, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info; + DmDeviceState state = DEVICE_STATE_ONLINE; + EXPECT_NO_THROW(dmDeviceStateManager->HandleDeviceStatusChange(state, info)); +} + +HWTEST_F(DmDeviceStateManagerTest, HandleDeviceStatusChange_002, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info; + DmDeviceState state = DEVICE_STATE_OFFLINE; + EXPECT_NO_THROW(dmDeviceStateManager->HandleDeviceStatusChange(state, info)); +} + +HWTEST_F(DmDeviceStateManagerTest, HandleDeviceStatusChange_003, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info; + DmDeviceState state = DEVICE_INFO_CHANGED; + EXPECT_NO_THROW(dmDeviceStateManager->HandleDeviceStatusChange(state, info)); +} + +HWTEST_F(DmDeviceStateManagerTest, HandleDeviceStatusChange_004, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info; + DmDeviceState state = static_cast(100); + EXPECT_NO_THROW(dmDeviceStateManager->HandleDeviceStatusChange(state, info)); +} + +HWTEST_F(DmDeviceStateManagerTest, StartOffLineTimer_002, testing::ext::TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + dmDeviceStateManager->timer_ = std::shared_ptr(); + dmDeviceStateManager->StartOffLineTimer(deviceInfo); + EXPECT_NE(dmDeviceStateManager->softbusConnector_, nullptr); +} + +HWTEST_F(DmDeviceStateManagerTest, DeleteOffLineTimer_001, testing::ext::TestSize.Level0) +{ + dmDeviceStateManager->timer_ = nullptr; + std::string udidhash = "udidhash"; + dmDeviceStateManager->DeleteOffLineTimer(udidhash); + EXPECT_NE(dmDeviceStateManager->softbusConnector_, nullptr); +} + +HWTEST_F(DmDeviceStateManagerTest, DeleteOffLineTimer_002, testing::ext::TestSize.Level0) +{ + dmDeviceStateManager->timer_ = std::shared_ptr(); + std::string udidhash = "udidhash"; + dmDeviceStateManager->DeleteOffLineTimer(udidhash); + EXPECT_NE(dmDeviceStateManager->softbusConnector_, nullptr); +} + +HWTEST_F(DmDeviceStateManagerTest, DeleteTimeOutGroup_002, testing::ext::TestSize.Level0) +{ + dmDeviceStateManager->timer_ = std::shared_ptr(); + std::string udidhash = "udidhash"; + dmDeviceStateManager->DeleteOffLineTimer(udidhash); + EXPECT_NE(dmDeviceStateManager->softbusConnector_, nullptr); +} + +HWTEST_F(DmDeviceStateManagerTest, CheckIsOnline_001, testing::ext::TestSize.Level0) +{ + std::string udid = "udid"; + bool ret = dmDeviceStateManager->CheckIsOnline(udid); + EXPECT_EQ(ret, false); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/commonunittest/UTTest_permission_manager.cpp b/test/commonunittest/UTTest_permission_manager.cpp index 3d1e18fad6d7e7513889f2850060561171357b03..3b5ba5d5ee1ce75f14c84d379bab51800284c912 100644 --- a/test/commonunittest/UTTest_permission_manager.cpp +++ b/test/commonunittest/UTTest_permission_manager.cpp @@ -261,6 +261,88 @@ HWTEST_F(PermissionManagerTest, CheckProcessNameValidOnGetDeviceInfo_001, testin ret = PermissionManager::GetInstance().CheckProcessNameValidOnGetDeviceInfo(processName); ASSERT_TRUE(ret); } + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidOnAuthCode_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidOnAuthCode(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnAuthCode(processName); + ASSERT_FALSE(ret); + + processName = "CollaborationFwk"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnAuthCode(processName); + ASSERT_TRUE(ret); +} + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidOnPinHolder_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_FALSE(ret); + + processName = "CollaborationFwk"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_TRUE(ret); +} + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidOnSetDnPolicy_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_FALSE(ret); + + processName = "CollaborationFwk"; + ret = PermissionManager::GetInstance().CheckProcessNameValidOnPinHolder(processName); + ASSERT_TRUE(ret); +} + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidModifyLocalDeviceName_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidModifyLocalDeviceName(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidModifyLocalDeviceName(processName); + ASSERT_FALSE(ret); +} + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidModifyRemoteDeviceName_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidModifyRemoteDeviceName(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidModifyRemoteDeviceName(processName); + ASSERT_FALSE(ret); + + processName = "com.ohos.settings"; + ret = PermissionManager::GetInstance().CheckProcessNameValidModifyRemoteDeviceName(processName); + ASSERT_TRUE(ret); +} + +HWTEST_F(PermissionManagerTest, CheckProcessNameValidPutDeviceProfileInfoList_001, testing::ext::TestSize.Level1) +{ + std::string processName = ""; + auto ret = PermissionManager::GetInstance().CheckProcessNameValidPutDeviceProfileInfoList(processName); + ASSERT_FALSE(ret); + + processName = "processName"; + ret = PermissionManager::GetInstance().CheckProcessNameValidPutDeviceProfileInfoList(processName); + ASSERT_FALSE(ret); +} } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/softbusunittest/UTTest_softbus_listener.cpp b/test/softbusunittest/UTTest_softbus_listener.cpp index b76deb9e82f3018147987172461cbde3bece81f3..32f4799225c36664b69953f7c3adae3f2e6f843b 100644 --- a/test/softbusunittest/UTTest_softbus_listener.cpp +++ b/test/softbusunittest/UTTest_softbus_listener.cpp @@ -1517,6 +1517,53 @@ HWTEST_F(SoftbusListenerTest, GetAttrFromCustomData_001, testing::ext::TestSize. EXPECT_CALL(*softbusCacheMock_, GetUdidFromCache(_, _)).WillOnce(Return(ERR_DM_FAILED)); softbusListener->UpdateDeviceName(&nodeBasicInfo); } + +HWTEST_F(SoftbusListenerTest, DeviceTrustedChange_001, testing::ext::TestSize.Level1) +{ + DevUserInfo localDevUserInfo; + localDevUserInfo.userId = 100; + localDevUserInfo.deviceId = "localdeviceId123"; + DevUserInfo remoteDevUserInfo; + remoteDevUserInfo.userId = 200; + remoteDevUserInfo.deviceId = "remotedeviceId456"; + std::string remoteAclList = "123456"; + int32_t result = softbusListener->OnSyncLocalAclList(localDevUserInfo, remoteDevUserInfo, remoteAclList); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(SoftbusListenerTest, GetAclListHash_001, testing::ext::TestSize.Level1) +{ + DevUserInfo localDevUserInfo; + localDevUserInfo.userId = 100; + localDevUserInfo.deviceId = "localdeviceId123"; + DevUserInfo remoteDevUserInfo; + remoteDevUserInfo.userId = 200; + remoteDevUserInfo.deviceId = "remotedeviceId456"; + std::string aclList = "654321"; + int32_t result = softbusListener->OnGetAclListHash(localDevUserInfo, remoteDevUserInfo, aclList); + EXPECT_EQ(result, DM_OK); +} + +HWTEST_F(SoftbusListenerTest, UpdateDeviceName_001, testing::ext::TestSize.Level1) +{ + NodeBasicInfo *info = nullptr; + if (softbusListener == nullptr) + { + softbusListener = std::make_shared(); + } + softbusListener->UpdateDeviceName(info); + EXPECT_CALL(*deviceProfileConnectorMock_, UpdateAclDeviceName(_, _)).Times(::testing::AtLeast(1)); +} + +HWTEST_F(SoftbusListenerTest, GetAttrFromCustomData_002, testing::ext::TestSize.Level1) +{ + DmDeviceInfo dmDevInfo; + int32_t actionId = 1; + const char* jsonString = R"({})"; + cJSON *customDataJson = cJSON_Parse(jsonString); + int32_t ret = softbusListener->GetAttrFromCustomData(customDataJson, dmDevInfo, actionId); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_dm_auth_state.cpp b/test/unittest/UTTest_dm_auth_state.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e35fba88d06d80c07e5b848deef469c526b06af --- /dev/null +++ b/test/unittest/UTTest_dm_auth_state.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022-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 "dm_log.h" +#include "dm_anonymous.h" +#include "dm_constants.h" +#include "dm_auth_message_processor.h" +#include "dm_auth_context.h" +#include "dm_auth_state_machine.h" +#include "UTTest_dm_auth_state.h" + +using namespace testing; +namespace OHOS { +namespace DistributedHardware { + +void DmAuthMessageProcessorTest::SetUpTestCase() +{ +} + +void DmAuthMessageProcessorTest::TearDownTestCase() +{ +} + +void DmAuthMessageProcessorTest::SetUp() +{ +} + +void DmAuthMessageProcessorTest::TearDown() +{ +} + +HWTEST_F(DmAuthStateTest, GetTaskTimeout_001, testing::ext::TestSize.Level1) +{ + const char *taskName = "taskName"; + int32_t taskTimeOut = 6; + std::shared_ptr context = std::make_shared(); + context->authType = AUTH_TYPE_UNKNOW; + std::shared_ptr state = std::make_shared(); + EXPECT_EQ(state->GetTaskTimeout(context, taskName, taskTimeOut), taskTimeOut); +} + +HWTEST_F(DmAuthStateTest, GetTaskTimeout_002, testing::ext::TestSize.Level1) +{ + const char *taskName = "deviceManagerTimer:authenticate"; + int32_t taskTimeOut = 6; + std::shared_ptr context = std::make_shared(); + context->authType = AUTH_TYPE_NFC; + std::shared_ptr state = std::make_shared(); + EXPECT_EQ(state->GetTaskTimeout(context, taskName, taskTimeOut), 20); +} + +HWTEST_F(DmAuthStateTest, GetTaskTimeout_003, testing::ext::TestSize.Level1) +{ + const char *taskName = "test"; + int32_t taskTimeOut = 6; + std::shared_ptr context = std::make_shared(); + context->authType = AUTH_TYPE_NFC; + std::shared_ptr state = std::make_shared(); + EXPECT_EQ(state->GetTaskTimeout(context, taskName, taskTimeOut), taskTimeOut); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_dm_auth_state.h b/test/unittest/UTTest_dm_auth_state.h new file mode 100644 index 0000000000000000000000000000000000000000..c584458f7ec46fcb7e8da898226c3bdb62e9036a --- /dev/null +++ b/test/unittest/UTTest_dm_auth_state.h @@ -0,0 +1,36 @@ +/* + * 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_DM_AUTH_STATE_TEST_H +#define OHOS_DM_AUTH_STATE_TEST_H + +#include +#include +#include +#include "json_object.h" + +namespace OHOS { +namespace DistributedHardware { +class DmAuthStateTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_AUTH_STATE_TEST_H + \ No newline at end of file diff --git a/test/unittest/UTTest_dm_pin_holder.cpp b/test/unittest/UTTest_dm_pin_holder.cpp index c5c0a8f116183c23e9b59154fe537a599330443c..ae5b068996acf4b686ddd60b9d68350610cf1292 100644 --- a/test/unittest/UTTest_dm_pin_holder.cpp +++ b/test/unittest/UTTest_dm_pin_holder.cpp @@ -1118,6 +1118,15 @@ HWTEST_F(DmPinHolderTest, OnSessionOpened_105, testing::ext::TestSize.Level1) EXPECT_EQ(ret, ERR_DM_FAILED); } +HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener = std::make_shared(); + std::shared_ptr pinHolder = std::make_shared(listener); + std::string message = R"({"TAG_REPLY" : 0})"; + pinHolder->ProcessDestroyResMsg(message); + ASSERT_NE(pinHolder->timer_, nullptr); +} + HWTEST_F(DmPinHolderTest, CreatePinholder_109, testing::ext::TestSize.Level1) { std::string packName = "com.ohos.dmtest"; @@ -1181,7 +1190,7 @@ HWTEST_F(DmPinHolderTest, DestroyPinHolder_107, testing::ext::TestSize.Level1) ASSERT_EQ(ret, DM_OK); } - HWTEST_F(DmPinHolderTest, DestroyPinHolder_108, testing::ext::TestSize.Level1) +HWTEST_F(DmPinHolderTest, DestroyPinHolder_108, testing::ext::TestSize.Level1) { std::string packName = "com.ohos.dmtest"; PeerTargetId targetId = { @@ -1225,7 +1234,8 @@ HWTEST_F(DmPinHolderTest, DestroyPinHolder_109, testing::ext::TestSize.Level1) int32_t ret = pinHolder->DestroyPinHolder(packName, targetId, pinType, payload); ASSERT_NE(ret, DM_OK); } - HWTEST_F(DmPinHolderTest, ProcessCloseSessionMsg_101, testing::ext::TestSize.Level1) + +HWTEST_F(DmPinHolderTest, ProcessCloseSessionMsg_101, testing::ext::TestSize.Level1) { std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1244,7 +1254,8 @@ HWTEST_F(DmPinHolderTest, ProcessCloseSessionMsg_102, testing::ext::TestSize.Lev pinHolder->ProcessCloseSessionMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } - HWTEST_F(DmPinHolderTest, ProcessDestroyMsg_106, testing::ext::TestSize.Level1) + +HWTEST_F(DmPinHolderTest, ProcessDestroyMsg_106, testing::ext::TestSize.Level1) { std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1256,7 +1267,8 @@ HWTEST_F(DmPinHolderTest, ProcessCloseSessionMsg_102, testing::ext::TestSize.Lev pinHolder->ProcessDestroyMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } - HWTEST_F(DmPinHolderTest, CloseSession_102, testing::ext::TestSize.Level1) + +HWTEST_F(DmPinHolderTest, CloseSession_102, testing::ext::TestSize.Level1) { std::shared_ptr listener = std::make_shared(); std::shared_ptr pinHolder = std::make_shared(listener); @@ -1285,6 +1297,25 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_101, testing::ext::TestSize.Level ASSERT_NE(pinHolder->timer_, nullptr); } +HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener = nullptr; + std::shared_ptr pinHolder = std::make_shared(listener); + std::string message = R"({"TAG_REPLY" : 0})"; + pinHolder->ProcessDestroyResMsg(message); + ASSERT_NE(pinHolder->timer_, nullptr); +} + +HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener = std::make_shared(); + std::shared_ptr pinHolder = std::make_shared(listener); + std::string message = R"({"REPLY" : 0})"; + pinHolder->session_ = nullptr; + pinHolder->ProcessDestroyResMsg(message); + ASSERT_NE(pinHolder->timer_, nullptr); +} + HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_102, testing::ext::TestSize.Level1) { JsonObject jsonObject; @@ -1308,6 +1339,26 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_103, testing::ext::TestSize.Level ASSERT_NE(pinHolder->timer_, nullptr); } +HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener = std::make_shared(); + std::shared_ptr pinHolder = std::make_shared(listener); + std::string message = R"({"REPLY" : 100})"; + pinHolder->session_ = nullptr; + pinHolder->ProcessDestroyResMsg(message); + ASSERT_NE(pinHolder->timer_, nullptr); +} + +HWTEST_F(DmPinHolderTest, GetPeerDeviceId_102, testing::ext::TestSize.Level1) +{ + std::shared_ptr listener = std::make_shared(); + std::shared_ptr pinHolder = std::make_shared(listener); + int32_t sessionId = 0; + std::string udidHash; + pinHolder->GetPeerDeviceId(sessionId, udidHash); + ASSERT_NE(pinHolder->timer_, nullptr); +} + HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_104, testing::ext::TestSize.Level1) { JsonObject jsonObject; @@ -1319,7 +1370,8 @@ HWTEST_F(DmPinHolderTest, ProcessDestroyResMsg_104, testing::ext::TestSize.Level pinHolder->ProcessDestroyResMsg(message); ASSERT_NE(pinHolder->timer_, nullptr); } - HWTEST_F(DmPinHolderTest, UnRegisterPinHolderCallback_101, testing::ext::TestSize.Level1) + +HWTEST_F(DmPinHolderTest, UnRegisterPinHolderCallback_101, testing::ext::TestSize.Level1) { std::string packName = "com.ohos.dmtest"; std::shared_ptr listener = std::make_shared(); diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 398e4ef0774dfc1f3a2990e411d0498c7635ddcb..e4bc8635c7b2da5a9bebeff93b47f9ff5d2e2064 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1247,6 +1247,121 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_012, testing::ext::TestSiz EXPECT_EQ(result, false); } +HWTEST_F(ReleationShipSyncMgrTest, ToStopUserPayLoad_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + msgObj.userId = 0x12345678; + uint8_t *msg = nullptr; + uint32_t len = 0; + msgObj.ToStopUserPayLoad(msg, len); + ASSERT_EQ(len, 2); + EXPECT_NE(msg, nullptr); + delete[] msg; +} + +HWTEST_F(ReleationShipSyncMgrTest, ToStopUserPayLoad_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + msgObj.userId = 0xFFFFFFFF; + uint8_t *msg = nullptr; + uint32_t len = 0; + msgObj.ToStopUserPayLoad(msg, len); + for (int i = 0; i < 2; i++) + { + EXPECT_EQ(msg[i], 255); + } + delete[] msg; +} + +HWTEST_F(ReleationShipSyncMgrTest, FromStopUserPayLoad_001, testing::ext::TestSize.Level1) +{ + const char *jsonString = "[120, 86, 52, 18]"; + cJSON *payloadJson = cJSON_Parse(jsonString); + RelationShipChangeMsg msgObj; + bool result = msgObj.FromStopUserPayLoad(payloadJson); + ASSERT_TRUE(result); + cJSON_Delete(payloadJson); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromStopUserPayLoad_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + bool result = msgObj.FromStopUserPayLoad(NULL); + ASSERT_FALSE(result); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromStopUserPayLoad_003, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + const char *jsonString = "[120]"; + cJSON *payloadJson = cJSON_Parse(jsonString); + bool result = msgObj.FromStopUserPayLoad(payloadJson); + ASSERT_FALSE(result); + cJSON_Delete(payloadJson); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromJson_001, testing::ext::TestSize.Level1) +{ + const std::string invalidJson = R"({ + "payload": ["value1", "value2"], + "peerUdid": "peer-udid-12345" + })"; + + RelationShipChangeMsg msgObj; + bool result = msgObj.FromJson(invalidJson); + + EXPECT_FALSE(result); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromJson_002, testing::ext::TestSize.Level1) +{ + const std::string invalidJson = R"({ + "type": 1, + "peerUdid": "peer-udid-12345" + })"; + + RelationShipChangeMsg msgObj; + bool result = msgObj.FromJson(invalidJson); + + EXPECT_FALSE(result); +} + +HWTEST_F(ReleationShipSyncMgrTest, FromJson_003, testing::ext::TestSize.Level1) +{ + const std::string invalidJson = R"({ + "type": 1, + "payload": ["value1", "value2"] + })"; + + RelationShipChangeMsg msgObj; + bool result = msgObj.FromJson(invalidJson); + + EXPECT_FALSE(result); +} + +HWTEST_F(ReleationShipSyncMgrTest, ToJson_001, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + std::string jsonString = msgObj.ToJson(); + EXPECT_TRUE(jsonString.empty()); +} + +HWTEST_F(ReleationShipSyncMgrTest, ToJson_002, testing::ext::TestSize.Level1) +{ + RelationShipChangeMsg msgObj; + msgObj.type = RelationShipChangeType::ACCOUNT_LOGOUT; + msgObj.userId = 1234567890; + msgObj.accountId = "account_123"; + msgObj.tokenId = 67890; + msgObj.peerUdids = {"udid1", "udid2"}; + msgObj.peerUdid = "peer_udid"; + msgObj.accountName = "test_account"; + msgObj.syncUserIdFlag = true; + + std::string jsonString = msgObj.ToJson(); + EXPECT_FALSE(jsonString.empty()); +} + HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_013, testing::ext::TestSize.Level1) { RelationShipChangeMsg msg; @@ -1459,7 +1574,6 @@ HWTEST_F(ReleationShipSyncMgrTest, FromAppUninstallPayLoad_001, testing::ext::Te result = msg.FromAppUninstallPayLoad(jsonObject); ASSERT_EQ(result, false); } - } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/mock/deviceprofile_connector_mock.cpp b/test/unittest/mock/deviceprofile_connector_mock.cpp index 4f82813a289ff08bcde1d6432d874c10a940a3a5..48f9b6b8908ea03fdbf96657765f746502d870af 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.cpp +++ b/test/unittest/mock/deviceprofile_connector_mock.cpp @@ -161,6 +161,10 @@ std::map DeviceProfileConnector::GetDeviceIdAndBindLevel(s return DmDeviceProfileConnector::dmDeviceProfileConnector->GetDeviceIdAndBindLevel(userIds, localUdid); } +int32_t DeviceProfileConnector::UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName) +{ + return DmDeviceProfileConnector::dmDeviceProfileConnector->UpdateAclDeviceName(udid, newDeviceName); +} void DeviceProfileConnector::DeleteAccessControlById(int64_t accessControlId) { return DmDeviceProfileConnector::dmDeviceProfileConnector->DeleteAccessControlById(accessControlId); diff --git a/test/unittest/mock/deviceprofile_connector_mock.h b/test/unittest/mock/deviceprofile_connector_mock.h index 84d5c9d04804bd05482ac71f3d149a58a32ab81a..114fe46f629a6636cd1f341e3d4075227d9f819d 100644 --- a/test/unittest/mock/deviceprofile_connector_mock.h +++ b/test/unittest/mock/deviceprofile_connector_mock.h @@ -65,6 +65,7 @@ public: const std::vector &foregroundUserIds, const std::vector &backgroundUserIds) = 0; virtual std::map GetDeviceIdAndBindLevel(std::vector userIds, const std::string &localUdid) = 0; + virtual int32_t UpdateAclDeviceName(const std::string &udid, const std::string &newDeviceName) = 0; virtual void DeleteAccessControlById(int64_t& accessControlId) = 0; virtual std::vector GetProcessInfoFromAclByUserId(const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId) = 0; @@ -119,6 +120,7 @@ public: (const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId)); MOCK_METHOD(std::vector, GetAccessControlProfile, ()); MOCK_METHOD(std::vector, GetAllAclIncludeLnnAcl, ()); + MOCK_METHOD(int32_t, UpdateAclDeviceName, (const std::string &, const std::string &)); MOCK_METHOD(std::vector, GetDeviceIdAndUdidListByTokenId, (const std::vector &userIds, const std::string &localUdid, int32_t tokenId)); MOCK_METHOD(void, CacheAcerAclId, (const DistributedDeviceProfile::AccessControlProfile &profile, diff --git a/test/unittest/mock/dm_softbus_cache_mock.cpp b/test/unittest/mock/dm_softbus_cache_mock.cpp index 322fa94994ab7bd5ef99b42c9e90bac8701bf7ad..254d5cde690552dfb33946685b4deccd7e86914a 100644 --- a/test/unittest/mock/dm_softbus_cache_mock.cpp +++ b/test/unittest/mock/dm_softbus_cache_mock.cpp @@ -59,5 +59,10 @@ int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::strin { return DmSoftbusCache::dmSoftbusCache->GetDeviceNameFromCache(udid, deviceName); } + +void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo) +{ + DmSoftbusCache::dmSoftbusCache->ChangeDeviceInfo(deviceInfo); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/mock/dm_softbus_cache_mock.h b/test/unittest/mock/dm_softbus_cache_mock.h index 1a519e53d7e4f1512b4f70a93fc75ba022b695b8..f82e1373e426fa4511ab80ae0a215cacecc7e1b3 100644 --- a/test/unittest/mock/dm_softbus_cache_mock.h +++ b/test/unittest/mock/dm_softbus_cache_mock.h @@ -34,6 +34,7 @@ public: virtual bool CheckIsOnline(const std::string &deviceId) = 0; virtual int32_t GetDeviceInfoFromCache(std::vector &deviceInfoList) = 0; virtual int32_t GetDeviceNameFromCache(const std::string &udid, std::string &deviceName) = 0; + virtual void ChangeDeviceInfo(const DmDeviceInfo deviceInfo) = 0; public: static inline std::shared_ptr dmSoftbusCache = nullptr; }; @@ -48,6 +49,7 @@ public: MOCK_METHOD(bool, CheckIsOnline, (const std::string &)); MOCK_METHOD(int32_t, GetDeviceInfoFromCache, (std::vector &)); MOCK_METHOD(int32_t, GetDeviceNameFromCache, (const std::string &, std::string &)); + MOCK_METHOD(void, ChangeDeviceInfo, (const DmDeviceInfo deviceInfo)); }; } }