cstring_comparison_op.hpp 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 C string comparison with enhanced reporting
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_TOOLS_CSTRING_COMPARISON_OP_HPP_050815GER
  11. #define BOOST_TEST_TOOLS_CSTRING_COMPARISON_OP_HPP_050815GER
  12. // Boost.Test
  13. #include <boost/test/tools/assertion.hpp>
  14. #include <boost/test/utils/is_cstring.hpp>
  15. #include <boost/test/utils/basic_cstring/compare.hpp>
  16. // Boost
  17. #include <boost/utility/enable_if.hpp>
  18. #include <boost/test/detail/suppress_warnings.hpp>
  19. //____________________________________________________________________________//
  20. namespace boost {
  21. namespace test_tools {
  22. namespace assertion {
  23. namespace op {
  24. // ************************************************************************** //
  25. // ************** string_compare ************** //
  26. // ************************************************************************** //
  27. #define DEFINE_CSTRING_COMPARISON( oper, name, rev, name_inverse ) \
  28. template<typename Lhs,typename Rhs> \
  29. struct name<Lhs,Rhs,typename boost::enable_if_c< \
  30. ( unit_test::is_cstring_comparable<Lhs>::value \
  31. && unit_test::is_cstring_comparable<Rhs>::value) \
  32. >::type > \
  33. { \
  34. typedef typename unit_test::deduce_cstring_transform<Lhs>::type lhs_char_type; \
  35. typedef typename unit_test::deduce_cstring_transform<Rhs>::type rhs_char_type; \
  36. public: \
  37. typedef assertion_result result_type; \
  38. typedef name_inverse<Lhs, Rhs> inverse; \
  39. \
  40. typedef name< \
  41. typename lhs_char_type::value_type, \
  42. typename rhs_char_type::value_type> elem_op; \
  43. \
  44. static bool \
  45. eval( Lhs const& lhs, Rhs const& rhs) \
  46. { \
  47. return lhs_char_type(lhs) oper rhs_char_type(rhs); \
  48. } \
  49. \
  50. template<typename PrevExprType> \
  51. static void \
  52. report( std::ostream& ostr, \
  53. PrevExprType const& lhs, \
  54. Rhs const& rhs) \
  55. { \
  56. lhs.report( ostr ); \
  57. ostr << revert() \
  58. << tt_detail::print_helper( rhs ); \
  59. } \
  60. \
  61. static char const* forward() \
  62. { return " " #oper " "; } \
  63. static char const* revert() \
  64. { return " " #rev " "; } \
  65. }; \
  66. /**/
  67. BOOST_TEST_FOR_EACH_COMP_OP( DEFINE_CSTRING_COMPARISON )
  68. #undef DEFINE_CSTRING_COMPARISON
  69. //____________________________________________________________________________//
  70. } // namespace op
  71. } // namespace assertion
  72. } // namespace test_tools
  73. } // namespace boost
  74. #include <boost/test/detail/enable_warnings.hpp>
  75. #endif // BOOST_TEST_TOOLS_CSTRING_COMPARISON_OP_HPP_050815GER