diff --git a/frameworks/native/distributed_file_inner/include/copy/file_copy_manager.h b/frameworks/native/distributed_file_inner/include/copy/file_copy_manager.h index ca95276ec6c00aa5c416dabf742864480636ccc0..ae24f2f1ba55e66fc9859db94e81f075a8b8c878 100644 --- a/frameworks/native/distributed_file_inner/include/copy/file_copy_manager.h +++ b/frameworks/native/distributed_file_inner/include/copy/file_copy_manager.h @@ -67,8 +67,12 @@ struct FileInfos { class FileCopyManager final { public: + static FileCopyManager &GetInstance() + { + static FileCopyManager instance; + return instance; + } using ProcessCallback = std::function; - static std::shared_ptr GetInstance(); int32_t Copy(const std::string &srcUri, const std::string &destUri, ProcessCallback &processCallback); int32_t Cancel(const std::string &srcUri, const std::string &destUri, const bool isKeepFiles = false); int32_t Cancel(const bool isKeepFiles = false); @@ -76,7 +80,6 @@ public: int32_t ExecLocal(std::shared_ptr infos); private: - static std::shared_ptr instance_; std::mutex FileInfosVecMutex_; std::vector> FileInfosVec_; diff --git a/frameworks/native/distributed_file_inner/include/copy/remote_file_copy_manager.h b/frameworks/native/distributed_file_inner/include/copy/remote_file_copy_manager.h index 295b0a5a79ba5ab19f7be0969f6a804564956a14..a66e2d9eac5780a802287995c753ef90ffae8027 100644 --- a/frameworks/native/distributed_file_inner/include/copy/remote_file_copy_manager.h +++ b/frameworks/native/distributed_file_inner/include/copy/remote_file_copy_manager.h @@ -24,7 +24,11 @@ namespace DistributedFile { class RemoteFileCopyManager { public: - static std::shared_ptr GetInstance(); + static RemoteFileCopyManager &GetInstance() + { + static RemoteFileCopyManager instance; + return instance; + } int32_t RemoteCopy(const std::string &srcUri, const std::string &destUri, const sptr &listener, const int32_t userId, const std::string ©Path); int32_t RemoteCancel(const std::string &srcUri, const std::string &destUri); @@ -38,7 +42,6 @@ private: void AddFileInfos(std::shared_ptr infos); bool IsFile(const std::string &path); private: - static std::shared_ptr instance_; std::mutex FileInfosVecMutex_; std::vector> FileInfosVec_; }; diff --git a/frameworks/native/distributed_file_inner/include/file_mount_manager.h b/frameworks/native/distributed_file_inner/include/file_mount_manager.h index 89f563249f86fa19ed094c4f4efc8eb7f5007ab9..9cac363cf3563d5515c9cfa5ab0130da3e83cebd 100644 --- a/frameworks/native/distributed_file_inner/include/file_mount_manager.h +++ b/frameworks/native/distributed_file_inner/include/file_mount_manager.h @@ -1,40 +1,43 @@ /* -* Copyright (c) 2025 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. -*/ + * Copyright (c) 2025 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_STORAGE_FILE_MOUNT_MANAGER_H #define OHOS_STORAGE_FILE_MOUNT_MANAGER_H + +#include "remote_file_share.h" #include #include #include -#include "remote_file_share.h" namespace OHOS { namespace Storage { namespace DistributedFile { class FileMountManager { public: - static int32_t GetDfsUrisDirFromLocal(const std::vector &uriList, - const int32_t userId, - std::unordered_map &uriToDfsUriMaps); - static std::shared_ptr GetInstance(); -private: - static std::shared_ptr instance_; + static FileMountManager &GetInstance() + { + static FileMountManager instance; + return instance; + } + static int32_t GetDfsUrisDirFromLocal( + const std::vector &uriList, + const int32_t userId, + std::unordered_map &uriToDfsUriMaps); }; -} -} -} +} // namespace DistributedFile +} // namespace Storage +} // namespace OHOS #endif // OHOS_STORAGE_FILE_MOUNT_MANAGER_H diff --git a/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp b/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp index 560f95880befad004564fb77a878591ff3f41f6b..857076c39d0f28d1f6b35a126aa0d16a7280be48 100644 --- a/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp +++ b/frameworks/native/distributed_file_inner/src/copy/file_copy_manager.cpp @@ -64,7 +64,6 @@ static const int OPEN_TRUC_VERSION = 20; #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) const uint32_t API_VERSION_MOD = 1000; #endif -std::shared_ptr FileCopyManager::instance_ = nullptr; uint32_t g_apiCompatibleVersion = 0; #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) && !defined(CROSS_PLATFORM) @@ -165,16 +164,6 @@ uint32_t GetApiCompatibleVersion() } #endif -std::shared_ptr FileCopyManager::GetInstance() -{ - static std::once_flag once; - std::call_once(once, []() { - FileCopyManager::instance_ = std::make_shared(); - }); - - return instance_; -} - int32_t FileCopyManager::Copy(const std::string &srcUri, const std::string &destUri, ProcessCallback &processCallback) { LOGE("FileCopyManager Copy start"); diff --git a/frameworks/native/distributed_file_inner/src/copy/remote_file_copy_manager.cpp b/frameworks/native/distributed_file_inner/src/copy/remote_file_copy_manager.cpp index dc041875573f92aaf7c3b54c9e4406d5a53326c3..27940578efc699118a391737699028e6084429a1 100644 --- a/frameworks/native/distributed_file_inner/src/copy/remote_file_copy_manager.cpp +++ b/frameworks/native/distributed_file_inner/src/copy/remote_file_copy_manager.cpp @@ -39,7 +39,6 @@ static const std::string MEDIA_AUTHORITY = "media"; static const std::string FILE_MANAGER_AUTHORITY = "docs"; static const std::string FILE_SCHEMA = "file://"; static const std::string FILE_SEPARATOR = "/"; -std::shared_ptr RemoteFileCopyManager::instance_ = nullptr; static std::string GetBundleName(const std::string &uri) { @@ -117,15 +116,6 @@ static std::string GetFileName(const std::string &path) return path.substr(pos + 1); } -std::shared_ptr RemoteFileCopyManager::GetInstance() -{ - static std::once_flag once; - std::call_once(once, []() { - RemoteFileCopyManager::instance_ = std::make_shared(); - }); - return instance_; -} - void RemoteFileCopyManager::AddFileInfos(std::shared_ptr infos) { std::lock_guard lock(FileInfosVecMutex_); @@ -231,7 +221,7 @@ int32_t RemoteFileCopyManager::RemoteCopy(const std::string &srcUri, const std:: }; infos->localListener = FileCopyLocalListener::GetLocalListener(infos->srcPath, infos->srcUriIsFile, processCallback); - auto result = FileCopyManager::GetInstance()->ExecLocal(infos); + auto result = FileCopyManager::GetInstance().ExecLocal(infos); if (ChangeOwnerRecursive(infos->destPath, infos->callingUid, infos->callingUid) != 0) { LOGE("ChangeOwnerRecursive failed, calling uid= %{public}d", infos->callingUid); } diff --git a/frameworks/native/distributed_file_inner/src/distributed_file_daemon_manager_impl.cpp b/frameworks/native/distributed_file_inner/src/distributed_file_daemon_manager_impl.cpp index 433f02a277759e6fc54939e420fc09eae9efda73..bbadaa0f888f1eec7bd50d66fb7a2c0fd70f96b1 100644 --- a/frameworks/native/distributed_file_inner/src/distributed_file_daemon_manager_impl.cpp +++ b/frameworks/native/distributed_file_inner/src/distributed_file_daemon_manager_impl.cpp @@ -255,17 +255,17 @@ int32_t DistributedFileDaemonManagerImpl::IsDirectory(const std::string &uri, bo int32_t DistributedFileDaemonManagerImpl::Copy(const std::string &srcUri, const std::string &destUri, ProcessCallback processCallback) { - return FileCopyManager::GetInstance()->Copy(srcUri, destUri, processCallback); + return FileCopyManager::GetInstance().Copy(srcUri, destUri, processCallback); } int32_t DistributedFileDaemonManagerImpl::Cancel(const std::string &srcUri, const std::string &destUri) { - return FileCopyManager::GetInstance()->Cancel(srcUri, destUri); + return FileCopyManager::GetInstance().Cancel(srcUri, destUri); } int32_t DistributedFileDaemonManagerImpl::Cancel() { - return FileCopyManager::GetInstance()->Cancel(); + return FileCopyManager::GetInstance().Cancel(); } } // namespace DistributedFile } // namespace Storage diff --git a/frameworks/native/distributed_file_inner/src/file_mount_manager.cpp b/frameworks/native/distributed_file_inner/src/file_mount_manager.cpp index eeb1a42ddddf285243ab1c847c8e9ec79e8d1f55..cc47286af4041b79e0d3f8ecff4f71c39fa55623 100644 --- a/frameworks/native/distributed_file_inner/src/file_mount_manager.cpp +++ b/frameworks/native/distributed_file_inner/src/file_mount_manager.cpp @@ -1,23 +1,23 @@ /* -* Copyright (c) 2025 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. -*/ + * Copyright (c) 2025 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 "dfs_error.h" #include "ipc_skeleton.h" #include "utils_log.h" +#include +#include #undef LOG_DOMAIN #undef LOG_TAG @@ -27,22 +27,11 @@ namespace OHOS { namespace Storage { namespace DistributedFile { -std::shared_ptr FileMountManager::instance_ = nullptr; - -std::shared_ptr FileMountManager::GetInstance() -{ - static std::once_flag once; - std::call_once(once, []() { - FileMountManager::instance_ = std::make_shared(); - }); - - return instance_; -} -int32_t FileMountManager::GetDfsUrisDirFromLocal(const std::vector &uriList, - const int32_t userId, - std::unordered_map &uriToDfsUriMaps) +int32_t FileMountManager::GetDfsUrisDirFromLocal( + const std::vector &uriList, + const int32_t userId, + std::unordered_map &uriToDfsUriMaps) { auto distributedFileDaemonProxy = DistributedFileDaemonProxy::GetInstance(); if (!distributedFileDaemonProxy) { @@ -52,6 +41,6 @@ int32_t FileMountManager::GetDfsUrisDirFromLocal(const std::vector return distributedFileDaemonProxy->GetDfsUrisDirFromLocal(uriList, userId, uriToDfsUriMaps); } -} -} -} \ No newline at end of file +} // namespace DistributedFile +} // namespace Storage +} // namespace OHOS \ No newline at end of file diff --git a/services/distributedfiledaemon/BUILD.gn b/services/distributedfiledaemon/BUILD.gn index c0cd8cdbb6026e648abc273898081978a26f3c0e..704bf7cf29a75fb5d6ccddd969b4f3b53ae22ddf 100644 --- a/services/distributedfiledaemon/BUILD.gn +++ b/services/distributedfiledaemon/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("distributed_file_daemon_kit_inner") { cfi_cross_dso = true debug = false } + sources = [ "${distributedfile_path}/frameworks/native/distributed_file_inner/src/asset/asset_adapter_sa_client.cpp", "${distributedfile_path}/frameworks/native/distributed_file_inner/src/asset/asset_obj.cpp", diff --git a/services/distributedfiledaemon/include/connect_count/connect_count.h b/services/distributedfiledaemon/include/connect_count/connect_count.h index 8ac745925d8e3b20971555951cba6a6e703352b8..95460f261bd43f7b92f2d3e45ff20d93b323ba51 100644 --- a/services/distributedfiledaemon/include/connect_count/connect_count.h +++ b/services/distributedfiledaemon/include/connect_count/connect_count.h @@ -24,6 +24,7 @@ #include #include "ipc/i_file_dfs_listener.h" +#include "single_instance.h" namespace OHOS { namespace Storage { @@ -50,11 +51,8 @@ enum Status { }; class ConnectCount final { + DECLARE_SINGLE_INSTANCE(ConnectCount); public: - ConnectCount() = default; - ~ConnectCount() = default; - static std::shared_ptr GetInstance(); - void AddConnect(uint32_t callingTokenId, const std::string &networkId, sptr &listener); bool CheckCount(const std::string &networkId); void RemoveAllConnect(); @@ -69,7 +67,6 @@ public: void NotifyFileStatusChange(const std::string &networkId, const int32_t status, const std::string &path, StatusType type); private: - static std::shared_ptr instance_; std::recursive_mutex connectMutex_; std::unordered_set> connectList_; std::recursive_mutex fileConnectMutex_; diff --git a/services/distributedfiledaemon/src/connect_count/connect_count.cpp b/services/distributedfiledaemon/src/connect_count/connect_count.cpp index 25428d24de2c68ac4d2899cb896776d160242f43..864ddc147b71ad3bf9fa67594a7e21f43916f471 100644 --- a/services/distributedfiledaemon/src/connect_count/connect_count.cpp +++ b/services/distributedfiledaemon/src/connect_count/connect_count.cpp @@ -22,16 +22,8 @@ namespace OHOS { namespace Storage { namespace DistributedFile { -std::shared_ptr ConnectCount::instance_ = nullptr; static const int32_t ON_STATUS_OFFLINE = 13900046; -std::shared_ptr ConnectCount::GetInstance() -{ - static std::once_flag once; - std::call_once(once, [&]() { - instance_ = std::make_shared(); - }); - return instance_; -} +IMPLEMENT_SINGLE_INSTANCE(ConnectCount); void ConnectCount::AddConnect(uint32_t callingTokenId, const std::string &networkId, sptr &listener) { diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index 609923cdf7e8a37ad77c0769877667b6d4e7d066..120adf323be598795726c740298203119c0f6eb6 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -255,6 +255,7 @@ void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo GetStorageManager(); if (storageMgrProxy_ == nullptr) { LOGE("storageMgrProxy_ is null"); + return; } ret = storageMgrProxy_->UMountDisShareFile(userId, localNetworkId); if (ret != NO_ERROR) { @@ -540,9 +541,9 @@ int32_t DeviceManagerAgent::UMountDfsDocs(const std::string &networkId, const st LOGI("UMountDfsDocs success, deviceId %{public}s erase count", Utils::GetAnonyString(deviceId).c_str()); RemoveMountDfsCount(deviceId); - ConnectCount::GetInstance()->NotifyFileStatusChange(networkId, Status::DISCONNECT_OK, - MOUNT_PATH + networkId.substr(0, VALID_MOUNT_PATH_LEN), - StatusType::CONNECTION_STATUS); + ConnectCount::GetInstance().NotifyFileStatusChange(networkId, Status::DISCONNECT_OK, + MOUNT_PATH + networkId.substr(0, VALID_MOUNT_PATH_LEN), + StatusType::CONNECTION_STATUS); } LOGI("storageMgr.UMountDfsDocs end."); return ret; @@ -619,6 +620,7 @@ int32_t DeviceManagerAgent::AddRemoteReverseObj(uint32_t callingTokenId, sptr lock(appCallConnectMutex_); if (clear) { appCallConnect_.clear(); return FileManagement::E_OK; diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index f60fa3f225f992fe903ffe08beb9533421955054..bd58b1066756709049ff0ae936b71b896d5065b3 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -213,10 +213,10 @@ int32_t Daemon::OpenP2PConnection(const DistributedHardware::DmDeviceInfo &devic sptr listener = nullptr; auto ret = ConnectionCount(deviceInfo); if (ret == E_OK) { - ConnectCount::GetInstance()->AddConnect(callingTokenId, deviceInfo.networkId, listener); + ConnectCount::GetInstance().AddConnect(callingTokenId, deviceInfo.networkId, listener); } else { if (ret == ERR_CHECKOUT_COUNT) { - ConnectCount::GetInstance()->RemoveConnect(callingTokenId, deviceInfo.networkId); + ConnectCount::GetInstance().RemoveConnect(callingTokenId, deviceInfo.networkId); } CleanUp(deviceInfo); } @@ -229,7 +229,7 @@ int32_t Daemon::CloseP2PConnection(const DistributedHardware::DmDeviceInfo &devi LOGI("Close P2P Connection networkId %{public}s", Utils::GetAnonyString(deviceInfo.networkId).c_str()); auto callingTokenId = IPCSkeleton::GetCallingTokenID(); auto networkId = std::string(deviceInfo.networkId); - ConnectCount::GetInstance()->RemoveConnect(callingTokenId, networkId); + ConnectCount::GetInstance().RemoveConnect(callingTokenId, networkId); CleanUp(deviceInfo); return 0; } @@ -246,7 +246,7 @@ int32_t Daemon::ConnectionCount(const DistributedHardware::DmDeviceInfo &deviceI auto targetDir = ss.str(); auto networkId = std::string(deviceInfo.networkId); int32_t ret = 0; - if (!ConnectCount::GetInstance()->CheckCount(networkId)) { + if (!ConnectCount::GetInstance().CheckCount(networkId)) { ret = DeviceManagerAgent::GetInstance()->OnDeviceP2POnline(deviceInfo); DevslDispatcher::GetDeviceDevsl(networkId); if (ret == NO_ERROR) { @@ -273,7 +273,7 @@ int32_t Daemon::CleanUp(const DistributedHardware::DmDeviceInfo &deviceInfo) { LOGI("CleanUp start"); auto networkId = std::string(deviceInfo.networkId); - if (!ConnectCount::GetInstance()->CheckCount(networkId)) { + if (!ConnectCount::GetInstance().CheckCount(networkId)) { auto ret = SendDfsDelayTask(networkId); LOGI("Close P2P Connection"); return ret; @@ -297,12 +297,12 @@ int32_t Daemon::ConnectionAndMount(const DistributedHardware::DmDeviceInfo &devi if (ret != NO_ERROR) { LOGE("connection failed"); if (ret == ERR_CHECKOUT_COUNT) { - ConnectCount::GetInstance()->RemoveConnect(callingTokenId, networkId); + ConnectCount::GetInstance().RemoveConnect(callingTokenId, networkId); } return ret; } - ConnectCount::GetInstance()->AddConnect(callingTokenId, networkId, remoteReverseObj); + ConnectCount::GetInstance().AddConnect(callingTokenId, networkId, remoteReverseObj); if (!hasFileAccessManager) { LOGW("permission denied: FILE_ACCESS_MANAGER_PERMISSION"); @@ -312,12 +312,12 @@ int32_t Daemon::ConnectionAndMount(const DistributedHardware::DmDeviceInfo &devi auto deviceManager = DeviceManagerAgent::GetInstance(); ret = deviceManager->MountDfsDocs(networkId, mountPath, callingTokenId); if (ret != NO_ERROR) { - ConnectCount::GetInstance()->RemoveConnect(callingTokenId, networkId); + ConnectCount::GetInstance().RemoveConnect(callingTokenId, networkId); LOGE("[MountDfsDocs] failed, ret is %{public}d", ret); return ret; } - ConnectCount::GetInstance()->NotifyFileStatusChange(networkId, Status::CONNECT_OK, HMDFS_FATH + mountPath, - StatusType::CONNECTION_STATUS); + ConnectCount::GetInstance().NotifyFileStatusChange(networkId, Status::CONNECT_OK, HMDFS_FATH + mountPath, + StatusType::CONNECTION_STATUS); NotifyRemotePublishNotification(networkId); return ret; } @@ -408,7 +408,7 @@ int32_t Daemon::CloseP2PConnectionEx(const std::string &networkId) LOGE("strcpy failed, res = %{public}d", res); return E_INVAL_ARG_NAPI; } - ConnectCount::GetInstance()->RemoveConnect(IPCSkeleton::GetCallingTokenID(), networkId); + ConnectCount::GetInstance().RemoveConnect(IPCSkeleton::GetCallingTokenID(), networkId); int32_t ret = CleanUp(deviceInfo); if (ret != NO_ERROR) { LOGE("Daemon::CloseP2PConnectionEx disconnection failed"); @@ -488,7 +488,7 @@ int32_t Daemon::InnerCopy(const std::string &srcUri, const std::string &dstUri, return ERR_BAD_VALUE; } OpenP2PConnection(deviceInfo); - auto ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy(srcUri, dstUri, + auto ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance().RemoteCopy(srcUri, dstUri, listener, QueryActiveUserId(), info.copyPath); CloseP2PConnection(deviceInfo); LOGI("InnerCopy end, ret = %{public}d", ret); @@ -802,7 +802,7 @@ int32_t Daemon::CancelCopyTask(const std::string &sessionName) int32_t Daemon::CancelCopyTask(const std::string &srcUri, const std::string &dstUri) { - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCancel(srcUri, dstUri); + Storage::DistributedFile::RemoteFileCopyManager::GetInstance().RemoteCancel(srcUri, dstUri); return E_OK; } @@ -821,12 +821,12 @@ void Daemon::DfsListenerDeathRecipient::OnRemoteDied(const wptr & } uint32_t callingTokenId; - auto ret = ConnectCount::GetInstance()->FindCallingTokenIdForListerner(diedRemote, callingTokenId); + auto ret = ConnectCount::GetInstance().FindCallingTokenIdForListerner(diedRemote, callingTokenId); if (ret != E_OK) { LOGE("fail to FindCallingTokenIdForListerner"); return; } - std::vector networkIds = ConnectCount::GetInstance()->RemoveConnect(callingTokenId); + std::vector networkIds = ConnectCount::GetInstance().RemoveConnect(callingTokenId); if (networkIds.empty()) { LOGE("fail to get networkIdSet"); return; @@ -843,7 +843,7 @@ void Daemon::DfsListenerDeathRecipient::OnRemoteDied(const wptr & LOGE("strcpy failed, res = %{public}d", res); return; } - if (!ConnectCount::GetInstance()->CheckCount(*it)) { + if (!ConnectCount::GetInstance().CheckCount(*it)) { DeviceManagerAgent::GetInstance()->OnDeviceP2POffline(deviceInfo); } } @@ -1048,7 +1048,7 @@ int32_t Daemon::UpdateDfsSwitchStatus(int32_t switchStatus) return E_INVAL_ARG_NAPI; } for (const auto &ele : mountInfo.second.callingCountMap_) { - ConnectCount::GetInstance()->RemoveConnect(ele.first, networkId); + ConnectCount::GetInstance().RemoveConnect(ele.first, networkId); } ret = CleanUp(deviceInfo); if (ret != NO_ERROR) { @@ -1078,7 +1078,7 @@ int32_t Daemon::RegisterFileDfsListener(const std::string &instanceId, const spt LOGE("listener is nullptr"); return E_INVAL_ARG_NAPI; } - ConnectCount::GetInstance()->AddFileConnect(instanceId, listener); + ConnectCount::GetInstance().AddFileConnect(instanceId, listener); return E_OK; } @@ -1089,7 +1089,7 @@ int32_t Daemon::UnregisterFileDfsListener(const std::string &instanceId) LOGE("InstanceId length is invalid."); return E_INVAL_ARG_NAPI; } - if (!ConnectCount::GetInstance()->RmFileConnect(instanceId)) { + if (!ConnectCount::GetInstance().RmFileConnect(instanceId)) { LOGE("RmFileConnect failed"); return E_INVAL_ARG_NAPI; } @@ -1141,7 +1141,7 @@ void Daemon::DisconnectByRemote(const string &networkId) LOGE("strcpy failed, res = %{public}d", res); return; } - ConnectCount::GetInstance()->RemoveConnect(IPCSkeleton::GetCallingTokenID(), networkId); + ConnectCount::GetInstance().RemoveConnect(IPCSkeleton::GetCallingTokenID(), networkId); int32_t ret = CleanUp(deviceInfo); if (ret != NO_ERROR) { LOGE("DisconnectByRemote disconnection failed."); diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 48467616614df99b036904c0a046e6c632545a10..85005e7c335598a4a8b8da825d1d1524f71d2147 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -111,7 +111,7 @@ void NetworkAgentTemplate::ConnectOnlineDevices() void NetworkAgentTemplate::DisconnectAllDevices() { sessionPool_.ReleaseAllSession(); - ConnectCount::GetInstance()->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); } // for closeP2P @@ -126,11 +126,11 @@ void NetworkAgentTemplate::DisconnectDeviceByP2PHmdfs(const DeviceInfo info) { LOGI("DeviceOffline, cid:%{public}s", Utils::GetAnonyString(info.GetCid()).c_str()); sessionPool_.ReleaseSession(info.GetCid(), true); - ConnectCount::GetInstance()->NotifyRemoteReverseObj(info.GetCid(), ON_STATUS_OFFLINE); - ConnectCount::GetInstance()->RemoveConnect(info.GetCid()); - ConnectCount::GetInstance()->NotifyFileStatusChange(info.GetCid(), Status::DEVICE_OFFLINE, - info.GetCid().substr(0, VALID_MOUNT_PATH_LEN), - StatusType::CONNECTION_STATUS); + ConnectCount::GetInstance().NotifyRemoteReverseObj(info.GetCid(), ON_STATUS_OFFLINE); + ConnectCount::GetInstance().RemoveConnect(info.GetCid()); + ConnectCount::GetInstance().NotifyFileStatusChange(info.GetCid(), Status::DEVICE_OFFLINE, + info.GetCid().substr(0, VALID_MOUNT_PATH_LEN), + StatusType::CONNECTION_STATUS); } // softbus offline, allConnect offline, hmdfs never has socket @@ -145,10 +145,10 @@ void NetworkAgentTemplate::CloseSessionForOneDevice(const string &cid) void NetworkAgentTemplate::CloseSessionForOneDeviceInner(std::string cid) { sessionPool_.ReleaseSession(cid, true); - ConnectCount::GetInstance()->NotifyRemoteReverseObj(cid, ON_STATUS_OFFLINE); - ConnectCount::GetInstance()->NotifyFileStatusChange( + ConnectCount::GetInstance().NotifyRemoteReverseObj(cid, ON_STATUS_OFFLINE); + ConnectCount::GetInstance().NotifyFileStatusChange( cid, Status::DEVICE_OFFLINE, cid.substr(0, VALID_MOUNT_PATH_LEN), StatusType::CONNECTION_STATUS); - ConnectCount::GetInstance()->RemoveConnect(cid); + ConnectCount::GetInstance().RemoveConnect(cid); } void NetworkAgentTemplate::AcceptSession(shared_ptr session, const std::string backStage) @@ -183,7 +183,7 @@ void NetworkAgentTemplate::GetSessionProcessInner(NotifyParam param) LOGI("NOTIFY_GET_SESSION, old fd %{public}d, remote cid %{public}s", fd, Utils::GetAnonyString(cidStr).c_str()); bool ifGetSession = sessionPool_.CheckIfGetSession(fd); sessionPool_.ReleaseSession(fd); - if (ifGetSession && ConnectCount::GetInstance()->CheckCount(cidStr)) { + if (ifGetSession && ConnectCount::GetInstance().CheckCount(cidStr)) { // for client GetSession(cidStr); } else { @@ -204,8 +204,8 @@ void NetworkAgentTemplate::GetSession(const string &cid) } LOGE("reget session failed"); sessionPool_.SinkOffline(cid); - ConnectCount::GetInstance()->NotifyRemoteReverseObj(cid, ON_STATUS_OFFLINE); - ConnectCount::GetInstance()->RemoveConnect(cid); + ConnectCount::GetInstance().NotifyRemoteReverseObj(cid, ON_STATUS_OFFLINE); + ConnectCount::GetInstance().RemoveConnect(cid); DeviceManagerAgent::GetInstance()->UMountDfsDocs(cid, cid.substr(0, VALID_MOUNT_PATH_LEN), true); } catch (const DfsuException &e) { LOGE("reget session failed, code: %{public}d", e.code()); diff --git a/services/distributedfiledaemon/src/network/session_pool.cpp b/services/distributedfiledaemon/src/network/session_pool.cpp index 76e6e715fed48232303032cc2e621709f7261227..4e8d15b847a80d1393c735d2f6432599f799fb4a 100644 --- a/services/distributedfiledaemon/src/network/session_pool.cpp +++ b/services/distributedfiledaemon/src/network/session_pool.cpp @@ -111,6 +111,7 @@ void SessionPool::ReleaseSession(const std::string &cid, bool isReleaseAll) bool SessionPool::FindCid(const std::string &cid) { + lock_guard lock(sessionPoolLock_); for (auto iter = usrSpaceSessionPool_.begin(); iter != usrSpaceSessionPool_.end(); ++iter) { if ((*iter)->GetCid() == cid) { return true; diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_session_listener.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_session_listener.cpp index 6cbca9a8ddc467a1924807a56c570ab65d098ee7..7cd470cbb0b96bd92f27cc396de0836d008c8711 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_session_listener.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_session_listener.cpp @@ -62,12 +62,22 @@ std::vector SoftBusSessionListener::GetFileName(const std::vector std::string { + size_t pos = filePath.rfind('/'); + if (pos == std::string::npos) { + return filePath; + } + if (pos + 1 >= filePath.size()) { + return ""; + } + return filePath.substr(pos + 1); + }; + if (dstPath.find("??") == 0) { - auto pos = dstPath.rfind("/"); - tmp.push_back(dstPath.substr(pos + 1)); + tmp.push_back(extractFileName(dstPath)); } else { - auto pos = path.rfind("/"); - tmp.push_back(path.substr(pos + 1)); + tmp.push_back(extractFileName(path)); } return tmp; } diff --git a/services/distributedfiledaemon/test/unittest/BUILD.gn b/services/distributedfiledaemon/test/unittest/BUILD.gn index f6c8f2bf365f945ea908ae59471ddd8bb93385fe..b834fc4ebf14f74a38aa35160e91dd034c7f1e83 100644 --- a/services/distributedfiledaemon/test/unittest/BUILD.gn +++ b/services/distributedfiledaemon/test/unittest/BUILD.gn @@ -1367,6 +1367,7 @@ group("unittest") { ":devsl_dispatcher_test", ":kernel_talker_test", ":os_account_observer_test", + ":session_pool_test", ":softbus_agent_sup_test", ":softbus_agent_test", ":softbus_asset_recv_listener_test", diff --git a/services/distributedfiledaemon/test/unittest/connect_count/BUILD.gn b/services/distributedfiledaemon/test/unittest/connect_count/BUILD.gn index 93786e1455256874de2571b1ef3dcf5d2bf355bb..a9640e6e7150600a6fad0e3a7df566ce84c6a658 100644 --- a/services/distributedfiledaemon/test/unittest/connect_count/BUILD.gn +++ b/services/distributedfiledaemon/test/unittest/connect_count/BUILD.gn @@ -63,6 +63,7 @@ ohos_unittest("connect_count_test") { "hilog:libhilog", "ipc:ipc_core", "json:nlohmann_json_static", + "safwk:system_ability_fwk", ] defines = [ diff --git a/services/distributedfiledaemon/test/unittest/connect_count/connect_count_test.cpp b/services/distributedfiledaemon/test/unittest/connect_count/connect_count_test.cpp index abc6735084ccb43b2a0793ea474e7b9019f323bf..ba5dffbcb3d72306d6fba6f80fcecb588ae64265 100644 --- a/services/distributedfiledaemon/test/unittest/connect_count/connect_count_test.cpp +++ b/services/distributedfiledaemon/test/unittest/connect_count/connect_count_test.cpp @@ -44,7 +44,6 @@ public: void TearDown(); public: - static inline std::shared_ptr connectCount_ = nullptr; static inline uint32_t testCallingTokenId = 1234; static inline std::string testNetworkId = "testNetworkId"; static inline sptr testListener = nullptr; @@ -55,15 +54,12 @@ public: void ConnectCountTest::SetUpTestCase(void) { GTEST_LOG_(INFO) << "ConnectCountTest SetUpTestCase"; - connectCount_ = ConnectCount::GetInstance(); testListener = new MockFileDfsListener(); // Use Mock class } void ConnectCountTest::TearDownTestCase(void) { GTEST_LOG_(INFO) << "ConnectCountTest TearDownTestCase"; - - connectCount_ = nullptr; testListener = nullptr; } @@ -75,7 +71,7 @@ void ConnectCountTest::SetUp(void) void ConnectCountTest::TearDown(void) { GTEST_LOG_(INFO) << "TearDown"; - connectCount_->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); } /** @@ -87,9 +83,9 @@ void ConnectCountTest::TearDown(void) HWTEST_F(ConnectCountTest, GetInstance_001, TestSize.Level1) { GTEST_LOG_(INFO) << "GetInstance_001 start"; - auto instance1 = ConnectCount::GetInstance(); - auto instance2 = ConnectCount::GetInstance(); - EXPECT_EQ(instance1, instance2); // Verify singleton instance + auto &instance1 = ConnectCount::GetInstance(); + auto &instance2 = ConnectCount::GetInstance(); + EXPECT_EQ(&instance1, &instance2); // Verify singleton instance GTEST_LOG_(INFO) << "GetInstance_001 end"; } @@ -102,8 +98,8 @@ HWTEST_F(ConnectCountTest, GetInstance_001, TestSize.Level1) HWTEST_F(ConnectCountTest, AddConnect_001, TestSize.Level1) { GTEST_LOG_(INFO) << "AddConnect_001 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - EXPECT_TRUE(connectCount_->CheckCount(testNetworkId)); // Verify connection is added + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + EXPECT_TRUE(ConnectCount::GetInstance().CheckCount(testNetworkId)); // Verify connection is added GTEST_LOG_(INFO) << "AddConnect_001 end"; } @@ -116,9 +112,9 @@ HWTEST_F(ConnectCountTest, AddConnect_001, TestSize.Level1) HWTEST_F(ConnectCountTest, AddConnect_002, TestSize.Level1) { GTEST_LOG_(INFO) << "AddConnect_002 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - auto networkIds = connectCount_->GetNetworkIds(testCallingTokenId); + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + auto networkIds = ConnectCount::GetInstance().GetNetworkIds(testCallingTokenId); EXPECT_EQ(networkIds.size(), 1); // Verify only one networkId is added GTEST_LOG_(INFO) << "AddConnect_002 end"; } @@ -132,10 +128,10 @@ HWTEST_F(ConnectCountTest, AddConnect_002, TestSize.Level1) HWTEST_F(ConnectCountTest, RemoveConnect_001, TestSize.Level1) { GTEST_LOG_(INFO) << "RemoveConnect_001 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - auto networkIds = connectCount_->RemoveConnect(testCallingTokenId); + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + auto networkIds = ConnectCount::GetInstance().RemoveConnect(testCallingTokenId); EXPECT_EQ(networkIds.size(), 1); // Verify networkId is returned - EXPECT_FALSE(connectCount_->CheckCount(testNetworkId)); // Verify connection is removed + EXPECT_FALSE(ConnectCount::GetInstance().CheckCount(testNetworkId)); // Verify connection is removed GTEST_LOG_(INFO) << "RemoveConnect_001 end"; } @@ -148,9 +144,9 @@ HWTEST_F(ConnectCountTest, RemoveConnect_001, TestSize.Level1) HWTEST_F(ConnectCountTest, RemoveConnect_002, TestSize.Level1) { GTEST_LOG_(INFO) << "RemoveConnect_002 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - connectCount_->RemoveConnect(testNetworkId); - EXPECT_FALSE(connectCount_->CheckCount(testNetworkId)); // Verify connection is removed + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().RemoveConnect(testNetworkId); + EXPECT_FALSE(ConnectCount::GetInstance().CheckCount(testNetworkId)); // Verify connection is removed GTEST_LOG_(INFO) << "RemoveConnect_002 end"; } @@ -163,9 +159,9 @@ HWTEST_F(ConnectCountTest, RemoveConnect_002, TestSize.Level1) HWTEST_F(ConnectCountTest, RemoveConnect_003, TestSize.Level1) { GTEST_LOG_(INFO) << "RemoveConnect_003 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - connectCount_->RemoveConnect(testCallingTokenId, testNetworkId); - EXPECT_FALSE(connectCount_->CheckCount(testNetworkId)); // Verify connection is removed + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().RemoveConnect(testCallingTokenId, testNetworkId); + EXPECT_FALSE(ConnectCount::GetInstance().CheckCount(testNetworkId)); // Verify connection is removed GTEST_LOG_(INFO) << "RemoveConnect_003 end"; } @@ -178,9 +174,9 @@ HWTEST_F(ConnectCountTest, RemoveConnect_003, TestSize.Level1) HWTEST_F(ConnectCountTest, RemoveAllConnect_001, TestSize.Level1) { GTEST_LOG_(INFO) << "RemoveAllConnect_001 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - connectCount_->RemoveAllConnect(); - EXPECT_FALSE(connectCount_->CheckCount(testNetworkId)); // Verify all connections are removed + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().RemoveAllConnect(); + EXPECT_FALSE(ConnectCount::GetInstance().CheckCount(testNetworkId)); // Verify all connections are removed GTEST_LOG_(INFO) << "RemoveAllConnect_001 end"; } @@ -199,8 +195,8 @@ HWTEST_F(ConnectCountTest, NotifyRemoteReverseObj_001, TestSize.Level1) OnStatus(testNetworkId, ON_STATUS_OFFLINE, "", 0)) .Times(1); // 仅在当前测试用例中生效 - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); - connectCount_->NotifyRemoteReverseObj(testNetworkId, ON_STATUS_OFFLINE); + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().NotifyRemoteReverseObj(testNetworkId, ON_STATUS_OFFLINE); // 清除 EXPECT_CALL 断言 testing::Mock::VerifyAndClearExpectations(testListener.GetRefPtr()); @@ -217,9 +213,10 @@ HWTEST_F(ConnectCountTest, NotifyRemoteReverseObj_001, TestSize.Level1) HWTEST_F(ConnectCountTest, FindCallingTokenIdForListerner_001, TestSize.Level1) { GTEST_LOG_(INFO) << "FindCallingTokenIdForListerner_001 start"; - connectCount_->AddConnect(testCallingTokenId, testNetworkId, testListener); + ConnectCount::GetInstance().AddConnect(testCallingTokenId, testNetworkId, testListener); uint32_t foundCallingTokenId = 0; - int32_t ret = connectCount_->FindCallingTokenIdForListerner(testListener->AsObject(), foundCallingTokenId); + int32_t ret = + ConnectCount::GetInstance().FindCallingTokenIdForListerner(testListener->AsObject(), foundCallingTokenId); EXPECT_EQ(ret, FileManagement::E_OK); // Verify success EXPECT_EQ(foundCallingTokenId, testCallingTokenId); // Verify correct tokenId is found GTEST_LOG_(INFO) << "FindCallingTokenIdForListerner_001 end"; @@ -236,7 +233,7 @@ HWTEST_F(ConnectCountTest, FindCallingTokenIdForListerner_002, TestSize.Level1) GTEST_LOG_(INFO) << "FindCallingTokenIdForListerner_002 start"; sptr invalidListener = nullptr; uint32_t foundCallingTokenId = 0; - int32_t ret = connectCount_->FindCallingTokenIdForListerner(invalidListener, foundCallingTokenId); + int32_t ret = ConnectCount::GetInstance().FindCallingTokenIdForListerner(invalidListener, foundCallingTokenId); EXPECT_EQ(ret, FileManagement::ERR_BAD_VALUE); // Verify error is returned GTEST_LOG_(INFO) << "FindCallingTokenIdForListerner_002 end"; } diff --git a/services/distributedfiledaemon/test/unittest/ipc/daemon/daemon_test.cpp b/services/distributedfiledaemon/test/unittest/ipc/daemon/daemon_test.cpp index 994430d3ca804bc00c7a822c34e95030fb06331c..8c6dac35be18cd4b3da494db06eb0399beb7b5c7 100644 --- a/services/distributedfiledaemon/test/unittest/ipc/daemon/daemon_test.cpp +++ b/services/distributedfiledaemon/test/unittest/ipc/daemon/daemon_test.cpp @@ -48,6 +48,7 @@ #include "softbus_session_pool.h" #include "system_ability_definition.h" #include "system_ability_manager_client_mock.h" +#include "securec.h" namespace { bool g_isLocalItDevice = false; @@ -561,7 +562,7 @@ HWTEST_F(DaemonTest, DaemonTest_OpenP2PConnection_001, TestSize.Level1) GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnection_001 begin"; ASSERT_NE(daemon_, nullptr); DistributedHardware::DmDeviceInfo deviceInfo; - ConnectCount::GetInstance()->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE)); EXPECT_EQ(daemon_->OpenP2PConnection(deviceInfo), ERR_BAD_VALUE); @@ -582,7 +583,7 @@ HWTEST_F(DaemonTest, DaemonTest_ConnectionCount_001, TestSize.Level1) GTEST_LOG_(INFO) << "DaemonTest_ConnectionCount_001 begin"; ASSERT_NE(daemon_, nullptr); DistributedHardware::DmDeviceInfo deviceInfo; - ConnectCount::GetInstance()->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE)); EXPECT_EQ(daemon_->ConnectionCount(deviceInfo), ERR_BAD_VALUE); @@ -603,7 +604,10 @@ HWTEST_F(DaemonTest, DaemonTest_CleanUp_001, TestSize.Level1) GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 begin"; ASSERT_NE(daemon_, nullptr); DistributedHardware::DmDeviceInfo deviceInfo; - ConnectCount::GetInstance()->RemoveAllConnect(); + string networkId = "testNetworkId"; + strcpy_s(deviceInfo.networkId, 96, networkId.c_str()); + + ConnectCount::GetInstance().RemoveAllConnect(); EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((E_OK))); EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_NULLPTR); sleep(1); @@ -611,6 +615,11 @@ HWTEST_F(DaemonTest, DaemonTest_CleanUp_001, TestSize.Level1) EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((ERR_BAD_VALUE))); EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_NULLPTR); sleep(1); + + sptr nullListener = nullptr; + ConnectCount::GetInstance().AddConnect(333, networkId, nullListener); + EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_OK); + sleep(1); GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 end"; } @@ -625,7 +634,7 @@ HWTEST_F(DaemonTest, DaemonTest_ConnectionAndMount_001, TestSize.Level1) GTEST_LOG_(INFO) << "DaemonTest_ConnectionAndMount_001 begin"; DistributedHardware::DmDeviceInfo deviceInfo = {.networkId = "test"}; sptr remoteReverseObj = nullptr; - ConnectCount::GetInstance()->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); // g_checkCallerPermission is ok but remote reject g_checkCallerPermission = true; @@ -1692,7 +1701,7 @@ HWTEST_F(DaemonTest, DaemonTest_RegisterFileDfsListener_001, TestSize.Level1) EXPECT_EQ(result, E_OK); // Verify listener was added - EXPECT_TRUE(ConnectCount::GetInstance()->RmFileConnect(instanceId)); + EXPECT_TRUE(ConnectCount::GetInstance().RmFileConnect(instanceId)); GTEST_LOG_(INFO) << "DaemonTest_RegisterFileDfsListener_001 end"; } diff --git a/services/distributedfiledaemon/test/unittest/network/network_agent_template_test.cpp b/services/distributedfiledaemon/test/unittest/network/network_agent_template_test.cpp index 09ebf9857d41672ae1538f8a1654715006bb850a..d8a862da8a62739a893549181957cbc28ddf13db 100644 --- a/services/distributedfiledaemon/test/unittest/network/network_agent_template_test.cpp +++ b/services/distributedfiledaemon/test/unittest/network/network_agent_template_test.cpp @@ -325,6 +325,28 @@ HWTEST_F(NetworkAgentTemplateTest, NetworkAgentTemplateTest_GetSessionProcessInn GTEST_LOG_(INFO) << "NetworkAgentTemplateTest_GetSessionProcessInner_0100 end"; } +/** + * @tc.name: NetworkAgentTemplateTest_GetSessionProcessInner_0200 + * @tc.desc: Verify the GetSessionProcessInner function. + * @tc.type: FUNC + * @tc.require: SR000H0387 + */ +HWTEST_F(NetworkAgentTemplateTest, NetworkAgentTemplateTest_GetSessionProcessInner_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NetworkAgentTemplateTest_GetSessionProcessInner_0200 start"; + int fd = 99; + NotifyParam param; + param.fd = fd; + std::shared_ptr session = std::make_shared(fd, "aaa"); + session.socketFd_ = fd; + session.IsServerSide_ = false; + NetworkAgentTemplate.sessionPool_.usrSpaceSessionPool_.push_back(session); + + EXPECT_NO_THROW(NetworkAgentTemplate::GetSessionProcessInner(param)); + NetworkAgentTemplate.sessionPool_.usrSpaceSessionPool_.clear(); + GTEST_LOG_(INFO) << "NetworkAgentTemplateTest_GetSessionProcessInner_0200 end"; +} + /** * @tc.name: NetworkAgentTemplateTest_GetSession_0100 * @tc.desc: Verify the GetSession function. diff --git a/services/distributedfiledaemon/test/unittest/network/session_pool_test.cpp b/services/distributedfiledaemon/test/unittest/network/session_pool_test.cpp index f5ece8cc16b89633064081173d07217cba74204b..88145f02fd37872043ad92206449f128903e0db3 100644 --- a/services/distributedfiledaemon/test/unittest/network/session_pool_test.cpp +++ b/services/distributedfiledaemon/test/unittest/network/session_pool_test.cpp @@ -319,11 +319,12 @@ HWTEST_F(SessionPoolTest, SessionPoolTest_CheckIfGetSession_0100, TestSize.Level auto kernelTalker = std::make_shared(wmp, [](NotifyParam ¶m) {}, [](const std::string &) {}); shared_ptr pool = make_shared(kernelTalker); int32_t fd = -1; // -1: fd - bool ret = pool->CheckIfGetSession(fd); + bool isServer = false; + bool ret = pool->CheckIfGetSession(fd, isServer); EXPECT_EQ(ret, false); pool->usrSpaceSessionPool_.push_back(session); - ret = pool->CheckIfGetSession(fd); + ret = pool->CheckIfGetSession(fd, isServer); EXPECT_EQ(ret, true); GTEST_LOG_(INFO) << "SessionPoolTest_CheckIfGetSession_0100 end"; } diff --git a/services/distributedfiledaemon/test/unittest/network/softbus/softbus_agent_sup_test.cpp b/services/distributedfiledaemon/test/unittest/network/softbus/softbus_agent_sup_test.cpp index 8874f85c8d238f9e4ad41e25f38ab88e7393e051..a6bd44795de98ea31580bb88ab45ea455c2a5b35 100644 --- a/services/distributedfiledaemon/test/unittest/network/softbus/softbus_agent_sup_test.cpp +++ b/services/distributedfiledaemon/test/unittest/network/softbus/softbus_agent_sup_test.cpp @@ -199,13 +199,13 @@ HWTEST_F(SoftbusAgentSupTest, SoftbusAgentSupTest_GetSessionProcessInner_0100, T auto session = make_shared(1, "testNetworkId"); session->SetFromServer(false); agent->sessionPool_.AddSessionToPool(session); - ConnectCount::GetInstance()->RemoveAllConnect(); + ConnectCount::GetInstance().RemoveAllConnect(); agent->GetSessionProcessInner(param); EXPECT_FALSE(agent->sessionPool_.FindCid("testNetworkId")); sptr listener = nullptr; agent->sessionPool_.AddSessionToPool(session); - ConnectCount::GetInstance()->AddConnect(1, "testNetworkId", listener); + ConnectCount::GetInstance().AddConnect(1, "testNetworkId", listener); agent->GetSessionProcessInner(param); EXPECT_FALSE(agent->sessionPool_.FindCid("testNetworkId")); diff --git a/services/distributedfiledaemon/test/unittest/network/softbus/softbus_session_listener_test.cpp b/services/distributedfiledaemon/test/unittest/network/softbus/softbus_session_listener_test.cpp index 1188b323ffb6010d84f419a62801d0229b1ce7bc..fdc79accc1db4272d33a18e038043c7e54b313a2 100644 --- a/services/distributedfiledaemon/test/unittest/network/softbus/softbus_session_listener_test.cpp +++ b/services/distributedfiledaemon/test/unittest/network/softbus/softbus_session_listener_test.cpp @@ -222,31 +222,113 @@ HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetRealPath_0100 /** * @tc.name: SoftBusSessionListenerTest_GetFileName_0100 - * @tc.desc: test GetFileName function. + * @tc.desc: Test GetFileName function with folder path. * @tc.type: FUNC * @tc.require: I9JKYU */ HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetFileName_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0100 start"; - vector fileList; - fileList.push_back("/data/test/test1/t1.txt"); - fileList.push_back("/data/test/test1/t2.txt"); - vector rltList; - rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test", "/data/test"); - EXPECT_EQ(rltList.size(), 2); + vector fileList = {"/data/test/test1/t1.txt", "/data/test/test1/t2.txt", "/data/test/test2/t3.txt"}; + vector rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test", "/data/test"); + EXPECT_EQ(rltList.size(), 3); EXPECT_EQ(rltList[0], "test1/t1.txt"); EXPECT_EQ(rltList[1], "test1/t2.txt"); - rltList.clear(); - rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test/test1/t1.txt", "/data/test"); + EXPECT_EQ(rltList[2], "test2/t3.txt"); + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0100 end"; +} + +/** + * @tc.name: SoftBusSessionListenerTest_GetFileName_0200 + * @tc.desc: Test GetFileName function with file path and normal dstPath. + * @tc.type: FUNC + * @tc.require: I9JKYU + */ +HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetFileName_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0200 start"; + vector fileList = {"/data/test/test1/t1.txt"}; + vector rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test/test1/t1.txt", "/data/test"); EXPECT_EQ(rltList.size(), 1); EXPECT_EQ(rltList[0], "t1.txt"); + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0200 end"; +} - rltList.clear(); - rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test/test1/t1.txt", "??data/test/test1/t2.txt"); +/** + * @tc.name: SoftBusSessionListenerTest_GetFileName_0300 + * @tc.desc: Test GetFileName function with dstPath starting with "??". + * @tc.type: FUNC + * @tc.require: I9JKYU + */ +HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetFileName_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0300 start"; + vector fileList = {"/data/test/test1/t1.txt"}; + vector rltList = SoftBusSessionListener::GetFileName(fileList, "/data/test/test1/t1.txt", + "\\?\\?data/test/test1/t2.txt"); EXPECT_EQ(rltList.size(), 1); EXPECT_EQ(rltList[0], "t2.txt"); - GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0100 end"; + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0300 end"; +} + +/** + * @tc.name: SoftBusSessionListenerTest_GetFileName_0400 + * @tc.desc: Test GetFileName function with edge cases. + * @tc.type: FUNC + * @tc.require: I9JKYU + */ +HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetFileName_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0400 start"; + + // Test path without slashes + vector fileList1 = {"testfile.txt"}; + vector rltList = SoftBusSessionListener::GetFileName(fileList1, "testfile.txt", "destination"); + EXPECT_EQ(rltList.size(), 1); + EXPECT_EQ(rltList[0], "testfile.txt"); + + // Test dstPath starting with "??" and no slashes + rltList = SoftBusSessionListener::GetFileName(fileList1, "testfile.txt", "??destinationfile"); + EXPECT_EQ(rltList.size(), 1); + EXPECT_EQ(rltList[0], "destinationfile"); + + // Test empty file list + vector emptyFileList; + rltList = SoftBusSessionListener::GetFileName(emptyFileList, "/data/test", "/data/test"); + EXPECT_EQ(rltList.size(), 0); + + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0400 end"; +} + +/** + * @tc.name: SoftBusSessionListenerTest_GetFileName_0500 + * @tc.desc: Test GetFileName function with slash edge cases. + * @tc.type: FUNC + * @tc.require: I9JKYU + */ +HWTEST_F(SoftBusSessionListenerTest, SoftBusSessionListenerTest_GetFileName_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0500 start"; + + // Test folder path ending with slash + vector fileList1 = {"/data/test/test1/t1.txt"}; + vector rltList = SoftBusSessionListener::GetFileName(fileList1, "/data/test/", "/data/test/"); + EXPECT_EQ(rltList.size(), 1); + EXPECT_EQ(rltList[0], "test1/t1.txt"); + + // Test dstPath ending with slash (returns empty string) + vector fileList2 = {"/data/test/file.txt"}; + rltList = SoftBusSessionListener::GetFileName(fileList2, "/data/test/file.txt", "??/data/test/newfile.txt/"); + EXPECT_EQ(rltList.size(), 1); + EXPECT_EQ(rltList[0], ""); + + // Test root path + vector fileList3 = {"/"}; + rltList = SoftBusSessionListener::GetFileName(fileList3, "/", "/"); + EXPECT_EQ(rltList.size(), 1); + EXPECT_EQ(rltList[0], ""); + + GTEST_LOG_(INFO) << "SoftBusSessionListenerTest_GetFileName_0500 end"; } /** diff --git a/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp b/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp index 5958f77b11d357d12a9bbfde437880fb7f75b672..f22271b60730a2ddcdf86f57da16c394a645a5fc 100644 --- a/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp +++ b/test/unittests/distributed_file_inner/copy/file_copy_manager_test.cpp @@ -80,23 +80,23 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0001, TestSize.Level0) string localUri = "/data/test/test.txt"; string dstUri = "/data/test/test.txt"; - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy("", localUri, listener_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy("", localUri, listener_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, "", listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(localUri, "", listener_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy("", "", listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy("", "", listener_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, dstUri, listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(localUri, dstUri, listener_); EXPECT_EQ(ret, EINVAL); string remoteUri = "/data/test/Copy/?networkid=/"; if (!ForceCreateDirectory(remoteUri)) { GTEST_LOG_(INFO) << "FileCopyManager_Copy_0001 create dir err"; } - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(remoteUri, "", listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(remoteUri, "", listener_); EXPECT_EQ(ret, EINVAL); if (!ForceRemoveDirectory(remoteUri)) { GTEST_LOG_(INFO) << "FileCopyManager_Copy_0001 remove dir err"; @@ -121,7 +121,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0002, TestSize.Level0) ASSERT_TRUE(fd != -1) <<"Failed to open file in FileCopyManager_Copy_0002!" << errno; close(fd); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, listener_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, listener_); EXPECT_EQ(ret, E_OK); ASSERT_EQ(remove(srcPath.c_str()), 0); ASSERT_EQ(remove(dstPath.c_str()), 0); @@ -145,7 +145,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0003, TestSize.Level0) ASSERT_TRUE(fd != -1) <<"Failed to open file in FileCopyManager_Copy_0003!" << errno; close(fd); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, listener_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, listener_); EXPECT_EQ(ret, EINVAL); ASSERT_EQ(remove(srcPath.c_str()), 0); GTEST_LOG_(INFO) << "FileCopyManager_Copy_0003 End"; @@ -168,7 +168,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0004, TestSize.Level0) ASSERT_TRUE(fd != -1) <<"Failed to open file in FileCopyManager_Copy_0004!" << errno; close(fd); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, listener_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, listener_); EXPECT_EQ(ret, E_OK); ASSERT_EQ(remove(srcPath.c_str()), 0); ASSERT_EQ(remove(destPath.c_str()), 0); @@ -187,16 +187,16 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0005, TestSize.Level0) string localUri = "/data/test/test.txt"; string dstUri = "/data/test/test.txt"; - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy("", localUri, emptyCallback_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy("", localUri, emptyCallback_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, "", listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(localUri, "", listener_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, dstUri, listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(localUri, dstUri, listener_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(localUri, dstUri, emptyCallback_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(localUri, dstUri, emptyCallback_); EXPECT_EQ(ret, EINVAL); GTEST_LOG_(INFO) << "FileCopyManager_Copy_0005 End"; @@ -216,10 +216,10 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0006, TestSize.Level0) string srcPath = "/storage/media/100/local/files/Docs/1.txt"; EXPECT_TRUE(OHOS::RemoveFile(srcPath)); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, emptyCallback_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, emptyCallback_); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, listener_); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, listener_); EXPECT_EQ(ret, ENOENT); GTEST_LOG_(INFO) << "FileCopyManager_Copy_0006 End"; @@ -239,7 +239,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Copy_0007, TestSize.Level0) string srcPath = "/storage/External/mtp/1.txt"; EXPECT_TRUE(OHOS::RemoveFile(srcPath)); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Copy(srcUri, destUri, emptyCallback_); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Copy(srcUri, destUri, emptyCallback_); EXPECT_EQ(ret, EINVAL); GTEST_LOG_(INFO) << "FileCopyManager_Copy_0007 End"; @@ -259,14 +259,14 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0001, TestSize.Level0) string srcpath = "/storage/media/100/local/files/Docs/11.txt"; string destpath = "/storage/media/100/local/files/Docs/dest11.txt"; // infos is nullptr - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(nullptr); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(nullptr); EXPECT_EQ(ret, EINVAL); auto infos = std::make_shared(); infos->srcUri = srcuri; infos->destUri = desturi; // infos localListener is nullptr - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, EINVAL); infos->srcUriIsFile = true; @@ -275,18 +275,18 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0001, TestSize.Level0) infos->localListener = FileCopyLocalListener::GetLocalListener(infos->srcPath, infos->srcUriIsFile, listener_); // srcPath and destPath is same - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, EINVAL); infos->destPath = destpath; // src file not exist - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, ENOENT); int fd = open(srcpath.c_str(), O_RDWR | O_CREAT); ASSERT_TRUE(fd != -1) <<"Failed to open file in FileCopyManager_ExecLocal_0001" << errno; close(fd); - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, E_OK); EXPECT_TRUE(std::filesystem::exists("/storage/media/100/local/files/Docs/dest11.txt")); ASSERT_EQ(remove(srcpath.c_str()), 0); @@ -295,7 +295,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0001, TestSize.Level0) infos->localListener = FileCopyLocalListener::GetLocalListener(infos->srcPath, infos->srcUriIsFile, emptyCallback_); // src file not exist, callback is nullptr - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, ENOENT); ASSERT_EQ(remove(destpath.c_str()), 0); GTEST_LOG_(INFO) << "FileCopyManager_ExecLocal_0001 End"; @@ -317,7 +317,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0002, TestSize.Level0) string destpath = "/storage/media/100/local/files/Docs/dstaa11/"; std::error_code errCode; if (!std::filesystem::exists(srcpath, errCode) && errCode.value() == E_OK) { - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(srcpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(srcpath); if (res != E_OK) { GTEST_LOG_(INFO) <<"Failed to mkdir"; } @@ -333,16 +333,16 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0002, TestSize.Level0) ProcessCallback processCallback = [](uint64_t processSize, uint64_t totalSize) -> void {}; infos->localListener = FileCopyLocalListener::GetLocalListener(infos->srcPath, infos->srcUriIsFile, processCallback); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); // destpath not exist EXPECT_EQ(ret, ENOENT); if (!std::filesystem::exists(destpath, errCode) && errCode.value() == E_OK) { - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(destpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(destpath); EXPECT_EQ(res, E_OK); } // dir copy to dir - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, 0); ASSERT_EQ(remove(srcpath.c_str()), 0); @@ -365,7 +365,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0003, TestSize.Level0) string destpath = "/storage/media/100/local/files/Docs/dstaa12/"; std::error_code errCode; if (!std::filesystem::exists(srcpath, errCode) && errCode.value() == E_OK) { - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(srcpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(srcpath); if (res != E_OK) { GTEST_LOG_(INFO) <<"Failed to mkdir"; } @@ -383,7 +383,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0003, TestSize.Level0) infos->localListener = FileCopyLocalListener::GetLocalListener(infos->srcPath, infos->srcUriIsFile, processCallback); // srcUriIsFile is true, destpath not exist - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_NE(ret, E_OK); ASSERT_EQ(ForceRemoveDirectory(srcpath), true); if (!ForceRemoveDirectory(destpath)) { @@ -417,10 +417,10 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0004, TestSize.Level0) infos->srcUriIsFile, processCallback); if (!std::filesystem::exists(destpath, errCode) && errCode.value() == E_OK) { - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(destpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(destpath); EXPECT_EQ(res, E_OK); } - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); // src path not exist EXPECT_EQ(ret, E_OK); ASSERT_EQ(ForceRemoveDirectory(destpath.c_str()), true); @@ -446,7 +446,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0005, TestSize.Level0) std::error_code errCode; if (!std::filesystem::exists(destpath, errCode) && errCode.value() == E_OK) { - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(destpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(destpath); ASSERT_EQ(res, E_OK); } @@ -459,7 +459,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0005, TestSize.Level0) infos->destPath = destpath; infos->srcUriIsFile = true; // file to dir - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, EINVAL); ASSERT_EQ(remove(srcpath.c_str()), 0); EXPECT_TRUE(ForceRemoveDirectory(destpath)); @@ -488,7 +488,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_ExecLocal_0006, TestSize.Level0) infos->srcUriIsFile, listener_); // destpath is invalid - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->ExecLocal(infos); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().ExecLocal(infos); EXPECT_EQ(ret, ENOENT); GTEST_LOG_(INFO) << "FileCopyManager_ExecLocal_0006 End"; } @@ -512,7 +512,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_DeleteResFile_0001, TestSize.Level EXPECT_TRUE(std::filesystem::exists(infos->destPath)); // 调用 DeleteResFile - Storage::DistributedFile::FileCopyManager::GetInstance()->DeleteResFile(infos); + Storage::DistributedFile::FileCopyManager::GetInstance().DeleteResFile(infos); // 验证文件是否被删除 EXPECT_FALSE(std::filesystem::exists(infos->destPath)); @@ -537,7 +537,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_DeleteResFile_0002, TestSize.Level EXPECT_FALSE(std::filesystem::exists(infos->destPath)); // 调用 DeleteResFile - Storage::DistributedFile::FileCopyManager::GetInstance()->DeleteResFile(infos); + Storage::DistributedFile::FileCopyManager::GetInstance().DeleteResFile(infos); // 验证文件仍然不存在 EXPECT_FALSE(std::filesystem::exists(infos->destPath)); @@ -574,7 +574,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_DeleteResFile_0003, TestSize.Level }; // 调用 DeleteResFile - Storage::DistributedFile::FileCopyManager::GetInstance()->DeleteResFile(infos); + Storage::DistributedFile::FileCopyManager::GetInstance().DeleteResFile(infos); // 验证文件和目录是否被删除 EXPECT_FALSE(std::filesystem::exists("/data/test/file1.txt")); @@ -583,7 +583,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_DeleteResFile_0003, TestSize.Level // 调用 DeleteResFile infos->localListener = nullptr; - Storage::DistributedFile::FileCopyManager::GetInstance()->DeleteResFile(infos); + Storage::DistributedFile::FileCopyManager::GetInstance().DeleteResFile(infos); GTEST_LOG_(INFO) << "FileCopyManager_DeleteResFile_0003 End"; } @@ -609,7 +609,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_DeleteResFile_0004, TestSize.Level }; // 调用 DeleteResFile - Storage::DistributedFile::FileCopyManager::GetInstance()->DeleteResFile(infos); + Storage::DistributedFile::FileCopyManager::GetInstance().DeleteResFile(infos); // 验证文件和目录仍然不存在 EXPECT_FALSE(std::filesystem::exists("/data/test/nonexistent_file.txt")); @@ -637,7 +637,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_OpenSrcFile_0001, TestSize.Level0) int32_t srcFd = -1; // Call the OpenSrcFile function - int ret = Storage::DistributedFile::FileCopyManager::GetInstance()->OpenSrcFile(infos->srcPath, infos, srcFd); + int ret = Storage::DistributedFile::FileCopyManager::GetInstance().OpenSrcFile(infos->srcPath, infos, srcFd); // Validate the file descriptor is opened successfully EXPECT_EQ(ret, 1); @@ -667,7 +667,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_OpenSrcFile_0002, TestSize.Level0) std::ofstream(infos->srcPath).close(); // Call the OpenSrcFile function - int ret = Storage::DistributedFile::FileCopyManager::GetInstance()->OpenSrcFile(infos->srcPath, infos, srcFd); + int ret = Storage::DistributedFile::FileCopyManager::GetInstance().OpenSrcFile(infos->srcPath, infos, srcFd); // Validate the file descriptor is opened successfully EXPECT_EQ(ret, 1); @@ -696,7 +696,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_OpenSrcFile_0003, TestSize.Level0) // Call the OpenSrcFile function int32_t srcFd = -1; - int ret = Storage::DistributedFile::FileCopyManager::GetInstance()->OpenSrcFile(infos->srcPath, infos, srcFd); + int ret = Storage::DistributedFile::FileCopyManager::GetInstance().OpenSrcFile(infos->srcPath, infos, srcFd); // Validate that the function fails when file does not exist EXPECT_NE(ret, 0); // Expect error code @@ -727,7 +727,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_OpenSrcFile_0004, TestSize.Level0) // Call the OpenSrcFile function int32_t srcFd = -1; - int ret = Storage::DistributedFile::FileCopyManager::GetInstance()->OpenSrcFile(infos->srcPath, infos, srcFd); + int ret = Storage::DistributedFile::FileCopyManager::GetInstance().OpenSrcFile(infos->srcPath, infos, srcFd); // Validate the file descriptor is opened successfully EXPECT_EQ(ret, 0); @@ -750,7 +750,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_CheckOrCreateLPath_0001, TestSize. GTEST_LOG_(INFO) << "FileCopyManager_CheckOrCreateLPath_0001 Start"; std::string destPath = ""; - int32_t ret = Storage::DistributedFile::FileCopyManager::GetInstance()->CheckOrCreatePath(destPath); + int32_t ret = Storage::DistributedFile::FileCopyManager::GetInstance().CheckOrCreatePath(destPath); EXPECT_EQ(ret, FILE_NOT_FOUND); GTEST_LOG_(INFO) << "FileCopyManager_CheckOrCreateLPath_0001 End"; @@ -774,22 +774,22 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_RemoveFileInfos_0001, TestSize.Lev infos2->destUri = "destUri2"; infos3->srcUri = "srcUri1"; infos3->destUri = "destUri2"; - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.clear(); - Storage::DistributedFile::FileCopyManager::GetInstance()->AddFileInfos(infos1); - Storage::DistributedFile::FileCopyManager::GetInstance()->AddFileInfos(infos2); - auto len = Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.size(); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.clear(); + Storage::DistributedFile::FileCopyManager::GetInstance().AddFileInfos(infos1); + Storage::DistributedFile::FileCopyManager::GetInstance().AddFileInfos(infos2); + auto len = Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 2); // 2: vector size - Storage::DistributedFile::FileCopyManager::GetInstance()->RemoveFileInfos(infos2); - len = Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.size(); + Storage::DistributedFile::FileCopyManager::GetInstance().RemoveFileInfos(infos2); + len = Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 1); // 1: vector size - Storage::DistributedFile::FileCopyManager::GetInstance()->RemoveFileInfos(infos3); - len = Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.size(); + Storage::DistributedFile::FileCopyManager::GetInstance().RemoveFileInfos(infos3); + len = Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 1); // 1: vector size - Storage::DistributedFile::FileCopyManager::GetInstance()->RemoveFileInfos(infos1); - len = Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.size(); + Storage::DistributedFile::FileCopyManager::GetInstance().RemoveFileInfos(infos1); + len = Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 0); // 0: vector size } @@ -805,7 +805,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_RecurCopyDir_0001, TestSize.Level0 auto infos = std::make_shared(); std::string srcPath = ""; std::string dstPath = ""; - auto res = Storage::DistributedFile::FileCopyManager::GetInstance()->RecurCopyDir(srcPath, dstPath, infos); + auto res = Storage::DistributedFile::FileCopyManager::GetInstance().RecurCopyDir(srcPath, dstPath, infos); EXPECT_EQ(res, E_OK); srcPath = "/data/test/RecurCopyDir/src/"; @@ -831,11 +831,11 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_RecurCopyDir_0001, TestSize.Level0 } infos->localListener = std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); - res = Storage::DistributedFile::FileCopyManager::GetInstance()->RecurCopyDir(srcPath, dstPath, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().RecurCopyDir(srcPath, dstPath, infos); EXPECT_EQ(res, E_OK); dstPath = dstPath + "dir/dir1/dir2"; - res = Storage::DistributedFile::FileCopyManager::GetInstance()->RecurCopyDir(srcPath, dstPath, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().RecurCopyDir(srcPath, dstPath, infos); EXPECT_EQ(res, ENOENT); std::string rootPath = "/data/test/RecurCopyDir"; @@ -859,17 +859,17 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_CopySubDir_0001, TestSize.Level0) std::string dstPath = "/data/test/CopySubDir/dst"; infos->localListener = std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); - auto res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopySubDir(srcPath, dstPath, infos); + auto res = Storage::DistributedFile::FileCopyManager::GetInstance().CopySubDir(srcPath, dstPath, infos); EXPECT_EQ(res, ENOENT); if (!ForceCreateDirectory(dstPath)) { GTEST_LOG_(INFO) << "FileCopyManager_CopySubDir_0001 create dir err" << dstPath; } - res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopySubDir(srcPath, dstPath, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().CopySubDir(srcPath, dstPath, infos); EXPECT_EQ(res, E_OK); std::string tmpDstDir = dstPath + "/dir"; - res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopySubDir(srcPath, tmpDstDir, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().CopySubDir(srcPath, tmpDstDir, infos); EXPECT_EQ(res, E_OK); std::string rootPath = "/data/test/CopySubDir"; if (!ForceRemoveDirectory(rootPath)) { @@ -892,18 +892,18 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_CopyDirFunc_0001, TestSize.Level0) std::string dstPath = "/data/test/CopyDirFunc/dst"; infos->localListener = std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); - auto res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopyDirFunc(srcPath, dstPath, infos); + auto res = Storage::DistributedFile::FileCopyManager::GetInstance().CopyDirFunc(srcPath, dstPath, infos); EXPECT_EQ(res, EINVAL); std::string tmpSrcPath = "/test/CopyDirFunc/"; - res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopyDirFunc(tmpSrcPath, dstPath, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().CopyDirFunc(tmpSrcPath, dstPath, infos); EXPECT_EQ(res, ENOENT); srcPath += "src"; if (!ForceCreateDirectory(dstPath)) { GTEST_LOG_(INFO) << "FileCopyManager_CopyDirFunc_0001 create dir err" << dstPath; } - res = Storage::DistributedFile::FileCopyManager::GetInstance()->CopyDirFunc(srcPath, dstPath, infos); + res = Storage::DistributedFile::FileCopyManager::GetInstance().CopyDirFunc(srcPath, dstPath, infos); EXPECT_EQ(res, E_OK); std::string rootPath = "/data/test/CopyDirFunc"; if (!ForceRemoveDirectory(rootPath)) { @@ -933,9 +933,9 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Cancel_0001, TestSize.Level0) infos2->transListener = sptr(new (std::nothrow) TransListener("/data/test/test.txt", emptyCallback_)); infos2->localListener = std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos1); - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos2); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos1); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos2); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(); EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "FileCopyManager_Cancel_0001 End"; } @@ -958,8 +958,8 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Cancel_0002, TestSize.Level0) std::string srcUri = "srcUri1"; std::string destUri = "destUri1"; - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos1); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(srcUri, destUri, true); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos1); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(srcUri, destUri, true); EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "FileCopyManager_Cancel_0002 End"; } @@ -985,9 +985,9 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Cancel_0003, TestSize.Level0) infos2->transListener = sptr(new (std::nothrow) TransListener("/data/test/test.txt", emptyCallback_)); infos2->localListener = std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos1); - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos2); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(true); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos1); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos2); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(true); EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "FileCopyManager_Cancel_0003 End"; } @@ -1010,24 +1010,24 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_Cancel_0004, TestSize.Level0) std::string srcUri = "srcUri1"; std::string destUri = "destUri3"; - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos1); - auto ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(srcUri, destUri); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos1); + auto ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri2"; destUri = "destUri1"; - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(srcUri, destUri); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri2"; destUri = "destUri2"; - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(srcUri, destUri); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri1"; destUri = "destUri1"; - ret = Storage::DistributedFile::FileCopyManager::GetInstance()->Cancel(srcUri, destUri); + ret = Storage::DistributedFile::FileCopyManager::GetInstance().Cancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); - Storage::DistributedFile::FileCopyManager::GetInstance()->FileInfosVec_.clear(); + Storage::DistributedFile::FileCopyManager::GetInstance().FileInfosVec_.clear(); GTEST_LOG_(INFO) << "FileCopyManager_Cancel_0004 End"; } @@ -1042,7 +1042,7 @@ HWTEST_F(FileCopyManagerTest, FileCopyManager_MakeDir_0001, TestSize.Level1) GTEST_LOG_(INFO) << "FileCopyManager_MakeDir_0001"; string srcpath = "/storage/media/100/local/files/Docs/bb/"; std::error_code errCode; - int res = Storage::DistributedFile::FileCopyManager::GetInstance()->MakeDir(srcpath); + int res = Storage::DistributedFile::FileCopyManager::GetInstance().MakeDir(srcpath); EXPECT_EQ(res, E_OK); ASSERT_EQ(ForceRemoveDirectory(srcpath.c_str()), true); GTEST_LOG_(INFO) << "FileCopyManager_MakeDir_0001 End"; diff --git a/test/unittests/distributed_file_inner/copy/remote_file_copy_manager_test.cpp b/test/unittests/distributed_file_inner/copy/remote_file_copy_manager_test.cpp index 4ee604018d08c19f43ecb8afb4632718e8825233..57662dc48b8c1366520ee183c0405be7271ffb56 100644 --- a/test/unittests/distributed_file_inner/copy/remote_file_copy_manager_test.cpp +++ b/test/unittests/distributed_file_inner/copy/remote_file_copy_manager_test.cpp @@ -1,17 +1,17 @@ /* -* Copyright (c) 2024-2025 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. -*/ + * Copyright (c) 2024-2025 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 "copy/remote_file_copy_manager.h" @@ -39,7 +39,8 @@ int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::st } } // namespace OHOS::AppFileService -namespace OHOS::Storage::DistributedFile::Test { +namespace OHOS::Test { +using namespace OHOS::Storage::DistributedFile; using namespace OHOS::FileManagement; using namespace testing; using namespace testing::ext; @@ -83,10 +84,10 @@ void RemoteFileCopyManagerTest::TearDown(void) } /** -* @tc.name: RemoteFileCopyManager_Copy_0001 -* @tc.desc: The execution of the Copy failed. -* @tc.type: FUNC -* @tc.require: I7TDJK + * @tc.name: RemoteFileCopyManager_Copy_0001 + * @tc.desc: The execution of the Copy failed. + * @tc.type: FUNC + * @tc.require: I7TDJK */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_Copy_0001, TestSize.Level0) { @@ -98,20 +99,20 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_Copy_0001, TestSize.Le sptr listenerCallback; - auto ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy("", localUri, listenerCallback, userId, copyPath); + auto ret = RemoteFileCopyManager::GetInstance().RemoteCopy("", localUri, listenerCallback, userId, copyPath); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy(localUri, "", listenerCallback, userId, copyPath); + ret = RemoteFileCopyManager::GetInstance().RemoteCopy(localUri, "", listenerCallback, userId, copyPath); EXPECT_EQ(ret, EINVAL); - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy("", "", listenerCallback, userId, copyPath); + ret = RemoteFileCopyManager::GetInstance().RemoteCopy("", "", listenerCallback, userId, copyPath); EXPECT_EQ(ret, EINVAL); string remoteUri = "/data/test/Copy/?networkid=/"; if (!ForceCreateDirectory(remoteUri)) { GTEST_LOG_(INFO) << "RemoteFileCopyManager_Copy_0001 create dir err"; } - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy(remoteUri, "", listenerCallback, userId, copyPath); + ret = RemoteFileCopyManager::GetInstance().RemoteCopy(remoteUri, "", listenerCallback, userId, copyPath); EXPECT_EQ(ret, EINVAL); if (!ForceRemoveDirectory(remoteUri)) { GTEST_LOG_(INFO) << "RemoteFileCopyManager_Copy_0001 remove dir err"; @@ -120,10 +121,10 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_Copy_0001, TestSize.Le } /** -* @tc.name: RemoteFileCopyManager_Copy_0002 -* @tc.desc: The execution of the Copy succeed. -* @tc.type: FUNC -* @tc.require: I7TDJK + * @tc.name: RemoteFileCopyManager_Copy_0002 + * @tc.desc: The execution of the Copy succeed. + * @tc.type: FUNC + * @tc.require: I7TDJK */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_Copy_0002, TestSize.Level0) { @@ -136,20 +137,20 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_Copy_0002, TestSize.Le sptr listenerCallback; int fd = open(srcPath.c_str(), O_RDWR | O_CREAT); - ASSERT_TRUE(fd != -1) <<"Failed to open file in RemoteFileCopyManager_Copy_0002!" << errno; + ASSERT_TRUE(fd != -1) << "Failed to open file in RemoteFileCopyManager_Copy_0002!" << errno; close(fd); - auto ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCopy(srcUri, destUri, listenerCallback, userId, copyPath); + auto ret = RemoteFileCopyManager::GetInstance().RemoteCopy(srcUri, destUri, listenerCallback, userId, copyPath); EXPECT_EQ(ret, ENOENT); ASSERT_EQ(remove(srcPath.c_str()), 0); GTEST_LOG_(INFO) << "RemoteFileCopyManager_Copy_0002 End"; } /** -* @tc.name: RemoteFileCopyManager_RemoteCancel_0001 -* @tc.desc: The execution of the cancel succeed. -* @tc.type: FUNC -* @tc.require: I7TDJK + * @tc.name: RemoteFileCopyManager_RemoteCancel_0001 + * @tc.desc: The execution of the cancel succeed. + * @tc.type: FUNC + * @tc.require: I7TDJK */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_RemoteCancel_0001, TestSize.Level0) { @@ -158,37 +159,37 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_RemoteCancel_0001, Tes infos1->srcUri = "srcUri1"; infos1->destUri = "destUri1"; infos1->transListener = nullptr; - infos1->localListener = std::make_shared("", - true, [](uint64_t processSize, uint64_t totalSize) -> void {}); + infos1->localListener = + std::make_shared("", true, [](uint64_t processSize, uint64_t totalSize) -> void {}); std::string srcUri = "srcUri1"; std::string destUri = "destUri3"; - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.emplace_back(infos1); - auto ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCancel(srcUri, destUri); + RemoteFileCopyManager::GetInstance().FileInfosVec_.emplace_back(infos1); + auto ret = RemoteFileCopyManager::GetInstance().RemoteCancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri2"; destUri = "destUri1"; - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCancel(srcUri, destUri); + ret = RemoteFileCopyManager::GetInstance().RemoteCancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri2"; destUri = "destUri2"; - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCancel(srcUri, destUri); + ret = RemoteFileCopyManager::GetInstance().RemoteCancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); srcUri = "srcUri1"; destUri = "destUri1"; - ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoteCancel(srcUri, destUri); + ret = RemoteFileCopyManager::GetInstance().RemoteCancel(srcUri, destUri); EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "RemoteFileCopyManager_RemoteCancel_0001 End"; } /** -* @tc.name: RemoteFileCopyManager_RemoveFileInfos_0001 -* @tc.desc: RemoveFileInfos -* @tc.type: FUNC -* @tc.require: I7TDJK -*/ + * @tc.name: RemoteFileCopyManager_RemoveFileInfos_0001 + * @tc.desc: RemoveFileInfos + * @tc.type: FUNC + * @tc.require: I7TDJK + */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_RemoveFileInfos_0001, TestSize.Level0) { GTEST_LOG_(INFO) << "RemoteFileCopyManager_RemoveFileInfos_0001 Start"; @@ -201,31 +202,31 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_RemoveFileInfos_0001, infos2->destUri = "destUri2"; infos3->srcUri = "srcUri1"; infos3->destUri = "destUri2"; - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.clear(); - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->AddFileInfos(infos1); - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->AddFileInfos(infos2); - auto len = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.size(); + RemoteFileCopyManager::GetInstance().FileInfosVec_.clear(); + RemoteFileCopyManager::GetInstance().AddFileInfos(infos1); + RemoteFileCopyManager::GetInstance().AddFileInfos(infos2); + auto len = RemoteFileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 2); // 2: vector size - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoveFileInfos(infos2); - len = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.size(); + RemoteFileCopyManager::GetInstance().RemoveFileInfos(infos2); + len = RemoteFileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 1); // 1: vector size - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoveFileInfos(infos3); - len = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.size(); + RemoteFileCopyManager::GetInstance().RemoveFileInfos(infos3); + len = RemoteFileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 1); // 1: vector size - Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->RemoveFileInfos(infos1); - len = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->FileInfosVec_.size(); + RemoteFileCopyManager::GetInstance().RemoveFileInfos(infos1); + len = RemoteFileCopyManager::GetInstance().FileInfosVec_.size(); EXPECT_EQ(len, 0); // 0: vector size } /** -* @tc.name: RemoteFileCopyManager_CreateFileInfos_0001 -* @tc.desc: CreateFileInfos -* @tc.type: FUNC -* @tc.require: I7TDJK -*/ + * @tc.name: RemoteFileCopyManager_CreateFileInfos_0001 + * @tc.desc: CreateFileInfos + * @tc.type: FUNC + * @tc.require: I7TDJK + */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_CreateFileInfos_0001, TestSize.Level0) { GTEST_LOG_(INFO) << "RemoteFileCopyManager_CreateFileInfos_0001 Start"; @@ -233,23 +234,23 @@ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_CreateFileInfos_0001, infos->srcUri = ""; int32_t userId = 100; string copyPath = "/data/storage/el2/distributedfiles/123412345/test.txt"; - int32_t ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->CreateFileInfos("", "", infos, userId, copyPath); + int32_t ret = RemoteFileCopyManager::GetInstance().CreateFileInfos("", "", infos, userId, copyPath); EXPECT_EQ(ret, E_OK); GTEST_LOG_(INFO) << "RemoteFileCopyManager_CreateFileInfos_0001 End"; } /** -* @tc.name: FileCopyManager_Cancel_0001 -* @tc.desc: The execution of the cancel succeed. -* @tc.type: FUNC -* @tc.require: I7TDJK + * @tc.name: FileCopyManager_Cancel_0001 + * @tc.desc: The execution of the cancel succeed. + * @tc.type: FUNC + * @tc.require: I7TDJK */ HWTEST_F(RemoteFileCopyManagerTest, RemoteFileCopyManager_IsMediaUri_0001, TestSize.Level0) { GTEST_LOG_(INFO) << "RemoteFileCopyManager_IsMediaUri_0001 Start"; string srcUri = "file://docs/storage/media/100/local/files/Docs/test.txt"; - int32_t ret = Storage::DistributedFile::RemoteFileCopyManager::GetInstance()->IsMediaUri(srcUri); + int32_t ret = RemoteFileCopyManager::GetInstance().IsMediaUri(srcUri); EXPECT_EQ(ret, false); GTEST_LOG_(INFO) << "RemoteFileCopyManager_IsMediaUri_0001 End"; } -} \ No newline at end of file +} // namespace OHOS::Test \ No newline at end of file