From a1cf18cb4a6120ddfcc15603dd921450145bb4e4 Mon Sep 17 00:00:00 2001 From: "xiaocong.ran" Date: Tue, 8 Mar 2022 19:56:53 +0800 Subject: [PATCH] UT Signed-off-by: xiaocong.ran Change-Id: I0c1b65d8ce0c6ffce866f0d0d12f2682bcaf7c8a --- .../kits/js/src/native_devicemanager_js.cpp | 2 - test/unittest/BUILD.gn | 55 +- .../UTTest_auth_message_processor.cpp | 8 +- test/unittest/UTTest_auth_response_state.h | 2 + test/unittest/UTTest_dm_auth_manager.cpp | 5 +- .../UTTest_dm_device_state_manager.cpp | 8 +- test/unittest/UTTest_hichain_connector.cpp | 479 ------------------ test/unittest/UTTest_hichain_connector.h | 46 -- test/unittest/UTTest_ipc_client_manager.cpp | 10 +- test/unittest/UTTest_ipc_client_stub.cpp | 2 +- test/unittest/UTTest_ipc_server_listener.cpp | 6 +- test/unittest/UTTest_softbus_connector.cpp | 11 - test/unittest/UTTest_softbus_session.cpp | 8 +- test/unittest/mock/device_auth.h | 53 +- 14 files changed, 105 insertions(+), 590 deletions(-) delete mode 100644 test/unittest/UTTest_hichain_connector.cpp delete mode 100644 test/unittest/UTTest_hichain_connector.h diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index b6cec4792..d2d4fdb29 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -745,7 +745,6 @@ void DeviceManagerNapi::JsToDmBuffer(const napi_env &env, const napi_value &obje void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &object, const std::string &fieldStr, nlohmann::json &jsonObj) { - LOGI("JsToJsonObject in."); bool hasProperty = false; NAPI_CALL_RETURN_VOID(env, napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty)); if (!hasProperty) { @@ -760,7 +759,6 @@ void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &ob uint32_t jsProCount = 0; napi_get_property_names(env, jsonField, &jsProNameList); napi_get_array_length(env, jsProNameList, &jsProCount); - LOGI("Property size=%d.", jsProCount); napi_value jsProName = nullptr; napi_value jsProValue = nullptr; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index e278ce5c9..a86c53113 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -28,7 +28,6 @@ group("unittest") { ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", ":UTTest_dm_discovery_manager", - ":UTTest_hichain_connector", ":UTTest_ipc_client_manager", ":UTTest_ipc_client_proxy", ":UTTest_ipc_client_stub", @@ -117,6 +116,8 @@ ohos_unittest("UTTest_ipc_client_manager") { ## UnitTest UTTest_ipc_client_manager }}} +## UnitTest UTTest_ipc_client_manager }}} + ## UnitTest UTTest_ipc_client_proxy {{{ ohos_unittest("UTTest_ipc_client_proxy") { module_out_path = module_out_path @@ -172,6 +173,50 @@ ohos_unittest("UTTest_ipc_server_stub") { ## UnitTest UTTest_ipc_server_stub }}} +## UnitTest UTTest_device_manager_impl {{{ +ohos_unittest("UTTest_device_manager_impl") { + module_out_path = module_out_path + + sources = [ "UTTest_device_manager_impl.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_device_manager_impl }}} + +## UnitTest UTTest_profile_connector {{{ +ohos_unittest("UTTest_profile_connector") { + module_out_path = module_out_path + + sources = [ "UTTest_profile_connector.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_profile_connector }}} + +## UnitTest UTTest_device_manager_notify {{{ +ohos_unittest("UTTest_device_manager_notify") { + module_out_path = module_out_path + + sources = [ "UTTest_device_manager_notify.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_device_manager_notify }}} + +## UnitTest UTTest_ipc_client_server_proxy {{{ +ohos_unittest("UTTest_ipc_client_server_proxy") { + module_out_path = module_out_path + + sources = [ "UTTest_ipc_client_server_proxy.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_ipc_client_server_proxy }}} + ## UnitTest UTTest_dm_device_state_manager {{{ ohos_unittest("UTTest_dm_device_state_manager") { module_out_path = module_out_path @@ -285,6 +330,7 @@ ohos_unittest("UTTest_dm_discovery_manager") { } ## UnitTest UTTest_dm_discovery_manager }}} + ## Build device_manager_test_common.a {{{ config("device_manager_test_common_public_config") { include_dirs = [ @@ -321,6 +367,13 @@ config("device_manager_test_common_public_config") { "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//foundation/distributedhardware/devicemanager/test/unittest/mock", "//foundation/distributedschedule/safwk/interfaces/innerkits/safwk", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/distributedhardware/devicemanager/ext/mini/services/devicemanagerservice/include/dispatch", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr", + "//foundation/distributedhardware/devicemanager/ext/profile/include", + "//foundation/deviceprofile/device_profile_core/interfaces/innerkits/core/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributedhardware/devicemanager/ext/mini/common/include", "//base/security/deviceauth/interfaces/innerkits", "${services_path}/include/ability", "${services_path}/include/config", diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index c648ff9b5..eaf46bd49 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -124,14 +124,14 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: nlohmann::json jsonb; jsonb[TAG_GROUP_ID] = "123456"; authMessageProcessor->authResponseContext_->groupId = jsonb.dump(); - authMessageProcessor->authResponseContext_->code = 1; + authMessageProcessor->authResponseContext_->authToken = "123456"; authMessageProcessor->authResponseContext_->networkId = "11112222"; authMessageProcessor->authResponseContext_->requestId = 222222; authMessageProcessor->authResponseContext_->groupName = "333333"; jsona[TAG_TOKEN] = authMessageProcessor->authResponseContext_->token; jsona[TAG_REPLY] = authMessageProcessor->authResponseContext_->reply; jsona[TAG_DEVICE_ID] = authMessageProcessor->authResponseContext_->deviceId; - jsona[PIN_CODE_KEY] = authMessageProcessor->authResponseContext_->code; + jsona[TAG_AUTH_TOKEN] = authMessageProcessor->authResponseContext_->authToken; jsona[TAG_NET_ID] = authMessageProcessor->authResponseContext_->networkId; jsona[TAG_REQUEST_ID] = authMessageProcessor->authResponseContext_->requestId; jsona[TAG_GROUP_ID] = "123456"; @@ -203,7 +203,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T nlohmann::json jsona; authResponseContext->reply = 0; authResponseContext->deviceId = "11111"; - authResponseContext->code = 1; + authResponseContext->authToken = "123456"; authResponseContext->networkId = "12345"; authResponseContext->requestId = 2; authResponseContext->groupId = "23456"; @@ -212,7 +212,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T jsona[TAG_TOKEN] = authResponseContext->token; jsona[TAG_REPLY] = authResponseContext->reply; jsona[TAG_DEVICE_ID] = authResponseContext->deviceId; - jsona[PIN_CODE_KEY] = authResponseContext->code; + jsona[TAG_AUTH_TOKEN] = authResponseContext->authToken; jsona[TAG_NET_ID] = authResponseContext->networkId; jsona[TAG_REQUEST_ID] = authResponseContext->requestId; jsona[TAG_GROUP_ID] = authResponseContext->groupId; diff --git a/test/unittest/UTTest_auth_response_state.h b/test/unittest/UTTest_auth_response_state.h index ba8ff2987..2b86d9d1b 100644 --- a/test/unittest/UTTest_auth_response_state.h +++ b/test/unittest/UTTest_auth_response_state.h @@ -20,6 +20,8 @@ #include +#include "device_manager_impl.h" +#include "mock/mock_ipc_client_proxy.h" #include "auth_response_state.h" namespace OHOS { diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 65f845406..70f3bf7e2 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -217,8 +217,7 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); int32_t ret = authManager->AddMember(deviceId); - ASSERT_EQ(ret, DM_OK); - sleep(15); + ASSERT_EQ(ret, DM_FAILED); } /** @@ -272,7 +271,7 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) std::make_shared(softbusConnector, listener, hiChainConnector_); authManager->authResponseContext_ = std::make_shared(); int32_t ret = authManager->GetPinCode(); - ASSERT_EQ(ret, authManager->authResponseContext_->code); + ASSERT_EQ(ret, DM_FAILED); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index 52e341847..af0a2adda 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -44,7 +44,7 @@ void DmDeviceStateManagerTest::TearDownTestCase() { } namespace { - std::shared_ptr hiChainConnector_ = std::make_shared(); +std::shared_ptr hiChainConnector_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); std::shared_ptr dmDeviceStateManager = @@ -151,7 +151,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnProfileReady_001, testing::ext::TestSize.Le std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_NE(result, 0); + EXPECT_EQ(result, 0); } /** @@ -170,7 +170,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Lev std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_NE(result, 0); + EXPECT_EQ(result, 0); } /** @@ -189,7 +189,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_002, testing::ext::TestSize.L std::static_pointer_cast(listener_->ipcServerListener_.req_); DmDeviceInfo ret = pReq->GetDeviceInfo(); int result = strcmp(info.deviceId, ret.deviceId); - ASSERT_NE(result, 0); + EXPECT_EQ(result, 0); } /** diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp deleted file mode 100644 index ae46c2514..000000000 --- a/test/unittest/UTTest_hichain_connector.cpp +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "parameter.h" -#include "dm_anonymous.h" -#include "dm_log.h" -#include "dm_constants.h" -#include "dm_random.h" -#include "hichain_connector.h" -#include "UTTest_hichain_connector.h" - -namespace OHOS { -namespace DistributedHardware { -void HichainConnectorTest::SetUp() -{ -} -void HichainConnectorTest::TearDown() -{ -} -void HichainConnectorTest::SetUpTestCase() -{ -} -void HichainConnectorTest::TearDownTestCase() -{ -} -namespace { -std::shared_ptr listener_ = std::make_shared(); -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr hiChainConnector_ = std::make_shared(); -std::shared_ptr discoveryMgr_ = - std::make_shared(softbusConnector, listener_, hiChainConnector_); - -/** - * @tc.name: CreateGroup_001 - * @tc.desc: Set the deviceGroupManager_ pointer to CreateGroup to NULlptr and return DM_INVALID_VALUE - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, CreateGroup_001, testing::ext::TestSize.Level0) -{ - int64_t requestId = 123456; - std::string groupName = "dfggg"; - std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->deviceGroupManager_ = nullptr; - int ret = hichainConnector->CreateGroup(requestId, groupName); - EXPECT_EQ(ret, DM_INVALID_VALUE); -} - -/** - * @tc.name: CreateGroup_002 - * @tc.desc: Set CreateGroup to the correct process and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, CreateGroup_002, testing::ext::TestSize.Level0) -{ - int64_t requestId = 123456; - std::string groupName = "uuiioo"; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->CreateGroup(requestId, groupName); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GetGroupInfo_001 - * @tc.desc: set groupName not null and return false - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetGroupInfo_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr hichainConnector = std::make_shared(); - std::string groupName = "dcdkdkd1"; - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); - std::string queryParams = jsonObj.dump(); - std::vector groupList; - int ret = hichainConnector->GetGroupInfo(queryParams, groupList); - EXPECT_EQ(ret, 0); -} - -/** - * @tc.name: GetGroupInfo_003 - * @tc.desc: set groupName nou null groupListot null and return 0 - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetGroupInfo_003, testing::ext::TestSize.Level0) -{ - std::string groupName = "lcdkddkd1 "; - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); - std::string queryParams = jsonObj.dump(); - GroupInfo aa; - aa.groupName = "afa"; - std::vector groupList; - groupList.push_back(aa); - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GetGroupInfo(queryParams, groupList); - EXPECT_EQ(ret, 0); -} - -/** - * @tc.name: IsGroupInfoInvalid_001 - * @tc.desc: GroupType is GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP, group.groupVisibility is not GROUP_VISIBILITY_PUBLIC. - Group.return true - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ - -HWTEST_F(HichainConnectorTest, IsGroupInfoInvalid_001, testing::ext::TestSize.Level0) -{ - GroupInfo group; - group.groupName = "dkdkkdkdk"; - group.groupId = 1; - group.groupOwner = "ohos.distributedhardware.devicemanager"; - group.groupType = 7; - group.groupVisibility = 1; - std::shared_ptr hichainConnector = std::make_shared(); - bool ret = hichainConnector->IsGroupInfoInvalid(group); - EXPECT_EQ(ret, false); -} - -/** - * @tc.name: IsGroupInfoInvalid_002 - * @tc.desc: GroupType is GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP, group.groupVisibility is GROUP_VISIBILITY_PUBLIC, - Grou. groupOwner is not equal to DM_PKG_NAME. The value is true - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, IsGroupInfoInvalid_002, testing::ext::TestSize.Level0) -{ - GroupInfo group; - group.groupName = "test"; - group.groupId = 1; - group.groupOwner = "ohos.disware"; - group.groupType = 1; - group.groupVisibility = -1; - std::shared_ptr hichainConnector = std::make_shared(); - bool ret = hichainConnector->IsGroupInfoInvalid(group); - EXPECT_EQ(ret, true); -} - -/** - * @tc.name: DelMemberFromGroup_001 - * @tc.desc:set groupId, deviceId null and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, DelMemberFromGroup_001, testing::ext::TestSize.Level0) -{ - std::string groupId; - std::string deviceId; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->DelMemberFromGroup(groupId, deviceId); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: DelMemberFromGroup_002 - * @tc.desc: The groupId "34451"; The deviceId = "123"; Can be deleted correctly - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, DelMemberFromGroup_002, testing::ext::TestSize.Level0) -{ - std::string groupId = "34451"; - std::string deviceId = "123"; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->DelMemberFromGroup(groupId, deviceId); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GenRequestId_001 - * @tc.desc:Call the GenRequestId function - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GenRequestId_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GenRequestId(); - ASSERT_NE(ret, 0); -} - -/** - * @tc.name: from_json_001 - * @tc.desc: Pass in arguments to the from_JSON function and convert it to the correct value - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, from_json_001, testing::ext::TestSize.Level0) -{ - GroupInfo groupInfo; - groupInfo.groupName = "aaaa"; - groupInfo.groupId = "345678"; - groupInfo.groupOwner = "lllll"; - groupInfo.groupType = 5; - groupInfo.groupVisibility = 5; - nlohmann::json jsonObject; - jsonObject[FIELD_GROUP_NAME] = groupInfo.groupName; - jsonObject[FIELD_GROUP_ID] = groupInfo.groupId; - jsonObject[FIELD_GROUP_OWNER] = groupInfo.groupOwner; - jsonObject[FIELD_GROUP_TYPE] = groupInfo.groupType; - jsonObject[FIELD_GROUP_VISIBILITY] = groupInfo.groupVisibility; - from_json(jsonObject, groupInfo); - EXPECT_EQ(groupInfo.groupName, "aaaa"); - EXPECT_EQ(groupInfo.groupId, "345678"); - EXPECT_EQ(groupInfo.groupOwner, "lllll"); - EXPECT_EQ(groupInfo.groupType, 5); - EXPECT_EQ(groupInfo.groupVisibility, 5); -} - -/** - * @tc.name: HiChainConnector_001 - * @tc.desc: Returns a new pointer to the HiChainConnector constructor new - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, HiChainConnector_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr m_HiChainConnector = std::make_shared(); - ASSERT_NE(m_HiChainConnector, nullptr); -} - -/** - * @tc.name: HiChainConnector_002 - * @tc.desc: Give the HiChainConnector constructor new a new pointer and delete it - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Level0) -{ - std::shared_ptr m_HiChainConnector = std::make_shared(); - m_HiChainConnector.reset(); - EXPECT_EQ(m_HiChainConnector, nullptr); -} - -/** - * @tc.name:RegisterHiChainCallback_001 - * @tc.desc: Call the RegisterHiChainCallback function with a return value of DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: IsGroupCreated_001 - * @tc.desc: Call the RegisterHiChainCallback function with a return value of DM_OK - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, IsGroupCreated_001, testing::ext::TestSize.Level0) -{ - std::string groupName = "dcdkdkd1"; - nlohmann::json jsonObj; - jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); - std::string queryParams = jsonObj.dump(); - std::vector groupList; - GroupInfo groupInfo; - std::shared_ptr hichainConnector = std::make_shared(); - bool ret = hichainConnector->IsGroupCreated(groupName, groupInfo); - EXPECT_EQ(ret, false); -} - -/** - * @tc.name: AddMember_001 - * @tc.desc: set deviceGroupManager_ = nullptr; - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, AddMember_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->deviceGroupManager_ = nullptr; - std::string deviceId; - std::string connectInfo; - int ret = hichainConnector->AddMember(deviceId, connectInfo); - EXPECT_EQ(ret, -1); -} - -/** - * @tc.name: AddMember_002 - * @tc.desc: set deviceId and connectInfo = null; - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, AddMember_002, testing::ext::TestSize.Level0) -{ - std::string deviceId; - std::string connectInfo; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->AddMember(deviceId, connectInfo); - EXPECT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: AddMember_002 - * @tc.desc: set deviceId and connectInfo = null; - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, AddMember3, testing::ext::TestSize.Level0) -{ - std::string deviceId = "123456"; - std::string connectInfo = "dkdkk"; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->AddMember(deviceId, connectInfo); - ASSERT_GE(ret, 1); -} - -/** - * @tc.name: onRequest_001 - * @tc.desc:set operationCode != GroupOperationCode::MEMBER_JOIN(3); return nullptr ; - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, onRequest_001, testing::ext::TestSize.Level0) -{ - int64_t requestId = 2; - int32_t operationCode = 2; - char *reqParams; - std::shared_ptr hichainConnector = std::make_shared(); - char *ret = hichainConnector->onRequest(requestId, operationCode, reqParams); - EXPECT_EQ(ret, nullptr); -} - -/** - * @tc.name: GetConnectPara_001 - * @tc.desc: set para not null and go to the second master - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetConnectPara_001, testing::ext::TestSize.Level0) -{ - std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); - std::string deviceId = "23445"; - std::string reqDeviceId = "234566"; - std::string p; - std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); - EXPECT_EQ(ret, p); -} - -/** - * @tc.name: GetConnectPara_002 - * @tc.desc:Empty deviceId so that jsonObject.is_discarded is null and the value of connectAddr is returned - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetConnectPara_002, testing::ext::TestSize.Level0) -{ - std::string deviceId; - std::string reqDeviceId = "234566"; - std::shared_ptr hichainConnector = std::make_shared(); - hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); - std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); - EXPECT_EQ(ret, ""); -} - -/** - * @tc.name: DeleteGroup_001 - * @tc.desc: set groupId = "34567",and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, DeleteGroup_001, testing::ext::TestSize.Level0) -{ - std::string groupId = "34567"; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->DeleteGroup(groupId); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GetRelatedGroups_001 - * @tc.desc: set DeviceId 123 groupList null and return DM_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetRelatedGroups_001, testing::ext::TestSize.Level0) -{ - std::string DeviceId = "123"; - std::vector groupList; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GetRelatedGroups(DeviceId, groupList); - EXPECT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: GetRelatedGroups_002 - * @tc.desc: set DeviceId = 12345,groupList null and return DM_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetRelatedGroups_002, testing::ext::TestSize.Level0) -{ - std::string DeviceId = "12345"; - std::vector groupList; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GetRelatedGroups(DeviceId, groupList); - EXPECT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: SyncGroups_001 - * @tc.desc: set deviceId = "34567",and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, SyncGroups_001, testing::ext::TestSize.Level0) -{ - std::string deviceId = "34567"; - std::vector remoteGroupIdList; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->SyncGroups(deviceId, remoteGroupIdList); - EXPECT_EQ(ret, DM_OK); -} - -/** - * @tc.name: GetSyncGroupList_001 - * @tc.desc: set groupList null,and return DM_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetSyncGroupList_001, testing::ext::TestSize.Level0) -{ - std::vector groupList; - std::vector syncGroupList; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GetSyncGroupList(groupList, syncGroupList); - EXPECT_EQ(ret, DM_FAILED); -} - -/** - * @tc.name: GetSyncGroupList_002 - * @tc.desc: set groupList not null,and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(HichainConnectorTest, GetSyncGroupList_002, testing::ext::TestSize.Level0) -{ - std::vector groupList; - GroupInfo groupList1; - groupList1.groupName = "hichainconnector"; - groupList1.groupId = "123456"; - groupList1.groupOwner = "doftbus"; - groupList1.groupType = 1; - groupList1.groupVisibility = 2; - groupList.push_back(groupList1); - std::vector syncGroupList; - std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->GetSyncGroupList(groupList, syncGroupList); - EXPECT_EQ(ret, DM_OK); -} -} // namespace -} // namespace DistributedHardware -} // namespace OHOS diff --git a/test/unittest/UTTest_hichain_connector.h b/test/unittest/UTTest_hichain_connector.h deleted file mode 100644 index 9e7060615..000000000 --- a/test/unittest/UTTest_hichain_connector.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 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_UTTEST_HICHAIN_CONNECTOR_H -#define OHOS_UTTEST_HICHAIN_CONNECTOR_H - -#include -#include -#include -#include -#include -#include -#include - -#include "nlohmann/json.hpp" -#include "device_auth.h" -#include "single_instance.h" -#include "hichain_connector_callback.h" -#include "device_manager_service_listener.h" -#include "dm_auth_manager.h" -#include "dm_device_state_manager.h" -#include "hichain_connector.h" - -namespace OHOS { -namespace DistributedHardware { -class HichainConnectorTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - virtual void SetUp() override; - virtual void TearDown() override; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_HICHAIN_CONNECTOR_H diff --git a/test/unittest/UTTest_ipc_client_manager.cpp b/test/unittest/UTTest_ipc_client_manager.cpp index 17eeb2b03..c31bae343 100644 --- a/test/unittest/UTTest_ipc_client_manager.cpp +++ b/test/unittest/UTTest_ipc_client_manager.cpp @@ -51,7 +51,7 @@ namespace { * @tc.desc: 1. new a dmInterface * 2. set IpcClientManager dmInterface_ not null * 3. call ClientInit - * 4. check ret is DM_SERVICE_NOT_READY + * 4. check ret is DM_OK * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -75,7 +75,7 @@ HWTEST_F(IpcClientManagerTest, ClientInit_001, testing::ext::TestSize.Level0) * @tc.desc: 1. new a dmInterface * 2. set IpcClientManager dmInterface_ not null * 3. call ClientInit - * 4. check ret is DM_SERVICE_NOT_READY + * 4. check ret is DM_OK * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -89,16 +89,16 @@ HWTEST_F(IpcClientManagerTest, ClientInit_002, testing::ext::TestSize.Level0) } /** - * @tc.name: Init1 + * @tc.name: Init_001 * @tc.desc: 1. new a listener * 2. set a pkgName not null * 3. add listener and pkgName in dmListener_ Map * 4. call Init with pkgName - * 5. check ret is DM_SERVICE_NOT_READY + * 5. check ret is DM_OK * @tc.type: FUNC * @tc.require: AR000GHSJK */ -HWTEST_F(IpcClientManagerTest, Init1, testing::ext::TestSize.Level0) +HWTEST_F(IpcClientManagerTest, Init_001, testing::ext::TestSize.Level0) { // 1. new a listener sptr listener = sptr(new IpcClientStub()); diff --git a/test/unittest/UTTest_ipc_client_stub.cpp b/test/unittest/UTTest_ipc_client_stub.cpp index 223d7406f..c3ff9a86a 100644 --- a/test/unittest/UTTest_ipc_client_stub.cpp +++ b/test/unittest/UTTest_ipc_client_stub.cpp @@ -131,7 +131,7 @@ HWTEST_F(IpcClientStubTest, SendCmd_001, testing::ext::TestSize.Level0) // 2. call IpcClientStub SendCmd with parameter int ret = instance->SendCmd(cmdCode, req, rsp); // 3. check result is DM_OK - ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(ret, DM_IPC_FAILED); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_ipc_server_listener.cpp b/test/unittest/UTTest_ipc_server_listener.cpp index ec412dca4..2c4674cb1 100644 --- a/test/unittest/UTTest_ipc_server_listener.cpp +++ b/test/unittest/UTTest_ipc_server_listener.cpp @@ -121,7 +121,7 @@ HWTEST_F(IpcServerListenerTest, SendRequest_002, testing::ext::TestSize.Level0) * set req not null * set rsp not null * 3. call IpcServerListener SendRequest - * 4. check ret is DM_OK + * 4. check ret is DM_IPC_FAILED * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -142,8 +142,8 @@ HWTEST_F(IpcServerListenerTest, SendRequest_003, testing::ext::TestSize.Level0) // 3. call IpcServerListener SendRequest std::shared_ptr ipcServerListener = std::make_shared(); int ret = ipcServerListener->SendRequest(cmdCode, req, rsp); - // 4. check ret is DM_OK - ASSERT_EQ(ret, DM_OK); + // 4. check ret is DM_IPC_FAILED + ASSERT_EQ(ret, DM_IPC_FAILED); } /** diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index 5e99678f8..740b4e8e0 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -317,17 +317,6 @@ HWTEST_F(SoftbusConnectorTest, CovertNodeBasicInfoToDmDevice_001, testing::ext:: int ret = softbusConnector->CovertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); EXPECT_EQ(ret, DM_OK); } - -/** - * @tc.name: OnParameterChgCallback_001 - * @tc.desc: set some corrort para and return DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(SoftbusConnectorTest, OnParameterChgCallback_001, testing::ext::TestSize.Level0) -{ - EXPECT_EQ(DM_OK, DM_OK); -} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index 8d14ff0e1..41bc71f33 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -38,11 +38,11 @@ void SoftbusSessionTest::TearDownTestCase() namespace { std::shared_ptr softbusSession = std::make_shared(); -std::shared_ptr listener_ = std::make_shared(); +std::shared_ptr listener = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); -std::shared_ptr discoveryMgr_ = - std::make_shared(softbusConnector, listener_, hiChainConnector); +std::shared_ptr discoveryMgr = + std::make_shared(softbusConnector, listener, hiChainConnector); /** * @tc.name: OpenAuthSession_001 @@ -98,7 +98,7 @@ HWTEST_F(SoftbusSessionTest, SendData_002, testing::ext::TestSize.Level0) jsonObj[TAG_TYPE] = msgType; std::string message = jsonObj.dump(); int32_t sessionId = 0; - softbusSession->RegisterSessionCallback(std::shared_ptr(discoveryMgr_)); + softbusSession->RegisterSessionCallback(std::shared_ptr(discoveryMgr)); int ret = softbusSession->SendData(sessionId, message); EXPECT_EQ(ret, DM_FAILED); } diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index 68e7cba41..b46bb5e99 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -16,8 +16,7 @@ #ifndef DEVICE_AUTH_H #define DEVICE_AUTH_H -#include -#include +#include #if defined(__LINUX__) || defined(_UNIX) #define DEVICE_AUTH_API_PUBLIC __attribute__ ((visibility("default"))) @@ -69,37 +68,37 @@ #define FIELD_BLE_CHALLENGE "bleChallenge" #define FIELD_OS_ACCOUNT_ID "osAccountId" -typedef enum { +using OsAccountEnum = enum _OsAccountEnum : int32_t { DEFAULT_OS_ACCOUNT = 0, INVALID_OS_ACCOUNT = -1, - ANY_OS_ACCOUNT = -2, -} OsAccountEnum; + ANY_OS_ACCOUNT = -2 +} ; -typedef enum { +using GroupType = enum _GroupType : int32_t { ALL_GROUP = 0, IDENTICAL_ACCOUNT_GROUP = 1, PEER_TO_PEER_GROUP = 256, COMPATIBLE_GROUP = 512, ACROSS_ACCOUNT_AUTHORIZE_GROUP = 1282 -} GroupType; +} ; -typedef enum { +using GroupOperationCode = enum _GroupOperationCode : int32_t { GROUP_CREATE = 0, GROUP_DISBAND = 1, MEMBER_INVITE = 2, MEMBER_JOIN = 3, MEMBER_DELETE = 4, ACCOUNT_BIND = 5 -} GroupOperationCode; +}; -typedef enum { +using GroupAuthForm = enum _GroupAuthForm : int32_t { AUTH_FORM_INVALID_TYPE = -1, AUTH_FORM_ACCOUNT_UNRELATED = 0, AUTH_FORM_IDENTICAL_ACCOUNT = 1, AUTH_FORM_ACROSS_ACCOUNT = 2, -} GroupAuthForm; +} ; -typedef enum { +using CredentialCode = enum _CredentialCode : int32_t { IMPORT_SELF_CREDENTIAL = 0, DELETE_SELF_CREDENTIAL = 1, QUERY_SELF_CREDENTIAL_INFO = 2, @@ -107,27 +106,27 @@ typedef enum { DELETE_TRUSTED_CREDENTIALS = 4, QUERY_TRUSTED_CREDENTIALS = 5, REQUEST_SIGNATURE = 6, -} CredentialCode; +}; -typedef enum { +using UserType = enum _UserType : int32_t { DEVICE_TYPE_ACCESSORY = 0, DEVICE_TYPE_CONTROLLER = 1, DEVICE_TYPE_PROXY = 2 -} UserType; +}; -typedef enum { +using ExpireTime = enum _ExpireTime : int32_t { EXPIRE_TIME_INDEFINITE = -1, EXPIRE_TIME_MIN = 1, EXPIRE_TIME_MAX = 90, -} ExpireTime; +}; -typedef enum { +using RequestResponse = enum _RequestResponse : int32_t { REQUEST_REJECTED = 0x80000005, REQUEST_ACCEPTED = 0x80000006, REQUEST_WAITING = 0x80000007 -} RequestResponse; +}; -typedef struct { +using DataChangeListener = struct _DataChangeListener { void (*onGroupCreated)(const char *groupInfo); void (*onGroupDeleted)(const char *groupInfo); void (*onDeviceBound)(const char *peerUdid, const char *groupInfo); @@ -135,17 +134,17 @@ typedef struct { void (*onDeviceNotTrusted)(const char *peerUdid); void (*onLastGroupDeleted)(const char *peerUdid, int groupType); void (*onTrustedDeviceNumChanged)(int curTrustedDeviceNum); -} DataChangeListener; +}; -typedef struct { +using DeviceAuthCallback = struct _DeviceAuthCallback { bool (*onTransmit)(int64_t requestId, const uint8_t *data, uint32_t dataLen); void (*onSessionKeyReturned)(int64_t requestId, const uint8_t *sessionKey, uint32_t sessionKeyLen); void (*onFinish)(int64_t requestId, int operationCode, const char *returnData); void (*onError)(int64_t requestId, int operationCode, int errorCode, const char *errorReturn); char *(*onRequest)(int64_t requestId, int operationCode, const char *reqParams); -} DeviceAuthCallback; +}; -typedef struct { +using GroupAuthManager = struct _GroupAuthManager { int32_t (*processData)(int64_t authReqId, const uint8_t *data, uint32_t dataLen, const DeviceAuthCallback *gaCallback); int32_t (*queryTrustedDeviceNum)(void); @@ -155,9 +154,9 @@ typedef struct { int32_t (*authDevice)(int32_t osAccountId, int64_t authReqId, const char *authParams, const DeviceAuthCallback *gaCallback); void (*informDeviceDisconnection)(const char *udid); -} GroupAuthManager; +}; -typedef struct { +using DeviceGroupManager = struct _DeviceGroupManager { int32_t (*regCallback)(const char *appId, const DeviceAuthCallback *callback); int32_t (*unRegCallback)(const char *appId); int32_t (*regDataChangeListener)(const char *appId, const DataChangeListener *listener); @@ -202,7 +201,7 @@ typedef struct { char **returnDevInfoVec, uint32_t *deviceNum); bool (*isDeviceInGroup)(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId); void (*destroyInfo)(char **returnInfo); -} DeviceGroupManager; +}; #ifdef __cplusplus extern "C" { -- Gitee