Format code using Clang-Format 10 and enforce via CI

Makes the format of the code base uniform.
This commit is contained in:
Alexander Grund 2022-01-24 16:11:29 +01:00
parent b5bb500bd2
commit ee72e8b9d8
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
97 changed files with 11189 additions and 10842 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -10,11 +10,11 @@
#define MOCK_TEST_DEFINED_HPP_INCLUDED
#ifdef BOOST_AUTO_TEST_MAIN
#undef BOOST_AUTO_TEST_MAIN
# undef BOOST_AUTO_TEST_MAIN
#endif
#include <turtle/mock.hpp>
MOCK_FUNCTION( f, 0, void(), f )
MOCK_FUNCTION(f, 0, void(), f)
#endif // MOCK_TEST_DEFINED_HPP_INCLUDED

File diff suppressed because it is too large Load diff

View file

@ -9,68 +9,68 @@
#include <turtle/detail/invocation.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( unlimited )
BOOST_AUTO_TEST_CASE(unlimited)
{
mock::detail::unlimited invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK(invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
}
BOOST_AUTO_TEST_CASE( once )
BOOST_AUTO_TEST_CASE(once)
{
mock::detail::once invocation;
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
BOOST_CHECK(!invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(invocation.exhausted());
BOOST_CHECK(!invocation.invoke());
}
BOOST_AUTO_TEST_CASE( never )
BOOST_AUTO_TEST_CASE(never)
{
mock::detail::never invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
BOOST_CHECK(invocation.verify());
BOOST_CHECK(invocation.exhausted());
BOOST_CHECK(!invocation.invoke());
}
BOOST_AUTO_TEST_CASE( at_most )
BOOST_AUTO_TEST_CASE(at_most)
{
mock::detail::at_most invocation( 1 );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
mock::detail::at_most invocation(1);
BOOST_CHECK(invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(invocation.exhausted());
BOOST_CHECK(!invocation.invoke());
}
BOOST_AUTO_TEST_CASE( at_least )
BOOST_AUTO_TEST_CASE(at_least)
{
mock::detail::at_least invocation( 1 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
mock::detail::at_least invocation(1);
BOOST_CHECK(!invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
}
BOOST_AUTO_TEST_CASE( between )
BOOST_AUTO_TEST_CASE(between)
{
mock::detail::between invocation( 1, 2 );
BOOST_CHECK( ! invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( ! invocation.exhausted() );
BOOST_CHECK( invocation.invoke() );
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
mock::detail::between invocation(1, 2);
BOOST_CHECK(!invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(!invocation.exhausted());
BOOST_CHECK(invocation.invoke());
BOOST_CHECK(invocation.verify());
BOOST_CHECK(invocation.exhausted());
BOOST_CHECK(!invocation.invoke());
}

View file

@ -9,110 +9,115 @@
#include <turtle/detail/is_functor.hpp>
#include <boost/test/unit_test.hpp>
#ifdef BOOST_MSVC
#pragma warning( push, 0 )
# pragma warning(push, 0)
#endif
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/phoenix.hpp>
#ifdef BOOST_MSVC
#pragma warning( pop )
# pragma warning(pop)
#endif
#include <boost/function.hpp>
#include <boost/bind/bind.hpp>
#include <boost/bind/placeholders.hpp>
#include <boost/function.hpp>
#include <boost/version.hpp>
#include <functional>
namespace
namespace {
struct declared_but_not_defined;
static_assert(!mock::detail::is_functor<declared_but_not_defined, int>::value, "Should not be a functor");
template<typename T>
void is_functor(T)
{
struct declared_but_not_defined;
static_assert( !mock::detail::is_functor< declared_but_not_defined, int >::value, "Should not be a functor" );
template< typename T >
void is_functor( T )
{
static_assert( mock::detail::is_functor< T, int >::value, "Should be a functor taking an int");
}
template< typename T >
void is_not_functor( T )
{
static_assert( !mock::detail::is_functor< T, int >::value, "Should not be a functor taking an int" );
}
void f0() {}
bool f1( int ) { return false; }
bool f2( std::string, int ) { return false; }
static_assert(mock::detail::is_functor<T, int>::value, "Should be a functor taking an int");
}
template<typename T>
void is_not_functor(T)
{
static_assert(!mock::detail::is_functor<T, int>::value, "Should not be a functor taking an int");
}
BOOST_AUTO_TEST_CASE( data_is_not_functor )
void f0() {}
bool f1(int)
{
is_not_functor( 42 );
return false;
}
bool f2(std::string, int)
{
return false;
}
} // namespace
BOOST_AUTO_TEST_CASE(data_is_not_functor)
{
is_not_functor(42);
}
BOOST_AUTO_TEST_CASE( function_is_functor )
BOOST_AUTO_TEST_CASE(function_is_functor)
{
is_not_functor( f0 );
is_functor( f1 );
is_not_functor( f2 );
is_not_functor(f0);
is_functor(f1);
is_not_functor(f2);
}
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
BOOST_AUTO_TEST_CASE(function_pointer_is_functor)
{
is_not_functor( &f0 );
is_functor( &f1 );
is_not_functor( &f2 );
is_not_functor(&f0);
is_functor(&f1);
is_not_functor(&f2);
}
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
BOOST_AUTO_TEST_CASE(std_ptr_fun_is_functor)
{
is_functor( std::ptr_fun( &f1 ) );
is_not_functor( std::ptr_fun( &f2 ) );
is_functor(std::ptr_fun(&f1));
is_not_functor(std::ptr_fun(&f2));
}
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
BOOST_AUTO_TEST_CASE(std_bind_first_is_functor)
{
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
is_functor(std::bind1st(std::ptr_fun(&f2), ""));
}
BOOST_AUTO_TEST_CASE( bind_is_functor )
BOOST_AUTO_TEST_CASE(bind_is_functor)
{
{
#if BOOST_VERSION >= 106000
using namespace boost::placeholders;
#endif
is_functor( boost::bind( &f0 ) );
is_functor( boost::bind( &f1, _1 ) );
is_functor( boost::bind( &f2, "", _1 ) );
is_functor(boost::bind(&f0));
is_functor(boost::bind(&f1, _1));
is_functor(boost::bind(&f2, "", _1));
}
is_functor( std::bind( &f0 ) );
is_functor( std::bind( &f1, std::placeholders::_1 ) );
is_functor( std::bind( &f2, "", std::placeholders::_1 ) );
is_functor(std::bind(&f0));
is_functor(std::bind(&f1, std::placeholders::_1));
is_functor(std::bind(&f2, "", std::placeholders::_1));
}
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
BOOST_AUTO_TEST_CASE(boost_lambda_is_functor)
{
is_functor( boost::lambda::_1 < 42 );
is_functor(boost::lambda::_1 < 42);
}
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
BOOST_AUTO_TEST_CASE(boost_phoenix_is_functor)
{
is_functor( boost::phoenix::arg_names::arg1 < 42 );
is_functor( boost::phoenix::arg_names::_1 < 42 );
is_functor(boost::phoenix::arg_names::arg1 < 42);
is_functor(boost::phoenix::arg_names::_1 < 42);
}
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
BOOST_AUTO_TEST_CASE(boost_function_is_functor)
{
is_functor( boost::function< void(int) >() );
is_functor(boost::function<void(int)>());
}
BOOST_AUTO_TEST_CASE( std_function_is_functor )
BOOST_AUTO_TEST_CASE(std_function_is_functor)
{
is_functor( std::function< void(int) >() );
is_functor(std::function<void(int)>());
}
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
BOOST_AUTO_TEST_CASE(cxx11_lambda_is_functor)
{
is_not_functor( []() {} );
is_functor( []( int ) {} );
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
is_not_functor([]() {});
is_functor([](int) {});
is_not_functor([](const std::string&, int) {});
is_not_functor([](int, const std::string&) {});
}

View file

@ -10,18 +10,17 @@
#include <boost/test/unit_test.hpp>
#include <type_traits>
namespace
namespace {
struct base
{
struct base
{
void method_1();
float method_2( int ) const;
};
typedef base base_type;
}
void method_1();
float method_2(int) const;
};
typedef base base_type;
} // namespace
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
BOOST_AUTO_TEST_CASE(mock_signature_generates_signature)
{
static_assert( std::is_same< void(), MOCK_SIGNATURE(method_1) >::value, "!");
static_assert( std::is_same< float( int ), MOCK_SIGNATURE(method_2) >::value, "!");
static_assert(std::is_same<void(), MOCK_SIGNATURE(method_1)>::value, "!");
static_assert(std::is_same<float(int), MOCK_SIGNATURE(method_2)>::value, "!");
}

View file

@ -10,218 +10,216 @@
#include <boost/test/unit_test.hpp>
#include <sstream>
namespace
namespace {
template<typename T>
std::string to_string(const T& t)
{
template< typename T >
std::string to_string( const T& t)
{
std::ostringstream s;
s << mock::detail::make_type_name(t);
return s.str();
}
std::ostringstream s;
s << mock::detail::make_type_name(t);
return s.str();
}
} // namespace
BOOST_AUTO_TEST_CASE( name_of_base_type_is_extracted )
BOOST_AUTO_TEST_CASE(name_of_base_type_is_extracted)
{
BOOST_CHECK_EQUAL( "char", to_string( 'a' ) );
BOOST_CHECK_EQUAL( "bool", to_string( true ) );
BOOST_CHECK_EQUAL( "int", to_string< int >( 0 ) );
BOOST_CHECK_EQUAL( "short", to_string< short >( 0 ) );
BOOST_CHECK_EQUAL( "long", to_string< long >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned int", to_string< unsigned int >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned short", to_string< unsigned short >( 0 ) );
BOOST_CHECK_EQUAL( "unsigned long", to_string< unsigned long >( 0 ) );
BOOST_CHECK_EQUAL("char", to_string('a'));
BOOST_CHECK_EQUAL("bool", to_string(true));
BOOST_CHECK_EQUAL("int", to_string<int>(0));
BOOST_CHECK_EQUAL("short", to_string<short>(0));
BOOST_CHECK_EQUAL("long", to_string<long>(0));
BOOST_CHECK_EQUAL("unsigned int", to_string<unsigned int>(0));
BOOST_CHECK_EQUAL("unsigned short", to_string<unsigned short>(0));
BOOST_CHECK_EQUAL("unsigned long", to_string<unsigned long>(0));
}
struct my_type_in_default_namespace
{
struct inner {};
struct inner
{};
};
BOOST_AUTO_TEST_CASE( name_of_type_in_default_namespace_is_extracted )
BOOST_AUTO_TEST_CASE(name_of_type_in_default_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "my_type_in_default_namespace", to_string( my_type_in_default_namespace() ) );
BOOST_CHECK_EQUAL("my_type_in_default_namespace", to_string(my_type_in_default_namespace()));
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_type_in_default_namespace_is_extracted )
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_type_in_default_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "inner", to_string( my_type_in_default_namespace::inner() ) );
BOOST_CHECK_EQUAL("inner", to_string(my_type_in_default_namespace::inner()));
}
template< typename T >
template<typename T>
struct my_template_type_in_default_namespace
{
struct inner {};
struct inner
{};
};
BOOST_AUTO_TEST_CASE( name_of_template_type_in_default_namespace_is_extracted )
BOOST_AUTO_TEST_CASE(name_of_template_type_in_default_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "my_template_type_in_default_namespace<int>", to_string( my_template_type_in_default_namespace<int>() ) );
BOOST_CHECK_EQUAL("my_template_type_in_default_namespace<int>",
to_string(my_template_type_in_default_namespace<int>()));
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_default_namespace_is_extracted )
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_template_type_in_default_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type_in_default_namespace<int>::inner() ) );
BOOST_CHECK_EQUAL("inner", to_string(my_template_type_in_default_namespace<int>::inner()));
}
namespace
namespace {
struct my_type_in_anonymous_namespace
{};
} // namespace
BOOST_AUTO_TEST_CASE(name_of_type_in_anonymous_namespace_is_extracted)
{
struct my_type_in_anonymous_namespace {};
BOOST_CHECK_EQUAL("my_type_in_anonymous_namespace", to_string(my_type_in_anonymous_namespace()));
}
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
namespace nm {
struct my_type_from_named_namespace
{};
} // namespace nm
BOOST_AUTO_TEST_CASE(name_of_type_from_named_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_namespace() ) );
BOOST_CHECK_EQUAL("my_type_from_named_namespace", to_string(nm::my_type_from_named_namespace()));
}
namespace nm
{
struct my_type_from_named_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
}
namespace nm
{
namespace inner
{
struct my_type_in_named_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_named_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_named_inner_namespace", to_string( nm::inner::my_type_in_named_inner_namespace() ) );
}
namespace
{
namespace inner
{
struct my_type_in_unnamed_inner_namespace {};
}
}
BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_unnamed_inner_namespace", to_string( inner::my_type_in_unnamed_inner_namespace() ) );
}
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
{
struct my_local_type {};
BOOST_CHECK_EQUAL( "my_local_type", to_string( my_local_type() ) );
}
namespace
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( my_template_type< std::exception const*& >::inner() ) );
}
namespace nm
{
template< typename T >
struct my_template_type
{
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_template_type<int>", to_string( nm::my_template_type< int >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception>", to_string( nm::my_template_type< std::exception >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const&>", to_string( nm::my_template_type< int const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const&>", to_string( nm::my_template_type< std::exception const& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*>", to_string( nm::my_template_type< int const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*>", to_string( nm::my_template_type< std::exception const* >() ) );
BOOST_CHECK_EQUAL( "my_template_type<int const*&>", to_string( nm::my_template_type< int const*& >() ) );
BOOST_CHECK_EQUAL( "my_template_type<exception const*&>", to_string( nm::my_template_type< std::exception const*& >() ) );
}
BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const* >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< int const*& >::inner() ) );
BOOST_CHECK_EQUAL( "inner", to_string( nm::my_template_type< std::exception const*& >::inner() ) );
}
namespace nm2
{
template< typename T >
struct my_template_type
{
template< typename U >
struct inner {};
};
}
BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< int const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int>", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< int >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const&>", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< int >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*>", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< int >::inner< int const*& >() ) );
BOOST_CHECK_EQUAL( "inner<int const*&>", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) );
}
namespace
{
template< typename T1, typename T2, typename T3 >
struct my_tpl
namespace nm { namespace inner {
struct my_type_in_named_inner_namespace
{};
}} // namespace nm::inner
BOOST_AUTO_TEST_CASE(name_of_type_in_named_inner_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("my_type_in_named_inner_namespace", to_string(nm::inner::my_type_in_named_inner_namespace()));
}
BOOST_AUTO_TEST_CASE( name_of_nested_template_with_multiple_arguments_is_extracted )
namespace { namespace inner {
struct my_type_in_unnamed_inner_namespace
{};
}} // namespace ::inner
BOOST_AUTO_TEST_CASE(name_of_type_in_unnamed_inner_namespace_is_extracted)
{
BOOST_CHECK_EQUAL( "vector<int, allocator<int>>", to_string( std::vector< int >() ) );
BOOST_CHECK_EQUAL( "vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>", to_string( std::vector< std::vector< int > >() ) );
BOOST_CHECK_EQUAL( "my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>", to_string( my_tpl< my_tpl< int, int, int >, my_tpl< int, int, int >, my_tpl< int, int, int > >() ) );
BOOST_CHECK_EQUAL("my_type_in_unnamed_inner_namespace", to_string(inner::my_type_in_unnamed_inner_namespace()));
}
BOOST_AUTO_TEST_CASE(name_of_local_type_is_extracted)
{
struct my_local_type
{};
BOOST_CHECK_EQUAL("my_local_type", to_string(my_local_type()));
}
namespace {
template<typename T>
struct my_template_type
{
struct inner
{};
};
} // namespace
BOOST_AUTO_TEST_CASE(name_of_template_type_in_anonymous_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("my_template_type<int>", to_string(my_template_type<int>()));
BOOST_CHECK_EQUAL("my_template_type<exception>", to_string(my_template_type<std::exception>()));
BOOST_CHECK_EQUAL("my_template_type<int const&>", to_string(my_template_type<int const&>()));
BOOST_CHECK_EQUAL("my_template_type<exception const&>", to_string(my_template_type<std::exception const&>()));
BOOST_CHECK_EQUAL("my_template_type<int const*>", to_string(my_template_type<int const*>()));
BOOST_CHECK_EQUAL("my_template_type<exception const*>", to_string(my_template_type<std::exception const*>()));
BOOST_CHECK_EQUAL("my_template_type<int const*&>", to_string(my_template_type<int const*&>()));
BOOST_CHECK_EQUAL("my_template_type<exception const*&>", to_string(my_template_type<std::exception const*&>()));
}
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_template_type_in_anonymous_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<int>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<int const&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception const&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<int const*>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception const*>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<int const*&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(my_template_type<std::exception const*&>::inner()));
}
namespace nm {
template<typename T>
struct my_template_type
{
struct inner
{};
};
} // namespace nm
BOOST_AUTO_TEST_CASE(name_of_template_type_in_named_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("my_template_type<int>", to_string(nm::my_template_type<int>()));
BOOST_CHECK_EQUAL("my_template_type<exception>", to_string(nm::my_template_type<std::exception>()));
BOOST_CHECK_EQUAL("my_template_type<int const&>", to_string(nm::my_template_type<int const&>()));
BOOST_CHECK_EQUAL("my_template_type<exception const&>", to_string(nm::my_template_type<std::exception const&>()));
BOOST_CHECK_EQUAL("my_template_type<int const*>", to_string(nm::my_template_type<int const*>()));
BOOST_CHECK_EQUAL("my_template_type<exception const*>", to_string(nm::my_template_type<std::exception const*>()));
BOOST_CHECK_EQUAL("my_template_type<int const*&>", to_string(nm::my_template_type<int const*&>()));
BOOST_CHECK_EQUAL("my_template_type<exception const*&>", to_string(nm::my_template_type<std::exception const*&>()));
}
BOOST_AUTO_TEST_CASE(name_of_inner_type_from_template_type_in_named_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<int>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<int const&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception const&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<int const*>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception const*>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<int const*&>::inner()));
BOOST_CHECK_EQUAL("inner", to_string(nm::my_template_type<std::exception const*&>::inner()));
}
namespace nm2 {
template<typename T>
struct my_template_type
{
template<typename U>
struct inner
{};
};
} // namespace nm2
BOOST_AUTO_TEST_CASE(name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted)
{
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<int>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<std::exception>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<int const&>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<std::exception const&>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<int const*>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<std::exception const*>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<int const*&>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int>", to_string(nm2::my_template_type<std::exception const*&>::inner<int>()));
BOOST_CHECK_EQUAL("inner<int const&>", to_string(nm2::my_template_type<int>::inner<int const&>()));
BOOST_CHECK_EQUAL("inner<int const&>", to_string(nm2::my_template_type<std::exception>::inner<int const&>()));
BOOST_CHECK_EQUAL("inner<int const*>", to_string(nm2::my_template_type<int>::inner<int const*>()));
BOOST_CHECK_EQUAL("inner<int const*>", to_string(nm2::my_template_type<std::exception>::inner<int const*>()));
BOOST_CHECK_EQUAL("inner<int const*&>", to_string(nm2::my_template_type<int>::inner<int const*&>()));
BOOST_CHECK_EQUAL("inner<int const*&>", to_string(nm2::my_template_type<std::exception>::inner<int const*&>()));
}
namespace {
template<typename T1, typename T2, typename T3>
struct my_tpl
{};
} // namespace
BOOST_AUTO_TEST_CASE(name_of_nested_template_with_multiple_arguments_is_extracted)
{
BOOST_CHECK_EQUAL("vector<int, allocator<int>>", to_string(std::vector<int>()));
BOOST_CHECK_EQUAL("vector<vector<int, allocator<int>>, allocator<vector<int, allocator<int>>>>",
to_string(std::vector<std::vector<int>>()));
BOOST_CHECK_EQUAL("my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>",
to_string(my_tpl<my_tpl<int, int, int>, my_tpl<int, int, int>, my_tpl<int, int, int>>()));
}

