mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Refactored Impls
This commit is contained in:
parent
58a26da31e
commit
0477465f8d
@ -8,8 +8,6 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
||||
|
||||
#include "internal/catch_context_impl.hpp"
|
||||
|
||||
#include "internal/catch_commandline.hpp"
|
||||
#include "internal/catch_list.hpp"
|
||||
#include "reporters/catch_reporter_basic.hpp"
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "catch_interfaces_reporter.h"
|
||||
#include "catch_interfaces_config.h"
|
||||
#include "catch_interfaces_generators.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@ -20,7 +21,7 @@ namespace Catch {
|
||||
class TestCaseInfo;
|
||||
struct IResultCapture;
|
||||
struct IRunner;
|
||||
class GeneratorsForTest;
|
||||
struct IGeneratorsForTest;
|
||||
|
||||
class StreamBufBase : public std::streambuf{};
|
||||
|
||||
@ -70,14 +71,14 @@ namespace Catch {
|
||||
friend IMutableContext& getCurrentMutableContext();
|
||||
|
||||
private:
|
||||
GeneratorsForTest* findGeneratorsForCurrentTest();
|
||||
GeneratorsForTest& getGeneratorsForCurrentTest();
|
||||
IGeneratorsForTest* findGeneratorsForCurrentTest();
|
||||
IGeneratorsForTest& getGeneratorsForCurrentTest();
|
||||
|
||||
private:
|
||||
IRunner* m_runner;
|
||||
IResultCapture* m_resultCapture;
|
||||
const IConfig* m_config;
|
||||
std::map<std::string, GeneratorsForTest*> m_generatorsByTestName;
|
||||
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,6 @@
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include "catch_runner_impl.hpp"
|
||||
#include "catch_generators_impl.hpp"
|
||||
#include "catch_console_colour_impl.hpp"
|
||||
|
||||
#include "catch_context.h"
|
||||
#include "catch_stream.hpp"
|
||||
@ -66,21 +64,21 @@ namespace Catch {
|
||||
throw std::domain_error( "Unknown stream: " + streamName );
|
||||
}
|
||||
|
||||
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
||||
IGeneratorsForTest* Context::findGeneratorsForCurrentTest() {
|
||||
std::string testName = getResultCapture().getCurrentTestName();
|
||||
|
||||
std::map<std::string, GeneratorsForTest*>::const_iterator it =
|
||||
std::map<std::string, IGeneratorsForTest*>::const_iterator it =
|
||||
m_generatorsByTestName.find( testName );
|
||||
return it != m_generatorsByTestName.end()
|
||||
? it->second
|
||||
: NULL;
|
||||
}
|
||||
|
||||
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
||||
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||
IGeneratorsForTest& Context::getGeneratorsForCurrentTest() {
|
||||
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||
if( !generators ) {
|
||||
std::string testName = getResultCapture().getCurrentTestName();
|
||||
generators = new GeneratorsForTest();
|
||||
generators = createGeneratorsForTest();
|
||||
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
||||
}
|
||||
return *generators;
|
||||
@ -93,7 +91,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
bool Context::advanceGeneratorsForCurrentTest() {
|
||||
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
||||
return generators && generators->moveNext();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
||||
|
||||
#include "catch_interfaces_generators.h"
|
||||
|
||||
#include "catch_common.h"
|
||||
|
||||
#include <vector>
|
||||
@ -16,7 +18,7 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct GeneratorInfo {
|
||||
struct GeneratorInfo : IGeneratorInfo {
|
||||
|
||||
GeneratorInfo( std::size_t size )
|
||||
: m_size( size ),
|
||||
@ -41,17 +43,17 @@ namespace Catch {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class GeneratorsForTest {
|
||||
class GeneratorsForTest : public IGeneratorsForTest {
|
||||
|
||||
public:
|
||||
~GeneratorsForTest() {
|
||||
deleteAll( m_generatorsInOrder );
|
||||
}
|
||||
|
||||
GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
|
||||
std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
|
||||
IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
|
||||
std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
|
||||
if( it == m_generatorsByName.end() ) {
|
||||
GeneratorInfo* info = new GeneratorInfo( size );
|
||||
IGeneratorInfo* info = new GeneratorInfo( size );
|
||||
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
|
||||
m_generatorsInOrder.push_back( info );
|
||||
return *info;
|
||||
@ -60,8 +62,8 @@ namespace Catch {
|
||||
}
|
||||
|
||||
bool moveNext() {
|
||||
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
|
||||
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
|
||||
std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
|
||||
std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( (*it)->moveNext() )
|
||||
return true;
|
||||
@ -70,15 +72,15 @@ namespace Catch {
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, GeneratorInfo*> m_generatorsByName;
|
||||
std::vector<GeneratorInfo*> m_generatorsInOrder;
|
||||
std::map<std::string, IGeneratorInfo*> m_generatorsByName;
|
||||
std::vector<IGeneratorInfo*> m_generatorsInOrder;
|
||||
};
|
||||
|
||||
|
||||
IGeneratorsForTest* createGeneratorsForTest()
|
||||
{
|
||||
return new GeneratorsForTest();
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#define INTERNAL_CATCH_LINESTR2( line ) #line
|
||||
#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
|
||||
|
||||
#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
||||
|
@ -8,4 +8,7 @@
|
||||
|
||||
#include "catch_registry_hub.hpp"
|
||||
#include "catch_notimplemented_exception.hpp"
|
||||
#include "catch_context_impl.hpp"
|
||||
#include "catch_console_colour_impl.hpp"
|
||||
#include "catch_generators_impl.hpp"
|
||||
// !TBD... migrate all impl headers here
|
||||
|
@ -1,14 +1,32 @@
|
||||
//
|
||||
// catch_interfaces_generators.h
|
||||
// CatchSelfTest
|
||||
//
|
||||
// Created by Phil Nash on 07/08/2012.
|
||||
//
|
||||
//
|
||||
/*
|
||||
* Created by Phil on 7/8/2012.
|
||||
* Copyright 2011 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)
|
||||
*/
|
||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
||||
|
||||
#ifndef CatchSelfTest_catch_interfaces_generators_h
|
||||
#define CatchSelfTest_catch_interfaces_generators_h
|
||||
#include <string>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct IGeneratorInfo {
|
||||
virtual ~IGeneratorInfo(){}
|
||||
virtual bool moveNext() = 0;
|
||||
virtual std::size_t getCurrentIndex() const = 0;
|
||||
};
|
||||
|
||||
struct IGeneratorsForTest {
|
||||
virtual ~IGeneratorsForTest() {}
|
||||
|
||||
#endif
|
||||
virtual IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) = 0;
|
||||
virtual bool moveNext() = 0;
|
||||
};
|
||||
|
||||
IGeneratorsForTest* createGeneratorsForTest();
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
||||
|
@ -90,6 +90,7 @@
|
||||
4A6D0C67149B3E3D00DB3EAA /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_junit.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_xml.hpp; sourceTree = "<group>"; };
|
||||
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = "<group>"; };
|
||||
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_generators.h; sourceTree = "<group>"; };
|
||||
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tostring.hpp; sourceTree = "<group>"; };
|
||||
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo_builder.hpp; sourceTree = "<group>"; };
|
||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour_impl.hpp; sourceTree = "<group>"; };
|
||||
@ -277,6 +278,7 @@
|
||||
4A6D0C56149B3E3D00DB3EAA /* catch_interfaces_runner.h */,
|
||||
4A6D0C57149B3E3D00DB3EAA /* catch_interfaces_testcase.h */,
|
||||
4AFC661D157E96A7009D58CF /* catch_interfaces_config.h */,
|
||||
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */,
|
||||
);
|
||||
name = Interfaces;
|
||||
sourceTree = "<group>";
|
||||
|
Loading…
Reference in New Issue
Block a user