Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: testing/gmock/test/gmock-matchers_test.cc

Issue 521012: Update gmock and gtest. (Closed)
Patch Set: update readme Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 using testing::internal::Interpolation; 114 using testing::internal::Interpolation;
115 using testing::internal::Interpolations; 115 using testing::internal::Interpolations;
116 using testing::internal::JoinAsTuple; 116 using testing::internal::JoinAsTuple;
117 using testing::internal::SkipPrefix; 117 using testing::internal::SkipPrefix;
118 using testing::internal::String; 118 using testing::internal::String;
119 using testing::internal::Strings; 119 using testing::internal::Strings;
120 using testing::internal::ValidateMatcherDescription; 120 using testing::internal::ValidateMatcherDescription;
121 using testing::internal::kInvalidInterpolation; 121 using testing::internal::kInvalidInterpolation;
122 using testing::internal::kPercentInterpolation; 122 using testing::internal::kPercentInterpolation;
123 using testing::internal::kTupleInterpolation; 123 using testing::internal::kTupleInterpolation;
124 using testing::internal::linked_ptr;
125 using testing::internal::scoped_ptr;
124 using testing::internal::string; 126 using testing::internal::string;
125 127
126 #ifdef GMOCK_HAS_REGEX 128 #ifdef GMOCK_HAS_REGEX
127 using testing::ContainsRegex; 129 using testing::ContainsRegex;
128 using testing::MatchesRegex; 130 using testing::MatchesRegex;
129 using testing::internal::RE; 131 using testing::internal::RE;
130 #endif // GMOCK_HAS_REGEX 132 #endif // GMOCK_HAS_REGEX
131 133
132 // For testing ExplainMatchResultTo(). 134 // For testing ExplainMatchResultTo().
133 class GreaterThanMatcher : public MatcherInterface<int> { 135 class GreaterThanMatcher : public MatcherInterface<int> {
134 public: 136 public:
135 explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {} 137 explicit GreaterThanMatcher(int rhs) : rhs_(rhs) {}
136 138
137 virtual bool Matches(int lhs) const { return lhs > rhs_; } 139 virtual bool Matches(int lhs) const { return lhs > rhs_; }
138 140
139 virtual void DescribeTo(::std::ostream* os) const { 141 virtual void DescribeTo(::std::ostream* os) const {
140 *os << "is greater than " << rhs_; 142 *os << "is greater than " << rhs_;
141 } 143 }
142 144
143 virtual void ExplainMatchResultTo(int lhs, ::std::ostream* os) const { 145 virtual void ExplainMatchResultTo(int lhs, ::std::ostream* os) const {
144 const int diff = lhs - rhs_; 146 const int diff = lhs - rhs_;
145 if (diff > 0) { 147 if (diff > 0) {
146 *os << "is " << diff << " more than " << rhs_; 148 *os << "is " << diff << " more than " << rhs_;
147 } else if (diff == 0) { 149 } else if (diff == 0) {
148 *os << "is the same as " << rhs_; 150 *os << "is the same as " << rhs_;
149 } else { 151 } else {
150 *os << "is " << -diff << " less than " << rhs_; 152 *os << "is " << -diff << " less than " << rhs_;
151 } 153 }
152 } 154 }
155
153 private: 156 private:
154 const int rhs_; 157 int rhs_;
155 }; 158 };
156 159
157 Matcher<int> GreaterThan(int n) { 160 Matcher<int> GreaterThan(int n) {
158 return MakeMatcher(new GreaterThanMatcher(n)); 161 return MakeMatcher(new GreaterThanMatcher(n));
159 } 162 }
160 163
161 // Returns the description of the given matcher. 164 // Returns the description of the given matcher.
162 template <typename T> 165 template <typename T>
163 string Describe(const Matcher<T>& m) { 166 string Describe(const Matcher<T>& m) {
164 stringstream ss; 167 stringstream ss;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 Matcher<int> m = MatcherCast<int>(Eq(5)); 329 Matcher<int> m = MatcherCast<int>(Eq(5));
327 EXPECT_TRUE(m.Matches(5)); 330 EXPECT_TRUE(m.Matches(5));
328 EXPECT_FALSE(m.Matches(6)); 331 EXPECT_FALSE(m.Matches(6));
329 } 332 }
330 333
331 // For testing casting matchers between compatible types. 334 // For testing casting matchers between compatible types.
332 class IntValue { 335 class IntValue {
333 public: 336 public:
334 // An int can be statically (although not implicitly) cast to a 337 // An int can be statically (although not implicitly) cast to a
335 // IntValue. 338 // IntValue.
336 explicit IntValue(int value) : value_(value) {} 339 explicit IntValue(int a_value) : value_(a_value) {}
337 340
338 int value() const { return value_; } 341 int value() const { return value_; }
339 private: 342 private:
340 int value_; 343 int value_;
341 }; 344 };
342 345
343 // For testing casting matchers between compatible types. 346 // For testing casting matchers between compatible types.
344 bool IsPositiveIntValue(const IntValue& foo) { 347 bool IsPositiveIntValue(const IntValue& foo) {
345 return foo.value() > 0; 348 return foo.value() > 0;
346 } 349 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 EXPECT_TRUE(m1.Matches(a1)); 554 EXPECT_TRUE(m1.Matches(a1));
552 EXPECT_FALSE(m1.Matches(a2)); 555 EXPECT_FALSE(m1.Matches(a2));
553 } 556 }
554 557
555 // Tests that Eq(v) describes itself properly. 558 // Tests that Eq(v) describes itself properly.
556 559
557 class Unprintable { 560 class Unprintable {
558 public: 561 public:
559 Unprintable() : c_('a') {} 562 Unprintable() : c_('a') {}
560 563
561 bool operator==(const Unprintable& rhs) { return true; } 564 bool operator==(const Unprintable& /* rhs */) { return true; }
562 private: 565 private:
563 char c_; 566 char c_;
564 }; 567 };
565 568
566 TEST(EqTest, CanDescribeSelf) { 569 TEST(EqTest, CanDescribeSelf) {
567 Matcher<Unprintable> m = Eq(Unprintable()); 570 Matcher<Unprintable> m = Eq(Unprintable());
568 EXPECT_EQ("is equal to 1-byte object <61>", Describe(m)); 571 EXPECT_EQ("is equal to 1-byte object <61>", Describe(m));
569 } 572 }
570 573
571 // Tests that Eq(v) can be used to match any type that supports 574 // Tests that Eq(v) can be used to match any type that supports
(...skipping 25 matching lines...) Expand all
597 } 600 }
598 601
599 // Tests that TypedEq<T>(v) has type Matcher<T>. 602 // Tests that TypedEq<T>(v) has type Matcher<T>.
600 603
601 // Type<T>::IsTypeOf(v) compiles iff the type of value v is T, where T 604 // Type<T>::IsTypeOf(v) compiles iff the type of value v is T, where T
602 // is a "bare" type (i.e. not in the form of const U or U&). If v's 605 // is a "bare" type (i.e. not in the form of const U or U&). If v's
603 // type is not T, the compiler will generate a message about 606 // type is not T, the compiler will generate a message about
604 // "undefined referece". 607 // "undefined referece".
605 template <typename T> 608 template <typename T>
606 struct Type { 609 struct Type {
607 static bool IsTypeOf(const T& v) { return true; } 610 static bool IsTypeOf(const T& /* v */) { return true; }
608 611
609 template <typename T2> 612 template <typename T2>
610 static void IsTypeOf(T2 v); 613 static void IsTypeOf(T2 v);
611 }; 614 };
612 615
613 TEST(TypedEqTest, HasSpecifiedType) { 616 TEST(TypedEqTest, HasSpecifiedType) {
614 // Verfies that the type of TypedEq<T>(v) is Matcher<T>. 617 // Verfies that the type of TypedEq<T>(v) is Matcher<T>.
615 Type<Matcher<int> >::IsTypeOf(TypedEq<int>(5)); 618 Type<Matcher<int> >::IsTypeOf(TypedEq<int>(5));
616 Type<Matcher<double> >::IsTypeOf(TypedEq<double>(5)); 619 Type<Matcher<double> >::IsTypeOf(TypedEq<double>(5));
617 } 620 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 // gmock-matchers.h: (point of instantiation: 'testing:: 711 // gmock-matchers.h: (point of instantiation: 'testing::
709 // gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()') 712 // gmock_matchers_test::IsNullTest_MatchesNullPointer_Test::TestBody()')
710 // gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc 713 // gmock-matchers.h: (instantiating: 'testing::PolymorphicMatc
711 Matcher<void*> m3 = IsNull(); 714 Matcher<void*> m3 = IsNull();
712 void* p3 = NULL; 715 void* p3 = NULL;
713 EXPECT_TRUE(m3.Matches(p3)); 716 EXPECT_TRUE(m3.Matches(p3));
714 EXPECT_FALSE(m3.Matches(reinterpret_cast<void*>(0xbeef))); 717 EXPECT_FALSE(m3.Matches(reinterpret_cast<void*>(0xbeef)));
715 #endif 718 #endif
716 } 719 }
717 720
721 TEST(IsNullTest, LinkedPtr) {
722 const Matcher<linked_ptr<int> > m = IsNull();
723 const linked_ptr<int> null_p;
724 const linked_ptr<int> non_null_p(new int);
725
726 EXPECT_TRUE(m.Matches(null_p));
727 EXPECT_FALSE(m.Matches(non_null_p));
728 }
729
730 TEST(IsNullTest, ReferenceToConstLinkedPtr) {
731 const Matcher<const linked_ptr<double>&> m = IsNull();
732 const linked_ptr<double> null_p;
733 const linked_ptr<double> non_null_p(new double);
734
735 EXPECT_TRUE(m.Matches(null_p));
736 EXPECT_FALSE(m.Matches(non_null_p));
737 }
738
739 TEST(IsNullTest, ReferenceToConstScopedPtr) {
740 const Matcher<const scoped_ptr<double>&> m = IsNull();
741 const scoped_ptr<double> null_p;
742 const scoped_ptr<double> non_null_p(new double);
743
744 EXPECT_TRUE(m.Matches(null_p));
745 EXPECT_FALSE(m.Matches(non_null_p));
746 }
747
718 // Tests that IsNull() describes itself properly. 748 // Tests that IsNull() describes itself properly.
719 TEST(IsNullTest, CanDescribeSelf) { 749 TEST(IsNullTest, CanDescribeSelf) {
720 Matcher<int*> m = IsNull(); 750 Matcher<int*> m = IsNull();
721 EXPECT_EQ("is NULL", Describe(m)); 751 EXPECT_EQ("is NULL", Describe(m));
722 EXPECT_EQ("is not NULL", DescribeNegation(m)); 752 EXPECT_EQ("is not NULL", DescribeNegation(m));
723 } 753 }
724 754
725 // Tests that NotNull() matches any non-NULL pointer of any type. 755 // Tests that NotNull() matches any non-NULL pointer of any type.
726 TEST(NotNullTest, MatchesNonNullPointer) { 756 TEST(NotNullTest, MatchesNonNullPointer) {
727 Matcher<int*> m1 = NotNull(); 757 Matcher<int*> m1 = NotNull();
728 int* p1 = NULL; 758 int* p1 = NULL;
729 int n = 0; 759 int n = 0;
730 EXPECT_FALSE(m1.Matches(p1)); 760 EXPECT_FALSE(m1.Matches(p1));
731 EXPECT_TRUE(m1.Matches(&n)); 761 EXPECT_TRUE(m1.Matches(&n));
732 762
733 Matcher<const char*> m2 = NotNull(); 763 Matcher<const char*> m2 = NotNull();
734 const char* p2 = NULL; 764 const char* p2 = NULL;
735 EXPECT_FALSE(m2.Matches(p2)); 765 EXPECT_FALSE(m2.Matches(p2));
736 EXPECT_TRUE(m2.Matches("hi")); 766 EXPECT_TRUE(m2.Matches("hi"));
737 } 767 }
738 768
769 TEST(NotNullTest, LinkedPtr) {
770 const Matcher<linked_ptr<int> > m = NotNull();
771 const linked_ptr<int> null_p;
772 const linked_ptr<int> non_null_p(new int);
773
774 EXPECT_FALSE(m.Matches(null_p));
775 EXPECT_TRUE(m.Matches(non_null_p));
776 }
777
778 TEST(NotNullTest, ReferenceToConstLinkedPtr) {
779 const Matcher<const linked_ptr<double>&> m = NotNull();
780 const linked_ptr<double> null_p;
781 const linked_ptr<double> non_null_p(new double);
782
783 EXPECT_FALSE(m.Matches(null_p));
784 EXPECT_TRUE(m.Matches(non_null_p));
785 }
786
787 TEST(NotNullTest, ReferenceToConstScopedPtr) {
788 const Matcher<const scoped_ptr<double>&> m = NotNull();
789 const scoped_ptr<double> null_p;
790 const scoped_ptr<double> non_null_p(new double);
791
792 EXPECT_FALSE(m.Matches(null_p));
793 EXPECT_TRUE(m.Matches(non_null_p));
794 }
795
739 // Tests that NotNull() describes itself properly. 796 // Tests that NotNull() describes itself properly.
740 TEST(NotNullTest, CanDescribeSelf) { 797 TEST(NotNullTest, CanDescribeSelf) {
741 Matcher<int*> m = NotNull(); 798 Matcher<int*> m = NotNull();
742 EXPECT_EQ("is not NULL", Describe(m)); 799 EXPECT_EQ("is not NULL", Describe(m));
743 } 800 }
744 801
745 // Tests that Ref(variable) matches an argument that references 802 // Tests that Ref(variable) matches an argument that references
746 // 'variable'. 803 // 'variable'.
747 TEST(RefTest, MatchesSameVariable) { 804 TEST(RefTest, MatchesSameVariable) {
748 int a = 0; 805 int a = 0;
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 return x > 0 ? 1 : 0; 1855 return x > 0 ? 1 : 0;
1799 } 1856 }
1800 1857
1801 // This functor returns true if the input is greater than the given 1858 // This functor returns true if the input is greater than the given
1802 // number. 1859 // number.
1803 class IsGreaterThan { 1860 class IsGreaterThan {
1804 public: 1861 public:
1805 explicit IsGreaterThan(int threshold) : threshold_(threshold) {} 1862 explicit IsGreaterThan(int threshold) : threshold_(threshold) {}
1806 1863
1807 bool operator()(int n) const { return n > threshold_; } 1864 bool operator()(int n) const { return n > threshold_; }
1865
1808 private: 1866 private:
1809 const int threshold_; 1867 int threshold_;
1810 }; 1868 };
1811 1869
1812 // For testing Truly(). 1870 // For testing Truly().
1813 const int foo = 0; 1871 const int foo = 0;
1814 1872
1815 // This predicate returns true iff the argument references foo and has 1873 // This predicate returns true iff the argument references foo and has
1816 // a zero value. 1874 // a zero value.
1817 bool ReferencesFooAndIsZero(const int& n) { 1875 bool ReferencesFooAndIsZero(const int& n) {
1818 return (&n == &foo) && (n == 0); 1876 return (&n == &foo) && (n == 0);
1819 } 1877 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt()))); 1954 EXPECT_THAT(make_tuple(2L, 1), Not(AllArgs(Lt())));
1897 } 1955 }
1898 1956
1899 TEST(AllArgsTest, WorksForNonTuple) { 1957 TEST(AllArgsTest, WorksForNonTuple) {
1900 EXPECT_THAT(42, AllArgs(Gt(0))); 1958 EXPECT_THAT(42, AllArgs(Gt(0)));
1901 EXPECT_THAT('a', Not(AllArgs(Eq('b')))); 1959 EXPECT_THAT('a', Not(AllArgs(Eq('b'))));
1902 } 1960 }
1903 1961
1904 class AllArgsHelper { 1962 class AllArgsHelper {
1905 public: 1963 public:
1964 AllArgsHelper() {}
1965
1906 MOCK_METHOD2(Helper, int(char x, int y)); 1966 MOCK_METHOD2(Helper, int(char x, int y));
1967
1968 private:
1969 GTEST_DISALLOW_COPY_AND_ASSIGN_(AllArgsHelper);
1907 }; 1970 };
1908 1971
1909 TEST(AllArgsTest, WorksInWithClause) { 1972 TEST(AllArgsTest, WorksInWithClause) {
1910 AllArgsHelper helper; 1973 AllArgsHelper helper;
1911 ON_CALL(helper, Helper(_, _)) 1974 ON_CALL(helper, Helper(_, _))
1912 .With(AllArgs(Lt())) 1975 .With(AllArgs(Lt()))
1913 .WillByDefault(Return(1)); 1976 .WillByDefault(Return(1));
1914 EXPECT_CALL(helper, Helper(_, _)); 1977 EXPECT_CALL(helper, Helper(_, _));
1915 EXPECT_CALL(helper, Helper(_, _)) 1978 EXPECT_CALL(helper, Helper(_, _))
1916 .With(AllArgs(Gt())) 1979 .With(AllArgs(Gt()))
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 EXPECT_EQ("", Explain(m, static_cast<const string*>(NULL))); 2384 EXPECT_EQ("", Explain(m, static_cast<const string*>(NULL)));
2322 2385
2323 const Matcher<int*> m2 = Pointee(GreaterThan(1)); 2386 const Matcher<int*> m2 = Pointee(GreaterThan(1));
2324 int n = 3; 2387 int n = 3;
2325 EXPECT_EQ("points to a value that is 2 more than 1", Explain(m2, &n)); 2388 EXPECT_EQ("points to a value that is 2 more than 1", Explain(m2, &n));
2326 } 2389 }
2327 2390
2328 // An uncopyable class. 2391 // An uncopyable class.
2329 class Uncopyable { 2392 class Uncopyable {
2330 public: 2393 public:
2331 explicit Uncopyable(int value) : value_(value) {} 2394 explicit Uncopyable(int a_value) : value_(a_value) {}
2332 2395
2333 int value() const { return value_; } 2396 int value() const { return value_; }
2334 private: 2397 private:
2335 const int value_; 2398 const int value_;
2336 GTEST_DISALLOW_COPY_AND_ASSIGN_(Uncopyable); 2399 GTEST_DISALLOW_COPY_AND_ASSIGN_(Uncopyable);
2337 }; 2400 };
2338 2401
2339 // Returns true iff x.value() is positive. 2402 // Returns true iff x.value() is positive.
2340 bool ValueIsPositive(const Uncopyable& x) { return x.value() > 0; } 2403 bool ValueIsPositive(const Uncopyable& x) { return x.value() > 0; }
2341 2404
2342 // A user-defined struct for testing Field(). 2405 // A user-defined struct for testing Field().
2343 struct AStruct { 2406 struct AStruct {
2344 AStruct() : x(0), y(1.0), z(5), p(NULL) {} 2407 AStruct() : x(0), y(1.0), z(5), p(NULL) {}
2345 AStruct(const AStruct& rhs) 2408 AStruct(const AStruct& rhs)
2346 : x(rhs.x), y(rhs.y), z(rhs.z.value()), p(rhs.p) {} 2409 : x(rhs.x), y(rhs.y), z(rhs.z.value()), p(rhs.p) {}
2347 2410
2348 int x; // A non-const field. 2411 int x; // A non-const field.
2349 const double y; // A const field. 2412 const double y; // A const field.
2350 Uncopyable z; // An uncopyable field. 2413 Uncopyable z; // An uncopyable field.
2351 const char* p; // A pointer field. 2414 const char* p; // A pointer field.
2415
2416 private:
2417 GTEST_DISALLOW_ASSIGN_(AStruct);
2352 }; 2418 };
2353 2419
2354 // A derived struct for testing Field(). 2420 // A derived struct for testing Field().
2355 struct DerivedStruct : public AStruct { 2421 struct DerivedStruct : public AStruct {
2356 char ch; 2422 char ch;
2423
2424 private:
2425 GTEST_DISALLOW_ASSIGN_(DerivedStruct);
2357 }; 2426 };
2358 2427
2359 // Tests that Field(&Foo::field, ...) works when field is non-const. 2428 // Tests that Field(&Foo::field, ...) works when field is non-const.
2360 TEST(FieldTest, WorksForNonConstField) { 2429 TEST(FieldTest, WorksForNonConstField) {
2361 Matcher<AStruct> m = Field(&AStruct::x, Ge(0)); 2430 Matcher<AStruct> m = Field(&AStruct::x, Ge(0));
2362 2431
2363 AStruct a; 2432 AStruct a;
2364 EXPECT_TRUE(m.Matches(a)); 2433 EXPECT_TRUE(m.Matches(a));
2365 a.x = -1; 2434 a.x = -1;
2366 EXPECT_FALSE(m.Matches(a)); 2435 EXPECT_FALSE(m.Matches(a));
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
2880 EXPECT_TRUE(matcher2.Matches(n)); 2949 EXPECT_TRUE(matcher2.Matches(n));
2881 EXPECT_FALSE(matcher2.Matches(n2)); 2950 EXPECT_FALSE(matcher2.Matches(n2));
2882 2951
2883 Matcher<const int&> matcher3 = ResultOf(ReferencingFunctor(), Eq(&n)); 2952 Matcher<const int&> matcher3 = ResultOf(ReferencingFunctor(), Eq(&n));
2884 EXPECT_TRUE(matcher3.Matches(n)); 2953 EXPECT_TRUE(matcher3.Matches(n));
2885 EXPECT_FALSE(matcher3.Matches(n2)); 2954 EXPECT_FALSE(matcher3.Matches(n2));
2886 } 2955 }
2887 2956
2888 class DivisibleByImpl { 2957 class DivisibleByImpl {
2889 public: 2958 public:
2890 explicit DivisibleByImpl(int divider) : divider_(divider) {} 2959 explicit DivisibleByImpl(int a_divider) : divider_(a_divider) {}
2891 2960
2892 template <typename T> 2961 template <typename T>
2893 bool Matches(const T& n) const { 2962 bool Matches(const T& n) const {
2894 return (n % divider_) == 0; 2963 return (n % divider_) == 0;
2895 } 2964 }
2896 2965
2897 void DescribeTo(::std::ostream* os) const { 2966 void DescribeTo(::std::ostream* os) const {
2898 *os << "is divisible by " << divider_; 2967 *os << "is divisible by " << divider_;
2899 } 2968 }
2900 2969
2901 void DescribeNegationTo(::std::ostream* os) const { 2970 void DescribeNegationTo(::std::ostream* os) const {
2902 *os << "is not divisible by " << divider_; 2971 *os << "is not divisible by " << divider_;
2903 } 2972 }
2904 2973
2905 void set_divider(int divider) { divider_ = divider; } 2974 void set_divider(int a_divider) { divider_ = a_divider; }
2906 int divider() const { return divider_; } 2975 int divider() const { return divider_; }
2907 2976
2908 private: 2977 private:
2909 int divider_; 2978 int divider_;
2910 }; 2979 };
2911 2980
2912 // For testing using ExplainMatchResultTo() with polymorphic matchers. 2981 // For testing using ExplainMatchResultTo() with polymorphic matchers.
2913 template <typename T> 2982 template <typename T>
2914 void ExplainMatchResultTo(const DivisibleByImpl& impl, const T& n, 2983 void ExplainMatchResultTo(const DivisibleByImpl& impl, const T& n,
2915 ::std::ostream* os) { 2984 ::std::ostream* os) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 const Matcher<int> m = GreaterThan(5); 3027 const Matcher<int> m = GreaterThan(5);
2959 EXPECT_EQ("is 1 more than 5", Explain(m, 6)); 3028 EXPECT_EQ("is 1 more than 5", Explain(m, 6));
2960 } 3029 }
2961 3030
2962 // The following two tests verify that values without a public copy 3031 // The following two tests verify that values without a public copy
2963 // ctor can be used as arguments to matchers like Eq(), Ge(), and etc 3032 // ctor can be used as arguments to matchers like Eq(), Ge(), and etc
2964 // with the help of ByRef(). 3033 // with the help of ByRef().
2965 3034
2966 class NotCopyable { 3035 class NotCopyable {
2967 public: 3036 public:
2968 explicit NotCopyable(int value) : value_(value) {} 3037 explicit NotCopyable(int a_value) : value_(a_value) {}
2969 3038
2970 int value() const { return value_; } 3039 int value() const { return value_; }
2971 3040
2972 bool operator==(const NotCopyable& rhs) const { 3041 bool operator==(const NotCopyable& rhs) const {
2973 return value() == rhs.value(); 3042 return value() == rhs.value();
2974 } 3043 }
2975 3044
2976 bool operator>=(const NotCopyable& rhs) const { 3045 bool operator>=(const NotCopyable& rhs) const {
2977 return value() >= rhs.value(); 3046 return value() >= rhs.value();
2978 } 3047 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
3500 3569
3501 // Tests PolymorphicMatcher::impl(). 3570 // Tests PolymorphicMatcher::impl().
3502 TEST(PolymorphicMatcherTest, CanAccessImpl) { 3571 TEST(PolymorphicMatcherTest, CanAccessImpl) {
3503 const PolymorphicMatcher<DivisibleByImpl> m(DivisibleByImpl(42)); 3572 const PolymorphicMatcher<DivisibleByImpl> m(DivisibleByImpl(42));
3504 const DivisibleByImpl& impl = m.impl(); 3573 const DivisibleByImpl& impl = m.impl();
3505 EXPECT_EQ(42, impl.divider()); 3574 EXPECT_EQ(42, impl.divider());
3506 } 3575 }
3507 3576
3508 } // namespace gmock_matchers_test 3577 } // namespace gmock_matchers_test
3509 } // namespace testing 3578 } // namespace testing
OLDNEW
« no previous file with comments | « testing/gmock/test/gmock-internal-utils_test.cc ('k') | testing/gmock/test/gmock-more-actions_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698