View file

@ -8,17 +8,16 @@
#include <turtle/mock.hpp>
namespace
namespace {
struct my_base
{
struct my_base
{
virtual ~my_base() = default;
virtual void my_method() = 0;
virtual void my_method( int ) = 0;
};
virtual ~my_base() = default;
virtual void my_method() = 0;
virtual void my_method(int) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}
MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 0)
};
} // namespace

View file

@ -12,7 +12,10 @@ MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
bool constraint(int, int) { return true; }
bool constraint(int, int)
{
return true;
}
void test_case()
{

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( "42" );
MOCK_EXPECT(c.my_method).with("42");
}

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( mock::equal( "42" ) );
MOCK_EXPECT(c.my_method).with(mock::equal("42"));
}

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 0, int(), my_method )
MOCK_METHOD_EXT(my_method, 0, int(), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( std::string() );
MOCK_EXPECT(c.my_method).returns(std::string());
}

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 0, std::string(), my_method )
MOCK_METHOD_EXT(my_method, 0, std::string(), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( 42 );
MOCK_EXPECT(c.my_method).returns(42);
}

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
MOCK_METHOD_EXT(my_method, 0, void(), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).returns( "42" );
MOCK_EXPECT(c.my_method).returns("42");
}

View file

@ -8,15 +8,14 @@
#include <turtle/mock.hpp>
namespace
namespace {
struct my_base
{
struct my_base
{
virtual ~my_base() = default;
};
virtual ~my_base() = default;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 0 )
};
}
MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 0)
};
} // namespace

