diff options
Diffstat (limited to 'include/cppunit')
| -rw-r--r-- | include/cppunit/extensions/HelperMacros.h | 11 | ||||
| -rw-r--r-- | include/cppunit/extensions/TestNamer.h | 7 | ||||
| -rw-r--r-- | include/cppunit/extensions/TestSuiteBuilderContext.h | 15 |
3 files changed, 33 insertions, 0 deletions
diff --git a/include/cppunit/extensions/HelperMacros.h b/include/cppunit/extensions/HelperMacros.h index 3dfab2d..4c30319 100644 --- a/include/cppunit/extensions/HelperMacros.h +++ b/include/cppunit/extensions/HelperMacros.h @@ -301,6 +301,17 @@ public: \ &TestFixtureType::testMethod, \ context.makeFixture() ) ) ) +#define CPPUNIT_TEST_PARAMETERIZED( testMethod, ... ) \ + for (auto& i : __VA_ARGS__) \ + { \ + TestFixtureType* fixture = context.makeFixture(); \ + CPPUNIT_TEST_SUITE_ADD_TEST( \ + ( new CPPUNIT_NS::TestCaller<TestFixtureType>( \ + context.getTestNameFor(#testMethod, i), \ + std::bind(&TestFixtureType::testMethod, fixture, i), \ + fixture))); \ + } + /*! \brief Add a test which fail if the specified exception is not caught. * * Example: diff --git a/include/cppunit/extensions/TestNamer.h b/include/cppunit/extensions/TestNamer.h index 3907569..0c8fb31 100644 --- a/include/cppunit/extensions/TestNamer.h +++ b/include/cppunit/extensions/TestNamer.h @@ -3,6 +3,7 @@ #include <cppunit/Portability.h> #include <string> +#include <cppunit/tools/StringHelper.h> #include <typeinfo> @@ -63,6 +64,12 @@ public: */ virtual std::string getTestNameFor( const std::string &testMethodName ) const; + template<typename E> + std::string getTestNameFor( const std::string& testMethodName, const E& val) const + { + return getTestNameFor(testMethodName) + " with parameter: " + CPPUNIT_NS::StringHelper::toString(val); + } + protected: std::string m_fixtureName; }; diff --git a/include/cppunit/extensions/TestSuiteBuilderContext.h b/include/cppunit/extensions/TestSuiteBuilderContext.h index b62eeb8..72bfa70 100644 --- a/include/cppunit/extensions/TestSuiteBuilderContext.h +++ b/include/cppunit/extensions/TestSuiteBuilderContext.h @@ -62,6 +62,21 @@ public: */ std::string getTestNameFor( const std::string &testMethodName ) const; + /*! \brief Returns the name of the test for the specified method with the corresponding parameter. + * + * \param testMethodName Name (including a parameter) of the method that implements a test. + * \return A string that is the concatenation of the test fixture name + * (returned by getFixtureName()), \a testMethodName, + * separated using '::' and the parameter. This provides a fairly unique name for a given + * test. The parameter must be convertable to std::string through operator<< + * or a specialization of CPPUNIT_NS::StringHelper::toString needs to exist. + */ + template<typename T> + std::string getTestNameFor( const std::string &testMethodName, const T& value ) const + { + return m_namer.getTestNameFor(testMethodName, value); + } + /*! \brief Adds property pair. * \param key PropertyKey string to add. * \param value PropertyValue string to add. |
