From f62c98107e7104a90782aa114a74db2422fc56a9 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 07:32:55 +0000 Subject: [PATCH 1/9] add properties tdd Signed-off-by: yangbiao59 --- interfaces/test/unittest/BUILD.gn | 1 + interfaces/test/unittest/fs/BUILD.gn | 69 +++++++++ .../fs/mod_fs/properties/access_core_test.cpp | 138 ++++++++++++++++++ .../fs/mod_fs/properties/mock/uv_fs_mock.cpp | 30 ++++ .../fs/mod_fs/properties/mock/uv_fs_mock.h | 50 +++++++ .../fs/mod_fs/properties/read_core_test.cpp | 124 ++++++++++++++++ 6 files changed, 412 insertions(+) create mode 100644 interfaces/test/unittest/fs/BUILD.gn create mode 100644 interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp create mode 100644 interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp create mode 100644 interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h create mode 100644 interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index ec75efa72..3a6c6eb26 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -16,6 +16,7 @@ group("file_api_unittest") { deps = [ "class_file:class_file_test", "filemgmt_libn_test:filemgmt_libn_test", + "js:ani_file_fs_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", ] diff --git a/interfaces/test/unittest/fs/BUILD.gn b/interfaces/test/unittest/fs/BUILD.gn new file mode 100644 index 000000000..bffa96325 --- /dev/null +++ b/interfaces/test/unittest/fs/BUILD.gn @@ -0,0 +1,69 @@ +# 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. + +import("//build/test.gni") +import("//foundation/filemanagement/file_api/file_api.gni") + +ohos_unittest("ani_file_fs_test") { + branch_protector_ret = "pac_ret" + testonly = true + + module_out_path = "file_api/file_api" + include_dirs = [ + "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", + "mock/uv_fs_read_mock.h", + ] + + sources = [ + "mock/uv_fs_mock.cpp", + "access_core_test.cpp", + "read_core_test.cpp", + ] + + deps = [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/native:task_signal_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${file_api_path}/interfaces/kits/js:ani_file_fs", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "app_file_service:fileuri_native", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", + "dfs_service:distributed_file_daemon_kit_inner", + "dfs_service:libdistributedfileutils", + "eventhandler:libeventhandler", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + "samgr:samgr_proxy", + ] + + defines = [ + "private=public", + ] + + cflags_cc = [ "-DENABLE_NAPI_MOCK" ] +} \ No newline at end of file diff --git a/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp b/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp new file mode 100644 index 000000000..913df19e9 --- /dev/null +++ b/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp @@ -0,0 +1,138 @@ +/* + * 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 "access_core.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class AccessCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void AccessCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void AccessCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void AccessCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void AccessCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_001 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_001"; + + std::string path; + std::optional mode; + + auto res = AccessCore::DoAccess(path, mode); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_001"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_002 + * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_002"; + + std::string path = "TEST"; + std::optional mode; + + auto res = AccessCore::DoAccess(path, mode); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_002"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_003 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_003"; + + std::string path = ""; + AccessModeType mode = AccessModeType::EXIST; + AccessFlag flag = DEFAULT_FLAG; + + auto res = AccessCore::DoAccess(path, mode, flag); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_003"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_004 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_004"; + + std::string path = "TEST"; + AccessModeType mode = AccessModeType::EXIST; + AccessFlag flag = DEFAULT_FLAG; + + auto res = AccessCore::DoAccess(path, mode, flag); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_004"; +} + + +} // OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp new file mode 100644 index 000000000..ae04aab30 --- /dev/null +++ b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp @@ -0,0 +1,30 @@ +/* + * 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 "uv_fs_mock.h" + + +using namespace OHOS::FileManagement::ModuleFileIO; + +int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_read(loop, req, file, bufs, nbufs, off, cb); +} diff --git a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h new file mode 100644 index 000000000..ea884c5c2 --- /dev/null +++ b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h @@ -0,0 +1,50 @@ +/* + * 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 UV_FS_MOCK_H +#define UV_FS_MOCK_H + +#include "read_core.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO { + +class Uvfs { +public: + static inline std::shared_ptr ins = nullptr; +public: + virtual ~Uvfs() = default; + virtual int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb) = 0; +}; + +class UvfsMock : public Uvfs { +public: + MOCK_METHOD7(uv_fs_read, int(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb)); +}; + + +} // OHOS::FileManagement::ModuleFileIO +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp b/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp new file mode 100644 index 000000000..c4dfda62e --- /dev/null +++ b/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp @@ -0,0 +1,124 @@ +/* + * 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 "read_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class ReadCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ReadCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void ReadCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void ReadCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void ReadCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_001 + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_001"; + + int32_t fd = -1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_001"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_002 + * @tc.desc: Test function of ReadCore::DoRead interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_002"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + + int32_t fd = 1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_002"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_003 + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_005"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(1)); + + int32_t fd = 1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From b7698399e78e7fc8664884fc9a247d410d79f930 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:10:39 +0000 Subject: [PATCH 2/9] modify Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 69 +++++++++ .../js/mod_fs/properties/access_core_test.cpp | 138 ++++++++++++++++++ .../js/mod_fs/properties/mock/uv_fs_mock.cpp | 30 ++++ .../js/mod_fs/properties/mock/uv_fs_mock.h | 50 +++++++ .../js/mod_fs/properties/read_core_test.cpp | 124 ++++++++++++++++ 5 files changed, 411 insertions(+) create mode 100644 interfaces/test/unittest/js/BUILD.gn create mode 100644 interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h create mode 100644 interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn new file mode 100644 index 000000000..bffa96325 --- /dev/null +++ b/interfaces/test/unittest/js/BUILD.gn @@ -0,0 +1,69 @@ +# 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. + +import("//build/test.gni") +import("//foundation/filemanagement/file_api/file_api.gni") + +ohos_unittest("ani_file_fs_test") { + branch_protector_ret = "pac_ret" + testonly = true + + module_out_path = "file_api/file_api" + include_dirs = [ + "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", + "mock/uv_fs_read_mock.h", + ] + + sources = [ + "mock/uv_fs_mock.cpp", + "access_core_test.cpp", + "read_core_test.cpp", + ] + + deps = [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/native:task_signal_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${file_api_path}/interfaces/kits/js:ani_file_fs", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "app_file_service:fileuri_native", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", + "dfs_service:distributed_file_daemon_kit_inner", + "dfs_service:libdistributedfileutils", + "eventhandler:libeventhandler", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + "samgr:samgr_proxy", + ] + + defines = [ + "private=public", + ] + + cflags_cc = [ "-DENABLE_NAPI_MOCK" ] +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp new file mode 100644 index 000000000..913df19e9 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp @@ -0,0 +1,138 @@ +/* + * 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 "access_core.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class AccessCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void AccessCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void AccessCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void AccessCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void AccessCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_001 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_001"; + + std::string path; + std::optional mode; + + auto res = AccessCore::DoAccess(path, mode); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_001"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_002 + * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_002"; + + std::string path = "TEST"; + std::optional mode; + + auto res = AccessCore::DoAccess(path, mode); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_002"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_003 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_003"; + + std::string path = ""; + AccessModeType mode = AccessModeType::EXIST; + AccessFlag flag = DEFAULT_FLAG; + + auto res = AccessCore::DoAccess(path, mode, flag); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_003"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_004 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_004"; + + std::string path = "TEST"; + AccessModeType mode = AccessModeType::EXIST; + AccessFlag flag = DEFAULT_FLAG; + + auto res = AccessCore::DoAccess(path, mode, flag); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_004"; +} + + +} // OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp new file mode 100644 index 000000000..ae04aab30 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp @@ -0,0 +1,30 @@ +/* + * 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 "uv_fs_mock.h" + + +using namespace OHOS::FileManagement::ModuleFileIO; + +int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_read(loop, req, file, bufs, nbufs, off, cb); +} diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h new file mode 100644 index 000000000..ea884c5c2 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h @@ -0,0 +1,50 @@ +/* + * 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 UV_FS_MOCK_H +#define UV_FS_MOCK_H + +#include "read_core.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO { + +class Uvfs { +public: + static inline std::shared_ptr ins = nullptr; +public: + virtual ~Uvfs() = default; + virtual int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb) = 0; +}; + +class UvfsMock : public Uvfs { +public: + MOCK_METHOD7(uv_fs_read, int(uv_loop_t* loop, uv_fs_t* req, + uv_file file, + const uv_buf_t bufs[], + unsigned int nbufs, + int64_t off, + uv_fs_cb cb)); +}; + + +} // OHOS::FileManagement::ModuleFileIO +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp new file mode 100644 index 000000000..c4dfda62e --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp @@ -0,0 +1,124 @@ +/* + * 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 "read_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class ReadCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ReadCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void ReadCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void ReadCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void ReadCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_001 + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_001"; + + int32_t fd = -1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_001"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_002 + * @tc.desc: Test function of ReadCore::DoRead interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_002"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + + int32_t fd = 1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_002"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_003 + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_005"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(1)); + + int32_t fd = 1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 92dff69dd716ea24ebe4c6fddbe255b304999843 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:11:20 +0000 Subject: [PATCH 3/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inte?= =?UTF-8?q?rfaces/test/unittest/fs/BUILD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/test/unittest/fs/BUILD.gn | 69 ---------------------------- 1 file changed, 69 deletions(-) delete mode 100644 interfaces/test/unittest/fs/BUILD.gn diff --git a/interfaces/test/unittest/fs/BUILD.gn b/interfaces/test/unittest/fs/BUILD.gn deleted file mode 100644 index bffa96325..000000000 --- a/interfaces/test/unittest/fs/BUILD.gn +++ /dev/null @@ -1,69 +0,0 @@ -# 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. - -import("//build/test.gni") -import("//foundation/filemanagement/file_api/file_api.gni") - -ohos_unittest("ani_file_fs_test") { - branch_protector_ret = "pac_ret" - testonly = true - - module_out_path = "file_api/file_api" - include_dirs = [ - "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", - "mock/uv_fs_read_mock.h", - ] - - sources = [ - "mock/uv_fs_mock.cpp", - "access_core_test.cpp", - "read_core_test.cpp", - ] - - deps = [ - "${file_api_path}/interfaces/kits/native:remote_uri_native", - "${file_api_path}/interfaces/kits/native:task_signal_native", - "${file_api_path}/interfaces/kits/rust:rust_file", - "${utils_path}/filemgmt_libfs:filemgmt_libfs", - "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", - "${file_api_path}/interfaces/kits/js:ani_file_fs", - ] - - external_deps = [ - "ability_runtime:ability_manager", - "app_file_service:fileuri_native", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "dfs_service:distributed_file_daemon_kit_inner", - "dfs_service:libdistributedfileutils", - "eventhandler:libeventhandler", - "googletest:gmock_main", - "googletest:gtest_main", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "libuv:uv", - "runtime_core:ani", - "runtime_core:libarkruntime", - "samgr:samgr_proxy", - ] - - defines = [ - "private=public", - ] - - cflags_cc = [ "-DENABLE_NAPI_MOCK" ] -} \ No newline at end of file -- Gitee From 51d7b3cd269937e4495c3283767fbb9bcccd0e7a Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:13:06 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inte?= =?UTF-8?q?rfaces/test/unittest/fs/mod=5Ffs/properties/access=5Fcore=5Ftes?= =?UTF-8?q?t.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/mod_fs/properties/access_core_test.cpp | 138 ------------------ 1 file changed, 138 deletions(-) delete mode 100644 interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp diff --git a/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp b/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp deleted file mode 100644 index 913df19e9..000000000 --- a/interfaces/test/unittest/fs/mod_fs/properties/access_core_test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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 "access_core.h" - -#include -#include - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class AccessCoreTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void AccessCoreTest::SetUpTestCase(void) -{ - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void AccessCoreTest::TearDownTestCase(void) -{ - GTEST_LOG_(INFO) << "TearDownTestCase"; -} - -void AccessCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void AccessCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: AccessCoreTest_DoAccess_001 - * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_001"; - - std::string path; - std::optional mode; - - auto res = AccessCore::DoAccess(path, mode); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_001"; -} - -/** - * @tc.name: AccessCoreTest_DoAccess_002 - * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_002"; - - std::string path = "TEST"; - std::optional mode; - - auto res = AccessCore::DoAccess(path, mode); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_002"; -} - -/** - * @tc.name: AccessCoreTest_DoAccess_003 - * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_003"; - - std::string path = ""; - AccessModeType mode = AccessModeType::EXIST; - AccessFlag flag = DEFAULT_FLAG; - - auto res = AccessCore::DoAccess(path, mode, flag); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_003"; -} - -/** - * @tc.name: AccessCoreTest_DoAccess_004 - * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_004"; - - std::string path = "TEST"; - AccessModeType mode = AccessModeType::EXIST; - AccessFlag flag = DEFAULT_FLAG; - - auto res = AccessCore::DoAccess(path, mode, flag); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_004"; -} - - -} // OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 0bc75eb13de3a150a9c9683a2020fa86e776bdb2 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:13:55 +0000 Subject: [PATCH 5/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inte?= =?UTF-8?q?rfaces/test/unittest/fs/mod=5Ffs/properties/read=5Fcore=5Ftest.?= =?UTF-8?q?cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/mod_fs/properties/read_core_test.cpp | 124 ------------------ 1 file changed, 124 deletions(-) delete mode 100644 interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp diff --git a/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp b/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp deleted file mode 100644 index c4dfda62e..000000000 --- a/interfaces/test/unittest/fs/mod_fs/properties/read_core_test.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - * 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 "read_core.h" -#include "mock/uv_fs_mock.h" - -#include -#include - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class ReadCoreTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void ReadCoreTest::SetUpTestCase(void) -{ - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void ReadCoreTest::TearDownTestCase(void) -{ - GTEST_LOG_(INFO) << "TearDownTestCase"; -} - -void ReadCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void ReadCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: ReadCoreTest_DoRead_001 - * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_001"; - - int32_t fd = -1; - void *buf = nullptr; - ArrayBuffer arrayBuffer(buf, 0); - - auto res = ReadCore::DoRead(fd, arrayBuffer); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_001"; -} - -/** - * @tc.name: ReadCoreTest_DoRead_002 - * @tc.desc: Test function of ReadCore::DoRead interface for FALSE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_002"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(-1)); - - int32_t fd = 1; - void *buf = nullptr; - ArrayBuffer arrayBuffer(buf, 0); - auto res = ReadCore::DoRead(fd, arrayBuffer); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_002"; -} - -/** - * @tc.name: ReadCoreTest_DoRead_003 - * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_005"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(1)); - - int32_t fd = 1; - void *buf = nullptr; - ArrayBuffer arrayBuffer(buf, 0); - auto res = ReadCore::DoRead(fd, arrayBuffer); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_003"; -} - -} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 515d4cdaed8217f035d0ecdf8c5931217f34e36b Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:14:09 +0000 Subject: [PATCH 6/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inte?= =?UTF-8?q?rfaces/test/unittest/fs/mod=5Ffs/properties/mock/uv=5Ffs=5Fmock?= =?UTF-8?q?.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/mod_fs/properties/mock/uv_fs_mock.cpp | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp diff --git a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp deleted file mode 100644 index ae04aab30..000000000 --- a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 "uv_fs_mock.h" - - -using namespace OHOS::FileManagement::ModuleFileIO; - -int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, - uv_file file, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t off, - uv_fs_cb cb) -{ - return Uvfs::ins->uv_fs_read(loop, req, file, bufs, nbufs, off, cb); -} -- Gitee From b96bfa3ddc7617a1568ecc08e0bbd10f2a8d1c7b Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 09:14:24 +0000 Subject: [PATCH 7/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20inte?= =?UTF-8?q?rfaces/test/unittest/fs/mod=5Ffs/properties/mock/uv=5Ffs=5Fmock?= =?UTF-8?q?.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fs/mod_fs/properties/mock/uv_fs_mock.h | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h diff --git a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h b/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h deleted file mode 100644 index ea884c5c2..000000000 --- a/interfaces/test/unittest/fs/mod_fs/properties/mock/uv_fs_mock.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 UV_FS_MOCK_H -#define UV_FS_MOCK_H - -#include "read_core.h" - -#include - -namespace OHOS::FileManagement::ModuleFileIO { - -class Uvfs { -public: - static inline std::shared_ptr ins = nullptr; -public: - virtual ~Uvfs() = default; - virtual int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, - uv_file file, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t off, - uv_fs_cb cb) = 0; -}; - -class UvfsMock : public Uvfs { -public: - MOCK_METHOD7(uv_fs_read, int(uv_loop_t* loop, uv_fs_t* req, - uv_file file, - const uv_buf_t bufs[], - unsigned int nbufs, - int64_t off, - uv_fs_cb cb)); -}; - - -} // OHOS::FileManagement::ModuleFileIO -#endif \ No newline at end of file -- Gitee From ec9e8e93f105e5a1b0709d41f390d0424cea83c7 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 10:17:55 +0000 Subject: [PATCH 8/9] update interfaces/test/unittest/js/BUILD.gn. Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index bffa96325..8b2275489 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -25,7 +25,7 @@ ohos_unittest("ani_file_fs_test") { ] sources = [ - "mock/uv_fs_mock.cpp", + "mod_fs/properties/mock/uv_fs_mock.cpp", "access_core_test.cpp", "read_core_test.cpp", ] -- Gitee From 140e07df6d560f9ecc3c96a2265321c08086b1f6 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 7 May 2025 10:38:29 +0000 Subject: [PATCH 9/9] update interfaces/test/unittest/js/BUILD.gn. Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index 8b2275489..340a55c01 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -26,8 +26,8 @@ ohos_unittest("ani_file_fs_test") { sources = [ "mod_fs/properties/mock/uv_fs_mock.cpp", - "access_core_test.cpp", - "read_core_test.cpp", + "mod_fs/properties/access_core_test.cpp", + "mod_fs/properties/read_core_test.cpp", ] deps = [ -- Gitee