mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@311 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
8d7b34792d
commit
5f651655c6
15 changed files with 194 additions and 240 deletions
|
|
@ -160,6 +160,10 @@
|
|||
RelativePath="..\..\src\libraries\turtle\args.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\libraries\turtle\boost_test_error.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\libraries\turtle\check.hpp"
|
||||
>
|
||||
|
|
@ -176,6 +180,10 @@
|
|||
RelativePath="..\..\src\libraries\turtle\constraints.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\libraries\turtle\default_error.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\libraries\turtle\error.hpp"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -238,10 +238,6 @@
|
|||
RelativePath="..\..\src\tests\turtle_test\sequence_test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\tests\turtle_test\silent_error.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\tests\turtle_test\type_name_test.cpp"
|
||||
>
|
||||
|
|
|
|||
91
src/libraries/turtle/boost_test_error.hpp
Normal file
91
src/libraries/turtle/boost_test_error.hpp
Normal file
|
|
@ -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 <boost/test/framework.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/test/execution_monitor.hpp>
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
74
src/libraries/turtle/default_error.hpp
Normal file
74
src/libraries/turtle/default_error.hpp
Normal file
|
|
@ -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 <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
|
@ -10,118 +10,15 @@
|
|||
#define MOCK_ERROR_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#ifdef MOCK_USE_BOOST_TEST
|
||||
#include <boost/test/framework.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/unit_test_suite.hpp>
|
||||
#include <boost/test/execution_monitor.hpp>
|
||||
#include <boost/exception/enable_current_exception.hpp>
|
||||
#else
|
||||
#include <iostream>
|
||||
#endif // MOCK_USE_BOOST_TEST
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 ); \
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "silent_error.hpp"
|
||||
#include "mock_error.hpp"
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
#define MOCK_ERROR_POLICY silent_error
|
||||
#define MOCK_ERROR_POLICY mock_error
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
|
|
|||
|
|
@ -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 <turtle/mock.hpp>
|
||||
#include <boost/preprocessor/repetition/enum.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 >
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#define MOCK_USE_BOOST_TEST
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "silent_error.hpp"
|
||||
#include "mock_error.hpp"
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
#define MOCK_ERROR_POLICY silent_error
|
||||
#define MOCK_ERROR_POLICY mock_error
|
||||
#include <turtle/object.hpp>
|
||||
#include <turtle/function.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "silent_error.hpp"
|
||||
#include "mock_error.hpp"
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
#define MOCK_ERROR_POLICY silent_error
|
||||
#define MOCK_ERROR_POLICY mock_error
|
||||
#include <turtle/mock.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws )
|
||||
|
|
|
|||
|
|
@ -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 <string>
|
||||
#include <stdexcept>
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue