CppUnit - The Unit Testing Library

CppUnit project page | FAQ

TestSuiteBuilderContext.h
Go to the documentation of this file.
1#ifndef CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
2#define CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
3
4#include <cppunit/Portability.h>
5#include <map>
6#include <string>
7
8#if CPPUNIT_NEED_DLL_DECL
9#pragma warning( push )
10#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
11#endif
12
13
14 CPPUNIT_NS_BEGIN
15
16class TestSuite;
17class TestFixture;
18class TestFixtureFactory;
19class TestNamer;
20
29 class CPPUNIT_API TestSuiteBuilderContextBase
30{
31public:
37 TestSuiteBuilderContextBase( TestSuite &suite,
38 const TestNamer &namer,
39 TestFixtureFactory &factory );
40
41 virtual ~TestSuiteBuilderContextBase();
42
47 void addTest( Test *test );
48
53 std::string getFixtureName() const;
54
63 std::string getTestNameFor( const std::string &testMethodName ) const;
64
74 template<typename T>
75 std::string getTestNameFor( const std::string &testMethodName, const T& value ) const
76 {
77 return m_namer.getTestNameFor(testMethodName, value);
78 }
79
84 void addProperty( const std::string &key,
85 const std::string &value );
86
90 const std::string getStringProperty( const std::string &key ) const;
91
92protected:
93 TestFixture *makeTestFixture() const;
94
95 // Notes: we use a vector here instead of a map to work-around the
96 // shared std::map in dll bug in VC6.
97 // See http://www.dinkumware.com/vc_fixes.html for detail.
98 typedef std::pair<std::string,std::string> Property;
99 typedef std::vector<Property> Properties;
100
101 TestSuite &m_suite;
102 const TestNamer &m_namer;
103 TestFixtureFactory &m_factory;
104
105private:
106 Properties m_properties;
107};
108
109
114template<class Fixture>
115 class TestSuiteBuilderContext : public TestSuiteBuilderContextBase
116{
117public:
118 typedef Fixture FixtureType;
119
120 TestSuiteBuilderContext( TestSuiteBuilderContextBase &contextBase )
121 : TestSuiteBuilderContextBase( contextBase )
122 {
123 }
124
131 FixtureType *makeFixture() const
132 {
133 return CPPUNIT_STATIC_CAST( FixtureType *,
134 TestSuiteBuilderContextBase::makeTestFixture() );
135 }
136};
137
138
139 CPPUNIT_NS_END
140
141#if CPPUNIT_NEED_DLL_DECL
142#pragma warning( pop )
143#endif
144
145#endif // CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
146
CPPUNIT_API
#define CPPUNIT_API
Definition CppUnitApi.h:27
Portability.h
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition Portability.h:106
CPPUNIT_STATIC_CAST
#define CPPUNIT_STATIC_CAST(TargetType, pointer)
Definition Portability.h:87
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
TestFixtureFactory
Abstract TestFixture factory (Implementation).
Definition TestFixtureFactory.h:17
TestFixture
Wraps a test case with setUp and tearDown methods.
Definition TestFixture.h:84
Test
Base class for all test objects.
Definition Test.h:26
TestNamer
Names a test or a fixture suite.
Definition TestNamer.h:39
TestSuiteBuilderContextBase::m_suite
TestSuite & m_suite
Definition TestSuiteBuilderContext.h:101
TestSuiteBuilderContextBase::Property
std::pair< std::string, std::string > Property
Definition TestSuiteBuilderContext.h:98
TestSuiteBuilderContextBase::getTestNameFor
std::string getTestNameFor(const std::string &testMethodName, const T &value) const
Returns the name of the test for the specified method with the corresponding parameter.
Definition TestSuiteBuilderContext.h:75
TestSuiteBuilderContextBase::getTestNameFor
std::string getTestNameFor(const std::string &testMethodName) const
Returns the name of the test for the specified method.
Definition TestSuiteBuilderContext.cpp:41
TestSuiteBuilderContextBase::makeTestFixture
TestFixture * makeTestFixture() const
Definition TestSuiteBuilderContext.cpp:49
TestSuiteBuilderContextBase::TestSuiteBuilderContextBase
TestSuiteBuilderContextBase(TestSuite &suite, const TestNamer &namer, TestFixtureFactory &factory)
Constructs a new context.
Definition TestSuiteBuilderContext.cpp:9
TestSuiteBuilderContextBase::getFixtureName
std::string getFixtureName() const
Returns the fixture name.
Definition TestSuiteBuilderContext.cpp:34
TestSuiteBuilderContextBase::Properties
std::vector< Property > Properties
Definition TestSuiteBuilderContext.h:99
TestSuiteBuilderContextBase::addTest
void addTest(Test *test)
Adds a test to the fixture suite.
Definition TestSuiteBuilderContext.cpp:27
TestSuiteBuilderContextBase::m_namer
const TestNamer & m_namer
Definition TestSuiteBuilderContext.h:102
TestSuiteBuilderContextBase::m_properties
Properties m_properties
Definition TestSuiteBuilderContext.h:106
TestSuiteBuilderContextBase::m_factory
TestFixtureFactory & m_factory
Definition TestSuiteBuilderContext.h:103
TestSuiteBuilderContext::TestSuiteBuilderContext
TestSuiteBuilderContext(TestSuiteBuilderContextBase &contextBase)
Definition TestSuiteBuilderContext.h:120
TestSuiteBuilderContext::FixtureType
Fixture FixtureType
Definition TestSuiteBuilderContext.h:118
TestSuiteBuilderContext::makeFixture
FixtureType * makeFixture() const
Returns a new TestFixture instance.
Definition TestSuiteBuilderContext.h:131
TestSuite
A Composite of Tests.
Definition TestSuite.h:41

| Send comments to: CppUnit Developers