| 20 | #include <testSystemTools.h> |
| 21 | |
| 22 | static int doLongPathTest() |
| 23 | { |
| 24 | using namespace kwsys; |
| 25 | static int const LONG_PATH_THRESHOLD = 512; |
| 26 | int res = 0; |
| 27 | std::string topdir(TEST_SYSTEMTOOLS_BINARY_DIR "/directory_testing/"); |
| 28 | std::stringstream testpathstrm; |
| 29 | std::string testdirpath; |
| 30 | std::string extendedtestdirpath; |
| 31 | |
| 32 | testpathstrm << topdir; |
| 33 | size_t pathlen = testpathstrm.str().length(); |
| 34 | testpathstrm.seekp(0, std::ios_base::end); |
| 35 | while (pathlen < LONG_PATH_THRESHOLD) { |
| 36 | testpathstrm << "0123456789/"; |
| 37 | pathlen = testpathstrm.str().length(); |
| 38 | } |
| 39 | |
| 40 | testdirpath = testpathstrm.str(); |
| 41 | #ifdef _WIN32 |
| 42 | extendedtestdirpath = |
| 43 | Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(testdirpath)); |
| 44 | #else |
| 45 | extendedtestdirpath = testdirpath; |
| 46 | #endif |
| 47 | |
| 48 | if (SystemTools::MakeDirectory(extendedtestdirpath)) { |
| 49 | std::ofstream testfile1( |
| 50 | (extendedtestdirpath + "longfilepathtest1.txt").c_str()); |
| 51 | std::ofstream testfile2( |
| 52 | (extendedtestdirpath + "longfilepathtest2.txt").c_str()); |
| 53 | testfile1 << "foo"; |
| 54 | testfile2 << "bar"; |
| 55 | testfile1.close(); |
| 56 | testfile2.close(); |
| 57 | |
| 58 | Directory testdir; |
| 59 | // Set res to failure if the directory doesn't load |
| 60 | std::string errorMessage = ""; |
| 61 | res += !testdir.Load(testdirpath, &errorMessage); |
| 62 | if (errorMessage != "") { |
| 63 | std::cerr << "Failed to list directory: " << errorMessage << std::endl; |
| 64 | } |
| 65 | // Increment res failure if the directory appears empty |
| 66 | res += testdir.GetNumberOfFiles() == 0; |
| 67 | // Increment res failures if the path has changed from |
| 68 | // what was provided. |
| 69 | res += testdirpath != testdir.GetPath(); |
| 70 | |
| 71 | SystemTools::RemoveADirectory(topdir); |
| 72 | } else { |
| 73 | std::cerr << "Failed to create directory with long path: " |
| 74 | << extendedtestdirpath << std::endl; |
| 75 | res += 1; |
| 76 | } |
| 77 | return res; |
| 78 | } |
| 79 | |