From 48d30364c557a7df0a828a41698940058b3c76f1 Mon Sep 17 00:00:00 2001 From: liyuke Date: Tue, 20 May 2025 12:19:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?tdd=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- .../src/mod_fs/properties/ani/mkdir_ani.cpp | 2 + .../js/src/mod_fs/properties/ani/mkdir_ani.h | 6 +- .../src/mod_fs/properties/ani/movedir_ani.cpp | 2 +- .../mod_fs/properties/ani/read_lines_ani.cpp | 5 +- .../mod_fs/properties/ani/read_lines_ani.h | 6 +- .../src/mod_fs/properties/ani/unlink_ani.cpp | 2 +- .../js/src/mod_fs/properties/ani/unlink_ani.h | 6 +- .../src/mod_fs/properties/ani/xattr_ani.cpp | 6 +- .../src/mod_fs/properties/fdatasync_core.cpp | 1 - .../js/src/mod_fs/properties/fdatasync_core.h | 2 +- .../js/src/mod_fs/properties/mkdir_core.h | 2 +- .../js/src/mod_fs/properties/mkdtemp_core.h | 2 +- .../js/src/mod_fs/properties/movedir_core.h | 1 - .../src/mod_fs/properties/read_lines_core.cpp | 12 +- .../src/mod_fs/properties/read_lines_core.h | 1 - .../js/src/mod_fs/properties/unlink_core.cpp | 6 +- .../js/src/mod_fs/properties/unlink_core.h | 2 +- interfaces/test/unittest/js/BUILD.gn | 11 +- .../mod_fs/properties/fdatasync_core_test.cpp | 111 ++++++++ .../js/mod_fs/properties/mkdir_core_test.cpp | 188 +++++++++++++ .../mod_fs/properties/mkdtemp_core_test.cpp | 110 ++++++++ .../js/mod_fs/properties/mock/system_mock.cpp | 28 ++ .../js/mod_fs/properties/mock/system_mock.h | 40 +++ .../js/mod_fs/properties/mock/uv_fs_mock.cpp | 64 +++-- .../js/mod_fs/properties/mock/uv_fs_mock.h | 93 +++---- .../mod_fs/properties/movedir_core_test.cpp | 258 ++++++++++++++++++ .../properties/read_lines_core_test.cpp | 176 ++++++++++++ .../js/mod_fs/properties/unlink_core_test.cpp | 107 ++++++++ .../js/mod_fs/properties/xattr_core_test.cpp | 169 ++++++++++++ 29 files changed, 1312 insertions(+), 107 deletions(-) create mode 100644 interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h create mode 100644 interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp index a5cd88374..2a9b29bcf 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp @@ -33,6 +33,7 @@ void MkdirkAni::MkdirSync0(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s ErrorHandler::Throw(env, EINVAL); return; } + auto ret = MkdirCore::DoMkdir(pathStr); if (!ret.IsSuccess()) { HILOGE("Mkdir failed"); @@ -50,6 +51,7 @@ void MkdirkAni::MkdirSync1(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s ErrorHandler::Throw(env, EINVAL); return; } + auto ret = MkdirCore::DoMkdir(pathStr, recursion); if (!ret.IsSuccess()) { HILOGE("DoMkdir failed"); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h index 8ed780e96..195d0db00 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H #include @@ -34,4 +34,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp index 33bfb77cf..77633e1b5 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp @@ -129,7 +129,7 @@ void MoveDirAni::MoveDirSync( auto [succMode, optMode] = TypeConverter::ToOptionalInt32(env, mode); if (!succMode) { - HILOGE("Failed to convert mode to int32"); + HILOGE("Invalid mode"); ErrorHandler::Throw(env, EINVAL); return; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp index 49b26f784..10c3ce394 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp @@ -53,7 +53,7 @@ ani_object ReadLinesAni::ReadLinesSync( { auto [succPath, filePath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { - HILOGE("Invalid path"); + HILOGE("Invalid path from ETS first argument"); ErrorHandler::Throw(env, EINVAL); return nullptr; } @@ -64,6 +64,7 @@ ani_object ReadLinesAni::ReadLinesSync( ErrorHandler::Throw(env, EINVAL); return nullptr; } + FsResult ret = ReadLinesCore::DoReadLines(filePath, opt); if (!ret.IsSuccess()) { HILOGE("Readlines failed"); @@ -71,6 +72,7 @@ ani_object ReadLinesAni::ReadLinesSync( ErrorHandler::Throw(env, err); return nullptr; } + const FsReaderIterator *readerIterator = ret.GetData().value(); auto result = ReaderIteratorAni::Wrap(env, move(readerIterator)); if (result == nullptr) { @@ -79,6 +81,7 @@ ani_object ReadLinesAni::ReadLinesSync( } return result; } + } // namespace ANI } // namespace ModuleFileIO } // namespace FileManagement diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h index 387298f81..3f1bfeb72 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H #include @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp index 91a929d13..763d6e72e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp @@ -29,7 +29,7 @@ void UnlinkAni::UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s { auto [succ, pathStr] = TypeConverter::ToUTF8String(env, path); if (!succ) { - HILOGE("Invalid path"); + HILOGE("Invalid path from ETS first argument"); ErrorHandler::Throw(env, EINVAL); return; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h index 817b25800..64aee8bd1 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H #include @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp index 47e6d92a5..2a69e0bd2 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp @@ -37,14 +37,14 @@ void XattrAni::SetXattrSync( auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); if (!keySucc) { - HILOGE("Invalid key"); + HILOGE("Invalid xattr key"); ErrorHandler::Throw(env, EINVAL); return; } auto [valueSucc, valueStr] = TypeConverter::ToUTF8String(env, value); if (!valueSucc) { - HILOGE("Invalid value"); + HILOGE("Invalid xattr value"); ErrorHandler::Throw(env, EINVAL); return; } @@ -69,7 +69,7 @@ ani_string XattrAni::GetXattrSync(ani_env *env, [[maybe_unused]] ani_class clazz auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); if (!keySucc) { - HILOGE("Invalid key"); + HILOGE("Invalid xattr key"); ErrorHandler::Throw(env, EINVAL); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp index 57b479f2b..38996fda0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp @@ -24,7 +24,6 @@ #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::ModuleFileIO { -using namespace std; FsResult FDataSyncCore::DoFDataSync(const int32_t &fd) { diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h index 8efb6f907..5e26c9140 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h @@ -24,6 +24,6 @@ class FDataSyncCore final { public: static FsResult DoFDataSync(const int32_t &fd); }; -const std::string PROCEDURE_FDATASYNC_NAME = "FileIOFdatasync"; + } // namespace OHOS::FileManagement::ModuleFileIO #endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_FDATASYNC_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h index cc6793693..46bc81a70 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h @@ -28,7 +28,7 @@ public: static FsResult DoMkdir(const std::string& path, std::optional recursion = std::nullopt); }; constexpr int DIR_DEFAULT_PERM = 0770; -const std::string PROCEDURE_READTEXT_NAME = "FileIOMkdir"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h index e638655ba..df936597f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h @@ -27,7 +27,7 @@ class MkdtempCore final { public: static FsResult DoMkdtemp(const std::string &path); }; -const std::string PROCEDURE_MKDTEMP_NAME = "FileIOMkdtemp"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir_core.h b/interfaces/kits/js/src/mod_fs/properties/movedir_core.h index e4db3553d..f10eaa532 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.h @@ -58,7 +58,6 @@ public: const std::string &src, const std::string &dest, std::optional mode = std::nullopt); }; -const std::string PROCEDURE_MOVEDIR_NAME = "FileIOMoveDir"; } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp index 819215c30..1f9869151 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp @@ -25,9 +25,9 @@ namespace FileManagement { namespace ModuleFileIO { using namespace std; -static int CheckOptionArg(optional option) +static int CheckOptionArg(Options option) { - auto encoding = option->encoding; + auto encoding = option.encoding; if (encoding != "utf-8") { return EINVAL; } @@ -79,7 +79,7 @@ static FsResult InstantiateReaderIterator(void *iterator, in FsResult ReadLinesCore::DoReadLines(const string &path, optional option) { if (option.has_value()) { - int ret = CheckOptionArg(option); + int ret = CheckOptionArg(option.value()); if (ret) { HILOGE("Invalid option.encoding parameter"); return FsResult::Error(ret); @@ -98,11 +98,7 @@ FsResult ReadLinesCore::DoReadLines(const string &path, opti HILOGE("Failed to get size of the file"); return FsResult::Error(ret); } - auto readeriterator = InstantiateReaderIterator(iterator, offset); - if (!readeriterator.IsSuccess()) { - return FsResult::Error(ENOMEM); - } - return FsResult::Success(readeriterator.GetData().value()); + return InstantiateReaderIterator(iterator, offset); } } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h index a450cc431..67cae2c52 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h @@ -37,7 +37,6 @@ public: const std::string &path, std::optional option = std::nullopt); }; -const std::string PROCEDURE_READLINES_NAME = "FileIOReadLines"; } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp index ecb92452e..339b56db0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp @@ -28,13 +28,13 @@ using namespace std; FsResult UnlinkCore::DoUnlink(const std::string &src) { - std::unique_ptr unlink_req = { + std::unique_ptr unlinkReq = { new uv_fs_t, FsUtils::FsReqCleanup }; - if (!unlink_req) { + if (!unlinkReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); } - int ret = uv_fs_unlink(nullptr, unlink_req.get(), src.c_str(), nullptr); + int ret = uv_fs_unlink(nullptr, unlinkReq.get(), src.c_str(), nullptr); if (ret < 0) { HILOGD("Failed to unlink with path"); return FsResult::Error(ret); diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.h b/interfaces/kits/js/src/mod_fs/properties/unlink_core.h index b2ea553f4..5989bbda2 100755 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.h @@ -27,7 +27,7 @@ class UnlinkCore final { public: static FsResult DoUnlink(const std::string &src); }; -const std::string PROCEDURE_READTEXT_NAME = "FileIOUnlink"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index e4e6a9d52..bd5883c79 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -22,19 +22,28 @@ ohos_unittest("ani_file_fs_test") { include_dirs = [ "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", - "mock/uv_fs_mock.h", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_readeriterator", + "${file_api_path}/interfaces/test/unittest/js/mod_fs/properties/mock", ] sources = [ "mod_fs/properties/mock/uv_fs_mock.cpp", + "mod_fs/properties/mock/system_mock.cpp", "mod_fs/properties/access_core_test.cpp", "mod_fs/properties/dup_core_test.cpp", + "mod_fs/properties/fdatasync_core_test.cpp", + "mod_fs/properties/mkdir_core_test.cpp", + "mod_fs/properties/mkdtemp_core_test.cpp", + "mod_fs/properties/movedir_core_test.cpp", "mod_fs/properties/read_core_test.cpp", + "mod_fs/properties/read_lines_core_test.cpp", "mod_fs/properties/rmdir_core_test.cpp", "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_test.cpp", + "mod_fs/properties/unlink_core_test.cpp", "mod_fs/properties/utimes_core_test.cpp", "mod_fs/properties/write_core_test.cpp", + "mod_fs/properties/xattr_core_test.cpp", ] deps = [ diff --git a/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp new file mode 100644 index 000000000..f2e6acdf7 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp @@ -0,0 +1,111 @@ +/* + * 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 +#include +#include +#include + +#include "fdatasync_core.h" +#include "mock/uv_fs_mock.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class FDataSyncCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path FDataSyncCoreTest::tempFilePath; + +void FDataSyncCoreTest::SetUpTestCase(void) +{ + tempFilePath = filesystem::temp_directory_path() / "fdatasync_test_file.txt"; + ofstream(tempFilePath) << "Test content\n123\n456"; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void FDataSyncCoreTest::TearDownTestCase(void) +{ + filesystem::remove(tempFilePath); + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void FDataSyncCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void FDataSyncCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: FDataSyncCoreTest_DoFDataSync_001 + * @tc.desc: Test function of FDataSyncCore::DoFDataSync interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FDataSyncCoreTest, FDataSyncCoreTest_DoFDataSync_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreTest_DoFDataSync_001"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(1)); + + string path = tempFilePath.string(); + auto fd = open(path.c_str(), O_RDWR | O_CREAT, 0666); + auto res = FDataSyncCore::DoFDataSync(fd); + EXPECT_EQ(res.IsSuccess(), true); + close(fd); + + GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreTest_DoFDataSync_001"; +} + +/** + * @tc.name: FDataSyncCoreTest_DoFDataSync_002 + * @tc.desc: Test function of FDataSyncCore::DoFDataSync interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FDataSyncCoreTest, FDataSyncCoreTest_DoFDataSync_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreTest_DoFDataSync_002"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(-1)); + + string path = tempFilePath.string(); + auto fd = open(path.c_str(), O_RDWR | O_CREAT, 0666); + auto res = FDataSyncCore::DoFDataSync(fd); + EXPECT_EQ(res.IsSuccess(), false); + close(fd); + + GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreTest_DoFDataSync_002"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp new file mode 100644 index 000000000..5bfcfd69e --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp @@ -0,0 +1,188 @@ +/* + * 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 +#include +#include +#include + +#include "mkdir_core.h" +#include "mock/uv_fs_mock.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class MkdirCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path MkdirCoreTest::tempFilePath; + +void MkdirCoreTest::SetUpTestCase(void) +{ + tempFilePath = filesystem::temp_directory_path() / "test"; + std::filesystem::create_directory(tempFilePath); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void MkdirCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + filesystem::remove_all(tempFilePath); +} + +void MkdirCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void MkdirCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: MkdirCoreTest_DoMkdir_0001 + * @tc.desc: Test function of DoMkdir() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0001"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_mkdir(_, _, _, _, _)).WillOnce(Return(0)); + + string path = tempFilePath.string() + "/test01"; + auto ret = MkdirCore::DoMkdir(path); + EXPECT_EQ(ret.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0001"; +} + +/** + * @tc.name: MkdirCoreTest_DoMkdir_0002 + * @tc.desc: Test function of DoMkdir() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0002"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(-2)).WillOnce(Return(0)); + + string path = tempFilePath.string() + "/test02/testDir"; + auto ret = MkdirCore::DoMkdir(path, true); + EXPECT_EQ(ret.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0002"; +} + +/** + * @tc.name: MkdirCoreTest_DoMkdir_0003 + * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0003"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_mkdir(_, _, _, _, _)).WillOnce(Return(1)); + + string path = tempFilePath.string() + "/test03"; + auto ret = MkdirCore::DoMkdir(path); + EXPECT_EQ(ret.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0003"; +} + +/** + * @tc.name: MkdirCoreTest_DoMkdir_0004 + * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0004"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + + string path = "/"; + auto ret = MkdirCore::DoMkdir(path, true); + EXPECT_EQ(ret.IsSuccess(), false); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900015); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "File exists"); + + GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0004"; +} + +/** + * @tc.name: MkdirCoreTest_DoMkdir_0005 + * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0005"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(2)); + + string path = ""; + auto ret = MkdirCore::DoMkdir(path, true); + EXPECT_EQ(ret.IsSuccess(), false); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900002); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "No such file or directory"); + + GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0005"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp new file mode 100644 index 000000000..aacda7880 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp @@ -0,0 +1,110 @@ +/* + * 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 +#include +#include +#include + +#include "mkdtemp_core.h" +#include "mock/uv_fs_mock.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class MkdtempCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path MkdtempCoreTest::tempFilePath; + +void MkdtempCoreTest::SetUpTestCase(void) +{ + tempFilePath = filesystem::temp_directory_path() / "test"; + std::filesystem::create_directory(tempFilePath); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void MkdtempCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + filesystem::remove_all(tempFilePath); +} + +void MkdtempCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void MkdtempCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: MkdtempCoreTest_DoMkdtemp_0001 + * @tc.desc: Test function of DoMkdtemp() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdtempCoreTest, MkdtempCoreTest_DoMkdtemp_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdtempCoreTest-begin MkdtempCoreTest_DoMkdtemp_0001"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_mkdtemp(_, _, _, _)).WillOnce(Return(0)); + + string path = tempFilePath.string() + "/XXXXXX"; + auto ret = MkdtempCore::DoMkdtemp(path); + EXPECT_EQ(ret.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MkdtempCoreTest-end MkdtempCoreTest_DoMkdtemp_0001"; +} + +/** + * @tc.name: MkdtempCoreTest_DoMkdtemp_0002 + * @tc.desc: Test function of DoMkdtemp() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MkdtempCoreTest, MkdtempCoreTest_DoMkdtemp_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MkdtempCoreTest-begin MkdtempCoreTest_DoMkdtemp_0002"; + + string path = tempFilePath.string() + "/XXXXXX"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_mkdtemp(_, _, _, _)).WillOnce(Return(-1)); + + auto ret = MkdtempCore::DoMkdtemp(path); + EXPECT_EQ(ret.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MkdtempCoreTest-end MkdtempCoreTest_DoMkdtemp_0002"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp new file mode 100644 index 000000000..be0c39c07 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp @@ -0,0 +1,28 @@ +/* + * 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 "system_mock.h" + +using namespace OHOS::FileManagement::ModuleFileIO; + +int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) +{ + return System::ins->setxattr(path, name, value, size, flags); +} + +int getxattr(const char *path, const char *name, void *value, size_t size) +{ + return System::ins->getxattr(path, name, value, size); +} diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h new file mode 100644 index 000000000..b0c173f8e --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h @@ -0,0 +1,40 @@ +/* + * 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 INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H + +#include + +namespace OHOS::FileManagement::ModuleFileIO { + +class System { +public: + static inline std::shared_ptr ins = nullptr; + +public: + virtual ~System() = default; + virtual int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) = 0; + virtual int getxattr(const char *path, const char *name, void *value, size_t size) = 0; +}; + +class SystemMock : public System { +public: + MOCK_METHOD5(setxattr, int(const char *path, const char *name, const void *value, size_t size, int flags)); + MOCK_METHOD4(getxattr, int(const char *path, const char *name, void *value, size_t size)); +}; + +} // namespace OHOS::FileManagement::ModuleFileIO +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H \ 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 index c4f112268..1e6748f17 100644 --- 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 @@ -13,74 +13,90 @@ * 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) +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); } -int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) +int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { return Uvfs::ins->uv_fs_readlink(loop, req, path, cb); } -int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) +int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { return Uvfs::ins->uv_fs_stat(loop, req, path, cb); } -int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, - double mtime, uv_fs_cb cb) +int uv_fs_utime(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, double mtime, uv_fs_cb cb) { return Uvfs::ins->uv_fs_utime(loop, req, path, atime, mtime, cb); } -int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - uv_fs_cb cb) +int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) { return Uvfs::ins->uv_fs_scandir(loop, req, path, flags, cb); } -int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) +int uv_fs_scandir_next(uv_fs_t *req, uv_dirent_t *ent) { return Uvfs::ins->uv_fs_scandir_next(req, ent); } -int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) +int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { return Uvfs::ins->uv_fs_rmdir(loop, req, path, cb); } -int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, - const char* new_path, int flags, uv_fs_cb cb) +int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb) { return Uvfs::ins->uv_fs_symlink(loop, req, path, new_path, flags, cb); } -int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - int mode, uv_fs_cb cb) +int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb) { return Uvfs::ins->uv_fs_open(loop, req, path, flags, mode, cb); } -int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd, - int64_t offset, uv_fs_cb cb) +int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb) { return Uvfs::ins->uv_fs_ftruncate(loop, req, fd, offset, cb); } -int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[], - unsigned int nbufs, int64_t offset, uv_fs_cb cb) +int uv_fs_write( + uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb) { return Uvfs::ins->uv_fs_write(loop, req, fd, bufs, nbufs, offset, cb); } + +int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_fdatasync(loop, req, file, cb); +} + +int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_mkdir(loop, req, path, mode, cb); +} + +int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_access(loop, req, path, flags, cb); +} + +int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_mkdtemp(loop, req, tpl, cb); +} + +int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_unlink(loop, req, path, cb); +} + +void uv_fs_req_cleanup(uv_fs_t *req) {} 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 index ad0522f9e..06e3f9628 100644 --- 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UV_FS_READ_MOCK_H -#define UV_FS_READ_MOCK_H +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H #include "read_core.h" @@ -25,59 +25,54 @@ 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; - virtual int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, - uv_fs_cb cb) = 0; - virtual int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) = 0; - virtual int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, - double mtime, uv_fs_cb cb) = 0; - virtual int uv_fs_scandir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - uv_fs_cb cb) = 0; - virtual int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) = 0; - virtual int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) = 0; - virtual int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path, - const char* new_path, int flags, uv_fs_cb cb) = 0; - virtual int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - int mode, uv_fs_cb cb) = 0; - virtual int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file fd, + 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; + virtual int uv_fs_readlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; + virtual int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; + virtual int uv_fs_utime( + uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, double mtime, uv_fs_cb cb) = 0; + virtual int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) = 0; + virtual int uv_fs_scandir_next(uv_fs_t *req, uv_dirent_t *ent) = 0; + virtual int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; + virtual int uv_fs_symlink( + uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb) = 0; + virtual int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb) = 0; + virtual int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb) = 0; + virtual int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb) = 0; - virtual int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[], - unsigned int nbufs, int64_t offset, uv_fs_cb cb) = 0; + virtual int uv_fs_fdatasync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) = 0; + virtual int uv_fs_mkdir(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb) = 0; + virtual int uv_fs_access(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) = 0; + virtual int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) = 0; + virtual int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, 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)); - MOCK_METHOD4(uv_fs_readlink, int(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb)); - MOCK_METHOD4(uv_fs_stat, int(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb)); - MOCK_METHOD6(uv_fs_utime, int(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime, - double mtime, uv_fs_cb cb)); - MOCK_METHOD5(uv_fs_scandir, int(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - uv_fs_cb cb)); - MOCK_METHOD2(uv_fs_scandir_next, int(uv_fs_t* req, uv_dirent_t* ent)); - MOCK_METHOD4(uv_fs_rmdir, int(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb)); - MOCK_METHOD6(uv_fs_symlink, int(uv_loop_t* loop, uv_fs_t* req, const char* path, - const char* new_path, int flags, uv_fs_cb cb)); - MOCK_METHOD6(uv_fs_open, int(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, - int mode, uv_fs_cb cb)); - MOCK_METHOD5(uv_fs_ftruncate, int(uv_loop_t* loop, uv_fs_t* req, uv_file fd, - int64_t offset, uv_fs_cb cb)); - MOCK_METHOD7(uv_fs_write, int(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[], - unsigned int nbufs, int64_t offset, uv_fs_cb cb)); + 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)); + MOCK_METHOD4(uv_fs_readlink, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); + MOCK_METHOD4(uv_fs_stat, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); + MOCK_METHOD6( + uv_fs_utime, int(uv_loop_t *loop, uv_fs_t *req, const char *path, double atime, double mtime, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_scandir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb)); + MOCK_METHOD2(uv_fs_scandir_next, int(uv_fs_t *req, uv_dirent_t *ent)); + MOCK_METHOD4(uv_fs_rmdir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); + MOCK_METHOD6(uv_fs_symlink, + int(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb)); + MOCK_METHOD6(uv_fs_open, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_ftruncate, int(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb)); + MOCK_METHOD7(uv_fs_write, int(uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, + int64_t offset, uv_fs_cb cb)); + MOCK_METHOD4(uv_fs_fdatasync, int(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_mkdir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int mode, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_access, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb)); + MOCK_METHOD4(uv_fs_mkdtemp, int(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb)); + MOCK_METHOD4(uv_fs_unlink, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); }; - -} // OHOS::FileManagement::ModuleFileIO -#endif \ No newline at end of file +} // namespace OHOS::FileManagement::ModuleFileIO +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp new file mode 100644 index 000000000..498a00e90 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp @@ -0,0 +1,258 @@ +/* + * 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 +#include +#include +#include + +#include "movedir_core.h" +#include "mock/uv_fs_mock.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class MoveDirCoreTest : public testing::Test { +public: + static filesystem::path srcPath; + static filesystem::path destPath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path MoveDirCoreTest::srcPath; +filesystem::path MoveDirCoreTest::destPath; + +void MoveDirCoreTest::SetUpTestCase(void) +{ + srcPath = filesystem::temp_directory_path() / "src/"; + destPath = filesystem::temp_directory_path() / "dest/"; + std::filesystem::create_directory(srcPath); + std::filesystem::create_directory(destPath); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void MoveDirCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + filesystem::remove_all(srcPath); + filesystem::remove_all(destPath); +} + +void MoveDirCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void MoveDirCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0001 + * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0001"; + + string src = srcPath.string() + "/test01"; + string dest = destPath.string(); + filesystem::create_directories(src); + + auto result = MoveDirCore::DoMoveDir(src, dest, optional()); + + EXPECT_TRUE(result.fsResult.IsSuccess()); + EXPECT_FALSE(result.errFiles.has_value()); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0001"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0002 + * @tc.desc: Test function of DoMoveDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; + + string src = srcPath.string() + "/test02"; + string dest = destPath.string(); + filesystem::create_directories(src); + + int invalidMode = DIRMODE_MAX + 1; + auto result = MoveDirCore::DoMoveDir(src, dest, optional(invalidMode)); + + EXPECT_FALSE(result.fsResult.IsSuccess()); + auto err = result.fsResult.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + EXPECT_FALSE(result.errFiles.has_value()); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0002"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0003 + * @tc.desc: Test function of DoMoveDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; + + string src = srcPath.string() + "/test03"; + string dest = destPath.string(); + + auto result = MoveDirCore::DoMoveDir(src, dest, optional(DIRMODE_DIRECTORY_REPLACE)); + + EXPECT_FALSE(result.fsResult.IsSuccess()); + auto err = result.fsResult.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + EXPECT_FALSE(result.errFiles.has_value()); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0003"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0004 + * @tc.desc: Test function of DoMoveDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; + + string src = srcPath.string(); + string dest = destPath.string() + "/test04"; + + auto result = MoveDirCore::DoMoveDir(src, dest, optional(DIRMODE_DIRECTORY_REPLACE)); + + EXPECT_FALSE(result.fsResult.IsSuccess()); + auto err = result.fsResult.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + EXPECT_FALSE(result.errFiles.has_value()); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0004"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0005 + * @tc.desc: Test function of DoMoveDir() interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0005"; + + string src = "/data/local/test05/src/src/src/test05"; + string dest = destPath.string() + "/src"; + filesystem::create_directories(src); + filesystem::create_directories(dest); + + auto result = MoveDirCore::DoMoveDir( + "/data/local/test05/", destPath.string(), optional(DIRMODE_DIRECTORY_THROW_ERR)); + + EXPECT_FALSE(result.fsResult.IsSuccess()); + auto err = result.fsResult.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900032); + EXPECT_FALSE(result.errFiles.has_value()); + + filesystem::remove_all("/data/local/test05"); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0005"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0006 + * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0006, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0006"; + + string src = "/data/local/test06/src/src/src/test06"; + string dest = destPath.string() + "/src"; + filesystem::create_directories(src); + filesystem::create_directories(dest); + + auto result = MoveDirCore::DoMoveDir( + "/data/local/test06/src", destPath.string(), optional(DIRMODE_DIRECTORY_REPLACE)); + + EXPECT_TRUE(result.fsResult.IsSuccess()); + + filesystem::remove_all("/data/local/test06"); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0006"; +} + +/** + * @tc.name: MoveDirCoreTest_DoMoveDir_0007 + * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0007, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0007"; + + filesystem::create_directories("/data/local/test07/src"); + filesystem::create_directories("/data/local/test07/dest"); + filesystem::path srcFile = "/data/local/test07/src/test_file.txt"; + ofstream(srcFile) << "Test content\n123\n456"; + filesystem::path destFile = "/data/local/test07/dest/test_file.txt"; + ofstream(destFile) << "Test content\ndest"; + + auto result = MoveDirCore::DoMoveDir( + "/data/local/test07/src/", "/data/local/test07/dest/", optional(DIRMODE_FILE_THROW_ERR)); + + EXPECT_FALSE(result.fsResult.IsSuccess()); + auto err = result.fsResult.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900015); + EXPECT_TRUE(result.errFiles.has_value()); + + filesystem::remove_all("/data/local/test07"); + + GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0007"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp new file mode 100644 index 000000000..486359019 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp @@ -0,0 +1,176 @@ +/* + * 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 +#include +#include +#include + +#include "mock/uv_fs_mock.h" +#include "read_lines_core.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class ReadLinesCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path ReadLinesCoreTest::tempFilePath; + +void ReadLinesCoreTest::SetUpTestCase(void) +{ + tempFilePath = filesystem::temp_directory_path() / "read_lines_test_file.txt"; + ofstream(tempFilePath) << "Test content\n123\n456"; + ofstream(tempFilePath).close(); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void ReadLinesCoreTest::TearDownTestCase(void) +{ + filesystem::remove(tempFilePath); + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void ReadLinesCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void ReadLinesCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: ReadLinesCoreTest_DoReadLines_001 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_001"; + + string path = "ReadLinesCoreTest_DoReadLines_001"; + Options option; + option.encoding = "utf-8"; + auto res = ReadLinesCore::DoReadLines(path, option); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_001"; +} + +/** + * @tc.name: ReadLinesCoreTest_DoReadLines_002 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_002"; + + string path = "ReadLinesCoreTest_DoReadLines_002"; + Options option; + option.encoding = "utf-16"; + auto res = ReadLinesCore::DoReadLines(path, option); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_002"; +} + +/** + * @tc.name: ReadLinesCoreTest_DoReadLines_003 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_003"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + + string path = tempFilePath.string(); + Options option; + option.encoding = "utf-8"; + auto res = ReadLinesCore::DoReadLines(path, option); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_003"; +} + +/** + * @tc.name: ReadLinesCoreTest_DoReadLines_004 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_004"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + + string path = tempFilePath.string(); + Options option; + option.encoding = "utf-8"; + auto res = ReadLinesCore::DoReadLines(path); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_004"; +} + +/** + * @tc.name: ReadLinesCoreTest_DoReadLines_005 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_005"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + + string path = tempFilePath.string(); + Options option; + option.encoding = "utf-8"; + auto res = ReadLinesCore::DoReadLines(path, option); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_005"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp new file mode 100644 index 000000000..79784d02c --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp @@ -0,0 +1,107 @@ +/* + * 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 +#include +#include +#include + +#include "mock/uv_fs_mock.h" +#include "unlink_core.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class UnlinkCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path UnlinkCoreTest::tempFilePath; + +void UnlinkCoreTest::SetUpTestCase(void) +{ + tempFilePath = filesystem::temp_directory_path() / "unlink_test_file.txt"; + ofstream(tempFilePath) << "Test content\n123\n456"; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void UnlinkCoreTest::TearDownTestCase(void) +{ + filesystem::remove(tempFilePath); + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void UnlinkCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void UnlinkCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: UnlinkCoreTest_DoUnlink_001 + * @tc.desc: Test function of UnlinkCore::DoUnlink interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UnlinkCoreTest, UnlinkCoreTest_DoUnlink_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin UnlinkCoreTest_DoUnlink_001"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_unlink(_, _, _, _)).WillOnce(Return(1)); + + string path = tempFilePath.string(); + auto res = UnlinkCore::DoUnlink(path); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end UnlinkCoreTest_DoUnlink_001"; +} + +/** + * @tc.name: UnlinkCoreTest_DoUnlink_002 + * @tc.desc: Test function of UnlinkCore::DoUnlink interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UnlinkCoreTest, UnlinkCoreTest_DoUnlink_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin UnlinkCoreTest_DoUnlink_002"; + + std::shared_ptr uv = std::make_shared(); + Uvfs::ins = uv; + EXPECT_CALL(*uv, uv_fs_unlink(_, _, _, _)).WillOnce(Return(-1)); + + string path = tempFilePath.string(); + auto res = UnlinkCore::DoUnlink(path); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end UnlinkCoreTest_DoUnlink_002"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp new file mode 100644 index 000000000..fb2d2dc47 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp @@ -0,0 +1,169 @@ +/* + * 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 +#include +#include +#include +#include + +#include "mock/system_mock.h" +#include "mock/uv_fs_mock.h" +#include "xattr_core.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class XattrCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path XattrCoreTest::tempFilePath; + +void XattrCoreTest::SetUpTestCase(void) +{ + tempFilePath = "/data/local/tmp/xattr_test_file.txt"; + ofstream tempfile(tempFilePath); + tempfile << "Test content\n123\n456"; + tempfile.close(); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void XattrCoreTest::TearDownTestCase(void) +{ + filesystem::remove(tempFilePath); + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void XattrCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void XattrCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: XattrCoreTest_DoSetXattr_001 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_001"; + + std::shared_ptr sys = std::make_shared(); + System::ins = sys; + EXPECT_CALL(*sys, setxattr(_, _, _, _, _)).WillOnce(Return(-1)); + + string path = tempFilePath.string(); + string key = "test_key"; + string value = "test_value"; + + auto ret = XattrCore::DoSetXattr(path, key, value); + + EXPECT_FALSE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_001"; +} + +/** + * @tc.name: XattrCoreTest_DoSetXattr_002 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_002"; + + string path = tempFilePath.string(); + std::string key(4097, 'a'); + std::string value = "test_value"; + + auto ret = XattrCore::DoSetXattr(path, key, value); + + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900020); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "Invalid argument"); + + GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_002"; +} + +/** + * @tc.name: XattrCoreTest_DoSetXattr_003 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_003"; + + string path = tempFilePath.string(); + std::string key = "test_key"; + std::string value(4097, 'a'); + + auto ret = XattrCore::DoSetXattr(path, key, value); + + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900020); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "Invalid argument"); + + GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_003"; +} + +/** + * @tc.name: XattrCoreTest_DoGetXattr_001 + * @tc.desc: Test function of XattrCore::DoGetXattr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoGetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoGetXattr_001"; + + std::string path = "/data/local/tmp/nonexistent_file"; + string key = "test_key"; + + auto ret = XattrCore::DoGetXattr(path, key); + + EXPECT_TRUE(ret.IsSuccess()); + EXPECT_EQ(ret.GetData().value(), ""); + + GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoGetXattr_001"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 2982471f6b14857f25f36a55807a80caed95b240 Mon Sep 17 00:00:00 2001 From: liyuke Date: Mon, 26 May 2025 17:17:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fdatasync=E3=80=81readlines=20TDD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- interfaces/test/unittest/js/BUILD.gn | 9 - ..._test.cpp => fdatasync_core_mock_test.cpp} | 53 ++-- .../js/mod_fs/properties/mkdir_core_test.cpp | 188 ------------- .../mod_fs/properties/mkdtemp_core_test.cpp | 110 -------- .../mod_fs/properties/movedir_core_test.cpp | 258 ------------------ ...test.cpp => read_lines_core_mock_test.cpp} | 84 ++++-- .../properties/read_lines_core_test.cpp | 73 ----- .../js/mod_fs/properties/xattr_core_test.cpp | 169 ------------ 8 files changed, 78 insertions(+), 866 deletions(-) rename interfaces/test/unittest/js/mod_fs/properties/{fdatasync_core_test.cpp => fdatasync_core_mock_test.cpp} (51%) delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp rename interfaces/test/unittest/js/mod_fs/properties/{unlink_core_test.cpp => read_lines_core_mock_test.cpp} (40%) delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index bd5883c79..29ca03b71 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -22,28 +22,19 @@ ohos_unittest("ani_file_fs_test") { include_dirs = [ "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", - "${file_api_path}/interfaces/kits/js/src/mod_fs/class_readeriterator", "${file_api_path}/interfaces/test/unittest/js/mod_fs/properties/mock", ] sources = [ "mod_fs/properties/mock/uv_fs_mock.cpp", - "mod_fs/properties/mock/system_mock.cpp", "mod_fs/properties/access_core_test.cpp", "mod_fs/properties/dup_core_test.cpp", - "mod_fs/properties/fdatasync_core_test.cpp", - "mod_fs/properties/mkdir_core_test.cpp", - "mod_fs/properties/mkdtemp_core_test.cpp", - "mod_fs/properties/movedir_core_test.cpp", "mod_fs/properties/read_core_test.cpp", - "mod_fs/properties/read_lines_core_test.cpp", "mod_fs/properties/rmdir_core_test.cpp", "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_test.cpp", - "mod_fs/properties/unlink_core_test.cpp", "mod_fs/properties/utimes_core_test.cpp", "mod_fs/properties/write_core_test.cpp", - "mod_fs/properties/xattr_core_test.cpp", ] deps = [ diff --git a/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp similarity index 51% rename from interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp rename to interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp index f2e6acdf7..8797eb955 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp @@ -26,86 +26,77 @@ using namespace testing; using namespace testing::ext; using namespace std; -class FDataSyncCoreTest : public testing::Test { +class FDataSyncCoreMockTest : public testing::Test { public: - static filesystem::path tempFilePath; static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); + static inline shared_ptr uvMock = nullptr; }; -filesystem::path FDataSyncCoreTest::tempFilePath; - -void FDataSyncCoreTest::SetUpTestCase(void) +void FDataSyncCoreMockTest::SetUpTestCase(void) { - tempFilePath = filesystem::temp_directory_path() / "fdatasync_test_file.txt"; - ofstream(tempFilePath) << "Test content\n123\n456"; GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; } -void FDataSyncCoreTest::TearDownTestCase(void) +void FDataSyncCoreMockTest::TearDownTestCase(void) { - filesystem::remove(tempFilePath); GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; } -void FDataSyncCoreTest::SetUp(void) +void FDataSyncCoreMockTest::SetUp(void) { GTEST_LOG_(INFO) << "SetUp"; } -void FDataSyncCoreTest::TearDown(void) +void FDataSyncCoreMockTest::TearDown(void) { GTEST_LOG_(INFO) << "TearDown"; } /** - * @tc.name: FDataSyncCoreTest_DoFDataSync_001 + * @tc.name: FDataSyncCoreMockTest_DoFDataSync_001 * @tc.desc: Test function of FDataSyncCore::DoFDataSync interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(FDataSyncCoreTest, FDataSyncCoreTest_DoFDataSync_001, testing::ext::TestSize.Level1) +HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreTest_DoFDataSync_001"; + GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreMockTest_DoFDataSync_001"; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(1)); + int fd = 3; - string path = tempFilePath.string(); - auto fd = open(path.c_str(), O_RDWR | O_CREAT, 0666); + EXPECT_CALL(*uvMock, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(1)); auto res = FDataSyncCore::DoFDataSync(fd); EXPECT_EQ(res.IsSuccess(), true); - close(fd); - GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreTest_DoFDataSync_001"; + GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreMockTest_DoFDataSync_001"; } /** - * @tc.name: FDataSyncCoreTest_DoFDataSync_002 + * @tc.name: FDataSyncCoreMockTest_DoFDataSync_002 * @tc.desc: Test function of FDataSyncCore::DoFDataSync interface for FAILED. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(FDataSyncCoreTest, FDataSyncCoreTest_DoFDataSync_002, testing::ext::TestSize.Level1) +HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreTest_DoFDataSync_002"; + GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreMockTest_DoFDataSync_002"; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(-1)); + int fd = 3; - string path = tempFilePath.string(); - auto fd = open(path.c_str(), O_RDWR | O_CREAT, 0666); + EXPECT_CALL(*uvMock, uv_fs_fdatasync(_, _, _, _)).WillOnce(Return(-1)); auto res = FDataSyncCore::DoFDataSync(fd); EXPECT_EQ(res.IsSuccess(), false); - close(fd); - GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreTest_DoFDataSync_002"; + GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreMockTest_DoFDataSync_002"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp deleted file mode 100644 index 5bfcfd69e..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_test.cpp +++ /dev/null @@ -1,188 +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 -#include -#include -#include - -#include "mkdir_core.h" -#include "mock/uv_fs_mock.h" - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class MkdirCoreTest : public testing::Test { -public: - static filesystem::path tempFilePath; - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -filesystem::path MkdirCoreTest::tempFilePath; - -void MkdirCoreTest::SetUpTestCase(void) -{ - tempFilePath = filesystem::temp_directory_path() / "test"; - std::filesystem::create_directory(tempFilePath); - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void MkdirCoreTest::TearDownTestCase(void) -{ - GTEST_LOG_(INFO) << "TearDownTestCase"; - filesystem::remove_all(tempFilePath); -} - -void MkdirCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void MkdirCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: MkdirCoreTest_DoMkdir_0001 - * @tc.desc: Test function of DoMkdir() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0001"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_mkdir(_, _, _, _, _)).WillOnce(Return(0)); - - string path = tempFilePath.string() + "/test01"; - auto ret = MkdirCore::DoMkdir(path); - EXPECT_EQ(ret.IsSuccess(), true); - - GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0001"; -} - -/** - * @tc.name: MkdirCoreTest_DoMkdir_0002 - * @tc.desc: Test function of DoMkdir() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0002"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(-2)).WillOnce(Return(0)); - - string path = tempFilePath.string() + "/test02/testDir"; - auto ret = MkdirCore::DoMkdir(path, true); - EXPECT_EQ(ret.IsSuccess(), true); - - GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0002"; -} - -/** - * @tc.name: MkdirCoreTest_DoMkdir_0003 - * @tc.desc: Test function of DoMkdir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0003"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_mkdir(_, _, _, _, _)).WillOnce(Return(1)); - - string path = tempFilePath.string() + "/test03"; - auto ret = MkdirCore::DoMkdir(path); - EXPECT_EQ(ret.IsSuccess(), false); - - GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0003"; -} - -/** - * @tc.name: MkdirCoreTest_DoMkdir_0004 - * @tc.desc: Test function of DoMkdir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0004"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); - - string path = "/"; - auto ret = MkdirCore::DoMkdir(path, true); - EXPECT_EQ(ret.IsSuccess(), false); - auto err = ret.GetError(); - int errCode = err.GetErrNo(); - EXPECT_EQ(errCode, 13900015); - auto msg = err.GetErrMsg(); - EXPECT_EQ(msg, "File exists"); - - GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0004"; -} - -/** - * @tc.name: MkdirCoreTest_DoMkdir_0005 - * @tc.desc: Test function of DoMkdir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdirCoreTest, MkdirCoreTest_DoMkdir_0005, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdirCoreTest-begin MkdirCoreTest_DoMkdir_0005"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_access(_, _, _, _, _)).WillOnce(Return(2)); - - string path = ""; - auto ret = MkdirCore::DoMkdir(path, true); - EXPECT_EQ(ret.IsSuccess(), false); - auto err = ret.GetError(); - int errCode = err.GetErrNo(); - EXPECT_EQ(errCode, 13900002); - auto msg = err.GetErrMsg(); - EXPECT_EQ(msg, "No such file or directory"); - - GTEST_LOG_(INFO) << "MkdirCoreTest-end MkdirCoreTest_DoMkdir_0005"; -} - -} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp deleted file mode 100644 index aacda7880..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/mkdtemp_core_test.cpp +++ /dev/null @@ -1,110 +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 -#include -#include -#include - -#include "mkdtemp_core.h" -#include "mock/uv_fs_mock.h" - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class MkdtempCoreTest : public testing::Test { -public: - static filesystem::path tempFilePath; - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -filesystem::path MkdtempCoreTest::tempFilePath; - -void MkdtempCoreTest::SetUpTestCase(void) -{ - tempFilePath = filesystem::temp_directory_path() / "test"; - std::filesystem::create_directory(tempFilePath); - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void MkdtempCoreTest::TearDownTestCase(void) -{ - GTEST_LOG_(INFO) << "TearDownTestCase"; - filesystem::remove_all(tempFilePath); -} - -void MkdtempCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void MkdtempCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: MkdtempCoreTest_DoMkdtemp_0001 - * @tc.desc: Test function of DoMkdtemp() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdtempCoreTest, MkdtempCoreTest_DoMkdtemp_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdtempCoreTest-begin MkdtempCoreTest_DoMkdtemp_0001"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_mkdtemp(_, _, _, _)).WillOnce(Return(0)); - - string path = tempFilePath.string() + "/XXXXXX"; - auto ret = MkdtempCore::DoMkdtemp(path); - EXPECT_EQ(ret.IsSuccess(), true); - - GTEST_LOG_(INFO) << "MkdtempCoreTest-end MkdtempCoreTest_DoMkdtemp_0001"; -} - -/** - * @tc.name: MkdtempCoreTest_DoMkdtemp_0002 - * @tc.desc: Test function of DoMkdtemp() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MkdtempCoreTest, MkdtempCoreTest_DoMkdtemp_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MkdtempCoreTest-begin MkdtempCoreTest_DoMkdtemp_0002"; - - string path = tempFilePath.string() + "/XXXXXX"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_mkdtemp(_, _, _, _)).WillOnce(Return(-1)); - - auto ret = MkdtempCore::DoMkdtemp(path); - EXPECT_EQ(ret.IsSuccess(), false); - - GTEST_LOG_(INFO) << "MkdtempCoreTest-end MkdtempCoreTest_DoMkdtemp_0002"; -} - -} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp deleted file mode 100644 index 498a00e90..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/movedir_core_test.cpp +++ /dev/null @@ -1,258 +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 -#include -#include -#include - -#include "movedir_core.h" -#include "mock/uv_fs_mock.h" - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class MoveDirCoreTest : public testing::Test { -public: - static filesystem::path srcPath; - static filesystem::path destPath; - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -filesystem::path MoveDirCoreTest::srcPath; -filesystem::path MoveDirCoreTest::destPath; - -void MoveDirCoreTest::SetUpTestCase(void) -{ - srcPath = filesystem::temp_directory_path() / "src/"; - destPath = filesystem::temp_directory_path() / "dest/"; - std::filesystem::create_directory(srcPath); - std::filesystem::create_directory(destPath); - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void MoveDirCoreTest::TearDownTestCase(void) -{ - GTEST_LOG_(INFO) << "TearDownTestCase"; - filesystem::remove_all(srcPath); - filesystem::remove_all(destPath); -} - -void MoveDirCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void MoveDirCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0001 - * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0001"; - - string src = srcPath.string() + "/test01"; - string dest = destPath.string(); - filesystem::create_directories(src); - - auto result = MoveDirCore::DoMoveDir(src, dest, optional()); - - EXPECT_TRUE(result.fsResult.IsSuccess()); - EXPECT_FALSE(result.errFiles.has_value()); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0001"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0002 - * @tc.desc: Test function of DoMoveDir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; - - string src = srcPath.string() + "/test02"; - string dest = destPath.string(); - filesystem::create_directories(src); - - int invalidMode = DIRMODE_MAX + 1; - auto result = MoveDirCore::DoMoveDir(src, dest, optional(invalidMode)); - - EXPECT_FALSE(result.fsResult.IsSuccess()); - auto err = result.fsResult.GetError(); - EXPECT_EQ(err.GetErrNo(), 13900020); - EXPECT_FALSE(result.errFiles.has_value()); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0002"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0003 - * @tc.desc: Test function of DoMoveDir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; - - string src = srcPath.string() + "/test03"; - string dest = destPath.string(); - - auto result = MoveDirCore::DoMoveDir(src, dest, optional(DIRMODE_DIRECTORY_REPLACE)); - - EXPECT_FALSE(result.fsResult.IsSuccess()); - auto err = result.fsResult.GetError(); - EXPECT_EQ(err.GetErrNo(), 13900020); - EXPECT_FALSE(result.errFiles.has_value()); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0003"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0004 - * @tc.desc: Test function of DoMoveDir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0002"; - - string src = srcPath.string(); - string dest = destPath.string() + "/test04"; - - auto result = MoveDirCore::DoMoveDir(src, dest, optional(DIRMODE_DIRECTORY_REPLACE)); - - EXPECT_FALSE(result.fsResult.IsSuccess()); - auto err = result.fsResult.GetError(); - EXPECT_EQ(err.GetErrNo(), 13900020); - EXPECT_FALSE(result.errFiles.has_value()); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0004"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0005 - * @tc.desc: Test function of DoMoveDir() interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0005, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0005"; - - string src = "/data/local/test05/src/src/src/test05"; - string dest = destPath.string() + "/src"; - filesystem::create_directories(src); - filesystem::create_directories(dest); - - auto result = MoveDirCore::DoMoveDir( - "/data/local/test05/", destPath.string(), optional(DIRMODE_DIRECTORY_THROW_ERR)); - - EXPECT_FALSE(result.fsResult.IsSuccess()); - auto err = result.fsResult.GetError(); - EXPECT_EQ(err.GetErrNo(), 13900032); - EXPECT_FALSE(result.errFiles.has_value()); - - filesystem::remove_all("/data/local/test05"); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0005"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0006 - * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0006, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0006"; - - string src = "/data/local/test06/src/src/src/test06"; - string dest = destPath.string() + "/src"; - filesystem::create_directories(src); - filesystem::create_directories(dest); - - auto result = MoveDirCore::DoMoveDir( - "/data/local/test06/src", destPath.string(), optional(DIRMODE_DIRECTORY_REPLACE)); - - EXPECT_TRUE(result.fsResult.IsSuccess()); - - filesystem::remove_all("/data/local/test06"); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0006"; -} - -/** - * @tc.name: MoveDirCoreTest_DoMoveDir_0007 - * @tc.desc: Test function of DoMoveDir() interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000IGDNF - */ -HWTEST_F(MoveDirCoreTest, MoveDirCoreTest_DoMoveDir_0007, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "MoveDirCoreTest-begin MoveDirCoreTest_DoMoveDir_0007"; - - filesystem::create_directories("/data/local/test07/src"); - filesystem::create_directories("/data/local/test07/dest"); - filesystem::path srcFile = "/data/local/test07/src/test_file.txt"; - ofstream(srcFile) << "Test content\n123\n456"; - filesystem::path destFile = "/data/local/test07/dest/test_file.txt"; - ofstream(destFile) << "Test content\ndest"; - - auto result = MoveDirCore::DoMoveDir( - "/data/local/test07/src/", "/data/local/test07/dest/", optional(DIRMODE_FILE_THROW_ERR)); - - EXPECT_FALSE(result.fsResult.IsSuccess()); - auto err = result.fsResult.GetError(); - EXPECT_EQ(err.GetErrNo(), 13900015); - EXPECT_TRUE(result.errFiles.has_value()); - - filesystem::remove_all("/data/local/test07"); - - GTEST_LOG_(INFO) << "MoveDirCoreTest-end MoveDirCoreTest_DoMoveDir_0007"; -} - -} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp similarity index 40% rename from interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp rename to interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp index 79784d02c..df5d48226 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/unlink_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp @@ -19,89 +19,117 @@ #include #include "mock/uv_fs_mock.h" -#include "unlink_core.h" +#include "read_lines_core.h" namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; using namespace testing::ext; using namespace std; -class UnlinkCoreTest : public testing::Test { +class ReadLinesCoreMockTest : public testing::Test { public: static filesystem::path tempFilePath; static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); + static inline shared_ptr uvMock = nullptr; }; -filesystem::path UnlinkCoreTest::tempFilePath; +filesystem::path ReadLinesCoreMockTest::tempFilePath; -void UnlinkCoreTest::SetUpTestCase(void) +void ReadLinesCoreMockTest::SetUpTestCase(void) { - tempFilePath = filesystem::temp_directory_path() / "unlink_test_file.txt"; - ofstream(tempFilePath) << "Test content\n123\n456"; GTEST_LOG_(INFO) << "SetUpTestCase"; + tempFilePath = filesystem::temp_directory_path() / "read_lines_test_file.txt"; + ofstream(tempFilePath) << "Test content\n123\n456"; + ofstream(tempFilePath).close(); + uvMock = std::make_shared(); + Uvfs::ins = uvMock; } -void UnlinkCoreTest::TearDownTestCase(void) +void ReadLinesCoreMockTest::TearDownTestCase(void) { filesystem::remove(tempFilePath); GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; } -void UnlinkCoreTest::SetUp(void) +void ReadLinesCoreMockTest::SetUp(void) { GTEST_LOG_(INFO) << "SetUp"; } -void UnlinkCoreTest::TearDown(void) +void ReadLinesCoreMockTest::TearDown(void) { GTEST_LOG_(INFO) << "TearDown"; } /** - * @tc.name: UnlinkCoreTest_DoUnlink_001 - * @tc.desc: Test function of UnlinkCore::DoUnlink interface for SUCCESS. + * @tc.name: ReadLinesCoreMockTest_DoReadLines_001 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(UnlinkCoreTest, UnlinkCoreTest_DoUnlink_001, testing::ext::TestSize.Level1) +HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin UnlinkCoreTest_DoUnlink_001"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_unlink(_, _, _, _)).WillOnce(Return(1)); + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_001"; string path = tempFilePath.string(); - auto res = UnlinkCore::DoUnlink(path); + Options option; + option.encoding = "utf-8"; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end UnlinkCoreTest_DoUnlink_001"; + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_001"; } /** - * @tc.name: UnlinkCoreTest_DoUnlink_002 - * @tc.desc: Test function of UnlinkCore::DoUnlink interface for FAILED. + * @tc.name: ReadLinesCoreMockTest_DoReadLines_002 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(UnlinkCoreTest, UnlinkCoreTest_DoUnlink_002, testing::ext::TestSize.Level1) +HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin UnlinkCoreTest_DoUnlink_002"; + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_002"; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_unlink(_, _, _, _)).WillOnce(Return(-1)); + string path = tempFilePath.string(); + Options option; + option.encoding = "utf-8"; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + auto res = ReadLinesCore::DoReadLines(path); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_002"; +} + +/** + * @tc.name: ReadLinesCoreMockTest_DoReadLines_003 + * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_003"; string path = tempFilePath.string(); - auto res = UnlinkCore::DoUnlink(path); + Options option; + option.encoding = "utf-8"; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end UnlinkCoreTest_DoUnlink_002"; + GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_003"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp index 486359019..7f7494488 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp @@ -18,7 +18,6 @@ #include #include -#include "mock/uv_fs_mock.h" #include "read_lines_core.h" namespace OHOS::FileManagement::ModuleFileIO::Test { @@ -101,76 +100,4 @@ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_002, testing::ext::Tes GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_002"; } -/** - * @tc.name: ReadLinesCoreTest_DoReadLines_003 - * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_003"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); - - string path = tempFilePath.string(); - Options option; - option.encoding = "utf-8"; - auto res = ReadLinesCore::DoReadLines(path, option); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_003"; -} - -/** - * @tc.name: ReadLinesCoreTest_DoReadLines_004 - * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_004"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); - - string path = tempFilePath.string(); - Options option; - option.encoding = "utf-8"; - auto res = ReadLinesCore::DoReadLines(path); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_004"; -} - -/** - * @tc.name: ReadLinesCoreTest_DoReadLines_005 - * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_005, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_005"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); - - string path = tempFilePath.string(); - Options option; - option.encoding = "utf-8"; - auto res = ReadLinesCore::DoReadLines(path, option); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_005"; -} - } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp deleted file mode 100644 index fb2d2dc47..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp +++ /dev/null @@ -1,169 +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 -#include -#include -#include -#include - -#include "mock/system_mock.h" -#include "mock/uv_fs_mock.h" -#include "xattr_core.h" - -namespace OHOS::FileManagement::ModuleFileIO::Test { -using namespace testing; -using namespace testing::ext; -using namespace std; - -class XattrCoreTest : public testing::Test { -public: - static filesystem::path tempFilePath; - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -filesystem::path XattrCoreTest::tempFilePath; - -void XattrCoreTest::SetUpTestCase(void) -{ - tempFilePath = "/data/local/tmp/xattr_test_file.txt"; - ofstream tempfile(tempFilePath); - tempfile << "Test content\n123\n456"; - tempfile.close(); - GTEST_LOG_(INFO) << "SetUpTestCase"; -} - -void XattrCoreTest::TearDownTestCase(void) -{ - filesystem::remove(tempFilePath); - GTEST_LOG_(INFO) << "TearDownTestCase"; -} - -void XattrCoreTest::SetUp(void) -{ - GTEST_LOG_(INFO) << "SetUp"; -} - -void XattrCoreTest::TearDown(void) -{ - GTEST_LOG_(INFO) << "TearDown"; -} - -/** - * @tc.name: XattrCoreTest_DoSetXattr_001 - * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_001"; - - std::shared_ptr sys = std::make_shared(); - System::ins = sys; - EXPECT_CALL(*sys, setxattr(_, _, _, _, _)).WillOnce(Return(-1)); - - string path = tempFilePath.string(); - string key = "test_key"; - string value = "test_value"; - - auto ret = XattrCore::DoSetXattr(path, key, value); - - EXPECT_FALSE(ret.IsSuccess()); - - GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_001"; -} - -/** - * @tc.name: XattrCoreTest_DoSetXattr_002 - * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_002"; - - string path = tempFilePath.string(); - std::string key(4097, 'a'); - std::string value = "test_value"; - - auto ret = XattrCore::DoSetXattr(path, key, value); - - EXPECT_FALSE(ret.IsSuccess()); - auto err = ret.GetError(); - int errCode = err.GetErrNo(); - EXPECT_EQ(errCode, 13900020); - auto msg = err.GetErrMsg(); - EXPECT_EQ(msg, "Invalid argument"); - - GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_002"; -} - -/** - * @tc.name: XattrCoreTest_DoSetXattr_003 - * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoSetXattr_003"; - - string path = tempFilePath.string(); - std::string key = "test_key"; - std::string value(4097, 'a'); - - auto ret = XattrCore::DoSetXattr(path, key, value); - - EXPECT_FALSE(ret.IsSuccess()); - auto err = ret.GetError(); - int errCode = err.GetErrNo(); - EXPECT_EQ(errCode, 13900020); - auto msg = err.GetErrMsg(); - EXPECT_EQ(msg, "Invalid argument"); - - GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoSetXattr_003"; -} - -/** - * @tc.name: XattrCoreTest_DoGetXattr_001 - * @tc.desc: Test function of XattrCore::DoGetXattr interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(XattrCoreTest, XattrCoreTest_DoGetXattr_001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "NClassTest-begin XattrCoreTest_DoGetXattr_001"; - - std::string path = "/data/local/tmp/nonexistent_file"; - string key = "test_key"; - - auto ret = XattrCore::DoGetXattr(path, key); - - EXPECT_TRUE(ret.IsSuccess()); - EXPECT_EQ(ret.GetData().value(), ""); - - GTEST_LOG_(INFO) << "NClassTest-end XattrCoreTest_DoGetXattr_001"; -} - -} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 3398062c43fb778433374dd2e4fcef1d732c52e6 Mon Sep 17 00:00:00 2001 From: liyuke Date: Mon, 26 May 2025 17:22:22 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fdatasync=E3=80=81readlines=20TDD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- .../js/mod_fs/properties/mock/system_mock.cpp | 28 ------------- .../js/mod_fs/properties/mock/system_mock.h | 40 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp delete mode 100644 interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp deleted file mode 100644 index be0c39c07..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp +++ /dev/null @@ -1,28 +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 "system_mock.h" - -using namespace OHOS::FileManagement::ModuleFileIO; - -int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) -{ - return System::ins->setxattr(path, name, value, size, flags); -} - -int getxattr(const char *path, const char *name, void *value, size_t size) -{ - return System::ins->getxattr(path, name, value, size); -} diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h deleted file mode 100644 index b0c173f8e..000000000 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h +++ /dev/null @@ -1,40 +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 INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H -#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H - -#include - -namespace OHOS::FileManagement::ModuleFileIO { - -class System { -public: - static inline std::shared_ptr ins = nullptr; - -public: - virtual ~System() = default; - virtual int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) = 0; - virtual int getxattr(const char *path, const char *name, void *value, size_t size) = 0; -}; - -class SystemMock : public System { -public: - MOCK_METHOD5(setxattr, int(const char *path, const char *name, const void *value, size_t size, int flags)); - MOCK_METHOD4(getxattr, int(const char *path, const char *name, void *value, size_t size)); -}; - -} // namespace OHOS::FileManagement::ModuleFileIO -#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_SYSTEM_MOCK_H \ No newline at end of file -- Gitee From 75b3749762a709dfad535c3b69fc486d82e65e9c Mon Sep 17 00:00:00 2001 From: liyuke Date: Tue, 27 May 2025 10:11:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- .../test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp | 4 ++-- .../test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 index 1e6748f17..13ceb7b54 100644 --- 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 @@ -53,9 +53,9 @@ int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) return Uvfs::ins->uv_fs_rmdir(loop, req, path, cb); } -int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb) +int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb) { - return Uvfs::ins->uv_fs_symlink(loop, req, path, new_path, flags, cb); + return Uvfs::ins->uv_fs_symlink(loop, req, path, newPath, flags, cb); } int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb 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 index 06e3f9628..6b0f3c5fd 100644 --- 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 @@ -38,7 +38,7 @@ public: virtual int uv_fs_scandir_next(uv_fs_t *req, uv_dirent_t *ent) = 0; virtual int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; virtual int uv_fs_symlink( - uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb) = 0; + uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb) = 0; virtual int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb) = 0; virtual int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb) = 0; virtual int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, @@ -62,7 +62,7 @@ public: MOCK_METHOD2(uv_fs_scandir_next, int(uv_fs_t *req, uv_dirent_t *ent)); MOCK_METHOD4(uv_fs_rmdir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); MOCK_METHOD6(uv_fs_symlink, - int(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb)); + int(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb)); MOCK_METHOD6(uv_fs_open, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)); MOCK_METHOD5(uv_fs_ftruncate, int(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb)); MOCK_METHOD7(uv_fs_write, int(uv_loop_t *loop, uv_fs_t *req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, -- Gitee From 5579212d86a5e9d41fde6f7a763a3b39c48382d6 Mon Sep 17 00:00:00 2001 From: liyuke Date: Tue, 27 May 2025 12:11:31 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81review=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- .../properties/fdatasync_core_mock_test.cpp | 10 +++++----- .../properties/read_lines_core_mock_test.cpp | 16 +++++++--------- .../mod_fs/properties/read_lines_core_test.cpp | 9 ++++----- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp index 8797eb955..c6308de50 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/fdatasync_core_mock_test.cpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include "fdatasync_core.h" #include "mock/uv_fs_mock.h" @@ -68,7 +68,7 @@ void FDataSyncCoreMockTest::TearDown(void) */ HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreMockTest_DoFDataSync_001"; + GTEST_LOG_(INFO) << "FDataSyncCoreMockTest-begin FDataSyncCoreMockTest_DoFDataSync_001"; int fd = 3; @@ -76,7 +76,7 @@ HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_001, testing:: auto res = FDataSyncCore::DoFDataSync(fd); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreMockTest_DoFDataSync_001"; + GTEST_LOG_(INFO) << "FDataSyncCoreMockTest-end FDataSyncCoreMockTest_DoFDataSync_001"; } /** @@ -88,7 +88,7 @@ HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_001, testing:: */ HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin FDataSyncCoreMockTest_DoFDataSync_002"; + GTEST_LOG_(INFO) << "FDataSyncCoreMockTest-begin FDataSyncCoreMockTest_DoFDataSync_002"; int fd = 3; @@ -96,7 +96,7 @@ HWTEST_F(FDataSyncCoreMockTest, FDataSyncCoreMockTest_DoFDataSync_002, testing:: auto res = FDataSyncCore::DoFDataSync(fd); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end FDataSyncCoreMockTest_DoFDataSync_002"; + GTEST_LOG_(INFO) << "FDataSyncCoreMockTest-end FDataSyncCoreMockTest_DoFDataSync_002"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp index df5d48226..118e5e28a 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_mock_test.cpp @@ -15,8 +15,8 @@ #include #include -#include #include +#include #include "mock/uv_fs_mock.h" #include "read_lines_core.h" @@ -75,7 +75,7 @@ void ReadLinesCoreMockTest::TearDown(void) */ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_001"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-begin ReadLinesCoreMockTest_DoReadLines_001"; string path = tempFilePath.string(); Options option; @@ -85,7 +85,7 @@ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_001, testing:: auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_001"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-end ReadLinesCoreMockTest_DoReadLines_001"; } /** @@ -97,17 +97,15 @@ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_001, testing:: */ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_002"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-begin ReadLinesCoreMockTest_DoReadLines_002"; string path = tempFilePath.string(); - Options option; - option.encoding = "utf-8"; EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); auto res = ReadLinesCore::DoReadLines(path); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_002"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-end ReadLinesCoreMockTest_DoReadLines_002"; } /** @@ -119,7 +117,7 @@ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_002, testing:: */ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_003, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreMockTest_DoReadLines_003"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-begin ReadLinesCoreMockTest_DoReadLines_003"; string path = tempFilePath.string(); Options option; @@ -129,7 +127,7 @@ HWTEST_F(ReadLinesCoreMockTest, ReadLinesCoreMockTest_DoReadLines_003, testing:: auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreMockTest_DoReadLines_003"; + GTEST_LOG_(INFO) << "ReadLinesCoreMockTest-end ReadLinesCoreMockTest_DoReadLines_003"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp index 7f7494488..92e4f19b4 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/read_lines_core_test.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include "read_lines_core.h" @@ -69,7 +68,7 @@ void ReadLinesCoreTest::TearDown(void) */ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_001"; + GTEST_LOG_(INFO) << "ReadLinesCoreTest-begin ReadLinesCoreTest_DoReadLines_001"; string path = "ReadLinesCoreTest_DoReadLines_001"; Options option; @@ -77,7 +76,7 @@ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_001, testing::ext::Tes auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_001"; + GTEST_LOG_(INFO) << "ReadLinesCoreTest-end ReadLinesCoreTest_DoReadLines_001"; } /** @@ -89,7 +88,7 @@ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_001, testing::ext::Tes */ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadLinesCoreTest_DoReadLines_002"; + GTEST_LOG_(INFO) << "ReadLinesCoreTest-begin ReadLinesCoreTest_DoReadLines_002"; string path = "ReadLinesCoreTest_DoReadLines_002"; Options option; @@ -97,7 +96,7 @@ HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_002, testing::ext::Tes auto res = ReadLinesCore::DoReadLines(path, option); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end ReadLinesCoreTest_DoReadLines_002"; + GTEST_LOG_(INFO) << "ReadLinesCoreTest-end ReadLinesCoreTest_DoReadLines_002"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee