blob: 40554bfe2dd9a44f16d5d5af6caadc73b1a6a74f [file] [log] [blame]
zhanyong.wan38ca64d2009-02-19 22:30:22 +00001// 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// Author: vladl@google.com (Vlad Losev)
31
32// Google Mock - a framework for writing C++ mock classes.
33//
34// This file tests that:
35// a. A header file defining a mock class can be included in multiple
36// translation units without causing a link error.
37// b. Actions and matchers can be instantiated with identical template
38// arguments in different translation units without causing link
39// errors.
40// The following constructs are currently tested:
41// Actions:
42// Return()
43// Return(value)
44// ReturnNull
45// ReturnRef
46// Assign
47// SetArgumentPointee
48// SetArrayArgument
49// SetErrnoAndReturn
50// Invoke(function)
51// Invoke(object, method)
52// InvokeWithoutArgs(function)
53// InvokeWithoutArgs(object, method)
54// InvokeArgument
55// WithArg
56// WithArgs
57// WithoutArgs
58// DoAll
59// DoDefault
60// IgnoreResult
61// Throw
62// ACTION()-generated
63// ACTION_P()-generated
64// ACTION_P2()-generated
65// Matchers:
66// _
67// A
68// An
69// Eq
70// Gt, Lt, Ge, Le, Ne
71// NotNull
72// Ref
73// TypedEq
74// DoubleEq
75// FloatEq
76// NanSensitiveDoubleEq
77// NanSensitiveFloatEq
78// ContainsRegex
79// MatchesRegex
80// EndsWith
81// HasSubstr
82// StartsWith
83// StrCaseEq
84// StrCaseNe
85// StrEq
86// StrNe
87// ElementsAre
88// ElementsAreArray
89// ContainerEq
90// Field
91// Property
92// ResultOf(function)
93// Pointee
94// Truly(predicate)
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 GMOCK_TEST_GMOCK_LINK_TEST_H_
115#define GMOCK_TEST_GMOCK_LINK_TEST_H_
116
117#include <gmock/gmock.h>
118
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000119#if !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000120#include <errno.h>
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000121#endif
122
zhanyong.wanbf550852009-06-09 06:09:53 +0000123#include <gmock/internal/gmock-port.h>
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000124#include <gtest/gtest.h>
125#include <iostream>
126#include <vector>
127
128using testing::_;
129using testing::A;
130using testing::AllOf;
131using testing::AnyOf;
132using testing::Assign;
133using testing::ContainerEq;
134using testing::DoAll;
135using testing::DoDefault;
136using testing::DoubleEq;
137using testing::ElementsAre;
138using testing::ElementsAreArray;
139using testing::EndsWith;
140using testing::Eq;
141using testing::Field;
142using testing::FloatEq;
143using testing::Ge;
144using testing::Gt;
145using testing::HasSubstr;
146using testing::IgnoreResult;
147using testing::Invoke;
148using testing::InvokeArgument;
149using testing::InvokeWithoutArgs;
zhanyong.wan2d970ee2009-09-24 21:41:36 +0000150using testing::IsNull;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000151using testing::Le;
152using testing::Lt;
153using testing::Matcher;
154using testing::MatcherCast;
155using testing::NanSensitiveDoubleEq;
156using testing::NanSensitiveFloatEq;
157using testing::Ne;
158using testing::Not;
159using testing::NotNull;
160using testing::Pointee;
161using testing::Property;
162using testing::Ref;
163using testing::ResultOf;
164using testing::Return;
165using testing::ReturnNull;
166using testing::ReturnRef;
167using testing::SetArgumentPointee;
168using testing::SetArrayArgument;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000169using testing::StartsWith;
170using testing::StrCaseEq;
171using testing::StrCaseNe;
172using testing::StrEq;
173using testing::StrNe;
174using testing::Truly;
175using testing::TypedEq;
176using testing::WithArg;
177using testing::WithArgs;
178using testing::WithoutArgs;
179
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000180#if !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000181using testing::SetErrnoAndReturn;
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000182#endif
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000183
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000184#if GTEST_HAS_EXCEPTIONS
185using testing::Throw;
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000186#endif
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000187
188#if GMOCK_HAS_REGEX
189using testing::ContainsRegex;
190using testing::MatchesRegex;
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000191#endif
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000192
193class Interface {
194 public:
195 virtual ~Interface() {}
196 virtual void VoidFromString(char* str) = 0;
197 virtual char* StringFromString(char* str) = 0;
198 virtual int IntFromString(char* str) = 0;
199 virtual int& IntRefFromString(char* str) = 0;
200 virtual void VoidFromFunc(void(*)(char*)) = 0;
201 virtual void VoidFromIntRef(int& n) = 0;
202 virtual void VoidFromFloat(float n) = 0;
203 virtual void VoidFromDouble(double n) = 0;
204 virtual void VoidFromVector(const std::vector<int>& v) = 0;
205};
206
207class Mock: public Interface {
208 public:
209 MOCK_METHOD1(VoidFromString, void(char* str));
210 MOCK_METHOD1(StringFromString, char*(char* str));
211 MOCK_METHOD1(IntFromString, int(char* str));
212 MOCK_METHOD1(IntRefFromString, int&(char* str));
213 MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
214 MOCK_METHOD1(VoidFromIntRef, void(int& n));
215 MOCK_METHOD1(VoidFromFloat, void(float n));
216 MOCK_METHOD1(VoidFromDouble, void(double n));
217 MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
218};
219
220class InvokeHelper {
221 public:
222 static void StaticVoidFromVoid() {}
223 void VoidFromVoid() {}
224 static void StaticVoidFromString(char*) {}
225 void VoidFromString(char*) {}
226 static int StaticIntFromString(char*) { return 1; }
227 static bool StaticBoolFromString(const char*) { return true; }
228};
229
230class FieldHelper {
231 public:
232 FieldHelper(int field) : field_(field) {}
233 int field() const { return field_; }
234 int field_; // NOLINT -- need external access to field_ to test
235 // the Field matcher.
236};
237
238// Tests the linkage of the ReturnVoid action.
239TEST(LinkTest, TestReturnVoid) {
240 Mock mock;
241
242 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
243 mock.VoidFromString(NULL);
244}
245
246// Tests the linkage of the Return action.
247TEST(LinkTest, TestReturn) {
248 Mock mock;
249 char ch = 'x';
250
251 EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
252 mock.StringFromString(NULL);
253}
254
255// Tests the linkage of the ReturnNull action.
256TEST(LinkTest, TestReturnNull) {
257 Mock mock;
258
259 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
260 mock.VoidFromString(NULL);
261}
262
263// Tests the linkage of the ReturnRef action.
264TEST(LinkTest, TestReturnRef) {
265 Mock mock;
266 int n = 42;
267
268 EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
269 mock.IntRefFromString(NULL);
270}
271
272// Tests the linkage of the Assign action.
273TEST(LinkTest, TestAssign) {
274 Mock mock;
275 char ch = 'x';
276
277 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
278 mock.VoidFromString(NULL);
279}
280
281// Tests the linkage of the SetArgumentPointee action.
282TEST(LinkTest, TestSetArgumentPointee) {
283 Mock mock;
284 char ch = 'x';
285
286 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgumentPointee<0>('y'));
287 mock.VoidFromString(&ch);
288}
289
290// Tests the linkage of the SetArrayArgument action.
291TEST(LinkTest, TestSetArrayArgument) {
292 Mock mock;
293 char ch = 'x';
294 char ch2 = 'y';
295
296 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2,
297 &ch2 + 1));
298 mock.VoidFromString(&ch);
299}
300
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000301#if !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000302
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000303// Tests the linkage of the SetErrnoAndReturn action.
304TEST(LinkTest, TestSetErrnoAndReturn) {
305 Mock mock;
306
307 int saved_errno = errno;
308 EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
309 mock.IntFromString(NULL);
310 errno = saved_errno;
311}
312
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000313#endif // !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000314
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000315// Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
316TEST(LinkTest, TestInvoke) {
317 Mock mock;
318 InvokeHelper test_invoke_helper;
319
320 EXPECT_CALL(mock, VoidFromString(_))
321 .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
322 .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
323 mock.VoidFromString(NULL);
324 mock.VoidFromString(NULL);
325}
326
327// Tests the linkage of the InvokeWithoutArgs action.
328TEST(LinkTest, TestInvokeWithoutArgs) {
329 Mock mock;
330 InvokeHelper test_invoke_helper;
331
332 EXPECT_CALL(mock, VoidFromString(_))
333 .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
334 .WillOnce(InvokeWithoutArgs(&test_invoke_helper,
335 &InvokeHelper::VoidFromVoid));
336 mock.VoidFromString(NULL);
337 mock.VoidFromString(NULL);
338}
339
340// Tests the linkage of the InvokeArgument action.
341TEST(LinkTest, TestInvokeArgument) {
342 Mock mock;
343 char ch = 'x';
344
345 EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
346 mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
347}
348
349// Tests the linkage of the WithArg action.
350TEST(LinkTest, TestWithArg) {
351 Mock mock;
352
353 EXPECT_CALL(mock, VoidFromString(_))
354 .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
355 mock.VoidFromString(NULL);
356}
357
358// Tests the linkage of the WithArgs action.
359TEST(LinkTest, TestWithArgs) {
360 Mock mock;
361
362 EXPECT_CALL(mock, VoidFromString(_))
363 .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
364 mock.VoidFromString(NULL);
365}
366
367// Tests the linkage of the WithoutArgs action.
368TEST(LinkTest, TestWithoutArgs) {
369 Mock mock;
370
371 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
372 mock.VoidFromString(NULL);
373}
374
375// Tests the linkage of the DoAll action.
376TEST(LinkTest, TestDoAll) {
377 Mock mock;
378 char ch = 'x';
379
380 EXPECT_CALL(mock, VoidFromString(_))
381 .WillOnce(DoAll(SetArgumentPointee<0>('y'), Return()));
382 mock.VoidFromString(&ch);
383}
384
385// Tests the linkage of the DoDefault action.
386TEST(LinkTest, TestDoDefault) {
387 Mock mock;
388 char ch = 'x';
389
390 ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
391 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
392 mock.VoidFromString(&ch);
393}
394
395// Tests the linkage of the IgnoreResult action.
396TEST(LinkTest, TestIgnoreResult) {
397 Mock mock;
398
399 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
400 mock.VoidFromString(NULL);
401}
402
403#if GTEST_HAS_EXCEPTIONS
404// Tests the linkage of the Throw action.
405TEST(LinkTest, TestThrow) {
406 Mock mock;
407
408 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
409 EXPECT_THROW(mock.VoidFromString(NULL), int);
410}
411#endif // GTEST_HAS_EXCEPTIONS
412
413// Tests the linkage of actions created using ACTION macro.
414namespace {
415ACTION(Return1) { return 1; }
416}
417
418TEST(LinkTest, TestActionMacro) {
419 Mock mock;
420
421 EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
422 mock.IntFromString(NULL);
423}
424
425// Tests the linkage of actions created using ACTION_P macro.
426namespace {
427ACTION_P(ReturnArgument, ret_value) { return ret_value; }
428}
429
430TEST(LinkTest, TestActionPMacro) {
431 Mock mock;
432
433 EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
434 mock.IntFromString(NULL);
435}
436
437// Tests the linkage of actions created using ACTION_P2 macro.
438namespace {
439ACTION_P2(ReturnEqualsEitherOf, first, second) {
440 return arg0 == first || arg0 == second;
441}
442}
443
444TEST(LinkTest, TestActionP2Macro) {
445 Mock mock;
446 char ch = 'x';
447
448 EXPECT_CALL(mock, IntFromString(_))
449 .WillOnce(ReturnEqualsEitherOf("one", "two"));
450 mock.IntFromString(&ch);
451}
452
453// Tests the linkage of the "_" matcher.
454TEST(LinkTest, TestMatcherAnything) {
455 Mock mock;
456
457 ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
458}
459
460// Tests the linkage of the A matcher.
461TEST(LinkTest, TestMatcherA) {
462 Mock mock;
463
464 ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
465}
466
467// Tests the linkage of the Eq and the "bare value" matcher.
468TEST(LinkTest, TestMatchersEq) {
469 Mock mock;
470 const char* p = "x";
471
472 ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
473 ON_CALL(mock, VoidFromString(const_cast<char*>("y")))
474 .WillByDefault(Return());
475}
476
477// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
478TEST(LinkTest, TestMatchersRelations) {
479 Mock mock;
480
481 ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
482 ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
483 ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
484 ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
485 ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
486}
487
488// Tests the linkage of the NotNull matcher.
489TEST(LinkTest, TestMatcherNotNull) {
490 Mock mock;
491
492 ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
493}
494
zhanyong.wan2d970ee2009-09-24 21:41:36 +0000495// Tests the linkage of the IsNull matcher.
496TEST(LinkTest, TestMatcherIsNull) {
497 Mock mock;
498
499 ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
500}
501
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000502// Tests the linkage of the Ref matcher.
503TEST(LinkTest, TestMatcherRef) {
504 Mock mock;
505 int a = 0;
506
507 ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
508}
509
510// Tests the linkage of the TypedEq matcher.
511TEST(LinkTest, TestMatcherTypedEq) {
512 Mock mock;
zhanyong.wan3fbd2dd2009-03-26 19:06:45 +0000513 long a = 0;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000514
515 ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
516}
517
518// Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
519// NanSensitiveDoubleEq matchers.
520TEST(LinkTest, TestMatchersFloatingPoint) {
521 Mock mock;
522 float a = 0;
523
524 ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
525 ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
526 ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
527 ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
528 .WillByDefault(Return());
529}
530
531#if GMOCK_HAS_REGEX
532// Tests the linkage of the ContainsRegex matcher.
533TEST(LinkTest, TestMatcherContainsRegex) {
534 Mock mock;
535
536 ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
537}
538
539// Tests the linkage of the MatchesRegex matcher.
540TEST(LinkTest, TestMatcherMatchesRegex) {
541 Mock mock;
542
543 ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
544}
545#endif // GMOCK_HAS_REGEX
546
547// Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
548TEST(LinkTest, TestMatchersSubstrings) {
549 Mock mock;
550
551 ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
552 ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
553 ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
554}
555
556// Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
557TEST(LinkTest, TestMatchersStringEquality) {
558 Mock mock;
559 ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
560 ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
561 ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
562 ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
563}
564
565// Tests the linkage of the ElementsAre matcher.
566TEST(LinkTest, TestMatcherElementsAre) {
567 Mock mock;
568
569 ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
570}
571
572// Tests the linkage of the ElementsAreArray matcher.
573TEST(LinkTest, TestMatcherElementsAreArray) {
574 Mock mock;
575 char arr[] = { 'a', 'b' };
576
577 ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
578}
579
580// Tests the linkage of the ContainerEq matcher.
581TEST(LinkTest, TestMatcherContainerEq) {
582 Mock mock;
583 std::vector<int> v;
584
585 ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
586}
587
588// Tests the linkage of the Field matcher.
589TEST(LinkTest, TestMatcherField) {
590 FieldHelper helper(0);
591
592 Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
593 EXPECT_TRUE(m.Matches(helper));
594
595 Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
596 EXPECT_TRUE(m2.Matches(&helper));
597}
598
599// Tests the linkage of the Property matcher.
600TEST(LinkTest, TestMatcherProperty) {
601 FieldHelper helper(0);
602
603 Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
604 EXPECT_TRUE(m.Matches(helper));
605
606 Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
607 EXPECT_TRUE(m2.Matches(&helper));
608}
609
610// Tests the linkage of the ResultOf matcher.
611TEST(LinkTest, TestMatcherResultOf) {
612 Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
613 EXPECT_TRUE(m.Matches(NULL));
614}
615
616// Tests the linkage of the ResultOf matcher.
617TEST(LinkTest, TestMatcherPointee) {
618 int n = 1;
619
620 Matcher<int*> m = Pointee(Eq(1));
621 EXPECT_TRUE(m.Matches(&n));
622}
623
624// Tests the linkage of the Truly matcher.
625TEST(LinkTest, TestMatcherTruly) {
626 Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
627 EXPECT_TRUE(m.Matches(NULL));
628}
629
630// Tests the linkage of the AllOf matcher.
631TEST(LinkTest, TestMatcherAllOf) {
632 Matcher<int> m = AllOf(_, Eq(1));
633 EXPECT_TRUE(m.Matches(1));
634}
635
636// Tests the linkage of the AnyOf matcher.
637TEST(LinkTest, TestMatcherAnyOf) {
638 Matcher<int> m = AnyOf(_, Eq(1));
639 EXPECT_TRUE(m.Matches(1));
640}
641
642// Tests the linkage of the Not matcher.
643TEST(LinkTest, TestMatcherNot) {
644 Matcher<int> m = Not(_);
645 EXPECT_FALSE(m.Matches(1));
646}
647
648// Tests the linkage of the MatcherCast<T>() function.
649TEST(LinkTest, TestMatcherCast) {
650 Matcher<const char*> m = MatcherCast<const char*>(_);
651 EXPECT_TRUE(m.Matches(NULL));
652}
653
654#endif // GMOCK_TEST_GMOCK_LINK_TEST_H_