ctkCoreTestingMacrosTest.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // CTK includes
  15. #include "ctkCoreTestingMacros.h"
  16. using namespace ctkCoreTestingUtilities;
  17. //----------------------------------------------------------------------------
  18. int TestCheckNullSuccess();
  19. int TestCheckNullFailure();
  20. int TestCheckNotNullSuccess();
  21. int TestCheckNotNullFailure();
  22. int TestCheckExitSuccessSuccess();
  23. int TestCheckExitSuccessFailure();
  24. int TestCheckIntSuccess();
  25. int TestCheckIntFailure();
  26. int TestCheckPointerSuccess();
  27. int TestCheckPointerFailure();
  28. int TestCheckPointerDifferentSuccess();
  29. int TestCheckPointerDifferentFailure();
  30. int TestCheckBoolSuccess();
  31. int TestCheckBoolFailure();
  32. int TestCheckStringSuccess();
  33. int TestCheckStringFailure();
  34. int TestCheckStdStringSuccess();
  35. int TestCheckStdStringFailure();
  36. int TestCheckQStringSuccess();
  37. int TestCheckQStringFailure();
  38. int TestCheckStdStringDifferentSuccess();
  39. int TestCheckStdStringDifferentFailure();
  40. int TestCheckQStringDifferentSuccess();
  41. int TestCheckQStringDifferentFailure();
  42. int TestCheckQStringListSuccess();
  43. int TestCheckQStringListFailure();
  44. int TestCheckQVariantSuccess();
  45. int TestCheckQVariantFailure();
  46. //----------------------------------------------------------------------------
  47. #define TestMacro(MACRO_NAME) \
  48. if (Test##MACRO_NAME##Success() != EXIT_SUCCESS) \
  49. { \
  50. return EXIT_FAILURE; \
  51. } \
  52. if (Test##MACRO_NAME##Failure() != EXIT_FAILURE) \
  53. { \
  54. return EXIT_FAILURE; \
  55. }
  56. //----------------------------------------------------------------------------
  57. int ctkCoreTestingMacrosTest(int , char * [])
  58. {
  59. TestMacro(CheckNull)
  60. TestMacro(CheckNotNull)
  61. TestMacro(CheckExitSuccess)
  62. TestMacro(CheckInt)
  63. TestMacro(CheckPointer)
  64. TestMacro(CheckPointerDifferent)
  65. TestMacro(CheckBool)
  66. TestMacro(CheckString)
  67. TestMacro(CheckStdString)
  68. TestMacro(CheckQString)
  69. TestMacro(CheckStdStringDifferent)
  70. TestMacro(CheckQStringDifferent)
  71. TestMacro(CheckQStringList)
  72. TestMacro(CheckQVariant)
  73. return EXIT_SUCCESS;
  74. }
  75. //----------------------------------------------------------------------------
  76. // Test CHECK_NULL
  77. //----------------------------------------------------------------------------
  78. int TestCheckNullSuccess()
  79. {
  80. void * nullPtr = 0;
  81. CHECK_NULL(nullPtr);
  82. return EXIT_SUCCESS;
  83. }
  84. //----------------------------------------------------------------------------
  85. int TestCheckNullFailure()
  86. {
  87. int integer = 42;
  88. void* notNullPtr = &integer;
  89. CHECK_NULL(notNullPtr);
  90. return EXIT_SUCCESS;
  91. }
  92. //----------------------------------------------------------------------------
  93. // Test CHECK_NOT_NULL
  94. //----------------------------------------------------------------------------
  95. int TestCheckNotNullSuccess()
  96. {
  97. int integer = 42;
  98. void* notNullPtr = &integer;
  99. CHECK_NOT_NULL(notNullPtr);
  100. return EXIT_SUCCESS;
  101. }
  102. //----------------------------------------------------------------------------
  103. int TestCheckNotNullFailure()
  104. {
  105. void * nullPtr = 0;
  106. CHECK_NOT_NULL(nullPtr);
  107. return EXIT_SUCCESS;
  108. }
  109. //----------------------------------------------------------------------------
  110. // Test CHECK_EXIT_SUCCESS
  111. //----------------------------------------------------------------------------
  112. int TestCheckExitSuccessSuccess()
  113. {
  114. int status = EXIT_SUCCESS;
  115. CHECK_EXIT_SUCCESS(status);
  116. return EXIT_SUCCESS;
  117. }
  118. //----------------------------------------------------------------------------
  119. int TestCheckExitSuccessFailure()
  120. {
  121. int status = EXIT_FAILURE;
  122. CHECK_EXIT_SUCCESS(status);
  123. return EXIT_SUCCESS;
  124. }
  125. //----------------------------------------------------------------------------
  126. // Test CHECK_INT
  127. //----------------------------------------------------------------------------
  128. int TestCheckIntSuccess()
  129. {
  130. CHECK_INT(4, 4);
  131. return EXIT_SUCCESS;
  132. }
  133. //----------------------------------------------------------------------------
  134. int TestCheckIntFailure()
  135. {
  136. CHECK_INT(4, 2);
  137. return EXIT_SUCCESS;
  138. }
  139. //----------------------------------------------------------------------------
  140. // Test CHECK_POINTER
  141. //----------------------------------------------------------------------------
  142. int TestCheckPointerSuccess()
  143. {
  144. int integer = 42;
  145. void* actual = &integer;
  146. void* expected = &integer;
  147. CHECK_POINTER(actual, expected);
  148. return EXIT_SUCCESS;
  149. }
  150. //----------------------------------------------------------------------------
  151. int TestCheckPointerFailure()
  152. {
  153. int integer = 42;
  154. void* actual = &integer;
  155. int integer2 = 42;
  156. void* expected = &integer2;
  157. CHECK_POINTER(actual, expected);
  158. return EXIT_SUCCESS;
  159. }
  160. //----------------------------------------------------------------------------
  161. // Test CHECK_POINTER_DIFFERENT
  162. //----------------------------------------------------------------------------
  163. int TestCheckPointerDifferentSuccess()
  164. {
  165. int integer = 42;
  166. void* actual = &integer;
  167. int integer2 = 42;
  168. void* expected = &integer2;
  169. CHECK_POINTER_DIFFERENT(actual, expected);
  170. return EXIT_SUCCESS;
  171. }
  172. //----------------------------------------------------------------------------
  173. int TestCheckPointerDifferentFailure()
  174. {
  175. int integer = 42;
  176. void* actual = &integer;
  177. void* expected = &integer;
  178. CHECK_POINTER_DIFFERENT(actual, expected);
  179. return EXIT_SUCCESS;
  180. }
  181. //----------------------------------------------------------------------------
  182. // Test CHECK_BOOL
  183. //----------------------------------------------------------------------------
  184. int TestCheckBoolSuccess()
  185. {
  186. CHECK_BOOL(true, true);
  187. return EXIT_SUCCESS;
  188. }
  189. //----------------------------------------------------------------------------
  190. int TestCheckBoolFailure()
  191. {
  192. CHECK_BOOL(true, false);
  193. return EXIT_SUCCESS;
  194. }
  195. //----------------------------------------------------------------------------
  196. // Test CHECK_STRING
  197. //----------------------------------------------------------------------------
  198. int TestCheckStringSuccess()
  199. {
  200. const char* actual = "string";
  201. const char* expected = "string";
  202. CHECK_STRING(actual, expected);
  203. return EXIT_SUCCESS;
  204. }
  205. //----------------------------------------------------------------------------
  206. int TestCheckStringFailure()
  207. {
  208. const char* actual = "string";
  209. const char* expected = "string2";
  210. CHECK_STRING(actual, expected);
  211. return EXIT_SUCCESS;
  212. }
  213. //----------------------------------------------------------------------------
  214. // Test CHECK_STD_STRING
  215. //----------------------------------------------------------------------------
  216. int TestCheckStdStringSuccess()
  217. {
  218. std::string actual = "string";
  219. std::string expected = "string";
  220. CHECK_STD_STRING(actual, expected);
  221. return EXIT_SUCCESS;
  222. }
  223. //----------------------------------------------------------------------------
  224. int TestCheckStdStringFailure()
  225. {
  226. std::string actual = "string";
  227. std::string expected = "string2";
  228. CHECK_STD_STRING(actual, expected);
  229. return EXIT_SUCCESS;
  230. }
  231. //----------------------------------------------------------------------------
  232. // Test CHECK_QSTRING
  233. //----------------------------------------------------------------------------
  234. int TestCheckQStringSuccess()
  235. {
  236. QString actual = "string";
  237. QString expected = "string";
  238. CHECK_QSTRING(actual, expected);
  239. return EXIT_SUCCESS;
  240. }
  241. //----------------------------------------------------------------------------
  242. int TestCheckQStringFailure()
  243. {
  244. QString actual = "string";
  245. QString expected = "string2";
  246. CHECK_QSTRING(actual, expected);
  247. return EXIT_SUCCESS;
  248. }
  249. //----------------------------------------------------------------------------
  250. // Test CHECK_STD_STRING_DIFFERENT
  251. //----------------------------------------------------------------------------
  252. int TestCheckStdStringDifferentSuccess()
  253. {
  254. std::string actual = "string";
  255. std::string expected = "string2";
  256. CHECK_STD_STRING_DIFFERENT(actual, expected);
  257. return EXIT_SUCCESS;
  258. }
  259. //----------------------------------------------------------------------------
  260. int TestCheckStdStringDifferentFailure()
  261. {
  262. std::string actual = "string";
  263. std::string expected = "string";
  264. CHECK_STD_STRING_DIFFERENT(actual, expected);
  265. return EXIT_SUCCESS;
  266. }
  267. //----------------------------------------------------------------------------
  268. // Test CHECK_QSTRING_DIFFERENT
  269. //----------------------------------------------------------------------------
  270. int TestCheckQStringDifferentSuccess()
  271. {
  272. QString actual = "string";
  273. QString expected = "string2";
  274. CHECK_QSTRING_DIFFERENT(actual, expected);
  275. return EXIT_SUCCESS;
  276. }
  277. //----------------------------------------------------------------------------
  278. int TestCheckQStringDifferentFailure()
  279. {
  280. QString actual = "string";
  281. QString expected = "string";
  282. CHECK_QSTRING_DIFFERENT(actual, expected);
  283. return EXIT_SUCCESS;
  284. }
  285. //----------------------------------------------------------------------------
  286. // Test CHECK_QSTRINGLIST
  287. //----------------------------------------------------------------------------
  288. int TestCheckQStringListSuccess()
  289. {
  290. QStringList actual = QStringList() << "a" << "b" << "c";
  291. QStringList expected = actual;
  292. CHECK_QSTRINGLIST(actual, expected);
  293. return EXIT_SUCCESS;
  294. }
  295. //----------------------------------------------------------------------------
  296. int TestCheckQStringListFailure()
  297. {
  298. QStringList actual = QStringList() << "a" << "b" << "c";
  299. QStringList expected = QStringList() << "a" << "x" << "c";
  300. CHECK_QSTRINGLIST(actual, expected);
  301. return EXIT_SUCCESS;
  302. }
  303. //----------------------------------------------------------------------------
  304. // Test CHECK_QVARIANT
  305. //----------------------------------------------------------------------------
  306. int TestCheckQVariantSuccess()
  307. {
  308. QVariant actual = QVariant(4);
  309. QVariant expected = actual;
  310. CHECK_QVARIANT(actual, expected);
  311. return EXIT_SUCCESS;
  312. }
  313. //----------------------------------------------------------------------------
  314. int TestCheckQVariantFailure()
  315. {
  316. QVariant actual = QVariant(4);
  317. QVariant expected = QVariant(2);
  318. CHECK_QVARIANT(actual, expected);
  319. return EXIT_SUCCESS;
  320. }