mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge pull request #23 from mat007/fix-boost-optional-for-non-serializable-type
Fix boost optional for non serializable type
This commit is contained in:
commit
d62c1f578d
3 changed files with 33 additions and 9 deletions
|
|
@ -14,6 +14,7 @@ Not yet released
|
|||
* Fixed build errors with Boost 1.59
|
||||
* 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
|
||||
* Added logging support for boost::optional
|
||||
|
||||
[endsect]
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/detail/container_fwd.hpp>
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <boost/none.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace boost
|
||||
|
|
@ -22,6 +23,7 @@ namespace boost
|
|||
template< typename T > class shared_ptr;
|
||||
template< typename T > class weak_ptr;
|
||||
template< typename T > class reference_wrapper;
|
||||
template< typename T > class optional;
|
||||
|
||||
namespace phoenix
|
||||
{
|
||||
|
|
@ -127,6 +129,17 @@ namespace detail
|
|||
{
|
||||
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
|
||||
template< typename T >
|
||||
|
|
@ -140,7 +153,7 @@ namespace detail
|
|||
return s << mock::format( t.lock() );
|
||||
}
|
||||
template< typename T, typename D >
|
||||
inline stream& operator<<( stream& s, const std::unique_ptr< T, D >& p )
|
||||
stream& operator<<( stream& s, const std::unique_ptr< T, D >& p )
|
||||
{
|
||||
return s << mock::format( p.get() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push, 0 )
|
||||
#endif
|
||||
|
|
@ -86,7 +87,7 @@ namespace
|
|||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( non_serializable_type_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( non_serializable_type_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( non_serializable() ) );
|
||||
}
|
||||
|
|
@ -155,7 +156,7 @@ namespace
|
|||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
#ifdef MOCK_USE_CONVERSIONS
|
||||
BOOST_CHECK_EQUAL( "serializable", to_string( derived_from_serializable() ) );
|
||||
|
|
@ -170,7 +171,7 @@ namespace
|
|||
{};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
#ifdef MOCK_USE_CONVERSIONS
|
||||
BOOST_CHECK_EQUAL( "streamable", to_string( derived_from_streamable() ) );
|
||||
|
|
@ -189,7 +190,7 @@ namespace
|
|||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_base_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_base_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_base() ) );
|
||||
}
|
||||
|
|
@ -202,7 +203,7 @@ namespace
|
|||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_serializable_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_serializable_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_serializable() ) );
|
||||
}
|
||||
|
|
@ -215,7 +216,7 @@ namespace
|
|||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_streamable_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_convertible_to_streamable_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_streamable() ) );
|
||||
}
|
||||
|
|
@ -232,7 +233,7 @@ namespace
|
|||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( ambiguous_convertible() ) );
|
||||
}
|
||||
|
|
@ -529,7 +530,7 @@ namespace
|
|||
{}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( callable_builtin_yields_an_question_mark_when_serialized )
|
||||
BOOST_AUTO_TEST_CASE( callable_builtin_yields_a_question_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", to_string( callable_builtin ) );
|
||||
BOOST_CHECK_EQUAL( "?", to_string( &callable_builtin ) );
|
||||
|
|
@ -668,3 +669,12 @@ BOOST_AUTO_TEST_CASE( nullptr_is_serialized )
|
|||
}
|
||||
|
||||
#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 ) );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue