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 
46 #if defined __GNUC__
47 # define NORETURN __attribute__((noreturn))
48 #else
49 # define NORETURN
50 #endif
51 
52 struct Asserter
53 {
56  NORETURN static void CPPUNIT_API fail( const Message &message,
57  const SourceLine &sourceLine = SourceLine() );
58 
62  NORETURN static void CPPUNIT_API fail( std::string message,
63  const SourceLine &sourceLine = SourceLine() );
64 
71  static void CPPUNIT_API failIf( bool shouldFail,
72  const Message &message,
73  const SourceLine &sourceLine = SourceLine() );
74 
82  static void CPPUNIT_API failIf( bool shouldFail,
83  std::string message,
84  const SourceLine &sourceLine = SourceLine() );
85 
96  static std::string CPPUNIT_API makeExpected( const std::string &expectedValue );
106  static std::string CPPUNIT_API makeExpectedEqual( const std::string &expectedValue );
113  static std::string CPPUNIT_API makeExpectedLess( const std::string &expectedValue );
120  static std::string CPPUNIT_API makeExpectedLessEqual( const std::string &expectedValue );
127  static std::string CPPUNIT_API makeExpectedGreater( const std::string &expectedValue );
134  static std::string CPPUNIT_API makeExpectedGreaterEqual( const std::string &expectedValue );
135 
145  static std::string CPPUNIT_API makeActual( const std::string &actualValue );
146 
150  static Message CPPUNIT_API makeNotEqualMessage( const std::string &expectedValue,
151  const std::string &actualValue,
152  const AdditionalMessage &additionalMessage = AdditionalMessage(),
153  const std::string &shortDescription = "equality assertion failed");
154 
155  static Message CPPUNIT_API makeMessage( const std::string &expectedValue,
156  const std::string &actualValue,
157  const std::string &shortDescription,
158  const AdditionalMessage &additionalMessage = AdditionalMessage());
159 
168  NORETURN static void CPPUNIT_API failNotEqual( std::string expected,
169  std::string actual,
170  const SourceLine &sourceLine,
171  const AdditionalMessage &additionalMessage = AdditionalMessage(),
172  std::string shortDescription = "equality assertion failed" );
173 
182  static void CPPUNIT_API failNotLess( std::string expected,
183  std::string actual,
184  const SourceLine &sourceLine,
185  const AdditionalMessage &additionalMessage = AdditionalMessage(),
186  std::string shortDescription = "less assertion failed" );
187 
196  static void CPPUNIT_API failNotGreater( std::string expected,
197  std::string actual,
198  const SourceLine &sourceLine,
199  const AdditionalMessage &additionalMessage = AdditionalMessage(),
200  std::string shortDescription = "greater assertion failed" );
201 
210  static void CPPUNIT_API failNotLessEqual( std::string expected,
211  std::string actual,
212  const SourceLine &sourceLine,
213  const AdditionalMessage &additionalMessage = AdditionalMessage(),
214  std::string shortDescription = "less equal assertion failed" );
215 
224  static void CPPUNIT_API failNotGreaterEqual( std::string expected,
225  std::string actual,
226  const SourceLine &sourceLine,
227  const AdditionalMessage &additionalMessage = AdditionalMessage(),
228  std::string shortDescription = "greater equal assertion failed" );
239  static void CPPUNIT_API failNotEqualIf( bool shouldFail,
240  std::string expected,
241  std::string actual,
242  const SourceLine &sourceLine,
243  const AdditionalMessage &additionalMessage = AdditionalMessage(),
244  std::string shortDescription = "equality assertion failed" );
245 
246 };
247 
248 
250 
251 
252 #endif // CPPUNIT_ASSERTER_H
Definition: Asserter.h:52
static void CPPUNIT_API failNotLessEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="less equal assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:157
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:27
static NORETURN void CPPUNIT_API fail(const Message &message, const SourceLine &sourceLine=SourceLine())
Throws a Exception with the specified message and location.
Definition: Asserter.cpp:19
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:81
static NORETURN 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:113
static void CPPUNIT_API failNotLess(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="less assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:128
static void CPPUNIT_API failNotGreater(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="greater assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:143
static std::string CPPUNIT_API makeExpectedGreater(const std::string &expectedValue)
Returns a expected value string for a message, case greater than.
Definition: Asserter.cpp:69
#define CPPUNIT_NS_END
Definition: Portability.h:106
#define CPPUNIT_NS_BEGIN
Definition: Portability.h:105
static void CPPUNIT_API failNotGreaterEqual(std::string expected, std::string actual, const SourceLine &sourceLine, const AdditionalMessage &additionalMessage=AdditionalMessage(), std::string shortDescription="greater equal assertion failed")
Throws an Exception with the specified message and location.
Definition: Asserter.cpp:171
static std::string CPPUNIT_API makeExpectedGreaterEqual(const std::string &expectedValue)
Returns a expected value string for a message, greater or equal than.
Definition: Asserter.cpp:75
static std::string CPPUNIT_API makeExpected(const std::string &expectedValue)
Returns a expected value string for a message, case equal than Typically used to create &#39;not equal&#39; m...
Definition: Asserter.cpp:45
Message associated to an Exception.A message is composed of two items:
Definition: Message.h:34
static Message CPPUNIT_API makeMessage(const std::string &expectedValue, const std::string &actualValue, const std::string &shortDescription, const AdditionalMessage &additionalMessage=AdditionalMessage())
Definition: Asserter.cpp:88
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:184
static std::string CPPUNIT_API makeExpectedEqual(const std::string &expectedValue)
Returns a expected value string for a message, case equal than Typically used to create &#39;not equal&#39; m...
Definition: Asserter.cpp:51
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:103
#define NORETURN
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:49
static std::string CPPUNIT_API makeExpectedLess(const std::string &expectedValue)
Returns a expected value string for a message, case less than.
Definition: Asserter.cpp:57
static std::string CPPUNIT_API makeExpectedLessEqual(const std::string &expectedValue)
Returns a expected value string for a message, case less or equal than.
Definition: Asserter.cpp:63
#define CPPUNIT_API
Definition: CppUnitApi.h:27

Send comments to:
CppUnit Developers