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