Removed all std::string to spare unnecessary memory allocations

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@383 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-10-02 10:47:27 +00:00
parent 64c638d59c
commit ad40a1a9cf
15 changed files with 157 additions and 102 deletions

View file

@ -14,7 +14,6 @@
#include <boost/test/unit_test_suite.hpp> #include <boost/test/unit_test_suite.hpp>
#include <boost/test/execution_monitor.hpp> #include <boost/test/execution_monitor.hpp>
#include <boost/exception/enable_current_exception.hpp> #include <boost/exception/enable_current_exception.hpp>
#include <string>
namespace mock namespace mock
{ {
@ -33,8 +32,8 @@ namespace mock
template< typename Context > template< typename Context >
static void fail( static void fail(
const std::string& message, const Context& context, const char* message, const Context& context,
const std::string& file = "unknown location", int line = 0 ) const char* file = "unknown location", int line = 0 )
{ {
boost::unit_test::framework::assertion_result( false ); boost::unit_test::framework::assertion_result( false );
boost::unit_test::unit_test_log boost::unit_test::unit_test_log
@ -46,7 +45,7 @@ namespace mock
template< typename Context > template< typename Context >
static void expected_call( const Context& context, static void expected_call( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
boost::unit_test::framework::assertion_result( true ); boost::unit_test::framework::assertion_result( true );
boost::unit_test::unit_test_log boost::unit_test::unit_test_log
@ -58,7 +57,7 @@ namespace mock
template< typename Context > template< typename Context >
static void missing_action( const Context& context, static void missing_action( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "missing action", context, file, line ); fail( "missing action", context, file, line );
} }
@ -69,19 +68,19 @@ namespace mock
} }
template< typename Context > template< typename Context >
static void sequence_failed( const Context& context, static void sequence_failed( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* file, int line )
{ {
fail( "sequence failed", context ); fail( "sequence failed", context, file, line );
} }
template< typename Context > template< typename Context >
static void verification_failed( const Context& context, static void verification_failed( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "verification failed", context, file, line ); fail( "verification failed", context, file, line );
} }
template< typename Context > template< typename Context >
static void untriggered_expectation( const Context& context, static void untriggered_expectation( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "untriggered expectation", context, file, line ); fail( "untriggered expectation", context, file, line );
} }

View file

@ -10,8 +10,10 @@
#define MOCK_CHILD_HPP_INCLUDED #define MOCK_CHILD_HPP_INCLUDED
#include "parent.hpp" #include "parent.hpp"
#include "type_name.hpp"
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/optional.hpp>
#include <ostream> #include <ostream>
#include <string>
namespace mock namespace mock
{ {
@ -23,8 +25,10 @@ namespace detail
child() child()
: parent_( 0 ) : parent_( 0 )
{} {}
void update( parent& p, const std::string& instance, void update( parent& p,
const std::string& type, const std::string& name ) boost::unit_test::const_string instance,
const boost::optional< type_name >& type,
boost::unit_test::const_string name )
{ {
if( instance != "?" || name_.empty() ) if( instance != "?" || name_.empty() )
p = parent( instance, type ); p = parent( instance, type );
@ -39,7 +43,7 @@ namespace detail
} }
private: private:
const parent* parent_; const parent* parent_;
std::string name_; boost::unit_test::const_string name_;
}; };
} }
} }

View file

@ -38,8 +38,10 @@
# endif # endif
#endif #endif
#ifndef MOCK_USE_BOOST_TEST
# ifdef BOOST_TEST_DECL # ifdef BOOST_TEST_DECL
# define MOCK_USE_BOOST_TEST # define MOCK_USE_BOOST_TEST
# endif # endif
#endif
#endif // MOCK_CONFIG_HPP_INCLUDED #endif // MOCK_CONFIG_HPP_INCLUDED

View file

