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