cstring_comparison_op.hpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 ) \
  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. \
  39. typedef name< \
  40. typename lhs_char_type::value_type, \
  41. typename rhs_char_type::value_type> elem_op; \
  42. \
  43. static bool \
  44. eval( Lhs const& lhs, Rhs const& rhs) \
  45. { \
  46. return lhs_char_type(lhs) oper rhs_char_type(rhs); \
  47. } \
  48. \
  49. template<typename PrevExprType> \
  50. static void \
  51. report( std::ostream& ostr, \
  52. PrevExprType const& lhs, \
  53. Rhs const& rhs) \
  54. { \
  55. lhs.report( ostr ); \
  56. ostr << revert() \
  57. << tt_detail::print_helper( rhs ); \
  58. } \
  59. \
  60. static char const* revert() \
  61. { return " " #rev " "; } \
  62. }; \
  63. /**/
  64. BOOST_TEST_FOR_EACH_COMP_OP( DEFINE_CSTRING_COMPARISON )
  65. #undef DEFINE_CSTRING_COMPARISON
  66. //____________________________________________________________________________//
  67. } // namespace op
  68. } // namespace assertion
  69. } // namespace test_tools
  70. } // namespace boost
  71. #include <boost/test/detail/enable_warnings.hpp>
  72. #endif // BOOST_TEST_TOOLS_CSTRING_COMPARISON_OP_HPP_050815GER