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 Mock(const Mock&) = delete;
225 Mock& operator=(const Mock&) = delete;
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(_))
305 .WillOnce(SetArrayArgument<0>(&ch2, &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(
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.
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 } // namespace
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 } // namespace
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 } // namespace
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"))).WillByDefault(Return());
496 }
497
498 // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
TEST(LinkTest,TestMatchersRelations)499 TEST(LinkTest, TestMatchersRelations) {
500 Mock mock;
501
502 ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
503 ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
504 ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
505 ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
506 ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
507 }
508
509 // Tests the linkage of the NotNull matcher.
TEST(LinkTest,TestMatcherNotNull)510 TEST(LinkTest, TestMatcherNotNull) {
511 Mock mock;
512
513 ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
514 }
515
516 // Tests the linkage of the IsNull matcher.
TEST(LinkTest,TestMatcherIsNull)517 TEST(LinkTest, TestMatcherIsNull) {
518 Mock mock;
519
520 ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
521 }
522
523 // Tests the linkage of the Ref matcher.
TEST(LinkTest,TestMatcherRef)524 TEST(LinkTest, TestMatcherRef) {
525 Mock mock;
526 int a = 0;
527
528 ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
529 }
530
531 // Tests the linkage of the TypedEq matcher.
TEST(LinkTest,TestMatcherTypedEq)532 TEST(LinkTest, TestMatcherTypedEq) {
533 Mock mock;
534 long a = 0;
535
536 ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
537 }
538
539 // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
540 // NanSensitiveDoubleEq matchers.
TEST(LinkTest,TestMatchersFloatingPoint)541 TEST(LinkTest, TestMatchersFloatingPoint) {
542 Mock mock;
543 float a = 0;
544
545 ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
546 ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
547 ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
548 ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
549 .WillByDefault(Return());
550 }
551
552 // Tests the linkage of the ContainsRegex matcher.
TEST(LinkTest,TestMatcherContainsRegex)553 TEST(LinkTest, TestMatcherContainsRegex) {
554 Mock mock;
555
556 ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
557 }
558
559 // Tests the linkage of the MatchesRegex matcher.
TEST(LinkTest,TestMatcherMatchesRegex)560 TEST(LinkTest, TestMatcherMatchesRegex) {
561 Mock mock;
562
563 ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
564 }
565
566 // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
TEST(LinkTest,TestMatchersSubstrings)567 TEST(LinkTest, TestMatchersSubstrings) {
568 Mock mock;
569
570 ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
571 ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
572 ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
573 }
574
575 // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
TEST(LinkTest,TestMatchersStringEquality)576 TEST(LinkTest, TestMatchersStringEquality) {
577 Mock mock;
578 ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
579 ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
580 ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
581 ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
582 }
583
584 // Tests the linkage of the ElementsAre matcher.
TEST(LinkTest,TestMatcherElementsAre)585 TEST(LinkTest, TestMatcherElementsAre) {
586 Mock mock;
587
588 ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
589 }
590
591 // Tests the linkage of the ElementsAreArray matcher.
TEST(LinkTest,TestMatcherElementsAreArray)592 TEST(LinkTest, TestMatcherElementsAreArray) {
593 Mock mock;
594 char arr[] = {'a', 'b'};
595
596 ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
597 }
598
599 // Tests the linkage of the IsSubsetOf matcher.
TEST(LinkTest,TestMatcherIsSubsetOf)600 TEST(LinkTest, TestMatcherIsSubsetOf) {
601 Mock mock;
602 char arr[] = {'a', 'b'};
603
604 ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
605 }
606
607 // Tests the linkage of the IsSupersetOf matcher.
TEST(LinkTest,TestMatcherIsSupersetOf)608 TEST(LinkTest, TestMatcherIsSupersetOf) {
609 Mock mock;
610 char arr[] = {'a', 'b'};
611
612 ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
613 }
614
615 // Tests the linkage of the ContainerEq matcher.
TEST(LinkTest,TestMatcherContainerEq)616 TEST(LinkTest, TestMatcherContainerEq) {
617 Mock mock;
618 std::vector<int> v;
619
620 ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
621 }
622
623 // Tests the linkage of the Field matcher.
TEST(LinkTest,TestMatcherField)624 TEST(LinkTest, TestMatcherField) {
625 FieldHelper helper(0);
626
627 Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
628 EXPECT_TRUE(m.Matches(helper));
629
630 Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
631 EXPECT_TRUE(m2.Matches(&helper));
632 }
633
634 // Tests the linkage of the Property matcher.
TEST(LinkTest,TestMatcherProperty)635 TEST(LinkTest, TestMatcherProperty) {
636 FieldHelper helper(0);
637
638 Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
639 EXPECT_TRUE(m.Matches(helper));
640
641 Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
642 EXPECT_TRUE(m2.Matches(&helper));
643 }
644
645 // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherResultOf)646 TEST(LinkTest, TestMatcherResultOf) {
647 Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
648 EXPECT_TRUE(m.Matches(nullptr));
649 }
650
651 // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherPointee)652 TEST(LinkTest, TestMatcherPointee) {
653 int n = 1;
654
655 Matcher<int*> m = Pointee(Eq(1));
656 EXPECT_TRUE(m.Matches(&n));
657 }
658
659 // Tests the linkage of the Truly matcher.
TEST(LinkTest,TestMatcherTruly)660 TEST(LinkTest, TestMatcherTruly) {
661 Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
662 EXPECT_TRUE(m.Matches(nullptr));
663 }
664
665 // Tests the linkage of the AllOf matcher.
TEST(LinkTest,TestMatcherAllOf)666 TEST(LinkTest, TestMatcherAllOf) {
667 Matcher<int> m = AllOf(_, Eq(1));
668 EXPECT_TRUE(m.Matches(1));
669 }
670
671 // Tests the linkage of the AnyOf matcher.
TEST(LinkTest,TestMatcherAnyOf)672 TEST(LinkTest, TestMatcherAnyOf) {
673 Matcher<int> m = AnyOf(_, Eq(1));
674 EXPECT_TRUE(m.Matches(1));
675 }
676
677 // Tests the linkage of the Not matcher.
TEST(LinkTest,TestMatcherNot)678 TEST(LinkTest, TestMatcherNot) {
679 Matcher<int> m = Not(_);
680 EXPECT_FALSE(m.Matches(1));
681 }
682
683 // Tests the linkage of the MatcherCast<T>() function.
TEST(LinkTest,TestMatcherCast)684 TEST(LinkTest, TestMatcherCast) {
685 Matcher<const char*> m = MatcherCast<const char*>(_);
686 EXPECT_TRUE(m.Matches(nullptr));
687 }
688
689 #endif // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
690