123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693 |
- // Copyright 2009, Google Inc.
- // All rights reserved.
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are
- // met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following disclaimer
- // in the documentation and/or other materials provided with the
- // distribution.
- // * Neither the name of Google Inc. nor the names of its
- // contributors may be used to endorse or promote products derived from
- // this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- // Google Mock - a framework for writing C++ mock classes.
- //
- // This file tests that:
- // a. A header file defining a mock class can be included in multiple
- // translation units without causing a link error.
- // b. Actions and matchers can be instantiated with identical template
- // arguments in different translation units without causing link
- // errors.
- // The following constructs are currently tested:
- // Actions:
- // Return()
- // Return(value)
- // ReturnNull
- // ReturnRef
- // Assign
- // SetArgPointee
- // SetArrayArgument
- // SetErrnoAndReturn
- // Invoke(function)
- // Invoke(object, method)
- // InvokeWithoutArgs(function)
- // InvokeWithoutArgs(object, method)
- // InvokeArgument
- // WithArg
- // WithArgs
- // WithoutArgs
- // DoAll
- // DoDefault
- // IgnoreResult
- // Throw
- // ACTION()-generated
- // ACTION_P()-generated
- // ACTION_P2()-generated
- // Matchers:
- // _
- // A
- // An
- // Eq
- // Gt, Lt, Ge, Le, Ne
- // NotNull
- // Ref
- // TypedEq
- // DoubleEq
- // FloatEq
- // NanSensitiveDoubleEq
- // NanSensitiveFloatEq
- // ContainsRegex
- // MatchesRegex
- // EndsWith
- // HasSubstr
- // StartsWith
- // StrCaseEq
- // StrCaseNe
- // StrEq
- // StrNe
- // ElementsAre
- // ElementsAreArray
- // ContainerEq
- // Field
- // Property
- // ResultOf(function)
- // ResultOf(callback)
- // Pointee
- // Truly(predicate)
- // AddressSatisfies
- // AllOf
- // AnyOf
- // Not
- // MatcherCast<T>
- //
- // Please note: this test does not verify the functioning of these
- // constructs, only that the programs using them will link successfully.
- //
- // Implementation note:
- // This test requires identical definitions of Interface and Mock to be
- // included in different translation units. We achieve this by writing
- // them in this header and #including it in gmock_link_test.cc and
- // gmock_link2_test.cc. Because the symbols generated by the compiler for
- // those constructs must be identical in both translation units,
- // definitions of Interface and Mock tests MUST be kept in the SAME
- // NON-ANONYMOUS namespace in this file. The test fixture class LinkTest
- // is defined as LinkTest1 in gmock_link_test.cc and as LinkTest2 in
- // gmock_link2_test.cc to avoid producing linker errors.
- #ifndef GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
- #define GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
- #include "gmock/gmock.h"
- #ifndef GTEST_OS_WINDOWS_MOBILE
- #include <errno.h>
- #endif
- #include <iostream>
- #include <vector>
- #include "gtest/gtest.h"
- #include "gtest/internal/gtest-port.h"
- using testing::_;
- using testing::A;
- using testing::Action;
- using testing::AllOf;
- using testing::AnyOf;
- using testing::Assign;
- using testing::ContainerEq;
- using testing::DoAll;
- using testing::DoDefault;
- using testing::DoubleEq;
- using testing::ElementsAre;
- using testing::ElementsAreArray;
- using testing::EndsWith;
- using testing::Eq;
- using testing::Field;
- using testing::FloatEq;
- using testing::Ge;
- using testing::Gt;
- using testing::HasSubstr;
- using testing::IgnoreResult;
- using testing::Invoke;
- using testing::InvokeArgument;
- using testing::InvokeWithoutArgs;
- using testing::IsNull;
- using testing::IsSubsetOf;
- using testing::IsSupersetOf;
- using testing::Le;
- using testing::Lt;
- using testing::Matcher;
- using testing::MatcherCast;
- using testing::NanSensitiveDoubleEq;
- using testing::NanSensitiveFloatEq;
- using testing::Ne;
- using testing::Not;
- using testing::NotNull;
- using testing::Pointee;
- using testing::Property;
- using testing::Ref;
- using testing::ResultOf;
- using testing::Return;
- using testing::ReturnNull;
- using testing::ReturnRef;
- using testing::SetArgPointee;
- using testing::SetArrayArgument;
- using testing::StartsWith;
- using testing::StrCaseEq;
- using testing::StrCaseNe;
- using testing::StrEq;
- using testing::StrNe;
- using testing::Truly;
- using testing::TypedEq;
- using testing::WithArg;
- using testing::WithArgs;
- using testing::WithoutArgs;
- #ifndef GTEST_OS_WINDOWS_MOBILE
- using testing::SetErrnoAndReturn;
- #endif
- #if GTEST_HAS_EXCEPTIONS
- using testing::Throw;
- using testing::Rethrow;
- #endif
- using testing::ContainsRegex;
- using testing::MatchesRegex;
- class Interface {
- public:
- virtual ~Interface() = default;
- virtual void VoidFromString(char* str) = 0;
- virtual char* StringFromString(char* str) = 0;
- virtual int IntFromString(char* str) = 0;
- virtual int& IntRefFromString(char* str) = 0;
- virtual void VoidFromFunc(void (*func)(char* str)) = 0;
- virtual void VoidFromIntRef(int& n) = 0; // NOLINT
- virtual void VoidFromFloat(float n) = 0;
- virtual void VoidFromDouble(double n) = 0;
- virtual void VoidFromVector(const std::vector<int>& v) = 0;
- };
- class Mock : public Interface {
- public:
- Mock() = default;
- MOCK_METHOD1(VoidFromString, void(char* str));
- MOCK_METHOD1(StringFromString, char*(char* str));
- MOCK_METHOD1(IntFromString, int(char* str));
- MOCK_METHOD1(IntRefFromString, int&(char* str));
- MOCK_METHOD1(VoidFromFunc, void(void (*func)(char* str)));
- MOCK_METHOD1(VoidFromIntRef, void(int& n)); // NOLINT
- MOCK_METHOD1(VoidFromFloat, void(float n));
- MOCK_METHOD1(VoidFromDouble, void(double n));
- MOCK_METHOD1(VoidFromVector, void(const std::vector<int>& v));
- private:
- Mock(const Mock&) = delete;
- Mock& operator=(const Mock&) = delete;
- };
- class InvokeHelper {
- public:
- static void StaticVoidFromVoid() {}
- void VoidFromVoid() {}
- static void StaticVoidFromString(char* /* str */) {}
- void VoidFromString(char* /* str */) {}
- static int StaticIntFromString(char* /* str */) { return 1; }
- static bool StaticBoolFromString(const char* /* str */) { return true; }
- };
- class FieldHelper {
- public:
- explicit FieldHelper(int a_field) : field_(a_field) {}
- int field() const { return field_; }
- int field_; // NOLINT -- need external access to field_ to test
- // the Field matcher.
- };
- // Tests the linkage of the ReturnVoid action.
- TEST(LinkTest, TestReturnVoid) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the Return action.
- TEST(LinkTest, TestReturn) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, StringFromString(_)).WillOnce(Return(&ch));
- mock.StringFromString(nullptr);
- }
- // Tests the linkage of the ReturnNull action.
- TEST(LinkTest, TestReturnNull) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Return());
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the ReturnRef action.
- TEST(LinkTest, TestReturnRef) {
- Mock mock;
- int n = 42;
- EXPECT_CALL(mock, IntRefFromString(_)).WillOnce(ReturnRef(n));
- mock.IntRefFromString(nullptr);
- }
- // Tests the linkage of the Assign action.
- TEST(LinkTest, TestAssign) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Assign(&ch, 'y'));
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the SetArgPointee action.
- TEST(LinkTest, TestSetArgPointee) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(SetArgPointee<0>('y'));
- mock.VoidFromString(&ch);
- }
- // Tests the linkage of the SetArrayArgument action.
- TEST(LinkTest, TestSetArrayArgument) {
- Mock mock;
- char ch = 'x';
- char ch2 = 'y';
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(SetArrayArgument<0>(&ch2, &ch2 + 1));
- mock.VoidFromString(&ch);
- }
- #ifndef GTEST_OS_WINDOWS_MOBILE
- // Tests the linkage of the SetErrnoAndReturn action.
- TEST(LinkTest, TestSetErrnoAndReturn) {
- Mock mock;
- int saved_errno = errno;
- EXPECT_CALL(mock, IntFromString(_)).WillOnce(SetErrnoAndReturn(1, -1));
- mock.IntFromString(nullptr);
- errno = saved_errno;
- }
- #endif // !GTEST_OS_WINDOWS_MOBILE
- // Tests the linkage of the Invoke(function) and Invoke(object, method) actions.
- TEST(LinkTest, TestInvoke) {
- Mock mock;
- InvokeHelper test_invoke_helper;
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(Invoke(&InvokeHelper::StaticVoidFromString))
- .WillOnce(Invoke(&test_invoke_helper, &InvokeHelper::VoidFromString));
- mock.VoidFromString(nullptr);
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the InvokeWithoutArgs action.
- TEST(LinkTest, TestInvokeWithoutArgs) {
- Mock mock;
- InvokeHelper test_invoke_helper;
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid))
- .WillOnce(
- InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid));
- mock.VoidFromString(nullptr);
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the InvokeArgument action.
- TEST(LinkTest, TestInvokeArgument) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, VoidFromFunc(_)).WillOnce(InvokeArgument<0>(&ch));
- mock.VoidFromFunc(InvokeHelper::StaticVoidFromString);
- }
- // Tests the linkage of the WithArg action.
- TEST(LinkTest, TestWithArg) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(WithArg<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the WithArgs action.
- TEST(LinkTest, TestWithArgs) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(WithArgs<0>(Invoke(&InvokeHelper::StaticVoidFromString)));
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the WithoutArgs action.
- TEST(LinkTest, TestWithoutArgs) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(WithoutArgs(Return()));
- mock.VoidFromString(nullptr);
- }
- // Tests the linkage of the DoAll action.
- TEST(LinkTest, TestDoAll) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(DoAll(SetArgPointee<0>('y'), Return()));
- mock.VoidFromString(&ch);
- }
- // Tests the linkage of the DoDefault action.
- TEST(LinkTest, TestDoDefault) {
- Mock mock;
- char ch = 'x';
- ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(DoDefault());
- mock.VoidFromString(&ch);
- }
- // Tests the linkage of the IgnoreResult action.
- TEST(LinkTest, TestIgnoreResult) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(IgnoreResult(Return(42)));
- mock.VoidFromString(nullptr);
- }
- #if GTEST_HAS_EXCEPTIONS
- // Tests the linkage of the Throw action.
- TEST(LinkTest, TestThrow) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_)).WillOnce(Throw(42));
- EXPECT_THROW(mock.VoidFromString(nullptr), int);
- }
- // Tests the linkage of the Rethrow action.
- TEST(LinkTest, TestRethrow) {
- Mock mock;
- EXPECT_CALL(mock, VoidFromString(_))
- .WillOnce(Rethrow(std::make_exception_ptr(42)));
- EXPECT_THROW(mock.VoidFromString(nullptr), int);
- }
- #endif // GTEST_HAS_EXCEPTIONS
- // The ACTION*() macros trigger warning C4100 (unreferenced formal
- // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
- // the macro definition, as the warnings are generated when the macro
- // is expanded and macro expansion cannot contain #pragma. Therefore
- // we suppress them here.
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
- // Tests the linkage of actions created using ACTION macro.
- namespace {
- ACTION(Return1) { return 1; }
- } // namespace
- TEST(LinkTest, TestActionMacro) {
- Mock mock;
- EXPECT_CALL(mock, IntFromString(_)).WillOnce(Return1());
- mock.IntFromString(nullptr);
- }
- // Tests the linkage of actions created using ACTION_P macro.
- namespace {
- ACTION_P(ReturnArgument, ret_value) { return ret_value; }
- } // namespace
- TEST(LinkTest, TestActionPMacro) {
- Mock mock;
- EXPECT_CALL(mock, IntFromString(_)).WillOnce(ReturnArgument(42));
- mock.IntFromString(nullptr);
- }
- // Tests the linkage of actions created using ACTION_P2 macro.
- namespace {
- ACTION_P2(ReturnEqualsEitherOf, first, second) {
- return arg0 == first || arg0 == second;
- }
- } // namespace
- GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
- TEST(LinkTest, TestActionP2Macro) {
- Mock mock;
- char ch = 'x';
- EXPECT_CALL(mock, IntFromString(_))
- .WillOnce(ReturnEqualsEitherOf("one", "two"));
- mock.IntFromString(&ch);
- }
- // Tests the linkage of the "_" matcher.
- TEST(LinkTest, TestMatcherAnything) {
- Mock mock;
- ON_CALL(mock, VoidFromString(_)).WillByDefault(Return());
- }
- // Tests the linkage of the A matcher.
- TEST(LinkTest, TestMatcherA) {
- Mock mock;
- ON_CALL(mock, VoidFromString(A<char*>())).WillByDefault(Return());
- }
- // Tests the linkage of the Eq and the "bare value" matcher.
- TEST(LinkTest, TestMatchersEq) {
- Mock mock;
- const char* p = "x";
- ON_CALL(mock, VoidFromString(Eq(p))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(const_cast<char*>("y"))).WillByDefault(Return());
- }
- // Tests the linkage of the Lt, Gt, Le, Ge, and Ne matchers.
- TEST(LinkTest, TestMatchersRelations) {
- Mock mock;
- ON_CALL(mock, VoidFromFloat(Lt(1.0f))).WillByDefault(Return());
- ON_CALL(mock, VoidFromFloat(Gt(1.0f))).WillByDefault(Return());
- ON_CALL(mock, VoidFromFloat(Le(1.0f))).WillByDefault(Return());
- ON_CALL(mock, VoidFromFloat(Ge(1.0f))).WillByDefault(Return());
- ON_CALL(mock, VoidFromFloat(Ne(1.0f))).WillByDefault(Return());
- }
- // Tests the linkage of the NotNull matcher.
- TEST(LinkTest, TestMatcherNotNull) {
- Mock mock;
- ON_CALL(mock, VoidFromString(NotNull())).WillByDefault(Return());
- }
- // Tests the linkage of the IsNull matcher.
- TEST(LinkTest, TestMatcherIsNull) {
- Mock mock;
- ON_CALL(mock, VoidFromString(IsNull())).WillByDefault(Return());
- }
- // Tests the linkage of the Ref matcher.
- TEST(LinkTest, TestMatcherRef) {
- Mock mock;
- int a = 0;
- ON_CALL(mock, VoidFromIntRef(Ref(a))).WillByDefault(Return());
- }
- // Tests the linkage of the TypedEq matcher.
- TEST(LinkTest, TestMatcherTypedEq) {
- Mock mock;
- long a = 0;
- ON_CALL(mock, VoidFromIntRef(TypedEq<int&>(a))).WillByDefault(Return());
- }
- // Tests the linkage of the FloatEq, DoubleEq, NanSensitiveFloatEq and
- // NanSensitiveDoubleEq matchers.
- TEST(LinkTest, TestMatchersFloatingPoint) {
- Mock mock;
- float a = 0;
- ON_CALL(mock, VoidFromFloat(FloatEq(a))).WillByDefault(Return());
- ON_CALL(mock, VoidFromDouble(DoubleEq(a))).WillByDefault(Return());
- ON_CALL(mock, VoidFromFloat(NanSensitiveFloatEq(a))).WillByDefault(Return());
- ON_CALL(mock, VoidFromDouble(NanSensitiveDoubleEq(a)))
- .WillByDefault(Return());
- }
- // Tests the linkage of the ContainsRegex matcher.
- TEST(LinkTest, TestMatcherContainsRegex) {
- Mock mock;
- ON_CALL(mock, VoidFromString(ContainsRegex(".*"))).WillByDefault(Return());
- }
- // Tests the linkage of the MatchesRegex matcher.
- TEST(LinkTest, TestMatcherMatchesRegex) {
- Mock mock;
- ON_CALL(mock, VoidFromString(MatchesRegex(".*"))).WillByDefault(Return());
- }
- // Tests the linkage of the StartsWith, EndsWith, and HasSubstr matchers.
- TEST(LinkTest, TestMatchersSubstrings) {
- Mock mock;
- ON_CALL(mock, VoidFromString(StartsWith("a"))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(EndsWith("c"))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(HasSubstr("b"))).WillByDefault(Return());
- }
- // Tests the linkage of the StrEq, StrNe, StrCaseEq, and StrCaseNe matchers.
- TEST(LinkTest, TestMatchersStringEquality) {
- Mock mock;
- ON_CALL(mock, VoidFromString(StrEq("a"))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(StrNe("a"))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(StrCaseEq("a"))).WillByDefault(Return());
- ON_CALL(mock, VoidFromString(StrCaseNe("a"))).WillByDefault(Return());
- }
- // Tests the linkage of the ElementsAre matcher.
- TEST(LinkTest, TestMatcherElementsAre) {
- Mock mock;
- ON_CALL(mock, VoidFromVector(ElementsAre('a', _))).WillByDefault(Return());
- }
- // Tests the linkage of the ElementsAreArray matcher.
- TEST(LinkTest, TestMatcherElementsAreArray) {
- Mock mock;
- char arr[] = {'a', 'b'};
- ON_CALL(mock, VoidFromVector(ElementsAreArray(arr))).WillByDefault(Return());
- }
- // Tests the linkage of the IsSubsetOf matcher.
- TEST(LinkTest, TestMatcherIsSubsetOf) {
- Mock mock;
- char arr[] = {'a', 'b'};
- ON_CALL(mock, VoidFromVector(IsSubsetOf(arr))).WillByDefault(Return());
- }
- // Tests the linkage of the IsSupersetOf matcher.
- TEST(LinkTest, TestMatcherIsSupersetOf) {
- Mock mock;
- char arr[] = {'a', 'b'};
- ON_CALL(mock, VoidFromVector(IsSupersetOf(arr))).WillByDefault(Return());
- }
- // Tests the linkage of the ContainerEq matcher.
- TEST(LinkTest, TestMatcherContainerEq) {
- Mock mock;
- std::vector<int> v;
- ON_CALL(mock, VoidFromVector(ContainerEq(v))).WillByDefault(Return());
- }
- // Tests the linkage of the Field matcher.
- TEST(LinkTest, TestMatcherField) {
- FieldHelper helper(0);
- Matcher<const FieldHelper&> m = Field(&FieldHelper::field_, Eq(0));
- EXPECT_TRUE(m.Matches(helper));
- Matcher<const FieldHelper*> m2 = Field(&FieldHelper::field_, Eq(0));
- EXPECT_TRUE(m2.Matches(&helper));
- }
- // Tests the linkage of the Property matcher.
- TEST(LinkTest, TestMatcherProperty) {
- FieldHelper helper(0);
- Matcher<const FieldHelper&> m = Property(&FieldHelper::field, Eq(0));
- EXPECT_TRUE(m.Matches(helper));
- Matcher<const FieldHelper*> m2 = Property(&FieldHelper::field, Eq(0));
- EXPECT_TRUE(m2.Matches(&helper));
- }
- // Tests the linkage of the ResultOf matcher.
- TEST(LinkTest, TestMatcherResultOf) {
- Matcher<char*> m = ResultOf(&InvokeHelper::StaticIntFromString, Eq(1));
- EXPECT_TRUE(m.Matches(nullptr));
- }
- // Tests the linkage of the ResultOf matcher.
- TEST(LinkTest, TestMatcherPointee) {
- int n = 1;
- Matcher<int*> m = Pointee(Eq(1));
- EXPECT_TRUE(m.Matches(&n));
- }
- // Tests the linkage of the Truly matcher.
- TEST(LinkTest, TestMatcherTruly) {
- Matcher<const char*> m = Truly(&InvokeHelper::StaticBoolFromString);
- EXPECT_TRUE(m.Matches(nullptr));
- }
- // Tests the linkage of the AllOf matcher.
- TEST(LinkTest, TestMatcherAllOf) {
- Matcher<int> m = AllOf(_, Eq(1));
- EXPECT_TRUE(m.Matches(1));
- }
- // Tests the linkage of the AnyOf matcher.
- TEST(LinkTest, TestMatcherAnyOf) {
- Matcher<int> m = AnyOf(_, Eq(1));
- EXPECT_TRUE(m.Matches(1));
- }
- // Tests the linkage of the Not matcher.
- TEST(LinkTest, TestMatcherNot) {
- Matcher<int> m = Not(_);
- EXPECT_FALSE(m.Matches(1));
- }
- // Tests the linkage of the MatcherCast<T>() function.
- TEST(LinkTest, TestMatcherCast) {
- Matcher<const char*> m = MatcherCast<const char*>(_);
- EXPECT_TRUE(m.Matches(nullptr));
- }
- #endif // GOOGLEMOCK_TEST_GMOCK_LINK_TEST_H_
|