Refactored tests

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@308 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-05-05 16:47:50 +00:00
parent ea501c3e00
commit 909e37da70
4 changed files with 60 additions and 595 deletions

View file

@ -21,6 +21,10 @@
<define name="MOCK_MAX_ARGS" value="20"/> <define name="MOCK_MAX_ARGS" value="20"/>
</defineset> </defineset>
</build-test> </build-test>
<build-test name="turtle_use_conversions" input="turtle_test" depends="boost" mode="all">
<compilerarg value="-Wno-uninitialized" location="mid" if="is-cygwin"/>
<defineset define="MOCK_USE_CONVERSIONS"/>
</build-test>
</target> </target>
<target name="analyse" description="run errors analyser"> <target name="analyse" description="run errors analyser">

View file

@ -214,6 +214,10 @@
RelativePath="..\..\src\tests\turtle_test\is_functor_test.cpp" RelativePath="..\..\src\tests\turtle_test\is_functor_test.cpp"
> >
</File> </File>
<File
RelativePath="..\..\src\tests\turtle_test\log_test.cpp"
>
</File>
<File <File
RelativePath="..\..\src\tests\turtle_test\log_with_conversions_test.cpp" RelativePath="..\..\src\tests\turtle_test\log_with_conversions_test.cpp"
> >

View file

