From 746964376368dca5517c272608a7ce51af65ca8e Mon Sep 17 00:00:00 2001 From: lcaidm Date: Wed, 26 Jan 2022 11:39:37 +0800 Subject: [PATCH] =?UTF-8?q?ACE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lcaidm --- common/include/dm_constants.h | 6 + ext/pin_auth/BUILD.gn | 47 +++++- ext/pin_auth/include/pin_auth.h | 5 +- ext/pin_auth/include/pin_auth_ui.h | 5 +- ext/pin_auth/src/pin_auth.cpp | 9 +- ext/pin_auth/src/pin_auth_ui.cpp | 51 ++++++- services/devicemanagerservice/BUILD.gn | 4 + .../include/authentication/authentication.h | 5 +- .../include/authentication/dm_auth_manager.h | 1 + .../src/authentication/dm_auth_manager.cpp | 60 +++++++- .../dependency/softbus/softbus_connector.cpp | 7 +- .../UTTest_auth_message_processor.cpp | 138 ++++++++++-------- test/unittest/UTTest_auth_request_state.cpp | 138 ++++++++++++------ test/unittest/UTTest_auth_response_state.cpp | 93 ++++++++---- .../UTTest_device_manager_service.cpp | 20 +++ ...UTTest_device_manager_service_listener.cpp | 6 +- test/unittest/UTTest_dm_auth_manager.cpp | 76 ++++++---- test/unittest/UTTest_hichain_connector.cpp | 7 +- test/unittest/UTTest_softbus_session.cpp | 4 +- 19 files changed, 475 insertions(+), 207 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 492de42c1..0820c20f4 100644 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -172,6 +172,12 @@ const std::string BR_MAC = "BR_MAC"; const std::string BLE_MAC = "BLE_MAC"; const std::string ETH_IP = "ETH_IP"; const std::string ETH_PORT = "ETH_PORT"; + +//ACE +const int32_t ACE_X = 50; +const int32_t ACE_Y = 200; +const int32_t ACE_WIDTH = 400; +const int32_t ACE_HEIGHT = 200; } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index 603d4ff14..837223468 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -25,10 +25,38 @@ if (defined(ohos_lite)) { include_dirs = [ "include", "${common_path}/include", - "${services_path}/include/adapter", "${ext_path}/pin_auth/include/ability", + "${services_path}/include/dependency/timer", + "${services_path}/include/config", + "${services_path}/include/adapter", "${services_path}/include/authentication", + "${services_path}/include/ability", + "${services_path}/include/deviceinfo", + "${services_path}/include/devicestate", + "${services_path}/include/discovery", + "${services_path}/include/dependency/commonevent", + "${services_path}/include/dependency/hichain", + "${services_path}/include/dependency/softbus", + "${services_path}/include/dependency/timer", + "${services_path}/include/ipc", + "${services_path}/include/ipc/standard", "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${services_path}/include", + "${innerkits_path}/native_cpp/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/ipc/standard", + "//third_party/json/include", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "//base/notification/ces_standard/frameworks/core/include", + "//base/notification/ces_standard/interfaces/innerkits/native/include", + "//base/security/deviceauth/interfaces/innerkits", + "//base/startup/syspara_lite/interfaces/kits", + "//base/startup/syspara_lite/adapter/native/syspara/include", ] sources = [ @@ -38,20 +66,33 @@ if (defined(ohos_lite)) { ] deps = [ + "${ext_path}/input_pin_dialog/dialog_ui/js:dialog_js_files_etc", + "${ext_path}/show_pin_dialog/dialog_ui/js:dialog_js_files_etc", + "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", + "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", + "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice", + "//foundation/windowmanager/wm:libwm", "//utils/native/base:utils", ] external_deps = [ - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "appexecfwk_standard:libeventhandler", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "dsoftbus_standard:softbus_client", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", "startup_l2:syspara", + "startup_l2:syspara_watchagent", ] defines = [ diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index 2129c94a1..b2636e0af 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -20,6 +20,7 @@ #include #include "authentication.h" +#include "dm_auth_manager.h" #include "dm_ability_manager.h" #include "pin_auth_ui.h" @@ -29,8 +30,8 @@ class PinAuth : public IAuthentication { public: PinAuth(); ~PinAuth(); - int32_t ShowAuthInfo() override; - int32_t StartAuth(std::shared_ptr dmAbilityManager) override; + int32_t ShowAuthInfo(int32_t code) override; + int32_t StartAuth(int32_t code, std::shared_ptr authManager) override; int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) override; private: diff --git a/ext/pin_auth/include/pin_auth_ui.h b/ext/pin_auth/include/pin_auth_ui.h index f8910cba2..61575797f 100644 --- a/ext/pin_auth/include/pin_auth_ui.h +++ b/ext/pin_auth/include/pin_auth_ui.h @@ -18,6 +18,7 @@ #include +#include "dm_auth_manager.h" #include "dm_ability_manager.h" namespace OHOS { @@ -25,8 +26,8 @@ namespace DistributedHardware { class PinAuthUi { public: PinAuthUi(); - int32_t ShowPinDialog(); - int32_t InputPinDialog(std::shared_ptr dmAbilityManager); + int32_t ShowPinDialog(int32_t code); + int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); private: int32_t StartFaUiService(std::shared_ptr dmAbilityManager); diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 5e123b0c5..138abc56f 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -33,15 +33,14 @@ PinAuth::~PinAuth() { } -int32_t PinAuth::ShowAuthInfo() +int32_t PinAuth::ShowAuthInfo(int32_t code) { - return pinAuthUi_->ShowPinDialog(); + return pinAuthUi_->ShowPinDialog(code); } -int32_t PinAuth::StartAuth(std::shared_ptr dmAbilityManager) +int32_t PinAuth::StartAuth(int32_t code, std::shared_ptr authManager) { - times_ = 0; - return pinAuthUi_->InputPinDialog(dmAbilityManager); + return pinAuthUi_->InputPinDialog(code, authManager); } int32_t PinAuth::VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp index 691e50052..5b08ed3bd 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/pin_auth_ui.cpp @@ -18,6 +18,8 @@ #include "dm_ability_manager.h" #include "dm_constants.h" #include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" namespace OHOS { namespace DistributedHardware { @@ -26,18 +28,53 @@ PinAuthUi::PinAuthUi() LOGI("AuthUi constructor"); } -int32_t PinAuthUi::ShowPinDialog() +int32_t PinAuthUi::ShowPinDialog(int32_t code) { + LOGI("ShowPinDialog start"); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = code; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "show_pin_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, + ACE_Y, + ACE_WIDTH, + ACE_HEIGHT, + [](int32_t id, const std::string& event, const std::string& params) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + }); + LOGI("ShowConfigDialog end"); return DM_OK; } -int32_t PinAuthUi::InputPinDialog(std::shared_ptr dmAbilityManager) +int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) { - if (dmAbilityManager == nullptr) { - LOGE("PinAuthUi::dmAbilityManager is null"); - return DM_FAILED; - } - return StartFaUiService(dmAbilityManager); + LOGI("InputPinDialog start"); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = code; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "input_pin_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, + ACE_Y, + ACE_WIDTH, + ACE_HEIGHT, + [authManager](int32_t id, const std::string& event, const std::string& params) { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authManager->VerifyPinAuthAuthentication(params.c_str()); + }); + LOGI("ShowConfigDialog end"); + return DM_OK; } int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager) diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 8d9799369..f4359edcc 100644 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -57,6 +57,7 @@ if (defined(ohos_lite)) { "//base/startup/syspara_lite/interfaces/kits", "//base/startup/syspara_lite/adapter/native/syspara/include", "//third_party/json/include", + "//third_party/flutter/skia", ] sources = [ @@ -85,12 +86,15 @@ if (defined(ohos_lite)) { ] deps = [ + "${common_path}/include/dialog_ui/js:dialog_js_files_etc", "${innerkits_path}/native_cpp:devicemanagersdk", "${utils_path}:devicemanagerutils", "//base/security/deviceauth/services:deviceauth_sdk", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/aafwk/standard/services/abilitymgr:abilityms", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", + "//foundation/windowmanager/wm:libwm", "//utils/native/base:utils", ] diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index 5783f1112..43c486511 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -20,11 +20,12 @@ namespace OHOS { namespace DistributedHardware { +class DmAuthManager; class IAuthentication { public: virtual ~IAuthentication() = default; - virtual int32_t ShowAuthInfo() = 0; - virtual int32_t StartAuth(std::shared_ptr dmAbilityManager) = 0; + virtual int32_t ShowAuthInfo(int32_t code) = 0; + virtual int32_t StartAuth(int32_t code, std::shared_ptr authManager) = 0; virtual int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) = 0; }; diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 2ea42c9b7..6b0298ec9 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -129,6 +129,7 @@ public: const std::string &extra); int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId); int32_t VerifyAuthentication(const std::string &authParam); + void VerifyPinAuthAuthentication(const std::string &action); void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result); void OnSessionClosed(int32_t sessionId); void OnDataReceived(int32_t sessionId, std::string message); diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index cde8a2e3c..2c8dcb03a 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -24,6 +24,9 @@ #include "dm_random.h" #include "nlohmann/json.hpp" #include "parameter.h" +#include "ui_service_mgr_client.h" +#include "dialog_callback_stub.h" +#include "dialog_callback.h" namespace OHOS { namespace DistributedHardware { @@ -97,7 +100,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au } if (extra.empty()) { LOGE("AuthenticateDevice failed, extra is empty"); - listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_INPUT_PARA_EMPTY); + listener_->OnAuthResult(pkgName, deviceId, "", AuthState::AUTH_REQUEST_INIT, DM_AUTH_BUSINESS_BUSY); return DM_INPUT_PARA_EMPTY; } @@ -652,27 +655,55 @@ int32_t DmAuthManager::GetPinCode() void DmAuthManager::ShowConfigDialog() { - std::shared_ptr authUi_ = std::make_shared(); - dmAbilityMgr_ = std::make_shared(); - authUi_->ShowConfirmDialog(dmAbilityMgr_); + LOGI("ShowConfigDialog start"); + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; + jsonObj[TAG_TOKEN] = authResponseContext_->token; + jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + std::shared_ptr authMgr_ = shared_from_this(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "config_dialog_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, + ACE_Y, + ACE_WIDTH, + ACE_HEIGHT, + [authMgr_](int32_t id, const std::string& event, const std::string& params) { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authMgr_->StartAuthProcess(atoi(params.c_str())); + }); + LOGI("ShowConfigDialog end"); } void DmAuthManager::ShowAuthInfoDialog() { - return; + LOGI("DmAuthManager::ShowAuthInfoDialog start"); + authResponseContext_->code = GeneratePincode(); + std::shared_ptr ptr; + if (authenticationMap_.find(1) == authenticationMap_.end()) { + LOGE("DmAuthManager::authenticationMap_ is null"); + return; + } + ptr = authenticationMap_[1]; + LOGI("ShowAuthInfoDialog code:%d", authResponseContext_->code); + ptr->ShowAuthInfo(authResponseContext_->code); } void DmAuthManager::ShowStartAuthDialog() { LOGI("DmAuthManager::ShowStartAuthDialog start"); - dmAbilityMgr_ = std::make_shared(); std::shared_ptr ptr; if (authenticationMap_.find(1) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return; } ptr = authenticationMap_[1]; - ptr->StartAuth(dmAbilityMgr_); + ptr->StartAuth(authResponseContext_->code, shared_from_this()); } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) @@ -737,5 +768,20 @@ void DmAuthManager::UserSwitchEventCallback (void) } } } + +void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) +{ + LOGI("DmAuthManager::VerifyPinAuthAuthentication"); + timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + if (action == "0") { + authRequestState_->TransitionTo(std::make_shared()); + } + if (action == "1") { + authRequestContext_->reason = DM_AUTH_INPUT_FAILED; + authResponseContext_->state = authRequestState_->GetStateType(); + authRequestState_->TransitionTo(std::make_shared()); + } + LOGI("DmAuthManager::VerifyAuthentication complete"); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 413733922..bc012d3f3 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -443,15 +443,14 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info) return; } + if (discoveryDeviceInfoMap_.empty()) { + return; + } DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); for (auto &iter : stateCallbackMap_) { iter.second->OnDeviceOnline(iter.first, dmDeviceInfo); } - - if (discoveryDeviceInfoMap_.empty()) { - return; - } // remove the discovery node map uint8_t udid[UDID_BUF_LEN] = {0}; int32_t ret = diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index c648ff9b5..2aa55bf3f 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -37,9 +37,6 @@ void AuthMessageProcessorTest::TearDownTestCase() } namespace { -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr listener = std::make_shared(); -std::shared_ptr hiChainConnector_ = std::make_shared(); /** * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001 * @tc.desc: 1 set cryptoAdapter_ to null @@ -50,8 +47,10 @@ std::shared_ptr hiChainConnector_ = std::make_shared data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr hiChainConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -74,6 +73,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes jsonObject[TAG_LOCAL_DEVICE_ID] = authMessageProcessor->authResponseContext_->localDeviceId; std::string str2 = jsonObject.dump(); ASSERT_EQ(str1, str2); + sleep(15); } /** @@ -84,9 +84,10 @@ HWTEST_F(AuthMessageProcessorTest, CreateNegotiateMessage_001, testing::ext::Tes */ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr hiChainConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authRequestContext_ = std::make_shared(); nlohmann::json jsona; @@ -101,6 +102,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::Tes std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); + sleep(15); } /** @@ -111,9 +113,10 @@ HWTEST_F(AuthMessageProcessorTest, CreateSyncGroupMessage_001, testing::ext::Tes */ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr hiChainConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsona; @@ -140,6 +143,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); + sleep(15); } /** @@ -150,9 +154,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseAuthMessage_001, testing::ext:: */ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); nlohmann::json jsona; @@ -163,6 +167,7 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext std::string str1 = jsona.dump(); std::string str2 = jsonObj.dump(); ASSERT_EQ(str1, str2); + sleep(15); } /** @@ -173,9 +178,9 @@ HWTEST_F(AuthMessageProcessorTest, CreateResponseFinishMessage_001, testing::ext */ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -185,6 +190,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext: authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseResponseFinishMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -195,9 +201,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseResponseFinishMessage_001, testing::ext: */ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); nlohmann::json jsona; @@ -220,6 +226,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseAuthResponseMessage(jsona); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -230,9 +237,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthResponseMessage_001, testing::ext::T */ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); @@ -255,6 +262,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -265,9 +273,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te */ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); @@ -290,6 +298,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -300,9 +309,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -318,6 +327,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -328,9 +338,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_001, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -346,6 +356,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -356,9 +367,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_002, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -374,6 +385,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -384,9 +396,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_003, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -402,6 +414,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -412,9 +425,9 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_004, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->authResponseContext_ = std::make_shared(); @@ -430,6 +443,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::Test authMessageProcessor->SetResponseContext(authResponseContext); authMessageProcessor->ParseNegotiateMessage(jsonObj); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -440,13 +454,14 @@ HWTEST_F(AuthMessageProcessorTest, ParseNegotiateMessage_005, testing::ext::Test */ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authRequestContext = std::make_shared(); authMessageProcessor->SetRequestContext(authRequestContext); ASSERT_EQ(authMessageProcessor->authRequestContext_, authRequestContext); + sleep(15); } /** @@ -457,13 +472,14 @@ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_001, testing::ext::TestSize */ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authRequestContext = std::make_shared(); authMessageProcessor->SetRequestContext(nullptr); ASSERT_EQ(authMessageProcessor->authRequestContext_, nullptr); + sleep(15); } /** @@ -474,13 +490,14 @@ HWTEST_F(AuthMessageProcessorTest, SetRequestContext_002, testing::ext::TestSize */ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); ASSERT_EQ(authMessageProcessor->authResponseContext_, authResponseContext); + sleep(15); } /** @@ -491,13 +508,14 @@ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_001, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(nullptr); ASSERT_EQ(authMessageProcessor->authResponseContext_, nullptr); + sleep(15); } /** @@ -508,13 +526,14 @@ HWTEST_F(AuthMessageProcessorTest, SetResponseContext_002, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseContext = authMessageProcessor->GetResponseContext(); ASSERT_EQ(authResponseContext, authMessageProcessor->authResponseContext_); + sleep(15); } /** @@ -525,13 +544,14 @@ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_001, testing::ext::TestSiz */ HWTEST_F(AuthMessageProcessorTest, GetResponseContext_002, testing::ext::TestSize.Level0) { - std::shared_ptr hiChainConnector_ = std::make_shared(); - std::shared_ptr data = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr data = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authMessageProcessor = std::make_shared(data); authMessageProcessor->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseContext = authMessageProcessor->GetResponseContext(); ASSERT_NE(authResponseContext, nullptr); + sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index bf554ee3b..92cf2951f 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -41,9 +41,6 @@ std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr listener = std::make_shared(); -std::shared_ptr hiChainConnector = std::make_shared(); /** * @tc.name: AuthRequestInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null @@ -54,6 +51,9 @@ std::shared_ptr hiChainConnector = std::make_shared softbusConnector = std::make_shared(); + std::shared_ptr hiChainConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); std::shared_ptr authManager = std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); @@ -90,13 +90,15 @@ HWTEST_F(AuthRequestStateTest, SetAuthManager_002, testing::ext::TestSize.Level0 */ HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->authManager_ = authManager; int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -109,8 +111,9 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr context = std::make_shared(); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr negotiateStartTimer = std::make_shared(NEGOTIATE_TIMEOUT_TASK); @@ -123,11 +126,11 @@ HWTEST_F(AuthRequestStateTest, TransitionTo_002, testing::ext::TestSize.Level0) authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); context->sessionId = 123456; authManager->SetAuthRequestState(authRequestState); - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authRequestState->SetAuthContext(context); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); + sleep(20); } /** @@ -142,6 +145,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INIT); + sleep(15); } /** @@ -154,13 +158,15 @@ HWTEST_F(AuthRequestStateTest, GetStateType_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager = nullptr; authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -173,8 +179,9 @@ HWTEST_F(AuthRequestStateTest, Enter_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -185,6 +192,7 @@ HWTEST_F(AuthRequestStateTest, Enter_002, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -199,6 +207,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE); + sleep(15); } /** @@ -211,12 +220,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -229,9 +240,11 @@ HWTEST_F(AuthRequestStateTest, Enter_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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(); @@ -246,6 +259,7 @@ HWTEST_F(AuthRequestStateTest, Enter_004, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -260,6 +274,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NEGOTIATE_DONE); + sleep(15); } /** @@ -272,12 +287,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -290,9 +307,11 @@ HWTEST_F(AuthRequestStateTest, Enter_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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; authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -300,7 +319,6 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authManager->SetAuthRequestState(authRequestState); authRequestState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); @@ -308,6 +326,7 @@ HWTEST_F(AuthRequestStateTest, Enter_006, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -322,6 +341,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_REPLY); + sleep(15); } /** @@ -334,12 +354,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -352,9 +374,11 @@ HWTEST_F(AuthRequestStateTest, Enter_007, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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); @@ -371,6 +395,7 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -385,6 +410,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT); + sleep(15); } /** @@ -397,12 +423,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -415,12 +443,14 @@ HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -435,6 +465,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_JOIN); + sleep(15); } /** @@ -447,12 +478,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -465,8 +498,10 @@ HWTEST_F(AuthRequestStateTest, Enter_011, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + printf("1\n"); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); @@ -476,16 +511,18 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; + printf("3\n"); authRequestState->SetAuthManager(authManager); authManager->SetAuthRequestState(authRequestState); - authManager->hiChainConnector_->RegisterHiChainCallback(authManager); - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); std::shared_ptr context = std::make_shared(); + printf("4\n"); context->deviceId = "44444"; context->sessionId = 55555; authRequestState->SetAuthContext(context); + printf("5\n"); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -500,6 +537,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_NETWORK); + sleep(15); } /** @@ -512,12 +550,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_007, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -530,8 +570,10 @@ HWTEST_F(AuthRequestStateTest, Enter_013, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + printf("1\n"); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; @@ -541,11 +583,13 @@ HWTEST_F(AuthRequestStateTest, Enter_014, testing::ext::TestSize.Level0) authManager->authRequestState_ = std::make_shared(); authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authManager->SetAuthRequestState(authRequestState); + printf("3\n"); authRequestState->SetAuthManager(authManager); int32_t ret = authRequestState->Enter(); + printf("4\n"); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -560,6 +604,7 @@ HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) std::shared_ptr authRequestState = std::make_shared(); int32_t ret = authRequestState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_REQUEST_FINISH); + sleep(15); } /** @@ -572,12 +617,14 @@ HWTEST_F(AuthRequestStateTest, GetStateType_008, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authRequestState->SetAuthManager(nullptr); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -590,9 +637,11 @@ HWTEST_F(AuthRequestStateTest, Enter_015, testing::ext::TestSize.Level0) */ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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); @@ -610,6 +659,7 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) authRequestState->SetAuthContext(context); int32_t ret = authRequestState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index 625f34443..ace33012d 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -37,9 +37,6 @@ void AuthResponseStateTest::TearDownTestCase() } namespace { -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr listener = std::make_shared(); -std::shared_ptr hiChainConnector = std::make_shared(); /** * @tc.name: AuthResponseInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null @@ -50,12 +47,14 @@ std::shared_ptr hiChainConnector = std::make_shared authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 1); + sleep(15); } /** @@ -72,6 +71,7 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_002, testing::ext::TestSize.Level authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->authManager_.use_count(); ASSERT_EQ(ret, 0); + sleep(15); } /** @@ -84,13 +84,15 @@ HWTEST_F(AuthResponseStateTest, SetAuthManager_002, testing::ext::TestSize.Level */ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->authManager_ = authManager; int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -103,8 +105,9 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_001, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr context = std::make_shared(); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseState_ = std::make_shared(); @@ -115,6 +118,7 @@ HWTEST_F(AuthResponseStateTest, TransitionTo_002, testing::ext::TestSize.Level0) authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->TransitionTo(std::make_shared()); ASSERT_EQ(ret, DM_OK); + sleep(20); } /** @@ -129,6 +133,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_001, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_INIT); + sleep(15); } /** @@ -143,6 +148,7 @@ HWTEST_F(AuthResponseStateTest, Enter_001, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -157,6 +163,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_002, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_NEGOTIATE); + sleep(15); } /** @@ -169,13 +176,15 @@ HWTEST_F(AuthResponseStateTest, GetStateType_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager = nullptr; authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -188,9 +197,11 @@ HWTEST_F(AuthResponseStateTest, Enter_002, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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(); @@ -200,7 +211,6 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) authManager->authResponseContext_->localDeviceId = "222"; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); authResponseState->SetAuthManager(authManager); std::shared_ptr context = std::make_shared(); context->deviceId = "123456"; @@ -222,6 +232,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_003, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_CONFIRM); + sleep(15); } /** @@ -234,12 +245,14 @@ HWTEST_F(AuthResponseStateTest, GetStateType_003, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_004, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -252,12 +265,14 @@ HWTEST_F(AuthResponseStateTest, Enter_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_005, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -272,6 +287,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_004, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_GROUP); + sleep(15); } /** @@ -284,12 +300,14 @@ HWTEST_F(AuthResponseStateTest, GetStateType_004, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -302,14 +320,19 @@ HWTEST_F(AuthResponseStateTest, Enter_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_007, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + printf("1\n"); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); + printf("2\n"); authResponseState->SetAuthManager(authManager); + printf("3\n"); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -324,6 +347,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_005, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_SHOW); + sleep(15); } /** @@ -336,12 +360,14 @@ HWTEST_F(AuthResponseStateTest, GetStateType_005, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_008, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -354,12 +380,14 @@ HWTEST_F(AuthResponseStateTest, Enter_008, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } /** @@ -374,6 +402,7 @@ HWTEST_F(AuthResponseStateTest, GetStateType_006, testing::ext::TestSize.Level0) std::shared_ptr authResponseState = std::make_shared(); int32_t ret = authResponseState->GetStateType(); ASSERT_EQ(ret, AuthState::AUTH_RESPONSE_FINISH); + sleep(15); } /** @@ -386,12 +415,14 @@ HWTEST_F(AuthResponseStateTest, GetStateType_006, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_010, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authResponseState->SetAuthManager(nullptr); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_FAILED); + sleep(15); } /** @@ -404,8 +435,9 @@ HWTEST_F(AuthResponseStateTest, Enter_010, testing::ext::TestSize.Level0) */ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager->authRequestState_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); @@ -425,6 +457,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authResponseState->SetAuthContext(context); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); + sleep(15); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 28256c67f..3a995051d 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -337,6 +337,26 @@ HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestS int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); EXPECT_EQ(ret, DM_NOT_INIT); } + +/** + * @tc.name: VerifyAuthentication_002 + * @tc.desc:Set intFlag for VerifyAuthentication to true and set authParam = "jdjjjj",The return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string authParam = "jdjjjj"; + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener_ = std::make_shared(); + DeviceManagerService::GetInstance().authMgr_ = + std::make_shared(softbusConnector, listener_, nullptr); + std::shared_ptr inputStartTimer = std::make_shared(INPUT_TIMEOUT_TASK); + DeviceManagerService::GetInstance().authMgr_->timerMap_[INPUT_TIMEOUT_TASK] = inputStartTimer; + int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); + EXPECT_EQ(ret, DM_FAILED); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 8f85f3dd6..3cef42c3f 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -63,7 +63,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceStateChange_001, testing::ext std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); int32_t dmState = pReq->GetDeviceState(); - EXPECT_EQ(0, dmState); + EXPECT_EQ(1, dmState); } /** @@ -83,7 +83,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnAuthResult_001, testing::ext::TestS listener_->OnAuthResult(pkgName, deviceId, token, status, reason); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); - std::string ret = pReq->GetPkgName(); + std ::string ret = pReq->GetPkgName(); EXPECT_EQ(ret, pkgName); } @@ -104,7 +104,7 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnVerifyAuthResult_001, testing::ext: listener_->OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); - std::string ret = pReq->GetDeviceId(); + std ::string ret = pReq->GetDeviceId(); EXPECT_EQ(ret, deviceId); } } // namespace diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 65f845406..651f58aff 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -44,10 +44,6 @@ std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; -std::shared_ptr softbusConnector = std::make_shared(); -std::shared_ptr listener = std::make_shared(); -std::shared_ptr hiChainConnector_ = std::make_shared(); - /** * @tc.name: DmAuthManager::UnAuthenticateDevice_001 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_ FAILED @@ -56,8 +52,9 @@ std::shared_ptr hiChainConnector_ = std::make_shared authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr sessionSession = std::shared_ptr(); std::shared_ptr authRequestContext = std::make_shared(); std::string pkgName = ""; @@ -74,8 +71,9 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -83,7 +81,7 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSiz authManager->authResponseContext_ = nullptr; authManager->SetAuthRequestState(authRequestState); int32_t ret = authManager->HandleAuthenticateTimeout(); - ASSERT_EQ(ret, DM_OK); + ASSERT_EQ(ret, DM_FAILED); } /** @@ -94,8 +92,9 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSiz */ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -113,8 +112,9 @@ HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSiz */ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr sessionSession = std::shared_ptr(); std::shared_ptr authRequestContext = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); @@ -133,17 +133,17 @@ HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); int32_t action = 0; - authManager->StartAuthProcess(action); - bool ret = authManager->authRequestContext_->deviceName.empty(); - ASSERT_EQ(ret, true); + int32_t ret = authManager->StartAuthProcess(action); + ASSERT_EQ(ret, DM_FAILED); } /** @@ -154,8 +154,9 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); @@ -163,7 +164,6 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->SetAuthResponseState(authResponseState); authManager->authResponseContext_->sessionId = 111; - authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); int32_t action = 1; int32_t ret = authManager->StartAuthProcess(action); ASSERT_EQ(ret, DM_OK); @@ -177,8 +177,9 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); authManager->authResponseContext_ = std::make_shared(); @@ -200,11 +201,14 @@ HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); 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); + authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); nlohmann::json jsonObject; @@ -213,8 +217,12 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; + jsonObject[TAG_GROUP_ID] = authManager->authResponseContext_->groupId; + jsonObject[TAG_GROUP_NAME] = authManager->authResponseContext_->groupName; + jsonObject[PIN_CODE_KEY] = authManager->authResponseContext_->code; + jsonObject[TAG_REQUEST_ID] = authManager->authResponseContext_->requestId; + jsonObject[TAG_DEVICE_ID] = authManager->authResponseContext_->deviceId; std::string deviceId = "44444"; - authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); int32_t ret = authManager->AddMember(deviceId); ASSERT_EQ(ret, DM_OK); @@ -229,8 +237,9 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authRequestState = std::make_shared(); std::shared_ptr authenticateStartTimer = std::make_shared(AUTHENTICATE_TIMEOUT_TASK); authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = authenticateStartTimer; @@ -251,8 +260,9 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) */ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); std::shared_ptr authResponseState = std::make_shared(); authManager->authResponseState_ = std::make_shared(); authManager->SetAuthResponseState(authResponseState); @@ -268,9 +278,11 @@ HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Lev */ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) { - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr softbusConnector = std::make_shared(); + std::shared_ptr listener = std::make_shared(); + std::shared_ptr authManager = std::make_shared(softbusConnector, listener, nullptr); authManager->authResponseContext_ = std::make_shared(); + ; int32_t ret = authManager->GetPinCode(); ASSERT_EQ(ret, authManager->authResponseContext_->code); } diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp index ae46c2514..3e1ea6e67 100644 --- a/test/unittest/UTTest_hichain_connector.cpp +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -43,9 +43,7 @@ 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_); +std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector, listener_, nullptr); /** * @tc.name: CreateGroup_001 @@ -263,7 +261,8 @@ HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Leve HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) { std::shared_ptr hichainConnector = std::make_shared(); - int ret = hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); + int ret = + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr_)); EXPECT_EQ(ret, DM_OK); } diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index 8d14ff0e1..b0d6e66a3 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -40,9 +40,7 @@ namespace { std::shared_ptr softbusSession = 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_, nullptr); /** * @tc.name: OpenAuthSession_001 -- Gitee