diff --git a/test/unittest/file_uri_native/BUILD.gn b/test/unittest/file_uri_native/BUILD.gn index 447faf2f7e33bd5492a2f0a20c2d2a6c8e975976..10cb53bbefb52803a3bee53dcd56c277c4bdb3e8 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 0000000000000000000000000000000000000000..f58a3e8307a11646cb158c46c1391d92eba961a8 --- /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 0000000000000000000000000000000000000000..3d5afd07d23a4e506c368e25eff1b42ad71cc976 --- /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