From 6442b17b9aef4d712283885b7c98d35d55119964 Mon Sep 17 00:00:00 2001 From: "weidong.liu@thundersoft.com" Date: Fri, 18 Mar 2022 09:15:54 +0800 Subject: [PATCH] test for UT --- test/unittest/BUILD.gn | 65 +++ .../UTTest_device_manager_service.cpp | 192 +++++++ ...UTTest_device_manager_service_listener.cpp | 66 ++- .../UTTest_device_profile_adapter.cpp | 123 +++++ test/unittest/UTTest_device_profile_adapter.h | 36 ++ test/unittest/UTTest_dm_adapter_manager.cpp | 85 +++ test/unittest/UTTest_dm_adapter_manager.h | 31 ++ test/unittest/UTTest_dm_auth_manager.cpp | 520 ++++++++++++++++++ .../UTTest_dm_common_event_manager.cpp | 121 ++++ .../unittest/UTTest_dm_common_event_manager.h | 37 ++ .../UTTest_dm_device_info_manager.cpp | 42 +- .../UTTest_dm_device_state_manager.cpp | 152 +++++ test/unittest/UTTest_dm_timer.cpp | 280 ++++++++++ test/unittest/UTTest_dm_timer.h | 31 ++ .../UTTest_multiple_user_connector.cpp | 86 +++ .../unittest/UTTest_multiple_user_connector.h | 36 ++ test/unittest/UTTest_profile_connector.cpp | 161 ++++++ test/unittest/UTTest_profile_connector.h | 36 ++ 18 files changed, 2096 insertions(+), 4 deletions(-) create mode 100644 test/unittest/UTTest_device_profile_adapter.cpp create mode 100644 test/unittest/UTTest_device_profile_adapter.h create mode 100644 test/unittest/UTTest_dm_adapter_manager.cpp create mode 100644 test/unittest/UTTest_dm_adapter_manager.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_dm_timer.cpp create mode 100644 test/unittest/UTTest_dm_timer.h create mode 100644 test/unittest/UTTest_multiple_user_connector.cpp create mode 100644 test/unittest/UTTest_multiple_user_connector.h create mode 100644 test/unittest/UTTest_profile_connector.cpp create mode 100644 test/unittest/UTTest_profile_connector.h diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9325d03ef..6eea2ddf8 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -24,21 +24,38 @@ group("unittest") { ":UTTest_auth_response_state", ":UTTest_device_manager_service", ":UTTest_device_manager_service_listener", + ":UTTest_device_profile_adapter", + ":UTTest_dm_adapter_manager", ":UTTest_dm_auth_manager", + ":UTTest_dm_common_event_manager", ":UTTest_dm_device_info_manager", ":UTTest_dm_device_state_manager", ":UTTest_dm_discovery_manager", + ":UTTest_dm_timer", ":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_multiple_user_connector", + ":UTTest_profile_connector", ":UTTest_softbus_connector", ":UTTest_softbus_session", ] } +## UnitTest UTTest_dm_common_event_manager {{{ +ohos_unittest("UTTest_dm_common_event_manager") { + module_out_path = module_out_path + + sources = [ "UTTest_dm_common_event_manager.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_dm_common_event_manager }}} + ## UnitTest device_manager_impl_test {{{ ohos_unittest("device_manager_impl_test") { module_out_path = module_out_path @@ -105,6 +122,28 @@ ohos_unittest("UTTest_softbus_session") { ## UnitTest UTTest_softbus_session }}} +## UnitTest UTTest_dm_adapter_manager {{{ +ohos_unittest("UTTest_dm_adapter_manager") { + module_out_path = module_out_path + + sources = [ "UTTest_dm_adapter_manager.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_dm_adapter_manager }}} + +## UnitTest UTTest_dm_timer {{{ +ohos_unittest("UTTest_dm_timer") { + module_out_path = module_out_path + + sources = [ "UTTest_dm_timer.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_dm_timer }}} + ## UnitTest UTTest_ipc_client_manager {{{ ohos_unittest("UTTest_ipc_client_manager") { module_out_path = module_out_path @@ -193,6 +232,28 @@ ohos_unittest("UTTest_profile_connector") { ## UnitTest UTTest_profile_connector }}} +## UnitTest UTTest_device_profile_adapter {{{ +ohos_unittest("UTTest_device_profile_adapter") { + module_out_path = module_out_path + + sources = [ "UTTest_device_profile_adapter.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_multiple_user_connector }}} + +## UnitTest UTTest_multiple_user_connector {{{ +ohos_unittest("UTTest_multiple_user_connector") { + module_out_path = module_out_path + + sources = [ "UTTest_multiple_user_connector.cpp" ] + + deps = [ ":device_manager_test_common" ] +} + +## UnitTest UTTest_multiple_user_connector }}} + ## UnitTest UTTest_device_manager_notify {{{ ohos_unittest("UTTest_device_manager_notify") { module_out_path = module_out_path @@ -403,7 +464,11 @@ ohos_static_library("device_manager_test_common") { "${innerkits_path}/native_cpp:devicemanagersdk", "${services_path}:devicemanagerservice", "${utils_path}:devicemanagerutils", + "//base/notification/ces_standard/frameworks/core:cesfwk_core", + "//base/notification/ces_standard/frameworks/native:cesfwk_innerkits", + "//foundation/aafwk/standard/interfaces/innerkits/want:want", "//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core", + "//foundation/distributedhardware/devicemanager/ext/profile:devicemanagerext_profile", "//foundation/distributedhardware/devicemanager/interfaces/kits/js:devicemanager", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gmock", diff --git a/test/unittest/UTTest_device_manager_service.cpp b/test/unittest/UTTest_device_manager_service.cpp index 28256c67f..69076914b 100644 --- a/test/unittest/UTTest_device_manager_service.cpp +++ b/test/unittest/UTTest_device_manager_service.cpp @@ -337,6 +337,198 @@ HWTEST_F(DeviceManagerServiceTest, VerifyAuthentication_001, testing::ext::TestS int ret = DeviceManagerService::GetInstance().VerifyAuthentication(authParam); EXPECT_EQ(ret, DM_NOT_INIT); } + +/** + * @tc.name: GetUdidByNetworkId_001 + * @tc.desc: Make success for GetUdidByNetworkId,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetUdidByNetworkId_002 + * @tc.desc: Make not init for GetUdidByNetworkId,The return value is + * DM_NOT_INIT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_002, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = false; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_NOT_INIT); +} + +/** + * @tc.name: GetUdidByNetworkId_003 + * @tc.desc: Make pkgName empty for GetUdidByNetworkId,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUdidByNetworkId_003, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = ""; + std::string netWorkId = ""; + std::string udid = ""; + int ret = DeviceManagerService::GetInstance().GetUdidByNetworkId(pkgName, netWorkId, udid); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: GetUuidByNetworkId_001 + * @tc.desc: Make success for GetUuidByNetworkId,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetUuidByNetworkId_002 + * @tc.desc: Make not init for GetUuidByNetworkId,The return value is + * DM_NOT_INIT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_002, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = false; + std::string pkgName = "com.ohos.test"; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_NOT_INIT); +} + +/** + * @tc.name: GetUuidByNetworkId_003 + * @tc.desc: Make pkgName empty for GetUuidByNetworkId,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetUuidByNetworkId_003, testing::ext::TestSize.Level0) +{ + DeviceManagerService::GetInstance().intFlag_ = true; + std::string pkgName = ""; + std::string netWorkId = ""; + std::string uuid = ""; + int ret = DeviceManagerService::GetInstance().GetUuidByNetworkId(pkgName, netWorkId, uuid); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: GetFaParam_001 + * @tc.desc: Make success for GetFaParam,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetFaParam_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + DmAuthParam authParam; + int ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetFaParam_002 + * @tc.desc: Make pkgName empty for GetFaParam, The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, GetFaParam_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = ""; + DmAuthParam authParam; + int ret = DeviceManagerService::GetInstance().GetFaParam(pkgName, authParam); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: SetUserOperation_001 + * @tc.desc: Make success for SetUserOperation,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, SetUserOperation_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + int32_t action = 0; + int ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: SetUserOperation_002 + * @tc.desc: Make pkgName empty for SetUserOperation,The return value is + * DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, SetUserOperation_002, testing::ext::TestSize.Level0) +{ + std::string pkgName = ""; + int32_t action = 0; + int ret = DeviceManagerService::GetInstance().SetUserOperation(pkgName, action); + EXPECT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + +/** + * @tc.name: RegisterDevStateCallback_001 + * @tc.desc: Make success for RegisterDevStateCallback,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, RegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string extra = "extra"; + int ret = DeviceManagerService::GetInstance().RegisterDevStateCallback(pkgName, extra); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: UnRegisterDevStateCallback_001 + * @tc.desc: Make success for UnRegisterDevStateCallback,The return value is + * DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceTest, UnRegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string extra = "extra"; + int ret = DeviceManagerService::GetInstance().UnRegisterDevStateCallback(pkgName, extra); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_device_manager_service_listener.cpp b/test/unittest/UTTest_device_manager_service_listener.cpp index 8f85f3dd6..dbb6726ef 100644 --- a/test/unittest/UTTest_device_manager_service_listener.cpp +++ b/test/unittest/UTTest_device_manager_service_listener.cpp @@ -107,6 +107,70 @@ HWTEST_F(DeviceManagerServiceListenerTest, OnVerifyAuthResult_001, testing::ext: std::string ret = pReq->GetDeviceId(); EXPECT_EQ(ret, deviceId); } + +/** + * @tc.name: OnDeviceFound_001 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId, info + * deviceId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDeviceFound_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + DmDeviceInfo info = { + .deviceId = "dkdkd", + .deviceName = "asda", + .deviceTypeId = 1, + }; + uint16_t subscribeId = 1; + listener_->OnDeviceFound(pkgName, subscribeId, info); +} + +/** + * @tc.name: OnDiscoveryFailed_001 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId, failedReason + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoveryFailed_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + std::string deviceId = "dkdkd"; + uint16_t subscribeId = 1; + int32_t failedReason = 1; + listener_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); +} + +/** + * @tc.name: OnDiscoverySuccess_001 + * @tc.desc: OnDeviceFound,construct a dummy listener, pass in pkgName, subscribeId + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnDiscoverySuccess_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + uint16_t subscribeId = 1; + listener_->OnDiscoverySuccess(pkgName, subscribeId); +} + +/** + * @tc.name: OnFaCall_001 + * @tc.desc: OnFaCall, construct a dummy listener, pass in pkgName, paramJson + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerServiceListenerTest, OnFaCall_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr listener_ = std::make_shared(); + std::string pkgName = "com.ohos.helloworld"; + std::string paramJson = "ahaha"; + listener_->OnFaCall(pkgName, paramJson); +} } // namespace } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/UTTest_device_profile_adapter.cpp b/test/unittest/UTTest_device_profile_adapter.cpp new file mode 100644 index 000000000..30d7d03eb --- /dev/null +++ b/test/unittest/UTTest_device_profile_adapter.cpp @@ -0,0 +1,123 @@ +/* + * 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 "dm_constants.h" +#include "dm_device_state_manager.h" +#include "profile_adapter.h" +#include "profile_connector_callback.h" +#include "profile_connector.h" +#include "device_profile_adapter.h" +#include "distributed_device_profile_client.h" +#include "UTTest_device_profile_adapter.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceProfileAdapterTest::SetUp() +{ +} +void DeviceProfileAdapterTest::TearDown() +{ +} +void DeviceProfileAdapterTest::SetUpTestCase() +{ +} +void DeviceProfileAdapterTest::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 deviceStateMgr = std::make_shared(softbusConnector, + listener, + hiChainConnector); +/** + * @tc.name: RegisterProfileListener_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, RegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceProfileAdapter->RegisterProfileListener(pkgName, deviceId, deviceStateMgr); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: UnRegisterProfileListener_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, UnRegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceProfileAdapter->UnRegisterProfileListener(pkgName); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnProfileChanged_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, OnProfileChanged_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceProfileAdapter->OnProfileChanged(pkgName, deviceId); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnProfileComplete_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceProfileAdapterTest, OnProfileComplete_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::shared_ptr deviceProfileAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceProfileAdapter->OnProfileComplete(pkgName, deviceId); + ASSERT_EQ(ret, DM_OK); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_device_profile_adapter.h b/test/unittest/UTTest_device_profile_adapter.h new file mode 100644 index 000000000..8ab5db577 --- /dev/null +++ b/test/unittest/UTTest_device_profile_adapter.h @@ -0,0 +1,36 @@ +/* + * 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_PROFILE_ADAPTER_TEST_H +#define OHOS_DEVICE_PROFILE_ADAPTER_TEST_H + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class DeviceProfileAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/test/unittest/UTTest_dm_adapter_manager.cpp b/test/unittest/UTTest_dm_adapter_manager.cpp new file mode 100644 index 000000000..16b4a22dc --- /dev/null +++ b/test/unittest/UTTest_dm_adapter_manager.cpp @@ -0,0 +1,85 @@ +/* + * 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_adapter_manager.h" +#include "dm_config_manager.h" +#include "UTTest_dm_adapter_manager.h" + +namespace OHOS { +namespace DistributedHardware { +void DmAdapterManagerTest::SetUp() +{ +} +void DmAdapterManagerTest::TearDown() +{ +} +void DmAdapterManagerTest::SetUpTestCase() +{ +} +void DmAdapterManagerTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr dmAdapterManager = + std::make_shared(); + +/** + * @tc.name: DmAdapterManager::GetDecisionAdapter_001 + * @tc.desc: 1 set soName to null + * 2 call DmAdapterManager::GetDecisionAdapter_001 with soName = nullptr + * @tc.type: FUNC + * @tc.require:AR000GHSJK + */ +HWTEST_F(DmAdapterManagerTest, GetDecisionAdapter_001, testing::ext::TestSize.Level0) +{ + std::string soName = "123"; + soName.clear(); + std::shared_ptr iDecisionAdapter = dmAdapterManager->GetDecisionAdapter(soName); + EXPECT_EQ(nullptr, iDecisionAdapter); +} + +/** + * @tc.name: DmAdapterManager::GetProfileAdapter_001 + * @tc.desc: 1 set soName to null + * 2 callDmAdapterManager::GetProfileAdapter_001 with soName = nullptr + * @tc.type: FUNC + * @tc.require:AR000GHSJK + */ +HWTEST_F(DmAdapterManagerTest, GetProfileAdapter_001, testing::ext::TestSize.Level0) +{ + std::string soName = "123"; + soName.clear(); + std::shared_ptr iProfileAdapter = dmAdapterManager->GetProfileAdapter(soName); + EXPECT_EQ(nullptr, iProfileAdapter); +} + +/** + * @tc.name: DmAdapterManager::GetCryptoAdapter_001 + * @tc.desc: 1 set soName to null + * 2 callDmAdapterManager::GetCryptoAdapter_001 with soName = nullptr + * @tc.type: FUNC + * @tc.require:AR000GHSJK + */ +HWTEST_F(DmAdapterManagerTest, GetCryptoAdapter_001, testing::ext::TestSize.Level0) +{ + std::string soName = "123"; + soName.clear(); + std::shared_ptr iCryptoAdapter = dmAdapterManager->GetCryptoAdapter(soName); + EXPECT_EQ(nullptr, iCryptoAdapter); +} +} +} +} diff --git a/test/unittest/UTTest_dm_adapter_manager.h b/test/unittest/UTTest_dm_adapter_manager.h new file mode 100644 index 000000000..b0a975e21 --- /dev/null +++ b/test/unittest/UTTest_dm_adapter_manager.h @@ -0,0 +1,31 @@ +/* + * 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_DM_ADAPTER_MANAGER_H +#define OHOS_UTTEST_DM_ADAPTER_MANAGER_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class DmAdapterManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 70f3bf7e2..ff8183ffe 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -43,11 +43,77 @@ std::string NEGOTIATE_TIMEOUT_TASK = "negotiateTimeoutTask"; std::string CONFIRM_TIMEOUT_TASK = "confirmTimeoutTask"; std::string INPUT_TIMEOUT_TASK = "inputTimeoutTask"; std::string ADD_TIMEOUT_TASK = "addTimeoutTask"; +std::string WAIT_NEGOTIATE_TIMEOUT_TASK = "waitNegotiateTimeoutTask"; +std::string WAIT_REQUEST_TIMEOUT_TASK = "waitRequestTimeoutTask"; std::shared_ptr softbusConnector = std::make_shared(); std::shared_ptr listener = std::make_shared(); std::shared_ptr hiChainConnector_ = std::make_shared(); +/** + * @tc.name: DmAuthManager::AuthenticateDevice_001 + * @tc.desc: softbusConnector_->HaveDeviceInMap(deviceId) == false + * Whether the return value of calling AuthenticateDevice is DM_AUTH_INPUT_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = nullptr; + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + std::string extra = "{\"pinCode\":\"1\"}"; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_AUTH_INPUT_FAILED); +} + +/** + * @tc.name: DmAuthManager::AuthenticateDevice_002 + * @tc.desc: authRequestState_ != nullptr || authResponseState_ != nullptr; + * Whether the return value of calling AuthenticateDevice is DM_AUTH_BUSINESS_BUSY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseState_ = std::make_shared(); + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + softbusConnector->discoveryDeviceInfoMap_[deviceId] = std::make_shared(); + std::string extra = "333"; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_AUTH_BUSINESS_BUSY); +} + +/** + * @tc.name: DmAuthManager::AuthenticateDevice_003 + * @tc.desc: extra.empty(); Whether the return value of calling AuthenticateDevice is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateDevice_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = nullptr; + std::string pkgName = "pkgName"; + int32_t authType = 1; + std::string deviceId = "222"; + softbusConnector->discoveryDeviceInfoMap_[deviceId] = std::make_shared(); + std::string extra = ""; + int32_t ret = authManager->AuthenticateDevice(pkgName, authType, deviceId, extra); + ASSERT_EQ(ret, DM_INPUT_PARA_EMPTY); +} + /** * @tc.name: DmAuthManager::UnAuthenticateDevice_001 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_ FAILED @@ -66,6 +132,129 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev ASSERT_EQ(ret, DM_FAILED); } +/** + * @tc.name: DmAuthManager::VerifyAuthentication_001 + * @tc.desc: authResponseContext_ == nullptr; Whether the return value of calling VerifyAuthentication is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = nullptr; + std::string authParam = "{\"pinCode\":\"1\"}"; + int32_t ret = authManager->VerifyAuthentication(authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::OnSessionOpened_001 + * @tc.desc: sessionSide = AUTH_SESSION_SIDE_SERVER; Call OnSessionOpened to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnSessionOpened_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t sessionId = 111; + int32_t sessionSide = AUTH_SESSION_SIDE_SERVER; + int32_t result = 222; + authManager->authResponseState_ = nullptr; + authManager->authRequestState_ = nullptr; + authManager->timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] = nullptr; + authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] = nullptr; + authManager->OnSessionOpened(sessionId, sessionSide, result); + ASSERT_TRUE(authManager->timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] != nullptr); + ASSERT_TRUE(authManager->timerMap_[AUTHENTICATE_TIMEOUT_TASK] != nullptr); +} + +/** + * @tc.name: DmAuthManager::OnSessionClosed_001 + * @tc.desc: Call OnSessionClosed to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnSessionClosed_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t sessionId = 111; + authManager->OnSessionClosed(sessionId); +} + +/** + * @tc.name: DmAuthManager::OnDataReceived_002 + * @tc.desc: authResponseContext_->msgType = MSG_TYPE_REQ_AUTH_TERMINATE; + * @Call OnDataReceived to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnDataReceived_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = nullptr; + authManager->authResponseState_ = nullptr; + authManager->authResponseContext_ = std::make_shared(); + int32_t sessionId = 111; + std::string message = "{\"groupId\":\"1\"}"; + authManager->authResponseContext_->sessionId = 0; + authManager->OnDataReceived(sessionId, message); + ASSERT_NE(sessionId, authManager->authResponseContext_->sessionId); +} + +/** + * @tc.name: DmAuthManager::OnMemberJoin_001 + * @tc.desc: status = DM_TIME_OUT; Call OnMemberJoin to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnMemberJoin_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); + authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; + int64_t requestId = 111; + int32_t status = DM_TIME_OUT; + authManager->authResponseContext_->requestId = 222; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_OK; + authManager->OnMemberJoin(requestId, status); + ASSERT_EQ(AuthState::AUTH_REQUEST_JOIN, authManager->authResponseContext_->state); + ASSERT_EQ(DM_AUTH_INPUT_FAILED, authManager->authRequestContext_->reason); +} + +/** + * @tc.name: DmAuthManager::OnMemberJoin_002 + * @tc.desc: status = DM_OK; Call OnMemberJoin to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnMemberJoin_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + std::shared_ptr joinStartTimer = std::make_shared(ADD_TIMEOUT_TASK); + authManager->timerMap_[ADD_TIMEOUT_TASK] = joinStartTimer; + int64_t requestId = 111; + int32_t status = DM_OK; + authManager->authResponseContext_->requestId = requestId; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_OK; + authManager->OnMemberJoin(requestId, status); + ASSERT_EQ(AuthState::AUTH_REQUEST_INIT, authManager->authResponseContext_->state); + ASSERT_EQ(DM_OK, authManager->authRequestContext_->reason); +} + /** * @tc.name: DmAuthManager::HandleAuthenticateTimeout_001 * @tc.desc: authResponseContext_= nullptr; Call handleauthenticatemeout to check whether the return value is DM_FAILED @@ -169,6 +358,29 @@ HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } +/** + * @tc.name: DmAuthManager::StartRespAuthProcess_001 + * @tc.desc: Call StartRespAuthProcess to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, StartRespAuthProcess_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr confirmStartTimer = std::make_shared(CONFIRM_TIMEOUT_TASK); + authManager->timerMap_[CONFIRM_TIMEOUT_TASK] = confirmStartTimer; + authManager->authResponseContext_ = std::make_shared(); + authManager->authRequestContext_ = std::make_shared(); + authManager->authRequestState_ = std::make_shared(); + authManager->authResponseContext_->reply = USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT; + authManager->authResponseContext_->state = AuthState::AUTH_REQUEST_INIT; + authManager->authRequestContext_->reason = DM_AUTH_NOT_AUTH; + authManager->StartRespAuthProcess(); + ASSERT_EQ(AuthState::AUTH_REQUEST_REPLY, authManager->authResponseContext_->state); + ASSERT_EQ(DM_AUTH_PEER_REJECT, authManager->authRequestContext_->reason); +} + /** * @tc.name: DmAuthManager::CreateGroup_001 * @tc.desc: Whether the return value of calling creategroup is DM_ OK @@ -220,6 +432,21 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_FAILED); } +/** + * @tc.name: DmAuthManager::GetConnectAddr_001 + * @tc.desc: Whether the return value of calling GetConnectAddr is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetConnectAddr_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::string deviceId = "123"; + std::string ret = authManager->GetConnectAddr(deviceId); + ASSERT_EQ(ret, ""); +} + /** * @tc.name: DmAuthManager::JoinNetwork_001 * @tc.desc: Whether the return value of calling joinnetwork is DM_ OK @@ -242,6 +469,115 @@ HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } +/** + * @tc.name: DmAuthManager::AuthenticateFinish_002 + * @tc.desc: authResponseState_ == nullptr; Call AuthenticateFinish to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, AuthenticateFinish_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseState_ = nullptr; + authManager->authRequestContext_ = std::make_shared(); + authManager->authMessageProcessor_ = std::make_shared(authManager); + authManager->isFinishOfLocal_ = false; + authManager->AuthenticateFinish(); + ASSERT_TRUE(nullptr == authManager->authRequestContext_); +} + +/** + * @tc.name: DmAuthManager::CancelDisplay_001 + * @tc.desc: Call CancelDisplay to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, CancelDisplay_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->CancelDisplay(); +} + +/** + * @tc.name: DmAuthManager::GeneratePincode_001 + * @tc.desc: Whether the return value of calling GeneratePincode is between MIN_PIN_CODE and MAX_PIN_CODE + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GeneratePincode_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t ret = authManager->GeneratePincode(); + ASSERT_LE(ret, MAX_PIN_CODE); + ASSERT_GT(ret, MIN_PIN_CODE); +} + +/** + * @tc.name: DmAuthManager::GenerateGroupName_001 + * @tc.desc: Whether the return value of calling GenerateGroupName is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GenerateGroupName_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + std::string ret = authManager->GenerateGroupName(); + ASSERT_STRNE(ret.c_str(), ""); +} + +/** + * @tc.name: DmAuthManager::GetIsCryptoSupport_001 + * @tc.desc: Whether the return value of calling GetIsCryptoSupport is true + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr authResponseState = std::make_shared(); + authManager->SetAuthResponseState(authResponseState); + std::shared_ptr authRequestState = std::make_shared(); + authManager->SetAuthRequestState(authRequestState); + bool ret = authManager->GetIsCryptoSupport(); + ASSERT_EQ(ret, true); +} + +/** + * @tc.name: DmAuthManager::GetIsCryptoSupport_002 + * @tc.desc: Whether the return value of calling GetIsCryptoSupport is false + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->SetAuthResponseState(nullptr); + bool ret = authManager->GetIsCryptoSupport(); + ASSERT_EQ(ret, false); +} + +/** + * @tc.name: DmAuthManager::SetAuthRequestState_001 + * @tc.desc: Whether the return value of calling SetAuthRequestState is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetAuthRequestState_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + std::shared_ptr authRequestState = std::make_shared(); + int32_t ret = authManager->SetAuthRequestState(authRequestState); + ASSERT_EQ(ret, DM_OK); +} + /** * @tc.name: DmAuthManager::SetAuthResponseState_001 * @tc.desc: Is the authresponsestate assignment successful @@ -273,6 +609,190 @@ HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level0) int32_t ret = authManager->GetPinCode(); ASSERT_EQ(ret, DM_FAILED); } + +/** + * @tc.name: DmAuthManager::ShowConfigDialog_001 + * @tc.desc: Call ShowConfigDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowConfigDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowConfigDialog(); +} + +/** + * @tc.name: DmAuthManager::ShowAuthInfoDialog_001 + * @tc.desc: Call ShowAuthInfoDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowAuthInfoDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowAuthInfoDialog(); +} + +/** + * @tc.name: DmAuthManager::ShowStartAuthDialog_001 + * @tc.desc: Call ShowStartAuthDialog to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->ShowStartAuthDialog(); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_001 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + authManager->dmAbilityMgr_ = std::make_shared(); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_002 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: DmAuthManager::GetAuthenticationParam_003 + * @tc.desc: Whether the return value of calling GetAuthenticationParam is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, GetAuthenticationParam_003, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->dmAbilityMgr_ = std::make_shared(); + DmAuthParam authParam = {0}; + int32_t ret = authManager->GetAuthenticationParam(authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::OnUserOperation_001 + * @tc.desc: Whether the return value of calling OnUserOperation is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnUserOperation_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t action = FaAction::USER_OPERATION_TYPE_ALLOW_AUTH; + int32_t ret = authManager->OnUserOperation(action); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::OnUserOperation_002 + * @tc.desc: Whether the return value of calling OnUserOperation is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, OnUserOperation_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t action = FaAction::USER_OPERATION_TYPE_ALLOW_AUTH; + int32_t ret = authManager->OnUserOperation(action); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: DmAuthManager::UserSwitchEventCallback_001 + * @tc.desc: Call UserSwitchEventCallback to check function being called + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, UserSwitchEventCallback_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t userId = 1; + authManager->UserSwitchEventCallback(userId); +} + +/** + * @tc.name: DmAuthManager::SetPageId_001 + * @tc.desc: Call SetPageId to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetPageId_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t pageId = 1; + int32_t ret = authManager->SetPageId(pageId); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::SetReason_001 + * @tc.desc: reason = AuthState::AUTH_REQUEST_INIT; + * @Call SetReason to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetReason_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + authManager->authResponseContext_ = std::make_shared(); + int32_t reason = AuthState::AUTH_REQUEST_INIT; + int32_t state = 222; + int32_t ret = authManager->SetReason(reason, state); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: DmAuthManager::SetReason_002 + * @tc.desc: reason = AuthState::AUTH_REQUEST_FINISH; + * @Call SetReason to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmAuthManagerTest, SetReason_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector_); + int32_t reason = AuthState::AUTH_REQUEST_FINISH; + int32_t state = 222; + authManager->authResponseContext_ = std::make_shared(); + int32_t ret = authManager->SetReason(reason, state); + ASSERT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS 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..ed97bc592 --- /dev/null +++ b/test/unittest/UTTest_dm_common_event_manager.cpp @@ -0,0 +1,121 @@ +/* + * 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_common_event_manager.h" +#include "dm_constants.h" +#include "hichain_connector.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::~DmCommonEventManager_001 + * @tc.desc: Destructor of DmCommonEventManager + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, DeleteDmCommonEventManager_001, testing::ext::TestSize.Level0) +{ + DmCommonEventManager::GetInstance().~DmCommonEventManager(); +} + +/** + * @tc.name: DmCommonEventManager::SubscribeServiceEvent_001 + * @tc.desc: call SubscribeServiceEvent(), pass parameters: strEvent and callbackNode.callback_ + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, SubscribeServiceEvent_001, testing::ext::TestSize.Level0) +{ + std::string strEvent = "test"; + CommomEventCallbackNode callbackNode; + callbackNode.callback_ = nullptr; + bool result = DmCommonEventManager::GetInstance().SubscribeServiceEvent(strEvent, callbackNode.callback_); + EXPECT_EQ(false, result); +} + +/** + * @tc.name: DmCommonEventManager::SubscribeServiceEvent_002 + * @tc.desc: call SubscribeServiceEvent(), pass parameters: strEvent and callbackNode.callback_ + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, SubscribeServiceEvent_002, testing::ext::TestSize.Level0) +{ + std::string strEvent = "test"; + CommomEventCallbackNode callbackNode; + std::shared_ptr subscriber = nullptr; + bool result = DmCommonEventManager::GetInstance().SubscribeServiceEvent(strEvent, callbackNode.callback_); + EXPECT_EQ(false, result); +} + +/** + * @tc.name: DmCommonEventManager::UnsubscribeServiceEvent_001 + * @tc.desc: call UnsubscribeServiceEvent(), pass parameters: strEvent + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, UnsubscribeServiceEvent_001, testing::ext::TestSize.Level0) +{ + std::string event = "123"; + CommomEventCallbackNode callbackNode; + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(event); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + std::shared_ptr subscriber = + std::make_shared(subscriberInfo, callbackNode.callback_, event); + DmCommonEventManager::GetInstance().dmEventSubscriber_[event] = subscriber; + std::string strEvent = "123"; + bool result = DmCommonEventManager::GetInstance().UnsubscribeServiceEvent(strEvent); + EXPECT_EQ(true, result); +} + +/** + * @tc.name: DmCommonEventManager::EventSubscriber::OnReceiveEvent_001 + * @tc.desc: call OnReceiveEvent(), pass parameters: data + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmCommonEventManagerTest, OnReceiveEvent_001, testing::ext::TestSize.Level0) +{ + EventFwk::CommonEventData data; + EventFwk::CommonEventSubscribeInfo subscribeInfo; + CommomEventCallbackNode callbackNode; + std::string strEvent = "test"; + std::shared_ptr eventSubscriber = + std::make_shared(subscribeInfo, callbackNode.callback_, strEvent); + eventSubscriber->OnReceiveEvent(data); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS 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..98cadf57c --- /dev/null +++ b/test/unittest/UTTest_dm_common_event_manager.h @@ -0,0 +1,37 @@ +/* + * 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 +#include "dm_common_event_manager.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_dm_device_info_manager.cpp b/test/unittest/UTTest_dm_device_info_manager.cpp index 5dedde908..1a6569411 100644 --- a/test/unittest/UTTest_dm_device_info_manager.cpp +++ b/test/unittest/UTTest_dm_device_info_manager.cpp @@ -51,9 +51,45 @@ std::shared_ptr dmDeviceStateManager = std::make_shared p = std::make_shared(softbusConnector); - ASSERT_NE(p, nullptr); + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ASSERT_NE(deviceInfoManager, nullptr); +} + +/** + * @tc.name: GetTrustedDeviceList_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetTrustedDeviceList_001, testing::ext::TestSize.Level0) +{ + int32_t ret = DM_OK; + std::string pkgName = ""; + std::string extra = ""; + std::vector deviceList; + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ret = deviceInfoManager->GetTrustedDeviceList(pkgName, extra, deviceList); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: GetLocalDeviceInfo_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceManagerImplTest, GetLocalDeviceInfo_001, testing::ext::TestSize.Level0) +{ + DmDeviceInfo deviceInfo; + int32_t ret = DM_OK; + std::shared_ptr deviceInfoManager = std::make_shared(softbusConnector); + ret = deviceInfoManager->GetLocalDeviceInfo(deviceInfo); + ASSERT_EQ(ret, DM_OK); } } // namespace } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index af0a2adda..7612a06db 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -77,6 +77,17 @@ HWTEST_F(DmDeviceStateManagerTest, DmDeviceStateManager_002, testing::ext::TestS EXPECT_EQ(p, nullptr); } +/** + * @tc.name: DestructDmDeviceStateManager_001 + * @tc.desc: set DmDeviceStateManager to tne new pointer,and it's not nullptr + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, DestructDmDeviceStateManager_001, testing::ext::TestSize.Level0) +{ + dmDeviceStateManager->~DmDeviceStateManager(); +} + /** * @tc.name: OnDeviceOnline_001 * @tc.desc: set info.deviceId to some para, and return it @@ -203,6 +214,147 @@ HWTEST_F(DmDeviceStateManagerTest, RegisterSoftbusStateCallback_001, testing::ex int ret = dmDeviceStateManager->RegisterSoftbusStateCallback(); EXPECT_EQ(ret, DM_OK); } + +/** + * @tc.name: RegisterProfileListener_001 + * @tc.desc: call RegisterProfileListener and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, RegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->RegisterOffLineTimer(info); + int ret = dmDeviceStateManager->RegisterProfileListener(pkgName, info); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: UnRegisterProfileListener_001 + * @tc.desc: call UnRegisterProfileListener and return DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, UnRegisterProfileListener_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->RegisterOffLineTimer(info); + int ret = dmDeviceStateManager->UnRegisterProfileListener(pkgName, info); + EXPECT_EQ(ret, DM_OK); +} + +/** + * @tc.name: PostDeviceOnline_001 + * @tc.desc: call PostDeviceOnline + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, PostDeviceOnline_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->PostDeviceOnline(pkgName, info); +} + +/** + * @tc.name: PostDeviceOffline_001 + * @tc.desc: call PostDeviceOffline + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, PostDeviceOffline_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->PostDeviceOffline(pkgName, info); +} + +/** + * @tc.name: RegisterDevStateCallback_001 + * @tc.desc: call RegisterDevStateCallback + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, RegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + std::string extra = "ahaha"; + dmDeviceStateManager->RegisterDevStateCallback(pkgName, extra); +} + +/** + * @tc.name: UnRegisterDevStateCallback_001 + * @tc.desc: call UnRegisterDevStateCallback + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, UnRegisterDevStateCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "123"; + std::string extra; + dmDeviceStateManager->UnRegisterDevStateCallback(pkgName, extra); +} + +/** + * @tc.name: RegisterOffLineTimer_001 + * @tc.desc: call RegisterOffLineTimer + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, RegisterOffLineTimer_001, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->RegisterOffLineTimer(info); +} + +/** + * @tc.name: StartOffLineTimer_001 + * @tc.desc: call StartOffLineTimer + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, StartOffLineTimer_001, testing::ext::TestSize.Level0) +{ + DmDeviceInfo info = { + .deviceId = "123", + .deviceName = "asda", + .deviceTypeId = 1, + }; + dmDeviceStateManager->StartOffLineTimer(info); +} + +/** + * @tc.name: DeleteTimeOutGroup_001 + * @tc.desc: call DeleteTimeOutGroup + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmDeviceStateManagerTest, DeleteTimeOutGroup_001, testing::ext::TestSize.Level0) +{ + dmDeviceStateManager->DeleteTimeOutGroup("123"); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_timer.cpp b/test/unittest/UTTest_dm_timer.cpp new file mode 100644 index 000000000..216788012 --- /dev/null +++ b/test/unittest/UTTest_dm_timer.cpp @@ -0,0 +1,280 @@ +/* + * 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 "dm_timer.h" +#include "UTTest_dm_timer.h" + +namespace OHOS { +namespace DistributedHardware { +void DmTimerTest::SetUp() +{ +} + +void DmTimerTest::TearDown() +{ +} + +void DmTimerTest::SetUpTestCase() +{ +} + +void DmTimerTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: DmTimerTest::DmTimer_001 + * @tc.desc: to check when name is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, DmTimer_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); +} + +/** + * @tc.name: DmTimerTest::DmTimer_002 + * @tc.desc: to check when name is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, DmTimer_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "123"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + EXPECT_EQ(DmTimerStatus::DM_STATUS_INIT, Timer_->mStatus_); + EXPECT_EQ(0, Timer_->mTimeOutSec_); + EXPECT_EQ(nullptr, Timer_->mHandle_); + EXPECT_EQ(nullptr, Timer_->mHandleData_); + EXPECT_EQ(0, Timer_->mTimeFd_[1]); + EXPECT_EQ(0, Timer_->mEv_.events); + EXPECT_EQ(0, Timer_->mEvents_[0].events); + EXPECT_EQ(0, Timer_->mEpFd_); + EXPECT_EQ("123", Timer_->mTimerName_); +} + +/** + * @tc.name: DmTimerTest::DisStructDmTimer_001 + * @tc.desc: to check when mTimerName_ is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, DisStructDmTimer_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->~DmTimer(); +} + +/** + * @tc.name: DmTimerTest::DisStructDmTimer_002 + * @tc.desc: to check when mTimerName_ is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, DisStructDmTimer_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "123"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->~DmTimer(); +} + +/** + * @tc.name: DmTimerTest::Start_001 + * @tc.desc: to check when mTimerName_ is empty,handle is nullptr,data is nullptr + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Start_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + uint32_t timeOut = 10; + TimeoutHandle handle = nullptr; + void *data = nullptr; + DmTimerStatus timerStatus = Timer_->Start(timeOut, handle, data); + EXPECT_EQ(DM_STATUS_FINISH, timerStatus); +} + +/** + * @tc.name: DmTimerTest::Start_002 + * @tc.desc: to check when mTimerName_ is not empty, handle is not nullptr, data is not nullptr, + * @mStatus_ != DmTimerStatus::DM_STATUS_INIT + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +static void TimeOutTest(void *data, DmTimer& timer) +{ + LOGE("time out test"); +} + +HWTEST_F(DmTimerTest, Start_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "1234"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + uint32_t timeOut = 10; + int idx = 1; + void *data = &idx; + Timer_->mStatus_ = DmTimerStatus::DM_STATUS_RUNNING; + DmTimerStatus timerStatus = Timer_->Start(timeOut, TimeOutTest, data); + EXPECT_EQ(DmTimerStatus::DM_STATUS_BUSY, timerStatus); +} + +/** + * @tc.name: DmTimerTest::Stop_001 + * @tc.desc: to check when mTimerName_ is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Stop_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + int32_t code = 1; + Timer_->Stop(code); +} + +/** + * @tc.name: DmTimerTest::Stop_002 + * @tc.desc: to check when mTimerName_ is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Stop_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "111"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + int32_t code = 1; + Timer_->Stop(code); +} + +/** + * @tc.name: DmTimerTest::Stop_003 + * @tc.desc: to check when mTimerName_ is not empty,mTimeFd_[1] is not 0 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Stop_003, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "111"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + int32_t code = 1; + Timer_->mTimeFd_[1] = 1; + Timer_->Stop(code); +} + +/** + * @tc.name: DmTimerTest::WaitForTimeout_001 + * @tc.desc: to check when mTimerName_ is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, WaitForTimeout_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->WaitForTimeout(); +} + +/** + * @tc.name: DmTimerTest::WaitForTimeout_002 + * @tc.desc: to check when mTimerName_ is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, WaitForTimeout_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "111"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->WaitForTimeout(); +} + +/** + * @tc.name: DmTimerTest::CreateTimeFd_001 + * @tc.desc: to check when mTimerName_ is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, CreateTimeFd_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + int32_t result = Timer_->CreateTimeFd(); + EXPECT_EQ(DM_STATUS_FINISH, result); +} + +/** + * @tc.name: DmTimerTest::CreateTimeFd_002 + * @tc.desc: to check when mTimerName_ is not empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, CreateTimeFd_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "123"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->CreateTimeFd(); +} + +/** + * @tc.name: DmTimerTest::Release_001 + * @tc.desc: to check when mTimerName_ is empty + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Release_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = ""; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->Release(); +} + +/** + * @tc.name: DmTimerTest::Release_002 + * @tc.desc: to check when mTimerName_ is not empty,mStatus_ is 0 + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, Release_002, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "111"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + Timer_->mStatus_ = DmTimerStatus::DM_STATUS_INIT; + Timer_->Release(); +} + +/** + * @tc.name: DmTimerTest::GetTimerName_001 + * @tc.desc: to check whether the return value is the same as mTimerName_ + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DmTimerTest, GetTimerName_001, testing::ext::TestSize.Level0) +{ + const std::string DM_TIMER_TASK = "111"; + std::shared_ptr Timer_ = std::make_shared(DM_TIMER_TASK); + std::string strTimer = Timer_->GetTimerName(); + EXPECT_EQ("111", strTimer); +} +} +} +} diff --git a/test/unittest/UTTest_dm_timer.h b/test/unittest/UTTest_dm_timer.h new file mode 100644 index 000000000..19990300f --- /dev/null +++ b/test/unittest/UTTest_dm_timer.h @@ -0,0 +1,31 @@ +/* + * 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_DM_TIMER_H +#define OHOS_UTTEST_DM_TIMER_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class DmTimerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/test/unittest/UTTest_multiple_user_connector.cpp b/test/unittest/UTTest_multiple_user_connector.cpp new file mode 100644 index 000000000..0380493b5 --- /dev/null +++ b/test/unittest/UTTest_multiple_user_connector.cpp @@ -0,0 +1,86 @@ +/* + * 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 "dm_constants.h" +#include "multiple_user_connector.h" +#include "UTTest_multiple_user_connector.h" + +namespace OHOS { +namespace DistributedHardware { +void MultipleUserConnectorTest::SetUp() +{ +} +void MultipleUserConnectorTest::TearDown() +{ +} +void MultipleUserConnectorTest::SetUpTestCase() +{ +} +void MultipleUserConnectorTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, GetCurrentAccountUserID_001, testing::ext::TestSize.Level0) +{ + int32_t ret = DM_OK; + ret = MultipleUserConnector::GetCurrentAccountUserID(); + ASSERT_TRUE(ret > 0); +} + +/** + * @tc.name: SetSwitchOldUserId_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, SetSwitchOldUserId_001, testing::ext::TestSize.Level0) +{ + int32_t userIdIn = 1234; + int32_t userIdOut = -1; + MultipleUserConnector::SetSwitchOldUserId(userIdIn); + userIdOut = MultipleUserConnector::GetSwitchOldUserId(); + ASSERT_EQ(userIdIn, userIdOut); +} + +/** + * @tc.name: GetSwitchOldUserId_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(MultipleUserConnectorTest, GetSwitchOldUserId_001, testing::ext::TestSize.Level0) +{ + int32_t userIdIn = 1234; + int32_t userIdOut = -1; + MultipleUserConnector::SetSwitchOldUserId(userIdIn); + userIdOut = MultipleUserConnector::GetSwitchOldUserId(); + ASSERT_EQ(userIdIn, userIdOut); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_multiple_user_connector.h b/test/unittest/UTTest_multiple_user_connector.h new file mode 100644 index 000000000..9f29c2c02 --- /dev/null +++ b/test/unittest/UTTest_multiple_user_connector.h @@ -0,0 +1,36 @@ +/* + * 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_MULTIPLE_USER_CONNECTOR_TEST_H +#define OHOS_MULTIPLE_USER_CONNECTOR_TEST_H + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class MultipleUserConnectorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/test/unittest/UTTest_profile_connector.cpp b/test/unittest/UTTest_profile_connector.cpp new file mode 100644 index 000000000..b827e4022 --- /dev/null +++ b/test/unittest/UTTest_profile_connector.cpp @@ -0,0 +1,161 @@ +/* + * 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 "dm_constants.h" +#include "dm_device_state_manager.h" +#include "profile_adapter.h" +#include "profile_connector_callback.h" +#include "profile_connector.h" +#include "device_profile_adapter.h" +#include "distributed_device_profile_client.h" +#include "UTTest_profile_connector.h" + +namespace OHOS { +namespace DistributedHardware { +void ProfileConnectorTest::SetUp() +{ +} +void ProfileConnectorTest::TearDown() +{ +} +void ProfileConnectorTest::SetUpTestCase() +{ +} +void ProfileConnectorTest::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 deviceStateMgr = std::make_shared(softbusConnector, + listener, + hiChainConnector); +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, RegisterProfileCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::string deviceId = "deviceId"; + std::string profileSoName = "libdevicemanagerext_profile.z.so"; + + DeviceProfileAdapter * deviceProfileAdapter = new DeviceProfileAdapter(); + + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->RegisterProfileCallback(pkgName, deviceId, deviceProfileAdapter); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnRegisterProfileCallback_001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "com.ohos.test"; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->UnRegisterProfileCallback(pkgName); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, SubscribeProfileEvents_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::list serviceIds; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->SubscribeProfileEvents(serviceIds, deviceId); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_001, testing::ext::TestSize.Level0) +{ + std::string deviceId = "deviceId"; + std::list serviceIds; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + profileConnector_->SubscribeProfileEvents(serviceIds, deviceId); + ret = profileConnector_->UnSubscribeProfileEvents(); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: OnDecisionFilterResult_002 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, UnSubscribeProfileEvents_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + int32_t ret = DM_OK; + ret = profileConnector_->UnSubscribeProfileEvents(); + ASSERT_EQ(ret, ERR_DM_UNSUBSCRIBE_DP_EVENTS); +} + +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Returns a new pointer to the constructor DmDeviceInfoManager new + * to construct an environment where the device has been discovered, and stop discovering + * the device. Its return value is DM_INPUT_PARA_EMPTY + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(ProfileConnectorTest, OnSyncCompleted_001, testing::ext::TestSize.Level0) +{ + DeviceProfile::SyncResult syncResults; + std::shared_ptr profileConnector_; + profileConnector_ = std::make_shared(); + profileConnector_->OnSyncCompleted(syncResults); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_profile_connector.h b/test/unittest/UTTest_profile_connector.h new file mode 100644 index 000000000..c0d53d2be --- /dev/null +++ b/test/unittest/UTTest_profile_connector.h @@ -0,0 +1,36 @@ +/* + * 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_PROFILE_CONNECTOR_TEST_H +#define OHOS_PROFILE_CONNECTOR_TEST_H + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class ProfileConnectorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif -- Gitee