From ad3124e8b2bbe5038309283a396ec94d07c79245 Mon Sep 17 00:00:00 2001 From: zhuhongtao66 Date: Wed, 7 Dec 2022 13:17:22 +0800 Subject: [PATCH] Add TDD testcases for device Signed-off-by: zhuhongtao66 --- BUILD.gn | 1 + .../test/unittest/BUILD.gn | 49 +++++++++ .../test/unittest/device/device_info_test.cpp | 104 ++++++++++++++++++ .../device/device_manager_agent_test.cpp | 46 ++++++++ 4 files changed, 200 insertions(+) create mode 100644 services/distributedfiledaemon/test/unittest/device/device_info_test.cpp diff --git a/BUILD.gn b/BUILD.gn index 656f569b8..751397f83 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -28,6 +28,7 @@ group("dfs_test_moudule") { deps = [ "${services_path}/distributedfiledaemon/test/unittest:daemon_stub_test", "${services_path}/distributedfiledaemon/test/unittest:daemon_test", + "${services_path}/distributedfiledaemon/test/unittest:device_info_test", "${services_path}/distributedfiledaemon/test/unittest:device_manager_agent_test", "${services_path}/distributedfiledaemon/test/unittest:devsl_dispatcher_test", "${services_path}/distributedfiledaemon/test/unittest:kernel_talker_test", diff --git a/services/distributedfiledaemon/test/unittest/BUILD.gn b/services/distributedfiledaemon/test/unittest/BUILD.gn index 67e8bf425..c56d0c214 100644 --- a/services/distributedfiledaemon/test/unittest/BUILD.gn +++ b/services/distributedfiledaemon/test/unittest/BUILD.gn @@ -501,11 +501,60 @@ ohos_unittest("softbus_session_test") { defines = [ "private=public" ] } +ohos_unittest("device_info_test") { + module_out_path = module_output_path + + sources = [ + "${services_path}/distributedfiledaemon/src/device/device_info.cpp", + "${services_path}/distributedfiledaemon/src/device/device_manager_agent.cpp", + "${services_path}/distributedfiledaemon/src/ipc/daemon.cpp", + "${services_path}/distributedfiledaemon/src/ipc/daemon_stub.cpp", + "${services_path}/distributedfiledaemon/src/mountpoint/mount_manager.cpp", + "${services_path}/distributedfiledaemon/src/mountpoint/mount_point.cpp", + "${services_path}/distributedfiledaemon/src/multiuser/os_account_observer.cpp", + "${services_path}/distributedfiledaemon/src/network/devsl_dispatcher.cpp", + "${services_path}/distributedfiledaemon/src/network/kernel_talker.cpp", + "${services_path}/distributedfiledaemon/src/network/network_agent_template.cpp", + "${services_path}/distributedfiledaemon/src/network/session_pool.cpp", + "${services_path}/distributedfiledaemon/src/network/softbus/softbus_agent.cpp", + "${services_path}/distributedfiledaemon/src/network/softbus/softbus_session.cpp", + "${services_path}/distributedfiledaemon/src/network/softbus/softbus_session_dispatcher.cpp", + ] + + sources += [ "device/device_info_test.cpp" ] + + configs = [ + ":module_private_config", + "${utils_path}:compiler_configs", + ] + + deps = [ + "${utils_path}:libdistributedfileutils", + "//base/security/device_auth/services:deviceauth_sdk", + "//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "common_event_service:cesfwk_innerkits", + "dataclassification:data_transit_mgr", + "dsoftbus:softbus_client", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [ "private=public" ] +} + group("unittest") { testonly = true deps = [ ":daemon_stub_test", ":daemon_test", + ":device_info_test", ":device_manager_agent_test", ":devsl_dispatcher_test", ":kernel_talker_test", diff --git a/services/distributedfiledaemon/test/unittest/device/device_info_test.cpp b/services/distributedfiledaemon/test/unittest/device/device_info_test.cpp new file mode 100644 index 000000000..5d2d93870 --- /dev/null +++ b/services/distributedfiledaemon/test/unittest/device/device_info_test.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 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 "gtest/gtest.h" +#include "device/device_info.h" + +namespace OHOS { +namespace Storage { +namespace DistributedFile { +namespace Test { +using namespace testing::ext; +using namespace std; + +class DeviceInfoTest : public testing::Test { +public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase(void) {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: DeviceInfoTest_SetCid_0100 + * @tc.desc: Verify the SetCid function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(DeviceInfoTest, DeviceInfoTest_SetCid_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DeviceInfoTest_SetCid_0100 start"; + + std::string testDevidId = "testdevid1"; + DeviceInfo devInfo; + devInfo.SetCid(testDevidId); + + std::string result = devInfo.GetCid(); + EXPECT_EQ(result, testDevidId); + GTEST_LOG_(INFO) << "DeviceInfoTest_SetCid_0100 end"; +} + +/** + * @tc.name: DeviceInfoTest_GetCid_0100 + * @tc.desc: Verify the GetCid function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(DeviceInfoTest, DeviceInfoTest_GetCid_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DeviceInfoTest_GetCid_0100 start"; + + DistributedHardware::DmDeviceInfo deviceInfo= { + .deviceId = "testdevid1", + .deviceName = "testdevname1", + .deviceTypeId = 1, + }; + DeviceInfo devInfo(deviceInfo); + std::string result = devInfo.GetCid(); + + EXPECT_EQ(result, deviceInfo.deviceId); + GTEST_LOG_(INFO) << "DeviceInfoTest_GetCid_0100 end"; +} + +/** + * @tc.name: DeviceInfoTest_Operater_Assignment_0100 + * @tc.desc: Verify the operater= function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(DeviceInfoTest, DeviceInfoTest_Operater_Assignment_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DeviceInfoTest_Operater_Assignment_0100 start"; + + DistributedHardware::DmDeviceInfo deviceInfo= { + .deviceId = "testdevid2", + .deviceName = "testdevname2", + .deviceTypeId = 2, + }; + DeviceInfo devInfo; + devInfo = deviceInfo; + std::string result = devInfo.GetCid(); + + EXPECT_EQ(result, deviceInfo.deviceId); + GTEST_LOG_(INFO) << "DeviceInfoTest_Operater_Assignment_0100 end"; +} +} // namespace Test +} // namespace DistributedFile +} // namespace Storage +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp b/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp index ec17c0e9f..f4b8da104 100644 --- a/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp +++ b/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp @@ -172,6 +172,52 @@ HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnDeviceReady_0100, Test EXPECT_TRUE(res == true); GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnDeviceReady_0100 end"; } + +/** + * @tc.name: DeviceManagerAgentTest_JoinGroup_0100 + * @tc.desc: Verify the JoinGroup function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_JoinGroup_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DeviceManagerAgentTest_JoinGroup_0100 start"; + bool res = true; + constexpr int userId = 101; + auto smp = make_shared(Utils::DfsuMountArgumentDescriptors::Alpha(userId, "account")); + + try { + DeviceManagerAgent::GetInstance()->JoinGroup(smp); + } catch (const exception &e) { + LOGE("Error:%{public}s", e.what()); + res = false; + } + + EXPECT_TRUE(res == true); + GTEST_LOG_(INFO) << "DeviceManagerAgentTest_JoinGroup_0100 end"; +} + +/** + * @tc.name: DeviceManagerAgentTest_OnRemoteDied_0100 + * @tc.desc: Verify the OnRemoteDied function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(DeviceManagerAgentTest, DeviceManagerAgentTest_OnRemoteDied_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnRemoteDied_0100 start"; + bool res = true; + + try { + DeviceManagerAgent::GetInstance()->OnRemoteDied(); + } catch (const exception &e) { + LOGE("Error:%{public}s", e.what()); + res = false; + } + + EXPECT_TRUE(res == true); + GTEST_LOG_(INFO) << "DeviceManagerAgentTest_OnRemoteDied_0100 end"; +} } // namespace Test } // namespace DistributedFile } // namespace Storage -- Gitee