1 #ifndef HAMCRESTQT_MATCHERASSERT_H
2 #define HAMCRESTQT_MATCHERASSERT_H
7 #include "stringdescription.h"
18 virtual void assertionError(
const QString &message) = 0;
23 listeners.append(listener);
27 static bool assertThat(
const QString &reason,
const T &actual,
const Matcher<T> &matcher,
const char *file,
int line)
38 notifyAssertionListener(description.
toString());
41 QTest::qFail(description.
toString().toLatin1(), file, line);
49 static bool assertThat(
const QString &reason,
const T &actual,
const QSharedPointer<Matcher<T> > &matcher,
const char *file,
int line)
51 return assertThat(reason, actual, *matcher, file, line);
55 static bool assertThat(
const T &actual,
const Matcher<T> &matcher,
const char *file,
int line)
57 return assertThat(QStringLiteral(
""), actual, matcher, file, line);
61 static bool assertThat(
const T &actual,
const QSharedPointer<Matcher<T> > &matcher,
const char *file,
int line)
63 return assertThat(QStringLiteral(
""), actual, *matcher, file, line);
66 static bool assertThat(
const QString &reason,
bool assertion,
const char *file,
int line)
70 notifyAssertionListener(reason);
73 QTest::qFail(reason.toLatin1(), file, line);
81 static void notifyAssertionListener(
const QString &message)
83 foreach (MatcherAssert::AssertionListener *listener, listeners) {
84 listener->assertionError(message);
88 static QList<MatcherAssert::AssertionListener*> listeners;
92 #define ASSERT_THAT(actual, matcher) \
94 if (!HamcrestQt::MatcherAssert::assertThat(actual, matcher, __FILE__, __LINE__))\
99 #define ASSERT_THAT_MSG(reason, actual, matcher) \
101 if (!HamcrestQt::MatcherAssert::assertThat(reason, actual, matcher, __FILE__, __LINE__))\
107 #endif // HAMCRESTQT_MATCHERASSERT_H
virtual QString toString() const
Returns the description as a string.
Definition: stringdescription.cpp:11
A matcher over acceptable values.
Definition: matcher.h:21
virtual Description & appendText(const QString &text)
Appends some plain text to the description.
Definition: basedescription.cpp:7
A Description that is stored as a string.
Definition: stringdescription.h:13
Definition: matcherassert.h:11
virtual bool matches(const T &item) const =0
Evaluates the matcher for argument item.
virtual void describeMismatch(const T &item, Description &mismatchDescription) const =0
Generate a description of why the matcher has not accepted the item.
virtual Description & appendText(const QString &text)=0
Appends some plain text to the description.
Definition: matcherassert.h:14
virtual Description & appendDescriptionOf(const SelfDescribing &value)=0
Appends the description of a SelfDescribing value to this description.