View file

@ -8,18 +8,17 @@
#include <turtle/mock.hpp>
BOOST_STATIC_ASSERT( MOCK_MAX_ARGS == 9 );
BOOST_STATIC_ASSERT(MOCK_MAX_ARGS == 9);
namespace
namespace {
struct my_base
{
struct my_base
{
virtual ~my_base() = default;
virtual void my_method( int, int, int, int, int, int, int, int, int, int ) = 0;
};
virtual ~my_base() = default;
virtual void my_method(int, int, int, int, int, int, int, int, int, int) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 10 )
};
}
MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 10)
};
} // namespace

View file

@ -8,16 +8,15 @@
#include <turtle/mock.hpp>
namespace
namespace {
struct my_base
{
struct my_base
{
virtual ~my_base() = default;
virtual void my_method( int ) = 0;
};
virtual ~my_base() = default;
virtual void my_method(int) = 0;
};
MOCK_BASE_CLASS( my_class, my_base )
{
MOCK_METHOD( my_method, 2 )
};
}
MOCK_BASE_CLASS(my_class, my_base)
{
MOCK_METHOD(my_method, 2)
};
} // namespace

View file

@ -8,12 +8,12 @@
#include <turtle/mock.hpp>
MOCK_CLASS( my_class )
MOCK_CLASS(my_class)
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_METHOD_EXT(my_method, 1, void(int), my_method)
};
void test_case()
{
my_class c;
MOCK_EXPECT( c.my_method ).with( 42, 42 );
MOCK_EXPECT(c.my_method).with(42, 42);
}

View file

@ -12,10 +12,10 @@
#define MOCK_ERROR_POLICY mock_error
#include <turtle/detail/singleton.hpp>
#include <boost/test/unit_test.hpp>
#include <stdexcept>
#include <sstream>
#include <stdexcept>
struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
struct mock_error_data_t : mock::detail::singleton<mock_error_data_t>
{
void reset()
{
@ -24,10 +24,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
last_message.clear();
last_context.clear();
}
bool verify()
{
return error_count == 0;
}
bool verify() { return error_count == 0; }
void call()
{
@ -35,9 +32,7 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
last_message.clear();
++call_count;
}
void fail( const std::string& message,
const std::string& context,
const char* file, int line )
void fail(const std::string& message, const std::string& context, const char* file, int line)
{
last_context = context;
last_message = message;
@ -52,59 +47,56 @@ struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
std::string last_context;
std::string last_file;
int last_line;
MOCK_SINGLETON_CONS( mock_error_data_t );
MOCK_SINGLETON_CONS(mock_error_data_t);
};
MOCK_SINGLETON_INST( mock_error_data )
MOCK_SINGLETON_INST(mock_error_data)
template< typename Result >
template<typename Result>
struct mock_error
{
static Result abort()
{
throw std::runtime_error( "aborted" );
}
static Result abort() { throw std::runtime_error("aborted"); }
static void pass( const char* /*file*/, int /*line*/ )
{}
static void pass(const char* /*file*/, int /*line*/) {}
template< typename Context >
static void call( const Context& /*context*/, const char* /*file*/, int /*line*/ )
template<typename Context>
static void call(const Context& /*context*/, const char* /*file*/, int /*line*/)
{
mock_error_data.call();
}
template< typename Context >
static void fail( const std::string& message, const Context& context, const char* file = "", int line = 0 )
template<typename Context>
static void fail(const std::string& message, const Context& context, const char* file = "", int line = 0)
{
std::ostringstream s;
s << context; // Context can be streamed
mock_error_data.fail( message, s.str(), file, line );
mock_error_data.fail(message, s.str(), file, line);
}
};
struct mock_error_fixture
{
mock_error_fixture()
{
mock_error_data.reset();
}
mock_error_fixture() { mock_error_data.reset(); }
~mock_error_fixture()
{
BOOST_CHECK( mock_error_data.verify() );
BOOST_CHECK_EQUAL( 0, mock_error_data.call_count );
BOOST_CHECK(mock_error_data.verify());
BOOST_CHECK_EQUAL(0, mock_error_data.call_count);
}
};
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, mock_error_data.call_count ); \
#define CHECK_CALLS(calls) \
BOOST_CHECK_EQUAL(calls, mock_error_data.call_count); \
mock_error_data.call_count = 0;
#define CHECK_ERROR( expr, error, calls, context ) \
BOOST_CHECK( mock_error_data.verify() ); \
try { expr; } catch( ... ) {} \
BOOST_CHECK_EQUAL( 1, mock_error_data.error_count ); \
BOOST_CHECK_EQUAL( error, mock_error_data.last_message ); \
BOOST_CHECK_EQUAL( context, mock_error_data.last_context ); \
CHECK_CALLS( calls ); \
#define CHECK_ERROR(expr, error, calls, context) \
BOOST_CHECK(mock_error_data.verify()); \
try \
{ \
expr; \
} catch(...) \
{} \
BOOST_CHECK_EQUAL(1, mock_error_data.error_count); \
BOOST_CHECK_EQUAL(error, mock_error_data.last_message); \
BOOST_CHECK_EQUAL(context, mock_error_data.last_context); \
CHECK_CALLS(calls); \
mock_error_data.reset();
#endif // MOCK_TEST_MOCK_ERROR_HPP_INCLUDED

View file

@ -9,16 +9,15 @@
#include <turtle/constraint.hpp>
#include <boost/test/unit_test.hpp>
namespace
{
MOCK_CONSTRAINT( constraint_0, actual == 0 )
MOCK_CONSTRAINT( constraint_1, expected, actual == expected )
MOCK_CONSTRAINT( constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1 )
}
namespace {
MOCK_CONSTRAINT(constraint_0, actual == 0)
MOCK_CONSTRAINT(constraint_1, expected, actual == expected)
MOCK_CONSTRAINT(constraint_2, expected_0, expected_1, actual == expected_0 || actual == expected_1)
} // namespace
BOOST_AUTO_TEST_CASE( mock_constraint_is_supported_by_compilers_with_variadic_macros )
BOOST_AUTO_TEST_CASE(mock_constraint_is_supported_by_compilers_with_variadic_macros)
{
BOOST_CHECK( constraint_0.c_( 0 ) );
BOOST_CHECK( constraint_1( 0 ).c_( 0 ) );
BOOST_CHECK( constraint_2( 0, 0 ).c_( 0 ) );
BOOST_CHECK(constraint_0.c_(0));
BOOST_CHECK(constraint_1(0).c_(0));
BOOST_CHECK(constraint_2(0, 0).c_(0));
}

View file