@ -32,7 +32,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized )
{ {
{ {
int i = 0; int i = 0;
@ -46,18 +46,18 @@ BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized_without_conversio
} }
} }
BOOST_AUTO_TEST_CASE( base_type_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( base_type_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "42", to_string( 42 ) ); BOOST_CHECK_EQUAL( "42", to_string( 42 ) );
} }
BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_bool_alpha_without_conversions ) BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_bool_alpha )
{ {
BOOST_CHECK_EQUAL( "true", to_string( true ) ); BOOST_CHECK_EQUAL( "true", to_string( true ) );
BOOST_CHECK_EQUAL( "false", to_string( false ) ); BOOST_CHECK_EQUAL( "false", to_string( false ) );
} }
BOOST_AUTO_TEST_CASE( strings_are_serialized_with_double_quotes_without_conversions ) BOOST_AUTO_TEST_CASE( strings_are_serialized_with_double_quotes )
{ {
BOOST_CHECK_EQUAL( "\"string\"", to_string( "string" ) ); BOOST_CHECK_EQUAL( "\"string\"", to_string( "string" ) );
BOOST_CHECK_EQUAL( "\"string\"", to_string( std::string( "string" ) ) ); BOOST_CHECK_EQUAL( "\"string\"", to_string( std::string( "string" ) ) );
@ -69,7 +69,7 @@ namespace
{}; {};
} }
BOOST_AUTO_TEST_CASE( non_serializable_type_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( non_serializable_type_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( non_serializable() ) ); BOOST_CHECK_EQUAL( "?", to_string( non_serializable() ) );
} }
@ -84,7 +84,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( serializable_type_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( serializable_type_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "serializable", to_string( serializable() ) ); BOOST_CHECK_EQUAL( "serializable", to_string( serializable() ) );
} }
@ -104,7 +104,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( streamable_type_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( streamable_type_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "streamable", to_string( streamable() ) ); BOOST_CHECK_EQUAL( "streamable", to_string( streamable() ) );
} }
@ -127,7 +127,7 @@ namespace mock
} }
} }
BOOST_AUTO_TEST_CASE( mock_streamable_type_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( mock_streamable_type_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "mock_streamable", to_string( mock_streamable() ) ); BOOST_CHECK_EQUAL( "mock_streamable", to_string( mock_streamable() ) );
} }
@ -138,9 +138,13 @@ namespace
{}; {};
} }
BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_an_interrogation_mark_when_serialized )
{ {
#ifdef MOCK_USE_CONVERSIONS
BOOST_CHECK_EQUAL( "serializable", to_string( derived_from_serializable() ) );
#else
BOOST_CHECK_EQUAL( "?", to_string( derived_from_serializable() ) ); BOOST_CHECK_EQUAL( "?", to_string( derived_from_serializable() ) );
#endif
} }
namespace namespace
@ -149,11 +153,17 @@ namespace
{}; {};
} }
BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_an_interrogation_mark_when_serialized )
{ {
#ifdef MOCK_USE_CONVERSIONS
BOOST_CHECK_EQUAL( "streamable", to_string( derived_from_streamable() ) );
#else
BOOST_CHECK_EQUAL( "?", to_string( derived_from_streamable() ) ); BOOST_CHECK_EQUAL( "?", to_string( derived_from_streamable() ) );
#endif
} }
#ifndef MOCK_USE_CONVERSIONS // all this does not compile with conversions activated, which is precisely the purpose of having this compilation flag
namespace namespace
{ {
struct convertible_to_base struct convertible_to_base
@ -162,7 +172,7 @@ namespace
}; };
} }
BOOST_AUTO_TEST_CASE( type_convertible_to_base_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_convertible_to_base_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_base() ) ); BOOST_CHECK_EQUAL( "?", to_string( convertible_to_base() ) );
} }
@ -175,7 +185,7 @@ namespace
}; };
} }
BOOST_AUTO_TEST_CASE( type_convertible_to_serializable_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_convertible_to_serializable_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_serializable() ) ); BOOST_CHECK_EQUAL( "?", to_string( convertible_to_serializable() ) );
} }
@ -188,7 +198,7 @@ namespace
}; };
} }
BOOST_AUTO_TEST_CASE( type_convertible_to_streamable_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_convertible_to_streamable_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( convertible_to_streamable() ) ); BOOST_CHECK_EQUAL( "?", to_string( convertible_to_streamable() ) );
} }
@ -205,7 +215,7 @@ namespace
}; };
} }
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( ambiguous_convertible() ) ); BOOST_CHECK_EQUAL( "?", to_string( ambiguous_convertible() ) );
} }
@ -226,11 +236,13 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( type_convertible_serializable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_convertible_serializable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "ambiguous_convertible_serializable", to_string( ambiguous_convertible_serializable() ) ); BOOST_CHECK_EQUAL( "ambiguous_convertible_serializable", to_string( ambiguous_convertible_serializable() ) );
} }
#endif // MOCK_USE_CONVERSIONS
namespace namespace
{ {
struct ambiguous_convertible_streamable struct ambiguous_convertible_streamable
@ -252,7 +264,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_streamable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_streamable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "ambiguous_convertible_streamable", to_string( ambiguous_convertible_streamable() ) ); BOOST_CHECK_EQUAL( "ambiguous_convertible_streamable", to_string( ambiguous_convertible_streamable() ) );
} }
@ -281,7 +293,7 @@ namespace mock
} }
} }
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_mock_streamable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_mock_streamable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "ambiguous_convertible_mock_streamable", to_string( ambiguous_convertible_mock_streamable() ) ); BOOST_CHECK_EQUAL( "ambiguous_convertible_mock_streamable", to_string( ambiguous_convertible_mock_streamable() ) );
} }
@ -298,7 +310,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( template_type_serializable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( template_type_serializable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "template_serializable", to_string( template_serializable< int >() ) ); BOOST_CHECK_EQUAL( "template_serializable", to_string( template_serializable< int >() ) );
} }
@ -321,7 +333,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( template_template_streamable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( template_template_streamable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "template_streamable", to_string( template_streamable< int >() ) ); BOOST_CHECK_EQUAL( "template_streamable", to_string( template_streamable< int >() ) );
} }
@ -347,35 +359,35 @@ namespace mock
} }
} }
BOOST_AUTO_TEST_CASE( template_mock_streamable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( template_mock_streamable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "template_mock_streamable", to_string( template_mock_streamable< int >() ) ); BOOST_CHECK_EQUAL( "template_mock_streamable", to_string( template_mock_streamable< int >() ) );
} }
BOOST_AUTO_TEST_CASE( std_pairs_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_pairs_are_serialized )
{ {
BOOST_CHECK_EQUAL( "(3,42)", to_string( std::make_pair( 3, 42.f ) ) ); 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_AUTO_TEST_CASE( std_auto_ptr_are_serialized )
{ {
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) ); BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) ); BOOST_CHECK_NE( "?", to_string( std::auto_ptr< int >( new int( 42 ) ) ) );
} }
BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( boost_shared_ptr_are_serialized )
{ {
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) ); BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >() ) );
BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >( new int( 42 ) ) ) ); BOOST_CHECK_NE( "?", to_string( boost::shared_ptr< int >( new int( 42 ) ) ) );
} }
BOOST_AUTO_TEST_CASE( boost_weak_ptr_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( boost_weak_ptr_are_serialized )
{ {
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 >() ) ) );
BOOST_CHECK_NE( "?", to_string( boost::weak_ptr< int >( boost::shared_ptr< int >( new int( 42 ) ) ) ) ); 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 ) BOOST_AUTO_TEST_CASE( std_deques_are_serialized )
{ {
std::deque< int > d; std::deque< int > d;
d.push_back( 12 ); d.push_back( 12 );
@ -383,7 +395,7 @@ BOOST_AUTO_TEST_CASE( std_deques_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(12,42)", to_string( d ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( d ) );
} }
BOOST_AUTO_TEST_CASE( std_lists_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_lists_are_serialized )
{ {
std::list< int > l; std::list< int > l;
l.push_back( 12 ); l.push_back( 12 );
@ -391,7 +403,7 @@ BOOST_AUTO_TEST_CASE( std_lists_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(12,42)", to_string( l ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( l ) );
} }
BOOST_AUTO_TEST_CASE( std_vectors_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_vectors_are_serialized )
{ {
std::vector< int > v; std::vector< int > v;
v.push_back( 12 ); v.push_back( 12 );
@ -399,7 +411,7 @@ BOOST_AUTO_TEST_CASE( std_vectors_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(12,42)", to_string( v ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( v ) );
} }
BOOST_AUTO_TEST_CASE( std_maps_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_maps_are_serialized )
{ {
std::map< int, std::string > m; std::map< int, std::string > m;
m[ 12 ] = "12"; m[ 12 ] = "12";
@ -407,7 +419,7 @@ BOOST_AUTO_TEST_CASE( std_maps_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) ); BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) );
} }
BOOST_AUTO_TEST_CASE( std_multimaps_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_multimaps_are_serialized )
{ {
std::multimap< int, std::string > m; std::multimap< int, std::string > m;
m.insert( std::make_pair( 12, "12" )); m.insert( std::make_pair( 12, "12" ));
@ -415,7 +427,7 @@ BOOST_AUTO_TEST_CASE( std_multimaps_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) ); BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) );
} }
BOOST_AUTO_TEST_CASE( std_sets_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_sets_are_serialized )
{ {
std::set< int > s; std::set< int > s;
s.insert( 12 ); s.insert( 12 );
@ -423,7 +435,7 @@ BOOST_AUTO_TEST_CASE( std_sets_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) );
} }
BOOST_AUTO_TEST_CASE( std_multisets_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( std_multisets_are_serialized )
{ {
std::multiset< int > s; std::multiset< int > s;
s.insert( 12 ); s.insert( 12 );
@ -431,17 +443,17 @@ BOOST_AUTO_TEST_CASE( std_multisets_are_serialized_without_conversions )
BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) );
} }
BOOST_AUTO_TEST_CASE( boost_assign_list_of_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( boost_assign_list_of_are_serialized )
{ {
BOOST_CHECK_EQUAL( "(12,42)", to_string( boost::assign::list_of( 12 )( 42 ) ) ); BOOST_CHECK_EQUAL( "(12,42)", to_string( boost::assign::list_of( 12 )( 42 ) ) );
} }
BOOST_AUTO_TEST_CASE( boost_assign_map_list_of_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( boost_assign_map_list_of_are_serialized )
{ {
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) ); BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) );
} }
BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized )
{ {
BOOST_CHECK_EQUAL( "3", to_string( boost::cref( 3 ) ) ); BOOST_CHECK_EQUAL( "3", to_string( boost::cref( 3 ) ) );
BOOST_CHECK_EQUAL( "\"string\"", to_string( boost::cref( "string" ) ) ); BOOST_CHECK_EQUAL( "\"string\"", to_string( boost::cref( "string" ) ) );
@ -453,7 +465,7 @@ namespace
{} {}
} }
BOOST_AUTO_TEST_CASE( callable_builtin_yields_an_interrogation_mark_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( callable_builtin_yields_an_interrogation_mark_when_serialized )
{ {
BOOST_CHECK_EQUAL( "?", to_string( callable_builtin ) ); BOOST_CHECK_EQUAL( "?", to_string( callable_builtin ) );
BOOST_CHECK_EQUAL( "?", to_string( &callable_builtin ) ); BOOST_CHECK_EQUAL( "?", to_string( &callable_builtin ) );
@ -469,7 +481,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( type_can_use_format_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( type_can_use_format_when_serialized )
{ {
BOOST_CHECK_EQUAL( "\"string\"", to_string( serialized_using_format() ) ); BOOST_CHECK_EQUAL( "\"string\"", to_string( serialized_using_format() ) );
} }
@ -484,7 +496,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( type_can_use_format_when_streamed_without_conversions ) BOOST_AUTO_TEST_CASE( type_can_use_format_when_streamed )
{ {
BOOST_CHECK_EQUAL( "\"string\"", to_string( streamed_using_format() ) ); BOOST_CHECK_EQUAL( "\"string\"", to_string( streamed_using_format() ) );
} }
@ -499,7 +511,7 @@ namespace
} }
} }
BOOST_AUTO_TEST_CASE( std_string_streamed_is_not_a_container_without_conversions ) BOOST_AUTO_TEST_CASE( std_string_streamed_is_not_a_container )
{ {
BOOST_CHECK_EQUAL( "string", to_string( std_string_streamed() ) ); BOOST_CHECK_EQUAL( "string", to_string( std_string_streamed() ) );
} }
@ -519,7 +531,7 @@ namespace detail
} }
} }
BOOST_AUTO_TEST_CASE( mock_detail_template_type_serializable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( mock_detail_template_type_serializable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "mock::detail::template_serializable", to_string( mock::detail::template_serializable< int >() ) ); BOOST_CHECK_EQUAL( "mock::detail::template_serializable", to_string( mock::detail::template_serializable< int >() ) );
} }
@ -545,7 +557,7 @@ namespace detail
} }
} }
BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_when_serialized_without_conversions ) BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_when_serialized )
{ {
BOOST_CHECK_EQUAL( "mock::detail::template_streamable", to_string( mock::detail::template_streamable< int >() ) ); BOOST_CHECK_EQUAL( "mock::detail::template_streamable", to_string( mock::detail::template_streamable< int >() ) );
} }

