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
16 class TestSuite;
17 class TestFixture;
18 class TestFixtureFactory;
19 class TestNamer;
20
29 class CPPUNIT_API TestSuiteBuilderContextBase
30{
31 public:
37 TestSuiteBuilderContextBase( TestSuite &suite,
38 const TestNamer &namer,
39 TestFixtureFactory &factory );
40
41 virtual ~TestSuiteBuilderContextBase();
42
43 TestSuiteBuilderContextBase(TestSuiteBuilderContextBase const &) = default;
44 TestSuiteBuilderContextBase(TestSuiteBuilderContextBase &&) = default;
45 TestSuiteBuilderContextBase & operator =(TestSuiteBuilderContextBase const &) = delete;
46 TestSuiteBuilderContextBase & operator =(TestSuiteBuilderContextBase &&) = delete;
47
52 void addTest( Test *test );
53
58 std::string getFixtureName() const;
59
68 std::string getTestNameFor( const std::string &testMethodName ) const;
69
79 template<typename T>
80 std::string getTestNameFor( const std::string &testMethodName, const T& value ) const
81 {
82 return m_namer.getTestNameFor(testMethodName, value);
83 }
84
89 void addProperty( const std::string &key,
90 const std::string &value );
91
95 const std::string getStringProperty( const std::string &key ) const;
96
97 protected:
98 TestFixture *makeTestFixture() const;
99
100 // Notes: we use a vector here instead of a map to work-around the
101 // shared std::map in dll bug in VC6.
102 // See http://www.dinkumware.com/vc_fixes.html for detail.
103 typedef std::pair<std::string,std::string> Property;
104 typedef std::vector<Property> Properties;
105
106 TestSuite &m_suite;
107 const TestNamer &m_namer;
108 TestFixtureFactory &m_factory;
109
110 private:
111 Properties m_properties;
112};
113
114
119 template<class Fixture>
120 class TestSuiteBuilderContext : public TestSuiteBuilderContextBase
121{
122 public:
123 typedef Fixture FixtureType;
124
125 TestSuiteBuilderContext( TestSuiteBuilderContextBase &contextBase )
126 : TestSuiteBuilderContextBase( contextBase )
127 {
128 }
129
136 FixtureType *makeFixture() const
137 {
138 return CPPUNIT_STATIC_CAST( FixtureType *,
139 TestSuiteBuilderContextBase::makeTestFixture() );
140 }
141};
142
143
144 CPPUNIT_NS_END
145
146#if CPPUNIT_NEED_DLL_DECL
147#pragma warning( pop )
148#endif
149
150#endif // CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
151
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
Context used when creating test suite in HelperMacros.
Definition: TestSuiteBuilderContext.h:30
TestSuiteBuilderContextBase::m_suite
TestSuite & m_suite
Definition: TestSuiteBuilderContext.h:106
TestSuiteBuilderContextBase::Property
std::pair< std::string, std::string > Property
Definition: TestSuiteBuilderContext.h:103
TestSuiteBuilderContextBase::TestSuiteBuilderContextBase
TestSuiteBuilderContextBase(TestSuiteBuilderContextBase const &)=default
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:80
TestSuiteBuilderContextBase::makeTestFixture
TestFixture * makeTestFixture() const
Definition: TestSuiteBuilderContext.cpp:49
TestSuiteBuilderContextBase::Properties
std::vector< Property > Properties
Definition: TestSuiteBuilderContext.h:104
TestSuiteBuilderContextBase::m_namer
const TestNamer & m_namer
Definition: TestSuiteBuilderContext.h:107
TestSuiteBuilderContextBase::m_properties
Properties m_properties
Definition: TestSuiteBuilderContext.h:111
TestSuiteBuilderContextBase::m_factory
TestFixtureFactory & m_factory
Definition: TestSuiteBuilderContext.h:108
TestSuiteBuilderContextBase::TestSuiteBuilderContextBase
TestSuiteBuilderContextBase(TestSuiteBuilderContextBase &&)=default
TestSuiteBuilderContext
Type-sage context used when creating test suite in HelperMacros.
Definition: TestSuiteBuilderContext.h:121
TestSuiteBuilderContext::TestSuiteBuilderContext
TestSuiteBuilderContext(TestSuiteBuilderContextBase &contextBase)
Definition: TestSuiteBuilderContext.h:125
TestSuiteBuilderContext::FixtureType
Fixture FixtureType
Definition: TestSuiteBuilderContext.h:123
TestSuiteBuilderContext::makeFixture
FixtureType * makeFixture() const
Returns a new TestFixture instance.
Definition: TestSuiteBuilderContext.h:136
TestSuite
A Composite of Tests.
Definition: TestSuite.h:41

| Send comments to: CppUnit Developers