Added support for logging std::auto_ptr, boost::shared_ptr and boost::weak_ptr

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@305 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-05-01 19:55:10 +00:00
parent 5ad7562d65
commit d6850d9c20
3 changed files with 59 additions and 0 deletions

View file

@ -14,9 +14,13 @@
#include <boost/function_types/is_callable_builtin.hpp>
#include <ostream>
#include <string>
#include <memory>
namespace boost
{
template< typename T > class shared_ptr;
template< typename T > class weak_ptr;
namespace assign_detail
{
template< typename T > class generic_list;
@ -173,6 +177,11 @@ namespace detail2
return detail2::formatter< T >( t );
}
template< typename T >
stream& operator<<( stream& s, const std::auto_ptr< T >& t )
{
return s << mock::format( t.get() );
}
template< typename T1, typename T2 >
stream& operator<<( stream& s, const std::pair< T1, T2 >& p )
{
@ -247,6 +256,16 @@ namespace detail
{
return s << mock::format( t.get() );
}
template< typename T >
stream& operator<<( stream& s, boost::shared_ptr< T > t )
{
return s << mock::format( t.get() );
}
template< typename T >
stream& operator<<( stream& s, boost::weak_ptr< T > t )
{
return s << mock::format( t.lock() );
}
template< typename T >
BOOST_DEDUCED_TYPENAME boost::enable_if<

View file

@ -9,6 +9,8 @@
#define MOCK_USE_CONVERSIONS
#include <turtle/log.hpp>
#include <boost/assign.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <deque>
@ -359,6 +361,24 @@ BOOST_AUTO_TEST_CASE( std_pairs_are_serialized_with_conversions )
BOOST_CHECK_EQUAL( "(3,42)", to_string( std::make_pair( 3, 42.f ) ) );
}
BOOST_AUTO_TEST_CASE( std_auto_ptr_are_serialized_with_conversions )
{
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) );
}
BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized_with_conversions )
{
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >( new int( 42 ) ) ) );
}
BOOST_AUTO_TEST_CASE( boost_weak_ptr_are_serialized_with_conversions )
{
BOOST_CHECK_NE( "?", to_string( boost::weak_ptr< int >( boost::shared_ptr< int >() ) ) );
BOOST_CHECK_NE( "?", to_string( boost::weak_ptr< int >( boost::shared_ptr< int >( new int( 42 ) ) ) ) );
}
BOOST_AUTO_TEST_CASE( std_deques_are_serialized_with_conversions )
{
std::deque< int > d;

View file

@ -8,6 +8,8 @@
#include <turtle/log.hpp>
#include <boost/assign.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <deque>
@ -355,6 +357,24 @@ BOOST_AUTO_TEST_CASE( std_pairs_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(3,42)", to_string( std::make_pair( 3, 42.f ) ) );
}
BOOST_AUTO_TEST_CASE( std_auto_ptr_are_serialized_without_conversions )
{
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) );
}
BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized_without_conversions )
{
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >( new int( 42 ) ) ) );
}
BOOST_AUTO_TEST_CASE( boost_weak_ptr_are_serialized_without_conversions )
{
BOOST_CHECK_NE( "?", to_string( boost::weak_ptr< int >( boost::shared_ptr< int >() ) ) );
BOOST_CHECK_NE( "?", to_string( boost::weak_ptr< int >( boost::shared_ptr< int >( new int( 42 ) ) ) ) );
}
BOOST_AUTO_TEST_CASE( std_deques_are_serialized_without_conversions )
{
std::deque< int > d;