blob: d9635907939425d23769584319780c1495b673fb [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:
zhanyong.wan32de5f52009-12-23 00:13:23 +0000209 Mock() {}
210
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000211 MOCK_METHOD1(VoidFromString, void(char* str));
212 MOCK_METHOD1(StringFromString, char*(char* str));
213 MOCK_METHOD1(IntFromString, int(char* str));
214 MOCK_METHOD1(IntRefFromString, int&(char* str));
215 MOCK_METHOD1(VoidFromFunc, void(void(*func)(char* str)));
216 MOCK_METHOD1(VoidFromIntRef, void(int& n));
217 MOCK_METHOD1(VoidFromFloat, void(float n));
218 MOCK_METHOD1(VoidFromDouble, void(double n));
219 MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
zhanyong.wan32de5f52009-12-23 00:13:23 +0000220
221 private:
222 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock);
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000223};
224
225class InvokeHelper {
226 public:
227 static void StaticVoidFromVoid() {}
228 void VoidFromVoid() {}
229 static void StaticVoidFromString(char*) {}
230 void VoidFromString(char*) {}
231 static int StaticIntFromString(char*) { return 1; }
232 static bool StaticBoolFromString(const char*) { return true; }
233};
234
235class FieldHelper {
236 public:
zhanyong.wan32de5f52009-12-23 00:13:23 +0000237 FieldHelper(int a_field) : field_(a_field) {}
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000238 int field() const { return field_; }
239 int field_; // NOLINT -- need external access to field_ to test
240 // the Field matcher.
241};
242
243// Tests the linkage of the ReturnVoid action.
244TEST(LinkTest, TestReturnVoid) {
245 Mock mock;
246
247 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
248 mock.VoidFromString(NULL);
249}
250
251// Tests the linkage of the Return action.
252TEST(LinkTest, TestReturn) {
253 Mock mock;
254 char ch = 'x';
255
256 EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
257 mock.StringFromString(NULL);
258}
259
260// Tests the linkage of the ReturnNull action.
261TEST(LinkTest, TestReturnNull) {
262 Mock mock;
263
264 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
265 mock.VoidFromString(NULL);
266}
267
268// Tests the linkage of the ReturnRef action.
269TEST(LinkTest, TestReturnRef) {
270 Mock mock;
271 int n = 42;
272
273 EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
274 mock.IntRefFromString(NULL);
275}
276
277// Tests the linkage of the Assign action.
278TEST(LinkTest, TestAssign) {
279 Mock mock;
280 char ch = 'x';
281
282 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
283 mock.VoidFromString(NULL);
284}
285
286// Tests the linkage of the SetArgumentPointee action.
287TEST(LinkTest, TestSetArgumentPointee) {
288 Mock mock;
289 char ch = 'x';
290
291 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgumentPointee<0>('y'));
292 mock.VoidFromString(&ch);
293}
294
295// Tests the linkage of the SetArrayArgument action.
296TEST(LinkTest, TestSetArrayArgument) {
297 Mock mock;
298 char ch = 'x';
299 char ch2 = 'y';
300
301 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArrayArgument<0>(&ch2,
302 &ch2 + 1));
303 mock.VoidFromString(&ch);
304}
305
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000306#if !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000307
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000308// Tests the linkage of the SetErrnoAndReturn action.
309TEST(LinkTest, TestSetErrnoAndReturn) {
310 Mock mock;
311
312 int saved_errno = errno;
313 EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
314 mock.IntFromString(NULL);
315 errno = saved_errno;
316}
317
zhanyong.wanf7af24c2009-09-24 21:17:24 +0000318#endif // !GTEST_OS_WINDOWS_MOBILE
zhanyong.wan5b5d62f2009-03-11 23:37:56 +0000319
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000320// Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
321TEST(LinkTest, TestInvoke) {
322 Mock mock;
323 InvokeHelper test_invoke_helper;
324
325 EXPECT_CALL(mock, VoidFromString(_))
326 .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
327 .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
328 mock.VoidFromString(NULL);
329 mock.VoidFromString(NULL);
330}
331
332// Tests the linkage of the InvokeWithoutArgs action.
333TEST(LinkTest, TestInvokeWithoutArgs) {
334 Mock mock;
335 InvokeHelper test_invoke_helper;
336
337 EXPECT_CALL(mock, VoidFromString(_))
338 .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
339 .WillOnce(InvokeWithoutArgs(&test_invoke_helper,
340 &InvokeHelper::VoidFromVoid));
341 mock.VoidFromString(NULL);
342 mock.VoidFromString(NULL);
343}
344
345// Tests the linkage of the InvokeArgument action.
346TEST(LinkTest, TestInvokeArgument) {
347 Mock mock;
348 char ch = 'x';
349
350 EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
351 mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
352}
353
354// Tests the linkage of the WithArg action.
355TEST(LinkTest, TestWithArg) {
356 Mock mock;
357
358 EXPECT_CALL(mock, VoidFromString(_))
359 .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
360 mock.VoidFromString(NULL);
361}
362
363// Tests the linkage of the WithArgs action.
364TEST(LinkTest, TestWithArgs) {
365 Mock mock;
366
367 EXPECT_CALL(mock, VoidFromString(_))
368 .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
369 mock.VoidFromString(NULL);
370}
371
372// Tests the linkage of the WithoutArgs action.
373TEST(LinkTest, TestWithoutArgs) {
374 Mock mock;
375
376 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
377 mock.VoidFromString(NULL);
378}
379
380// Tests the linkage of the DoAll action.
381TEST(LinkTest, TestDoAll) {
382 Mock mock;
383 char ch = 'x';
384
385 EXPECT_CALL(mock, VoidFromString(_))
386 .WillOnce(DoAll(SetArgumentPointee<0>('y'), Return()));
387 mock.VoidFromString(&ch);
388}
389
390// Tests the linkage of the DoDefault action.
391TEST(LinkTest, TestDoDefault) {
392 Mock mock;
393 char ch = 'x';
394
395 ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
396 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
397 mock.VoidFromString(&ch);
398}
399
400// Tests the linkage of the IgnoreResult action.
401TEST(LinkTest, TestIgnoreResult) {
402 Mock mock;
403
404 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
405 mock.VoidFromString(NULL);
406}
407
408#if GTEST_HAS_EXCEPTIONS
409// Tests the linkage of the Throw action.
410TEST(LinkTest, TestThrow) {
411 Mock mock;
412
413 EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
414 EXPECT_THROW(mock.VoidFromString(NULL), int);
415}
416#endif // GTEST_HAS_EXCEPTIONS
417
zhanyong.wan32de5f52009-12-23 00:13:23 +0000418// The ACTION*() macros trigger warning C4100 (unreferenced formal
419// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
420// the macro definition, as the warnings are generated when the macro
421// is expanded and macro expansion cannot contain #pragma. Therefore
422// we suppress them here.
423#ifdef _MSC_VER
424#pragma warning(push)
425#pragma warning(disable:4100)
426#endif
427
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000428// Tests the linkage of actions created using ACTION macro.
429namespace {
430ACTION(Return1) { return 1; }
431}
432
433TEST(LinkTest, TestActionMacro) {
434 Mock mock;
435
436 EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
437 mock.IntFromString(NULL);
438}
439
440// Tests the linkage of actions created using ACTION_P macro.
441namespace {
442ACTION_P(ReturnArgument, ret_value) { return ret_value; }
443}
444
445TEST(LinkTest, TestActionPMacro) {
446 Mock mock;
447
448 EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
449 mock.IntFromString(NULL);
450}
451
452// Tests the linkage of actions created using ACTION_P2 macro.
453namespace {
454ACTION_P2(ReturnEqualsEitherOf, first, second) {
455 return arg0 == first || arg0 == second;
456}
457}
458
zhanyong.wan32de5f52009-12-23 00:13:23 +0000459#ifdef _MSC_VER
460#pragma warning(pop)
461#endif
462
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000463TEST(LinkTest, TestActionP2Macro) {
464 Mock mock;
465 char ch = 'x';
466
467 EXPECT_CALL(mock, IntFromString(_))
468 .WillOnce(ReturnEqualsEitherOf("one", "two"));
469 mock.IntFromString(&ch);
470}
471
472// Tests the linkage of the "_" matcher.
473TEST(LinkTest, TestMatcherAnything) {
474 Mock mock;
475
476 ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
477}
478
479// Tests the linkage of the A matcher.
480TEST(LinkTest, TestMatcherA) {
481 Mock mock;
482
483 ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
484}
485
486// Tests the linkage of the Eq and the "bare value" matcher.
487TEST(LinkTest, TestMatchersEq) {
488 Mock mock;
489 const char* p = "x";
490
491 ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
492 ON_CALL(mock, VoidFromString(const_cast<char*>("y")))
493 .WillByDefault(Return());
494}
495
496// Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
497TEST(LinkTest, TestMatchersRelations) {
498 Mock mock;
499
500 ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
501 ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
502 ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
503 ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
504 ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
505}
506
507// Tests the linkage of the NotNull matcher.
508TEST(LinkTest, TestMatcherNotNull) {
509 Mock mock;
510
511 ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
512}
513
zhanyong.wan2d970ee2009-09-24 21:41:36 +0000514// Tests the linkage of the IsNull matcher.
515TEST(LinkTest, TestMatcherIsNull) {
516 Mock mock;
517
518 ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
519}
520
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000521// Tests the linkage of the Ref matcher.
522TEST(LinkTest, TestMatcherRef) {
523 Mock mock;
524 int a = 0;
525
526 ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
527}
528
529// Tests the linkage of the TypedEq matcher.
530TEST(LinkTest, TestMatcherTypedEq) {
531 Mock mock;
zhanyong.wan3fbd2dd2009-03-26 19:06:45 +0000532 long a = 0;
zhanyong.wan38ca64d2009-02-19 22:30:22 +0000533
534 ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
535}
536
537// Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
538// NanSensitiveDoubleEq matchers.
539TEST(LinkTest, TestMatchersFloatingPoint) {
540 Mock mock;
541 float a = 0;
542
543 ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
544 ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
545 ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
546 ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
547 .WillByDefault(Return());
548}
549
550#if GMOCK_HAS_REGEX
551// Tests the linkage of the ContainsRegex matcher.
552TEST(LinkTest, TestMatcherContainsRegex) {
553 Mock mock;
554
555 ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
556}
557
558// Tests the linkage of the MatchesRegex matcher.
559TEST(LinkTest, TestMatcherMatchesRegex) {
560 Mock mock;
561
562 ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
563}
564#endif // GMOCK_HAS_REGEX
565
566// Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
567TEST(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.
576TEST(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.
585TEST(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.
592TEST(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 ContainerEq matcher.
600TEST(LinkTest, TestMatcherContainerEq) {
601 Mock mock;
602 std::vector<int> v;
603
604 ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
605}
606
607// Tests the linkage of the Field matcher.
608TEST(LinkTest, TestMatcherField) {
609 FieldHelper helper(0);
610
611 Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
612 EXPECT_TRUE(m.Matches(helper));
613
614 Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
615 EXPECT_TRUE(m2.Matches(&helper));
616}
617
618// Tests the linkage of the Property matcher.
619TEST(LinkTest, TestMatcherProperty) {
620 FieldHelper helper(0);
621
622 Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
623 EXPECT_TRUE(m.Matches(helper));
624
625 Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
626 EXPECT_TRUE(m2.Matches(&helper));
627}
628
629// Tests the linkage of the ResultOf matcher.
630TEST(LinkTest, TestMatcherResultOf) {
631 Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
632 EXPECT_TRUE(m.Matches(NULL));
633}
634
635// Tests the linkage of the ResultOf matcher.
636TEST(LinkTest, TestMatcherPointee) {
637 int n = 1;
638
639 Matcher<int*> m = Pointee(Eq(1));
640 EXPECT_TRUE(m.Matches(&n));
641}
642
643// Tests the linkage of the Truly matcher.
644TEST(LinkTest, TestMatcherTruly) {
645 Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
646 EXPECT_TRUE(m.Matches(NULL));
647}
648
649// Tests the linkage of the AllOf matcher.
650TEST(LinkTest, TestMatcherAllOf) {
651 Matcher<int> m = AllOf(_, Eq(1));
652 EXPECT_TRUE(m.Matches(1));
653}
654
655// Tests the linkage of the AnyOf matcher.
656TEST(LinkTest, TestMatcherAnyOf) {
657 Matcher<int> m = AnyOf(_, Eq(1));
658 EXPECT_TRUE(m.Matches(1));
659}
660
661// Tests the linkage of the Not matcher.
662TEST(LinkTest, TestMatcherNot) {
663 Matcher<int> m = Not(_);
664 EXPECT_FALSE(m.Matches(1));
665}
666
667// Tests the linkage of the MatcherCast<T>() function.
668TEST(LinkTest, TestMatcherCast) {
669 Matcher<const char*> m = MatcherCast<const char*>(_);
670 EXPECT_TRUE(m.Matches(NULL));
671}
672
673#endif // GMOCK_TEST_GMOCK_LINK_TEST_H_