check_type.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // (C) Copyright John Maddock 2000.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_CHECK_TYPE_HPP
  6. #define BOOST_CHECK_TYPE_HPP
  7. #include "test.hpp"
  8. #include <boost/type_traits/is_same.hpp>
  9. /*
  10. macro:
  11. BOOST_CHECK_TYPE(type_expression, expected_type)
  12. type_expression: an expression that evaluates to a typename.
  13. expected_value: the type we expect to find.
  14. */
  15. #ifdef __BORLANDC__
  16. #pragma option -w-8008 -w-8066 -w-8019
  17. #endif
  18. #define BOOST_CHECK_TYPE(type_expression, expected_type)\
  19. do{\
  20. if(!::boost::is_same< type_expression, expected_type >::value){\
  21. BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression)\
  22. << "\" did not have the expected type:\n\tevaluating: boost::is_same<"\
  23. << BOOST_STRINGIZE(type_expression) << ", " << BOOST_STRINGIZE(expected_type)\
  24. << ">" << "\n\tfound: "\
  25. << typeid(::boost::is_same< type_expression, expected_type >).name());\
  26. }else\
  27. BOOST_CHECK_MESSAGE(true, "Validating Type Expression: \""\
  28. << BOOST_STRINGIZE(expression) << "\"");\
  29. }while(0)
  30. #define BOOST_CHECK_TYPE3(type_expression, type_expression_suffix, expected_type)\
  31. do{\
  32. if(!::boost::is_same< type_expression, type_expression_suffix, expected_type >::value){\
  33. BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression)\
  34. << "\" did not have the expected type:\n\tevaluating: boost::is_same<"\
  35. << BOOST_STRINGIZE((type_expression, type_expression_suffix)) << ", " << BOOST_STRINGIZE(expected_type)\
  36. << ">" << "\n\tfound: "\
  37. << typeid(::boost::is_same< type_expression, type_expression_suffix, expected_type >).name());\
  38. }else\
  39. BOOST_CHECK_MESSAGE(true, "Validating Type Expression: \""\
  40. << BOOST_STRINGIZE(expression) << "\"");\
  41. }while(0)
  42. #define BOOST_CHECK_TYPE4(type_expression, suffix1, suffix2, expected_type)\
  43. do{\
  44. if(!::boost::is_same< type_expression, suffix1, suffix2, expected_type >::value){\
  45. BOOST_CHECK_MESSAGE(false, "The expression: \"" << BOOST_STRINGIZE(expression)\
  46. << "\" did not have the expected type:\n\tevaluating: boost::is_same<"\
  47. << BOOST_STRINGIZE((type_expression, suffix1, suffix2)) << ", " << BOOST_STRINGIZE(expected_type)\
  48. << ">" << "\n\tfound: "\
  49. << typeid(::boost::is_same< type_expression, suffix1, suffix2, expected_type >).name());\
  50. }else\
  51. BOOST_CHECK_MESSAGE(true, "Validating Type Expression: \""\
  52. << BOOST_STRINGIZE(expression) << "\"");\
  53. }while(0)
  54. #endif