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
31 // Google Mock - a framework for writing C++ mock classes.
32 //
33 // This file tests that:
34 // a. A header file defining a mock class can be included in multiple
35 // translation units without causing a link error.
36 // b. Actions and matchers can be instantiated with identical template
37 // arguments in different translation units without causing link
38 // errors.
39 // The following constructs are currently tested:
40 // Actions:
41 // Return()
42 // Return(value)
43 // ReturnNull
44 // ReturnRef
45 // Assign
46 // SetArgPointee
47 // SetArrayArgument
48 // SetErrnoAndReturn
49 // Invoke(function)
50 // Invoke(object, method)
51 // InvokeWithoutArgs(function)
52 // InvokeWithoutArgs(object, method)
53 // InvokeArgument
54 // WithArg
55 // WithArgs
56 // WithoutArgs
57 // DoAll
58 // DoDefault
59 // IgnoreResult
60 // Throw
61 // ACTION()-generated
62 // ACTION_P()-generated
63 // ACTION_P2()-generated
64 // Matchers:
65 // _
66 // A
67 // An
68 // Eq
69 // Gt, Lt, Ge, Le, Ne
70 // NotNull
71 // Ref
72 // TypedEq
73 // DoubleEq
74 // FloatEq
75 // NanSensitiveDoubleEq
76 // NanSensitiveFloatEq
77 // ContainsRegex
78 // MatchesRegex
79 // EndsWith
80 // HasSubstr
81 // StartsWith
82 // StrCaseEq
83 // StrCaseNe
84 // StrEq
85 // StrNe
86 // ElementsAre
87 // ElementsAreArray
88 // ContainerEq
89 // Field
90 // Property
91 // ResultOf(function)
92 // ResultOf(callback)
93 // Pointee
94 // Truly(predicate)
95 // AddressSatisfies
96 // AllOf
97 // AnyOf
98 // Not
99 // MatcherCast<T>
100 //
101 // Please note: this test does not verify the functioning of these
102 // constructs, only that the programs using them will link successfully.
103 //
104 // Implementation note:
105 // This test requires identical definitions of Interface and Mock to be
106 // included in different translation units. We achieve this by writing
107 // them in this header and #including it in gmock_link_test.cc and
108 // gmock_link2_test.cc. Because the symbols generated by the compiler for
109 // those constructs must be identical in both translation units,
110 // definitions of Interface and Mock tests MUST be kept in the SAME
111 // NON-ANONYMOUS namespace in this file. The test fixture class LinkTest
112 // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in
113 // gmock_link2_test.cc to avoid producing linker errors.
114
115 #ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
116 #define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
117
118 #include "gmock/gmock.h"
119
120 #if !GTEST_OS_WINDOWS_MOBILE
121 # include <errno.h>
122 #endif
123
124 #include <iostream>
125 #include <vector>
126
127 #include "gtest/gtest.h"
128 #include "gtest/internal/gtest-port.h"
129
130 using testing::_;
131 using testing::A;
132 using testing::Action;
133 using testing::AllOf;
134 using testing::AnyOf;
135 using testing::Assign;
136 using testing::ContainerEq;
137 using testing::DoAll;
138 using testing::DoDefault;
139 using testing::DoubleEq;
140 using testing::ElementsAre;
141 using testing::ElementsAreArray;
142 using testing::EndsWith;
143 using testing::Eq;
144 using testing::Field;
145 using testing::FloatEq;
146 using testing::Ge;
147 using testing::Gt;
148 using testing::HasSubstr;
149 using testing::IgnoreResult;
150 using testing::Invoke;
151 using testing::InvokeArgument;
152 using testing::InvokeWithoutArgs;
153 using testing::IsNull;
154 using testing::IsSubsetOf;
155 using testing::IsSupersetOf;
156 using testing::Le;
157 using testing::Lt;
158 using testing::Matcher;
159 using testing::MatcherCast;
160 using testing::NanSensitiveDoubleEq;
161 using testing::NanSensitiveFloatEq;
162 using testing::Ne;
163 using testing::Not;
164 using testing::NotNull;
165 using testing::Pointee;
166 using testing::Property;
167 using testing::Ref;
168 using testing::ResultOf;
169 using testing::Return;
170 using testing::ReturnNull;
171 using testing::ReturnRef;
172 using testing::SetArgPointee;
173 using testing::SetArrayArgument;
174 using testing::StartsWith;
175 using testing::StrCaseEq;
176 using testing::StrCaseNe;
177 using testing::StrEq;
178 using testing::StrNe;
179 using testing::Truly;
180 using testing::TypedEq;
181 using testing::WithArg;
182 using testing::WithArgs;
183 using testing::WithoutArgs;
184
185 #if !GTEST_OS_WINDOWS_MOBILE
186 using testing::SetErrnoAndReturn;
187 #endif
188
189 #if GTEST_HAS_EXCEPTIONS
190 using testing::Throw;
191 #endif
192
193 using testing::ContainsRegex;
194 using testing::MatchesRegex;
195
196 class Interface {
197 public:
~Interface()198 virtual ~Interface() {}
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:
Mock()212 Mock() {}
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 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
226 };
227
228 class InvokeHelper {
229 public:
StaticVoidFromVoid()230 static void StaticVoidFromVoid() {}
VoidFromVoid()231 void VoidFromVoid() {}
StaticVoidFromString(char *)232 static void StaticVoidFromString(char* /* str */) {}
VoidFromString(char *)233 void VoidFromString(char* /* str */) {}
StaticIntFromString(char *)234 static int StaticIntFromString(char* /* str */) { return 1; }
StaticBoolFromString(const char *)235 static bool StaticBoolFromString(const char* /* str */) { return true; }
236 };
237
238 class FieldHelper {
239 public:
FieldHelper(int a_field)240 explicit FieldHelper(int a_field) : field_(a_field) {}
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.
TEST(LinkTest,TestReturnVoid)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.
TEST(LinkTest,TestReturn)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.
TEST(LinkTest,TestReturnNull)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.
TEST(LinkTest,TestReturnRef)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.
TEST(LinkTest,TestAssign)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.
TEST(LinkTest,TestSetArgPointee)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.
TEST(LinkTest,TestSetArrayArgument)299 TEST(LinkTest, TestSetArrayArgument) {
300 Mock mock;
301 char ch = 'x';
302 char ch2 = 'y';
303
304 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2,
305 &ch2 + 1));
306 mock.VoidFromString(&ch);
307 }
308
309 #if !GTEST_OS_WINDOWS_MOBILE
310
311 // Tests the linkage of the SetErrnoAndReturn action.
TEST(LinkTest,TestSetErrnoAndReturn)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.
TEST(LinkTest,TestInvoke)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.
TEST(LinkTest,TestInvokeWithoutArgs)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(InvokeWithoutArgs(&test_invoke_helper,
343 &InvokeHelper::VoidFromVoid));
344 mock.VoidFromString(nullptr);
345 mock.VoidFromString(nullptr);
346 }
347
348 // Tests the linkage of the InvokeArgument action.
TEST(LinkTest,TestInvokeArgument)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.
TEST(LinkTest,TestWithArg)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.
TEST(LinkTest,TestWithArgs)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.
TEST(LinkTest,TestWithoutArgs)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.
TEST(LinkTest,TestDoAll)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.
TEST(LinkTest,TestDoDefault)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.
TEST(LinkTest,TestIgnoreResult)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.
TEST(LinkTest,TestThrow)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 #ifdef _MSC_VER
427 # pragma warning(push)
428 # pragma warning(disable:4100)
429 #endif
430
431 // Tests the linkage of actions created using ACTION macro.
432 namespace {
ACTION(Return1)433 ACTION(Return1) { return 1; }
434 }
435
TEST(LinkTest,TestActionMacro)436 TEST(LinkTest, TestActionMacro) {
437 Mock mock;
438
439 EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
440 mock.IntFromString(nullptr);
441 }
442
443 // Tests the linkage of actions created using ACTION_P macro.
444 namespace {
ACTION_P(ReturnArgument,ret_value)445 ACTION_P(ReturnArgument, ret_value) { return ret_value; }
446 }
447
TEST(LinkTest,TestActionPMacro)448 TEST(LinkTest, TestActionPMacro) {
449 Mock mock;
450
451 EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
452 mock.IntFromString(nullptr);
453 }
454
455 // Tests the linkage of actions created using ACTION_P2 macro.
456 namespace {
ACTION_P2(ReturnEqualsEitherOf,first,second)457 ACTION_P2(ReturnEqualsEitherOf, first, second) {
458 return arg0 == first || arg0 == second;
459 }
460 }
461
462 #ifdef _MSC_VER
463 # pragma warning(pop)
464 #endif
465
TEST(LinkTest,TestActionP2Macro)466 TEST(LinkTest, TestActionP2Macro) {
467 Mock mock;
468 char ch = 'x';
469
470 EXPECT_CALL(mock, IntFromString(_))
471 .WillOnce(ReturnEqualsEitherOf("one", "two"));
472 mock.IntFromString(&ch);
473 }
474
475 // Tests the linkage of the "_" matcher.
TEST(LinkTest,TestMatcherAnything)476 TEST(LinkTest, TestMatcherAnything) {
477 Mock mock;
478
479 ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
480 }
481
482 // Tests the linkage of the A matcher.
TEST(LinkTest,TestMatcherA)483 TEST(LinkTest, TestMatcherA) {
484 Mock mock;
485
486 ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
487 }
488
489 // Tests the linkage of the Eq and the "bare value" matcher.
TEST(LinkTest,TestMatchersEq)490 TEST(LinkTest, TestMatchersEq) {
491 Mock mock;
492 const char* p = "x";
493
494 ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
495 ON_CALL(mock, VoidFromString(const_cast<char*>("y")))
496 .WillByDefault(Return());
497 }
498
499 // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
TEST(LinkTest,TestMatchersRelations)500 TEST(LinkTest, TestMatchersRelations) {
501 Mock mock;
502
503 ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
504 ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
505 ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
506 ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
507 ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
508 }
509
510 // Tests the linkage of the NotNull matcher.
TEST(LinkTest,TestMatcherNotNull)511 TEST(LinkTest, TestMatcherNotNull) {
512 Mock mock;
513
514 ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
515 }
516
517 // Tests the linkage of the IsNull matcher.
TEST(LinkTest,TestMatcherIsNull)518 TEST(LinkTest, TestMatcherIsNull) {
519 Mock mock;
520
521 ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
522 }
523
524 // Tests the linkage of the Ref matcher.
TEST(LinkTest,TestMatcherRef)525 TEST(LinkTest, TestMatcherRef) {
526 Mock mock;
527 int a = 0;
528
529 ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
530 }
531
532 // Tests the linkage of the TypedEq matcher.
TEST(LinkTest,TestMatcherTypedEq)533 TEST(LinkTest, TestMatcherTypedEq) {
534 Mock mock;
535 long a = 0;
536
537 ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
538 }
539
540 // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
541 // NanSensitiveDoubleEq matchers.
TEST(LinkTest,TestMatchersFloatingPoint)542 TEST(LinkTest, TestMatchersFloatingPoint) {
543 Mock mock;
544 float a = 0;
545
546 ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
547 ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
548 ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
549 ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
550 .WillByDefault(Return());
551 }
552
553 // Tests the linkage of the ContainsRegex matcher.
TEST(LinkTest,TestMatcherContainsRegex)554 TEST(LinkTest, TestMatcherContainsRegex) {
555 Mock mock;
556
557 ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
558 }
559
560 // Tests the linkage of the MatchesRegex matcher.
TEST(LinkTest,TestMatcherMatchesRegex)561 TEST(LinkTest, TestMatcherMatchesRegex) {
562 Mock mock;
563
564 ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
565 }
566
567 // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
TEST(LinkTest,TestMatchersSubstrings)568 TEST(LinkTest, TestMatchersSubstrings) {
569 Mock mock;
570
571 ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
572 ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
573 ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
574 }
575
576 // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
TEST(LinkTest,TestMatchersStringEquality)577 TEST(LinkTest, TestMatchersStringEquality) {
578 Mock mock;
579 ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
580 ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
581 ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
582 ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
583 }
584
585 // Tests the linkage of the ElementsAre matcher.
TEST(LinkTest,TestMatcherElementsAre)586 TEST(LinkTest, TestMatcherElementsAre) {
587 Mock mock;
588
589 ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
590 }
591
592 // Tests the linkage of the ElementsAreArray matcher.
TEST(LinkTest,TestMatcherElementsAreArray)593 TEST(LinkTest, TestMatcherElementsAreArray) {
594 Mock mock;
595 char arr[] = { 'a', 'b' };
596
597 ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
598 }
599
600 // Tests the linkage of the IsSubsetOf matcher.
TEST(LinkTest,TestMatcherIsSubsetOf)601 TEST(LinkTest, TestMatcherIsSubsetOf) {
602 Mock mock;
603 char arr[] = {'a', 'b'};
604
605 ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
606 }
607
608 // Tests the linkage of the IsSupersetOf matcher.
TEST(LinkTest,TestMatcherIsSupersetOf)609 TEST(LinkTest, TestMatcherIsSupersetOf) {
610 Mock mock;
611 char arr[] = {'a', 'b'};
612
613 ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
614 }
615
616 // Tests the linkage of the ContainerEq matcher.
TEST(LinkTest,TestMatcherContainerEq)617 TEST(LinkTest, TestMatcherContainerEq) {
618 Mock mock;
619 std::vector<int> v;
620
621 ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
622 }
623
624 // Tests the linkage of the Field matcher.
TEST(LinkTest,TestMatcherField)625 TEST(LinkTest, TestMatcherField) {
626 FieldHelper helper(0);
627
628 Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
629 EXPECT_TRUE(m.Matches(helper));
630
631 Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
632 EXPECT_TRUE(m2.Matches(&helper));
633 }
634
635 // Tests the linkage of the Property matcher.
TEST(LinkTest,TestMatcherProperty)636 TEST(LinkTest, TestMatcherProperty) {
637 FieldHelper helper(0);
638
639 Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
640 EXPECT_TRUE(m.Matches(helper));
641
642 Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
643 EXPECT_TRUE(m2.Matches(&helper));
644 }
645
646 // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherResultOf)647 TEST(LinkTest, TestMatcherResultOf) {
648 Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
649 EXPECT_TRUE(m.Matches(nullptr));
650 }
651
652 // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherPointee)653 TEST(LinkTest, TestMatcherPointee) {
654 int n = 1;
655
656 Matcher<int*> m = Pointee(Eq(1));
657 EXPECT_TRUE(m.Matches(&n));
658 }
659
660 // Tests the linkage of the Truly matcher.
TEST(LinkTest,TestMatcherTruly)661 TEST(LinkTest, TestMatcherTruly) {
662 Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
663 EXPECT_TRUE(m.Matches(nullptr));
664 }
665
666 // Tests the linkage of the AllOf matcher.
TEST(LinkTest,TestMatcherAllOf)667 TEST(LinkTest, TestMatcherAllOf) {
668 Matcher<int> m = AllOf(_, Eq(1));
669 EXPECT_TRUE(m.Matches(1));
670 }
671
672 // Tests the linkage of the AnyOf matcher.
TEST(LinkTest,TestMatcherAnyOf)673 TEST(LinkTest, TestMatcherAnyOf) {
674 Matcher<int> m = AnyOf(_, Eq(1));
675 EXPECT_TRUE(m.Matches(1));
676 }
677
678 // Tests the linkage of the Not matcher.
TEST(LinkTest,TestMatcherNot)679 TEST(LinkTest, TestMatcherNot) {
680 Matcher<int> m = Not(_);
681 EXPECT_FALSE(m.Matches(1));
682 }
683
684 // Tests the linkage of the MatcherCast<T>() function.
TEST(LinkTest,TestMatcherCast)685 TEST(LinkTest, TestMatcherCast) {
686 Matcher<const char*> m = MatcherCast<const char*>(_);
687 EXPECT_TRUE(m.Matches(nullptr));
688 }
689
690 #endif // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
691