ctkCoreTestingMacrosTest.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. //----------------------------------------------------------------------------
  43. #define TestMacro(MACRO_NAME) \
  44. if (Test##MACRO_NAME##Success() != EXIT_SUCCESS) \
  45. { \
  46. return EXIT_FAILURE; \
  47. } \
  48. if (Test##MACRO_NAME##Failure() != EXIT_FAILURE) \
  49. { \
  50. return EXIT_FAILURE; \
  51. }
  52. //----------------------------------------------------------------------------
  53. int ctkCoreTestingMacrosTest(int , char * [])
  54. {
  55. TestMacro(CheckNull)
  56. TestMacro(CheckNotNull)
  57. TestMacro(CheckExitSuccess)
  58. TestMacro(CheckInt)
  59. TestMacro(CheckPointer)
  60. TestMacro(CheckPointerDifferent)
  61. TestMacro(CheckBool)
  62. TestMacro(CheckString)
  63. TestMacro(CheckStdString)
  64. TestMacro(CheckQString)
  65. TestMacro(CheckStdStringDifferent)
  66. TestMacro(CheckQStringDifferent)
  67. return EXIT_SUCCESS;
  68. }
  69. //----------------------------------------------------------------------------
  70. // Test CHECK_NULL
  71. //----------------------------------------------------------------------------
  72. int TestCheckNullSuccess()
  73. {
  74. void * nullPtr = 0;
  75. CHECK_NULL(nullPtr);
  76. return EXIT_SUCCESS;
  77. }
  78. //----------------------------------------------------------------------------
  79. int TestCheckNullFailure()
  80. {
  81. int integer = 42;
  82. void* notNullPtr = &integer;
  83. CHECK_NULL(notNullPtr);
  84. return EXIT_SUCCESS;
  85. }
  86. //----------------------------------------------------------------------------
  87. // Test CHECK_NOT_NULL
  88. //----------------------------------------------------------------------------
  89. int TestCheckNotNullSuccess()
  90. {
  91. int integer = 42;
  92. void* notNullPtr = &integer;
  93. CHECK_NOT_NULL(notNullPtr);
  94. return EXIT_SUCCESS;
  95. }
  96. //----------------------------------------------------------------------------
  97. int TestCheckNotNullFailure()
  98. {
  99. void * nullPtr = 0;
  100. CHECK_NOT_NULL(nullPtr);
  101. return EXIT_SUCCESS;
  102. }
  103. //----------------------------------------------------------------------------
  104. // Test CHECK_EXIT_SUCCESS
  105. //----------------------------------------------------------------------------
  106. int TestCheckExitSuccessSuccess()
  107. {
  108. int status = EXIT_SUCCESS;
  109. CHECK_EXIT_SUCCESS(status);
  110. return EXIT_SUCCESS;
  111. }
  112. //----------------------------------------------------------------------------
  113. int TestCheckExitSuccessFailure()
  114. {
  115. int status = EXIT_FAILURE;
  116. CHECK_EXIT_SUCCESS(status);
  117. return EXIT_SUCCESS;
  118. }
  119. //----------------------------------------------------------------------------
  120. // Test CHECK_INT
  121. //----------------------------------------------------------------------------
  122. int TestCheckIntSuccess()
  123. {
  124. CHECK_INT(4, 4);
  125. return EXIT_SUCCESS;
  126. }
  127. //----------------------------------------------------------------------------
  128. int TestCheckIntFailure()
  129. {
  130. CHECK_INT(4, 2);
  131. return EXIT_SUCCESS;
  132. }
  133. //----------------------------------------------------------------------------
  134. // Test CHECK_POINTER
  135. //----------------------------------------------------------------------------
  136. int TestCheckPointerSuccess()
  137. {
  138. int integer = 42;
  139. void* actual = &integer;
  140. void* expected = &integer;
  141. CHECK_POINTER(actual, expected);
  142. return EXIT_SUCCESS;
  143. }
  144. //----------------------------------------------------------------------------
  145. int TestCheckPointerFailure()
  146. {
  147. int integer = 42;
  148. void* actual = &integer;
  149. int integer2 = 42;
  150. void* expected = &integer2;
  151. CHECK_POINTER(actual, expected);
  152. return EXIT_SUCCESS;
  153. }
  154. //----------------------------------------------------------------------------
  155. // Test CHECK_POINTER_DIFFERENT
  156. //----------------------------------------------------------------------------
  157. int TestCheckPointerDifferentSuccess()
  158. {
  159. int integer = 42;
  160. void* actual = &integer;
  161. int integer2 = 42;
  162. void* expected = &integer2;
  163. CHECK_POINTER_DIFFERENT(actual, expected);
  164. return EXIT_SUCCESS;
  165. }
  166. //----------------------------------------------------------------------------
  167. int TestCheckPointerDifferentFailure()
  168. {
  169. int integer = 42;
  170. void* actual = &integer;
  171. void* expected = &integer;
  172. CHECK_POINTER_DIFFERENT(actual, expected);
  173. return EXIT_SUCCESS;
  174. }
  175. //----------------------------------------------------------------------------
  176. // Test CHECK_BOOL
  177. //----------------------------------------------------------------------------
  178. int TestCheckBoolSuccess()
  179. {
  180. CHECK_BOOL(true, true);
  181. return EXIT_SUCCESS;
  182. }
  183. //----------------------------------------------------------------------------
  184. int TestCheckBoolFailure()
  185. {
  186. CHECK_BOOL(true, false);
  187. return EXIT_SUCCESS;
  188. }
  189. //----------------------------------------------------------------------------
  190. // Test CHECK_STRING
  191. //----------------------------------------------------------------------------
  192. int TestCheckStringSuccess()
  193. {
  194. const char* actual = "string";
  195. const char* expected = "string";
  196. CHECK_STRING(actual, expected);
  197. return EXIT_SUCCESS;
  198. }
  199. //----------------------------------------------------------------------------
  200. int TestCheckStringFailure()
  201. {
  202. const char* actual = "string";
  203. const char* expected = "string2";
  204. CHECK_STRING(actual, expected);
  205. return EXIT_SUCCESS;
  206. }
  207. //----------------------------------------------------------------------------
  208. // Test CHECK_STD_STRING
  209. //----------------------------------------------------------------------------
  210. int TestCheckStdStringSuccess()
  211. {
  212. std::string actual = "string";
  213. std::string expected = "string";
  214. CHECK_STD_STRING(actual, expected);
  215. return EXIT_SUCCESS;
  216. }
  217. //----------------------------------------------------------------------------
  218. int TestCheckStdStringFailure()
  219. {
  220. std::string actual = "string";
  221. std::string expected = "string2";
  222. CHECK_STD_STRING(actual, expected);
  223. return EXIT_SUCCESS;
  224. }
  225. //----------------------------------------------------------------------------
  226. // Test CHECK_QSTRING
  227. //----------------------------------------------------------------------------
  228. int TestCheckQStringSuccess()
  229. {
  230. QString actual = "string";
  231. QString expected = "string";
  232. CHECK_QSTRING(actual, expected);
  233. return EXIT_SUCCESS;
  234. }
  235. //----------------------------------------------------------------------------
  236. int TestCheckQStringFailure()
  237. {
  238. QString actual = "string";
  239. QString expected = "string2";
  240. CHECK_QSTRING(actual, expected);
  241. return EXIT_SUCCESS;
  242. }
  243. //----------------------------------------------------------------------------
  244. // Test CHECK_STD_STRING_DIFFERENT
  245. //----------------------------------------------------------------------------
  246. int TestCheckStdStringDifferentSuccess()
  247. {
  248. std::string actual = "string";
  249. std::string expected = "string2";
  250. CHECK_STD_STRING_DIFFERENT(actual, expected);
  251. return EXIT_SUCCESS;
  252. }
  253. //----------------------------------------------------------------------------
  254. int TestCheckStdStringDifferentFailure()
  255. {
  256. std::string actual = "string";
  257. std::string expected = "string";
  258. CHECK_STD_STRING_DIFFERENT(actual, expected);
  259. return EXIT_SUCCESS;
  260. }
  261. //----------------------------------------------------------------------------
  262. // Test CHECK_QSTRING_DIFFERENT
  263. //----------------------------------------------------------------------------
  264. int TestCheckQStringDifferentSuccess()
  265. {
  266. QString actual = "string";
  267. QString expected = "string2";
  268. CHECK_QSTRING_DIFFERENT(actual, expected);
  269. return EXIT_SUCCESS;
  270. }
  271. //----------------------------------------------------------------------------
  272. int TestCheckQStringDifferentFailure()
  273. {
  274. QString actual = "string";
  275. QString expected = "string";
  276. CHECK_QSTRING_DIFFERENT(actual, expected);
  277. return EXIT_SUCCESS;
  278. }