Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@311 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-05-08 17:44:49 +00:00
parent 8d7b34792d
commit 5f651655c6
15 changed files with 194 additions and 240 deletions

View file

@ -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 ); \

View file

@ -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>

View file

@ -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>

View file

@ -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 >

View file

@ -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>

View file

@ -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>

View file

@ -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 )

View file

@ -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