Refactored Impls

This commit is contained in:
Phil Nash 2012-08-07 08:18:48 +01:00
parent 58a26da31e
commit 0477465f8d
7 changed files with 61 additions and 39 deletions

View File

@ -8,8 +8,6 @@
#ifndef TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
#define 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_commandline.hpp"
#include "internal/catch_list.hpp" #include "internal/catch_list.hpp"
#include "reporters/catch_reporter_basic.hpp" #include "reporters/catch_reporter_basic.hpp"

View File

@ -10,6 +10,7 @@
#include "catch_interfaces_reporter.h" #include "catch_interfaces_reporter.h"
#include "catch_interfaces_config.h" #include "catch_interfaces_config.h"
#include "catch_interfaces_generators.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -20,7 +21,7 @@ namespace Catch {
class TestCaseInfo; class TestCaseInfo;
struct IResultCapture; struct IResultCapture;
struct IRunner; struct IRunner;
class GeneratorsForTest; struct IGeneratorsForTest;
class StreamBufBase : public std::streambuf{}; class StreamBufBase : public std::streambuf{};
@ -70,14 +71,14 @@ namespace Catch {
friend IMutableContext& getCurrentMutableContext(); friend IMutableContext& getCurrentMutableContext();
private: private:
GeneratorsForTest* findGeneratorsForCurrentTest(); IGeneratorsForTest* findGeneratorsForCurrentTest();
GeneratorsForTest& getGeneratorsForCurrentTest(); IGeneratorsForTest& getGeneratorsForCurrentTest();
private: private:
IRunner* m_runner; IRunner* m_runner;
IResultCapture* m_resultCapture; IResultCapture* m_resultCapture;
const IConfig* m_config; const IConfig* m_config;
std::map<std::string, GeneratorsForTest*> m_generatorsByTestName; std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
}; };
} }

View File

@ -6,8 +6,6 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/ */
#include "catch_runner_impl.hpp" #include "catch_runner_impl.hpp"
#include "catch_generators_impl.hpp"
#include "catch_console_colour_impl.hpp"
#include "catch_context.h" #include "catch_context.h"
#include "catch_stream.hpp" #include "catch_stream.hpp"
@ -66,21 +64,21 @@ namespace Catch {
throw std::domain_error( "Unknown stream: " + streamName ); throw std::domain_error( "Unknown stream: " + streamName );
} }
GeneratorsForTest* Context::findGeneratorsForCurrentTest() { IGeneratorsForTest* Context::findGeneratorsForCurrentTest() {
std::string testName = getResultCapture().getCurrentTestName(); 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 ); m_generatorsByTestName.find( testName );
return it != m_generatorsByTestName.end() return it != m_generatorsByTestName.end()
? it->second ? it->second
: NULL; : NULL;
} }
GeneratorsForTest& Context::getGeneratorsForCurrentTest() { IGeneratorsForTest& Context::getGeneratorsForCurrentTest() {
GeneratorsForTest* generators = findGeneratorsForCurrentTest(); IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
if( !generators ) { if( !generators ) {
std::string testName = getResultCapture().getCurrentTestName(); std::string testName = getResultCapture().getCurrentTestName();
generators = new GeneratorsForTest(); generators = createGeneratorsForTest();
m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
} }
return *generators; return *generators;
@ -93,7 +91,7 @@ namespace Catch {
} }
bool Context::advanceGeneratorsForCurrentTest() { bool Context::advanceGeneratorsForCurrentTest() {
GeneratorsForTest* generators = findGeneratorsForCurrentTest(); IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
return generators && generators->moveNext(); return generators && generators->moveNext();
} }
} }

View File

@ -8,6 +8,8 @@
#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
#include "catch_interfaces_generators.h"
#include "catch_common.h" #include "catch_common.h"
#include <vector> #include <vector>
@ -16,7 +18,7 @@
namespace Catch { namespace Catch {
struct GeneratorInfo { struct GeneratorInfo : IGeneratorInfo {
GeneratorInfo( std::size_t size ) GeneratorInfo( std::size_t size )
: m_size( size ), : m_size( size ),
@ -41,17 +43,17 @@ namespace Catch {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
class GeneratorsForTest { class GeneratorsForTest : public IGeneratorsForTest {
public: public:
~GeneratorsForTest() { ~GeneratorsForTest() {
deleteAll( m_generatorsInOrder ); deleteAll( m_generatorsInOrder );
} }
GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) { IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
if( it == m_generatorsByName.end() ) { if( it == m_generatorsByName.end() ) {
GeneratorInfo* info = new GeneratorInfo( size ); IGeneratorInfo* info = new GeneratorInfo( size );
m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
m_generatorsInOrder.push_back( info ); m_generatorsInOrder.push_back( info );
return *info; return *info;
@ -60,8 +62,8 @@ namespace Catch {
} }
bool moveNext() { bool moveNext() {
std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
for(; it != itEnd; ++it ) { for(; it != itEnd; ++it ) {
if( (*it)->moveNext() ) if( (*it)->moveNext() )
return true; return true;
@ -70,15 +72,15 @@ namespace Catch {
} }
private: private:
std::map<std::string, GeneratorInfo*> m_generatorsByName; std::map<std::string, IGeneratorInfo*> m_generatorsByName;
std::vector<GeneratorInfo*> m_generatorsInOrder; std::vector<IGeneratorInfo*> m_generatorsInOrder;
}; };
IGeneratorsForTest* createGeneratorsForTest()
{
return new GeneratorsForTest();
}
} // end namespace Catch } // 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 #endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED

View File

@ -8,4 +8,7 @@
#include "catch_registry_hub.hpp" #include "catch_registry_hub.hpp"
#include "catch_notimplemented_exception.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 // !TBD... migrate all impl headers here

View File

@ -1,14 +1,32 @@
// /*
// catch_interfaces_generators.h * Created by Phil on 7/8/2012.
// CatchSelfTest * Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
// *
// Created by Phil Nash on 07/08/2012. * 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 #include <string>
#define CatchSelfTest_catch_interfaces_generators_h
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

View File

@ -90,6 +90,7 @@
4A6D0C67149B3E3D00DB3EAA /* catch_reporter_junit.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_junit.hpp; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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 */, 4A6D0C56149B3E3D00DB3EAA /* catch_interfaces_runner.h */,
4A6D0C57149B3E3D00DB3EAA /* catch_interfaces_testcase.h */, 4A6D0C57149B3E3D00DB3EAA /* catch_interfaces_testcase.h */,
4AFC661D157E96A7009D58CF /* catch_interfaces_config.h */, 4AFC661D157E96A7009D58CF /* catch_interfaces_config.h */,
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */,
); );
name = Interfaces; name = Interfaces;
sourceTree = "<group>"; sourceTree = "<group>";