1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00
Files
CMake/testStatus.cxx
KWSys Upstream 4ac17cff42 KWSys 2023-01-19 (be3c441e)
Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit be3c441e46e091a7606565221bb5ae7c9a9b684f (master).

Upstream Shortlog
-----------------

Brad King (4):
      6c66ba9e clang-format.bash: Use generic clang-format attribute
      82ae3f28 clang-format.bash: update to clang-format-15
      a61d0ad6 Empty commit at end of history preceding clang-format-15 style transition
      3cb35bf3 CONTRIBUTING: Update documented clang-format version to 15

Kitware Robot (1):
      f685d817 Revise C++ coding style using clang-format-15

Sean McBride (1):
      d6c6fd82 testDirectory: Rename functions to fix -Wreserved-identifier warnings
2023-01-19 09:17:34 -05:00

130 lines
3.7 KiB
C++

/* 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.IsSuccess()) {
std::cerr << "Status Success gives false IsSuccess\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.IsSuccess()) {
std::cerr << "Status POSIX gives true IsSuccess\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.IsSuccess()) {
std::cerr << "Status Windows gives true IsSuccess\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;
}