Changed some std::string args to char* to improve compile time

This commit is contained in:
Phil Nash 2011-01-07 09:38:32 +00:00
parent 896a04f5e8
commit a65f210cb2
4 changed files with 23 additions and 21 deletions

View File

@ -95,8 +95,8 @@ public:
MutableResultInfo() MutableResultInfo()
{} {}
MutableResultInfo( const std::string& expr, bool isNot, const std::string& filename, std::size_t line, const std::string& macroName ) MutableResultInfo( const char* expr, bool isNot, const char* filename, std::size_t line, const char* macroName )
: ResultInfo( ( isNot ? "!" : "" ) + expr, ResultWas::Unknown, isNot, filename, line, macroName ) : ResultInfo( expr, ResultWas::Unknown, isNot, filename, line, macroName )
{ {
} }
void setResultType( ResultWas::OfType result ) void setResultType( ResultWas::OfType result )
@ -138,7 +138,7 @@ private:
class ResultBuilder class ResultBuilder
{ {
public: 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 ) : m_result( expr, isNot, filename, line, macroName )
{} {}

View File

@ -46,7 +46,7 @@ namespace Catch
m_expressionIncomplete( false ) 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_macroName( macroName ),
m_filename( filename ), m_filename( filename ),
m_line( line ), m_line( line ),
@ -56,6 +56,8 @@ namespace Catch
m_isNot( isNot ), m_isNot( isNot ),
m_expressionIncomplete( false ) m_expressionIncomplete( false )
{ {
if( isNot )
m_expr = "!" + m_expr;
} }
bool ok() const bool ok() const

View File

@ -55,7 +55,7 @@ private:
typedef void(*TestFunction)(); typedef void(*TestFunction)();
struct FreeFunctionTestCase : TestCase struct FreeFunctionTestCase : ITestCase
{ {
FreeFunctionTestCase( TestFunction fun ) FreeFunctionTestCase( TestFunction fun )
: fun( fun ) : fun( fun )
@ -66,18 +66,18 @@ struct FreeFunctionTestCase : TestCase
fun(); fun();
} }
virtual TestCase* clone() const virtual ITestCase* clone() const
{ {
return new FreeFunctionTestCase( fun ); return new FreeFunctionTestCase( fun );
} }
virtual bool operator == ( const TestCase& other ) const virtual bool operator == ( const ITestCase& other ) const
{ {
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun == ffOther->fun; return ffOther && fun == ffOther->fun;
} }
virtual bool operator < ( const TestCase& other ) const virtual bool operator < ( const ITestCase& other ) const
{ {
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun < ffOther->fun; return ffOther && fun < ffOther->fun;
@ -88,7 +88,7 @@ private:
}; };
template<typename C> template<typename C>
struct MethodTestCase : TestCase struct MethodTestCase : ITestCase
{ {
MethodTestCase( void (C::*method)() ) MethodTestCase( void (C::*method)() )
: method( method ) : method( method )
@ -100,18 +100,18 @@ struct MethodTestCase : TestCase
(obj.*method)(); (obj.*method)();
} }
virtual TestCase* clone() const virtual ITestCase* clone() const
{ {
return new MethodTestCase<C>( method ); return new MethodTestCase<C>( method );
} }
virtual bool operator == ( const TestCase& other ) const virtual bool operator == ( const ITestCase& other ) const
{ {
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other ); const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && method == mtOther->method; return mtOther && method == mtOther->method;
} }
virtual bool operator < ( const TestCase& other ) const virtual bool operator < ( const ITestCase& other ) const
{ {
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other ); const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && &method < &mtOther->method; return mtOther && &method < &mtOther->method;
@ -123,13 +123,13 @@ private:
struct AutoReg 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 ) ); TestRegistry::instance().registerTest( TestCaseInfo( new FreeFunctionTestCase( function ), name, description ) );
} }
template<typename C> template<typename C>
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<C>( method ), name, description ) ); TestRegistry::instance().registerTest( TestCaseInfo( new MethodTestCase<C>( method ), name, description ) );
} }

View File

@ -18,19 +18,19 @@
namespace Catch namespace Catch
{ {
struct TestCase struct ITestCase
{ {
virtual ~TestCase(){} virtual ~ITestCase(){}
virtual void invoke() const = 0; virtual void invoke() const = 0;
virtual TestCase* clone() const = 0; virtual ITestCase* clone() const = 0;
virtual bool operator == ( const TestCase& other ) const = 0; virtual bool operator == ( const ITestCase& other ) const = 0;
virtual bool operator < ( const TestCase& other ) const = 0; virtual bool operator < ( const ITestCase& other ) const = 0;
}; };
class TestCaseInfo class TestCaseInfo
{ {
public: public:
TestCaseInfo( TestCase* testCase, const std::string& name, const std::string& description ) TestCaseInfo( ITestCase* testCase, const char* name, const char* description )
: test( testCase ), : test( testCase ),
name( name ), name( name ),
description( description ) description( description )
@ -97,7 +97,7 @@ namespace Catch
} }
private: private:
TestCase* test; ITestCase* test;
std::string name; std::string name;
std::string description; std::string description;
}; };