From 66268d74dbf2da989fd3ed57871aa9e92d55205f Mon Sep 17 00:00:00 2001 From: mat007 Date: Wed, 21 Jul 2010 07:54:25 +0000 Subject: [PATCH] Added Boost.Test log info when an expectation is fulfilled git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@164 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/error.hpp | 18 ++++++++++++++++++ src/libraries/turtle/function.hpp | 3 +++ src/tests/turtle_test/mock_error.hpp | 6 ++++++ src/tests/turtle_test/silent_error.hpp | 3 +++ 4 files changed, 30 insertions(+) diff --git a/src/libraries/turtle/error.hpp b/src/libraries/turtle/error.hpp index 4a575c5..e41d8a1 100644 --- a/src/libraries/turtle/error.hpp +++ b/src/libraries/turtle/error.hpp @@ -31,6 +31,8 @@ namespace mock { static Result abort() { + boost::unit_test::framework::test_unit_aborted( + boost::unit_test::framework::current_test_case() ); throw boost::enable_current_exception( exception() ); } @@ -47,6 +49,18 @@ namespace mock << boost::unit_test::log::end(); } + static void expected_call( const std::string& 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 + << boost::unit_test::lazy_ostream::instance() + << "mock expectation fulfilled: " << context + << boost::unit_test::log::end(); + } + #else // MOCK_USE_BOOST_TEST struct exception @@ -68,6 +82,10 @@ namespace mock << "mock error: " << message << ": " << context << std::endl; } + static void expected_call( const std::string& /*context*/, + const std::string& /*file*/, int /*line*/ ) + {} + #endif // MOCK_USE_BOOST_TEST static void missing_action( const std::string& context, diff --git a/src/libraries/turtle/function.hpp b/src/libraries/turtle/function.hpp index dcaa43b..921e876 100644 --- a/src/libraries/turtle/function.hpp +++ b/src/libraries/turtle/function.hpp @@ -222,6 +222,7 @@ namespace mock ErrorPolicy::missing_action( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ return ErrorPolicy::abort(); \ } \ + ErrorPolicy::expected_call( MOCK_EXPECTATION_CONTEXT(n), it->file(), it->line() ); \ return it->functor()( BOOST_PP_ENUM_PARAMS(n, p) ); \ } \ valid_ = false; \ @@ -259,6 +260,8 @@ namespace mock it->file(), it->line() ); return T::abort(); } + ErrorPolicy::expected_call( context( "" ), + it->file(), it->line() ); return it->functor()(); } valid_ = false; diff --git a/src/tests/turtle_test/mock_error.hpp b/src/tests/turtle_test/mock_error.hpp index 7438217..dcc5618 100644 --- a/src/tests/turtle_test/mock_error.hpp +++ b/src/tests/turtle_test/mock_error.hpp @@ -36,6 +36,9 @@ namespace mock { ++missing_action_count; } + static void expected_call( const std::string& /*context*/, + const std::string& /*file*/, int /*line*/ ) + {} static void unexpected_call( const std::string& /*context*/ ) { ++unexpected_call_count; @@ -66,6 +69,9 @@ namespace mock { ++missing_action_count; } + static void expected_call( const std::string& /*context*/, + const std::string& /*file*/, int /*line*/ ) + {} static void unexpected_call( const std::string& /*context*/ ) { ++unexpected_call_count; diff --git a/src/tests/turtle_test/silent_error.hpp b/src/tests/turtle_test/silent_error.hpp index c89dc63..911fdb4 100644 --- a/src/tests/turtle_test/silent_error.hpp +++ b/src/tests/turtle_test/silent_error.hpp @@ -22,6 +22,9 @@ namespace mock { throw std::runtime_error( "abort" ); } + static void expected_call( const std::string& /*context*/, + const std::string& /*file*/, int /*line*/ ) + {} static void unexpected_call( const std::string& /*context*/ ) {} static void missing_action( const std::string& /*context*/,