From a65f210cb2ce859c76c363c8b662ea8434e912e4 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 7 Jan 2011 09:38:32 +0000 Subject: [PATCH] Changed some std::string args to char* to improve compile time --- internal/catch_capture.hpp | 6 +++--- internal/catch_resultinfo.hpp | 4 +++- internal/catch_test_registry.hpp | 20 ++++++++++---------- internal/catch_testcase.hpp | 14 +++++++------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp index aba1db93..e5d77598 100644 --- a/internal/catch_capture.hpp +++ b/internal/catch_capture.hpp @@ -95,8 +95,8 @@ public: MutableResultInfo() {} - MutableResultInfo( const std::string& expr, bool isNot, const std::string& filename, std::size_t line, const std::string& macroName ) - : ResultInfo( ( isNot ? "!" : "" ) + expr, ResultWas::Unknown, isNot, filename, line, macroName ) + MutableResultInfo( const char* expr, bool isNot, const char* filename, std::size_t line, const char* macroName ) + : ResultInfo( expr, ResultWas::Unknown, isNot, filename, line, macroName ) { } void setResultType( ResultWas::OfType result ) @@ -138,7 +138,7 @@ private: class ResultBuilder { public: - ResultBuilder( const char* expr, bool isNot, const std::string& filename, std::size_t line, const std::string& macroName ) + ResultBuilder( const char* expr, bool isNot, const char* filename, std::size_t line, const char* macroName ) : m_result( expr, isNot, filename, line, macroName ) {} diff --git a/internal/catch_resultinfo.hpp b/internal/catch_resultinfo.hpp index 8a6c58a9..75c54421 100644 --- a/internal/catch_resultinfo.hpp +++ b/internal/catch_resultinfo.hpp @@ -46,7 +46,7 @@ namespace Catch m_expressionIncomplete( false ) {} - ResultInfo( const std::string& expr, ResultWas::OfType result, bool isNot, const std::string& filename, std::size_t line, const std::string& macroName ) + ResultInfo( const char* expr, ResultWas::OfType result, bool isNot, const char* filename, std::size_t line, const char* macroName ) : m_macroName( macroName ), m_filename( filename ), m_line( line ), @@ -56,6 +56,8 @@ namespace Catch m_isNot( isNot ), m_expressionIncomplete( false ) { + if( isNot ) + m_expr = "!" + m_expr; } bool ok() const diff --git a/internal/catch_test_registry.hpp b/internal/catch_test_registry.hpp index 8874a68d..9913f845 100644 --- a/internal/catch_test_registry.hpp +++ b/internal/catch_test_registry.hpp @@ -55,7 +55,7 @@ private: typedef void(*TestFunction)(); -struct FreeFunctionTestCase : TestCase +struct FreeFunctionTestCase : ITestCase { FreeFunctionTestCase( TestFunction fun ) : fun( fun ) @@ -66,18 +66,18 @@ struct FreeFunctionTestCase : TestCase fun(); } - virtual TestCase* clone() const + virtual ITestCase* clone() const { return new FreeFunctionTestCase( fun ); } - virtual bool operator == ( const TestCase& other ) const + virtual bool operator == ( const ITestCase& other ) const { const FreeFunctionTestCase* ffOther = dynamic_cast ( &other ); return ffOther && fun == ffOther->fun; } - virtual bool operator < ( const TestCase& other ) const + virtual bool operator < ( const ITestCase& other ) const { const FreeFunctionTestCase* ffOther = dynamic_cast ( &other ); return ffOther && fun < ffOther->fun; @@ -88,7 +88,7 @@ private: }; template -struct MethodTestCase : TestCase +struct MethodTestCase : ITestCase { MethodTestCase( void (C::*method)() ) : method( method ) @@ -100,18 +100,18 @@ struct MethodTestCase : TestCase (obj.*method)(); } - virtual TestCase* clone() const + virtual ITestCase* clone() const { return new MethodTestCase( method ); } - virtual bool operator == ( const TestCase& other ) const + virtual bool operator == ( const ITestCase& other ) const { const MethodTestCase* mtOther = dynamic_cast( &other ); return mtOther && method == mtOther->method; } - virtual bool operator < ( const TestCase& other ) const + virtual bool operator < ( const ITestCase& other ) const { const MethodTestCase* mtOther = dynamic_cast( &other ); return mtOther && &method < &mtOther->method; @@ -123,13 +123,13 @@ private: struct AutoReg { - AutoReg( TestFunction function, const std::string& name, const std::string& description ) + AutoReg( TestFunction function, const char* name, const char* description ) { TestRegistry::instance().registerTest( TestCaseInfo( new FreeFunctionTestCase( function ), name, description ) ); } template - AutoReg( void (C::*method)(), const std::string& name, const std::string& description ) + AutoReg( void (C::*method)(), const char* name, const char* description ) { TestRegistry::instance().registerTest( TestCaseInfo( new MethodTestCase( method ), name, description ) ); } diff --git a/internal/catch_testcase.hpp b/internal/catch_testcase.hpp index 3bd17d43..9102a79d 100644 --- a/internal/catch_testcase.hpp +++ b/internal/catch_testcase.hpp @@ -18,19 +18,19 @@ namespace Catch { - struct TestCase + struct ITestCase { - virtual ~TestCase(){} + virtual ~ITestCase(){} virtual void invoke() const = 0; - virtual TestCase* clone() const = 0; - virtual bool operator == ( const TestCase& other ) const = 0; - virtual bool operator < ( const TestCase& other ) const = 0; + virtual ITestCase* clone() const = 0; + virtual bool operator == ( const ITestCase& other ) const = 0; + virtual bool operator < ( const ITestCase& other ) const = 0; }; class TestCaseInfo { public: - TestCaseInfo( TestCase* testCase, const std::string& name, const std::string& description ) + TestCaseInfo( ITestCase* testCase, const char* name, const char* description ) : test( testCase ), name( name ), description( description ) @@ -97,7 +97,7 @@ namespace Catch } private: - TestCase* test; + ITestCase* test; std::string name; std::string description; };