| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_TESTING_GMOCK_SUPPORT_H_ | 5 #ifndef V8_TESTING_GMOCK_SUPPORT_H_ |
| 6 #define V8_TESTING_GMOCK_SUPPORT_H_ | 6 #define V8_TESTING_GMOCK_SUPPORT_H_ |
| 7 | 7 |
| 8 #include <cmath> |
| 9 |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 11 |
| 10 namespace testing { | 12 namespace testing { |
| 11 | 13 |
| 12 template <typename T> | 14 template <typename T> |
| 13 class Capture { | 15 class Capture { |
| 14 public: | 16 public: |
| 15 Capture() : value_(), has_value_(false) {} | 17 Capture() : value_(), has_value_(false) {} |
| 16 | 18 |
| 17 const T& value() const { return value_; } | 19 const T& value() const { return value_; } |
| 18 bool has_value() const { return has_value_; } | 20 bool has_value() const { return has_value_; } |
| 19 | 21 |
| 20 void SetValue(const T& value) { | 22 void SetValue(const T& value) { |
| 21 DCHECK(!has_value()); | 23 DCHECK(!has_value()); |
| 22 value_ = value; | 24 value_ = value; |
| 23 has_value_ = true; | 25 has_value_ = true; |
| 24 } | 26 } |
| 25 | 27 |
| 26 private: | 28 private: |
| 27 T value_; | 29 T value_; |
| 28 bool has_value_; | 30 bool has_value_; |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 | 33 |
| 34 MATCHER(IsNaN, std::string(negation ? "isn't" : "is") + " NaN") { |
| 35 return std::isnan(arg); |
| 36 } |
| 37 |
| 38 |
| 32 namespace internal { | 39 namespace internal { |
| 33 | 40 |
| 34 template <typename T> | 41 template <typename T> |
| 35 class CaptureEqMatcher : public MatcherInterface<T> { | 42 class CaptureEqMatcher : public MatcherInterface<T> { |
| 36 public: | 43 public: |
| 37 explicit CaptureEqMatcher(Capture<T>* capture) : capture_(capture) {} | 44 explicit CaptureEqMatcher(Capture<T>* capture) : capture_(capture) {} |
| 38 | 45 |
| 39 virtual void DescribeTo(std::ostream* os) const { | 46 virtual void DescribeTo(std::ostream* os) const { |
| 40 *os << "captured by " << static_cast<const void*>(capture_); | 47 *os << "captured by " << static_cast<const void*>(capture_); |
| 41 if (capture_->has_value()) *os << " which has value " << capture_->value(); | 48 if (capture_->has_value()) *os << " which has value " << capture_->value(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 // CaptureEq(capture) captures the value passed in during matching as long as it | 70 // CaptureEq(capture) captures the value passed in during matching as long as it |
| 64 // is unset, and once set, compares the value for equality with the argument. | 71 // is unset, and once set, compares the value for equality with the argument. |
| 65 template <typename T> | 72 template <typename T> |
| 66 Matcher<T> CaptureEq(Capture<T>* capture) { | 73 Matcher<T> CaptureEq(Capture<T>* capture) { |
| 67 return MakeMatcher(new internal::CaptureEqMatcher<T>(capture)); | 74 return MakeMatcher(new internal::CaptureEqMatcher<T>(capture)); |
| 68 } | 75 } |
| 69 | 76 |
| 70 } // namespace testing | 77 } // namespace testing |
| 71 | 78 |
| 72 #endif // V8_TESTING_GMOCK_SUPPORT_H_ | 79 #endif // V8_TESTING_GMOCK_SUPPORT_H_ |
| OLD | NEW |