testStatus.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.IsSuccess()) {
  30. std::cerr << "Status Success gives false IsSuccess\n";
  31. res = false;
  32. }
  33. if (!status) {
  34. std::cerr << "Status Success kind is not true\n";
  35. res = false;
  36. }
  37. if (status.GetPOSIX() != 0) {
  38. std::cerr << "Status Success kind does not return POSIX 0\n";
  39. res = false;
  40. }
  41. #ifdef _WIN32
  42. if (status.GetWindows() != 0) {
  43. std::cerr << "Status Success kind does not return Windows 0\n";
  44. res = false;
  45. }
  46. #endif
  47. if (status.GetString() != "Success") {
  48. std::cerr << "Status Success kind does not return \"Success\" string\n";
  49. res = false;
  50. }
  51. status = kwsys::Status::POSIX(EINVAL);
  52. if (status.GetKind() != kwsys::Status::Kind::POSIX) {
  53. std::cerr << "Status POSIX constructor does not produce POSIX\n";
  54. res = false;
  55. }
  56. if (status.IsSuccess()) {
  57. std::cerr << "Status POSIX gives true IsSuccess\n";
  58. res = false;
  59. }
  60. if (status) {
  61. std::cerr << "Status POSIX kind is not false\n";
  62. res = false;
  63. }
  64. if (status.GetPOSIX() != EINVAL) {
  65. std::cerr << "Status POSIX kind does not preserve POSIX value\n";
  66. res = false;
  67. }
  68. #ifdef _WIN32
  69. if (status.GetWindows() != 0) {
  70. std::cerr << "Status POSIX kind does not return Windows 0\n";
  71. res = false;
  72. }
  73. #endif
  74. if (status.GetString().empty()) {
  75. std::cerr << "Status POSIX kind returns empty string\n";
  76. res = false;
  77. }
  78. errno = ENOENT;
  79. status = kwsys::Status::POSIX_errno();
  80. if (status.GetPOSIX() != ENOENT) {
  81. std::cerr << "Status POSIX_errno did not use errno\n";
  82. res = false;
  83. }
  84. errno = 0;
  85. #ifdef _WIN32
  86. status = kwsys::Status::Windows(ERROR_INVALID_PARAMETER);
  87. if (status.GetKind() != kwsys::Status::Kind::Windows) {
  88. std::cerr << "Status Windows constructor does not produce Windows\n";
  89. res = false;
  90. }
  91. if (status.IsSuccess()) {
  92. std::cerr << "Status Windows gives true IsSuccess\n";
  93. res = false;
  94. }
  95. if (status) {
  96. std::cerr << "Status Windows kind is not false\n";
  97. res = false;
  98. }
  99. if (status.GetWindows() != ERROR_INVALID_PARAMETER) {
  100. std::cerr << "Status Windows kind does not preserve Windows value\n";
  101. res = false;
  102. }
  103. if (status.GetPOSIX() != 0) {
  104. std::cerr << "Status Windows kind does not return POSIX 0\n";
  105. res = false;
  106. }
  107. if (status.GetString().empty()) {
  108. std::cerr << "Status Windows kind returns empty string\n";
  109. res = false;
  110. }
  111. SetLastError(ERROR_FILE_NOT_FOUND);
  112. status = kwsys::Status::Windows_GetLastError();
  113. if (status.GetWindows() != ERROR_FILE_NOT_FOUND) {
  114. std::cerr << "Status Windows_GetLastError did not use GetLastError()\n";
  115. res = false;
  116. }
  117. SetLastError(ERROR_SUCCESS);
  118. #endif
  119. }
  120. return res ? 0 : 1;
  121. }