CppUnit project page FAQ

Asserter.h
Go to the documentation of this file.
1 #ifndef CPPUNIT_ASSERTER_H
2 #define CPPUNIT_ASSERTER_H
3 
5 #include <cppunit/SourceLine.h>
6 #include <string>
7 
9 
10 
11 class Message;
12 
13 
45 struct Asserter
46 {
49  static void CPPUNIT_API fail( const Message &message,
50  const SourceLine &sourceLine = SourceLine() );
51 
55  static void CPPUNIT_API fail( std::string message,
56  const SourceLine &sourceLine = SourceLine() );
57 
64  static void CPPUNIT_API failIf( bool shouldFail,
65  const Message &message,
66  const SourceLine &sourceLine = SourceLine() );
67 
75  static void CPPUNIT_API failIf( bool shouldFail,
76  std::string message,
77  const SourceLine &sourceLine = SourceLine() );
78 
88  static std::string CPPUNIT_API makeExpected( const std::string &expectedValue );
89 
99  static std::string CPPUNIT_API makeActual( const std::string &actualValue );
100 
101  static Message CPPUNIT_API makeNotEqualMessage( const std::string &expectedValue,
102  const std::string &actualValue,
103  const AdditionalMessage &additionalMessage = AdditionalMessage(),
104  const std::string &shortDescription = "equality assertion failed");
105 
114  static void CPPUNIT_API failNotEqual( std::string expected,
115  std::string actual,
116  const SourceLine &sourceLine,
117  const AdditionalMessage &additionalMessage = AdditionalMessage(),
118  std::string shortDescription = "equality assertion failed" );
119 
130  static void CPPUNIT_API failNotEqualIf( bool shouldFail,
131  std::string expected,
132  std::string actual,
133  const SourceLine &sourceLine,
134  const AdditionalMessage &additionalMessage = AdditionalMessage(),
135  std::string shortDescription = "equality assertion failed" );
136 
137 };
138 
139 
141 
142 
143 #endif // CPPUNIT_ASSERTER_H
A set of functions to help writing assertion macros.Here is an example of assertion, a simplified version of the actual assertion implemented in examples/cppunittest/XmlUniformiser.h:
Definition: Asserter.h:45
static void CPPUNIT_API failIf(bool shouldFail, const Message &message, const SourceLine &sourceLine=SourceLine())
Throws a Exception with the specified message and location.
Definition: Asserter.cpp:26
static void CPPUNIT_API fail(const Message &message, const SourceLine &sourceLine=SourceLine())
Throws a Exception with the specified message and location.
Definition: Asserter.cpp:18
An additional Message for assertions.Provides a implicit constructor that takes a single string...
Definition: AdditionalMessage.h:39
Represents a source line location.Used to capture the failure location in assertion.
Definition: SourceLine.h:30
static std::string CPPUNIT_API makeActual(const std::string &actualValue)
Returns an actual value string for a message. Typically used to create &#39;not equal&#39; message...
Definition: Asserter.cpp:52
static void CPPUNIT_API failNotEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="equality assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:74
#define CPPUNIT_NS_END
Definition: Portability.h:120
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:119
static std::string CPPUNIT_API makeExpected(const std::string &expectedValue)
Returns a expected value string for a message. Typically used to create &#39;not equal&#39; message...
Definition: Asserter.cpp:45
Message associated to an Exception.A message is composed of two items:
Definition: Message.h:38
static void CPPUNIT_API failNotEqualIf(bool shouldFail, std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="equality assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:89
static Message CPPUNIT_API makeNotEqualMessage(const std::string &expectedValue, const std::string &actualValue, const AdditionalMessage &additionalMessage=AdditionalMessage(), const std::string &shortDescription="equality assertion failed")
Definition: Asserter.cpp:59
#define CPPUNIT_API
Definition: CppUnitApi.h:27

Send comments to:
CppUnit Developers