Blame include/cppunit/extensions/TestSuiteBuilderContext.h

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