diff --git a/src/libraries/turtle/log.hpp b/src/libraries/turtle/log.hpp index 91d29a7..b8c8d3e 100644 --- a/src/libraries/turtle/log.hpp +++ b/src/libraries/turtle/log.hpp @@ -143,13 +143,13 @@ namespace detail const T* t_; }; - struct any + struct data { template< typename T > - any( const T& t ) + data( const T& t ) : h_( new holder_imp< T >( t ) ) {} - ~any() + ~data() { delete h_; } @@ -157,7 +157,7 @@ namespace detail }; } - stream& operator<<( stream& s, const detail::any& d ) + stream& operator<<( stream& s, const detail::data& d ) { d.h_->serialize( *s.s_ ); return s; @@ -165,7 +165,7 @@ namespace detail #else // MOCK_LOG_CONVERSIONS -namespace detail +namespace detail4 { template< typename S, typename T > S& operator<<( S &s, const T& ) @@ -177,7 +177,7 @@ namespace detail template< typename T > void serialize( std::ostream& s, const T& t ) { - using namespace detail; + using namespace detail4; s << t; } diff --git a/src/tests/turtle_test/log_with_conversions_test.cpp b/src/tests/turtle_test/log_with_conversions_test.cpp index 9471608..75cbb16 100644 --- a/src/tests/turtle_test/log_with_conversions_test.cpp +++ b/src/tests/turtle_test/log_with_conversions_test.cpp @@ -470,3 +470,49 @@ BOOST_AUTO_TEST_CASE( type_can_use_format_when_streamed_with_conversions ) { BOOST_CHECK_EQUAL( "\"string\"", to_string( streamed_using_format() ) ); } + +namespace mock +{ +namespace detail +{ + template< typename T > + struct template_serializable + {}; + template< typename T > + std::ostream& operator<<( std::ostream& s, const template_serializable< T >& ) + { + return s << "mock::detail::template_serializable"; + } +} +} + +BOOST_AUTO_TEST_CASE( mock_detail_template_type_serializable_yields_its_value_when_serialized_with_conversions ) +{ + BOOST_CHECK_EQUAL( "mock::detail::template_serializable", to_string( mock::detail::template_serializable< int >() ) ); +} + +namespace mock +{ +namespace detail +{ + template< typename T > + struct template_streamable + {}; + template< typename T > + std::ostream& operator<<( std::ostream& s, const template_streamable< T >& ) + { + BOOST_FAIL( "should not have been called" ); + return s; + } + template< typename T > + mock::stream& operator<<( mock::stream& s, const template_streamable< T >& ) + { + return s << "mock::detail::template_streamable"; + } +} +} + +BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_when_serialized_with_conversions ) +{ + BOOST_CHECK_EQUAL( "mock::detail::template_streamable", to_string( mock::detail::template_streamable< int >() ) ); +} diff --git a/src/tests/turtle_test/log_without_conversions_test.cpp b/src/tests/turtle_test/log_without_conversions_test.cpp index f25ebab..0638d82 100644 --- a/src/tests/turtle_test/log_without_conversions_test.cpp +++ b/src/tests/turtle_test/log_without_conversions_test.cpp @@ -466,3 +466,49 @@ BOOST_AUTO_TEST_CASE( type_can_use_format_when_streamed_without_conversions ) { BOOST_CHECK_EQUAL( "\"string\"", to_string( streamed_using_format() ) ); } + +namespace mock +{ +namespace detail +{ + template< typename T > + struct template_serializable + {}; + template< typename T > + std::ostream& operator<<( std::ostream& s, const template_serializable< T >& ) + { + return s << "mock::detail::template_serializable"; + } +} +} + +BOOST_AUTO_TEST_CASE( mock_detail_template_type_serializable_yields_its_value_when_serialized_without_conversions ) +{ + BOOST_CHECK_EQUAL( "mock::detail::template_serializable", to_string( mock::detail::template_serializable< int >() ) ); +} + +namespace mock +{ +namespace detail +{ + template< typename T > + struct template_streamable + {}; + template< typename T > + std::ostream& operator<<( std::ostream& s, const template_streamable< T >& ) + { + BOOST_FAIL( "should not have been called" ); + return s; + } + template< typename T > + mock::stream& operator<<( mock::stream& s, const template_streamable< T >& ) + { + return s << "mock::detail::template_streamable"; + } +} +} + +BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_when_serialized_without_conversions ) +{ + BOOST_CHECK_EQUAL( "mock::detail::template_streamable", to_string( mock::detail::template_streamable< int >() ) ); +}