diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 9bb53a07..7f8e2a2d 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -127,7 +127,7 @@ namespace Catch { } void useStream( const std::string& streamName ) { - std::streambuf* newBuf = Context::createStreamBuf( streamName ); + std::streambuf* newBuf = createStreamBuf( streamName ); setStreamBuf( newBuf ); delete m_streambuf; m_streambuf = newBuf; diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h index 8bb385bd..005b0bfa 100644 --- a/include/internal/catch_context.h +++ b/include/internal/catch_context.h @@ -44,42 +44,10 @@ namespace Catch { }; IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); + IMutableContext& getCurrentMutableContext(); + void cleanUpContext(); + std::streambuf* createStreamBuf( const std::string& streamName ); - class Context : public IMutableContext { - - Context(); - Context( const Context& ); - void operator=( const Context& ); - - public: // IContext - virtual IResultCapture& getResultCapture(); - virtual IRunner& getRunner(); - virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ); - virtual bool advanceGeneratorsForCurrentTest(); - virtual const IConfig* getConfig() const; - - public: // IMutableContext - virtual void setResultCapture( IResultCapture* resultCapture ); - virtual void setRunner( IRunner* runner ); - virtual void setConfig( const IConfig* config ); - - public: // Statics - static std::streambuf* createStreamBuf( const std::string& streamName ); - static void cleanUp(); - - friend IMutableContext& getCurrentMutableContext(); - - private: - IGeneratorsForTest* findGeneratorsForCurrentTest(); - IGeneratorsForTest& getGeneratorsForCurrentTest(); - - private: - IRunner* m_runner; - IResultCapture* m_resultCapture; - const IConfig* m_config; - std::map m_generatorsByTestName; - }; } #endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED diff --git a/include/internal/catch_context_impl.hpp b/include/internal/catch_context_impl.hpp index d3ecfcb1..0121d4e7 100644 --- a/include/internal/catch_context_impl.hpp +++ b/include/internal/catch_context_impl.hpp @@ -11,6 +11,74 @@ #include "catch_stream.hpp" namespace Catch { + + class Context : public IMutableContext { + + Context() : m_config( NULL ) {} + Context( const Context& ); + void operator=( const Context& ); + + public: // IContext + virtual IResultCapture& getResultCapture() { + return *m_resultCapture; + } + virtual IRunner& getRunner() { + return *m_runner; + } + virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) { + return getGeneratorsForCurrentTest() + .getGeneratorInfo( fileInfo, totalSize ) + .getCurrentIndex(); + } + virtual bool advanceGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + return generators && generators->moveNext(); + } + + virtual const IConfig* getConfig() const { + return m_config; + } + + public: // IMutableContext + virtual void setResultCapture( IResultCapture* resultCapture ) { + m_resultCapture = resultCapture; + } + virtual void setRunner( IRunner* runner ) { + m_runner = runner; + } + virtual void setConfig( const IConfig* config ) { + m_config = config; + } + + friend IMutableContext& getCurrentMutableContext(); + + private: + IGeneratorsForTest* findGeneratorsForCurrentTest() { + std::string testName = getResultCapture().getCurrentTestName(); + + std::map::const_iterator it = + m_generatorsByTestName.find( testName ); + return it != m_generatorsByTestName.end() + ? it->second + : NULL; + } + + IGeneratorsForTest& getGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + if( !generators ) { + std::string testName = getResultCapture().getCurrentTestName(); + generators = createGeneratorsForTest(); + m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); + } + return *generators; + } + + private: + IRunner* m_runner; + IResultCapture* m_resultCapture; + const IConfig* m_config; + std::map m_generatorsByTestName; + }; namespace { Context* currentContext = NULL; @@ -23,75 +91,17 @@ namespace Catch { IContext& getCurrentContext() { return getCurrentMutableContext(); } - - Context::Context() - : m_config( NULL ) - {} - void Context::cleanUp() { - delete currentContext; - currentContext = NULL; - } - - void Context::setRunner( IRunner* runner ) { - m_runner = runner; - } - - void Context::setResultCapture( IResultCapture* resultCapture ) { - m_resultCapture = resultCapture; - } - - const IConfig* Context::getConfig() const { - return m_config; - } - void Context::setConfig( const IConfig* config ) { - m_config = config; - } - - IResultCapture& Context::getResultCapture() { - return *m_resultCapture; - } - - IRunner& Context::getRunner() { - return *m_runner; - } - - std::streambuf* Context::createStreamBuf( const std::string& streamName ) { + std::streambuf* createStreamBuf( const std::string& streamName ) { if( streamName == "stdout" ) return std::cout.rdbuf(); if( streamName == "stderr" ) return std::cerr.rdbuf(); if( streamName == "debug" ) return new StreamBufImpl; - + throw std::domain_error( "Unknown stream: " + streamName ); } - IGeneratorsForTest* Context::findGeneratorsForCurrentTest() { - std::string testName = getResultCapture().getCurrentTestName(); - - std::map::const_iterator it = - m_generatorsByTestName.find( testName ); - return it != m_generatorsByTestName.end() - ? it->second - : NULL; - } - - IGeneratorsForTest& Context::getGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - if( !generators ) { - std::string testName = getResultCapture().getCurrentTestName(); - generators = createGeneratorsForTest(); - m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); - } - return *generators; - } - - size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) { - return getGeneratorsForCurrentTest() - .getGeneratorInfo( fileInfo, totalSize ) - .getCurrentIndex(); - } - - bool Context::advanceGeneratorsForCurrentTest() { - IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); - return generators && generators->moveNext(); + void cleanUpContext() { + delete currentContext; + currentContext = NULL; } } diff --git a/include/internal/catch_registry_hub.hpp b/include/internal/catch_registry_hub.hpp index 28b00efc..4a8e9a35 100644 --- a/include/internal/catch_registry_hub.hpp +++ b/include/internal/catch_registry_hub.hpp @@ -68,7 +68,7 @@ namespace Catch { void cleanUp() { delete getTheRegistryHub(); getTheRegistryHub() = NULL; - Context::cleanUp(); + cleanUpContext(); } } // end namespace Catch