Blame include/cppunit/Asserter.h

Packit Service e31359
#ifndef CPPUNIT_ASSERTER_H
Packit Service e31359
#define CPPUNIT_ASSERTER_H
Packit Service e31359
Packit Service e31359
#include <cppunit/AdditionalMessage.h>
Packit Service e31359
#include <cppunit/SourceLine.h>
Packit Service e31359
#include <string>
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_BEGIN
Packit Service e31359
Packit Service e31359
Packit Service e31359
class Message;
Packit Service e31359
Packit Service e31359
Packit Service e31359
/*! \brief A set of functions to help writing assertion macros.
Packit Service e31359
 * \ingroup CreatingNewAssertions
Packit Service e31359
 *
Packit Service e31359
 * Here is an example of assertion, a simplified version of the
Packit Service e31359
 * actual assertion implemented in examples/cppunittest/XmlUniformiser.h:
Packit Service e31359
 * \code
Packit Service e31359
 * #include <cppunit/SourceLine.h>
Packit Service e31359
 * #include <cppunit/TestAssert.h>
Packit Service e31359
 * 
Packit Service e31359
 * void 
Packit Service e31359
 * checkXmlEqual( std::string expectedXml,
Packit Service e31359
 *                std::string actualXml,
Packit Service e31359
 *                CppUnit::SourceLine sourceLine )
Packit Service e31359
 * {
Packit Service e31359
 *   std::string expected = XmlUniformiser( expectedXml ).stripped();
Packit Service e31359
 *   std::string actual = XmlUniformiser( actualXml ).stripped();
Packit Service e31359
 * 
Packit Service e31359
 *   if ( expected == actual )
Packit Service e31359
 *     return;
Packit Service e31359
 * 
Packit Service e31359
 *   ::CppUnit::Asserter::failNotEqual( expected,
Packit Service e31359
 *                                      actual,
Packit Service e31359
 *                                      sourceLine );
Packit Service e31359
 * }
Packit Service e31359
 * 
Packit Service e31359
 * /// Asserts that two XML strings are equivalent.
Packit Service e31359
 * #define CPPUNITTEST_ASSERT_XML_EQUAL( expected, actual ) \
Packit Service e31359
 *     checkXmlEqual( expected, actual,                     \
Packit Service e31359
 *                    CPPUNIT_SOURCELINE() )
Packit Service e31359
 * \endcode
Packit Service e31359
 */