@ -9,386 +9,372 @@
#include <turtle/constraints.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( all_comparison_constraints_can_be_instanciated )
BOOST_AUTO_TEST_CASE(all_comparison_constraints_can_be_instanciated)
{
mock::equal( 0 );
mock::less( 0 );
mock::greater( 0 );
mock::less_equal( 0 );
mock::greater_equal( 0 );
mock::equal(0);
mock::less(0);
mock::greater(0);
mock::less_equal(0);
mock::greater_equal(0);
}
BOOST_AUTO_TEST_CASE( constraints_can_be_negated_using_the_not_operator )
BOOST_AUTO_TEST_CASE(constraints_can_be_negated_using_the_not_operator)
{
! mock::any;
! mock::affirm;
! mock::negate;
! mock::evaluate;
! mock::equal( 0 );
! mock::less( 0 );
! mock::greater( 0 );
! mock::less_equal( 0 );
! mock::greater_equal( 0 );
!mock::any;
!mock::affirm;
!mock::negate;
!mock::evaluate;
!mock::equal(0);
!mock::less(0);
!mock::greater(0);
!mock::less_equal(0);
!mock::greater_equal(0);
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_or_operator )
BOOST_AUTO_TEST_CASE(constraints_can_be_combined_using_the_or_operator)
{
mock::less( 0 ) || mock::greater( 0 );
mock::less(0) || mock::greater(0);
}
BOOST_AUTO_TEST_CASE( constraints_can_be_combined_using_the_and_operator )
BOOST_AUTO_TEST_CASE(constraints_can_be_combined_using_the_and_operator)
{
mock::less( 0 ) && mock::greater( 0 );
mock::less(0) && mock::greater(0);
}
BOOST_AUTO_TEST_CASE( equal_constraint )
BOOST_AUTO_TEST_CASE(equal_constraint)
{
BOOST_CHECK( mock::equal( std::string( "string" ) ).c_( "string" ) );
BOOST_CHECK( ! mock::equal( std::string( "string" ) ).c_( "not string" ) );
BOOST_CHECK(mock::equal(std::string("string")).c_("string"));
BOOST_CHECK(!mock::equal(std::string("string")).c_("not string"));
{
std::string s;
auto c = mock::equal( std::cref( s ) );
auto c = mock::equal(std::cref(s));
s = "string";
BOOST_CHECK( c.c_( "string" ) );
BOOST_CHECK(c.c_("string"));
}
{
std::unique_ptr< int > i;
std::unique_ptr< int > j( new int( 3 ) );
BOOST_CHECK( ! mock::equal( i ).c_( j ) );
BOOST_CHECK( ! mock::equal( j ).c_( i ) );
BOOST_CHECK( mock::equal( i ).c_( i ) );
BOOST_CHECK( mock::equal( j ).c_( j ) );
std::unique_ptr<int> i;
std::unique_ptr<int> j(new int(3));
BOOST_CHECK(!mock::equal(i).c_(j));
BOOST_CHECK(!mock::equal(j).c_(i));
BOOST_CHECK(mock::equal(i).c_(i));
BOOST_CHECK(mock::equal(j).c_(j));
}
}
BOOST_AUTO_TEST_CASE( equal_constraint_deref )
BOOST_AUTO_TEST_CASE(equal_constraint_deref)
{
{
int i = 3;
BOOST_CHECK( mock::equal( 3 ).c_( &i ) );
BOOST_CHECK( ! mock::equal( 7 ).c_( &i ) );
BOOST_CHECK(mock::equal(3).c_(&i));
BOOST_CHECK(!mock::equal(7).c_(&i));
}
{
int* i = 0;
BOOST_CHECK( ! mock::equal( 3 ).c_( i ) );
BOOST_CHECK(!mock::equal(3).c_(i));
}
{
std::unique_ptr< int > j( new int( 3 ) );
BOOST_CHECK( mock::equal( 3 ).c_( j ) );
std::unique_ptr< int > i;
BOOST_CHECK( ! mock::equal( 3 ).c_( i ) );
std::unique_ptr<int> j(new int(3));
BOOST_CHECK(mock::equal(3).c_(j));
std::unique_ptr<int> i;
BOOST_CHECK(!mock::equal(3).c_(i));
}
}
BOOST_AUTO_TEST_CASE( same_constraint )
BOOST_AUTO_TEST_CASE(same_constraint)
{
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK( ! mock::same( i ).c_( j ) );
BOOST_CHECK( mock::same( i ).c_( i ) );
BOOST_CHECK_EQUAL(i, j);
BOOST_CHECK(!mock::same(i).c_(j));
BOOST_CHECK(mock::same(i).c_(i));
}
{
int i = 0;
int j = 0;
BOOST_CHECK_EQUAL( i, j );
auto c = mock::same( i );
BOOST_CHECK( ! c.c_( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL(i, j);
auto c = mock::same(i);
BOOST_CHECK(!c.c_(j));
BOOST_CHECK(c.c_(i));
}
{
std::nullptr_t p;
BOOST_CHECK( mock::same( p ).c_( p ) );
BOOST_CHECK(mock::same(p).c_(p));
}
}
BOOST_AUTO_TEST_CASE( assign_constraint )
BOOST_AUTO_TEST_CASE(assign_constraint)
{
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
BOOST_CHECK(mock::assign(3).c_(i));
BOOST_CHECK_EQUAL(3, i);
}
{
int i = 0;
BOOST_CHECK( mock::assign( 3 ).c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
BOOST_CHECK(mock::assign(3).c_(&i));
BOOST_CHECK_EQUAL(3, i);
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::assign( &j ).c_( i ) );
BOOST_CHECK_EQUAL( &j, i );
BOOST_CHECK(mock::assign(&j).c_(i));
BOOST_CHECK_EQUAL(&j, i);
}
{
int* i = 0;
const int j = 1;
BOOST_CHECK( ! mock::assign( j ).c_( i ) );
BOOST_CHECK( ! i );
BOOST_CHECK(!mock::assign(j).c_(i));
BOOST_CHECK(!i);
}
{
int i = 0;
int j = 1;
mock::constraint<
mock::detail::assign<
std::reference_wrapper< const int >
>
> c = mock::assign( std::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 1, i );
mock::constraint<mock::detail::assign<std::reference_wrapper<const int>>> c = mock::assign(std::cref(j));
BOOST_CHECK(c.c_(i));
BOOST_CHECK_EQUAL(1, i);
j = 3;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( 3, i );
BOOST_CHECK(c.c_(i));
BOOST_CHECK_EQUAL(3, i);
}
{
int i = 0;
int j = 1;
auto c = mock::assign( std::cref( j ) );
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 1, i );
auto c = mock::assign(std::cref(j));
BOOST_CHECK(c.c_(&i));
BOOST_CHECK_EQUAL(1, i);
j = 3;
BOOST_CHECK( c.c_( &i ) );
BOOST_CHECK_EQUAL( 3, i );
BOOST_CHECK(c.c_(&i));
BOOST_CHECK_EQUAL(3, i);
}
{
const int* i = 0;
int k = 1;
int* j = &k;
auto c = mock::assign( std::cref( j ) );
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
auto c = mock::assign(std::cref(j));
BOOST_CHECK(c.c_(i));
BOOST_CHECK_EQUAL(j, i);
j = 0;
BOOST_CHECK( c.c_( i ) );
BOOST_CHECK_EQUAL( j, i );
BOOST_CHECK(c.c_(i));
BOOST_CHECK_EQUAL(j, i);
}
}
BOOST_AUTO_TEST_CASE( retrieve_constraint )
BOOST_AUTO_TEST_CASE(retrieve_constraint)
{
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, j);
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( &j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(&j));
BOOST_CHECK_EQUAL(i, &j);
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
const int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
int* i = 0;
int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
int** i = 0;
int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
const int** i = 0;
const int* j = 0;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
int i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, j);
}
{
const int* i = 0;
const int j = 1;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
std::nullptr_t* i = 0;
std::nullptr_t j;
BOOST_CHECK( mock::retrieve( i ).c_( j ) );
BOOST_CHECK_EQUAL( i, &j );
BOOST_CHECK(mock::retrieve(i).c_(j));
BOOST_CHECK_EQUAL(i, &j);
}
{
std::unique_ptr< int > i;
std::unique_ptr< int > j( new int( 3 ) );
BOOST_CHECK( mock::retrieve( i ).c_( std::move( j ) ) );
BOOST_REQUIRE( i );
BOOST_CHECK_EQUAL( 3, *i );
BOOST_CHECK( !j );
std::unique_ptr<int> i;
std::unique_ptr<int> j(new int(3));
BOOST_CHECK(mock::retrieve(i).c_(std::move(j)));
BOOST_REQUIRE(i);
BOOST_CHECK_EQUAL(3, *i);
BOOST_CHECK(!j);
}
}
namespace
namespace {
struct A
{};
struct B
{
struct A
{
};
struct B
{
B& operator=( const A& )
{
return *this;
}
};
}
B& operator=(const A&) { return *this; }
};
} // namespace
BOOST_AUTO_TEST_CASE( retrieve_constraint_uses_assignment_operator )
BOOST_AUTO_TEST_CASE(retrieve_constraint_uses_assignment_operator)
{
B b;
const A a = A();
mock::retrieve( b ).c_( a );
mock::retrieve(b).c_(a);
}
BOOST_AUTO_TEST_CASE( affirm_constraint )
BOOST_AUTO_TEST_CASE(affirm_constraint)
{
{
int* i = 0;
int j;
BOOST_CHECK( ! mock::affirm.c_( i ) );
BOOST_CHECK( mock::affirm.c_( &j ) );
BOOST_CHECK(!mock::affirm.c_(i));
BOOST_CHECK(mock::affirm.c_(&j));
}
{
std::unique_ptr< int > i;
std::unique_ptr< int > j( new int( 3 ) );
BOOST_CHECK( ! mock::affirm.c_( i ) );
BOOST_CHECK( mock::affirm.c_( j ) );
std::unique_ptr<int> i;
std::unique_ptr<int> j(new int(3));
BOOST_CHECK(!mock::affirm.c_(i));
BOOST_CHECK(mock::affirm.c_(j));
}
}
BOOST_AUTO_TEST_CASE( negate_constraint )
BOOST_AUTO_TEST_CASE(negate_constraint)
{
int* i = 0;
int j;
BOOST_CHECK( mock::negate.c_( i ) );
BOOST_CHECK( ! mock::negate.c_( &j ) );
BOOST_CHECK(mock::negate.c_(i));
BOOST_CHECK(!mock::negate.c_(&j));
}
namespace
namespace {
bool return_true()
{
bool return_true()
{
return true;
}
bool return_false()
{
return false;
}
return true;
}
bool return_false()
{
return false;
}
} // namespace
BOOST_AUTO_TEST_CASE(call_constraint)
{
BOOST_CHECK(mock::call(&return_true).c_());
BOOST_CHECK(!mock::call(&return_false).c_());
}
BOOST_AUTO_TEST_CASE( call_constraint )
BOOST_AUTO_TEST_CASE(evaluate_constraint)
{
BOOST_CHECK( mock::call( &return_true ).c_() );
BOOST_CHECK( ! mock::call( &return_false ).c_() );
BOOST_CHECK(mock::evaluate.c_(&return_true));
BOOST_CHECK(!mock::evaluate.c_(&return_false));
}
BOOST_AUTO_TEST_CASE( evaluate_constraint )
BOOST_AUTO_TEST_CASE(contain_constraint_with_const_char_ptr)
{
BOOST_CHECK( mock::evaluate.c_( &return_true ) );
BOOST_CHECK( ! mock::evaluate.c_( &return_false ) );
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_const_char_ptr )
{
BOOST_CHECK( mock::contain( "string" ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( "string" ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( "not found" ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK(mock::contain("string").c_("this is a string"));
BOOST_CHECK(mock::contain("string").c_(std::string("this is a string")));
BOOST_CHECK(!mock::contain("not found").c_("this is a string"));
BOOST_CHECK(!mock::contain("not found").c_(std::string("this is a string")));
{
const char* s = 0;
auto c = mock::contain( std::cref( s ) );
auto c = mock::contain(std::cref(s));
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
BOOST_CHECK(c.c_("this is a string"));
BOOST_CHECK(c.c_(std::string("this is a string")));
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
BOOST_CHECK(!c.c_("this is a string"));
BOOST_CHECK(!c.c_(std::string("this is a string")));
}
}
BOOST_AUTO_TEST_CASE( contain_constraint_with_strings )
BOOST_AUTO_TEST_CASE(contain_constraint_with_strings)
{
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( "this is a string" ) );
BOOST_CHECK( mock::contain( std::string( "string" ) ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( "this is a string" ) );
BOOST_CHECK( ! mock::contain( std::string( "not found" ) ).c_( std::string( "this is a string" ) ) );
BOOST_CHECK(mock::contain(std::string("string")).c_("this is a string"));
BOOST_CHECK(mock::contain(std::string("string")).c_(std::string("this is a string")));
BOOST_CHECK(!mock::contain(std::string("not found")).c_("this is a string"));
BOOST_CHECK(!mock::contain(std::string("not found")).c_(std::string("this is a string")));
{
std::string s;
mock::constraint<
mock::detail::contain<
std::reference_wrapper< const std::string >
>
> c = mock::contain( std::cref( s ) );
mock::constraint<mock::detail::contain<std::reference_wrapper<const std::string>>> c =
mock::contain(std::cref(s));
s = "string";
BOOST_CHECK( c.c_( "this is a string" ) );
BOOST_CHECK( c.c_( std::string( "this is a string" ) ) );
BOOST_CHECK(c.c_("this is a string"));
BOOST_CHECK(c.c_(std::string("this is a string")));
s = "not found";
BOOST_CHECK( ! c.c_( "this is a string" ) );
BOOST_CHECK( ! c.c_( std::string( "this is a string" ) ) );
BOOST_CHECK(!c.c_("this is a string"));
BOOST_CHECK(!c.c_(std::string("this is a string")));
}
}
namespace
namespace {
struct type_with_overloaded_address_operator
{
struct type_with_overloaded_address_operator
{
void operator&() {}
void operator&() const {}
};
}
void operator&() {}
void operator&() const {}
};
} // namespace
BOOST_AUTO_TEST_CASE( type_with_overloaded_address_operator_can_be_used_in_constraints )
BOOST_AUTO_TEST_CASE(type_with_overloaded_address_operator_can_be_used_in_constraints)
{
type_with_overloaded_address_operator t;
mock::same( t ).c_( t );
mock::retrieve( t ).c_( t );
mock::same(t).c_(t);
mock::retrieve(t).c_(t);
type_with_overloaded_address_operator* pt;
mock::retrieve( pt ).c_( t );
mock::retrieve(pt).c_(t);
}
BOOST_AUTO_TEST_CASE( close_constraint )
BOOST_AUTO_TEST_CASE(close_constraint)
{
BOOST_CHECK( mock::close( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close( 12.0, 0.0001 ).c_( 13 ) );
BOOST_CHECK(mock::close(12.0, 0.0001).c_(12));
BOOST_CHECK(!mock::close(12.0, 0.0001).c_(13));
}
BOOST_AUTO_TEST_CASE( close_fraction_constraint )
BOOST_AUTO_TEST_CASE(close_fraction_constraint)
{
BOOST_CHECK( mock::close_fraction( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::close_fraction( 12.0, 0.0001 ).c_( 13 ) );
BOOST_CHECK(mock::close_fraction(12.0, 0.0001).c_(12));
BOOST_CHECK(!mock::close_fraction(12.0, 0.0001).c_(13));
}
BOOST_AUTO_TEST_CASE( small_constraint )
BOOST_AUTO_TEST_CASE(small_constraint)
{
BOOST_CHECK( mock::small( 0.0001 ).c_( 0. ) );
BOOST_CHECK( ! mock::small( 0.0001 ).c_( 12. ) );
BOOST_CHECK(mock::small(0.0001).c_(0.));
BOOST_CHECK(!mock::small(0.0001).c_(12.));
}
BOOST_AUTO_TEST_CASE( near_constraint )
BOOST_AUTO_TEST_CASE(near_constraint)
{
BOOST_CHECK( mock::near( 12.0, 0.0001 ).c_( 12 ) );
BOOST_CHECK( ! mock::near( 12.0, 0.0001 ).c_( 13 ) );
BOOST_CHECK(mock::near(12.0, 0.0001).c_(12));
BOOST_CHECK(!mock::near(12.0, 0.0001).c_(13));
}

View file

@ -10,16 +10,14 @@
#include <turtle/exception.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions )
BOOST_AUTO_TEST_CASE(a_mock_exception_is_not_an_std_exception_to_not_mess_with_user_exceptions)
{
try
{
throw mock::exception();
}
catch( std::exception& )
} catch(std::exception&)
{
BOOST_FAIL( "mock::exception must not be an std::exception" );
}
catch( mock::exception& )
BOOST_FAIL("mock::exception must not be an std::exception");
} catch(mock::exception&)
{}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -9,70 +9,66 @@
#include <turtle/detail/function.hpp>
#include <boost/test/unit_test.hpp>
namespace
namespace {
template<typename Expected, typename Actual>
bool match(Expected expected, Actual actual)
{
template< typename Expected, typename Actual >
bool match( Expected expected, Actual actual )
{
return mock::matcher< Actual, Expected >( expected )( actual );
}
return mock::matcher<Actual, Expected>(expected)(actual);
}
} // namespace
BOOST_AUTO_TEST_CASE(int_and_int_can_be_compared)
{
BOOST_CHECK(match(3, 3));
BOOST_CHECK(!match(3, 4));
BOOST_CHECK(!match(4, 3));
}
BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared )
{
BOOST_CHECK( match( 3, 3 ) );
BOOST_CHECK( ! match( 3, 4 ) );
BOOST_CHECK( ! match( 4, 3 ) );
}
BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared )
BOOST_AUTO_TEST_CASE(ref_to_int_and_int_can_be_compared)
{
const int i = 3;
BOOST_CHECK( match( 3, std::cref( i ) ) );
BOOST_CHECK( ! match( 4, std::cref( i ) ) );
BOOST_CHECK(match(3, std::cref(i)));
BOOST_CHECK(!match(4, std::cref(i)));
}
namespace
namespace {
struct fixture
{
struct fixture
fixture() : text("same text"), actual(text.c_str())
{
fixture()
: text( "same text" )
, actual( text.c_str() )
{
const char* static_string = "same text";
BOOST_REQUIRE( actual != static_string );
BOOST_REQUIRE( actual == std::string( static_string ) );
}
std::string text;
const char* actual;
};
}
const char* static_string = "same text";
BOOST_REQUIRE(actual != static_string);
BOOST_REQUIRE(actual == std::string(static_string));
}
std::string text;
const char* actual;
};
} // namespace
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_pointer_can_be_compared, fixture )
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_pointer_can_be_compared, fixture)
{
const char* expected = "same text";
BOOST_CHECK( match( expected, actual ) );
BOOST_CHECK(match(expected, actual));
const char* unexpected = "different text";
BOOST_CHECK( ! match( actual, unexpected ) );
BOOST_CHECK(!match(actual, unexpected));
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_string_literal_can_be_compared, fixture )
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_string_literal_can_be_compared, fixture)
{
BOOST_CHECK( match( "same text", actual ) );
BOOST_CHECK( ! match( "different text", actual ) );
BOOST_CHECK(match("same text", actual));
BOOST_CHECK(!match("different text", actual));
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_array_can_be_compared, fixture )
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_const_char_array_can_be_compared, fixture)
{
const char expected[10] = "same text";
BOOST_CHECK( match( expected, actual ) );
BOOST_CHECK(match(expected, actual));
const char unexpected[15] = "different text";
BOOST_CHECK( ! match( unexpected, actual ) );
BOOST_CHECK(!match(unexpected, actual));
}
BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_std_string_can_be_compared, fixture )
BOOST_FIXTURE_TEST_CASE(const_char_pointer_and_std_string_can_be_compared, fixture)
{
BOOST_CHECK( match( std::string( "same text" ), actual ) );
BOOST_CHECK( ! match( std::string( "different text" ), actual ) );
BOOST_CHECK(match(std::string("same text"), actual));
BOOST_CHECK(!match(std::string("different text"), actual));
}

