diff options
author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-03-15 21:23:04 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2010-03-15 21:23:04 +0000 |
commit | a862f1de30ed1ef259bcec61c5939200b29c765c (patch) | |
tree | d88a08ccf38d37809112b99742bd38b325eb691e /include | |
parent | 34b034c21ef4af7c0100194ed6f85910fc99debb (diff) | |
download | googletest-a862f1de30ed1ef259bcec61c5939200b29c765c.tar.gz googletest-a862f1de30ed1ef259bcec61c5939200b29c765c.tar.bz2 googletest-a862f1de30ed1ef259bcec61c5939200b29c765c.zip |
Adds IsInterested() to MatchResultListener; clarifies the format of matcher description and match result explanation; renames the free function MatchAndExplain() to ExplainMatchResult() to avoid it being hidden inside a MATCHER* definition.
Diffstat (limited to 'include')
-rw-r--r-- | include/gmock/gmock-matchers.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/include/gmock/gmock-matchers.h b/include/gmock/gmock-matchers.h index 50c0d7bf..8dba440a 100644 --- a/include/gmock/gmock-matchers.h +++ b/include/gmock/gmock-matchers.h @@ -90,6 +90,12 @@ class MatchResultListener { // Returns the underlying ostream. ::std::ostream* stream() { return stream_; } + // Returns true iff the listener is interested in an explanation of + // the match result. A matcher's MatchAndExplain() method can use + // this information to avoid generating the explanation when no one + // intends to hear it. + bool IsInterested() const { return stream_ != NULL; } + private: ::std::ostream* const stream_; @@ -106,7 +112,10 @@ class MatcherInterface { virtual ~MatcherInterface() {} // Returns true iff the matcher matches x; also explains the match - // result to 'listener'. + // result to 'listener', in the form of a non-restrictive relative + // clause ("which ...", "whose ...", etc) that describes x. For + // example, the MatchAndExplain() method of the Pointee(...) matcher + // should generate an explanation like "which points to ...". // // You should override this method when defining a new matcher. // @@ -118,7 +127,11 @@ class MatcherInterface { // listener->stream() may be NULL. virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; - // Describes this matcher to an ostream. + // Describes this matcher to an ostream. The function should print + // a verb phrase that describes the property a value matching this + // matcher should have. The subject of the verb phrase is the value + // being matched. For example, the DescribeTo() method of the Gt(7) + // matcher prints "is greater than 7". virtual void DescribeTo(::std::ostream* os) const = 0; // Describes the negation of this matcher to an ostream. For @@ -2853,7 +2866,7 @@ inline bool Value(const T& value, M matcher) { // Matches the value against the given matcher and explains the match // result to listener. template <typename T, typename M> -inline bool MatchAndExplain( +inline bool ExplainMatchResult( M matcher, const T& value, MatchResultListener* listener) { return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener); } |