testFindPackageCommand.cxx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmFindPackageCommand.h"
  11. #include <iostream>
  12. #include <string>
  13. #define cmPassed(m) std::cout << "Passed: " << (m) << "\n"
  14. #define cmFailed(m) \
  15. std::cout << "FAILED: " << (m) << "\n"; \
  16. failed = 1
  17. int testFindPackageCommand(int /*unused*/, char* /*unused*/ [])
  18. {
  19. int failed = 0;
  20. // ----------------------------------------------------------------------
  21. // Test cmFindPackage::Sort
  22. std::vector<std::string> testString;
  23. testString.push_back("lib-0.0");
  24. testString.push_back("lib-1.2");
  25. testString.push_back("lib-2.0");
  26. testString.push_back("lib-19.0.1");
  27. testString.push_back("lib-20.01.1");
  28. testString.push_back("lib-20.2.2a");
  29. cmFindPackageCommand::Sort(testString.begin(), testString.end(),
  30. cmFindPackageCommand::Natural,
  31. cmFindPackageCommand::Asc);
  32. if (!(testString[0] == "lib-0.0" && testString[1] == "lib-1.2" &&
  33. testString[2] == "lib-2.0" && testString[3] == "lib-19.0.1" &&
  34. testString[4] == "lib-20.01.1" && testString[5] == "lib-20.2.2a")) {
  35. cmFailed("cmSystemTools::Sort fail with Natural ASC");
  36. }
  37. cmFindPackageCommand::Sort(testString.begin(), testString.end(),
  38. cmFindPackageCommand::Natural,
  39. cmFindPackageCommand::Dec);
  40. if (!(testString[5] == "lib-0.0" && testString[4] == "lib-1.2" &&
  41. testString[3] == "lib-2.0" && testString[2] == "lib-19.0.1" &&
  42. testString[1] == "lib-20.01.1" && testString[0] == "lib-20.2.2a")) {
  43. cmFailed("cmSystemTools::Sort fail with Natural ASC");
  44. }
  45. cmFindPackageCommand::Sort(testString.begin(), testString.end(),
  46. cmFindPackageCommand::Name_order,
  47. cmFindPackageCommand::Dec);
  48. if (!(testString[5] == "lib-0.0" && testString[4] == "lib-1.2" &&
  49. testString[3] == "lib-19.0.1" && testString[2] == "lib-2.0" &&
  50. testString[1] == "lib-20.01.1" && testString[0] == "lib-20.2.2a")) {
  51. cmFailed("cmSystemTools::Sort fail with Name DEC");
  52. }
  53. cmFindPackageCommand::Sort(testString.begin(), testString.end(),
  54. cmFindPackageCommand::Name_order,
  55. cmFindPackageCommand::Asc);
  56. if (!(testString[0] == "lib-0.0" && testString[1] == "lib-1.2" &&
  57. testString[2] == "lib-19.0.1" && testString[3] == "lib-2.0" &&
  58. testString[4] == "lib-20.01.1" && testString[5] == "lib-20.2.2a")) {
  59. cmFailed("cmSystemTools::Sort fail with Natural ASC");
  60. }
  61. if (!failed) {
  62. cmPassed("cmSystemTools::Sort working");
  63. }
  64. return failed;
  65. }