File indexing completed on 2025-01-18 09:52:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_TOOLS_IMPL_COMMON_HPP_012705GER
0016 #define BOOST_TEST_TOOLS_IMPL_COMMON_HPP_012705GER
0017
0018
0019 #include <boost/test/detail/config.hpp>
0020 #include <boost/test/detail/global_typedef.hpp>
0021
0022
0023 #include <boost/mpl/or.hpp>
0024 #include <boost/static_assert.hpp>
0025 #include <boost/type_traits/is_array.hpp>
0026 #include <boost/type_traits/is_function.hpp>
0027 #include <boost/type_traits/is_abstract.hpp>
0028 #include <boost/type_traits/has_left_shift.hpp>
0029
0030 #include <ios>
0031 #include <iostream>
0032 #include <limits>
0033
0034 #if !defined(BOOST_NO_CXX11_NULLPTR)
0035 #include <cstddef>
0036 #endif
0037
0038 #include <boost/test/detail/suppress_warnings.hpp>
0039
0040
0041
0042 namespace boost {
0043 namespace test_tools {
0044 namespace tt_detail {
0045
0046
0047
0048
0049
0050 namespace impl {
0051 template <class T>
0052 std::ostream& boost_test_print_type(std::ostream& ostr, T const& t) {
0053 BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
0054 "Type has to implement operator<< to be printable");
0055 ostr << t;
0056 return ostr;
0057 }
0058
0059 struct boost_test_print_type_impl {
0060 template <class R>
0061 std::ostream& operator()(std::ostream& ostr, R const& r) const {
0062 return boost_test_print_type(ostr, r);
0063 }
0064 };
0065 }
0066
0067
0068 template <class T> struct static_const { static const T value; };
0069 template <class T> const T static_const<T>::value = T();
0070
0071 namespace {
0072 static const impl::boost_test_print_type_impl& boost_test_print_type =
0073 static_const<impl::boost_test_print_type_impl>::value;
0074 }
0075
0076
0077
0078
0079
0080
0081 template<typename T>
0082 struct print_log_value {
0083 void operator()( std::ostream& ostr, T const& t )
0084 {
0085 typedef typename mpl::or_<is_array<T>,is_function<T>,is_abstract<T> >::type cant_use_nl;
0086
0087 std::streamsize old_precision = set_precision( ostr, cant_use_nl() );
0088
0089
0090 using boost::test_tools::tt_detail::boost_test_print_type;
0091 boost_test_print_type(ostr, t);
0092
0093 if( old_precision != (std::streamsize)-1 )
0094 ostr.precision( old_precision );
0095 }
0096
0097 std::streamsize set_precision( std::ostream& ostr, mpl::false_ )
0098 {
0099 if( std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::radix == 2 )
0100 return ostr.precision( 2 + std::numeric_limits<T>::digits * 301/1000 );
0101 else if ( std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::radix == 10 ) {
0102 #ifdef BOOST_NO_CXX11_NUMERIC_LIMITS
0103
0104
0105
0106 return ostr.precision( 2 + std::numeric_limits<T>::digits10 );
0107 #else
0108
0109
0110 return ostr.precision( std::numeric_limits<T>::max_digits10 );
0111 #endif
0112 }
0113
0114
0115 return (std::streamsize)-1;
0116 }
0117
0118 std::streamsize set_precision( std::ostream&, mpl::true_ ) { return (std::streamsize)-1; }
0119 };
0120
0121
0122
0123 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0124 template<typename T, std::size_t N >
0125 struct print_log_value< T[N] > {
0126 void operator()( std::ostream& ostr, T const* t )
0127 {
0128 ostr << t;
0129 }
0130 };
0131 #endif
0132
0133
0134
0135 template<>
0136 struct BOOST_TEST_DECL print_log_value<bool> {
0137 void operator()( std::ostream& ostr, bool t );
0138 };
0139
0140
0141
0142 template<>
0143 struct BOOST_TEST_DECL print_log_value<char> {
0144 void operator()( std::ostream& ostr, char t );
0145 };
0146
0147
0148
0149 template<>
0150 struct BOOST_TEST_DECL print_log_value<unsigned char> {
0151 void operator()( std::ostream& ostr, unsigned char t );
0152 };
0153
0154
0155
0156 template<>
0157 struct BOOST_TEST_DECL print_log_value<wchar_t> {
0158 void operator()( std::ostream& ostr, wchar_t t );
0159 };
0160
0161
0162
0163 template<>
0164 struct BOOST_TEST_DECL print_log_value<char const*> {
0165 void operator()( std::ostream& ostr, char const* t );
0166 };
0167
0168
0169
0170 template<>
0171 struct BOOST_TEST_DECL print_log_value<wchar_t const*> {
0172 void operator()( std::ostream& ostr, wchar_t const* t );
0173 };
0174
0175 #if !defined(BOOST_NO_CXX11_NULLPTR)
0176 template<>
0177 struct print_log_value<std::nullptr_t> {
0178
0179 void operator()( std::ostream& ostr, std::nullptr_t ) {
0180 ostr << "nullptr";
0181 }
0182 };
0183 #endif
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 template<typename T>
0194 struct print_helper_t {
0195 explicit print_helper_t( T const& t ) : m_t( t ) {}
0196
0197 T const& m_t;
0198 };
0199
0200
0201
0202 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0203
0204 template<typename T, std::size_t N >
0205 struct print_helper_t< T[N] > {
0206 explicit print_helper_t( T const * t ) : m_t( t ) {}
0207
0208 T const * m_t;
0209 };
0210 #endif
0211
0212
0213
0214 template<typename T>
0215 inline print_helper_t<T>
0216 print_helper( T const& t )
0217 {
0218 return print_helper_t<T>( t );
0219 }
0220
0221
0222
0223 template<typename T>
0224 inline std::ostream&
0225 operator<<( std::ostream& ostr, print_helper_t<T> const& ph )
0226 {
0227 print_log_value<T>()( ostr, ph.m_t );
0228
0229 return ostr;
0230 }
0231
0232
0233
0234 }
0235
0236
0237
0238
0239
0240 #define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \
0241 namespace boost{ namespace test_tools{ namespace tt_detail{ \
0242 template<> \
0243 struct print_log_value<the_type > { \
0244 void operator()( std::ostream&, the_type const& ) {} \
0245 }; \
0246 }}} \
0247
0248
0249 }
0250 }
0251
0252 #include <boost/test/detail/enable_warnings.hpp>
0253
0254 #endif