From c10555d212d8d04664bf94fddacb4e781416ef96 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Wed, 23 Nov 2022 10:20:10 +0000 Subject: [PATCH] delete Test module. Signed-off-by: zhangkaixiang5@huawei.com --- BUILD.gn | 2 - services/distributedfiledaemon/BUILD.gn | 2 - .../{ipc/i_daemon.h => common/constant.h} | 23 +-- .../include/device/device_info.h | 1 - .../include/ipc/daemon.h | 67 ------- .../include/ipc/daemon_stub.h | 44 ----- .../src/device/device_info.cpp | 3 +- .../src/device/device_manager_agent.cpp | 12 +- .../distributedfiledaemon/src/ipc/daemon.cpp | 124 ------------ .../src/ipc/daemon_stub.cpp | 47 ----- .../src/network/devsl_dispatcher.cpp | 5 +- .../src/network/softbus/softbus_agent.cpp | 6 +- .../test/unittest/BUILD.gn | 115 ----------- .../test/unittest/ipc/daemon_stub_mock.h | 34 ---- .../test/unittest/ipc/daemon_stub_test.cpp | 123 ------------ .../test/unittest/ipc/daemon_test.cpp | 187 ------------------ test/moduletest/BUILD.gn | 2 - 17 files changed, 18 insertions(+), 779 deletions(-) rename services/distributedfiledaemon/include/{ipc/i_daemon.h => common/constant.h} (66%) delete mode 100644 services/distributedfiledaemon/include/ipc/daemon.h delete mode 100644 services/distributedfiledaemon/include/ipc/daemon_stub.h delete mode 100644 services/distributedfiledaemon/src/ipc/daemon.cpp delete mode 100644 services/distributedfiledaemon/src/ipc/daemon_stub.cpp delete mode 100644 services/distributedfiledaemon/test/unittest/ipc/daemon_stub_mock.h delete mode 100644 services/distributedfiledaemon/test/unittest/ipc/daemon_stub_test.cpp delete mode 100644 services/distributedfiledaemon/test/unittest/ipc/daemon_test.cpp diff --git a/BUILD.gn b/BUILD.gn index 3d0f2232a..9f0027d79 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -26,8 +26,6 @@ group("services_target") { group("dfs_test_moudule") { testonly = true deps = [ - "${services_path}/distributedfiledaemon/test/unittest:daemon_stub_test", - "${services_path}/distributedfiledaemon/test/unittest:daemon_test", "${services_path}/distributedfiledaemon/test/unittest:devsl_dispatcher_test", "${services_path}/distributedfiledaemon/test/unittest:kernel_talker_test", "${services_path}/distributedfiledaemon/test/unittest:os_account_observer_test", diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn index ea0db9b3f..2954af8e7 100644 --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -24,8 +24,6 @@ ohos_shared_library("libdistributedfiledaemon") { sources = [ "src/device/device_info.cpp", "src/device/device_manager_agent.cpp", - "src/ipc/daemon.cpp", - "src/ipc/daemon_stub.cpp", "src/mountpoint/mount_manager.cpp", "src/mountpoint/mount_point.cpp", "src/multiuser/os_account_observer.cpp", diff --git a/services/distributedfiledaemon/include/ipc/i_daemon.h b/services/distributedfiledaemon/include/common/constant.h similarity index 66% rename from services/distributedfiledaemon/include/ipc/i_daemon.h rename to services/distributedfiledaemon/include/common/constant.h index e3bcacc30..8c252c5e4 100644 --- a/services/distributedfiledaemon/include/ipc/i_daemon.h +++ b/services/distributedfiledaemon/include/common/constant.h @@ -12,30 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef I_DAEMON_H -#define I_DAEMON_H - -#include "iremote_broker.h" +#ifndef CONSTANT_H +#define CONSTANT_H +#include namespace OHOS { namespace Storage { namespace DistributedFile { -class IDaemon : public IRemoteBroker { -public: - enum { - DFS_DAEMON_CMD_ECHO = 0, - }; - enum { - DFS_DAEMON_SUCCESS = 0, - DFS_DAEMON_DESCRIPTOR_IS_EMPTY, - }; - virtual int32_t EchoServerDemo(const std::string &echoStr) = 0; static inline const std::string SERVICE_NAME { "ohos.storage.distributedfile.daemon" }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.storage.distributedfile.daemon") -}; + } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // I_DAEMON_H \ No newline at end of file +#endif // CONSTANT_H \ No newline at end of file diff --git a/services/distributedfiledaemon/include/device/device_info.h b/services/distributedfiledaemon/include/device/device_info.h index 532455cdd..d018fb48a 100644 --- a/services/distributedfiledaemon/include/device/device_info.h +++ b/services/distributedfiledaemon/include/device/device_info.h @@ -20,7 +20,6 @@ #include "device_manager.h" #include "dm_device_info.h" -#include "ipc/i_daemon.h" namespace OHOS { namespace Storage { diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h deleted file mode 100644 index 7843c9bd4..000000000 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 DAEMON_H -#define DAEMON_H - -#include -#include -#include - -#include "daemon_stub.h" -#include "i_daemon.h" -#include "iremote_stub.h" -#include "multiuser/os_account_observer.h" -#include "nocopyable.h" -#include "refbase.h" -#include "system_ability.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; - -class Daemon final : public SystemAbility, public DaemonStub, protected NoCopyable { - DECLARE_SYSTEM_ABILITY(Daemon); - -public: - explicit Daemon(int32_t saID, bool runOnCreate = true) : SystemAbility(saID, runOnCreate) {}; - virtual ~Daemon() = default; - - void OnStart() override; - void OnStop() override; - void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; - void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; - ServiceRunningState QueryServiceState() const - { - return state_; - } - - int32_t EchoServerDemo(const std::string &echoStr) override; - -private: - Daemon(); - ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START }; - static sptr instance_; - static std::mutex instanceLock_; - bool registerToService_ { false }; - std::shared_ptr subScriber_; - void PublishSA(); - void RegisterOsAccount(); -}; -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS -#endif // DAEMON_H \ No newline at end of file diff --git a/services/distributedfiledaemon/include/ipc/daemon_stub.h b/services/distributedfiledaemon/include/ipc/daemon_stub.h deleted file mode 100644 index dbade18c1..000000000 --- a/services/distributedfiledaemon/include/ipc/daemon_stub.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 DAEMON_STUB_H -#define DAEMON_STUB_H - -#include - -#include "i_daemon.h" -#include "iremote_stub.h" -#include "message_option.h" -#include "message_parcel.h" -#include "refbase.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -class DaemonStub : public IRemoteStub { -public: - DaemonStub(); - virtual ~DaemonStub() = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - using DaemonInterface = int32_t (DaemonStub::*)(MessageParcel &data, MessageParcel &reply); - std::map opToInterfaceMap_; - - int32_t EchoServerDemoInner(MessageParcel &data, MessageParcel &reply); -}; -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS -#endif // DAEMON_STUB_H \ No newline at end of file diff --git a/services/distributedfiledaemon/src/device/device_info.cpp b/services/distributedfiledaemon/src/device/device_info.cpp index 9807ce5ff..cc8670288 100644 --- a/services/distributedfiledaemon/src/device/device_info.cpp +++ b/services/distributedfiledaemon/src/device/device_info.cpp @@ -14,6 +14,7 @@ */ #include "device/device_info.h" +#include "common/constant.h" #include "dfsu_exception.h" #include "utils_log.h" @@ -28,7 +29,7 @@ DeviceInfo::DeviceInfo(const DistributedHardware::DmDeviceInfo &nodeInfo) initCidFlag_ = true; // convert networkId to udid auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); - deviceManager.GetUdidByNetworkId(IDaemon::SERVICE_NAME, cid_, udid_); + deviceManager.GetUdidByNetworkId(SERVICE_NAME, cid_, udid_); } DeviceInfo &DeviceInfo::operator=(const DistributedHardware::DmDeviceInfo &nodeInfo) diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index 2947a60ae..e2edc729a 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -19,9 +19,9 @@ #include #include +#include "common/constant.h" #include "device_auth.h" #include "dfsu_exception.h" -#include "ipc/i_daemon.h" #include "mountpoint/mount_manager.h" #include "network/devsl_dispatcher.h" #include "network/softbus/softbus_agent.h" @@ -236,7 +236,7 @@ void DeviceManagerAgent::QueryRelatedGroups(const std::string &udid, const std:: char *returnGroupVec = nullptr; uint32_t groupNum = 0; - ret = hichainDevGroupMgr_->getRelatedGroups(ANY_OS_ACCOUNT, IDaemon::SERVICE_NAME.c_str(), udid.c_str(), + ret = hichainDevGroupMgr_->getRelatedGroups(ANY_OS_ACCOUNT, SERVICE_NAME.c_str(), udid.c_str(), &returnGroupVec, &groupNum); if (ret != 0 || returnGroupVec == nullptr) { LOGE("failed to get related groups, ret %{public}d", ret); @@ -300,7 +300,7 @@ void DeviceManagerAgent::OnDeviceChanged(const DistributedHardware::DmDeviceInfo void DeviceManagerAgent::InitLocalNodeInfo() { NodeBasicInfo tmpNodeInfo; - int errCode = GetLocalNodeDeviceInfo(IDaemon::SERVICE_NAME.c_str(), &tmpNodeInfo); + int errCode = GetLocalNodeDeviceInfo(SERVICE_NAME.c_str(), &tmpNodeInfo); if (errCode != 0) { ThrowException(errCode, "Failed to get info of local devices"); } @@ -320,7 +320,7 @@ DeviceInfo &DeviceManagerAgent::GetLocalDeviceInfo() vector DeviceManagerAgent::GetRemoteDevicesInfo() { string extra = ""; - string pkgName = IDaemon::SERVICE_NAME; + string pkgName = SERVICE_NAME; vector deviceList; auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); @@ -339,7 +339,7 @@ vector DeviceManagerAgent::GetRemoteDevicesInfo() void DeviceManagerAgent::RegisterToExternalDm() { auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); - string pkgName = IDaemon::SERVICE_NAME; + string pkgName = SERVICE_NAME; int errCode = deviceManager.InitDeviceManager(pkgName, shared_from_this()); if (errCode != 0) { ThrowException(errCode, "Failed to InitDeviceManager"); @@ -355,7 +355,7 @@ void DeviceManagerAgent::RegisterToExternalDm() void DeviceManagerAgent::UnregisterFromExternalDm() { auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); - string pkgName = IDaemon::SERVICE_NAME; + string pkgName = SERVICE_NAME; int errCode = deviceManager.UnRegisterDevStateCallback(pkgName); if (errCode != 0) { ThrowException(errCode, "Failed to UnRegisterDevStateCallback"); diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp deleted file mode 100644 index 194fb0d50..000000000 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 "ipc/daemon.h" - -#include -#include - -#include "common_event_manager.h" -#include "common_event_support.h" -#include "iremote_object.h" -#include "mountpoint/mount_manager.h" -#include "system_ability_definition.h" -#include "utils_log.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -using namespace std; - -REGISTER_SYSTEM_ABILITY_BY_ID(Daemon, FILEMANAGEMENT_DISTRIBUTED_FILE_DAEMON_SA_ID, true); - -void Daemon::PublishSA() -{ - LOGI("Begin to init"); - if (!registerToService_) { - bool ret = SystemAbility::Publish(this); - if (!ret) { - throw runtime_error("Failed to publish the daemon"); - } - registerToService_ = true; - } - LOGI("Init finished successfully"); -} - -void Daemon::RegisterOsAccount() -{ - EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED); - EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); - subScriber_ = std::make_shared(subscribeInfo); - bool subRet = EventFwk::CommonEventManager::SubscribeCommonEvent(subScriber_); - if (!subRet) { - LOGE("Subscribe common event failed"); - } -} - -void Daemon::OnStart() -{ - LOGI("Begin to start service"); - if (state_ == ServiceRunningState::STATE_RUNNING) { - LOGD("Daemon has already started"); - return; - } - - try { - PublishSA(); - AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID); - } catch (const exception &e) { - LOGE("%{public}s", e.what()); - } - - state_ = ServiceRunningState::STATE_RUNNING; - LOGI("Start service successfully"); -} - -void Daemon::OnStop() -{ - LOGI("Begin to stop"); - state_ = ServiceRunningState::STATE_NOT_START; - registerToService_ = false; - bool subRet = EventFwk::CommonEventManager::UnSubscribeCommonEvent(subScriber_); - if (!subRet) { - LOGE("UnSubscribe common event failed"); - } - subScriber_ = nullptr; - LOGI("Stop finished successfully"); -} - -void Daemon::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) -{ - (void)systemAbilityId; - (void)deviceId; - RegisterOsAccount(); -} - -void Daemon::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) -{ - (void)deviceId; - if (systemAbilityId != COMMON_EVENT_SERVICE_ID) { - LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID"); - return; - } - - if (subScriber_ == nullptr) { - LOGE("Daemon::OnRemoveSystemAbility subscriberPtr is nullptr"); - return; - } - - bool subscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(subScriber_); - LOGI("Daemon::OnRemoveSystemAbility subscribeResult = %{public}d", subscribeResult); - subScriber_ = nullptr; -} - -int32_t Daemon::EchoServerDemo(const string &echoStr) -{ - (void)echoStr; - return 0; -} -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS diff --git a/services/distributedfiledaemon/src/ipc/daemon_stub.cpp b/services/distributedfiledaemon/src/ipc/daemon_stub.cpp deleted file mode 100644 index 5b741452d..000000000 --- a/services/distributedfiledaemon/src/ipc/daemon_stub.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 "ipc/daemon_stub.h" -#include "utils_log.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -DaemonStub::DaemonStub() -{ - opToInterfaceMap_[DFS_DAEMON_CMD_ECHO] = &DaemonStub::EchoServerDemoInner; -} - -int32_t DaemonStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - return DFS_DAEMON_DESCRIPTOR_IS_EMPTY; - } - auto interfaceIndex = opToInterfaceMap_.find(code); - if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { - LOGE("Cannot response request %d: unknown tranction", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return (this->*(interfaceIndex->second))(data, reply); -} - -int32_t DaemonStub::EchoServerDemoInner(MessageParcel &data, MessageParcel &reply) -{ - LOGI("hello, world"); - return ERR_NONE; -} -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS diff --git a/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp b/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp index 4e9f1cd26..73e17b4ce 100644 --- a/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp +++ b/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp @@ -14,9 +14,8 @@ */ #include "network/devsl_dispatcher.h" - +#include "common/constant.h" #include "device_manager.h" -#include "ipc/i_daemon.h" #include "securec.h" #include "utils_log.h" @@ -57,7 +56,7 @@ uint32_t DevslDispatcher::DevslGetRegister(const std::string &cid, std::weak_ptr { std::string udid; auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); - deviceManager.GetUdidByNetworkId(IDaemon::SERVICE_NAME, cid, udid); + deviceManager.GetUdidByNetworkId(SERVICE_NAME, cid, udid); std::lock_guard lock(mutex); DEVSLQueryParams queryParams = MakeDevslQueryParams(udid); diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index efd334bfb..acbe91b6c 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -18,7 +18,7 @@ #include #include "dfsu_exception.h" -#include "ipc/i_daemon.h" +#include "common/constant.h" #include "ipc_skeleton.h" #include "network/softbus/softbus_session.h" #include "network/softbus/softbus_session_dispatcher.h" @@ -58,7 +58,7 @@ void SoftbusAgent::JoinDomain() }; SoftbusSessionDispatcher::RegisterSessionListener(sessionName_, shared_from_this()); - int ret = ::CreateSessionServer(IDaemon::SERVICE_NAME.c_str(), sessionName_.c_str(), &sessionListener); + int ret = ::CreateSessionServer(SERVICE_NAME.c_str(), sessionName_.c_str(), &sessionListener); if (ret != 0) { stringstream ss; ss << "Failed to CreateSessionServer, errno:" << ret; @@ -70,7 +70,7 @@ void SoftbusAgent::JoinDomain() void SoftbusAgent::QuitDomain() { - int ret = ::RemoveSessionServer(IDaemon::SERVICE_NAME.c_str(), sessionName_.c_str()); + int ret = ::RemoveSessionServer(SERVICE_NAME.c_str(), sessionName_.c_str()); if (ret != 0) { stringstream ss; ss << "Failed to RemoveSessionServer, errno:" << ret; diff --git a/services/distributedfiledaemon/test/unittest/BUILD.gn b/services/distributedfiledaemon/test/unittest/BUILD.gn index 02e69cefc..e407bf6f6 100644 --- a/services/distributedfiledaemon/test/unittest/BUILD.gn +++ b/services/distributedfiledaemon/test/unittest/BUILD.gn @@ -32,8 +32,6 @@ ohos_unittest("device_manager_agent_test") { 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", @@ -74,111 +72,12 @@ ohos_unittest("device_manager_agent_test") { defines = [ "private=public" ] } -ohos_unittest("daemon_stub_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 += [ "ipc/daemon_stub_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:gmock_main", - "//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" ] -} - -ohos_unittest("daemon_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 += [ "ipc/daemon_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" ] -} - ohos_unittest("os_account_observer_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", @@ -225,8 +124,6 @@ ohos_unittest("devsl_dispatcher_test") { 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", @@ -272,8 +169,6 @@ ohos_unittest("kernel_talker_test") { 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", @@ -319,8 +214,6 @@ ohos_unittest("session_pool_test") { 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", @@ -366,8 +259,6 @@ ohos_unittest("softbus_agent_test") { 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", @@ -413,8 +304,6 @@ ohos_unittest("softbus_session_dispatcher_test") { 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", @@ -460,8 +349,6 @@ ohos_unittest("softbus_session_test") { 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", @@ -504,8 +391,6 @@ ohos_unittest("softbus_session_test") { group("unittest") { testonly = true deps = [ - ":daemon_stub_test", - ":daemon_test", ":devsl_dispatcher_test", ":kernel_talker_test", ":os_account_observer_test", diff --git a/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_mock.h b/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_mock.h deleted file mode 100644 index 3a1cebb41..000000000 --- a/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_mock.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ -#ifndef DAEMON_STUB_MOCK_H -#define DAEMON_STUB_MOCK_H - -#include "gmock/gmock.h" -#include "ipc/daemon_stub.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -class DaemonStubMock : public DaemonStub { -public: - explicit DaemonStubMock() {} - virtual ~DaemonStubMock() {} - - MOCK_METHOD1(EchoServerDemo, int32_t(const std::string &)); -}; -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS -#endif // DAEMON_STUB_MOCK_H \ No newline at end of file diff --git a/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_test.cpp b/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_test.cpp deleted file mode 100644 index 8f0e89c9a..000000000 --- a/services/distributedfiledaemon/test/unittest/ipc/daemon_stub_test.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 "gtest/gtest.h" -#include "daemon_stub_mock.h" -#include "ipc/daemon_stub.h" -#include "ipc/i_daemon.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -namespace Test { -namespace { - const int ERROR_CODE = 99999; -} -using namespace testing::ext; - -class DaemonStubTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void DaemonStubTest::SetUpTestCase(void) -{ - // input testsuit setup step,setup invoked before all testcases -} - -void DaemonStubTest::TearDownTestCase(void) -{ - // input testsuit teardown step,teardown invoked after all testcases -} - -void DaemonStubTest::SetUp(void) -{ - // input testcase setup step,setup invoked before each testcases -} - -void DaemonStubTest::TearDown(void) -{ - // input testcase teardown step,teardown invoked after each testcases -} - -/** - * @tc.name: DaemonStubTest_OnRemoteRequest_0100 - * @tc.desc: Verify the OnRemoteRequest function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0100 start"; - DaemonStubMock mock; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - bool bRet = data.WriteInterfaceToken(u"error descriptor"); - EXPECT_TRUE(bRet) << "write token error"; - - int32_t ret = mock.OnRemoteRequest(IDaemon::DFS_DAEMON_CMD_ECHO, data, reply, option); - EXPECT_TRUE(ret != ERR_NONE) << "descriptor error"; - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0100 end"; -} - -/** - * @tc.name: DaemonStubTest_OnRemoteRequest_0200 - * @tc.desc: Verify the OnRemoteRequest function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0200, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0200 start"; - DaemonStubMock mock; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - bool bRet = data.WriteInterfaceToken(IDaemon::GetDescriptor()); - EXPECT_TRUE(bRet) << "write token error"; - - int32_t ret = mock.OnRemoteRequest(ERROR_CODE, data, reply, option); - EXPECT_TRUE(ret != IDaemon::DFS_DAEMON_SUCCESS) << "request code error"; - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0200 end"; -} - -/** - * @tc.name: DaemonStubTest_OnRemoteRequest_0300 - * @tc.desc: Verify the OnRemoteRequest function. - * @tc.type: FUNC - * @tc.require: AR000GK4HB - */ -HWTEST_F(DaemonStubTest, DaemonStubTest_OnRemoteRequest_0300, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0300 start"; - DaemonStubMock mock; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - bool bRet = data.WriteInterfaceToken(IDaemon::GetDescriptor()); - EXPECT_TRUE(bRet) << "write token error"; - - int32_t ret = mock.OnRemoteRequest(IDaemon::DFS_DAEMON_CMD_ECHO, data, reply, option); - EXPECT_TRUE(ret == IDaemon::DFS_DAEMON_SUCCESS); - GTEST_LOG_(INFO) << "DaemonStubTest_OnRemoteRequest_0300 end"; -} -} // namespace Test -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS \ No newline at end of file diff --git a/services/distributedfiledaemon/test/unittest/ipc/daemon_test.cpp b/services/distributedfiledaemon/test/unittest/ipc/daemon_test.cpp deleted file mode 100644 index b4a1923d4..000000000 --- a/services/distributedfiledaemon/test/unittest/ipc/daemon_test.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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 "gtest/gtest.h" -#include "ipc/daemon.h" -#include "utils_log.h" - -namespace OHOS { -namespace Storage { -namespace DistributedFile { -namespace Test { -using namespace testing::ext; - -std::shared_ptr g_daemon = nullptr; - -class DaemonTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void DaemonTest::SetUpTestCase(void) -{ - // input testsuit setup step,setup invoked before all testcases - if (g_daemon == nullptr) { - int32_t saId = 10; - g_daemon = std::make_shared(saId); - ASSERT_TRUE(g_daemon != nullptr) << "SystemAbility failed"; - } -} - -void DaemonTest::TearDownTestCase(void) -{ - // input testsuit teardown step,teardown invoked after all testcases - g_daemon = nullptr; -} - -void DaemonTest::SetUp(void) -{ - // input testcase setup step,setup invoked before each testcases -} - -void DaemonTest::TearDown(void) -{ - // input testcase teardown step,teardown invoked after each testcases -} - -/** - * @tc.name: DaemonTest_OnStart_0100 - * @tc.desc: Verify the OnStart function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_OnStart_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_OnStart_0100 start"; - bool res = true; - try { - g_daemon->OnStart(); - } - catch(const std::exception& e) { - res = false; - LOGE("DaemonTest_OnStart_0100 : %{public}s", e.what()); - } - EXPECT_TRUE(res == true); - GTEST_LOG_(INFO) << "DaemonTest_OnStart_0100 end"; -} - -/** - * @tc.name: DaemonTest_OnAddSystemAbility_0200 - * @tc.desc: Verify the OnAddSystemAbility function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_OnAddSystemAbility_0200, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_0200 start"; - bool res = true; - try { - int32_t saId = 10; - g_daemon->OnAddSystemAbility(saId, ""); - } - catch(const std::exception& e) { - res = false; - LOGE("DaemonTest_OnAddSystemAbility_0200 : %{public}s", e.what()); - } - EXPECT_TRUE(res == true); - GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_0200 end"; -} - -/** - * @tc.name: DaemonTest_OnRemoveSystemAbility_0300 - * @tc.desc: Verify the OnRemoveSystemAbility function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_OnRemoveSystemAbility_0300, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_0300 start"; - bool res = true; - try { - int32_t saId = 10; - g_daemon->OnRemoveSystemAbility(saId, ""); - } - catch(const std::exception& e) { - res = false; - LOGE("DaemonTest_OnRemoveSystemAbility_0300 : %{public}s", e.what()); - } - EXPECT_TRUE(res == true); - GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_0300 end"; -} - -/** - * @tc.name: DaemonTest_QueryServiceState_0400 - * @tc.desc: Verify the QueryServiceState function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_QueryServiceState_0400, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_QueryServiceState_0400 start"; - ServiceRunningState state { ServiceRunningState::STATE_NOT_START }; - state = g_daemon->QueryServiceState(); - EXPECT_EQ(state, ServiceRunningState::STATE_RUNNING); - GTEST_LOG_(INFO) << "DaemonTest_QueryServiceState_0400 end"; -} - -/** - * @tc.name: DaemonTest_EchoServerDemo_0500 - * @tc.desc: Verify the EchoServerDemo function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_EchoServerDemo_0500, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_EchoServerDemo_0500 start"; - int32_t res = 1; - try { - res = g_daemon->EchoServerDemo(""); - } - catch(const std::exception& e) { - LOGE("DaemonTest_EchoServerDemo_0500 : %{public}s", e.what()); - } - EXPECT_EQ(res, 0); - GTEST_LOG_(INFO) << "DaemonTest_EchoServerDemo_0500 end"; -} - -/** - * @tc.name: DaemonTest_OnStop_0600 - * @tc.desc: Verify the OnStop function. - * @tc.type: FUNC - * @tc.require: SR000H0387 - */ -HWTEST_F(DaemonTest, DaemonTest_OnStop_0600, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "DaemonTest_OnStop_0600 start"; - bool res = true; - try { - g_daemon->OnStop(); - } - catch(const std::exception& e) { - res = false; - LOGE("DaemonTest_OnStop_0600 : %{public}s", e.what()); - } - EXPECT_TRUE(res == true); - GTEST_LOG_(INFO) << "DaemonTest_OnStop_0600 end"; -} -} // namespace Test -} // namespace DistributedFile -} // namespace Storage -} // namespace OHOS \ No newline at end of file diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index e28eaf786..4f3de710d 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -35,8 +35,6 @@ ohos_moduletest("DistributedFileDaemonServiceTest") { 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", -- Gitee