Blame include/cppunit/TestResult.h

Packit 8c9aa0
#ifndef CPPUNIT_TESTRESULT_H
Packit 8c9aa0
#define CPPUNIT_TESTRESULT_H
Packit 8c9aa0
Packit 8c9aa0
#include <cppunit/Portability.h>
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
#include <cppunit/SynchronizedObject.h>
Packit 8c9aa0
#include <deque>
Packit 8c9aa0
#include <string>
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_BEGIN
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
class Exception;
Packit 8c9aa0
class Functor;
Packit 8c9aa0
class Protector;
Packit 8c9aa0
class ProtectorChain;
Packit 8c9aa0
class Test;
Packit 8c9aa0
class TestFailure;
Packit 8c9aa0
class TestListener;
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
/*! \brief Manages TestListener.
Packit 8c9aa0
 * \ingroup TrackingTestExecution
Packit 8c9aa0
 *
Packit 8c9aa0
 * A single instance of this class is used when running the test. It is usually
Packit 8c9aa0
 * created by the test runner (TestRunner).
Packit 8c9aa0
 *
Packit 8c9aa0
 * This class shouldn't have to be inherited from. Use a TestListener
Packit 8c9aa0
 * or one of its subclasses to be informed of the ongoing tests.
Packit 8c9aa0
 * Use a Outputter to receive a test summary once it has finished
Packit 8c9aa0
 *
Packit 8c9aa0
 * TestResult supplies a template method 'setSynchronizationObject()'
Packit 8c9aa0
 * so that subclasses can provide mutual exclusion in the face of multiple
Packit 8c9aa0
 * threads.  This can be useful when tests execute in one thread and
Packit 8c9aa0
 * they fill a subclass of TestResult which effects change in another 
Packit 8c9aa0
 * thread.  To have mutual exclusion, override setSynchronizationObject()
Packit 8c9aa0
 * and make sure that you create an instance of ExclusiveZone at the 
Packit 8c9aa0
 * beginning of each method.
Packit 8c9aa0
 *
Packit 8c9aa0
 * \see Test, TestListener, TestResultCollector, Outputter.
Packit 8c9aa0
 */
Packit 8c9aa0
class CPPUNIT_API TestResult : protected SynchronizedObject
Packit 8c9aa0
{
Packit 8c9aa0
public:
Packit 8c9aa0
  /// Construct a TestResult
Packit 8c9aa0
  TestResult( SynchronizationObject *syncObject = 0 );
Packit 8c9aa0
Packit 8c9aa0
  /// Destroys a test result
Packit 8c9aa0
  virtual ~TestResult();
Packit 8c9aa0
Packit 8c9aa0
  virtual void addListener( TestListener *listener );
Packit 8c9aa0
Packit 8c9aa0
  virtual void removeListener( TestListener *listener );
Packit 8c9aa0
Packit 8c9aa0
  /// Resets the stop flag.
Packit 8c9aa0
  virtual void reset();
Packit 8c9aa0
  
Packit 8c9aa0
  /// Stop testing
Packit 8c9aa0
  virtual void stop();
Packit 8c9aa0
Packit 8c9aa0
  /// Returns whether testing should be stopped
Packit 8c9aa0
  virtual bool shouldStop() const;
Packit 8c9aa0
Packit 8c9aa0
  /// Informs TestListener that a test will be started.
Packit 8c9aa0
  virtual void startTest( Test *test );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Adds an error to the list of errors. 
Packit 8c9aa0
   *  The passed in exception
Packit 8c9aa0
   *  caused the error
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual void addError( Test *test, Exception *e );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Adds a failure to the list of failures. The passed in exception
Packit 8c9aa0
   * caused the failure.
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual void addFailure( Test *test, Exception *e );
Packit 8c9aa0
Packit 8c9aa0
  /// Informs TestListener that a test was completed.
Packit 8c9aa0
  virtual void endTest( Test *test );
Packit 8c9aa0
Packit 8c9aa0
  /// Informs TestListener that a test suite will be started.
Packit 8c9aa0
  virtual void startSuite( Test *test );
Packit 8c9aa0
Packit 8c9aa0
  /// Informs TestListener that a test suite was completed.
Packit 8c9aa0
  virtual void endSuite( Test *test );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Run the specified test.
Packit 8c9aa0
   * 
Packit 8c9aa0
   * Calls startTestRun(), test->run(this), and finally endTestRun().
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual void runTest( Test *test );
Packit 8c9aa0
Packit 8c9aa0
  /*! \brief Protects a call to the specified functor.
Packit 8c9aa0
   *
Packit 8c9aa0
   * See Protector to understand how protector works. A default protector is
Packit 8c9aa0
   * always present. It captures CppUnit::Exception, std::exception and
Packit 8c9aa0
   * any other exceptions, retrieving as much as possible information about
Packit 8c9aa0
   * the exception as possible.
Packit 8c9aa0
   *
Packit 8c9aa0
   * Additional Protector can be added to the chain to support other exception
Packit 8c9aa0
   * types using pushProtector() and popProtector().
Packit 8c9aa0
   *
Packit 8c9aa0
   * \param functor Functor to call (typically a call to setUp(), runTest() or
Packit 8c9aa0
   *                tearDown().
Packit 8c9aa0
   * \param test Test the functor is associated to (used for failure reporting).
Packit 8c9aa0
   * \param shortDescription Short description override for the failure message.
Packit 8c9aa0
   */
Packit 8c9aa0
  virtual bool protect( const Functor &functor,
Packit 8c9aa0
                        Test *test,
Packit 8c9aa0
                        const std::string &shortDescription = std::string("") );
Packit 8c9aa0
Packit 8c9aa0
  /// Adds the specified protector to the protector chain.
Packit 8c9aa0
  virtual void pushProtector( Protector *protector );
Packit 8c9aa0
Packit 8c9aa0
  /// Removes the last protector from the protector chain.
Packit 8c9aa0
  virtual void popProtector();
Packit 8c9aa0
Packit 8c9aa0
protected:
Packit 8c9aa0
  /*! \brief Called to add a failure to the list of failures.
Packit 8c9aa0
   */
Packit 8c9aa0
  void addFailure( const TestFailure &failure );
Packit 8c9aa0
Packit 8c9aa0
  virtual void startTestRun( Test *test );
Packit 8c9aa0
  virtual void endTestRun( Test *test );
Packit 8c9aa0
  
Packit 8c9aa0
protected:
Packit 8c9aa0
  typedef std::deque<TestListener *> TestListeners;
Packit 8c9aa0
  TestListeners m_listeners;
Packit 8c9aa0
  ProtectorChain *m_protectorChain;
Packit 8c9aa0
  bool m_stop;
Packit 8c9aa0
Packit 8c9aa0
private: 
Packit 8c9aa0
  TestResult( const TestResult &other );
Packit 8c9aa0
  TestResult &operator =( const TestResult &other );
Packit 8c9aa0
};
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
CPPUNIT_NS_END
Packit 8c9aa0
Packit 8c9aa0
Packit 8c9aa0
#if CPPUNIT_NEED_DLL_DECL
Packit 8c9aa0
#pragma warning( pop )
Packit 8c9aa0
#endif
Packit 8c9aa0
Packit 8c9aa0
#endif // CPPUNIT_TESTRESULT_H
Packit 8c9aa0
Packit 8c9aa0