Changed layout to match boost

This commit is contained in:
Mathieu Champlon 2015-03-04 06:23:30 +01:00
parent 7a8ba352c6
commit c950c24f52
122 changed files with 15469 additions and 15550 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,76 +1,76 @@
// http://turtle.sourceforge.net
//
// 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)
#include <turtle/detail/invocation.hpp>
#include <boost/test/auto_unit_test.hpp>
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_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_AUTO_TEST_CASE( never )
{
mock::detail::never invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
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() );
}
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() );
}
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() );
}
// http://turtle.sourceforge.net
//
// 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)
#include <turtle/detail/invocation.hpp>
#include <boost/test/auto_unit_test.hpp>
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_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_AUTO_TEST_CASE( never )
{
mock::detail::never invocation;
BOOST_CHECK( invocation.verify() );
BOOST_CHECK( invocation.exhausted() );
BOOST_CHECK( ! invocation.invoke() );
}
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() );
}
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() );
}
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() );
}

View file

@ -1,155 +1,155 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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)
#include <turtle/detail/is_functor.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef BOOST_MSVC
#pragma warning( push, 0 )
#endif
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/phoenix.hpp>
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace
{
struct declared_but_not_defined;
BOOST_MPL_ASSERT_NOT((
mock::detail::is_functor< declared_but_not_defined, int > ));
template< typename T >
void is_functor( T )
{
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
}
template< typename T >
void is_not_functor( T )
{
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
}
void f0() {}
bool f1( int ) { return false; }
bool f2( std::string, int ) { return false; }
}
BOOST_AUTO_TEST_CASE( data_is_not_functor )
{
is_not_functor( 42 );
}
BOOST_AUTO_TEST_CASE( function_is_functor )
{
is_functor( f0 );
is_functor( f1 );
is_functor( f2 );
}
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
{
is_functor( &f0 );
is_functor( &f1 );
is_functor( &f2 );
}
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
{
is_functor( std::ptr_fun( &f1 ) );
is_functor( std::ptr_fun( &f2 ) );
}
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
{
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
}
namespace
{
struct unary_functor0 : public std::unary_function< void, void >
{};
struct unary_functor1 : public std::unary_function< int, void >
{};
}
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
{
is_functor( unary_functor0() );
is_functor( unary_functor1() );
}
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
{
is_functor( boost::bind( &f0 ) );
is_functor( boost::bind( &f1, _1 ) );
is_functor( boost::bind( &f2, "", _1 ) );
}
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
{
is_functor( boost::lambda::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
{
is_functor( boost::phoenix::arg_names::arg1 < 42 );
is_functor( boost::phoenix::arg_names::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
{
is_functor( boost::function< void() >() );
}
namespace
{
struct result_type_functor
{
typedef void result_type;
};
}
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
{
is_functor( result_type_functor() );
}
namespace
{
struct sig_functor
{
template< typename Args >
struct sig
{
typedef void type;
};
};
}
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
{
is_functor( sig_functor() );
}
#ifdef MOCK_LAMBDAS
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
{
is_not_functor( []() {} );
#ifdef MOCK_DECLTYPE
is_functor( []( int ) {} );
#else
is_not_functor( []( int ) {} );
#endif
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
}
#endif
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2009
//
// 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)
#include <turtle/detail/is_functor.hpp>
#include <boost/test/auto_unit_test.hpp>
#ifdef BOOST_MSVC
#pragma warning( push, 0 )
#endif
#include <boost/lambda/lambda.hpp>
#include <boost/phoenix/phoenix.hpp>
#ifdef BOOST_MSVC
#pragma warning( pop )
#endif
#include <boost/function.hpp>
#include <boost/bind.hpp>
namespace
{
struct declared_but_not_defined;
BOOST_MPL_ASSERT_NOT((
mock::detail::is_functor< declared_but_not_defined, int > ));
template< typename T >
void is_functor( T )
{
BOOST_MPL_ASSERT(( mock::detail::is_functor< T, int > ));
}
template< typename T >
void is_not_functor( T )
{
BOOST_MPL_ASSERT_NOT(( mock::detail::is_functor< T, int > ));
}
void f0() {}
bool f1( int ) { return false; }
bool f2( std::string, int ) { return false; }
}
BOOST_AUTO_TEST_CASE( data_is_not_functor )
{
is_not_functor( 42 );
}
BOOST_AUTO_TEST_CASE( function_is_functor )
{
is_functor( f0 );
is_functor( f1 );
is_functor( f2 );
}
BOOST_AUTO_TEST_CASE( function_pointer_is_functor )
{
is_functor( &f0 );
is_functor( &f1 );
is_functor( &f2 );
}
BOOST_AUTO_TEST_CASE( std_ptr_fun_is_functor )
{
is_functor( std::ptr_fun( &f1 ) );
is_functor( std::ptr_fun( &f2 ) );
}
BOOST_AUTO_TEST_CASE( std_bind_first_is_functor )
{
is_functor( std::bind1st( std::ptr_fun( &f2 ), "" ) );
}
namespace
{
struct unary_functor0 : public std::unary_function< void, void >
{};
struct unary_functor1 : public std::unary_function< int, void >
{};
}
BOOST_AUTO_TEST_CASE( std_unary_functor_is_functor )
{
is_functor( unary_functor0() );
is_functor( unary_functor1() );
}
BOOST_AUTO_TEST_CASE( boost_bind_is_functor )
{
is_functor( boost::bind( &f0 ) );
is_functor( boost::bind( &f1, _1 ) );
is_functor( boost::bind( &f2, "", _1 ) );
}
BOOST_AUTO_TEST_CASE( boost_lambda_is_functor )
{
is_functor( boost::lambda::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_phoenix_is_functor )
{
is_functor( boost::phoenix::arg_names::arg1 < 42 );
is_functor( boost::phoenix::arg_names::_1 < 42 );
}
BOOST_AUTO_TEST_CASE( boost_function_is_functor )
{
is_functor( boost::function< void() >() );
}
namespace
{
struct result_type_functor
{
typedef void result_type;
};
}
BOOST_AUTO_TEST_CASE( class_with_result_type_is_functor )
{
is_functor( result_type_functor() );
}
namespace
{
struct sig_functor
{
template< typename Args >
struct sig
{
typedef void type;
};
};
}
BOOST_AUTO_TEST_CASE( class_with_sig_is_functor )
{
is_functor( sig_functor() );
}
#ifdef MOCK_LAMBDAS
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
{
is_not_functor( []() {} );
#ifdef MOCK_DECLTYPE
is_functor( []( int ) {} );
#else
is_not_functor( []( int ) {} );
#endif
is_not_functor( []( const std::string&, int ) {} );
is_not_functor( []( int, const std::string& ) {} );
}
#endif

View file

@ -1,29 +1,29 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// 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)
#include <turtle/detail/signature.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
namespace
{
struct base
{
void method_1();
float method_2( int ) const;
};
typedef base base_type;
}
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{
BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
}
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// 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)
#include <turtle/detail/signature.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/mpl/assert.hpp>
namespace
{
struct base
{
void method_1();
float method_2( int ) const;
};
typedef base base_type;
}
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{
BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > ));
BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > ));
}

View file

@ -1,225 +1,225 @@
// http://turtle.sourceforge.net
//
// 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)
#include <turtle/detail/type_name.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/lexical_cast.hpp>
namespace
{
template< typename T >
std::string to_string( const T& )
{
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
}
}
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 ) );
}
struct my_type_in_default_namespace
{
struct inner {};
};
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_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() ) );
}
template< typename T >
struct my_template_type_in_default_namespace
{
struct inner {};
};
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_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() ) );
}
namespace
{
struct my_type_in_anonymous_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_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", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(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
{};
}
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 > >() ) );
}
// http://turtle.sourceforge.net
//
// 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)
#include <turtle/detail/type_name.hpp>
#include <boost/test/auto_unit_test.hpp>
#include <boost/lexical_cast.hpp>
namespace
{
template< typename T >
std::string to_string( const T& )
{
return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) );
}
}
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 ) );
}
struct my_type_in_default_namespace
{
struct inner {};
};
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_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() ) );
}
template< typename T >
struct my_template_type_in_default_namespace
{
struct inner {};
};
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_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() ) );
}
namespace
{
struct my_type_in_anonymous_namespace {};
}
BOOST_AUTO_TEST_CASE( name_of_type_in_anonymous_namespace_is_extracted )
{
BOOST_CHECK_EQUAL( "my_type_in_anonymous_namespace", to_string( my_type_in_anonymous_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", boost::lexical_cast< std::string >( MOCK_TYPE_NAME(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
{};
}
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 > >() ) );
}