CppUnit - The Unit Testing Library

CppUnit project page | FAQ

Asserter.h
Go to the documentation of this file.
1#ifndef CPPUNIT_ASSERTER_H
2#define CPPUNIT_ASSERTER_H
3
4#include <cppunit/AdditionalMessage.h>
5#include <cppunit/SourceLine.h>
6#include <string>
7
8 CPPUNIT_NS_BEGIN
9
10
11class Message;
12
13
45
46 struct Asserter
47{
50 [[noreturn]] static void CPPUNIT_API fail( const Message &message,
51 const SourceLine &sourceLine = SourceLine() );
52
56 [[noreturn]] static void CPPUNIT_API fail( std::string message,
57 const SourceLine &sourceLine = SourceLine() );
58
65 static void CPPUNIT_API failIf( bool shouldFail,
66 const Message &message,
67 const SourceLine &sourceLine = SourceLine() );
68
76 static void CPPUNIT_API failIf( bool shouldFail,
77 std::string message,
78 const SourceLine &sourceLine = SourceLine() );
79
90 static std::string CPPUNIT_API makeExpected( const std::string &expectedValue );
100 static std::string CPPUNIT_API makeExpectedEqual( const std::string &expectedValue );
107 static std::string CPPUNIT_API makeExpectedLess( const std::string &expectedValue );
114 static std::string CPPUNIT_API makeExpectedLessEqual( const std::string &expectedValue );
121 static std::string CPPUNIT_API makeExpectedGreater( const std::string &expectedValue );
128 static std::string CPPUNIT_API makeExpectedGreaterEqual( const std::string &expectedValue );
129
139 static std::string CPPUNIT_API makeActual( const std::string &actualValue );
140
144 static Message CPPUNIT_API makeNotEqualMessage( const std::string &expectedValue,
145 const std::string &actualValue,
146 const AdditionalMessage &additionalMessage = AdditionalMessage(),
147 const std::string &shortDescription = "equality assertion failed");
148
149 static Message CPPUNIT_API makeMessage( const std::string &expectedValue,
150 const std::string &actualValue,
151 const std::string &shortDescription,
152 const AdditionalMessage &additionalMessage = AdditionalMessage());
153
162 [[noreturn]] static void CPPUNIT_API failNotEqual( std::string expected,
163 std::string actual,
164 const SourceLine &sourceLine,
165 const AdditionalMessage &additionalMessage = AdditionalMessage(),
166 std::string shortDescription = "equality assertion failed" );
167
176 static void CPPUNIT_API failNotLess( std::string expected,
177 std::string actual,
178 const SourceLine &sourceLine,
179 const AdditionalMessage &additionalMessage = AdditionalMessage(),
180 std::string shortDescription = "less assertion failed" );
181
190 static void CPPUNIT_API failNotGreater( std::string expected,
191 std::string actual,
192 const SourceLine &sourceLine,
193 const AdditionalMessage &additionalMessage = AdditionalMessage(),
194 std::string shortDescription = "greater assertion failed" );
195
204 static void CPPUNIT_API failNotLessEqual( std::string expected,
205 std::string actual,
206 const SourceLine &sourceLine,
207 const AdditionalMessage &additionalMessage = AdditionalMessage(),
208 std::string shortDescription = "less equal assertion failed" );
209
218 static void CPPUNIT_API failNotGreaterEqual( std::string expected,
219 std::string actual,
220 const SourceLine &sourceLine,
221 const AdditionalMessage &additionalMessage = AdditionalMessage(),
222 std::string shortDescription = "greater equal assertion failed" );
233 static void CPPUNIT_API failNotEqualIf( bool shouldFail,
234 std::string expected,
235 std::string actual,
236 const SourceLine &sourceLine,
237 const AdditionalMessage &additionalMessage = AdditionalMessage(),
238 std::string shortDescription = "equality assertion failed" );
239
240};
241
242
243 CPPUNIT_NS_END
244
245
246#endif // CPPUNIT_ASSERTER_H
AdditionalMessage.h
CPPUNIT_API
#define CPPUNIT_API
Definition CppUnitApi.h:27
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition Portability.h:106
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
SourceLine.h
AdditionalMessage
An additional Message for assertions.
Definition AdditionalMessage.h:40
Message
Message associated to an Exception.A message is composed of two items:
Definition Message.h:35
SourceLine
Represents a source line location.
Definition SourceLine.h:31
Asserter
A set of functions to help writing assertion macros.
Definition Asserter.h:47
Asserter::failNotLess
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
Asserter::failNotGreaterEqual
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
Asserter::makeExpected
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 'not equal' m...
Definition Asserter.cpp:45
Asserter::fail
static void CPPUNIT_API fail(const Message &message, const SourceLine &sourceLine=SourceLine())
Throws a Exception with the specified message and location.
Definition Asserter.cpp:19
Asserter::failNotEqual
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:113
Asserter::makeMessage
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
Asserter::failNotEqualIf
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
Asserter::makeExpectedGreater
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
Asserter::failNotGreater
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
Asserter::makeExpectedLess
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
Asserter::makeExpectedGreaterEqual
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
Asserter::makeExpectedLessEqual
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
Asserter::failIf
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
Asserter::makeActual
static std::string CPPUNIT_API makeActual(const std::string &actualValue)
Returns an actual value string for a message. Typically used to create 'not equal' message,...
Definition Asserter.cpp:81
Asserter::makeExpectedEqual
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 'not equal' m...
Definition Asserter.cpp:51
Asserter::failNotLessEqual
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
Asserter::makeNotEqualMessage
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

| Send comments to: CppUnit Developers