Packit Service e31359
Packit Service e31359
#if defined __GNUC__
Packit Service e31359
#   define NORETURN __attribute__((noreturn))
Packit Service e31359
#else
Packit Service e31359
#   define NORETURN
Packit Service e31359
#endif
Packit Service e31359
Packit Service e31359
struct Asserter
Packit Service e31359
{
Packit Service e31359
  /*! \brief Throws a Exception with the specified message and location.
Packit Service e31359
   */
Packit Service e31359
  NORETURN static void CPPUNIT_API fail( const Message &message, 
Packit Service e31359
                                const SourceLine &sourceLine = SourceLine() );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws a Exception with the specified message and location.
Packit Service e31359
   * \deprecated Use fail( Message, SourceLine ) instead.
Packit Service e31359
   */
Packit Service e31359
  NORETURN static void CPPUNIT_API fail( std::string message, 
Packit Service e31359
                                const SourceLine &sourceLine = SourceLine() );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws a Exception with the specified message and location.
Packit Service e31359
   * \param shouldFail if \c true then the exception is thrown. Otherwise
Packit Service e31359
   *                   nothing happen.
Packit Service e31359
   * \param message Message explaining the assertion failiure.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failIf( bool shouldFail, 
Packit Service e31359
                                  const Message &message, 
Packit Service e31359
                                  const SourceLine &sourceLine = SourceLine() );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws a Exception with the specified message and location.
Packit Service e31359
   * \deprecated Use failIf( bool, Message, SourceLine ) instead.
Packit Service e31359
   * \param shouldFail if \c true then the exception is thrown. Otherwise
Packit Service e31359
   *                   nothing happen.
Packit Service e31359
   * \param message Message explaining the assertion failiure.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failIf( bool shouldFail, 
Packit Service e31359
                                  std::string message, 
Packit Service e31359
                                  const SourceLine &sourceLine = SourceLine() );
Packit Service e31359
Packit Service e31359
  /*! \brief Returns a expected value string for a message, case equal than
Packit Service e31359
   * Typically used to create 'not equal' message, or to check that a message
Packit Service e31359
   * contains the expected content when writing unit tests for your custom 
Packit Service e31359
   * assertions.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected: ".
Packit Service e31359
   * \deprecated Use makeExpectedEqual instead
Packit Service e31359
   * \see makeActual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpected( const std::string &expectedValue );
Packit Service e31359
  /*! \brief Returns a expected value string for a message, case equal than
Packit Service e31359
   * Typically used to create 'not equal' message, or to check that a message
Packit Service e31359
   * contains the expected content when writing unit tests for your custom 
Packit Service e31359
   * assertions.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected: ".
Packit Service e31359
   * \see makeActual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpectedEqual( const std::string &expectedValue );
Packit Service e31359
  /*! \brief Returns a expected value string for a message, case less than.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected less than: ".
Packit Service e31359
   * \see makeExpectedEqual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpectedLess( const std::string &expectedValue );
Packit Service e31359
  /*! \brief Returns a expected value string for a message, case less or equal than.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected: ".
Packit Service e31359
   * \see makeExpectedEqual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpectedLessEqual( const std::string &expectedValue );
Packit Service e31359
  /*! \brief Returns a expected value string for a message, case greater than.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected: ".
Packit Service e31359
   * \see makeExpectedEqual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpectedGreater( const std::string &expectedValue );
Packit Service e31359
  /*! \brief Returns a expected value string for a message, greater or equal than.
Packit Service e31359
   *
Packit Service e31359
   * \param expectedValue String that represents the expected value.
Packit Service e31359
   * \return \a expectedValue prefixed with "Expected: ".
Packit Service e31359
   * \see makeExpectedEqual().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeExpectedGreaterEqual( const std::string &expectedValue );
Packit Service e31359
Packit Service e31359
  /*! \brief Returns an actual value string for a message.
Packit Service e31359
   * Typically used to create 'not equal' message, or to check that a message
Packit Service e31359
   * contains the expected content when writing unit tests for your custom 
Packit Service e31359
   * assertions.
Packit Service e31359
   *
Packit Service e31359
   * \param actualValue String that represents the actual value.
Packit Service e31359
   * \return \a actualValue prefixed with "Actual  : ".
Packit Service e31359
   * \see makeExpected().
Packit Service e31359
   */
Packit Service e31359
  static std::string CPPUNIT_API makeActual( const std::string &actualValue );
Packit Service e31359
Packit Service e31359
  /*!
Packit Service e31359
   * \deprecated Use makeMessage instead
Packit Service e31359
   */ 
Packit Service e31359
  static Message CPPUNIT_API makeNotEqualMessage( const std::string &expectedValue,
Packit Service e31359
                                                  const std::string &actualValue,
Packit Service e31359
                                                  const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                                  const std::string &shortDescription = "equality assertion failed");
Packit Service e31359
Packit Service e31359
  static Message CPPUNIT_API makeMessage( const std::string &expectedValue,
Packit Service e31359
                                                  const std::string &actualValue,
Packit Service e31359
                                                  const std::string &shortDescription,
Packit Service e31359
                                                  const AdditionalMessage &additionalMessage = AdditionalMessage());
Packit Service e31359
Packit Service e31359
  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          what are the differences between the expected and actual value.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  NORETURN static void CPPUNIT_API failNotEqual( std::string expected, 
Packit Service e31359
                                        std::string actual, 
Packit Service e31359
                                        const SourceLine &sourceLine,
Packit Service e31359
                                        const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                        std::string shortDescription = "equality assertion failed" );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          what are the differences between the expected and actual value.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failNotLess( std::string expected, 
Packit Service e31359
                                        std::string actual, 
Packit Service e31359
                                        const SourceLine &sourceLine,
Packit Service e31359
                                        const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                        std::string shortDescription = "less assertion failed" );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          what are the differences between the expected and actual value.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failNotGreater( std::string expected, 
Packit Service e31359
                                        std::string actual, 
Packit Service e31359
                                        const SourceLine &sourceLine,
Packit Service e31359
                                        const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                        std::string shortDescription = "greater assertion failed" );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          what are the differences between the expected and actual value.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failNotLessEqual( std::string expected, 
Packit Service e31359
                                        std::string actual, 
Packit Service e31359
                                        const SourceLine &sourceLine,
Packit Service e31359
                                        const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                        std::string shortDescription = "less equal assertion failed" );
Packit Service e31359
Packit Service e31359
  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          what are the differences between the expected and actual value.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failNotGreaterEqual( std::string expected, 
Packit Service e31359
                                        std::string actual, 
Packit Service e31359
                                        const SourceLine &sourceLine,
Packit Service e31359
                                        const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                        std::string shortDescription = "greater equal assertion failed" );  /*! \brief Throws an Exception with the specified message and location.
Packit Service e31359
Packit Service e31359
   * \param shouldFail if \c true then the exception is thrown. Otherwise
Packit Service e31359
   *                   nothing happen.
Packit Service e31359
   * \param expected Text describing the expected value.
Packit Service e31359
   * \param actual Text describing the actual value.
Packit Service e31359
   * \param sourceLine Location of the assertion.
Packit Service e31359
   * \param additionalMessage Additional message. Usually used to report
Packit Service e31359
   *                          where the "difference" is located.
Packit Service e31359
   * \param shortDescription Short description for the failure message.
Packit Service e31359
   */
Packit Service e31359
  static void CPPUNIT_API failNotEqualIf( bool shouldFail,
Packit Service e31359
                                          std::string expected, 
Packit Service e31359
                                          std::string actual, 
Packit Service e31359
                                          const SourceLine &sourceLine,
Packit Service e31359
                                          const AdditionalMessage &additionalMessage = AdditionalMessage(),
Packit Service e31359
                                          std::string shortDescription = "equality assertion failed" );
Packit Service e31359
Packit Service e31359
};
Packit Service e31359
Packit Service e31359
Packit Service e31359
CPPUNIT_NS_END
Packit Service e31359
Packit Service e31359
Packit Service e31359
#endif  // CPPUNIT_ASSERTER_H