From d7e209ea8fde92c725ee8d17b349deffbaf9fa9b Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Tue, 8 Apr 2025 09:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AA=92=E4=BD=93=E7=B1=BB=E5=9E=8BURI?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=88=86=E5=B8=83=E5=BC=8FURI=20Signed-off-b?= =?UTF-8?q?y:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/common/include/sandbox_helper.h | 2 + interfaces/common/src/sandbox_helper.cpp | 28 +++ .../src/remote_file_share.cpp | 160 +++++++++++++----- .../file_share_native/file_share_test.cpp | 62 +++++++ .../remote_file_share_test.cpp | 59 ++++++- 5 files changed, 263 insertions(+), 48 deletions(-) diff --git a/interfaces/common/include/sandbox_helper.h b/interfaces/common/include/sandbox_helper.h index c0fa99864..ac94fc32c 100644 --- a/interfaces/common/include/sandbox_helper.h +++ b/interfaces/common/include/sandbox_helper.h @@ -29,10 +29,12 @@ private: static std::unordered_map backupSandboxPathMap_; static bool GetSandboxPathMap(); static bool GetBackupSandboxPathMap(); + static void* libMediaHandle_; public: static std::string Encode(const std::string &uri); static std::string Decode(const std::string &uri); static bool CheckValidPath(const std::string &filePath); + static int32_t GetMediaSharePath(const std::vector &fileUris, std::vector &physicalPaths); static int32_t GetPhysicalPath(const std::string &fileUri, const std::string &userId, std::string &physicalPath); static int32_t GetBackupPhysicalPath(const std::string &fileUri, const std::string &userId, diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index 3ec9256e4..2dac229ae 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -15,6 +15,7 @@ #include "sandbox_helper.h" +#include #include #include #include @@ -27,6 +28,8 @@ using namespace std; namespace OHOS { namespace AppFileService { +typedef void (*ConvertFileUriToMntPath)(const std::vector &fileUris, + std::vector &physicalPaths); namespace { const string PACKAGE_NAME_FLAG = ""; const string CURRENT_USER_ID_FLAG = ""; @@ -63,6 +66,7 @@ struct MediaUriInfo { std::unordered_map SandboxHelper::sandboxPathMap_; std::unordered_map SandboxHelper::backupSandboxPathMap_; std::mutex SandboxHelper::mapMutex_; +void* SandboxHelper::libMediaHandle_; string SandboxHelper::Encode(const string &uri) { @@ -308,6 +312,30 @@ static int32_t GetMediaPhysicalPath(const std::string &sandboxPath, const std::s return 0; } +int32_t SandboxHelper::GetMediaSharePath(const std::vector &fileUris, + std::vector &physicalPaths) +{ + if (libMediaHandle_ == nullptr) { + libMediaHandle_ = dlopen("libmedia_library_handler.z.so", RTLD_LAZY | RTLD_GLOBAL); + } + if (libMediaHandle_ == nullptr) { + LOGE("dlopen libmedia_library_handler.z.so failed, errno = %{public}s", dlerror()); + return -EINVAL; + } + ConvertFileUriToMntPath convertFileUriToMntPath = + (ConvertFileUriToMntPath)dlsym(libMediaHandle_, "ConvertFileUriToMntPath"); + if (convertFileUriToMntPath == nullptr) { + LOGE("GetMediaSharePath dlsym failed, errno %{public}s", dlerror()); + return -EINVAL; + } + convertFileUriToMntPath(fileUris, physicalPaths); + if (fileUris.size() != physicalPaths.size()) { + LOGE("GetMediaSharePath returns fewer results than the output parameters"); + return -EINVAL; + } + return 0; +} + static void GetNetworkIdFromUri(const std::string &fileUri, string &networkId) { Uri uri(fileUri); diff --git a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp index 568d8a573..28dfc1a78 100644 --- a/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp +++ b/interfaces/innerkits/native/remote_file_share/src/remote_file_share.cpp @@ -40,10 +40,12 @@ namespace ModuleRemoteFileShare { using namespace OHOS::DistributedHardware; #endif namespace { +const int E_OK = 0; const int HMDFS_CID_SIZE = 64; const int USER_ID_INIT = 100; const unsigned HMDFS_IOC = 0xf2; const std::string FILE_SCHEME = "file"; +const std::string BACKSLASH = "/"; const std::string DISTRIBUTED_DIR_PATH = "/data/storage/el2/distributedfiles"; const std::string DST_PATH_HEAD = "/data/service/el2/"; const std::string DST_PATH_MID = "/hmdfs/account/data/"; @@ -93,7 +95,7 @@ static std::string GetProcessName() { char pthreadName[PATH_MAX]; int ret = pthread_getname_np(pthread_self(), pthreadName, sizeof(pthreadName)); - if (ret != 0) { + if (ret != E_OK) { LOGE("RemoteFileShare::GetProcessName, pthread_getname_np failed with %{public}d", errno); return ""; } @@ -133,12 +135,12 @@ static int CreateShareDir(const std::string &path) { if (access(path.c_str(), F_OK) != 0) { int ret = mkdir(path.c_str(), S_IRWXU); - if (ret != 0) { + if (ret != E_OK) { LOGE("RemoteFileShare::CreateShareDir, make dir failed with %{public}d", errno); return errno; } } - return 0; + return E_OK; } static std::string GetSharePath(const int &userId, const std::string &packageName) @@ -154,18 +156,18 @@ static std::string GetLowerSharePath(const int &userId, const std::string &packa static bool DeleteShareDir(const std::string &PACKAGE_PATH, const std::string &SHARE_PATH) { bool result = true; - if (access(SHARE_PATH.c_str(), F_OK) == 0) { + if (access(SHARE_PATH.c_str(), F_OK) == E_OK) { int ret = rmdir(SHARE_PATH.c_str()); - if (ret != 0) { + if (ret != E_OK) { LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); result = false; } else { LOGI("RemoteFileShare::DeleteShareDir, delete path successfully"); } } - if (access(PACKAGE_PATH.c_str(), F_OK) == 0) { + if (access(PACKAGE_PATH.c_str(), F_OK) == E_OK) { int ret = rmdir(PACKAGE_PATH.c_str()); - if (ret != 0) { + if (ret != E_OK) { LOGE("RemoteFileShare::DeleteShareDir, delete dir failed with %{public}d", errno); result = false; } else { @@ -194,7 +196,7 @@ static int CreateShareFile(struct HmdfsShareControl &shareControl, const char *f LOGE("RemoteFileShare::CreateShareFile, ioctl failed with %{public}d", errno); } close(dirFd); - return 0; + return E_OK; } static int CheckInputValidity(const int &fd, const int &userId, const std::string &deviceId) @@ -210,7 +212,7 @@ int RemoteFileShare::CreateSharePath(const int &fd, struct HmdfsShareControl shareControl; shareControl.fd = fd; - if (CheckInputValidity(fd, userId, deviceId) != 0) { + if (CheckInputValidity(fd, userId, deviceId) != E_OK) { LOGE("RemoteFileShare::CreateSharePath, invalid argument with %{public}d", EINVAL); return EINVAL; } @@ -228,9 +230,9 @@ int RemoteFileShare::CreateSharePath(const int &fd, } const std::string LOWER_SHARE_PATH = PACKAGE_PATH + SHARE_PATH_DIR; - if (CreateShareDir(PACKAGE_PATH) != 0) + if (CreateShareDir(PACKAGE_PATH) != E_OK) return errno; - if (CreateShareDir(LOWER_SHARE_PATH) != 0) { + if (CreateShareDir(LOWER_SHARE_PATH) != E_OK) { DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); return errno; } @@ -251,32 +253,34 @@ int RemoteFileShare::CreateSharePath(const int &fd, } sharePath = SHARE_PATH + "/" + file_name; - if (CreateShareFile(shareControl, realPath, deviceId) != 0) { + if (CreateShareFile(shareControl, realPath, deviceId) != E_OK) { LOGE("RemoteFileShare::CreateSharePath, create share file failed with %{public}d", errno); /* When the file is exist, we should not delete the dictionary */ if (errno == EEXIST) { - return 0; + return E_OK; } sharePath = ""; DeleteShareDir(PACKAGE_PATH, LOWER_SHARE_PATH); return errno; } LOGI("RemoteFileShare::CreateSharePath, create successfully"); - return 0; + return E_OK; } static int GetDistributedPath(Uri &uri, const int &userId, std::string &distributedPath, - const std::string &bundleName) + const std::string &bundleName, + const std::string &networkId) { - distributedPath = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + bundleName + - REMOTE_SHARE_PATH_DIR + SandboxHelper::Decode(uri.GetPath()); + distributedPath = DST_PATH_HEAD + std::to_string(userId) + DST_PATH_MID + bundleName + REMOTE_SHARE_PATH_DIR + + BACKSLASH + networkId + SandboxHelper::Decode(uri.GetPath()); if (distributedPath.size() >= PATH_MAX) { + LOGE("Path is too long with %{public}zu", distributedPath.size()); return -EINVAL; } - return 0; + return E_OK; } static std::string GetPhysicalPath(Uri &uri, const std::string &userId) @@ -289,7 +293,7 @@ static std::string GetPhysicalPath(Uri &uri, const std::string &userId) std::string physicalPath = ""; int ret = SandboxHelper::GetPhysicalPath(uri.ToString(), userId, physicalPath); - if (ret != 0) { + if (ret != E_OK) { LOGE("Get physical path failed with %{public}d", ret); return ""; } @@ -341,8 +345,8 @@ static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, const std::string &networkId, const std::string &bundleName) { - hui.uriStr = FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + REMOTE_SHARE_PATH_DIR + - uri.GetPath() + networkId; + hui.uriStr = FILE_SCHEME + "://" + bundleName + DISTRIBUTED_DIR_PATH + REMOTE_SHARE_PATH_DIR + BACKSLASH + + networkId + uri.GetPath() + NETWORK_PARA + networkId; hui.fileSize = fileSize; return; @@ -351,14 +355,14 @@ static void SetHmdfsUriInfo(struct HmdfsUriInfo &hui, static int32_t SetPublicDirHmdfsInfo(const std::string &physicalPath, const std::string &uriStr, struct HmdfsUriInfo &hui, const std::string &networkId) { - hui.uriStr = uriStr + networkId; + hui.uriStr = uriStr + NETWORK_PARA + networkId; struct stat buf = {}; - if (stat(physicalPath.c_str(), &buf) != 0) { + if (stat(physicalPath.c_str(), &buf) != E_OK) { LOGE("Failed to get physical path stat with %{public}d", -errno); return -errno; } hui.fileSize = static_cast(buf.st_size); - return 0; + return E_OK; } static int32_t GetMergePathFd(HmdfsDstInfo &hdi, UniqueFd &dirFd, const int32_t &userId) @@ -371,12 +375,12 @@ static int32_t GetMergePathFd(HmdfsDstInfo &hdi, UniqueFd &dirFd, const int32_t return errno; } int32_t ret = ioctl(dirMergeFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != 0) { + if (ret != E_OK) { LOGE("Ioctl merge failed with %{public}d", errno); return -errno; } dirFd = std::move(dirMergeFd); - return 0; + return E_OK; } int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui) @@ -393,17 +397,16 @@ int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int bundleName = MEDIA_BUNDLE_NAME; } - std::string networkId = NETWORK_PARA + GetLocalNetworkId(); + std::string networkId = GetLocalNetworkId(); if (bundleName == FILE_MANAGER_AUTHORITY) { (void)SetPublicDirHmdfsInfo(physicalPath, uriStr, hui, networkId); LOGD("GetDfsUriFromLocal successfully"); - return 0; + return E_OK; } std::string distributedPath; - int ret = GetDistributedPath(uri, userId, distributedPath, bundleName); - if (ret != 0) { - LOGE("Path is too long with %{public}d", ret); + int ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); + if (ret != E_OK) { return ret; } @@ -418,28 +421,96 @@ int32_t RemoteFileShare::GetDfsUriFromLocal(const std::string &uriStr, const int } ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != 0 && GetMergePathFd(hdi, dirFd, userId) != 0) { + if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { return errno; } SetHmdfsUriInfo(hui, uri, hdi.size, networkId, bundleName); LOGI("GetDfsUriFromLocal successfully"); - return 0; + return E_OK; +} + +static int32_t UriCategoryByType(const std::vector &uriList, + std::vector &mediaUriList, + std::vector &otherUriList) +{ + LOGI("GetDfsUrisFromLocal UriCategoryByType start"); + if (uriList.size() == 0) { + LOGE("Parameter uriList is NULL"); + return -EINVAL; + } + for (auto &uriStr : uriList) { + Uri uri(uriStr); + std::string bundleName = uri.GetAuthority(); + if (bundleName == MEDIA_AUTHORITY) { + mediaUriList.push_back(uriStr); + } else { + otherUriList.push_back(uriStr); + } + } + return E_OK; +} + +static int32_t GetMediaDfsUrisFromLocal(const std::vector &uriList, + const int32_t &userId, + std::unordered_map &uriToDfsUriMaps) +{ + LOGI("GetMediaDfsUrisFromLocal start"); + std::string ioctlDir = SHAER_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID; + UniqueFd dirFd(open(ioctlDir.c_str(), O_RDONLY)); + if (dirFd < 0) { + LOGE("Open share path failed with %{public}d", errno); + return errno; + } + std::vector physicalPaths; + int getPhysicalPathRet = SandboxHelper::GetMediaSharePath(uriList, physicalPaths); + if (getPhysicalPathRet != E_OK) { + return -EINVAL; + } + std::string networkId = GetLocalNetworkId(); + std::string bundleName = MEDIA_BUNDLE_NAME; + for (size_t i = 0; i < uriList.size(); i++) { + Uri uri(uriList[i]); + LOGD("GetDfsUriFromLocal begin, uri: %{private}s", uriList[i].c_str()); + std::string distributedPath; + int ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); + if (ret != E_OK) { + return ret; + } + struct HmdfsDstInfo hdi; + InitHmdfsInfo(hdi, physicalPaths[i], distributedPath, bundleName); + ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); + if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { + return errno; + } + HmdfsUriInfo dfsUriInfo; + SetHmdfsUriInfo(dfsUriInfo, uri, hdi.size, networkId, bundleName); + uriToDfsUriMaps.insert({uriList[i], dfsUriInfo}); + } + LOGI("GetDfsUrisFromLocal successfully"); + return E_OK; } int32_t RemoteFileShare::GetDfsUrisFromLocal(const std::vector &uriList, const int32_t &userId, std::unordered_map &uriToDfsUriMaps) { - LOGI("GetDfsUrisFromLocal start"); + std::vector otherUriList; + std::vector mediaUriList; + int ret = UriCategoryByType(uriList, mediaUriList, otherUriList); + if (ret == E_OK && mediaUriList.size() != E_OK) { + ret = GetMediaDfsUrisFromLocal(mediaUriList, userId, uriToDfsUriMaps); + } + if (ret != E_OK) { + return ret; + } std::string ioctlDir = SHAER_PATH_HEAD + std::to_string(userId) + LOWER_SHARE_PATH_MID; UniqueFd dirFd(open(ioctlDir.c_str(), O_RDONLY)); if (dirFd < 0) { LOGE("Open share path failed with %{public}d", errno); return errno; } - LOGI("open ioctlDir end"); - std::string networkId = NETWORK_PARA + GetLocalNetworkId(); - for (auto &uriStr : uriList) { + std::string networkId = GetLocalNetworkId(); + for (const auto &uriStr : otherUriList) { Uri uri(uriStr); std::string bundleName = uri.GetAuthority(); LOGD("GetDfsUriFromLocal begin, uri: %{private}s", uriStr.c_str()); @@ -448,27 +519,22 @@ int32_t RemoteFileShare::GetDfsUrisFromLocal(const std::vector &uri LOGE("Failed to get physical path"); return -EINVAL; } - if (bundleName == MEDIA_AUTHORITY) { - bundleName = MEDIA_BUNDLE_NAME; - } if (bundleName == FILE_MANAGER_AUTHORITY) { HmdfsUriInfo dfsUriInfo; (void)SetPublicDirHmdfsInfo(physicalPath, uriStr, dfsUriInfo, networkId); uriToDfsUriMaps.insert({uriStr, dfsUriInfo}); - LOGD("GetDfsUriFromLocal successfully"); continue; } std::string distributedPath; - int ret = GetDistributedPath(uri, userId, distributedPath, bundleName); - if (ret != 0) { - LOGE("Path is too long with %{public}d", ret); + ret = GetDistributedPath(uri, userId, distributedPath, bundleName, networkId); + if (ret != E_OK) { return ret; } struct HmdfsDstInfo hdi; InitHmdfsInfo(hdi, physicalPath, distributedPath, bundleName); ret = ioctl(dirFd, HMDFS_IOC_GET_DST_PATH, &hdi); - if (ret != 0 && GetMergePathFd(hdi, dirFd, userId) != 0) { + if (ret != E_OK && GetMergePathFd(hdi, dirFd, userId) != E_OK) { return errno; } HmdfsUriInfo dfsUriInfo; @@ -476,7 +542,7 @@ int32_t RemoteFileShare::GetDfsUrisFromLocal(const std::vector &uri uriToDfsUriMaps.insert({uriStr, dfsUriInfo}); } LOGI("GetDfsUrisFromLocal successfully"); - return 0; + return E_OK; } int32_t RemoteFileShare::TransRemoteUriToLocal(const std::vector &uriList, @@ -529,7 +595,7 @@ int32_t RemoteFileShare::TransRemoteUriToLocal(const std::vector &u return -EINVAL; } resultList = tmpResultList; - return 0; + return E_OK; } } // namespace ModuleRemoteFileShare } // namespace AppFileService diff --git a/test/unittest/file_share_native/file_share_test.cpp b/test/unittest/file_share_native/file_share_test.cpp index d87c28f60..22d26eb86 100644 --- a/test/unittest/file_share_native/file_share_test.cpp +++ b/test/unittest/file_share_native/file_share_test.cpp @@ -460,6 +460,68 @@ HWTEST_F(FileShareTest, File_share_GetPhysicalPath_0007, testing::ext::TestSize. GTEST_LOG_(INFO) << "FileShareTest-end File_share_GetPhysicalPath_0007"; } +/** + * @tc.name: File_share_GetMediaSharePath_0001 + * @tc.desc: Test function of GetMediaSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7PDZL + */ +HWTEST_F(FileShareTest, File_share_GetMediaSharePath_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileShareTest-begin File_share_GetMediaSharePath_0001"; + std::string fileUri = "file://media/Photo/test/IMG_12345_999999/test.jpg"; + vector uriList; + vector physicalPathList; + uriList.push_back(fileUri); + int32_t ret = SandboxHelper::GetMediaSharePath(uriList, physicalPathList); + EXPECT_EQ(ret, -EINVAL); + GTEST_LOG_(INFO) << "FileShareTest-end File_share_GetMediaSharePath_0001"; +} + +/** + * @tc.name: File_share_GetMediaSharePath_0002 + * @tc.desc: Test function of GetMediaSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7PDZL + */ +HWTEST_F(FileShareTest, File_share_GetMediaSharePath_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileShareTest-begin File_share_GetMediaSharePath_0002"; + std::string fileUri = "file://media/Photo"; + vector uriList; + vector physicalPathList; + uriList.push_back(fileUri); + int32_t ret = SandboxHelper::GetMediaSharePath(uriList, physicalPathList); + EXPECT_EQ(ret, -EINVAL); + GTEST_LOG_(INFO) << "FileShareTest-end File_share_GetMediaSharePath_0002"; +} + +/** + * @tc.name: File_share_GetMediaSharePath_0003 + * @tc.desc: Test function of GetMediaSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7PDZL + */ +HWTEST_F(FileShareTest, File_share_GetMediaSharePath_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FileShareTest-begin File_share_GetMediaSharePath_0003"; + std::string fileUri = "file://media/Photo/test/IMG_12345_/test.JPG"; + std::string fileUri1 = "file://media/Photo/test/IMG_12345_/test.JPG"; + vector uriList; + vector physicalPathList; + uriList.push_back(fileUri); + uriList.push_back(fileUri1); + int32_t ret = SandboxHelper::GetMediaSharePath(uriList, physicalPathList); + EXPECT_EQ(ret, -EINVAL); + GTEST_LOG_(INFO) << "FileShareTest-end File_share_GetMediaSharePath_0003"; +} + /** * @tc.name: File_share_CheckValidPath_0001 * @tc.desc: Test function of CheckValidPath() interface for FAILURE. diff --git a/test/unittest/remote_file_share/remote_file_share_test.cpp b/test/unittest/remote_file_share/remote_file_share_test.cpp index 7b97212c5..5df49b322 100644 --- a/test/unittest/remote_file_share/remote_file_share_test.cpp +++ b/test/unittest/remote_file_share/remote_file_share_test.cpp @@ -477,7 +477,7 @@ namespace { HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0015, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0015"; - const string uriStr = "file://media/Photo/12/IMG_12345_0011/test.jpg"; + const string uriStr = "file://media/Photo/test/IMG_12345_0011/test.jpg"; const int userId = USER_ID; HmdfsUriInfo hui; int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); @@ -522,6 +522,63 @@ namespace { GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0016"; } + /** + * @tc.name: remote_file_share_GetDfsUriFromLocal_0017 + * @tc.desc: Test function of GetDfsUrisFromLocal() interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7KDF7 + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0017, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0017"; + const string uriStr = "file://docs/storage/Users/currentUser/Documents/1.txt"; + const string uriStr1 = "file://media/Photo/test/IMG_12345_0011/test.jpg"; + const int userId = USER_ID; + HmdfsUriInfo hui; + int ret = RemoteFileShare::GetDfsUriFromLocal(uriStr, userId, hui); + EXPECT_EQ(ret, E_OK); + + vector uriList; + unordered_map uriToDfsUriMaps; + uriList.push_back(uriStr); + uriList.push_back(uriStr1); + ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); + EXPECT_EQ(ret, -EINVAL); + + GTEST_LOG_(INFO) << "RemoteFileShareTest uri is " << hui.uriStr; + GTEST_LOG_(INFO) << "RemoteFileShareTest file size is " << hui.fileSize; + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0017"; + } + + /** + * @tc.name: remote_file_share_GetDfsUriFromLocal_0018 + * @tc.desc: Test function of GetDfsUrisFromLocal() interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7KDF7 + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_GetDfsUriFromLocal_0018, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_GetDfsUriFromLocal_0018"; + const string uriStr = "file://media/Photo/test/IMG_12345_0011/test.jpg"; + const string uriStr1 = "file://media/Photo/test/IMG_12345_0012/test1.jpg"; + const string uriStr2 = "file://media/Photo/test/IMG_12345_0013/test1.jpg"; + const int userId = USER_ID; + + vector uriList; + unordered_map uriToDfsUriMaps; + uriList.push_back(uriStr); + uriList.push_back(uriStr1); + uriList.push_back(uriStr2); + int ret = RemoteFileShare::GetDfsUrisFromLocal(uriList, userId, uriToDfsUriMaps); + EXPECT_EQ(ret, -EINVAL); + + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_GetDfsUriFromLocal_0018"; + } + /** * @tc.name: remote_file_share_test_0012 * @tc.desc: Test function of TransRemoteUriToLocal() interface for SUCCESS. -- Gitee