From 6c16dd968c7e877fcfdd38f07e9793cf7a8ad54d Mon Sep 17 00:00:00 2001 From: mat007 Date: Thu, 24 Jan 2013 22:38:51 +0000 Subject: [PATCH] Fixed type name extraction involving template classes git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@587 860be788-9bd5-4423-9f1e-828f051e677b --- test/detail/test_type_name.cpp | 48 ++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/test/detail/test_type_name.cpp b/test/detail/test_type_name.cpp index bc26a9b..f3ad36d 100644 --- a/test/detail/test_type_name.cpp +++ b/test/detail/test_type_name.cpp @@ -8,6 +8,7 @@ #include #include +#include #include namespace @@ -15,7 +16,12 @@ namespace template< typename T > std::string to_string( const T& ) { - return boost::lexical_cast< std::string >( mock::detail::type_name( BOOST_SP_TYPEID( T ) ) ); + std::string result = boost::lexical_cast< std::string >( mock::detail::type_name( BOOST_SP_TYPEID( T ) ) ); + boost::algorithm::replace_all( result, "& ", "&" ); + boost::algorithm::replace_all( result, " &", "&" ); + boost::algorithm::replace_all( result, "* ", "*" ); + boost::algorithm::replace_all( result, " *", "*" ); + return result; } } @@ -127,12 +133,24 @@ BOOST_AUTO_TEST_CASE( name_of_template_type_in_anonymous_namespace_is_extracted { BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< int >() ) ); BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< std::exception >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< int const& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< std::exception const& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< int const* >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< std::exception const* >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( my_template_type< int const*& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", 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 @@ -148,12 +166,24 @@ BOOST_AUTO_TEST_CASE( name_of_template_type_in_named_namespace_is_extracted ) { BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< int >() ) ); BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< std::exception >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< int const& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< std::exception const& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< int const* >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< std::exception const* >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", to_string( nm::my_template_type< int const*& >() ) ); + BOOST_CHECK_EQUAL( "my_template_type", 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 @@ -166,8 +196,22 @@ namespace nm2 }; } -BOOST_AUTO_TEST_CASE( name_of_inner_type_from_template_type_in_named_namespace_is_extracted2 ) +BOOST_AUTO_TEST_CASE( name_of_template_inner_type_from_template_type_in_named_namespace_is_extracted ) { BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int >::inner< int >() ) ); BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception >::inner< int >() ) ); + + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int const& >::inner< int >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception const& >::inner< int >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int const* >::inner< int >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception const* >::inner< int >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int const*& >::inner< int >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception const*& >::inner< int >() ) ); + + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int >::inner< int const& >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception >::inner< int const& >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int >::inner< int const* >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception >::inner< int const* >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< int >::inner< int const*& >() ) ); + BOOST_CHECK_EQUAL( "inner", to_string( nm2::my_template_type< std::exception >::inner< int const*& >() ) ); }