2010-12-31 17:54:35 -05:00
|
|
|
/*
|
|
|
|
* Created by Phil on 31/12/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
2011-01-07 05:22:24 -05:00
|
|
|
#include "catch_test_case_registry_impl.hpp"
|
2011-01-11 04:13:31 -05:00
|
|
|
#include "catch_runner_impl.hpp"
|
2011-01-28 05:18:23 -05:00
|
|
|
#include "catch_generators_impl.hpp"
|
2012-02-25 15:36:22 -05:00
|
|
|
#include "catch_console_colour_impl.hpp"
|
2012-05-10 03:17:06 -04:00
|
|
|
|
|
|
|
#include "catch_exception_translator_registry.hpp"
|
|
|
|
#include "catch_context.h"
|
|
|
|
#include "catch_reporter_registry.hpp"
|
2011-01-18 04:20:06 -05:00
|
|
|
#include "catch_stream.hpp"
|
2010-12-31 17:54:35 -05:00
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
namespace Catch {
|
|
|
|
|
2012-05-22 03:55:19 -04:00
|
|
|
namespace {
|
2012-06-05 05:13:52 -04:00
|
|
|
Context* currentContext = NULL;
|
2012-05-22 03:55:19 -04:00
|
|
|
}
|
|
|
|
IMutableContext& getCurrentMutableContext() {
|
2012-06-05 05:13:52 -04:00
|
|
|
if( !currentContext )
|
|
|
|
currentContext = new Context();
|
|
|
|
return *currentContext;
|
2012-05-22 03:55:19 -04:00
|
|
|
}
|
|
|
|
IContext& getCurrentContext() {
|
|
|
|
return getCurrentMutableContext();
|
|
|
|
}
|
2012-05-21 13:52:09 -04:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
Context::Context()
|
2011-01-07 05:01:40 -05:00
|
|
|
: m_reporterRegistry( new ReporterRegistry ),
|
2011-04-20 10:40:40 -04:00
|
|
|
m_testCaseRegistry( new TestRegistry ),
|
2012-06-05 15:50:47 -04:00
|
|
|
m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry ),
|
|
|
|
m_config( NULL )
|
2012-05-10 02:58:48 -04:00
|
|
|
{}
|
2011-01-11 04:13:31 -05:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
void Context::cleanUp() {
|
2012-06-05 05:13:52 -04:00
|
|
|
delete currentContext;
|
|
|
|
currentContext = NULL;
|
2012-02-18 04:58:30 -05:00
|
|
|
}
|
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
void Context::setRunner( IRunner* runner ) {
|
2012-05-21 13:52:09 -04:00
|
|
|
m_runner = runner;
|
2011-01-11 04:13:31 -05:00
|
|
|
}
|
2012-05-10 02:58:48 -04:00
|
|
|
|
|
|
|
void Context::setResultCapture( IResultCapture* resultCapture ) {
|
2012-05-21 13:52:09 -04:00
|
|
|
m_resultCapture = resultCapture;
|
2011-01-11 04:13:31 -05:00
|
|
|
}
|
2012-06-05 15:50:47 -04:00
|
|
|
|
|
|
|
const IConfig* Context::getConfig() const {
|
|
|
|
return m_config;
|
|
|
|
}
|
|
|
|
void Context::setConfig( const IConfig* config ) {
|
|
|
|
m_config = config;
|
|
|
|
}
|
2011-01-11 04:13:31 -05:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
IResultCapture& Context::getResultCapture() {
|
2012-05-21 13:52:09 -04:00
|
|
|
return *m_resultCapture;
|
2011-01-11 04:13:31 -05:00
|
|
|
}
|
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
IRunner& Context::getRunner() {
|
2012-05-21 13:52:09 -04:00
|
|
|
return *m_runner;
|
2011-01-11 04:13:31 -05:00
|
|
|
}
|
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
IReporterRegistry& Context::getReporterRegistry() {
|
2012-05-21 13:52:09 -04:00
|
|
|
return *m_reporterRegistry.get();
|
2010-12-31 17:54:35 -05:00
|
|
|
}
|
2011-01-07 05:01:40 -05:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
ITestCaseRegistry& Context::getTestCaseRegistry() {
|
2012-05-21 13:52:09 -04:00
|
|
|
return *m_testCaseRegistry.get();
|
2011-01-07 05:01:40 -05:00
|
|
|
}
|
2011-01-18 04:20:06 -05:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
IExceptionTranslatorRegistry& Context::getExceptionTranslatorRegistry() {
|
2012-05-21 13:52:09 -04:00
|
|
|
return *m_exceptionTranslatorRegistry.get();
|
2011-04-20 10:40:40 -04:00
|
|
|
}
|
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
std::streambuf* Context::createStreamBuf( const std::string& streamName ) {
|
2011-01-18 04:20:06 -05:00
|
|
|
if( streamName == "stdout" ) return std::cout.rdbuf();
|
|
|
|
if( streamName == "stderr" ) return std::cerr.rdbuf();
|
|
|
|
if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>;
|
|
|
|
|
|
|
|
throw std::domain_error( "Unknown stream: " + streamName );
|
|
|
|
}
|
2011-01-26 18:23:33 -05:00
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
2012-05-22 03:55:19 -04:00
|
|
|
std::string testName = getResultCapture().getCurrentTestName();
|
2011-01-26 18:23:33 -05:00
|
|
|
|
|
|
|
std::map<std::string, GeneratorsForTest*>::const_iterator it =
|
|
|
|
m_generatorsByTestName.find( testName );
|
|
|
|
return it != m_generatorsByTestName.end()
|
|
|
|
? it->second
|
|
|
|
: NULL;
|
|
|
|
}
|
2012-05-10 02:58:48 -04:00
|
|
|
|
|
|
|
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
2011-01-26 18:23:33 -05:00
|
|
|
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
2012-05-16 03:02:20 -04:00
|
|
|
if( !generators ) {
|
2012-05-22 03:55:19 -04:00
|
|
|
std::string testName = getResultCapture().getCurrentTestName();
|
2011-01-26 18:23:33 -05:00
|
|
|
generators = new GeneratorsForTest();
|
|
|
|
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
|
|
|
}
|
|
|
|
return *generators;
|
|
|
|
}
|
2011-01-18 04:20:06 -05:00
|
|
|
|
2012-05-16 03:02:20 -04:00
|
|
|
size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) {
|
2012-05-21 13:52:09 -04:00
|
|
|
return getGeneratorsForCurrentTest()
|
2011-01-26 18:23:33 -05:00
|
|
|
.getGeneratorInfo( fileInfo, totalSize )
|
|
|
|
.getCurrentIndex();
|
|
|
|
}
|
|
|
|
|
2012-05-10 02:58:48 -04:00
|
|
|
bool Context::advanceGeneratorsForCurrentTest() {
|
2012-05-21 13:52:09 -04:00
|
|
|
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
2011-01-26 18:23:33 -05:00
|
|
|
return generators && generators->moveNext();
|
|
|
|
}
|
2010-12-31 17:54:35 -05:00
|
|
|
}
|