CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkCoreTestingMacros.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkCoreTestingMacros_h
22 #define __ctkCoreTestingMacros_h
23 
25 
50 
52 #define CHECK_NULL(pointer) \
53  { \
54  const void* pointerValue = (pointer); \
55  if (!ctkCoreTestingUtilities::CheckNull(__LINE__,#pointer " is not NULL", pointerValue)) \
56  { \
57  return EXIT_FAILURE; \
58  } \
59  }
60 
62 #define CHECK_NOT_NULL(pointer) \
63  { \
64  if (!ctkCoreTestingUtilities::CheckNotNull(__LINE__,#pointer " is NULL", (pointer))) \
65  { \
66  return EXIT_FAILURE; \
67  } \
68  }
69 
70 #define CHECK_EXIT_SUCCESS(actual) \
71  { \
72  if (!ctkCoreTestingUtilities::CheckInt(__LINE__,#actual " != EXIT_SUCCESS", (actual), EXIT_SUCCESS)) \
73  { \
74  return EXIT_FAILURE; \
75  } \
76  }
77 
79 #define CHECK_INT(actual, expected) \
80  { \
81  if (!ctkCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual), (expected))) \
82  { \
83  return EXIT_FAILURE; \
84  } \
85  }
86 
88 #define CHECK_POINTER(actual, expected) \
89  { \
90  if (!ctkCoreTestingUtilities::CheckPointer(__LINE__,#actual " != " #expected, (actual), (expected))) \
91  { \
92  return EXIT_FAILURE; \
93  } \
94  }
95 
97 #define CHECK_POINTER_DIFFERENT(actual, expected) \
98  { \
99  if (!ctkCoreTestingUtilities::CheckPointer(__LINE__,#actual " == " #expected, (actual), (expected), false)) \
100  { \
101  return EXIT_FAILURE; \
102  } \
103  }
104 
106 #define CHECK_BOOL(actual, expected) \
107  { \
108  if (!ctkCoreTestingUtilities::CheckInt(__LINE__,#actual " != " #expected, (actual)?1:0, (expected)?1:0)) \
109  { \
110  return EXIT_FAILURE; \
111  } \
112  }
113 
116 #define CHECK_STRING(actual, expected) \
117  { \
118  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected))) \
119  { \
120  return EXIT_FAILURE; \
121  } \
122  }
123 
127 #define CHECK_STD_STRING(actual, expected) \
128  { \
129  std::string a = (actual); \
130  std::string e = (expected); \
131  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str())) \
132  { \
133  return EXIT_FAILURE; \
134  } \
135  }
136 
140 #define CHECK_QSTRING(actual, expected) \
141  { \
142  QString a = (actual); \
143  QString e = (expected); \
144  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, qPrintable(a), qPrintable(e))) \
145  { \
146  return EXIT_FAILURE; \
147  } \
148  }
149 
152 #define CHECK_STRING_DIFFERENT(actual, expected) \
153  { \
154  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, (actual), (expected), false)) \
155  { \
156  return EXIT_FAILURE; \
157  } \
158  }
159 
163 #define CHECK_STD_STRING_DIFFERENT(actual, expected) \
164  { \
165  std::string a = (actual); \
166  std::string e = (expected); \
167  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, a.c_str(), e.c_str(), false)) \
168  { \
169  return EXIT_FAILURE; \
170  } \
171  }
172 
176 #define CHECK_QSTRING_DIFFERENT(actual, expected) \
177  { \
178  QString a = (actual); \
179  QString e = (expected); \
180  if (!ctkCoreTestingUtilities::CheckString(__LINE__,#actual " != " #expected, qPrintable(a), qPrintable(e), false)) \
181  { \
182  return EXIT_FAILURE; \
183  } \
184  }
185 
187 #define CHECK_QSTRINGLIST(actual, expected) \
188  { \
189  QStringList a = (actual); \
190  QStringList e = (expected); \
191  if (!ctkCoreTestingUtilities::CheckStringList(__LINE__,#actual " != " #expected, a, e)) \
192  { \
193  return EXIT_FAILURE; \
194  } \
195  }
196 
198 #define CHECK_QVARIANT(actual, expected) \
199  { \
200  QVariant a = (actual); \
201  QVariant e = (expected); \
202  if (!ctkCoreTestingUtilities::CheckVariant(__LINE__,#actual " != " #expected, a, e)) \
203  { \
204  return EXIT_FAILURE; \
205  } \
206  }
207 
208 #endif
209