testStatus.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include KWSYS_HEADER(Status.hxx)
  5. // Work-around CMake dependency scanning limitation. This must
  6. // duplicate the above list of headers.
  7. #if 0
  8. # include "Status.hxx.in"
  9. #endif
  10. #include <cerrno>
  11. #include <iostream>
  12. #ifdef _WIN32
  13. # include <windows.h>
  14. #endif
  15. int testStatus(int, char* [])
  16. {
  17. bool res = true;
  18. {
  19. kwsys::Status status;
  20. if (status.GetKind() != kwsys::Status::Kind::Success) {
  21. std::cerr << "Status default constructor does not produce Success\n";
  22. res = false;
  23. }
  24. status = kwsys::Status::Success();
  25. if (status.GetKind() != kwsys::Status::Kind::Success) {
  26. std::cerr << "Status Success constructor does not produce Success\n";
  27. res = false;
  28. }
  29. if (!status) {
  30. std::cerr << "Status Success kind is not true\n";
  31. res = false;
  32. }
  33. if (status.GetPOSIX() != 0) {
  34. std::cerr << "Status Success kind does not return POSIX 0\n";
  35. res = false;
  36. }
  37. #ifdef _WIN32
  38. if (status.GetWindows() != 0) {
  39. std::cerr << "Status Success kind does not return Windows 0\n";
  40. res = false;
  41. }
  42. #endif
  43. if (status.GetString() != "Success") {
  44. std::cerr << "Status Success kind does not return \"Success\" string\n";
  45. res = false;
  46. }
  47. status = kwsys::Status::POSIX(EINVAL);
  48. if (status.GetKind() != kwsys::Status::Kind::POSIX) {
  49. std::cerr << "Status POSIX constructor does not produce POSIX\n";
  50. res = false;
  51. }
  52. if (status) {
  53. std::cerr << "Status POSIX kind is not false\n";
  54. res = false;
  55. }
  56. if (status.GetPOSIX() != EINVAL) {
  57. std::cerr << "Status POSIX kind does not preserve POSIX value\n";
  58. res = false;
  59. }
  60. #ifdef _WIN32
  61. if (status.GetWindows() != 0) {
  62. std::cerr << "Status POSIX kind does not return Windows 0\n";
  63. res = false;
  64. }
  65. #endif
  66. if (status.GetString().empty()) {
  67. std::cerr << "Status POSIX kind returns empty string\n";
  68. res = false;
  69. }
  70. errno = ENOENT;
  71. status = kwsys::Status::POSIX_errno();
  72. if (status.GetPOSIX() != ENOENT) {
  73. std::cerr << "Status POSIX_errno did not use errno\n";
  74. res = false;
  75. }
  76. errno = 0;
  77. #ifdef _WIN32
  78. status = kwsys::Status::Windows(ERROR_INVALID_PARAMETER);
  79. if (status.GetKind() != kwsys::Status::Kind::Windows) {
  80. std::cerr << "Status Windows constructor does not produce Windows\n";
  81. res = false;
  82. }
  83. if (status) {
  84. std::cerr << "Status Windows kind is not false\n";
  85. res = false;
  86. }
  87. if (status.GetWindows() != ERROR_INVALID_PARAMETER) {
  88. std::cerr << "Status Windows kind does not preserve Windows value\n";
  89. res = false;
  90. }
  91. if (status.GetPOSIX() != 0) {
  92. std::cerr << "Status Windows kind does not return POSIX 0\n";
  93. res = false;
  94. }
  95. if (status.GetString().empty()) {
  96. std::cerr << "Status Windows kind returns empty string\n";
  97. res = false;
  98. }
  99. SetLastError(ERROR_FILE_NOT_FOUND);
  100. status = kwsys::Status::Windows_GetLastError();
  101. if (status.GetWindows() != ERROR_FILE_NOT_FOUND) {
  102. std::cerr << "Status Windows_GetLastError did not use GetLastError()\n";
  103. res = false;
  104. }
  105. SetLastError(ERROR_SUCCESS);
  106. #endif
  107. }
  108. return res ? 0 : 1;
  109. }