Added logging support for boost::optional

This commit is contained in:
Mathieu Champlon 2016-02-08 05:40:39 +01:00
parent c35b76c8f0
commit 506e10f76a
3 changed files with 24 additions and 0 deletions

View file

@ -14,6 +14,7 @@ Not yet released
* Fixed build errors with Boost 1.59 * Fixed build errors with Boost 1.59
* Fixed multiply defined symbol definition for MOCK_FUNCTION included from several translation units * Fixed multiply defined symbol definition for MOCK_FUNCTION included from several translation units
* Fixed extra semicolon warning with BOOST_GLOBAL_FIXTURE prior to Boost 1.59 * Fixed extra semicolon warning with BOOST_GLOBAL_FIXTURE prior to Boost 1.59
* Added logging support for boost::optional
[endsect] [endsect]

View file

@ -15,6 +15,7 @@
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <boost/detail/container_fwd.hpp> #include <boost/detail/container_fwd.hpp>
#include <boost/function_types/is_callable_builtin.hpp> #include <boost/function_types/is_callable_builtin.hpp>
#include <boost/none.hpp>
#include <memory> #include <memory>
namespace boost namespace boost
@ -22,6 +23,7 @@ namespace boost
template< typename T > class shared_ptr; template< typename T > class shared_ptr;
template< typename T > class weak_ptr; template< typename T > class weak_ptr;
template< typename T > class reference_wrapper; template< typename T > class reference_wrapper;
template< typename T > class optional;
namespace phoenix namespace phoenix
{ {
@ -127,6 +129,17 @@ namespace detail
{ {
return s << mock::format( t.lock() ); return s << mock::format( t.lock() );
} }
inline stream& operator<<( stream& s, const boost::none_t& )
{
return s << "none";
}
template< typename T >
stream& operator<<( stream& s, const boost::optional< T >& t )
{
if( t )
return s << mock::format( t.get() );
return s << boost::none;
}
#ifdef MOCK_SMART_PTR #ifdef MOCK_SMART_PTR
template< typename T > template< typename T >

View file

@ -12,6 +12,7 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp> #include <boost/weak_ptr.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
#pragma warning( push, 0 ) #pragma warning( push, 0 )
#endif #endif
@ -668,3 +669,12 @@ BOOST_AUTO_TEST_CASE( nullptr_is_serialized )
} }
#endif #endif
BOOST_AUTO_TEST_CASE( mock_boost_optional_yields_its_value_when_serialized )
{
BOOST_CHECK_EQUAL( "7", to_string( boost::optional< int >( 7 ) ) );
BOOST_CHECK_EQUAL( "?", to_string( boost::optional< non_serializable >( non_serializable() ) ) );
BOOST_CHECK_EQUAL( "none", to_string( boost::optional< int >() ) );
BOOST_CHECK_EQUAL( "none", to_string( boost::optional< non_serializable >() ) );
BOOST_CHECK_EQUAL( "none", to_string( boost::none ) );
}