Hamcrest-Qt  0.0.1
Hamcrest matchers for C++/Qt
 All Classes Namespaces Functions
isequal.h
1 #ifndef HAMCRESTQT_ISEQUAL_H
2 #define HAMCRESTQT_ISEQUAL_H
3 
4 #include <QSharedPointer>
5 
6 #include "basematcher.h"
7 #include "description.h"
8 #include "areequal_p.h"
9 
10 namespace HamcrestQt {
11 
16 template <typename T>
17 class IsEqual : public BaseMatcher<T>
18 {
19 public:
20  explicit IsEqual(const T &equalArg) : expectedValue(equalArg) {}
21 
22  virtual bool matches(const T &actualValue) const
23  {
24  return AreEqual(actualValue, expectedValue);
25  }
26 
27  virtual void describeTo(Description &description) const
28  {
29  description.appendValue(expectedValue);
30  }
31 
32 private:
33  T expectedValue;
34 };
35 
36 template <typename T>
37 QSharedPointer<Matcher<T> > equalTo(const T &operand)
38 {
39  return QSharedPointer<Matcher<T> >(new IsEqual<T>(operand));
40 }
41 
42 // template specialization for c-style string
43 inline QSharedPointer<Matcher<const char*> > equalTo(const char operand[])
44 {
45  return QSharedPointer<Matcher<const char*> >(new IsEqual<const char*>(operand));
46 }
47 
48 } // namespace HamcrestQt
49 
50 #endif // HAMCRESTQT_ISEQUAL_H
A description of a Matcher.
Definition: description.h:17
virtual bool matches(const T &actualValue) const
Evaluates the matcher for argument item.
Definition: isequal.h:22
Description & appendValue(const T &value)
Appends an arbitrary value to the description.
Definition: description.h:90
virtual void describeTo(Description &description) const
Generates a description of the object.
Definition: isequal.h:27
BaseClass for all Matcher implementations.
Definition: basematcher.h:17
Is the value equal to another value, as tested by the operator==() method?
Definition: isequal.h:17