xref: /freebsd/contrib/googletest/googlemock/test/gmock_link_test.h (revision 47ef2a131091508e049ab10cad7f91a3c1342cd9)
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 using testing::Rethrow;
191 #endif
192 
193 using testing::ContainsRegex;
194 using testing::MatchesRegex;
195 
196 class Interface {
197  public:
198   virtual ~Interface() = default;
199   virtual void VoidFromString(char* str) = 0;
200   virtual char* StringFromString(char* str) = 0;
201   virtual int IntFromString(char* str) = 0;
202   virtual int& IntRefFromString(char* str) = 0;
203   virtual void VoidFromFunc(void (*func)(char* str)) = 0;
204   virtual void VoidFromIntRef(int& n) = 0;  // NOLINT
205   virtual void VoidFromFloat(float n) = 0;
206   virtual void VoidFromDouble(double n) = 0;
207   virtual void VoidFromVector(const std::vector<int>& v) = 0;
208 };
209 
210 class Mock : public Interface {
211  public:
212   Mock() = default;
213 
214   MOCK_METHOD1(VoidFromString, void(char* str));
215   MOCK_METHOD1(StringFromString, char*(char* str));
216   MOCK_METHOD1(IntFromString, int(char* str));
217   MOCK_METHOD1(IntRefFromString, int&(char* str));
218   MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
219   MOCK_METHOD1(VoidFromIntRef, void(int& n));  // NOLINT
220   MOCK_METHOD1(VoidFromFloat, void(float n));
221   MOCK_METHOD1(VoidFromDouble, void(double n));
222   MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
223 
224  private:
225   Mock(const Mock&) = delete;
226   Mock& operator=(const Mock&) = delete;
227 };
228 
229 class InvokeHelper {
230  public:
231   static void StaticVoidFromVoid() {}
232   void VoidFromVoid() {}
233   static void StaticVoidFromString(char* /* str */) {}
234   void VoidFromString(char* /* str */) {}
235   static int StaticIntFromString(char* /* str */) { return 1; }
236   static bool StaticBoolFromString(const char* /* str */) { return true; }
237 };
238 
239 class FieldHelper {
240  public:
241   explicit FieldHelper(int a_field) : field_(a_field) {}
242   int field() const { return field_; }
243   int field_;  // NOLINT -- need external access to field_ to test
244                //           the Field matcher.
245 };
246 
247 // Tests the linkage of the ReturnVoid action.
248 TEST(LinkTest, TestReturnVoid) {
249   Mock mock;
250 
251   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
252   mock.VoidFromString(nullptr);
253 }
254 
255 // Tests the linkage of the Return action.
256 TEST(LinkTest, TestReturn) {
257   Mock mock;
258   char ch = 'x';
259 
260   EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
261   mock.StringFromString(nullptr);
262 }
263 
264 // Tests the linkage of the ReturnNull action.
265 TEST(LinkTest, TestReturnNull) {
266   Mock mock;
267 
268   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
269   mock.VoidFromString(nullptr);
270 }
271 
272 // Tests the linkage of the ReturnRef action.
273 TEST(LinkTest, TestReturnRef) {
274   Mock mock;
275   int n = 42;
276 
277   EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
278   mock.IntRefFromString(nullptr);
279 }
280 
281 // Tests the linkage of the Assign action.
282 TEST(LinkTest, TestAssign) {
283   Mock mock;
284   char ch = 'x';
285 
286   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
287   mock.VoidFromString(nullptr);
288 }
289 
290 // Tests the linkage of the SetArgPointee action.
291 TEST(LinkTest, TestSetArgPointee) {
292   Mock mock;
293   char ch = 'x';
294 
295   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y'));
296   mock.VoidFromString(&ch);
297 }
298 
299 // Tests the linkage of the SetArrayArgument action.
300 TEST(LinkTest, TestSetArrayArgument) {
301   Mock mock;
302   char ch = 'x';
303   char ch2 = 'y';
304 
305   EXPECT_CALL(mock, VoidFromString(_))
306       .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
307   mock.VoidFromString(&ch);
308 }
309 
310 #ifndef GTEST_OS_WINDOWS_MOBILE
311 
312 // Tests the linkage of the SetErrnoAndReturn action.
313 TEST(LinkTest, TestSetErrnoAndReturn) {
314   Mock mock;
315 
316   int saved_errno = errno;
317   EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
318   mock.IntFromString(nullptr);
319   errno = saved_errno;
320 }
321 
322 #endif  // !GTEST_OS_WINDOWS_MOBILE
323 
324 // Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
325 TEST(LinkTest, TestInvoke) {
326   Mock mock;
327   InvokeHelper test_invoke_helper;
328 
329   EXPECT_CALL(mock, VoidFromString(_))
330       .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
331       .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
332   mock.VoidFromString(nullptr);
333   mock.VoidFromString(nullptr);
334 }
335 
336 // Tests the linkage of the InvokeWithoutArgs action.
337 TEST(LinkTest, TestInvokeWithoutArgs) {
338   Mock mock;
339   InvokeHelper test_invoke_helper;
340 
341   EXPECT_CALL(mock, VoidFromString(_))
342       .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
343       .WillOnce(
344           InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
345   mock.VoidFromString(nullptr);
346   mock.VoidFromString(nullptr);
347 }
348 
349 // Tests the linkage of the InvokeArgument action.
350 TEST(LinkTest, TestInvokeArgument) {
351   Mock mock;
352   char ch = 'x';
353 
354   EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
355   mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
356 }
357 
358 // Tests the linkage of the WithArg action.
359 TEST(LinkTest, TestWithArg) {
360   Mock mock;
361 
362   EXPECT_CALL(mock, VoidFromString(_))
363       .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
364   mock.VoidFromString(nullptr);
365 }
366 
367 // Tests the linkage of the WithArgs action.
368 TEST(LinkTest, TestWithArgs) {
369   Mock mock;
370 
371   EXPECT_CALL(mock, VoidFromString(_))
372       .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
373   mock.VoidFromString(nullptr);
374 }
375 
376 // Tests the linkage of the WithoutArgs action.
377 TEST(LinkTest, TestWithoutArgs) {
378   Mock mock;
379 
380   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
381   mock.VoidFromString(nullptr);
382 }
383 
384 // Tests the linkage of the DoAll action.
385 TEST(LinkTest, TestDoAll) {
386   Mock mock;
387   char ch = 'x';
388 
389   EXPECT_CALL(mock, VoidFromString(_))
390       .WillOnce(DoAll(SetArgPointee<0>('y'), Return()));
391   mock.VoidFromString(&ch);
392 }
393 
394 // Tests the linkage of the DoDefault action.
395 TEST(LinkTest, TestDoDefault) {
396   Mock mock;
397   char ch = 'x';
398 
399   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
400   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
401   mock.VoidFromString(&ch);
402 }
403 
404 // Tests the linkage of the IgnoreResult action.
405 TEST(LinkTest, TestIgnoreResult) {
406   Mock mock;
407 
408   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
409   mock.VoidFromString(nullptr);
410 }
411 
412 #if GTEST_HAS_EXCEPTIONS
413 // Tests the linkage of the Throw action.
414 TEST(LinkTest, TestThrow) {
415   Mock mock;
416 
417   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
418   EXPECT_THROW(mock.VoidFromString(nullptr), int);
419 }
420 // Tests the linkage of the Rethrow action.
421 TEST(LinkTest, TestRethrow) {
422   Mock mock;
423 
424   EXPECT_CALL(mock, VoidFromString(_))
425       .WillOnce(Rethrow(std::make_exception_ptr(42)));
426   EXPECT_THROW(mock.VoidFromString(nullptr), int);
427 }
428 #endif  // GTEST_HAS_EXCEPTIONS
429 
430 // The ACTION*() macros trigger warning C4100 (unreferenced formal
431 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
432 // the macro definition, as the warnings are generated when the macro
433 // is expanded and macro expansion cannot contain #pragma.  Therefore
434 // we suppress them here.
435 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
436 
437 // Tests the linkage of actions created using ACTION macro.
438 namespace {
439 ACTION(Return1) { return 1; }
440 }  // namespace
441 
442 TEST(LinkTest, TestActionMacro) {
443   Mock mock;
444 
445   EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
446   mock.IntFromString(nullptr);
447 }
448 
449 // Tests the linkage of actions created using ACTION_P macro.
450 namespace {
451 ACTION_P(ReturnArgument, ret_value) { return ret_value; }
452 }  // namespace
453 
454 TEST(LinkTest, TestActionPMacro) {
455   Mock mock;
456 
457   EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
458   mock.IntFromString(nullptr);
459 }
460 
461 // Tests the linkage of actions created using ACTION_P2 macro.
462 namespace {
463 ACTION_P2(ReturnEqualsEitherOf, first, second) {
464   return arg0 == first || arg0 == second;
465 }
466 }  // namespace
467 
468 GTEST_DISABLE_MSC_WARNINGS_POP_()  // 4100
469 
470 TEST(LinkTest, TestActionP2Macro) {
471   Mock mock;
472   char ch = 'x';
473 
474   EXPECT_CALL(mock, IntFromString(_))
475       .WillOnce(ReturnEqualsEitherOf("one", "two"));
476   mock.IntFromString(&ch);
477 }
478 
479 // Tests the linkage of the "_" matcher.
480 TEST(LinkTest, TestMatcherAnything) {
481   Mock mock;
482 
483   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
484 }
485 
486 // Tests the linkage of the A matcher.
487 TEST(LinkTest, TestMatcherA) {
488   Mock mock;
489 
490   ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
491 }
492 
493 // Tests the linkage of the Eq and the "bare value" matcher.
494 TEST(LinkTest, TestMatchersEq) {
495   Mock mock;
496   const char* p = "x";
497 
498   ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
499   ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
500 }
501 
502 // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
503 TEST(LinkTest, TestMatchersRelations) {
504   Mock mock;
505 
506   ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
507   ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
508   ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
509   ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
510   ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
511 }
512 
513 // Tests the linkage of the NotNull matcher.
514 TEST(LinkTest, TestMatcherNotNull) {
515   Mock mock;
516 
517   ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
518 }
519 
520 // Tests the linkage of the IsNull matcher.
521 TEST(LinkTest, TestMatcherIsNull) {
522   Mock mock;
523 
524   ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
525 }
526 
527 // Tests the linkage of the Ref matcher.
528 TEST(LinkTest, TestMatcherRef) {
529   Mock mock;
530   int a = 0;
531 
532   ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
533 }
534 
535 // Tests the linkage of the TypedEq matcher.
536 TEST(LinkTest, TestMatcherTypedEq) {
537   Mock mock;
538   long a = 0;
539 
540   ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
541 }
542 
543 // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
544 // NanSensitiveDoubleEq matchers.
545 TEST(LinkTest, TestMatchersFloatingPoint) {
546   Mock mock;
547   float a = 0;
548 
549   ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
550   ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
551   ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
552   ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
553       .WillByDefault(Return());
554 }
555 
556 // Tests the linkage of the ContainsRegex matcher.
557 TEST(LinkTest, TestMatcherContainsRegex) {
558   Mock mock;
559 
560   ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
561 }
562 
563 // Tests the linkage of the MatchesRegex matcher.
564 TEST(LinkTest, TestMatcherMatchesRegex) {
565   Mock mock;
566 
567   ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
568 }
569 
570 // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
571 TEST(LinkTest, TestMatchersSubstrings) {
572   Mock mock;
573 
574   ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
575   ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
576   ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
577 }
578 
579 // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
580 TEST(LinkTest, TestMatchersStringEquality) {
581   Mock mock;
582   ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
583   ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
584   ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
585   ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
586 }
587 
588 // Tests the linkage of the ElementsAre matcher.
589 TEST(LinkTest, TestMatcherElementsAre) {
590   Mock mock;
591 
592   ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
593 }
594 
595 // Tests the linkage of the ElementsAreArray matcher.
596 TEST(LinkTest, TestMatcherElementsAreArray) {
597   Mock mock;
598   char arr[] = {'a', 'b'};
599 
600   ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
601 }
602 
603 // Tests the linkage of the IsSubsetOf matcher.
604 TEST(LinkTest, TestMatcherIsSubsetOf) {
605   Mock mock;
606   char arr[] = {'a', 'b'};
607 
608   ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
609 }
610 
611 // Tests the linkage of the IsSupersetOf matcher.
612 TEST(LinkTest, TestMatcherIsSupersetOf) {
613   Mock mock;
614   char arr[] = {'a', 'b'};
615 
616   ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
617 }
618 
619 // Tests the linkage of the ContainerEq matcher.
620 TEST(LinkTest, TestMatcherContainerEq) {
621   Mock mock;
622   std::vector<int> v;
623 
624   ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
625 }
626 
627 // Tests the linkage of the Field matcher.
628 TEST(LinkTest, TestMatcherField) {
629   FieldHelper helper(0);
630 
631   Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
632   EXPECT_TRUE(m.Matches(helper));
633 
634   Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
635   EXPECT_TRUE(m2.Matches(&helper));
636 }
637 
638 // Tests the linkage of the Property matcher.
639 TEST(LinkTest, TestMatcherProperty) {
640   FieldHelper helper(0);
641 
642   Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
643   EXPECT_TRUE(m.Matches(helper));
644 
645   Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
646   EXPECT_TRUE(m2.Matches(&helper));
647 }
648 
649 // Tests the linkage of the ResultOf matcher.
650 TEST(LinkTest, TestMatcherResultOf) {
651   Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
652   EXPECT_TRUE(m.Matches(nullptr));
653 }
654 
655 // Tests the linkage of the ResultOf matcher.
656 TEST(LinkTest, TestMatcherPointee) {
657   int n = 1;
658 
659   Matcher<int*> m = Pointee(Eq(1));
660   EXPECT_TRUE(m.Matches(&n));
661 }
662 
663 // Tests the linkage of the Truly matcher.
664 TEST(LinkTest, TestMatcherTruly) {
665   Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
666   EXPECT_TRUE(m.Matches(nullptr));
667 }
668 
669 // Tests the linkage of the AllOf matcher.
670 TEST(LinkTest, TestMatcherAllOf) {
671   Matcher<int> m = AllOf(_, Eq(1));
672   EXPECT_TRUE(m.Matches(1));
673 }
674 
675 // Tests the linkage of the AnyOf matcher.
676 TEST(LinkTest, TestMatcherAnyOf) {
677   Matcher<int> m = AnyOf(_, Eq(1));
678   EXPECT_TRUE(m.Matches(1));
679 }
680 
681 // Tests the linkage of the Not matcher.
682 TEST(LinkTest, TestMatcherNot) {
683   Matcher<int> m = Not(_);
684   EXPECT_FALSE(m.Matches(1));
685 }
686 
687 // Tests the linkage of the MatcherCast<T>() function.
688 TEST(LinkTest, TestMatcherCast) {
689   Matcher<const char*> m = MatcherCast<const char*>(_);
690   EXPECT_TRUE(m.Matches(nullptr));
691 }
692 
693 #endif  // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
694