Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
is.h
1 #ifndef HAMCRESTQT_IS_H
2 #define HAMCRESTQT_IS_H
3 
4 #include <QSharedPointer>
5 
6 #include "basematcher.h"
7 #include "isequal.h"
8 
9 namespace HamcrestQt {
10 
18 template <typename T>
19 class Is : public BaseMatcher<T>
20 {
21 public:
22  explicit Is(const QSharedPointer<Matcher<T> > &m) : matcher(m) {}
23 
24  virtual bool matches(const T &item) const
25  {
26  return matcher->matches(item);
27  }
28 
29  virtual void describeTo(Description &description) const
30  {
31  description.appendText("is ").appendDescriptionOf(*matcher);
32  }
33 
34  virtual void describeMismatch(const T &item, Description &description) const
35  {
36  matcher->describeMismatch(item, description);
37  }
38 
39 private:
40  QSharedPointer<Matcher<T> > matcher;
41 };
42 
53 template <typename T>
54 QSharedPointer<Matcher<T> > is(const QSharedPointer<Matcher<T> > &matcher)
55 {
56  return QSharedPointer<Matcher<T> >(new Is<T>(matcher));
57 }
58 
59 template <typename T>
60 QSharedPointer<Matcher<T> > is(const T &operand)
61 {
62  return is(equalTo(operand));
63 }
64 
65 // template specialization for c-style string
66 inline QSharedPointer<Matcher<const char*> > is(const char *operand)
67 {
68  return QSharedPointer<Matcher<const char*> >(new Is<const char*>(equalTo(operand)));
69 }
70 
71 } // namespace HamcrestQt
72 
73 #endif // HAMCRESTQT_IS_H
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: is.h:29
A description of a Matcher.
Definition: description.h:17
A matcher over acceptable values.
Definition: matcher.h:21
virtual bool matches(const T &item) const
Evaluates the matcher for argument item.
Definition: is.h:24
Decorates another Matcher, retaining the behaviour but allowing tests to be slightly more expressive...
Definition: is.h:19
QSharedPointer< Matcher< T > > is(const QSharedPointer< Matcher< T > > &matcher)
Decorates another Matcher, retaining its behaviour, but allowing tests to be slightly more expressive...
Definition: is.h:54
BaseClass for all Matcher implementations.
Definition: basematcher.h:17
virtual void describeMismatch(const T &item, Description &description) const
Generate a description of why the matcher has not accepted the item.
Definition: is.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.