From 973d6f8d050791be0a66868dd3b1b5a9706d9bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Mon, 19 May 2025 12:00:47 +0800 Subject: [PATCH] fs properties tdd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- interfaces/test/unittest/BUILD.gn | 3 + interfaces/test/unittest/js/BUILD.gn | 70 ++- .../js/mod_fs/properties/close_core_test.cpp | 173 ++++++ .../properties/create_stream_core_test.cpp | 81 +++ .../properties/fdopen_stream_core_test.cpp | 117 ++++ .../mod_fs/properties/listfile_core_test.cpp | 524 ++++++++++++++++++ .../mod_fs/properties/read_text_core_test.cpp | 246 ++++++++ 7 files changed, 1213 insertions(+), 1 deletion(-) create mode 100644 interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/fdopen_stream_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/listfile_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/read_text_core_test.cpp diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 3a6c6eb26..b47f7a2b3 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -19,5 +19,8 @@ group("file_api_unittest") { "js:ani_file_fs_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", + "ani_file_fs_test", + "ani_file_hash_test", + "ani_file_securitylabel_test". ] } diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index e4e6a9d52..2fda5f8cc 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -19,17 +19,27 @@ ohos_unittest("ani_file_fs_test") { testonly = true module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + include_dirs = [ "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stream", "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", "mock/uv_fs_mock.h", ] sources = [ - "mod_fs/properties/mock/uv_fs_mock.cpp", + "mod_fs/class_stream/fs_stream_test.cpp", "mod_fs/properties/access_core_test.cpp", + "mod_fs/properties/close_core_test.cpp", + "mod_fs/properties/create_stream_core_test.cpp", "mod_fs/properties/dup_core_test.cpp", + "mod_fs/properties/fdopen_stream_core_test.cpp", + "mod_fs/properties/listfile_core_test.cpp", + "mod_fs/properties/mock/uv_fs_mock.cpp", "mod_fs/properties/read_core_test.cpp", + "mod_fs/properties/read_text_core_test.cpp", "mod_fs/properties/rmdir_core_test.cpp", "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_test.cpp", @@ -74,4 +84,62 @@ ohos_unittest("ani_file_fs_test") { ] cflags_cc = [ "-DENABLE_NAPI_MOCK" ] +} + +ohos_unittest("ani_file_hash_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ + "mod_hash/hash_core_test.cpp", + ] + + include_dirs = [ + "mock/libuv", + "${file_api_path}/interfaces/kits/js/src/mod_hash", + ] + + deps = [ + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${file_api_path}/interfaces/kits/js:ani_file_hash", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "libuv:uv", + "googletest:gmock_main", + "googletest:gtest_main", + ] +} + +ohos_unittest("ani_file_securitylabel_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ + "mod_securitylabel/securitylabel_core_test.cpp", + ] + + include_dirs = [ + "mock/libuv", + "${file_api_path}/interfaces/kits/js/src/mod_securitylabel", + ] + + deps = [ + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${file_api_path}/interfaces/kits/js:ani_file_securitylabel", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "libuv:uv", + "googletest:gmock_main", + "googletest:gtest_main", + ] } \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp new file mode 100644 index 000000000..0fdb4a86e --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp @@ -0,0 +1,173 @@ +/* +* 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 "close_core.h" +#include "open_core.h" + +#define FILE_PATH "/data/test/CloseCoreTest.txt" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +class CloseCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) { + int32_t fd = open(FILE_PATH, CREATE | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() { + rmdir(FILE_PATH); + }; + void SetUp() {}; + void TearDown() {}; +// private: +// int32_t fd = 0; +}; + +/** +* @tc.name: DoCloseTestFd_0001 +* @tc.desc: Test function of DoClose() interface for invalid arguments. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFd_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFd_0001"; + auto ret = CloseCore::DoClose(-1); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0001"; +} + +/** +* @tc.name: DoCloseTestFd_0002 +* @tc.desc: Test function of DoClose() interface for sucess. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFd_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFd_0002"; + int32_t fd = open(FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + + auto ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + int32_t fdEnd = open(FILE_PATH, O_RDWR); + if (fdEnd <= 0) { + close(fdEnd); + ASSERT_TRUE(false); + } + EXPECT_EQ(fdEnd, fd); + + ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0002"; +} + +/** +* @tc.name: DoCloseTestFd_0003 +* @tc.desc: Test function of DoClose() interface for failed. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFd_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFd_0003"; + int32_t fd = open(FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + auto ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + ret = CloseCore::DoClose(fd); + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900008); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0003"; +} + +/** +* @tc.name: DoCloseTestFile_0001 +* @tc.desc: Test function of DoClose() interface for success. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFile_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFile_0001"; + auto fileRes = OpenCore::DoOpen(FILE_PATH); + if (!fileRes.IsSuccess()) { + ASSERT_TRUE(false); + } + FsFile *file = fileRes.GetData().value(); + auto ret = CloseCore::DoClose(file); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFile_0001"; +} + +/** +* @tc.name: DoCloseTestFile_0002 +* @tc.desc: Test function of DoClose() interface for failed get fd. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFile_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFile_0002"; + auto fileRes = OpenCore::DoOpen(FILE_PATH); + if (!fileRes.IsSuccess()) { + ASSERT_TRUE(false); + } + FsFile *file = fileRes.GetData().value(); + auto ret = CloseCore::DoClose(file); + EXPECT_TRUE(ret.IsSuccess()); + + ret = CloseCore::DoClose(file); + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFile_0002"; +} + +} +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp new file mode 100644 index 000000000..904908c53 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp @@ -0,0 +1,81 @@ +/* +* 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 "create_stream_core.h" + +#define CREATE_STREAM_FILE_PATH "/data/test/CreateStreamCoreTest.txt" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +class CreateStreamCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) { + int32_t fd = open(CREATE_STREAM_FILE_PATH, CREATE | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() { + rmdir(CREATE_STREAM_FILE_PATH); + }; + void SetUp() {}; + void TearDown() {}; +}; +/** +* @tc.name: DoCreateStreamTest_0001 +* @tc.desc: Test function of DoCreateStream() interface for success. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CreateStreamCoreTest, DoCreateStreamTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateStreamCoreTest-begin DoCreateStreamTest_0001"; + auto ret = CreateStreamCore::DoCreateStream(CREATE_STREAM_FILE_PATH, "r"); + ASSERT_TRUE(ret.IsSuccess()); + + auto stream = ret.GetData().value(); + ASSERT_NE(stream, nullptr); + auto retClose = stream->Close(); + EXPECT_TRUE(retClose.IsSuccess()); + + GTEST_LOG_(INFO) << "CreateStreamCoreTest-end DoCreateStreamTest_0001"; +} + +/** +* @tc.name: DoCreateStreamTest_0002 +* @tc.desc: Test function of DoCreateStream() interface for fail. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(CreateStreamCoreTest, DoCreateStreamTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateStreamCoreTest-begin DoCreateStreamTest_0002"; + auto ret = CreateStreamCore::DoCreateStream(CREATE_STREAM_FILE_PATH, "ssss"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "CreateStreamCoreTest-end DoCreateStreamTest_0002"; +} + +} +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/fdopen_stream_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fdopen_stream_core_test.cpp new file mode 100644 index 000000000..1f31630e5 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/fdopen_stream_core_test.cpp @@ -0,0 +1,117 @@ +/* +* 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 "fdopen_stream_core.h" + +#define FDOPEN_STREAM_FILE_PATH "/data/test/FdopenStreamCoreTest.txt" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +class FdopenStreamCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) { + int32_t fd = open(FDOPEN_STREAM_FILE_PATH, CREATE | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() { + rmdir(FDOPEN_STREAM_FILE_PATH); + }; + void SetUp() {}; + void TearDown() {}; +}; +/** +* @tc.name: DoFdopenStreamTest_0001 +* @tc.desc: Test function of DoFdopenStream() interface for success. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(FdopenStreamCoreTest, DoFdopenStreamTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-begin DoFdopenStreamTest_0001"; + int32_t fd = open(FDOPEN_STREAM_FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + + auto ret = FdopenStreamCore::DoFdopenStream(fd, "r"); + ASSERT_TRUE(ret.IsSuccess()); + + auto stream = ret.GetData().value(); + ASSERT_NE(stream, nullptr); + auto retClose = stream->Close(); + EXPECT_TRUE(retClose.IsSuccess()); + + close(fd); + + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-end DoFdopenStreamTest_0001"; +} + +/** +* @tc.name: DoFdopenStreamTest_0002 +* @tc.desc: Test function of DoFdopenStream() interface for fd < 0. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(FdopenStreamCoreTest, DoFdopenStreamTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-begin DoFdopenStreamTest_0002"; + auto ret = FdopenStreamCore::DoFdopenStream(-1, "r"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-end DoFdopenStreamTest_0002"; +} + +/** +* @tc.name: DoFdopenStreamTest_0003 +* @tc.desc: Test function of DoFdopenStream() interface for fail. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(FdopenStreamCoreTest, DoFdopenStreamTest_0003, testing::ext::TestSize.Level1) +{ + int32_t fd = open(FDOPEN_STREAM_FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-begin DoFdopenStreamTest_0003"; + auto ret = FdopenStreamCore::DoFdopenStream(fd, "sssssss"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + close(fd); + + GTEST_LOG_(INFO) << "FdopenStreamCoreTest-end DoFdopenStreamTest_0003"; +} + +} +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/listfile_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/listfile_core_test.cpp new file mode 100644 index 000000000..063ce90a9 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/listfile_core_test.cpp @@ -0,0 +1,524 @@ +/* +* 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 "listfile_core.h" + +#define DIR_PATH "/data/test/ListFileCoreTest" +#define EMPTY_PATH "/data/test/Empty" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +namespace fs = std::filesystem; + +static void create_file(const fs::path& path, const std::vector& data, bool binary = true) +{ + fs::create_directories(path.parent_path()); // 确保目录存在 + std::ofstream file(path, binary ? std::ios::binary : std::ios::out); + if (!file) { + std::cerr << "创建文件失败: " << path << std::endl; + return; + } + file.write(reinterpret_cast(data.data()), data.size()); + std::cout << "已创建文件: " << path << std::endl; +} + +static void writeBuffer(const string filename) +{ + const int target_size = 1024; + std::vector buffer(target_size, 0); + std::ofstream file(filename, std::ios::binary); + file.write(buffer.data(), buffer.size()); +} + +class ListFileCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) { + fs::create_directory(EMPTY_PATH); + const std::vector directories = { + "/data/test/ListFileCoreTest", // 单级目录 + "/data/test/ListFileCoreTest/level1", // 二级目录 + "/data/test/ListFileCoreTest/level1/level2" // 三级目录 + }; + + // 为每个文件类型创建3个文件 + for (int i = 0; i < 3; ++i) { + create_file(directories[i] / ("text_" + std::to_string(i+1) + ".txt"), + {'F','i','l','e',' ',char('0'+i+1)}, false); + + create_file(directories[i] / ("image_" + std::to_string(i+1) + ".png"), + {0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A}); + + create_file(directories[i] / ("photo_" + std::to_string(i+1) + ".jpg"), + {0xFF,0xD8,0xFF,0xE0,0x00,0x10,0x4A,0x46}); + + create_file(directories[i] / ("data_" + std::to_string(i+1) + ".data"), + {0xAB,0xCD,0xEF, char(i), char(i+1), char(i+2)}); + } + + writeBuffer("/data/test/ListFileCoreTest/text_1.txt"); + }; + static void TearDownTestCase() { + rmdir(DIR_PATH); + rmdir(EMPTY_PATH); + }; + void SetUp() {}; + void TearDown() {}; +}; + +/** +* @tc.name: DoListFileCoreTest_0001 +* @tc.desc: Test function of DoListFileCore() interface for error suffix. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0001"; + FsListFileOptions opt; + FsFileFilter filter; + // filter.SetSuffix({"txt"}); // 无效后缀(缺少`.`) + std::vector suffixVector = {"txt"}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0001"; +} + +/** +* @tc.name: DoListFileCoreTest_0002 +* @tc.desc: Test function of DoListFileCore() interface for error suffix. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0002"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector suffixVector = {".tx@t"}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0002"; +} + +/** +* @tc.name: DoListFileCoreTest_0003 +* @tc.desc: Test function of DoListFileCore() interface for error listNum. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0003"; + FsListFileOptions opt; + opt.listNum = -5; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0003"; +} + +/** +* @tc.name: DoListFileCoreTest_0004 +* @tc.desc: Test function of DoListFileCore() interface for current suffix. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0004"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector suffixVector = {".txt"}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 2); + EXPECT_EQ(files[0], "text_1.txt"); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0004"; +} + +/** +* @tc.name: DoListFileCoreTest_0005 +* @tc.desc: Test function of DoListFileCore() interface for no maching suffix . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0005"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector suffixVector = {".abc"}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_FALSE(files[0].empty()); + EXPECT_EQ(files[0], "level1"); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0005"; +} + +/** +* @tc.name: DoListFileCoreTest_0006 +* @tc.desc: Test function of DoListFileCore() interface for current display name . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0006, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0006"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector displayNameVector = {"text*.txt"}; + std::optional> optionalDisplayName = displayNameVector; + filter.SetDisplayName(optionalDisplayName); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 1); + EXPECT_EQ(files[0], "text_1.txt"); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0006"; +} + +/** +* @tc.name: DoListFileCoreTest_0007 +* @tc.desc: Test function of DoListFileCore() interface for current fileSizeOver . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0007, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0007"; + FsListFileOptions opt; + FsFileFilter filter; + filter.SetFileSizeOver(500); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 2); + EXPECT_EQ(files[0], "text_1.txt"); + EXPECT_EQ(files[1], "level1"); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0007"; +} + +/** +* @tc.name: DoListFileCoreTest_0008 +* @tc.desc: Test function of DoListFileCore() interface for displayMame = 0 . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0008, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0008"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector displayNameVector = {}; + std::optional> optionalDisplayName = displayNameVector; + filter.SetDisplayName(optionalDisplayName); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0008"; +} + +/** +* @tc.name: DoListFileCoreTest_0009 +* @tc.desc: Test function of DoListFileCore() interface for error fileSizeOver . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0009, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0009"; + FsListFileOptions opt; + FsFileFilter filter; + filter.SetFileSizeOver(-1); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0009"; +} + +/** +* @tc.name: DoListFileCoreTest_0010 +* @tc.desc: Test function of DoListFileCore() interface for error lstModitiedAfter . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0010, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0010"; + FsListFileOptions opt; + FsFileFilter filter; + filter.SetLastModifiedAfter(-1); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0010"; +} + +/** +* @tc.name: DoListFileCoreTest_0011 +* @tc.desc: Test function of DoListFileCore() interface for true recursion . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0011, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0011"; + FsListFileOptions opt; + opt.recursion = true; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 12); + EXPECT_EQ(files[0], "/text_1.txt"); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0011"; +} + +/** +* @tc.name: DoListFileCoreTest_0012 +* @tc.desc: Test function of DoListFileCore() interface for empty directory . +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0012, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0012"; + auto result = ListFileCore::DoListFile(EMPTY_PATH); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_TRUE(files.empty()); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0012"; +} + +/** +* @tc.name: DoListFileCoreTest_0013 +* @tc.desc: Test function of DoListFileCore() interface for current listNum. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0013, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0013"; + FsListFileOptions opt; + opt.listNum = 3; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 3); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0013"; +} + +/** +* @tc.name: DoListFileCoreTest_0014 +* @tc.desc: Test function of DoListFileCore() interface for no such file or directory. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0014, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0014"; + auto result = ListFileCore::DoListFile("/data/local/tmp/ascecedssw"); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900002); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0014"; +} + +/** +* @tc.name: DoListFileCoreTest_0015 +* @tc.desc: Test function of DoListFileCore() interface for >256 length suffix. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0015, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0015"; + FsListFileOptions opt; + FsFileFilter filter; + + const size_t TARGET_LENGTH = 257; + std::string str = "."; + for (size_t i = 1; i < TARGET_LENGTH; ++i) { + str += std::to_string(i % 10); + } + + std::vector suffixVector = {str}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0015"; +} + +/** +* @tc.name: DoListFileCoreTest_0016 +* @tc.desc: Test function of DoListFileCore() interface for empty suffix. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0016, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0016"; + FsListFileOptions opt; + FsFileFilter filter; + std::vector suffixVector = {}; + std::optional> optionalSuffix = suffixVector; + filter.SetSuffix(optionalSuffix); + opt.filter = filter; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + EXPECT_FALSE(result.IsSuccess()); + + auto err = result.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0016"; +} + +/** +* @tc.name: DoListFileCoreTest_0017 +* @tc.desc: Test function of DoListFileCore() interface for 0 listNum. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ListFileCoreTest, DoListFileCoreTest_0017, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ListFileCoreTest-begin DoListFileCoreTest_0017"; + FsListFileOptions opt; + opt.listNum = 0; + + auto result = ListFileCore::DoListFile(DIR_PATH, opt); + ASSERT_TRUE(result.IsSuccess()); + + auto files = result.GetData().value(); + EXPECT_EQ(files.size(), 5); + + GTEST_LOG_(INFO) << "ListFileCoreTest-end DoListFileCoreTest_0017"; +} + +} +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_text_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_text_core_test.cpp new file mode 100644 index 000000000..fd900e1ee --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/read_text_core_test.cpp @@ -0,0 +1,246 @@ +/* +* 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 + +#define FILE_INFO "hello world" +#define FILE_PATH "/data/test/ReadTextCoreTest.txt" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +const string content = "hello world"; + +class ReadTextCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) { + int32_t fd = open(FILE_PATH, CREATE | O_RDWR, 0644); + write(fd, content.c_str(), content.length()); + close(fd); + }; + static void TearDownTestCase() { + rmdir(FILE_PATH); + }; + void SetUp() {}; + void TearDown() {}; +}; +/** +* @tc.name: DoReadTextTest_0001 +* @tc.desc: Test function of DoReadText() interface for single argument. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0001"; + auto ret = ReadTextCore::DoReadText(FILE_PATH); + EXPECT_TRUE(ret.IsSuccess()); + + const auto &resText = ret.GetData().value(); + string res = std::get<0>(resText); + EXPECT_EQ(res, FILE_INFO); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0001"; +} + +/** +* @tc.name: DoReadTextTest_0002 +* @tc.desc: Test function of DoReadText() interface for invalid offset. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0002"; + ReadTextOptions options; + options.offset = -1; + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0002"; +} + +/** +* @tc.name: DoReadTextTest_0003 +* @tc.desc: Test function of DoReadText() interface for invalid length < 0. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0003"; + ReadTextOptions options; + options.length = -5; + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0003"; +} + +/** +* @tc.name: DoReadTextTest_0004 +* @tc.desc: Test function of DoReadText() interface for invalid length > UINT_MAX. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0004"; + ReadTextOptions options; + options.length = static_cast(UINT_MAX) + 1; + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0004"; +} + +/** +* @tc.name: DoReadTextTest_0005 +* @tc.desc: Test function of DoReadText() interface for invalid encoding. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0005"; + ReadTextOptions options; + options.encoding = "gbk"; + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0005"; +} + +/** +* @tc.name: DoReadTextTest_0006 +* @tc.desc: Test function of DoReadText() interface for no such file or directory. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0006, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0006"; + auto ret = ReadTextCore::DoReadText("ReadTextCoreTest-begin-DoReadTextTest_0006.txt"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900002); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0006"; +} + +/** +* @tc.name: DoReadTextTest_0007 +* @tc.desc: Test function of DoReadText() interface for huge offset. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0007, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0007"; + ReadTextOptions options; + options.offset = 1000000; // 假设文件较小 + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0007"; +} + +/** +* @tc.name: DoReadTextTest_0008 +* @tc.desc: Test function of DoReadText() interface for no such file or directory. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0008, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0008"; + ReadTextOptions options; + options.length = 1000000; // 超过实际大小 + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + ASSERT_TRUE(ret.IsSuccess()); + + const auto &resText = ret.GetData().value(); + string res = std::get<0>(resText); + EXPECT_EQ(res, FILE_INFO); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0008"; +} + +/** +* @tc.name: DoReadTextTest_0009 +* @tc.desc: Test function of DoReadText() interface for success. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +* @tc.require: AR000IGDNF +*/ +HWTEST_F(ReadTextCoreTest, DoReadTextTest_0009, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadTextCoreTest-begin DoReadTextTest_0009"; + ReadTextOptions options; + options.offset = 2; + options.length = 5; + auto ret = ReadTextCore::DoReadText(FILE_PATH, options); + ASSERT_TRUE(ret.IsSuccess()); + + const auto &resText = ret.GetData().value(); + string res = std::get<0>(resText); + std::string extracted = std::string(FILE_INFO).substr( + options.offset.value(), options.length.value()); + EXPECT_EQ(res, extracted); + + GTEST_LOG_(INFO) << "ReadTextCoreTest-end DoReadTextTest_0009"; +} + +} +} +} \ No newline at end of file -- Gitee