xref: /freebsd/contrib/googletest/googlemock/test/gmock_link_test.h (revision 5ca8c28cd8c725b81781201cfdb5f9969396f934)
1b89a7cc2SEnji Cooper // Copyright 2009, Google Inc.
2b89a7cc2SEnji Cooper // All rights reserved.
3b89a7cc2SEnji Cooper //
4b89a7cc2SEnji Cooper // Redistribution and use in source and binary forms, with or without
5b89a7cc2SEnji Cooper // modification, are permitted provided that the following conditions are
6b89a7cc2SEnji Cooper // met:
7b89a7cc2SEnji Cooper //
8b89a7cc2SEnji Cooper //     * Redistributions of source code must retain the above copyright
9b89a7cc2SEnji Cooper // notice, this list of conditions and the following disclaimer.
10b89a7cc2SEnji Cooper //     * Redistributions in binary form must reproduce the above
11b89a7cc2SEnji Cooper // copyright notice, this list of conditions and the following disclaimer
12b89a7cc2SEnji Cooper // in the documentation and/or other materials provided with the
13b89a7cc2SEnji Cooper // distribution.
14b89a7cc2SEnji Cooper //     * Neither the name of Google Inc. nor the names of its
15b89a7cc2SEnji Cooper // contributors may be used to endorse or promote products derived from
16b89a7cc2SEnji Cooper // this software without specific prior written permission.
17b89a7cc2SEnji Cooper //
18b89a7cc2SEnji Cooper // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19b89a7cc2SEnji Cooper // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20b89a7cc2SEnji Cooper // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21b89a7cc2SEnji Cooper // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22b89a7cc2SEnji Cooper // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23b89a7cc2SEnji Cooper // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24b89a7cc2SEnji Cooper // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25b89a7cc2SEnji Cooper // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26b89a7cc2SEnji Cooper // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27b89a7cc2SEnji Cooper // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28b89a7cc2SEnji Cooper // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29b89a7cc2SEnji Cooper 
30b89a7cc2SEnji Cooper // Google Mock - a framework for writing C++ mock classes.
31b89a7cc2SEnji Cooper //
32b89a7cc2SEnji Cooper // This file tests that:
33b89a7cc2SEnji Cooper // a. A header file defining a mock class can be included in multiple
34b89a7cc2SEnji Cooper //    translation units without causing a link error.
35b89a7cc2SEnji Cooper // b. Actions and matchers can be instantiated with identical template
36b89a7cc2SEnji Cooper //    arguments in different translation units without causing link
37b89a7cc2SEnji Cooper //    errors.
38b89a7cc2SEnji Cooper //    The following constructs are currently tested:
39b89a7cc2SEnji Cooper //    Actions:
40b89a7cc2SEnji Cooper //      Return()
41b89a7cc2SEnji Cooper //      Return(value)
42b89a7cc2SEnji Cooper //      ReturnNull
43b89a7cc2SEnji Cooper //      ReturnRef
44b89a7cc2SEnji Cooper //      Assign
45b89a7cc2SEnji Cooper //      SetArgPointee
46b89a7cc2SEnji Cooper //      SetArrayArgument
47b89a7cc2SEnji Cooper //      SetErrnoAndReturn
48b89a7cc2SEnji Cooper //      Invoke(function)
49b89a7cc2SEnji Cooper //      Invoke(object, method)
50b89a7cc2SEnji Cooper //      InvokeWithoutArgs(function)
51b89a7cc2SEnji Cooper //      InvokeWithoutArgs(object, method)
52b89a7cc2SEnji Cooper //      InvokeArgument
53b89a7cc2SEnji Cooper //      WithArg
54b89a7cc2SEnji Cooper //      WithArgs
55b89a7cc2SEnji Cooper //      WithoutArgs
56b89a7cc2SEnji Cooper //      DoAll
57b89a7cc2SEnji Cooper //      DoDefault
58b89a7cc2SEnji Cooper //      IgnoreResult
59b89a7cc2SEnji Cooper //      Throw
60b89a7cc2SEnji Cooper //      ACTION()-generated
61b89a7cc2SEnji Cooper //      ACTION_P()-generated
62b89a7cc2SEnji Cooper //      ACTION_P2()-generated
63b89a7cc2SEnji Cooper //    Matchers:
64b89a7cc2SEnji Cooper //      _
65b89a7cc2SEnji Cooper //      A
66b89a7cc2SEnji Cooper //      An
67b89a7cc2SEnji Cooper //      Eq
68b89a7cc2SEnji Cooper //      Gt, Lt, Ge, Le, Ne
69b89a7cc2SEnji Cooper //      NotNull
70b89a7cc2SEnji Cooper //      Ref
71b89a7cc2SEnji Cooper //      TypedEq
72b89a7cc2SEnji Cooper //      DoubleEq
73b89a7cc2SEnji Cooper //      FloatEq
74b89a7cc2SEnji Cooper //      NanSensitiveDoubleEq
75b89a7cc2SEnji Cooper //      NanSensitiveFloatEq
76b89a7cc2SEnji Cooper //      ContainsRegex
77b89a7cc2SEnji Cooper //      MatchesRegex
78b89a7cc2SEnji Cooper //      EndsWith
79b89a7cc2SEnji Cooper //      HasSubstr
80b89a7cc2SEnji Cooper //      StartsWith
81b89a7cc2SEnji Cooper //      StrCaseEq
82b89a7cc2SEnji Cooper //      StrCaseNe
83b89a7cc2SEnji Cooper //      StrEq
84b89a7cc2SEnji Cooper //      StrNe
85b89a7cc2SEnji Cooper //      ElementsAre
86b89a7cc2SEnji Cooper //      ElementsAreArray
87b89a7cc2SEnji Cooper //      ContainerEq
88b89a7cc2SEnji Cooper //      Field
89b89a7cc2SEnji Cooper //      Property
90b89a7cc2SEnji Cooper //      ResultOf(function)
91b89a7cc2SEnji Cooper //      ResultOf(callback)
92b89a7cc2SEnji Cooper //      Pointee
93b89a7cc2SEnji Cooper //      Truly(predicate)
94b89a7cc2SEnji Cooper //      AddressSatisfies
95b89a7cc2SEnji Cooper //      AllOf
96b89a7cc2SEnji Cooper //      AnyOf
97b89a7cc2SEnji Cooper //      Not
98b89a7cc2SEnji Cooper //      MatcherCast<T>
99b89a7cc2SEnji Cooper //
100b89a7cc2SEnji Cooper //  Please note: this test does not verify the functioning of these
101b89a7cc2SEnji Cooper //  constructs, only that the programs using them will link successfully.
102b89a7cc2SEnji Cooper //
103b89a7cc2SEnji Cooper // Implementation note:
104b89a7cc2SEnji Cooper // This test requires identical definitions of Interface and Mock to be
105b89a7cc2SEnji Cooper // included in different translation units.  We achieve this by writing
106b89a7cc2SEnji Cooper // them in this header and #including it in gmock_link_test.cc and
107b89a7cc2SEnji Cooper // gmock_link2_test.cc.  Because the symbols generated by the compiler for
108b89a7cc2SEnji Cooper // those constructs must be identical in both translation units,
109b89a7cc2SEnji Cooper // definitions of Interface and Mock tests MUST be kept in the SAME
110b89a7cc2SEnji Cooper // NON-ANONYMOUS namespace in this file.  The test fixture class LinkTest
111b89a7cc2SEnji Cooper // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in
112b89a7cc2SEnji Cooper // gmock_link2_test.cc to avoid producing linker errors.
113b89a7cc2SEnji Cooper 
11428f6c2f2SEnji Cooper #ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
11528f6c2f2SEnji Cooper #define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
116b89a7cc2SEnji Cooper 
117b89a7cc2SEnji Cooper #include "gmock/gmock.h"
118b89a7cc2SEnji Cooper 
11928f6c2f2SEnji Cooper #ifndef GTEST_OS_WINDOWS_MOBILE
120b89a7cc2SEnji Cooper #include <errno.h>
121b89a7cc2SEnji Cooper #endif
122b89a7cc2SEnji Cooper 
123b89a7cc2SEnji Cooper #include <iostream>
124b89a7cc2SEnji Cooper #include <vector>
125b89a7cc2SEnji Cooper 
126b89a7cc2SEnji Cooper #include "gtest/gtest.h"
127b89a7cc2SEnji Cooper #include "gtest/internal/gtest-port.h"
128b89a7cc2SEnji Cooper 
129b89a7cc2SEnji Cooper using testing::_;
130b89a7cc2SEnji Cooper using testing::A;
131b89a7cc2SEnji Cooper using testing::Action;
132b89a7cc2SEnji Cooper using testing::AllOf;
133b89a7cc2SEnji Cooper using testing::AnyOf;
134b89a7cc2SEnji Cooper using testing::Assign;
135b89a7cc2SEnji Cooper using testing::ContainerEq;
136b89a7cc2SEnji Cooper using testing::DoAll;
137b89a7cc2SEnji Cooper using testing::DoDefault;
138b89a7cc2SEnji Cooper using testing::DoubleEq;
139b89a7cc2SEnji Cooper using testing::ElementsAre;
140b89a7cc2SEnji Cooper using testing::ElementsAreArray;
141b89a7cc2SEnji Cooper using testing::EndsWith;
142b89a7cc2SEnji Cooper using testing::Eq;
143b89a7cc2SEnji Cooper using testing::Field;
144b89a7cc2SEnji Cooper using testing::FloatEq;
145b89a7cc2SEnji Cooper using testing::Ge;
146b89a7cc2SEnji Cooper using testing::Gt;
147b89a7cc2SEnji Cooper using testing::HasSubstr;
148b89a7cc2SEnji Cooper using testing::IgnoreResult;
149b89a7cc2SEnji Cooper using testing::Invoke;
150b89a7cc2SEnji Cooper using testing::InvokeArgument;
151b89a7cc2SEnji Cooper using testing::InvokeWithoutArgs;
152b89a7cc2SEnji Cooper using testing::IsNull;
153b89a7cc2SEnji Cooper using testing::IsSubsetOf;
154b89a7cc2SEnji Cooper using testing::IsSupersetOf;
155b89a7cc2SEnji Cooper using testing::Le;
156b89a7cc2SEnji Cooper using testing::Lt;
157b89a7cc2SEnji Cooper using testing::Matcher;
158b89a7cc2SEnji Cooper using testing::MatcherCast;
159b89a7cc2SEnji Cooper using testing::NanSensitiveDoubleEq;
160b89a7cc2SEnji Cooper using testing::NanSensitiveFloatEq;
161b89a7cc2SEnji Cooper using testing::Ne;
162b89a7cc2SEnji Cooper using testing::Not;
163b89a7cc2SEnji Cooper using testing::NotNull;
164b89a7cc2SEnji Cooper using testing::Pointee;
165b89a7cc2SEnji Cooper using testing::Property;
166b89a7cc2SEnji Cooper using testing::Ref;
167b89a7cc2SEnji Cooper using testing::ResultOf;
168b89a7cc2SEnji Cooper using testing::Return;
169b89a7cc2SEnji Cooper using testing::ReturnNull;
170b89a7cc2SEnji Cooper using testing::ReturnRef;
171b89a7cc2SEnji Cooper using testing::SetArgPointee;
172b89a7cc2SEnji Cooper using testing::SetArrayArgument;
173b89a7cc2SEnji Cooper using testing::StartsWith;
174b89a7cc2SEnji Cooper using testing::StrCaseEq;
175b89a7cc2SEnji Cooper using testing::StrCaseNe;
176b89a7cc2SEnji Cooper using testing::StrEq;
177b89a7cc2SEnji Cooper using testing::StrNe;
178b89a7cc2SEnji Cooper using testing::Truly;
179b89a7cc2SEnji Cooper using testing::TypedEq;
180b89a7cc2SEnji Cooper using testing::WithArg;
181b89a7cc2SEnji Cooper using testing::WithArgs;
182b89a7cc2SEnji Cooper using testing::WithoutArgs;
183b89a7cc2SEnji Cooper 
18428f6c2f2SEnji Cooper #ifndef GTEST_OS_WINDOWS_MOBILE
185b89a7cc2SEnji Cooper using testing::SetErrnoAndReturn;
186b89a7cc2SEnji Cooper #endif
187b89a7cc2SEnji Cooper 
188b89a7cc2SEnji Cooper #if GTEST_HAS_EXCEPTIONS
189b89a7cc2SEnji Cooper using testing::Throw;
190*5ca8c28cSEnji Cooper using testing::Rethrow;
191b89a7cc2SEnji Cooper #endif
192b89a7cc2SEnji Cooper 
193b89a7cc2SEnji Cooper using testing::ContainsRegex;
194b89a7cc2SEnji Cooper using testing::MatchesRegex;
195b89a7cc2SEnji Cooper 
196b89a7cc2SEnji Cooper class Interface {
197b89a7cc2SEnji Cooper  public:
19828f6c2f2SEnji Cooper   virtual ~Interface() = default;
199b89a7cc2SEnji Cooper   virtual void VoidFromString(char* str) = 0;
200b89a7cc2SEnji Cooper   virtual char* StringFromString(char* str) = 0;
201b89a7cc2SEnji Cooper   virtual int IntFromString(char* str) = 0;
202b89a7cc2SEnji Cooper   virtual int& IntRefFromString(char* str) = 0;
203b89a7cc2SEnji Cooper   virtual void VoidFromFunc(void (*func)(char* str)) = 0;
204b89a7cc2SEnji Cooper   virtual void VoidFromIntRef(int& n) = 0;  // NOLINT
205b89a7cc2SEnji Cooper   virtual void VoidFromFloat(float n) = 0;
206b89a7cc2SEnji Cooper   virtual void VoidFromDouble(double n) = 0;
207b89a7cc2SEnji Cooper   virtual void VoidFromVector(const std::vector<int>& v) = 0;
208b89a7cc2SEnji Cooper };
209b89a7cc2SEnji Cooper 
210b89a7cc2SEnji Cooper class Mock : public Interface {
211b89a7cc2SEnji Cooper  public:
21228f6c2f2SEnji Cooper   Mock() = default;
213b89a7cc2SEnji Cooper 
214b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromString, void(char* str));
215b89a7cc2SEnji Cooper   MOCK_METHOD1(StringFromString, char*(char* str));
216b89a7cc2SEnji Cooper   MOCK_METHOD1(IntFromString, int(char* str));
217b89a7cc2SEnji Cooper   MOCK_METHOD1(IntRefFromString, int&(char* str));
218b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
219b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromIntRef, void(int& n));  // NOLINT
220b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromFloat, void(float n));
221b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromDouble, void(double n));
222b89a7cc2SEnji Cooper   MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
223b89a7cc2SEnji Cooper 
224b89a7cc2SEnji Cooper  private:
22528f6c2f2SEnji Cooper   Mock(const Mock&) = delete;
22628f6c2f2SEnji Cooper   Mock& operator=(const Mock&) = delete;
227b89a7cc2SEnji Cooper };
228b89a7cc2SEnji Cooper 
229b89a7cc2SEnji Cooper class InvokeHelper {
230b89a7cc2SEnji Cooper  public:
StaticVoidFromVoid()231b89a7cc2SEnji Cooper   static void StaticVoidFromVoid() {}
VoidFromVoid()232b89a7cc2SEnji Cooper   void VoidFromVoid() {}
StaticVoidFromString(char *)233b89a7cc2SEnji Cooper   static void StaticVoidFromString(char* /* str */) {}
VoidFromString(char *)234b89a7cc2SEnji Cooper   void VoidFromString(char* /* str */) {}
StaticIntFromString(char *)235b89a7cc2SEnji Cooper   static int StaticIntFromString(char* /* str */) { return 1; }
StaticBoolFromString(const char *)236b89a7cc2SEnji Cooper   static bool StaticBoolFromString(const char* /* str */) { return true; }
237b89a7cc2SEnji Cooper };
238b89a7cc2SEnji Cooper 
239b89a7cc2SEnji Cooper class FieldHelper {
240b89a7cc2SEnji Cooper  public:
FieldHelper(int a_field)241b89a7cc2SEnji Cooper   explicit FieldHelper(int a_field) : field_(a_field) {}
field()242b89a7cc2SEnji Cooper   int field() const { return field_; }
243b89a7cc2SEnji Cooper   int field_;  // NOLINT -- need external access to field_ to test
244b89a7cc2SEnji Cooper                //           the Field matcher.
245b89a7cc2SEnji Cooper };
246b89a7cc2SEnji Cooper 
247b89a7cc2SEnji Cooper // Tests the linkage of the ReturnVoid action.
TEST(LinkTest,TestReturnVoid)248b89a7cc2SEnji Cooper TEST(LinkTest, TestReturnVoid) {
249b89a7cc2SEnji Cooper   Mock mock;
250b89a7cc2SEnji Cooper 
251b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
25228f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
253b89a7cc2SEnji Cooper }
254b89a7cc2SEnji Cooper 
255b89a7cc2SEnji Cooper // Tests the linkage of the Return action.
TEST(LinkTest,TestReturn)256b89a7cc2SEnji Cooper TEST(LinkTest, TestReturn) {
257b89a7cc2SEnji Cooper   Mock mock;
258b89a7cc2SEnji Cooper   char ch = 'x';
259b89a7cc2SEnji Cooper 
260b89a7cc2SEnji Cooper   EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
26128f6c2f2SEnji Cooper   mock.StringFromString(nullptr);
262b89a7cc2SEnji Cooper }
263b89a7cc2SEnji Cooper 
264b89a7cc2SEnji Cooper // Tests the linkage of the ReturnNull action.
TEST(LinkTest,TestReturnNull)265b89a7cc2SEnji Cooper TEST(LinkTest, TestReturnNull) {
266b89a7cc2SEnji Cooper   Mock mock;
267b89a7cc2SEnji Cooper 
268b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
26928f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
270b89a7cc2SEnji Cooper }
271b89a7cc2SEnji Cooper 
272b89a7cc2SEnji Cooper // Tests the linkage of the ReturnRef action.
TEST(LinkTest,TestReturnRef)273b89a7cc2SEnji Cooper TEST(LinkTest, TestReturnRef) {
274b89a7cc2SEnji Cooper   Mock mock;
275b89a7cc2SEnji Cooper   int n = 42;
276b89a7cc2SEnji Cooper 
277b89a7cc2SEnji Cooper   EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
27828f6c2f2SEnji Cooper   mock.IntRefFromString(nullptr);
279b89a7cc2SEnji Cooper }
280b89a7cc2SEnji Cooper 
281b89a7cc2SEnji Cooper // Tests the linkage of the Assign action.
TEST(LinkTest,TestAssign)282b89a7cc2SEnji Cooper TEST(LinkTest, TestAssign) {
283b89a7cc2SEnji Cooper   Mock mock;
284b89a7cc2SEnji Cooper   char ch = 'x';
285b89a7cc2SEnji Cooper 
286b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
28728f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
288b89a7cc2SEnji Cooper }
289b89a7cc2SEnji Cooper 
290b89a7cc2SEnji Cooper // Tests the linkage of the SetArgPointee action.
TEST(LinkTest,TestSetArgPointee)291b89a7cc2SEnji Cooper TEST(LinkTest, TestSetArgPointee) {
292b89a7cc2SEnji Cooper   Mock mock;
293b89a7cc2SEnji Cooper   char ch = 'x';
294b89a7cc2SEnji Cooper 
295b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y'));
296b89a7cc2SEnji Cooper   mock.VoidFromString(&ch);
297b89a7cc2SEnji Cooper }
298b89a7cc2SEnji Cooper 
299b89a7cc2SEnji Cooper // Tests the linkage of the SetArrayArgument action.
TEST(LinkTest,TestSetArrayArgument)300b89a7cc2SEnji Cooper TEST(LinkTest, TestSetArrayArgument) {
301b89a7cc2SEnji Cooper   Mock mock;
302b89a7cc2SEnji Cooper   char ch = 'x';
303b89a7cc2SEnji Cooper   char ch2 = 'y';
304b89a7cc2SEnji Cooper 
30528f6c2f2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
30628f6c2f2SEnji Cooper       .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
307b89a7cc2SEnji Cooper   mock.VoidFromString(&ch);
308b89a7cc2SEnji Cooper }
309b89a7cc2SEnji Cooper 
31028f6c2f2SEnji Cooper #ifndef GTEST_OS_WINDOWS_MOBILE
311b89a7cc2SEnji Cooper 
312b89a7cc2SEnji Cooper // Tests the linkage of the SetErrnoAndReturn action.
TEST(LinkTest,TestSetErrnoAndReturn)313b89a7cc2SEnji Cooper TEST(LinkTest, TestSetErrnoAndReturn) {
314b89a7cc2SEnji Cooper   Mock mock;
315b89a7cc2SEnji Cooper 
316b89a7cc2SEnji Cooper   int saved_errno = errno;
317b89a7cc2SEnji Cooper   EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
31828f6c2f2SEnji Cooper   mock.IntFromString(nullptr);
319b89a7cc2SEnji Cooper   errno = saved_errno;
320b89a7cc2SEnji Cooper }
321b89a7cc2SEnji Cooper 
322b89a7cc2SEnji Cooper #endif  // !GTEST_OS_WINDOWS_MOBILE
323b89a7cc2SEnji Cooper 
324b89a7cc2SEnji Cooper // Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
TEST(LinkTest,TestInvoke)325b89a7cc2SEnji Cooper TEST(LinkTest, TestInvoke) {
326b89a7cc2SEnji Cooper   Mock mock;
327b89a7cc2SEnji Cooper   InvokeHelper test_invoke_helper;
328b89a7cc2SEnji Cooper 
329b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
330b89a7cc2SEnji Cooper       .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
331b89a7cc2SEnji Cooper       .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
33228f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
33328f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
334b89a7cc2SEnji Cooper }
335b89a7cc2SEnji Cooper 
336b89a7cc2SEnji Cooper // Tests the linkage of the InvokeWithoutArgs action.
TEST(LinkTest,TestInvokeWithoutArgs)337b89a7cc2SEnji Cooper TEST(LinkTest, TestInvokeWithoutArgs) {
338b89a7cc2SEnji Cooper   Mock mock;
339b89a7cc2SEnji Cooper   InvokeHelper test_invoke_helper;
340b89a7cc2SEnji Cooper 
341b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
342b89a7cc2SEnji Cooper       .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
34328f6c2f2SEnji Cooper       .WillOnce(
34428f6c2f2SEnji Cooper           InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
34528f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
34628f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
347b89a7cc2SEnji Cooper }
348b89a7cc2SEnji Cooper 
349b89a7cc2SEnji Cooper // Tests the linkage of the InvokeArgument action.
TEST(LinkTest,TestInvokeArgument)350b89a7cc2SEnji Cooper TEST(LinkTest, TestInvokeArgument) {
351b89a7cc2SEnji Cooper   Mock mock;
352b89a7cc2SEnji Cooper   char ch = 'x';
353b89a7cc2SEnji Cooper 
354b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
355b89a7cc2SEnji Cooper   mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
356b89a7cc2SEnji Cooper }
357b89a7cc2SEnji Cooper 
358b89a7cc2SEnji Cooper // Tests the linkage of the WithArg action.
TEST(LinkTest,TestWithArg)359b89a7cc2SEnji Cooper TEST(LinkTest, TestWithArg) {
360b89a7cc2SEnji Cooper   Mock mock;
361b89a7cc2SEnji Cooper 
362b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
363b89a7cc2SEnji Cooper       .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
36428f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
365b89a7cc2SEnji Cooper }
366b89a7cc2SEnji Cooper 
367b89a7cc2SEnji Cooper // Tests the linkage of the WithArgs action.
TEST(LinkTest,TestWithArgs)368b89a7cc2SEnji Cooper TEST(LinkTest, TestWithArgs) {
369b89a7cc2SEnji Cooper   Mock mock;
370b89a7cc2SEnji Cooper 
371b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
372b89a7cc2SEnji Cooper       .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
37328f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
374b89a7cc2SEnji Cooper }
375b89a7cc2SEnji Cooper 
376b89a7cc2SEnji Cooper // Tests the linkage of the WithoutArgs action.
TEST(LinkTest,TestWithoutArgs)377b89a7cc2SEnji Cooper TEST(LinkTest, TestWithoutArgs) {
378b89a7cc2SEnji Cooper   Mock mock;
379b89a7cc2SEnji Cooper 
380b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
38128f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
382b89a7cc2SEnji Cooper }
383b89a7cc2SEnji Cooper 
384b89a7cc2SEnji Cooper // Tests the linkage of the DoAll action.
TEST(LinkTest,TestDoAll)385b89a7cc2SEnji Cooper TEST(LinkTest, TestDoAll) {
386b89a7cc2SEnji Cooper   Mock mock;
387b89a7cc2SEnji Cooper   char ch = 'x';
388b89a7cc2SEnji Cooper 
389b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
390b89a7cc2SEnji Cooper       .WillOnce(DoAll(SetArgPointee<0>('y'), Return()));
391b89a7cc2SEnji Cooper   mock.VoidFromString(&ch);
392b89a7cc2SEnji Cooper }
393b89a7cc2SEnji Cooper 
394b89a7cc2SEnji Cooper // Tests the linkage of the DoDefault action.
TEST(LinkTest,TestDoDefault)395b89a7cc2SEnji Cooper TEST(LinkTest, TestDoDefault) {
396b89a7cc2SEnji Cooper   Mock mock;
397b89a7cc2SEnji Cooper   char ch = 'x';
398b89a7cc2SEnji Cooper 
399b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
400b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
401b89a7cc2SEnji Cooper   mock.VoidFromString(&ch);
402b89a7cc2SEnji Cooper }
403b89a7cc2SEnji Cooper 
404b89a7cc2SEnji Cooper // Tests the linkage of the IgnoreResult action.
TEST(LinkTest,TestIgnoreResult)405b89a7cc2SEnji Cooper TEST(LinkTest, TestIgnoreResult) {
406b89a7cc2SEnji Cooper   Mock mock;
407b89a7cc2SEnji Cooper 
408b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
40928f6c2f2SEnji Cooper   mock.VoidFromString(nullptr);
410b89a7cc2SEnji Cooper }
411b89a7cc2SEnji Cooper 
412b89a7cc2SEnji Cooper #if GTEST_HAS_EXCEPTIONS
413b89a7cc2SEnji Cooper // Tests the linkage of the Throw action.
TEST(LinkTest,TestThrow)414b89a7cc2SEnji Cooper TEST(LinkTest, TestThrow) {
415b89a7cc2SEnji Cooper   Mock mock;
416b89a7cc2SEnji Cooper 
417b89a7cc2SEnji Cooper   EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
41828f6c2f2SEnji Cooper   EXPECT_THROW(mock.VoidFromString(nullptr), int);
419b89a7cc2SEnji Cooper }
420*5ca8c28cSEnji Cooper // Tests the linkage of the Rethrow action.
TEST(LinkTest,TestRethrow)421*5ca8c28cSEnji Cooper TEST(LinkTest, TestRethrow) {
422*5ca8c28cSEnji Cooper   Mock mock;
423*5ca8c28cSEnji Cooper 
424*5ca8c28cSEnji Cooper   EXPECT_CALL(mock, VoidFromString(_))
425*5ca8c28cSEnji Cooper       .WillOnce(Rethrow(std::make_exception_ptr(42)));
426*5ca8c28cSEnji Cooper   EXPECT_THROW(mock.VoidFromString(nullptr), int);
427*5ca8c28cSEnji Cooper }
428b89a7cc2SEnji Cooper #endif  // GTEST_HAS_EXCEPTIONS
429b89a7cc2SEnji Cooper 
430b89a7cc2SEnji Cooper // The ACTION*() macros trigger warning C4100 (unreferenced formal
431b89a7cc2SEnji Cooper // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
432b89a7cc2SEnji Cooper // the macro definition, as the warnings are generated when the macro
433b89a7cc2SEnji Cooper // is expanded and macro expansion cannot contain #pragma.  Therefore
434b89a7cc2SEnji Cooper // we suppress them here.
43528f6c2f2SEnji Cooper GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
436b89a7cc2SEnji Cooper 
437b89a7cc2SEnji Cooper // Tests the linkage of actions created using ACTION macro.
438b89a7cc2SEnji Cooper namespace {
ACTION(Return1)439b89a7cc2SEnji Cooper ACTION(Return1) { return 1; }
44028f6c2f2SEnji Cooper }  // namespace
441b89a7cc2SEnji Cooper 
TEST(LinkTest,TestActionMacro)442b89a7cc2SEnji Cooper TEST(LinkTest, TestActionMacro) {
443b89a7cc2SEnji Cooper   Mock mock;
444b89a7cc2SEnji Cooper 
445b89a7cc2SEnji Cooper   EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
44628f6c2f2SEnji Cooper   mock.IntFromString(nullptr);
447b89a7cc2SEnji Cooper }
448b89a7cc2SEnji Cooper 
449b89a7cc2SEnji Cooper // Tests the linkage of actions created using ACTION_P macro.
450b89a7cc2SEnji Cooper namespace {
ACTION_P(ReturnArgument,ret_value)451b89a7cc2SEnji Cooper ACTION_P(ReturnArgument, ret_value) { return ret_value; }
45228f6c2f2SEnji Cooper }  // namespace
453b89a7cc2SEnji Cooper 
TEST(LinkTest,TestActionPMacro)454b89a7cc2SEnji Cooper TEST(LinkTest, TestActionPMacro) {
455b89a7cc2SEnji Cooper   Mock mock;
456b89a7cc2SEnji Cooper 
457b89a7cc2SEnji Cooper   EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
45828f6c2f2SEnji Cooper   mock.IntFromString(nullptr);
459b89a7cc2SEnji Cooper }
460b89a7cc2SEnji Cooper 
461b89a7cc2SEnji Cooper // Tests the linkage of actions created using ACTION_P2 macro.
462b89a7cc2SEnji Cooper namespace {
ACTION_P2(ReturnEqualsEitherOf,first,second)463b89a7cc2SEnji Cooper ACTION_P2(ReturnEqualsEitherOf, first, second) {
464b89a7cc2SEnji Cooper   return arg0 == first || arg0 == second;
465b89a7cc2SEnji Cooper }
46628f6c2f2SEnji Cooper }  // namespace
467b89a7cc2SEnji Cooper 
46828f6c2f2SEnji Cooper GTEST_DISABLE_MSC_WARNINGS_POP_()  // 4100
469b89a7cc2SEnji Cooper 
TEST(LinkTest,TestActionP2Macro)470b89a7cc2SEnji Cooper TEST(LinkTest, TestActionP2Macro) {
471b89a7cc2SEnji Cooper   Mock mock;
472b89a7cc2SEnji Cooper   char ch = 'x';
473b89a7cc2SEnji Cooper 
474b89a7cc2SEnji Cooper   EXPECT_CALL(mock, IntFromString(_))
475b89a7cc2SEnji Cooper       .WillOnce(ReturnEqualsEitherOf("one", "two"));
476b89a7cc2SEnji Cooper   mock.IntFromString(&ch);
477b89a7cc2SEnji Cooper }
478b89a7cc2SEnji Cooper 
479b89a7cc2SEnji Cooper // Tests the linkage of the "_" matcher.
TEST(LinkTest,TestMatcherAnything)480b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherAnything) {
481b89a7cc2SEnji Cooper   Mock mock;
482b89a7cc2SEnji Cooper 
483b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
484b89a7cc2SEnji Cooper }
485b89a7cc2SEnji Cooper 
486b89a7cc2SEnji Cooper // Tests the linkage of the A matcher.
TEST(LinkTest,TestMatcherA)487b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherA) {
488b89a7cc2SEnji Cooper   Mock mock;
489b89a7cc2SEnji Cooper 
490b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
491b89a7cc2SEnji Cooper }
492b89a7cc2SEnji Cooper 
493b89a7cc2SEnji Cooper // Tests the linkage of the Eq and the "bare value" matcher.
TEST(LinkTest,TestMatchersEq)494b89a7cc2SEnji Cooper TEST(LinkTest, TestMatchersEq) {
495b89a7cc2SEnji Cooper   Mock mock;
496b89a7cc2SEnji Cooper   const char* p = "x";
497b89a7cc2SEnji Cooper 
498b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
49928f6c2f2SEnji Cooper   ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
500b89a7cc2SEnji Cooper }
501b89a7cc2SEnji Cooper 
502b89a7cc2SEnji Cooper // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
TEST(LinkTest,TestMatchersRelations)503b89a7cc2SEnji Cooper TEST(LinkTest, TestMatchersRelations) {
504b89a7cc2SEnji Cooper   Mock mock;
505b89a7cc2SEnji Cooper 
506b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
507b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
508b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
509b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
510b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
511b89a7cc2SEnji Cooper }
512b89a7cc2SEnji Cooper 
513b89a7cc2SEnji Cooper // Tests the linkage of the NotNull matcher.
TEST(LinkTest,TestMatcherNotNull)514b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherNotNull) {
515b89a7cc2SEnji Cooper   Mock mock;
516b89a7cc2SEnji Cooper 
517b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
518b89a7cc2SEnji Cooper }
519b89a7cc2SEnji Cooper 
520b89a7cc2SEnji Cooper // Tests the linkage of the IsNull matcher.
TEST(LinkTest,TestMatcherIsNull)521b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherIsNull) {
522b89a7cc2SEnji Cooper   Mock mock;
523b89a7cc2SEnji Cooper 
524b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
525b89a7cc2SEnji Cooper }
526b89a7cc2SEnji Cooper 
527b89a7cc2SEnji Cooper // Tests the linkage of the Ref matcher.
TEST(LinkTest,TestMatcherRef)528b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherRef) {
529b89a7cc2SEnji Cooper   Mock mock;
530b89a7cc2SEnji Cooper   int a = 0;
531b89a7cc2SEnji Cooper 
532b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
533b89a7cc2SEnji Cooper }
534b89a7cc2SEnji Cooper 
535b89a7cc2SEnji Cooper // Tests the linkage of the TypedEq matcher.
TEST(LinkTest,TestMatcherTypedEq)536b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherTypedEq) {
537b89a7cc2SEnji Cooper   Mock mock;
538b89a7cc2SEnji Cooper   long a = 0;
539b89a7cc2SEnji Cooper 
540b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
541b89a7cc2SEnji Cooper }
542b89a7cc2SEnji Cooper 
543b89a7cc2SEnji Cooper // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
544b89a7cc2SEnji Cooper // NanSensitiveDoubleEq matchers.
TEST(LinkTest,TestMatchersFloatingPoint)545b89a7cc2SEnji Cooper TEST(LinkTest, TestMatchersFloatingPoint) {
546b89a7cc2SEnji Cooper   Mock mock;
547b89a7cc2SEnji Cooper   float a = 0;
548b89a7cc2SEnji Cooper 
549b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
550b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
551b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
552b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
553b89a7cc2SEnji Cooper       .WillByDefault(Return());
554b89a7cc2SEnji Cooper }
555b89a7cc2SEnji Cooper 
556b89a7cc2SEnji Cooper // Tests the linkage of the ContainsRegex matcher.
TEST(LinkTest,TestMatcherContainsRegex)557b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherContainsRegex) {
558b89a7cc2SEnji Cooper   Mock mock;
559b89a7cc2SEnji Cooper 
560b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
561b89a7cc2SEnji Cooper }
562b89a7cc2SEnji Cooper 
563b89a7cc2SEnji Cooper // Tests the linkage of the MatchesRegex matcher.
TEST(LinkTest,TestMatcherMatchesRegex)564b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherMatchesRegex) {
565b89a7cc2SEnji Cooper   Mock mock;
566b89a7cc2SEnji Cooper 
567b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
568b89a7cc2SEnji Cooper }
569b89a7cc2SEnji Cooper 
570b89a7cc2SEnji Cooper // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
TEST(LinkTest,TestMatchersSubstrings)571b89a7cc2SEnji Cooper TEST(LinkTest, TestMatchersSubstrings) {
572b89a7cc2SEnji Cooper   Mock mock;
573b89a7cc2SEnji Cooper 
574b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
575b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
576b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
577b89a7cc2SEnji Cooper }
578b89a7cc2SEnji Cooper 
579b89a7cc2SEnji Cooper // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
TEST(LinkTest,TestMatchersStringEquality)580b89a7cc2SEnji Cooper TEST(LinkTest, TestMatchersStringEquality) {
581b89a7cc2SEnji Cooper   Mock mock;
582b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
583b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
584b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
585b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
586b89a7cc2SEnji Cooper }
587b89a7cc2SEnji Cooper 
588b89a7cc2SEnji Cooper // Tests the linkage of the ElementsAre matcher.
TEST(LinkTest,TestMatcherElementsAre)589b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherElementsAre) {
590b89a7cc2SEnji Cooper   Mock mock;
591b89a7cc2SEnji Cooper 
592b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
593b89a7cc2SEnji Cooper }
594b89a7cc2SEnji Cooper 
595b89a7cc2SEnji Cooper // Tests the linkage of the ElementsAreArray matcher.
TEST(LinkTest,TestMatcherElementsAreArray)596b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherElementsAreArray) {
597b89a7cc2SEnji Cooper   Mock mock;
598b89a7cc2SEnji Cooper   char arr[] = {'a', 'b'};
599b89a7cc2SEnji Cooper 
600b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
601b89a7cc2SEnji Cooper }
602b89a7cc2SEnji Cooper 
603b89a7cc2SEnji Cooper // Tests the linkage of the IsSubsetOf matcher.
TEST(LinkTest,TestMatcherIsSubsetOf)604b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherIsSubsetOf) {
605b89a7cc2SEnji Cooper   Mock mock;
606b89a7cc2SEnji Cooper   char arr[] = {'a', 'b'};
607b89a7cc2SEnji Cooper 
608b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
609b89a7cc2SEnji Cooper }
610b89a7cc2SEnji Cooper 
611b89a7cc2SEnji Cooper // Tests the linkage of the IsSupersetOf matcher.
TEST(LinkTest,TestMatcherIsSupersetOf)612b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherIsSupersetOf) {
613b89a7cc2SEnji Cooper   Mock mock;
614b89a7cc2SEnji Cooper   char arr[] = {'a', 'b'};
615b89a7cc2SEnji Cooper 
616b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
617b89a7cc2SEnji Cooper }
618b89a7cc2SEnji Cooper 
619b89a7cc2SEnji Cooper // Tests the linkage of the ContainerEq matcher.
TEST(LinkTest,TestMatcherContainerEq)620b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherContainerEq) {
621b89a7cc2SEnji Cooper   Mock mock;
622b89a7cc2SEnji Cooper   std::vector<int> v;
623b89a7cc2SEnji Cooper 
624b89a7cc2SEnji Cooper   ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
625b89a7cc2SEnji Cooper }
626b89a7cc2SEnji Cooper 
627b89a7cc2SEnji Cooper // Tests the linkage of the Field matcher.
TEST(LinkTest,TestMatcherField)628b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherField) {
629b89a7cc2SEnji Cooper   FieldHelper helper(0);
630b89a7cc2SEnji Cooper 
631b89a7cc2SEnji Cooper   Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
632b89a7cc2SEnji Cooper   EXPECT_TRUE(m.Matches(helper));
633b89a7cc2SEnji Cooper 
634b89a7cc2SEnji Cooper   Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
635b89a7cc2SEnji Cooper   EXPECT_TRUE(m2.Matches(&helper));
636b89a7cc2SEnji Cooper }
637b89a7cc2SEnji Cooper 
638b89a7cc2SEnji Cooper // Tests the linkage of the Property matcher.
TEST(LinkTest,TestMatcherProperty)639b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherProperty) {
640b89a7cc2SEnji Cooper   FieldHelper helper(0);
641b89a7cc2SEnji Cooper 
642b89a7cc2SEnji Cooper   Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
643b89a7cc2SEnji Cooper   EXPECT_TRUE(m.Matches(helper));
644b89a7cc2SEnji Cooper 
645b89a7cc2SEnji Cooper   Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
646b89a7cc2SEnji Cooper   EXPECT_TRUE(m2.Matches(&helper));
647b89a7cc2SEnji Cooper }
648b89a7cc2SEnji Cooper 
649b89a7cc2SEnji Cooper // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherResultOf)650b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherResultOf) {
651b89a7cc2SEnji Cooper   Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
65228f6c2f2SEnji Cooper   EXPECT_TRUE(m.Matches(nullptr));
653b89a7cc2SEnji Cooper }
654b89a7cc2SEnji Cooper 
655b89a7cc2SEnji Cooper // Tests the linkage of the ResultOf matcher.
TEST(LinkTest,TestMatcherPointee)656b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherPointee) {
657b89a7cc2SEnji Cooper   int n = 1;
658b89a7cc2SEnji Cooper 
659b89a7cc2SEnji Cooper   Matcher<int*> m = Pointee(Eq(1));
660b89a7cc2SEnji Cooper   EXPECT_TRUE(m.Matches(&n));
661b89a7cc2SEnji Cooper }
662b89a7cc2SEnji Cooper 
663b89a7cc2SEnji Cooper // Tests the linkage of the Truly matcher.
TEST(LinkTest,TestMatcherTruly)664b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherTruly) {
665b89a7cc2SEnji Cooper   Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
66628f6c2f2SEnji Cooper   EXPECT_TRUE(m.Matches(nullptr));
667b89a7cc2SEnji Cooper }
668b89a7cc2SEnji Cooper 
669b89a7cc2SEnji Cooper // Tests the linkage of the AllOf matcher.
TEST(LinkTest,TestMatcherAllOf)670b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherAllOf) {
671b89a7cc2SEnji Cooper   Matcher<int> m = AllOf(_, Eq(1));
672b89a7cc2SEnji Cooper   EXPECT_TRUE(m.Matches(1));
673b89a7cc2SEnji Cooper }
674b89a7cc2SEnji Cooper 
675b89a7cc2SEnji Cooper // Tests the linkage of the AnyOf matcher.
TEST(LinkTest,TestMatcherAnyOf)676b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherAnyOf) {
677b89a7cc2SEnji Cooper   Matcher<int> m = AnyOf(_, Eq(1));
678b89a7cc2SEnji Cooper   EXPECT_TRUE(m.Matches(1));
679b89a7cc2SEnji Cooper }
680b89a7cc2SEnji Cooper 
681b89a7cc2SEnji Cooper // Tests the linkage of the Not matcher.
TEST(LinkTest,TestMatcherNot)682b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherNot) {
683b89a7cc2SEnji Cooper   Matcher<int> m = Not(_);
684b89a7cc2SEnji Cooper   EXPECT_FALSE(m.Matches(1));
685b89a7cc2SEnji Cooper }
686b89a7cc2SEnji Cooper 
687b89a7cc2SEnji Cooper // Tests the linkage of the MatcherCast<T>() function.
TEST(LinkTest,TestMatcherCast)688b89a7cc2SEnji Cooper TEST(LinkTest, TestMatcherCast) {
689b89a7cc2SEnji Cooper   Matcher<const char*> m = MatcherCast<const char*>(_);
69028f6c2f2SEnji Cooper   EXPECT_TRUE(m.Matches(nullptr));
691b89a7cc2SEnji Cooper }
692b89a7cc2SEnji Cooper 
69328f6c2f2SEnji Cooper #endif  // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
694