From a561f02bf2d2c7df834863a6e81f932a0712285b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E9=87=91=E6=B2=9B?= Date: Sat, 26 Jul 2025 18:07:42 +0800 Subject: [PATCH 1/2] file/stat TDD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶金沛 Change-Id: I48e7d0c1b82bbd2c0ab0750dd235bb473a1d35a1 --- .../mod_fs/class_file/fs_file_mock_test.cpp | 180 +++++++++--------- .../js/mod_fs/class_file/fs_file_test.cpp | 168 ++++++++-------- .../mod_fs/class_stat/fs_stat_mock_test.cpp | 40 ++-- .../unittest/js/mod_fs/common/fs_err_code.h | 34 ++++ .../unittest/js/mod_fs/mock/eventfd_mock.cpp | 83 ++++++++ .../unittest/js/mod_fs/mock/eventfd_mock.h | 53 ++++++ .../unittest/js/mod_fs/mock/inotify_mock.cpp | 125 ++++++++++++ .../unittest/js/mod_fs/mock/inotify_mock.h | 57 ++++++ .../js/mod_fs/mock/mock_progress_listener.h | 29 +++ .../unittest/js/mod_fs/mock/poll_mock.cpp | 83 ++++++++ .../test/unittest/js/mod_fs/mock/poll_mock.h | 53 ++++++ .../unittest/js/mod_fs/mock/unistd_mock.cpp | 125 ++++++++++++ .../unittest/js/mod_fs/mock/unistd_mock.h | 57 ++++++ .../properties/access_core_mock_test.cpp | 39 +--- .../js/mod_fs/properties/access_core_test.cpp | 12 +- .../properties/mkdir_core_mock_test.cpp | 10 +- .../js/mod_fs/properties/mock/system_mock.cpp | 2 +- .../js/mod_fs/properties/mock/system_mock.h | 4 +- .../js/mod_fs/properties/mock/uv_fs_mock.cpp | 8 +- .../js/mod_fs/properties/mock/uv_fs_mock.h | 25 +-- .../mod_fs/properties/open_core_mock_test.cpp | 77 ++++---- .../js/mod_fs/properties/open_core_test.cpp | 88 ++++----- .../mod_fs/properties/stat_core_mock_test.cpp | 29 ++- .../js/mod_fs/properties/stat_core_test.cpp | 4 +- 24 files changed, 1033 insertions(+), 352 deletions(-) create mode 100644 interfaces/test/unittest/js/mod_fs/common/fs_err_code.h create mode 100644 interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.h create mode 100644 interfaces/test/unittest/js/mod_fs/mock/inotify_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/mock/inotify_mock.h create mode 100644 interfaces/test/unittest/js/mod_fs/mock/mock_progress_listener.h create mode 100644 interfaces/test/unittest/js/mod_fs/mock/poll_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/mock/poll_mock.h create mode 100644 interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/mock/unistd_mock.h diff --git a/interfaces/test/unittest/js/mod_fs/class_file/fs_file_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/class_file/fs_file_mock_test.cpp index 0dcd0e963..90cc1f29f 100644 --- a/interfaces/test/unittest/js/mod_fs/class_file/fs_file_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/class_file/fs_file_mock_test.cpp @@ -75,12 +75,12 @@ void FsFileMockTest::TearDown(void) } /** -* @tc.name: FsFileMockTest_GetPath_001 -* @tc.desc: Test function of GetPath() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetPath_001 + * @tc.desc: Test function of GetPath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetPath_001, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetPath_001"; @@ -100,12 +100,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetPath_001, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetPath_002 -* @tc.desc: Test function of GetPath() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetPath_002 + * @tc.desc: Test function of GetPath() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetPath_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetPath_002"; @@ -119,12 +119,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetPath_002, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetName_003 -* @tc.desc: Test function of GetName() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetName_003 + * @tc.desc: Test function of GetName() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_003, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetName_003"; @@ -138,12 +138,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_003, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetName_004 -* @tc.desc: Test function of GetName() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetName_004 + * @tc.desc: Test function of GetName() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_004, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetName_004"; @@ -157,12 +157,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_004, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetParent_005 -* @tc.desc: Test function of GetParent() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetParent_005 + * @tc.desc: Test function of GetParent() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_005, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetParent_005"; @@ -176,12 +176,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_005, testing::ext::TestSize.Le } /** -* @tc.name: FsFileMockTest_GetName_006 -* @tc.desc: Test function of GetName() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetName_006 + * @tc.desc: Test function of GetName() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_006, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetName_006"; @@ -201,12 +201,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_006, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetParent_007 -* @tc.desc: Test function of GetParent() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetParent_007 + * @tc.desc: Test function of GetParent() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_007, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetParent_007"; @@ -226,12 +226,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_007, testing::ext::TestSize.Le } /** -* @tc.name: FsFileMockTest_GetName_008 -* @tc.desc: Test function of GetName() interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetName_008 + * @tc.desc: Test function of GetName() interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_008, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetName_008"; @@ -251,12 +251,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetName_008, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_GetParent_009 -* @tc.desc: Test function of GetParent() interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_GetParent_009 + * @tc.desc: Test function of GetParent() interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_009, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_GetParent_009"; @@ -276,12 +276,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_GetParent_009, testing::ext::TestSize.Le } /** -* @tc.name: FsFileMockTest_Lock_010 -* @tc.desc: Test function of Lock() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_Lock_010 + * @tc.desc: Test function of Lock() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_Lock_010, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_Lock_010"; @@ -294,12 +294,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_Lock_010, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileMockTest_Lock_011 -* @tc.desc: Test function of Lock() interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_Lock_011 + * @tc.desc: Test function of Lock() interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_Lock_011, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_Lock_011"; @@ -312,12 +312,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_Lock_011, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileMockTest_TryLock_012 -* @tc.desc: Test function of TryLock() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_TryLock_012 + * @tc.desc: Test function of TryLock() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_TryLock_012, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_TryLock_012"; @@ -330,12 +330,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_TryLock_012, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_TryLock_013 -* @tc.desc: Test function of TryLock() interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_TryLock_013 + * @tc.desc: Test function of TryLock() interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_TryLock_013, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_TryLock_013"; @@ -348,12 +348,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_TryLock_013, testing::ext::TestSize.Leve } /** -* @tc.name: FsFileMockTest_UnLock_014 -* @tc.desc: Test function of UnLock() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_UnLock_014 + * @tc.desc: Test function of UnLock() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_UnLock_014, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_UnLock_014"; @@ -366,12 +366,12 @@ HWTEST_F(FsFileMockTest, FsFileMockTest_UnLock_014, testing::ext::TestSize.Level } /** -* @tc.name: FsFileMockTest_UnLock_015 -* @tc.desc: Test function of UnLock() interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileMockTest_UnLock_015 + * @tc.desc: Test function of UnLock() interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileMockTest, FsFileMockTest_UnLock_015, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileMockTest-begin FsFileMockTest_UnLock_015"; diff --git a/interfaces/test/unittest/js/mod_fs/class_file/fs_file_test.cpp b/interfaces/test/unittest/js/mod_fs/class_file/fs_file_test.cpp index 242d472ff..e432f66f6 100644 --- a/interfaces/test/unittest/js/mod_fs/class_file/fs_file_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/class_file/fs_file_test.cpp @@ -29,8 +29,8 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); - std::unique_ptr fileEntity; - std::unique_ptr fsFile; + unique_ptr fileEntity; + unique_ptr fsFile; }; void FsFileTest::SetUpTestCase(void) @@ -47,13 +47,13 @@ void FsFileTest::SetUp(void) { GTEST_LOG_(INFO) << "SetUp"; - fileEntity = std::make_unique(); + fileEntity = make_unique(); const int fdValue = 3; const bool isClosed = false; - fileEntity->fd_ = std::make_unique(fdValue, isClosed); + fileEntity->fd_ = make_unique(fdValue, isClosed); fileEntity->path_ = "/data/test/file_test.txt"; fileEntity->uri_ = ""; - fsFile = std::make_unique(std::move(fileEntity)); + fsFile = make_unique(move(fileEntity)); } void FsFileTest::TearDown(void) @@ -62,12 +62,12 @@ void FsFileTest::TearDown(void) } /** -* @tc.name: FsFileTest_Constructor_001 -* @tc.desc: Test function of FsFile::Constructor() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_Constructor_001 + * @tc.desc: Test function of FsFile::Constructor() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_Constructor_001, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_Constructor_001"; @@ -79,12 +79,12 @@ HWTEST_F(FsFileTest, FsFileTest_Constructor_001, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetFD_002 -* @tc.desc: Test function of GetFD() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetFD_002 + * @tc.desc: Test function of GetFD() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetFD_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetFD_002"; @@ -96,17 +96,17 @@ HWTEST_F(FsFileTest, FsFileTest_GetFD_002, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetFD_003 -* @tc.desc: Test function of GetFD() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetFD_003 + * @tc.desc: Test function of GetFD() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetFD_003, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetFD_003"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->GetFD(); EXPECT_EQ(result.IsSuccess(), false); @@ -114,17 +114,17 @@ HWTEST_F(FsFileTest, FsFileTest_GetFD_003, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetPath_004 -* @tc.desc: Test function of GetPath() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetPath_004 + * @tc.desc: Test function of GetPath() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetPath_004, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetPath_004"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->GetPath(); EXPECT_EQ(result.IsSuccess(), false); @@ -132,17 +132,17 @@ HWTEST_F(FsFileTest, FsFileTest_GetPath_004, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetName_005 -* @tc.desc: Test function of GetName() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetName_005 + * @tc.desc: Test function of GetName() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetName_005, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetName_005"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->GetName(); EXPECT_EQ(result.IsSuccess(), false); @@ -150,17 +150,17 @@ HWTEST_F(FsFileTest, FsFileTest_GetName_005, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetParent_006 -* @tc.desc: Test function of GetParent() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetParent_006 + * @tc.desc: Test function of GetParent() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetParent_006, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetParent_006"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->GetParent(); EXPECT_EQ(result.IsSuccess(), false); @@ -168,17 +168,17 @@ HWTEST_F(FsFileTest, FsFileTest_GetParent_006, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_Lock_007 -* @tc.desc: Test function of Lock() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_Lock_007 + * @tc.desc: Test function of Lock() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_Lock_007, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_Lock_007"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->Lock(true); EXPECT_EQ(result.IsSuccess(), false); @@ -186,17 +186,17 @@ HWTEST_F(FsFileTest, FsFileTest_Lock_007, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_TryLock_008 -* @tc.desc: Test function of TryLock() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_TryLock_008 + * @tc.desc: Test function of TryLock() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_TryLock_008, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_TryLock_008"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->TryLock(true); EXPECT_EQ(result.IsSuccess(), false); @@ -204,17 +204,17 @@ HWTEST_F(FsFileTest, FsFileTest_TryLock_008, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_UnLock_009 -* @tc.desc: Test function of UnLock() interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_UnLock_009 + * @tc.desc: Test function of UnLock() interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_UnLock_009, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_UnLock_009"; - fsFile = std::make_unique(nullptr); + fsFile = make_unique(nullptr); auto result = fsFile->UnLock(); EXPECT_EQ(result.IsSuccess(), false); @@ -222,12 +222,12 @@ HWTEST_F(FsFileTest, FsFileTest_UnLock_009, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetName_010 -* @tc.desc: Test function of GetName() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetName_010 + * @tc.desc: Test function of GetName() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetName_010, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetName_010"; @@ -240,12 +240,12 @@ HWTEST_F(FsFileTest, FsFileTest_GetName_010, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetParent_011 -* @tc.desc: Test function of GetParent() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetParent_011 + * @tc.desc: Test function of GetParent() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetParent_011, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetParent_011"; @@ -258,12 +258,12 @@ HWTEST_F(FsFileTest, FsFileTest_GetParent_011, testing::ext::TestSize.Level1) } /** -* @tc.name: FsFileTest_GetPath_012 -* @tc.desc: Test function of GetPath() interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: FsFileTest_GetPath_012 + * @tc.desc: Test function of GetPath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(FsFileTest, FsFileTest_GetPath_012, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "FsFileTest-begin FsFileTest_GetPath_012"; diff --git a/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp index ea2e168d5..2de8331e0 100644 --- a/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ -#include "fs_stat.h" -#include "../properties/mock/system_mock.h" +#include +#include + #include "fs_stat_entity.h" +#include "fs_stat.h" #include "securec.h" - -#include -#include +#include "system_mock.h" namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -38,7 +38,7 @@ public: void FsStatMockTest::SetUpTestCase(void) { GTEST_LOG_(INFO) << "SetUpTestCase"; - sys = std::make_shared(); + sys = make_shared(); System::ins = sys; } @@ -70,17 +70,17 @@ HWTEST_F(FsStatMockTest, FsStatMockTest_GetLocation_001, testing::ext::TestSize. { GTEST_LOG_(INFO) << "FsStatMockTes-begin FsStatMockTest_GetLocation_001"; - std::unique_ptr statEntity; - std::unique_ptr fsStat; - statEntity = std::make_unique(); - statEntity->fileInfo_ = std::make_unique(); + unique_ptr statEntity; + unique_ptr fsStat; + statEntity = make_unique(); + statEntity->fileInfo_ = make_unique(); statEntity->fileInfo_->isPath = true; int length = 100; - string testPath = "/test/path"; - statEntity->fileInfo_->path = std::make_unique(length); + string testPath = "/test/stat_path"; + statEntity->fileInfo_->path = make_unique(length); strncpy_s(statEntity->fileInfo_->path.get(), length, testPath.c_str(), testPath.size()); statEntity->fileInfo_->path.get()[99] = '\0'; - fsStat = std::make_unique(std::move(statEntity)); + fsStat = make_unique(move(statEntity)); EXPECT_CALL(*sys, getxattr(_, _, _, _)).WillOnce(Return(1)); EXPECT_EQ(fsStat->GetLocation(), 1); @@ -99,15 +99,15 @@ HWTEST_F(FsStatMockTest, FsStatMockTest_GetLocation_002, testing::ext::TestSize. { GTEST_LOG_(INFO) << "FsStatMockTes-begin FsStatMockTest_GetLocation_002"; - std::unique_ptr statEntity; - std::unique_ptr fsStat; - statEntity = std::make_unique(); - statEntity->fileInfo_ = std::make_unique(); + unique_ptr statEntity; + unique_ptr fsStat; + statEntity = make_unique(); + statEntity->fileInfo_ = make_unique(); statEntity->fileInfo_->isPath = false; - const int fdValue = 3; + const int fdValue = 3; //模拟fd为3 const bool isClosed = false; - statEntity->fileInfo_->fdg = std::make_unique(fdValue, isClosed); - fsStat = std::make_unique(std::move(statEntity)); + statEntity->fileInfo_->fdg = make_unique(fdValue, isClosed); + fsStat = make_unique(move(statEntity)); EXPECT_CALL(*sys, fgetxattr(_, _, _, _)).WillOnce(Return(1)); EXPECT_EQ(fsStat->GetLocation(), 1); diff --git a/interfaces/test/unittest/js/mod_fs/common/fs_err_code.h b/interfaces/test/unittest/js/mod_fs/common/fs_err_code.h new file mode 100644 index 000000000..7e8a4cbbd --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/common/fs_err_code.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_COMMON_FS_ERR_CODE_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_COMMON_FS_ERR_CODE_H + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +enum FsErrCode { + E_IO_CODE = 13900005, + E_INVAL_CODE = 13900020, +}; + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_COMMON_FS_ERR_CODE_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp new file mode 100644 index 000000000..1b140d042 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp @@ -0,0 +1,83 @@ +/* + * 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 "eventfd_mock.h" + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +thread_local std::shared_ptr EventfdMock::eventfdMock = nullptr; +thread_local bool EventfdMock::mockable = false; + +std::shared_ptr EventfdMock::GetMock() +{ + if (eventfdMock == nullptr) { + eventfdMock = std::make_shared(); + } + return eventfdMock; +} + +void EventfdMock::EnableMock() +{ + mockable = true; +} + +void EventfdMock::DisableMock() +{ + eventfdMock = nullptr; + mockable = false; +} + +bool EventfdMock::IsMockable() +{ + return mockable; +} + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +using namespace OHOS::FileManagement::ModuleFileIO::Test; + +int eventfd(unsigned int count, int flags) +{ + if (EventfdMock::IsMockable()) { + return EventfdMock::GetMock()->eventfd(count, flags); + } + + static int (*realEventfd)(unsigned int, int) = []() { + auto func = (int (*)(unsigned int, int))dlsym(RTLD_NEXT, "eventfd"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real eventfd: " << dlerror(); + } + return func; + }(); + + if (!realEventfd) { + return -1; + } + + return realEventfd(count, flags); +} + +} // extern "C" +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.h b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.h new file mode 100644 index 000000000..97dd8430f --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_EVENTFD_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_EVENTFD_MOCK_H + +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +class IEventfdMock { +public: + virtual ~IEventfdMock() = default; + virtual int eventfd(unsigned int, int) = 0; +}; + +class EventfdMock : public IEventfdMock { +public: + MOCK_METHOD(int, eventfd, (unsigned int, int), (override)); + +public: + static std::shared_ptr GetMock(); + static void EnableMock(); + static void DisableMock(); + static bool IsMockable(); + +private: + static thread_local std::shared_ptr eventfdMock; + static thread_local bool mockable; +}; + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_EVENTFD_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.cpp new file mode 100644 index 000000000..729d21a55 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.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 "inotify_mock.h" + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +thread_local std::shared_ptr InotifyMock::inotifyMock = nullptr; +thread_local bool InotifyMock::mockable = false; + +std::shared_ptr InotifyMock::GetMock() +{ + if (inotifyMock == nullptr) { + inotifyMock = std::make_shared(); + } + return inotifyMock; +} + +void InotifyMock::EnableMock() +{ + mockable = true; +} + +void InotifyMock::DisableMock() +{ + inotifyMock = nullptr; + mockable = false; +} + +bool InotifyMock::IsMockable() +{ + return mockable; +} + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +using namespace OHOS::FileManagement::ModuleFileIO::Test; + +int inotify_init() +{ + if (InotifyMock::IsMockable()) { + return InotifyMock::GetMock()->inotify_init(); + } + + static int (*realInotifyInit)() = []() { + auto func = (int (*)())dlsym(RTLD_NEXT, "inotify_init"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real inotify_init: " << dlerror(); + } + return func; + }(); + + if (!realInotifyInit) { + return -1; + } + + return realInotifyInit(); +} + +int inotify_add_watch(int fd, const char *pathname, uint32_t mask) +{ + if (InotifyMock::IsMockable()) { + return InotifyMock::GetMock()->inotify_add_watch(fd, pathname, mask); + } + + static int (*realInotifyAddWatch)(int, const char *, uint32_t) = []() { + auto func = (int (*)(int, const char *, uint32_t))dlsym(RTLD_NEXT, "inotify_add_watch"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real inotify_add_watch: " << dlerror(); + } + return func; + }(); + + if (!realInotifyAddWatch) { + return -1; + } + + return realInotifyAddWatch(fd, pathname, mask); +} + +int inotify_rm_watch(int fd, int wd) +{ + if (InotifyMock::IsMockable()) { + return InotifyMock::GetMock()->inotify_rm_watch(fd, wd); + } + + static int (*realInotifyRmWatch)(int, int) = []() { + auto func = (int (*)(int, int))dlsym(RTLD_NEXT, "inotify_rm_watch"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real inotify_rm_watch: " << dlerror(); + } + return func; + }(); + + if (!realInotifyRmWatch) { + return -1; + } + + return realInotifyRmWatch(fd, wd); +} + +} // extern "C" +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.h b/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.h new file mode 100644 index 000000000..233403309 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/inotify_mock.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H + +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +class IInotifyMock { +public: + virtual ~IInotifyMock() = default; + virtual int inotify_init() = 0; + virtual int inotify_add_watch(int, const char *, uint32_t) = 0; + virtual int inotify_rm_watch(int, int) = 0; +}; + +class InotifyMock : public IInotifyMock { +public: + MOCK_METHOD(int, inotify_init, (), (override)); + MOCK_METHOD(int, inotify_add_watch, (int, const char *, uint32_t), (override)); + MOCK_METHOD(int, inotify_rm_watch, (int, int), (override)); + +public: + static std::shared_ptr GetMock(); + static void EnableMock(); + static void DisableMock(); + static bool IsMockable(); + +private: + static thread_local std::shared_ptr inotifyMock; + static thread_local bool mockable; +}; + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_INOTIFY_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/mock_progress_listener.h b/interfaces/test/unittest/js/mod_fs/mock/mock_progress_listener.h new file mode 100644 index 000000000..e7851c98d --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/mock_progress_listener.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_MOCK_PROGRESS_LISTENER_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_MOCK_PROGRESS_LISTENER_H + +#include +#include "i_progress_listener.h" + +namespace OHOS::FileManagement::ModuleFileIO { +class MockProgressListener : public IProgressListener { +public: + MOCK_METHOD(void, InvokeListener, (uint64_t progressSize, uint64_t totalSize), (const, override)); +}; +} // namespace OHOS::FileManagement::ModuleFileIO + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_MOCK_PROGRESS_LISTENER_H diff --git a/interfaces/test/unittest/js/mod_fs/mock/poll_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/poll_mock.cpp new file mode 100644 index 000000000..6e2095ab2 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/poll_mock.cpp @@ -0,0 +1,83 @@ +/* + * 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 "poll_mock.h" + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +thread_local std::shared_ptr PollMock::pollMock = nullptr; +thread_local bool PollMock::mockable = false; + +std::shared_ptr PollMock::GetMock() +{ + if (pollMock == nullptr) { + pollMock = std::make_shared(); + } + return pollMock; +} + +void PollMock::EnableMock() +{ + mockable = true; +} + +void PollMock::DisableMock() +{ + pollMock = nullptr; + mockable = false; +} + +bool PollMock::IsMockable() +{ + return mockable; +} + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +using namespace OHOS::FileManagement::ModuleFileIO::Test; + +int poll(struct pollfd *fds, nfds_t n, int timeout) +{ + if (PollMock::IsMockable()) { + return PollMock::GetMock()->poll(fds, n, timeout); + } + + static int (*realPoll)(struct pollfd * fds, nfds_t n, int timeout) = []() { + auto func = (int (*)(struct pollfd *, nfds_t, int))dlsym(RTLD_NEXT, "poll"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real poll: " << dlerror(); + } + return func; + }(); + + if (!realPoll) { + return -1; + } + + return realPoll(fds, n, timeout); +} + +} // extern "C" +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/poll_mock.h b/interfaces/test/unittest/js/mod_fs/mock/poll_mock.h new file mode 100644 index 000000000..da771e4ec --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/poll_mock.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_POLL_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_POLL_MOCK_H + +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +class IPollMock { +public: + virtual ~IPollMock() = default; + virtual int poll(struct pollfd *, nfds_t, int) = 0; +}; + +class PollMock : public IPollMock { +public: + MOCK_METHOD(int, poll, (struct pollfd *, nfds_t, int), (override)); + +public: + static std::shared_ptr GetMock(); + static void EnableMock(); + static void DisableMock(); + static bool IsMockable(); + +private: + static thread_local std::shared_ptr pollMock; + static thread_local bool mockable; +}; + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_POLL_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp new file mode 100644 index 000000000..cda59d9bf --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.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 "unistd_mock.h" + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +thread_local std::shared_ptr UnistdMock::unistdMock = nullptr; +thread_local bool UnistdMock::mockable = false; + +std::shared_ptr UnistdMock::GetMock() +{ + if (unistdMock == nullptr) { + unistdMock = std::make_shared(); + } + return unistdMock; +} + +void UnistdMock::EnableMock() +{ + mockable = true; +} + +void UnistdMock::DisableMock() +{ + unistdMock = nullptr; + mockable = false; +} + +bool UnistdMock::IsMockable() +{ + return mockable; +} + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#ifdef __cplusplus +extern "C" { +using namespace OHOS::FileManagement::ModuleFileIO::Test; + +int access(const char *filename, int amode) +{ + if (UnistdMock::IsMockable()) { + return UnistdMock::GetMock()->access(filename, amode); + } + + static int (*realAccess)(const char *filename, int amode) = []() { + auto func = (int (*)(const char *, int))dlsym(RTLD_NEXT, "access"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real access: " << dlerror(); + } + return func; + }(); + + if (!realAccess) { + return -1; + } + + return realAccess(filename, amode); +} + +int close(int fd) +{ + if (UnistdMock::IsMockable()) { + return UnistdMock::GetMock()->close(fd); + } + + static int (*realClose)(int fd) = []() { + auto func = (int (*)(int))dlsym(RTLD_NEXT, "close"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real close: " << dlerror(); + } + return func; + }(); + + if (!realClose) { + return -1; + } + + return realClose(fd); +} + +ssize_t read(int fd, void *buf, size_t count) +{ + if (UnistdMock::IsMockable()) { + return UnistdMock::GetMock()->read(fd, buf, count); + } + + static ssize_t (*realRead)(int fd, void *buf, size_t count) = []() { + auto func = (ssize_t(*)(int, void *, size_t))dlsym(RTLD_NEXT, "read"); + if (!func) { + GTEST_LOG_(ERROR) << "Failed to resolve real read: " << dlerror(); + } + return func; + }(); + + if (!realRead) { + return 0; + } + + return realRead(fd, buf, count); +} + +} // extern "C" +#endif \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.h b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.h new file mode 100644 index 000000000..ec6f961e1 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_UNISTD_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_UNISTD_MOCK_H + +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace Test { + +class IUnistdMock { +public: + virtual ~IUnistdMock() = default; + virtual int access(const char *, int) = 0; + virtual int close(int) = 0; + virtual ssize_t read(int, void *, size_t) = 0; +}; + +class UnistdMock : public IUnistdMock { +public: + MOCK_METHOD(int, access, (const char *, int), (override)); + MOCK_METHOD(int, close, (int), (override)); + MOCK_METHOD(ssize_t, read, (int, void *, size_t), (override)); + +public: + static std::shared_ptr GetMock(); + static void EnableMock(); + static void DisableMock(); + static bool IsMockable(); + +private: + static thread_local std::shared_ptr unistdMock; + static thread_local bool mockable; +}; + +} // namespace Test +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_MOCK_UNISTD_MOCK_H diff --git a/interfaces/test/unittest/js/mod_fs/properties/access_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/access_core_mock_test.cpp index 4d9355d9c..a95e4eea4 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/access_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/access_core_mock_test.cpp @@ -67,7 +67,7 @@ void AccessCoreMockTest::TearDown(void) */ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_001, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreMockTest_DoAccess_001"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-begin AccessCoreMockTest_DoAccess_001"; std::string path = "TEST"; std::optional mode; @@ -76,7 +76,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_001, testing::ext::Test auto res = AccessCore::DoAccess(path, mode); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreMockTest_DoAccess_001"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-end AccessCoreMockTest_DoAccess_001"; } /** @@ -88,7 +88,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_001, testing::ext::Test */ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_002, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreMockTest_DoAccess_002"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-begin AccessCoreMockTest_DoAccess_002"; std::string path = "TEST"; std::optional mode; @@ -98,7 +98,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_002, testing::ext::Test auto res = AccessCore::DoAccess(path, mode); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreMockTest_DoAccess_002"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-end AccessCoreMockTest_DoAccess_002"; } /** @@ -110,7 +110,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_002, testing::ext::Test */ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_003, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreMockTest_DoAccess_003"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-begin AccessCoreMockTest_DoAccess_003"; std::string path = "TEST"; AccessModeType mode = AccessModeType::EXIST; @@ -120,7 +120,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_003, testing::ext::Test auto res = AccessCore::DoAccess(path, mode, flag); EXPECT_EQ(res.IsSuccess(), false); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreMockTest_DoAccess_003"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-end AccessCoreMockTest_DoAccess_003"; } /** @@ -132,7 +132,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_003, testing::ext::Test */ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_004, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "NClassTest-begin AccessCoreMockTest_DoAccess_004"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-begin AccessCoreMockTest_DoAccess_004"; std::string path = "TEST"; AccessModeType mode = AccessModeType::EXIST; @@ -143,30 +143,7 @@ HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_004, testing::ext::Test auto res = AccessCore::DoAccess(path, mode, flag); EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "NClassTest-end AccessCoreMockTest_DoAccess_004"; -} - -/** - * @tc.name: AccessCoreMockTest_DoAccess_005 - * @tc.desc: Test function of AccessCore::DoAccess interface for success. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - */ -HWTEST_F(AccessCoreMockTest, AccessCoreMockTest_DoAccess_005, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AccessCoreMockTest-begin AccessCoreMockTest_DoAccess_005"; - - std::string path = DISTRIBUTED_FILE_PREFIX; - AccessModeType mode = AccessModeType::EXIST; - AccessFlag flag = LOCAL_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) << "AccessCoreMockTest-end AccessCoreMockTest_DoAccess_005"; + GTEST_LOG_(INFO) << "AccessCoreMockTest-end AccessCoreMockTest_DoAccess_004"; } } // OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/access_core_test.cpp index b7966bd3c..6460d9a65 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 @@ -24,7 +24,6 @@ namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; using namespace testing::ext; using namespace std; - const mode_t DIR_PERMISSIONS = 0755; class AccessCoreTest : public testing::Test { @@ -61,8 +60,7 @@ void AccessCoreTest::TearDown(void) } // 递归创建多级目录的辅助函数 -bool CreateDirectoryRecursive(const std::string& path) -{ +bool CreateDirectoryRecursive(const std::string& path) { if (path.empty()) { return false; } @@ -74,8 +72,7 @@ bool CreateDirectoryRecursive(const std::string& path) pos++; } - while ((pos = path.find('/', pos)) != std::string::npos) - { + while ((pos = path.find('/', pos)) != std::string::npos) { dir = path.substr(0, pos++); if (dir.empty()) { continue; @@ -87,8 +84,7 @@ bool CreateDirectoryRecursive(const std::string& path) } } - if (mkdir(path.c_str(), DIR_PERMISSIONS) == -1 && errno != EEXIST) - { + if (mkdir(path.c_str(), DIR_PERMISSIONS) == -1 && errno != EEXIST) { return false; } return true; @@ -212,7 +208,7 @@ HWTEST_F(AccessCoreTest, AccessCoreTest_DoAccess_006, testing::ext::TestSize.Lev { GTEST_LOG_(INFO) << "AccessCoreTest-begin AccessCoreTest_DoAccess_006"; - std::string path = "test"; + std::string path = "AccessCoreTest"; AccessModeType mode = AccessModeType::EXIST; AccessFlag flag = LOCAL_FLAG; diff --git a/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_mock_test.cpp index c70674062..9c5bc7789 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/mkdir_core_mock_test.cpp @@ -15,11 +15,11 @@ #include #include -#include #include +#include #include "mkdir_core.h" -#include "mock/uv_fs_mock.h" +#include "uv_fs_mock.h" namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; @@ -107,7 +107,7 @@ HWTEST_F(MkdirCoreMockTest, MkdirCoreMockTest_DoMkdir_0002, testing::ext::TestSi /** * @tc.name: MkdirCoreMockTest_DoMkdir_0003 - * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.desc: Test function of DoMkdir() interface is FAILED for uv_fs_mkdir return 1. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -127,7 +127,7 @@ HWTEST_F(MkdirCoreMockTest, MkdirCoreMockTest_DoMkdir_0003, testing::ext::TestSi /** * @tc.name: MkdirCoreMockTest_DoMkdir_0004 - * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.desc: Test function of DoMkdir() interface is FAILED for file exists. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -152,7 +152,7 @@ HWTEST_F(MkdirCoreMockTest, MkdirCoreMockTest_DoMkdir_0004, testing::ext::TestSi /** * @tc.name: MkdirCoreMockTest_DoMkdir_0005 - * @tc.desc: Test function of DoMkdir() interface for FAILED. + * @tc.desc: Test function of DoMkdir() interface is FAILED for no such file or directory. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp index 5878a9304..189edf925 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.cpp @@ -23,7 +23,7 @@ int setxattr(const char *path, const char *name, const void *value, size_t size, return System::ins->setxattr(path, name, value, size, flags); } -int getxattr(const char *path, const char *name, void *value, size_t size) +ssize_t getxattr(const char *path, const char *name, void *value, size_t size) { return System::ins->getxattr(path, name, value, size); } diff --git a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h index 3ff74be78..dad578b09 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/system_mock.h @@ -29,7 +29,7 @@ public: public: virtual ~System() = default; virtual int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) = 0; - virtual int getxattr(const char *path, const char *name, void *value, size_t size) = 0; + virtual ssize_t getxattr(const char *path, const char *name, void *value, size_t size) = 0; virtual int fgetxattr(int filedes, const char *name, void *value, size_t size) = 0; virtual int flock(int fd, int operation) = 0; }; @@ -37,7 +37,7 @@ public: class SystemMock : public System { public: MOCK_METHOD5(setxattr, int(const char *path, const char *name, const void *value, size_t size, int flags)); - MOCK_METHOD4(getxattr, int(const char *path, const char *name, void *value, size_t size)); + MOCK_METHOD4(getxattr, ssize_t(const char *path, const char *name, void *value, size_t size)); MOCK_METHOD4(fgetxattr, int(int filedes, const char *name, void *value, size_t size)); MOCK_METHOD2(flock, int(int fd, int operation)); }; 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 b656a1ad1..2a13ecf69 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.cpp @@ -13,10 +13,8 @@ * limitations under the License. */ - #include "uv_fs_mock.h" - using namespace OHOS::FileManagement::ModuleFileIO; int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t off, @@ -55,9 +53,9 @@ int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) return Uvfs::ins->uv_fs_rmdir(loop, req, path, cb); } -int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, uv_fs_cb cb) +int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb) { - return Uvfs::ins->uv_fs_symlink(loop, req, path, new_path, flags, cb); + return Uvfs::ins->uv_fs_symlink(loop, req, path, newPath, flags, cb); } int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb) @@ -134,4 +132,4 @@ int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file outFd, uv_file inFd, i int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) { return Uvfs::ins->uv_fs_lstat(loop, req, path, cb); -} \ No newline at end of file +} 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 1fa703a0f..0bcfa87a5 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h +++ b/interfaces/test/unittest/js/mod_fs/properties/mock/uv_fs_mock.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UV_FS_READ_MOCK_H -#define UV_FS_READ_MOCK_H +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H #include "uv.h" @@ -25,6 +25,7 @@ namespace OHOS::FileManagement::ModuleFileIO { class Uvfs { public: static inline std::shared_ptr ins = nullptr; + public: virtual ~Uvfs() = default; virtual int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, @@ -36,7 +37,7 @@ public: virtual int uv_fs_scandir(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb) = 0; virtual int uv_fs_scandir_next(uv_fs_t *req, uv_dirent_t *ent) = 0; virtual int uv_fs_rmdir(uv_loop_t *loop, uv_fs_t *req, const char* path, uv_fs_cb cb) = 0; - virtual int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, + virtual int uv_fs_symlink(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb) = 0; virtual int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb) = 0; virtual int uv_fs_ftruncate(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb) = 0; @@ -50,9 +51,9 @@ public: virtual int uv_fs_mkdtemp(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb) = 0; virtual int uv_fs_unlink(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; 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 int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) = 0; - virtual int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file outFd, uv_file inFd, - int64_t off, size_t len, uv_fs_cb cb) = 0; + virtual int uv_fs_fsync(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb) = 0; + virtual int uv_fs_sendfile(uv_loop_t *loop, uv_fs_t *req, uv_file outFd, uv_file inFd, int64_t off, size_t len, + uv_fs_cb cb) = 0; virtual int uv_fs_lstat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb) = 0; }; @@ -67,7 +68,7 @@ public: MOCK_METHOD5(uv_fs_scandir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, uv_fs_cb cb)); MOCK_METHOD2(uv_fs_scandir_next, int(uv_fs_t *req, uv_dirent_t *ent)); MOCK_METHOD4(uv_fs_rmdir, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); - MOCK_METHOD6(uv_fs_symlink, int(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *new_path, int flags, + MOCK_METHOD6(uv_fs_symlink, int(uv_loop_t *loop, uv_fs_t *req, const char *path, const char *newPath, int flags, uv_fs_cb cb)); MOCK_METHOD6(uv_fs_open, int(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)); MOCK_METHOD5(uv_fs_ftruncate, int(uv_loop_t *loop, uv_fs_t *req, uv_file fd, int64_t offset, uv_fs_cb cb)); @@ -81,11 +82,11 @@ public: MOCK_METHOD4(uv_fs_mkdtemp, int(uv_loop_t *loop, uv_fs_t *req, const char *tpl, uv_fs_cb cb)); MOCK_METHOD4(uv_fs_unlink, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); 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_METHOD4(uv_fs_fsync, int(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb)); - MOCK_METHOD7(uv_fs_sendfile, int(uv_loop_t* loop, uv_fs_t* req, uv_file outFd, uv_file inFd, - int64_t off, size_t len, uv_fs_cb cb)); + MOCK_METHOD4(uv_fs_fsync, int(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)); + MOCK_METHOD7(uv_fs_sendfile, int(uv_loop_t *loop, uv_fs_t *req, uv_file outFd, uv_file inFd, int64_t off, + size_t len, uv_fs_cb cb)); MOCK_METHOD4(uv_fs_lstat, int(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)); }; -} // OHOS::FileManagement::ModuleFileIO -#endif \ No newline at end of file +} // namespace OHOS::FileManagement::ModuleFileIO +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_PROPERTIES_MOCK_UV_FS_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/open_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/open_core_mock_test.cpp index 27cd72731..abee054b1 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/open_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/open_core_mock_test.cpp @@ -13,14 +13,15 @@ * limitations under the License. */ -#include "open_core.h" -#include "mock/uv_fs_mock.h" - #include #include #include #include +#include "mock/uv_fs_mock.h" +#include "open_core.h" +#include "unistd_mock.h" + namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; using namespace testing::ext; @@ -32,6 +33,8 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + +private: static inline shared_ptr uvMock = nullptr; }; @@ -40,6 +43,7 @@ void OpenCoreMockTest::SetUpTestCase(void) GTEST_LOG_(INFO) << "SetUpTestCase"; uvMock = std::make_shared(); Uvfs::ins = uvMock; + UnistdMock::EnableMock(); } void OpenCoreMockTest::TearDownTestCase(void) @@ -47,6 +51,7 @@ void OpenCoreMockTest::TearDownTestCase(void) GTEST_LOG_(INFO) << "TearDownTestCase"; Uvfs::ins = nullptr; uvMock = nullptr; + UnistdMock::DisableMock(); } void OpenCoreMockTest::SetUp(void) @@ -60,19 +65,19 @@ void OpenCoreMockTest::TearDown(void) } /** -* @tc.name: OpenCoreMockTest_DoOpen_001 -* @tc.desc: Test function of OpenCore::DoOpen interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreMockTest_DoOpen_001 + * @tc.desc: Test function of OpenCore::DoOpen interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreMockTest, OpenCoreMockTest_DoOpen_001, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreMockTest-begin OpenCoreMockTest_DoOpen_001"; - string path = "/test/open_test.txt"; + string path = "/test/OpenCoreMockTest_DoOpen_001"; int32_t mode = 0; - + EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(0)); auto res = OpenCore::DoOpen(path, mode); EXPECT_EQ(res.IsSuccess(), true); @@ -81,59 +86,67 @@ HWTEST_F(OpenCoreMockTest, OpenCoreMockTest_DoOpen_001, testing::ext::TestSize.L } /** -* @tc.name: OpenCoreMockTest_DoOpen_002 -* @tc.desc: Test function of OpenCore::DoOpen interface for SUCCESS. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreMockTest_DoOpen_002 + * @tc.desc: Test function of OpenCore::DoOpen interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreMockTest, OpenCoreMockTest_DoOpen_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreMockTest-begin OpenCoreMockTest_DoOpen_002"; - string path = "file://test/open_test.txt"; + string path = "file://test/OpenCoreMockTest_DoOpen_002"; int32_t mode = 0; + auto unistdMock = UnistdMock::GetMock(); EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(0)); + EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1)); + EXPECT_CALL(*unistdMock, access(testing::_, testing::_)).WillRepeatedly(testing::Return(0)); auto res = OpenCore::DoOpen(path, mode); + testing::Mock::VerifyAndClearExpectations(unistdMock.get()); EXPECT_EQ(res.IsSuccess(), true); GTEST_LOG_(INFO) << "OpenCoreMockTest-end OpenCoreMockTest_DoOpen_002"; } /** -* @tc.name: OpenCoreMockTest_DoOpen_003 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreMockTest_DoOpen_003 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreMockTest, OpenCoreMockTest_DoOpen_003, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreMockTest-begin OpenCoreMockTest_DoOpen_003"; - string path = "file://test/open_test.txt"; + string path = "file://test/OpenCoreMockTest_DoOpen_003"; int32_t mode = 0; + auto unistdMock = UnistdMock::GetMock(); EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(-1)); + EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1)); + EXPECT_CALL(*unistdMock, access(testing::_, testing::_)).WillRepeatedly(testing::Return(0)); auto res = OpenCore::DoOpen(path, mode); + testing::Mock::VerifyAndClearExpectations(&unistdMock); EXPECT_EQ(res.IsSuccess(), false); GTEST_LOG_(INFO) << "OpenCoreMockTest-end OpenCoreMockTest_DoOpen_003"; } /** -* @tc.name: OpenCoreMockTest_DoOpen_004 -* @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreMockTest_DoOpen_004 + * @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreMockTest, OpenCoreMockTest_DoOpen_004, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreMockTest-begin OpenCoreMockTest_DoOpen_004"; - string path = "/test/open_test.txt"; + string path = "/test/OpenCoreMockTest_DoOpen_004"; int32_t mode = 0; EXPECT_CALL(*uvMock, uv_fs_open(_, _, _, _, _, _)).WillOnce(Return(-1)); diff --git a/interfaces/test/unittest/js/mod_fs/properties/open_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/open_core_test.cpp index fcfc9019b..a6cad138a 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/open_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/open_core_test.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include - #include "open_core.h" +#include + namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; using namespace testing::ext; @@ -51,12 +51,12 @@ void OpenCoreTest::TearDown(void) } /** -* @tc.name: OpenCoreTest_DoOpen_001 -* @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_001 + * @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_001, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_001"; @@ -71,12 +71,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_001, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_002 -* @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_002 + * @tc.desc: Test function of OpenCore::DoOpen interface for ERROR. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_002, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_002"; @@ -91,12 +91,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_002, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_003 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_003 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_003, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_003"; @@ -111,12 +111,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_003, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_004 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_004 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_004, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_004"; @@ -131,12 +131,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_004, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_005 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_005 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_005, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_005"; @@ -151,12 +151,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_005, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_006 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_006 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_006, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_006"; @@ -171,12 +171,12 @@ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_006, testing::ext::TestSize.Level1) } /** -* @tc.name: OpenCoreTest_DoOpen_007 -* @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. -* @tc.size: MEDIUM -* @tc.type: FUNC -* @tc.level Level 1 -*/ + * @tc.name: OpenCoreTest_DoOpen_007 + * @tc.desc: Test function of OpenCore::DoOpen interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ HWTEST_F(OpenCoreTest, OpenCoreTest_DoOpen_007, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "OpenCoreTest-begin OpenCoreTest_DoOpen_007"; diff --git a/interfaces/test/unittest/js/mod_fs/properties/stat_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/stat_core_mock_test.cpp index 2fd8bd7f5..2a3133bdb 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/stat_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/stat_core_mock_test.cpp @@ -13,10 +13,10 @@ * limitations under the License. */ -#include "securec.h" #include "stat_core.h" #include "uv_fs_mock.h" +#include #include namespace OHOS::FileManagement::ModuleFileIO::Test { @@ -59,7 +59,7 @@ void StatCoreMockTest::TearDown(void) /** * @tc.name: StatCoreMockTest_DoStat_001 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.desc: Test function of StatCore::DoStat interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -82,7 +82,7 @@ HWTEST_F(StatCoreMockTest, StatCoreMockTest_DoStat_001, testing::ext::TestSize.L /** * @tc.name: StatCoreMockTest_DoStat_002 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.desc: Test function of StatCore::DoStat interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -105,7 +105,7 @@ HWTEST_F(StatCoreMockTest, StatCoreMockTest_DoStat_002, testing::ext::TestSize.L /** * @tc.name: StatCoreMockTest_DoStat_003 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.desc: Test function of StatCore::DoStat interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -127,30 +127,27 @@ HWTEST_F(StatCoreMockTest, StatCoreMockTest_DoStat_003, testing::ext::TestSize.L } /** - * @tc.name: StatCoreMockTest_DoStat_005 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.name: StatCoreMockTest_DoStat_004 + * @tc.desc: Test function of StatCore::DoStat interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(StatCoreMockTest, StatCoreMockTest_DoStat_005, testing::ext::TestSize.Level1) +HWTEST_F(StatCoreMockTest, StatCoreMockTest_DoStat_004, testing::ext::TestSize.Level1) { - GTEST_LOG_(INFO) << "StatCoreMockTest-begin StatCoreMockTest_DoStat_005"; + GTEST_LOG_(INFO) << "StatCoreMockTest-begin StatCoreMockTest_DoStat_004"; FileInfo fileinfo; - string buffer = "Hello, World!"; - int pathLength = buffer.size() + 1; - fileinfo.path = std::make_unique(pathLength); - memcpy_s(fileinfo.path.get(), pathLength, buffer.c_str(), buffer.size()); - fileinfo.fdg = std::make_unique(-1); - fileinfo.isPath = true; + 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(), false); + EXPECT_EQ(res.IsSuccess(), true); - GTEST_LOG_(INFO) << "StatCoreMockTest-end StatCoreMockTest_DoStat_005"; + GTEST_LOG_(INFO) << "StatCoreMockTest-end StatCoreMockTest_DoStat_004"; } } // 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 index 5ad93fbf9..f11d92625 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/stat_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/stat_core_test.cpp @@ -52,7 +52,7 @@ void StatCoreTest::TearDown(void) /** * @tc.name: StatCoreTest_DoStat_001 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.desc: Test function of StatCore::DoStat interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -71,7 +71,7 @@ HWTEST_F(StatCoreTest, StatCoreTest_DoStat_001, testing::ext::TestSize.Level1) /** * @tc.name: StatCoreTest_DoStat_002 - * @tc.desc: Test function of FsyncCore::DoStat interface for FALSE. + * @tc.desc: Test function of StatCore::DoStat interface for FALSE. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 -- Gitee From 175b8a29756fac2a28335d90442c882a09310204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E9=87=91=E6=B2=9B?= Date: Mon, 28 Jul 2025 14:58:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?file/stat=20TDD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶金沛 Change-Id: I644211efe846662a962dd49fcbbcab3d59eb83b2 --- interfaces/test/unittest/js/BUILD.gn | 2 ++ .../test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp | 2 +- interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp | 1 + interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp | 3 ++- .../test/unittest/js/mod_fs/properties/access_core_test.cpp | 2 -- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index dbef98d62..c6fc874c1 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -24,12 +24,14 @@ ohos_unittest("ani_file_fs_mock_test") { "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stat", "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", + "${file_api_path}/interfaces/test/unittest/js/mod_fs/mock", "${file_api_path}/interfaces/test/unittest/js/mod_fs/properties/mock", ] sources = [ "mod_fs/class_file/fs_file_mock_test.cpp", "mod_fs/class_stat/fs_stat_mock_test.cpp", + "mod_fs/mock/unistd_mock.cpp", "mod_fs/properties/access_core_mock_test.cpp", "mod_fs/properties/copy_file_core_mock_test.cpp", "mod_fs/properties/mkdir_core_mock_test.cpp", diff --git a/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp index 2de8331e0..45e6ff86f 100644 --- a/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/class_stat/fs_stat_mock_test.cpp @@ -104,7 +104,7 @@ HWTEST_F(FsStatMockTest, FsStatMockTest_GetLocation_002, testing::ext::TestSize. statEntity = make_unique(); statEntity->fileInfo_ = make_unique(); statEntity->fileInfo_->isPath = false; - const int fdValue = 3; //模拟fd为3 + const int fdValue = 3; const bool isClosed = false; statEntity->fileInfo_->fdg = make_unique(fdValue, isClosed); fsStat = make_unique(move(statEntity)); diff --git a/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp index 1b140d042..693852ff6 100644 --- a/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp +++ b/interfaces/test/unittest/js/mod_fs/mock/eventfd_mock.cpp @@ -30,6 +30,7 @@ std::shared_ptr EventfdMock::GetMock() if (eventfdMock == nullptr) { eventfdMock = std::make_shared(); } + return eventfdMock; } diff --git a/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp index cda59d9bf..35d0459f2 100644 --- a/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp +++ b/interfaces/test/unittest/js/mod_fs/mock/unistd_mock.cpp @@ -30,6 +30,7 @@ std::shared_ptr UnistdMock::GetMock() if (unistdMock == nullptr) { unistdMock = std::make_shared(); } + return unistdMock; } @@ -122,4 +123,4 @@ ssize_t read(int fd, void *buf, size_t count) } } // extern "C" -#endif \ No newline at end of file +#endif 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 6460d9a65..9de2a18b6 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 @@ -19,7 +19,6 @@ #include #include - namespace OHOS::FileManagement::ModuleFileIO::Test { using namespace testing; using namespace testing::ext; @@ -59,7 +58,6 @@ void AccessCoreTest::TearDown(void) GTEST_LOG_(INFO) << "TearDown"; } -// 递归创建多级目录的辅助函数 bool CreateDirectoryRecursive(const std::string& path) { if (path.empty()) { return false; -- Gitee