-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathvtkAddonTestingMacros.h
217 lines (190 loc) · 6.54 KB
/
vtkAddonTestingMacros.h
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*==============================================================================
Program: 3D Slicer
Copyright (c) Kitware Inc.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
and was partially funded by NIH grant 1U24CA194354-01
==============================================================================*/
#ifndef __vtkAddonTestingMacros_h
#define __vtkAddonTestingMacros_h
// vtkAddon includes
#include <vtkAddonTestingUtilities.h>
/// Convenience macros for unit tests.
///
/// The macro returns from the current method with EXIT_FAILURE if the check fails.
/// Expressions can be passed as arguments, they are guaranteed to be executed only once.
///
/// Example:
///
/// \code{.cpp}
/// int testedFunction(int a, int b) { return a+b; }
///
/// int MyTest1(int , char * [])
/// {
///
/// int current = 40 + 2;
/// int expected = 42;
/// CHECK_INT(current, expected);
///
/// CHECK_INT(testedFunction(40,2), 42);
/// CHECK_INT(testedFunction(35,5), 40);
///
/// return EXIT_SUCCESS;
/// }
///
/// \endcode
/// Verifies that pointer is nullptr
#define CHECK_NULL(pointer) \
{ \
const void* pointerValue = (pointer); \
if (!vtkAddonTestingUtilities::CheckNull(__LINE__,#pointer " is not NULL", pointerValue)) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies that pointer is not nullptr
#define CHECK_NOT_NULL(pointer) \
{ \
if (!vtkAddonTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies that pointer is nullptr,
/// if check fails then it calls methodToCallOnFailure before returning with failure
#define CHECK_NOT_NULL_ADD_REPORT(pointer, methodToCallOnFailure) \
{ \
if (!vtkAddonTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}
#define CHECK_EXIT_SUCCESS(actual) \
{ \
if (!vtkAddonTestingUtilities::CheckInt(__LINE__,#actual " != EXIT_SUCCESS", (actual), EXIT_SUCCESS)) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual double value is the same as expected
#define CHECK_DOUBLE(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::Check<double>(__LINE__,#actual " != " #expected, (actual), (expected), "CheckDouble")) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual double value is the same as expected, within the specified tolerance
#define CHECK_DOUBLE_TOLERANCE(actual, expected, tolerance) \
{ \
if (!vtkAddonTestingUtilities::CheckDoubleTolerance(__LINE__,#actual " != " #expected " (tolerance: " #tolerance ")", (actual), (expected), (tolerance))) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual int value is the same as expected
#define CHECK_INT(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual int value is the same as expected,
/// if check fails then it calls methodToCallOnFailure before returning with failure
#define CHECK_INT_ADD_REPORT(actual, expected, methodToCallOnFailure) \
{ \
if (!vtkAddonTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual pointer value is the same as expected
#define CHECK_POINTER(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckPointer(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual pointer value is the same as expected
#define CHECK_POINTER_DIFFERENT(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckPointer(__LINE__,#actual " == " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual bool value is the same as expected
#define CHECK_BOOL(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual)?1:0, (expected)?1:0)) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual const char* value is the same as expected.
/// It can handle nullptr pointer inputs.
#define CHECK_STRING(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual std::string value is the same as expected.
/// It is safe to use for comparing std::string values.
/// It cannot handle nullptr pointer inputs.
#define CHECK_STD_STRING(actual, expected) \
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!vtkAddonTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str())) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual const char* value is the same as expected,
/// if check fails then it calls methodToCallOnFailure before returning with failure
/// It can handle nullptr pointer inputs.
#define CHECK_STRING_ADD_REPORT(actual, expected, methodToCallOnFailure) \
{ \
if (!vtkAddonTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
{ \
methodToCallOnFailure; \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual const char* value is not the same as expected.
/// It can handle nullptr pointer inputs.
#define CHECK_STRING_DIFFERENT(actual, expected) \
{ \
if (!vtkAddonTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected), false)) \
{ \
return EXIT_FAILURE; \
} \
}
/// Verifies if actual std::string value is not the same as expected.
/// It is safe to use for comparing std::string values.
/// It cannot handle nullptr pointer inputs.
#define CHECK_STD_STRING_DIFFERENT(actual, expected) \
{ \
std::string a = (actual); \
std::string e = (expected); \
if (!vtkAddonTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str(), false)) \
{ \
return EXIT_FAILURE; \
} \
}
// Commonly used headers in tests
#include "vtkNew.h"
#include "vtkTestingOutputWindow.h"
#endif