mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 23:36:11 +01:00
Moved context object entirely into impl file
This commit is contained in:
parent
0477465f8d
commit
fb386f458d
@ -127,7 +127,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void useStream( const std::string& streamName ) {
|
void useStream( const std::string& streamName ) {
|
||||||
std::streambuf* newBuf = Context::createStreamBuf( streamName );
|
std::streambuf* newBuf = createStreamBuf( streamName );
|
||||||
setStreamBuf( newBuf );
|
setStreamBuf( newBuf );
|
||||||
delete m_streambuf;
|
delete m_streambuf;
|
||||||
m_streambuf = newBuf;
|
m_streambuf = newBuf;
|
||||||
|
@ -45,41 +45,9 @@ namespace Catch {
|
|||||||
|
|
||||||
IContext& getCurrentContext();
|
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<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||||
|
@ -12,6 +12,74 @@
|
|||||||
|
|
||||||
namespace Catch {
|
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<std::string, IGeneratorsForTest*>::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<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
||||||
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Context* currentContext = NULL;
|
Context* currentContext = NULL;
|
||||||
}
|
}
|
||||||
@ -24,39 +92,7 @@ namespace Catch {
|
|||||||
return getCurrentMutableContext();
|
return getCurrentMutableContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
Context::Context()
|
std::streambuf* createStreamBuf( const std::string& streamName ) {
|
||||||
: 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 ) {
|
|
||||||
if( streamName == "stdout" ) return std::cout.rdbuf();
|
if( streamName == "stdout" ) return std::cout.rdbuf();
|
||||||
if( streamName == "stderr" ) return std::cerr.rdbuf();
|
if( streamName == "stderr" ) return std::cerr.rdbuf();
|
||||||
if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>;
|
if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>;
|
||||||
@ -64,34 +100,8 @@ namespace Catch {
|
|||||||
throw std::domain_error( "Unknown stream: " + streamName );
|
throw std::domain_error( "Unknown stream: " + streamName );
|
||||||
}
|
}
|
||||||
|
|
||||||
IGeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
void cleanUpContext() {
|
||||||
std::string testName = getResultCapture().getCurrentTestName();
|
delete currentContext;
|
||||||
|
currentContext = NULL;
|
||||||
std::map<std::string, IGeneratorsForTest*>::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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ namespace Catch {
|
|||||||
void cleanUp() {
|
void cleanUp() {
|
||||||
delete getTheRegistryHub();
|
delete getTheRegistryHub();
|
||||||
getTheRegistryHub() = NULL;
|
getTheRegistryHub() = NULL;
|
||||||
Context::cleanUp();
|
cleanUpContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
Loading…
Reference in New Issue
Block a user