View file

@ -1,555 +0,0 @@
//
// Copyright Mathieu Champlon 2008
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#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>
#include <list>
#include <map>
#include <set>
#include <boost/test/auto_unit_test.hpp>
#define BOOST_LIB_NAME boost_unit_test_framework
#include <boost/config/auto_link.hpp>
namespace
{
template< typename T >
std::string to_string( T t )
{
std::stringstream s;
s << mock::format( t );
return s.str();
}
}
BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized_with_conversions )
{
{
int i = 0;
BOOST_CHECK_NE( "?", to_string( &i ) );
BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) );
}
{
const int i = 0;
BOOST_CHECK_NE( "?", to_string( &i ) );
BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) );
}
}
BOOST_AUTO_TEST_CASE( base_type_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "42", to_string( 42 ) );
}
BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_bool_alpha_with_conversions )
{
BOOST_CHECK_EQUAL( "true", to_string( true ) );
BOOST_CHECK_EQUAL( "false", to_string( false ) );
}
BOOST_AUTO_TEST_CASE( strings_are_serialized_with_double_quotes_with_conversions )
{
BOOST_CHECK_EQUAL( "\"string\"", to_string( "string" ) );
BOOST_CHECK_EQUAL( "\"string\"", to_string( std::string( "string" ) ) );
}
namespace
{
struct non_serializable
{};
}
BOOST_AUTO_TEST_CASE( non_serializable_type_yields_an_interrogation_mark_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "?", to_string( non_serializable() ) );
}
namespace
{
struct serializable
{};
std::ostream& operator<<( std::ostream& s, const serializable& )
{
return s << "serializable";
}
}
BOOST_AUTO_TEST_CASE( serializable_type_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "serializable", to_string( serializable() ) );
}
namespace
{
struct streamable
{};
std::ostream& operator<<( std::ostream& s, const streamable& )
{
BOOST_FAIL( "should not have been called" );
return s;
}
mock::stream& operator<<( mock::stream& s, const streamable& )
{
return s << "streamable";
}
}
BOOST_AUTO_TEST_CASE( streamable_type_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "streamable", to_string( streamable() ) );
}
namespace
{
struct mock_streamable
{};
std::ostream& operator<<( std::ostream& s, const mock_streamable& )
{
BOOST_FAIL( "should not have been called" );
return s;
}
}
namespace mock
{
stream& operator<<( stream& s, const mock_streamable& )
{
return s << "mock_streamable";
}
}
BOOST_AUTO_TEST_CASE( mock_streamable_type_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "mock_streamable", to_string( mock_streamable() ) );
}
namespace
{
struct derived_from_serializable : serializable
{};
}
BOOST_AUTO_TEST_CASE( type_derived_from_serializable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "serializable", to_string( derived_from_serializable() ) );
}
namespace
{
struct derived_from_streamable : streamable
{};
}
BOOST_AUTO_TEST_CASE( type_derived_from_streamable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "streamable", to_string( derived_from_streamable() ) );
}
//namespace
//{
// struct convertible_to_base
// {
// operator int() const
// {
// return 3;
// }
// };
//}
//
//BOOST_AUTO_TEST_CASE( type_convertible_to_base_yields_its_value_when_serialized_with_conversions )
//{
// BOOST_CHECK_EQUAL( "3", to_string( convertible_to_base() ) );
//}
//namespace
//{
// struct convertible_to_serializable
// {
// operator serializable() const;
// };
//}
//
//BOOST_AUTO_TEST_CASE( type_convertible_to_serializable_yields_its_value_when_serialized_with_conversions )
//{
// BOOST_CHECK_EQUAL( "serializable", to_string( convertible_to_serializable() ) );
//}
//namespace
//{
// struct convertible_to_streamable
// {
// operator streamable() const;
// };
//}
//
//BOOST_AUTO_TEST_CASE( type_convertible_to_streamable_yields_its_value_when_serialized_with_conversions )
//{
// BOOST_CHECK_EQUAL( "streamable", to_string( convertible_to_streamable() ) );
//}
//namespace
//{
// struct ambiguous_convertible
// {
// operator float() const;
// operator int() const;
// operator serializable() const;
// operator streamable() const;
// template< typename T > operator T() const;
// };
//}
//
//BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_yields_an_interrogation_mark_when_serialized_with_conversions )
//{
// BOOST_CHECK_EQUAL( "?", to_string( ambiguous_convertible() ) );
//}
//namespace
//{
// struct ambiguous_convertible_serializable
// {
// operator float() const;
// operator int() const;
// operator serializable() const;
// operator streamable() const;
// template< typename T > operator T() const;
// };
// std::ostream& operator<<( std::ostream& s, const ambiguous_convertible_serializable& )
// {
// return s << "ambiguous_convertible_serializable";
// }
//}
//
//BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_serializable_yields_its_value_when_serialized_with_conversions )
//{
// BOOST_CHECK_EQUAL( "ambiguous_convertible_serializable", to_string( ambiguous_convertible_serializable() ) );
//}
namespace
{
struct ambiguous_convertible_streamable
{
operator float() const;
operator int() const;
operator serializable() const;
operator streamable() const;
template< typename T > operator T() const;
};
std::ostream& operator<<( std::ostream& s, const ambiguous_convertible_streamable& )
{
BOOST_FAIL( "should not have been called" );
return s;
}
mock::stream& operator<<( mock::stream& s, const ambiguous_convertible_streamable& )
{
return s << "ambiguous_convertible_streamable";
}
}
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_streamable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "ambiguous_convertible_streamable", to_string( ambiguous_convertible_streamable() ) );
}
namespace
{
struct ambiguous_convertible_mock_streamable
{
operator float() const;
operator int() const;
operator serializable() const;
operator streamable() const;
template< typename T > operator T() const;
};
std::ostream& operator<<( std::ostream& s, const ambiguous_convertible_mock_streamable& )
{
BOOST_FAIL( "should not have been called" );
return s;
}
}
namespace mock
{
stream& operator<<( stream& s, const ambiguous_convertible_mock_streamable& )
{
return s << "ambiguous_convertible_mock_streamable";
}
}
BOOST_AUTO_TEST_CASE( type_ambiguous_convertible_mock_streamable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "ambiguous_convertible_mock_streamable", to_string( ambiguous_convertible_mock_streamable() ) );
}
namespace
{
template< typename T >
struct template_serializable
{};
template< typename T >
std::ostream& operator<<( std::ostream& s, const template_serializable< T >& )
{
return s << "template_serializable";
}
}
BOOST_AUTO_TEST_CASE( template_type_serializable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "template_serializable", to_string( template_serializable< int >() ) );
}
namespace
{
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 << "template_streamable";
}
}
BOOST_AUTO_TEST_CASE( template_streamable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "template_streamable", to_string( template_streamable< int >() ) );
}
namespace
{
template< typename T >
struct template_mock_streamable
{};
template< typename T >
std::ostream& operator<<( std::ostream& s, const template_mock_streamable< T >& )
{
BOOST_FAIL( "should not have been called" );
return s;
}
}
namespace mock
{
template< typename T >
stream& operator<<( stream& s, const template_mock_streamable< T >& )
{
return s << "template_mock_streamable";
}
}
BOOST_AUTO_TEST_CASE( template_mock_streamable_yields_its_value_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "template_mock_streamable", to_string( template_mock_streamable< int >() ) );
}
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;
d.push_back( 12 );
d.push_back( 42 );
BOOST_CHECK_EQUAL( "(12,42)", to_string( d ) );
}
BOOST_AUTO_TEST_CASE( std_lists_are_serialized_with_conversions )
{
std::list< int > l;
l.push_back( 12 );
l.push_back( 42 );
BOOST_CHECK_EQUAL( "(12,42)", to_string( l ) );
}
BOOST_AUTO_TEST_CASE( std_vectors_are_serialized_with_conversions )
{
std::vector< int > v;
v.push_back( 12 );
v.push_back( 42 );
BOOST_CHECK_EQUAL( "(12,42)", to_string( v ) );
}
BOOST_AUTO_TEST_CASE( std_maps_are_serialized_with_conversions )
{
std::map< int, std::string > m;
m[ 12 ] = "12";
m[ 42 ] = "42";
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) );
}
BOOST_AUTO_TEST_CASE( std_multimaps_are_serialized_with_conversions )
{
std::multimap< int, std::string > m;
m.insert( std::make_pair( 12, "12" ));
m.insert( std::make_pair( 42, "42" ));
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( m ) );
}
BOOST_AUTO_TEST_CASE( std_sets_are_serialized_with_conversions )
{
std::set< int > s;
s.insert( 12 );
s.insert( 42 );
BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) );
}
BOOST_AUTO_TEST_CASE( std_multisets_are_serialized_with_conversions )
{
std::multiset< int > s;
s.insert( 12 );
s.insert( 42 );
BOOST_CHECK_EQUAL( "(12,42)", to_string( s ) );
}
BOOST_AUTO_TEST_CASE( boost_assign_list_of_are_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "(12,42)", to_string( boost::assign::list_of( 12 )( 42 ) ) );
}
BOOST_AUTO_TEST_CASE( boost_assign_map_list_of_are_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "((12,\"12\"),(42,\"42\"))", to_string( boost::assign::map_list_of( 12, "12" )( 42, "42" ) ) );
}
BOOST_AUTO_TEST_CASE( boost_reference_wrappers_are_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "3", to_string( boost::cref( 3 ) ) );
BOOST_CHECK_EQUAL( "\"string\"", to_string( boost::cref( "string" ) ) );
}
namespace
{
void callable_builtin()
{}
}
BOOST_AUTO_TEST_CASE( callable_builtin_yields_an_interrogation_mark_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "?", to_string( callable_builtin ) );
BOOST_CHECK_EQUAL( "?", to_string( &callable_builtin ) );
}
namespace
{
struct serialized_using_format
{};
std::ostream& operator<<( std::ostream& s, const serialized_using_format& )
{
return s << mock::format( "string" );
}
}
BOOST_AUTO_TEST_CASE( type_can_use_format_when_serialized_with_conversions )
{
BOOST_CHECK_EQUAL( "\"string\"", to_string( serialized_using_format() ) );
}
namespace
{
struct streamed_using_format
{};
mock::stream& operator<<( mock::stream& s, const streamed_using_format& )
{
return s << mock::format( "string" );
}
}
BOOST_AUTO_TEST_CASE( type_can_use_format_when_streamed_with_conversions )
{
BOOST_CHECK_EQUAL( "\"string\"", to_string( streamed_using_format() ) );
}
namespace
{
struct std_string_streamed
{};
mock::stream& operator<<( mock::stream& s, const std_string_streamed& )
{
return s << std::string( "string" );
}
}
BOOST_AUTO_TEST_CASE( std_string_streamed_is_not_a_container_with_conversions )
{
BOOST_CHECK_EQUAL( "string", to_string( std_string_streamed() ) );
}
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 >() ) );
}