From a39b3697f852d9b2fd8675ff056d103632e4b4b6 Mon Sep 17 00:00:00 2001 From: "weidong.liu@thundersoft.com" Date: Tue, 15 Mar 2022 13:56:18 +0800 Subject: [PATCH] compile test for UT --- test/unittest/BUILD.gn | 24 ++ test/unittest/UTTest_dm_adapter_manager.cpp | 85 ++++++ test/unittest/UTTest_dm_adapter_manager.h | 31 +++ test/unittest/UTTest_dm_timer.cpp | 280 ++++++++++++++++++++ test/unittest/UTTest_dm_timer.h | 31 +++ 5 files changed, 451 insertions(+) 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_timer.cpp create mode 100644 test/unittest/UTTest_dm_timer.h diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 9325d03ef..3d46497db 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -24,10 +24,12 @@ group("unittest") { ":UTTest_auth_response_state", ":UTTest_device_manager_service", ":UTTest_device_manager_service_listener", + ":UTTest_dm_adapter_manager", ":UTTest_dm_auth_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", @@ -105,6 +107,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 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_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 -- Gitee