testSystemTools.cxx 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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. if (kwsys::SystemTools::TestFileAccess(testNewFile,
  305. kwsys::TEST_FILE_WRITE)) {
  306. std::cerr
  307. << "TestFileAccess incorrectly indicated that this is a writable file:"
  308. << testNewFile << std::endl;
  309. res = false;
  310. }
  311. if (!kwsys::SystemTools::TestFileAccess(testNewFile, kwsys::TEST_FILE_OK)) {
  312. std::cerr
  313. << "TestFileAccess incorrectly indicated that this file does not exist:"
  314. << testNewFile << std::endl;
  315. res = false;
  316. }
  317. // Test restoring/setting full permissions.
  318. if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask)) {
  319. std::cerr << "Problem with SetPermissions (2) for: " << testNewFile
  320. << std::endl;
  321. res = false;
  322. }
  323. if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm)) {
  324. std::cerr << "Problem with GetPermissions (3) for: " << testNewFile
  325. << std::endl;
  326. res = false;
  327. }
  328. if ((thisPerm & fullMask) != fullMask) {
  329. std::cerr << "SetPermissions failed to set permissions (2) for: "
  330. << testNewFile << ": actual = " << thisPerm
  331. << "; expected = " << fullMask << std::endl;
  332. res = false;
  333. }
  334. // Test setting file permissions while honoring umask
  335. if (!kwsys::SystemTools::SetPermissions(testNewFile, fullMask, true)) {
  336. std::cerr << "Problem with SetPermissions (3) for: " << testNewFile
  337. << std::endl;
  338. res = false;
  339. }
  340. if (!kwsys::SystemTools::GetPermissions(testNewFile, thisPerm)) {
  341. std::cerr << "Problem with GetPermissions (4) for: " << testNewFile
  342. << std::endl;
  343. res = false;
  344. }
  345. if ((thisPerm & fullMask) != 0) {
  346. std::cerr << "SetPermissions failed to honor umask for: " << testNewFile
  347. << ": actual = " << thisPerm << "; expected = " << 0
  348. << std::endl;
  349. res = false;
  350. }
  351. // Restore umask
  352. umask(orig_umask);
  353. // Restore file permissions
  354. if (!kwsys::SystemTools::SetPermissions(testNewFile, origPerm)) {
  355. std::cerr << "Problem with SetPermissions (4) for: " << testNewFile
  356. << std::endl;
  357. res = false;
  358. }
  359. // Remove the test file
  360. if (!kwsys::SystemTools::RemoveFile(testNewFile)) {
  361. std::cerr << "Problem with RemoveFile: " << testNewFile << std::endl;
  362. res = false;
  363. }
  364. std::string const testFileMissing(testNewDir + "/testMissingFile.txt");
  365. if (!kwsys::SystemTools::RemoveFile(testFileMissing)) {
  366. std::string const& msg = kwsys::SystemTools::GetLastSystemError();
  367. std::cerr << "RemoveFile(\"" << testFileMissing << "\") failed: " << msg
  368. << "\n";
  369. res = false;
  370. }
  371. std::string const testFileMissingDir(testNewDir + "/missing/file.txt");
  372. if (!kwsys::SystemTools::RemoveFile(testFileMissingDir)) {
  373. std::string const& msg = kwsys::SystemTools::GetLastSystemError();
  374. std::cerr << "RemoveFile(\"" << testFileMissingDir << "\") failed: " << msg
  375. << "\n";
  376. res = false;
  377. }
  378. kwsys::SystemTools::Touch(testNewFile, true);
  379. if (!kwsys::SystemTools::RemoveADirectory(testNewDir)) {
  380. std::cerr << "Problem with RemoveADirectory for: " << testNewDir
  381. << std::endl;
  382. res = false;
  383. }
  384. #ifdef KWSYS_TEST_SYSTEMTOOLS_LONG_PATHS
  385. // Perform the same file and directory creation and deletion tests but
  386. // with paths > 256 characters in length.
  387. const std::string testNewLongDir(
  388. TEST_SYSTEMTOOLS_BINARY_DIR
  389. "/"
  390. "012345678901234567890123456789012345678901234567890123456789"
  391. "012345678901234567890123456789012345678901234567890123456789"
  392. "012345678901234567890123456789012345678901234567890123456789"
  393. "012345678901234567890123456789012345678901234567890123456789"
  394. "01234567890123");
  395. const std::string testNewLongFile(
  396. testNewLongDir +
  397. "/"
  398. "012345678901234567890123456789012345678901234567890123456789"
  399. "012345678901234567890123456789012345678901234567890123456789"
  400. "012345678901234567890123456789012345678901234567890123456789"
  401. "012345678901234567890123456789012345678901234567890123456789"
  402. "0123456789.txt");
  403. if (!kwsys::SystemTools::MakeDirectory(testNewLongDir)) {
  404. std::cerr << "Problem with MakeDirectory for: " << testNewLongDir
  405. << std::endl;
  406. res = false;
  407. }
  408. if (!kwsys::SystemTools::Touch(testNewLongFile.c_str(), true)) {
  409. std::cerr << "Problem with Touch for: " << testNewLongFile << std::endl;
  410. res = false;
  411. }
  412. if (!kwsys::SystemTools::RemoveFile(testNewLongFile)) {
  413. std::cerr << "Problem with RemoveFile: " << testNewLongFile << std::endl;
  414. res = false;
  415. }
  416. kwsys::SystemTools::Touch(testNewLongFile.c_str(), true);
  417. if (!kwsys::SystemTools::RemoveADirectory(testNewLongDir)) {
  418. std::cerr << "Problem with RemoveADirectory for: " << testNewLongDir
  419. << std::endl;
  420. res = false;
  421. }
  422. #endif
  423. return res;
  424. }
  425. static bool CheckStringOperations()
  426. {
  427. bool res = true;
  428. std::string test = "mary had a little lamb.";
  429. if (kwsys::SystemTools::CapitalizedWords(test) !=
  430. "Mary Had A Little Lamb.") {
  431. std::cerr << "Problem with CapitalizedWords " << '"' << test << '"'
  432. << std::endl;
  433. res = false;
  434. }
  435. test = "Mary Had A Little Lamb.";
  436. if (kwsys::SystemTools::UnCapitalizedWords(test) !=
  437. "mary had a little lamb.") {
  438. std::cerr << "Problem with UnCapitalizedWords " << '"' << test << '"'
  439. << std::endl;
  440. res = false;
  441. }
  442. test = "MaryHadTheLittleLamb.";
  443. if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
  444. "Mary Had The Little Lamb.") {
  445. std::cerr << "Problem with AddSpaceBetweenCapitalizedWords " << '"' << test
  446. << '"' << std::endl;
  447. res = false;
  448. }
  449. char* cres =
  450. kwsys::SystemTools::AppendStrings("Mary Had A", " Little Lamb.");
  451. if (strcmp(cres, "Mary Had A Little Lamb.")) {
  452. std::cerr << "Problem with AppendStrings "
  453. << "\"Mary Had A\" \" Little Lamb.\"" << std::endl;
  454. res = false;
  455. }
  456. delete[] cres;
  457. cres = 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. if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.", 'a') != 3) {
  465. std::cerr << "Problem with CountChar "
  466. << "\"Mary Had A Little Lamb.\"" << std::endl;
  467. res = false;
  468. }
  469. cres = kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.", "aeiou");
  470. if (strcmp(cres, "Mry Hd A Lttl Lmb.")) {
  471. std::cerr << "Problem with RemoveChars "
  472. << "\"Mary Had A Little Lamb.\"" << std::endl;
  473. res = false;
  474. }
  475. delete[] cres;
  476. cres = kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
  477. if (strcmp(cres, "A")) {
  478. std::cerr << "Problem with RemoveCharsButUpperHex "
  479. << "\"Mary Had A Little Lamb.\"" << std::endl;
  480. res = false;
  481. }
  482. delete[] cres;
  483. char* cres2 = strdup("Mary Had A Little Lamb.");
  484. kwsys::SystemTools::ReplaceChars(cres2, "aeiou", 'X');
  485. if (strcmp(cres2, "MXry HXd A LXttlX LXmb.")) {
  486. std::cerr << "Problem with ReplaceChars "
  487. << "\"Mary Had A Little Lamb.\"" << std::endl;
  488. res = false;
  489. }
  490. free(cres2);
  491. if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
  492. "Mary ")) {
  493. std::cerr << "Problem with StringStartsWith "
  494. << "\"Mary Had A Little Lamb.\"" << std::endl;
  495. res = false;
  496. }
  497. if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
  498. " Lamb.")) {
  499. std::cerr << "Problem with StringEndsWith "
  500. << "\"Mary Had A Little Lamb.\"" << std::endl;
  501. res = false;
  502. }
  503. cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
  504. if (strcmp(cres, "Mary Had A Little Lamb.")) {
  505. std::cerr << "Problem with DuplicateString "
  506. << "\"Mary Had A Little Lamb.\"" << std::endl;
  507. res = false;
  508. }
  509. delete[] cres;
  510. test = "Mary Had A Little Lamb.";
  511. if (kwsys::SystemTools::CropString(test, 13) != "Mary ...Lamb.") {
  512. std::cerr << "Problem with CropString "
  513. << "\"Mary Had A Little Lamb.\"" << std::endl;
  514. res = false;
  515. }
  516. std::vector<std::string> lines;
  517. kwsys::SystemTools::Split("Mary Had A Little Lamb.", lines, ' ');
  518. if (lines[0] != "Mary" || lines[1] != "Had" || lines[2] != "A" ||
  519. lines[3] != "Little" || lines[4] != "Lamb.") {
  520. std::cerr << "Problem with Split "
  521. << "\"Mary Had A Little Lamb.\"" << std::endl;
  522. res = false;
  523. }
  524. if (kwsys::SystemTools::ConvertToWindowsOutputPath(
  525. "L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  526. "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {
  527. std::cerr << "Problem with ConvertToWindowsOutputPath "
  528. << "\"L://Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
  529. res = false;
  530. }
  531. if (kwsys::SystemTools::ConvertToWindowsOutputPath(
  532. "//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  533. "\"\\\\grayson\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {
  534. std::cerr << "Problem with ConvertToWindowsOutputPath "
  535. << "\"//grayson/Local Mojo/Hex Power Pack/Iffy Voodoo\""
  536. << std::endl;
  537. res = false;
  538. }
  539. if (kwsys::SystemTools::ConvertToUnixOutputPath(
  540. "//Local Mojo/Hex Power Pack/Iffy Voodoo") !=
  541. "//Local\\ Mojo/Hex\\ Power\\ Pack/Iffy\\ Voodoo") {
  542. std::cerr << "Problem with ConvertToUnixOutputPath "
  543. << "\"//Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
  544. res = false;
  545. }
  546. return res;
  547. }
  548. static bool CheckPutEnv(const std::string& env, const char* name,
  549. const char* value)
  550. {
  551. if (!kwsys::SystemTools::PutEnv(env)) {
  552. std::cerr << "PutEnv(\"" << env << "\") failed!" << std::endl;
  553. return false;
  554. }
  555. std::string v = "(null)";
  556. kwsys::SystemTools::GetEnv(name, v);
  557. if (v != value) {
  558. std::cerr << "GetEnv(\"" << name << "\") returned \"" << v << "\", not \""
  559. << value << "\"!" << std::endl;
  560. return false;
  561. }
  562. return true;
  563. }
  564. static bool CheckUnPutEnv(const char* env, const char* name)
  565. {
  566. if (!kwsys::SystemTools::UnPutEnv(env)) {
  567. std::cerr << "UnPutEnv(\"" << env << "\") failed!" << std::endl;
  568. return false;
  569. }
  570. std::string v;
  571. if (kwsys::SystemTools::GetEnv(name, v)) {
  572. std::cerr << "GetEnv(\"" << name << "\") returned \"" << v
  573. << "\", not (null)!" << std::endl;
  574. return false;
  575. }
  576. return true;
  577. }
  578. static bool CheckEnvironmentOperations()
  579. {
  580. bool res = true;
  581. res &= CheckPutEnv("A=B", "A", "B");
  582. res &= CheckPutEnv("B=C", "B", "C");
  583. res &= CheckPutEnv("C=D", "C", "D");
  584. res &= CheckPutEnv("D=E", "D", "E");
  585. res &= CheckUnPutEnv("A", "A");
  586. res &= CheckUnPutEnv("B=", "B");
  587. res &= CheckUnPutEnv("C=D", "C");
  588. /* Leave "D=E" in environment so a memory checker can test for leaks. */
  589. return res;
  590. }
  591. static bool CheckRelativePath(const std::string& local,
  592. const std::string& remote,
  593. const std::string& expected)
  594. {
  595. std::string result = kwsys::SystemTools::RelativePath(local, remote);
  596. if (!kwsys::SystemTools::ComparePath(expected, result)) {
  597. std::cerr << "RelativePath(" << local << ", " << remote << ") yielded "
  598. << result << " instead of " << expected << std::endl;
  599. return false;
  600. }
  601. return true;
  602. }
  603. static bool CheckRelativePaths()
  604. {
  605. bool res = true;
  606. res &= CheckRelativePath("/usr/share", "/bin/bash", "../../bin/bash");
  607. res &= CheckRelativePath("/usr/./share/", "/bin/bash", "../../bin/bash");
  608. res &= CheckRelativePath("/usr//share/", "/bin/bash", "../../bin/bash");
  609. res &=
  610. CheckRelativePath("/usr/share/../bin/", "/bin/bash", "../../bin/bash");
  611. res &= CheckRelativePath("/usr/share", "/usr/share//bin", "bin");
  612. return res;
  613. }
  614. static bool CheckCollapsePath(const std::string& path,
  615. const std::string& expected,
  616. const char* base = nullptr)
  617. {
  618. std::string result = kwsys::SystemTools::CollapseFullPath(path, base);
  619. if (!kwsys::SystemTools::ComparePath(expected, result)) {
  620. std::cerr << "CollapseFullPath(" << path << ") yielded " << result
  621. << " instead of " << expected << std::endl;
  622. return false;
  623. }
  624. return true;
  625. }
  626. static bool CheckCollapsePath()
  627. {
  628. bool res = true;
  629. res &= CheckCollapsePath("/usr/share/*", "/usr/share/*");
  630. res &= CheckCollapsePath("C:/Windows/*", "C:/Windows/*");
  631. res &= CheckCollapsePath("/usr/share/../lib", "/usr/lib");
  632. res &= CheckCollapsePath("/usr/share/./lib", "/usr/share/lib");
  633. res &= CheckCollapsePath("/usr/share/../../lib", "/lib");
  634. res &= CheckCollapsePath("/usr/share/.././../lib", "/lib");
  635. res &= CheckCollapsePath("/../lib", "/lib");
  636. res &= CheckCollapsePath("/../lib/", "/lib");
  637. res &= CheckCollapsePath("/", "/");
  638. res &= CheckCollapsePath("C:/", "C:/");
  639. res &= CheckCollapsePath("C:/../", "C:/");
  640. res &= CheckCollapsePath("C:/../../", "C:/");
  641. res &= CheckCollapsePath("../b", "../../b", "../");
  642. res &= CheckCollapsePath("../a/../b", "../b", "../rel");
  643. res &= CheckCollapsePath("a/../b", "../rel/b", "../rel");
  644. return res;
  645. }
  646. static std::string StringVectorToString(const std::vector<std::string>& vec)
  647. {
  648. std::stringstream ss;
  649. ss << "vector(";
  650. for (auto i = vec.begin(); i != vec.end(); ++i) {
  651. if (i != vec.begin()) {
  652. ss << ", ";
  653. }
  654. ss << *i;
  655. }
  656. ss << ")";
  657. return ss.str();
  658. }
  659. static bool CheckGetPath()
  660. {
  661. const char* envName = "S";
  662. #ifdef _WIN32
  663. const char* envValue = "C:\\Somewhere\\something;D:\\Temp";
  664. #else
  665. const char* envValue = "/Somewhere/something:/tmp";
  666. #endif
  667. const char* registryPath = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MyApp; MyKey]";
  668. std::vector<std::string> originalPaths;
  669. originalPaths.emplace_back(registryPath);
  670. std::vector<std::string> expectedPaths;
  671. expectedPaths.emplace_back(registryPath);
  672. #ifdef _WIN32
  673. expectedPaths.push_back("C:/Somewhere/something");
  674. expectedPaths.push_back("D:/Temp");
  675. #else
  676. expectedPaths.emplace_back("/Somewhere/something");
  677. expectedPaths.emplace_back("/tmp");
  678. #endif
  679. bool res = true;
  680. res &= CheckPutEnv(std::string(envName) + "=" + envValue, envName, envValue);
  681. std::vector<std::string> paths = originalPaths;
  682. kwsys::SystemTools::GetPath(paths, envName);
  683. if (paths != expectedPaths) {
  684. std::cerr << "GetPath(" << StringVectorToString(originalPaths) << ", "
  685. << envName << ") yielded " << StringVectorToString(paths)
  686. << " instead of " << StringVectorToString(expectedPaths)
  687. << std::endl;
  688. res = false;
  689. }
  690. res &= CheckUnPutEnv(envName, envName);
  691. return res;
  692. }
  693. static bool CheckGetFilenameName()
  694. {
  695. const char* windowsFilepath = "C:\\somewhere\\something";
  696. const char* unixFilepath = "/somewhere/something";
  697. #if defined(_WIN32) || defined(KWSYS_SYSTEMTOOLS_SUPPORT_WINDOWS_SLASHES)
  698. std::string expectedWindowsFilename = "something";
  699. #else
  700. std::string expectedWindowsFilename = "C:\\somewhere\\something";
  701. #endif
  702. std::string expectedUnixFilename = "something";
  703. bool res = true;
  704. std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath);
  705. if (filename != expectedWindowsFilename) {
  706. std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded "
  707. << filename << " instead of " << expectedWindowsFilename
  708. << std::endl;
  709. res = false;
  710. }
  711. filename = kwsys::SystemTools::GetFilenameName(unixFilepath);
  712. if (filename != expectedUnixFilename) {
  713. std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename
  714. << " instead of " << expectedUnixFilename << std::endl;
  715. res = false;
  716. }
  717. return res;
  718. }
  719. static bool CheckFind()
  720. {
  721. bool res = true;
  722. const std::string testFindFileName("testFindFile.txt");
  723. const std::string testFindFile(TEST_SYSTEMTOOLS_BINARY_DIR "/" +
  724. testFindFileName);
  725. if (!kwsys::SystemTools::Touch(testFindFile, true)) {
  726. std::cerr << "Problem with Touch for: " << testFindFile << std::endl;
  727. // abort here as the existence of the file only makes the test meaningful
  728. return false;
  729. }
  730. std::vector<std::string> searchPaths;
  731. searchPaths.emplace_back(TEST_SYSTEMTOOLS_BINARY_DIR);
  732. if (kwsys::SystemTools::FindFile(testFindFileName, searchPaths, true)
  733. .empty()) {
  734. std::cerr << "Problem with FindFile without system paths for: "
  735. << testFindFileName << std::endl;
  736. res = false;
  737. }
  738. if (kwsys::SystemTools::FindFile(testFindFileName, searchPaths, false)
  739. .empty()) {
  740. std::cerr << "Problem with FindFile with system paths for: "
  741. << testFindFileName << std::endl;
  742. res = false;
  743. }
  744. return res;
  745. }
  746. static bool CheckIsSubDirectory()
  747. {
  748. bool res = true;
  749. if (kwsys::SystemTools::IsSubDirectory("/foo", "/") == false) {
  750. std::cerr << "Problem with IsSubDirectory (root - unix): " << std::endl;
  751. res = false;
  752. }
  753. if (kwsys::SystemTools::IsSubDirectory("c:/foo", "c:/") == false) {
  754. std::cerr << "Problem with IsSubDirectory (root - dos): " << std::endl;
  755. res = false;
  756. }
  757. if (kwsys::SystemTools::IsSubDirectory("/foo/bar", "/foo") == false) {
  758. std::cerr << "Problem with IsSubDirectory (deep): " << std::endl;
  759. res = false;
  760. }
  761. if (kwsys::SystemTools::IsSubDirectory("/foo", "/foo") == true) {
  762. std::cerr << "Problem with IsSubDirectory (identity): " << std::endl;
  763. res = false;
  764. }
  765. if (kwsys::SystemTools::IsSubDirectory("/fooo", "/foo") == true) {
  766. std::cerr << "Problem with IsSubDirectory (substring): " << std::endl;
  767. res = false;
  768. }
  769. if (kwsys::SystemTools::IsSubDirectory("/foo/", "/foo") == true) {
  770. std::cerr << "Problem with IsSubDirectory (prepended slash): "
  771. << std::endl;
  772. res = false;
  773. }
  774. return res;
  775. }
  776. static bool CheckGetLineFromStream()
  777. {
  778. const std::string fileWithFiveCharsOnFirstLine(TEST_SYSTEMTOOLS_SOURCE_DIR
  779. "/README.rst");
  780. kwsys::ifstream file(fileWithFiveCharsOnFirstLine.c_str(), std::ios::in);
  781. if (!file) {
  782. std::cerr << "Problem opening: " << fileWithFiveCharsOnFirstLine
  783. << std::endl;
  784. return false;
  785. }
  786. std::string line;
  787. bool has_newline = false;
  788. bool result;
  789. file.seekg(0, std::ios::beg);
  790. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  791. if (!result || line.size() != 5) {
  792. std::cerr << "First line does not have five characters: " << line.size()
  793. << std::endl;
  794. return false;
  795. }
  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 after rewind: "
  800. << line.size() << std::endl;
  801. return false;
  802. }
  803. bool ret = true;
  804. for (size_t size = 1; size <= 5; ++size) {
  805. file.seekg(0, std::ios::beg);
  806. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline,
  807. static_cast<long>(size));
  808. if (!result || line.size() != size) {
  809. std::cerr << "Should have read " << size << " characters but got "
  810. << line.size() << std::endl;
  811. ret = false;
  812. }
  813. }
  814. return ret;
  815. }
  816. static bool CheckGetLineFromStreamLongLine()
  817. {
  818. const std::string fileWithLongLine("longlines.txt");
  819. std::string firstLine, secondLine;
  820. // First line: large buffer, containing a carriage return for some reason.
  821. firstLine.assign(2050, ' ');
  822. firstLine += "\rfirst";
  823. secondLine.assign(2050, 'y');
  824. secondLine += "second";
  825. // Create file with long lines.
  826. {
  827. kwsys::ofstream out(fileWithLongLine.c_str(), std::ios::binary);
  828. if (!out) {
  829. std::cerr << "Problem opening for write: " << fileWithLongLine
  830. << std::endl;
  831. return false;
  832. }
  833. out << firstLine << "\r\n\n" << secondLine << "\n";
  834. }
  835. kwsys::ifstream file(fileWithLongLine.c_str(), std::ios::binary);
  836. if (!file) {
  837. std::cerr << "Problem opening: " << fileWithLongLine << std::endl;
  838. return false;
  839. }
  840. std::string line;
  841. bool has_newline = false;
  842. bool result;
  843. // Read first line.
  844. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  845. if (!result || line != firstLine) {
  846. std::cerr << "First line does not match, expected " << firstLine.size()
  847. << " characters, got " << line.size() << std::endl;
  848. return false;
  849. }
  850. if (!has_newline) {
  851. std::cerr << "Expected new line to be read from first line" << std::endl;
  852. return false;
  853. }
  854. // Read empty line.
  855. has_newline = false;
  856. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  857. if (!result || !line.empty()) {
  858. std::cerr << "Expected successful read with an empty line, got "
  859. << line.size() << " characters" << std::endl;
  860. return false;
  861. }
  862. if (!has_newline) {
  863. std::cerr << "Expected new line to be read for an empty line" << std::endl;
  864. return false;
  865. }
  866. // Read second line.
  867. has_newline = false;
  868. result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, -1);
  869. if (!result || line != secondLine) {
  870. std::cerr << "Second line does not match, expected " << secondLine.size()
  871. << " characters, got " << line.size() << std::endl;
  872. return false;
  873. }
  874. if (!has_newline) {
  875. std::cerr << "Expected new line to be read from second line" << std::endl;
  876. return false;
  877. }
  878. return true;
  879. }
  880. static bool writeFile(const char* fileName, const char* data)
  881. {
  882. kwsys::ofstream out(fileName, std::ios::binary);
  883. out << data;
  884. if (!out) {
  885. std::cerr << "Failed to write file: " << fileName << std::endl;
  886. return false;
  887. }
  888. return true;
  889. }
  890. static std::string readFile(const char* fileName)
  891. {
  892. kwsys::ifstream in(fileName, std::ios::binary);
  893. std::stringstream sstr;
  894. sstr << in.rdbuf();
  895. std::string data = sstr.str();
  896. if (!in) {
  897. std::cerr << "Failed to read file: " << fileName << std::endl;
  898. return std::string();
  899. }
  900. return data;
  901. }
  902. struct
  903. {
  904. const char* a;
  905. const char* b;
  906. bool differ;
  907. } diff_test_cases[] = { { "one", "one", false },
  908. { "one", "two", true },
  909. { "", "", false },
  910. { "\n", "\r\n", false },
  911. { "one\n", "one\n", false },
  912. { "one\r\n", "one\n", false },
  913. { "one\n", "one", false },
  914. { "one\ntwo", "one\ntwo", false },
  915. { "one\ntwo", "one\r\ntwo", false } };
  916. static bool CheckTextFilesDiffer()
  917. {
  918. const int num_test_cases =
  919. sizeof(diff_test_cases) / sizeof(diff_test_cases[0]);
  920. for (int i = 0; i < num_test_cases; ++i) {
  921. if (!writeFile("file_a", diff_test_cases[i].a) ||
  922. !writeFile("file_b", diff_test_cases[i].b)) {
  923. return false;
  924. }
  925. if (kwsys::SystemTools::TextFilesDiffer("file_a", "file_b") !=
  926. diff_test_cases[i].differ) {
  927. std::cerr << "Incorrect TextFilesDiffer result for test case " << i + 1
  928. << "." << std::endl;
  929. return false;
  930. }
  931. }
  932. return true;
  933. }
  934. static bool CheckCopyFileIfDifferent()
  935. {
  936. bool ret = true;
  937. const int num_test_cases =
  938. sizeof(diff_test_cases) / sizeof(diff_test_cases[0]);
  939. for (int i = 0; i < num_test_cases; ++i) {
  940. if (!writeFile("file_a", diff_test_cases[i].a) ||
  941. !writeFile("file_b", diff_test_cases[i].b)) {
  942. return false;
  943. }
  944. const char* cptarget =
  945. i < 4 ? TEST_SYSTEMTOOLS_BINARY_DIR "/file_b" : "file_b";
  946. if (!kwsys::SystemTools::CopyFileIfDifferent("file_a", cptarget)) {
  947. std::cerr << "CopyFileIfDifferent() returned false for test case "
  948. << i + 1 << "." << std::endl;
  949. ret = false;
  950. continue;
  951. }
  952. std::string bdata = readFile("file_b");
  953. if (diff_test_cases[i].a != bdata) {
  954. std::cerr << "Incorrect CopyFileIfDifferent file contents in test case "
  955. << i + 1 << "." << std::endl;
  956. ret = false;
  957. continue;
  958. }
  959. }
  960. if (!kwsys::SystemTools::MakeDirectory("dir_a") ||
  961. !kwsys::SystemTools::MakeDirectory("dir_b")) {
  962. return false;
  963. }
  964. if (!kwsys::SystemTools::CopyFileIfDifferent("dir_a/", "dir_b")) {
  965. ret = false;
  966. }
  967. return ret;
  968. }
  969. static bool CheckURLParsing()
  970. {
  971. bool ret = true;
  972. std::string url = "http://user:pw@hostname:42/full/url.com";
  973. std::string protocol, username, password, hostname, dataport, database;
  974. kwsys::SystemTools::ParseURL(url, protocol, username, password, hostname,
  975. dataport, database);
  976. if (protocol != "http" || username != "user" || password != "pw" ||
  977. hostname != "hostname" || dataport != "42" ||
  978. database != "full/url.com") {
  979. std::cerr << "Incorrect URL parsing" << std::endl;
  980. ret = false;
  981. }
  982. std::string uri =
  983. "file://hostname/path/to/"
  984. "a%20file%20with%20str%C3%A0ng%C3%A8%20ch%40r%20and%20s%C2%B5aces";
  985. kwsys::SystemTools::ParseURL(uri, protocol, username, password, hostname,
  986. dataport, database, true);
  987. if (protocol != "file" || hostname != "hostname" ||
  988. database != "path/to/a file with stràngè ch@r and sµaces") {
  989. std::cerr << "Incorrect URL parsing or decoding" << std::endl;
  990. ret = false;
  991. }
  992. return ret;
  993. }
  994. int testSystemTools(int, char* [])
  995. {
  996. bool res = true;
  997. int cc;
  998. for (cc = 0; toUnixPaths[cc][0]; cc++) {
  999. res &= CheckConvertToUnixSlashes(toUnixPaths[cc][0], toUnixPaths[cc][1]);
  1000. }
  1001. // Special check for ~
  1002. std::string output;
  1003. if (kwsys::SystemTools::GetEnv("HOME", output)) {
  1004. output += "/foo bar/lala";
  1005. res &= CheckConvertToUnixSlashes("~/foo bar/lala", output);
  1006. }
  1007. for (cc = 0; checkEscapeChars[cc][0]; cc++) {
  1008. res &= CheckEscapeChars(checkEscapeChars[cc][0], checkEscapeChars[cc][1],
  1009. *checkEscapeChars[cc][2], checkEscapeChars[cc][3]);
  1010. }
  1011. res &= CheckFileOperations();
  1012. res &= CheckStringOperations();
  1013. res &= CheckEnvironmentOperations();
  1014. res &= CheckRelativePaths();
  1015. res &= CheckCollapsePath();
  1016. res &= CheckGetPath();
  1017. res &= CheckFind();
  1018. res &= CheckIsSubDirectory();
  1019. res &= CheckGetLineFromStream();
  1020. res &= CheckGetLineFromStreamLongLine();
  1021. res &= CheckGetFilenameName();
  1022. res &= CheckTextFilesDiffer();
  1023. res &= CheckCopyFileIfDifferent();
  1024. res &= CheckURLParsing();
  1025. return res ? 0 : 1;
  1026. }