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)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
|
|
|
|
2015-08-05 20:02:17 +02:00
|
|
|
#include "catch_run_context.hpp"
|
2012-05-10 09:17:06 +02:00
|
|
|
|
|
|
|
#include "catch_context.h"
|
2011-01-18 10:20:06 +01:00
|
|
|
#include "catch_stream.hpp"
|
2017-01-16 11:30:44 +01:00
|
|
|
#include "catch_common.h"
|
2010-12-31 23:54:35 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
namespace Catch {
|
2012-08-08 09:33:54 +02:00
|
|
|
|
|
|
|
class Context : public IMutableContext {
|
|
|
|
|
2015-07-01 08:33:27 +02:00
|
|
|
Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
|
2013-04-23 19:58:56 +02:00
|
|
|
Context( Context const& );
|
|
|
|
void operator=( Context const& );
|
2012-08-08 09:33:54 +02:00
|
|
|
|
2017-01-16 11:30:44 +01:00
|
|
|
public:
|
|
|
|
virtual ~Context() {
|
|
|
|
deleteAllValues( m_generatorsByTestName );
|
|
|
|
}
|
|
|
|
|
2012-08-08 09:33:54 +02:00
|
|
|
public: // IContext
|
2014-05-20 19:49:28 +02:00
|
|
|
virtual IResultCapture* getResultCapture() {
|
|
|
|
return m_resultCapture;
|
2012-08-08 09:33:54 +02:00
|
|
|
}
|
2014-05-20 19:49:28 +02:00
|
|
|
virtual IRunner* getRunner() {
|
|
|
|
return m_runner;
|
2012-08-08 09:33:54 +02:00
|
|
|
}
|
2013-04-23 19:58:56 +02:00
|
|
|
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
|
2012-08-08 09:33:54 +02:00
|
|
|
return getGeneratorsForCurrentTest()
|
|
|
|
.getGeneratorInfo( fileInfo, totalSize )
|
|
|
|
.getCurrentIndex();
|
|
|
|
}
|
|
|
|
virtual bool advanceGeneratorsForCurrentTest() {
|
|
|
|
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
|
|
|
return generators && generators->moveNext();
|
|
|
|
}
|
|
|
|
|
2013-05-28 19:51:53 +02:00
|
|
|
virtual Ptr<IConfig const> getConfig() const {
|
2012-08-08 09:33:54 +02:00
|
|
|
return m_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
public: // IMutableContext
|
|
|
|
virtual void setResultCapture( IResultCapture* resultCapture ) {
|
|
|
|
m_resultCapture = resultCapture;
|
|
|
|
}
|
|
|
|
virtual void setRunner( IRunner* runner ) {
|
|
|
|
m_runner = runner;
|
|
|
|
}
|
2013-05-28 19:51:53 +02:00
|
|
|
virtual void setConfig( Ptr<IConfig const> const& config ) {
|
2012-08-08 09:33:54 +02:00
|
|
|
m_config = config;
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-08-08 09:33:54 +02:00
|
|
|
friend IMutableContext& getCurrentMutableContext();
|
|
|
|
|
|
|
|
private:
|
|
|
|
IGeneratorsForTest* findGeneratorsForCurrentTest() {
|
2014-05-20 19:49:28 +02:00
|
|
|
std::string testName = getResultCapture()->getCurrentTestName();
|
2012-08-08 09:33:54 +02:00
|
|
|
|
|
|
|
std::map<std::string, IGeneratorsForTest*>::const_iterator it =
|
2015-03-04 08:08:53 +01:00
|
|
|
m_generatorsByTestName.find( testName );
|
2012-08-08 09:33:54 +02:00
|
|
|
return it != m_generatorsByTestName.end()
|
2013-07-23 09:15:34 +02:00
|
|
|
? it->second
|
2015-07-01 08:33:27 +02:00
|
|
|
: CATCH_NULL;
|
2012-08-08 09:33:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IGeneratorsForTest& getGeneratorsForCurrentTest() {
|
|
|
|
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
|
|
|
if( !generators ) {
|
2014-05-20 19:49:28 +02:00
|
|
|
std::string testName = getResultCapture()->getCurrentTestName();
|
2012-08-08 09:33:54 +02:00
|
|
|
generators = createGeneratorsForTest();
|
|
|
|
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
|
|
|
}
|
|
|
|
return *generators;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-10-23 16:35:07 +02:00
|
|
|
Ptr<IConfig const> m_config;
|
2012-08-08 09:33:54 +02:00
|
|
|
IRunner* m_runner;
|
|
|
|
IResultCapture* m_resultCapture;
|
|
|
|
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-05-22 09:55:19 +02:00
|
|
|
namespace {
|
2015-07-01 08:33:27 +02:00
|
|
|
Context* currentContext = CATCH_NULL;
|
2012-05-22 09:55:19 +02:00
|
|
|
}
|
|
|
|
IMutableContext& getCurrentMutableContext() {
|
2012-06-05 11:13:52 +02:00
|
|
|
if( !currentContext )
|
|
|
|
currentContext = new Context();
|
|
|
|
return *currentContext;
|
2012-05-22 09:55:19 +02:00
|
|
|
}
|
|
|
|
IContext& getCurrentContext() {
|
|
|
|
return getCurrentMutableContext();
|
|
|
|
}
|
2012-02-18 10:58:30 +01:00
|
|
|
|
2012-08-08 09:33:54 +02:00
|
|
|
void cleanUpContext() {
|
|
|
|
delete currentContext;
|
2015-07-01 08:33:27 +02:00
|
|
|
currentContext = CATCH_NULL;
|
2011-01-27 00:23:33 +01:00
|
|
|
}
|
2010-12-31 23:54:35 +01:00
|
|
|
}
|
2012-09-17 07:42:29 +02:00
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|