diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index cd7403f4..74fd7604 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -16,7 +16,6 @@ #ifndef OHOS_DM_CONSTANTS_H #define OHOS_DM_CONSTANTS_H -#include #include namespace OHOS { @@ -43,7 +42,6 @@ const int32_t MIN_PIN_CODE = 100000; const int32_t MAX_PIN_CODE = 999999; const int32_t DISCOVER_STATUS_LEN = 20; const int32_t COMMON_CALLBACK_MAX_SIZE = 200; -// const int32_t TOKEN_LEN = 9; enum { DM_OK = 0, diff --git a/common/include/ipc/ipc_def.h b/common/include/ipc/ipc_def.h index ec3a93d3..e2245f8b 100644 --- a/common/include/ipc/ipc_def.h +++ b/common/include/ipc/ipc_def.h @@ -21,7 +21,7 @@ namespace DistributedHardware { #define DEVICE_MANAGER_SERVICE_NAME "dev_mgr_svc" #define MAX_DM_IPC_LEN 2048 -#define DECLARE_IPC_MODEL(className) \ +#define DECLARE_IPC_MODEL(className) do { \ public: \ className() = default; \ virtual ~className() = default; \ @@ -30,7 +30,8 @@ public: \ className(const className &) = delete; \ className &operator=(const className &) = delete; \ className(className &&) = delete; \ - className &operator=(className &&) = delete + className &operator=(className &&) = delete \ +} while(0) #define DECLARE_IPC_INTERFACE(className) DECLARE_IPC_MODEL(className) diff --git a/common/include/single_instance.h b/common/include/single_instance.h index 0bfa9e40..a695ce4c 100644 --- a/common/include/single_instance.h +++ b/common/include/single_instance.h @@ -18,7 +18,7 @@ namespace OHOS { namespace DistributedHardware { -#define DECLARE_SINGLE_INSTANCE_BASE(className) \ +#define DECLARE_SINGLE_INSTANCE_BASE(className) do { \ public: \ static className &GetInstance(); \ \ @@ -26,20 +26,23 @@ private: \ className(const className &) = delete; \ className &operator=(const className &) = delete; \ className(className &&) = delete; \ - className &operator=(className &&) = delete; + className &operator=(className &&) = delete; \ +} while(0) -#define DECLARE_SINGLE_INSTANCE(className) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() = default; \ - ~className() = default; +#define DECLARE_SINGLE_INSTANCE(className) do { \ + DECLARE_SINGLE_INSTANCE_BASE(className) \ +private: \ + className() = default; \ + ~className() = default; \ +} while(0) -#define IMPLEMENT_SINGLE_INSTANCE(className) \ - className &className::GetInstance() \ - { \ - static auto instance = new className(); \ - return *instance; \ - } +#define IMPLEMENT_SINGLE_INSTANCE(className) do { \ + className &className::GetInstance() \ + { \ + static auto instance = new className(); \ + return *instance; \ + } \ +} while(0) }; // namespace DistributedHardware }; // namespace OHOS diff --git a/ext/pin_auth/include/ability/dm_ability_manager.h b/ext/pin_auth/include/ability/dm_ability_manager.h index 225fefc6..7f472095 100644 --- a/ext/pin_auth/include/ability/dm_ability_manager.h +++ b/ext/pin_auth/include/ability/dm_ability_manager.h @@ -16,9 +16,6 @@ #ifndef OHOS_DM_ABILITY_MANAGER_H #define OHOS_DM_ABILITY_MANAGER_H -#include - -#include #include #include diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 781a375f..5e123b0c 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -23,6 +23,7 @@ namespace OHOS { namespace DistributedHardware { +const int32_t MAX_VERIFY_TIMES = 3; PinAuth::PinAuth() { LOGI("PinAuth constructor"); @@ -59,7 +60,7 @@ int32_t PinAuth::VerifyAuthentication(std::string pinToken, int32_t code, const int32_t inputPinToken = jsonObject[PIN_TOKEN]; if (code == inputPinCode && stoi(pinToken) == inputPinToken) { return DM_OK; - } else if (code != inputPinCode && times_ < 3) { + } else if (code != inputPinCode && times_ < MAX_VERIFY_TIMES) { return DM_AUTH_INPUT_FAILED; } else { return DM_FAILED; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index 9e76a136..09577fdd 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -21,8 +21,6 @@ #include #include "device_manager_callback.h" -#include "dm_device_info.h" -#include "dm_subscribe_info.h" namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 82226e95..e1a881b9 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -287,7 +287,6 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply) std::string pkgName = (const char *)IpcIoPopString(&reply, &len); size_t devIdLen = 0; std::string deviceId = (const char *)IpcIoPopString(&reply, &devIdLen); - // int32_t pinToken = IpcIoPopInt32(&reply); int32_t status = IpcIoPopInt32(&reply); int32_t reason = IpcIoPopInt32(&reply); diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index 644701c1..be759e55 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -233,7 +233,6 @@ ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, Messag int32_t authType = pReq->GetAuthType(); DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); std::string deviceId = deviceInfo.deviceId; - // DmAppImageInfo imageInfo = pReq->GetAppImageInfo(); if (!data.WriteString(pkgName)) { LOGE("write pkgName failed"); diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index ddf8e747..227d48e6 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -205,8 +205,6 @@ public: static void JsToDmTokenInfo(const napi_env &env, const napi_value &object, const std::string &fieldStr, nlohmann::json &jsonObj); static void JsToDmAuthExtra(const napi_env &env, const napi_value ¶m, nlohmann::json &jsonObj); - // static void JsToDmFilterOptions(const napi_env &env, const napi_value &object, - // OHOS::DistributedHardware::DmFilterOptions &filterOptions); static void DmDeviceInfotoJsDeviceInfo(const napi_env &env, const OHOS::DistributedHardware::DmDeviceInfo &vecDevInfo, napi_value &result); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 3a4184de..9f7dce9d 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -26,12 +26,13 @@ using namespace OHOS::DistributedHardware; namespace { -#define GET_PARAMS(env, info, num) \ - size_t argc = num; \ - napi_value argv[num] = {nullptr}; \ - napi_value thisVar = nullptr; \ - void *data = nullptr; \ - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)) +#define GET_PARAMS(env, info, num) do { \ + size_t argc = num; \ + napi_value argv[num] = {nullptr}; \ + napi_value thisVar = nullptr; \ + void *data = nullptr; \ + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)) \ +} while(0) const std::string DM_NAPI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; const std::string DM_NAPI_EVENT_DEVICE_FOUND = "deviceFound"; @@ -530,7 +531,6 @@ void DeviceManagerNapi::JsToDmExtra(const napi_env &env, const napi_value &objec uint8_t *appThumbnailBufferPtr = nullptr; int32_t appThumbnailBufferLen = 0; JsToDmBuffer(env, object, "appThumbnail", &appThumbnailBufferPtr, appThumbnailBufferLen); - // appImageInfo.Reset(appIconBufferPtr, appIconBufferLen, appThumbnailBufferPtr, appThumbnailBufferLen); if (appIconBufferPtr != nullptr) { free(appIconBufferPtr); appIconBufferPtr = nullptr; @@ -1048,7 +1048,6 @@ napi_value DeviceManagerNapi::CallDeviceList(napi_env env, napi_callback_info in return result; } else { LOGE("CallDeviceList for argc %d Type = %d", argc, (int)eventHandleType); - // DmFilterOptions filterOptions; napi_deferred deferred; napi_value promise = 0; napi_create_promise(env, &deferred, &promise); @@ -1125,8 +1124,7 @@ napi_value DeviceManagerNapi::GetTrustedDeviceList(napi_env env, napi_callback_i return promise; } else if (argc == 1) { return CallDeviceList(env, info, deviceInfoAsyncCallbackInfo); - } else if (argc == 2) { - // DmFilterOptions filterOptions; + } else if (argc == DM_NAPI_ARGS_TWO) { GET_PARAMS(env, info, DM_NAPI_ARGS_TWO); napi_valuetype valueType; napi_typeof(env, argv[0], &valueType); @@ -1389,10 +1387,6 @@ napi_value DeviceManagerNapi::JsOnFrench(napi_env env, int32_t num, napi_value t NAPI_ASSERT(env, typeLen < DM_NAPI_BUF_LENGTH, "typeLen >= MAXLEN"); char type[DM_NAPI_BUF_LENGTH] = {0}; napi_get_value_string_utf8(env, argv[0], type, typeLen + 1, &typeLen); - if (num) { - // DmFilterOptions filterOptions; - // JsToDmFilterOptions(env, argv[1], filterOptions); - } std::string eventType = type; DeviceManagerNapi *deviceManagerWrapper = nullptr; @@ -1413,7 +1407,7 @@ napi_value DeviceManagerNapi::JsOn(napi_env env, napi_callback_info info) size_t argc = 0; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - if (argc == 3) { + if (argc == DM_NAPI_ARGS_THREE) { LOGI("JsOff in argc == 3"); GET_PARAMS(env, info, DM_NAPI_ARGS_THREE); NAPI_ASSERT(env, argc >= DM_NAPI_ARGS_THREE, "Wrong number of arguments, required 2"); @@ -1427,7 +1421,7 @@ napi_value DeviceManagerNapi::JsOn(napi_env env, napi_callback_info info) NAPI_ASSERT(env, valueType == napi_object, "type mismatch for parameter 2"); napi_valuetype eventHandleType = napi_undefined; - napi_typeof(env, argv[2], &eventHandleType); + napi_typeof(env, argv[DM_NAPI_ARGS_TWO], &eventHandleType); NAPI_ASSERT(env, eventHandleType == napi_function, "type mismatch for parameter 3"); return JsOnFrench(env, 1, thisVar, argv); @@ -1475,7 +1469,7 @@ napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info) size_t argc = 0; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, nullptr, &thisVar, nullptr)); - if (argc == 3) { + if (argc == DM_NAPI_ARGS_THREE) { LOGI("JsOff in argc == 3"); GET_PARAMS(env, info, DM_NAPI_ARGS_THREE); size_t requireArgc = 1; @@ -1491,7 +1485,7 @@ napi_value DeviceManagerNapi::JsOff(napi_env env, napi_callback_info info) if (argc > requireArgc) { napi_valuetype eventHandleType = napi_undefined; - napi_typeof(env, argv[2], &eventHandleType); + napi_typeof(env, argv[DM_NAPI_ARGS_TWO], &eventHandleType); NAPI_ASSERT(env, eventValueType == napi_function, "type mismatch for parameter 2"); } return JsOffFrench(env, 1, thisVar, argv); diff --git a/services/devicemanagerservice/include/adapter/crypto_adapter.h b/services/devicemanagerservice/include/adapter/crypto_adapter.h index 099107ed..1ae62730 100644 --- a/services/devicemanagerservice/include/adapter/crypto_adapter.h +++ b/services/devicemanagerservice/include/adapter/crypto_adapter.h @@ -15,9 +15,6 @@ #ifndef OHOS_DM_CRYPTO_ADAPTER_H #define OHOS_DM_CRYPTO_ADAPTER_H - -#include - namespace OHOS { namespace DistributedHardware { class ICryptoAdapter { diff --git a/services/devicemanagerservice/include/adapter/profile_adapter.h b/services/devicemanagerservice/include/adapter/profile_adapter.h index 39f5a3de..d7100f37 100644 --- a/services/devicemanagerservice/include/adapter/profile_adapter.h +++ b/services/devicemanagerservice/include/adapter/profile_adapter.h @@ -16,7 +16,6 @@ #ifndef OHOS_DM_PROFILE_ADAPTER_H #define OHOS_DM_PROFILE_ADAPTER_H -#include #include namespace OHOS { diff --git a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp index e81442c7..6d87d130 100644 --- a/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp +++ b/services/devicemanagerservice/src/ability/lite/dm_ability_manager.cpp @@ -16,7 +16,6 @@ #include "dm_ability_manager.h" #include "dm_constants.h" -#include "semaphore.h" namespace OHOS { namespace DistributedHardware { diff --git a/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp b/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp index 693656d5..d7913a6d 100644 --- a/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp +++ b/services/devicemanagerservice/src/adapter/standard/dm_adapter_manager.cpp @@ -15,8 +15,6 @@ #include "dm_adapter_manager.h" -#include - #include "config_manager.h" #include "dm_constants.h" #include "dm_log.h" diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 1b547a60..b1273738 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -219,7 +219,6 @@ void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) authResponseContext_->reply = json[TAG_REPLY]; authResponseContext_->deviceId = json[TAG_DEVICE_ID]; authResponseContext_->token = json[TAG_TOKEN]; - // authResponseContext_->deviceId = json[TAG_GROUPIDS]; if (authResponseContext_->reply == 0) { authResponseContext_->code = json[PIN_CODE_KEY]; authResponseContext_->networkId = json[TAG_NET_ID]; @@ -237,7 +236,6 @@ void AuthMessageProcessor::ParseAuthRequestMessage() nlohmann::json jsonObject = authSplitJsonList_.front(); authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; authResponseContext_->reply = jsonObject[TAG_REPLY]; - // authResponseContext_->syncGroupList = jsonObject[TAG_GROUPIDS]; authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE]; LOGI("AuthMessageProcessor::ParseAuthResponseMessage %d,%d", authResponseContext_->reply); LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp index 1323b4e6..e34ea708 100644 --- a/services/devicemanagerservice/src/authentication/auth_request_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp @@ -15,8 +15,6 @@ #include "auth_request_state.h" -#include - #include "dm_auth_manager.h" #include "dm_constants.h" @@ -32,10 +30,6 @@ void AuthRequestState::SetAuthManager(std::shared_ptr authManager authManager_ = std::move(authManager); } -// void AuthRequestState::SetLastState(std::shared_ptr state) { -// lastState_ = state; -// } - void AuthRequestState::SetAuthContext(std::shared_ptr context) { context_ = std::move(context); @@ -99,12 +93,6 @@ int32_t AuthRequestNegotiateDoneState::GetStateType() void AuthRequestNegotiateDoneState::Enter() { - // //1. 获取对端加解密信息,并对比两端状态 - // - // //2. 保存加解密状态,发送认证请求 - // authMessageProcessor_->CreateMessage(MSG_TYPE_REQ_AUTH); - // std::string message; - // softbusSession_->SendData(context_.sessionId, message); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { LOGE("AuthRequestState::authManager_ null"); diff --git a/services/devicemanagerservice/src/authentication/auth_response_state.cpp b/services/devicemanagerservice/src/authentication/auth_response_state.cpp index 10c4c17f..d812b19f 100644 --- a/services/devicemanagerservice/src/authentication/auth_response_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_response_state.cpp @@ -94,7 +94,6 @@ void AuthResponseConfirmState::Enter() { //委托授权UI模块进行用户交互 //如果交互成功 - // TransitionTo(new AuthResponseGroupState()); LOGI("AuthResponse:: AuthResponseConfirmState Enter"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { @@ -112,7 +111,6 @@ int32_t AuthResponseGroupState::GetStateType() void AuthResponseGroupState::Enter() { // //1.创建群组, - // authManagerPtr_->GetHiChainConnector()->CreateGroup(); LOGI("AuthResponse:: AuthResponseGroupState Enter"); std::shared_ptr stateAuthManager = authManager_.lock(); if (stateAuthManager == nullptr) { diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index dcce54d5..ccb269e4 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -80,13 +80,6 @@ DmAuthManager::~DmAuthManager() int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra) { - // TODO:检查pkgName的权限 - - // std::shared_ptr authentication = authenticationMap_[authType]; - // if (authentication == nullptr) { - // LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authType); - // return DM_AUTH_NOT_SUPPORT; - // } LOGE("DmAuthManager::AuthenticateDevice is"); if (authRequestState_ != nullptr && authResponseState_ != nullptr) { LOGE("DmAuthManager::AuthenticateDevice %s is request authentication.", @@ -141,7 +134,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } } authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); - authRequestState_ = std::shared_ptr(new AuthRequestInitState()); + authRequestState_ = std::make_shared(); authRequestState_->SetAuthManager(shared_from_this()); authRequestState_->SetAuthContext(authRequestContext_); authRequestState_->Enter(); @@ -181,7 +174,6 @@ int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const st LOGE("DmAuthManager::UnAuthenticateDevice groupList.size = 0"); return DM_FAILED; } - // groupId = authResponseContext_->groupId; return DM_OK; } @@ -201,7 +193,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) switch (ret) { case DM_OK: { - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestJoinState())); + authRequestState_->TransitionTo(std::make_shared()); } break; case DM_AUTH_INPUT_FAILED: @@ -214,7 +206,7 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) default: { CancelDisplay(); - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); } } @@ -228,7 +220,7 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI if (sessionSide == AUTH_SESSION_SIDE_SERVER) { if (authResponseState_ == nullptr) { authMessageProcessor_ = std::make_shared(shared_from_this()); - authResponseState_ = std::shared_ptr(new AuthResponseInitState()); + authResponseState_ = std::make_shared(); authResponseState_->SetAuthManager(shared_from_this()); authResponseState_->Enter(); hiChainConnector_->RegisterHiChainCallback(pkgName, shared_from_this()); @@ -255,7 +247,7 @@ void DmAuthManager::OnSessionOpened(const std::string &pkgName, int32_t sessionI authRequestState_->SetAuthContext(authRequestContext_); authMessageProcessor_->SetRequestContext(authRequestContext_); authResponseContext_ = std::make_shared(); - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestNegotiateState())); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("DmAuthManager::OnSessionOpened but request state %d is wrong", authRequestState_->GetStateType()); } @@ -292,7 +284,7 @@ void DmAuthManager::OnDataReceived(const std::string &pkgName, int32_t sessionId case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT) { timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseNegotiateState())); + authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); } @@ -300,21 +292,21 @@ void DmAuthManager::OnDataReceived(const std::string &pkgName, int32_t sessionId case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE) { timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); - authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseConfirmState())); + authResponseState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); } break; case MSG_TYPE_RESP_AUTH: if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE_DONE) { - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestReplyState())); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); } break; case MSG_TYPE_RESP_NEGOTIATE: if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_NEGOTIATE) { - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestNegotiateDoneState())); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("Device manager auth state error"); } @@ -322,7 +314,7 @@ void DmAuthManager::OnDataReceived(const std::string &pkgName, int32_t sessionId case MSG_TYPE_REQ_AUTH_TERMINATE: if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { - authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseFinishState())); + authResponseState_->TransitionTo(std::make_shared()); } else if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { LOGE("Device manager auth state error"); @@ -353,7 +345,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); - authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseShowState())); + authResponseState_->TransitionTo(std::make_shared()); } void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) @@ -365,16 +357,14 @@ void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) if (authRequestState_ != nullptr) { timerMap_[ADD_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (status != DM_OK || authResponseContext_->requestId != requestId) { - if (authRequestState_ == nullptr) { - // authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseFinishState())); - } else { + if (authRequestState_ != nullptr) { authResponseContext_->reply = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = DM_AUTH_INPUT_FAILED; - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); return; } } - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestNetworkState())); + authRequestState_->TransitionTo(std::make_shared()); } } @@ -388,7 +378,7 @@ void DmAuthManager::HandleAuthenticateTimeout() } authResponseContext_->reply = authRequestState_->GetStateType(); authRequestContext_->reason = DM_TIME_OUT; - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); } LOGI("DmAuthManager::HandleAuthenticateTimeout start complete"); } @@ -403,7 +393,7 @@ void DmAuthManager::EstablishAuthChannel(const std::string &deviceId) authResponseContext_ = std::make_shared(); authResponseContext_->reply = AuthState::AUTH_REQUEST_NEGOTIATE; authRequestContext_->reason = DM_AUTH_OPEN_SESSION_FAILED; - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); } } @@ -466,7 +456,7 @@ void DmAuthManager::SendAuthRequest(const int32_t &sessionId) } if (authResponseContext_->reply == DM_AUTH_PEER_REJECT) { - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); return; } @@ -488,7 +478,7 @@ void DmAuthManager::StartAuthProcess(const int32_t &action) authResponseContext_->reply = action; if (authResponseContext_->reply == USER_OPERATION_TYPE_ALLOW_AUTH && authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_CONFIRM) { - authResponseState_->TransitionTo(std::shared_ptr(new AuthResponseGroupState())); + authResponseState_->TransitionTo(std::make_shared()); } else { authMessageProcessor_->SetResponseContext(authResponseContext_); std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH); @@ -504,12 +494,12 @@ void DmAuthManager::StartRespAuthProcess() std::shared_ptr inputStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); timerMap_[INPUT_TIMEOUT_TASK] = inputStartTimer; inputStartTimer->Start(INPUT_TIMEOUT, TimeOut, this); - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestInputState())); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("do not accept"); authResponseContext_->reply = AuthState::AUTH_REQUEST_REPLY; authRequestContext_->reason = DM_AUTH_PEER_REJECT; - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); } } @@ -557,7 +547,7 @@ void DmAuthManager::JoinNetwork() timerMap_[AUTHENTICATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseContext_->reply = AuthState::AUTH_REQUEST_FINISH; authRequestContext_->reason = DM_OK; - authRequestState_->TransitionTo(std::shared_ptr(new AuthRequestFinishState())); + authRequestState_->TransitionTo(std::make_shared()); } void DmAuthManager::AuthenticateFinish() diff --git a/services/devicemanagerservice/src/dependency/commonevent/event_manager_adapt.cpp b/services/devicemanagerservice/src/dependency/commonevent/event_manager_adapt.cpp index 91e7fba2..7c1cc8ef 100644 --- a/services/devicemanagerservice/src/dependency/commonevent/event_manager_adapt.cpp +++ b/services/devicemanagerservice/src/dependency/commonevent/event_manager_adapt.cpp @@ -15,8 +15,6 @@ #include "event_manager_adapt.h" -#include - #include "dm_constants.h" using namespace OHOS::EventFwk; diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index 55187251..f5daca0c 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -196,9 +196,6 @@ int32_t HiChainConnector::AddMember(std::string deviceId, std::string &connectIn jsonObj[FIELD_CONNECT_PARAMS] = connectInfomation.c_str(); std::string tmpStr = jsonObj.dump(); int64_t requestId = jsonObject[TAG_REQUEST_ID]; - // LOGI("HiChainConnector::AddMember completed requestId%d, jsonObject[TAG_GROUP_ID]%s ", requestId, - // groupId.c_str()); LOGI("HiChainConnector::AddMember completed DM_PKG_NAME %s", DM_PKG_NAME.c_str()); - // LOGI("HiChainConnector::AddMember completedtmpStr%s", tmpStr.c_str()); int32_t ret = deviceGroupManager_->addMemberToGroup(requestId, DM_PKG_NAME.c_str(), tmpStr.c_str()); LOGI("HiChainConnector::AddMember completed"); return ret; diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 475cef15..6aeb389e 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -16,10 +16,6 @@ #include "softbus_connector.h" #include -#include - -#include -#include #include "dm_anonymous.h" #include "dm_constants.h" @@ -110,7 +106,6 @@ int32_t SoftbusConnector::Init() LOGI("service unpublish result is : %d", ret); } -// ret = WatchParameter(DISCOVER_STATUS_KEY.c_str(), &SoftbusConnector::OnParameterChgCallback, nullptr); LOGI("register Watch Parameter result is : %d"); return ret; } diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index c0b3f992..b2290ede 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -15,8 +15,6 @@ #include "device_manager_service_listener.h" -#include - #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_log.h" @@ -91,7 +89,6 @@ void DeviceManagerServiceListener::OnAuthResult(const std::string &pkgName, cons pReq->SetDeviceId(deviceId); pReq->SetToken(token); pReq->SetStatus(status); - // pReq->SetReason(reason); ipcServerListener_.SendRequest(SERVER_AUTH_RESULT, pReq, pRsp); } diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 788e7567..9e7a479f 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -100,7 +100,6 @@ void DmDeviceStateManager::OnDeviceReady(const std::string &pkgName, const DmDev void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std::string deviceId) { - //deviceId is uuid; DmDeviceInfo saveInfo; auto iter = remoteDeviceInfos_.find(deviceId); if (iter == remoteDeviceInfos_.end()) { diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index eded6b94..09e10c29 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -54,7 +54,7 @@ HWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0 std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->authManager_.use_count(); authRequestState->authManager_.reset(); @@ -71,7 +71,7 @@ HWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0 */ HWTEST_F(AuthRequestStateTest, SetAuthManager_002, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->authManager_.use_count(); authRequestState->authManager_.reset(); @@ -91,10 +91,10 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->authManager_ = authManager; - int32_t ret = authRequestState->TransitionTo(std::shared_ptr(new AuthRequestNegotiateState())); + int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); sleep(15); } @@ -113,14 +113,14 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); std::shared_ptr context = std::make_shared(); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); context->sessionId = 123456; authRequestState->SetAuthContext(context); authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->TransitionTo(std::shared_ptr(new AuthRequestNegotiateState())); + int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); sleep(20); } @@ -134,7 +134,7 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INIT); sleep(15); @@ -153,7 +153,7 @@ HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); @@ -174,10 +174,10 @@ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestInitState()); + authManager->authRequestState_ = std::make_shared(); authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->deviceId = "123456"; @@ -196,8 +196,7 @@ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE); sleep(15); @@ -216,8 +215,7 @@ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -237,13 +235,12 @@ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNegotiateState()); + authManager->authRequestState_ = std::make_shared(); authManager->authRequestContext_->deviceId = "111"; authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); @@ -264,8 +261,7 @@ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateDoneState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE_DONE); sleep(15); @@ -284,8 +280,7 @@ HWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateDoneState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -305,8 +300,7 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNegotiateDoneState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; @@ -332,7 +326,7 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestReplyState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_REPLY); sleep(15); @@ -351,7 +345,7 @@ HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestReplyState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -371,14 +365,14 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestReplyState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr inputStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = inputStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestReplyState()); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->sessionId = 1; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); @@ -401,7 +395,7 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInputState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT); sleep(15); @@ -420,7 +414,7 @@ HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInputState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -440,7 +434,7 @@ HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInputState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); @@ -456,7 +450,7 @@ HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestJoinState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_JOIN); sleep(15); @@ -475,7 +469,7 @@ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestJoinState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -495,7 +489,7 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestJoinState()); + std::shared_ptr authRequestState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); @@ -532,8 +526,7 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNetworkState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NETWORK); sleep(15); @@ -552,8 +545,7 @@ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNetworkState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -573,14 +565,13 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestNetworkState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNetworkState()); + authManager->authRequestState_ = std::make_shared(); authManager->SetAuthRequestState(authRequestState); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); @@ -597,8 +588,7 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) { - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestFinishState()); + std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_FINISH); sleep(15); @@ -617,8 +607,7 @@ HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestFinishState()); + std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -638,16 +627,15 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = - std::shared_ptr(new AuthRequestFinishState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr inputStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = inputStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseFinishState()); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); + authManager->authResponseState_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->sessionId = 1; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index 48e886fe..98c359b1 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -50,8 +50,7 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_001, testing::ext::TestSize.Level std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 1); @@ -68,8 +67,7 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_001, testing::ext::TestSize.Level */ HWTEST_F(AuthResponseStateTest, SetAuthManager_002, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 0); @@ -89,11 +87,10 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->authManager_ = authManager; - int32_t ret = authResponseState->TransitionTo(std::shared_ptr(new AuthResponseNegotiateState())); + int32_t ret = authResponseState->TransitionTo(std::make_shared();); ASSERT_EQ(ret, DM_FAILED); sleep(15); } @@ -112,14 +109,14 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); std::shared_ptr context = std::make_shared(); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); context->sessionId = 123456; authRequestState->SetAuthContext(context); authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->TransitionTo(std::shared_ptr(new AuthRequestNegotiateState())); + int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); sleep(20); } @@ -133,8 +130,7 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_001, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_INIT); sleep(15); @@ -149,8 +145,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_001, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); sleep(15); @@ -165,8 +160,7 @@ HWTEST_F(AuthResponseStateTest, Enter_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_002, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseNegotiateState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_NEGOTIATE); sleep(15); @@ -185,8 +179,7 @@ HWTEST_F(AuthResponseStateTest, Enter_002, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseNegotiateState()); + std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); @@ -207,14 +200,13 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseNegotiateState()); + std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseNegotiateState()); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNegotiateState()); + authManager->authResponseState_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->deviceId = "111"; authManager->authResponseContext_->localDeviceId = "222"; authResponseState->SetAuthManager(authManager); @@ -235,8 +227,7 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_003, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_CONFIRM); sleep(15); @@ -255,8 +246,7 @@ HWTEST_F(AuthResponseStateTest, Enter_004, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -276,8 +266,7 @@ HWTEST_F(AuthResponseStateTest, Enter_005, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); @@ -293,8 +282,7 @@ HWTEST_F(AuthResponseStateTest, Enter_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_004, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseGroupState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_GROUP); sleep(15); @@ -313,8 +301,7 @@ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseGroupState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -334,8 +321,7 @@ HWTEST_F(AuthResponseStateTest, Enter_007, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseGroupState()); + std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); @@ -354,8 +340,7 @@ HWTEST_F(AuthResponseStateTest, Enter_007, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_005, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseShowState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_SHOW); sleep(15); @@ -374,8 +359,7 @@ HWTEST_F(AuthResponseStateTest, Enter_008, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseShowState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -395,8 +379,7 @@ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseShowState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); @@ -412,8 +395,7 @@ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, GetStateType_006, testing::ext::TestSize.Level0) { - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseFinishState()); + std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_FINISH); sleep(15); @@ -432,8 +414,7 @@ HWTEST_F(AuthResponseStateTest, Enter_010, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseFinishState()); + std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); @@ -453,10 +434,9 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = - std::shared_ptr(new AuthResponseFinishState()); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseFinishState()); + std::shared_ptr authResponseState = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); diff --git a/test/unittest/UTTest_device_message.h b/test/unittest/UTTest_device_message.h index 3d818e9a..1e6e647f 100644 --- a/test/unittest/UTTest_device_message.h +++ b/test/unittest/UTTest_device_message.h @@ -12,11 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #ifndef OHOS_DEVICE_MESSAGE_TEST_H #define OHOS_DEVICE_MESSAGE_TEST_H -#define private public -#define protected public #include #include @@ -35,6 +33,4 @@ public: }; } } -#endif // OHOS_DM_IMPL_TEST_H -#undef private -#undef protected +#endif // OHOS_DEVICE_MESSAGE_TEST_H \ No newline at end of file diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index a911efe3..0dae29bd 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -56,7 +56,7 @@ HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestInitState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr context = std::make_shared(); std::string pkgName = "111"; int32_t authType = 1; @@ -79,7 +79,7 @@ HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr context = std::make_shared(); const std::string pkgName = "111"; int32_t authType = 1; @@ -285,12 +285,12 @@ HWTEST_F(DmAuthManagerTest, VerifyAuthentication_001, testing::ext::TestSize.Lev std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestNetworkState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); authManager->timerMap_[INPUT_TIMEOUT_TASK] = negotiateStartTimer; authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNetworkState()); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_=nullptr; authManager->SetAuthRequestState(authRequestState); int32_t ret =authManager->HandleAuthenticateTimeout(); @@ -311,10 +311,10 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSiz std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestNetworkState()); + std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestNetworkState()); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_=nullptr; authManager->SetAuthRequestState(authRequestState); int32_t ret =authManager->HandleAuthenticateTimeout(); @@ -332,10 +332,10 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSiz std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestFinishState()); + std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); + authManager->authRequestState_ = std::make_shared(); authManager->SetAuthRequestState(authRequestState); int32_t ret =authManager->HandleAuthenticateTimeout(); ASSERT_EQ(ret,DM_OK); @@ -356,7 +356,7 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev std::shared_ptr authRequestContext = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); + authManager->authRequestState_ = std::make_shared(); std::string deviceId1; int32_t ret =authManager->EstablishAuthChannel(deviceId1); ASSERT_EQ(ret, DM_FAILED); @@ -373,12 +373,12 @@ HWTEST_F(DmAuthManagerTest, SendAuthRequest_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestNegotiateState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); authManager->timerMap_[NEGOTIATE_TIMEOUT_TASK] = negotiateStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared();; - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); + authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->cryptoSupport = true; authManager->SetAuthRequestState(authRequestState); int32_t sessionId=1; @@ -397,10 +397,10 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseConfirmState()); + authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); int32_t action = 0; int32_t ret =authManager->StartAuthProcess(action); @@ -418,10 +418,10 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseConfirmState()); + authManager->authResponseState_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->SetAuthResponseState(authResponseState); authManager->authResponseContext_->sessionId=111; @@ -441,11 +441,11 @@ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseConfirmState()); + std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseConfirmState()); + authManager->authResponseState_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->SetAuthResponseState(authResponseState); authManager->authResponseContext_->requestId=111; @@ -466,7 +466,7 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseInitState()); + std::shared_ptr authResponseState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); @@ -502,13 +502,13 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authRequestState = std::shared_ptr(new AuthRequestFinishState()); + std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); - authManager->authRequestState_ = std::shared_ptr(new AuthRequestFinishState()); + authManager->authRequestState_ = std::make_shared(); authManager->SetAuthRequestState(authRequestState); int32_t ret =authManager->JoinNetwork(); ASSERT_EQ(ret, DM_OK); @@ -525,7 +525,7 @@ HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_001, testing::ext::TestSize.Level std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseFinishState()); + authManager->authResponseState_ = std::make_shared(); bool isCryptoSupport = false; int32_t ret =authManager->GetIsCryptoSupport(isCryptoSupport); ASSERT_EQ(ret,DM_OK); @@ -542,8 +542,8 @@ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Lev std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener); - std::shared_ptr authResponseState = std::shared_ptr(new AuthResponseFinishState()); - authManager->authResponseState_ = std::shared_ptr(new AuthResponseFinishState()); + std::shared_ptr authResponseState = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); int32_t ret =authManager->SetAuthResponseState(authResponseState); ASSERT_EQ(ret, DM_OK); diff --git a/test/unittest/UTTest_dm_device_info_manager.cpp b/test/unittest/UTTest_dm_device_info_manager.cpp index 992f5a01..88c37adb 100644 --- a/test/unittest/UTTest_dm_device_info_manager.cpp +++ b/test/unittest/UTTest_dm_device_info_manager.cpp @@ -40,8 +40,7 @@ namespace { std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); -std::shared_ptr dmDeviceStateManager = - std::shared_ptr(new DmDeviceInfoManager(softbusConnector)); +std::shared_ptr dmDeviceStateManager = std::make_shared(softbusConnector); /** * @tc.name: DmDeviceInfoManager_001 @@ -53,8 +52,7 @@ std::shared_ptr dmDeviceStateManager = */ HWTEST_F(DeviceManagerImplTest, DmDeviceInfoManager_001, testing::ext::TestSize.Level0) { - std::shared_ptr p = - std::shared_ptr(new DmDeviceInfoManager(softbusConnector)); + std::shared_ptr p = std::make_shared(softbusConnector); ASSERT_NE(p, nullptr); } } // namespace diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index 8ea55d52..853781c5 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -47,7 +47,7 @@ namespace { std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); -std::shared_ptr dmDeviceStateManager = std::shared_ptr(new DmDeviceStateManager(softbusConnector, listener_)); +std::shared_ptr dmDeviceStateManager = std::make_shared(softbusConnector, listener_); /** * @tc.name: DmDeviceStateManager_001 @@ -57,7 +57,7 @@ std::shared_ptr dmDeviceStateManager = std::shared_ptr p = std::shared_ptr(new DmDeviceStateManager(softbusConnector, listener_)); + std::shared_ptr p = std::make_shared(softbusConnector, listener_); ASSERT_NE(p, nullptr); } @@ -70,7 +70,7 @@ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_001, testing::ext::TestS */ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_002, testing::ext::TestSize.Level0) { - std::shared_ptr p = std::shared_ptr(new DmDeviceStateManager(softbusConnector, listener_)); + std::shared_ptr p = std::make_shared(softbusConnector, listener_); p.reset(); EXPECT_EQ(p, nullptr); } diff --git a/utils/include/ipc/lite/ipc_cmd_register.h b/utils/include/ipc/lite/ipc_cmd_register.h index f3d6ac3d..d6367772 100644 --- a/utils/include/ipc/lite/ipc_cmd_register.h +++ b/utils/include/ipc/lite/ipc_cmd_register.h @@ -27,7 +27,7 @@ namespace OHOS { namespace DistributedHardware { -#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB, paraC, paraD) \ +#define ON_IPC_SET_REQUEST(cmdCode, paraA, paraB, paraC, paraD) do { \ static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD); \ struct IpcRegisterSetRequestFunc##cmdCode { \ IpcRegisterSetRequestFunc##cmdCode() \ @@ -36,9 +36,10 @@ namespace DistributedHardware { } \ }; \ IpcRegisterSetRequestFunc##cmdCode g_IpcRegisterSetRequestFunc##cmdCode; \ - static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD) + static int32_t IpcSetRequest##cmdCode(paraA, paraB, paraC, paraD) \ +} while(0) -#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) \ +#define ON_IPC_READ_RESPONSE(cmdCode, paraA, paraB) do { \ static int32_t IpcReadResponse##cmdCode(paraA, paraB); \ struct IpcRegisterReadResponseFunc##cmdCode { \ IpcRegisterReadResponseFunc##cmdCode() \ @@ -47,9 +48,10 @@ namespace DistributedHardware { } \ }; \ IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ - static int32_t IpcReadResponse##cmdCode(paraA, paraB) + static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ +} while(0) -#define ON_IPC_CMD(cmdCode, paraA) \ +#define ON_IPC_CMD(cmdCode, paraA) do { \ static void IpcCmdProcess##cmdCode(paraA); \ struct IpcRegisterCmdProcessFunc##cmdCode { \ IpcRegisterCmdProcessFunc##cmdCode() \ @@ -58,9 +60,10 @@ namespace DistributedHardware { } \ }; \ IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ - static void IpcCmdProcess##cmdCode(paraA) + static void IpcCmdProcess##cmdCode(paraA) \ +} while(0) -#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB) \ +#define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB) do { \ static void IpcServerCmdProcess##cmdCode(paraA, paraB); \ class IpcRegisterServerCmdProcessFunc##cmdCode { \ public: \ @@ -70,7 +73,8 @@ namespace DistributedHardware { } \ }; \ IpcRegisterServerCmdProcessFunc##cmdCode g_IpcRegisterServerCmdProcessFunc##cmdCode; \ - static void IpcServerCmdProcess##cmdCode(paraA, paraB) + static void IpcServerCmdProcess##cmdCode(paraA, paraB) \ +} while(0) using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t bufferLen);