xref: /freebsd/contrib/googletest/googlemock/test/gmock_link_test.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 // Copyright 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // Google Mock - a framework for writing C++ mock classes.
31 //
32 // This file tests that:
33 // a. A header file defining a mock class can be included in multiple
34 //    translation units without causing a link error.
35 // b. Actions and matchers can be instantiated with identical template
36 //    arguments in different translation units without causing link
37 //    errors.
38 //    The following constructs are currently tested:
39 //    Actions:
40 //      Return()
41 //      Return(value)
42 //      ReturnNull
43 //      ReturnRef
44 //      Assign
45 //      SetArgPointee
46 //      SetArrayArgument
47 //      SetErrnoAndReturn
48 //      Invoke(function)
49 //      Invoke(object, method)
50 //      InvokeWithoutArgs(function)
51 //      InvokeWithoutArgs(object, method)
52 //      InvokeArgument
53 //      WithArg
54 //      WithArgs
55 //      WithoutArgs
56 //      DoAll
57 //      DoDefault
58 //      IgnoreResult
59 //      Throw
60 //      ACTION()-generated
61 //      ACTION_P()-generated
62 //      ACTION_P2()-generated
63 //    Matchers:
64 //      _
65 //      A
66 //      An
67 //      Eq
68 //      Gt, Lt, Ge, Le, Ne
69 //      NotNull
70 //      Ref
71 //      TypedEq
72 //      DoubleEq
73 //      FloatEq
74 //      NanSensitiveDoubleEq
75 //      NanSensitiveFloatEq
76 //      ContainsRegex
77 //      MatchesRegex
78 //      EndsWith
79 //      HasSubstr
80 //      StartsWith
81 //      StrCaseEq
82 //      StrCaseNe
83 //      StrEq
84 //      StrNe
85 //      ElementsAre
86 //      ElementsAreArray
87 //      ContainerEq
88 //      Field
89 //      Property
90 //      ResultOf(function)
91 //      ResultOf(callback)
92 //      Pointee
93 //      Truly(predicate)
94 //      AddressSatisfies
95 //      AllOf
96 //      AnyOf
97 //      Not
98 //      MatcherCast<T>
99 //
100 //  Please note: this test does not verify the functioning of these
101 //  constructs, only that the programs using them will link successfully.
102 //
103 // Implementation note:
104 // This test requires identical definitions of Interface and Mock to be
105 // included in different translation units.  We achieve this by writing
106 // them in this header and #including it in gmock_link_test.cc and
107 // gmock_link2_test.cc.  Because the symbols generated by the compiler for
108 // those constructs must be identical in both translation units,
109 // definitions of Interface and Mock tests MUST be kept in the SAME
110 // NON-ANONYMOUS namespace in this file.  The test fixture class LinkTest
111 // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in
112 // gmock_link2_test.cc to avoid producing linker errors.
113 
114 #ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
115 #define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
116 
117 #include "gmock/gmock.h"
118 
119 #ifndef GTEST_OS_WINDOWS_MOBILE
120 #include <errno.h>
121 #endif
122 
123 #include <iostream>
124 #include <vector>
125 
126 #include "gtest/gtest.h"
127 #include "gtest/internal/gtest-port.h"
128 
129 using testing::_;
130 using testing::A;
131 using testing::Action;
132 using testing::AllOf;
133 using testing::AnyOf;
134 using testing::Assign;
135 using testing::ContainerEq;
136 using testing::DoAll;
137 using testing::DoDefault;
138 using testing::DoubleEq;
139 using testing::ElementsAre;
140 using testing::ElementsAreArray;
141 using testing::EndsWith;
142 using testing::Eq;
143 using testing::Field;
144 using testing::FloatEq;
145 using testing::Ge;
146 using testing::Gt;
147 using testing::HasSubstr;
148 using testing::IgnoreResult;
149 using testing::Invoke;
150 using testing::InvokeArgument;
151 using testing::InvokeWithoutArgs;
152 using testing::IsNull;
153 using testing::IsSubsetOf;
154 using testing::IsSupersetOf;
155 using testing::Le;
156 using testing::Lt;
157 using testing::Matcher;
158 using testing::MatcherCast;
159 using testing::NanSensitiveDoubleEq;
160 using testing::NanSensitiveFloatEq;
161 using testing::Ne;
162 using testing::Not;
163 using testing::NotNull;
164 using testing::Pointee;
165 using testing::Property;
166 using testing::Ref;
167 using testing::ResultOf;
168 using testing::Return;
169 using testing::ReturnNull;
170 using testing::ReturnRef;
171 using testing::SetArgPointee;
172 using testing::SetArrayArgument;
173 using testing::StartsWith;
174 using testing::StrCaseEq;
175 using testing::StrCaseNe;
176 using testing::StrEq;
177 using testing::StrNe;
178 using testing::Truly;
179 using testing::TypedEq;
180 using testing::WithArg;
181 using testing::WithArgs;
182 using testing::WithoutArgs;
183 
184 #ifndef GTEST_OS_WINDOWS_MOBILE
185 using testing::SetErrnoAndReturn;
186 #endif
187 
188 #if GTEST_HAS_EXCEPTIONS
189 using testing::Throw;
190 #endif
191 
192 using testing::ContainsRegex;
193 using testing::MatchesRegex;
194 
195 class Interface {
196  public:
197   virtual ~Interface() = default;
198   virtual void VoidFromString(char* str) = 0;
199   virtual char* StringFromString(char* str) = 0;
200   virtual int IntFromString(char* str) = 0;
201   virtual int& IntRefFromString(char* str) = 0;
202   virtual void VoidFromFunc(void (*func)(char* str)) = 0;
203   virtual void VoidFromIntRef(int& n) = 0;  // NOLINT
204   virtual void VoidFromFloat(float n) = 0;
205   virtual void VoidFromDouble(double n) = 0;
206   virtual void VoidFromVector(const std::vector<int>& v) = 0;
207 };
208 
209 class Mock : public Interface {
210  public:
211   Mock() = default;
212 
213   MOCK_METHOD1(VoidFromString, void(char* str));
214   MOCK_METHOD1(StringFromString, char*(char* str));
215   MOCK_METHOD1(IntFromString, int(char* str));
216   MOCK_METHOD1(IntRefFromString, int&(char* str));
217   MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
218   MOCK_METHOD1(VoidFromIntRef, void(int& n));  // NOLINT
219   MOCK_METHOD1(VoidFromFloat, void(float n));
220   MOCK_METHOD1(VoidFromDouble, void(double n));
221   MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
222 
223  private:
224   Mock(const Mock&) = delete;
225   Mock& operator=(const Mock&) = delete;
226 };
227 
228 class InvokeHelper {
229  public:
230   static void StaticVoidFromVoid() {}
231   void VoidFromVoid() {}
232   static void StaticVoidFromString(char* /* str */) {}
233   void VoidFromString(char* /* str */) {}
234   static int StaticIntFromString(char* /* str */) { return 1; }
235   static bool StaticBoolFromString(const char* /* str */) { return true; }
236 };
237 
238 class FieldHelper {
239  public:
240   explicit FieldHelper(int a_field) : field_(a_field) {}
241   int field() const { return field_; }
242   int field_;  // NOLINT -- need external access to field_ to test
243                //           the Field matcher.
244 };
245 
246 // Tests the linkage of the ReturnVoid action.
247 TEST(LinkTest, TestReturnVoid) {
248   Mock mock;
249 
250   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
251   mock.VoidFromString(nullptr);
252 }
253 
254 // Tests the linkage of the Return action.
255 TEST(LinkTest, TestReturn) {
256   Mock mock;
257   char ch = 'x';
258 
259   EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
260   mock.StringFromString(nullptr);
261 }
262 
263 // Tests the linkage of the ReturnNull action.
264 TEST(LinkTest, TestReturnNull) {
265   Mock mock;
266 
267   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
268   mock.VoidFromString(nullptr);
269 }
270 
271 // Tests the linkage of the ReturnRef action.
272 TEST(LinkTest, TestReturnRef) {
273   Mock mock;
274   int n = 42;
275 
276   EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
277   mock.IntRefFromString(nullptr);
278 }
279 
280 // Tests the linkage of the Assign action.
281 TEST(LinkTest, TestAssign) {
282   Mock mock;
283   char ch = 'x';
284 
285   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
286   mock.VoidFromString(nullptr);
287 }
288 
289 // Tests the linkage of the SetArgPointee action.
290 TEST(LinkTest, TestSetArgPointee) {
291   Mock mock;
292   char ch = 'x';
293 
294   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y'));
295   mock.VoidFromString(&ch);
296 }
297 
298 // Tests the linkage of the SetArrayArgument action.
299 TEST(LinkTest, TestSetArrayArgument) {
300   Mock mock;
301   char ch = 'x';
302   char ch2 = 'y';
303 
304   EXPECT_CALL(mock, VoidFromString(_))
305       .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
306   mock.VoidFromString(&ch);
307 }
308 
309 #ifndef GTEST_OS_WINDOWS_MOBILE
310 
311 // Tests the linkage of the SetErrnoAndReturn action.
312 TEST(LinkTest, TestSetErrnoAndReturn) {
313   Mock mock;
314 
315   int saved_errno = errno;
316   EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
317   mock.IntFromString(nullptr);
318   errno = saved_errno;
319 }
320 
321 #endif  // !GTEST_OS_WINDOWS_MOBILE
322 
323 // Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
324 TEST(LinkTest, TestInvoke) {
325   Mock mock;
326   InvokeHelper test_invoke_helper;
327 
328   EXPECT_CALL(mock, VoidFromString(_))
329       .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
330       .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
331   mock.VoidFromString(nullptr);
332   mock.VoidFromString(nullptr);
333 }
334 
335 // Tests the linkage of the InvokeWithoutArgs action.
336 TEST(LinkTest, TestInvokeWithoutArgs) {
337   Mock mock;
338   InvokeHelper test_invoke_helper;
339 
340   EXPECT_CALL(mock, VoidFromString(_))
341       .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
342       .WillOnce(
343           InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
344   mock.VoidFromString(nullptr);
345   mock.VoidFromString(nullptr);
346 }
347 
348 // Tests the linkage of the InvokeArgument action.
349 TEST(LinkTest, TestInvokeArgument) {
350   Mock mock;
351   char ch = 'x';
352 
353   EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
354   mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
355 }
356 
357 // Tests the linkage of the WithArg action.
358 TEST(LinkTest, TestWithArg) {
359   Mock mock;
360 
361   EXPECT_CALL(mock, VoidFromString(_))
362       .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
363   mock.VoidFromString(nullptr);
364 }
365 
366 // Tests the linkage of the WithArgs action.
367 TEST(LinkTest, TestWithArgs) {
368   Mock mock;
369 
370   EXPECT_CALL(mock, VoidFromString(_))
371       .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
372   mock.VoidFromString(nullptr);
373 }
374 
375 // Tests the linkage of the WithoutArgs action.
376 TEST(LinkTest, TestWithoutArgs) {
377   Mock mock;
378 
379   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
380   mock.VoidFromString(nullptr);
381 }
382 
383 // Tests the linkage of the DoAll action.
384 TEST(LinkTest, TestDoAll) {
385   Mock mock;
386   char ch = 'x';
387 
388   EXPECT_CALL(mock, VoidFromString(_))
389       .WillOnce(DoAll(SetArgPointee<0>('y'), Return()));
390   mock.VoidFromString(&ch);
391 }
392 
393 // Tests the linkage of the DoDefault action.
394 TEST(LinkTest, TestDoDefault) {
395   Mock mock;
396   char ch = 'x';
397 
398   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
399   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
400   mock.VoidFromString(&ch);
401 }
402 
403 // Tests the linkage of the IgnoreResult action.
404 TEST(LinkTest, TestIgnoreResult) {
405   Mock mock;
406 
407   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
408   mock.VoidFromString(nullptr);
409 }
410 
411 #if GTEST_HAS_EXCEPTIONS
412 // Tests the linkage of the Throw action.
413 TEST(LinkTest, TestThrow) {
414   Mock mock;
415 
416   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
417   EXPECT_THROW(mock.VoidFromString(nullptr), int);
418 }
419 #endif  // GTEST_HAS_EXCEPTIONS
420 
421 // The ACTION*() macros trigger warning C4100 (unreferenced formal
422 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
423 // the macro definition, as the warnings are generated when the macro
424 // is expanded and macro expansion cannot contain #pragma.  Therefore
425 // we suppress them here.
426 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
427 
428 // Tests the linkage of actions created using ACTION macro.
429 namespace {
430 ACTION(Return1) { return 1; }
431 }  // namespace
432 
433 TEST(LinkTest, TestActionMacro) {
434   Mock mock;
435 
436   EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
437   mock.IntFromString(nullptr);
438 }
439 
440 // Tests the linkage of actions created using ACTION_P macro.
441 namespace {
442 ACTION_P(ReturnArgument, ret_value) { return ret_value; }
443 }  // namespace
444 
445 TEST(LinkTest, TestActionPMacro) {
446   Mock mock;
447 
448   EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
449   mock.IntFromString(nullptr);
450 }
451 
452 // Tests the linkage of actions created using ACTION_P2 macro.
453 namespace {
454 ACTION_P2(ReturnEqualsEitherOf, first, second) {
455   return arg0 == first || arg0 == second;
456 }
457 }  // namespace
458 
459 GTEST_DISABLE_MSC_WARNINGS_POP_()  // 4100
460 
461 TEST(LinkTest, TestActionP2Macro) {
462   Mock mock;
463   char ch = 'x';
464 
465   EXPECT_CALL(mock, IntFromString(_))
466       .WillOnce(ReturnEqualsEitherOf("one", "two"));
467   mock.IntFromString(&ch);
468 }
469 
470 // Tests the linkage of the "_" matcher.
471 TEST(LinkTest, TestMatcherAnything) {
472   Mock mock;
473 
474   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
475 }
476 
477 // Tests the linkage of the A matcher.
478 TEST(LinkTest, TestMatcherA) {
479   Mock mock;
480 
481   ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
482 }
483 
484 // Tests the linkage of the Eq and the "bare value" matcher.
485 TEST(LinkTest, TestMatchersEq) {
486   Mock mock;
487   const char* p = "x";
488 
489   ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
490   ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
491 }
492 
493 // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
494 TEST(LinkTest, TestMatchersRelations) {
495   Mock mock;
496 
497   ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
498   ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
499   ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
500   ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
501   ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
502 }
503 
504 // Tests the linkage of the NotNull matcher.
505 TEST(LinkTest, TestMatcherNotNull) {
506   Mock mock;
507 
508   ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
509 }
510 
511 // Tests the linkage of the IsNull matcher.
512 TEST(LinkTest, TestMatcherIsNull) {
513   Mock mock;
514 
515   ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
516 }
517 
518 // Tests the linkage of the Ref matcher.
519 TEST(LinkTest, TestMatcherRef) {
520   Mock mock;
521   int a = 0;
522 
523   ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
524 }
525 
526 // Tests the linkage of the TypedEq matcher.
527 TEST(LinkTest, TestMatcherTypedEq) {
528   Mock mock;
529   long a = 0;
530 
531   ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
532 }
533 
534 // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
535 // NanSensitiveDoubleEq matchers.
536 TEST(LinkTest, TestMatchersFloatingPoint) {
537   Mock mock;
538   float a = 0;
539 
540   ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
541   ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
542   ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
543   ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
544       .WillByDefault(Return());
545 }
546 
547 // Tests the linkage of the ContainsRegex matcher.
548 TEST(LinkTest, TestMatcherContainsRegex) {
549   Mock mock;
550 
551   ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
552 }
553 
554 // Tests the linkage of the MatchesRegex matcher.
555 TEST(LinkTest, TestMatcherMatchesRegex) {
556   Mock mock;
557 
558   ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
559 }
560 
561 // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
562 TEST(LinkTest, TestMatchersSubstrings) {
563   Mock mock;
564 
565   ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
566   ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
567   ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
568 }
569 
570 // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
571 TEST(LinkTest, TestMatchersStringEquality) {
572   Mock mock;
573   ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
574   ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
575   ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
576   ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
577 }
578 
579 // Tests the linkage of the ElementsAre matcher.
580 TEST(LinkTest, TestMatcherElementsAre) {
581   Mock mock;
582 
583   ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
584 }
585 
586 // Tests the linkage of the ElementsAreArray matcher.
587 TEST(LinkTest, TestMatcherElementsAreArray) {
588   Mock mock;
589   char arr[] = {'a', 'b'};
590 
591   ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
592 }
593 
594 // Tests the linkage of the IsSubsetOf matcher.
595 TEST(LinkTest, TestMatcherIsSubsetOf) {
596   Mock mock;
597   char arr[] = {'a', 'b'};
598 
599   ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
600 }
601 
602 // Tests the linkage of the IsSupersetOf matcher.
603 TEST(LinkTest, TestMatcherIsSupersetOf) {
604   Mock mock;
605   char arr[] = {'a', 'b'};
606 
607   ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
608 }
609 
610 // Tests the linkage of the ContainerEq matcher.
611 TEST(LinkTest, TestMatcherContainerEq) {
612   Mock mock;
613   std::vector<int> v;
614 
615   ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
616 }
617 
618 // Tests the linkage of the Field matcher.
619 TEST(LinkTest, TestMatcherField) {
620   FieldHelper helper(0);
621 
622   Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
623   EXPECT_TRUE(m.Matches(helper));
624 
625   Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
626   EXPECT_TRUE(m2.Matches(&helper));
627 }
628 
629 // Tests the linkage of the Property matcher.
630 TEST(LinkTest, TestMatcherProperty) {
631   FieldHelper helper(0);
632 
633   Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
634   EXPECT_TRUE(m.Matches(helper));
635 
636   Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
637   EXPECT_TRUE(m2.Matches(&helper));
638 }
639 
640 // Tests the linkage of the ResultOf matcher.
641 TEST(LinkTest, TestMatcherResultOf) {
642   Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
643   EXPECT_TRUE(m.Matches(nullptr));
644 }
645 
646 // Tests the linkage of the ResultOf matcher.
647 TEST(LinkTest, TestMatcherPointee) {
648   int n = 1;
649 
650   Matcher<int*> m = Pointee(Eq(1));
651   EXPECT_TRUE(m.Matches(&n));
652 }
653 
654 // Tests the linkage of the Truly matcher.
655 TEST(LinkTest, TestMatcherTruly) {
656   Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
657   EXPECT_TRUE(m.Matches(nullptr));
658 }
659 
660 // Tests the linkage of the AllOf matcher.
661 TEST(LinkTest, TestMatcherAllOf) {
662   Matcher<int> m = AllOf(_, Eq(1));
663   EXPECT_TRUE(m.Matches(1));
664 }
665 
666 // Tests the linkage of the AnyOf matcher.
667 TEST(LinkTest, TestMatcherAnyOf) {
668   Matcher<int> m = AnyOf(_, Eq(1));
669   EXPECT_TRUE(m.Matches(1));
670 }
671 
672 // Tests the linkage of the Not matcher.
673 TEST(LinkTest, TestMatcherNot) {
674   Matcher<int> m = Not(_);
675   EXPECT_FALSE(m.Matches(1));
676 }
677 
678 // Tests the linkage of the MatcherCast<T>() function.
679 TEST(LinkTest, TestMatcherCast) {
680   Matcher<const char*> m = MatcherCast<const char*>(_);
681   EXPECT_TRUE(m.Matches(nullptr));
682 }
683 
684 #endif  // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
685