1
#ifndef CPPUNIT_MESSAGE_H
2
#define CPPUNIT_MESSAGE_H
4
#include <cppunit/Portability.h>
6
#if CPPUNIT_NEED_DLL_DECL
7
#pragma warning( push )
8
#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
11
#include <cppunit/portability/CppUnitDeque.h>
18
#if CPPUNIT_NEED_DLL_DECL
19
// template class CPPUNIT_API std::deque<std::string>;
22
/*! \brief Message associated to an Exception.
23
* \ingroup CreatingNewAssertions
24
* A message is composed of two items:
25
* - a short description (~20/30 characters)
26
* - a list of detail strings
28
* The short description is used to indicate how the detail strings should be
29
* interpreted. It usually indicates the failure types, such as
30
* "assertion failed", "forced failure", "unexpected exception caught",
31
* "equality assertion failed"... It should not contains new line character (\n).
33
* Detail strings are used to provide more information about the failure. It
34
* can contains the asserted expression, the expected and actual values in an
35
* equality assertion, some addional messages... Detail strings can contains
36
* new line characters (\n).
38
class CPPUNIT_API Message
43
// Ensure thread-safe copy by detaching the string.
44
Message( const Message &other );
46
explicit Message( const std::string &shortDescription );
48
Message( const std::string &shortDescription,
49
const std::string &detail1 );
51
Message( const std::string &shortDescription,
52
const std::string &detail1,
53
const std::string &detail2 );
55
Message( const std::string &shortDescription,
56
const std::string &detail1,
57
const std::string &detail2,
58
const std::string &detail3 );
60
Message &operator =( const Message &other );
62
/*! \brief Returns the short description.
63
* \return Short description.
65
const std::string &shortDescription() const;
67
/*! \brief Returns the number of detail string.
68
* \return Number of detail string.
70
int detailCount() const;
72
/*! \brief Returns the detail at the specified index.
73
* \param index Zero based index of the detail string to return.
74
* \returns Detail string at the specified index.
75
* \exception std::invalid_argument if \a index < 0 or index >= detailCount().
77
std::string detailAt( int index ) const;
79
/*! \brief Returns a string that represents a list of the detail strings.
83
* Message message( "not equal", "Expected: 3", "Actual: 7" );
84
* std::string details = message.details();
85
* // details contains:
86
* // "- Expected: 3\n- Actual: 7\n" \endcode
88
* \return A string that is a concatenation of all the detail strings. Each detail
89
* string is prefixed with '- ' and suffixed with '\n' before being
90
* concatenated to the other.
92
std::string details() const;
94
/*! \brief Removes all detail strings.
98
/*! \brief Adds a single detail string.
99
* \param detail Detail string to add.
101
void addDetail( const std::string &detail );
103
/*! \brief Adds two detail strings.
104
* \param detail1 Detail string to add.
105
* \param detail2 Detail string to add.
107
void addDetail( const std::string &detail1,
108
const std::string &detail2 );
110
/*! \brief Adds three detail strings.
111
* \param detail1 Detail string to add.
112
* \param detail2 Detail string to add.
113
* \param detail3 Detail string to add.
115
void addDetail( const std::string &detail1,
116
const std::string &detail2,
117
const std::string &detail3 );
119
/*! \brief Adds the detail strings of the specified message.
120
* \param message All the detail strings of this message are added to this one.
122
void addDetail( const Message &message );
124
/*! \brief Sets the short description.
125
* \param shortDescription New short description.
127
void setShortDescription( const std::string &shortDescription );
129
/*! \brief Tests if a message is identical to another one.
130
* \param other Message this message is compared to.
131
* \return \c true if the two message are identical, \c false otherwise.
133
bool operator ==( const Message &other ) const;
135
/*! \brief Tests if a message is different from another one.
136
* \param other Message this message is compared to.
137
* \return \c true if the two message are not identical, \c false otherwise.
139
bool operator !=( const Message &other ) const;
142
std::string m_shortDescription;
144
typedef CppUnitDeque<std::string> Details;
151
#if CPPUNIT_NEED_DLL_DECL
152
#pragma warning( pop )
156
#endif // CPPUNIT_MESSAGE_H