From 0c5c4af45133c905d3b69752850f1a057073f83b Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 28 May 2025 12:06:57 +0000 Subject: [PATCH 1/6] add tdd Signed-off-by: yangbiao59 --- .../mod_fs/properties/dup_core_mock_test.cpp | 80 +++++++++ .../js/mod_fs/properties/dup_core_test.cpp | 13 +- .../properties/fsync_core_mock_test.cpp | 99 ++++++++++ .../js/mod_fs/properties/lseek_core_test.cpp | 115 ++++++++++++ .../properties/rename_core_mock_test.cpp | 103 +++++++++++ .../mod_fs/properties/symlink_core_test.cpp | 39 ++-- .../properties/truncate_core_mock_test.cpp | 170 ++++++++++++++++++ .../mod_fs/properties/truncate_core_test.cpp | 125 +------------ .../properties/utimes_core_mock_test.cpp | 125 +++++++++++++ .../js/mod_fs/properties/utimes_core_test.cpp | 76 +------- .../properties/write_core_mock_test.cpp | 123 +++++++++++++ .../js/mod_fs/properties/write_core_test.cpp | 78 ++++---- 12 files changed, 878 insertions(+), 268 deletions(-) create mode 100644 interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/fsync_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/lseek_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/truncate_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp diff --git a/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp new file mode 100644 index 000000000..196c7b7ef --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp @@ -0,0 +1,80 @@ +/* + * 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 "dup_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class DupCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void DupCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void DupCoreMockTest::TearDownTestCase(void) +{ + Uvfs::ins = nullptr; + uvMock = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void DupCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void DupCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: DupCoreMockTest_DoDup_001 + * @tc.desc: Test function of DupCore::DoDup interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(DupCoreMockTest, DupCoreMockTest_DoDup_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin DupCoreMockTest_DoDup_001"; + + int32_t fd = 1; + + EXPECT_CALL(*uvMock, uv_fs_readlink(_, _, _, _)).WillOnce(Return(-1)); + auto res = DupCore::DoDup(fd); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end DupCoreMockTest_DoDup_001"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp index 6d92836d6..e622a27f6 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp @@ -14,10 +14,10 @@ */ #include "dup_core.h" -#include "mock/uv_fs_mock.h" +#include +#include #include -#include namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -80,16 +80,15 @@ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_001, testing::ext::TestSize.Level1) HWTEST_F(DupCoreTest, DupCoreTest_DoDup_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "NClassTest-begin DupCoreTest_DoDup_002"; - int32_t fd = 1; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_readlink(_, _, _, _)).WillOnce(Return(-1)); + int32_t fd = open("temp_file.txt", O_CREAT | O_RDWR, 0666); + ASSERT_NE(fd, -1); + close(fd); auto res = DupCore::DoDup(fd); + EXPECT_EQ(res.IsSuccess(), false); GTEST_LOG_(INFO) << "NClassTest-end DupCoreTest_DoDup_002"; } - } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/fsync_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fsync_core_mock_test.cpp new file mode 100644 index 000000000..038f5c0c7 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/fsync_core_mock_test.cpp @@ -0,0 +1,99 @@ +/* + * 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 "fsync_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class FsyncCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void FsyncCoreMockTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void FsyncCoreMockTest::TearDownTestCase(void) +{ + Uvfs::ins = nullptr; + uvfs = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void FsyncCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void FsyncCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: FsyncCoreMockTest_DoFsync_001 + * @tc.desc: Test function of RenameCore::DoFsync interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FsyncCoreMockTest, FsyncCoreMockTest_DoFsync_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsyncCoreMockTest-begin FsyncCoreMockTest_DoFsync_001"; + + EXPECT_CALL(*uvfs, uv_fs_fsync(_, _, _, _)).WillOnce(Return(-1)); + + auto res = FsyncCore::DoFsync(1); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "FsyncCoreMockTest-end FsyncCoreMockTest_DoFsync_001"; +} + +/** + * @tc.name: FsyncCoreMockTest_DoFsync_002 + * @tc.desc: Test function of RenameCore::DoFsync interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FsyncCoreMockTest, FsyncCoreMockTest_DoFsync_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsyncCoreMockTest-begin FsyncCoreMockTest_DoFsync_002"; + + EXPECT_CALL(*uvfs, uv_fs_fsync(_, _, _, _)).WillOnce(Return(1)); + + auto res = FsyncCore::DoFsync(1); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "FsyncCoreMockTest-end FsyncCoreMockTest_DoFsync_002"; +} + + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/lseek_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/lseek_core_test.cpp new file mode 100644 index 000000000..60c248d1a --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/lseek_core_test.cpp @@ -0,0 +1,115 @@ +/* + * 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 "lseek_core.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class LseekCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void LseekCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void LseekCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void LseekCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void LseekCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: LseekCoreTest_DoLseek_001 + * @tc.desc: Test function of LseekCore::DoLseek interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LseekCoreTest, LseekCoreTest_DoLseek_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LseekCoreTest-begin LseekCoreTest_DoLseek_001"; + + int32_t fd = -1; + int64_t offset = 0; + + auto res = LseekCore::DoLseek(fd, offset); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "LseekCoreTest-end LseekCoreTest_DoLseek_001"; +} + +/** + * @tc.name: LseekCoreTest_DoLseek_002 + * @tc.desc: Test function of LseekCore::DoLseek interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LseekCoreTest, LseekCoreTest_DoLseek_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LseekCoreTest-begin LseekCoreTest_DoLseek_002"; + + int32_t fd = 1; + int64_t offset = 0; + optional pos = std::make_optional(static_cast(-1)); + + auto res = LseekCore::DoLseek(fd, offset, pos); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "LseekCoreTest-end LseekCoreTest_DoLseek_002"; +} + +/** + * @tc.name: LseekCoreTest_DoLseek_003 + * @tc.desc: Test function of LseekCore::DoLseek interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LseekCoreTest, LseekCoreTest_DoLseek_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LseekCoreTest-begin LseekCoreTest_DoLseek_003"; + + int32_t fd = 1; + int64_t offset = 0; + optional pos = std::make_optional(SeekPos::CURRENT); + + auto res = LseekCore::DoLseek(fd, offset, pos); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "LseekCoreTest-end LseekCoreTest_DoLseek_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp new file mode 100644 index 000000000..2391244cd --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp @@ -0,0 +1,103 @@ +/* + * 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 "rename_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class RenameCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void RenameCoreMockTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void RenameCoreMockTest::TearDownTestCase(void) +{ + Uvfs::ins = nullptr; + uvfs = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void RenameCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void RenameCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: RenameCoreMockTest_DoRename_001 + * @tc.desc: Test function of RenameCore::DoRename interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_001"; + string src; + string dest; + + EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = RenameCore::DoRename(src, dest); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_001"; +} + +/** + * @tc.name: RenameCoreMockTest_DoRename_002 + * @tc.desc: Test function of RenameCore::DoRename interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_002"; + string src; + string dest; + + EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(1)); + + auto res = RenameCore::DoRename(src, dest); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_002"; +} + + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/symlink_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_test.cpp index 2910fcb9e..1d36e44f0 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/symlink_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_test.cpp @@ -25,80 +25,81 @@ using namespace testing; using namespace testing::ext; using namespace std; -class SymlinkCoreTest : public testing::Test { +class SymlinkCoreMockTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); void TearDown(); + static inline shared_ptr uvMock = nullptr; }; -void SymlinkCoreTest::SetUpTestCase(void) +void SymlinkCoreMockTest::SetUpTestCase(void) { GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; } -void SymlinkCoreTest::TearDownTestCase(void) +void SymlinkCoreMockTest::TearDownTestCase(void) { GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; } -void SymlinkCoreTest::SetUp(void) +void SymlinkCoreMockTest::SetUp(void) { GTEST_LOG_(INFO) << "SetUp"; } -void SymlinkCoreTest::TearDown(void) +void SymlinkCoreMockTest::TearDown(void) { GTEST_LOG_(INFO) << "TearDown"; } /** - * @tc.name: SymlinkCoreTest_DoSymlink_001 + * @tc.name: SymlinkCoreMockTest_DoSymlink_001 * @tc.desc: Test function of SymlinkCore::DoSymlink interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(SymlinkCoreTest, SymlinkCoreTest_DoSymlink_001, testing::ext::TestSize.Level1) +HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreTest_DoSymlink_001"; + GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_001"; string target; string srcPath; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(-1)); + EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(-1)); auto res = SymlinkCore::DoSymlink(target, srcPath); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreTest_DoSymlink_001"; + GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_001"; } /** - * @tc.name: SymlinkCoreTest_DoSymlink_002 + * @tc.name: SymlinkCoreMockTest_DoSymlink_002 * @tc.desc: Test function of SymlinkCore::DoSymlink interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(SymlinkCoreTest, SymlinkCoreTest_DoSymlink_002, testing::ext::TestSize.Level1) +HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreTest_DoSymlink_002"; + GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_002"; string target; string srcPath; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(1)); auto res = SymlinkCore::DoSymlink(target, srcPath); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreTest_DoSymlink_002"; + GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_002"; } } // OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/truncate_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/truncate_core_mock_test.cpp new file mode 100644 index 000000000..24d2769ab --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/truncate_core_mock_test.cpp @@ -0,0 +1,170 @@ +/* + * 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 "truncate_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class TruncateCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void TruncateCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void TruncateCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void TruncateCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void TruncateCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: TruncateCoreMockTest_DoTruncate_001 + * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(TruncateCoreMockTest, TruncateCoreMockTest_DoTruncate_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "TruncateCoreMockTest-begin TruncateCoreMockTest_DoTruncate_001"; + + FileInfo fileInfo; + fileInfo.isPath = true; + fileInfo.fdg = std::make_unique(1); + + EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(-1)); + auto res = TruncateCore::DoTruncate(fileInfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "TruncateCoreMockTest-end TruncateCoreMockTest_DoTruncate_001"; +} + +/** + * @tc.name: TruncateCoreMockTest_DoTruncate_002 + * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(TruncateCoreMockTest, TruncateCoreMockTest_DoTruncate_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "TruncateCoreMockTest-begin TruncateCoreMockTest_DoTruncate_002"; + + FileInfo fileInfo; + fileInfo.isPath = true; + fileInfo.fdg = std::make_unique(1); + + EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(-1)); + auto res = TruncateCore::DoTruncate(fileInfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "TruncateCoreMockTest-end TruncateCoreMockTest_DoTruncate_002"; +} + +/** + * @tc.name: TruncateCoreMockTest_DoTruncate_003 + * @tc.desc: Test function of RmdirCore::DoTruncate interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(TruncateCoreMockTest, TruncateCoreMockTest_DoTruncate_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "TruncateCoreMockTest-begin TruncateCoreMockTest_DoTruncate_003"; + + FileInfo fileInfo; + fileInfo.isPath = true; + fileInfo.fdg = std::make_unique(1); + + EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(1)); + auto res = TruncateCore::DoTruncate(fileInfo); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "TruncateCoreMockTest-end TruncateCoreMockTest_DoTruncate_003"; +} + +/** + * @tc.name: TruncateCoreMockTest_DoTruncate_004 + * @tc.desc: Test function of RmdirCore::DoTruncate interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(TruncateCoreMockTest, TruncateCoreMockTest_DoTruncate_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "TruncateCoreMockTest-begin TruncateCoreMockTest_DoTruncate_004"; + + FileInfo fileInfo; + fileInfo.fdg = std::make_unique(1); + + EXPECT_CALL(*uvMock, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(-1)); + auto res = TruncateCore::DoTruncate(fileInfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "TruncateCoreMockTest-end TruncateCoreMockTest_DoTruncate_004"; +} + +/** + * @tc.name: TruncateCoreMockTest_DoTruncate_005 + * @tc.desc: Test function of RmdirCore::DoTruncate interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(TruncateCoreMockTest, TruncateCoreMockTest_DoTruncate_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "TruncateCoreMockTest-begin TruncateCoreMockTest_DoTruncate_005"; + + FileInfo fileInfo; + fileInfo.fdg = std::make_unique(1); + + EXPECT_CALL(*uvMock, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(1)); + auto res = TruncateCore::DoTruncate(fileInfo); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "TruncateCoreMockTest-end TruncateCoreMockTest_DoTruncate_005"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/truncate_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/truncate_core_test.cpp index cb1ef1e16..b9a98e51f 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/truncate_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/truncate_core_test.cpp @@ -14,10 +14,9 @@ */ #include "truncate_core.h" -#include "mock/uv_fs_mock.h" #include -#include + namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -91,126 +90,4 @@ HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_002, testing::ext::TestSi GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_002"; } -/** - * @tc.name: TruncateCoreTest_DoTruncate_003 - * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_003"; - FileInfo fileInfo; - fileInfo.isPath = true; - fileInfo.fdg = std::make_unique(1); - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(-1)); - - auto res = TruncateCore::DoTruncate(fileInfo); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_003"; -} - -/** - * @tc.name: TruncateCoreTest_DoTruncate_004 - * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_004"; - FileInfo fileInfo; - fileInfo.isPath = true; - fileInfo.fdg = std::make_unique(1); - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(1)); - EXPECT_CALL(*uv, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(-1)); - - auto res = TruncateCore::DoTruncate(fileInfo); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_004"; -} - -/** - * @tc.name: TruncateCoreTest_DoTruncate_005 - * @tc.desc: Test function of RmdirCore::DoTruncate interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_005, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_005"; - FileInfo fileInfo; - fileInfo.isPath = true; - fileInfo.fdg = std::make_unique(1); - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(1)); - EXPECT_CALL(*uv, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(1)); - - auto res = TruncateCore::DoTruncate(fileInfo); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_005"; -} - -/** - * @tc.name: TruncateCoreTest_DoTruncate_006 - * @tc.desc: Test function of RmdirCore::DoTruncate interface for FALSE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_006, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_006"; - FileInfo fileInfo; - fileInfo.fdg = std::make_unique(1); - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(-1)); - - auto res = TruncateCore::DoTruncate(fileInfo); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_006"; -} - -/** - * @tc.name: TruncateCoreTest_DoTruncate_007 - * @tc.desc: Test function of RmdirCore::DoTruncate interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_007, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_007"; - FileInfo fileInfo; - fileInfo.fdg = std::make_unique(1); - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_ftruncate(_, _, _, _, _)).WillOnce(Return(1)); - - auto res = TruncateCore::DoTruncate(fileInfo); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_007"; -} - } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp new file mode 100644 index 000000000..c2aba0a67 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp @@ -0,0 +1,125 @@ +/* + * 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 "utimes_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class UtimesCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void UtimesCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void UtimesCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void UtimesCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void UtimesCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_001 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for Failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_001"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_001"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_002 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_002"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(-1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_002"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_003 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_003"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp index b81af547a..54ee576cc 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp @@ -14,10 +14,9 @@ */ #include "utimes_core.h" -#include "mock/uv_fs_mock.h" #include -#include + namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -62,84 +61,13 @@ void UtimesCoreTest::TearDown(void) HWTEST_F(UtimesCoreTest, UtimesCoreTest_DoUtimes_001, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "UtimesCoreTest-begin UtimesCoreTest_DoUtimes_001"; + string path; double mtime = -1; auto res = UtimesCore::DoUtimes(path, mtime); - EXPECT_EQ(res.IsSuccess(), false); GTEST_LOG_(INFO) << "UtimesCoreTest-end UtimesCoreTest_DoUtimes_001"; } -/** - * @tc.name: UtimesCoreTest_DoUtimes_002 - * @tc.desc: Test function of UtimesCore::DoUtimes interface for Failed. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(UtimesCoreTest, UtimesCoreTest_DoUtimes_002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "UtimesCoreTest-begin UtimesCoreTest_DoUtimes_002"; - string path; - double mtime = 1; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); - - auto res = UtimesCore::DoUtimes(path, mtime); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "UtimesCoreTest-end UtimesCoreTest_DoUtimes_002"; -} - -/** - * @tc.name: UtimesCoreTest_DoUtimes_003 - * @tc.desc: Test function of UtimesCore::DoUtimes interface for FALSE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(UtimesCoreTest, UtimesCoreTest_DoUtimes_003, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "UtimesCoreTest-begin UtimesCoreTest_DoUtimes_003"; - string path; - double mtime = 1; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); - EXPECT_CALL(*uv, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(-1)); - - auto res = UtimesCore::DoUtimes(path, mtime); - EXPECT_EQ(res.IsSuccess(), false); - - GTEST_LOG_(INFO) << "UtimesCoreTest-end UtimesCoreTest_DoUtimes_003"; -} - -/** - * @tc.name: UtimesCoreTest_DoUtimes_004 - * @tc.desc: Test function of UtimesCore::DoUtimes interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(UtimesCoreTest, UtimesCoreTest_DoUtimes_004, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "UtimesCoreTest-begin UtimesCoreTest_DoUtimes_004"; - string path; - double mtime = 1; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); - EXPECT_CALL(*uv, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(1)); - - auto res = UtimesCore::DoUtimes(path, mtime); - EXPECT_EQ(res.IsSuccess(), true); - - GTEST_LOG_(INFO) << "UtimesCoreTest-end UtimesCoreTest_DoUtimes_004"; -} - } // namespace OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp new file mode 100644 index 000000000..c88af5150 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp @@ -0,0 +1,123 @@ +/* + * 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 "write_core.h" +#include "mock/uv_fs_mock.h" + +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class WriteCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void WriteCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void WriteCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void WriteCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void WriteCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: WriteCoreMockTest_DoWrite1_001 + * @tc.desc: Test function of WriteCore::DoWrite3 interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(WriteCoreMockTest, WriteCoreMockTest_DoWrite1_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteCoreMockTest-begin WriteCoreMockTest_DoWrite1_001"; + + int32_t fd = 1; + string buffer; + + EXPECT_CALL(*uvMock, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + auto res = WriteCore::DoWrite(fd, buffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "WriteCoreMockTest-end WriteCoreMockTest_DoWrite1_001"; +} + +/** + * @tc.name: WriteCoreMockTest_DoWrite1_002 + * @tc.desc: Test function of WriteCore::DoWrite3 interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(WriteCoreMockTest, WriteCoreMockTest_DoWrite1_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteCoreMockTest-begin WriteCoreMockTest_DoWrite1_002"; + + int32_t fd = 1; + string buffer; + + EXPECT_CALL(*uvMock, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(1)); + auto res = WriteCore::DoWrite(fd, buffer); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "WriteCoreMockTest-end WriteCoreMockTest_DoWrite1_002"; +} + +/** + * @tc.name: WriteCoreMockTest_DoWrite2_003 + * @tc.desc: Test function of WriteCore::DoWrite2 interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(WriteCoreMockTest, WriteCoreMockTest_DoWrite2_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WriteCoreMockTest-begin WriteCoreMockTest_DoWrite2_003"; + + int32_t fd = -1; + string buffer; + + EXPECT_CALL(*uvMock, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + auto res = WriteCore::DoWrite(fd, buffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "WriteCoreMockTest-end WriteCoreMockTest_DoWrite2_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/write_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/write_core_test.cpp index c6ee32ef6..1741f168f 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/write_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/write_core_test.cpp @@ -14,10 +14,8 @@ */ #include "write_core.h" -#include "mock/uv_fs_mock.h" #include -#include namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -71,88 +69,80 @@ HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_001, testing::ext::TestSize.Level } /** - * @tc.name: WriteCoreTest_DoWrite1_002 - * @tc.desc: Test function of WriteCore::DoWrite3 interface for FALSE. + * @tc.name: WriteCoreTest_DoWrite2_001 + * @tc.desc: Test function of WriteCore::DoWrite2 interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_002, testing::ext::TestSize.Level1) +HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite2_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite1_002"; - int32_t fd = 1; + GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite2_001"; + int32_t fd = -1; string buffer; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(-1)); auto res = WriteCore::DoWrite(fd, buffer); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite1_002"; + GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite2_001"; } +#if defined(_WIN64) || defined(__X86_64__) || defined(__ppc64__) || defined(__LP64__) /** - * @tc.name: WriteCoreTest_DoWrite1_003 - * @tc.desc: Test function of WriteCore::DoWrite3 interface for SUCCESS. + * @tc.name: WriteCoreTest_DoWrite1_002 + * @tc.desc: Test function of WriteCore::DoWrite1 interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_003, testing::ext::TestSize.Level1) +HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite1_003"; - int32_t fd = 1; - string buffer; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(1)); + GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite1_002"; + int32_t fd = -1; + ArrayBuffer buffer(nullptr, 0); auto res = WriteCore::DoWrite(fd, buffer); - EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite1_003"; + EXPECT_EQ(res.IsSuccess(), false); + GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite1_002"; } +#else +#endif /** - * @tc.name: WriteCoreTest_DoWrite2_001 - * @tc.desc: Test function of WriteCore::DoWrite2 interface for FALSE. + * @tc.name: WriteCoreTest_DoWrite1_003 + * @tc.desc: Test function of WriteCore::DoWrite1 interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite2_001, testing::ext::TestSize.Level1) +HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_003, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite2_001"; - int32_t fd = -1; - string buffer; + GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite1_003"; + int32_t fd = 1; + ArrayBuffer buffer(nullptr, 1); + std::optional options = std::make_optional(WriteOptions()); + options->offset = std::make_optional(-1); - auto res = WriteCore::DoWrite(fd, buffer); + auto res = WriteCore::DoWrite(fd, buffer, options); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite2_001"; + GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite1_003"; } /** - * @tc.name: WriteCoreTest_DoWrite2_002 - * @tc.desc: Test function of WriteCore::DoWrite2 interface for FALSE. + * @tc.name: WriteCoreTest_DoWrite1_004 + * @tc.desc: Test function of WriteCore::DoWrite1 interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite2_002, testing::ext::TestSize.Level1) +HWTEST_F(WriteCoreTest, WriteCoreTest_DoWrite1_004, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite2_002"; - int32_t fd = -1; - string buffer; - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - - EXPECT_CALL(*uv, uv_fs_write(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + GTEST_LOG_(INFO) << "WriteCoreTest-begin WriteCoreTest_DoWrite1_004"; + int32_t fd = 1; + ArrayBuffer buffer(nullptr, 1); auto res = WriteCore::DoWrite(fd, buffer); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite2_002"; + GTEST_LOG_(INFO) << "WriteCoreTest-end WriteCoreTest_DoWrite1_004"; } - } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 3c1e0a33e5f1c2227544d8ac6ed6069d4d248b57 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Thu, 29 May 2025 08:06:02 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangbiao59 --- .../unittest/js/mod_fs/properties/dup_core_mock_test.cpp | 4 ++-- .../test/unittest/js/mod_fs/properties/dup_core_test.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp index 196c7b7ef..3b2a2aa05 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/dup_core_mock_test.cpp @@ -66,7 +66,7 @@ void DupCoreMockTest::TearDown(void) */ HWTEST_F(DupCoreMockTest, DupCoreMockTest_DoDup_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin DupCoreMockTest_DoDup_001"; + GTEST_LOG_(INFO) << "DupCoreMockTest-begin DupCoreMockTest_DoDup_001"; int32_t fd = 1; @@ -74,7 +74,7 @@ HWTEST_F(DupCoreMockTest, DupCoreMockTest_DoDup_001, testing::ext::TestSize.Leve auto res = DupCore::DoDup(fd); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end DupCoreMockTest_DoDup_001"; + GTEST_LOG_(INFO) << "DupCoreMockTest-end DupCoreMockTest_DoDup_001"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp index e622a27f6..f1dc1b2f8 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp @@ -61,13 +61,13 @@ void DupCoreTest::TearDown(void) */ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin DupCoreTest_DoDup_001"; + GTEST_LOG_(INFO) << "DupCoreTest-begin DupCoreTest_DoDup_001"; int32_t fd = -1; auto res = DupCore::DoDup(fd); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end DupCoreTest_DoDup_001"; + GTEST_LOG_(INFO) << "DupCoreTest-end DupCoreTest_DoDup_001"; } /** @@ -79,7 +79,7 @@ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_001, testing::ext::TestSize.Level1) */ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin DupCoreTest_DoDup_002"; + GTEST_LOG_(INFO) << "DupCoreTest-begin DupCoreTest_DoDup_002"; int32_t fd = open("temp_file.txt", O_CREAT | O_RDWR, 0666); ASSERT_NE(fd, -1); close(fd); @@ -88,7 +88,7 @@ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_002, testing::ext::TestSize.Level1) EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end DupCoreTest_DoDup_002"; + GTEST_LOG_(INFO) << "DupCoreTest-end DupCoreTest_DoDup_002"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 50afdcb96b175e99d4f3e5f6beb264224b672c2a Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Thu, 29 May 2025 11:51:04 +0000 Subject: [PATCH 3/6] update interfaces/test/unittest/js/BUILD.gn. Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 60 +++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index 7b67ba03b..42557c135 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -34,7 +34,12 @@ ohos_unittest("ani_file_fs_test") { ] sources = [ - "mod_fs/class_stream/fs_stream_test.cpp", + "mod_fs/properties/dup_core_test.cpp", + "mod_fs/properties/lseek_core_test.cpp", + "mod_fs/properties/symlink_core_test.cpp", + "mod_fs/properties/truncate_core_test.cpp", + "mod_fs/properties/utimes_core_test.cpp", + "mod_fs/properties/write_core_test.cpp", ] deps = [ @@ -56,6 +61,59 @@ ohos_unittest("ani_file_fs_test") { "libuv:uv", ] + defines = [ + "private=public", + ] +} + +ohos_unittest("ani_file_fs_mock_test") { + branch_protector_ret = "pac_ret" + 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_atomicfile", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_randomaccessfile", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_readeriterator", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stat", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stream", + "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", + "${file_api_path}/interfaces/test/unittest/js/mod_fs/properties/mock", + ] + + sources = [ + "mod_fs/properties/dup_core_mock_test.cpp", + "mod_fs/properties/fsync_core_mock_test.cpp", + "mod_fs/properties/rename_core_mock_test.cpp", + "mod_fs/properties/truncate_core_mock_test.cpp", + "mod_fs/properties/utimes_core_mock_test.cpp", + "mod_fs/properties/write_core_mock_test.cpp", + ] + + deps = [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/native:task_signal_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${file_api_path}/interfaces/kits/js:ani_file_fs", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "app_file_service:fileuri_native", + "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_core", + "libuv:uv", + ] + defines = [ "private=public", ] -- Gitee From c70cf20181cdf3cc7a8294675978a6e0cd195fa9 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Thu, 29 May 2025 14:34:06 +0000 Subject: [PATCH 4/6] update interfaces/test/unittest/js/BUILD.gn. Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index c5e7f74a9..247c7d67e 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -36,7 +36,6 @@ ohos_unittest("ani_file_fs_test") { sources = [ "mod_fs/properties/dup_core_test.cpp", "mod_fs/properties/lseek_core_test.cpp", - "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_test.cpp", "mod_fs/properties/utimes_core_test.cpp", "mod_fs/properties/write_core_test.cpp", @@ -95,6 +94,7 @@ ohos_unittest("ani_file_fs_mock_test") { "mod_fs/properties/dup_core_mock_test.cpp", "mod_fs/properties/fsync_core_mock_test.cpp", "mod_fs/properties/rename_core_mock_test.cpp", + "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_mock_test.cpp", "mod_fs/properties/utimes_core_mock_test.cpp", "mod_fs/properties/write_core_mock_test.cpp", -- Gitee From bd70d91d4b203a06ebd7bc93eb58afa660ce0d1b Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Fri, 30 May 2025 07:20:46 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangbiao59 --- .../test/unittest/js/mod_fs/properties/dup_core_test.cpp | 2 +- .../unittest/js/mod_fs/properties/utimes_core_mock_test.cpp | 3 +-- .../unittest/js/mod_fs/properties/write_core_mock_test.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp index f1dc1b2f8..e9c4d733d 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/dup_core_test.cpp @@ -80,7 +80,7 @@ HWTEST_F(DupCoreTest, DupCoreTest_DoDup_001, testing::ext::TestSize.Level1) HWTEST_F(DupCoreTest, DupCoreTest_DoDup_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "DupCoreTest-begin DupCoreTest_DoDup_002"; - int32_t fd = open("temp_file.txt", O_CREAT | O_RDWR, 0666); + int32_t fd = open("DupCoreTest_DoDup.txt", O_CREAT | O_RDWR, 0666); ASSERT_NE(fd, -1); close(fd); diff --git a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp index c2aba0a67..c429451ed 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp @@ -14,10 +14,9 @@ */ #include "utimes_core.h" -#include "mock/uv_fs_mock.h" +#include "uv_fs_mock.h" #include -#include namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; diff --git a/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp index c88af5150..e16651fad 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/write_core_mock_test.cpp @@ -14,10 +14,9 @@ */ #include "write_core.h" -#include "mock/uv_fs_mock.h" +#include "uv_fs_mock.h" #include -#include namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; -- Gitee From 6cb5be00f9750eba4f9fbf52a4973cc53c5dae56 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Wed, 18 Jun 2025 03:45:52 +0000 Subject: [PATCH 6/6] new Signed-off-by: yangbiao59 --- interfaces/test/unittest/js/BUILD.gn | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index da839ff1f..d7ed4a365 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -20,6 +20,8 @@ ohos_unittest("ani_file_fs_test") { 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_atomicfile", "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", @@ -77,6 +79,8 @@ ohos_unittest("ani_file_fs_mock_test") { 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_atomicfile", "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", -- Gitee