diff --git a/build/vc80/turtle.vcproj b/build/vc80/turtle.vcproj
index 2db2e54..8d4b98c 100644
--- a/build/vc80/turtle.vcproj
+++ b/build/vc80/turtle.vcproj
@@ -184,10 +184,6 @@
RelativePath="..\..\src\libraries\turtle\expectation.hpp"
>
-
-
@@ -197,7 +193,7 @@
>
-
-
diff --git a/build/vc80/turtle_test.vcproj b/build/vc80/turtle_test.vcproj
index a429b86..2f1e986 100644
--- a/build/vc80/turtle_test.vcproj
+++ b/build/vc80/turtle_test.vcproj
@@ -198,10 +198,6 @@
RelativePath="..\..\src\tests\turtle_test\error_test.cpp"
>
-
-
@@ -215,7 +211,7 @@
>
+
+
#include
diff --git a/src/libraries/turtle/constraints.hpp b/src/libraries/turtle/constraints.hpp
index 974130c..2cb8a92 100644
--- a/src/libraries/turtle/constraints.hpp
+++ b/src/libraries/turtle/constraints.hpp
@@ -10,7 +10,7 @@
#define MOCK_CONSTRAINTS_HPP_INCLUDED
#include "constraint.hpp"
-#include "format.hpp"
+#include "log.hpp"
#include
#include
#include
diff --git a/src/libraries/turtle/format.hpp b/src/libraries/turtle/format.hpp
deleted file mode 100644
index c346712..0000000
--- a/src/libraries/turtle/format.hpp
+++ /dev/null
@@ -1,155 +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)
-//
-
-#ifndef MOCK_FORMAT_HPP_INCLUDED
-#define MOCK_FORMAT_HPP_INCLUDED
-
-#include "is_serializable.hpp"
-#include "is_formattable.hpp"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace mock
-{
-namespace detail
-{
- template< typename T >
- void serialize( std::ostream& s, const T& t,
- BOOST_DEDUCED_TYPENAME boost::enable_if<
- BOOST_DEDUCED_TYPENAME detail::is_formattable< std::ostream, T >
- >::type* = 0 )
- {
- format( s, t );
- }
- template< typename T >
- void serialize( std::ostream& s, const T& t,
- BOOST_DEDUCED_TYPENAME boost::enable_if<
- boost::mpl::and_<
- boost::mpl::not_<
- BOOST_DEDUCED_TYPENAME detail::is_formattable< std::ostream, T >
- >,
- BOOST_DEDUCED_TYPENAME detail::is_serializable< std::ostream, T >
- >
- >::type* = 0 )
- {
- s << t;
- }
- template< typename T >
- void serialize( std::ostream& s, const T&,
- BOOST_DEDUCED_TYPENAME boost::disable_if<
- boost::mpl::or_<
- BOOST_DEDUCED_TYPENAME detail::is_formattable< std::ostream, T >,
- BOOST_DEDUCED_TYPENAME detail::is_serializable< std::ostream, T >
- >
- >::type* = 0 )
- {
- s << '?';
- }
-
- BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(is_container, const_iterator, false)
-}
-
- template< typename T >
- class protect
- {
- public:
- explicit protect( const T& t )
- : t_( &t )
- {}
- const T& operator*() const
- {
- return *t_;
- }
- const T* operator->() const
- {
- return t_;
- }
- private:
- const T* t_;
- };
- template< typename T >
- std::ostream& operator<<( std::ostream& s, protect< T > t )
- {
- format( s, t );
- return s;
- }
-
- template< typename T >
- protect< T > format( const T& t )
- {
- return protect< T >( t );
- }
-
- template< typename T >
- void format( std::ostream& s, protect< T > t,
- BOOST_DEDUCED_TYPENAME boost::disable_if<
- detail::is_container< T >
- >::type* = 0 )
- {
- detail::serialize( s, *t );
- }
-
- inline void format( std::ostream& s, protect< bool > b )
- {
- s << std::boolalpha << *b;
- }
- inline void format( std::ostream& s, protect< std::string > str )
- {
- s << '"' << *str << '"';
- }
- inline void format( std::ostream& s, protect< const char* > str )
- {
- s << '"' << *str << '"';
- }
-
- template< typename T1, typename T2 >
- void format( std::ostream& s, protect< std::pair< T1, T2 > > p )
- {
- s << '(' << mock::format( p->first )
- << ',' << mock::format( p->second ) << ')';
- }
-
- template< typename T >
- void format( std::ostream& s, protect< T* >,
- BOOST_DEDUCED_TYPENAME boost::enable_if<
- boost::function_types::is_callable_builtin< T* >
- >::type* = 0 )
- {
- s << '?';
- }
-
- template< typename T >
- void format( std::ostream& s, protect< T > c,
- BOOST_DEDUCED_TYPENAME boost::enable_if<
- detail::is_container< T >
- >::type* = 0 )
- {
- s << '(';
- // if an error is generated by the line below it means T is
- // being mistaken for a container because it has a typedef
- // const_iterator : the solution would be to add a format override
- // for mock::protect< T >.
- for( BOOST_DEDUCED_TYPENAME T::const_iterator it = c->begin();
- it != c->end(); ++it )
- {
- if( it != c->begin() )
- s << ',';
- s << mock::format( *it );
- }
- s << ')';
- }
-}
-
-#endif // #ifndef MOCK_FORMAT_HPP_INCLUDED
diff --git a/src/libraries/turtle/function.hpp b/src/libraries/turtle/function.hpp
index 11264d2..b817478 100644
--- a/src/libraries/turtle/function.hpp
+++ b/src/libraries/turtle/function.hpp
@@ -13,7 +13,7 @@
#include "error.hpp"
#include "expectation.hpp"
#include "root.hpp"
-#include "format.hpp"
+#include "log.hpp"
#include "args.hpp"
#include
#include
diff --git a/src/libraries/turtle/is_container.hpp b/src/libraries/turtle/is_container.hpp
new file mode 100644
index 0000000..5b7673b
--- /dev/null
+++ b/src/libraries/turtle/is_container.hpp
@@ -0,0 +1,26 @@
+//
+// Copyright Mathieu Champlon 2011
+//
+// 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)
+//
+
+#ifndef MOCK_IS_CONTAINER_HPP_INCLUDED
+#define MOCK_IS_CONTAINER_HPP_INCLUDED
+
+#include
+
+namespace mock
+{
+namespace detail
+{
+ BOOST_MPL_HAS_XXX_TRAIT_DEF( const_iterator )
+
+ template< typename T >
+ struct is_container : has_const_iterator< T >
+ {};
+}
+}
+
+#endif // #ifndef MOCK_IS_CONTAINER_HPP_INCLUDED
diff --git a/src/libraries/turtle/is_formattable.hpp b/src/libraries/turtle/is_formattable.hpp
deleted file mode 100644
index af67f59..0000000
--- a/src/libraries/turtle/is_formattable.hpp
+++ /dev/null
@@ -1,52 +0,0 @@
-//
-// Copyright Mathieu Champlon 2011
-//
-// 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)
-//
-
-#ifndef MOCK_IS_FORMATABLE_HPP_INCLUDED
-#define MOCK_IS_FORMATABLE_HPP_INCLUDED
-
-#include "yes_no_type.hpp"
-#include "sink.hpp"
-#include
-
-#ifdef _MSC_VER
-#pragma warning( push )
-#pragma warning( disable: 4913 )
-#endif
-
-namespace mock
-{
-namespace detail
-{
-namespace formattable
-{
- template< typename S >
- detail::yes_type format( S&, detail::sink );
-
- template< typename S, typename T >
- struct impl
- {
- static S* s;
- static T* t;
- // if an error is generated by the line below it means T has more than
- // one conversion to other types which are formattable : the easiest
- // solution would be to add a format function for T as well.
- enum { value = sizeof( yes_type(), format( *s, *t ), yes_type() ) == sizeof( yes_type ) };
- };
-}
- template< typename S, typename T >
- struct is_formattable
- : boost::mpl::bool_< formattable::impl< S, T >::value >
- {};
-}
-}
-
-#ifdef _MSC_VER
-#pragma warning( pop )
-#endif
-
-#endif // #ifndef MOCK_IS_FORMATABLE_HPP_INCLUDED
diff --git a/src/libraries/turtle/is_serializable.hpp b/src/libraries/turtle/is_serializable.hpp
deleted file mode 100644
index 511ad7b..0000000
--- a/src/libraries/turtle/is_serializable.hpp
+++ /dev/null
@@ -1,47 +0,0 @@
-//
-// Copyright Mathieu Champlon 2011
-//
-// 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)
-//
-
-#ifndef MOCK_IS_SERIALIZABLE_HPP_INCLUDED
-#define MOCK_IS_SERIALIZABLE_HPP_INCLUDED
-
-#include "yes_no_type.hpp"
-#include
-
-#ifdef _MSC_VER
-#pragma warning( push )
-#pragma warning( disable: 4913 )
-#endif
-
-namespace mock
-{
-namespace detail
-{
-namespace serializable
-{
- template< typename S, typename T >
- yes_type operator<<( S&, const T& );
-
- template< typename S, typename T >
- struct impl
- {
- static S* s;
- static T* t;
- enum { value = sizeof( yes_type(), (*s << *t), yes_type() ) == sizeof( yes_type ) };
- };
-}
- template< typename S, typename T >
- struct is_serializable : boost::mpl::bool_< serializable::impl< S, T >::value >
- {};
-}
-}
-
-#ifdef _MSC_VER
-#pragma warning( pop )
-#endif
-
-#endif // #ifndef MOCK_IS_SERIALIZABLE_HPP_INCLUDED
diff --git a/src/libraries/turtle/log.hpp b/src/libraries/turtle/log.hpp
new file mode 100644
index 0000000..077b562
--- /dev/null
+++ b/src/libraries/turtle/log.hpp
@@ -0,0 +1,245 @@
+//
+// Copyright Mathieu Champlon 2011
+//
+// 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)
+//
+
+#ifndef MOCK_LOG_HPP_INCLUDED
+#define MOCK_LOG_HPP_INCLUDED
+
+#include "is_container.hpp"
+#include
+#include
+#include
+#include
+#include
+
+namespace mock
+{
+ struct stream
+ {
+ explicit stream( std::ostream& s )
+ : s_( &s )
+ {}
+ std::ostream* s_;
+ };
+
+namespace detail3
+{
+ template< typename T >
+ struct serializer
+ {
+ explicit serializer( const T& t )
+ : t_( &t )
+ {}
+ void serialize( stream& s ) const
+ {
+ // if it fails here because ambiguous stuff
+ // -> add operator<< to mock::stream for T
+ s << *t_;
+ }
+ const T* t_;
+ };
+ template<>
+ struct serializer< bool >
+ {
+ explicit serializer( bool b )
+ : b_( b )
+ {}
+ void serialize( stream& s ) const
+ {
+ *s.s_ << std::boolalpha << b_;
+ }
+ bool b_;
+ };
+ template<>
+ struct serializer< const char* >
+ {
+ explicit serializer( const char* s )
+ : s_( s )
+ {}
+ void serialize( stream& s ) const
+ {
+ *s.s_ << '"' << s_ << '"';
+ }
+ const char* s_;
+ };
+ template<>
+ struct serializer< std::string >
+ {
+ explicit serializer( const std::string& s )
+ : s_( &s )
+ {}
+ void serialize( stream& s ) const
+ {
+ *s.s_ << '"' << *s_ << '"';
+ }
+ const std::string* s_;
+ };
+
+ template< typename T >
+ stream& operator<<( stream& s, const serializer< T >& ser )
+ {
+ ser.serialize( s );
+ return s;
+ }
+
+ template< typename T >
+ std::ostream& operator<<( std::ostream& s, const serializer< T >& ser )
+ {
+ stream ss( s );
+ ser.serialize( ss );
+ return s;
+ }
+}
+ template< typename T >
+ detail3::serializer< T > format( const T& t )
+ {
+ return detail3::serializer< T >( t );
+ }
+ inline detail3::serializer< const char* > format( const char* s )
+ {
+ return detail3::serializer< const char* >( s );
+ }
+
+#ifdef MOCK_LOG_CONVERSIONS
+
+namespace detail
+{
+ struct sink
+ {
+ template< typename T >
+ sink( const T&, BOOST_DEDUCED_TYPENAME boost::disable_if<
+ boost::is_fundamental< T > >::type* = 0 )
+ {}
+ };
+
+ std::ostream& operator<<( std::ostream& s, const detail::sink& )
+ {
+ return s << "?";
+ }
+
+ struct holder
+ {
+ virtual ~holder()
+ {}
+ virtual void serialize( std::ostream& s ) const = 0;
+ };
+
+ template< typename T >
+ struct holder_imp : holder
+ {
+ explicit holder_imp( const T& t )
+ : t_( &t )
+ {}
+ virtual void serialize( std::ostream& s ) const
+ {
+ // if it fails here because ambiguous stuff
+ // -> add operator<< to mock::stream for T
+ s << *t_;
+ }
+ const T* t_;
+ };
+
+ struct any
+ {
+ template< typename T >
+ any( const T& t )
+ : h_( new holder_imp< T >( t ) )
+ {}
+ ~any()
+ {
+ delete h_;
+ }
+ holder* h_;
+ };
+}
+
+ stream& operator<<( stream& s, const detail::any& d )
+ {
+ d.h_->serialize( *s.s_ );
+ return s;
+ }
+
+#else // MOCK_LOG_CONVERSIONS
+
+namespace detail
+{
+ template< typename S, typename T >
+ S& operator<<( S &s, const T& )
+ {
+ return s << "?";
+ }
+}
+
+ template< typename T >
+ void serialize( std::ostream& s, const T& t )
+ {
+ using namespace detail;
+ s << t;
+ }
+
+namespace detail2
+{
+ template< typename S, typename T >
+ S& operator<<( S& s, const T& t )
+ {
+ serialize( s, t );
+ return s;
+ }
+}
+
+ template< typename T >
+ BOOST_DEDUCED_TYPENAME boost::disable_if<
+ detail::is_container< T >, stream&
+ >::type
+ operator<<( stream& s, const T& t )
+ {
+ using namespace detail2;
+ *s.s_ << t;
+ return s;
+ }
+
+#endif // MOCK_LOG_CONVERSIONS
+
+ template< typename T1, typename T2 >
+ stream& operator<<( stream& s, const std::pair< T1, T2 >& p )
+ {
+ return s << '(' << mock::format( p.first )
+ << ',' << mock::format( p.second ) << ')';
+ }
+
+ template< typename Container >
+ BOOST_DEDUCED_TYPENAME boost::enable_if<
+ detail::is_container< Container >, stream&
+ >::type
+ operator<<( stream& s, const Container& c )
+ {
+ s << '(';
+ // if an error is generated by the line below it means Container is
+ // being mismatched for a container because it has a typedef
+ // const_iterator : the easiest solution would be to add a format
+ // function for Container as well.
+ for( BOOST_DEDUCED_TYPENAME Container::const_iterator it = c.begin();
+ it != c.end(); ++it )
+ {
+ if( it != c.begin() )
+ s << ',';
+ s << mock::format( *it );
+ }
+ return s << ')';
+ }
+
+ template< typename T >
+ BOOST_DEDUCED_TYPENAME boost::enable_if<
+ boost::function_types::is_callable_builtin< T >, stream&
+ >::type
+ operator<<( stream& s, const T* )
+ {
+ return s << '?';
+ }
+}
+
+#endif // #ifndef MOCK_LOG_HPP_INCLUDED
diff --git a/src/libraries/turtle/operators.hpp b/src/libraries/turtle/operators.hpp
index 12ded04..57fff09 100644
--- a/src/libraries/turtle/operators.hpp
+++ b/src/libraries/turtle/operators.hpp
@@ -10,7 +10,7 @@
#define MOCK_OPERATORS_HPP_INCLUDED
#include "constraint.hpp"
-#include "format.hpp"
+#include "log.hpp"
namespace mock
{
diff --git a/src/libraries/turtle/sink.hpp b/src/libraries/turtle/sink.hpp
deleted file mode 100644
index 0002caa..0000000
--- a/src/libraries/turtle/sink.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//
-// Copyright Mathieu Champlon 2011
-//
-// 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)
-//
-
-#ifndef MOCK_ANY_HPP_INCLUDED
-#define MOCK_ANY_HPP_INCLUDED
-
-namespace mock
-{
-namespace detail
-{
- struct sink
- {
- template< typename T >
- sink( const T& );
- };
-}
-}
-
-#endif // #ifndef MOCK_ANY_HPP_INCLUDED
diff --git a/src/tests/errors_test/mismatch_type_in_returns_action.cpp b/src/tests/errors_test/mismatch_type_in_returns_action.cpp
index 6c5b292..36fc444 100644
--- a/src/tests/errors_test/mismatch_type_in_returns_action.cpp
+++ b/src/tests/errors_test/mismatch_type_in_returns_action.cpp
@@ -10,13 +10,13 @@
namespace
{
- MOCK_CLASS( mocked )
+ MOCK_CLASS( cl )
{
- MOCK_METHOD_EXT( method, 0, int(), method ) // add another test with void() and another with std::string()
+ MOCK_METHOD_EXT( m, 0, int(), m ) // add another test with void() and another with std::string()
};
void test_case()
{
- mocked m;
- MOCK_EXPECT( m, method ).returns( "42" );
+ cl c;
+ MOCK_EXPECT( c, m ).returns( "42" );
}
}
diff --git a/src/tests/turtle_test/format_test.cpp b/src/tests/turtle_test/format_test.cpp
deleted file mode 100644
index 176b2a8..0000000
--- a/src/tests/turtle_test/format_test.cpp
+++ /dev/null
@@ -1,217 +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)
-//
-
-#include
-#include
-#include
-#include
-#include
-#include