diff --git a/build/vc100/turtle.vcxproj b/build/vc100/turtle.vcxproj index 07825ef..abf8ec3 100644 --- a/build/vc100/turtle.vcxproj +++ b/build/vc100/turtle.vcxproj @@ -19,15 +19,12 @@ - - - diff --git a/build/vc100/turtle.vcxproj.filters b/build/vc100/turtle.vcxproj.filters index 0d98328..0b27826 100644 --- a/build/vc100/turtle.vcxproj.filters +++ b/build/vc100/turtle.vcxproj.filters @@ -19,9 +19,6 @@ Source Files - - Source Files - Source Files @@ -37,9 +34,6 @@ Source Files - - Source Files - Source Files\detail @@ -70,9 +64,6 @@ Source Files\detail - - Source Files\detail - Source Files\detail diff --git a/turtle/boost_test_error.hpp b/turtle/boost_test_error.hpp deleted file mode 100644 index 2c22535..0000000 --- a/turtle/boost_test_error.hpp +++ /dev/null @@ -1,98 +0,0 @@ -// http://turtle.sourceforge.net -// -// 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_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED -#define MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED - -#include -#include -#include -#include -#include - -namespace mock -{ - struct exception : virtual boost::execution_aborted - {}; - - template< typename Result > - struct boost_test_error_policy - { - static Result abort() - { - boost::unit_test::framework::test_unit_aborted( - boost::unit_test::framework::current_test_case() ); - throw boost::enable_current_exception( exception() ); - } - - static void checkpoint( const char* file, int line ) - { - boost::unit_test::unit_test_log.set_checkpoint( file, - static_cast< std::size_t >( line ) ); - } - - template< typename Context > - static void fail( - const char* message, const Context& context, - const char* file = "unknown location", int line = 0 ) - { - boost::unit_test::framework::assertion_result( false ); - boost::unit_test::unit_test_log - << boost::unit_test::log::begin( file, - static_cast< std::size_t >( line ) ) - << boost::unit_test::log_all_errors - << message << ": " << context - << boost::unit_test::log::end(); - } - - template< typename Context > - static void expected_call( const Context& context, - const char* file, int line ) - { - boost::unit_test::framework::assertion_result( true ); - boost::unit_test::unit_test_log - << boost::unit_test::log::begin( file, - static_cast< std::size_t >( line ) ) - << boost::unit_test::log_successful_tests - << "mock expectation fulfilled: " << context - << boost::unit_test::log::end(); - } - - template< typename Context > - static void missing_action( const Context& context, - const char* file, int line ) - { - fail( "missing action", context, file, line ); - } - template< typename Context > - static void unexpected_call( const Context& context ) - { - fail( "unexpected call", context ); - } - template< typename Context > - static void sequence_failed( const Context& context, - const char* file, int line ) - { - fail( "sequence failed", context, file, line ); - } - template< typename Context > - static void verification_failed( const Context& context, - const char* file, int line ) - { - fail( "verification failed", context, file, line ); - } - template< typename Context > - static void untriggered_expectation( const Context& context, - const char* file, int line ) - { - fail( "untriggered expectation", context, file, line ); - } - }; -} // mock - -#endif // MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED diff --git a/turtle/config.hpp b/turtle/config.hpp index 3646d90..f93bb59 100644 --- a/turtle/config.hpp +++ b/turtle/config.hpp @@ -43,10 +43,4 @@ # endif #endif -#ifndef MOCK_USE_BOOST_TEST -# ifdef BOOST_TEST_DECL -# define MOCK_USE_BOOST_TEST -# endif -#endif - #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/turtle/default_error.hpp b/turtle/default_error.hpp deleted file mode 100644 index 274454e..0000000 --- a/turtle/default_error.hpp +++ /dev/null @@ -1,76 +0,0 @@ -// http://turtle.sourceforge.net -// -// 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_DEFAULT_ERROR_POLICY_HPP_INCLUDED -#define MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED - -#include - -namespace mock -{ - struct exception - {}; - - template< typename Result > - struct default_error_policy - { - static Result abort() - { - throw exception(); - } - - static void checkpoint( const char* /*file*/, int /*line*/ ) - {} - - template< typename Context > - static void fail( - const char* message, const Context& context, - const char* file = "unknown location", int line = 0 ) - { - std::cerr << file << '(' << line << "): " - << message << ": " << context << std::endl; - } - - template< typename Context > - static void expected_call( const Context& /*context*/, - const char* /*file*/, int /*line*/ ) - {} - - template< typename Context > - static void missing_action( const Context& context, - const char* file, int line ) - { - fail( "missing action", context, file, line ); - } - template< typename Context > - static void unexpected_call( const Context& context ) - { - fail( "unexpected call", context ); - } - template< typename Context > - static void sequence_failed( const Context& context, - const char* file, int line ) - { - fail( "sequence failed", context, file, line ); - } - template< typename Context > - static void verification_failed( const Context& context, - const char* file, int line ) - { - fail( "verification failed", context, file, line ); - } - template< typename Context > - static void untriggered_expectation( const Context& context, - const char* file, int line ) - { - fail( "untriggered expectation", context, file, line ); - } - }; -} // mock - -#endif // MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED diff --git a/turtle/detail/cleanup.hpp b/turtle/detail/cleanup.hpp deleted file mode 100644 index 24032c5..0000000 --- a/turtle/detail/cleanup.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// http://turtle.sourceforge.net -// -// 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_CLEANUP_HPP_INCLUDED -#define MOCK_CLEANUP_HPP_INCLUDED - -#include "../config.hpp" - -#ifdef MOCK_USE_BOOST_TEST - -#include "root.hpp" -#include - -namespace mock -{ -namespace detail -{ - struct cleanup - { - ~cleanup() - { - // $$$$ MAT : because of a bug in Boost.Test - // this will crash if anything needs to be logged - // see https://svn.boost.org/trac/boost/ticket/5563 - //mock::verify(); - mock::reset(); - } - }; - BOOST_GLOBAL_FIXTURE( cleanup ); -} -} // mock - -#endif - -#endif // MOCK_CLEANUP_HPP_INCLUDED diff --git a/turtle/detail/function_impl_template.hpp b/turtle/detail/function_impl_template.hpp index a7ba874..9329924 100644 --- a/turtle/detail/function_impl_template.hpp +++ b/turtle/detail/function_impl_template.hpp @@ -8,6 +8,10 @@ #include "expectation_template.hpp" +#ifndef MOCK_ERROR_POLICY +# error no error policy has been set +#endif + #define MOCK_FORMAT(z, n, N) \ << ' ' << mock::format( t##n ) \ << BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',') diff --git a/turtle/error.hpp b/turtle/error.hpp index 5ef109e..216c3be 100644 --- a/turtle/error.hpp +++ b/turtle/error.hpp @@ -9,16 +9,112 @@ #ifndef MOCK_ERROR_HPP_INCLUDED #define MOCK_ERROR_HPP_INCLUDED -#include "config.hpp" - #ifndef MOCK_ERROR_POLICY -# ifdef MOCK_USE_BOOST_TEST -# define MOCK_ERROR_POLICY boost_test_error_policy -# include "boost_test_error.hpp" -# else -# define MOCK_ERROR_POLICY default_error_policy -# include "default_error.hpp" -# endif -#endif +#define MOCK_ERROR_POLICY mock::error + +#include +#include +#include +#include +#include + +namespace mock +{ + struct exception : virtual boost::execution_aborted + {}; + + template< typename Result > + struct error + { + static Result abort() + { + boost::unit_test::framework::test_unit_aborted( + boost::unit_test::framework::current_test_case() ); + throw boost::enable_current_exception( exception() ); + } + + static void checkpoint( const char* file, int line ) + { + boost::unit_test::unit_test_log.set_checkpoint( file, + static_cast< std::size_t >( line ) ); + } + + template< typename Context > + static void fail( + const char* message, const Context& context, + const char* file = "unknown location", int line = 0 ) + { + boost::unit_test::framework::assertion_result( false ); + boost::unit_test::unit_test_log + << boost::unit_test::log::begin( file, + static_cast< std::size_t >( line ) ) + << boost::unit_test::log_all_errors + << message << ": " << context + << boost::unit_test::log::end(); + } + + template< typename Context > + static void expected_call( const Context& context, + const char* file, int line ) + { + boost::unit_test::framework::assertion_result( true ); + boost::unit_test::unit_test_log + << boost::unit_test::log::begin( file, + static_cast< std::size_t >( line ) ) + << boost::unit_test::log_successful_tests + << "mock expectation fulfilled: " << context + << boost::unit_test::log::end(); + } + + template< typename Context > + static void missing_action( const Context& context, + const char* file, int line ) + { + fail( "missing action", context, file, line ); + } + template< typename Context > + static void unexpected_call( const Context& context ) + { + fail( "unexpected call", context ); + } + template< typename Context > + static void sequence_failed( const Context& context, + const char* file, int line ) + { + fail( "sequence failed", context, file, line ); + } + template< typename Context > + static void verification_failed( const Context& context, + const char* file, int line ) + { + fail( "verification failed", context, file, line ); + } + template< typename Context > + static void untriggered_expectation( const Context& context, + const char* file, int line ) + { + fail( "untriggered expectation", context, file, line ); + } + }; + + bool verify(); + void reset(); + +namespace detail +{ + struct cleanup + { + ~cleanup() + { + // see https://svn.boost.org/trac/boost/ticket/5563 + //mock::verify(); + mock::reset(); + } + }; + BOOST_GLOBAL_FIXTURE( cleanup ); +} +} // mock + +#endif // MOCK_ERROR_POLICY #endif // MOCK_ERROR_HPP_INCLUDED diff --git a/turtle/mock.hpp b/turtle/mock.hpp index 92c4179..5c36a39 100644 --- a/turtle/mock.hpp +++ b/turtle/mock.hpp @@ -18,7 +18,6 @@ #include "detail/type_name.hpp" #include "detail/signature.hpp" #include "detail/parameter.hpp" -#include "detail/cleanup.hpp" #include #include #include