You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3867 lines
145 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: xtests/xtests.h (formerly part of Synesis' internal test codebase)
  3. *
  4. * Purpose: Main header file for xTests, a simple unit/component-testing
  5. * library.
  6. *
  7. * Created: 20th June 1999
  8. * Updated: 6th July 2012
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 1999-2012, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file xtests/xtests.h
  42. *
  43. * [C, C++] Simple unit/component-testing library.
  44. */
  45. #ifndef XTESTS_INCL_XTESTS_H_XTESTS
  46. #define XTESTS_INCL_XTESTS_H_XTESTS
  47. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  48. # define XTESTS_VER_XTESTS_H_XTESTS_MAJOR 3
  49. # define XTESTS_VER_XTESTS_H_XTESTS_MINOR 31
  50. # define XTESTS_VER_XTESTS_H_XTESTS_REVISION 5
  51. # define XTESTS_VER_XTESTS_H_XTESTS_EDIT 308
  52. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Version information
  55. */
  56. /**
  57. * \def _XTESTS_VER_MAJOR
  58. * The Major version number of the xTests library
  59. *
  60. * \def _XTESTS_VER_MINOR
  61. * Minor version number of the xTests library
  62. *
  63. * \def _XTESTS_VER_REVISION
  64. * The revision number of the xTests library
  65. *
  66. * \def _XTESTS_VER
  67. * The composite version of the xTests library
  68. */
  69. #define _XTESTS_VER_MAJOR 0
  70. #define _XTESTS_VER_MINOR 16
  71. #define _XTESTS_VER_REVISION 6
  72. #define _XTESTS_VER 0x001006ff
  73. /* /////////////////////////////////////////////////////////////////////////
  74. * Includes - 1
  75. */
  76. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  77. # include <stlsoft/stlsoft.h>
  78. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  79. /* /////////////////////////////////////////////////////////////////////////
  80. * Compatibility
  81. */
  82. #if _STLSOFT_VER < 0x010973ff
  83. # error xTests requires version 1.9.115 (or later) of STLSoft; download from www.stlsoft.org
  84. #endif /* _STLSOFT_VER */
  85. #if defined(STLSOFT_COMPILER_IS_WATCOM)
  86. # define _XTESTS_NO_CPP_API
  87. #endif /* compiler */
  88. /* /////////////////////////////////////////////////////////////////////////
  89. * Includes - 2
  90. */
  91. #ifdef __cplusplus
  92. # include <platformstl/platformstl.h>
  93. # if defined(PLATFORMSTL_OS_IS_UNIX)
  94. /* We include threading.h to prevent the definition of _REENTRANT standard
  95. * headers on some UNIX operating systems from confusing the feature
  96. * discrimination in UNIXSTL and having it think that we're multithreading
  97. * when we're not.
  98. */
  99. # include <unixstl/synch/util/features.h>
  100. # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  101. # endif /* PLATFORMSTL_OS_IS_???? */
  102. # if !defined(_XTESTS_NO_CPP_API)
  103. # ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE
  104. # include <stlsoft/meta/is_integral_type.hpp>
  105. # endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE */
  106. # ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE
  107. # include <stlsoft/meta/is_same_type.hpp>
  108. # endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_SAME_TYPE */
  109. # ifndef STLSOFT_INCL_STLSOFT_META_HPP_SELECT_FIRST_TYPE_IF
  110. # include <stlsoft/meta/select_first_type_if.hpp>
  111. # endif /* !STLSOFT_INCL_STLSOFT_META_HPP_SELECT_FIRST_TYPE_IF */
  112. # ifdef STLSOFT_MINIMUM_SAS_INCLUDES
  113. # ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING
  114. # include <stlsoft/shims/access/string/std/c_string.h>
  115. # endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING */
  116. # else /* ? STLSOFT_MINIMUM_SAS_INCLUDES */
  117. # ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
  118. # include <stlsoft/shims/access/string.hpp>
  119. # endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING */
  120. # endif /* STLSOFT_MINIMUM_SAS_INCLUDES */
  121. # endif /* !_XTESTS_NO_CPP_API */
  122. # if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
  123. # include <new>
  124. # include <stdexcept>
  125. # endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  126. # if defined(STLSOFT_CF_RTTI_SUPPORT)
  127. # include <typeinfo>
  128. # endif /* STLSOFT_CF_RTTI_SUPPORT */
  129. # include <algorithm>
  130. #endif /* __cplusplus */
  131. #include <stdio.h>
  132. /* /////////////////////////////////////////////////////////////////////////
  133. * Namespace
  134. */
  135. #if defined(_STLSOFT_NO_NAMESPACE)
  136. # define _XTESTS_NO_NAMESPACE
  137. #endif /* _STLSOFT_NO_NAMESPACE */
  138. #ifndef _XTESTS_NO_NAMESPACE
  139. namespace xtests
  140. {
  141. namespace c
  142. {
  143. #endif /* !_XTESTS_NO_NAMESPACE */
  144. /* /////////////////////////////////////////////////////////////////////////
  145. * Features
  146. */
  147. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  148. # ifndef XTESTS_CALL
  149. # ifdef __cplusplus
  150. # define XTESTS_CALL(x) extern "C" x
  151. # else /* ? __cplusplus */
  152. # define XTESTS_CALL(x) extern x
  153. # endif /* __cplusplus */
  154. # endif /* !XTESTS_CALL */
  155. # ifdef STLSOFT_CF_FUNCTION_SYMBOL_SUPPORT
  156. # define XTESTS_GET_FUNCTION_() __FUNCTION__
  157. # else /* ? STLSOFT_CF_FUNCTION_SYMBOL_SUPPORT */
  158. # define XTESTS_GET_FUNCTION_() stlsoft_static_cast(char const*, 0)
  159. # endif /* STLSOFT_CF_FUNCTION_SYMBOL_SUPPORT */
  160. # ifndef _XTESTS_NO_NAMESPACE
  161. # define XTESTS_NS_QUAL(ns, sym) ns::sym
  162. # else /* ? _XTESTS_NO_NAMESPACE */
  163. # define XTESTS_NS_QUAL(ns, sym) sym
  164. # endif /* _XTESTS_NO_NAMESPACE */
  165. # define XTESTS_NS_C_QUAL(sym) XTESTS_NS_QUAL(xtests::c, sym)
  166. # define XTESTS_NS_CPP_QUAL(sym) XTESTS_NS_QUAL(xtests::c::cpp, sym)
  167. # if defined(STLSOFT_CF_RTTI_SUPPORT) && \
  168. ( !defined(STLSOFT_COMPILER_IS_MSVC) || \
  169. _MSC_VER >= 1310)
  170. # define XTESTS_REPORT_EXCEPTION_(x) XTESTS_NS_C_QUAL(xtests_caseExcepted)(typeid(x).name(), x.what())
  171. # else /* ? STLSOFT_CF_RTTI_SUPPORT */
  172. # define XTESTS_REPORT_EXCEPTION_(x) XTESTS_NS_C_QUAL(xtests_caseExcepted)("<exception-type unknown: rtti not available>", x.what())
  173. # endif /* STLSOFT_CF_RTTI_SUPPORT */
  174. # if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
  175. # if defined(STLSOFT_COMPILER_IS_GCC)
  176. /* GCC 4.2 on Mac has a strange defect whereby the thrown exception
  177. * doesn't get caught. When placed in a try-catch-throw, it works.
  178. * Smells like a code generation defect - particularly likely when
  179. * only some of the FF build configuration variants experience it -
  180. * and this workaround seems effective.
  181. */
  182. # define XTESTS_INVOKE_TEST_CASE_FN_INNER_(fn) do { try { (*fn)(); } catch(...) { throw; } } while(0)
  183. # else /* ? compiler */
  184. # define XTESTS_INVOKE_TEST_CASE_FN_INNER_(fn) (*fn)()
  185. # endif /* compiler */
  186. # define XTESTS_INVOKE_TEST_CASE_FN_(fn, name) \
  187. \
  188. do \
  189. { \
  190. try \
  191. { \
  192. XTESTS_INVOKE_TEST_CASE_FN_INNER_(fn); \
  193. } \
  194. catch(std::bad_alloc& x) \
  195. { \
  196. XTESTS_REPORT_EXCEPTION_(x); \
  197. \
  198. throw; \
  199. } \
  200. catch(XTESTS_NS_CPP_QUAL(requirement_failed_exception)& /* x */) \
  201. { \
  202. } \
  203. catch(std::exception& x) \
  204. { \
  205. XTESTS_REPORT_EXCEPTION_(x); \
  206. } \
  207. } while(0)
  208. # define XTESTS_INVOKE_TEST_CASE_FN_THROWS_(fn, name, type) \
  209. \
  210. do \
  211. { \
  212. try \
  213. { \
  214. XTESTS_INVOKE_TEST_CASE_FN_INNER_(fn); \
  215. \
  216. XTESTS_NS_C_QUAL(xtests_caseExceptionExpected)(#type); \
  217. } \
  218. catch(XTESTS_NS_CPP_QUAL(requirement_failed_exception)& /* x */) \
  219. { \
  220. } \
  221. catch(type& /* x */) \
  222. { \
  223. XTESTS_TEST_PASSED(); \
  224. } \
  225. catch(std::bad_alloc& x) \
  226. { \
  227. XTESTS_REPORT_EXCEPTION_(x); \
  228. \
  229. throw; \
  230. } \
  231. catch(std::exception& x) \
  232. { \
  233. XTESTS_REPORT_EXCEPTION_(x); \
  234. } \
  235. } while(0)
  236. # else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  237. # define XTESTS_INVOKE_TEST_CASE_FN_(fn, name) (*fn)()
  238. # endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  239. # if defined(STLSOFT_COMPILER_IS_DMC)
  240. # define XTESTS_INVOKE_c_str_data_a_(x) stlsoft_ns_qual(c_str_data_a)(x)
  241. # define XTESTS_INVOKE_c_str_data_w_(x) stlsoft_ns_qual(c_str_data_w)(x)
  242. # define XTESTS_INVOKE_c_str_len_a_(x) stlsoft_ns_qual(c_str_len_a)(x)
  243. # define XTESTS_INVOKE_c_str_len_w_(x) stlsoft_ns_qual(c_str_len_w)(x)
  244. # define XTESTS_INVOKE_c_str_ptr_a_(x) stlsoft_ns_qual(c_str_ptr_a)(x)
  245. # define XTESTS_INVOKE_c_str_ptr_w_(x) stlsoft_ns_qual(c_str_ptr_w)(x)
  246. # elif defined(STLSOFT_COMPILER_IS_GCC)
  247. # define XTESTS_INVOKE_c_str_data_a_(x) c_str_data_a(x)
  248. # define XTESTS_INVOKE_c_str_data_w_(x) c_str_data_w(x)
  249. # define XTESTS_INVOKE_c_str_len_a_(x) c_str_len_a(x)
  250. # define XTESTS_INVOKE_c_str_len_w_(x) c_str_len_w(x)
  251. # define XTESTS_INVOKE_c_str_ptr_a_(x) c_str_ptr_a(x)
  252. # define XTESTS_INVOKE_c_str_ptr_w_(x) c_str_ptr_w(x)
  253. # else /* ? compiler */
  254. # define XTESTS_INVOKE_c_str_data_a_(x) c_str_data_a(x)
  255. # define XTESTS_INVOKE_c_str_data_w_(x) c_str_data_w(x)
  256. # define XTESTS_INVOKE_c_str_len_a_(x) c_str_len_a(x)
  257. # define XTESTS_INVOKE_c_str_len_w_(x) c_str_len_w(x)
  258. # define XTESTS_INVOKE_c_str_ptr_a_(x) c_str_ptr_a(x)
  259. # define XTESTS_INVOKE_c_str_ptr_w_(x) c_str_ptr_w(x)
  260. # endif /* compiler */
  261. # if defined(STLSOFT_COMPILER_IS_MSVC) && \
  262. ( _MSC_VER >= 1500 || \
  263. ( _MSC_VER >= 1400 && \
  264. defined(_MSC_FULL_VER) && \
  265. _MSC_FULL_VER >= 140050320))
  266. # define XTESTS_DECLARE_DEPRECATION(symtype, oldfn, newfn) __declspec(deprecated("The " symtype " " STLSOFT_STRINGIZE(oldfn) " is deprecated and will be removed from a future version of xTests; use " STLSOFT_STRINGIZE(newfn) " instead"))
  267. # define XTESTS_CALL_DEPRECATED(rt, oldfn, newfn) XTESTS_DECLARE_DEPRECATION("function", oldfn, newfn) XTESTS_CALL(rt)
  268. # else /* ? compiler */
  269. # define XTESTS_DECLARE_DEPRECATION(symtype, oldfn, newfn)
  270. # define XTESTS_CALL_DEPRECATED(rt, oldfn, newfn) XTESTS_CALL(rt)
  271. # endif /* compiler */
  272. /* function pointer casts */
  273. # define XTESTS_VOID_FUNCTION_CAST_(f) stlsoft_c_cast( void(*)(void), f )
  274. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  275. /* /////////////////////////////////////////////////////////////////////////
  276. * Constants & definitions
  277. */
  278. /** Flags to be passed to xtests_startRunner
  279. *
  280. * \ingroup group__xtests__test_runner_functions
  281. *
  282. * \see XTESTS_START_RUNNER_WITH_FLAGS()
  283. * \see XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM()
  284. * \see XTESTS_START_RUNNER_WITH_REPORTER_AND_FLAGS()
  285. * \see XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS()
  286. * \see XTESTS_START_RUNNER_WITH_SETUP_FNS()
  287. * \see XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS_AND_SETUP_FNS()
  288. */
  289. enum xtests_runner_flags_t
  290. {
  291. xtestsRunnerFlagsNoWindowsDebugString = 0x0001
  292. , xtestsReportOnlyNonEmptyCases = 0x0002
  293. };
  294. #ifndef __cplusplus
  295. typedef enum xtests_runner_flags_t xtests_runner_flags_t;
  296. #endif /* !__cplusplus */
  297. /** \def XTESTS_FP_APPROXIMATE_FACTOR
  298. * The factor within which floating point numbers are deemed to be
  299. * approximately equal.
  300. */
  301. #define XTESTS_FP_APPROXIMATE_FACTOR (1.000001)
  302. /* /////////////////////////////////////////////////////////////////////////
  303. * Macros
  304. */
  305. /** \defgroup group__xtests__test_runner_functions Test Runner Functions
  306. *
  307. * Functions that are used to define, start, report on, and complete test
  308. * runners.
  309. */
  310. /** \defgroup group__xtests__test_case_functions Test Case Functions
  311. *
  312. * Functions that are used to define, start, and complete test cases.
  313. */
  314. /** \defgroup group__xtests__test_functions Test Functions
  315. *
  316. * Functions that are used to exercise tests.
  317. */
  318. /** \defgroup group__xtests__utiliy_functions Utility Functions
  319. *
  320. * Utility functions that supplement use of the library.
  321. */
  322. /** \def XTESTS_START_RUNNER(name, verbosity)
  323. *
  324. * \ingroup group__xtests__test_runner_functions
  325. *
  326. * Starts a test runner that will report to stdout
  327. *
  328. * A test runner is a logically-related group of test cases.
  329. *
  330. * \param name The name of the test-runner
  331. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  332. * runner will be executed
  333. */
  334. #define XTESTS_START_RUNNER(name, verbosity) \
  335. \
  336. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), NULL, NULL, NULL, 0, NULL, NULL, NULL))
  337. /** \def XTESTS_START_RUNNER_WITH_SETUP_FNS(name, verbosity, setup, teardown, setupParam)
  338. *
  339. * \ingroup group__xtests__test_runner_functions
  340. *
  341. * Starts a test runner that will report to stdout
  342. *
  343. * A test runner is a logically-related group of test cases.
  344. *
  345. * \param name The name of the test-runner
  346. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  347. * runner will be executed
  348. * \param setup The function to be called before each test
  349. * \param teardown The function to be called after each test
  350. * \param setupParam A caller-supplied parameter that is passed with
  351. * each invocation of the setup and teardown functions
  352. *
  353. * \see xTests_Setup_t
  354. * \see xTests_Teardown_t
  355. */
  356. #define XTESTS_START_RUNNER_WITH_SETUP_FNS(name, verbosity, setup, teardown, setupParam) \
  357. \
  358. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), NULL, NULL, NULL, 0, (setup), (teardown), (setupParam)))
  359. /** \def XTESTS_START_RUNNER_WITH_STREAM(name, verbosity, stm)
  360. *
  361. * \ingroup group__xtests__test_runner_functions
  362. *
  363. * Starts a test runner
  364. *
  365. * A test runner is a logically-related group of test cases.
  366. *
  367. * \param name The name of the test-runner
  368. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  369. * runner will be executed
  370. * \param stm The stream to which output will be written
  371. */
  372. #define XTESTS_START_RUNNER_WITH_STREAM(name, verbosity, stm) \
  373. \
  374. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), NULL, NULL, stm, 0, NULL, NULL, NULL))
  375. /** \def XTESTS_START_RUNNER_WITH_REPORTER(name, verbosity, reporter, reporterParam)
  376. *
  377. * \ingroup group__xtests__test_runner_functions
  378. *
  379. * Starts a test runner with the given callback reporter
  380. *
  381. * A test runner is a logically-related group of test cases.
  382. *
  383. * \param name The name of the test-runner
  384. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  385. * runner will be executed
  386. * \param reporter The reporter instance
  387. * \param reporterParam A caller-supplied parameter that is passed with
  388. * every callback
  389. */
  390. #define XTESTS_START_RUNNER_WITH_REPORTER(name, verbosity, reporter, reporterParam) \
  391. \
  392. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), (reporter), (reporterParam), NULL, 0, NULL, NULL, NULL))
  393. /** \def XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM(name, verbosity, reporter, reporterParam, stm)
  394. *
  395. * \ingroup group__xtests__test_runner_functions
  396. *
  397. * Starts a test runner with the given callback reporter
  398. *
  399. * A test runner is a logically-related group of test cases.
  400. *
  401. * \param name The name of the test-runner
  402. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  403. * runner will be executed
  404. * \param reporter The reporter instance
  405. * \param reporterParam A caller-supplied parameter that is passed with
  406. * every callback
  407. * \param stm The stream to which output will be written
  408. */
  409. #define XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM(name, verbosity, reporter, reporterParam, stm) \
  410. \
  411. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), (reporter), (reporterParam), stm, 0, NULL, NULL, NULL))
  412. /** \def XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS(name, verbosity, reporter, reporterParam, stm, flags)
  413. *
  414. * \ingroup group__xtests__test_runner_functions
  415. *
  416. * Starts a test runner with the given callback reporter
  417. *
  418. * A test runner is a logically-related group of test cases.
  419. *
  420. * \param name The name of the test-runner
  421. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  422. * runner will be executed
  423. * \param reporter The reporter instance
  424. * \param reporterParam A caller-supplied parameter that is passed with
  425. * every callback
  426. * \param stm The stream to which output will be written
  427. * \param flags The \link xtests::c::xtests_runner_flags_t flags\endlink
  428. * that moderate the runner behaviour
  429. */
  430. #define XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS(name, verbosity, reporter, reporterParam, stm, flags) \
  431. \
  432. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), (reporter), (reporterParam), (stm), (flags), NULL, NULL, NULL))
  433. /** \def XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS_AND_SETUP_FNS(name, verbosity, reporter, reporterParam, stm, flags, setup, teardown, setupParam)
  434. *
  435. * \ingroup group__xtests__test_runner_functions
  436. *
  437. * Starts a test runner with the given callback reporter
  438. *
  439. * A test runner is a logically-related group of test cases.
  440. *
  441. * \param name The name of the test-runner
  442. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  443. * runner will be executed
  444. * \param reporter The reporter instance
  445. * \param reporterParam A caller-supplied parameter that is passed with
  446. * every invocation of the reporter
  447. * \param stm The stream to which output will be written
  448. * \param flags The \link xtests::c::xtests_runner_flags_t flags\endlink
  449. * that moderate the runner behaviour
  450. * \param setup The function to be called before each test
  451. * \param teardown The function to be called after each test
  452. * \param setupParam A caller-supplied parameter that is passed with
  453. * each invocation of the setup and teardown functions
  454. */
  455. #define XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS_AND_SETUP_FNS(name, verbosity, reporter, reporterParam, stm, flags, setup, teardown, setupParam) \
  456. \
  457. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), (reporter), (reporterParam), (stm), (flags), (setup), (teardown), (setupParam)))
  458. /** \def XTESTS_START_RUNNER_WITH_FLAGS(name, verbosity, flags)
  459. *
  460. * \ingroup group__xtests__test_runner_functions
  461. *
  462. * Starts a test runner that will report to stdout
  463. *
  464. * A test runner is a logically-related group of test cases.
  465. *
  466. * \param name The name of the test-runner
  467. * \param verbosity The verbosity (see xtests_verbosity_t) at which the
  468. * runner will be executed
  469. * \param flags The \link xtests::c::xtests_runner_flags_t flags\endlink
  470. * that moderate the runner behaviour
  471. */
  472. #define XTESTS_START_RUNNER_WITH_FLAGS(name, verbosity, flags) \
  473. \
  474. (0 == XTESTS_NS_C_QUAL(xtests_startRunner)((name), (verbosity), NULL, NULL, NULL, (flags), NULL, NULL, NULL))
  475. /** \def XTESTS_PRINT_RESULTS()
  476. *
  477. * \ingroup group__xtests__test_runner_functions
  478. *
  479. * Prints the test results of the currently executing test.
  480. *
  481. * \note This can only be invoked after a successful invocation of
  482. * XTESTS_START_RUNNER() or XTESTS_START_RUNNER_WITH_REPORTER(), and
  483. * before invocation of XTESTS_END_RUNNER() or
  484. * XTESTS_END_RUNNER_UPDATE_EXITCODE().
  485. */
  486. #define XTESTS_PRINT_RESULTS() \
  487. \
  488. XTESTS_NS_C_QUAL(xtests_printRunnerResults)()
  489. /** \def XTESTS_END_RUNNER()
  490. *
  491. * \ingroup group__xtests__test_runner_functions
  492. *
  493. * Ends a test runner
  494. */
  495. #define XTESTS_END_RUNNER() \
  496. \
  497. XTESTS_NS_C_QUAL(xtests_endRunner)(NULL)
  498. /** \def XTESTS_ABEND(terminationMessage)
  499. *
  500. * \ingroup group__xtests__test_runner_functions
  501. *
  502. * Abnormal end of tests, and process termination
  503. */
  504. #define XTESTS_ABEND(terminationMessage) \
  505. \
  506. XTESTS_NS_C_QUAL(xtests_abend)(terminationMessage)
  507. /** \def XTESTS_END_RUNNER_UPDATE_EXITCODE()
  508. *
  509. * \ingroup group__xtests__test_runner_functions
  510. *
  511. * Ends a test runner, and modifies a caller-supplied exit code parameter
  512. *
  513. * \param retCode A pointer to a variable of type <code>int</code> that will
  514. * receive an exit code.
  515. *
  516. * \remarks The variable should have been initialised to
  517. * <code>EXIT_SUCCESS</code>, and each invocation of
  518. * XTESTS_END_RUNNER_UPDATE_EXITCODE() (for each separate test-runner
  519. * in a given application) will only set it to <code>EXIT_FAILURE</code>
  520. * in the case where that runner has failed one or more tests.
  521. */
  522. #define XTESTS_END_RUNNER_UPDATE_EXITCODE(retCode) \
  523. \
  524. stlsoft_static_cast(void, XTESTS_NS_C_QUAL(xtests_endRunner)(retCode))
  525. /** \def XTESTS_CASE_BEGIN(name, desc)
  526. *
  527. * \ingroup group__xtests__test_case_functions
  528. *
  529. * Begins a test case, of the given name and description
  530. *
  531. * \param name The name of the test case
  532. * \param desc The description of the test case. May be <code>NULL</code>
  533. * or the empty string (<code>""</code>).
  534. */
  535. #define XTESTS_CASE_BEGIN(name, desc) \
  536. \
  537. (0 == XTESTS_NS_C_QUAL(xtests_beginTestCase)((name), (desc)))
  538. /** \def XTESTS_CASE_END(name, desc)
  539. *
  540. * \ingroup group__xtests__test_case_functions
  541. *
  542. * Ends the current test case
  543. *
  544. * \param name The name of the test case
  545. *
  546. * \note The <code>name</code> parameter is ignored in the current
  547. * implementation, which can only run one test case at a time.
  548. */
  549. #define XTESTS_CASE_END(name) \
  550. \
  551. stlsoft_static_cast(void, XTESTS_NS_C_QUAL(xtests_endTestCase)((name)))
  552. /** \def XTESTS_RUN_CASE_WITH_NAME_AND_DESC(name, desc, fn)
  553. *
  554. * \ingroup group__xtests__test_case_functions
  555. *
  556. * Runs the given test case function, specifying a name and description
  557. *
  558. * \param name Name of the test case
  559. * \param desc Description of the test case
  560. * \param fn A function, taking no parameters and returning
  561. * <code>void</code>, that executes a number of tests representing a test
  562. * case.
  563. *
  564. * \note This can only be invoked after a successful invocation of
  565. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  566. */
  567. #define XTESTS_RUN_CASE_WITH_NAME_AND_DESC(name, desc, fn) \
  568. \
  569. do \
  570. { \
  571. if(XTESTS_CASE_BEGIN(name, desc)) \
  572. { \
  573. XTESTS_INVOKE_TEST_CASE_FN_(fn, name); \
  574. \
  575. XTESTS_CASE_END(name); \
  576. } \
  577. \
  578. } while(0)
  579. /** \def XTESTS_RUN_CASE_WITH_DESC(fn, desc)
  580. *
  581. * \ingroup group__xtests__test_case_functions
  582. *
  583. * Runs the given test case function, specifying a description
  584. *
  585. * \param fn A function, taking no parameters and returning
  586. * <code>void</code>, that executes a number of tests representing a test
  587. * case.
  588. * \param desc Description of the test case
  589. *
  590. * \note This can only be invoked after a successful invocation of
  591. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  592. */
  593. #define XTESTS_RUN_CASE_WITH_DESC(fn, desc) \
  594. \
  595. XTESTS_RUN_CASE_WITH_NAME_AND_DESC(#fn, desc, fn)
  596. \
  597. /** \def XTESTS_RUN_CASE(fn)
  598. *
  599. * \ingroup group__xtests__test_case_functions
  600. *
  601. * Runs the given test case function
  602. *
  603. * \param fn A function, taking no parameters and returning
  604. * <code>void</code>, that executes a number of tests representing a test
  605. * case.
  606. *
  607. * \note This can only be invoked after a successful invocation of
  608. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  609. */
  610. #define XTESTS_RUN_CASE(fn) \
  611. \
  612. XTESTS_RUN_CASE_WITH_DESC(fn, "")
  613. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  614. /** \def XTESTS_RUN_CASE_THAT_THROWS_WITH_NAME_AND_DESC(name, desc, fn, type)
  615. *
  616. * \ingroup group__xtests__test_case_functions
  617. *
  618. * Runs the given test case function, specifying a name and description, and
  619. * the type of an exception that is expected
  620. *
  621. * \param name Name of the test case
  622. * \param desc Description of the test case
  623. * \param fn A function, taking no parameters and returning
  624. * <code>void</code>, that executes a number of tests representing a test
  625. * case.
  626. * \param type The type of the exception that is expected to be thrown
  627. *
  628. * \note This can only be invoked after a successful invocation of
  629. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  630. */
  631. # define XTESTS_RUN_CASE_THAT_THROWS_WITH_NAME_AND_DESC(name, desc, fn, type) \
  632. \
  633. do \
  634. { \
  635. if(XTESTS_CASE_BEGIN(name, desc)) \
  636. { \
  637. XTESTS_INVOKE_TEST_CASE_FN_THROWS_(fn, name, type); \
  638. \
  639. XTESTS_CASE_END(name); \
  640. } \
  641. \
  642. } while(0)
  643. /** \def XTESTS_RUN_CASE_THAT_THROWS_WITH_DESC(fn, desc, type)
  644. *
  645. * \ingroup group__xtests__test_case_functions
  646. *
  647. * Runs the given test case function, specifying a description, and
  648. * the type of an exception that is expected
  649. *
  650. * \param fn A function, taking no parameters and returning
  651. * <code>void</code>, that executes a number of tests representing a test
  652. * case.
  653. * \param desc Description of the test case
  654. * \param type The type of the exception that is expected to be thrown
  655. *
  656. * \note This can only be invoked after a successful invocation of
  657. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  658. */
  659. # define XTESTS_RUN_CASE_THAT_THROWS_WITH_DESC(fn, desc, type) \
  660. \
  661. XTESTS_RUN_CASE_THAT_THROWS_WITH_NAME_AND_DESC(#fn, desc, fn, type)
  662. /** \def XTESTS_RUN_CASE_THAT_THROWS(fn, type)
  663. *
  664. * \ingroup group__xtests__test_case_functions
  665. *
  666. * Runs the given test case function, specifying the type of an exception
  667. * that is expected
  668. *
  669. * \param fn A function, taking no parameters and returning
  670. * <code>void</code>, that executes a number of tests representing a test
  671. * case.
  672. * \param type The type of the exception that is expected to be thrown
  673. *
  674. * \note This can only be invoked after a successful invocation of
  675. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  676. */
  677. # define XTESTS_RUN_CASE_THAT_THROWS(fn, type) \
  678. \
  679. XTESTS_RUN_CASE_THAT_THROWS_WITH_NAME_AND_DESC(#fn, "", fn, type)
  680. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  681. /** \def XTESTS_TEST_FAIL_WITH_QUALIFIER(msg, qualifier)
  682. *
  683. * \ingroup group__xtests__test_functions
  684. *
  685. * Causes a test failure to be expressed, passing an explanatory message and
  686. * a message qualifier.
  687. *
  688. * \param msg The message explaining the failure condition
  689. * \param qualifier The message qualifier.
  690. *
  691. * \note This can only be invoked after a successful invocation of
  692. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  693. */
  694. #define XTESTS_TEST_FAIL_WITH_QUALIFIER(msg, qualifier) \
  695. \
  696. XTESTS_NS_C_QUAL(xtests_writeFailMessage)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), msg, qualifier)
  697. /** \def XTESTS_TEST_FAIL(msg)
  698. *
  699. * \ingroup group__xtests__test_functions
  700. *
  701. * Causes a test failure to be expressed, passing an explanatory message.
  702. *
  703. * \param msg The message explaining the failure condition
  704. *
  705. * \note This can only be invoked after a successful invocation of
  706. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  707. */
  708. #define XTESTS_TEST_FAIL(msg) \
  709. \
  710. XTESTS_TEST_FAIL_WITH_QUALIFIER(msg, stlsoft_static_cast(char const*, NULL))
  711. /** \def XTESTS_TEST_PASSED()
  712. *
  713. * \ingroup group__xtests__test_functions
  714. *
  715. * Causes a test success to be expressed.
  716. *
  717. * \note This can only be invoked after a successful invocation of
  718. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  719. */
  720. #define XTESTS_TEST_PASSED() \
  721. \
  722. XTESTS_NS_C_QUAL(xtests_testPassed)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "")
  723. /** \def XTESTS_TEST_WITH_MESSAGE(expr, msg)
  724. *
  725. * \ingroup group__xtests__test_functions
  726. *
  727. * Causes a test to be exercised, passing an explanatory message to be used
  728. * in the case of failure.
  729. *
  730. * \param expr The expression whose truth is to be evaluated
  731. * \param msg The message explaining the failure condition
  732. *
  733. * \note This can only be invoked after a successful invocation of
  734. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  735. */
  736. #define XTESTS_TEST_WITH_MESSAGE(expr, msg) \
  737. \
  738. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  739. ((expr) \
  740. ? XTESTS_NS_C_QUAL(xtests_testPassed)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), msg) \
  741. : XTESTS_NS_C_QUAL(xtests_testFailed)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), msg)))
  742. /** \def XTESTS_TEST(expr)
  743. *
  744. * \ingroup group__xtests__test_functions
  745. *
  746. * Causes a test to be exercised.
  747. *
  748. * \param expr The expression whose truth is to be evaluated
  749. *
  750. * \note This can only be invoked after a successful invocation of
  751. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  752. */
  753. #define XTESTS_TEST(expr) \
  754. \
  755. XTESTS_TEST_WITH_MESSAGE(expr, #expr)
  756. /* /////////////////////////////////////////////////////////
  757. * Test enumerations
  758. */
  759. /** \def XTESTS_TEST_ENUM_EQUAL(expected, actual)
  760. *
  761. * \ingroup group__xtests__test_functions
  762. *
  763. * Tests that two enumerator values are exactly equal.
  764. *
  765. * \param expected The expected enumerator value
  766. * \param actual The actual enumerator value
  767. *
  768. * \remarks The enumerators should be of the same type
  769. *
  770. * \note This can only be invoked after a successful invocation of
  771. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  772. */
  773. #define XTESTS_TEST_ENUM_EQUAL(expected, actual) XTESTS_TEST_INTEGER_EQUAL_EXACT(stlsoft_static_cast(int, (expected)), stlsoft_static_cast(int, (actual)))
  774. /** \def XTESTS_TEST_ENUM_NOT_EQUAL(expected, actual)
  775. *
  776. * \ingroup group__xtests__test_functions
  777. *
  778. * Tests that two enumerator values are not equal.
  779. *
  780. * \param expected The expected enumerator value
  781. * \param actual The actual enumerator value
  782. *
  783. * \remarks The enumerators should be of the same type
  784. *
  785. * \note This can only be invoked after a successful invocation of
  786. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  787. */
  788. #define XTESTS_TEST_ENUM_NOT_EQUAL(expected, actual) XTESTS_TEST_INTEGER_NOT_EQUAL(stlsoft_static_cast(int, (expected)), stlsoft_static_cast(int, (actual)))
  789. /* /////////////////////////////////////////////////////////
  790. * Test integers
  791. */
  792. #if defined(__cplusplus) && \
  793. !defined(_XTESTS_NO_CPP_API)
  794. /** \def XTESTS_TEST_INTEGER_EQUAL_EXACT(expected, actual)
  795. *
  796. * \ingroup group__xtests__test_functions
  797. *
  798. * Tests that two integer values are exactly equal.
  799. *
  800. * \param expected The expected integer value
  801. * \param actual The actual integer value
  802. *
  803. * \remarks The integers should be of the same type
  804. *
  805. * \note This can only be invoked after a successful invocation of
  806. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  807. */
  808. # define XTESTS_TEST_INTEGER_EQUAL_EXACT(expected, actual) \
  809. \
  810. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  811. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  812. /** \def XTESTS_TEST_INTEGER_NOT_EQUAL(expected, actual)
  813. *
  814. * \ingroup group__xtests__test_functions
  815. *
  816. * Tests that two integer values are not equal.
  817. *
  818. * \param expected The expected integer value
  819. * \param actual The actual integer value
  820. *
  821. * \remarks The integers should be of the same type
  822. *
  823. * \note This can only be invoked after a successful invocation of
  824. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  825. */
  826. # define XTESTS_TEST_INTEGER_NOT_EQUAL(expected, actual) \
  827. \
  828. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  829. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual))))
  830. /** \def XTESTS_TEST_INTEGER_GREATER(expected, actual)
  831. *
  832. * \ingroup group__xtests__test_functions
  833. *
  834. * Tests that the actual integer value is greater than the expected value.
  835. *
  836. * \param expected The expected integer value
  837. * \param actual The actual integer value
  838. *
  839. * \note This can only be invoked after a successful invocation of
  840. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  841. */
  842. # define XTESTS_TEST_INTEGER_GREATER(expected, actual) \
  843. \
  844. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  845. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThan))))
  846. /** \def XTESTS_TEST_INTEGER_LESS(expected, actual)
  847. *
  848. * \ingroup group__xtests__test_functions
  849. *
  850. * Tests that the actual integer value is less than the expected value.
  851. *
  852. * \param expected The expected integer value
  853. * \param actual The actual integer value
  854. *
  855. * \note This can only be invoked after a successful invocation of
  856. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  857. */
  858. # define XTESTS_TEST_INTEGER_LESS(expected, actual) \
  859. \
  860. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  861. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThan))))
  862. /** \def XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(expected, actual)
  863. *
  864. * \ingroup group__xtests__test_functions
  865. *
  866. * Tests that the actual integer value is greater than or equal to the
  867. * expected value.
  868. *
  869. * \param expected The expected integer value
  870. * \param actual The actual integer value
  871. *
  872. * \note This can only be invoked after a successful invocation of
  873. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  874. */
  875. # define XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(expected, actual) \
  876. \
  877. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  878. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThanOrEqual))))
  879. /** \def XTESTS_TEST_INTEGER_LESS_OR_EQUAL(expected, actual)
  880. *
  881. * \ingroup group__xtests__test_functions
  882. *
  883. * Tests that the actual integer value is less than or equal to the expected
  884. * value.
  885. *
  886. * \param expected The expected integer value
  887. * \param actual The actual integer value
  888. *
  889. * \note This can only be invoked after a successful invocation of
  890. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  891. */
  892. # define XTESTS_TEST_INTEGER_LESS_OR_EQUAL(expected, actual) \
  893. \
  894. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  895. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThanOrEqual))))
  896. /** \def XTESTS_TEST_INTEGER_EQUAL_ANY_IN_RANGE(begin, end, actual)
  897. *
  898. * \ingroup group__xtests__test_functions
  899. *
  900. * Tests that a given integer value matches any of the elements in a
  901. * given range.
  902. *
  903. * \param begin Start iterator of the match range
  904. * \param end End iterator of the match range
  905. * \param actual The actual integer value
  906. *
  907. * \remarks The value type of the iterators should be the same as the
  908. * type of the tested value
  909. *
  910. * \note This can only be invoked after a successful invocation of
  911. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  912. */
  913. # define XTESTS_TEST_INTEGER_EQUAL_ANY_IN_RANGE(begin, end, actual) \
  914. \
  915. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  916. XTESTS_NS_CPP_QUAL(xtests_test_integer_any_in_range(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "XTESTS_TEST_INTEGER_EQUAL_ANY_IN_RANGE(" ## #begin ## ", " ## #end ## ", " ## #actual ## ")", (begin), (end), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  917. /** \def XTESTS_TEST_INTEGER_EQUAL_ANY_NOT_IN_RANGE(begin, end, actual)
  918. *
  919. * \ingroup group__xtests__test_functions
  920. *
  921. * Tests that a given integer value matches none of the elements in a
  922. * given range.
  923. *
  924. * \param begin Start iterator of the match range
  925. * \param end End iterator of the match range
  926. * \param actual The actual integer value
  927. *
  928. * \remarks The value type of the iterators should be the same as the
  929. * type of the tested value
  930. *
  931. * \note This can only be invoked after a successful invocation of
  932. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  933. */
  934. # define XTESTS_TEST_INTEGER_EQUAL_ANY_NOT_IN_RANGE(begin, end, actual) \
  935. \
  936. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  937. XTESTS_NS_CPP_QUAL(xtests_test_integer_any_in_range(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "XTESTS_TEST_INTEGER_EQUAL_ANY_IN_RANGE(" ## #begin ## ", " ## #end ## ", " ## #actual ## ")", (begin), (end), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual))))
  938. #if 0
  939. /** \def XTESTS_TEST_INTEGER_EQUAL_ANY_OF(expected, actual)
  940. *
  941. * \ingroup group__xtests__test_functions
  942. *
  943. * Tests that a given integer value matches any of the given expected values.
  944. *
  945. * \param expected The expected value(s)
  946. * \param actual The actual integer value
  947. *
  948. * \note This can only be invoked after a successful invocation of
  949. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  950. */
  951. # define XTESTS_TEST_INTEGER_EQUAL_ANY_OF(expected, actual) \
  952. \
  953. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  954. \
  955. XTESTS_NS_CPP_QUAL(xtests_test_integer_one_of( \
  956. __FILE__ \
  957. , __LINE__ \
  958. , XTESTS_GET_FUNCTION_() \
  959. , "XTESTS_TEST_INTEGER_EQUAL_ANY_OF(" ## #expected ## ", " ## #actual ## ")" \
  960. , (expected) \
  961. , (actual) \
  962. , XTESTS_NS_C_QUAL(xtestsComparisonEqual))) \
  963. )
  964. #endif /* 0 */
  965. # define XTESTS_TEST_INTEGER_EQUAL_ANY_OF2(expected0, expected1, actual) \
  966. \
  967. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  968. \
  969. XTESTS_NS_CPP_QUAL(xtests_test_integer_one_of( \
  970. __FILE__ \
  971. , __LINE__ \
  972. , XTESTS_GET_FUNCTION_() \
  973. , "XTESTS_TEST_INTEGER_EQUAL_ANY_OF(" ## #expected0 ## ", " ## #expected1 ## ", " ## #actual ## ")" \
  974. , (actual) \
  975. , (expected0) \
  976. , (expected1) \
  977. , XTESTS_NS_C_QUAL(xtestsComparisonEqual))) \
  978. )
  979. # define XTESTS_TEST_INTEGER_EQUAL_ANY_OF3(expected0, expected1, expected2, actual) \
  980. \
  981. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  982. \
  983. XTESTS_NS_CPP_QUAL(xtests_test_integer_one_of( \
  984. __FILE__ \
  985. , __LINE__ \
  986. , XTESTS_GET_FUNCTION_() \
  987. , "XTESTS_TEST_INTEGER_EQUAL_ANY_OF(" ## #expected0 ## ", " ## #expected1 ## ", " ## #expected2 ## ", " ## #actual ## ")" \
  988. , (actual) \
  989. , (expected0) \
  990. , (expected1) \
  991. , (expected2) \
  992. , XTESTS_NS_C_QUAL(xtestsComparisonEqual))) \
  993. )
  994. /* /////////////////////////////////////////////////////////
  995. * Test Booleans
  996. */
  997. /** \def XTESTS_TEST_BOOLEAN_EQUAL(expected, actual)
  998. *
  999. * \ingroup group__xtests__test_functions
  1000. *
  1001. * Tests that two boolean values are exactly equal.
  1002. *
  1003. * \param expected The expected boolean value
  1004. * \param actual The actual boolean value
  1005. *
  1006. * \note This can only be invoked after a successful invocation of
  1007. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1008. */
  1009. # define XTESTS_TEST_BOOLEAN_EQUAL(expected, actual) \
  1010. \
  1011. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1012. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  1013. /** \def XTESTS_TEST_BOOLEAN_NOT_EQUAL(expected, actual)
  1014. *
  1015. * \ingroup group__xtests__test_functions
  1016. *
  1017. * Tests that two boolean values are not equal.
  1018. *
  1019. * \param expected The expected boolean value
  1020. * \param actual The actual boolean value
  1021. *
  1022. * \note This can only be invoked after a successful invocation of
  1023. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1024. */
  1025. # define XTESTS_TEST_BOOLEAN_NOT_EQUAL(expected, actual) \
  1026. \
  1027. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1028. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual))))
  1029. /** \def XTESTS_TEST_BOOLEAN_TRUE(actual)
  1030. *
  1031. * \ingroup group__xtests__test_functions
  1032. *
  1033. * Tests that an expression is true
  1034. *
  1035. * \param actual The boolean expression that is expected to be true
  1036. *
  1037. * \note This can only be invoked after a successful invocation of
  1038. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1039. */
  1040. # define XTESTS_TEST_BOOLEAN_TRUE(actual) \
  1041. \
  1042. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1043. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", true, (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  1044. /** \def XTESTS_TEST_BOOLEAN_FALSE(actual)
  1045. *
  1046. * \ingroup group__xtests__test_functions
  1047. *
  1048. * Tests that an expression is false
  1049. *
  1050. * \param actual The boolean expression that is expected to be false
  1051. *
  1052. * \note This can only be invoked after a successful invocation of
  1053. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1054. */
  1055. # define XTESTS_TEST_BOOLEAN_FALSE(actual) \
  1056. \
  1057. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1058. XTESTS_NS_CPP_QUAL(xtests_test_integer(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", false, (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  1059. /* /////////////////////////////////////////////////////////
  1060. * Test characters
  1061. */
  1062. /** \def XTESTS_TEST_CHARACTER_EQUAL_EXACT(expected, actual)
  1063. *
  1064. * \ingroup group__xtests__test_functions
  1065. *
  1066. * Tests that two character values are exactly equal.
  1067. *
  1068. * \param expected The expected character value
  1069. * \param actual The actual character value
  1070. *
  1071. * \remarks The characters should be of the same type
  1072. *
  1073. * \note This can only be invoked after a successful invocation of
  1074. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1075. */
  1076. # define XTESTS_TEST_CHARACTER_EQUAL_EXACT(expected, actual) \
  1077. \
  1078. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1079. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  1080. /** \def XTESTS_TEST_CHARACTER_NOT_EQUAL(expected, actual)
  1081. *
  1082. * \ingroup group__xtests__test_functions
  1083. *
  1084. * Tests that two character values are not equal.
  1085. *
  1086. * \param expected The expected character value
  1087. * \param actual The actual character value
  1088. *
  1089. * \remarks The characters should be of the same type
  1090. *
  1091. * \note This can only be invoked after a successful invocation of
  1092. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1093. */
  1094. # define XTESTS_TEST_CHARACTER_NOT_EQUAL(expected, actual) \
  1095. \
  1096. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1097. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual))))
  1098. /** \def XTESTS_TEST_CHARACTER_GREATER(expected, actual)
  1099. *
  1100. * \ingroup group__xtests__test_functions
  1101. *
  1102. * Tests that the actual character value is greater than the expected value.
  1103. *
  1104. * \param expected The expected character value
  1105. * \param actual The actual character value
  1106. *
  1107. * \note This can only be invoked after a successful invocation of
  1108. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1109. */
  1110. # define XTESTS_TEST_CHARACTER_GREATER(expected, actual) \
  1111. \
  1112. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1113. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThan))))
  1114. /** \def XTESTS_TEST_CHARACTER_LESS(expected, actual)
  1115. *
  1116. * \ingroup group__xtests__test_functions
  1117. *
  1118. * Tests that the actual character value is less than the expected value.
  1119. *
  1120. * \param expected The expected character value
  1121. * \param actual The actual character value
  1122. *
  1123. * \note This can only be invoked after a successful invocation of
  1124. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1125. */
  1126. # define XTESTS_TEST_CHARACTER_LESS(expected, actual) \
  1127. \
  1128. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1129. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThan))))
  1130. /** \def XTESTS_TEST_CHARACTER_GREATER_OR_EQUAL(expected, actual)
  1131. *
  1132. * \ingroup group__xtests__test_functions
  1133. *
  1134. * Tests that the actual character value is greater than or equal to the
  1135. * expected value.
  1136. *
  1137. * \param expected The expected character value
  1138. * \param actual The actual character value
  1139. *
  1140. * \note This can only be invoked after a successful invocation of
  1141. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1142. */
  1143. # define XTESTS_TEST_CHARACTER_GREATER_OR_EQUAL(expected, actual) \
  1144. \
  1145. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1146. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThanOrEqual))))
  1147. /** \def XTESTS_TEST_CHARACTER_LESS_OR_EQUAL(expected, actual)
  1148. *
  1149. * \ingroup group__xtests__test_functions
  1150. *
  1151. * Tests that the actual character value is less than or equal to the expected
  1152. * value.
  1153. *
  1154. * \param expected The expected character value
  1155. * \param actual The actual character value
  1156. *
  1157. * \note This can only be invoked after a successful invocation of
  1158. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1159. */
  1160. # define XTESTS_TEST_CHARACTER_LESS_OR_EQUAL(expected, actual) \
  1161. \
  1162. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1163. XTESTS_NS_CPP_QUAL(xtests_test_character(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThanOrEqual))))
  1164. /* /////////////////////////////////////////////////////////
  1165. * Test floating-points
  1166. */
  1167. /** \def XTESTS_TEST_FLOATINGPOINT_EQUAL_EXACT(expected, actual)
  1168. *
  1169. * \ingroup group__xtests__test_functions
  1170. *
  1171. * Tests that two floating point values are exactly equal
  1172. *
  1173. * \param expected The expected floating point value
  1174. * \param actual The actual floating point value
  1175. *
  1176. * \note This can only be invoked after a successful invocation of
  1177. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1178. */
  1179. # define XTESTS_TEST_FLOATINGPOINT_EQUAL_EXACT(expected, actual) \
  1180. \
  1181. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1182. XTESTS_NS_CPP_QUAL(xtests_test_floating_point(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual))))
  1183. /** \def XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_EXACT(expected, actual)
  1184. *
  1185. * \ingroup group__xtests__test_functions
  1186. *
  1187. * Tests that two floating point values are not exactly equal
  1188. *
  1189. * \param expected The expected floating point value
  1190. * \param actual The actual floating point value
  1191. *
  1192. * \note This can only be invoked after a successful invocation of
  1193. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1194. */
  1195. # define XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_EXACT(expected, actual) \
  1196. \
  1197. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1198. XTESTS_NS_CPP_QUAL(xtests_test_floating_point(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual))))
  1199. /** \def XTESTS_TEST_FLOATINGPOINT_EQUAL_APPROX(expected, actual)
  1200. *
  1201. * \ingroup group__xtests__test_functions
  1202. *
  1203. * Tests that two floating point values are approximately
  1204. * equal (as defined by xtests_setFloatingPointCloseFactor()).
  1205. *
  1206. * \param expected The expected floating point value
  1207. * \param actual The actual floating point value
  1208. *
  1209. * \note This can only be invoked after a successful invocation of
  1210. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1211. */
  1212. # define XTESTS_TEST_FLOATINGPOINT_EQUAL_APPROX(expected, actual) \
  1213. \
  1214. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1215. XTESTS_NS_CPP_QUAL(xtests_test_floating_point(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual))))
  1216. /** \def XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_APPROX(expected, actual)
  1217. *
  1218. * \ingroup group__xtests__test_functions
  1219. *
  1220. * Tests that two floating point values are not approximately
  1221. * equal (as defined by xtests_setFloatingPointCloseFactor()).
  1222. *
  1223. * \param expected The expected floating point value
  1224. * \param actual The actual floating point value
  1225. *
  1226. * \note This can only be invoked after a successful invocation of
  1227. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1228. */
  1229. # define XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_APPROX(expected, actual) \
  1230. \
  1231. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1232. XTESTS_NS_CPP_QUAL(xtests_test_floating_point(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual))))
  1233. /* Requiring tests
  1234. *
  1235. * These cause an exception of type XXXXX to be thrown if the condition
  1236. * fails, thereby preventing the execution of any further tests that
  1237. * rely on previously established assertions, which may result in undefined
  1238. * behaviour (and possible program failure).
  1239. */
  1240. /** \def XTESTS_REQUIRE(test)
  1241. *
  1242. * \ingroup group__xtests__test_functions
  1243. *
  1244. * Causes the current test case to exit immediately if the given test
  1245. * fails, without considering any other tests
  1246. *
  1247. * \param test The test that must succeed
  1248. *
  1249. * \note This is only available in C++ compilation units
  1250. */
  1251. # if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
  1252. # define XTESTS_REQUIRE(test) XTESTS_NS_CPP_QUAL(xtests_require)(!(!(test)))
  1253. # else /* STLSOFT_CF_EXCEPTION_SUPPORT */
  1254. # define XTESTS_REQUIRE(test) XTESTS_NS_C_QUAL(xtests_require_C)(!(!(test)))
  1255. # endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  1256. #else /* ? __cplusplus) && !_XTESTS_NO_CPP_API */
  1257. # define XTESTS_TEST_INTEGER_EQUAL_EXACT(expected, actual) XTESTS_TEST((expected) == (actual))
  1258. # define XTESTS_TEST_INTEGER_NOT_EQUAL(expected, actual) XTESTS_TEST((expected) != (actual))
  1259. # define XTESTS_TEST_INTEGER_GREATER(expected, actual) XTESTS_TEST((expected) < (actual))
  1260. # define XTESTS_TEST_INTEGER_LESS(expected, actual) XTESTS_TEST((expected) > (actual))
  1261. # define XTESTS_TEST_INTEGER_GREATER_OR_EQUAL(expected, actual) XTESTS_TEST((expected) <= (actual))
  1262. # define XTESTS_TEST_INTEGER_LESS_OR_EQUAL(expected, actual) XTESTS_TEST((expected) >= (actual))
  1263. # define XTESTS_TEST_BOOLEAN_EQUAL(expected, actual) XTESTS_TEST((expected) == (actual))
  1264. # define XTESTS_TEST_BOOLEAN_NOT_EQUAL(expected, actual) XTESTS_TEST((expected) != (actual))
  1265. # define XTESTS_TEST_BOOLEAN_TRUE(actual) XTESTS_TEST((actual))
  1266. # define XTESTS_TEST_BOOLEAN_FALSE(actual) XTESTS_TEST(!(actual))
  1267. # define XTESTS_TEST_CHARACTER_EQUAL_EXACT(expected, actual) XTESTS_TEST((expected) == (actual))
  1268. # define XTESTS_TEST_CHARACTER_NOT_EQUAL(expected, actual) XTESTS_TEST((expected) != (actual))
  1269. # define XTESTS_TEST_CHARACTER_GREATER(expected, actual) XTESTS_TEST((expected) < (actual))
  1270. # define XTESTS_TEST_CHARACTER_LESS(expected, actual) XTESTS_TEST((expected) > (actual))
  1271. # define XTESTS_TEST_CHARACTER_GREATER_OR_EQUAL(expected, actual) XTESTS_TEST((expected) <= (actual))
  1272. # define XTESTS_TEST_CHARACTER_LESS_OR_EQUAL(expected, actual) XTESTS_TEST((expected) >= (actual))
  1273. # define XTESTS_TEST_FLOATINGPOINT_EQUAL_APPROX(expected, actual) XTESTS_TEST(xtests_floatingPointClose((expected), (actual)))
  1274. # define XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_APPROX(expected, actual) XTESTS_TEST(!xtests_floatingPointClose((expected), (actual)))
  1275. #endif /* __cplusplus) && !_XTESTS_NO_CPP_API */
  1276. /** \def XTESTS_ARRAY_END_POST(ar)
  1277. *
  1278. * \ingroup group__xtests__utiliy_functions
  1279. *
  1280. * Evaluates the end-point of an array, based on its static array size.
  1281. */
  1282. #ifdef __DMC__
  1283. # define XTESTS_ARRAY_END_POST(ar) (&(ar)[0] + STLSOFT_NUM_ELEMENTS(ar))
  1284. #else /* ? compiler */
  1285. # define XTESTS_ARRAY_END_POST(ar) (&0[(ar)] + STLSOFT_NUM_ELEMENTS(ar))
  1286. #endif /* compiler */
  1287. /* /////////////////////////////////////////////////////////
  1288. * Test integers
  1289. */
  1290. /** \def XTESTS_TEST_INTEGER_EQUAL(expected, actual)
  1291. *
  1292. * \ingroup group__xtests__test_functions
  1293. *
  1294. * Tests that two integer values (of the same type) are equal.
  1295. *
  1296. * \param expected The expected integer value
  1297. * \param actual The actual integer value
  1298. *
  1299. * \note This can only be invoked after a successful invocation of
  1300. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1301. */
  1302. #define XTESTS_TEST_INTEGER_EQUAL(expected, actual) XTESTS_TEST_INTEGER_EQUAL_EXACT(expected, actual)
  1303. /** \def XTESTS_TEST_FLOATINGPOINT_EQUAL(expected, actual)
  1304. *
  1305. * \ingroup group__xtests__test_functions
  1306. *
  1307. * Tests that two floating point values (of the same type) are equal.
  1308. *
  1309. * \param expected The expected floating point value
  1310. * \param actual The actual floating point value
  1311. *
  1312. * \note This can only be invoked after a successful invocation of
  1313. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1314. */
  1315. #define XTESTS_TEST_FLOATINGPOINT_EQUAL(expected, actual) XTESTS_TEST_FLOATINGPOINT_EQUAL_APPROX(expected, actual)
  1316. /** \def XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL(expected, actual)
  1317. *
  1318. * \ingroup group__xtests__test_functions
  1319. *
  1320. * Tests that two floating point values (of the same type) are not equal.
  1321. *
  1322. * \param expected The expected floating point value
  1323. * \param actual The actual floating point value
  1324. *
  1325. * \note This can only be invoked after a successful invocation of
  1326. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1327. */
  1328. #define XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL(expected, actual) XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL_APPROX(expected, actual)
  1329. /** \def XTESTS_TEST_CHARACTER_EQUAL(expected, actual)
  1330. *
  1331. * \ingroup group__xtests__test_functions
  1332. *
  1333. * Tests that two character values (of the same type) are equal.
  1334. *
  1335. * \param expected The expected character value
  1336. * \param actual The actual character value
  1337. *
  1338. * \note This can only be invoked after a successful invocation of
  1339. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1340. */
  1341. #define XTESTS_TEST_CHARACTER_EQUAL(expected, actual) XTESTS_TEST_CHARACTER_EQUAL_EXACT(expected, actual)
  1342. /* /////////////////////////////////////////////////////////
  1343. * Test multibyte strings
  1344. */
  1345. /** \def XTESTS_TEST_MULTIBYTE_STRING_EQUAL(expected, actual)
  1346. *
  1347. * \ingroup group__xtests__test_functions
  1348. *
  1349. * Tests that two (multibyte) strings are equal.
  1350. *
  1351. * \param expected The expected value of the string
  1352. * \param actual The actual value of the string
  1353. *
  1354. * \note This can only be invoked after a successful invocation of
  1355. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1356. */
  1357. #define XTESTS_TEST_MULTIBYTE_STRING_EQUAL(expected, actual) \
  1358. \
  1359. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1360. XTESTS_NS_C_QUAL(xtests_testMultibyteStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1361. /** \def XTESTS_TEST_MULTIBYTE_STRING_EQUAL_APPROX(expected, actual)
  1362. *
  1363. * \ingroup group__xtests__test_functions
  1364. *
  1365. * Tests that two (multibyte) strings are approximately equal (by ignoring
  1366. * case).
  1367. *
  1368. * \param expected The expected value of the string
  1369. * \param actual The actual value of the string
  1370. *
  1371. * \note This can only be invoked after a successful invocation of
  1372. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1373. */
  1374. #define XTESTS_TEST_MULTIBYTE_STRING_EQUAL_APPROX(expected, actual) \
  1375. \
  1376. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1377. XTESTS_NS_C_QUAL(xtests_testMultibyteStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1378. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL(expected, actual)
  1379. *
  1380. * \ingroup group__xtests__test_functions
  1381. *
  1382. * Tests that two (multibyte) strings are not equal.
  1383. *
  1384. * \param expected The expected value of the string
  1385. * \param actual The actual value of the string
  1386. *
  1387. * \note This can only be invoked after a successful invocation of
  1388. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1389. */
  1390. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL(expected, actual) \
  1391. \
  1392. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1393. XTESTS_NS_C_QUAL(xtests_testMultibyteStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1394. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_APPROX(expected, actual)
  1395. *
  1396. * \ingroup group__xtests__test_functions
  1397. *
  1398. * Tests that two (multibyte) strings are not equal (when ignoring
  1399. * case).
  1400. *
  1401. * \param expected The expected value of the string
  1402. * \param actual The actual value of the string
  1403. *
  1404. * \note This can only be invoked after a successful invocation of
  1405. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1406. */
  1407. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_APPROX(expected, actual) \
  1408. \
  1409. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1410. XTESTS_NS_C_QUAL(xtests_testMultibyteStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1411. /** \def XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(expected, actual, n)
  1412. *
  1413. * \ingroup group__xtests__test_functions
  1414. *
  1415. * Tests that two (multibyte) strings are equal up to a given limit.
  1416. *
  1417. * \param expected The expected value of the string
  1418. * \param actual The actual value of the string
  1419. * \param n The maximum number of characters to compare
  1420. *
  1421. * \note This can only be invoked after a successful invocation of
  1422. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1423. */
  1424. #define XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N(expected, actual, n) \
  1425. \
  1426. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1427. XTESTS_NS_C_QUAL(xtests_testMultibyteStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1428. /** \def XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N_APPROX(expected, actual, n)
  1429. *
  1430. * \ingroup group__xtests__test_functions
  1431. *
  1432. * Tests that two (multibyte) strings are approximately equal (by ignoring
  1433. * case), up to a given limit.
  1434. *
  1435. * \param expected The expected value of the string
  1436. * \param actual The actual value of the string
  1437. * \param n The maximum number of characters to compare
  1438. *
  1439. * \note This can only be invoked after a successful invocation of
  1440. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1441. */
  1442. #define XTESTS_TEST_MULTIBYTE_STRING_EQUAL_N_APPROX(expected, actual, n) \
  1443. \
  1444. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1445. XTESTS_NS_C_QUAL(xtests_testMultibyteStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1446. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_N(expected, actual, n)
  1447. *
  1448. * \ingroup group__xtests__test_functions
  1449. *
  1450. * Tests that two (multibyte) strings are not equal.
  1451. *
  1452. * \param expected The expected value of the string
  1453. * \param actual The actual value of the string
  1454. * \param n The maximum number of characters to compare
  1455. *
  1456. * \note This can only be invoked after a successful invocation of
  1457. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1458. */
  1459. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_N(expected, actual, n) \
  1460. \
  1461. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1462. XTESTS_NS_C_QUAL(xtests_testMultibyteStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1463. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_N_APPROX(expected, actual, n)
  1464. *
  1465. * \ingroup group__xtests__test_functions
  1466. *
  1467. * Tests that two (multibyte) strings are not equal (when ignoring
  1468. * case).
  1469. *
  1470. * \param expected The expected value of the string
  1471. * \param actual The actual value of the string
  1472. * \param n The maximum number of characters to compare
  1473. *
  1474. * \note This can only be invoked after a successful invocation of
  1475. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1476. */
  1477. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_EQUAL_N_APPROX(expected, actual, n) \
  1478. \
  1479. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1480. XTESTS_NS_C_QUAL(xtests_testMultibyteStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1481. /* /////////////////////////////////////////////////////////
  1482. * Test wide strings
  1483. */
  1484. /** \def XTESTS_TEST_WIDE_STRING_EQUAL(expected, actual)
  1485. *
  1486. * \ingroup group__xtests__test_functions
  1487. *
  1488. * Tests that two (wide) strings are equal.
  1489. *
  1490. * \param expected The expected value of the string
  1491. * \param actual The actual value of the string
  1492. *
  1493. * \note This can only be invoked after a successful invocation of
  1494. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1495. */
  1496. #define XTESTS_TEST_WIDE_STRING_EQUAL(expected, actual) \
  1497. \
  1498. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1499. XTESTS_NS_C_QUAL(xtests_testWideStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1500. /** \def XTESTS_TEST_WIDE_STRING_EQUAL_APPROX(expected, actual)
  1501. *
  1502. * \ingroup group__xtests__test_functions
  1503. *
  1504. * Tests that two (wide) strings are approximately equal (by ignoring case).
  1505. *
  1506. * \param expected The expected value of the string
  1507. * \param actual The actual value of the string
  1508. *
  1509. * \note This can only be invoked after a successful invocation of
  1510. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1511. */
  1512. #define XTESTS_TEST_WIDE_STRING_EQUAL_APPROX(expected, actual) \
  1513. \
  1514. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1515. XTESTS_NS_C_QUAL(xtests_testWideStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1516. /** \def XTESTS_TEST_WIDE_STRING_NOT_EQUAL(expected, actual)
  1517. *
  1518. * \ingroup group__xtests__test_functions
  1519. *
  1520. * Tests that two (wide) strings are not equal.
  1521. *
  1522. * \param expected The expected value of the string
  1523. * \param actual The actual value of the string
  1524. *
  1525. * \note This can only be invoked after a successful invocation of
  1526. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1527. */
  1528. #define XTESTS_TEST_WIDE_STRING_NOT_EQUAL(expected, actual) \
  1529. \
  1530. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1531. XTESTS_NS_C_QUAL(xtests_testWideStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1532. /** \def XTESTS_TEST_WIDE_STRING_NOT_EQUAL_APPROX(expected, actual)
  1533. *
  1534. * \ingroup group__xtests__test_functions
  1535. *
  1536. * Tests that two (wide) strings are not equal (when ignoring
  1537. * case).
  1538. *
  1539. * \param expected The expected value of the string
  1540. * \param actual The actual value of the string
  1541. *
  1542. * \note This can only be invoked after a successful invocation of
  1543. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1544. */
  1545. #define XTESTS_TEST_WIDE_STRING_NOT_EQUAL_APPROX(expected, actual) \
  1546. \
  1547. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1548. XTESTS_NS_C_QUAL(xtests_testWideStrings)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1549. /** \def XTESTS_TEST_WIDE_STRING_EQUAL_N(expected, actual, n)
  1550. *
  1551. * \ingroup group__xtests__test_functions
  1552. *
  1553. * Tests that two (wide) strings are equal up to a given limit.
  1554. *
  1555. * \param expected The expected value of the string
  1556. * \param actual The actual value of the string
  1557. * \param n The maximum number of characters to compare
  1558. *
  1559. * \note This can only be invoked after a successful invocation of
  1560. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1561. */
  1562. #define XTESTS_TEST_WIDE_STRING_EQUAL_N(expected, actual, n) \
  1563. \
  1564. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1565. XTESTS_NS_C_QUAL(xtests_testWideStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1566. /** \def XTESTS_TEST_WIDE_STRING_EQUAL_N_APPROX(expected, actual, n)
  1567. *
  1568. * \ingroup group__xtests__test_functions
  1569. *
  1570. * Tests that two (wide) strings are approximately equal (by ignoring
  1571. * case), up to a given limit.
  1572. *
  1573. * \param expected The expected value of the string
  1574. * \param actual The actual value of the string
  1575. * \param n The maximum number of characters to compare
  1576. *
  1577. * \note This can only be invoked after a successful invocation of
  1578. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1579. */
  1580. #define XTESTS_TEST_WIDE_STRING_EQUAL_N_APPROX(expected, actual, n) \
  1581. \
  1582. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1583. XTESTS_NS_C_QUAL(xtests_testWideStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1584. /** \def XTESTS_TEST_WIDE_STRING_NOT_EQUAL_N(expected, actual, n)
  1585. *
  1586. * \ingroup group__xtests__test_functions
  1587. *
  1588. * Tests that two (wide) strings are not equal.
  1589. *
  1590. * \param expected The expected value of the string
  1591. * \param actual The actual value of the string
  1592. * \param n The maximum number of characters to compare
  1593. *
  1594. * \note This can only be invoked after a successful invocation of
  1595. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1596. */
  1597. #define XTESTS_TEST_WIDE_STRING_NOT_EQUAL_N(expected, actual, n) \
  1598. \
  1599. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1600. XTESTS_NS_C_QUAL(xtests_testWideStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1601. /** \def XTESTS_TEST_WIDE_STRING_NOT_EQUAL_N_APPROX(expected, actual, n)
  1602. *
  1603. * \ingroup group__xtests__test_functions
  1604. *
  1605. * Tests that two (wide) strings are not equal (when ignoring case).
  1606. *
  1607. * \param expected The expected value of the string
  1608. * \param actual The actual value of the string
  1609. * \param n The maximum number of characters to compare
  1610. *
  1611. * \note This can only be invoked after a successful invocation of
  1612. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1613. */
  1614. #define XTESTS_TEST_WIDE_STRING_NOT_EQUAL_N_APPROX(expected, actual, n) \
  1615. \
  1616. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1617. XTESTS_NS_C_QUAL(xtests_testWideStringsN)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), n, XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1618. /** \def XTESTS_TEST_MULTIBYTE_STRING_CONTAIN(expected, actual)
  1619. *
  1620. * \ingroup group__xtests__test_functions
  1621. *
  1622. * Tests that the string contains the expected sub-sequence.
  1623. *
  1624. * \param expected The substring to find with the actual string
  1625. * \param actual The actual value of the string
  1626. *
  1627. * \note This can only be invoked after a successful invocation of
  1628. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1629. */
  1630. #define XTESTS_TEST_MULTIBYTE_STRING_CONTAIN(expected, actual) \
  1631. \
  1632. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1633. XTESTS_NS_C_QUAL(xtests_testMultibyteStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1634. /** \def XTESTS_TEST_MULTIBYTE_STRING_CONTAIN_APPROX(expected, actual)
  1635. *
  1636. * \ingroup group__xtests__test_functions
  1637. *
  1638. * Tests that the string contains the expected sub-sequence (disregarding
  1639. * case).
  1640. *
  1641. * \param expected The substring to find with the actual string
  1642. * \param actual The actual value of the string
  1643. *
  1644. * \note This can only be invoked after a successful invocation of
  1645. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1646. */
  1647. #define XTESTS_TEST_MULTIBYTE_STRING_CONTAIN_APPROX(expected, actual) \
  1648. \
  1649. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1650. XTESTS_NS_C_QUAL(xtests_testMultibyteStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1651. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_CONTAIN(expected, actual)
  1652. *
  1653. * \ingroup group__xtests__test_functions
  1654. *
  1655. * Tests that the string does not contain the expected sub-sequence.
  1656. *
  1657. * \param expected The substring to find with the actual string
  1658. * \param actual The actual value of the string
  1659. *
  1660. * \note This can only be invoked after a successful invocation of
  1661. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1662. */
  1663. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_CONTAIN(expected, actual) \
  1664. \
  1665. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1666. XTESTS_NS_C_QUAL(xtests_testMultibyteStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1667. /** \def XTESTS_TEST_MULTIBYTE_STRING_NOT_CONTAIN_APPROX(expected, actual)
  1668. *
  1669. * \ingroup group__xtests__test_functions
  1670. *
  1671. * Tests that the string does not contain the expected sub-sequence
  1672. * (disregarding case).
  1673. *
  1674. * \param expected The substring to find with the actual string
  1675. * \param actual The actual value of the string
  1676. *
  1677. * \note This can only be invoked after a successful invocation of
  1678. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1679. */
  1680. #define XTESTS_TEST_MULTIBYTE_STRING_NOT_CONTAIN_APPROX(expected, actual) \
  1681. \
  1682. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1683. XTESTS_NS_C_QUAL(xtests_testMultibyteStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1684. /** \def XTESTS_TEST_WIDE_STRING_CONTAIN(expected, actual)
  1685. *
  1686. * \ingroup group__xtests__test_functions
  1687. *
  1688. * Tests that the string contains the expected sub-sequence.
  1689. *
  1690. * \param expected The substring to find with the actual string
  1691. * \param actual The actual value of the string
  1692. *
  1693. * \note This can only be invoked after a successful invocation of
  1694. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1695. */
  1696. #define XTESTS_TEST_WIDE_STRING_CONTAIN(expected, actual) \
  1697. \
  1698. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1699. XTESTS_NS_C_QUAL(xtests_testWideStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1700. /** \def XTESTS_TEST_WIDE_STRING_CONTAIN_APPROX(expected, actual)
  1701. *
  1702. * \ingroup group__xtests__test_functions
  1703. *
  1704. * Tests that the string contains the expected sub-sequence (disregarding
  1705. * case).
  1706. *
  1707. * \param expected The substring to find with the actual string
  1708. * \param actual The actual value of the string
  1709. *
  1710. * \note This can only be invoked after a successful invocation of
  1711. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1712. */
  1713. #define XTESTS_TEST_WIDE_STRING_CONTAIN_APPROX(expected, actual) \
  1714. \
  1715. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1716. XTESTS_NS_C_QUAL(xtests_testWideStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxEqual)))
  1717. /** \def XTESTS_TEST_WIDE_STRING_NOT_CONTAIN(expected, actual)
  1718. *
  1719. * \ingroup group__xtests__test_functions
  1720. *
  1721. * Tests that the string does not contain the expected sub-sequence.
  1722. *
  1723. * \param expected The substring to find with the actual string
  1724. * \param actual The actual value of the string
  1725. *
  1726. * \note This can only be invoked after a successful invocation of
  1727. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1728. */
  1729. #define XTESTS_TEST_WIDE_STRING_NOT_CONTAIN(expected, actual) \
  1730. \
  1731. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1732. XTESTS_NS_C_QUAL(xtests_testWideStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1733. /** \def XTESTS_TEST_WIDE_STRING_NOT_CONTAIN_APPROX(expected, actual)
  1734. *
  1735. * \ingroup group__xtests__test_functions
  1736. *
  1737. * Tests that the string does not contain the expected sub-sequence.
  1738. *
  1739. * \param expected The substring to find with the actual string
  1740. * \param actual The actual value of the string
  1741. *
  1742. * \note This can only be invoked after a successful invocation of
  1743. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1744. */
  1745. #define XTESTS_TEST_WIDE_STRING_NOT_CONTAIN_APPROX(expected, actual) \
  1746. \
  1747. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1748. XTESTS_NS_C_QUAL(xtests_testWideStringContains)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonApproxNotEqual)))
  1749. /* /////////////////////////////////////////////////////////
  1750. * Test pointers
  1751. */
  1752. /** \def XTESTS_TEST_POINTER_EQUAL(expected, actual)
  1753. *
  1754. * \ingroup group__xtests__test_functions
  1755. *
  1756. * Tests that two pointers are equal.
  1757. *
  1758. * \param expected The expected value of the pointer
  1759. * \param actual The actual value of the pointer
  1760. *
  1761. * \note This can only be invoked after a successful invocation of
  1762. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1763. */
  1764. #define XTESTS_TEST_POINTER_EQUAL(expected, actual) \
  1765. \
  1766. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1767. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1768. /** \def XTESTS_TEST_POINTER_NOT_EQUAL(expected, actual)
  1769. *
  1770. * \ingroup group__xtests__test_functions
  1771. *
  1772. * Tests that two pointer values are not equal.
  1773. *
  1774. * \param expected The expected pointer value
  1775. * \param actual The actual pointer value
  1776. *
  1777. * \remarks The pointers should be of the same type
  1778. *
  1779. * \note This can only be invoked after a successful invocation of
  1780. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1781. */
  1782. # define XTESTS_TEST_POINTER_NOT_EQUAL(expected, actual) \
  1783. \
  1784. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1785. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1786. /** \def XTESTS_TEST_POINTER_GREATER(expected, actual)
  1787. *
  1788. * \ingroup group__xtests__test_functions
  1789. *
  1790. * Tests that the actual pointer value is greater than the expected value.
  1791. *
  1792. * \param expected The expected pointer value
  1793. * \param actual The actual pointer value
  1794. *
  1795. * \note This can only be invoked after a successful invocation of
  1796. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1797. */
  1798. # define XTESTS_TEST_POINTER_GREATER(expected, actual) \
  1799. \
  1800. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1801. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThan)))
  1802. /** \def XTESTS_TEST_POINTER_LESS(expected, actual)
  1803. *
  1804. * \ingroup group__xtests__test_functions
  1805. *
  1806. * Tests that the actual pointer value is less than the expected value.
  1807. *
  1808. * \param expected The expected pointer value
  1809. * \param actual The actual pointer value
  1810. *
  1811. * \note This can only be invoked after a successful invocation of
  1812. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1813. */
  1814. # define XTESTS_TEST_POINTER_LESS(expected, actual) \
  1815. \
  1816. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1817. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThan)))
  1818. /** \def XTESTS_TEST_POINTER_GREATER_OR_EQUAL(expected, actual)
  1819. *
  1820. * \ingroup group__xtests__test_functions
  1821. *
  1822. * Tests that the actual pointer value is greater than or equal to the
  1823. * expected value.
  1824. *
  1825. * \param expected The expected pointer value
  1826. * \param actual The actual pointer value
  1827. *
  1828. * \note This can only be invoked after a successful invocation of
  1829. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1830. */
  1831. # define XTESTS_TEST_POINTER_GREATER_OR_EQUAL(expected, actual) \
  1832. \
  1833. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1834. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonGreaterThanOrEqual)))
  1835. /** \def XTESTS_TEST_POINTER_LESS_OR_EQUAL(expected, actual)
  1836. *
  1837. * \ingroup group__xtests__test_functions
  1838. *
  1839. * Tests that the actual pointer value is less than or equal to the expected
  1840. * value.
  1841. *
  1842. * \param expected The expected pointer value
  1843. * \param actual The actual pointer value
  1844. *
  1845. * \note This can only be invoked after a successful invocation of
  1846. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1847. */
  1848. # define XTESTS_TEST_POINTER_LESS_OR_EQUAL(expected, actual) \
  1849. \
  1850. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1851. XTESTS_NS_C_QUAL(xtests_testPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", (expected), (actual), XTESTS_NS_C_QUAL(xtestsComparisonLessThanOrEqual)))
  1852. /* /////////////////////////////////////////////////////////
  1853. * Test function pointers
  1854. */
  1855. /** \def XTESTS_TEST_FUNCTION_POINTER_EQUAL(expected, actual)
  1856. *
  1857. * \ingroup group__xtests__test_functions
  1858. *
  1859. * Tests that two pointers are equal.
  1860. *
  1861. * \param expected The expected value of the pointer
  1862. * \param actual The actual value of the pointer
  1863. *
  1864. * \note This can only be invoked after a successful invocation of
  1865. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1866. */
  1867. #define XTESTS_TEST_FUNCTION_POINTER_EQUAL(expected, actual) \
  1868. \
  1869. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1870. XTESTS_NS_C_QUAL(xtests_testFunctionPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", XTESTS_VOID_FUNCTION_CAST_(expected), XTESTS_VOID_FUNCTION_CAST_(actual), XTESTS_NS_C_QUAL(xtestsComparisonEqual)))
  1871. /** \def XTESTS_TEST_FUNCTION_POINTER_NOT_EQUAL(expected, actual)
  1872. *
  1873. * \ingroup group__xtests__test_functions
  1874. *
  1875. * Tests that two pointer values are not equal.
  1876. *
  1877. * \param expected The expected pointer value
  1878. * \param actual The actual pointer value
  1879. *
  1880. * \remarks The pointers should be of the same type
  1881. *
  1882. * \note This can only be invoked after a successful invocation of
  1883. * XTESTS_CASE_BEGIN() and before invocation of XTESTS_CASE_END().
  1884. */
  1885. # define XTESTS_TEST_FUNCTION_POINTER_NOT_EQUAL(expected, actual) \
  1886. \
  1887. (!XTESTS_NS_C_QUAL(xTests_hasRequiredConditionFailed()) && \
  1888. XTESTS_NS_C_QUAL(xtests_testFunctionPointers)(__FILE__, __LINE__, XTESTS_GET_FUNCTION_(), "", XTESTS_VOID_FUNCTION_CAST_(expected), XTESTS_VOID_FUNCTION_CAST_(actual), XTESTS_NS_C_QUAL(xtestsComparisonNotEqual)))
  1889. /* /////////////////////////////////////////////////////////////////////////
  1890. * Helper functions
  1891. */
  1892. #ifdef __cplusplus
  1893. # if !defined(_XTESTS_NO_CPP_API)
  1894. # ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  1895. /* c_str_len_n_X(s, n)
  1896. *
  1897. * prevents len-limited strlen() from overstepping
  1898. */
  1899. inline size_t c_str_len_n_a(char const* s, size_t n)
  1900. {
  1901. size_t len = 0;
  1902. for(; '\0' != *s && len != n; ++s, ++len)
  1903. {}
  1904. return len;
  1905. }
  1906. inline size_t c_str_len_n_w(wchar_t const* s, size_t n)
  1907. {
  1908. size_t len = 0;
  1909. for(; '\0' != *s && len != n; ++s, ++len)
  1910. {}
  1911. return len;
  1912. }
  1913. template <typename S>
  1914. inline size_t c_str_len_n_a(S const& s, size_t n)
  1915. {
  1916. stlsoft_ns_using(c_str_len_a);
  1917. size_t len = XTESTS_INVOKE_c_str_len_a_(s);
  1918. return (len < n) ? len : n;
  1919. }
  1920. template <typename S>
  1921. inline size_t c_str_len_n_w(S const& s, size_t n)
  1922. {
  1923. stlsoft_ns_using(c_str_len_w);
  1924. size_t len = XTESTS_INVOKE_c_str_len_w_(s);
  1925. return (len < n) ? len : n;
  1926. }
  1927. # endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  1928. # endif /* !_XTESTS_NO_CPP_API */
  1929. #endif /* __cplusplus */
  1930. /* /////////////////////////////////////////////////////////////////////////
  1931. * API functions
  1932. */
  1933. /** The verbosity level to be applied when executing a test runner
  1934. *
  1935. * \ingroup group__xtests__test_runner_functions
  1936. *
  1937. * Verbosity affects the output from an xTests test program. Output comes
  1938. * in the following forms:
  1939. *
  1940. * - a test failure (highly granular)
  1941. * - a test case summary
  1942. * - a test runner summary
  1943. *
  1944. *
  1945. *
  1946. * \see XTESTS_START_RUNNER()
  1947. * \see XTESTS_START_RUNNER_WITH_REPORTER()
  1948. */
  1949. enum xtests_verbosity_t
  1950. {
  1951. XTESTS_VERBOSITY_SILENT = -1 /*!< There is no output of any kind; status must be indicated by program return code */
  1952. , XTESTS_VERBOSITY_RUNNER_SUMMARY_ON_ERROR = 0 /*!< Outputs only a runner summary only on error */
  1953. , XTESTS_VERBOSITY_RUNNER_SUMMARY = 1 /*!< Outputs only a runner summary */
  1954. , XTESTS_VERBOSITY_FIRST_CASE_SUMMARY_ON_ERROR = 2 /*!< Outputs a runner summary and the first case summary only on error */
  1955. , XTESTS_VERBOSITY_CASE_SUMMARY_ON_ERROR = 3 /*!< Outputs a runner summary and a summary for each test case in error */
  1956. , XTESTS_VERBOSITY_CASE_SUMMARY = 4 /*!< Outputs a runner summary and a summary for each test case */
  1957. , XTESTS_VERBOSITY_VERBOSE = 9 /*!< Maximum amount of output */
  1958. };
  1959. #ifndef __cplusplus
  1960. typedef enum xtests_verbosity_t xtests_verbosity_t;
  1961. #endif /* !__cplusplus */
  1962. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  1963. enum xtests_comparison_t
  1964. {
  1965. /* NOTE: NEVER CHANGE THE ORDER OF THESE ENUMERATORS !!!!!!!!!!! */
  1966. xtestsComparisonEqual = 0
  1967. , xtestsComparisonNotEqual
  1968. , xtestsComparisonGreaterThan
  1969. , xtestsComparisonLessThan
  1970. , xtestsComparisonGreaterThanOrEqual
  1971. , xtestsComparisonLessThanOrEqual
  1972. , xtestsComparisonApproxEqual
  1973. , xtestsComparisonApproxNotEqual
  1974. /* NOTE: NEVER CHANGE THE ORDER OF THESE ENUMERATORS !!!!!!!!!!! */
  1975. , xtestsComparison_max_enumerator
  1976. };
  1977. # ifndef __cplusplus
  1978. typedef enum xtests_comparison_t xtests_comparison_t;
  1979. # endif /* !__cplusplus */
  1980. # ifdef __cplusplus
  1981. enum xtests_variable_type_t
  1982. {
  1983. xtestsVariableNone = 0
  1984. , xtestsVariableBoolean = 1
  1985. , xtestsVariableOpaquePointer = 3
  1986. , xtestsVariableMultibyteCharacter = 5
  1987. , xtestsVariableWideCharacter = 6
  1988. , xtestsVariableMultibyteString = 7
  1989. , xtestsVariableWideString = 8
  1990. , xtestsVariableSignedChar = 11
  1991. , xtestsVariableUnsignedChar = 12
  1992. , xtestsVariableShort = 13
  1993. , xtestsVariableUnsignedShort = 14
  1994. , xtestsVariableInt = 15
  1995. , xtestsVariableUnsignedInt = 16
  1996. , xtestsVariableLong = 17
  1997. , xtestsVariableUnsignedLong = 18
  1998. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  1999. , xtestsVariableLongLong = 19
  2000. , xtestsVariableUnsignedLongLong = 20
  2001. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2002. , xtestsVariableDouble = 31
  2003. };
  2004. #ifndef __cplusplus
  2005. typedef enum xtests_variable_type_t xtests_variable_type_t;
  2006. #endif /* !__cplusplus */
  2007. enum xtests_test_type_t
  2008. {
  2009. xtestsTestFullComparison = 0
  2010. , xtestsTestPartialComparison = 1
  2011. , xtestsTestContainment = 2
  2012. };
  2013. #ifndef __cplusplus
  2014. typedef enum xtests_test_type_t xtests_test_type_t;
  2015. #endif /* !__cplusplus */
  2016. union xtests_variable_value_t
  2017. {
  2018. int booleanValue;
  2019. int intValue;
  2020. unsigned int uintValue;
  2021. long longValue;
  2022. unsigned long ulongValue;
  2023. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  2024. stlsoft_ns_qual(ss_sint64_t) longlongValue;
  2025. stlsoft_ns_qual(ss_uint64_t) ulonglongValue;
  2026. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2027. char multibyteCharacterValue;
  2028. wchar_t wideCharacterValue;
  2029. char const* multibyteStringValue;
  2030. wchar_t const* wideStringValue;
  2031. double doubleValue;
  2032. void const volatile* opaquePointerValue;
  2033. explicit xtests_variable_value_t(bool b);
  2034. explicit xtests_variable_value_t(char ch);
  2035. explicit xtests_variable_value_t(wchar_t ch, xtests_variable_type_t type /* = xtestsVariableMultibyteCharacter */);
  2036. explicit xtests_variable_value_t(signed int i);
  2037. explicit xtests_variable_value_t(unsigned int i);
  2038. explicit xtests_variable_value_t(signed long i);
  2039. explicit xtests_variable_value_t(unsigned long i);
  2040. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  2041. explicit xtests_variable_value_t(stlsoft_ns_qual(ss_sint64_t) const& i);
  2042. explicit xtests_variable_value_t(stlsoft_ns_qual(ss_uint64_t) const& i);
  2043. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2044. explicit xtests_variable_value_t(char const* s);
  2045. explicit xtests_variable_value_t(wchar_t const* s);
  2046. explicit xtests_variable_value_t(char const* s, size_t n);
  2047. explicit xtests_variable_value_t(wchar_t const* s, size_t n);
  2048. explicit xtests_variable_value_t(double const& d);
  2049. explicit xtests_variable_value_t(void const volatile* pv);
  2050. };
  2051. #ifndef __cplusplus
  2052. typedef union xtests_variable_value_t xtests_variable_value_t;
  2053. #endif /* !__cplusplus */
  2054. struct xtests_variable_t
  2055. {
  2056. xtests_variable_type_t variableType;
  2057. xtests_test_type_t testType;
  2058. xtests_variable_value_t value;
  2059. size_t valueLen;
  2060. public:
  2061. explicit xtests_variable_t(char ch);
  2062. explicit xtests_variable_t(wchar_t ch, xtests_variable_type_t type /* = xtestsVariableMultibyteCharacter */);
  2063. explicit xtests_variable_t(bool b);
  2064. explicit xtests_variable_t(int b, xtests_variable_type_t type /* = xtestsVariableBoolean */);
  2065. explicit xtests_variable_t(signed char i);
  2066. explicit xtests_variable_t(unsigned char i);
  2067. explicit xtests_variable_t(signed short i);
  2068. explicit xtests_variable_t(unsigned short i);
  2069. explicit xtests_variable_t(signed int i);
  2070. explicit xtests_variable_t(unsigned int i);
  2071. explicit xtests_variable_t(signed long i);
  2072. explicit xtests_variable_t(unsigned long i);
  2073. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  2074. explicit xtests_variable_t(stlsoft_ns_qual(ss_sint64_t) const& i);
  2075. explicit xtests_variable_t(stlsoft_ns_qual(ss_uint64_t) const& i);
  2076. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2077. explicit xtests_variable_t(char const* s, size_t n, xtests_test_type_t testType = xtestsTestFullComparison);
  2078. explicit xtests_variable_t(wchar_t const* s, size_t n, xtests_test_type_t testType = xtestsTestFullComparison);
  2079. explicit xtests_variable_t(char const* s, xtests_test_type_t testType = xtestsTestFullComparison);
  2080. explicit xtests_variable_t(wchar_t const* s, xtests_test_type_t testType = xtestsTestFullComparison);
  2081. explicit xtests_variable_t(double const& d);
  2082. explicit xtests_variable_t(void const volatile* pv);
  2083. };
  2084. #ifndef __cplusplus
  2085. typedef union xtests_variable_t xtests_variable_t;
  2086. #endif /* !__cplusplus */
  2087. /** Summary of results for a single test case, or for all test cases
  2088. * in a test runner
  2089. */
  2090. struct xTests_runner_results_t
  2091. {
  2092. typedef stlsoft_ns_qual(uint32_t) uint32_t;
  2093. char const* name;
  2094. uint32_t numCases;
  2095. uint32_t numTests;
  2096. uint32_t numFailedCases;
  2097. uint32_t numFailedTests;
  2098. uint32_t numMissingExpectedExceptions;
  2099. uint32_t numUnexpectedExceptions;
  2100. };
  2101. /** Interface to a type whose instances may be used to report results
  2102. */
  2103. struct xTests_Reporter_t
  2104. {
  2105. protected:
  2106. # if defined(STLSOFT_COMPILER_IS_GCC)
  2107. virtual ~xTests_Reporter_t()
  2108. {}
  2109. # else /* ? compiler */
  2110. ~xTests_Reporter_t()
  2111. {}
  2112. private:
  2113. virtual void dummy_dtor()
  2114. {}
  2115. # endif /* compiler */
  2116. public: /* Overrides */
  2117. virtual void onStartRunner(void* reporterParam, char const* name, int verbosity) = 0;
  2118. virtual void onBeginTestCase(void* reporterParam, char const* name, char const* desc, int verbosity) = 0;
  2119. virtual void onTestPassed(void* reporterParam, char const* file, int line, char const* function, char const* expr, xtests_comparison_t comparison, int verbosity) = 0;
  2120. virtual void onTestFailed(void* reporterParam, char const* file, int line, char const* function, char const* expr, xtests_variable_t const* expectedValue, xtests_variable_t const* actualValue, ptrdiff_t length, xtests_comparison_t comparison, int verbosity) = 0;
  2121. virtual void onWriteFailMessage(void* reporterParam, char const* file, int line, char const* function, char const* message, char const* qualifyingInformation, int verbosity) = 0;
  2122. virtual void onCaseExcepted(void* reporterParam, char const* caseName, char const* exceptionType, char const* exceptionMessage, int verbosity) = 0;
  2123. virtual void onCaseExceptionExpected(void* reporterParam, char const* caseName, char const* exceptionType, int verbosity) = 0;
  2124. virtual void onEndTestCase(void* reporterParam, char const* name, xTests_runner_results_t const* results, int verbosity) = 0;
  2125. virtual void onPrintRunnerResults(void* reporterParam, xTests_runner_results_t const* results, int verbosity) = 0;
  2126. virtual void onAbend(void* reporterParam, char const* message, int verbosity) = 0;
  2127. virtual void onDefect(void* reporterParam, char const* message, char const* qualifier, int verbosity) = 0;
  2128. virtual void onEndRunner(void* reporterParam, char const* name, int verbosity) = 0;
  2129. };
  2130. # else /* ? __cplusplus */
  2131. struct xTests_Reporter_t;
  2132. typedef struct xTests_Reporter_t xTests_Reporter_t;
  2133. # endif /* __cplusplus */
  2134. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  2135. /** Function that is used to setup the test environment for each test case
  2136. *
  2137. * \param param The caller-supplied parameter passed to xtests_startRunner()
  2138. * (via XTESTS_START_RUNNER_WITH_SETUP_FNS() or
  2139. * XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS_AND_SETUP_FNS())
  2140. *
  2141. * \return A value that indicates whether setup was successful
  2142. * \retval 0 Setup was successful
  2143. * \retval !0 Setup failed. In this case, the test case will not be executed.
  2144. */
  2145. typedef int (*xTests_Setup_t)(void* param);
  2146. /** Function that is used to teardown the test environment for each test
  2147. * case
  2148. *
  2149. * \param param The caller-supplied parameter passed to xtests_startRunner()
  2150. * (via XTESTS_START_RUNNER_WITH_SETUP_FNS() or
  2151. * XTESTS_START_RUNNER_WITH_REPORTER_AND_STREAM_AND_FLAGS_AND_SETUP_FNS())
  2152. *
  2153. * \return Ignored in the current version.
  2154. */
  2155. typedef int (*xTests_Teardown_t)(void* param);
  2156. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  2157. XTESTS_CALL(int)
  2158. xtests_startRunner(
  2159. char const* name
  2160. , int verbosity
  2161. , xTests_Reporter_t* reporter /* = NULL => reports to console (fprintf); also reports via OutputDebugString() on windows */
  2162. , void* reporterParam /* = NULL */
  2163. , FILE* stm /* = NULL => stdout */
  2164. , int flags /* = 0 */
  2165. , xTests_Setup_t setup
  2166. , xTests_Teardown_t teardown
  2167. , void* setupParam
  2168. );
  2169. XTESTS_CALL(int)
  2170. xtests_endRunner(int *retCode);
  2171. XTESTS_CALL(void)
  2172. xtests_printRunnerResults(void);
  2173. XTESTS_CALL(void)
  2174. xtests_abend(char const* message);
  2175. XTESTS_CALL(int)
  2176. xtests_beginTestCase(
  2177. char const* name
  2178. , char const* desc
  2179. );
  2180. XTESTS_CALL(int)
  2181. xtests_endTestCase(char const* name);
  2182. XTESTS_CALL(int)
  2183. xtests_testPassed(
  2184. char const* file
  2185. , int line
  2186. , char const* function
  2187. , char const* expr
  2188. );
  2189. XTESTS_CALL(int)
  2190. xtests_testFailed(
  2191. char const* file
  2192. , int line
  2193. , char const* function
  2194. , char const* expr
  2195. );
  2196. XTESTS_CALL(int)
  2197. xtests_testFailed_int(
  2198. char const* file
  2199. , int line
  2200. , char const* function
  2201. , char const* expr
  2202. , int expected
  2203. , int actual
  2204. , xtests_comparison_t comp
  2205. );
  2206. XTESTS_CALL(int)
  2207. xtests_testFailed_long(
  2208. char const* file
  2209. , int line
  2210. , char const* function
  2211. , char const* expr
  2212. , long expected
  2213. , long actual
  2214. , xtests_comparison_t comp
  2215. );
  2216. XTESTS_CALL(int)
  2217. xtests_testFailed_ulong(
  2218. char const* file
  2219. , int line
  2220. , char const* function
  2221. , char const* expr
  2222. , unsigned long expected
  2223. , unsigned long actual
  2224. , xtests_comparison_t comp
  2225. );
  2226. # ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  2227. XTESTS_CALL(int)
  2228. xtests_testFailed_longlong(
  2229. char const* file
  2230. , int line
  2231. , char const* function
  2232. , char const* expr
  2233. , stlsoft_ns_qual(ss_sint64_t) expected
  2234. , stlsoft_ns_qual(ss_sint64_t) actual
  2235. , xtests_comparison_t comp
  2236. );
  2237. XTESTS_CALL(int)
  2238. xtests_testFailed_ulonglong(
  2239. char const* file
  2240. , int line
  2241. , char const* function
  2242. , char const* expr
  2243. , stlsoft_ns_qual(ss_uint64_t) expected
  2244. , stlsoft_ns_qual(ss_uint64_t) actual
  2245. , xtests_comparison_t comp
  2246. );
  2247. # endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2248. XTESTS_CALL(int)
  2249. xtests_testFailed_boolean(
  2250. char const* file
  2251. , int line
  2252. , char const* function
  2253. , char const* expr
  2254. , int expected
  2255. , int actual
  2256. , xtests_comparison_t comp
  2257. );
  2258. XTESTS_CALL(int)
  2259. xtests_testFailed_double(
  2260. char const* file
  2261. , int line
  2262. , char const* function
  2263. , char const* expr
  2264. , double expected
  2265. , double actual
  2266. , xtests_comparison_t comp
  2267. );
  2268. XTESTS_CALL(int)
  2269. xtests_testMultibyteStrings(
  2270. char const* file
  2271. , int line
  2272. , char const* function
  2273. , char const* expr
  2274. , char const* expected
  2275. , char const* actual
  2276. , xtests_comparison_t comp
  2277. );
  2278. XTESTS_CALL(int)
  2279. xtests_testMultibyteStringsN(
  2280. char const* file
  2281. , int line
  2282. , char const* function
  2283. , char const* expr
  2284. , char const* expected
  2285. , char const* actual
  2286. , ptrdiff_t n /* exact if +ve; limit if -ve */
  2287. , xtests_comparison_t comp
  2288. );
  2289. XTESTS_CALL(int)
  2290. xtests_testMultibyteStringsN_(
  2291. char const* file
  2292. , int line
  2293. , char const* function
  2294. , char const* expr
  2295. , char const* expected
  2296. , char const* actual
  2297. , ptrdiff_t n /* exact if +ve; limit if -ve */
  2298. , size_t cchExpected
  2299. , size_t cchActual
  2300. , xtests_comparison_t comp
  2301. );
  2302. #if defined(__cplusplus) && \
  2303. !defined(_XTESTS_NO_CPP_API)
  2304. template<
  2305. typename S0
  2306. , typename S1
  2307. >
  2308. inline
  2309. int
  2310. xtests_testMultibyteStrings(
  2311. char const* file
  2312. , int line
  2313. , char const* function
  2314. , char const* expr
  2315. , S0 const& expected
  2316. , S1 const& actual
  2317. , xtests_comparison_t comp
  2318. )
  2319. {
  2320. stlsoft_ns_using(c_str_ptr_a);
  2321. return xtests_testMultibyteStrings(file, line, function, expr, XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(expected)), XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(actual)), comp);
  2322. }
  2323. template<
  2324. typename S0
  2325. , typename S1
  2326. >
  2327. inline
  2328. int
  2329. xtests_testMultibyteStringsN(
  2330. char const* file
  2331. , int line
  2332. , char const* function
  2333. , char const* expr
  2334. , S0 const& expected
  2335. , S1 const& actual
  2336. , int n /* exact if +ve; limit if -ve */
  2337. , xtests_comparison_t comp
  2338. )
  2339. {
  2340. stlsoft_ns_using(c_str_data_a);
  2341. return xtests_testMultibyteStringsN_(
  2342. file
  2343. , line
  2344. , function
  2345. , expr
  2346. , XTESTS_INVOKE_c_str_data_a_(XTESTS_INVOKE_c_str_data_a_(expected))
  2347. , XTESTS_INVOKE_c_str_data_a_(XTESTS_INVOKE_c_str_data_a_(actual))
  2348. , n
  2349. , c_str_len_n_a(expected, stlsoft_static_cast(size_t, (n < 0) ? -n : n))
  2350. , c_str_len_n_a(actual, stlsoft_static_cast(size_t, (n < 0) ? -n : n))
  2351. , comp
  2352. );
  2353. }
  2354. #endif /* C++ && !_XTESTS_NO_CPP_API */
  2355. XTESTS_CALL(int)
  2356. xtests_testWideStrings(
  2357. char const* file
  2358. , int line
  2359. , char const* function
  2360. , char const* expr
  2361. , wchar_t const* expected
  2362. , wchar_t const* actual
  2363. , xtests_comparison_t comp
  2364. );
  2365. XTESTS_CALL(int)
  2366. xtests_testWideStringsN_(
  2367. char const* file
  2368. , int line
  2369. , char const* function
  2370. , char const* expr
  2371. , wchar_t const* expected
  2372. , wchar_t const* actual
  2373. , int n /* exact if +ve; limit if -ve */
  2374. , size_t cchExpected
  2375. , size_t cchActual
  2376. , xtests_comparison_t comp
  2377. );
  2378. XTESTS_CALL(int)
  2379. xtests_testWideStringsN(
  2380. char const* file
  2381. , int line
  2382. , char const* function
  2383. , char const* expr
  2384. , wchar_t const* expected
  2385. , wchar_t const* actual
  2386. , int n /* exact if +ve; limit if -ve */
  2387. , xtests_comparison_t comp
  2388. );
  2389. #if defined(__cplusplus) && \
  2390. !defined(_XTESTS_NO_CPP_API)
  2391. template<
  2392. typename S0
  2393. , typename S1
  2394. >
  2395. inline
  2396. int
  2397. xtests_testWideStrings(
  2398. char const* file
  2399. , int line
  2400. , char const* function
  2401. , char const* expr
  2402. , S0 const& expected
  2403. , S1 const& actual
  2404. , xtests_comparison_t comp
  2405. )
  2406. {
  2407. stlsoft_ns_using(c_str_ptr_w);
  2408. return xtests_testWideStrings(file, line, function, expr, XTESTS_INVOKE_c_str_ptr_w_(XTESTS_INVOKE_c_str_ptr_w_(expected)), XTESTS_INVOKE_c_str_ptr_w_(XTESTS_INVOKE_c_str_ptr_w_(actual)), comp);
  2409. }
  2410. template<
  2411. typename S0
  2412. , typename S1
  2413. >
  2414. inline
  2415. int
  2416. xtests_testWideStringsN(
  2417. char const* file
  2418. , int line
  2419. , char const* function
  2420. , char const* expr
  2421. , S0 const& expected
  2422. , S1 const& actual
  2423. , int n /* exact if +ve; limit if -ve */
  2424. , xtests_comparison_t comp
  2425. )
  2426. {
  2427. stlsoft_ns_using(c_str_data_w);
  2428. return xtests_testWideStringsN_(
  2429. file
  2430. , line
  2431. , function
  2432. , expr
  2433. , XTESTS_INVOKE_c_str_data_w_(XTESTS_INVOKE_c_str_data_w_(expected))
  2434. , XTESTS_INVOKE_c_str_data_w_(XTESTS_INVOKE_c_str_data_w_(actual))
  2435. , n
  2436. , c_str_len_n_w(expected, stlsoft_static_cast(size_t, (n < 0) ? -n : n))
  2437. , c_str_len_n_w(actual, stlsoft_static_cast(size_t, (n < 0) ? -n : n))
  2438. , comp
  2439. );
  2440. }
  2441. #endif /* C++ && !_XTESTS_NO_CPP_API */
  2442. XTESTS_CALL(int)
  2443. xtests_testMultibyteStringContains(
  2444. char const* file
  2445. , int line
  2446. , char const* function
  2447. , char const* expr
  2448. , char const* expected
  2449. , char const* actual
  2450. , xtests_comparison_t comp
  2451. );
  2452. #if defined(__cplusplus) && \
  2453. !defined(_XTESTS_NO_CPP_API)
  2454. template<
  2455. typename S0
  2456. , typename S1
  2457. >
  2458. inline
  2459. int
  2460. xtests_testMultibyteStringContains(
  2461. char const* file
  2462. , int line
  2463. , char const* function
  2464. , char const* expr
  2465. , S0 const& expected
  2466. , S1 const& actual
  2467. , xtests_comparison_t comp
  2468. )
  2469. {
  2470. stlsoft_ns_using(c_str_ptr_a);
  2471. return xtests_testMultibyteStringContains(file, line, function, expr, XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(expected)), XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(actual)), comp);
  2472. }
  2473. #endif /* C++ && !_XTESTS_NO_CPP_API */
  2474. XTESTS_CALL(int)
  2475. xtests_testWideStringContains(
  2476. char const* file
  2477. , int line
  2478. , char const* function
  2479. , char const* expr
  2480. , wchar_t const* expected
  2481. , wchar_t const* actual
  2482. , xtests_comparison_t comp
  2483. );
  2484. #if defined(__cplusplus) && \
  2485. !defined(_XTESTS_NO_CPP_API)
  2486. template<
  2487. typename S0
  2488. , typename S1
  2489. >
  2490. inline
  2491. int
  2492. xtests_testWideStringContains(
  2493. char const* file
  2494. , int line
  2495. , char const* function
  2496. , char const* expr
  2497. , S0 const& expected
  2498. , S1 const& actual
  2499. , xtests_comparison_t comp
  2500. )
  2501. {
  2502. stlsoft_ns_using(c_str_ptr_w);
  2503. return xtests_testWideStringContains(file, line, function, expr, XTESTS_INVOKE_c_str_ptr_w_(XTESTS_INVOKE_c_str_ptr_w_(expected)), XTESTS_INVOKE_c_str_ptr_w_(XTESTS_INVOKE_c_str_ptr_w_(actual)), comp);
  2504. }
  2505. #endif /* C++ && !_XTESTS_NO_CPP_API */
  2506. XTESTS_CALL(int)
  2507. xtests_testPointers(
  2508. char const* file
  2509. , int line
  2510. , char const* function
  2511. , char const* expr
  2512. , void volatile const* expected
  2513. , void volatile const* actual
  2514. , xtests_comparison_t comp
  2515. );
  2516. XTESTS_CALL(int)
  2517. xtests_testFunctionPointers(
  2518. char const* file
  2519. , int line
  2520. , char const* function
  2521. , char const* expr
  2522. , void (*expected)(void)
  2523. , void (*actual)(void)
  2524. , xtests_comparison_t comp
  2525. );
  2526. XTESTS_CALL(int)
  2527. xtests_testCharactersA(
  2528. char const* file
  2529. , int line
  2530. , char const* function
  2531. , char const* expr
  2532. , char expected
  2533. , char actual
  2534. , xtests_comparison_t comp
  2535. );
  2536. XTESTS_CALL(int)
  2537. xtests_testCharactersW(
  2538. char const* file
  2539. , int line
  2540. , char const* function
  2541. , char const* expr
  2542. , wchar_t expected
  2543. , wchar_t actual
  2544. , xtests_comparison_t comp
  2545. );
  2546. XTESTS_CALL(int)
  2547. xtests_writeFailMessage(
  2548. char const* file
  2549. , int line
  2550. , char const* function
  2551. , char const* message
  2552. , char const* qualifyingInformation
  2553. );
  2554. #if defined(__cplusplus) && \
  2555. !defined(_XTESTS_NO_CPP_API)
  2556. template<
  2557. typename S0
  2558. , typename S1
  2559. >
  2560. inline
  2561. int
  2562. xtests_writeFailMessage(
  2563. char const* file
  2564. , int line
  2565. , char const* function
  2566. , S0 const& message
  2567. , S1 const& qualifyingInformation
  2568. )
  2569. {
  2570. stlsoft_ns_using(c_str_ptr_a);
  2571. return xtests_writeFailMessage(
  2572. file
  2573. , line
  2574. , function
  2575. , XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(message))
  2576. , XTESTS_INVOKE_c_str_ptr_a_(XTESTS_INVOKE_c_str_ptr_a_(qualifyingInformation)));
  2577. }
  2578. #endif /* C++ && !_XTESTS_NO_CPP_API */
  2579. XTESTS_CALL(void)
  2580. xtests_caseExcepted(
  2581. char const* exceptionType
  2582. , char const* exceptionMessage
  2583. );
  2584. XTESTS_CALL(void)
  2585. xtests_caseExceptionExpected(
  2586. char const* exceptionType
  2587. );
  2588. XTESTS_CALL(int)
  2589. xtests_floatingPointClose(
  2590. double expected
  2591. , double actual
  2592. );
  2593. /** Sets the floating-point number closesness factor, used in
  2594. * XTESTS_TEST_FLOATINGPOINT_EQUAL_APPROX()
  2595. *
  2596. * \param factor The factor. Must be >= 1.0 and < 2.0
  2597. * \param old Optional pointer to receive the previous value. May be NULL
  2598. *
  2599. * \see XTESTS_FLOATINGPOINT_FACTOR_SCOPE
  2600. */
  2601. XTESTS_CALL(double)
  2602. xtests_setFloatingPointCloseFactor(
  2603. double factor
  2604. , double* old /* = NULL */
  2605. );
  2606. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  2607. /* /////////////////////////////////////////////////////////////////////////
  2608. * C++-only functionality
  2609. */
  2610. #if defined(__cplusplus) && \
  2611. !defined(_XTESTS_NO_CPP_API)
  2612. # ifndef _XTESTS_NO_NAMESPACE
  2613. namespace cpp
  2614. {
  2615. # endif /* !_XTESTS_NO_NAMESPACE */
  2616. # if defined(STLSOFT_CF_EXCEPTION_SUPPORT)
  2617. # ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  2618. class requirement_failed_exception
  2619. : public std::runtime_error
  2620. {
  2621. public:
  2622. typedef std::runtime_error parent_class_type;
  2623. typedef requirement_failed_exception class_type;
  2624. public:
  2625. explicit requirement_failed_exception(char const* message)
  2626. : parent_class_type(message)
  2627. {}
  2628. };
  2629. inline
  2630. void
  2631. xtests_require(int success)
  2632. {
  2633. if(!success)
  2634. {
  2635. throw requirement_failed_exception("XTESTS_REQUIRE()'d test failed");
  2636. }
  2637. }
  2638. # endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  2639. # endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  2640. /** Scoping class that sets the floating-point close factor for a
  2641. * controlled period
  2642. */
  2643. class xtest_floatingpoint_factor_scope
  2644. {
  2645. public:
  2646. /** Sets the floating point close factor to the given value */
  2647. xtest_floatingpoint_factor_scope(double const& factor)
  2648. : m_original(xtests_setFloatingPointCloseFactor(factor, NULL))
  2649. {}
  2650. /** Resets the floating point close factor to the original value */
  2651. ~xtest_floatingpoint_factor_scope() stlsoft_throw_0()
  2652. {
  2653. xtests_setFloatingPointCloseFactor(m_original, NULL);
  2654. }
  2655. private:
  2656. xtest_floatingpoint_factor_scope(xtest_floatingpoint_factor_scope const&);
  2657. xtest_floatingpoint_factor_scope &operator =(xtest_floatingpoint_factor_scope const&);
  2658. private:
  2659. const double m_original;
  2660. };
  2661. /** \def XTESTS_FLOATINGPOINT_FACTOR_SCOPE
  2662. *
  2663. * [C++ only] Macro used to declare an instance of the
  2664. * class xtests::c::cpp::xtest_floatingpoint_factor_scope, which causes the
  2665. * floating point factor to be set to a new value for the lifetime of the
  2666. * object, and then returned to its prior value
  2667. <pre>
  2668. XTESTS_TEST_FLOATINGPOINT_NOT_EQUAL(5.05, 5.06);
  2669. XTESTS_FLOATINGPOINT_FACTOR_SCOPE factor_scoper(1.1); // highly permissive factor
  2670. XTESTS_TEST_FLOATINGPOINT_EQUAL(5.05, 5.06);
  2671. </pre>
  2672. */
  2673. # define XTESTS_FLOATINGPOINT_FACTOR_SCOPE XTESTS_NS_CPP_QUAL(xtest_floatingpoint_factor_scope)
  2674. # ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  2675. template <typename T>
  2676. struct xtests_failure_reporter;
  2677. template <>
  2678. struct xtests_failure_reporter<int>
  2679. {
  2680. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, int expected, int actual, xtests_comparison_t comp)
  2681. {
  2682. stlsoft_static_cast(void, xtests_testFailed_int(file, line, function, expr, expected, actual, comp));
  2683. }
  2684. };
  2685. template <>
  2686. struct xtests_failure_reporter<unsigned int>
  2687. {
  2688. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, unsigned int expected, unsigned int actual, xtests_comparison_t comp)
  2689. {
  2690. stlsoft_static_cast(void, xtests_testFailed_ulong(file, line, function, expr, static_cast<unsigned long>(expected), static_cast<unsigned long>(actual), comp));
  2691. }
  2692. };
  2693. template <>
  2694. struct xtests_failure_reporter<signed char>
  2695. {
  2696. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, signed char expected, signed char actual, xtests_comparison_t comp)
  2697. {
  2698. stlsoft_static_cast(void, xtests_failure_reporter<int>::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp));
  2699. }
  2700. };
  2701. template <>
  2702. struct xtests_failure_reporter<unsigned char>
  2703. {
  2704. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, unsigned char expected, unsigned char actual, xtests_comparison_t comp)
  2705. {
  2706. stlsoft_static_cast(void, xtests_failure_reporter<int>::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp));
  2707. }
  2708. };
  2709. template <>
  2710. struct xtests_failure_reporter<short>
  2711. {
  2712. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, int expected, int actual, xtests_comparison_t comp)
  2713. {
  2714. stlsoft_static_cast(void, xtests_failure_reporter<int>::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp));
  2715. }
  2716. };
  2717. template <>
  2718. struct xtests_failure_reporter<unsigned short>
  2719. {
  2720. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, int expected, int actual, xtests_comparison_t comp)
  2721. {
  2722. stlsoft_static_cast(void, xtests_failure_reporter<int>::xtests_report_failure_equal(file, line, function, expr, int(expected), int(actual), comp));
  2723. }
  2724. };
  2725. #ifdef STLSOFT_CF_SHORT_DISTINCT_INT_TYPE
  2726. template <>
  2727. struct xtests_failure_reporter<stlsoft::sint16_t>
  2728. {
  2729. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::sint16_t expected, stlsoft::sint16_t actual, xtests_comparison_t comp)
  2730. {
  2731. stlsoft_static_cast(void, xtests_testFailed_int(file, line, function, expr, int(expected), int(actual), comp));
  2732. }
  2733. };
  2734. template <>
  2735. struct xtests_failure_reporter<stlsoft::uint16_t>
  2736. {
  2737. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::uint16_t expected, stlsoft::uint16_t actual, xtests_comparison_t comp)
  2738. {
  2739. stlsoft_static_cast(void, xtests_testFailed_int(file, line, function, expr, int(expected), int(actual), comp));
  2740. }
  2741. };
  2742. #endif /* STLSOFT_CF_SHORT_DISTINCT_INT_TYPE */
  2743. #ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE
  2744. template <>
  2745. struct xtests_failure_reporter<stlsoft::sint32_t>
  2746. {
  2747. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::sint32_t expected, stlsoft::sint32_t actual, xtests_comparison_t comp)
  2748. {
  2749. stlsoft_static_cast(void, xtests_testFailed_int(file, line, function, expr, int(expected), int(actual), comp));
  2750. }
  2751. };
  2752. template <>
  2753. struct xtests_failure_reporter<stlsoft::uint32_t>
  2754. {
  2755. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::uint32_t expected, stlsoft::uint32_t actual, xtests_comparison_t comp)
  2756. {
  2757. stlsoft_static_cast(void, xtests_testFailed_int(file, line, function, expr, int(expected), int(actual), comp));
  2758. }
  2759. };
  2760. #endif /* STLSOFT_CF_INT_DISTINCT_INT_TYPE */
  2761. template <>
  2762. struct xtests_failure_reporter<long>
  2763. {
  2764. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, long expected, long actual, xtests_comparison_t comp)
  2765. {
  2766. stlsoft_static_cast(void, xtests_testFailed_long(file, line, function, expr, expected, actual, comp));
  2767. }
  2768. };
  2769. template <>
  2770. struct xtests_failure_reporter<unsigned long>
  2771. {
  2772. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, unsigned long expected, unsigned long actual, xtests_comparison_t comp)
  2773. {
  2774. stlsoft_static_cast(void, xtests_testFailed_ulong(file, line, function, expr, expected, actual, comp));
  2775. }
  2776. };
  2777. # ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  2778. template <>
  2779. struct xtests_failure_reporter< stlsoft_ns_qual(ss_sint64_t)>
  2780. {
  2781. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::sint64_t expected, stlsoft::sint64_t actual, xtests_comparison_t comp)
  2782. {
  2783. stlsoft_static_cast(void, xtests_testFailed_longlong(file, line, function, expr, expected, actual, comp));
  2784. }
  2785. };
  2786. template <>
  2787. struct xtests_failure_reporter< stlsoft_ns_qual(ss_uint64_t)>
  2788. {
  2789. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, stlsoft::uint64_t expected, stlsoft::uint64_t actual, xtests_comparison_t comp)
  2790. {
  2791. stlsoft_static_cast(void, xtests_testFailed_ulonglong(file, line, function, expr, expected, actual, comp));
  2792. }
  2793. };
  2794. # endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  2795. template <>
  2796. struct xtests_failure_reporter<bool>
  2797. {
  2798. static void xtests_report_failure_equal(char const* file, int line, char const* function, char const* expr, int expected, int actual, xtests_comparison_t comp)
  2799. {
  2800. stlsoft_static_cast(void, xtests_testFailed_boolean(file, line, function, expr, expected, actual, comp));
  2801. }
  2802. };
  2803. template<
  2804. typename T1
  2805. , typename T2
  2806. >
  2807. struct xtests_integer_failure_reporter_selector
  2808. {
  2809. private:
  2810. enum { are_types_same = (0 != stlsoft::is_same_type<T1, T2>::value) };
  2811. enum { T1_is_larger_than_T2 = sizeof(T1) > sizeof(T2) };
  2812. typedef typename stlsoft::select_first_type_if< T1
  2813. , T2
  2814. , T1_is_larger_than_T2
  2815. >::type larger_type_;
  2816. public:
  2817. typedef xtests_failure_reporter<larger_type_> type;
  2818. };
  2819. template<
  2820. typename I1
  2821. , typename I2
  2822. >
  2823. inline
  2824. void
  2825. xtests_reportFailedIntegerComparison(
  2826. char const* file
  2827. , int line
  2828. , char const* function
  2829. , char const* expr
  2830. , I1 const& expected
  2831. , I2 const& actual
  2832. , xtests_comparison_t comp
  2833. )
  2834. {
  2835. STLSOFT_STATIC_ASSERT(0 != stlsoft::is_integral_type<I1>::value);
  2836. STLSOFT_STATIC_ASSERT(0 != stlsoft::is_integral_type<I2>::value);
  2837. # if defined(STLSOFT_COMPILER_IS_BORLAND)
  2838. xtests_integer_failure_reporter_selector<I1, I2>::type::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
  2839. # else /* ? compiler */
  2840. typedef typename xtests_integer_failure_reporter_selector<I1, I2>::type failure_reporter_t;
  2841. failure_reporter_t::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
  2842. # endif /* compiler */
  2843. }
  2844. #if defined(STLSOFT_COMPILER_IS_MSVC) && \
  2845. _MSC_VER >= 1310 && \
  2846. !defined(_WIN64) && \
  2847. defined(_Wp64)
  2848. /* This special overload is to allow for cases such as:
  2849. *
  2850. * XTESTS_TEST_INTEGER_EQUAL(4u, sink.size());
  2851. */
  2852. inline
  2853. void
  2854. xtests_reportFailedIntegerComparison(
  2855. char const* file
  2856. , int line
  2857. , char const* function
  2858. , char const* expr
  2859. , unsigned int expected
  2860. , size_t actual
  2861. , xtests_comparison_t comp
  2862. )
  2863. {
  2864. stlsoft_static_cast(void, xtests_testFailed_ulong(file, line, function, expr, static_cast<unsigned long>(expected), static_cast<unsigned long>(actual), comp));
  2865. }
  2866. #endif
  2867. inline
  2868. void
  2869. xtests_reportFailedIntegerComparison(
  2870. char const* file
  2871. , int line
  2872. , char const* function
  2873. , char const* expr
  2874. , bool expected
  2875. , bool actual
  2876. , xtests_comparison_t comp
  2877. )
  2878. {
  2879. # if defined(STLSOFT_COMPILER_IS_BORLAND)
  2880. xtests_integer_failure_reporter_selector<bool, bool>::type::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
  2881. # else /* ? compiler */
  2882. typedef xtests_integer_failure_reporter_selector<bool, bool>::type failure_reporter_t;
  2883. failure_reporter_t::xtests_report_failure_equal(file, line, function, expr, expected, actual, comp);
  2884. # endif /* compiler */
  2885. }
  2886. #if 0
  2887. inline
  2888. void
  2889. xtests_reportFailedIntegerComparison(
  2890. char const* file
  2891. , int line
  2892. , char const* function
  2893. , char const* expr
  2894. , int expected
  2895. , bool actual
  2896. , xtests_comparison_t comp
  2897. )
  2898. {
  2899. xtests_reportFailedIntegerComparison(file, line, function, expr, 0 != expected, actual, comp);
  2900. }
  2901. #endif /* 0 */
  2902. inline
  2903. void
  2904. xtests_reportFailedFloatingPointComparison(
  2905. char const* file
  2906. , int line
  2907. , char const* function
  2908. , char const* expr
  2909. , double const& expected
  2910. , double const& actual
  2911. , xtests_comparison_t comp
  2912. )
  2913. {
  2914. stlsoft_static_cast(void, xtests_testFailed_double(file, line, function, expr, expected, actual, comp));
  2915. }
  2916. template<
  2917. typename I
  2918. , typename II
  2919. >
  2920. inline
  2921. int
  2922. xtests_test_integer_compare_to_range_(
  2923. char const* /* file */
  2924. , int /* line */
  2925. , char const* /* function */
  2926. , char const* /* expr */
  2927. , II begin
  2928. , II end
  2929. , I const& actual
  2930. , xtests_comparison_t comp
  2931. )
  2932. {
  2933. for(; begin != end; ++begin)
  2934. {
  2935. I const& expected = *begin;
  2936. switch(comp)
  2937. {
  2938. case xtestsComparisonEqual:
  2939. case xtestsComparisonApproxEqual:
  2940. if(expected == actual)
  2941. {
  2942. return true;
  2943. }
  2944. break;
  2945. case xtestsComparisonNotEqual:
  2946. case xtestsComparisonApproxNotEqual:
  2947. if(expected != actual)
  2948. {
  2949. return true;
  2950. }
  2951. break;
  2952. case xtestsComparisonGreaterThan:
  2953. if(actual > expected)
  2954. {
  2955. return true;
  2956. }
  2957. break;
  2958. case xtestsComparisonLessThan:
  2959. if(actual < expected)
  2960. {
  2961. return true;
  2962. }
  2963. break;
  2964. case xtestsComparisonGreaterThanOrEqual:
  2965. if(actual >= expected)
  2966. {
  2967. return true;
  2968. }
  2969. break;
  2970. case xtestsComparisonLessThanOrEqual:
  2971. if(actual <= expected)
  2972. {
  2973. return true;
  2974. }
  2975. break;
  2976. default:
  2977. STLSOFT_MESSAGE_ASSERT("unrecognised enumerator", false);
  2978. case xtestsComparison_max_enumerator:
  2979. xtests_abend("invalid test comparison type: test framework may be out of date!");
  2980. break;
  2981. }
  2982. }
  2983. return false;
  2984. }
  2985. template<
  2986. typename I
  2987. , typename II
  2988. >
  2989. inline
  2990. int
  2991. xtests_test_integer_any_in_range(
  2992. char const* file
  2993. , int line
  2994. , char const* function
  2995. , char const* expr
  2996. , II begin
  2997. , II end
  2998. , I const& actual
  2999. , xtests_comparison_t comp
  3000. )
  3001. {
  3002. int comparisonSucceeded = xtests_test_integer_compare_to_range_(file, line, function, expr, begin, end, actual, comp);
  3003. if(comparisonSucceeded)
  3004. {
  3005. xtests_testPassed(file, line, function, expr);
  3006. }
  3007. else
  3008. {
  3009. #if 0
  3010. xtests_reportFailedIntegerComparison(file, line, function, expr, expected, actual, comp);
  3011. #else /* ? 0 */
  3012. xtests_testFailed(file, line, function, expr);
  3013. #endif /* 0 */
  3014. }
  3015. return comparisonSucceeded;
  3016. }
  3017. template<
  3018. typename I1
  3019. , typename I2
  3020. >
  3021. inline
  3022. int
  3023. xtests_test_integer(
  3024. char const* file
  3025. , int line
  3026. , char const* function
  3027. , char const* expr
  3028. , I1 const& expected
  3029. , I2 const& actual
  3030. , xtests_comparison_t comp
  3031. )
  3032. {
  3033. int comparisonSucceeded = false;
  3034. switch(comp)
  3035. {
  3036. case xtestsComparisonEqual:
  3037. case xtestsComparisonApproxEqual:
  3038. if(expected == actual)
  3039. {
  3040. comparisonSucceeded = true;
  3041. }
  3042. break;
  3043. case xtestsComparisonNotEqual:
  3044. case xtestsComparisonApproxNotEqual:
  3045. if(expected != actual)
  3046. {
  3047. comparisonSucceeded = true;
  3048. }
  3049. break;
  3050. case xtestsComparisonGreaterThan:
  3051. if(actual > expected)
  3052. {
  3053. comparisonSucceeded = true;
  3054. }
  3055. break;
  3056. case xtestsComparisonLessThan:
  3057. if(actual < expected)
  3058. {
  3059. comparisonSucceeded = true;
  3060. }
  3061. break;
  3062. case xtestsComparisonGreaterThanOrEqual:
  3063. if(actual >= expected)
  3064. {
  3065. comparisonSucceeded = true;
  3066. }
  3067. break;
  3068. case xtestsComparisonLessThanOrEqual:
  3069. if(actual <= expected)
  3070. {
  3071. comparisonSucceeded = true;
  3072. }
  3073. break;
  3074. default:
  3075. STLSOFT_MESSAGE_ASSERT("unrecognised enumerator", false);
  3076. case xtestsComparison_max_enumerator:
  3077. xtests_abend("invalid test comparison type: test framework may be out of date!");
  3078. break;
  3079. }
  3080. if(comparisonSucceeded)
  3081. {
  3082. xtests_testPassed(file, line, function, expr);
  3083. }
  3084. else
  3085. {
  3086. xtests_reportFailedIntegerComparison(file, line, function, expr, expected, actual, comp);
  3087. }
  3088. return comparisonSucceeded;
  3089. }
  3090. template<
  3091. typename I0
  3092. , typename I1
  3093. >
  3094. inline
  3095. int
  3096. xtests_test_integer_one_of(
  3097. char const* file
  3098. , int line
  3099. , char const* function
  3100. , char const* expr
  3101. , I1 const& actual
  3102. , I0 const& expected0
  3103. , I0 const& expected1
  3104. , I0 const& expected2
  3105. , I0 const& expected3
  3106. , I0 const& expected4
  3107. , I0 const& expected5
  3108. , I0 const& expected6
  3109. , I0 const& expected7
  3110. , xtests_comparison_t comp
  3111. )
  3112. {
  3113. I0 const range[] = {
  3114. expected0
  3115. , expected1
  3116. , expected2
  3117. , expected3
  3118. , expected4
  3119. , expected5
  3120. , expected6
  3121. , expected7
  3122. };
  3123. return xtests_test_integer_any_in_range(file, line, function, expr, &range[0], &range[0] + STLSOFT_NUM_ELEMENTS(range), actual, comp);
  3124. }
  3125. template<
  3126. typename I0
  3127. , typename I1
  3128. >
  3129. inline
  3130. int
  3131. xtests_test_integer_one_of(
  3132. char const* file
  3133. , int line
  3134. , char const* function
  3135. , char const* expr
  3136. , I1 const& actual
  3137. , I0 const& expected0
  3138. , I0 const& expected1
  3139. , I0 const& expected2
  3140. , I0 const& expected3
  3141. , I0 const& expected4
  3142. , I0 const& expected5
  3143. , I0 const& expected6
  3144. , xtests_comparison_t comp
  3145. )
  3146. {
  3147. return xtests_test_integer_one_of(
  3148. file, line, function, expr
  3149. , actual
  3150. , expected0, expected1, expected2, expected3, expected4, expected5, expected6, expected0
  3151. , comp
  3152. );
  3153. }
  3154. template<
  3155. typename I0
  3156. , typename I1
  3157. >
  3158. inline
  3159. int
  3160. xtests_test_integer_one_of(
  3161. char const* file
  3162. , int line
  3163. , char const* function
  3164. , char const* expr
  3165. , I1 const& actual
  3166. , I0 const& expected0
  3167. , I0 const& expected1
  3168. , I0 const& expected2
  3169. , I0 const& expected3
  3170. , I0 const& expected4
  3171. , I0 const& expected5
  3172. , xtests_comparison_t comp
  3173. )
  3174. {
  3175. return xtests_test_integer_one_of(
  3176. file, line, function, expr
  3177. , actual
  3178. , expected0, expected1, expected2, expected3, expected4, expected5, expected0, expected0
  3179. , comp
  3180. );
  3181. }
  3182. template<
  3183. typename I0
  3184. , typename I1
  3185. >
  3186. inline
  3187. int
  3188. xtests_test_integer_one_of(
  3189. char const* file
  3190. , int line
  3191. , char const* function
  3192. , char const* expr
  3193. , I1 const& actual
  3194. , I0 const& expected0
  3195. , I0 const& expected1
  3196. , I0 const& expected2
  3197. , I0 const& expected3
  3198. , I0 const& expected4
  3199. , xtests_comparison_t comp
  3200. )
  3201. {
  3202. return xtests_test_integer_one_of(
  3203. file, line, function, expr
  3204. , actual
  3205. , expected0, expected1, expected2, expected3, expected4, expected0, expected0, expected0
  3206. , comp
  3207. );
  3208. }
  3209. template<
  3210. typename I0
  3211. , typename I1
  3212. >
  3213. inline
  3214. int
  3215. xtests_test_integer_one_of(
  3216. char const* file
  3217. , int line
  3218. , char const* function
  3219. , char const* expr
  3220. , I1 const& actual
  3221. , I0 const& expected0
  3222. , I0 const& expected1
  3223. , I0 const& expected2
  3224. , I0 const& expected3
  3225. , xtests_comparison_t comp
  3226. )
  3227. {
  3228. return xtests_test_integer_one_of(
  3229. file, line, function, expr
  3230. , actual
  3231. , expected0, expected1, expected2, expected3, expected0, expected0, expected0, expected0
  3232. , comp
  3233. );
  3234. }
  3235. template<
  3236. typename I0
  3237. , typename I1
  3238. >
  3239. inline
  3240. int
  3241. xtests_test_integer_one_of(
  3242. char const* file
  3243. , int line
  3244. , char const* function
  3245. , char const* expr
  3246. , I1 const& actual
  3247. , I0 const& expected0
  3248. , I0 const& expected1
  3249. , I0 const& expected2
  3250. , xtests_comparison_t comp
  3251. )
  3252. {
  3253. return xtests_test_integer_one_of(
  3254. file, line, function, expr
  3255. , actual
  3256. , expected0, expected1, expected2, expected0, expected0, expected0, expected0, expected0
  3257. , comp
  3258. );
  3259. }
  3260. template<
  3261. typename I0
  3262. , typename I1
  3263. >
  3264. inline
  3265. int
  3266. xtests_test_integer_one_of(
  3267. char const* file
  3268. , int line
  3269. , char const* function
  3270. , char const* expr
  3271. , I1 const& actual
  3272. , I0 const& expected0
  3273. , I0 const& expected1
  3274. , xtests_comparison_t comp
  3275. )
  3276. {
  3277. return xtests_test_integer_one_of(
  3278. file, line, function, expr
  3279. , actual
  3280. , expected0, expected1, expected0, expected0, expected0, expected0, expected0, expected0
  3281. , comp
  3282. );
  3283. }
  3284. inline
  3285. int
  3286. xtests_test_character(
  3287. char const* file
  3288. , int line
  3289. , char const* function
  3290. , char const* expr
  3291. , char expected
  3292. , char actual
  3293. , xtests_comparison_t comp
  3294. )
  3295. {
  3296. return xtests_testCharactersA(file, line, function, expr, expected, actual, comp);
  3297. }
  3298. inline
  3299. int
  3300. xtests_test_character(
  3301. char const* file
  3302. , int line
  3303. , char const* function
  3304. , char const* expr
  3305. , wchar_t expected
  3306. , wchar_t actual
  3307. , xtests_comparison_t comp
  3308. )
  3309. {
  3310. return xtests_testCharactersW(file, line, function, expr, expected, actual, comp);
  3311. }
  3312. inline
  3313. int
  3314. xtests_test_floating_point(
  3315. char const* file
  3316. , int line
  3317. , char const* function
  3318. , char const* expr
  3319. , double const& expected
  3320. , double const& actual
  3321. , xtests_comparison_t comp
  3322. )
  3323. {
  3324. int comparisonSucceeded = false;
  3325. switch(comp)
  3326. {
  3327. case xtestsComparisonEqual:
  3328. if(expected == actual)
  3329. {
  3330. comparisonSucceeded = true;
  3331. }
  3332. break;
  3333. case xtestsComparisonApproxEqual:
  3334. if(xtests_floatingPointClose(expected, actual))
  3335. {
  3336. comparisonSucceeded = true;
  3337. }
  3338. break;
  3339. case xtestsComparisonNotEqual:
  3340. if(expected != actual)
  3341. {
  3342. comparisonSucceeded = true;
  3343. }
  3344. break;
  3345. case xtestsComparisonApproxNotEqual:
  3346. if(!xtests_floatingPointClose(expected, actual))
  3347. {
  3348. comparisonSucceeded = true;
  3349. }
  3350. break;
  3351. case xtestsComparisonGreaterThan:
  3352. if(actual > expected)
  3353. {
  3354. comparisonSucceeded = true;
  3355. }
  3356. break;
  3357. case xtestsComparisonLessThan:
  3358. if(actual < expected)
  3359. {
  3360. comparisonSucceeded = true;
  3361. }
  3362. break;
  3363. case xtestsComparisonGreaterThanOrEqual:
  3364. if(actual >= expected)
  3365. {
  3366. comparisonSucceeded = true;
  3367. }
  3368. break;
  3369. case xtestsComparisonLessThanOrEqual:
  3370. if(actual <= expected)
  3371. {
  3372. comparisonSucceeded = true;
  3373. }
  3374. break;
  3375. default:
  3376. STLSOFT_MESSAGE_ASSERT("unrecognised enumerator", false);
  3377. case xtestsComparison_max_enumerator:
  3378. xtests_abend("invalid test comparison type: test framework may be out of date!");
  3379. break;
  3380. }
  3381. if(comparisonSucceeded)
  3382. {
  3383. stlsoft_static_cast(void, xtests_testPassed(file, line, function, expr));
  3384. }
  3385. else
  3386. {
  3387. stlsoft_static_cast(void, xtests_reportFailedFloatingPointComparison(file, line, function, expr, expected, actual, comp));
  3388. }
  3389. return comparisonSucceeded;
  3390. }
  3391. # endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  3392. # ifndef _XTESTS_NO_NAMESPACE
  3393. } /* namespace cpp */
  3394. # endif /* !_XTESTS_NO_NAMESPACE */
  3395. #else /* __cplusplus && !_XTESTS_NO_CPP_API */
  3396. # define XTESTS_REQUIRE(test) XTESTS_NS_C_QUAL(xtests_require_C)(!(!(test)))
  3397. #endif /* __cplusplus) && !_XTESTS_NO_CPP_API */
  3398. /** [INTERNAL] Worker function for XTESTS_REQUIRE() (in C compilation units)
  3399. */
  3400. XTESTS_CALL(int)
  3401. xtests_require_C(
  3402. int success
  3403. );
  3404. /** [INTERNAL] Worker function
  3405. */
  3406. XTESTS_CALL(int)
  3407. xTests_hasRequiredConditionFailed(void);
  3408. /* /////////////////////////////////////////////////////////////////////////
  3409. * Helper functions
  3410. */
  3411. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  3412. XTESTS_CALL(int)
  3413. xtests_commandLine_parseVerbosity(
  3414. int argc
  3415. , char** argv
  3416. , int* verbosity
  3417. );
  3418. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  3419. /** \def XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, pverbosity)
  3420. *
  3421. * \ingroup group__xtests__utiliy_functions
  3422. *
  3423. * Parses a verbosity from the command-line
  3424. *
  3425. * Parse the verbosity from the command-line arguments, looking for an
  3426. * argument of the form "--verbosity=<N>", where N is a non-negative
  3427. * integer.
  3428. *
  3429. * \param argc The <code>argc</code> parameter passed into
  3430. * <code>main()</code>
  3431. * \param argv The <code>argv</code> parameter passed into
  3432. * <code>main()</code>
  3433. * \param pverbosity A pointer to an integer to receive the verbosity. Will
  3434. * be set to xtestsVerbositySummaryOnSuccess even if no verbosity argument
  3435. * is found. May not be NULL.
  3436. *
  3437. * \return The index of argument containing the verbosity, or 0 to indicate
  3438. * failure
  3439. */
  3440. #define XTESTS_COMMANDLINE_PARSEVERBOSITY(argc, argv, pverbosity) \
  3441. \
  3442. stlsoft_static_cast(void, XTESTS_NS_C_QUAL(xtests_commandLine_parseVerbosity)((argc), (argv), (pverbosity)))
  3443. /* /////////////////////////////////////////////////////////////////////////
  3444. * Obsolete names
  3445. */
  3446. #ifndef XTESTS_DOCUMENTATION_SKIP_SECTION
  3447. # define XTESTS_FAIL_WITH_QUALIFIER(msg, qualifier) XTESTS_TEST_FAIL_WITH_QUALIFIER(msg, qualifier)
  3448. # define XTESTS_FAIL(msg) XTESTS_TEST_FAIL(msg)
  3449. # define XTESTS_PASSED() XTESTS_TEST_PASSED()
  3450. # define XTESTS_TEST_MULTIBYTE_STRINGS_EQUAL XTESTS_TEST_MULTIBYTE_STRING_EQUAL
  3451. #endif /* !XTESTS_DOCUMENTATION_SKIP_SECTION */
  3452. /* /////////////////////////////////////////////////////////////////////////
  3453. * Namespace
  3454. */
  3455. #ifndef _XTESTS_NO_NAMESPACE
  3456. } /* namespace c */
  3457. } /* namespace xtests */
  3458. #endif /* !_XTESTS_NO_NAMESPACE */
  3459. /* ////////////////////////////////////////////////////////////////////// */
  3460. #endif /* !XTESTS_INCL_XTESTS_H_XTESTS */
  3461. /* ///////////////////////////// end of file //////////////////////////// */