From 7724ab42aa9a4db64d93e0cbab0bd325c0070632 Mon Sep 17 00:00:00 2001 From: "weibo.wang" Date: Wed, 16 Mar 2022 16:42:27 +0800 Subject: [PATCH] UTTest Change-Id: I1f7a56ef3d2647b9cfbea812cd353106995f0a67 Signed-off-by: weibo.wang --- .../dependency/softbus/softbus_connector.h | 4 + test/unittest/BUILD.gn | 92 +- .../UTTest_auth_message_processor.cpp | 31 + test/unittest/UTTest_auth_request_state.cpp | 76 +- test/unittest/UTTest_auth_response_state.cpp | 37 + test/unittest/UTTest_device_manager_impl.cpp | 2513 ++++++++++ test/unittest/UTTest_device_manager_impl.h | 74 + .../unittest/UTTest_device_manager_notify.cpp | 4078 +++++++++++++++++ test/unittest/UTTest_device_manager_notify.h | 104 + .../UTTest_dm_device_state_manager.cpp | 14 +- test/unittest/UTTest_dm_discovery_manager.cpp | 10 + test/unittest/UTTest_hichain_connector.cpp | 477 ++ test/unittest/UTTest_hichain_connector.h | 46 + test/unittest/UTTest_ipc_client_manager.cpp | 46 +- test/unittest/UTTest_ipc_client_manager.h | 10 + .../UTTest_ipc_client_server_proxy.cpp | 69 + .../unittest/UTTest_ipc_client_server_proxy.h | 38 + test/unittest/UTTest_ipc_client_stub.cpp | 11 +- test/unittest/UTTest_ipc_cmd_register.cpp | 943 ++++ test/unittest/UTTest_ipc_cmd_register.h | 45 + test/unittest/UTTest_ipc_server_stub.cpp | 4 +- test/unittest/UTTest_pin_auth.cpp | 266 ++ test/unittest/UTTest_pin_auth.h | 34 + test/unittest/UTTest_pin_auth_ui.cpp | 109 + test/unittest/UTTest_pin_auth_ui.h | 34 + test/unittest/UTTest_softbus_connector.cpp | 453 +- test/unittest/UTTest_softbus_session.cpp | 21 +- test/unittest/mock/device_auth.h | 8 +- test/unittest/mock/mock_ipc_client_proxy.h | 2 + test/unittest/mock/softbus_bus_center.cpp | 22 +- 30 files changed, 9608 insertions(+), 63 deletions(-) create mode 100644 test/unittest/UTTest_device_manager_impl.cpp create mode 100644 test/unittest/UTTest_device_manager_impl.h create mode 100644 test/unittest/UTTest_device_manager_notify.cpp create mode 100644 test/unittest/UTTest_device_manager_notify.h create mode 100644 test/unittest/UTTest_hichain_connector.cpp create mode 100644 test/unittest/UTTest_hichain_connector.h create mode 100644 test/unittest/UTTest_ipc_client_server_proxy.cpp create mode 100644 test/unittest/UTTest_ipc_client_server_proxy.h create mode 100644 test/unittest/UTTest_ipc_cmd_register.cpp create mode 100644 test/unittest/UTTest_ipc_cmd_register.h create mode 100644 test/unittest/UTTest_pin_auth.cpp create mode 100644 test/unittest/UTTest_pin_auth.h create mode 100644 test/unittest/UTTest_pin_auth_ui.cpp create mode 100644 test/unittest/UTTest_pin_auth_ui.h diff --git a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h index a957f42a8..be6150065 100644 --- a/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h +++ b/services/devicemanagerservice/include/dependency/softbus/softbus_connector.h @@ -32,6 +32,10 @@ namespace OHOS { namespace DistributedHardware { +void DeviceOnLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo); +void DeviceOffLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo); class SoftbusConnector { public: static void OnPublishSuccess(int32_t publishId); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9325d03ef..45e29ee01 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -28,17 +28,66 @@ group("unittest") { ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", ":UTTest_dm_discovery_manager", + ":UTTest_softbus_connector", + ":UTTest_softbus_session", ":UTTest_ipc_client_manager", ":UTTest_ipc_client_proxy", ":UTTest_ipc_client_stub", ":UTTest_ipc_server_client_proxy", ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", - ":UTTest_softbus_connector", - ":UTTest_softbus_session", + ":UTTest_device_manager_notify", + ":UTTest_hichain_connector", + ":UTTest_device_manager_impl", + ":UTTest_ipc_client_server_proxy", + ":UTTest_ipc_cmd_register", + ":UTTest_pin_auth", ] } +## UnitTest UTTest_ipc_client_server_proxy {{{ +ohos_unittest("UTTest_ipc_client_server_proxy") { + module_out_path = module_out_path + + sources = [ "UTTest_ipc_client_server_proxy.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_ipc_client_server_proxy }}} + +## UnitTest UTTest_pin_auth {{{ +ohos_unittest("UTTest_pin_auth") { + module_out_path = module_out_path + + sources = [ "UTTest_pin_auth.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_pin_auth }}} + +## UnitTest UTTest_pin_auth_ui {{{ +ohos_unittest("UTTest_pin_auth_ui") { + module_out_path = module_out_path + + sources = [ "UTTest_pin_auth_ui.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_pin_auth_ui }}} +## UnitTest UTTest_ipc_cmd_register {{{ +ohos_unittest("UTTest_ipc_cmd_register") { + module_out_path = module_out_path + + sources = [ "UTTest_ipc_cmd_register.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_ipc_cmd_register }}} + ## UnitTest device_manager_impl_test {{{ ohos_unittest("device_manager_impl_test") { module_out_path = module_out_path @@ -87,9 +136,23 @@ ohos_unittest("UTTest_dm_device_info_manager") { ohos_unittest("UTTest_softbus_connector") { module_out_path = module_out_path - sources = [ "UTTest_softbus_connector.cpp" ] + sources = [ + "${services_path}/src/adapter/standard/dm_adapter_manager.cpp", + "${services_path}/src/config/dm_config_manager.cpp", + "${services_path}/src/dependency/hichain/hichain_connector.cpp", + "${services_path}/src/dependency/multipleuser/multiple_user_connector.cpp", + "${services_path}/src/dependency/softbus/softbus_connector.cpp", + "${services_path}/src/dependency/softbus/softbus_session.cpp", + "${services_path}/src/dependency/timer/dm_timer.cpp", + "${services_path}/src/device_manager_service_listener.cpp", + "${services_path}/src/devicestate/dm_device_state_manager.cpp", + "${services_path}/src/discovery/dm_discovery_manager.cpp", + "//foundation/distributedhardware/devicemanager/test/unittest/mock/ipc_server_listener.cpp", + "//foundation/distributedhardware/devicemanager/test/unittest/mock/parameter.cpp", + "UTTest_softbus_connector.cpp" + ] - deps = [ ":device_manager_test_common" ] + deps = [ ":device_manager_test" ] } ## UnitTest UTTest_softbus_connector }}} @@ -116,6 +179,8 @@ ohos_unittest("UTTest_ipc_client_manager") { ## UnitTest UTTest_ipc_client_manager }}} +## UnitTest UTTest_ipc_client_manager }}} + ## UnitTest UTTest_ipc_client_proxy {{{ ohos_unittest("UTTest_ipc_client_proxy") { module_out_path = module_out_path @@ -134,6 +199,7 @@ ohos_unittest("UTTest_ipc_client_stub") { sources = [ "UTTest_ipc_client_stub.cpp" ] deps = [ ":device_manager_test_common" ] + } ## UnitTest UTTest_ipc_client_stub }}} @@ -145,6 +211,7 @@ ohos_unittest("UTTest_ipc_server_client_proxy") { sources = [ "UTTest_ipc_server_client_proxy.cpp" ] deps = [ ":device_manager_test_common" ] + } ## UnitTest UTTest_ipc_server_client_proxy }}} @@ -156,6 +223,7 @@ ohos_unittest("UTTest_ipc_server_listener") { sources = [ "UTTest_ipc_server_listener.cpp" ] deps = [ ":device_manager_test_common" ] + } ## UnitTest UTTest_ipc_server_listener }}} @@ -167,6 +235,7 @@ ohos_unittest("UTTest_ipc_server_stub") { sources = [ "UTTest_ipc_server_stub.cpp" ] deps = [ ":device_manager_test_common" ] + } ## UnitTest UTTest_ipc_server_stub }}} @@ -204,17 +273,6 @@ ohos_unittest("UTTest_device_manager_notify") { ## UnitTest UTTest_device_manager_notify }}} -## UnitTest UTTest_ipc_client_server_proxy {{{ -ohos_unittest("UTTest_ipc_client_server_proxy") { - module_out_path = module_out_path - - sources = [ "UTTest_ipc_client_server_proxy.cpp" ] - - deps = [ ":device_manager_test_common" ] -} - -## UnitTest UTTest_ipc_client_server_proxy }}} - ## UnitTest UTTest_dm_device_state_manager {{{ ohos_unittest("UTTest_dm_device_state_manager") { module_out_path = module_out_path @@ -375,6 +433,7 @@ config("device_manager_test_common_public_config") { "//base/security/deviceauth/interfaces/innerkits", "${services_path}/include/ability", "${services_path}/include/config", + "${ext_path}/pin_auth/include", ] cflags = [ @@ -403,6 +462,9 @@ ohos_static_library("device_manager_test_common") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservice", "${utils_path}:devicemanagerutils", + "${ext_path}/pin_auth:devicemanagerext_pin_auth", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", + "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index eaf46bd49..43d1011e7 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -40,6 +40,37 @@ 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::AuthMessageProcessor_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr Test = + std::make_shared(softbusConnector, listener, hiChainConnector_); + ASSERT_NE(Test, nullptr); +} + +/** + * @tc.name: AuthMessageProcessor::AuthMessageProcessor_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::AuthMessageProcessor_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthMessageProcessorTest, AuthMessageProcessor_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr Test = + std::make_shared(softbusConnector, listener, hiChainConnector_); + Test.reset(); + EXPECT_EQ(Test, nullptr); +} + /** * @tc.name: AuthMessageProcessor::CreateNegotiateMessage_001 * @tc.desc: 1 set cryptoAdapter_ to null diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index 310d859d3..e391e7b37 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -45,13 +45,87 @@ std::shared_ptr softbusConnector = std::make_shared listener = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); /** - * @tc.name: AuthRequestInitState::SetAuthManager_001 + * @tc.name: AuthResponseInitState::Leave_001 + * @tc.desc: 1 set authManager not null + * 2 call AuthResponseInitState::Leave with authManager != null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthRequestStateTest, Leave_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr authRequestState = std::make_shared(); + int32_t ret = authRequestState->Leave(); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: AuthRequestInitState::SetAuthContext_001 * @tc.desc: 1 set authManager not null * 2 call AuthRequestInitState::SetAuthManager with authManager != null * 3 check ret is authResponseState->authManager_.use_count() * @tc.type: FUNC * @tc.require: AR000GHSJK */ +HWTEST_F(AuthRequestStateTest, SetAuthContext_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr context = std::make_shared(); + std::shared_ptr authRequestState = std::make_shared(); + authRequestState->SetAuthContext(context); + int32_t ret = authRequestState->context_.use_count(); + authRequestState->context_.reset(); + ASSERT_EQ(ret, 2); +} + +/** + * @tc.name: AuthRequestInitState::SetAuthManager_002 + * @tc.desc: 1 set authManager to null + * 2 call AuthRequestInitState::SetAuthManager with authManager = null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthRequestStateTest, SetAuthContext_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authRequestState = std::make_shared(); + authRequestState->SetAuthContext(nullptr); + int32_t ret = authRequestState->authManager_.use_count(); + authRequestState->authManager_.reset(); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: AuthRequestInitState::GetAuthContext_001 + * @tc.desc: 1 set authManager not null + * 2 call AuthRequestInitState::GetAuthContext with authManager != null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthRequestStateTest, GetAuthContext_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr context = std::make_shared(); + std::shared_ptr authRequestState = std::make_shared(); + authRequestState->GetAuthContext(); + int32_t ret = authRequestState->context_.use_count(); + authRequestState->context_.reset(); + ASSERT_EQ(ret, 0); +} + +/** + * @tc.name: AuthRequestInitState::SetAuthManager_001 + * @tc.desc: 1 set authManager not null + * 2 call AuthRequestInitState::GetAuthContext with authManager != null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ HWTEST_F(AuthRequestStateTest, SetAuthManager_001, testing::ext::TestSize.Level0) { std::shared_ptr authManager = diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index e3db904f1..52033d51c 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -40,6 +40,43 @@ 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::Leave_001 + * @tc.desc: 1 set authManager not null + * 2 call AuthResponseInitState::Leave with authManager != null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthResponseStateTest, Leave_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr authResponseState = std::make_shared(); + int32_t ret = authResponseState->Leave(); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: AuthRequestInitState::GetAuthContext_001 + * @tc.desc: 1 set authManager not null + * 2 call AuthRequestInitState::GetAuthContext with authManager != null + * 3 check ret is authResponseState->authManager_.use_count() + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(AuthResponseStateTest, GetAuthContext_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); + std::shared_ptr authResponseState = std::make_shared(); + std::shared_ptr context = std::make_shared(); + authResponseState->GetAuthContext(); + int32_t ret = authResponseState->context_.use_count(); + authResponseState->context_.reset(); + ASSERT_EQ(ret, 0); +} + /** * @tc.name: AuthResponseInitState::SetAuthManager_001 * @tc.desc: 1 set authManager not null diff --git a/test/unittest/UTTest_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp new file mode 100644 index 000000000..5d8c1b22a --- /dev/null +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -0,0 +1,2513 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_device_manager_impl.h" +#include "dm_device_info.h" + +#include +#include "device_manager_impl.h" +#include "device_manager_notify.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_get_dmfaparam_rsp.h" +#include "ipc_get_info_by_network_req.h" +#include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_local_device_info_rsp.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_req.h" +#include "ipc_rsp.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_skeleton.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_unauthenticate_device_req.h" +#include "ipc_verify_authenticate_req.h" +#include "securec.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceManagerImplTest::SetUp() +{ +} + +void DeviceManagerImplTest::TearDown() +{ +} + +void DeviceManagerImplTest::SetUpTestCase() +{ +} + +void DeviceManagerImplTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: InitDeviceManager_001 + * @tc.desc: 1. call DeviceManagerImpl::InitDeviceManager with packName = null, dmInitCallback = nullprt + * 2. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_001, testing::ext::TestSize.Level0) +{ + // 1. call DeviceManagerImpl::InitDeviceManager with packName = null, dmInitCallback = nullprt + std::string packName = ""; + std::shared_ptr dmInitCallback = nullptr; + int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, dmInitCallback); + // 2. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: InitDeviceManager_002 + * @tc.desc: 1. set packName not null + * set dmInitCallback not null + * 2. MOCK IpcClientProxy Init return DM_OK + * 3. call DeviceManagerImpl::InitDeviceManager with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(); + //2.MOCK IpcClientProxy Init return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,Init(testing::_)).Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::InitDeviceManager with parameter + int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, callback); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: InitDeviceManager_003 + * @tc.desc: 1. set packName not null + * set dmInitCallback not null + * 2. MOCK IpcClientProxy Init return DM_INIT_FAILED + * 3. call DeviceManagerImpl::InitDeviceManager with parameter + * 4. check ret is DM_INIT_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(); + //2.MOCK IpcClientProxy Init return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,Init(testing::_)).Times(1).WillOnce(testing::Return(DM_INIT_FAILED)); + // 3. call DeviceManagerImpl::InitDeviceManager with parameter + int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, callback); + // 4. check ret is DM_INIT_FAILED + ASSERT_EQ(ret, DM_INIT_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: InitDeviceManager_004 + * @tc.desc: 1. call DeviceManagerImpl::InitDeviceManager with packName not null, dmInitCallback = nullprt + * 2. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_004, testing::ext::TestSize.Level0) +{ + // 1. call DeviceManagerImpl::InitDeviceManager with packName not null, dmInitCallback = nullprt + std::string packName = "com.ohos.test"; + std::shared_ptr callback = nullptr; + int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, callback); + // 2. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: InitDeviceManager_005 + * @tc.desc: 1. call DeviceManagerImpl::InitDeviceManager with packName not null, dmInitCallback = nullprt + * 2. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, InitDeviceManager_005, testing::ext::TestSize.Level0) +{ + // 1. call DeviceManagerImpl::InitDeviceManager with packName not null, dmInitCallback = nullprt + std::string packName = ""; + std::shared_ptr callback = std::make_shared();; + int32_t ret= DeviceManager::GetInstance().InitDeviceManager(packName, callback); + // 2. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnInitDeviceManager_001 + * @tc.desc: 1. call DeviceManagerImpl::InitDeviceManager with packName not null, dmInitCallback = nullprt + * 2. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager_001, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = ""; + // 2. call DeviceManagerImpl::InitDeviceManager with parameter + int32_t ret= DeviceManager::GetInstance().UnInitDeviceManager(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnInitDeviceManager_002 + * @tc.desc: 1. set packName not null + * 2. MOCK IpcClientProxy UnInit return DM_UNINIT_FAILED + * 3. call DeviceManagerImpl::UnInitDeviceManager with parameter + * 4. check ret is DM_UNINIT_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // 2. call DeviceManagerImpl::InitDeviceManager with parameter + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,UnInit(testing::_)).Times(1).WillOnce(testing::Return(DM_UNINIT_FAILED)); + int32_t ret= DeviceManager::GetInstance().UnInitDeviceManager(packName); + // 3. check ret is DM_UNINIT_FAILED + ASSERT_EQ(ret, DM_UNINIT_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnInitDeviceManager_003 + * @tc.desc: 1. set packName not null + * 2. MOCK IpcClientProxy UnInit return DM_OK + * 3. call DeviceManagerImpl::UnInitDeviceManager with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // 2. call DeviceManagerImpl::InitDeviceManager with parameter + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,UnInit(testing::_)).Times(1).WillOnce(testing::Return(DM_OK)); + int32_t ret= DeviceManager::GetInstance().UnInitDeviceManager(packName); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnInitDeviceManager_004 + * @tc.desc: 1. set packName not null + * 2. MOCK IpcClientProxy UnInit return DM_INIT_FAILED + * 3. call DeviceManagerImpl::UnInitDeviceManager with parameter + * 4. check ret is DM_UNINIT_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager_004, testing::ext::TestSize.Level0) +{ + // 1. set packNamen not null + std::string packName = "com.ohos.test"; + // 2. call DeviceManagerImpl::InitDeviceManager with parameter + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,UnInit(testing::_)).Times(1).WillOnce(testing::Return(DM_INIT_FAILED)); + int32_t ret= DeviceManager::GetInstance().UnInitDeviceManager(packName); + // 3. check ret is DM_UNINIT_FAILED + ASSERT_EQ(ret, DM_UNINIT_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnInitDeviceManager_005 + * @tc.desc: 1. set packName not null + * 2. MOCK IpcClientProxy UnInit return DM_INIT_FAILED + * 3. call DeviceManagerImpl::UnInitDeviceManager with parameter + * 4. check ret is DM_UNINIT_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnInitDeviceManager_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // 2. call DeviceManagerImpl::InitDeviceManager with parameter + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,UnInit(testing::_)).Times(1).WillOnce(testing::Return(DM_INIT_FAILED)); + int32_t ret= DeviceManager::GetInstance().UnInitDeviceManager(packName); + // 3. check ret is DM_UNINIT_FAILED + ASSERT_EQ(ret, DM_UNINIT_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetTrustedDeviceList_001 + * @tc.desc: 1. set packName null + * set extra null + * set deviceList null + * 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra = ""; + // set deviceList null + std::vector deviceList; + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: GetTrustedDeviceList_002 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_IPC_SEND_REQUEST_FAILED + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra = ""; + // set deviceList null + std::vector deviceList; + // 2. MOCK IpcClientProxy SendRequest return DM_IPC_SEND_REQUEST_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_IPC_SEND_REQUEST_FAILED)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetTrustedDeviceList_003 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra = ""; + // set deviceList null + std::vector deviceList; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetTrustedDeviceList_004 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra = "test"; + // set deviceList null + std::vector deviceList; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); + // 3. check ret is DEVICEMANAGER_IPC_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetTrustedDeviceList_005 + * @tc.desc: 1. set packName null + * set extra null + * set deviceList null + * 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra = "test"; + // set deviceList null + std::vector deviceList; + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetTrustedDeviceList(packName, extra, deviceList); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + + +/** + * @tc.name: GetLocalDeviceInfo_001 + * @tc.desc: 1. set packName null + * set extra null + * set deviceList null + * 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + DmDeviceInfo info; + // 2. MOCK IpcClientProxy SendRequest return DM_IPC_SEND_REQUEST_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetLocalDeviceInfo(packName, info); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetLocalDeviceInfo_002 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_IPC_SEND_REQUEST_FAILED + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + DmDeviceInfo info; + // 2. MOCK IpcClientProxy SendRequest return DM_IPC_SEND_REQUEST_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_IPC_SEND_REQUEST_FAILED)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetLocalDeviceInfo(packName, info); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetLocalDeviceInfo_003 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + DmDeviceInfo info; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetLocalDeviceInfo(packName, info); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetLocalDeviceInfo_004 + * @tc.desc: 1. set packName not null + * set extra null + * set deviceList null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set extra null + DmDeviceInfo info; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetLocalDeviceInfo(packName, info); + // 3. check ret is DEVICEMANAGER_IPC_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetLocalDeviceInfo_005 + * @tc.desc: 1. set packName null + * set extra null + * set deviceList null + * 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = ""; + // set extra null + DmDeviceInfo info; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 2. call DeviceManagerImpl::GetTrustedDeviceList with parameter + int32_t ret= DeviceManager::GetInstance().GetLocalDeviceInfo(packName, info); + // 3. check ret is DEVICEMANAGER_IPC_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + + +/** + * @tc.name: RegisterDevStateCallback_001 + * @tc.desc: 1. set packName null + * set extra null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DEVICEMANAGER_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra= ""; + // set callback nullptr + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra, callback); + // 3. check ret is DM_INVALID_VALUE + + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDevStateCallback_002 + * @tc.desc: 1. set packName not null + * set extra null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= ""; + // set callback not null + std::shared_ptr callback =std::make_shared(); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: RegisterDevStateCallback_003 + * @tc.desc: 1. set packName null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string pkgName = ""; + // set extra null + std::string extra= "test"; + // set callback nullptr + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(pkgName, extra, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDevStateCallback_004 + * @tc.desc: 1. set packName not null + * set extra not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string pkgName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + // set callback nullptr + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(pkgName, extra, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDevStateCallback_005 + * @tc.desc: 1. set packName not null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string pkgName = "com.ohos.test"; + // set extra null + std::string extra= "test1"; + // set callback nullptr + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(pkgName, extra, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_001 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_002 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_003 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_004 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_005 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: StartDeviceDiscovery_001 + * @tc.desc: 1. set packName null + * set subscribeInfo null + * set callback null + * 2. call DeviceManagerImpl::StartDeviceDiscovery with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set subscribeInfo null + std::string extra= "test"; + DmSubscribeInfo subscribeInfo; + // set callback null + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::StartDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo , extra , callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: StartDeviceDiscovery_002 + * @tc.desc: 1. set packName null + * set subscribeInfo null + * set callback null + * 2. call DeviceManagerImpl::StartDeviceDiscovery with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.helloworld"; + std::string extra= "test"; + // set subscribeInfo null + DmSubscribeInfo subscribeInfo; + // set callback null + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::StartDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo, extra, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: StartDeviceDiscovery_003 + * @tc.desc: 1. set packName null + * set subscribeInfo null + * set callback null + * 2. call DeviceManagerImpl::StartDeviceDiscovery with parameter + * 3. check ret is DEVICEMANAGER_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set subscribeInfo is 0 + DmSubscribeInfo subscribeInfo; + std::string extra = "test"; + std::shared_ptr callback = std::make_shared(); ; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo, extra, callback); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StartDeviceDiscovery_004 + * @tc.desc: 1. set packName not null + * set subscribeInfo null + * set callback not null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::StartDeviceDiscovery with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + std::string extra= "test"; + // set subscribeInfo null + DmSubscribeInfo subscribeInfo; + // set callback not null + std::shared_ptr callback = std::make_shared(); + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::StartDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo , extra , callback); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StartDeviceDiscovery_005 + * @tc.desc: 1. set packName not null + * set subscribeInfo null + * set callback not null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::StartDeviceDiscovery with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StartDeviceDiscovery_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + std::string extra= "test"; + // set subscribeInfo null + DmSubscribeInfo subscribeInfo; + // set callback not null + std::shared_ptr callback = std::make_shared(); + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::StartDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StartDeviceDiscovery(packName, subscribeInfo , extra , callback); + // 4. check ret is DEVICEMANAGER_IPC_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StopDeviceDiscovery_001 + * @tc.desc: 1. set packName null + * set subscribeId is 0 + * 2. call DeviceManagerImpl::StopDeviceDiscovery with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set subscribeInfo is 0 + uint16_t subscribeId = 0; + // 2. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(packName, subscribeId); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: StopDeviceDiscovery_002 + * @tc.desc: 1. set packName not null + * set subscribeId is 0 + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 2. call DeviceManagerImpl::StopDeviceDiscovery with parameter + * 3. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set subscribeInfo is 0 + uint16_t subscribeId = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(packName, subscribeId); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StopDeviceDiscovery_003 + * @tc.desc: 1. set packName not null + * set subscribeId is 0 + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set subscribeInfo is 0 + uint16_t subscribeId = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(packName, subscribeId); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StopDeviceDiscovery_004 + * @tc.desc: 1. set packName not null + * set subscribeId is 0 + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set subscribeInfo is 0 + uint16_t subscribeId = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(packName, subscribeId); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: StopDeviceDiscovery_005 + * @tc.desc: 1. set packName not null + * set subscribeId is 0 + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, StopDeviceDiscovery_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set subscribeInfo is 0 + uint16_t subscribeId = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_POINT_NULL)); + // 3. call DeviceManagerImpl::StopDeviceDiscovery with parameter + int32_t ret = DeviceManager::GetInstance().StopDeviceDiscovery(packName, subscribeId); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: AuthenticateDevice_001 + * @tc.desc: 1. set packName = null + * set dmDeviceInfo = null + * set dmAppImageInfo = null + * set extra = null + * set callback = nullptr + * 2. call DeviceManagerImpl::AuthenticateDevice with parameter + * 3. check ret is DEVICEMANAGER_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, AuthenticateDevice_001, testing::ext::TestSize.Level0) +{ + // 1. set packName = null + std::string packName = ""; + int32_t authType = 1; + // set dmDeviceInfo = null + DmDeviceInfo dmDeviceInfo; + // set extra = null + std::string extra= ""; + // set callback = nullptr + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, authType, dmDeviceInfo, extra, callback); + // 3. check ret is DEVICEMANAGER_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: AuthenticateDevice_002 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, AuthenticateDevice_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + int32_t authType = 1; + // set dmDeviceInfo null + DmDeviceInfo dmDeviceInfo; + // set extra null + std::string extra = ""; + // set callback null + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, authType, dmDeviceInfo, extra, callback); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: AuthenticateDevice_003 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + int32_t authType = 1; + // set dmAppImageInfo null + DmDeviceInfo dmDeviceInfo; + // set extra null + std::string extra = ""; + // set callback null + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, authType, dmDeviceInfo, extra, callback); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: AuthenticateDevice_004 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, AuthenticateDevice_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + int32_t authType = 1; + // set dmAppImageInfo null + DmDeviceInfo dmDeviceInfo; + // set extra null + std::string extra = ""; + // set callback null + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, authType, dmDeviceInfo, extra, callback); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: AuthenticateDevice_005 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, AuthenticateDevice_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + int32_t authType = 1; + // set dmAppImageInfo null + DmDeviceInfo dmDeviceInfo; + // set extra null + std::string extra = ""; + // set callback null + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().AuthenticateDevice(packName, authType, dmDeviceInfo, extra, callback); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnAuthenticateDevice_001 + * @tc.desc: 1. set packName = null + * set dmDeviceInfo = null + * set dmAppImageInfo = null + * set extra = null + * set callback = nullptr + * 2. call DeviceManagerImpl::AuthenticateDevice with parameter + * 3. check ret is DEVICEMANAGER_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level0) +{ + // 1. set packName = null + std::string packName = ""; + std::string deviceId = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId); + // 3. check ret is DEVICEMANAGER_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnAuthenticateDevice_002 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_002, testing::ext::TestSize.Level0) +{ + // 1. set packName = null + std::string packName = "com.ohos.helloworld"; + std::string deviceId = ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId); + // 3. check ret is DEVICEMANAGER_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnAuthenticateDevice_003 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set callback null + std::string deviceId = "1"; + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnAuthenticateDevice_004 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + std::string deviceId = "1"; + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnAuthenticateDevice_005 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnAuthenticateDevice_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + std::string deviceId = "1"; + std::shared_ptr callback = nullptr; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnAuthenticateDevice(packName, deviceId); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetFaParam_001 + * @tc.desc: 1. set packName = null + * set dmDeviceInfo = null + * set dmAppImageInfo = null + * set extra = null + * set callback = nullptr + * 2. call DeviceManagerImpl::AuthenticateDevice with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetFaParam_001, testing::ext::TestSize.Level0) +{ + // 1. set packName = null + std::string packName = ""; + DmAuthParam dmFaParam; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().GetFaParam(packName, dmFaParam); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: GetFaParam_002 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetFaParam_002, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set callback null + DmAuthParam dmFaParam; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().GetFaParam(packName, dmFaParam); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetFaParam_003 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetFaParam_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set callback null + DmAuthParam dmFaParam; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().GetFaParam(packName, dmFaParam); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetFaParam_004 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetFaParam_004, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + DmAuthParam dmFaParam; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().GetFaParam(packName, dmFaParam); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetFaParam_005 + * @tc.desc: 1. set packName not null + * set dmDeviceInfo null + * set dmAppImageInfo null + * set extra null + * set callback null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::AuthenticateDevice with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetFaParam_005, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.helloworld"; + // set dmDeviceInfo null + DmAuthParam dmFaParam; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().GetFaParam(packName, dmFaParam); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: SetUserOperation_001 + * @tc.desc: 1. set packName null + * set action null + * 2. call DeviceManagerImpl::SetUserOperation with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, SetUserOperation_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set authParam null + int32_t action = 0; + // 2. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().SetUserOperation(packName, action); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: SetUserOperation_002 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, SetUserOperation_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + int32_t action = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().SetUserOperation(packName, action); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: SetUserOperation_003 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, SetUserOperation_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set authParam null + int32_t action = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().SetUserOperation(packName, action); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: SetUserOperation_004 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, SetUserOperation_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + int32_t action = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().SetUserOperation(packName, action); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: SetUserOperation_005 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, SetUserOperation_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + int32_t action = 0; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().SetUserOperation(packName, action); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUdidByNetworkId_001 + * @tc.desc: 1. set packName null + * set action null + * 2. call DeviceManagerImpl::SetUserOperation with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set authParam null + std::string netWorkId = "111"; + std::string udid = "222"; + // 2. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUdidByNetworkId(packName, netWorkId, udid); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: GetUdidByNetworkId_002 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUdidByNetworkId_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string udid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUdidByNetworkId(packName, netWorkId, udid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUdidByNetworkId_003 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUdidByNetworkId_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string udid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUdidByNetworkId(packName, netWorkId, udid); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUdidByNetworkId_004 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUdidByNetworkId_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string udid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUdidByNetworkId(packName, netWorkId, udid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUdidByNetworkId_005 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUdidByNetworkId_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string udid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUdidByNetworkId(packName, netWorkId, udid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUuidByNetworkId_001 + * @tc.desc: 1. set packName null + * set action null + * 2. call DeviceManagerImpl::SetUserOperation with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set authParam null + std::string netWorkId = "111"; + std::string uuid = "222"; + // 2. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: GetUuidByNetworkId_002 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_FAILED + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUuidByNetworkId_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string uuid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_FAILED + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_FAILED)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUuidByNetworkId_003 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_OK + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUuidByNetworkId_003, testing::ext::TestSize.Level0) +{ + // 1. set packName not null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string uuid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_OK + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); + // 4. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUuidByNetworkId_004 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUuidByNetworkId_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string uuid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_SERVICE_NOT_READY + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_SERVICE_NOT_READY)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: GetUuidByNetworkId_005 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetUuidByNetworkId_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set authParam null + std::string netWorkId = "111"; + std::string uuid = "222"; + // 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_POINT_NULL)); + // 3. call DeviceManagerImpl::SetUserOperation with parameter + int32_t ret= DeviceManager::GetInstance().GetUuidByNetworkId(packName, netWorkId, uuid); + // 4. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_001 + * @tc.desc: 1. set packName not null + * set action null + * 2. MOCK IpcClientProxy SendRequest return DM_POINT_NULL + * 3. call DeviceManagerImpl::SetUserOperation with parameter + * 4. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set callback null + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packName, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_002 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set callback null + std::shared_ptr callback = std::make_shared(); + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packName, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_003 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set callback null + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packName, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_004 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set callback null + std::shared_ptr callback = std::make_shared(); + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packName, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_005 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName (""); + // set callback null + std::shared_ptr callback = nullptr; + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(packName, callback); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_001 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(packName); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_002 + * @tc.desc: 1. set packName not null + * 2. call DeviceManagerImpl::UnRegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // 2. call DeviceManagerImpl::RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(packName); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_003 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManager RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_OK + * 4. set checkMap null + * 5. Get checkMap from DeviceManagerNotify + * 6. call DeviceManager UnRegisterDeviceManagerFaCallback with parameter + * 7. Get checkMap from pkgName + * 8. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + std::shared_ptr callback = std::make_shared(); + // 2. call DeviceManager RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(pkgName, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + // 4. set checkMap null + std::shared_ptr checkMap = nullptr; + // 5. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManager UnRegisterDeviceManagerFaCallback with parameter + DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); + // 7. Get checkMap from pkgName + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_004 + * @tc.desc: 1. set packName not null + * set callback not null + * 2. call DeviceManager RegisterDeviceManagerFaCallback with parameter + * 3. check ret is DM_OK + * 4. set checkMap null + * 5. Get checkMap from DeviceManagerNotify + * 6. call DeviceManager UnRegisterDeviceManagerFaCallback with parameter + * 7. Get checkMap from pkgName + * 8. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + std::shared_ptr callback = std::make_shared(); + // 2. call DeviceManager RegisterDeviceManagerFaCallback with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(pkgName, callback); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + // 4. set checkMap null + std::shared_ptr checkMap = nullptr; + // 5. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set unRegisterPkgNamr different from pkgName + std::string unRegisterPkgName = "com.ohos.test1"; + // 7. call DeviceManager UnRegisterDeviceManagerFaCallback with unRegisterPkgName + DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(unRegisterPkgName); + // 7. Get checkMap from pkgName + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_005 + * @tc.desc: 1. set packName not null + * 2. Set checkMap null + * 3. Get checkMap from DeviceManagerNotify + * 4. check checkMap not null + * 5. Set unRegisterPkgName is different from register pkgName + * 6. call DeviceManager UnRegisterDevStateCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // 2. Set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 4. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 5. Set unRegisterPkgName is different from register pkgName + std::string unRegisterPkgName = "com.ohos.test1"; + // 6. call DeviceManager UnRegisterDeviceManagerFaCallback with parameter + DeviceManager::GetInstance().UnRegisterDeviceManagerFaCallback(unRegisterPkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDevStateCallback_006 + * @tc.desc: 1. set packName null + * set extra null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_006, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string pkgName = ""; + // set extra null + std::string extra= "test"; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(pkgName, extra); + // 3. check ret is DM_INVALID_VALUE; + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDevStateCallback_007 + * @tc.desc: 1. set packName not null + * set extra null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_007, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra= ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: RegisterDevStateCallback_008 + * @tc.desc: 1. set packName null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_008, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_IPC_FAILED)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: RegisterDevStateCallback_009 + * @tc.desc: 1. set packName not null + * set extra not null + * set callback not null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_009, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: RegisterDevStateCallback_010 + * @tc.desc: 1. set packName not null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, RegisterDevStateCallback_010, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().RegisterDevStateCallback(packName, extra); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnRegisterDevStateCallback_006 + * @tc.desc: 1. set packName null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_006, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra= ""; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName, extra); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_007 + * @tc.desc: 1. set packName not null + * 2. call DeviceManagerImpl::UnRegisterDevStateCallback with parameter + * 3. check ret is DM_INVALID_VALUE + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_007, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = ""; + // set extra null + std::string extra= "test"; + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName, extra); + // 3. check ret is DM_INVALID_VALUE + ASSERT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: UnRegisterDevStateCallback_008 + * @tc.desc: 1. set packName null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_008, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_IPC_FAILED)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName, extra); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnRegisterDevStateCallback_009 + * @tc.desc: 1. set packName null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_IPC_SEND_REQUEST_FAILED + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_009, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return( DM_SERVICE_NOT_READY)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName, extra); + // 3. check ret is DM_IPC_SEND_REQUEST_FAILED + ASSERT_EQ(ret, DM_IPC_SEND_REQUEST_FAILED); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} + +/** + * @tc.name: UnRegisterDevStateCallback_010 + * @tc.desc: 1. set packName not null + * set extra not null + * set callback null + * 2. call DeviceManagerImpl::RegisterDevStateCallback with parameter + * 3. check ret is DM_OK + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, UnRegisterDevStateCallback_010, testing::ext::TestSize.Level0) +{ + // 1. set packName null + std::string packName = "com.ohos.test"; + // set extra null + std::string extra= "test"; + std::shared_ptr mockInstance = std::make_shared(); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = mockInstance; + EXPECT_CALL(*mockInstance,SendRequest(testing::_,testing::_,testing::_)) + .Times(1).WillOnce(testing::Return(DM_OK)); + // 2. call DeviceManagerImpl::AuthenticateDevice with parameter + int32_t ret= DeviceManager::GetInstance().UnRegisterDevStateCallback(packName, extra); + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); + DeviceManagerImpl::GetInstance().ipcClientProxy_ = nullptr; +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_impl.h b/test/unittest/UTTest_device_manager_impl.h new file mode 100644 index 000000000..525d78cb3 --- /dev/null +++ b/test/unittest/UTTest_device_manager_impl.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DEVICE_MANAGER_IMPL_TEST_H +#define OHOS_DEVICE_MANAGER_IMPL_TEST_H + +#include +#include + +#include "mock/mock_ipc_client_proxy.h" +#include +#include +#include "device_manager.h" +#include "single_instance.h" + + +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerImplTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +class DeviceDiscoveryCallbackTest : public DiscoveryCallback { +public: + DeviceDiscoveryCallbackTest() : DiscoveryCallback() {} + virtual ~DeviceDiscoveryCallbackTest() {} + virtual void OnDiscoverySuccess(uint16_t subscribeId) override {} + virtual void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override {} + virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override {} +}; + +class DmInitCallbackTest : public DmInitCallback { +public: + DmInitCallbackTest() : DmInitCallback() {} + virtual ~DmInitCallbackTest() override {} + virtual void OnRemoteDied() override {} +}; + +class DeviceStateCallbackTest : public DeviceStateCallback { +public: + DeviceStateCallbackTest() : DeviceStateCallback() {} + virtual ~DeviceStateCallbackTest() override {} + virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override {} + virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override {} +}; + +class DeviceManagerFaCallbackTest : public DeviceManagerFaCallback { +public: + DeviceManagerFaCallbackTest() : DeviceManagerFaCallback() {} + virtual ~DeviceManagerFaCallbackTest() override {} + virtual void OnCall(const std::string ¶mJson) override {} +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DEVICE_MANAGER_IMPL_TEST_H diff --git a/test/unittest/UTTest_device_manager_notify.cpp b/test/unittest/UTTest_device_manager_notify.cpp new file mode 100644 index 000000000..768e1c0a5 --- /dev/null +++ b/test/unittest/UTTest_device_manager_notify.cpp @@ -0,0 +1,4078 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_device_manager_notify.h" +#include "device_manager_notify.h" +#include "device_manager_errno.h" +#include "dm_device_info.h" +#include "ipc_remote_broker.h" +#include "iremote_object.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "ipc_client_manager.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_rsp.h" +#include "ipc_def.h" + +#include + +namespace OHOS { +namespace DistributedHardware { +void DeviceManagerNotifyTest::SetUp() +{ +} + +void DeviceManagerNotifyTest::TearDown() +{ +} + +void DeviceManagerNotifyTest::SetUpTestCase() +{ +} + +void DeviceManagerNotifyTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: RegisterDeathRecipientCallback_001 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeathRecipientCallback_002 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback null + std::shared_ptr dmInitCallback = nullptr; + // 2. set checkMap not null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeathRecipientCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr dmInitCallback = nullptr; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[testPkgName]; + // 6. check checkMap not null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeathRecipientCallback_004 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call checkMap OnRemoteDied + * 7. check count is 1 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call checkMap OnRemoteDied + checkMap->OnRemoteDied(); + // 7. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterDeathRecipientCallback_005 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call checkMap OnRemoteDied + * 7. check count is 1 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = nullptr; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeathRecipientCallback_001 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(pkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeathRecipientCallback_002 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeathRecipientCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. call checkMap OnRemoteDied + * 10. check count is 1 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 9. call checkMap OnRemoteDied + checkMap->OnRemoteDied(); + // 10. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: UnRegisterDeathRecipientCallback_004 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 9. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeathRecipientCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName nullptr + std::string testPkgName = ""; + // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeviceStateCallback_001 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeviceStateCallback_002 + * @tc.desc: 1. set pkgName not null + * set Callback null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback null + std::shared_ptr callback = nullptr; + // 2. set checkMap not null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeviceStateCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = nullptr; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[testPkgName]; + // 6. check checkMap not null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDeviceStateCallback_004 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call checkMap OnDeviceOnline + * 7. check count is 1 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call checkMap OnDeviceOnline + DmDeviceInfo deviceInfo; + checkMap->OnDeviceOnline(deviceInfo); + // 7. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterDeviceStateCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + int count = 0; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[testPkgName]; + // 6. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceStateCallback_001 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceStateCallback_002 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest,UnRegisterDeviceStateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceStateCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest,UnRegisterDeviceStateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 9. call checkMap OnDeviceOnline + DmDeviceInfo deviceInfo; + checkMap->OnDeviceOnline(deviceInfo); + // 10. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: UnRegisterDeviceStateCallback_004 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 8 check checkMap null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDeviceStateCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest,UnRegisterDeviceStateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 9. call checkMap OnDeviceOnline + DmDeviceInfo deviceInfo; + checkMap->OnDeviceOnline(deviceInfo); + // 10. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterDiscoverCallback_001 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDiscoverCallback_002 + * @tc.desc: 1. set pkgName not null + * set Callback null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback null + std::shared_ptr callback = nullptr; + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap not null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDiscoverCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = nullptr; + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 6. check checkMap not null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterDiscoverCallback_004 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call checkMap OnDiscoverySuccess + * 7. check count is 1 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call checkMap OnDiscoverySuccess + checkMap->OnDiscoverySuccess(subscribeId); + // 7. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterDiscoverCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + int count = 0; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(count); + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 6. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDiscoverCallback_001 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDiscoverCallback_002 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDiscoverCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * 10. call checkMap OnDiscoverySuccess + * 11. check count is 1 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 9 check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 10. call checkMap OnDiscoverySuccess + checkMap->OnDiscoverySuccess(subscribeId); + // 11. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: UnRegisterDiscoverCallback_004 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 8 check checkMap null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterDiscoverCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * 10. call checkMap OnDiscoverySuccess + * 11. check count is 1 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 9 check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 10. call checkMap OnDiscoverySuccess + checkMap->OnDiscoverySuccess(subscribeId); + // 11. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterAuthenticateCallback_001 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: RegisterAuthenticateCallback_002 + * @tc.desc: 1. set pkgName not null + * set Callback null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback null + std::shared_ptr callback = nullptr; + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap not null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterAuthenticateCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr callback = nullptr; + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check checkMap not null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: RegisterAuthenticateCallback_004 + * @tc.desc: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call checkMap OnAuthResult + std::string token ="1"; + int32_t status = 1; + int32_t reason = 1; + checkMap->OnAuthResult(deviceId, token, status, reason); + // 7. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: RegisterAuthenticateCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + int count = 0; + // set dmInitCallback not null + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterAuthenticateCallback_001 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterAuthenticateCallback_002 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterAuthenticateCallback_003 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * 10. call checkMap OnAuthResult + * 11. check count is 1 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 9 check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 10. call checkMap OnAuthResult + std::string token ="1"; + int32_t status = 1; + int32_t reason = 1; + checkMap->OnAuthResult(deviceId, token, status, reason); + // 11. check count is 1 + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: UnRegisterAuthenticateCallback_004 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 8. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterAuthenticateCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/** + * @tc.name: UnRegisterPackageCallback_001 + * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + * 5. call DeviceManagerNotify UnRegisterPackageCallback with PkgName + * 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_001, testing::ext::TestSize.Level0) +{ + // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + std::string pkgName = "com.ohos.test"; + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + std::shared_ptr checkMap = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + ASSERT_NE(checkMap, nullptr); + // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + int count1 = 0; + std::shared_ptr deviceStateCallback = std::make_shared(count1); + std::shared_ptr checkMap1 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback); + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + ASSERT_NE(checkMap1, nullptr); + // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + int count2 = 0; + std::shared_ptr deviceDiscoveryCallback = std::make_shared(count2); + uint16_t subscribeId = 0; + std::shared_ptr checkMap2 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback); + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + ASSERT_NE(checkMap2, nullptr); + // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + int count3 = 0; + std::shared_ptr authenticateCallback = std::make_shared(count3); + std::string deviceId = "1"; + std::shared_ptr checkMap3 = nullptr; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback); + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap3, nullptr); + // 5. call DeviceManagerNotify UnRegisterPackageCallback with PkgName + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + ASSERT_EQ(checkMap, nullptr); + ASSERT_EQ(checkMap1, nullptr); + ASSERT_EQ(checkMap2, nullptr); + ASSERT_EQ(checkMap3, nullptr); +} + +/** + * @tc.name: UnRegisterPackageCallback_002 + * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + * 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + * 6. check if checkMap checkMap1 checkMap2 checkMap3 is not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_002, testing::ext::TestSize.Level0) +{ + // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + std::string pkgName = "com.ohos.test"; + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + std::shared_ptr checkMap = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + ASSERT_NE(checkMap, nullptr); + // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + int count1 = 0; + std::shared_ptr deviceStateCallback = std::make_shared(count1); + std::shared_ptr checkMap1 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback); + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + ASSERT_NE(checkMap1, nullptr); + // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + int count2 = 0; + std::shared_ptr deviceDiscoveryCallback = std::make_shared(count2); + uint16_t subscribeId = 0; + std::shared_ptr checkMap2 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback); + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + ASSERT_NE(checkMap2, nullptr); + // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + int count3 = 0; + std::shared_ptr authenticateCallback = std::make_shared(count3); + std::string deviceId = "1"; + std::shared_ptr checkMap3 = nullptr; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback); + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap3, nullptr); + // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + std::string testPkgName = "com.ohos.test1"; + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + ASSERT_NE(checkMap, nullptr); + ASSERT_NE(checkMap1, nullptr); + ASSERT_NE(checkMap2, nullptr); + ASSERT_NE(checkMap3, nullptr); +} + +/** + * @tc.name: UnRegisterPackageCallback_003 + * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + * 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + * 6. check if checkMap checkMap1 checkMap2 checkMap3 is not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_003, testing::ext::TestSize.Level0) +{ + // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + std::string pkgName = "com.ohos.test"; + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + std::shared_ptr checkMap = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + ASSERT_NE(checkMap, nullptr); + // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + int count1 = 0; + std::shared_ptr deviceStateCallback = std::make_shared(count1); + std::shared_ptr checkMap1 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback); + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + ASSERT_NE(checkMap1, nullptr); + // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + int count2 = 0; + std::shared_ptr deviceDiscoveryCallback = std::make_shared(count2); + uint16_t subscribeId = 0; + std::shared_ptr checkMap2 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback); + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + ASSERT_NE(checkMap2, nullptr); + // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + int count3 = 0; + std::shared_ptr authenticateCallback = std::make_shared(count3); + std::string deviceId = "1"; + std::shared_ptr checkMap3 = nullptr; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback); + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap3, nullptr); + // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + std::string testPkgName = "com.ohos.test1"; + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + ASSERT_NE(checkMap, nullptr); + ASSERT_NE(checkMap1, nullptr); + ASSERT_NE(checkMap2, nullptr); + ASSERT_NE(checkMap3, nullptr); + // 7. call checkMap OnRemoteDied() + checkMap->OnRemoteDied(); + // call checkMap1 OnDeviceOnline + DmDeviceInfo deviceInfo; + checkMap1->OnDeviceOnline(deviceInfo); + // call checkMap2 OnDeviceFound + checkMap2->OnDeviceFound(subscribeId, deviceInfo); + // call checkMap3 OnAuthResult + std::string token ="1";; + int32_t status = 1; + int32_t reason = 1; + checkMap3->OnAuthResult(deviceId, token, status, reason); + // 8. check count count1 count2 count3 is 1 + ASSERT_EQ(count, 1); + ASSERT_EQ(count1, 1); + ASSERT_EQ(count2, 1); + ASSERT_EQ(count3, 1); +} + +/** + * @tc.name: UnRegisterPackageCallback_004 + * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + * 5. call DeviceManagerNotify UnRegisterPackageCallback with PkgName + * 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_004, testing::ext::TestSize.Level0) +{ + // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + std::string pkgName = "com.ohos.test"; + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + std::shared_ptr checkMap = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + ASSERT_NE(checkMap, nullptr); + // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + int count1 = 0; + std::shared_ptr deviceStateCallback = std::make_shared(count1); + std::shared_ptr checkMap1 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback); + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + ASSERT_NE(checkMap1, nullptr); + // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + int count2 = 0; + std::shared_ptr deviceDiscoveryCallback = std::make_shared(count2); + uint16_t subscribeId = 0; + std::shared_ptr checkMap2 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback); + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + ASSERT_NE(checkMap2, nullptr); + // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + int count3 = 0; + std::shared_ptr authenticateCallback = std::make_shared(count3); + std::string deviceId = "1"; + std::shared_ptr checkMap3 = nullptr; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback); + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap3, nullptr); + // 5. call DeviceManagerNotify UnRegisterPackageCallback with PkgName + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + if (checkMap == nullptr && checkMap1 == nullptr && checkMap2 == nullptr && checkMap3 == nullptr) { + ASSERT_NE(count, 1); + ASSERT_NE(count1, 1); + ASSERT_NE(count2, 1); + ASSERT_NE(count3, 1); + return; + } + ASSERT_EQ(checkMap, nullptr); + ASSERT_EQ(checkMap1, nullptr); + ASSERT_EQ(checkMap2, nullptr); + ASSERT_EQ(checkMap3, nullptr); +} + +/** + * @tc.name: UnRegisterPackageCallback_005 + * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + * 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + * 6. check if checkMap checkMap1 checkMap2 checkMap3 is not null + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_005, testing::ext::TestSize.Level0) +{ + // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback + std::string pkgName = "com.ohos.test"; + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + std::shared_ptr checkMap = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + ASSERT_NE(checkMap, nullptr); + // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback + int count1 = 0; + std::shared_ptr deviceStateCallback = std::make_shared(count1); + std::shared_ptr checkMap1 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback); + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + ASSERT_NE(checkMap1, nullptr); + // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId + int count2 = 0; + std::shared_ptr deviceDiscoveryCallback = std::make_shared(count2); + uint16_t subscribeId = 0; + std::shared_ptr checkMap2 = nullptr; + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback); + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + ASSERT_NE(checkMap2, nullptr); + // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback + int count3 = 0; + std::shared_ptr authenticateCallback = std::make_shared(count3); + std::string deviceId = "1"; + std::shared_ptr checkMap3 = nullptr; + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback); + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap3, nullptr); + // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName); + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null + ASSERT_NE(checkMap, nullptr); + ASSERT_NE(checkMap1, nullptr); + ASSERT_NE(checkMap2, nullptr); + ASSERT_NE(checkMap3, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: RegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * EnvConditions: RegisterDeviceManagerFaCallback success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: RegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback null + std::shared_ptr DmFaCallback = nullptr; + // 2. set checkMap not null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: RegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName com.ohos.test + * set DmFaCallback not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + std::shared_ptr DmFaCallback = nullptr; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[testPkgName]; + // 6. check checkMap not null + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: RegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * EnvConditions: RegisterDeviceManagerFaCallback success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call checkMap OnCall + std::string paramJson = "test"; + checkMap->OnCall(paramJson); + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: RegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName com.ohos.test + * set DmFaCallback not null + * 2. set checkMap null + * 3. set testpkcName com.ohos.test1 + * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 5. Get checkMap from DeviceManagerNotify with testpkcName + * 6. check checkMap null + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 5. Get checkMap from DeviceManagerNotify with testpkcName + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[testPkgName]; + // 6. check checkMap not null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: UnRegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * EnvConditions: UnRegisterDeviceManagerFaCallback success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8 check checkMap null + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * Function: DeviceManagerNotifyTest + * SubFunction: UnRegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8 check checkMap not null + ASSERT_NE(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_003 + * Function: DeviceManagerNotifyTest + * SubFunction: UnRegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 9. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 10. call checkMap OnCall + std::string paramJson = "test"; + checkMap->OnCall(paramJson); + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_004 + * Function: DeviceManagerNotifyTest + * SubFunction: UnRegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * EnvConditions: UnRegisterDeviceManagerFaCallback success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); + // 7. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 8 check checkMap null + if (checkMap == nullptr) { + ASSERT_NE(count, 1); + return; + } + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_005 + * Function: DeviceManagerNotifyTest + * SubFunction: UnRegisterDeviceManagerFaCallback + * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName com.ohos.test + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + * 8. Get checkMap from DeviceManagerNotify + * 9. check checkMap not null + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); + // 8. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 9. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 10. call checkMap OnCall + std::string paramJson = "test"; + checkMap->OnCall(paramJson); + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnRemoteDied + * Function: DeviceManagerNotifyTest + * SubFunction: OnRemoteDied + * FunctionPoints: DeviceManagerNotifyTest OnRemoteDied + * EnvConditions: OnRemoteDied success. + * CaseDescription: 1. set pkgName not null + * set dmInitCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnRemoteDied + * 7. check if dmInitCallback OnRemoteDied called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnRemoteDied1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnRemoteDied + DeviceManagerNotify::GetInstance().OnRemoteDied(); + // 7. check if dmInitCallback OnRemoteDied called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOnline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOnline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline + * EnvConditions: OnDeviceOnline success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceOnline + * 7. check if callback OnDeviceOnline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnDeviceOnline + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo); + // 7. check if callback OnDeviceOnline called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOnline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOnline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOnline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOnline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOnline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOnline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOnline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOnline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOnline called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOnline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOnline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = ""; + // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOnline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOffline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOffline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline + * EnvConditions: OnDeviceOffline success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceOffline + * 7. check if callback OnDeviceOffline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnDeviceOffline + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo); + // 7. check if callback OnDeviceOffline called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOffline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOffline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOffline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOffline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOffline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName null + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOffline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOffline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOffline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName null + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOffline called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceOffline + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceOffline + * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); + // 8. check if callback OnDeviceOffline called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceChanged + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceChanged + * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged + * EnvConditions: OnDeviceChanged success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceChanged + * 7. check if callback OnDeviceChanged called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnDeviceChanged + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo); + // 7. check if callback OnDeviceChanged called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceChanged + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceChanged + * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); + // 8. check if callback OnDeviceChanged called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceChanged + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceChanged + * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); + // 8. check if callback OnDeviceChanged called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceChanged + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceChanged + * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. set testpkcName com.ohos.test1 + std::string testPkgName = ""; + // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); + // 8. check if callback OnDeviceChanged called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceChanged + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceChanged + * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set Callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); + // 8. check if callback OnDeviceChanged called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceFound + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceFound + * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound + * EnvConditions: OnDeviceFound success. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound + * 7. check if callback OnDeviceFound called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + DmDeviceInfo deviceInfo; + // 6. call DeviceManagerNotify OnDeviceFound + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo); + // 7. check if callback OnDeviceFound called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceFound + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceFound + * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound2, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + DmDeviceInfo deviceInfo; + std::string testPkgName = "com.ohos.test1"; + // 6. call DeviceManagerNotify OnDeviceFound + DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); + // 7. check if callback OnDeviceFound called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceFound + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceFound + * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testsubscribeId + * 7. check if callback OnDeviceFound called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound3, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + DmDeviceInfo deviceInfo; + uint16_t testsubscribeId = 1; + // 6. call DeviceManagerNotify OnDeviceFound + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, testsubscribeId, deviceInfo); + // 7. check if callback OnDeviceFound called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceFound + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceFound + * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound4, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + DmDeviceInfo deviceInfo; + std::string testPkgName = ""; + // 6. call DeviceManagerNotify OnDeviceFound + DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); + // 7. check if callback OnDeviceFound called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDeviceFound + * Function: DeviceManagerNotifyTest + * SubFunction: OnDeviceFound + * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound5, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + DmDeviceInfo deviceInfo; + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 6. call DeviceManagerNotify OnDeviceFound + DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); + // 7. check if callback OnDeviceFound called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverFailed + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverFailed + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed + * EnvConditions: OnDiscoverFailed success. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + int32_t failedReason = 0; + // 6. call DeviceManagerNotify OnDiscoverFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoverFailed called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverFailed + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverFailed + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName + * 7. check if callback OnDiscoverFailed called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed2, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = "com.ohos.test1"; + int32_t failedReason = 0; + // 6. call DeviceManagerNotify OnDiscoverFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoverFailed called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverFailed + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverFailed + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverFailed With testsubscribeId + * 7. check if callback OnDiscoverFailed called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed3, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + int32_t failedReason = 0; + uint16_t testsubscribeId = 1; + // 6. call DeviceManagerNotify OnDiscoverFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason); + // 7. check if callback OnDiscoverFailed called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverFailed + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverFailed + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName + * 7. check if callback OnDiscoverFailed called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed4, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = ""; + int32_t failedReason = 0; + // 6. call DeviceManagerNotify OnDiscoverFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoverFailed called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverFailed + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverFailed + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName + * 7. check if callback OnDiscoverFailed called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed5, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + int32_t failedReason = 0; + // 6. call DeviceManagerNotify OnDiscoverFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoverFailed called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverySuccess + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverySuccess + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess + * EnvConditions: OnDiscoverySuccess success. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverySuccess + * 7. check if callback OnDiscoverySuccess called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnDiscoverySuccess + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverySuccess + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverySuccess + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName + * 7. check if callback OnDiscoverySuccess called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess2, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = "com.ohos.test1"; + // 6. call DeviceManagerNotify OnDiscoverySuccess + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverySuccess + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverySuccess + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverySuccess With testsubscribeId + * 7. check if callback OnDiscoverySuccess called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess3, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + uint16_t testsubscribeId = 1; + // 6. call DeviceManagerNotify OnDiscoverySuccess + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, testsubscribeId); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverySuccess + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverySuccess + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName + * 7. check if callback OnDiscoverySuccess called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess4, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = ""; + // 6. call DeviceManagerNotify OnDiscoverySuccess + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnDiscoverySuccess + * Function: DeviceManagerNotifyTest + * SubFunction: OnDiscoverySuccess + * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess + * EnvConditions: N/A. + * CaseDescription: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName + * 7. check if callback OnDiscoverySuccess called. + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess5, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 6. call DeviceManagerNotify OnDiscoverySuccess + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult wiht testPkgName + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult2, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string testPkgName = "com.ohos.test1"; + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(testPkgName, deviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult wiht testDeviceId + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult3, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string testDeviceId = "2"; + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult4, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult5, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string testPkaName = "com.ohos.test1"; + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(testPkaName, deviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult6, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string testDeviceId = "2"; + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 0); + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_NE(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest OnAuthResult + * Function: OnAuthResult + * SubFunction: RegisterAuthenticateCallback + * FunctionPoints: DeviceManagerNotifyTest OnAuthResult + * EnvConditions: OnAuthResult success. + * CaseDescription: 1. set pkgName not null + * set Callback not null + * set deviceId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult7, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set callback not null + int count = 0; + std::shared_ptr callback = std::make_shared(count); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter + DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + std::string token = "111"; + uint32_t status = 0; + uint32_t reason = 0; + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); + checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId]; + ASSERT_EQ(checkMap, nullptr); +} + +/* + * Feature: DeviceManagerNotifyTest OnFaCall + * Function: DeviceManagerNotifyTest + * SubFunction: OnFaCall + * FunctionPoints: DeviceManagerNotifyTest OnFaCall + * EnvConditions: OnFaCall success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnFaCall + * 7. check if callback OnCheckAuthResult called + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall1, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnFaCall + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnFaCall + * Function: DeviceManagerNotifyTest + * SubFunction: OnFaCall + * FunctionPoints: DeviceManagerNotifyTest OnFaCall + * EnvConditions: OnFaCall success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnFaCall with testPkgName + * 7. check if callback OnCheckAuthResult called + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall2, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnFaCall + std::string testPkgName = "com.ohos.test1"; + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(testPkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnFaCall + * Function: DeviceManagerNotifyTest + * SubFunction: OnFaCall + * FunctionPoints: DeviceManagerNotifyTest OnFaCall + * EnvConditions: OnFaCall success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnFaCall with testPkgName + * 7. check if callback OnCheckAuthResult called + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall3, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnFaCall + std::string testPkgName = ""; + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(testPkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 0); +} + +/* + * Feature: DeviceManagerNotifyTest OnFaCall + * Function: DeviceManagerNotifyTest + * SubFunction: OnFaCall + * FunctionPoints: DeviceManagerNotifyTest OnFaCall + * EnvConditions: OnFaCall success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnFaCall with testPkgName + * 7. check if callback OnCheckAuthResult called + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall4, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnFaCall + std::string testPkgName = ""; + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(testPkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 1); +} + +/* + * Feature: DeviceManagerNotifyTest OnFaCall + * Function: DeviceManagerNotifyTest + * SubFunction: OnFaCall + * FunctionPoints: DeviceManagerNotifyTest OnFaCall + * EnvConditions: OnFaCall success. + * CaseDescription: 1. set pkgName not null + * set DmFaCallback not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnFaCall with testPkgName + * 7. check if callback OnCheckAuthResult called + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall5, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set DmFaCallback not null + int count = 0; + std::shared_ptr DmFaCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, DmFaCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmFaCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnFaCall + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(testPkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 0); +} +} // namespace + +DmInitCallbackTest::DmInitCallbackTest(int &count) : DmInitCallback() +{ + count_ = &count; +} +void DmInitCallbackTest::OnRemoteDied() +{ + *count_ = *count_ + 1; +} + +DeviceStateCallbackTest::DeviceStateCallbackTest(int &count) : DeviceStateCallback() +{ + count_ = &count; +} + +void DeviceStateCallbackTest::OnDeviceOnline(const DmDeviceInfo &deviceInfo) +{ + *count_ = *count_ + 1; +} + +void DeviceStateCallbackTest::OnDeviceReady(const DmDeviceInfo &deviceInfo) +{ + *count_ = *count_ + 1; +} + +void DeviceStateCallbackTest::OnDeviceOffline(const DmDeviceInfo &deviceInfo) +{ + *count_ = *count_ + 1; +} + +void DeviceStateCallbackTest::OnDeviceChanged(const DmDeviceInfo &deviceInfo) +{ + *count_ = *count_ + 1; +} + +DiscoveryCallbackTest::DiscoveryCallbackTest(int &count) : DiscoveryCallback() +{ + count_ = &count; +} + +void DiscoveryCallbackTest :: OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) +{ + *count_ = *count_ + 1; +} + +void DiscoveryCallbackTest :: OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) +{ + *count_ = *count_ + 1; +} + +void DiscoveryCallbackTest :: OnDiscoverySuccess(uint16_t subscribeId) +{ + *count_ = *count_ + 1; +} + +AuthenticateCallbackTest :: AuthenticateCallbackTest(int &count) : AuthenticateCallback() +{ + count_ = &count; +} + +void AuthenticateCallbackTest :: OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, + int32_t reason) +{ + *count_ = *count_ + 1; +} + +// CheckAuthCallbackTest :: CheckAuthCallbackTest(int &count) : CheckAuthCallback() +// { +// count_ = &count; +// } + +// void CheckAuthCallbackTest :: OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag) +// { +// *count_ = *count_ + 1; +// } + +DeviceManagerFaCallbackTest :: DeviceManagerFaCallbackTest(int &count) : DeviceManagerFaCallback() +{ + count_ = &count; +} + +void DeviceManagerFaCallbackTest :: OnCall(const std::string ¶mJson) +{ + *count_ = *count_ + 1; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_notify.h b/test/unittest/UTTest_device_manager_notify.h new file mode 100644 index 000000000..728d0e296 --- /dev/null +++ b/test/unittest/UTTest_device_manager_notify.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DEVICE_MANAGER_NOTIFY_TEST_H +#define OHOS_DEVICE_MANAGER_NOTIFY_TEST_H + +#include +#include +#include +#include +#include +#include +#include + +#include "dm_device_info.h" +#include "dm_subscribe_info.h" +#include "device_manager_callback.h" +#include "single_instance.h" +namespace OHOS { +namespace DistributedHardware { +class DeviceManagerNotifyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +class DmInitCallbackTest : public DmInitCallback { +public: + DmInitCallbackTest(int &count); + virtual ~DmInitCallbackTest() override {} + virtual void OnRemoteDied() override; +private: + int *count_ = nullptr; +}; + +class DeviceStateCallbackTest : public DeviceStateCallback { +public: + DeviceStateCallbackTest(int &count); + virtual ~DeviceStateCallbackTest() override {} + virtual void OnDeviceOnline(const DmDeviceInfo &deviceInfo) override; + virtual void OnDeviceReady(const DmDeviceInfo &deviceInfo) override; + virtual void OnDeviceOffline(const DmDeviceInfo &deviceInfo) override; + virtual void OnDeviceChanged(const DmDeviceInfo &deviceInfo) override; +private: + int *count_ = nullptr; +}; + +class DiscoveryCallbackTest : public DiscoveryCallback { +public: + DiscoveryCallbackTest(int &count); + virtual ~DiscoveryCallbackTest() override {} + virtual void OnDiscoverySuccess(uint16_t subscribeId) override; + virtual void OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) override; + virtual void OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) override; +private: + int *count_ = nullptr; +}; + +class AuthenticateCallbackTest : public AuthenticateCallback { +public: + AuthenticateCallbackTest(int &count); + virtual ~AuthenticateCallbackTest() override {} + virtual void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, + int32_t reason); +private: + int *count_ = nullptr; +}; + +// class CheckAuthCallbackTest : public CheckAuthCallback { +// public: +// CheckAuthCallbackTest(int &count); +// virtual ~CheckAuthCallbackTest(){} +// virtual void OnCheckAuthResult(std::string &deviceId, int32_t resultCode, int32_t flag); +// private: +// int *count_ = nullptr; +// }; + +class DeviceManagerFaCallbackTest : public DeviceManagerFaCallback { +public: + DeviceManagerFaCallbackTest(int &count); + virtual ~DeviceManagerFaCallbackTest() override {} + virtual void OnCall(const std::string ¶mJson) override; +private: + int *count_ = nullptr; +}; + +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DEVICE_MANAGER_NOTIFY_TEST_H diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index 725b0e44f..094c03964 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -44,7 +44,7 @@ void DmDeviceStateManagerTest::TearDownTestCase() { } namespace { -std::shared_ptr hiChainConnector_ = std::make_shared(); + std::shared_ptr hiChainConnector_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); std::shared_ptr dmDeviceStateManager = @@ -87,7 +87,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceOnline_001, testing::ext::TestSize.Le { std::string pkgName = "123"; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceOnline(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -106,7 +106,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceOffline_001, testing::ext::TestSize.L { std::string pkgName; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceOffline(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -125,7 +125,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_001, testing::ext::TestSize.L { std::string pkgName; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceChanged(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -145,7 +145,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnProfileReady_001, testing::ext::TestSize.Le std::string pkgName; std::string deviceId; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnProfileReady(pkgName, deviceId); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -164,7 +164,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Lev { std::string pkgName; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceReady(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -183,7 +183,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceChanged_002, testing::ext::TestSize.L { std::string pkgName; DmDeviceInfo info; - strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123"); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceChanged(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index 03fff20ce..ac324fa66 100644 --- a/test/unittest/UTTest_dm_discovery_manager.cpp +++ b/test/unittest/UTTest_dm_discovery_manager.cpp @@ -47,6 +47,16 @@ namespace { std::shared_ptr softbusConnector_ = std::make_shared(); std::shared_ptr listener_ = std::make_shared(); std::shared_ptr discoveryMgr_ = std::make_shared(softbusConnector_, listener_); +/** + * @tc.name: TimeOut_001 + * @tc.desc: Test whether the DmDiscoveryManager function can generate a new pointer + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDiscoveryManagerTest, TimeOut_001, testing::ext::TestSize.Level0) +{ + +} /** * @tc.name: DmDiscoveryManager_001 diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp new file mode 100644 index 000000000..4ffa0185c --- /dev/null +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -0,0 +1,477 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "parameter.h" +#include "dm_anonymous.h" +#include "dm_log.h" +#include "dm_constants.h" +#include "dm_random.h" +#include "hichain_connector.h" +#include "UTTest_hichain_connector.h" + +namespace OHOS { +namespace DistributedHardware { +void HichainConnectorTest::SetUp() +{ +} +void HichainConnectorTest::TearDown() +{ +} +void HichainConnectorTest::SetUpTestCase() +{ +} +void HichainConnectorTest::TearDownTestCase() +{ +} +namespace { +std::shared_ptr listener = std::make_shared(); +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr discoveryMgr = + std::make_shared(softbusConnector, listener, hiChainConnector); + +/** + * @tc.name: CreateGroup_001 + * @tc.desc: Set the deviceGroupManager_ pointer to CreateGroup to NULlptr and return DM_INVALID_VALUE + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, CreateGroup_001, testing::ext::TestSize.Level0) +{ + int64_t requestId = 123456; + std::string groupName = "dfggg"; + hiChainConnector->deviceGroupManager_ = nullptr; + int ret = hiChainConnector->CreateGroup(requestId, groupName); + EXPECT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: CreateGroup_002 + * @tc.desc: Set CreateGroup to the correct process and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, CreateGroup_002, testing::ext::TestSize.Level0) +{ + int64_t requestId = 123456; + std::string groupName = "uuiioo"; + int ret = hiChainConnector->CreateGroup(requestId, groupName); + EXPECT_EQ(ret, DM_INVALID_VALUE); +} + +/** + * @tc.name: GetGroupInfo_001 + * @tc.desc: set groupName not null and return false + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetGroupInfo_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + std::string groupName = "dcdkdkd1"; + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); + std::string queryParams = jsonObj.dump(); + std::vector groupList; + int ret = hichainConnector->GetGroupInfo(queryParams, groupList); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: GetGroupInfo_003 + * @tc.desc: set groupName nou null groupListot null and return 0 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetGroupInfo_002, testing::ext::TestSize.Level0) +{ + std::string groupName = "lcdkddkd1 "; + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); + std::string queryParams = jsonObj.dump(); + GroupInfo aa; + aa.groupName = "afa"; + std::vector groupList; + groupList.push_back(aa); + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GetGroupInfo(queryParams, groupList); + EXPECT_EQ(ret, 0); +} + +/** + * @tc.name: IsGroupInfoInvalid_001 + * @tc.desc: GroupType is GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP, group.groupVisibility is not GROUP_VISIBILITY_PUBLIC. + Group.return true + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ + +HWTEST_F(HichainConnectorTest, IsGroupInfoInvalid_001, testing::ext::TestSize.Level0) +{ + GroupInfo group; + group.groupName = "dkdkkdkdk"; + group.groupId = 1; + group.groupOwner = "ohos.distributedhardware.devicemanager"; + group.groupType = 7; + group.groupVisibility = 1; + std::shared_ptr hichainConnector = std::make_shared(); + bool ret = hichainConnector->IsGroupInfoInvalid(group); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: IsGroupInfoInvalid_002 + * @tc.desc: GroupType is GROUP_TYPE_IDENTICAL_ACCOUNT_GROUP, group.groupVisibility is GROUP_VISIBILITY_PUBLIC, + Grou. groupOwner is not equal to DM_PKG_NAME. The value is true + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, IsGroupInfoInvalid_002, testing::ext::TestSize.Level0) +{ + GroupInfo group; + group.groupName = "test"; + group.groupId = 1; + group.groupOwner = "ohos.disware"; + group.groupType = 1; + group.groupVisibility = -1; + std::shared_ptr hichainConnector = std::make_shared(); + bool ret = hichainConnector->IsGroupInfoInvalid(group); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: DelMemberFromGroup_001 + * @tc.desc:set groupId, deviceId null and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, DelMemberFromGroup_001, testing::ext::TestSize.Level0) +{ + std::string groupId; + std::string deviceId; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->DelMemberFromGroup(groupId, deviceId); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DelMemberFromGroup_002 + * @tc.desc: The groupId "34451"; The deviceId = "123"; Can be deleted correctly + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, DelMemberFromGroup_002, testing::ext::TestSize.Level0) +{ + std::string groupId = "34451"; + std::string deviceId = "123"; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->DelMemberFromGroup(groupId, deviceId); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GenRequestId_001 + * @tc.desc:Call the GenRequestId function + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GenRequestId_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GenRequestId(); + ASSERT_NE(ret, 0); +} + +/** + * @tc.name: from_json_001 + * @tc.desc: Pass in arguments to the from_JSON function and convert it to the correct value + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, from_json_001, testing::ext::TestSize.Level0) +{ + GroupInfo groupInfo; + groupInfo.groupName = "aaaa"; + groupInfo.groupId = "345678"; + groupInfo.groupOwner = "lllll"; + groupInfo.groupType = 5; + groupInfo.groupVisibility = 5; + nlohmann::json jsonObject; + jsonObject[FIELD_GROUP_NAME] = groupInfo.groupName; + jsonObject[FIELD_GROUP_ID] = groupInfo.groupId; + jsonObject[FIELD_GROUP_OWNER] = groupInfo.groupOwner; + jsonObject[FIELD_GROUP_TYPE] = groupInfo.groupType; + jsonObject[FIELD_GROUP_VISIBILITY] = groupInfo.groupVisibility; + from_json(jsonObject, groupInfo); + EXPECT_EQ(groupInfo.groupName, "aaaa"); + EXPECT_EQ(groupInfo.groupId, "345678"); + EXPECT_EQ(groupInfo.groupOwner, "lllll"); + EXPECT_EQ(groupInfo.groupType, 5); + EXPECT_EQ(groupInfo.groupVisibility, 5); +} + +/** + * @tc.name: HiChainConnector_001 + * @tc.desc: Returns a new pointer to the HiChainConnector constructor new + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, HiChainConnector_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr m_HiChainConnector = std::make_shared(); + ASSERT_NE(m_HiChainConnector, nullptr); +} + +/** + * @tc.name: HiChainConnector_002 + * @tc.desc: Give the HiChainConnector constructor new a new pointer and delete it + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, HiChainConnector_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr m_HiChainConnector = std::make_shared(); + m_HiChainConnector.reset(); + EXPECT_EQ(m_HiChainConnector, nullptr); +} + +/** + * @tc.name:RegisterHiChainCallback_001 + * @tc.desc: Call the RegisterHiChainCallback function with a return value of DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, RegisterHiChainCallback_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr)); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: IsGroupCreated_001 + * @tc.desc: Call the RegisterHiChainCallback function with a return value of DM_OK + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, IsGroupCreated_001, testing::ext::TestSize.Level0) +{ + std::string groupName = "dcdkdkd1"; + nlohmann::json jsonObj; + jsonObj[FIELD_GROUP_NAME] = groupName.c_str(); + std::string queryParams = jsonObj.dump(); + std::vector groupList; + GroupInfo groupInfo; + std::shared_ptr hichainConnector = std::make_shared(); + bool ret = hichainConnector->IsGroupCreated(groupName, groupInfo); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: AddMember_001 + * @tc.desc: set deviceGroupManager_ = nullptr; + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, AddMember_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + hichainConnector->deviceGroupManager_ = nullptr; + std::string deviceId; + std::string connectInfo; + int ret = hichainConnector->AddMember(deviceId, connectInfo); + EXPECT_EQ(ret, -1); +} + +/** + * @tc.name: AddMember_002 + * @tc.desc: set deviceId and connectInfo = null; + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, AddMember_002, testing::ext::TestSize.Level0) +{ + std::string deviceId; + std::string connectInfo; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->AddMember(deviceId, connectInfo); + EXPECT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: AddMember_002 + * @tc.desc: set deviceId and connectInfo = null; + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, AddMember3, testing::ext::TestSize.Level0) +{ + std::string deviceId = "123456"; + std::string connectInfo = "dkdkk"; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->AddMember(deviceId, connectInfo); + ASSERT_GE(ret, 1); +} + +/** + * @tc.name: onRequest_001 + * @tc.desc:set operationCode != GroupOperationCode::MEMBER_JOIN(3); return nullptr ; + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, onRequest_001, testing::ext::TestSize.Level0) +{ + int64_t requestId = 2; + int32_t operationCode = 2; + char *reqParams; + std::shared_ptr hichainConnector = std::make_shared(); + char *ret = hichainConnector->onRequest(requestId, operationCode, reqParams); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.name: GetConnectPara_001 + * @tc.desc: set para not null and go to the second master + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetConnectPara_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr)); + std::string deviceId = "23445"; + std::string reqDeviceId = "234566"; + std::string p; + std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); + EXPECT_EQ(ret, p); +} + +/** + * @tc.name: GetConnectPara_002 + * @tc.desc:Empty deviceId so that jsonObject.is_discarded is null and the value of connectAddr is returned + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetConnectPara_002, testing::ext::TestSize.Level0) +{ + std::string deviceId; + std::string reqDeviceId = "234566"; + std::shared_ptr hichainConnector = std::make_shared(); + hichainConnector->RegisterHiChainCallback(std::shared_ptr(discoveryMgr)); + std::string ret = hichainConnector->GetConnectPara(deviceId, reqDeviceId); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.name: DeleteGroup_001 + * @tc.desc: set groupId = "34567",and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, DeleteGroup_001, testing::ext::TestSize.Level0) +{ + std::string groupId = "34567"; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->DeleteGroup(groupId); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetRelatedGroups_001 + * @tc.desc: set DeviceId 123 groupList null and return DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetRelatedGroups_001, testing::ext::TestSize.Level0) +{ + std::string DeviceId = "123"; + std::vector groupList; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GetRelatedGroups(DeviceId, groupList); + EXPECT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: GetRelatedGroups_002 + * @tc.desc: set DeviceId = 12345,groupList null and return DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetRelatedGroups_002, testing::ext::TestSize.Level0) +{ + std::string DeviceId = "12345"; + std::vector groupList; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GetRelatedGroups(DeviceId, groupList); + EXPECT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: SyncGroups_001 + * @tc.desc: set deviceId = "34567",and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, SyncGroups_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "34567"; + std::vector remoteGroupIdList; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->SyncGroups(deviceId, remoteGroupIdList); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetSyncGroupList_001 + * @tc.desc: set groupList null,and return DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetSyncGroupList_001, testing::ext::TestSize.Level0) +{ + std::vector groupList; + std::vector syncGroupList; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GetSyncGroupList(groupList, syncGroupList); + EXPECT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: GetSyncGroupList_002 + * @tc.desc: set groupList not null,and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, GetSyncGroupList_002, testing::ext::TestSize.Level0) +{ + std::vector groupList; + GroupInfo groupList1; + groupList1.groupName = "hichainconnector"; + groupList1.groupId = "123456"; + groupList1.groupOwner = "doftbus"; + groupList1.groupType = 1; + groupList1.groupVisibility = 2; + groupList.push_back(groupList1); + std::vector syncGroupList; + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->GetSyncGroupList(groupList, syncGroupList); + EXPECT_EQ(ret, DM_OK); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_hichain_connector.h b/test/unittest/UTTest_hichain_connector.h new file mode 100644 index 000000000..9e7060615 --- /dev/null +++ b/test/unittest/UTTest_hichain_connector.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_UTTEST_HICHAIN_CONNECTOR_H +#define OHOS_UTTEST_HICHAIN_CONNECTOR_H + +#include +#include +#include +#include +#include +#include +#include + +#include "nlohmann/json.hpp" +#include "device_auth.h" +#include "single_instance.h" +#include "hichain_connector_callback.h" +#include "device_manager_service_listener.h" +#include "dm_auth_manager.h" +#include "dm_device_state_manager.h" +#include "hichain_connector.h" + +namespace OHOS { +namespace DistributedHardware { +class HichainConnectorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_HICHAIN_CONNECTOR_H diff --git a/test/unittest/UTTest_ipc_client_manager.cpp b/test/unittest/UTTest_ipc_client_manager.cpp index 9efedfc32..6c7e1b30a 100644 --- a/test/unittest/UTTest_ipc_client_manager.cpp +++ b/test/unittest/UTTest_ipc_client_manager.cpp @@ -46,6 +46,36 @@ void IpcClientManagerTest::TearDownTestCase() } namespace { + /** + * @tc.name: OnRemoteDied_001 + * @tc.desc: 1. new a dmInterface + * 2. set IpcClientManager dmInterface_ not null + * 3. call ClientInit + * 4. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcClientManagerTest, OnRemoteDied_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set dmInitCallback not null + int count = 0; + std::shared_ptr dmInitCallback = std::make_shared(count); + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter + DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnRemoteDied + DeviceManagerNotify::GetInstance().OnRemoteDied(); + // 7. check if dmInitCallback OnRemoteDied called + ASSERT_EQ(count, 1); +} + /** * @tc.name: ClientInit_001 * @tc.desc: 1. new a dmInterface @@ -67,7 +97,7 @@ HWTEST_F(IpcClientManagerTest, ClientInit_001, testing::ext::TestSize.Level0) // 3. call ClientInit int ret = instance->ClientInit(); // 4. check ret is DM_OK - ASSERT_NE(ret, DM_INIT_FAILED); + ASSERT_EQ(ret, DM_OK); } /** @@ -85,7 +115,7 @@ HWTEST_F(IpcClientManagerTest, ClientInit_002, testing::ext::TestSize.Level0) // 3. call ClientInit int ret = instance->ClientInit(); // 4. check ret is DM_OK - ASSERT_NE(ret, DM_INIT_FAILED); + ASSERT_EQ(ret, DM_OK); } /** @@ -110,7 +140,7 @@ HWTEST_F(IpcClientManagerTest, Init_001, testing::ext::TestSize.Level0) // 4. call Init with pkgName int32_t ret = instance->Init(pkgName); // 5. check ret is DM_OK - ASSERT_NE(ret, DM_INIT_FAILED); + ASSERT_EQ(ret, DM_OK); } /** @@ -579,5 +609,15 @@ HWTEST_F(IpcClientManagerTest, IsInit_002, testing::ext::TestSize.Level0) ASSERT_EQ(ret, false); } } // namespace + +DmInitCallbackTest::DmInitCallbackTest(int &count) : DmInitCallback() +{ + count_ = &count; +} + +void DmInitCallbackTest::OnRemoteDied() +{ + *count_ = *count_ + 1; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_client_manager.h b/test/unittest/UTTest_ipc_client_manager.h index bd25fb4de..7a01fabdd 100644 --- a/test/unittest/UTTest_ipc_client_manager.h +++ b/test/unittest/UTTest_ipc_client_manager.h @@ -21,6 +21,7 @@ #include "mock/mock_ipc_client_manager.h" #include "ipc_client_manager.h" +#include "device_manager_callback.h" namespace OHOS { namespace DistributedHardware { class IpcClientManagerTest : public testing::Test { @@ -30,6 +31,15 @@ public: virtual void SetUp() override; virtual void TearDown() override; }; + +class DmInitCallbackTest : public DmInitCallback { +public: + DmInitCallbackTest(int &count); + virtual ~DmInitCallbackTest() override {} + virtual void OnRemoteDied() override; +private: + int *count_ = nullptr; +}; } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_ipc_client_server_proxy.cpp b/test/unittest/UTTest_ipc_client_server_proxy.cpp new file mode 100644 index 000000000..1c0bca057 --- /dev/null +++ b/test/unittest/UTTest_ipc_client_server_proxy.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_ipc_client_server_proxy.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "ipc_cmd_register.h" +#include "ipc_def.h" +#include "ipc_types.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_start_discovery_req.h" +#include + +namespace OHOS { +namespace DistributedHardware { +void IpcClientServerProxyTest::SetUp() +{ +} + +void IpcClientServerProxyTest::TearDown() +{ +} + +void IpcClientServerProxyTest::SetUpTestCase() +{ +} + +void IpcClientServerProxyTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: SendCmd_001 + * @tc.desc: 1. set cmdCode not null + * 2. set remoteObject nullptr + * 3. call IpcClientServerProxy SendCmd + * 4. check ret is DEVICEMANAGER_NULLPTR + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcClientServerProxyTest, SendCmd_001, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = 1; + // 2. set remoteObject nullptr + sptr remoteObject = nullptr; + // 3. call IpcClientServerProxy SendCmd + auto instance = new IpcClientServerProxy(remoteObject); + int ret = instance->SendCmd(cmdCode,nullptr,nullptr); + // 4. check ret is DEVICEMANAGER_NULLPTR + ASSERT_EQ(ret, DM_POINT_NULL); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_ipc_client_server_proxy.h b/test/unittest/UTTest_ipc_client_server_proxy.h new file mode 100644 index 000000000..a89a6fa98 --- /dev/null +++ b/test/unittest/UTTest_ipc_client_server_proxy.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_CLIENT_SERVER_PROXY_TEST_H +#define OHOS_IPC_CLIENT_SERVER_PROXY_TEST_H + +#include +#include + +#include "ipc_remote_broker.h" +#include "ipc_client_server_proxy.h" +#include "iremote_proxy.h" +namespace OHOS { +namespace DistributedHardware { +class IpcClientServerProxyTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_IPC_CLIENT_SERVER_PROXY_TEST_H diff --git a/test/unittest/UTTest_ipc_client_stub.cpp b/test/unittest/UTTest_ipc_client_stub.cpp index 0a42bb666..b8c34a21d 100644 --- a/test/unittest/UTTest_ipc_client_stub.cpp +++ b/test/unittest/UTTest_ipc_client_stub.cpp @@ -72,8 +72,9 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) int code = 999; sptr instance = new IpcClientStub(); // 3. call IpcClientStub OnRemoteRequest with parameter - int32_t result = instance->OnRemoteRequest(code, data, reply, option); - if (result != DM_OK) { + int32_t ret = instance->OnRemoteRequest(code, data, reply, option); + int32_t result = DM_OK; + if (ret != result) { result = DM_FAILED; } // 4. check result is DM_FAILED @@ -105,7 +106,7 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) // 3. call IpcClientStub OnRemoteRequest with parameter int ret = instance->OnRemoteRequest(code, data, reply, option); // 4. check result is DM_OK - ASSERT_NE(ret, DM_OK); + ASSERT_EQ(ret, ERR_INVALID_STATE); } /** @@ -114,7 +115,7 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) * set req is nullptr * set rsp is nullptr * 2. call IpcClientStub SendCmd with parameter - * 3. check result is DM_IPC_FAILED + * 3. check result is DM_OK * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -129,7 +130,7 @@ HWTEST_F(IpcClientStubTest, SendCmd_001, testing::ext::TestSize.Level0) sptr instance = new IpcClientStub(); // 2. call IpcClientStub SendCmd with parameter int ret = instance->SendCmd(cmdCode, req, rsp); - // 3. check result is DM_IPC_FAILED + // 3. check result is DM_OK ASSERT_EQ(ret, DM_IPC_FAILED); } } // namespace diff --git a/test/unittest/UTTest_ipc_cmd_register.cpp b/test/unittest/UTTest_ipc_cmd_register.cpp new file mode 100644 index 000000000..60a2c60e0 --- /dev/null +++ b/test/unittest/UTTest_ipc_cmd_register.cpp @@ -0,0 +1,943 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_ipc_cmd_register.h" +#include "ipc_client_manager.h" +#include "ipc_register_listener_req.h" +#include "ipc_get_trustdevice_rsp.h" +#include "ipc_get_info_by_network_rsp.h" +#include "ipc_get_info_by_network_req.h" +#include "ipc_get_trustdevice_req.h" +#include "ipc_start_discovery_req.h" +#include "ipc_stop_discovery_req.h" +#include "ipc_get_dmfaparam_rsp.h" +#include "ipc_register_dev_state_callback_req.h" +#include "ipc_set_useroperation_req.h" +#include "ipc_verify_authenticate_req.h" +#include "ipc_unauthenticate_device_req.h" +#include "ipc_authenticate_device_req.h" +#include "ipc_get_local_device_info_rsp.h" +#include "device_manager_notify.h" +#include "ipc_req.h" +#include "dm_device_info.h" +#include "dm_constants.h" +#include "dm_log.h" +#include + +namespace OHOS { +namespace DistributedHardware { +void IpcCmdRegisterTest::SetUp() +{ +} + +void IpcCmdRegisterTest::TearDown() +{ +} + +void IpcCmdRegisterTest::SetUpTestCase() +{ +} + +void IpcCmdRegisterTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: SetRequest_001 + * @tc.desc: 1. set cmdCode not null + * set MessageParcel data null + * set IpcReq null + * 2. call IpcCmdRegister OnRemoteRequest with parameter + * 3. check ret is DM_IPC_NOT_REGISTER_FUNC + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, SetRequest_001, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = 999; + // set MessageParcel data null + MessageParcel data; + // set IpcReq null + std::shared_ptr req = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data); + // 3. check ret is DM_IPC_NOT_REGISTER_FUNC + ASSERT_EQ(ret, DM_IPC_NOT_REGISTER_FUNC); +} + +/** + * @tc.name: SetRequest_002 + * @tc.desc: 1. set cmdCode not null + * set MessageParcel data null + * set IpcRegisterListenerReq null + * 2. call IpcCmdRegister OnRemoteRequest with parameter + * 3. check ret is DM_IPC_TRANSACTION_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, SetRequest_002, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = REGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel data; + // set IpcRegisterListenerReq null + std::shared_ptr req = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data); + // 3. check ret is DM_IPC_TRANSACTION_FAILED + ASSERT_EQ(ret, DM_IPC_TRANSACTION_FAILED); +} + +/** + * @tc.name: SetRequest_003 + * @tc.desc: 1. set cmdCode not null + * set MessageParcel data null + * set IpcRegisterListenerReq with pkgName not null + * 2. call IpcCmdRegister OnRemoteRequest with parameter + * 3. check ret is DM_IPC_TRANSACTION_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, SetRequest_003, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = REGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel data; + // set IpcRegisterListenerReq null + std::shared_ptr req = std::make_shared(); + std::string pkgName = "com.ohos.test"; + req->SetPkgName(pkgName); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data); + // 3. check ret is DM_IPC_TRANSACTION_FAILED + ASSERT_EQ(ret, DM_IPC_TRANSACTION_FAILED); +} + +/** + * @tc.name: SetRequest_004 + * @tc.desc: 1. set cmdCode not null + * set MessageParcel data null + * set IpcRegisterListenerReq with listener + * 2. call IpcCmdRegister OnRemoteRequest with parameter + * 3. check ret is DM_IPC_TRANSACTION_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, SetRequest_004, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = REGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel data; + // set IpcRegisterListenerReq null + std::shared_ptr req = std::make_shared(); + sptr listener = nullptr; + std::string pkgName = ""; + req->SetPkgName(pkgName); + req->SetListener(listener); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data); + // 3. check ret is DM_IPC_TRANSACTION_FAILED + ASSERT_EQ(ret, DM_IPC_TRANSACTION_FAILED); +} + +/** + * @tc.name: SetRequest_005 + * @tc.desc: 1. set cmdCode not null + * set MessageParcel data null + * set IpcRegisterListenerReq with listener + * 2. call IpcCmdRegister OnRemoteRequest with parameter + * 3. check ret is DM_IPC_TRANSACTION_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, SetRequest_005, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = REGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel data; + // set IpcRegisterListenerReq null + std::shared_ptr req = std::make_shared(); + sptr listener = nullptr; + std::string pkgName = "listen not null"; + req->SetPkgName(pkgName); + req->SetListener(listener); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data); + // 3. check ret is DM_IPC_TRANSACTION_FAILED + ASSERT_EQ(ret, DM_IPC_TRANSACTION_FAILED); +} + +/** + * @tc.name: ReadResponse_001 + * @tc.desc: 1. set cmdCode 9999 + * set MessageParcel reply null + * 2. call IpcCmdRegister ReadResponse with parameter + * 3. check ret is DM_IPC_NOT_REGISTER_FUNC + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, ReadResponse_001, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = 9999; + // set MessageParcel data null + MessageParcel reply; + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister ReadResponse with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp); + // 3. check ret is DM_IPC_NOT_REGISTER_FUNC + ASSERT_EQ(ret, DM_IPC_NOT_REGISTER_FUNC); +} + +/** + * @tc.name: ReadResponse_002 + * @tc.desc: 1. set cmdCode REGISTER_DEVICE_MANAGER_LISTENER + * set MessageParcel reply null + * set IpcRsp null + * 2. call IpcCmdRegister ReadResponse with parameter + * 3. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, ReadResponse_002, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = REGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel reply; + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);; + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: ReadResponse_003 + * @tc.desc: 1. set cmdCode UNREGISTER_DEVICE_MANAGER_LISTENER + * set MessageParcel reply null + * set IpcRsp null + * 2. call IpcCmdRegister ReadResponse with parameter + * 3. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, ReadResponse_003, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = UNREGISTER_DEVICE_MANAGER_LISTENER; + // set MessageParcel data null + MessageParcel reply; + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);; + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: ReadResponse_004 + * @tc.desc: 1. set cmdCode GET_TRUST_DEVICE_LIST + * set MessageParcel reply null + * set IpcRsp null + * 2. call IpcCmdRegister ReadResponse with parameter + * 3. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, ReadResponse_004, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = GET_TRUST_DEVICE_LIST; + // set MessageParcel data null + MessageParcel reply; + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);; + // 3. check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: ReadResponse_005 + * @tc.desc: 1. set cmdCode GET_TRUST_DEVICE_LIST + * set MessageParcel reply null + * set IpcRsp null + * 2. call IpcCmdRegister ReadResponse with parameter + * 3. check ret is DM_IPC_TRANSACTION_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, ReadResponse_005, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = GET_TRUST_DEVICE_LIST; + // set MessageParcel data null + MessageParcel reply; + reply.WriteInt32(10); + int32_t deviceTotalSize = 10 * (int32_t)sizeof(DmDeviceInfo); + DmDeviceInfo *dmDeviceInfo = nullptr; + reply.WriteRawData(dmDeviceInfo,deviceTotalSize); + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister OnRemoteRequest with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().ReadResponse(cmdCode, reply, rsp);; + // 3. check ret is DM_IPC_TRANSACTION_FAILED + ASSERT_EQ(ret, DM_IPC_TRANSACTION_FAILED); +} + +/** + * @tc.name: OnIpcCmd_001 + * @tc.desc: 1. set cmdCode 9999 + * set MessageParcel reply null + * 2. call IpcCmdRegister OnIpcCmd with parameter + * 3. check ret is DEVICEMANAGER_IPC_NOT_REGISTER_FUNC + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_001, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode not null + int32_t cmdCode = 9999; + // set MessageParcel data null + MessageParcel reply; + MessageParcel data; + // set IpcRegisterListenerReq null + std::shared_ptr rsp = std::make_shared(); + // 2. call IpcCmdRegister ReadResponse with parameter + int ret = 0; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); + // 3. check ret is DM_IPC_NOT_REGISTER_FUNC + ASSERT_EQ(ret, DM_IPC_NOT_REGISTER_FUNC); +} + +/** + * @tc.name: OnIpcCmd_002 + * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + * 2. data.WriteString(pkgname) + * data.WriteInt32(DEVICE_STATE_ONLINE) + * data.WriteRawData(&dmDeviceInfo, deviceSize) + * 3. call IpcCmdRegister OnIpcCmd with parameter + * 4. check ret is DM_OK + * check result is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_002, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; + MessageParcel reply; + MessageParcel data; + // 2. data.WriteString(pkgname) + data.WriteString("com.ohos.test"); + // data.WriteInt32(DEVICE_STATE_ONLINE) + data.WriteInt32(DEVICE_STATE_ONLINE); + DmDeviceInfo dmDeviceInfo; + size_t deviceSize = sizeof(DmDeviceInfo); + // data.WriteRawData(&dmDeviceInfo, deviceSize) + data.WriteRawData(&dmDeviceInfo, deviceSize); + // 3. call IpcCmdRegister OnIpcCmd with parameter + int ret = 0; + int result = 0; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); + result = reply.ReadInt32(); + // 4. check result is DM_OK + // check ret is DEVICEMANAGER_IPC_NOT_REGISTER_FUNC + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnIpcCmd_003 + * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + * 2. data.WriteString(pkgname) + * data.WriteInt32(DEVICE_STATE_ONLINE) + * data.WriteRawData(nullptr, deviceSize) + * 3. call IpcCmdRegister OnIpcCmd with parameter + * 4. check ret is DEVICEMANAGER_OK + * check result is DEVICE_STATE_ONLINE + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_003, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; + MessageParcel reply; + MessageParcel data; + // 2. data.WriteString(pkgname) + data.WriteString("com.ohos.test"); + // data.WriteInt32(DEVICE_STATE_ONLINE) + data.WriteInt32(DEVICE_STATE_ONLINE); + // data.WriteRawData(nullptr, deviceSize) + size_t deviceSize = sizeof(DmDeviceInfo); + data.WriteRawData(nullptr, deviceSize); + // 3. call IpcCmdRegister OnIpcCmd with parameter + int ret = 0; + int result = 0; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); + result = reply.ReadInt32(); + // 4. check result is DEVICE_STATE_ONLINE + ASSERT_EQ(result, DEVICE_STATE_ONLINE); + // check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnIpcCmd_004 + * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + * 2. data.WriteString(pkgname) + * data.WriteInt32(DEVICE_STATE_OFFLINE) + * data.WriteRawData(nullptr, deviceSize) + * 3. call IpcCmdRegister OnIpcCmd with parameter + * 4. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_004, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; + MessageParcel reply; + MessageParcel data; + // 2. data.WriteString(pkgname) + data.WriteString("com.ohos.test"); + // data.WriteInt32(DEVICE_STATE_OFFLINE) + data.WriteInt32(DEVICE_STATE_OFFLINE); + size_t deviceSize = sizeof(DmDeviceInfo); + // data.WriteRawData(nullptr, deviceSize) + data.WriteRawData(nullptr, deviceSize); + // 3. call IpcCmdRegister OnIpcCmd with parameter + int ret = 0; + int result = 0; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); + result = reply.ReadInt32(); + // check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnIpcCmd_005 + * @tc.desc: 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + * 2. data.WriteString(pkgname) + * data.WriteInt32(DEVICE_INFO_CHANGED) + * data.WriteRawData(nullptr, deviceSize) + * 3. call IpcCmdRegister OnIpcCmd with parameter + * 4. check ret is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(IpcCmdRegisterTest, OnIpcCmd_005, testing::ext::TestSize.Level0) +{ + // 1. set cmdCode SERVER_DEVICE_STATE_NOTIFY + int32_t cmdCode = SERVER_DEVICE_STATE_NOTIFY; + MessageParcel reply; + MessageParcel data; + // 2. data.WriteString(pkgname) + data.WriteString("com.ohos.test"); + // data.WriteInt32(DEVICE_INFO_CHANGED) + data.WriteInt32(DEVICE_INFO_CHANGED); + size_t deviceSize = sizeof(DmDeviceInfo); + // data.WriteRawData(nullptr, deviceSize) + data.WriteRawData(nullptr, deviceSize); + // 3. call IpcCmdRegister OnIpcCmd with parameter + int ret = 0; + int result = 0; + ret = IpcCmdRegister::GetInstance().OnIpcCmd(cmdCode, data, reply); + result = reply.ReadInt32(); + // 4.check ret is DM_OK + ASSERT_EQ(ret, DM_OK); +} +} // namespace +ON_IPC_SET_REQUEST(REGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + sptr listener = pReq->GetListener(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_TRANSACTION_FAILED; + } + if (!data.WriteRemoteObject(listener)) { + LOGE("write listener failed"); + return DM_IPC_TRANSACTION_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(REGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(UNREGISTER_DEVICE_MANAGER_LISTENER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::string pkgName = pBaseReq->GetPkgName(); + if (!data.WriteString(pkgName)) { + LOGE("write papam failed"); + return DM_IPC_TRANSACTION_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNREGISTER_DEVICE_MANAGER_LISTENER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_TRUST_DEVICE_LIST, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + if (!data.WriteString(pkgName)) { + LOGE("write pkg failed"); + return DM_IPC_TRANSACTION_FAILED; + } + if (!data.WriteString(extra)) { + LOGE("write extra failed"); + return DM_IPC_TRANSACTION_FAILED; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + int32_t deviceNum = reply.ReadInt32(); + if (deviceNum > 0) { + std::vector deviceInfoVec; + DmDeviceInfo *pDmDeviceinfo = nullptr; + for (int32_t i = 0; i < deviceNum; ++i) { + pDmDeviceinfo = nullptr; + pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo)); + if (pDmDeviceinfo == nullptr) { + LOGE("GetTrustedDeviceList read node info failed!"); + pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED); + return DM_IPC_TRANSACTION_FAILED; + } + deviceInfoVec.emplace_back(*pDmDeviceinfo); + } + pRsp->SetDeviceVec(deviceInfoVec); + } + pRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_LOCAL_DEVICE_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + if (!data.WriteString(pkgName)) { + return DM_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_LOCAL_DEVICE_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + DmDeviceInfo *localDeviceInfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo)); + if (localDeviceInfo == nullptr) { + LOGE("write subscribe info failed"); + } + pRsp->SetLocalDeviceInfo(*localDeviceInfo); + pRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_UDID_BY_NETWORK, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string netWorkId = pReq->GetNetWorkId(); + if (!data.WriteString(pkgName)) { + return DM_FLATTEN_OBJECT; + } + if (!data.WriteString(netWorkId)) { + return DM_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_UDID_BY_NETWORK, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + pRsp->SetErrCode(reply.ReadInt32()); + pRsp->SetUdid(reply.ReadString()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(GET_UUID_BY_NETWORK, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string netWorkId = pReq->GetNetWorkId(); + if (!data.WriteString(pkgName)) { + return DM_FLATTEN_OBJECT; + } + if (!data.WriteString(netWorkId)) { + return DM_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(GET_UUID_BY_NETWORK, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + pRsp->SetErrCode(reply.ReadInt32()); + pRsp->SetUuid(reply.ReadString()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(START_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + const DmSubscribeInfo dmSubscribeInfo = pReq->GetSubscribeInfo(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteRawData(&dmSubscribeInfo, sizeof(DmSubscribeInfo))) { + LOGE("write subscribe info failed"); + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(START_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + uint16_t subscribeId = pReq->GetSubscribeId(); + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteInt16((int16_t)subscribeId)) { + LOGE("write subscribeId failed"); + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(STOP_DEVICE_DISCOVER, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(AUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + int32_t authType = pReq->GetAuthType(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + std::string deviceId = deviceInfo.deviceId; + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteString(extra)) { + LOGE("write extra failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteString(deviceId)) { + LOGE("write extra failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteInt32(authType)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(AUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(UNAUTHENTICATE_DEVICE, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + DmDeviceInfo deviceInfo = pReq->GetDeviceInfo(); + std::string deviceId = deviceInfo.deviceId; + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + if (!data.WriteString(deviceId)) { + LOGE("write extra failed"); + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNAUTHENTICATE_DEVICE, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(VERIFY_AUTHENTICATION, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string authPara = pReq->GetAuthPara(); + if (!data.WriteString(authPara)) { + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(VERIFY_AUTHENTICATION, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(SERVER_GET_DMFA_INFO, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string packagename = pReq->GetPkgName(); + if (!data.WriteString(packagename)) { + LOGE("write pkgName failed"); + return DM_IPC_FLATTEN_OBJECT; + } + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_GET_DMFA_INFO, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + std::shared_ptr pRsp = std::static_pointer_cast(pBaseRsp); + DmAuthParam authParam; + authParam.direction = reply.ReadInt32(); + authParam.authType = reply.ReadInt32(); + authParam.authToken = reply.ReadString(); + authParam.packageName = reply.ReadString(); + authParam.appName = reply.ReadString(); + authParam.appDescription = reply.ReadString(); + authParam.business = reply.ReadInt32(); + authParam.pincode = reply.ReadInt32(); + pRsp->SetDmAuthParam(authParam); + return DM_OK; +} + +ON_IPC_SET_REQUEST(SERVER_USER_AUTH_OPERATION, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + int32_t action = pReq->GetOperation(); + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_TRANSACTION_FAILED; + } + if (!data.WriteInt32(action)) { + LOGE("write action failed"); + return DM_WRITE_FAILED; + } + + return DM_OK; +} + +ON_IPC_READ_RESPONSE(SERVER_USER_AUTH_OPERATION, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(REGISTER_DEV_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = + std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_TRANSACTION_FAILED; + } + if (!data.WriteString(extra)) { + LOGE("write extra failed"); + return DM_WRITE_FAILED; + } + + return DM_OK; +} + +ON_IPC_READ_RESPONSE(REGISTER_DEV_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_SET_REQUEST(UNREGISTER_DEV_STATE_CALLBACK, std::shared_ptr pBaseReq, MessageParcel &data) +{ + std::shared_ptr pReq = + std::static_pointer_cast(pBaseReq); + std::string pkgName = pReq->GetPkgName(); + std::string extra = pReq->GetExtra(); + + if (!data.WriteString(pkgName)) { + LOGE("write pkgName failed"); + return DM_IPC_TRANSACTION_FAILED; + } + if (!data.WriteString(extra)) { + LOGE("write extra failed"); + return DM_WRITE_FAILED; + } + + return DM_OK; +} + +ON_IPC_READ_RESPONSE(UNREGISTER_DEV_STATE_CALLBACK, MessageParcel &reply, std::shared_ptr pBaseRsp) +{ + pBaseRsp->SetErrCode(reply.ReadInt32()); + return DM_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + DmDeviceState deviceState = static_cast(data.ReadInt32()); + DmDeviceInfo dmDeviceInfo; + size_t deviceSize = sizeof(DmDeviceInfo); + void *deviceInfo = (void *)data.ReadRawData(deviceSize); + if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) { + reply.WriteInt32(DM_IPC_COPY_FAILED); + return DM_OK; + } + switch (deviceState) { + case DEVICE_STATE_ONLINE: + DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, dmDeviceInfo); + break; + case DEVICE_STATE_OFFLINE: + DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, dmDeviceInfo); + break; + case DEVICE_INFO_CHANGED: + DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, dmDeviceInfo); + break; + case DEVICE_INFO_READY: + DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, dmDeviceInfo); + break; + default: + LOGE("unknown device state:%d", deviceState); + break; + } + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int16_t subscribeId = data.ReadInt16(); + DmDeviceInfo dmDeviceInfo; + size_t deviceSize = sizeof(DmDeviceInfo); + void *deviceInfo = (void *)data.ReadRawData(deviceSize); + if (deviceInfo != nullptr && memcpy_s(&dmDeviceInfo, deviceSize, deviceInfo, deviceSize) != 0) { + reply.WriteInt32(DM_IPC_COPY_FAILED); + return DM_IPC_COPY_FAILED; + } + DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, dmDeviceInfo); + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + int16_t subscribeId = data.ReadInt16(); + int32_t failedReason = data.ReadInt32(); + + if (failedReason == DM_OK) { + DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); + } else { + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); + } + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string deviceId = data.ReadString(); + std::string token = data.ReadString(); + int32_t status = data.ReadInt32(); + int32_t reason = data.ReadInt32(); + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason); + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_CMD(SERVER_VERIFY_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) +{ + std::string pkgName = data.ReadString(); + std::string deviceId = data.ReadString(); + int32_t resultCode = data.ReadInt32(); + int32_t flag = data.ReadInt32(); + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + reply.WriteInt32(DM_OK); + return DM_OK; +} + +ON_IPC_CMD(SERVER_DEVICE_FA_NOTIFY, MessageParcel &data, MessageParcel &reply) +{ + std::string packagename = data.ReadString(); + std::string paramJson = data.ReadString(); + DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson); + if (!reply.WriteInt32(DM_OK)) { + LOGE("write return failed"); + return DM_WRITE_FAILED; + } + return DM_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_ipc_cmd_register.h b/test/unittest/UTTest_ipc_cmd_register.h new file mode 100644 index 000000000..6a89dab7b --- /dev/null +++ b/test/unittest/UTTest_ipc_cmd_register.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_IPC_CMD_REGISTER_TEST_H +#define OHOS_IPC_CMD_REGISTER_TEST_H + +#include +#include + +#include +#include +#include + +#include "ipc_cmd_register.h" +#include "iremote_broker.h" +#include "single_instance.h" + +#include "ipc_types.h" +#include "ipc_req.h" +#include "ipc_rsp.h" +namespace OHOS { +namespace DistributedHardware { +class IpcCmdRegisterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_IPC_CMD_REGISTER_TEST_H diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index 1b25c056e..34482b441 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -168,8 +168,8 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) int ret = 0; // 2. Call IpcServerStub OnRemoteRequest with param ret = IpcServerStub::GetInstance().OnRemoteRequest(code, data, reply, option); - // 3. check ret not DM_OK - ASSERT_NE(ret, DM_OK); + // 3. check ret not ERR_INVALID_STATE + ASSERT_EQ(ret, ERR_INVALID_STATE); } /** diff --git a/test/unittest/UTTest_pin_auth.cpp b/test/unittest/UTTest_pin_auth.cpp new file mode 100644 index 000000000..114eb62c2 --- /dev/null +++ b/test/unittest/UTTest_pin_auth.cpp @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_pin_auth.h" + +#include + +#include + +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace DistributedHardware { +void PinAuthTest::SetUp() +{ +} + +void PinAuthTest::TearDown() +{ +} + +void PinAuthTest::SetUpTestCase() +{ +} + +void PinAuthTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); +/** + * @tc.name: DmAuthManager::ShowAuthInfo_001 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, ShowAuthInfo_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + std::string authToken = "123456"; + int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::ShowAuthInfo_002 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json jsonObject; + jsonObject[PIN_TOKEN] = 123456; + std::string authToken = jsonObject.dump(); + int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::ShowAuthInfo_003 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, ShowAuthInfo_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json jsonObject; + jsonObject[PIN_CODE_KEY] = 123456; + std::string authToken = jsonObject.dump(); + int32_t ret = pinAuth->ShowAuthInfo(authToken, nullptr); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::ShowAuthInfo_004 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, ShowAuthInfo_004, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json jsonObject; + jsonObject[PIN_CODE_KEY] = 123456; + std::string authToken = jsonObject.dump(); + int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: DmAuthManager::StartAuth_001 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, StartAuth_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + std::string authToken = ""; + int32_t ret = pinAuth->StartAuth(authToken, nullptr); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::StartAuth_002 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, StartAuth_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + std::string authToken = ""; + int32_t ret = pinAuth->StartAuth(authToken, authManager); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::StartAuth_003 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, StartAuth_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json jsonObject; + jsonObject[PIN_TOKEN] = 123456; + std::string authToken = jsonObject.dump(); + int32_t ret = pinAuth->StartAuth(authToken, authManager); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::StartAuth_004 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, StartAuth_004, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json jsonObject; + jsonObject[PIN_CODE_KEY] = 123456; + std::string authToken = jsonObject.dump(); + int32_t ret = pinAuth->StartAuth(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::VerifyAuthentication_001 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + std::string authToken; + std::string authParam = "1"; + int32_t ret = pinAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::VerifyAuthentication_001 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + std::string authToken; + std::string authParam = "0"; + int32_t ret = pinAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_OK); +} +/** + * @tc.name: DmAuthManager::VerifyAuthentication_003 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, VerifyAuthentication_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json authParamJson; + authParamJson[PIN_CODE_KEY] = 123456; + authParamJson[PIN_TOKEN] = 123456; + nlohmann::json authTokenJson; + authTokenJson[PIN_CODE_KEY] = 123456; + authTokenJson[PIN_TOKEN] = 123456; + std::string authToken = authTokenJson.dump(); + std::string authParam = authParamJson.dump(); + int32_t ret = pinAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::VerifyAuthentication_004 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_AUTH_INPUT_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, VerifyAuthentication_004, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json authParamJson; + authParamJson[PIN_CODE_KEY] = 012345; + authParamJson[PIN_TOKEN] = 123456; + nlohmann::json authTokenJson; + authTokenJson[PIN_CODE_KEY] = 123456; + authTokenJson[PIN_TOKEN] = 123456; + std::string authToken = authTokenJson.dump(); + std::string authParam = authParamJson.dump(); + int32_t ret = pinAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_AUTH_INPUT_FAILED); +} + +/** + * @tc.name: DmAuthManager::VerifyAuthentication_005 + * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthTest, VerifyAuthentication_005, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuth = std::make_shared(); + nlohmann::json authParamJson; + authParamJson[PIN_CODE_KEY] = 012345; + authParamJson[PIN_TOKEN] = 123456; + nlohmann::json authTokenJson; + authTokenJson[PIN_CODE_KEY] = 123456; + authTokenJson[PIN_TOKEN] = 123456; + std::string authToken = authTokenJson.dump(); + std::string authParam = authParamJson.dump(); + pinAuth->VerifyAuthentication(authToken, authParam); + pinAuth->VerifyAuthentication(authToken, authParam); + int32_t ret = pinAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_FAILED); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_pin_auth.h b/test/unittest/UTTest_pin_auth.h new file mode 100644 index 000000000..4fb2f4796 --- /dev/null +++ b/test/unittest/UTTest_pin_auth.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_PIN_AUTH_TEST_H +#define OHOS_PIN_AUTH_TEST_H + +#include + +#include "pin_auth.h" + +namespace OHOS { +namespace DistributedHardware { +class PinAuthTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_PIN_AUTH_TEST_H \ No newline at end of file diff --git a/test/unittest/UTTest_pin_auth_ui.cpp b/test/unittest/UTTest_pin_auth_ui.cpp new file mode 100644 index 000000000..cb11c0e99 --- /dev/null +++ b/test/unittest/UTTest_pin_auth_ui.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UTTest_pin_auth_ui.h" + +#include + +#include + +#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 { +void PinAuthUiTest::SetUp() +{ +} + +void PinAuthUiTest::TearDown() +{ +} + +void PinAuthUiTest::SetUpTestCase() +{ +} + +void PinAuthUiTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); +/** + * @tc.name: PinAuthUi::ShowPinDialog_001 + * @tc.desc: Call ShowPinDialog to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthUiTest, ShowPinDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuthUi = std::make_shared(); + int32_t code = 123456; + int32_t ret = pinAuthUi->ShowPinDialog(code, nullptr); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: PinAuthUi::ShowPinDialog_002 + * @tc.desc: Call ShowPinDialog to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuthUi = std::make_shared(); + int32_t code = 123456; + int32_t ret = pinAuthUi->ShowPinDialog(code, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: PinAuthUi::ShowPinDialog_001 + * @tc.desc: Call InputPinDialog to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuthUi = std::make_shared(); + int32_t code = 123456; + int32_t ret = pinAuthUi->InputPinDialog(code, nullptr); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: PinAuthUi::ShowPinDialog_001 + * @tc.desc: Call InputPinDialog to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr pinAuthUi = std::make_shared(); + int32_t code = 123456; + int32_t ret = pinAuthUi->InputPinDialog(code, authManager); + ASSERT_EQ(ret, DM_OK); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_pin_auth_ui.h b/test/unittest/UTTest_pin_auth_ui.h new file mode 100644 index 000000000..4e3cb16b7 --- /dev/null +++ b/test/unittest/UTTest_pin_auth_ui.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_PIN_AUTH_UI_TEST_H +#define OHOS_PIN_AUTH_UI_TEST_H + +#include + +#include "pin_auth_ui.h" + +namespace OHOS { +namespace DistributedHardware { +class PinAuthUiTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_PIN_AUTH_UI_TEST_H \ No newline at end of file diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index f1a1ad6ab..666cc3b20 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -19,11 +19,17 @@ #include #include +#include #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_device_info.h" #include "dm_log.h" +#include "ipc_notify_auth_result_req.h" +#include "ipc_notify_device_state_req.h" +#include "ipc_notify_device_found_req.h" +#include "ipc_notify_discover_result_req.h" +#include "ipc_notify_verify_auth_result_req.h" #include "parameter.h" #include "softbus_connector.h" #include "system_ability_definition.h" @@ -44,7 +50,122 @@ void SoftbusConnectorTest::TearDownTestCase() } namespace { -static std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr deviceStateMgr = std::make_shared(softbusConnector, listener, hiChainConnector); +std::shared_ptr discoveryMgr = std::make_shared(softbusConnector, listener); +/** + * @tc.name: DeviceOnLine_001 + * @tc.desc: go tothe corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, DeviceOnLine_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info; + strncpy(info.deviceId, "123", sizeof(info.deviceId)); + deviceStateMgr->RegisterSoftbusStateCallback(); + DeviceOnLine(SoftbusConnector::stateCallbackMap_, info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + ret = true; + listener->ipcServerListener_.req_ = nullptr; + } + EXPECT_EQ(ret, true); + SoftbusConnector::stateCallbackMap_.clear(); +} + +/** + * @tc.name: DeviceOnLine_002 + * @tc.desc: go tothe corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, DeviceOnLine_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info; + strncpy(info.deviceId, "123", sizeof(info.deviceId)); + DeviceOnLine(SoftbusConnector::stateCallbackMap_, info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + ret = true; + listener->ipcServerListener_.req_ = nullptr; + } + EXPECT_EQ(ret, false); + SoftbusConnector::stateCallbackMap_.clear(); +} + +/** + * @tc.name: DeviceOffLine_001 + * @tc.desc: go tothe corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, DeviceOffLine_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info; + strncpy(info.deviceId, "123", sizeof(info.deviceId)); + deviceStateMgr->RegisterSoftbusStateCallback(); + DeviceOffLine(SoftbusConnector::stateCallbackMap_, info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + ret = true; + listener->ipcServerListener_.req_ = nullptr; + } + EXPECT_EQ(ret, true); + SoftbusConnector::stateCallbackMap_.clear(); +} + +/** + * @tc.name: DeviceOffLine_002 + * @tc.desc: go tothe corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, DeviceOffLine_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info; + strncpy(info.deviceId, "123", sizeof(info.deviceId)); + DeviceOffLine(SoftbusConnector::stateCallbackMap_, info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + ret = true; + listener->ipcServerListener_.req_ = nullptr; + } + EXPECT_EQ(ret, false); + SoftbusConnector::stateCallbackMap_.clear(); +} + +/** + * @tc.name: SoftbusConnector_001 + * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, SoftbusConnector_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr m_SoftbusConnector = std::make_shared(); + ASSERT_NE(m_SoftbusConnector, nullptr); +} + +/** + * @tc.name: SoftbusConnector_002 + * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr,and delete it + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr m_SoftbusConnector = std::make_shared(); + m_SoftbusConnector.reset(); + EXPECT_EQ(m_SoftbusConnector, nullptr); +} + /** * @tc.name: Init_001 * @tc.desc: go tothe corrort case and return DM_OK @@ -66,14 +187,11 @@ HWTEST_F(SoftbusConnectorTest, Init_001, testing::ext::TestSize.Level0) HWTEST_F(SoftbusConnectorTest, RegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0) { std::string pkgName = "com.ohos.helloworld"; - std::shared_ptr listener_ = std::make_shared(); - std::shared_ptr discoveryMgr_ = - std::make_shared(softbusConnector, listener_); - int ret = softbusConnector->RegisterSoftbusDiscoveryCallback( - pkgName, std::shared_ptr(discoveryMgr_)); - int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName); - EXPECT_EQ(ret1, 1); - EXPECT_EQ(ret, DM_OK); + int ret1 = softbusConnector->RegisterSoftbusDiscoveryCallback( + pkgName, std::shared_ptr(discoveryMgr)); + int ret = SoftbusConnector::discoveryCallbackMap_.count(pkgName); + EXPECT_EQ(ret1, DM_OK); + EXPECT_EQ(ret, 1); } /** @@ -92,6 +210,23 @@ HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing:: EXPECT_EQ(ret, DM_OK); } +/** + * @tc.name: RegisterSoftbusStateCallback_001 + * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusStateCallback function to corrort ,return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, RegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.helloworld"; + int ret = softbusConnector->RegisterSoftbusStateCallback( + pkgName, std::shared_ptr(deviceStateMgr)); + int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName); + EXPECT_EQ(ret1, DM_OK); + EXPECT_EQ(ret, 0); + softbusConnector->UnRegisterSoftbusStateCallback(pkgName); +} + /** * @tc.name: UnRegisterSoftbusStateCallback_001 * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusStateCallback function to corrort ,return DM_OK @@ -147,6 +282,47 @@ HWTEST_F(SoftbusConnectorTest, StartDiscovery_001, testing::ext::TestSize.Level0 EXPECT_EQ(ret, DM_DISCOVERY_FAILED); } +/** + * @tc.name: StopDiscovery_001 + * @tc.desc: get StartDiscovery to wroing master and return DM_DISCOVERY_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, StopDiscovery_001, testing::ext::TestSize.Level0) +{ + uint16_t subscribeId = (uint16_t)123456; + int ret = softbusConnector->StopDiscovery(subscribeId); + EXPECT_NE(ret, 0); +} + +/** + * @tc.name: GetUdidByNetworkId_001 + * @tc.desc: get StartDiscovery to wroing master and return DM_DISCOVERY_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0) +{ + const char *networkId = "123456"; + std::string udid; + int ret = softbusConnector->GetUdidByNetworkId(networkId, udid); + EXPECT_NE(ret, 0); +} + +/** + * @tc.name: GetUuidByNetworkId_001 + * @tc.desc: get StartDiscovery to wroing master and return DM_DISCOVERY_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0) +{ + const char *networkId = "123456"; + std::string udid; + int ret = softbusConnector->GetUdidByNetworkId(networkId, udid); + EXPECT_NE(ret, 0); +} + /** * @tc.name: IsDeviceOnLine_001 * @tc.desc: set deviceId = "12333";,and return false @@ -169,33 +345,51 @@ HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_001, testing::ext::TestSize.Level0 HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_002, testing::ext::TestSize.Level0) { std::string deviceId = "145677"; + NodeBasicInfo Info; + strncpy(Info.networkId, "145677", sizeof(Info.networkId)); bool ret = softbusConnector->IsDeviceOnLine(deviceId); EXPECT_EQ(ret, false); } /** - * @tc.name: SoftbusConnector_001 - * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr + * @tc.name: GetSoftbusSession_001 + * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr,and delete it * @tc.type: FUNC * @tc.require: AR000GHSJK */ -HWTEST_F(SoftbusConnectorTest, SoftbusConnector_001, testing::ext::TestSize.Level0) +HWTEST_F(SoftbusConnectorTest, GetSoftbusSession_001, testing::ext::TestSize.Level0) { - std::shared_ptr m_SoftbusConnector = std::make_shared(); - ASSERT_NE(m_SoftbusConnector, nullptr); + std::shared_ptr softSession = softbusConnector->GetSoftbusSession(); + EXPECT_NE(softSession, nullptr); } /** - * @tc.name: SoftbusConnector_002 + * @tc.name: GetSoftbusSession_001 * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr,and delete it * @tc.type: FUNC * @tc.require: AR000GHSJK */ -HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Level0) +HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_001, testing::ext::TestSize.Level0) { - std::shared_ptr m_SoftbusConnector = std::make_shared(); - m_SoftbusConnector.reset(); - EXPECT_EQ(m_SoftbusConnector, nullptr); + std::string deviceId = "12345678"; + SoftbusConnector::discoveryDeviceInfoMap_[deviceId]; + bool ret = softbusConnector->HaveDeviceInMap(deviceId); + EXPECT_EQ(ret, true); + SoftbusConnector::discoveryDeviceInfoMap_.clear(); +} + +/** + * @tc.name: GetSoftbusSession_001 + * @tc.desc: set SoftbusConnector to new a pointer ,and the pointer nou equal nullptr,and delete it + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_002, testing::ext::TestSize.Level0) +{ + std::string deviceId = "12345678"; + bool ret = softbusConnector->HaveDeviceInMap(deviceId); + EXPECT_EQ(ret, false); + SoftbusConnector::discoveryDeviceInfoMap_.clear(); } /** @@ -225,6 +419,7 @@ HWTEST_F(SoftbusConnectorTest, GetConnectionIpAddress_002, testing::ext::TestSiz int ret = softbusConnector->GetConnectionIpAddress(deviceId, ipAddress); EXPECT_EQ(ret, DM_FAILED); } + /** * @tc.name: GetConnectionIpAddress_003 * @tc.desc: set deviceInfo.addrNum = -1;go to second master and return DM_FAILED @@ -315,6 +510,226 @@ HWTEST_F(SoftbusConnectorTest, CovertNodeBasicInfoToDmDevice_001, testing::ext:: int ret = softbusConnector->CovertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); EXPECT_EQ(ret, DM_OK); } + +/** + * @tc.name: CovertNodeBasicInfoToDmDevice_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, CovertDeviceInfoToDmDevice_001, testing::ext::TestSize.Level0) +{ + DeviceInfo deviceInfo = { + .devId = "123456", + .devType = (DeviceType)1, + .devName = "11111" + }; + DmDeviceInfo dm; + DmDeviceInfo dm_1 = { + .deviceId = "123456", + .deviceName = "11111", + .deviceTypeId = 1 + }; + softbusConnector->CovertDeviceInfoToDmDevice(deviceInfo, dm); + bool ret = false; + if (strcmp(dm.deviceId, dm_1.deviceId) == 0) { + ret = true; + } + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: OnSoftBusDeviceOnline_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "123456"; + SoftbusConnector::discoveryDeviceInfoMap_[deviceId]; + NodeBasicInfo *info = nullptr; + softbusConnector->OnSoftBusDeviceOnline(info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: OnSoftBusDeviceOnline_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_002, testing::ext::TestSize.Level0) +{ + std::string deviceId = "123456"; + NodeBasicInfo info = { + .networkId = "123456", + .deviceName = "123456", + .deviceTypeId = 1 + }; + std::string pkgName = "com.ohos.helloworld"; + softbusConnector->RegisterSoftbusStateCallback( + pkgName, std::shared_ptr(deviceStateMgr)); + softbusConnector->OnSoftBusDeviceOnline(&info); + sleep(1); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, true); + softbusConnector->UnRegisterSoftbusStateCallback(pkgName); +} + +/** + * @tc.name: OnSoftBusDeviceOnline_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftBusDeviceOnline_003, testing::ext::TestSize.Level0) +{ + std::string deviceId = "123456"; + NodeBasicInfo info = { + .networkId = "123456", + .deviceName = "123456", + .deviceTypeId = 1 + }; + std::string oldName = DM_PKG_NAME; + std::string DM_PKG_NAME = "com.ohos.test"; + softbusConnector->OnSoftBusDeviceOnline(&info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, false); + DM_PKG_NAME = oldName; +} + +/** + * @tc.name: OnSoftbusDeviceOffline_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceOffline_001, testing::ext::TestSize.Level0) +{ + NodeBasicInfo *info = nullptr; + softbusConnector->OnSoftbusDeviceOffline(info); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + ret = true; + } + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: OnSoftbusDeviceOffline_002 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceOffline_002, testing::ext::TestSize.Level0) +{ + NodeBasicInfo info = { + .networkId = "123456", + .deviceName = "123456", + .deviceTypeId = 1 + }; + std::string pkgName = "com.ohos.helloworld"; + softbusConnector->RegisterSoftbusStateCallback( + pkgName, std::shared_ptr(deviceStateMgr)); + softbusConnector->OnSoftbusDeviceOffline(&info); + sleep(1); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, true); + softbusConnector->UnRegisterSoftbusStateCallback(pkgName); +} + +/** + * @tc.name: OnSoftbusDeviceFound_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_001, testing::ext::TestSize.Level0) +{ + DeviceInfo *device = nullptr; + softbusConnector->OnSoftbusDeviceFound(device); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, false); + +} + +/** + * @tc.name: OnSoftbusDiscoveryFailed_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryFailed_001, testing::ext::TestSize.Level0) +{ + int32_t subscribeId= 123456; + DiscoveryFailReason failReason = (DiscoveryFailReason)1; + std::string pkgName = "com.ohos.helloworld"; + softbusConnector->RegisterSoftbusDiscoveryCallback( + pkgName, std::shared_ptr(discoveryMgr)); + softbusConnector->OnSoftbusDiscoveryFailed(subscribeId, failReason); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, true); + softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName); +} + +/** + * @tc.name: OnSoftbusDiscoverySuccess_001 + * @tc.desc: go to the corrort case and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoverySuccess_001, testing::ext::TestSize.Level0) +{ + int32_t subscribeId= 123456; + std::string pkgName = "com.ohos.helloworld"; + softbusConnector->RegisterSoftbusDiscoveryCallback( + pkgName, std::shared_ptr(discoveryMgr)); + softbusConnector->OnSoftbusDiscoverySuccess(subscribeId); + bool ret = false; + if (listener->ipcServerListener_.req_ != nullptr) { + listener->ipcServerListener_.req_ = nullptr; + ret = true; + } + EXPECT_EQ(ret, true); + softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName); +} + +/** + * @tc.name: OnParameterChgCallback_001 + * @tc.desc: set some corrort para and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusConnectorTest, OnParameterChgCallback_001, testing::ext::TestSize.Level0) +{ + EXPECT_EQ(DM_OK, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_softbus_session.cpp b/test/unittest/UTTest_softbus_session.cpp index 41bc71f33..c82e60b15 100644 --- a/test/unittest/UTTest_softbus_session.cpp +++ b/test/unittest/UTTest_softbus_session.cpp @@ -38,11 +38,11 @@ void SoftbusSessionTest::TearDownTestCase() namespace { std::shared_ptr softbusSession = std::make_shared(); -std::shared_ptr listener = std::make_shared(); +std::shared_ptr listener_ = std::make_shared(); std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr hiChainConnector = std::make_shared(); -std::shared_ptr discoveryMgr = - std::make_shared(softbusConnector, listener, hiChainConnector); +std::shared_ptr discoveryMgr_ = + std::make_shared(softbusConnector, listener_, hiChainConnector); /** * @tc.name: OpenAuthSession_001 @@ -98,7 +98,7 @@ HWTEST_F(SoftbusSessionTest, SendData_002, testing::ext::TestSize.Level0) jsonObj[TAG_TYPE] = msgType; std::string message = jsonObj.dump(); int32_t sessionId = 0; - softbusSession->RegisterSessionCallback(std::shared_ptr(discoveryMgr)); + softbusSession->RegisterSessionCallback(std::shared_ptr(discoveryMgr_)); int ret = softbusSession->SendData(sessionId, message); EXPECT_EQ(ret, DM_FAILED); } @@ -155,6 +155,19 @@ HWTEST_F(SoftbusSessionTest, GetPeerDeviceId_001, testing::ext::TestSize.Level0) EXPECT_EQ(ret, DM_OK); } +/** + * @tc.name: RegisterSessionCallback_001 + * @tc.desc: set info to null and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(SoftbusSessionTest, RegisterSessionCallback_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr callback; + int ret = softbusSession->RegisterSessionCallback(callback); + EXPECT_EQ(ret, DM_OK); +} + /** * @tc.name: UnRegisterSessionCallback_001 * @tc.desc: set info to null and return DM_FAILED diff --git a/test/unittest/mock/device_auth.h b/test/unittest/mock/device_auth.h index b55bf24f5..b46bb5e99 100644 --- a/test/unittest/mock/device_auth.h +++ b/test/unittest/mock/device_auth.h @@ -71,8 +71,8 @@ using OsAccountEnum = enum _OsAccountEnum : int32_t { DEFAULT_OS_ACCOUNT = 0, INVALID_OS_ACCOUNT = -1, - ANY_OS_ACCOUNT = -2, -}; + ANY_OS_ACCOUNT = -2 +} ; using GroupType = enum _GroupType : int32_t { ALL_GROUP = 0, @@ -80,7 +80,7 @@ using GroupType = enum _GroupType : int32_t { PEER_TO_PEER_GROUP = 256, COMPATIBLE_GROUP = 512, ACROSS_ACCOUNT_AUTHORIZE_GROUP = 1282 -}; +} ; using GroupOperationCode = enum _GroupOperationCode : int32_t { GROUP_CREATE = 0, @@ -96,7 +96,7 @@ using GroupAuthForm = enum _GroupAuthForm : int32_t { AUTH_FORM_ACCOUNT_UNRELATED = 0, AUTH_FORM_IDENTICAL_ACCOUNT = 1, AUTH_FORM_ACROSS_ACCOUNT = 2, -}; +} ; using CredentialCode = enum _CredentialCode : int32_t { IMPORT_SELF_CREDENTIAL = 0, diff --git a/test/unittest/mock/mock_ipc_client_proxy.h b/test/unittest/mock/mock_ipc_client_proxy.h index fd134ac2d..cc8b0746c 100644 --- a/test/unittest/mock/mock_ipc_client_proxy.h +++ b/test/unittest/mock/mock_ipc_client_proxy.h @@ -25,6 +25,8 @@ namespace OHOS { namespace DistributedHardware { class MockIpcClientProxy : public IpcClientProxy, public RefBase { public: + MOCK_METHOD1(Init, int32_t(const std::string &pkgName)); + MOCK_METHOD1(UnInit, int32_t(const std::string &pkgName)); MOCK_METHOD3(SendRequest, int32_t(int32_t cmdCode, std::shared_ptr req, std::shared_ptr rsp)); }; } // namespace DistributedHardware diff --git a/test/unittest/mock/softbus_bus_center.cpp b/test/unittest/mock/softbus_bus_center.cpp index 9998102d3..a510a0a51 100644 --- a/test/unittest/mock/softbus_bus_center.cpp +++ b/test/unittest/mock/softbus_bus_center.cpp @@ -18,15 +18,31 @@ int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInfoKey key, uint8_t *info, int32_t infoLen) { - return 0; + if (pkgName == "ohos.distributedhardware.devicemanager") { + info = (uint8_t*)networkId; + return 0; + } + return -1; } int32_t RegNodeDeviceStateCb(const char *pkgName, INodeStateCb *callback) { - return 0; + if (pkgName == "ohos.distributedhardware.devicemanager") { + return 0; + } + return -1; }; int32_t GetAllNodeDeviceInfo(const char *pkgName, NodeBasicInfo **info, int32_t *infoNum) { - return 0; + if (pkgName == "ohos.distributedhardware.devicemanager") { + *infoNum = 1; + *info = { + .networkId = "123456", + .deviceName = "123456", + .deviceTypeId = 1 + }; + return 0; + } + return -1; } \ No newline at end of file -- Gitee