2010-12-31 23:54:35 +01: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 11:22:24 +01:00
|
|
|
#include "catch_test_case_registry_impl.hpp"
|
2011-01-11 10:13:31 +01:00
|
|
|
#include "catch_runner_impl.hpp"
|
2011-01-28 11:18:23 +01:00
|
|
|
#include "catch_generators_impl.hpp"
|
2012-02-25 21:36:22 +01:00
|
|
|
#include "catch_console_colour_impl.hpp"
|
2012-05-10 09:17:06 +02:00
|
|
|
|
|
|
|
#include "catch_exception_translator_registry.hpp"
|
|
|
|
#include "catch_context.h"
|
|
|
|
#include "catch_reporter_registry.hpp"
|
2011-01-18 10:20:06 +01:00
|
|
|
#include "catch_stream.hpp"
|
2010-12-31 23:54:35 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
namespace Catch {
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
Context::Context()
|
2011-01-07 11:01:40 +01:00
|
|
|
: m_reporterRegistry( new ReporterRegistry ),
|
2011-04-20 16:40:40 +02:00
|
|
|
m_testCaseRegistry( new TestRegistry ),
|
|
|
|
m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry )
|
2012-05-10 08:58:48 +02:00
|
|
|
{}
|
2011-01-11 10:13:31 +01:00
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
Context& Context::me() {
|
|
|
|
Context*& hub = singleInstance();
|
2012-02-18 10:58:30 +01:00
|
|
|
if( !hub )
|
2012-05-10 08:58:48 +02:00
|
|
|
hub = new Context();
|
2012-02-18 10:58:30 +01:00
|
|
|
return *hub;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
void Context::cleanUp() {
|
|
|
|
Context*& hub = singleInstance();
|
2012-02-18 10:58:30 +01:00
|
|
|
delete hub;
|
|
|
|
hub = NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
Context*& Context::singleInstance() {
|
|
|
|
static Context* hub = NULL;
|
2011-01-07 11:01:40 +01:00
|
|
|
return hub;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
void Context::setRunner( IRunner* runner ) {
|
2011-01-11 10:13:31 +01:00
|
|
|
me().m_runner = runner;
|
|
|
|
}
|
2012-05-10 08:58:48 +02:00
|
|
|
|
|
|
|
void Context::setResultCapture( IResultCapture* resultCapture ) {
|
2011-01-11 10:13:31 +01:00
|
|
|
me().m_resultCapture = resultCapture;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
IResultCapture& Context::getResultCapture() {
|
2011-01-11 10:13:31 +01:00
|
|
|
return *me().m_resultCapture;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
IRunner& Context::getRunner() {
|
2011-01-11 10:13:31 +01:00
|
|
|
return *me().m_runner;
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
IReporterRegistry& Context::getReporterRegistry() {
|
2010-12-31 23:54:35 +01:00
|
|
|
return *me().m_reporterRegistry.get();
|
|
|
|
}
|
2011-01-07 11:01:40 +01:00
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
ITestCaseRegistry& Context::getTestCaseRegistry() {
|
2011-01-07 11:22:24 +01:00
|
|
|
return *me().m_testCaseRegistry.get();
|
2011-01-07 11:01:40 +01:00
|
|
|
}
|
2011-01-18 10:20:06 +01:00
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
IExceptionTranslatorRegistry& Context::getExceptionTranslatorRegistry() {
|
2011-04-20 16:40:40 +02:00
|
|
|
return *me().m_exceptionTranslatorRegistry.get();
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
std::streambuf* Context::createStreamBuf( const std::string& streamName ) {
|
2011-01-18 10:20:06 +01: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-27 00:23:33 +01:00
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
2011-01-27 00:23:33 +01:00
|
|
|
std::string testName = getResultCapture().getCurrentTestName();
|
|
|
|
|
|
|
|
std::map<std::string, GeneratorsForTest*>::const_iterator it =
|
|
|
|
m_generatorsByTestName.find( testName );
|
|
|
|
return it != m_generatorsByTestName.end()
|
|
|
|
? it->second
|
|
|
|
: NULL;
|
|
|
|
}
|
2012-05-10 08:58:48 +02:00
|
|
|
|
|
|
|
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
2011-01-27 00:23:33 +01:00
|
|
|
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
2012-05-16 09:02:20 +02:00
|
|
|
if( !generators ) {
|
2011-01-27 00:23:33 +01:00
|
|
|
std::string testName = getResultCapture().getCurrentTestName();
|
|
|
|
generators = new GeneratorsForTest();
|
|
|
|
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
|
|
|
}
|
|
|
|
return *generators;
|
|
|
|
}
|
2011-01-18 10:20:06 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) {
|
2011-01-27 00:23:33 +01:00
|
|
|
return me().getGeneratorsForCurrentTest()
|
|
|
|
.getGeneratorInfo( fileInfo, totalSize )
|
|
|
|
.getCurrentIndex();
|
|
|
|
}
|
|
|
|
|
2012-05-10 08:58:48 +02:00
|
|
|
bool Context::advanceGeneratorsForCurrentTest() {
|
2011-01-27 00:23:33 +01:00
|
|
|
GeneratorsForTest* generators = me().findGeneratorsForCurrentTest();
|
|
|
|
return generators && generators->moveNext();
|
|
|
|
}
|
2010-12-31 23:54:35 +01:00
|
|
|
}
|