global_typedef.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. //!@file
  8. //!@brief some trivial global typedefs
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_GLOBAL_TYPEDEF_HPP_021005GER
  11. #define BOOST_TEST_GLOBAL_TYPEDEF_HPP_021005GER
  12. #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
  13. #define BOOST_TEST_L( s ) ::boost::unit_test::const_string( s, sizeof( s ) - 1 )
  14. #define BOOST_TEST_STRINGIZE( s ) BOOST_TEST_L( BOOST_STRINGIZE( s ) )
  15. #define BOOST_TEST_EMPTY_STRING BOOST_TEST_L( "" )
  16. #include <boost/test/detail/suppress_warnings.hpp>
  17. //____________________________________________________________________________//
  18. namespace boost {
  19. namespace unit_test {
  20. typedef unsigned long counter_t;
  21. //____________________________________________________________________________//
  22. enum report_level { INV_REPORT_LEVEL, CONFIRMATION_REPORT, SHORT_REPORT, DETAILED_REPORT, NO_REPORT };
  23. //____________________________________________________________________________//
  24. //! Indicates the output format for the loggers or the test tree printing
  25. enum output_format { OF_INVALID,
  26. OF_CLF, ///< compiler log format
  27. OF_XML, ///< XML format for report and log,
  28. OF_JUNIT, ///< JUNIT format for report and log,
  29. OF_CUSTOM_LOGGER, ///< User specified logger.
  30. OF_DOT ///< dot format for output content
  31. };
  32. //____________________________________________________________________________//
  33. enum test_unit_type { TUT_CASE = 0x01, TUT_SUITE = 0x10, TUT_ANY = 0x11 };
  34. //____________________________________________________________________________//
  35. enum assertion_result { AR_FAILED, AR_PASSED, AR_TRIGGERED };
  36. //____________________________________________________________________________//
  37. typedef unsigned long test_unit_id;
  38. const test_unit_id INV_TEST_UNIT_ID = 0xFFFFFFFF;
  39. const test_unit_id MAX_TEST_CASE_ID = 0xFFFFFFFE;
  40. const test_unit_id MIN_TEST_CASE_ID = 0x00010000;
  41. const test_unit_id MAX_TEST_SUITE_ID = 0x0000FF00;
  42. const test_unit_id MIN_TEST_SUITE_ID = 0x00000001;
  43. //____________________________________________________________________________//
  44. namespace ut_detail {
  45. inline test_unit_type
  46. test_id_2_unit_type( test_unit_id id )
  47. {
  48. return (id & 0xFFFF0000) != 0 ? TUT_CASE : TUT_SUITE;
  49. }
  50. //! Helper class for restoring the current test unit ID in a RAII manner
  51. struct test_unit_id_restore {
  52. test_unit_id_restore(test_unit_id& to_restore_, test_unit_id new_value)
  53. : to_restore(to_restore_)
  54. , bkup(to_restore_) {
  55. to_restore = new_value;
  56. }
  57. ~test_unit_id_restore() {
  58. to_restore = bkup;
  59. }
  60. private:
  61. test_unit_id& to_restore;
  62. test_unit_id bkup;
  63. };
  64. //____________________________________________________________________________//
  65. } // namespace ut_detail
  66. // helper templates to prevent ODR violations
  67. template<class T>
  68. struct static_constant {
  69. static T value;
  70. };
  71. template<class T>
  72. T static_constant<T>::value;
  73. //____________________________________________________________________________//
  74. // helper defines for singletons.
  75. // BOOST_TEST_SINGLETON_CONS should appear in the class body,
  76. // BOOST_TEST_SINGLETON_CONS_IMPL should be in only one translation unit. The
  77. // global instance should be declared by BOOST_TEST_SINGLETON_INST.
  78. #define BOOST_TEST_SINGLETON_CONS_NO_CTOR( type ) \
  79. public: \
  80. static type& instance(); \
  81. private: \
  82. BOOST_DELETED_FUNCTION(type(type const&)) \
  83. BOOST_DELETED_FUNCTION(type& operator=(type const&)) \
  84. BOOST_DEFAULTED_FUNCTION(~type(), {}) \
  85. /**/
  86. #define BOOST_TEST_SINGLETON_CONS( type ) \
  87. BOOST_TEST_SINGLETON_CONS_NO_CTOR(type) \
  88. private: \
  89. BOOST_DEFAULTED_FUNCTION(type(), {}) \
  90. /**/
  91. #define BOOST_TEST_SINGLETON_CONS_IMPL( type ) \
  92. type& type::instance() { \
  93. static type the_inst; return the_inst; \
  94. } \
  95. /**/
  96. //____________________________________________________________________________//
  97. #if defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ < 4
  98. #define BOOST_TEST_SINGLETON_INST( inst ) \
  99. static BOOST_JOIN( inst, _t)& inst BOOST_ATTRIBUTE_UNUSED = BOOST_JOIN (inst, _t)::instance();
  100. #else
  101. #define BOOST_TEST_SINGLETON_INST( inst ) \
  102. namespace { BOOST_JOIN( inst, _t)& inst BOOST_ATTRIBUTE_UNUSED = BOOST_JOIN( inst, _t)::instance(); }
  103. #endif
  104. } // namespace unit_test
  105. } // namespace boost
  106. //____________________________________________________________________________//
  107. #include <boost/test/detail/enable_warnings.hpp>
  108. #endif // BOOST_TEST_GLOBAL_TYPEDEF_HPP_021005GER