From 4eda902aa13ac294128ce8873438f0fbbb68a4e1 Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Sat, 18 Jan 2025 19:00:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E8=BA=AB=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E8=8E=B7=E5=8F=96uri=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=20Signed-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unittest/file_uri_native/BUILD.gn | 9 ++++- .../include/common_mock.h | 37 +++++++++++++++++++ .../src/common_mock.cpp | 31 ++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/mock/file_uri_Common_Func_mock/include/common_mock.h create mode 100644 tests/mock/file_uri_Common_Func_mock/src/common_mock.cpp diff --git a/test/unittest/file_uri_native/BUILD.gn b/test/unittest/file_uri_native/BUILD.gn index 447faf2f7..10cb53bbe 100644 --- a/test/unittest/file_uri_native/BUILD.gn +++ b/test/unittest/file_uri_native/BUILD.gn @@ -24,7 +24,14 @@ ohos_unittest("file_uri_test") { module_out_path = "filemanagement/app_file_service" resource_config_file = "../resource/ohos_test.xml" - sources = [ "file_uri_test.cpp" ] + include_dirs = [ + "${app_file_service_path}/tests/mock/file_uri_Common_Func_mock/include/common_mock.h", + "//third_party/googletest/include", + ] + sources = [ + "file_uri_test.cpp", + "${app_file_service_path}/tests/mock/file_uri_Common_Func_mock/src/upms_mock.cpp", + ] external_deps = [ "ability_base:base", diff --git a/tests/mock/file_uri_Common_Func_mock/include/common_mock.h b/tests/mock/file_uri_Common_Func_mock/include/common_mock.h new file mode 100644 index 000000000..f58a3e830 --- /dev/null +++ b/tests/mock/file_uri_Common_Func_mock/include/common_mock.h @@ -0,0 +1,37 @@ +/* +* 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 FILEMANAGEMENT_APP_FILE_SERVICE_COMMON_MOCK_H +#define FILEMANAGEMENT_APP_FILE_SERVICE_COMMON_MOCK_H +#include +#include "b_error/b_error.h" + +namespace OHOS { +namespace AppFileService { +class CommonFunMock { +public: + virtual ~CommonFunMock() = default; + virtual ErrCode GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex, std::string &dirName) = 0; + static inline std::shared_ptr commonFunManagerKitMock = nullptr; +}; + +class commonFunMock : public CommonFunMock { +public: + MOCK_METHOD2(GetDirByBundleNameAndAppIndex, ErrCode(const std::string &bundleName, const int32_t appIndex, std::string &dirName); +}; +} // namespace AppFileService +} // namespace OHOS + +#endif // FILEMANAGEMENT_APP_FILE_SERVICE_COMMON_MOCK_H diff --git a/tests/mock/file_uri_Common_Func_mock/src/common_mock.cpp b/tests/mock/file_uri_Common_Func_mock/src/common_mock.cpp new file mode 100644 index 000000000..3d5afd07d --- /dev/null +++ b/tests/mock/file_uri_Common_Func_mock/src/common_mock.cpp @@ -0,0 +1,31 @@ +/* +* 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 "common_mock.h" +#include "bundle_mgr_client.h" + +namespace OHOS { +using namespace AppFileService; +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +BundleMgrClient &BundleMgrClient::GetInstance() +{ + return nullptr; +} +ErrCode BundleMgrClient::GetDirByBundleNameAndAppIndex(const std::string &bundleName, const int32_t appIndex, std::string &dirName) +{ + return -1; +} + +} // namespace OHOS \ No newline at end of file -- Gitee