summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testStatus.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-04-15 15:11:12 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-04-15 15:11:17 (GMT)
commit27b5dc35a67f28f46a2b91cf813cd6b34c5a21b8 (patch)
tree222a588e93b1eb85ca561706d72f9da28ca7e359 /Source/kwsys/testStatus.cxx
parentb65912006e5c0644329b838103226597af4fecef (diff)
parent3ef5dab010aef5ebab2022021989cb80718d00fc (diff)
downloadCMake-27b5dc35a67f28f46a2b91cf813cd6b34c5a21b8.zip
CMake-27b5dc35a67f28f46a2b91cf813cd6b34c5a21b8.tar.gz
CMake-27b5dc35a67f28f46a2b91cf813cd6b34c5a21b8.tar.bz2
Merge topic 'update-kwsys'
3ef5dab010 cmSystemTools: Simplify using KWSys Status ec1b6157cb Update CMake code using KWSys to account for Status return values eef585efaa Merge branch 'upstream-KWSys' into update-kwsys a790167101 KWSys 2021-04-14 (7ab1c601) Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Ben Boeckel <ben.boeckel@kitware.com> Merge-request: !6004
Diffstat (limited to 'Source/kwsys/testStatus.cxx')
-rw-r--r--Source/kwsys/testStatus.cxx117
1 files changed, 117 insertions, 0 deletions
diff --git a/Source/kwsys/testStatus.cxx b/Source/kwsys/testStatus.cxx
new file mode 100644
index 0000000..f85ef42
--- /dev/null
+++ b/Source/kwsys/testStatus.cxx
@@ -0,0 +1,117 @@
+/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
+#include "kwsysPrivate.h"
+#include KWSYS_HEADER(Status.hxx)
+
+// Work-around CMake dependency scanning limitation. This must
+// duplicate the above list of headers.
+#if 0
+# include "Status.hxx.in"
+#endif
+
+#include <cerrno>
+#include <iostream>
+
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
+int testStatus(int, char* [])
+{
+ bool res = true;
+ {
+ kwsys::Status status;
+ if (status.GetKind() != kwsys::Status::Kind::Success) {
+ std::cerr << "Status default constructor does not produce Success\n";
+ res = false;
+ }
+
+ status = kwsys::Status::Success();
+ if (status.GetKind() != kwsys::Status::Kind::Success) {
+ std::cerr << "Status Success constructor does not produce Success\n";
+ res = false;
+ }
+ if (!status) {
+ std::cerr << "Status Success kind is not true\n";
+ res = false;
+ }
+ if (status.GetPOSIX() != 0) {
+ std::cerr << "Status Success kind does not return POSIX 0\n";
+ res = false;
+ }
+#ifdef _WIN32
+ if (status.GetWindows() != 0) {
+ std::cerr << "Status Success kind does not return Windows 0\n";
+ res = false;
+ }
+#endif
+ if (status.GetString() != "Success") {
+ std::cerr << "Status Success kind does not return \"Success\" string\n";
+ res = false;
+ }
+
+ status = kwsys::Status::POSIX(EINVAL);
+ if (status.GetKind() != kwsys::Status::Kind::POSIX) {
+ std::cerr << "Status POSIX constructor does not produce POSIX\n";
+ res = false;
+ }
+ if (status) {
+ std::cerr << "Status POSIX kind is not false\n";
+ res = false;
+ }
+ if (status.GetPOSIX() != EINVAL) {
+ std::cerr << "Status POSIX kind does not preserve POSIX value\n";
+ res = false;
+ }
+#ifdef _WIN32
+ if (status.GetWindows() != 0) {
+ std::cerr << "Status POSIX kind does not return Windows 0\n";
+ res = false;
+ }
+#endif
+ if (status.GetString().empty()) {
+ std::cerr << "Status POSIX kind returns empty string\n";
+ res = false;
+ }
+ errno = ENOENT;
+ status = kwsys::Status::POSIX_errno();
+ if (status.GetPOSIX() != ENOENT) {
+ std::cerr << "Status POSIX_errno did not use errno\n";
+ res = false;
+ }
+ errno = 0;
+
+#ifdef _WIN32
+ status = kwsys::Status::Windows(ERROR_INVALID_PARAMETER);
+ if (status.GetKind() != kwsys::Status::Kind::Windows) {
+ std::cerr << "Status Windows constructor does not produce Windows\n";
+ res = false;
+ }
+ if (status) {
+ std::cerr << "Status Windows kind is not false\n";
+ res = false;
+ }
+ if (status.GetWindows() != ERROR_INVALID_PARAMETER) {
+ std::cerr << "Status Windows kind does not preserve Windows value\n";
+ res = false;
+ }
+ if (status.GetPOSIX() != 0) {
+ std::cerr << "Status Windows kind does not return POSIX 0\n";
+ res = false;
+ }
+ if (status.GetString().empty()) {
+ std::cerr << "Status Windows kind returns empty string\n";
+ res = false;
+ }
+
+ SetLastError(ERROR_FILE_NOT_FOUND);
+ status = kwsys::Status::Windows_GetLastError();
+ if (status.GetWindows() != ERROR_FILE_NOT_FOUND) {
+ std::cerr << "Status Windows_GetLastError did not use GetLastError()\n";
+ res = false;
+ }
+ SetLastError(ERROR_SUCCESS);
+#endif
+ }
+ return res ? 0 : 1;
+}