diff --git a/build/vc80/turtle.vcproj b/build/vc80/turtle.vcproj index a211f88..71c4c75 100644 --- a/build/vc80/turtle.vcproj +++ b/build/vc80/turtle.vcproj @@ -160,6 +160,10 @@ RelativePath="..\..\src\libraries\turtle\args.hpp" > + + @@ -176,6 +180,10 @@ RelativePath="..\..\src\libraries\turtle\constraints.hpp" > + + diff --git a/build/vc80/turtle_test.vcproj b/build/vc80/turtle_test.vcproj index e954efa..54a1911 100644 --- a/build/vc80/turtle_test.vcproj +++ b/build/vc80/turtle_test.vcproj @@ -238,10 +238,6 @@ RelativePath="..\..\src\tests\turtle_test\sequence_test.cpp" > - - diff --git a/src/libraries/turtle/boost_test_error.hpp b/src/libraries/turtle/boost_test_error.hpp new file mode 100644 index 0000000..c41e43c --- /dev/null +++ b/src/libraries/turtle/boost_test_error.hpp @@ -0,0 +1,91 @@ +// +// 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 +#include + +namespace mock +{ + struct exception : public 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() ); + } + + template< typename Context > + static void fail( + const std::string& message, const Context& context, + const std::string& 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, (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 std::string& file, int line ) + { + boost::unit_test::framework::assertion_result( true ); + boost::unit_test::unit_test_log + << boost::unit_test::log::begin( file, (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 std::string& 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 std::string& /*file*/, int /*line*/ ) + { + fail( "sequence failed", context ); + } + template< typename Context > + static void verification_failed( const Context& context, + const std::string& file, int line ) + { + fail( "verification failed", context, file, line ); + } + template< typename Context > + static void untriggered_expectation( const Context& context, + const std::string& file, int line ) + { + fail( "untriggered expectation", context, file, line ); + } + }; +} + +#endif // MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED diff --git a/src/libraries/turtle/config.hpp b/src/libraries/turtle/config.hpp index 00bf32d..3bf42f0 100644 --- a/src/libraries/turtle/config.hpp +++ b/src/libraries/turtle/config.hpp @@ -32,16 +32,4 @@ # error BOOST_FUNCTION_MAX_ARGS must be set to MOCK_MAX_ARGS or higher #endif -#ifdef BOOST_TEST_DECL -# define MOCK_USE_BOOST_TEST -#endif - -#ifndef MOCK_ERROR_POLICY -# ifdef MOCK_USE_BOOST_TEST -# define MOCK_ERROR_POLICY boost_test_error_policy -# else -# define MOCK_ERROR_POLICY basic_error_policy -# endif -#endif - #endif // MOCK_CONFIG_HPP_INCLUDED diff --git a/src/libraries/turtle/default_error.hpp b/src/libraries/turtle/default_error.hpp new file mode 100644 index 0000000..6e05f1f --- /dev/null +++ b/src/libraries/turtle/default_error.hpp @@ -0,0 +1,74 @@ +// +// 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 +#include + +namespace mock +{ + struct exception + {}; + + template< typename Result > + struct basic_error_policy + { + static Result abort() + { + throw exception(); + } + + template< typename Context > + static void fail( + const std::string& message, const Context& context, + const std::string& 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 std::string& /*file*/, int /*line*/ ) + {} + + template< typename Context > + static void missing_action( const Context& context, + const std::string& 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 std::string& /*file*/, int /*line*/ ) + { + fail( "sequence failed", context ); + } + template< typename Context > + static void verification_failed( const Context& context, + const std::string& file, int line ) + { + fail( "verification failed", context, file, line ); + } + template< typename Context > + static void untriggered_expectation( const Context& context, + const std::string& file, int line ) + { + fail( "untriggered expectation", context, file, line ); + } + }; +} + +#endif // MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED diff --git a/src/libraries/turtle/error.hpp b/src/libraries/turtle/error.hpp index 80a2ce8..750abb8 100644 --- a/src/libraries/turtle/error.hpp +++ b/src/libraries/turtle/error.hpp @@ -10,118 +10,15 @@ #define MOCK_ERROR_HPP_INCLUDED #include "config.hpp" -#ifdef MOCK_USE_BOOST_TEST -#include -#include -#include -#include -#include -#else -#include -#endif // MOCK_USE_BOOST_TEST -#include -namespace mock -{ -#ifdef MOCK_USE_BOOST_TEST - - struct exception : public 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() ); - } - - template< typename Context > - static void fail( - const std::string& message, const Context& context, - const std::string& 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, (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 std::string& file, int line ) - { - boost::unit_test::framework::assertion_result( true ); - boost::unit_test::unit_test_log - << boost::unit_test::log::begin( file, (std::size_t)line ) - << boost::unit_test::log_successful_tests - << "mock expectation fulfilled: " << context - << boost::unit_test::log::end(); - } - -#else // MOCK_USE_BOOST_TEST - - struct exception - {}; - - template< typename Result > - struct basic_error_policy - { - static Result abort() - { - throw exception(); - } - - template< typename Context > - static void fail( - const std::string& message, const Context& context, - const std::string& 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 std::string& /*file*/, int /*line*/ ) - {} - -#endif // MOCK_USE_BOOST_TEST - - template< typename Context > - static void missing_action( const Context& context, - const std::string& 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 std::string& /*file*/, int /*line*/ ) - { - fail( "sequence failed", context ); - } - template< typename Context > - static void verification_failed( const Context& context, - const std::string& file, int line ) - { - fail( "verification failed", context, file, line ); - } - template< typename Context > - static void untriggered_expectation( const Context& context, - const std::string& file, int line ) - { - fail( "untriggered expectation", context, file, line ); - } - }; -} +#ifndef MOCK_ERROR_POLICY +# if defined(BOOST_TEST_DECL) || defined(MOCK_USE_BOOST_TEST) +# define MOCK_ERROR_POLICY boost_test_error_policy +# include "boost_test_error.hpp" +# else +# define MOCK_ERROR_POLICY basic_error_policy +# include "default_error.hpp" +# endif +#endif #endif // MOCK_ERROR_HPP_INCLUDED diff --git a/src/libraries/turtle/mock.hpp b/src/libraries/turtle/mock.hpp index b63c16b..f62b7ac 100644 --- a/src/libraries/turtle/mock.hpp +++ b/src/libraries/turtle/mock.hpp @@ -10,7 +10,6 @@ #define MOCK_MOCK_HPP_INCLUDED #include "config.hpp" -#include "error.hpp" #include "object.hpp" #include "function.hpp" #include "type_name.hpp" diff --git a/src/tests/turtle_test/function_test.cpp b/src/tests/turtle_test/function_test.cpp index ae672aa..afc8422 100644 --- a/src/tests/turtle_test/function_test.cpp +++ b/src/tests/turtle_test/function_test.cpp @@ -22,7 +22,7 @@ expected_call_count = 0; #define CHECK_ERROR( expr, error, calls, context ) \ BOOST_CHECK( verify() ); \ - expr; \ + try { expr; } catch( ... ) {} \ BOOST_CHECK_EQUAL( 1, error##_count ); \ CHECK_CALLS( calls ); \ BOOST_CHECK_EQUAL( context, last_context ); \ diff --git a/src/tests/turtle_test/integration_test.cpp b/src/tests/turtle_test/integration_test.cpp index d078ee2..451d671 100644 --- a/src/tests/turtle_test/integration_test.cpp +++ b/src/tests/turtle_test/integration_test.cpp @@ -6,13 +6,13 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#include "silent_error.hpp" +#include "mock_error.hpp" #include #define BOOST_LIB_NAME boost_unit_test_framework #include -#define MOCK_ERROR_POLICY silent_error +#define MOCK_ERROR_POLICY mock_error #include #include diff --git a/src/tests/turtle_test/max_args_test.cpp b/src/tests/turtle_test/max_args_test.cpp index 1642446..ac78f13 100644 --- a/src/tests/turtle_test/max_args_test.cpp +++ b/src/tests/turtle_test/max_args_test.cpp @@ -7,9 +7,9 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#include "silent_error.hpp" +#include "mock_error.hpp" -#define MOCK_ERROR_POLICY silent_error +#define MOCK_ERROR_POLICY mock_error #include #include diff --git a/src/tests/turtle_test/mock_error.hpp b/src/tests/turtle_test/mock_error.hpp index 11724c1..777fe93 100644 --- a/src/tests/turtle_test/mock_error.hpp +++ b/src/tests/turtle_test/mock_error.hpp @@ -31,8 +31,7 @@ namespace mock { static Result abort() { - static BOOST_DEDUCED_TYPENAME boost::remove_reference< Result >::type r; - return r; + throw std::runtime_error( "aborted" ); } template< typename Context > @@ -43,57 +42,10 @@ namespace mock ++missing_action_count; } template< typename Context > - static void expected_call( const Context& context, + static void expected_call( const Context& /*context*/, const std::string& /*file*/, int /*line*/ ) { - last_context = boost::lexical_cast< std::string >( context ); - ++expected_call_count; - } - template< typename Context > - static void unexpected_call( const Context& context ) - { - last_context = boost::lexical_cast< std::string >( context ); - ++unexpected_call_count; - } - template< typename Context > - static void sequence_failed( const Context& context, - const std::string& /*file*/, int /*line*/ ) - { - last_context = boost::lexical_cast< std::string >( context ); - ++sequence_failed_count; - } - template< typename Context > - static void verification_failed( const Context& context, - const std::string& /*file*/, int /*line*/ ) - { - last_context = boost::lexical_cast< std::string >( context ); - ++verification_failed_count; - } - template< typename Context > - static void untriggered_expectation( const Context& context, - const std::string& /*file*/, int /*line*/ ) - { - last_context = boost::lexical_cast< std::string >( context ); - ++untriggered_expectation_count; - } - }; - template<> - struct mock_error< void > - { - static void abort() - {} - template< typename Context > - static void missing_action( const Context& context, - const std::string& /*file*/, int /*line*/ ) - { - last_context = boost::lexical_cast< std::string >( context ); - ++missing_action_count; - } - template< typename Context > - static void expected_call( const Context& context, - const std::string& /*file*/, int /*line*/ ) - { - last_context = boost::lexical_cast< std::string >( context ); + last_context.clear(); ++expected_call_count; } template< typename Context > diff --git a/src/tests/turtle_test/mock_test.cpp b/src/tests/turtle_test/mock_test.cpp index 9163b84..5b788cf 100644 --- a/src/tests/turtle_test/mock_test.cpp +++ b/src/tests/turtle_test/mock_test.cpp @@ -6,7 +6,6 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#define MOCK_USE_BOOST_TEST #include #include #include diff --git a/src/tests/turtle_test/object_test.cpp b/src/tests/turtle_test/object_test.cpp index 2d4daae..a44a030 100644 --- a/src/tests/turtle_test/object_test.cpp +++ b/src/tests/turtle_test/object_test.cpp @@ -6,13 +6,13 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#include "silent_error.hpp" +#include "mock_error.hpp" #include #define BOOST_LIB_NAME boost_unit_test_framework #include -#define MOCK_ERROR_POLICY silent_error +#define MOCK_ERROR_POLICY mock_error #include #include diff --git a/src/tests/turtle_test/sequence_test.cpp b/src/tests/turtle_test/sequence_test.cpp index 431e07f..ec1fc8d 100644 --- a/src/tests/turtle_test/sequence_test.cpp +++ b/src/tests/turtle_test/sequence_test.cpp @@ -6,13 +6,13 @@ // http://www.boost.org/LICENSE_1_0.txt) // -#include "silent_error.hpp" +#include "mock_error.hpp" #include #define BOOST_LIB_NAME boost_unit_test_framework #include -#define MOCK_ERROR_POLICY silent_error +#define MOCK_ERROR_POLICY mock_error #include BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws ) diff --git a/src/tests/turtle_test/silent_error.hpp b/src/tests/turtle_test/silent_error.hpp deleted file mode 100644 index ea07381..0000000 --- a/src/tests/turtle_test/silent_error.hpp +++ /dev/null @@ -1,50 +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_TEST_SILENT_ERROR_HPP_INCLUDED -#define MOCK_TEST_SILENT_ERROR_HPP_INCLUDED - -#include -#include - -namespace mock -{ - template< typename Result > - struct silent_error - { - static Result abort() - { - throw std::runtime_error( "abort" ); - } - template< typename Context > - static void expected_call( const Context& /*context*/, - const std::string& /*file*/, int /*line*/ ) - {} - template< typename Context > - static void unexpected_call( const Context& /*context*/ ) - {} - template< typename Context > - static void missing_action( const Context& /*context*/, - const std::string& /*file*/, int /*line*/ ) - {} - template< typename Context > - static void sequence_failed( const Context& /*context*/, - const std::string& /*file*/, int /*line*/ ) - {} - template< typename Context > - static void verification_failed( const Context& /*context*/, - const std::string& /*file*/, int /*line*/ ) - {} - template< typename Context > - static void untriggered_expectation( const Context& /*context*/, - const std::string& /*file*/, int /*line*/ ) - {} - }; -} - -#endif // MOCK_TEST_SILENT_ERROR_HPP_INCLUDED