CppUnit - The Unit Testing Library

CppUnit project page | FAQ

Message Class Reference
Creating custom assertions

Message associated to an Exception.A message is composed of two items: More...

`#include <Message.h>`

Inheritance diagram for Message:
[legend]

## Public Member Functions
| Message ()
| Message (const Message &other)
| Message (const std::string &shortDescription)
| Message (const std::string &shortDescription, const std::string &detail1)
| Message (const std::string &shortDescription, const std::string &detail1, const std::string &detail2)
| Message (const std::string &shortDescription, const std::string &detail1, const std::string &detail2, const std::string &detail3)
virtual | ~Message ()
Message & | operator= (const Message &other)
const std::string & | shortDescription () const
| Returns the short description.
int | detailCount () const
| Returns the number of detail string.
std::string | detailAt (int index) const
| Returns the detail at the specified index.
std::string | details () const
| Returns a string that represents a list of the detail strings.
void | clearDetails ()
| Removes all detail strings.
void | addDetail (const std::string &detail)
| Adds a single detail string.
void | addDetail (const std::string &detail1, const std::string &detail2)
| Adds two detail strings.
void | addDetail (const std::string &detail1, const std::string &detail2, const std::string &detail3)
| Adds three detail strings.
void | addDetail (const Message &message)
| Adds the detail strings of the specified message.
void | setShortDescription (const std::string &shortDescription)
| Sets the short description.
bool | operator== (const Message &other) const
| Tests if a message is identical to another one.
bool | operator!= (const Message &other) const
| Tests if a message is different from another one.

## Private Types
typedef std::deque< std::string > | Details

## Private Attributes
std::string | m_shortDescription
Details | m_details

## Detailed Description

Message associated to an Exception.

A message is composed of two items:

- a short description (~20/30 characters)
- a list of detail strings

The short description is used to indicate how the detail strings should be interpreted. It usually indicates the failure types, such as "assertion failed", "forced failure", "unexpected exception caught", "equality assertion failed"... It should not contains new line character (
).

Detail strings are used to provide more information about the failure. It can contains the asserted expression, the expected and actual values in an equality assertion, some addional messages... Detail strings can contains new line characters (
).

## Member Typedef Documentation

## ◆ Details

typedef std::deque<std::string> Message::Details
| private

## Constructor & Destructor Documentation

## ◆ Message() [1/6]

Message::Message | ( |  | ) |
| inline

## ◆ Message() [2/6]

CPPUNIT_NS_BEGIN Message::Message | ( | const Message & | other | ) |

## ◆ Message() [3/6]

Message::Message | ( | const std::string & | shortDescription | ) |
| explicit

## ◆ Message() [4/6]

Message::Message | ( | const std::string & | shortDescription,
|  | const std::string & | detail1 )

## ◆ Message() [5/6]

Message::Message | ( | const std::string & | shortDescription,
|  | const std::string & | detail1,
|  | const std::string & | detail2 )

## ◆ Message() [6/6]

Message::Message | ( | const std::string & | shortDescription,
|  | const std::string & | detail1,
|  | const std::string & | detail2,
|  | const std::string & | detail3 )

## ◆ ~Message()

Message::~Message | ( |  | ) |
| virtual

## Member Function Documentation

## ◆ addDetail() [1/4]

void Message::addDetail | ( | const Message & | message | ) |

Adds the detail strings of the specified message.

Parameters

  message | All the detail strings of this message are added to this one.

## ◆ addDetail() [2/4]

void Message::addDetail | ( | const std::string & | detail | ) |

Adds a single detail string.

Parameters

  detail | Detail string to add.

## ◆ addDetail() [3/4]

void Message::addDetail | ( | const std::string & | detail1,
|  | const std::string & | detail2 )

Adds two detail strings.

Parameters

  detail1 | Detail string to add.
  detail2 | Detail string to add.

## ◆ addDetail() [4/4]

void Message::addDetail | ( | const std::string & | detail1,
|  | const std::string & | detail2,
|  | const std::string & | detail3 )

Adds three detail strings.

Parameters

  detail1 | Detail string to add.
  detail2 | Detail string to add.
  detail3 | Detail string to add.

## ◆ clearDetails()

void Message::clearDetails | ( |  | ) |

Removes all detail strings.

## ◆ detailAt()

std::string Message::detailAt | ( | int | index | ) | const

Returns the detail at the specified index.

Parameters

  index | Zero based index of the detail string to return.

Returns
  Detail string at the specified index.

Exceptions

  std::invalid_argument | if index < 0 or index >= detailCount().

## ◆ detailCount()

int Message::detailCount | ( |  | ) | const

Returns the number of detail string.

Returns
  Number of detail string.

## ◆ details()

std::string Message::details | ( |  | ) | const

Returns a string that represents a list of the detail strings.

Example:

Message message( "not equal", "Expected: 3", "Actual: 7" );
std::string details = message.details();
// details contains:
// "- Expected: 3\n- Actual: 7\n"
Message::Message
Message()
Definition Message.h:37
Message::details
std::string details() const
Returns a string that represents a list of the detail strings.
Definition Message.cpp:96

Returns
  A string that is a concatenation of all the detail strings. Each detail string is prefixed with '- ' and suffixed with '
  ' before being concatenated to the other.

## ◆ operator!=()

bool Message::operator!= | ( | const Message & | other | ) | const

Tests if a message is different from another one.

Parameters

  other | Message this message is compared to.

Returns
  `true` if the two message are not identical, `false` otherwise.

## ◆ operator=()

Message & Message::operator= | ( | const Message & | other | ) |

## ◆ operator==()

bool Message::operator== | ( | const Message & | other | ) | const

Tests if a message is identical to another one.

Parameters

  other | Message this message is compared to.

Returns
  `true` if the two message are identical, `false` otherwise.

## ◆ setShortDescription()

void Message::setShortDescription | ( | const std::string & | shortDescription | ) |

Sets the short description.

Parameters

  shortDescription | New short description.

## ◆ shortDescription()

const std::string & Message::shortDescription | ( |  | ) | const

Returns the short description.

Returns
  Short description.

## Member Data Documentation

## ◆ m_details

Details Message::m_details
| private

## ◆ m_shortDescription

std::string Message::m_shortDescription
| private

The documentation for this class was generated from the following files:

- Message.h
- Message.cpp

| Send comments to: CppUnit Developers