View file

@ -8,32 +8,31 @@
#include "mock_error.hpp"
#include <turtle/mock.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/test/unit_test.hpp>
#define IDENTITY(z, n, d) d
namespace
namespace {
struct my_custom_mock
{
struct my_custom_mock
{
MOCK_METHOD_EXT( method, MOCK_MAX_ARGS, void( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag )
MOCK_METHOD_EXT( method2, MOCK_MAX_ARGS, int( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int) ), tag_2 )
};
}
MOCK_METHOD_EXT(method, MOCK_MAX_ARGS, void(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag)
MOCK_METHOD_EXT(method2, MOCK_MAX_ARGS, int(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, int)), tag_2)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args, mock_error_fixture)
{
my_custom_mock m;
MOCK_EXPECT( m.tag ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) );
CHECK_CALLS( 1 );
MOCK_EXPECT(m.tag).once().with(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0));
m.method(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0));
CHECK_CALLS(1);
}
BOOST_FIXTURE_TEST_CASE( call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(call_mock_method_with_max_number_of_args_and_a_return_value, mock_error_fixture)
{
my_custom_mock m;
MOCK_EXPECT( m.tag_2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ).returns( 42 );
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0) ) );
CHECK_CALLS( 1 );
MOCK_EXPECT(m.tag_2).once().with(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0)).returns(42);
BOOST_CHECK_EQUAL(42, m.method2(BOOST_PP_ENUM(MOCK_MAX_ARGS, IDENTITY, 0)));
CHECK_CALLS(1);
}

View file

