diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index e4e6a9d52bb0398a1fa2cc095b3c3d8f1c9e0f3d..7869d244b9b787a65cd80abba802d75851aad296 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -22,15 +22,20 @@ ohos_unittest("ani_file_fs_test") { include_dirs = [ "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", - "mock/uv_fs_mock.h", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stat", ] sources = [ "mod_fs/properties/mock/uv_fs_mock.cpp", "mod_fs/properties/access_core_test.cpp", "mod_fs/properties/dup_core_test.cpp", + "mod_fs/properties/fsync_core_test.cpp", + "mod_fs/properties/lseek_core_test.cpp", + "mod_fs/properties/move_core_test.cpp", "mod_fs/properties/read_core_test.cpp", + "mod_fs/properties/rename_core_test.cpp", "mod_fs/properties/rmdir_core_test.cpp", + "mod_fs/properties/stat_core_test.cpp", "mod_fs/properties/symlink_core_test.cpp", "mod_fs/properties/truncate_core_test.cpp", "mod_fs/properties/utimes_core_test.cpp", diff --git a/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp index 913df19e9f30cf248cb1775e6d0ec0a18f930101..9580f98e71c6b37c4263278f196eb3f74ca12e03 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp @@ -15,6 +15,7 @@ #include "access_core.h" +#include "mock/uv_fs_mock.h" #include #include @@ -30,15 +31,19 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + static inline std::shared_ptr uvMock = nullptr; }; void AccessCoreTest::SetUpTestCase(void) { + uvMock = std::make_shared(); + Uvfs::ins = uvMock; GTEST_LOG_(INFO) << "SetUpTestCase"; } void AccessCoreTest::TearDownTestCase(void) { + Uvfs::ins = nullptr; GTEST_LOG_(INFO) << "TearDownTestCase"; } @@ -74,7 +79,7 @@ HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_001, testing::ext::TestSize.Lev /** * @tc.name: AccessCoreTest_DoAccess_002 - * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for SUCCESS. + * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -86,15 +91,17 @@ HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_002, testing::ext::TestSize.Lev std::string path = "TEST"; std::optional mode; + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(-1)); + auto res = AccessCore::DoAccess(path, mode); - EXPECT_EQ(res.IsSuccess(), true); + EXPECT_EQ(res.IsSuccess(), false); GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_002"; } /** * @tc.name: AccessCoreTest_DoAccess_003 - * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.desc: Test function of AccessCore::ValidAccessArgs interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -103,6 +110,28 @@ HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_003, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_003"; + std::string path = "TEST"; + std::optional mode; + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + + auto res = AccessCore::DoAccess(path, mode); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_003"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_004 + * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_004"; + std::string path = ""; AccessModeType mode = AccessModeType::EXIST; AccessFlag flag = DEFAULT_FLAG; @@ -110,28 +139,53 @@ HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_003, testing::ext::TestSize.Lev auto res = AccessCore::DoAccess(path, mode, flag); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_003"; + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_004"; } /** - * @tc.name: AccessCoreTest_DoAccess_004 + * @tc.name: AccessCoreTest_DoAccess_005 + * @tc.desc: Test function of AccessCore::DoAccess interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_005"; + + std::string path = "TEST"; + AccessModeType mode = AccessModeType::EXIST; + AccessFlag flag = DEFAULT_FLAG; + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = AccessCore::DoAccess(path, mode, flag); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_005"; +} + +/** + * @tc.name: AccessCoreTest_DoAccess_006 * @tc.desc: Test function of AccessCore::DoAccess interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_004, testing::ext::TestSize.Level1) +HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_006, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_004"; + GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreTest_DoAccess_006"; std::string path = "TEST"; AccessModeType mode = AccessModeType::EXIST; AccessFlag flag = DEFAULT_FLAG; + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + auto res = AccessCore::DoAccess(path, mode, flag); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_004"; + GTEST_LOG_(INFO) << "NClassTest-end AccessCoreTest_DoAccess_006"; } diff --git a/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27e2663d8f122f59a3b8393cdc7383bf1009b95b --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp @@ -0,0 +1,329 @@ +/* + * 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 "copy_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 CopyCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void CopyCoreTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void CopyCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void CopyCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void CopyCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: CopyCoreTest_UnregisterListener_001 + * @tc.desc: Test function of CopyCoreTest::UnregisterListener interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_UnregisterListener_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_UnregisterListener_001"; + + std::shared_ptr fileInfos = nullptr; + + CopyCore::UnregisterListener(fileInfos); + EXPECT_EQ(fileInfos, nullptr); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_UnregisterListener_001"; +} + +/** + * @tc.name: CopyCoreTest_UnregisterListener_002 + * @tc.desc: Test function of CopyCoreTest::UnregisterListener interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_UnregisterListener_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_UnregisterListener_002"; + + std::shared_ptr fileInfos = std::make_shared(); + + CopyCore::UnregisterListener(fileInfos); + EXPECT_EQ(CopyCore::jsCbMap_.find(*fileInfos), CopyCore::jsCbMap_.end()); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_UnregisterListener_002"; +} + +/** + * @tc.name: CopyCoreTest_UnregisterListener_003 + * @tc.desc: Test function of CopyCoreTest::UnregisterListener interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_UnregisterListener_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_UnregisterListener_003"; + + std::shared_ptr fileInfos = std::make_shared(); + CopyCore::jsCbMap_[*fileInfos] = nullptr; + + CopyCore::UnregisterListener(fileInfos); + EXPECT_EQ(CopyCore::jsCbMap_.find(*fileInfos), CopyCore::jsCbMap_.end()); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_UnregisterListener_003"; +} + +/** + * @tc.name: CopyCoreTest_ValidOperand_001 + * @tc.desc: Test function of CopyCoreTest::ValidOperand interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ValidOperand_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ValidOperand_001"; + + std::string uriStr = "file://"; + + bool res = CopyCore::ValidOperand(uriStr); + EXPECT_TRUE(res); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ValidOperand_001"; +} + +/** + * @tc.name: CopyCoreTest_ValidOperand_002 + * @tc.desc: Test function of CopyCoreTest::ValidOperand interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ValidOperand_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ValidOperand_002"; + + std::string uriStr = "TEST"; + + bool res = CopyCore::ValidOperand(uriStr); + EXPECT_FALSE(res); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ValidOperand_002"; +} + +/** + * @tc.name: CopyCoreTest_CheckOrCreatePath_001 + * @tc.desc: Test function of CopyCoreTest::CheckOrCreatePath interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_CheckOrCreatePath_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_CheckOrCreatePath_001"; + + std::string destPath = "file"; + + bool res = CopyCore::CheckOrCreatePath(destPath); + EXPECT_EQ(res, 0); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_CheckOrCreatePath_001"; +} + +/** + * @tc.name: CopyCoreTest_CheckOrCreatePath_002 + * @tc.desc: Test function of CopyCoreTest::CheckOrCreatePath interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_CheckOrCreatePath_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_CheckOrCreatePath_002"; + + std::string destPath = "file"; + auto file = open(destPath.c_str(), O_RDWR); + if (file >= 0) { + bool res = CopyCore::CheckOrCreatePathPath); + EXPECT_EQ(res, 0); + } + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_CheckOrCreatePath_002"; +} + +/** + * @tc.name: CopyCoreTest_ValidParam_001 + * @tc.desc: Test function of CopyCoreTest::ValidParam interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ValidParam_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ValidParam_001"; + + string src = "test"; + string dest; + std::optional options = std::nullopt; + std::shared_ptr fileInfos = nullptr; + + int res = CopyCore::ValidParam(src, dest, options, fileInfos); + EXPECT_EQ(res, CommonErrCode::E_PARAMS); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ValidParam_001"; +} + +/** + * @tc.name: CopyCoreTest_ValidParam_002 + * @tc.desc: Test function of CopyCoreTest::ValidParam interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ValidParam_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ValidParam_002"; + + string src = "file://"; + string dest = "file://"; + auto fuc = [] (uint64_t progressSize, uint64_t totalSize) {}; + CopyOptions copyOptions; + copyOptions.listenerCb = fuc; + copyOptions.taskSignalEntityCore = std::make_shared(); + std::optional options = + std::make_optional(copyOptions); + std::shared_ptr fileInfos = nullptr; + + auto res = CopyCore::ValidParam(src, dest, options, fileInfos); + EXPECT_EQ(res, 0); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ValidParam_002"; +} + +/** + * @tc.name: CopyCoreTest_ExecLocal_001 + * @tc.desc: Test function of CopyCoreTest::ExecLocal interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ExecLocal_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ExecLocal_001"; + + std::shared_ptr infos = std::make_shared(); + infos->isFile = true; + infos->srcPath = "test"; + infos->destPath = "test"; + std::shared_ptr callback; + + int res = CopyCore::ExecLocal(infos, callback); + EXPECT_EQ(res, EINVAL); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ExecLocal_001"; +} + +/** + * @tc.name: CopyCoreTest_ExecLocal_002 + * @tc.desc: Test function of CopyCoreTest::ExecLocal interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_ExecLocal_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_ExecLocal_002"; + + std::shared_ptr infos = std::make_shared(); + infos->isFile = true; + infos->srcPath = "srcPath"; + infos->destPath = "destPath"; + infos->hasListener = false; + std::shared_ptr callback; + + int res = CopyCore::ExecLocal(infos, callback); + EXPECT_EQ(res, EINVAL); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ExecLocal_002"; +} + +/** + * @tc.name: CopyCoreTest_GetUVEntry_001 + * @tc.desc: Test function of CopyCoreTest::GetUVEntry interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_GetUVEntry_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_GetUVEntry_001"; + + std::shared_ptr infos = nullptr; + CopyCore::jsCbMap_[*infos] = std::make_shared(nullptr); + + auto res = CopyCore::GetUVEntry(infos); + EXPECT_NE(res, nullptr); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_GetUVEntry_001"; +} + +/** + * @tc.name: CopyCoreTest_GetUVEntry_002 + * @tc.desc: Test function of CopyCoreTest::GetUVEntry interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(CopyCoreTest, CopyCoreTest_GetUVEntry_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CopyCoreTest-begin CopyCoreTest_GetUVEntry_002"; + + std::shared_ptr infos; + + auto res = CopyCore::GetUVEntry(infos); + EXPECT_EQ(res, nullptr); + + GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_GetUVEntry_002"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/fsync_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/fsync_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..169244abe2156000065241783f817c5d05427835 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/fsync_core_test.cpp @@ -0,0 +1,97 @@ +/* + * 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 FsyncCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void FsyncCoreTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void FsyncCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void FsyncCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void FsyncCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: FsyncCoreTest_DoFsync_001 + * @tc.desc: Test function of RenameCore::DoFsync interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FsyncCoreTest, FsyncCoreTest_DoFsync_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsyncCoreTest-begin FsyncCoreTest_DoFsync_001"; + + EXPECT_CALL(*uvfs, uv_fs_fsync(_, _, _, _)).WillOnce(Return(-1)); + + auto res = FsyncCore::DoFsync(1); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "FsyncCoreTest-end FsyncCoreTest_DoFsync_001"; +} + +/** + * @tc.name: FsyncCoreTest_DoFsync_002 + * @tc.desc: Test function of RenameCore::DoFsync interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(FsyncCoreTest, FsyncCoreTest_DoFsync_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsyncCoreTest-begin FsyncCoreTest_DoFsync_002"; + + EXPECT_CALL(*uvfs, uv_fs_fsync(_, _, _, _)).WillOnce(Return(1)); + + auto res = FsyncCore::DoFsync(1); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "FsyncCoreTest-end FsyncCoreTest_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 0000000000000000000000000000000000000000..fc86e7db139655e9ca52900b7a77120fd9597652 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/lseek_core_test.cpp @@ -0,0 +1,120 @@ +/* + * 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 "mock/uv_fs_mock.h" + +#include +#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(); + static inline shared_ptr uvfs = nullptr; +}; + +void LseekCoreTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + 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/mock/uv_fs_mock.cpp b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp index c4f112268ebfe3ef27f7127b1024a5196348b1ec..ec427920db4a5d4e43acfec096e0aa7577a5674d 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp @@ -84,3 +84,31 @@ int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[] { return Uvfs::ins->uv_fs_write(loop, req, fd, bufs, nbufs, offset, cb); } + +void uv_fs_req_cleanup(uv_fs_t *req) +{ + return Uvfs::ins->uv_fs_req_cleanup(req); +} + +int uv_fs_access(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + int flags, + uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_access(loop, req, path, flags, cb); +} + +int uv_fs_rename(uv_loop_t* loop, + uv_fs_t* req, + const char* path, + const char* newPath, + uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_rename(loop, req, path, newPath, cb); +} + +int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) +{ + return Uvfs::ins->uv_fs_fsync(loop, req, file, cb); +} diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h index ad0522f9ee28ca3ecdb1e5d3e8e66fbb8892200a..c0f9a9318a07ab4214af771e1f9bae9360bd0ca1 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h @@ -50,6 +50,10 @@ public: int64_t offset, uv_fs_cb cb) = 0; virtual int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb) = 0; + virtual int uv_fs_access(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb) = 0; + virtual int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path, const char* newPath, uv_fs_cb cb) = 0; + virtual void uv_fs_req_cleanup(uv_fs_t *req) = 0; + virtual int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) = 0; }; class UvfsMock : public Uvfs { @@ -76,6 +80,11 @@ public: int64_t offset, uv_fs_cb cb)); MOCK_METHOD7(uv_fs_write, int(uv_loop_t* loop, uv_fs_t* req, uv_file fd, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_access, int(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_fs_cb cb)); + MOCK_METHOD5(uv_fs_rename, int(uv_loop_t* loop, uv_fs_t* req, const char* path, + const char* newPath, uv_fs_cb cb)); + MOCK_METHOD1(uv_fs_req_cleanup, void(uv_fs_t *req)); + MOCK_METHOD4(uv_fs_fsync, int(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb)); }; diff --git a/interfaces/test/unittest/js/mod_fs/properties/move_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/move_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d71a0f36f04146416705573a42591020d4ad910 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/move_core_test.cpp @@ -0,0 +1,264 @@ +/* + * 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 "move_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 MoveCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline std::shared_ptr uvMock = nullptr; +}; + +void MoveCoreTest::SetUpTestCase(void) +{ + uvMock = std::make_shared(); + Uvfs::ins = uvMock; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void MoveCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void MoveCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void MoveCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_001 + * @tc.desc: Test function of MoveCore::DoMove interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_001"; + + std::string src; + std::string dest; + + auto res = MoveCore::DoMove(src, dest); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_001"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_002 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_002"; + + std::string src; + std::string dest; + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*uvMock, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = MoveCore::DoMove(src, dest); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_002"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_003 + * @tc.desc: Test function of MoveCore::DoMove interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_003"; + + std::string src; + std::string dest; + optional mode = std::make_optional(MODE_FORCE_MOVE); + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*uvMock, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = MoveCore::DoMove(src, dest, mode); + EXPECT_EQ(res.IsSuccess(), false); + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_003"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_004 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_004"; + + std::string src; + std::string dest; + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = MoveCore::DoMove(src, dest); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_004"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_005 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_005"; + + std::string src; + std::string dest; + optional mode = std::make_optional(MODE_THROW_ERR); + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(1)).WillOnce(Return(0)); + + auto res = MoveCore::DoMove(src, dest, mode); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_005"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_006 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_006, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_006"; + + std::string src; + std::string dest; + optional mode = std::make_optional(MODE_THROW_ERR); + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(1)).WillOnce(Return(-1)); + + auto res = MoveCore::DoMove(src, dest, mode); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_006"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_007 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_007, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_007"; + + std::string src; + std::string dest; + optional mode = std::make_optional(MODE_FORCE_MOVE); + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = MoveCore::DoMove(src, dest, mode); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_007"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_008 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_008, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_008"; + + std::string src; + std::string dest; + optional mode = std::make_optional(MODE_FORCE_MOVE); + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(1)); + + auto res = MoveCore::DoMove(src, dest, mode); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_008"; +} + +/** + * @tc.name: MoveCoreTest_DoMove_009 + * @tc.desc: Test function of MoveCore::DoMove interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_009, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_009"; + + std::string src; + std::string dest; + + EXPECT_CALL(*uvMock, uv_fs_access(_, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*uvMock, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(1)); + + auto res = MoveCore::DoMove(src, dest); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_009"; +} + + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp index c4dfda62e57d9df66484565a9b9c19f96adeec8c..9db834d04c8118382da646d23067d2997532e238 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/read_core_test.cpp @@ -16,6 +16,8 @@ #include "read_core.h" #include "mock/uv_fs_mock.h" +#include +#include #include #include @@ -30,10 +32,13 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + static inline std::shared_ptr uvMock = nullptr; }; void ReadCoreTest::SetUpTestCase(void) { + uvMock = std::make_shared(); + Uvfs::ins = uvMock; GTEST_LOG_(INFO) << "SetUpTestCase"; } @@ -61,7 +66,7 @@ void ReadCoreTest::TearDown(void) */ HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_001"; + GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_001"; int32_t fd = -1; void *buf = nullptr; @@ -70,31 +75,28 @@ HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_001, testing::ext::TestSize.Level1) auto res = ReadCore::DoRead(fd, arrayBuffer); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_001"; + GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_001"; } /** * @tc.name: ReadCoreTest_DoRead_002 - * @tc.desc: Test function of ReadCore::DoRead interface for FALSE. + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_002"; - - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_002"; - int32_t fd = 1; + int32_t fd = -1; void *buf = nullptr; - ArrayBuffer arrayBuffer(buf, 0); + ArrayBuffer arrayBuffer(buf, 0xffffffff + 1); + auto res = ReadCore::DoRead(fd, arrayBuffer); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_002"; + GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_002"; } /** @@ -106,19 +108,64 @@ HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_002, testing::ext::TestSize.Level1) */ HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_003, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin ReadCoreTest_DoRead_005"; + GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_003"; + + int32_t fd = -1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + optional options = std::make_optional(); + options->length = std::make_optional(-1); - std::shared_ptr uv = std::make_shared(); - Uvfs::ins = uv; - EXPECT_CALL(*uv, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(1)); + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_003"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_004 + * @tc.desc: Test function of ReadCore::DoRead interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_004"; int32_t fd = 1; void *buf = nullptr; ArrayBuffer arrayBuffer(buf, 0); + + EXPECT_CALL(*uvMock, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(-1)); + + auto res = ReadCore::DoRead(fd, arrayBuffer); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_004"; +} + +/** + * @tc.name: ReadCoreTest_DoRead_005 + * @tc.desc: Test function of ReadCore::DoRead interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(ReadCoreTest, ReadCoreTest_DoRead_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ReadCoreTest-begin ReadCoreTest_DoRead_005"; + + int32_t fd = 1; + void *buf = nullptr; + ArrayBuffer arrayBuffer(buf, 0); + + EXPECT_CALL(*uvMock, uv_fs_read(_, _, _, _, _, _, _)).WillOnce(Return(1)); + auto res = ReadCore::DoRead(fd, arrayBuffer); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end ReadCoreTest_DoRead_003"; + GTEST_LOG_(INFO) << "ReadCoreTest-end ReadCoreTest_DoRead_005"; } } // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/rename_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/rename_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..809b06b786c87ba3e7a68394db93f52cbfd21eeb --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/rename_core_test.cpp @@ -0,0 +1,101 @@ +/* + * 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 RenameCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void RenameCoreTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void RenameCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void RenameCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void RenameCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: RenameCoreTest_DoRename_001 + * @tc.desc: Test function of RenameCore::DoRename interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreTest, RenameCoreTest_DoRename_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreTest-begin RenameCoreTest_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) << "RenameCoreTest-end RenameCoreTest_DoRename_001"; +} + +/** + * @tc.name: RenameCoreTest_DoRename_002 + * @tc.desc: Test function of RenameCore::DoRename interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreTest, RenameCoreTest_DoRename_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreTest-begin RenameCoreTest_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) << "RenameCoreTest-end RenameCoreTest_DoRename_002"; +} + + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/stat_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/stat_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..26cf5ac7713afef373b07487fe39c072a734c2a0 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/stat_core_test.cpp @@ -0,0 +1,192 @@ +/* + * 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 "stat_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 StatCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void StatCoreTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void StatCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void StatCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void StatCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: StatCoreTest_DoStat_001 + * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_001"; + + FileInfo fileinfo; + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_001"; +} + +/** + * @tc.name: StatCoreTest_DoStat_002 + * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_002"; + + FileInfo fileinfo; + fileinfo.path = std::make_unique(1); + fileinfo.isPath = true; + + EXPECT_CALL(*uvfs, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_002"; +} + +/** + * @tc.name: StatCoreTest_DoStat_003 + * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_003"; + + FileInfo fileinfo; + fileinfo.path = std::make_unique(1); + fileinfo.isPath = true; + + EXPECT_CALL(*uvfs, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_003"; +} + +/** + * @tc.name: StatCoreTest_DoStat_004 + * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_004"; + + FileInfo fileinfo; + fileinfo.path = std::make_unique(1); + fileinfo.isPath = false; + + EXPECT_CALL(*uvfs, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_004"; +} + +/** + * @tc.name: StatCoreTest_DoStat_005 + * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_005"; + + FileInfo fileinfo; + fileinfo.path = std::make_unique(1); + fileinfo.fdg = std::make_unique(-1); + fileinfo.isPath = false; + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_005"; +} + +/** + * @tc.name: StatCoreTest_DoStat_006 + * @tc.desc: Test function of FsyncCore::DoStat interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(StatCoreTest, StatCoreTest_DoStat_006, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "StatCoreTest-begin StatCoreTest_DoStat_006"; + + FileInfo fileinfo; + fileinfo.path = std::make_unique(1); + fileinfo.fdg = std::make_unique(1); + fileinfo.isPath = false; + + EXPECT_CALL(*uvfs, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + + auto res = StatCore::DoStat(fileinfo); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "StatCoreTest-end StatCoreTest_DoStat_006"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file