testSystemTools.cxx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=========================================================================
  2. Program: KWSys - Kitware System Library
  3. Module: $RCSfile$
  4. Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
  5. See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  8. PURPOSE. See the above copyright notices for more information.
  9. =========================================================================*/
  10. #include "kwsysPrivate.h"
  11. #if defined(_MSC_VER)
  12. # pragma warning (disable:4786)
  13. #endif
  14. #include KWSYS_HEADER(SystemTools.hxx)
  15. #include KWSYS_HEADER(ios/iostream)
  16. // Work-around CMake dependency scanning limitation. This must
  17. // duplicate the above list of headers.
  18. #if 0
  19. # include "SystemTools.hxx.in"
  20. # include "kwsys_ios_iostream.h.in"
  21. #endif
  22. const char* toUnixPaths[][2] =
  23. {
  24. { "/usr/local/bin/passwd", "/usr/local/bin/passwd" },
  25. { "/usr/lo cal/bin/pa sswd", "/usr/lo cal/bin/pa sswd" },
  26. { "/usr/lo\\ cal/bin/pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
  27. { "c:/usr/local/bin/passwd", "c:/usr/local/bin/passwd" },
  28. { "c:/usr/lo cal/bin/pa sswd", "c:/usr/lo cal/bin/pa sswd" },
  29. { "c:/usr/lo\\ cal/bin/pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
  30. { "\\usr\\local\\bin\\passwd", "/usr/local/bin/passwd" },
  31. { "\\usr\\lo cal\\bin\\pa sswd", "/usr/lo cal/bin/pa sswd" },
  32. { "\\usr\\lo\\ cal\\bin\\pa\\ sswd", "/usr/lo\\ cal/bin/pa\\ sswd" },
  33. { "c:\\usr\\local\\bin\\passwd", "c:/usr/local/bin/passwd" },
  34. { "c:\\usr\\lo cal\\bin\\pa sswd", "c:/usr/lo cal/bin/pa sswd" },
  35. { "c:\\usr\\lo\\ cal\\bin\\pa\\ sswd", "c:/usr/lo\\ cal/bin/pa\\ sswd" },
  36. { "\\\\usr\\local\\bin\\passwd", "//usr/local/bin/passwd" },
  37. { "\\\\usr\\lo cal\\bin\\pa sswd", "//usr/lo cal/bin/pa sswd" },
  38. { "\\\\usr\\lo\\ cal\\bin\\pa\\ sswd", "//usr/lo\\ cal/bin/pa\\ sswd" },
  39. {0, 0}
  40. };
  41. bool CheckConvertToUnixSlashes(kwsys_stl::string input, kwsys_stl::string output)
  42. {
  43. kwsys_stl::string result = input;
  44. kwsys::SystemTools::ConvertToUnixSlashes(result);
  45. if ( result != output )
  46. {
  47. kwsys_ios::cerr << "Problem with ConvertToUnixSlashes - input: " << input.c_str() << " output: " << result.c_str() << " expected: " << output.c_str() << kwsys_ios::endl;
  48. return false;
  49. }
  50. return true;
  51. }
  52. int main(/*int argc, char* argv*/)
  53. {
  54. int cc;
  55. for ( cc = 0; toUnixPaths[cc][0]; cc ++ )
  56. {
  57. CheckConvertToUnixSlashes(toUnixPaths[cc][0], toUnixPaths[cc][1]);
  58. }
  59. // Special check for ~
  60. kwsys_stl::string output;
  61. if(kwsys::SystemTools::GetEnv("HOME", output))
  62. {
  63. output += "/foo bar/lala";
  64. CheckConvertToUnixSlashes("~/foo bar/lala", output);
  65. }
  66. return 0;
  67. }