From 2d1267b962997546550ac92359715f1104d5f9c4 Mon Sep 17 00:00:00 2001 From: "xiaocong.ran" Date: Fri, 11 Mar 2022 19:20:25 +0800 Subject: [PATCH] UT Signed-off-by: xiaocong.ran Change-Id: I6b4d29d66169cb0a9e5de3e7935771b9b2378892 --- .../dependency/softbus/softbus_connector.h | 4 + test/unittest/BUILD.gn | 60 +- test/unittest/UTTest_device_manager_impl.cpp | 2514 ++++++++++ test/unittest/UTTest_device_manager_impl.h | 74 + .../unittest/UTTest_device_manager_notify.cpp | 4428 +++++++++++++++++ test/unittest/UTTest_device_manager_notify.h | 104 + .../UTTest_dm_common_event_manager.cpp | 145 + .../unittest/UTTest_dm_common_event_manager.h | 45 + test/unittest/UTTest_hichain_connector.cpp | 511 ++ test/unittest/UTTest_hichain_connector.h | 46 + test/unittest/UTTest_ipc_client_stub.cpp | 6 +- test/unittest/UTTest_ipc_server_stub.cpp | 6 +- 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 | 365 +- test/unittest/UTTest_softbus_session.cpp | 21 +- test/unittest/mock/device_auth.cpp | 8 + test/unittest/mock/mock_ipc_client_proxy.h | 2 + 20 files changed, 8751 insertions(+), 31 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_dm_common_event_manager.cpp create mode 100644 test/unittest/UTTest_dm_common_event_manager.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_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..78164a503 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -22,23 +22,61 @@ group("unittest") { ":UTTest_auth_message_processor", ":UTTest_auth_request_state", ":UTTest_auth_response_state", + ":UTTest_device_manager_impl", + ":UTTest_device_manager_notify", ":UTTest_device_manager_service", ":UTTest_device_manager_service_listener", ":UTTest_dm_auth_manager", ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", ":UTTest_dm_discovery_manager", + ":UTTest_hichain_connector", ":UTTest_ipc_client_manager", ":UTTest_ipc_client_proxy", ":UTTest_ipc_client_stub", ":UTTest_ipc_server_client_proxy", ":UTTest_ipc_server_listener", ":UTTest_ipc_server_stub", + ":UTTest_pin_auth", + ":UTTest_pin_auth_ui", ":UTTest_softbus_connector", ":UTTest_softbus_session", ] } +## 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 +125,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 }}} @@ -342,6 +394,7 @@ config("device_manager_test_common_public_config") { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${ext_path}/pin_auth/include", "${utils_path}/include", "${utils_path}/include/ipc/standard", "${services_path}/include", @@ -403,6 +456,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_device_manager_impl.cpp b/test/unittest/UTTest_device_manager_impl.cpp new file mode 100644 index 000000000..830f26ae0 --- /dev/null +++ b/test/unittest/UTTest_device_manager_impl.cpp @@ -0,0 +1,2514 @@ +/* + * 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..f6d218c61 --- /dev/null +++ b/test/unittest/UTTest_device_manager_notify.cpp @@ -0,0 +1,4428 @@ +/* + * 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); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_001 + * @tc.desc: 1. set pkgName not null + * set dmInitCallback not null + * 2. set count to 0 + * 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, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count to 0 + 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); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_002 + * @tc.desc: 1. set pkgName not null + * 2. set DmFaCallback not null + * 3. set checkMap not null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set DmFaCallback 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); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_003 + * @tc.desc: 1. set pkgName not null + * 2. set DmFaCallback not null + * 3. set checkMap not null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_004 + * @tc.desc: 1. set pkgName not null + * 2. set count null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count to 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); +} + +/** + * @tc.name: RegisterDeviceManagerFaCallback_005 + * @tc.desc: 1. set pkgName com.ohos.test + * 2. set count null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify with testpkcName + * 5. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName com.ohos.test + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_001 + * @tc.desc: 1. set pkgName not null + * 2. set dmInitCallback not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify with testpkcName + * 5. check checkMap not null + * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter + * 7. Get checkMap from DeviceManagerNotify + * 8. check checkMap null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_002 + * @tc.desc: 1. set pkgName not null + * 2. set count null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeviceManagerFaCallback + * 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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 RegisterDeviceManagerFaCallback + 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); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_003 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count not null + int count = 1; + 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, 2); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_004 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: UnRegisterDeviceManagerFaCallback_005 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnRemoteDied_001 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnRemoteDied + * 8. check if dmInitCallback OnRemoteDied called + * 9. check checkMap not null + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnRemoteDied_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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: OnDeviceOnline_001 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceOnline + * 7. check if callback OnDeviceOnline called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count not null + int count = 0; + // set Callback not null + 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); +} + +/** + * @tc.name: OnDeviceOnline_002 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback + * 5. check checkMap not null + * 6. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count not null + int count = 0; + // set Callback not null + 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); +} + +/** + * @tc.name: OnDeviceOnline_003 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count not null + int count = 0; + // set Callback not null + 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 + 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); +} + +/** + * @tc.name: OnDeviceOnline_004 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName + * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName + * 8. check if callback OnDeviceOnline called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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 + 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); +} + +/** + * @tc.name: OnDeviceOnline_005 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnDeviceOffline_001 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_001, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnDeviceOffline_002 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnDeviceOffline_003 + * @tc.desc: 1. set pkgName not null + * 2. set count not null + * 3. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_003, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnDeviceOffline_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. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set count 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); +} + +/** + * @tc.name: OnDeviceOffline_005 + * @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 DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName + * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName + * 8. check if callback OnDeviceOffline called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_005, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = "com.ohos.test"; + // set count 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); +} + +/** + * @tc.name: OnDeviceChanged_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 DeviceManagerNotify OnDeviceChanged + * 7. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: OnDeviceChanged_002 + * @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. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: OnDeviceChanged_003 + * @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. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: OnDeviceChanged_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. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0) +{ + // 1. set pkgName not null + std::string pkgName = ""; + // set count 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); +} + +/** + * @tc.name: OnDeviceChanged_005 + * @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. set testpkcName com.ohos.test1 + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +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); +} + +/** + * @tc.name: OnDeviceReady_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. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady_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 UnRegisterDeviceStateCallback withtestPkgName + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); + // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceReady(testPkgName, deviceInfo); + // 8. check if callback OnDeviceChanged called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDeviceReady_002 + * @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. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceReady with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady_002, 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 OnDeviceReady with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceReady(testPkgName, deviceInfo); + // 8. check if callback OnDeviceReady called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnDeviceReady_003 + * @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. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceReady with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady_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 OnDeviceReady with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceReady(testPkgName, deviceInfo); + // 8. check if callback OnDeviceReady called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnDeviceReady_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. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceReady with testpkcName + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady_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. set testpkcName com.ohos.test1 + std::string testPkgName = "com.ohos.test1"; + // 7. call DeviceManagerNotify OnDeviceReady with testpkcName + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceReady(testPkgName, deviceInfo); + // 8. check if callback OnDeviceReady called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDeviceReady_005 + * @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. set testpkcName null + * 7. call DeviceManagerNotify OnDeviceReady + * 8. check if callback OnDeviceChanged called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady_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 OnDeviceReady + DmDeviceInfo deviceInfo; + DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, deviceInfo); + // 7. check if callback OnDeviceReady called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnDeviceFound_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 DeviceManagerNotify OnDeviceFound + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound_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); + // 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); +} + +/** + * @tc.name: OnDeviceFound_002 + * @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 DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound_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); + // 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); +} + +/** + * @tc.name: OnDeviceFound_003 + * @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 DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound_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); + // 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); +} + +/** + * @tc.name: OnDeviceFound_004 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound_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); + // set subscribeId not null + uint16_t subscribeId = 0; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback 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); +} + +/** + * @tc.name: OnDeviceFound_005 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound_005, 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); +} + +/** + * @tc.name: OnDiscoveryFailed_001 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoveryFailed_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); + // 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 OnDiscoveryFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoveryFailed called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnDiscoveryFailed_002 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoveryFailed_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); + // 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; + std::string testPkgName = "com.ohos.test1"; + // 6. call DeviceManagerNotify OnDiscoveryFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoveryFailed called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDiscoveryFailed_003 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoveryFailed_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); + // 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 OnDiscoveryFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason); + // 7. check if callback OnDiscoveryFailed called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDiscoveryFailed_004 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoveryFailed_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); + // 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; + std::string testPkgName = ""; + // 6. call DeviceManagerNotify OnDiscoveryFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoveryFailed called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDiscoveryFailed_005 + * @tc.desc: 1. set pkgName not null + * set callback not null + * set subscribeId not null + * 2. set checkMap null + * 3. call DeviceManagerNotifyTest RegisterDiscoveryCallback with parameter + * 4. Get checkMap from DeviceManagerNotify + * 5. check checkMap not null + * 6. call DeviceManagerNotify OnDeviceFound With testPkgName + * 7. check if callback OnDeviceFound called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoveryFailed_005, 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); + int32_t failedReason = 0; + std::string testPkgName = ""; + DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); + // 6. call DeviceManagerNotify OnDiscoveryFailed + DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); + // 7. check if callback OnDiscoveryFailed called + ASSERT_EQ(count, 0); +} + +/** + * @tc.name: OnDiscoverySuccess_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 DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess_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); + // 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); +} + +/** + * @tc.name: OnDiscoverySuccess_002 + * @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 DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess_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); + // 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); +} + +/** + * @tc.name: OnDiscoverySuccess_003 + * @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 DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess_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); + // 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); +} + +/** + * @tc.name: OnDiscoverySuccess_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 DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess_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); + // 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); +} + +/** + * @tc.name: OnDiscoverySuccess_005 + * @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 DeviceManagerNotify OnDiscoverFailed + * 7. check if callback OnDiscoverFailed called. + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess_005, 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); +} + +/** + * @tc.name: OnAuthResult_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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_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); + // 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); +} + +/** + * @tc.name: OnAuthResult_002 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_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); + // 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); +} + +/** + * @tc.name: OnAuthResult_003 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_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); + // 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); +} + +/** + * @tc.name: OnAuthResult_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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_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); + // 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); +} + +/** + * @tc.name: OnAuthResult_005 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_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); + // 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); +} + +/** + * @tc.name: OnAuthResult_006 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_006, 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); +} + +/** + * @tc.name: OnAuthResult_007 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnAuthResult_007, 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); +} + +/** + * @tc.name: OnVerifyAuthResult_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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult_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); + // 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().RegisterVerifyAuthenticationCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + int32_t resultCode = 0; + int32_t flag = 0; + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: OnVerifyAuthResult_002 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult_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); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterVerifyAuthenticationCallback with parameter + DeviceManagerNotify::GetInstance().RegisterVerifyAuthenticationCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + int32_t resultCode = 0; + int32_t flag = 0; + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + ASSERT_EQ(checkMap, nullptr); +} + +/** + * @tc.name: OnVerifyAuthResult_003 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult_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); + // 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().RegisterVerifyAuthenticationCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + int32_t resultCode = 1; + int32_t flag = 1; + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnVerifyAuthResult_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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult_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); + // 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().RegisterVerifyAuthenticationCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + int32_t resultCode = 1; + int32_t flag = 1; + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnVerifyAuthResult_005 + * @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 DeviceManagerNotify OnAuthResult + * 7. check if callback OnDiscoverySuccess called + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult_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); + // set subscribeId not null + std::string deviceId = "1"; + // 2. set checkMap null + std::shared_ptr checkMap = nullptr; + // 3. call DeviceManagerNotifyTest RegisterVerifyAuthenticationCallback with parameter + DeviceManagerNotify::GetInstance().RegisterVerifyAuthenticationCallback(pkgName, deviceId, callback); + // 4. Get checkMap from DeviceManagerNotify + checkMap = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName]; + // 5. check checkMap not null + ASSERT_NE(checkMap, nullptr); + // 6. call DeviceManagerNotify OnAuthResult + int32_t resultCode = 1; + int32_t flag = 1; + DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag); + // 7. check if callback OnDiscoverySuccess called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnFaCall_001 + * @tc.desc: 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall_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); + // 6. call DeviceManagerNotify OnFaCall + std::string paramJson = "trstParamJson"; + DeviceManagerNotify::GetInstance().OnFaCall(pkgName, paramJson); + // 7. check if callback OnCheckAuthResult called + ASSERT_EQ(count, 1); +} + +/** + * @tc.name: OnFaCall_002 + * @tc.desc: 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall_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 + 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); +} + +/** + * @tc.name: OnFaCall_003 + * @tc.desc: 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall_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 + 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); +} + +/** + * @tc.name: OnFaCall_004 + * @tc.desc: 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall_004, 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); +} + +/** + * @tc.name: OnFaCall_005 + * @tc.desc: 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 + * deviceTypeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerNotifyTest, OnFaCall_005, 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; +} + +DeviceManagerFaCallbackTest :: DeviceManagerFaCallbackTest(int &count) : DeviceManagerFaCallback() +{ + count_ = &count; +} + +void DeviceManagerFaCallbackTest :: OnCall(const std::string ¶mJson) +{ + *count_ = *count_ + 1; +} + +VerifyAuthCallbackTest :: VerifyAuthCallbackTest(int &count) : VerifyAuthCallback() +{ + count_ = &count; +} + +void VerifyAuthCallbackTest :: OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) +{ + *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..efe1a4181 --- /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 DeviceManagerFaCallbackTest : public DeviceManagerFaCallback { +public: + DeviceManagerFaCallbackTest(int &count); + virtual ~DeviceManagerFaCallbackTest() override {} + virtual void OnCall(const std::string ¶mJson) override; +private: + int *count_ = nullptr; +}; + +class VerifyAuthCallbackTest : public VerifyAuthCallback { +public: + VerifyAuthCallbackTest(int &count); + virtual ~VerifyAuthCallbackTest() override {} + virtual void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) override; +private: + int *count_ = nullptr; +}; + +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DEVICE_MANAGER_NOTIFY_TEST_H diff --git a/test/unittest/UTTest_dm_common_event_manager.cpp b/test/unittest/UTTest_dm_common_event_manager.cpp new file mode 100644 index 000000000..79df226dd --- /dev/null +++ b/test/unittest/UTTest_dm_common_event_manager.cpp @@ -0,0 +1,145 @@ +/* + * 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 "dm_constants.h" +#include "UTTest_dm_common_event_manager.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmCommonEventManagerTest::SetUp() +{ +} + +void DmCommonEventManagerTest::TearDown() +{ +} + +void DmCommonEventManagerTest::SetUpTestCase() +{ +} + +void DmCommonEventManagerTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: DmCommonEventManager::GetInstance_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, GetInstance_001, testing::ext::TestSize.Level0) +{ + DmCommonEventManager &instance = DmCommonEventManager::GetInstance(); +} + +/** + * @tc.name: DmCommonEventManager::DmCommonEventManager_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, DmCommonEventManager_001, testing::ext::TestSize.Level0) +{ +// std::thread th(DmCommonEventManager::GetInstance().DealCallback()); +// EXPECT_EQ(false, th.detach()); +} + +/** + * @tc.name: DmCommonEventManager::~DmCommonEventManager_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, DeleteDmCommonEventManager_001, testing::ext::TestSize.Level0) +{ + // for (auto iter = DmCommonEventManager::GetInstance().dmEventSubscriber_.begin(); iter != DmCommonEventManager::GetInstance().dmEventSubscriber_.end(); iter++) { + // EXPECT_EQ(true, CommonEventManager::UnSubscribeCommonEvent(iter->second)); + // } +} + +/** + * @tc.name: DmCommonEventManager::DealCallback_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, DealCallback_001, testing::ext::TestSize.Level0) +{ + // DmCommonEventManager::GetInstance().DealCallback(); +} + +/** + * @tc.name: DmCommonEventManager::SubscribeServiceEvent_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +// CommomEventCallback SubscribeServiceEventCallBack(uint8_t unitNo, uint32_t data) +// { + +// } + +HWTEST_F(DmCommonEventManagerTest, SubscribeServiceEvent_001, testing::ext::TestSize.Level0) +{ + // string strEvent = "test"; + // SubscribeServiceEventCallBack = nullptr; + // bool result = DmCommonEventManager::GetInstance().SubscribeServiceEvent(strEvent, (const CommomEventCallback)SubscribeServiceEventCallBack); + // EXPECT_EQ(false, result); +} + +/** + * @tc.name: DmCommonEventManager::UnsubscribeServiceEvent_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, UnsubscribeServiceEvent_001, testing::ext::TestSize.Level0) +{ + +} + +/** + * @tc.name: DmCommonEventManager::EventSubscriber::OnReceiveEvent_001 + * @tc.desc: 1 set cryptoAdapter_ to null + * 2 call AuthMessageProcessor::CreateNegotiateMessage_001 with cryptoAdapter_ = nullptr + * 3 check ret is authMessageProcessor->CreateNegotiateMessage(jsonObj); + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +// HWTEST_F(DmCommonEventManagerTest, EventSubscriber::OnReceiveEvent_001, testing::ext::TestSize.Level0) +// { + +// } + +} // namespace +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/UTTest_dm_common_event_manager.h b/test/unittest/UTTest_dm_common_event_manager.h new file mode 100644 index 000000000..a92081db2 --- /dev/null +++ b/test/unittest/UTTest_dm_common_event_manager.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_DM_COMMON_EVENT_MANAGER_TEST_H +#define OHOS_DM_COMMON_EVENT_MANAGER_TEST_H + +#include +#include +#include + +#include "dm_common_event_manager.h" +#include "common_event.h" +#include "common_event_data.h" +#include "common_event_manager.h" +#include "common_event_subscribe_info.h" +#include "common_event_subscriber.h" +#include "dm_log.h" +#include "matching_skills.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedHardware { +class DmCommonEventManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS + +#endif // OHOS_DM_COMMON_EVENT_MANAGER_TEST_H diff --git a/test/unittest/UTTest_hichain_connector.cpp b/test/unittest/UTTest_hichain_connector.cpp new file mode 100644 index 000000000..fbcbe6a67 --- /dev/null +++ b/test/unittest/UTTest_hichain_connector.cpp @@ -0,0 +1,511 @@ +/* + * 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_002 + * @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: onFinish_001 + * @tc.desc: set groupName nou null groupListot null and return 0 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, onFinish_001, 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:RegisterHiChainCallback_001 + * @tc.desc: Call the RegisterHiChainCallback function with a return value of DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(HichainConnectorTest, UnRegisterHiChainCallback_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr hichainConnector = std::make_shared(); + int ret = hichainConnector->UnRegisterHiChainCallback(); + 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_stub.cpp b/test/unittest/UTTest_ipc_client_stub.cpp index c3ff9a86a..5aaf69456 100644 --- a/test/unittest/UTTest_ipc_client_stub.cpp +++ b/test/unittest/UTTest_ipc_client_stub.cpp @@ -88,7 +88,7 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) * set MessageParcel not null * 2. set set code is SERVER_DEVICE_FA_NOTIFY * 3. call IpcClientStub OnRemoteRequest with parameter - * 4. check result is DM_OK + * 4. check result is ERR_INVALID_STATE * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -105,8 +105,8 @@ HWTEST_F(IpcClientStubTest, OnRemoteRequest_002, testing::ext::TestSize.Level0) sptr instance = new IpcClientStub(); // 3. call IpcClientStub OnRemoteRequest with parameter int ret = instance->OnRemoteRequest(code, data, reply, option); - // 4. check result is DM_OK - ASSERT_EQ(ret, DM_OK); + // 4. check result is ERR_INVALID_STATE + ASSERT_EQ(ret, ERR_INVALID_STATE); } /** diff --git a/test/unittest/UTTest_ipc_server_stub.cpp b/test/unittest/UTTest_ipc_server_stub.cpp index 9bd4cf349..b118693c7 100644 --- a/test/unittest/UTTest_ipc_server_stub.cpp +++ b/test/unittest/UTTest_ipc_server_stub.cpp @@ -154,7 +154,7 @@ HWTEST_F(IpcServerStubTest, OnRemoteRequest_001, testing::ext::TestSize.Level0) * @tc.name: OnRemoteRequest_002 * @tc.desc: 1. Set Code = 999 * 2. Call IpcServerStub OnRemoteRequest with param - * 3. check ret not DM_OK + * 3. check ret not ERR_INVALID_STATE * @tc.type: FUNC * @tc.require: AR000GHSJK */ @@ -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_EQ(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 740b4e8e0..a0eb715a7 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -24,6 +24,11 @@ #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 +49,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 +186,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 +209,22 @@ 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); +} + /** * @tc.name: UnRegisterSoftbusStateCallback_001 * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusStateCallback function to corrort ,return DM_OK @@ -147,6 +280,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 @@ -176,28 +350,44 @@ HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_002, testing::ext::TestSize.Level0 } /** - * @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(); } /** @@ -227,6 +417,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 @@ -317,6 +508,142 @@ HWTEST_F(SoftbusConnectorTest, CovertNodeBasicInfoToDmDevice_001, testing::ext:: int ret = softbusConnector->CovertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); EXPECT_EQ(ret, DM_OK); } + +/** + * @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 (SoftbusConnector::discoveryDeviceInfoMap_.count(deviceId) == 0) { + ret = true; + } + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: OnSoftBusDeviceOnline_002 + * @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"; + SoftbusConnector::discoveryDeviceInfoMap_[deviceId]; + 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 (SoftbusConnector::discoveryDeviceInfoMap_.count(deviceId) == 0) { + 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: 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) { + 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.cpp b/test/unittest/mock/device_auth.cpp index b18839a32..1db3fb648 100644 --- a/test/unittest/mock/device_auth.cpp +++ b/test/unittest/mock/device_auth.cpp @@ -52,4 +52,12 @@ int32_t (*getRelatedGroups)(const char *appId, const char *peerDeviceId, char ** groupNum = 1; returnGroupVec = "123"; } + return 0; +} + +bool (*isDeviceInGroup)(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId) +{ + if(groupId == 0) { + return ture; + } } \ No newline at end of file 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 -- Gitee