blob: f85ef422dbf322347f9828b66fe620b00eb78fe9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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;
}
|