diff --git a/include/turtle/detail/type_name.hpp b/include/turtle/detail/type_name.hpp index e3b4df9..72e3025 100644 --- a/include/turtle/detail/type_name.hpp +++ b/include/turtle/detail/type_name.hpp @@ -15,15 +15,6 @@ #include #include #include -#if BOOST_VERSION >= 107000 -# include -# define MOCK_TYPEID( t ) BOOST_CORE_TYPEID(t) -# define MOCK_TYPEINFO boost::core::typeinfo -#else -# include -# define MOCK_TYPEID( t ) BOOST_SP_TYPEID(t) -# define MOCK_TYPEINFO boost::detail::sp_typeinfo -#endif #include #include #include @@ -33,8 +24,6 @@ #include #endif -#define MOCK_TYPE_NAME( t ) mock::detail::type_name( MOCK_TYPEID(t) ) - namespace mock { namespace detail @@ -42,7 +31,7 @@ namespace detail class type_name { public: - explicit type_name( const MOCK_TYPEINFO& info ) + explicit type_name( const std::type_info& info ) : info_( &info ) {} friend std::ostream& operator<<( std::ostream& s, const type_name& t ) @@ -51,8 +40,7 @@ namespace detail return s; } private: - void serialize( std::ostream& s, - const MOCK_TYPEINFO& info ) const + static void serialize( std::ostream& s, const std::type_info& info ) { const char* name = info.name(); #ifdef __GNUC__ @@ -69,7 +57,7 @@ namespace detail typedef std::string::size_type size_type; - void serialize( std::ostream& s, std::string name ) const + static void serialize( std::ostream& s, std::string name ) { const size_type nm = rfind( name, ':' ) + 1; const size_type tpl = name.find( '<', nm ); @@ -80,7 +68,7 @@ namespace detail list( s, name.substr( tpl + 1, name.rfind( '>' ) - tpl - 1 ) ); s << '>'; } - void list( std::ostream& s, const std::string& name ) const + static void list( std::ostream& s, const std::string& name ) { const size_type comma = rfind( name, ',' ); if( comma != std::string::npos ) @@ -90,7 +78,7 @@ namespace detail } serialize( s, name.substr( comma + 1 ) ); } - std::string clean( std::string name ) const + static std::string clean( std::string name ) { boost::algorithm::trim( name ); boost::algorithm::erase_all( name, "class " ); @@ -102,7 +90,7 @@ namespace detail boost::algorithm::replace_all( name, "* ", "*" ); return name; } - size_type rfind( const std::string& name, char c ) const + static size_type rfind( const std::string& name, char c ) { size_type count = 0; for( size_type i = name.size() - 1; i > 0; --i ) @@ -117,8 +105,18 @@ namespace detail return std::string::npos; } - const MOCK_TYPEINFO* info_; + const std::type_info* info_; }; + template< typename T > + type_name make_type_name() + { + return type_name( typeid(T) ); + } + template< typename T > + type_name make_type_name( const T& ) + { + return type_name( typeid(T) ); + } } } // mock diff --git a/include/turtle/mock.hpp b/include/turtle/mock.hpp index a5c8052..423ab74 100644 --- a/include/turtle/mock.hpp +++ b/include/turtle/mock.hpp @@ -63,7 +63,7 @@ { \ mock::detail::configure( *this, t##_mock_, \ instance.substr( 0, instance.rfind( BOOST_PP_STRINGIZE(t) ) ), \ - MOCK_TYPE_NAME(*this), \ + mock::detail::make_type_name(*this), \ BOOST_PP_STRINGIZE(t) ); \ return t##_mock_; \ } diff --git a/test/detail/test_type_name.cpp b/test/detail/test_type_name.cpp index 292414a..cdaf736 100644 --- a/test/detail/test_type_name.cpp +++ b/test/detail/test_type_name.cpp @@ -13,9 +13,9 @@ namespace { template< typename T > - std::string to_string( const T& ) + std::string to_string( const T& t) { - return boost::lexical_cast< std::string >( MOCK_TYPE_NAME(T) ); + return boost::lexical_cast< std::string >( mock::detail::make_type_name(t) ); } } @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted ) 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) ) ); + BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( mock::detail::make_type_name() ) ); } namespace diff --git a/test/test_object.cpp b/test/test_object.cpp index a2c45de..4e8dba2 100644 --- a/test/test_object.cpp +++ b/test/test_object.cpp @@ -33,7 +33,7 @@ namespace { fixture() { - mock::detail::configure( o, e, "instance", MOCK_TYPE_NAME(o), "name" ); + mock::detail::configure( o, e, "instance", mock::detail::make_type_name(o), "name" ); } object o; mock::detail::function< void() > e; @@ -73,7 +73,7 @@ BOOST_FIXTURE_TEST_CASE( an_object_is_assignable_by_sharing_its_state, mock_erro mock::detail::function< void() > e; { object o2; - mock::detail::configure( o2, e, "instance", MOCK_TYPE_NAME(o2), "name" ); + mock::detail::configure( o2, e, "instance", mock::detail::make_type_name(o2), "name" ); e.expect().once(); o1 = o2; CHECK_ERROR( @@ -93,7 +93,7 @@ BOOST_FIXTURE_TEST_CASE( an_object_is_copiable_by_sharing_its_state, mock_error_ auto o2 = std::make_unique(); const object o1( *o2 ); mock::detail::function< void() > e; - mock::detail::configure( *o2, e, "instance", MOCK_TYPE_NAME(*o2), "name" ); + mock::detail::configure( *o2, e, "instance", mock::detail::make_type_name(*o2), "name" ); e.expect().once(); CHECK_ERROR( BOOST_CHECK( ! mock::verify( *o2 ) ),