Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhil Nash2012-08-07 08:18:48 +0100
committerPhil Nash2012-08-07 08:18:48 +0100
commit0477465f8d69ef87eff604b1bd2dfa24d74f5b70 (patch)
treefd3ed882d0a814fed99e93a86442547131639e6d
parent58a26da31e5af6aaca71183de2f88a5079a41e34 (diff)
downloadcatch3-0477465f8d69ef87eff604b1bd2dfa24d74f5b70.tar.gz
Refactored Impls
-rw-r--r--include/catch_runner.hpp2
-rw-r--r--include/internal/catch_context.h9
-rw-r--r--include/internal/catch_context_impl.hpp14
-rw-r--r--include/internal/catch_generators_impl.hpp30
-rw-r--r--include/internal/catch_impl.hpp3
-rw-r--r--include/internal/catch_interfaces_generators.h38
-rw-r--r--projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj2
7 files changed, 60 insertions, 38 deletions
diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 3c75ecad..4ae06f85 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -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"
diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h
index 0fb42dd2..8bb385bd 100644
--- a/include/internal/catch_context.h
+++ b/include/internal/catch_context.h
@@ -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;
};
}
diff --git a/include/internal/catch_context_impl.hpp b/include/internal/catch_context_impl.hpp
index 097ae1df..d3ecfcb1 100644
--- a/include/internal/catch_context_impl.hpp
+++ b/include/internal/catch_context_impl.hpp
@@ -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();
}
}
diff --git a/include/internal/catch_generators_impl.hpp b/include/internal/catch_generators_impl.hpp
index 4b6a9551..f97519fb 100644
--- a/include/internal/catch_generators_impl.hpp
+++ b/include/internal/catch_generators_impl.hpp
@@ -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;
};
-
-} // end namespace Catch
-#define INTERNAL_CATCH_LINESTR2( line ) #line
-#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
+ IGeneratorsForTest* createGeneratorsForTest()
+ {
+ return new GeneratorsForTest();
+ }
-#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
+} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
diff --git a/include/internal/catch_impl.hpp b/include/internal/catch_impl.hpp
index d0a1b252..0157c72e 100644
--- a/include/internal/catch_impl.hpp
+++ b/include/internal/catch_impl.hpp
@@ -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
diff --git a/include/internal/catch_interfaces_generators.h b/include/internal/catch_interfaces_generators.h
index 1265d181..ef651edc 100644
--- a/include/internal/catch_interfaces_generators.h
+++ b/include/internal/catch_interfaces_generators.h
@@ -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
diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
index 0e0726c1..db5421ac 100644
--- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
+++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj
@@ -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>";