diff --git a/BUILD.gn b/BUILD.gn index c51710244e9eb1bbab75df65bab83827aeff9fb0..0ea2c036b44f81eb2e6d4bc26f939df12d7a12cf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -13,11 +13,19 @@ import("//build/ohos.gni") -group("libremotefileshare") { +group("file_share_js_sdk") { + deps = [ + "interfaces/kits/js:fileshare", + "interfaces/kits/js:fileuri", + "interfaces/kits/js:remotefileshare", + ] +} + +group("file_share_native_sdk") { deps = [ "interfaces/innerkits/native/file_share:fileshare_native", - "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native:remote_file_share_native", - "//foundation/filemanagement/app_file_service/interfaces/kits/js:remotefileshare", + "interfaces/innerkits/native/file_uri:fileuri_native", + "interfaces/innerkits/remote_file_share/native:remote_file_share_native", ] } diff --git a/bundle.json b/bundle.json index fc02fdb7680ad45c54ac72ad65f516d9ce9774ed..85e9af7f9bb0adb5de3bc4c66e24309c76655dab 100644 --- a/bundle.json +++ b/bundle.json @@ -26,9 +26,8 @@ "group_type": { "base_group": [], "fwk_group": [ - "//foundation/filemanagement/app_file_service:libremotefileshare", - "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileshare", - "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileuri" + "//foundation/filemanagement/app_file_service:file_share_js_sdk", + "//foundation/filemanagement/app_file_service:file_share_native_sdk" ], "service_group": [ "//foundation/filemanagement/app_file_service:tgt_backup_extension", @@ -41,19 +40,19 @@ { "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_share:fileshare_native", "header": { - "header_files": [ - "file_share.h" - ], - "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_share/include" + "header_files": [ + "file_share.h" + ], + "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_share/include" } }, { "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native:remote_file_share_native", "header": { - "header_files": [ - "remote_file_share.h" - ], - "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native" + "header_files": [ + "remote_file_share.h" + ], + "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/remote_file_share/native" } }, { @@ -70,6 +69,15 @@ "impl/i_service_reverse.h" ] } + }, + { + "name": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_uri:fileuri_native", + "header": { + "header_files": [ + "file_uri.h" + ], + "header_base": "//foundation/filemanagement/app_file_service/interfaces/innerkits/native/file_uri/include" + } } ], "test": [ diff --git a/interfaces/innerkits/native/file_uri/BUILD.gn b/interfaces/innerkits/native/file_uri/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9b085b969365091b81f7c7fb9cb538794b38c9db --- /dev/null +++ b/interfaces/innerkits/native/file_uri/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2023 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. + +import("//build/ohos.gni") + +config("file_uri_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../common", + ] +} + +ohos_shared_library("fileuri_native") { + sources = [ "src/file_uri.cpp" ] + + public_configs = [ ":file_uri_config" ] + + external_deps = [ + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + part_name = "app_file_service" + subsystem_name = "filemanagement" +} diff --git a/interfaces/innerkits/native/file_uri/include/file_uri.h b/interfaces/innerkits/native/file_uri/include/file_uri.h new file mode 100644 index 0000000000000000000000000000000000000000..9ade1879a6a6f7f2308bea43778c79b498899189 --- /dev/null +++ b/interfaces/innerkits/native/file_uri/include/file_uri.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 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 APP_FILE_SERVICE_FILE_URI_H +#define APP_FILE_SERVICE_FILE_URI_H + +#include +#include +#include +#include "uri.h" + +namespace OHOS { +namespace AppFileService { +namespace ModuleFileUri { +using namespace std; +const string FILE_SCHEME = "file"; +const string DATA_SHARE_SCHEME = "datashare"; +const string SCHEME_SYMBOL = ":"; +const string PATH_SYMBOL = "/"; +const string FRAGMENT_SYMBOLS = "#"; +const string NETWORK_ID_TAG = "networkid"; +const string EQUAL_SIGN = "="; +const string REMOTE_URI_TAG = "fdFromBinder"; +const string MEDIA = "/media/"; +const string MEDIA_BUNDLE_NAME = "media"; +const int MAX_URI_SIZE = 128; + +class FileUri : public OHOS::Uri { + static setfdFromBinder; + static void RemoveFd(int fd); +public: + explicit FileUri(const std::string &uri): Uri(uri) {} + static bool IsRemoteUri(const string &uri); + static bool IsRemoteUri(const string &path, int &fd, const int& flags = O_RDONLY); + static int ConvertUri(const int &fd, string &remoteUri); + static int OpenRemoteUri(const string &remoteUri); + static bool IsMediaUri(const string &uri); + static bool IsFileUri(const string &uri); + static string TransToDataShareUri(const string fileUri); + static string TransToFileUri(const string dataShareUri); + static string GetFileUriFromPath(const string path); + ~FileUri() {} +}; +} // namespace ModuleFileUri +} // namespace AppFileService +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native/file_uri/src/file_uri.cpp b/interfaces/innerkits/native/file_uri/src/file_uri.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a3b73b989f8f230b7bbd1bef9551f3854f968a3 --- /dev/null +++ b/interfaces/innerkits/native/file_uri/src/file_uri.cpp @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2023 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 "file_uri.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "accesstoken_kit.h" +#include "bundle_info.h" +#include "bundle_mgr_proxy.h" +#include "hap_token_info.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "log.h" +#include "status_receiver_host.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace AppFileService { +namespace ModuleFileUri { +using namespace OHOS::AppExecFwk; + +setFileUri::fdFromBinder; + +static bool IsUri(const string &uri) +{ + string::size_type posSymbol = uri.find(SCHEME_SYMBOL + PATH_SYMBOL + PATH_SYMBOL); + return posSymbol != string::npos; +} + +bool FileUri::IsRemoteUri(const string& uri) +{ + if (IsUri(uri)) { + string scheme = FileUri(uri).GetScheme(); + if (scheme == DATA_SHARE_SCHEME || scheme == FILE_SCHEME) { + string::size_type posFragment = uri.find(FRAGMENT_SYMBOLS + REMOTE_URI_TAG + EQUAL_SIGN); + return posFragment != string::npos; + } + } + return false; +} + +bool FileUri::IsMediaUri(const string &uri) +{ + if (IsUri(uri)) { + FileUri fileUri = FileUri(uri); + string scheme = fileUri.GetScheme(); + string path = fileUri.GetPath(); + std::size_t len = MEDIA.length(); + if (path.length() > len) { + string media = path.substr(0, len); + return scheme == DATA_SHARE_SCHEME && media == MEDIA; + } + } + return false; +} + +bool FileUri::IsFileUri(const string &uri) +{ + return IsUri(uri) && FileUri(uri).GetScheme() == FILE_SCHEME; +} + +static bool IsAllDigits(string fdStr) +{ + for (size_t i = 0; i < fdStr.size(); i++) { + if (!isdigit(fdStr[i])) { + return false; + } + } + return true; +} + +static string GetCallingPkgName() +{ + uint32_t pid = IPCSkeleton::GetCallingTokenID(); + Security::AccessToken::HapTokenInfo tokenInfo = Security::AccessToken::HapTokenInfo(); + Security::AccessToken::AccessTokenKit::GetHapTokenInfo(pid, tokenInfo); + return tokenInfo.bundleName; +} + +void FileUri::RemoveFd(int fd) +{ + auto iter = fdFromBinder.find(fd); + if (iter != fdFromBinder.end()) { + fdFromBinder.erase(iter); + } +} + +bool FileUri::IsRemoteUri(const string& path, int &fd, const int& flags) +{ + if (!IsRemoteUri(path)) { + return false; + } + string::size_type posFd = path.find(EQUAL_SIGN); + string::size_type posFragment = path.find(FRAGMENT_SYMBOLS); + string fragment = path.substr(posFragment + 1, REMOTE_URI_TAG.size()); + if (fragment == REMOTE_URI_TAG) { + string fdStr = path.substr(posFd + 1); + if (IsAllDigits(fdStr)) { + fd = stoi(fdStr.c_str()); + if (fd < 0 || flags != O_RDONLY) { + fd = -1; + } + RemoveFd(fd); + return true; + } + fd = -1; + return true; + } + return false; +} + +int FileUri::ConvertUri(const int &fd, string &remoteUri) +{ + if (fd < 0) { + return -EINVAL; + } + + if (fdFromBinder.size() == MAX_URI_SIZE) { + close(*fdFromBinder.begin()); + fdFromBinder.erase(fdFromBinder.begin()); + } + fdFromBinder.emplace(fd); + + string pkgName = GetCallingPkgName(); + remoteUri = DATA_SHARE_SCHEME + ":///" + pkgName + "/" + FRAGMENT_SYMBOLS + + REMOTE_URI_TAG + EQUAL_SIGN + to_string(fd); + return 0; +} + +int FileUri::OpenRemoteUri(const string &remoteUri) +{ + int fd = -1; + (void)IsRemoteUri(remoteUri, fd); + + return fd; +} + +string FileUri::TransToFileUri(const string dataShareUri) +{ + FileUri fileUri(dataShareUri); + string uri; + string fragment; + if (IsMediaUri(dataShareUri)) { + string deviceId = fileUri.GetAuthority(); + if (!deviceId.empty()) { + fragment = FRAGMENT_SYMBOLS + NETWORK_ID_TAG + EQUAL_SIGN + deviceId; + } + string path = fileUri.GetPath(); + uri = FILE_SCHEME + SCHEME_SYMBOL + PATH_SYMBOL + path + fragment; + } else if (IsRemoteUri(dataShareUri)) { + string::size_type posFragment = dataShareUri.find(FRAGMENT_SYMBOLS); + fragment = dataShareUri.substr(posFragment); + uri = FILE_SCHEME + SCHEME_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + fragment; + } else { + LOGE("Failed to TransToFileUri, dataShareUri is %{public}s", dataShareUri.c_str()); + return ""; + } + LOGI("Success to TransToFileUri, fileUri is %{public}s", uri.c_str()); + return uri; +} + +string FileUri::TransToDataShareUri(const string uri) +{ + if (!FileUri::IsFileUri(uri)) { + LOGE("Failed to TransToDataShareUri, parameter is invalid! parameter = %{public}s", uri.c_str()); + return ""; + } + string dataShareUri; + if (IsRemoteUri(uri)) { + string::size_type posFragment = uri.find(FRAGMENT_SYMBOLS); + string fragment = uri.substr(posFragment); + dataShareUri = DATA_SHARE_SCHEME + SCHEME_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + fragment; + } else { + FileUri fileUri(uri); + string bundleName = fileUri.GetAuthority(); + string path = fileUri.GetPath(); + if (bundleName.empty() || path.empty()) { + LOGE("Failed to TransToDataShareUri, parameter is invalid! parameter = %{public}s", uri.c_str()); + return ""; + } + string fragment = fileUri.GetFragment(); + string deviceId; + if (!fragment.empty()) { + string::size_type posId = fragment.find(EQUAL_SIGN); + deviceId = fragment.substr(posId + 1); + } + dataShareUri = DATA_SHARE_SCHEME + SCHEME_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + deviceId + PATH_SYMBOL + bundleName + path; + } + LOGI("Success to TransToDataShareUri, dataShareUri is %{public}s", dataShareUri.c_str()); + return dataShareUri; +} + +static sptr GetBundleMgrProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + LOGE("fail to get system ability mgr."); + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + LOGE("fail to get bundle manager proxy."); + return nullptr; + } + + return iface_cast(remoteObject); +} + +static string GetBundleName() +{ + int uid = -1; + uid = IPCSkeleton::GetCallingUid(); + + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + LOGE("GetBundleName: bundle mgr proxy is nullptr."); + return ""; + } + + BundleInfo bundleInfo; + auto ret = bundleMgrProxy->GetBundleInfoForSelf(uid, bundleInfo); + if (ret != 0) { + LOGE("GetBundleName: bundleName get fail. uid is %{public}d", uid); + return ""; + } + + return bundleInfo.name; +} + +string FileUri::GetFileUriFromPath(const string path) +{ + string bundleName = GetBundleName(); + string uri = FILE_SCHEME + SCHEME_SYMBOL + PATH_SYMBOL + PATH_SYMBOL + bundleName + path; + return uri; +} +} // namespace ModuleFileUri +} // namespace AppFileService +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/file_uri/get_uri_from_path.cpp b/interfaces/kits/js/file_uri/get_uri_from_path.cpp index 30c77385ac3784e1c422583d827e806ef8c2be23..ef25da9069ac4e1005ae3c35f67ba6947a8f1cd3 100644 --- a/interfaces/kits/js/file_uri/get_uri_from_path.cpp +++ b/interfaces/kits/js/file_uri/get_uri_from_path.cpp @@ -80,7 +80,7 @@ napi_value GetUriFromPath::Sync(napi_env env, napi_callback_info info) return nullptr; } string packageName = GetBundleName(); - string uri = SCHEME + SCHEME_SEPARATOR + PATH_SYMBOLS + packageName + path.get(); + string uri = FILE_SCHEME + SCHEME_SYMBOLS + packageName + path.get(); return NVal::CreateUTF8String(env, uri).val_; } diff --git a/interfaces/kits/js/file_uri/get_uri_from_path.h b/interfaces/kits/js/file_uri/get_uri_from_path.h index 7dbea01cd50d4fb90e09facdaa349d028eb6fb8f..674ee5dc6b18fb3eebb12bff66a390d7c6eea0e9 100644 --- a/interfaces/kits/js/file_uri/get_uri_from_path.h +++ b/interfaces/kits/js/file_uri/get_uri_from_path.h @@ -24,9 +24,8 @@ namespace AppFileService { namespace ModuleFileUri { using namespace std; -const string SCHEME = "file"; -const char SCHEME_SEPARATOR = ':'; -const string PATH_SYMBOLS = "//"; +const string FILE_SCHEME = "file"; +const string SCHEME_SYMBOLS = "://"; const string FRAGMENT_SYMBOLS = "#"; class GetUriFromPath final { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bce4a610a06117da087b800566b9918c57b088bd..53d8db6d17ff7d0eee037bc1c1d3354156b11729 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -15,6 +15,7 @@ group("unittest") { testonly = true deps = [ "file_share_native:file_share_test", + "file_uri_native:file_uri_test", "remote_file_share:remote_file_share_test", ] } diff --git a/test/unittest/file_uri_native/BUILD.gn b/test/unittest/file_uri_native/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0114f6eb204e06a6aa321018ec901a1b218d46c7 --- /dev/null +++ b/test/unittest/file_uri_native/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2023 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. + +import("//build/test.gni") + +ohos_unittest("file_uri_test") { + module_out_path = "filemanagement/app_file_service" + sources = [ "file_uri_test.cpp" ] + deps = [ "//third_party/googletest:gtest_main" ] + external_deps = [ + "app_file_service:fileuri_native", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4099e59baa14c38e0b57d9e489cbb58495118f64 --- /dev/null +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "file_uri.h" + +namespace { + using namespace std; + using namespace OHOS::AppFileService::ModuleFileUri; + + class FileUriTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: File_Uri_TransToFileUri_0000 + * @tc.desc: Test function of TransToFileUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0000"; + string dataShareUri = "datashare://1002/media/image/12"; + string resultUri = "file://media/image/12#networkid=1002"; + string fileuri = FileUri::TransToFileUri(dataShareUri); + ASSERT_TRUE(!fileuri.empty()) << "fileuri is empty!"; + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0000"; + } + + /** + * @tc.name: File_Uri_TransToFileUri_0001 + * @tc.desc: Test function of TransToFileUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0001"; + string dataShareUri = "datashare:///media/image/12"; + string resultUri = "file://media/image/12"; + string fileuri = FileUri::TransToFileUri(dataShareUri); + ASSERT_TRUE(!fileuri.empty()) << "fileuri is empty!"; + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0001"; + } + + /** + * @tc.name: File_Uri_TransToFileUri_0002 + * @tc.desc: Test function of TransToFileUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0002"; + string dataShareUri = "datashare:////#fdFromBinder=12"; + string resultUri = "file:////#fdFromBinder=12"; + string fileuri = FileUri::TransToFileUri(dataShareUri); + ASSERT_TRUE(!fileuri.empty()) << "fileuri is empty!"; + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0002"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0003 + * @tc.desc: Test function of TransToDataShareUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0003"; + string fileuri = "file://media/image/12#networkid=1002"; + string resultUri = "datashare://1002/media/image/12"; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + ASSERT_TRUE(!dataShareUri.empty()) << "dataShareUri is empty!"; + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0003"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0004 + * @tc.desc: Test function of TransToDataShareUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0004, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0004"; + string fileuri = "file://media/image/12"; + string resultUri = "datashare:///media/image/12"; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + ASSERT_TRUE(!dataShareUri.empty()) << "dataShareUri is empty!"; + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0004"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0005 + * @tc.desc: Test function of TransToDataShareUri() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0005, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0005"; + string fileuri = "file:////#fdFromBinder=12"; + string resultUri = "datashare:////#fdFromBinder=12"; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + ASSERT_TRUE(!dataShareUri.empty()) << "dataShareUri is empty!"; + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0005"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0006 + * @tc.desc: Test function of TransToDataShareUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0006, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0006"; + string fileuri = "file://"; + string resultUri = ""; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0006"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0007 + * @tc.desc: Test function of TransToDataShareUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0007, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0007"; + string fileuri = "file:/media/image/12"; + string resultUri = ""; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0007"; + } + + /** + * @tc.name: File_Uri_TransToDataShareUri_0008 + * @tc.desc: Test function of TransToDataShareUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToDataShareUri_0008, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToDataShareUri_0008"; + string fileuri = "fil://media/image/12"; + string resultUri = ""; + string dataShareUri = FileUri::TransToDataShareUri(fileuri); + EXPECT_EQ(dataShareUri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToDataShareUri_0008"; + } + + /** + * @tc.name: File_Uri_TransToFileUri_0009 + * @tc.desc: Test function of TransToFileUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0009, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0009"; + string dataShareUri = "datashare:////"; + string resultUri = ""; + string fileuri = FileUri::TransToFileUri(dataShareUri); + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0009"; + } + + /** + * @tc.name: File_Uri_TransToFileUri_0010 + * @tc.desc: Test function of TransToFileUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0010, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0010"; + string dataShareUri = "datashare:/media/image/12"; + string resultUri = ""; + string fileuri = FileUri::TransToFileUri(dataShareUri); + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0010"; + } + + /** + * @tc.name: File_Uri_TransToFileUri_0011 + * @tc.desc: Test function of TransToFileUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(FileUriTest, File_Uri_TransToFileUri_0011, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_TransToFileUri_0011"; + string dataShareUri = "datashar:///media/image/12"; + string resultUri = ""; + string fileuri = FileUri::TransToFileUri(dataShareUri); + EXPECT_EQ(fileuri, resultUri); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_TransToFileUri_0011"; + } +} \ No newline at end of file