@ -11,404 +11,385 @@
#include <boost/test/unit_test.hpp>
#include <functional>
namespace
namespace {
template<typename T>
void my_function(T& t)
{
template< typename T >
void my_function( T& t )
{
t.my_method( "some parameter" );
}
MOCK_CLASS( mock_class )
{
MOCK_METHOD_EXT( my_method, 1, void( const std::string& ), my_tag )
};
t.my_method("some parameter");
}
MOCK_CLASS(mock_class)
{
MOCK_METHOD_EXT(my_method, 1, void(const std::string&), my_tag)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_object_for_static_polymorphism, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_object_for_static_polymorphism, mock_error_fixture)
{
const mock_class m;
MOCK_EXPECT( m.my_tag ).once().with( "some parameter" );
my_function( m );
CHECK_CALLS( 1 );
MOCK_EXPECT(m.my_tag).once().with("some parameter");
my_function(m);
CHECK_CALLS(1);
}
namespace
namespace {
MOCK_CLASS(mock_class_with_operator)
{
MOCK_CLASS( mock_class_with_operator )
{
MOCK_CONST_METHOD_EXT( operator+=, 1, mock_class_with_operator&( int ), addition )
};
}
MOCK_CONST_METHOD_EXT(operator+=, 1, mock_class_with_operator &(int), addition)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_addition_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_addition_operator, mock_error_fixture)
{
mock_class_with_operator m;
MOCK_EXPECT( m.addition ).once().returns( std::ref( m ) );
MOCK_EXPECT(m.addition).once().returns(std::ref(m));
m += 1;
CHECK_CALLS( 1 );
CHECK_CALLS(1);
}
namespace
namespace {
MOCK_CLASS(mock_class_with_conversion_operator)
{
MOCK_CLASS( mock_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR( operator, int, conversion )
};
}
MOCK_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_conversion_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_conversion_operator, mock_error_fixture)
{
mock_class_with_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
MOCK_EXPECT(m.conversion).once().returns(42);
BOOST_CHECK_EQUAL(42, static_cast<int>(m));
CHECK_CALLS(1);
}
namespace
namespace {
template<typename T>
MOCK_CLASS(mock_template_class_with_conversion_operator)
{ MOCK_CONVERSION_OPERATOR_TPL(operator, T, conversion) };
} // namespace
BOOST_FIXTURE_TEST_CASE(mock_template_conversion_operator, mock_error_fixture)
{
template< typename T >
MOCK_CLASS( mock_template_class_with_conversion_operator )
{
MOCK_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
mock_template_class_with_conversion_operator<int> m;
MOCK_EXPECT(m.conversion).once().returns(42);
BOOST_CHECK_EQUAL(42, static_cast<int>(m));
CHECK_CALLS(1);
}
BOOST_FIXTURE_TEST_CASE( mock_template_conversion_operator, mock_error_fixture )
namespace {
MOCK_CLASS(mock_class_with_const_conversion_operator)
{
mock_template_class_with_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
}
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
namespace
{
MOCK_CLASS( mock_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
BOOST_FIXTURE_TEST_CASE( mock_const_conversion_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_const_conversion_operator, mock_error_fixture)
{
mock_class_with_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
MOCK_EXPECT(m.conversion).once().returns(42);
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
BOOST_CHECK_EQUAL(42, i);
CHECK_CALLS(1);
}
namespace
namespace {
MOCK_CLASS(mock_class_with_non_const_conversion_operator)
{
MOCK_CLASS( mock_class_with_non_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR( operator, int, conversion )
};
}
MOCK_CONST_CONVERSION_OPERATOR(operator, int, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_non_const_conversion_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_non_const_conversion_operator, mock_error_fixture)
{
mock_class_with_non_const_conversion_operator m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
MOCK_EXPECT(m.conversion).once().returns(42);
int i = m;
BOOST_CHECK_EQUAL( 42, i );
CHECK_CALLS( 1 );
BOOST_CHECK_EQUAL(42, i);
CHECK_CALLS(1);
}
namespace
namespace {
template<typename T>
MOCK_CLASS(mock_template_class_with_const_conversion_operator)
{
template< typename T >
MOCK_CLASS( mock_template_class_with_const_conversion_operator )
{
MOCK_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
MOCK_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_template_const_conversion_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_template_const_conversion_operator, mock_error_fixture)
{
mock_template_class_with_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
mock_template_class_with_const_conversion_operator<int> m;
MOCK_EXPECT(m.conversion).once().returns(42);
BOOST_CHECK_EQUAL(42, static_cast<int>(m));
CHECK_CALLS(1);
}
namespace
namespace {
template<typename T>
MOCK_CLASS(mock_template_class_with_non_const_conversion_operator)
{
template< typename T >
MOCK_CLASS( mock_template_class_with_non_const_conversion_operator )
{
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL( operator, T, conversion )
};
}
MOCK_NON_CONST_CONVERSION_OPERATOR_TPL(operator, T, conversion)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_template_non_const_conversion_operator, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_template_non_const_conversion_operator, mock_error_fixture)
{
mock_template_class_with_non_const_conversion_operator< int > m;
MOCK_EXPECT( m.conversion ).once().returns( 42 );
BOOST_CHECK_EQUAL( 42, static_cast< int >( m ) );
CHECK_CALLS( 1 );
mock_template_class_with_non_const_conversion_operator<int> m;
MOCK_EXPECT(m.conversion).once().returns(42);
BOOST_CHECK_EQUAL(42, static_cast<int>(m));
CHECK_CALLS(1);
}
namespace
namespace {
MOCK_CLASS(my_mock)
{
MOCK_CLASS( my_mock )
{
MOCK_CONST_METHOD_EXT( my_method, 1, void( int ), my_method )
MOCK_CONST_METHOD_EXT( my_method_2, 1, void( int ), my_method_2 )
};
}
MOCK_CONST_METHOD_EXT(my_method, 1, void(int), my_method)
MOCK_CONST_METHOD_EXT(my_method_2, 1, void(int), my_method_2)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(MOCK_CONST_METHOD_EXT_macro_defines_a_bindable_method, mock_error_fixture)
{
my_mock m;
const auto f = std::bind( &my_mock::my_method, &m, 42 );
(void) f;
const auto f = std::bind(&my_mock::my_method, &m, 42);
(void)f;
}
BOOST_FIXTURE_TEST_CASE( MOCK_VERIFY_macro, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(MOCK_VERIFY_macro, mock_error_fixture)
{
my_mock m;
MOCK_VERIFY( m.my_method );
MOCK_VERIFY(m.my_method);
}
BOOST_FIXTURE_TEST_CASE( MOCK_RESET_macro, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(MOCK_RESET_macro, mock_error_fixture)
{
my_mock m;
MOCK_RESET( m.my_method );
MOCK_RESET(m.my_method);
}
BOOST_FIXTURE_TEST_CASE( MOCK_EXPECT_macro, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(MOCK_EXPECT_macro, mock_error_fixture)
{
my_mock m;
MOCK_EXPECT( m.my_method ).once().with( 42 );
m.my_method( 42 );
CHECK_CALLS( 1 );
MOCK_EXPECT(m.my_method).once().with(42);
m.my_method(42);
CHECK_CALLS(1);
}
namespace
namespace {
template<typename T>
std::string to_string(const T& t)
{
template< typename T >
std::string to_string( const T& t )
{
std::stringstream s;
s << t;
return s.str();
}
std::stringstream s;
s << t;
return s.str();
}
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_object_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_object_is_named, mock_error_fixture)
{
my_mock m;
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "?.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_method_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL( "m.my_mock::my_method", to_string( MOCK_HELPER( m.my_method ) ) );
BOOST_CHECK_EQUAL("?.my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m.my_method)));
BOOST_CHECK_EQUAL("?.my_mock::my_method_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_method_2)));
BOOST_CHECK_EQUAL("m.my_mock::my_method", to_string(MOCK_HELPER(m.my_method)));
BOOST_CHECK_EQUAL("m.my_mock::my_method_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_method_2)));
BOOST_CHECK_EQUAL("m.my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m.my_method)));
BOOST_CHECK_EQUAL("m.my_mock::my_method", to_string(MOCK_HELPER(m.my_method)));
}
BOOST_FIXTURE_TEST_CASE( mock_object_shared_pointer_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_object_shared_pointer_is_named, mock_error_fixture)
{
std::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
std::shared_ptr<my_mock> m(new my_mock);
BOOST_CHECK_EQUAL("?.my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
}
BOOST_FIXTURE_TEST_CASE( mock_object_const_shared_pointer_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_object_const_shared_pointer_is_named, mock_error_fixture)
{
const std::shared_ptr< my_mock > m( new my_mock );
BOOST_CHECK_EQUAL( "?.my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_ANONYMOUS_HELPER( m->my_method ) ) );
BOOST_CHECK_EQUAL( "m->my_mock::my_method", to_string( MOCK_HELPER( m->my_method ) ) );
const std::shared_ptr<my_mock> m(new my_mock);
BOOST_CHECK_EQUAL("?.my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_ANONYMOUS_HELPER(m->my_method)));
BOOST_CHECK_EQUAL("m->my_mock::my_method", to_string(MOCK_HELPER(m->my_method)));
}
namespace
namespace {
struct my_custom_mock
{
struct my_custom_mock
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_and_without_inheriting_from_object_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_and_without_inheriting_from_object_is_named,
mock_error_fixture)
{
my_custom_mock m;
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL("?.my_custom_mock::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("?.my_custom_mock::my_tag_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag_2)));
BOOST_CHECK_EQUAL("m.my_custom_mock::my_tag", to_string(MOCK_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("m.my_custom_mock::my_tag_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag_2)));
BOOST_CHECK_EQUAL("m.my_custom_mock::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("m.my_custom_mock::my_tag", to_string(MOCK_HELPER(m.my_tag)));
}
namespace
namespace {
struct my_custom_mock_object : mock::object
{
struct my_custom_mock_object : mock::object
{
MOCK_METHOD_EXT( my_method, 0, void(), my_tag )
MOCK_METHOD_EXT( my_method_2, 0, void(), my_tag_2 )
};
}
MOCK_METHOD_EXT(my_method, 0, void(), my_tag)
MOCK_METHOD_EXT(my_method_2, 0, void(), my_tag_2)
};
} // namespace
BOOST_FIXTURE_TEST_CASE( custom_mock_object_without_macros_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(custom_mock_object_without_macros_is_named, mock_error_fixture)
{
my_custom_mock_object m;
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "?.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag_2", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag_2 ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_ANONYMOUS_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL( "m.my_custom_mock_object::my_tag", to_string( MOCK_HELPER( m.my_tag ) ) );
BOOST_CHECK_EQUAL("?.my_custom_mock_object::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("?.my_custom_mock_object::my_tag_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag_2)));
BOOST_CHECK_EQUAL("m.my_custom_mock_object::my_tag", to_string(MOCK_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("m.my_custom_mock_object::my_tag_2", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag_2)));
BOOST_CHECK_EQUAL("m.my_custom_mock_object::my_tag", to_string(MOCK_ANONYMOUS_HELPER(m.my_tag)));
BOOST_CHECK_EQUAL("m.my_custom_mock_object::my_tag", to_string(MOCK_HELPER(m.my_tag)));
}
BOOST_FIXTURE_TEST_CASE( mock_functor, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_functor, mock_error_fixture)
{
MOCK_FUNCTOR( f1, void() );
MOCK_FUNCTOR( f2, int( const std::string& ) );
MOCK_FUNCTOR(f1, void());
MOCK_FUNCTOR(f2, int(const std::string&));
}
namespace
namespace {
template<typename T>
struct tpl_functor_class
{
template< typename T >
struct tpl_functor_class
{
MOCK_FUNCTOR( f, void( T ) );
};
}
MOCK_FUNCTOR(f, void(T));
};
} // namespace
BOOST_FIXTURE_TEST_CASE( mock_functor_reset, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_functor_reset, mock_error_fixture)
{
MOCK_FUNCTOR( f, void() );
MOCK_RESET( f );
mock::reset( f );
MOCK_FUNCTOR(f, void());
MOCK_RESET(f);
mock::reset(f);
}
BOOST_FIXTURE_TEST_CASE( mock_functor_verify, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_functor_verify, mock_error_fixture)
{
MOCK_FUNCTOR( f, void() );
MOCK_VERIFY( f );
mock::verify( f );
MOCK_FUNCTOR(f, void());
MOCK_VERIFY(f);
mock::verify(f);
}
BOOST_FIXTURE_TEST_CASE( mock_functor_is_named, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(mock_functor_is_named, mock_error_fixture)
{
MOCK_FUNCTOR( f, void() );
BOOST_CHECK_EQUAL( "f", to_string( MOCK_HELPER( f ) ) );
MOCK_FUNCTOR(f, void());
BOOST_CHECK_EQUAL("f", to_string(MOCK_HELPER(f)));
}
namespace
namespace {
MOCK_FUNCTION(mock_function, 1, float(int), mock_function)
}
BOOST_FIXTURE_TEST_CASE(mock_function_is_named, mock_error_fixture)
{
MOCK_FUNCTION( mock_function, 1, float( int ), mock_function )
BOOST_CHECK_EQUAL("mock_function", to_string(MOCK_HELPER(mock_function)));
}
BOOST_FIXTURE_TEST_CASE( mock_function_is_named, mock_error_fixture )
namespace {
MOCK_CLASS(static_function_class)
{
BOOST_CHECK_EQUAL( "mock_function", to_string( MOCK_HELPER( mock_function ) ) );
}
MOCK_STATIC_METHOD(f, 1, float(int), f)
};
} // namespace
namespace
BOOST_FIXTURE_TEST_CASE(mock_static_function_is_named, mock_error_fixture)
{
MOCK_CLASS( static_function_class )
{
MOCK_STATIC_METHOD( f, 1, float( int ), f )
};
BOOST_CHECK_EQUAL("static_function_class::f", to_string(MOCK_HELPER(static_function_class::f)));
}
BOOST_FIXTURE_TEST_CASE( mock_static_function_is_named, mock_error_fixture )
namespace {
MOCK_CLASS(round_parenthesized_signature)
{
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
}
MOCK_METHOD_EXT(m0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), m0)
MOCK_STATIC_METHOD(m1, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), m1)
MOCK_FUNCTOR(f0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()));
};
MOCK_FUNCTION(fun0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()), fun0)
} // namespace
namespace
namespace {
struct base
{
MOCK_CLASS( round_parenthesized_signature )
{
MOCK_METHOD_EXT( m0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map< int, int >()), m0 )
MOCK_STATIC_METHOD( m1, 0, MOCK_PROTECT_FUNCTION_SIG(std::map< int, int >()), m1 )
MOCK_FUNCTOR( f0, MOCK_PROTECT_FUNCTION_SIG(std::map< int, int >()) );
};
MOCK_FUNCTION( fun0, 0, MOCK_PROTECT_FUNCTION_SIG(std::map< int, int >()), fun0 )
}
virtual ~base() = default;
namespace
virtual void m1() = 0;
virtual void m10() const = 0;
virtual void m11() = 0;
};
MOCK_BASE_CLASS(variadic, base)
{
struct base
{
virtual ~base() = default;
MOCK_METHOD(m1, 0)
MOCK_METHOD(m2, 0, void())
MOCK_METHOD(m3, 0, void(), m3)
MOCK_CONST_METHOD(m10, 0)
MOCK_CONST_METHOD(m4, 0, void())
MOCK_CONST_METHOD(m5, 0, void(), m5)
MOCK_NON_CONST_METHOD(m11, 0)
MOCK_NON_CONST_METHOD(m6, 0, void())
MOCK_NON_CONST_METHOD(m7, 0, void(), m7)
MOCK_STATIC_METHOD(m8, 0, void())
MOCK_STATIC_METHOD(m9, 0, void(), m9)
};
virtual void m1() = 0;
virtual void m10() const = 0;
virtual void m11() = 0;
};
template<typename T>
MOCK_BASE_CLASS(variadic_tpl, base)
{
MOCK_METHOD(m1, 0, void())
MOCK_METHOD_TPL(m2, 0, T())
MOCK_METHOD_TPL(m3, 0, T(), m3)
MOCK_CONST_METHOD_TPL(m4, 0, T())
MOCK_CONST_METHOD_TPL(m5, 0, T(), m5)
MOCK_NON_CONST_METHOD_TPL(m6, 0, T())
MOCK_NON_CONST_METHOD_TPL(m7, 0, T(), m7)
MOCK_STATIC_METHOD_TPL(m8, 0, T())
MOCK_STATIC_METHOD_TPL(m9, 0, T(), m9)
};
MOCK_BASE_CLASS( variadic, base )
{
MOCK_METHOD( m1, 0 )
MOCK_METHOD( m2, 0, void() )
MOCK_METHOD( m3, 0, void(), m3 )
MOCK_CONST_METHOD( m10, 0 )
MOCK_CONST_METHOD( m4, 0, void() )
MOCK_CONST_METHOD( m5, 0, void(), m5 )
MOCK_NON_CONST_METHOD( m11, 0 )
MOCK_NON_CONST_METHOD( m6, 0, void() )
MOCK_NON_CONST_METHOD( m7, 0, void(), m7 )
MOCK_STATIC_METHOD( m8, 0, void() )
MOCK_STATIC_METHOD( m9, 0, void(), m9 )
};
MOCK_BASE_CLASS(comma_base, std::map<int, int>)
{};
template< typename T >
MOCK_BASE_CLASS( variadic_tpl, base )
{
MOCK_METHOD( m1, 0, void() )
MOCK_METHOD_TPL( m2, 0, T() )
MOCK_METHOD_TPL( m3, 0, T(), m3 )
MOCK_CONST_METHOD_TPL( m4, 0, T() )
MOCK_CONST_METHOD_TPL( m5, 0, T(), m5 )
MOCK_NON_CONST_METHOD_TPL( m6, 0, T() )
MOCK_NON_CONST_METHOD_TPL( m7, 0, T(), m7 )
MOCK_STATIC_METHOD_TPL( m8, 0, T() )
MOCK_STATIC_METHOD_TPL( m9, 0, T(), m9 )
};
MOCK_FUNCTION(fun1, 0, void())
MOCK_FUNCTION(fun2, 0, void(), fun2)
MOCK_FUNCTION(fun3, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()))
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
{};
MOCK_FUNCTION( fun1, 0, void() )
MOCK_FUNCTION( fun2, 0, void(), fun2 )
MOCK_FUNCTION( fun3, 0, MOCK_PROTECT_FUNCTION_SIG(std::map< int, int >()) )
MOCK_FUNCTOR( f_variadic, std::map< int, int >() );
}
MOCK_FUNCTOR(f_variadic, std::map<int, int>());
} // namespace
#ifdef BOOST_MSVC
# define MOCK_STDCALL __stdcall
# define MOCK_STDCALL __stdcall
#else
# define MOCK_STDCALL
# define MOCK_STDCALL
#endif
namespace stdcall
namespace stdcall {
struct base
{
struct base
{
virtual ~base() = default;
virtual ~base() = default;
virtual void MOCK_STDCALL m1() = 0;
};
virtual void MOCK_STDCALL m1() = 0;
};
MOCK_BASE_CLASS( derived, base )
{
MOCK_CONSTRUCTOR( MOCK_STDCALL derived, 0, (), derived )
MOCK_DESTRUCTOR( MOCK_STDCALL ~derived, derived )
MOCK_CONVERSION_OPERATOR( MOCK_STDCALL operator, int, to_int )
MOCK_METHOD_EXT( MOCK_STDCALL m1, 0, void(), m1 )
MOCK_METHOD_EXT( MOCK_STDCALL m2, 0, void(), m2 )
MOCK_METHOD( MOCK_STDCALL m3, 0, void(), m3 )
MOCK_STATIC_METHOD( MOCK_STDCALL m4, 0, void(), m4 )
};
MOCK_BASE_CLASS(derived, base)
{
MOCK_CONSTRUCTOR(MOCK_STDCALL derived, 0, (), derived)
MOCK_DESTRUCTOR(MOCK_STDCALL ~derived, derived)
MOCK_CONVERSION_OPERATOR(MOCK_STDCALL operator, int, to_int)
MOCK_METHOD_EXT(MOCK_STDCALL m1, 0, void(), m1)
MOCK_METHOD_EXT(MOCK_STDCALL m2, 0, void(), m2)
MOCK_METHOD(MOCK_STDCALL m3, 0, void(), m3)
MOCK_STATIC_METHOD(MOCK_STDCALL m4, 0, void(), m4)
};
MOCK_FUNCTION( MOCK_STDCALL f, 0, void(), f )
}
MOCK_FUNCTION(MOCK_STDCALL f, 0, void(), f)
} // namespace stdcall

View file

@ -7,102 +7,81 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include "mock_error.hpp"
#include <turtle/detail/function.hpp>
#include <turtle/reset.hpp>
#include <turtle/verify.hpp>
#include <turtle/detail/function.hpp>
#include <boost/test/unit_test.hpp>
#include <memory>
namespace
{
struct object : mock::object
{};
namespace {
struct object : mock::object
{};
object static_o;
}
object static_o;
} // namespace
BOOST_FIXTURE_TEST_CASE( verifying_an_empty_object_succeeds, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(verifying_an_empty_object_succeeds, mock_error_fixture)
{
object o;
BOOST_CHECK( mock::verify( o ) );
BOOST_CHECK(mock::verify(o));
}
namespace
namespace {
struct fixture : mock_error_fixture
{
struct fixture : mock_error_fixture
{
fixture()
{
mock::detail::configure( o, e, "instance", mock::detail::make_type_name(o), "name" );
}
object o;
mock::detail::function< void() > e;
};
}
fixture() { mock::detail::configure(o, e, "instance", mock::detail::make_type_name(o), "name"); }
object o;
mock::detail::function<void()> e;
};
} // namespace
BOOST_FIXTURE_TEST_CASE( verifying_an_object_containing_a_failing_expectation_fails, fixture )
BOOST_FIXTURE_TEST_CASE(verifying_an_object_containing_a_failing_expectation_fails, fixture)
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
CHECK_ERROR(BOOST_CHECK(!mock::verify(o)), "verification failed", 0, "instanceobject::name\n. once()");
mock::reset(o);
BOOST_CHECK(mock::verify(o));
}
BOOST_FIXTURE_TEST_CASE( verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture )
BOOST_FIXTURE_TEST_CASE(verifying_all_objects_with_one_of_them_containing_a_failing_expectation_fails, fixture)
{
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify() ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(BOOST_CHECK(!mock::verify()), "verification failed", 0, "instanceobject::name\n. once()");
mock::reset();
BOOST_CHECK( mock::verify() );
BOOST_CHECK(mock::verify());
}
BOOST_FIXTURE_TEST_CASE( resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds, fixture )
BOOST_FIXTURE_TEST_CASE(resetting_an_object_containing_a_failing_expectation_and_verifying_it_succeeds, fixture)
{
e.expect().once();
mock::reset( o );
BOOST_CHECK( mock::verify( o ) );
mock::reset(o);
BOOST_CHECK(mock::verify(o));
}
BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(an_object_is_assignable_by_sharing_its_state, mock_error_fixture)
{
object o1;
mock::detail::function< void() > e;
mock::detail::function<void()> e;
{
object o2;
mock::detail::configure( o2, e, "instance", mock::detail::make_type_name(o2), "name" );
mock::detail::configure(o2, e, "instance", mock::detail::make_type_name(o2), "name");
e.expect().once();
o1 = o2;
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
CHECK_ERROR(BOOST_CHECK(!mock::verify(o2)), "verification failed", 0, "instanceobject::name\n. once()");
}
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
}
BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(an_object_is_copiable_by_sharing_its_state, mock_error_fixture)
{
auto o2 = std::make_unique<object>();
const object o1( *o2 );
mock::detail::function< void() > e;
mock::detail::configure( *o2, e, "instance", mock::detail::make_type_name(*o2), "name" );
const object o1(*o2);
mock::detail::function<void()> e;
mock::detail::configure(*o2, e, "instance", mock::detail::make_type_name(*o2), "name");
e.expect().once();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( *o2 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(BOOST_CHECK(!mock::verify(*o2)), "verification failed", 0, "instanceobject::name\n. once()");
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
o2.reset();
CHECK_ERROR(
BOOST_CHECK( ! mock::verify( o1 ) ),
"verification failed", 0, "instanceobject::name\n. once()" );
CHECK_ERROR(BOOST_CHECK(!mock::verify(o1)), "verification failed", 0, "instanceobject::name\n. once()");
}

View file

@ -7,108 +7,110 @@
// http://www.boost.org/LICENSE_1_0.txt)
#include "mock_error.hpp"
#include <turtle/sequence.hpp>
#include <turtle/detail/function.hpp>
#include <turtle/sequence.hpp>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_throws, mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )" );
mock::detail::function<void(int)> e;
e.expect().once().with(1).in(s);
e.expect().once().with(2).in(s);
BOOST_CHECK_NO_THROW(e(2));
CHECK_ERROR(e(1), "sequence failed", 1, "?( 1 )\n. once().with( 1 )\nv once().with( 2 )");
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_out_of_order_multiple_invocations_throws,
mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
CHECK_ERROR( e( 1 ), "sequence failed", 2, "?( 1 )\n. unlimited().with( 1 )\nv once().with( 2 )" );
mock::detail::function<void(int)> e;
e.expect().with(1).in(s);
e.expect().once().with(2).in(s);
BOOST_CHECK_NO_THROW(e(1));
BOOST_CHECK_NO_THROW(e(2));
CHECK_ERROR(e(1), "sequence failed", 2, "?( 1 )\n. unlimited().with( 1 )\nv once().with( 2 )");
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_calling_in_order_is_valid, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_calling_in_order_is_valid, mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().once().with( 1 ).in( s );
e.expect().once().with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 2 );
mock::detail::function<void(int)> e;
e.expect().once().with(1).in(s);
e.expect().once().with(2).in(s);
BOOST_CHECK_NO_THROW(e(1));
BOOST_CHECK_NO_THROW(e(2));
BOOST_CHECK(e.verify());
CHECK_CALLS(2);
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_and_multiply_calling_in_order_is_valid, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_and_multiply_calling_in_order_is_valid, mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void( int ) > e;
e.expect().exactly( 2 ).with( 1 ).in( s );
e.expect().exactly( 2 ).with( 2 ).in( s );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 1 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK_NO_THROW( e( 2 ) );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 4 );
mock::detail::function<void(int)> e;
e.expect().exactly(2).with(1).in(s);
e.expect().exactly(2).with(2).in(s);
BOOST_CHECK_NO_THROW(e(1));
BOOST_CHECK_NO_THROW(e(1));
BOOST_CHECK_NO_THROW(e(2));
BOOST_CHECK_NO_THROW(e(2));
BOOST_CHECK(e.verify());
CHECK_CALLS(4);
}
BOOST_FIXTURE_TEST_CASE( registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(registering_to_a_sequence_enforces_call_order_verification_between_two_different_expectations,
mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
mock::detail::function<void()> e1, e2;
e1.expect().once().in(s);
e2.expect().once().in(s);
BOOST_CHECK_NO_THROW(e2());
CHECK_ERROR(e1(), "sequence failed", 1, "?()\n. once()");
}
BOOST_FIXTURE_TEST_CASE( destroying_a_sequence_does_not_remove_order_call_enforcement, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(destroying_a_sequence_does_not_remove_order_call_enforcement, mock_error_fixture)
{
mock::detail::function< void() > e1, e2;
mock::detail::function<void()> e1, e2;
{
mock::sequence s;
e1.expect().once().in( s );
e2.expect().once().in( s );
e1.expect().once().in(s);
e2.expect().once().in(s);
}
BOOST_CHECK_NO_THROW( e2() );
CHECK_ERROR( e1(), "sequence failed", 1, "?()\n. once()" );
BOOST_CHECK_NO_THROW(e2());
CHECK_ERROR(e1(), "sequence failed", 1, "?()\n. once()");
}
BOOST_FIXTURE_TEST_CASE( resetting_an_expectation_removes_it_from_order_call_enforcement, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(resetting_an_expectation_removes_it_from_order_call_enforcement, mock_error_fixture)
{
mock::sequence s;
mock::detail::function< void() > e1, e2;
e1.expect().once().in( s );
e2.expect().once().in( s );
mock::detail::function<void()> e1, e2;
e1.expect().once().in(s);
e2.expect().once().in(s);
e1.reset();
BOOST_CHECK_NO_THROW( e2() );
BOOST_CHECK( e1.verify() );
BOOST_CHECK( e2.verify() );
CHECK_CALLS( 1 );
BOOST_CHECK_NO_THROW(e2());
BOOST_CHECK(e1.verify());
BOOST_CHECK(e2.verify());
CHECK_CALLS(1);
}
BOOST_FIXTURE_TEST_CASE( an_expectation_can_be_used_in_several_sequences, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(an_expectation_can_be_used_in_several_sequences, mock_error_fixture)
{
mock::sequence s1, s2;
mock::detail::function< void() > e;
e.expect().once().in( s1, s2 );
BOOST_CHECK_NO_THROW( e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
mock::detail::function<void()> e;
e.expect().once().in(s1, s2);
BOOST_CHECK_NO_THROW(e());
BOOST_CHECK(e.verify());
CHECK_CALLS(1);
}
BOOST_FIXTURE_TEST_CASE( a_result_specification_is_set_after_a_sequence, mock_error_fixture )
BOOST_FIXTURE_TEST_CASE(a_result_specification_is_set_after_a_sequence, mock_error_fixture)
{
mock::sequence s;
mock::detail::function< int() > e;
e.expect().once().in( s ).returns( 3 );
BOOST_CHECK_EQUAL( 3, e() );
BOOST_CHECK( e.verify() );
CHECK_CALLS( 1 );
mock::detail::function<int()> e;
e.expect().once().in(s).returns(3);
BOOST_CHECK_EQUAL(3, e());
BOOST_CHECK(e.verify());
CHECK_CALLS(1);
}