testSystemTools.cxx 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
  3. #include "kwsysPrivate.h"
  4. #if defined(_MSC_VER)
  5. # pragma warning(disable : 4786)
  6. #endif
  7. #include KWSYS_HEADER(FStream.hxx)
  8. #include KWSYS_HEADER(SystemTools.hxx)
  9. // Work-around CMake dependency scanning limitation. This must
  10. // duplicate the above list of headers.
  11. #if 0
  12. # include "FStream.hxx.in"
  13. # include "SystemTools.hxx.in"
  14. #endif
  15. // Include with <> instead of "" to avoid getting any in-source copy
  16. // left on disk.
  17. #include <testSystemTools.h>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <stdlib.h> /* free */
  21. #include <string.h> /* strcmp */
  22. #if defined(_WIN32) && !defined(__CYGWIN__)
  23. # include <io.h> /* _umask (MSVC) / umask (Borland) */
  24. # ifdef _MSC_VER
  25. # define umask _umask // Note this is still umask on Borland
  26. # endif
  27. #endif
  28. #include <sys/stat.h> /* umask (POSIX), _S_I* constants (Windows) */
  29. // Visual C++ does not define mode_t (note that Borland does, however).
  30. #if defined(_MSC_VER)
  31. typedef unsigned short mode_t;
  32. #endif
  33. static const char* toUnixPaths[][2] = {
  34. { "/usr/local/bin/passwd", "/usr/local/bin/passwd" },
  35. { "/usr/lo cal/bin/pa sswd", "/usr/lo cal/bin/pa sswd" },
  36. { "/usr/lo\\ cal/bin/pa\\ sswd", "/usr/lo/ cal/bin/pa/ sswd" },
  37. { "c:/usr/local/bin/passwd", "c:/usr/local/bin/passwd" },
  38. { "c:/usr/lo cal/bin/pa sswd", "c:/usr/lo cal/bin/pa sswd" },
  39. { "c:/usr/lo\\ cal/bin/pa\\ sswd", "c:/usr/lo/ cal/bin/pa/ sswd" },
  40. { "\\usr\\local\\bin\\passwd", "/usr/local/bin/passwd" },
  41. { "\\usr\\lo cal\\bin\\pa sswd", "/usr/lo cal/bin/pa sswd" },
  42. { "\\usr\\lo\\ cal\\bin\\pa\\ sswd", "/usr/lo/ cal/bin/pa/ sswd" },
  43. { "c:\\usr\\local\\bin\\passwd", "c:/usr/local/bin/passwd" },
  44. { "c:\\usr\\lo cal\\bin\\pa sswd", "c:/usr/lo cal/bin/pa sswd" },
  45. { "c:\\usr\\lo\\ cal\\bin\\pa\\ sswd", "c:/usr/lo/ cal/bin/pa/ sswd" },
  46. { "\\\\usr\\local\\bin\\passwd", "//usr/local/bin/passwd" },
  47. { "\\\\usr\\lo cal\\bin\\pa sswd", "//usr/lo cal/bin/pa sswd" },
  48. { "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo/ cal/bin/pa/ sswd" },
  49. { nullptr, nullptr }
  50. };
  51. static bool CheckConvertToUnixSlashes(std::string const& input,
  52. std::string const& output)
  53. {
  54. std::string result = input;
  55. kwsys::SystemTools::ConvertToUnixSlashes(result);
  56. if (result != output) {
  57. std::cerr << "Problem with ConvertToUnixSlashes - input: " << input
  58. << " output: " << result << " expected: " << output << std::endl;
  59. return false;
  60. }
  61. return true;
  62. }
  63. static const char* checkEscapeChars[][4] = {
  64. { "1 foo 2 bar 2", "12", "\\", "\\1 foo \\2 bar \\2" },
  65. { " {} ", "{}", "#", " #{#} " },
  66. { nullptr, nullptr, nullptr, nullptr }
  67. };
  68. static bool CheckEscapeChars(std::string const& input,
  69. const char* chars_to_escape, char escape_char,
  70. std::string const& output)
  71. {
  72. std::string result = kwsys::SystemTools::EscapeChars(
  73. input.c_str(), chars_to_escape, escape_char);
  74. if (result != output) {
  75. std::cerr << "Problem with CheckEscapeChars - input: " << input
  76. << " output: " << result << " expected: " << output << std::endl;
  77. return false;
  78. }
  79. return true;
  80. }
  81. static bool CheckFileOperations()
  82. {
  83. bool res = true;
  84. const std::string testNonExistingFile(TEST_SYSTEMTOOLS_SOURCE_DIR
  85. "/testSystemToolsNonExistingFile");
  86. const std::string testDotFile(TEST_SYSTEMTOOLS_SOURCE_DIR "/.");
  87. const std::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
  88. "/testSystemTools.bin");
  89. const std::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
  90. "/testSystemTools.cxx");
  91. const std::string testNewDir(TEST_SYSTEMTOOLS_BINARY_DIR
  92. "/testSystemToolsNewDir");
  93. const std::string testNewFile(testNewDir + "/testNewFile.txt");
  94. if (kwsys::SystemTools::DetectFileType(testNonExistingFile.c_str()) !=
  95. kwsys::SystemTools::FileTypeUnknown) {
  96. std::cerr << "Problem with DetectFileType - failed to detect type of: "
  97. << testNonExistingFile << std::endl;
  98. res = false;
  99. }
  100. if (kwsys::SystemTools::DetectFileType(testDotFile.c_str()) !=
  101. kwsys::SystemTools::FileTypeUnknown) {
  102. std::cerr << "Problem with DetectFileType - failed to detect type of: "
  103. << testDotFile << std::endl;
  104. res = false;
  105. }
  106. if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
  107. kwsys::SystemTools::FileTypeBinary) {
  108. std::cerr << "Problem with DetectFileType - failed to detect type of: "
  109. << testBinFile << std::endl;
  110. res = false;
  111. }
  112. if (kwsys::SystemTools::DetectFileType(testTxtFile.c_str()) !=
  113. kwsys::SystemTools::FileTypeText) {
  114. std::cerr << "Problem with DetectFileType - failed to detect type of: "
  115. << testTxtFile << std::endl;
  116. res = false;
  117. }
  118. if (kwsys::SystemTools::FileLength(testBinFile) != 766) {
  119. std::cerr << "Problem with FileLength - incorrect length for: "
  120. << testBinFile << std::endl;
  121. res = false;
  122. }
  123. kwsys::SystemTools::Stat_t buf;
  124. if (kwsys::SystemTools::Stat(testTxtFile.c_str(), &buf) != 0) {
  125. std::cerr << "Problem with Stat - unable to stat text file: "
  126. << testTxtFile << std::endl;
  127. res = false;
  128. }
  129. if (kwsys::SystemTools::Stat(testBinFile, &buf) != 0) {
  130. std::cerr << "Problem with Stat - unable to stat bin file: " << testBinFile
  131. << std::endl;
  132. res = false;
  133. }
  134. if (!kwsys::SystemTools::MakeDirectory(testNewDir)) {
  135. std::cerr << "Problem with MakeDirectory for: " << testNewDir << std::endl;
  136. res = false;
  137. }
  138. // calling it again should just return true
  139. if (!kwsys::SystemTools::MakeDirectory(testNewDir)) {
  140. std::cerr << "Problem with second call to MakeDirectory for: "
  141. << testNewDir << std::endl;
  142. res = false;
  143. }
  144. // calling with 0 pointer should return false
  145. if (kwsys::SystemTools::MakeDirectory(nullptr)) {
  146. std::cerr << "Problem with MakeDirectory(0)" << std::endl;
  147. res = false;
  148. }
  149. // calling with an empty string should return false
  150. if (kwsys::SystemTools::MakeDirectory(std::string())) {
  151. std::cerr << "Problem with MakeDirectory(std::string())" << std::endl;
  152. res = false;
  153. }
  154. // check existence
  155. if (!kwsys::SystemTools::FileExists(testNewDir.c_str(), false)) {
  156. std::cerr << "Problem with FileExists as C string and not file for: "
  157. << testNewDir << std::endl;
  158. res = false;
  159. }
  160. // check existence
  161. if (!kwsys::SystemTools::PathExists(testNewDir)) {
  162. std::cerr << "Problem with PathExists for: " << testNewDir << std::endl;
  163. res = false;
  164. }
  165. // remove it
  166. if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
  167. std::cerr << "Problem with RemoveADirectory for: " << testNewDir
  168. << std::endl;
  169. res = false;
  170. }
  171. // check existence
  172. if (kwsys::SystemTools::FileExists(testNewDir.c_str(), false)) {
  173. std::cerr << "After RemoveADirectory: "
  174. << "Problem with FileExists as C string and not file for: "
  175. << testNewDir << std::endl;
  176. res = false;
  177. }
  178. // check existence
  179. if (kwsys::SystemTools::PathExists(testNewDir)) {
  180. std::cerr << "After RemoveADirectory: "
  181. << "Problem with PathExists for: " << testNewDir << std::endl;
  182. res = false;
  183. }
  184. // create it using the char* version
  185. if (!kwsys::SystemTools::MakeDirectory(testNewDir.c_str())) {
  186. std::cerr << "Problem with second call to MakeDirectory as C string for: "
  187. << testNewDir << std::endl;
  188. res = false;
  189. }
  190. if (!kwsys::SystemTools::Touch(testNewFile, true)) {
  191. std::cerr << "Problem with Touch for: " << testNewFile << std::endl;
  192. res = false;
  193. }
  194. // calling MakeDirectory with something that is no file should fail
  195. if (kwsys::SystemTools::MakeDirectory(testNewFile)) {
  196. std::cerr << "Problem with to MakeDirectory for: " << testNewFile
  197. << std::endl;
  198. res = false;
  199. }
  200. // calling with 0 pointer should return false
  201. if (kwsys::SystemTools::FileExists(nullptr)) {
  202. std::cerr << "Problem with FileExists(0)" << std::endl;
  203. res = false;
  204. }
  205. if (kwsys::SystemTools::FileExists(nullptr, true)) {
  206. std::cerr << "Problem with FileExists(0) as file" << std::endl;
  207. res = false;
  208. }
  209. // calling with an empty string should return false
  210. if (kwsys::SystemTools::FileExists(std::string())) {
  211. std::cerr << "Problem with FileExists(std::string())" << std::endl;
  212. res = false;
  213. }
  214. // FileExists(x, true) should return false on a directory
  215. if (kwsys::SystemTools::FileExists(testNewDir, true)) {
  216. std::cerr << "Problem with FileExists as file for: " << testNewDir
  217. << std::endl;
  218. res = false;
  219. }
  220. if (kwsys::SystemTools::FileExists(testNewDir.c_str(), true)) {
  221. std::cerr << "Problem with FileExists as C string and file for: "
  222. << testNewDir << std::endl;
  223. res = false;
  224. }
  225. // FileExists(x, false) should return true even on a directory
  226. if (!kwsys::SystemTools::FileExists(testNewDir, false)) {
  227. std::cerr << "Problem with FileExists as not file for: " << testNewDir
  228. << std::endl;
  229. res = false;
  230. }
  231. if (!kwsys::SystemTools::FileExists(testNewDir.c_str(), false)) {
  232. std::cerr << "Problem with FileExists as C string and not file for: "
  233. << testNewDir << std::endl;
  234. res = false;
  235. }
  236. // should work, was created as new file before
  237. if (!kwsys::SystemTools::FileExists(testNewFile)) {
  238. std::cerr << "Problem with FileExists for: " << testNewFile << std::endl;
  239. res = false;
  240. }
  241. if (!kwsys::SystemTools::FileExists(testNewFile.c_str())) {
  242. std::cerr << "Problem with FileExists as C string for: " << testNewFile
  243. << std::endl;
  244. res = false;
  245. }
  246. if (!kwsys::SystemTools::FileExists(testNewFile, true)) {
  247. std::cerr << "Problem with FileExists as file for: " << testNewFile
  248. << std::endl;
  249. res = false;
  250. }
  251. if (!kwsys::SystemTools::FileExists(testNewFile.c_str(), true)) {
  252. std::cerr << "Problem with FileExists as C string and file for: "
  253. << testNewFile << std::endl;
  254. res = false;
  255. }
  256. // calling with an empty string should return false
  257. if (kwsys::SystemTools::PathExists(std::string())) {
  258. std::cerr << "Problem with PathExists(std::string())" << std::endl;
  259. res = false;
  260. }
  261. // PathExists(x) should return true on a directory
  262. if (!kwsys::SystemTools::PathExists(testNewDir)) {
  263. std::cerr << "Problem with PathExists for: " << testNewDir << std::endl;
  264. res = false;
  265. }
  266. // should work, was created as new file before
  267. if (!kwsys::SystemTools::PathExists(testNewFile)) {
  268. std::cerr << "Problem with PathExists for: " << testNewFile << std::endl;
  269. res = false;
  270. }
  271. // Reset umask
  272. #if defined(_WIN32) && !defined(__CYGWIN__)
  273. // NOTE: Windows doesn't support toggling _S_IREAD.
  274. mode_t fullMask = _S_IWRITE;
  275. #else
  276. // On a normal POSIX platform, we can toggle all permissions.
  277. mode_t fullMask = S_IRWXU | S_IRWXG | S_IRWXO;
  278. #endif
  279. mode_t orig_umask = umask(fullMask);
  280. // Test file permissions without umask
  281. mode_t origPerm, thisPerm;
  282. if (!kwsys::SystemTools::GetPermissions(testNewFile, origPerm)) {
  283. std::cerr << "Problem with GetPermissions (1) for: " << testNewFile
  284. << std::endl;
  285. res = false;
  286. }
  287. if (!kwsys::SystemTools::SetPermissions(testNewFile, 0)) {
  288. std::cerr << "Problem with SetPermissions (1) for: " << testNewFile
  289. << std::endl;
  290. res = false;
  291. }
  292. if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm)) {
  293. std::cerr << "Problem with GetPermissions (2) for: " << testNewFile
  294. << std::endl;
  295. res = false;
  296. }
  297. if ((thisPerm & fullMask) != 0) {
  298. std::cerr << "SetPermissions failed to set permissions (1) for: "
  299. << testNewFile << ": actual = " << thisPerm
  300. << "; expected = " << 0 << std::endl;
  301. res = false;
  302. }
  303. // While we're at it, check proper TestFileAccess functionality.
  304. bool do_write_test = true;
  305. #if defined(__linux__)
  306. // If we are running as root on linux ignore this check, as
  307. // root can always write to files
  308. do_write_test = (getuid() != 0);
  309. #endif
  310. if (do_write_test &&
  311. kwsys::SystemTools::TestFileAccess(testNewFile,
  312. kwsys::TEST_FILE_WRITE)) {
  313. std::cerr
  314. << "TestFileAccess incorrectly indicated that this is a writable file:"
  315. << testNewFile << std::endl;
  316. res = false;
  317. }
  318. if (!kwsys::SystemTools::TestFileAccess(testNewFile, kwsys::TEST_FILE_OK)) {
  319. std::cerr
  320. << "TestFileAccess incorrectly indicated that this file does not exist:"
  321. << testNewFile << std::endl;
  322. res = false;
  323. }
  324. // Test restoring/setting full permissions.
  325. if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask)) {
  326. std::cerr << "Problem with SetPermissions (2) for: " << testNewFile
  327. << std::endl;
  328. res = false;
  329. }
  330. if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm)) {
  331. std::cerr << "Problem with GetPermissions (3) for: " << testNewFile
  332. << std::endl;
  333. res = false;
  334. }
  335. if ((thisPerm & fullMask) != fullMask) {
  336. std::cerr << "SetPermissions failed to set permissions (2) for: "
  337. << testNewFile << ": actual = " << thisPerm
  338. << "; expected = " << fullMask << std::endl;
  339. res = false;
  340. }
  341. // Test setting file permissions while honoring umask
  342. if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask, true)) {
  343. std::cerr << "Problem with SetPermissions (3) for: " << testNewFile
  344. << std::endl;
  345. res = false;
  346. }
  347. if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm)) {
  348. std::cerr << "Problem with GetPermissions (4) for: " << testNewFile
  349. << std::endl;
  350. res = false;
  351. }
  352. if ((thisPerm & fullMask) != 0) {
  353. std::cerr << "SetPermissions failed to honor umask for: " << testNewFile
  354. << ": actual = " << thisPerm << "; expected = " << 0
  355. << std::endl;
  356. res = false;
  357. }
  358. // Restore umask
  359. umask(orig_umask);
  360. // Restore file permissions
  361. if (!kwsys::SystemTools::SetPermissions(testNewFile, origPerm)) {
  362. std::cerr << "Problem with SetPermissions (4) for: " << testNewFile
  363. << std::endl;
  364. res = false;
  365. }
  366. // Remove the test file
  367. if (!kwsys::SystemTools::RemoveFile(testNewFile)) {
  368. std::cerr << "Problem with RemoveFile: " << testNewFile << std::endl;
  369. res = false;
  370. }
  371. std::string const testFileMissing(testNewDir + "/testMissingFile.txt");
  372. if (!kwsys::SystemTools::RemoveFile(testFileMissing)) {
  373. std::string const& msg = kwsys::SystemTools::GetLastSystemError();
  374. std::cerr << "RemoveFile(\"" << testFileMissing << "\") failed: " << msg
  375. << "\n";
  376. res = false;
  377. }
  378. std::string const testFileMissingDir(testNewDir + "/missing/file.txt");
  379. if (!kwsys::SystemTools::RemoveFile(testFileMissingDir)) {
  380. std::string const& msg = kwsys::SystemTools::GetLastSystemError();
  381. std::cerr << "RemoveFile(\"" << testFileMissingDir << "\") failed: " << msg
  382. << "\n";
  383. res = false;
  384. }
  385. kwsys::SystemTools::Touch(testNewFile, true);
  386. if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
  387. std::cerr << "Problem with RemoveADirectory for: " << testNewDir
  388. << std::endl;
  389. res = false;
  390. }
  391. #ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
  392. // Perform the same file and directory creation and deletion tests but
  393. // with paths > 256 characters in length.
  394. const std::string testNewLongDir(
  395. TEST_SYSTEMTOOLS_BINARY_DIR
  396. "/"
  397. "012345678901234567890123456789012345678901234567890123456789"
  398. "012345678901234567890123456789012345678901234567890123456789"
  399. "012345678901234567890123456789012345678901234567890123456789"
  400. "012345678901234567890123456789012345678901234567890123456789"
  401. "01234567890123");
  402. const std::string testNewLongFile(
  403. testNewLongDir +
  404. "/"
  405. "012345678901234567890123456789012345678901234567890123456789"
  406. "012345678901234567890123456789012345678901234567890123456789"
  407. "012345678901234567890123456789012345678901234567890123456789"
  408. "012345678901234567890123456789012345678901234567890123456789"
  409. "0123456789.txt");
  410. if (!kwsys::SystemTools::MakeDirectory(testNewLongDir)) {
  411. std::cerr << "Problem with MakeDirectory for: " << testNewLongDir
  412. << std::endl;
  413. res = false;
  414. }
  415. if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true)) {
  416. std::cerr << "Problem with Touch for: " << testNewLongFile << std::endl;
  417. res = false;
  418. }
  419. if (!kwsys::SystemTools::RemoveFile(testNewLongFile)) {
  420. std::cerr << "Problem with RemoveFile: " << testNewLongFile << std::endl;
  421. res = false;
  422. }
  423. kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
  424. if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir)) {
  425. std::cerr << "Problem with RemoveADirectory for: " << testNewLongDir
  426. << std::endl;
  427. res = false;
  428. }
  429. #endif
  430. return res;
  431. }
  432. static bool CheckStringOperations()
  433. {
  434. bool res = true;
  435. std::string test = "mary had a little lamb.";
  436. if (kwsys::SystemTools::CapitalizedWords(test) !=
  437. "Mary Had A Little Lamb.") {
  438. std::cerr << "Problem with CapitalizedWords " << '"' << test << '"'
  439. << std::endl;
  440. res = false;
  441. }
  442. test = "Mary Had A Little Lamb.";
  443. if (kwsys::SystemTools::UnCapitalizedWords(test) !=
  444. "mary had a little lamb.") {
  445. std::cerr << "Problem with UnCapitalizedWords " << '"' << test << '"'
  446. << std::endl;
  447. res = false;
  448. }
  449. test = "MaryHadTheLittleLamb.";
  450. if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
  451. "Mary Had The Little Lamb.") {
  452. std::cerr << "Problem with AddSpaceBetweenCapitalizedWords " << '"' << test
  453. << '"' << std::endl;
  454. res = false;
  455. }
  456. char* cres =
  457. kwsys::SystemTools::AppendStrings("Mary Had A", " Little Lamb.");
  458. if (strcmp(cres, "Mary Had A Little Lamb.")) {
  459. std::cerr << "Problem with AppendStrings "
  460. << "\"Mary Had A\" \" Little Lamb.\"" << std::endl;
  461. res = false;
  462. }
  463. delete[] cres;
  464. cres = kwsys::SystemTools::AppendStrings("Mary Had", " A ", "Little Lamb.");
  465. if (strcmp(cres, "Mary Had A Little Lamb.")) {
  466. std::cerr << "Problem with AppendStrings "
  467. << "\"Mary Had\" \" A \" \"Little Lamb.\"" << std::endl;
  468. res = false;
  469. }
  470. delete[] cres;
  471. if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.", 'a') != 3) {
  472. std::cerr << "Problem with CountChar "
  473. << "\"Mary Had A Little Lamb.\"" << std::endl;
  474. res = false;
  475. }
  476. cres = kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.", "aeiou");
  477. if (strcmp(cres, "Mry Hd A Lttl Lmb.")) {
  478. std::cerr << "Problem with RemoveChars "
  479. << "\"Mary Had A Little Lamb.\"" << std::endl;
  480. res = false;
  481. }
  482. delete[] cres;
  483. cres = kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
  484. if (strcmp(cres, "A")) {
  485. std::cerr << "Problem with RemoveCharsButUpperHex "
  486. << "\"Mary Had A Little Lamb.\"" << std::endl;
  487. res = false;
  488. }
  489. delete[] cres;
  490. char* cres2 = strdup("Mary Had A Little Lamb.");
  491. kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X');
  492. if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) {
  493. std::cerr << "Problem with ReplaceChars "
  494. << "\"Mary Had A Little Lamb.\"" << std::endl;
  495. res = false;
  496. }
  497. free(cres2);
  498. if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
  499. "Mary ")) {
  500. std::cerr << "Problem with StringStartsWith "
  501. << "\"Mary Had A Little Lamb.\"" << std::endl;
  502. res = false;
  503. }
  504. if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
  505. " Lamb.")) {
  506. std::cerr << "Problem with StringEndsWith "
  507. << "\"Mary Had A Little Lamb.\"" << std::endl;
  508. res = false;
  509. }
  510. cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
  511. if (strcmp(cres, "Mary Had A Little Lamb.")) {
  512. std::cerr << "Problem with DuplicateString "
  513. << "\"Mary Had A Little Lamb.\"" << std::endl;
  514. res = false;
  515. }
  516. delete[] cres;
  517. test = "Mary Had A Little Lamb.";
  518. if (kwsys::SystemTools::CropString(test, 13) != "Mary ...Lamb.") {
  519. std::cerr << "Problem with CropString "
  520. << "\"Mary Had A Little Lamb.\"" << std::endl;
  521. res = false;
  522. }
  523. std::vector<std::string> lines;
  524. kwsys::SystemTools::Split("Mary Had A Little Lamb.", lines, ' ');
  525. if (lines[0] != "Mary" || lines[1] != "Had" || lines[2] != "A" ||
  526. lines[3] != "Little" || lines[4] != "Lamb.") {
  527. std::cerr << "Problem with Split "
  528. << "\"Mary Had A Little Lamb.\"" << std::endl;
  529. res = false;
  530. }
  531. if (kwsys::SystemTools::ConvertToWindowsOutputPath(
  532. "L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  533. "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {
  534. std::cerr << "Problem with ConvertToWindowsOutputPath "
  535. << "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
  536. res = false;
  537. }
  538. if (kwsys::SystemTools::ConvertToWindowsOutputPath(
  539. "//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  540. "\"\\\\grayson\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {
  541. std::cerr << "Problem with ConvertToWindowsOutputPath "
  542. << "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\""
  543. << std::endl;
  544. res = false;
  545. }
  546. if (kwsys::SystemTools::ConvertToUnixOutputPath(
  547. "//Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  548. "//Local\\ Mojo/Hex\\ Power\\ Pack/Iffy\\ Voodoo") {
  549. std::cerr << "Problem with ConvertToUnixOutputPath "
  550. << "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
  551. res = false;
  552. }
  553. return res;
  554. }
  555. static bool CheckPutEnv(const std::string& env, const char* name,
  556. const char* value)
  557. {
  558. if (!kwsys::SystemTools::PutEnv(env)) {
  559. std::cerr << "PutEnv(\"" << env << "\") failed!" << std::endl;
  560. return false;
  561. }
  562. std::string v = "(null)";
  563. kwsys::SystemTools::GetEnv(name, v);
  564. if (v != value) {
  565. std::cerr << "GetEnv(\"" << name << "\") returned \"" << v << "\", not \""
  566. << value << "\"!" << std::endl;
  567. return false;
  568. }
  569. return true;
  570. }
  571. static bool CheckUnPutEnv(const char* env, const char* name)
  572. {
  573. if (!kwsys::SystemTools::UnPutEnv(env)) {
  574. std::cerr << "UnPutEnv(\"" << env << "\") failed!" << std::endl;
  575. return false;
  576. }
  577. std::string v;
  578. if (kwsys::SystemTools::GetEnv(name, v)) {
  579. std::cerr << "GetEnv(\"" << name << "\") returned \"" << v
  580. << "\", not (null)!" << std::endl;
  581. return false;
  582. }
  583. return true;
  584. }
  585. static bool CheckEnvironmentOperations()
  586. {
  587. bool res = true;
  588. res &= CheckPutEnv("A=B", "A", "B");
  589. res &= CheckPutEnv("B=C", "B", "C");
  590. res &= CheckPutEnv("C=D", "C", "D");
  591. res &= CheckPutEnv("D=E", "D", "E");
  592. res &= CheckUnPutEnv("A", "A");
  593. res &= CheckUnPutEnv("B=", "B");
  594. res &= CheckUnPutEnv("C=D", "C");
  595. /* Leave "D=E" in environment so a memory checker can test for leaks. */
  596. return res;
  597. }
  598. static bool CheckRelativePath(const std::string& local,
  599. const std::string& remote,
  600. const std::string& expected)
  601. {
  602. std::string result = kwsys::SystemTools::RelativePath(local, remote);
  603. if (!kwsys::SystemTools::ComparePath(expected, result)) {
  604. std::cerr << "RelativePath(" << local << ", " << remote << ") yielded "
  605. << result << " instead of " << expected << std::endl;
  606. return false;
  607. }
  608. return true;
  609. }
  610. static bool CheckRelativePaths()
  611. {
  612. bool res = true;
  613. res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash");
  614. res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash");
  615. res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash");
  616. res &=
  617. CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash");
  618. res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin");
  619. return res;
  620. }
  621. static bool CheckCollapsePath(const std::string& path,
  622. const std::string& expected,
  623. const char* base = nullptr)
  624. {
  625. std::string result = kwsys::SystemTools::CollapseFullPath(path, base);
  626. if (!kwsys::SystemTools::ComparePath(expected, result)) {
  627. std::cerr << "CollapseFullPath(" << path << ") yielded " << result
  628. << " instead of " << expected << std::endl;
  629. return false;
  630. }
  631. return true;
  632. }
  633. static bool CheckCollapsePath()
  634. {
  635. bool res = true;
  636. res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
  637. res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
  638. res &= CheckCollapsePath("/usr/share/../lib", "/usr/lib");
  639. res &= CheckCollapsePath("/usr/share/./lib", "/usr/share/lib");
  640. res &= CheckCollapsePath("/usr/share/../../lib", "/lib");
  641. res &= CheckCollapsePath("/usr/share/.././../lib", "/lib");
  642. res &= CheckCollapsePath("/../lib", "/lib");
  643. res &= CheckCollapsePath("/../lib/", "/lib");
  644. res &= CheckCollapsePath("/", "/");
  645. res &= CheckCollapsePath("C:/", "C:/");
  646. res &= CheckCollapsePath("C:/../", "C:/");
  647. res &= CheckCollapsePath("C:/../../", "C:/");
  648. res &= CheckCollapsePath("../b", "../../b", "../");
  649. res &= CheckCollapsePath("../a/../b", "../b", "../rel");
  650. res &= CheckCollapsePath("a/../b", "../rel/b", "../rel");
  651. return res;
  652. }
  653. static std::string StringVectorToString(const std::vector<std::string>& vec)
  654. {
  655. std::stringstream ss;
  656. ss << "vector(";
  657. for (auto i = vec.begin(); i != vec.end(); ++i) {
  658. if (i != vec.begin()) {
  659. ss << ", ";
  660. }
  661. ss << *i;
  662. }
  663. ss << ")";
  664. return ss.str();
  665. }
  666. static bool CheckGetPath()
  667. {
  668. const char* envName = "S";
  669. #ifdef _WIN32
  670. const char* envValue = "C:\\Somewhere\\something;D:\\Temp";
  671. #else
  672. const char* envValue = "/Somewhere/something:/tmp";
  673. #endif
  674. const char* registryPath = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp; MyKey]";
  675. std::vector<std::string> originalPaths;
  676. originalPaths.emplace_back(registryPath);
  677. std::vector<std::string> expectedPaths;
  678. expectedPaths.emplace_back(registryPath);
  679. #ifdef _WIN32
  680. expectedPaths.push_back("C:/Somewhere/something");
  681. expectedPaths.push_back("D:/Temp");
  682. #else
  683. expectedPaths.emplace_back("/Somewhere/something");
  684. expectedPaths.emplace_back("/tmp");
  685. #endif
  686. bool res = true;
  687. res &= CheckPutEnv(std::string(envName) + "=" + envValue, envName, envValue);
  688. std::vector<std::string> paths = originalPaths;
  689. kwsys::SystemTools::GetPath(paths, envName);
  690. if (paths != expectedPaths) {
  691. std::cerr << "GetPath(" << StringVectorToString(originalPaths) << ", "
  692. << envName << ") yielded " << StringVectorToString(paths)
  693. << " instead of " << StringVectorToString(expectedPaths)
  694. << std::endl;
  695. res = false;
  696. }
  697. res &= CheckUnPutEnv(envName, envName);
  698. return res;
  699. }
  700. static bool CheckGetFilenameName()
  701. {
  702. const char* windowsFilepath = "C:\\somewhere\\something";
  703. const char* unixFilepath = "/somewhere/something";
  704. #if defined(_WIN32) || defined(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
  705. std::string expectedWindowsFilename = "something";
  706. #else
  707. std::string expectedWindowsFilename = "C:\\somewhere\\something";
  708. #endif
  709. std::string expectedUnixFilename = "something";
  710. bool res = true;
  711. std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath);
  712. if (filename != expectedWindowsFilename) {
  713. std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded "
  714. << filename << " instead of " << expectedWindowsFilename
  715. << std::endl;
  716. res = false;
  717. }
  718. filename = kwsys::SystemTools::GetFilenameName(unixFilepath);
  719. if (filename != expectedUnixFilename) {
  720. std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename
  721. << " instead of " << expectedUnixFilename << std::endl;
  722. res = false;
  723. }
  724. return res;
  725. }
  726. static bool CheckFind()
  727. {
  728. bool res = true;
  729. const std::string testFindFileName("testFindFile.txt");
  730. const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/" +
  731. testFindFileName);
  732. if (!kwsys::SystemTools::Touch(testFindFile, true)) {
  733. std::cerr << "Problem with Touch for: " << testFindFile << std::endl;
  734. // abort here as the existence of the file only makes the test meaningful
  735. return false;
  736. }
  737. std::vector<std::string> searchPaths;
  738. searchPaths.emplace_back(TEST_SYSTEMTOOLS_BINARY_DIR);
  739. if (kwsys::SystemTools::FindFile(testFindFileName, searchPaths, true)
  740. .empty()) {
  741. std::cerr << "Problem with FindFile without system paths for: "
  742. << testFindFileName << std::endl;
  743. res = false;
  744. }
  745. if (kwsys::SystemTools::FindFile(testFindFileName, searchPaths, false)
  746. .empty()) {
  747. std::cerr << "Problem with FindFile with system paths for: "
  748. << testFindFileName << std::endl;
  749. res = false;
  750. }
  751. return res;
  752. }
  753. static bool CheckIsSubDirectory()
  754. {
  755. bool res = true;
  756. if (kwsys::SystemTools::IsSubDirectory("/foo", "/") == false) {
  757. std::cerr << "Problem with IsSubDirectory (root - unix): " << std::endl;
  758. res = false;
  759. }
  760. if (kwsys::SystemTools::IsSubDirectory("c:/foo", "c:/") == false) {
  761. std::cerr << "Problem with IsSubDirectory (root - dos): " << std::endl;
  762. res = false;
  763. }
  764. if (kwsys::SystemTools::IsSubDirectory("/foo/bar", "/foo") == false) {
  765. std::cerr << "Problem with IsSubDirectory (deep): " << std::endl;
  766. res = false;
  767. }
  768. if (kwsys::SystemTools::IsSubDirectory("/foo", "/foo") == true) {
  769. std::cerr << "Problem with IsSubDirectory (identity): " << std::endl;
  770. res = false;
  771. }
  772. if (kwsys::SystemTools::IsSubDirectory("/fooo", "/foo") == true) {
  773. std::cerr << "Problem with IsSubDirectory (substring): " << std::endl;
  774. res = false;
  775. }
  776. if (kwsys::SystemTools::IsSubDirectory("/foo/", "/foo") == true) {
  777. std::cerr << "Problem with IsSubDirectory (prepended slash): "
  778. << std::endl;
  779. res = false;
  780. }
  781. return res;
  782. }
  783. static bool CheckGetLineFromStream()
  784. {
  785. const std::string fileWithFiveCharsOnFirstLine(TEST_SYSTEMTOOLS_SOURCE_DIR
  786. "/README.rst");
  787. kwsys::ifstream file(fileWithFiveCharsOnFirstLine.c_str(), std::ios::in);
  788. if (!file) {
  789. std::cerr << "Problem opening: " << fileWithFiveCharsOnFirstLine
  790. << std::endl;
  791. return false;
  792. }
  793. std::string line;
  794. bool has_newline = false;
  795. bool result;
  796. file.seekg(0, std::ios::beg);
  797. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  798. if (!result || line.size() != 5) {
  799. std::cerr << "First line does not have five characters: " << line.size()
  800. << std::endl;
  801. return false;
  802. }
  803. file.seekg(0, std::ios::beg);
  804. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  805. if (!result || line.size() != 5) {
  806. std::cerr << "First line does not have five characters after rewind: "
  807. << line.size() << std::endl;
  808. return false;
  809. }
  810. bool ret = true;
  811. for (size_t size = 1; size <= 5; ++size) {
  812. file.seekg(0, std::ios::beg);
  813. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline,
  814. static_cast<long>(size));
  815. if (!result || line.size() != size) {
  816. std::cerr << "Should have read " << size << " characters but got "
  817. << line.size() << std::endl;
  818. ret = false;
  819. }
  820. }
  821. return ret;
  822. }
  823. static bool CheckGetLineFromStreamLongLine()
  824. {
  825. const std::string fileWithLongLine("longlines.txt");
  826. std::string firstLine, secondLine;
  827. // First line: large buffer, containing a carriage return for some reason.
  828. firstLine.assign(2050, ' ');
  829. firstLine += "\rfirst";
  830. secondLine.assign(2050, 'y');
  831. secondLine += "second";
  832. // Create file with long lines.
  833. {
  834. kwsys::ofstream out(fileWithLongLine.c_str(), std::ios::binary);
  835. if (!out) {
  836. std::cerr << "Problem opening for write: " << fileWithLongLine
  837. << std::endl;
  838. return false;
  839. }
  840. out << firstLine << "\r\n\n" << secondLine << "\n";
  841. }
  842. kwsys::ifstream file(fileWithLongLine.c_str(), std::ios::binary);
  843. if (!file) {
  844. std::cerr << "Problem opening: " << fileWithLongLine << std::endl;
  845. return false;
  846. }
  847. std::string line;
  848. bool has_newline = false;
  849. bool result;
  850. // Read first line.
  851. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  852. if (!result || line != firstLine) {
  853. std::cerr << "First line does not match, expected " << firstLine.size()
  854. << " characters, got " << line.size() << std::endl;
  855. return false;
  856. }
  857. if (!has_newline) {
  858. std::cerr << "Expected new line to be read from first line" << std::endl;
  859. return false;
  860. }
  861. // Read empty line.
  862. has_newline = false;
  863. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  864. if (!result || !line.empty()) {
  865. std::cerr << "Expected successful read with an empty line, got "
  866. << line.size() << " characters" << std::endl;
  867. return false;
  868. }
  869. if (!has_newline) {
  870. std::cerr << "Expected new line to be read for an empty line" << std::endl;
  871. return false;
  872. }
  873. // Read second line.
  874. has_newline = false;
  875. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  876. if (!result || line != secondLine) {
  877. std::cerr << "Second line does not match, expected " << secondLine.size()
  878. << " characters, got " << line.size() << std::endl;
  879. return false;
  880. }
  881. if (!has_newline) {
  882. std::cerr << "Expected new line to be read from second line" << std::endl;
  883. return false;
  884. }
  885. return true;
  886. }
  887. static bool writeFile(const char* fileName, const char* data)
  888. {
  889. kwsys::ofstream out(fileName, std::ios::binary);
  890. out << data;
  891. if (!out) {
  892. std::cerr << "Failed to write file: " << fileName << std::endl;
  893. return false;
  894. }
  895. return true;
  896. }
  897. static std::string readFile(const char* fileName)
  898. {
  899. kwsys::ifstream in(fileName, std::ios::binary);
  900. std::stringstream sstr;
  901. sstr << in.rdbuf();
  902. std::string data = sstr.str();
  903. if (!in) {
  904. std::cerr << "Failed to read file: " << fileName << std::endl;
  905. return std::string();
  906. }
  907. return data;
  908. }
  909. struct
  910. {
  911. const char* a;
  912. const char* b;
  913. bool differ;
  914. } diff_test_cases[] = { { "one", "one", false },
  915. { "one", "two", true },
  916. { "", "", false },
  917. { "\n", "\r\n", false },
  918. { "one\n", "one\n", false },
  919. { "one\r\n", "one\n", false },
  920. { "one\n", "one", false },
  921. { "one\ntwo", "one\ntwo", false },
  922. { "one\ntwo", "one\r\ntwo", false } };
  923. static bool CheckTextFilesDiffer()
  924. {
  925. const int num_test_cases =
  926. sizeof(diff_test_cases) / sizeof(diff_test_cases[0]);
  927. for (int i = 0; i < num_test_cases; ++i) {
  928. if (!writeFile("file_a", diff_test_cases[i].a) ||
  929. !writeFile("file_b", diff_test_cases[i].b)) {
  930. return false;
  931. }
  932. if (kwsys::SystemTools::TextFilesDiffer("file_a", "file_b") !=
  933. diff_test_cases[i].differ) {
  934. std::cerr << "Incorrect TextFilesDiffer result for test case " << i + 1
  935. << "." << std::endl;
  936. return false;
  937. }
  938. }
  939. return true;
  940. }
  941. static bool CheckCopyFileIfDifferent()
  942. {
  943. bool ret = true;
  944. const int num_test_cases =
  945. sizeof(diff_test_cases) / sizeof(diff_test_cases[0]);
  946. for (int i = 0; i < num_test_cases; ++i) {
  947. if (!writeFile("file_a", diff_test_cases[i].a) ||
  948. !writeFile("file_b", diff_test_cases[i].b)) {
  949. return false;
  950. }
  951. const char* cptarget =
  952. i < 4 ? TEST_SYSTEMTOOLS_BINARY_DIR "/file_b" : "file_b";
  953. if (!kwsys::SystemTools::CopyFileIfDifferent("file_a", cptarget)) {
  954. std::cerr << "CopyFileIfDifferent() returned false for test case "
  955. << i + 1 << "." << std::endl;
  956. ret = false;
  957. continue;
  958. }
  959. std::string bdata = readFile("file_b");
  960. if (diff_test_cases[i].a != bdata) {
  961. std::cerr << "Incorrect CopyFileIfDifferent file contents in test case "
  962. << i + 1 << "." << std::endl;
  963. ret = false;
  964. continue;
  965. }
  966. }
  967. if (!kwsys::SystemTools::MakeDirectory("dir_a") ||
  968. !kwsys::SystemTools::MakeDirectory("dir_b")) {
  969. return false;
  970. }
  971. if (!kwsys::SystemTools::CopyFileIfDifferent("dir_a/", "dir_b")) {
  972. ret = false;
  973. }
  974. return ret;
  975. }
  976. static bool CheckURLParsing()
  977. {
  978. bool ret = true;
  979. std::string url = "http://user:pw@hostname:42/full/url.com";
  980. std::string protocol, username, password, hostname, dataport, database;
  981. kwsys::SystemTools::ParseURL(url, protocol, username, password, hostname,
  982. dataport, database);
  983. if (protocol != "http" || username != "user" || password != "pw" ||
  984. hostname != "hostname" || dataport != "42" ||
  985. database != "full/url.com") {
  986. std::cerr << "Incorrect URL parsing" << std::endl;
  987. ret = false;
  988. }
  989. std::string uri =
  990. "file://hostname/path/to/"
  991. "a%20file%20with%20str%C3%A0ng%C3%A8%20ch%40r%20and%20s%C2%B5aces";
  992. kwsys::SystemTools::ParseURL(uri, protocol, username, password, hostname,
  993. dataport, database, true);
  994. if (protocol != "file" || hostname != "hostname" ||
  995. database != "path/to/a file with stràngè ch@r and sµaces") {
  996. std::cerr << "Incorrect URL parsing or decoding" << std::endl;
  997. ret = false;
  998. }
  999. return ret;
  1000. }
  1001. int testSystemTools(int, char* [])
  1002. {
  1003. bool res = true;
  1004. int cc;
  1005. for (cc = 0; toUnixPaths[cc][0]; cc++) {
  1006. res &= CheckConvertToUnixSlashes(toUnixPaths[cc][0], toUnixPaths[cc][1]);
  1007. }
  1008. // Special check for ~
  1009. std::string output;
  1010. if (kwsys::SystemTools::GetEnv("HOME", output)) {
  1011. output += "/foo bar/lala";
  1012. res &= CheckConvertToUnixSlashes("~/foo bar/lala", output);
  1013. }
  1014. for (cc = 0; checkEscapeChars[cc][0]; cc++) {
  1015. res &= CheckEscapeChars(checkEscapeChars[cc][0], checkEscapeChars[cc][1],
  1016. *checkEscapeChars[cc][2], checkEscapeChars[cc][3]);
  1017. }
  1018. res &= CheckFileOperations();
  1019. res &= CheckStringOperations();
  1020. res &= CheckEnvironmentOperations();
  1021. res &= CheckRelativePaths();
  1022. res &= CheckCollapsePath();
  1023. res &= CheckGetPath();
  1024. res &= CheckFind();
  1025. res &= CheckIsSubDirectory();
  1026. res &= CheckGetLineFromStream();
  1027. res &= CheckGetLineFromStreamLongLine();
  1028. res &= CheckGetFilenameName();
  1029. res &= CheckTextFilesDiffer();
  1030. res &= CheckCopyFileIfDifferent();
  1031. res &= CheckURLParsing();
  1032. return res ? 0 : 1;
  1033. }