@ -9,9 +9,11 @@
#ifndef MOCK_CONTEXT_HPP_INCLUDED #ifndef MOCK_CONTEXT_HPP_INCLUDED
#define MOCK_CONTEXT_HPP_INCLUDED #define MOCK_CONTEXT_HPP_INCLUDED
#include "type_name.hpp"
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/optional.hpp>
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <ostream> #include <ostream>
#include <string>
namespace mock namespace mock
{ {
@ -25,8 +27,10 @@ namespace detail
context() {} context() {}
virtual ~context() {} virtual ~context() {}
virtual void add( const void* p, verifiable& v, const std::string& instance, virtual void add( const void* p, verifiable& v,
const std::string& type, const std::string& name ) = 0; boost::unit_test::const_string instance,
const boost::optional< type_name >& type,
boost::unit_test::const_string name ) = 0;
virtual void add( verifiable& v ) = 0; virtual void add( verifiable& v ) = 0;
virtual void remove( verifiable& v ) = 0; virtual void remove( verifiable& v ) = 0;

View file

@ -10,7 +10,6 @@
#define MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED #define MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED
#include <iostream> #include <iostream>
#include <string>
namespace mock namespace mock
{ {
@ -27,8 +26,8 @@ namespace mock
template< typename Context > template< typename Context >
static void fail( static void fail(
const std::string& message, const Context& context, const char* message, const Context& context,
const std::string& file = "unknown location", int line = 0 ) const char* file = "unknown location", int line = 0 )
{ {
std::cerr << file << '(' << line << "): " std::cerr << file << '(' << line << "): "
<< message << ": " << context << std::endl; << message << ": " << context << std::endl;
@ -36,12 +35,12 @@ namespace mock
template< typename Context > template< typename Context >
static void expected_call( const Context& /*context*/, static void expected_call( const Context& /*context*/,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{} {}
template< typename Context > template< typename Context >
static void missing_action( const Context& context, static void missing_action( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "missing action", context, file, line ); fail( "missing action", context, file, line );
} }
@ -52,19 +51,19 @@ namespace mock
} }
template< typename Context > template< typename Context >
static void sequence_failed( const Context& context, static void sequence_failed( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* file, int line )
{ {
fail( "sequence failed", context ); fail( "sequence failed", context, file, line );
} }
template< typename Context > template< typename Context >
static void verification_failed( const Context& context, static void verification_failed( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "verification failed", context, file, line ); fail( "verification failed", context, file, line );
} }
template< typename Context > template< typename Context >
static void untriggered_expectation( const Context& context, static void untriggered_expectation( const Context& context,
const std::string& file, int line ) const char* file, int line )
{ {
fail( "untriggered expectation", context, file, line ); fail( "untriggered expectation", context, file, line );
} }

View file

@ -36,7 +36,7 @@ namespace detail
, file_( "unknown location" ) , file_( "unknown location" )
, line_( 0 ) , line_( 0 )
{} {}
void set_location( const std::string& file, int line ) void set_location( const char* file, int line )
{ {
file_ = file; file_ = file;
line_ = line; line_ = line;
@ -65,7 +65,7 @@ namespace detail
return i_->invoked(); return i_->invoked();
} }
const std::string& file() const const char* file() const
{ {
return file_; return file_;
} }
@ -100,7 +100,7 @@ namespace detail
typedef sequences_type::const_iterator sequences_cit; typedef sequences_type::const_iterator sequences_cit;
sequences_type sequences_; sequences_type sequences_;
std::string file_; const char* file_;
int line_; int line_;
}; };

View file

@ -16,6 +16,7 @@
#include "verifiable.hpp" #include "verifiable.hpp"
#include "log.hpp" #include "log.hpp"
#include "args.hpp" #include "args.hpp"
#include "type_name.hpp"
#include <boost/function_types/result_type.hpp> #include <boost/function_types/result_type.hpp>
#include <boost/function_types/function_arity.hpp> #include <boost/function_types/function_arity.hpp>
#include <boost/function_types/parameter_types.hpp> #include <boost/function_types/parameter_types.hpp>
@ -23,8 +24,10 @@
#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/comparison/equal.hpp> #include <boost/preprocessor/comparison/equal.hpp>
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
#include <boost/test/utils/lazy_ostream.hpp> #include <boost/test/utils/lazy_ostream.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <ostream> #include <ostream>
#include <list> #include <list>
@ -63,7 +66,7 @@ namespace mock
impl_->reset(); impl_->reset();
} }
expectation_type& expect( const std::string& file, int line ) expectation_type& expect( const char* file, int line )
{ {
return impl_->expect( file, line ); return impl_->expect( file, line );
} }
@ -95,18 +98,21 @@ namespace mock
return s << *e.impl_; return s << *e.impl_;
} }
function& _configure( detail::context& c, const std::string& instance ) function& _configure( detail::context& c,
boost::unit_test::const_string instance )
{ {
if( ! impl_->context_ ) if( ! impl_->context_ )
c.add( *impl_ ); c.add( *impl_ );
c.add( impl_.get(), *impl_, instance, "", "" ); c.add( impl_.get(), *impl_, instance,
boost::optional< detail::type_name >(), "" );
impl_->context_ = &c; impl_->context_ = &c;
return *this; return *this;
} }
void configure( detail::context& c, const void* p, void configure( detail::context& c, const void* p,
const std::string& instance, const std::string& type, boost::unit_test::const_string instance,
const std::string& name ) const const boost::optional< detail::type_name >& type,
boost::unit_test::const_string name ) const
{ {
if( ! impl_->context_ ) if( ! impl_->context_ )
c.add( *impl_ ); c.add( *impl_ );
@ -170,7 +176,7 @@ namespace mock
expectations_.clear(); expectations_.clear();
} }
expectation_type& expect( const std::string& file, int line ) expectation_type& expect( const char* file, int line )
{ {
expectation_type& e = expect(); expectation_type& e = expect();
e.set_location( file, line ); e.set_location( file, line );

View file

@ -13,8 +13,8 @@
#include "cleanup.hpp" #include "cleanup.hpp"
#include "object.hpp" #include "object.hpp"
#include "function.hpp" #include "function.hpp"
#include "type_name.hpp"
#include "args.hpp" #include "args.hpp"
#include "type_name.hpp"
#include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <boost/function_types/parameter_types.hpp> #include <boost/function_types/parameter_types.hpp>
@ -105,7 +105,7 @@ namespace detail
#define MOCK_METHOD_EXPECTATION(S, t) \ #define MOCK_METHOD_EXPECTATION(S, t) \
mutable mock::function< S > t##expectation; \ mutable mock::function< S > t##expectation; \
mock::function< S >& t##configure( const mock::detail::context&, \ mock::function< S >& t##configure( const mock::detail::context&, \
const std::string& instance ) const \ boost::unit_test::const_string instance ) const \
{ \ { \
mock::detail::configure( *this, t##expectation, instance, \ mock::detail::configure( *this, t##expectation, instance, \
mock::detail::type_name( typeid( *this ) ), \ mock::detail::type_name( typeid( *this ) ), \

View file

@ -13,10 +13,10 @@
#include "context.hpp" #include "context.hpp"
#include "parent.hpp" #include "parent.hpp"
#include "child.hpp" #include "child.hpp"
#include "type_name.hpp"
#include <boost/type_traits/is_base_of.hpp> #include <boost/type_traits/is_base_of.hpp>
#include <boost/utility/enable_if.hpp> #include <boost/utility/enable_if.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <string>
namespace mock namespace mock
{ {
@ -41,8 +41,9 @@ namespace mock
{ {
public: public:
virtual void add( const void* /*p*/, verifiable& v, virtual void add( const void* /*p*/, verifiable& v,
const std::string& instance, const std::string& type, boost::unit_test::const_string instance,
const std::string& name ) const boost::optional< detail::type_name >& type,
boost::unit_test::const_string name )
{ {
if( children_.empty() ) if( children_.empty() )
mock::detail::root.add( *this ); mock::detail::root.add( *this );
@ -95,16 +96,20 @@ namespace mock
namespace detail namespace detail
{ {
template< typename E > template< typename E >
E& configure( const object& o, E& e, const std::string& instance, E& configure( const object& o, E& e,
const std::string& type, const std::string& name ) boost::unit_test::const_string instance,
const boost::optional< type_name >& type,
boost::unit_test::const_string name )
{ {
e.configure( *o.impl_, o.impl_.get(), instance, type, name ); e.configure( *o.impl_, o.impl_.get(), instance, type, name );
return e; return e;
} }
template< typename E, typename T > template< typename E, typename T >
E& configure( const T& t, E& e, const std::string& instance, E& configure( const T& t, E& e,
const std::string& type, const std::string& name, boost::unit_test::const_string instance,
const boost::optional< type_name >& type,
boost::unit_test::const_string name,
BOOST_DEDUCED_TYPENAME boost::disable_if< BOOST_DEDUCED_TYPENAME boost::disable_if<
BOOST_DEDUCED_TYPENAME boost::is_base_of< object, T > BOOST_DEDUCED_TYPENAME boost::is_base_of< object, T >
>::type* = 0 ) >::type* = 0 )

View file

@ -9,8 +9,10 @@
#ifndef MOCK_PARENT_HPP_INCLUDED #ifndef MOCK_PARENT_HPP_INCLUDED
#define MOCK_PARENT_HPP_INCLUDED #define MOCK_PARENT_HPP_INCLUDED
#include "type_name.hpp"
#include <boost/optional.hpp>
#include <boost/test/utils/basic_cstring/io.hpp>
#include <ostream> #include <ostream>
#include <string>
namespace mock namespace mock
{ {
@ -21,20 +23,21 @@ namespace detail
public: public:
parent() parent()
{} {}
parent( const std::string& instance, const std::string& type ) parent( boost::unit_test::const_string instance,
const boost::optional< type_name >& type )
: instance_( instance ) : instance_( instance )
, type_( type ) , type_( type )
{} {}
friend std::ostream& operator<<( std::ostream& s, const parent& p ) friend std::ostream& operator<<( std::ostream& s, const parent& p )
{ {
s << p.instance_; s << p.instance_;
if( ! p.type_.empty() ) if( p.type_ )
s << " " + p.type_ + "::"; s << " " << *p.type_ << "::";
return s; return s;
} }
private: private:
std::string instance_; boost::unit_test::const_string instance_;
std::string type_; boost::optional< type_name > type_;
}; };
} }
} }

View file

@ -16,7 +16,6 @@
#include "function.hpp" #include "function.hpp"
#include <boost/test/utils/trivial_singleton.hpp> #include <boost/test/utils/trivial_singleton.hpp>
#include <ostream> #include <ostream>
#include <string>
#include <map> #include <map>
namespace mock namespace mock
@ -28,8 +27,9 @@ namespace detail
{ {
public: public:
virtual void add( const void* p, verifiable& v, virtual void add( const void* p, verifiable& v,
const std::string& instance, const std::string& type, boost::unit_test::const_string instance,
const std::string& name ) const boost::optional< type_name >& type,
boost::unit_test::const_string name )
{ {
children_it it = children_.lower_bound( &v ); children_it it = children_.lower_bound( &v );
if( it == children_.end() || if( it == children_.end() ||
@ -94,8 +94,9 @@ namespace detail
if( --it_->second.second == 0 ) if( --it_->second.second == 0 )
parents_->erase( it_ ); parents_->erase( it_ );
} }
void update( const std::string& instance, const std::string& type, void update( boost::unit_test::const_string instance,
const std::string& name ) const boost::optional< type_name >& type,
boost::unit_test::const_string name )
{ {
child_.update( it_->second.first, instance, type, name ); child_.update( it_->second.first, instance, type, name );
} }

View file

@ -9,8 +9,10 @@
#ifndef MOCK_TYPE_NAME_HPP_INCLUDED #ifndef MOCK_TYPE_NAME_HPP_INCLUDED
#define MOCK_TYPE_NAME_HPP_INCLUDED #define MOCK_TYPE_NAME_HPP_INCLUDED
#include <boost/test/utils/basic_cstring/io.hpp>
#include <stdexcept> #include <stdexcept>
#include <typeinfo> #include <typeinfo>
#include <ostream>
#ifdef __GNUC__ #ifdef __GNUC__
#include <cxxabi.h> #include <cxxabi.h>
#include <cstdlib> #include <cstdlib>
@ -20,7 +22,19 @@ namespace mock
{ {
namespace detail namespace detail
{ {
inline std::string type_full_name( const std::type_info& info ) class type_name
{
public:
explicit type_name( const std::type_info& info )
: info_( &info )
{}
friend std::ostream& operator<<( std::ostream& s, const type_name& t )
{
t.serialize( s, *t.info_ );
return s;
}
private:
void serialize( std::ostream& s, const std::type_info& info ) const
{ {
const char* name = info.name(); const char* name = info.name();
#ifdef __GNUC__ #ifdef __GNUC__
@ -40,21 +54,30 @@ namespace detail
char* p_; char* p_;
} g( result ); } g( result );
if( result ) if( result )
return result; serialize( s, result );
else
#endif #endif
return name; serialize( s, name );
} }
inline std::string type_name( const std::type_info& info ) void serialize( std::ostream& s, boost::unit_test::const_string name ) const
{ {
const std::string name = type_full_name( info );
std::size_t p = name.rfind( "::" ); std::size_t p = name.rfind( "::" );
if( p != std::string::npos ) if( p != boost::unit_test::const_string::npos )
return name.substr( p + 2 ); {
p = name.rfind( " " ); s << name.substr( p + 2 );
if( p != std::string::npos ) return;
return name.substr( p + 1 );
return name;
} }
p = name.rfind( " " );
if( p != boost::unit_test::const_string::npos )
{
s << name.substr( p + 1 );
return;
}
s << name;
}
const std::type_info* info_;
};
} }
} }

View file

@ -12,7 +12,6 @@
#define MOCK_ERROR_POLICY mock_error #define MOCK_ERROR_POLICY mock_error
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <stdexcept> #include <stdexcept>
#include <string>
namespace namespace
{ {
@ -37,14 +36,14 @@ namespace mock
template< typename Context > template< typename Context >
static void missing_action( const Context& context, static void missing_action( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{ {
last_context = boost::lexical_cast< std::string >( context ); last_context = boost::lexical_cast< std::string >( context );
++missing_action_count; ++missing_action_count;
} }
template< typename Context > template< typename Context >
static void expected_call( const Context& /*context*/, static void expected_call( const Context& /*context*/,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{ {
last_context.clear(); last_context.clear();
++expected_call_count; ++expected_call_count;
@ -57,21 +56,21 @@ namespace mock
} }
template< typename Context > template< typename Context >
static void sequence_failed( const Context& context, static void sequence_failed( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{ {
last_context = boost::lexical_cast< std::string >( context ); last_context = boost::lexical_cast< std::string >( context );
++sequence_failed_count; ++sequence_failed_count;
} }
template< typename Context > template< typename Context >
static void verification_failed( const Context& context, static void verification_failed( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{ {
last_context = boost::lexical_cast< std::string >( context ); last_context = boost::lexical_cast< std::string >( context );
++verification_failed_count; ++verification_failed_count;
} }
template< typename Context > template< typename Context >
static void untriggered_expectation( const Context& context, static void untriggered_expectation( const Context& context,
const std::string& /*file*/, int /*line*/ ) const char* /*file*/, int /*line*/ )
{ {
last_context = boost::lexical_cast< std::string >( context ); last_context = boost::lexical_cast< std::string >( context );
++untriggered_expectation_count; ++untriggered_expectation_count;

View file

@ -28,7 +28,7 @@ namespace
{ {
fixture() fixture()
{ {
mock::detail::configure( o, e, "instance", "type", "name" ); mock::detail::configure( o, e, "instance", mock::detail::type_name( typeid( "type" ) ), "name" );
} }
mock::object o; mock::object o;
mock::function< void() > e; mock::function< void() > e;
@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE( an_object_is_assignable_by_sharing_its_state )
mock::function< void() > e; mock::function< void() > e;
{ {
mock::object o2; mock::object o2;
mock::detail::configure( o2, e, "instance", "type", "name" ); mock::detail::configure( o2, e, "instance", mock::detail::type_name( typeid( "type" ) ), "name" );
e.expect().once(); e.expect().once();
o1 = o2; o1 = o2;
BOOST_CHECK( ! mock::verify( o2 ) ); BOOST_CHECK( ! mock::verify( o2 ) );
@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE( an_object_is_copiable_by_sharing_its_state )
std::auto_ptr< mock::object > o2( new mock::object ); std::auto_ptr< mock::object > o2( new mock::object );
const mock::object o1( *o2 ); const mock::object o1( *o2 );
mock::function< void() > e; mock::function< void() > e;
mock::detail::configure( *o2, e, "instance", "type", "name" ); mock::detail::configure( *o2, e, "instance", mock::detail::type_name( typeid( "type" ) ), "name" );
e.expect().once(); e.expect().once();
BOOST_CHECK( ! mock::verify( *o2 ) ); BOOST_CHECK( ! mock::verify( *o2 ) );
BOOST_CHECK( ! mock::verify( o1 ) ); BOOST_CHECK( ! mock::verify( o1 ) );

View file

@ -8,12 +8,22 @@
#include <turtle/type_name.hpp> #include <turtle/type_name.hpp>
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>
#include <boost/lexical_cast.hpp>
struct my_type_from_default_namespace {}; struct my_type_from_default_namespace {};
namespace
{
template< typename T >
std::string to_string( const T& )
{
return boost::lexical_cast< std::string >( mock::detail::type_name( typeid( T ) ) );
}
}
BOOST_AUTO_TEST_CASE( name_of_type_from_default_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_type_from_default_namespace_is_extracted )
{ {
BOOST_CHECK_EQUAL( "my_type_from_default_namespace", mock::detail::type_name( typeid( my_type_from_default_namespace ) ) ); BOOST_CHECK_EQUAL( "my_type_from_default_namespace", to_string( my_type_from_default_namespace() ) );
} }
namespace namespace
@ -23,7 +33,7 @@ namespace
BOOST_AUTO_TEST_CASE( name_of_type_from_anonymous_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_type_from_anonymous_namespace_is_extracted )
{ {
BOOST_CHECK_EQUAL( "my_type_from_anonymous_namespace", mock::detail::type_name( typeid( my_type_from_anonymous_namespace ) ) ); BOOST_CHECK_EQUAL( "my_type_from_anonymous_namespace", to_string( my_type_from_anonymous_namespace() ) );
} }
namespace nm namespace nm
@ -33,7 +43,7 @@ namespace nm
BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_type_from_named_namespace_is_extracted )
{ {
BOOST_CHECK_EQUAL( "my_type_from_named_namespace", mock::detail::type_name( typeid( nm::my_type_from_named_namespace ) ) ); BOOST_CHECK_EQUAL( "my_type_from_named_namespace", to_string( nm::my_type_from_named_namespace() ) );
} }
namespace nm namespace nm
@ -46,7 +56,7 @@ namespace inner
BOOST_AUTO_TEST_CASE( name_of_type_from_named_inner_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_type_from_named_inner_namespace_is_extracted )
{ {
BOOST_CHECK_EQUAL( "my_type_from_named_inner_namespace", mock::detail::type_name( typeid( nm::inner::my_type_from_named_inner_namespace ) ) ); BOOST_CHECK_EQUAL( "my_type_from_named_inner_namespace", to_string( nm::inner::my_type_from_named_inner_namespace() ) );
} }
namespace namespace
@ -59,11 +69,11 @@ namespace inner
BOOST_AUTO_TEST_CASE( name_of_type_from_unnamed_inner_namespace_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_type_from_unnamed_inner_namespace_is_extracted )
{ {
BOOST_CHECK_EQUAL( "my_type_from_unnamed_inner_namespace", mock::detail::type_name( typeid( inner::my_type_from_unnamed_inner_namespace ) ) ); BOOST_CHECK_EQUAL( "my_type_from_unnamed_inner_namespace", to_string( inner::my_type_from_unnamed_inner_namespace() ) );
} }
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted ) BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
{ {
struct my_local_type {}; struct my_local_type {};
BOOST_CHECK_EQUAL( "my_local_type", mock::detail::type_name( typeid( my_local_type ) ) ); BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( mock::detail::type_name( typeid( my_local_type ) ) ) );
} }