diff --git a/base/test/unittest/common/utils_directory_test.cpp b/base/test/unittest/common/utils_directory_test.cpp index 0314fcb4e8e88d816467099b105ba2d0c1f34c59..038840e4ea5a3026b0ee76ccd7fddae3dfe43e25 100644 --- a/base/test/unittest/common/utils_directory_test.cpp +++ b/base/test/unittest/common/utils_directory_test.cpp @@ -203,9 +203,48 @@ HWTEST_F(UtilsDirectoryTest, testGetDirFiles001, TestSize.Level0) /* * @tc.name: testGetDirFiles002 - * @tc.desc: test GetDirFiles works on symlink +* @tc.desc: test GetDirFiles works on deeply nested directory and handles very long path */ HWTEST_F(UtilsDirectoryTest, testGetDirFiles002, TestSize.Level0) +{ + string parentPath = "/data/test_dir/"; + string veryLongPath = "/data/test_dir/"; + + int length = 10000; + + for (int i = 0; i < length; i++) { + veryLongPath += "0"; + veryLongPath += "/"; + } + + EXPECT_EQ(mkdir("/data/test_dir", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH), 0); + chdir(parentPath.c_str()); + + for (int i = 0; i < length; i++) { + EXPECT_EQ(mkdir("./0", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH), 0); + EXPECT_EQ(chdir("./0"), 0); + } + + ofstream file("./test_file"); + file.close(); + EXPECT_EQ(chdir("/data/test"), 0); + + auto files = vector(); + + GetDirFiles(parentPath, files); + + EXPECT_EQ(files.size(), 1); + EXPECT_EQ((veryLongPath + "test_file").length(), files[0].length()); + EXPECT_EQ(veryLongPath + "test_file", files[0]); + + ForceRemoveDirectory(parentPath); +} + +/* + * @tc.name: testGetDirFiles003 + * @tc.desc: test GetDirFiles works on symlink + */ +HWTEST_F(UtilsDirectoryTest, testGetDirFiles003, TestSize.Level0) { // create a test dir string originalDataPath = "/data/original"; diff --git a/base/test/unittest/rust/BUILD.gn b/base/test/unittest/rust/BUILD.gn index 48c3f66c02154615a850f43d8e084b67637e56c3..4ec296c33d2bfc50fcaf3d5355e9916a681faf63 100644 --- a/base/test/unittest/rust/BUILD.gn +++ b/base/test/unittest/rust/BUILD.gn @@ -28,6 +28,7 @@ if (host_os == "linux" && !is_asan && !is_arkui_x) { if (!use_clang_coverage) { deps += [ ":rust_utils_ashmem_test", + ":rust_utils_directory_test", ":rust_utils_file_test", ] }