1 #ifndef HAMCRESTQT_ALLOF_H
2 #define HAMCRESTQT_ALLOF_H
5 #include <QSharedPointer>
7 #include "diagnosingmatcher.h"
19 explicit AllOf(
const QList<QSharedPointer<
Matcher<T> > > &m) : matchers(m) {}
21 virtual bool matches(
const T &item,
Description &mismatch)
const
23 foreach (
const QSharedPointer<
Matcher<T> > &matcher, matchers) {
24 if (!matcher->matches(item)) {
26 matcher->describeMismatch(item, mismatch);
36 description.
appendList(QStringLiteral(
"("), QStringLiteral(
" and "), QStringLiteral(
")"),
37 matchers.begin(), matchers.end());
41 QList<QSharedPointer<Matcher<T> > > matchers;
51 QSharedPointer<Matcher<T> >
allOf(
const QList<QSharedPointer<
Matcher<T> > > &matchers)
53 return QSharedPointer<Matcher<T> >(
new AllOf<T>(matchers));
57 QSharedPointer<Matcher<T> >
allOf(
const QSharedPointer<Matcher<T> > &first,
58 const QSharedPointer<Matcher<T> > &second)
60 QList<QSharedPointer<Matcher<T> > > matchers;
61 matchers.append(first);
62 matchers.append(second);
63 return allOf(matchers);
67 QSharedPointer<Matcher<T> >
allOf(
const QSharedPointer<Matcher<T> > &first,
68 const QSharedPointer<Matcher<T> > &second,
69 const QSharedPointer<Matcher<T> > &third)
71 QList<QSharedPointer<Matcher<T> > > matchers;
72 matchers.append(first);
73 matchers.append(second);
74 matchers.append(third);
75 return allOf(matchers);
79 QSharedPointer<Matcher<T> >
allOf(
const QSharedPointer<Matcher<T> > &first,
80 const QSharedPointer<Matcher<T> > &second,
81 const QSharedPointer<Matcher<T> > &third,
82 const QSharedPointer<Matcher<T> > &fourth)
84 QList<QSharedPointer<Matcher<T> > > matchers;
85 matchers.append(first);
86 matchers.append(second);
87 matchers.append(third);
88 matchers.append(fourth);
89 return allOf(matchers);
93 QSharedPointer<Matcher<T> >
allOf(
const QSharedPointer<Matcher<T> > &first,
94 const QSharedPointer<Matcher<T> > &second,
95 const QSharedPointer<Matcher<T> > &third,
96 const QSharedPointer<Matcher<T> > &fourth,
97 const QSharedPointer<Matcher<T> > &fifth)
99 QList<QSharedPointer<Matcher<T> > > matchers;
100 matchers.append(first);
101 matchers.append(second);
102 matchers.append(third);
103 matchers.append(fourth);
104 matchers.append(fifth);
105 return allOf(matchers);
108 template <
typename T>
109 QSharedPointer<Matcher<T> >
allOf(
const QSharedPointer<Matcher<T> > &first,
110 const QSharedPointer<Matcher<T> > &second,
111 const QSharedPointer<Matcher<T> > &third,
112 const QSharedPointer<Matcher<T> > &fourth,
113 const QSharedPointer<Matcher<T> > &fifth,
114 const QSharedPointer<Matcher<T> > &sixth)
116 QList<QSharedPointer<Matcher<T> > > matchers;
117 matchers.append(first);
118 matchers.append(second);
119 matchers.append(third);
120 matchers.append(fourth);
121 matchers.append(fifth);
122 matchers.append(sixth);
123 return allOf(matchers);
128 #endif // HAMCRESTQT_ALLOF_H
A description of a Matcher.
Definition: description.h:17
A matcher over acceptable values.
Definition: matcher.h:21
QSharedPointer< Matcher< T > > allOf(const QList< QSharedPointer< Matcher< T > > > &matchers)
Creates a matcher that matches if the examined object matches ALL of the specified matchers...
Definition: allof.h:51
Description & appendList(const QString &start, const QString &separator, const QString &end, Iterator startIterator, Iterator endIterator)
Appends a list of SelfDescribing objects to the description.
Definition: description.h:54
Definition: diagnosingmatcher.h:9
Calculates the logical conjunction of multiple matchers.
Definition: allof.h:16
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: allof.h:34
virtual Description & appendText(const QString &text)=0
Appends some plain text to the description.
virtual Description & appendDescriptionOf(const SelfDescribing &value)=0
Appends the description of a SelfDescribing value to this description.