Blame include/cppunit/extensions/TestSuiteBuilderContext.h

Packit Service e31359
#ifndef CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
Packit Service e31359
#define CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
Packit Service e31359
Packit Service e31359
#include <cppunit/Portability.h>
Packit Service e31359
#include <map>
Packit Service e31359
#include <string>
Packit Service e31359
Packit Service e31359
#if CPPUNIT_NEED_DLL_DECL
Packit Service e31359
#pragma warning( push )
Packit Service e31359
#pragma warning( disable: 4251 )  // X needs to have dll-interface to be used by clients of class Z
Packit Service e31359
#endif
Packit Service e31359
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_BEGIN
Packit Service e31359
Packit Service e31359
class TestSuite;
Packit Service e31359
class TestFixture;
Packit Service e31359
class TestFixtureFactory;
Packit Service e31359
class TestNamer;
Packit Service e31359
Packit Service e31359
/*! \brief Context used when creating test suite in HelperMacros.
Packit Service e31359
 *
Packit Service e31359
 * Base class for all context used when creating test suite. The
Packit Service e31359
 * actual context type during test suite creation is TestSuiteBuilderContext.
Packit Service e31359
 *
Packit Service e31359
 * \sa CPPUNIT_TEST_SUITE, CPPUNIT_TEST_SUITE_ADD_TEST, 
Packit Service e31359
 *     CPPUNIT_TEST_SUITE_ADD_CUSTOM_TESTS.
Packit Service e31359
 */
Packit Service e31359
class CPPUNIT_API TestSuiteBuilderContextBase
Packit Service e31359
{
Packit Service e31359
public:
Packit Service e31359
  /*! \brief Constructs a new context.
Packit Service e31359
   *
Packit Service e31359
   * You should not use this. The context is created in 
Packit Service e31359
   * CPPUNIT_TEST_SUITE().
Packit Service e31359
   */
Packit Service e31359
  TestSuiteBuilderContextBase( TestSuite &suite,
Packit Service e31359
                               const TestNamer &namer,
Packit Service e31359
                               TestFixtureFactory &factory );
Packit Service e31359
Packit Service e31359
  virtual ~TestSuiteBuilderContextBase();
Packit Service e31359
Packit Service e31359
  /*! \brief Adds a test to the fixture suite.
Packit Service e31359
   *
Packit Service e31359
   * \param test Test to add to the fixture suite. Must not be \c NULL.
Packit Service e31359
   */
Packit Service e31359
  void addTest( Test *test );
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the fixture name.
Packit Service e31359
   * \return Fixture name. It is the name used to name the fixture
Packit Service e31359
   *         suite.
Packit Service e31359
   */
Packit Service e31359
  std::string getFixtureName() const;
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the name of the test for the specified method.
Packit Service e31359
   *
Packit Service e31359
   * \param testMethodName Name of the method that implements a test.
Packit Service e31359
   * \return A string that is the concatenation of the test fixture name 
Packit Service e31359
   *         (returned by getFixtureName()) and\a testMethodName, 
Packit Service e31359
   *         separated using '::'. This provides a fairly unique name for a given
Packit Service e31359
   *         test.
Packit Service e31359
   */
Packit Service e31359
  std::string getTestNameFor( const std::string &testMethodName ) const;
Packit Service e31359
Packit Service e31359
  /*! \brief Returns the name of the test for the specified method with the corresponding parameter.
Packit Service e31359
   *
Packit Service e31359
   * \param testMethodName Name (including a parameter) of the method that implements a test.
Packit Service e31359
   * \return A string that is the concatenation of the test fixture name
Packit Service e31359
   *         (returned by getFixtureName()), \a testMethodName,
Packit Service e31359
   *         separated using '::' and the parameter. This provides a fairly unique name for a given
Packit Service e31359
   *         test. The parameter must be convertable to std::string through operator<<
Packit Service e31359
   *         or a specialization of CPPUNIT_NS::StringHelper::toString needs to exist.
Packit Service e31359
   */
Packit Service e31359
  template<typename T>
Packit Service e31359
  std::string getTestNameFor( const std::string &testMethodName, const T& value ) const
Packit Service e31359
  {
Packit Service e31359
      return m_namer.getTestNameFor(testMethodName, value);
Packit Service e31359
  }
Packit Service e31359
Packit Service e31359
  /*! \brief Adds property pair.
Packit Service e31359
   * \param key   PropertyKey string to add.
Packit Service e31359
   * \param value PropertyValue string to add.
Packit Service e31359
   */
Packit Service e31359
  void addProperty( const std::string &key, 
Packit Service e31359
                    const std::string &value );
Packit Service e31359
  
Packit Service e31359
  /*! \brief Returns property value assigned to param key.
Packit Service e31359
   * \param key PropertyKey string.
Packit Service e31359
   */
Packit Service e31359
  const std::string getStringProperty( const std::string &key ) const;
Packit Service e31359
Packit Service e31359
protected:
Packit Service e31359
  TestFixture *makeTestFixture() const;
Packit Service e31359
Packit Service e31359
  // Notes: we use a vector here instead of a map to work-around the
Packit Service e31359
  // shared std::map in dll bug in VC6.
Packit Service e31359
  // See http://www.dinkumware.com/vc_fixes.html for detail.
Packit Service e31359
  typedef std::pair<std::string,std::string> Property;
Packit Service e31359
  typedef std::vector<Property> Properties;
Packit Service e31359
Packit Service e31359
  TestSuite &m_suite;
Packit Service e31359
  const TestNamer &m_namer;
Packit Service e31359
  TestFixtureFactory &m_factory;
Packit Service e31359
Packit Service e31359
private:
Packit Service e31359
  Properties m_properties;
Packit Service e31359
};
Packit Service e31359
Packit Service e31359
Packit Service e31359
/*! \brief Type-sage context used when creating test suite in HelperMacros.
Packit Service e31359
 * 
Packit Service e31359
 * \sa TestSuiteBuilderContextBase.
Packit Service e31359
 */
Packit Service e31359
template<class Fixture>
Packit Service e31359
class TestSuiteBuilderContext : public TestSuiteBuilderContextBase
Packit Service e31359
{
Packit Service e31359
public:
Packit Service e31359
  typedef Fixture FixtureType;
Packit Service e31359
Packit Service e31359
  TestSuiteBuilderContext( TestSuiteBuilderContextBase &contextBase )
Packit Service e31359
      : TestSuiteBuilderContextBase( contextBase )
Packit Service e31359
  {
Packit Service e31359
  }
Packit Service e31359
Packit Service e31359
  /*! \brief Returns a new TestFixture instance.
Packit Service e31359
   * \return A new fixture instance. The fixture instance is returned by
Packit Service e31359
   *         the TestFixtureFactory passed on construction. The actual type 
Packit Service e31359
   *         is that of the fixture on which the static method suite() 
Packit Service e31359
   *         was called.
Packit Service e31359
   */
Packit Service e31359
  FixtureType *makeFixture() const
Packit Service e31359
  {
Packit Service e31359
    return CPPUNIT_STATIC_CAST( FixtureType *, 
Packit Service e31359
                                TestSuiteBuilderContextBase::makeTestFixture() );
Packit Service e31359
  }
Packit Service e31359
};
Packit Service e31359
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_END
Packit Service e31359
Packit Service e31359
#if CPPUNIT_NEED_DLL_DECL
Packit Service e31359
#pragma warning( pop )
Packit Service e31359
#endif
Packit Service e31359
Packit Service e31359
#endif // CPPUNIT_HELPER_TESTSUITEBUILDERCONTEXT_H
Packit Service e31359