40 #include <type_traits>
52 using ::testing::internal::kAllow;
54 using ::testing::internal::kFail;
56 using ::testing::internal::kWarn;
59 #if GTEST_HAS_STREAM_REDIRECTION
66 class MockIncomplete {
74 void PrintTo(
const Incomplete&
x, ::std::ostream* os);
76 TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
81 MockIncomplete incomplete;
87 void PrintTo(
const Incomplete& , ::std::ostream* os) {
94 class NonDefaultConstructible {
96 explicit NonDefaultConstructible(
int ) {}
105 MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
110 MockA(
const MockA&) =
delete;
111 MockA& operator=(
const MockA&) =
delete;
122 MockB(
const MockB&) =
delete;
123 MockB& operator=(
const MockB&) =
delete;
126 class ReferenceHoldingMock {
128 ReferenceHoldingMock() =
default;
130 MOCK_METHOD1(AcceptReference,
void(std::shared_ptr<MockA>*));
133 ReferenceHoldingMock(
const ReferenceHoldingMock&) =
delete;
134 ReferenceHoldingMock& operator=(
const ReferenceHoldingMock&) =
delete;
142 #define Method MethodW
146 virtual ~CC() =
default;
149 class MockCC :
public CC {
156 MockCC(
const MockCC&) =
delete;
157 MockCC& operator=(
const MockCC&) =
delete;
161 TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
168 TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
175 TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
182 TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
188 #undef Method // Done with macro redefinition tests.
192 TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
200 TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
210 TEST(OnCallSyntaxTest, WithIsOptional) {
217 TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
225 .WillByDefault(
Return(Result()));
227 ".With() cannot appear more than once in an ON_CALL()");
230 TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
241 TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
248 ".WillByDefault() must appear exactly once in an ON_CALL()");
253 TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
262 TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
273 TEST(ExpectCallSyntaxTest, WithIsOptional) {
280 TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
287 ".With() cannot appear more than once in an EXPECT_CALL()");
292 TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
299 ".With() must be the first clause in an EXPECT_CALL()");
307 ".With() must be the first clause in an EXPECT_CALL()");
312 TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
324 TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
331 ".Times() cannot appear more than once in an EXPECT_CALL()");
337 TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
345 ".Times() may only appear *before* ");
350 TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
361 TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
365 EXPECT_CALL(a, DoA(1)).InSequence(s1, s2).InSequence(s1);
370 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
379 ".InSequence() cannot appear after ");
384 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
392 ".InSequence() cannot appear after ");
397 TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
403 ".After() cannot appear after ");
409 TEST(ExpectCallSyntaxTest, WillIsOptional) {
419 TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
429 TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
436 ".WillOnce() cannot appear after ");
441 TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
452 TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
460 ".WillRepeatedly() cannot appear more than once in an "
464 TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
471 ".WillRepeatedly() cannot appear after ");
474 TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
484 TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
489 EXPECT_CALL(a, DoA(1)).RetiresOnSaturation().RetiresOnSaturation();
491 ".RetiresOnSaturation() cannot appear more than once");
496 TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
507 "to be called once");
515 "to be called once");
518 #if GTEST_HAS_STREAM_REDIRECTION
522 TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
552 TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
565 .RetiresOnSaturation();
579 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
580 "Expected to be never called, but has 1 WillOnce().",
583 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
584 "Expected to be called at most once, "
585 "but has 2 WillOnce()s.",
589 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n"
590 "Expected to be called once, but has 2 WillOnce()s.",
593 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
594 "Expected to be never called, but has 0 WillOnce()s "
595 "and a WillRepeatedly().",
599 "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n"
600 "Expected to be called once, but has 1 WillOnce() "
601 "and a WillRepeatedly().",
607 TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
616 "Too few actions specified in EXPECT_CALL(b, DoB())...\n"
617 "Expected to be called between 2 and 3 times, "
618 "but has only 1 WillOnce().",
623 TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
652 "Uninteresting mock function call");
679 #endif // GTEST_HAS_STREAM_REDIRECTION
685 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
694 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
703 TEST(OnCallTest, PicksLastMatchingOnCall) {
716 TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
729 TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
738 TEST(ExpectCallTest, CatchesTooFewCalls) {
746 "Actual function \"DoB Method\" call count "
747 "doesn't match EXPECT_CALL(b, DoB(5))...\n"
748 " Expected: to be called at least twice\n"
749 " Actual: called once - unsatisfied and active");
754 TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
770 "to be called twice");
782 TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
804 "to be called at least once");
807 #if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
808 GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
813 TEST(ExpectCallTest, NonMoveableType) {
815 struct NonMoveableStruct {
816 explicit NonMoveableStruct(
int x_in) :
x(x_in) {}
817 NonMoveableStruct(NonMoveableStruct&&) =
delete;
822 static_assert(!std::is_move_constructible_v<NonMoveableStruct>);
823 static_assert(!std::is_copy_constructible_v<NonMoveableStruct>);
825 static_assert(!std::is_move_assignable_v<NonMoveableStruct>);
826 static_assert(!std::is_copy_assignable_v<NonMoveableStruct>);
830 const auto return_17 = [] {
return NonMoveableStruct(17); };
832 static_cast<void>(OnceAction<NonMoveableStruct()>{return_17});
833 static_cast<void>(Action<NonMoveableStruct()>{return_17});
835 static_cast<void>(OnceAction<NonMoveableStruct(int)>{return_17});
836 static_cast<void>(Action<NonMoveableStruct(int)>{return_17});
840 MockFunction<NonMoveableStruct()> mock;
843 .WillRepeatedly(return_17);
850 #endif // C++17 and above
854 TEST(ExpectCallTest, NthMatchTakesNthAction) {
866 TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
875 #if GTEST_HAS_STREAM_REDIRECTION
879 TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
900 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
901 "Called 3 times, but only 2 WillOnce()s are specified"
902 " - returning default value."));
904 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
905 "Called 4 times, but only 2 WillOnce()s are specified"
906 " - returning default value."));
909 TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhaustedActions) {
923 TEST(FunctionMockerMessageTest,
924 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
925 std::string on_call_location;
936 #endif // GTEST_HAS_STREAM_REDIRECTION
939 TEST(UninterestingCallTest, DoesDefaultAction) {
953 TEST(UnexpectedCallTest, DoesDefaultAction) {
962 "Unexpected mock function call");
976 TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
986 "Unexpected mock function call - returning directly.\n"
987 " Function call: DoA(9)\n"
988 "Google Mock tried the following 1 expectation, but it didn't match:");
991 " Expected arg #0: is equal to 1\n"
993 " Expected: to be called once\n"
994 " Actual: called once - saturated and active");
1003 "Unexpected mock function call - returning directly.\n"
1004 " Function call: DoA(2)\n"
1005 "Google Mock tried the following 2 expectations, but none matched:");
1008 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n"
1009 " Expected arg #0: is equal to 1\n"
1011 " Expected: to be called once\n"
1012 " Actual: called once - saturated and active");
1015 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n"
1016 " Expected arg #0: is equal to 3\n"
1018 " Expected: to be called once\n"
1019 " Actual: never called - unsatisfied and active");
1025 TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
1031 "Unexpected mock function call - returning default value.\n"
1032 " Function call: DoB(2)\n"
1034 "Google Mock tried the following 1 expectation, but it didn't match:");
1037 " Expected arg #0: is equal to 1\n"
1039 " Expected: to be called once\n"
1040 " Actual: called once - saturated and active");
1045 TEST(UnexpectedCallTest, RetiredExpectation) {
1051 " Expected: the expectation is active\n"
1052 " Actual: it is retired");
1057 TEST(UnexpectedCallTest, UnmatchedArguments) {
1062 " Expected arg #0: is equal to 1\n"
1069 TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) {
1077 ::testing::TestPartResultArray failures;
1079 ::testing::ScopedFakeTestPartResultReporter reporter(&failures);
1087 const ::testing::TestPartResult& r = failures.GetTestPartResult(0);
1088 EXPECT_EQ(::testing::TestPartResult::kNonFatalFailure, r.type());
1092 #ifdef GTEST_USES_POSIX_RE
1097 "the following immediate pre-requisites are not satisfied:\n"
1098 "(.|\n)*: pre-requisite #0\n"
1099 "(.|\n)*: pre-requisite #1"));
1104 "the following immediate pre-requisites are not satisfied:"));
1105 EXPECT_THAT(r.message(), ContainsRegex(
": pre-requisite #0"));
1106 EXPECT_THAT(r.message(), ContainsRegex(
": pre-requisite #1"));
1107 #endif // GTEST_USES_POSIX_RE
1114 TEST(UndefinedReturnValueTest,
1115 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1120 #if GTEST_HAS_EXCEPTIONS
1129 TEST(ExcessiveCallTest, DoesDefaultAction) {
1136 bool result =
false;
1138 "Mock function called more times than expected");
1144 EXPECT_CALL(b, DoB(0)).Description(
"DoB Method").Times(0);
1148 "Mock function \"DoB Method\" called more times than expected");
1154 TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
1156 EXPECT_CALL(a, DoA(
_)).Description(
"DoA Method").Times(0);
1159 "Mock function \"DoA Method\" called more times than expected - "
1160 "returning directly.\n"
1161 " Function call: DoA(9)\n"
1162 " Expected: to be never called\n"
1163 " Actual: called once - over-saturated and active");
1168 TEST(ExcessiveCallTest, GeneratesFailureForNonVoidFunction) {
1174 "Mock function called more times than expected - "
1175 "returning default value.\n"
1176 " Function call: DoB(2)\n"
1178 " Expected: to be called once\n"
1179 " Actual: called twice - over-saturated and active");
1184 TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1197 "Unexpected mock function call");
1203 TEST(InSequenceTest, NestedInSequence) {
1222 "Unexpected mock function call");
1228 TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1242 "Unexpected mock function call");
1250 TEST(SequenceTest, AnyOrderIsOkByDefault) {
1276 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1296 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1314 PartialOrderTest() {
1333 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1344 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1354 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1364 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1374 TEST(SequenceTest, Retirement) {
1379 EXPECT_CALL(a, DoA(
_)).InSequence(s).RetiresOnSaturation();
1389 TEST(ExpectationTest, ConstrutorsWork) {
1399 Expectation e5 =
EXPECT_CALL(a, DoA(5)).InSequence(s);
1401 Expectation e6 =
EXPECT_CALL(a, DoA(6)).After(e2);
1404 Expectation e9 =
EXPECT_CALL(a, DoA(9)).RetiresOnSaturation();
1406 Expectation e10 = e2;
1421 TEST(ExpectationTest, AssignmentWorks) {
1436 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1437 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1440 TEST(ExpectationSetTest, ConstructorsWork) {
1444 const Expectation e2;
1447 ExpectationSet es3 = e1;
1448 ExpectationSet es4(e1);
1449 ExpectationSet es5 = e2;
1450 ExpectationSet es6(e2);
1451 ExpectationSet es7 = es2;
1469 TEST(ExpectationSetTest, AssignmentWorks) {
1471 ExpectationSet es2 = Expectation();
1479 TEST(ExpectationSetTest, InsertionWorks) {
1491 ExpectationSet::const_iterator it1 = es1.begin();
1492 ExpectationSet::const_iterator it2 = it1;
1499 TEST(ExpectationSetTest, SizeWorks) {
1503 es += Expectation();
1513 TEST(ExpectationSetTest, IsEnumerable) {
1517 es += Expectation();
1518 ExpectationSet::const_iterator it = es.begin();
1527 TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1539 TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1545 const Expectation e2 =
EXPECT_CALL(b, DoB()).Times(2).After(e1);
1555 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1575 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1582 Expectation e2 =
EXPECT_CALL(b, DoB()).Times(2).After(e1);
1596 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1616 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1636 TEST(AfterTest, CanBeUsedWithInSequence) {
1653 TEST(AfterTest, CanBeCalledManyTimes) {
1658 EXPECT_CALL(a, DoA(4)).After(e1).After(e2).After(e3);
1667 TEST(AfterTest, AcceptsUpToFiveArguments) {
1674 EXPECT_CALL(a, DoA(6)).After(e1, e2, e3, es1, es2);
1685 TEST(AfterTest, AcceptsDuplicatedInput) {
1697 EXPECT_CALL(a, ReturnResult(3)).After(e1, e2, es, e1);
1710 TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1726 TEST(DeletingMockEarlyTest, Success1) {
1727 MockB*
const b1 =
new MockB;
1728 MockA*
const a =
new MockA;
1729 MockB*
const b2 =
new MockB;
1736 .WillRepeatedly(
Return(
true));
1751 TEST(DeletingMockEarlyTest, Success2) {
1752 MockB*
const b1 =
new MockB;
1753 MockA*
const a =
new MockA;
1754 MockB*
const b2 =
new MockB;
1780 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1781 MockA*
const a =
new MockA;
1786 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1787 MockA*
const a =
new MockA;
1789 a->ReturnResult(42);
1793 TEST(DeletingMockEarlyTest, Failure1) {
1794 MockB*
const b1 =
new MockB;
1795 MockA*
const a =
new MockA;
1796 MockB*
const b2 =
new MockB;
1813 TEST(DeletingMockEarlyTest, Failure2) {
1814 MockB*
const b1 =
new MockB;
1815 MockA*
const a =
new MockA;
1816 MockB*
const b2 =
new MockB;
1832 class EvenNumberCardinality :
public CardinalityInterface {
1836 bool IsSatisfiedByCallCount(
int call_count)
const override {
1837 return call_count % 2 == 0;
1842 bool IsSaturatedByCallCount(
int )
const override {
1847 void DescribeTo(::std::ostream* os)
const override {
1848 *os <<
"called even number of times";
1852 Cardinality EvenNumber() {
return Cardinality(
new EvenNumberCardinality); }
1854 TEST(ExpectationBaseTest,
1855 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1856 MockA* a =
new MockA;
1859 EXPECT_CALL(*a, DoA(1)).Times(EvenNumber()).InSequence(s);
1872 struct Printable {};
1874 inline void operator<<(::std::ostream& os,
const Printable&) {
1878 struct Unprintable {
1879 Unprintable() :
value(0) {}
1887 MOCK_METHOD6(VoidMethod,
void(
bool cond,
int n, std::string s,
void*
p,
1888 const Printable& x, Unprintable y));
1892 MockC(
const MockC&) =
delete;
1893 MockC& operator=(
const MockC&) =
delete;
1898 VerboseFlagPreservingFixture()
1901 ~VerboseFlagPreservingFixture()
override {
1908 VerboseFlagPreservingFixture(
const VerboseFlagPreservingFixture&) =
delete;
1909 VerboseFlagPreservingFixture& operator=(
const VerboseFlagPreservingFixture&) =
1913 #if GTEST_HAS_STREAM_REDIRECTION
1918 TEST(FunctionCallMessageTest,
1919 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
1923 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
1932 TEST(FunctionCallMessageTest,
1933 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
1937 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
1963 TEST(FunctionCallMessageTest,
1964 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
1972 "Uninteresting mock function call - returning default value.\n"
1973 " Function call: DoB()\n"
1981 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
1985 ContainsRegex(
"Uninteresting mock function call - returning directly\\.\n"
1986 " Function call: VoidMethod"
1987 "\\(false, 5, \"Hi\", NULL, @.+ "
1988 "Printable, 4-byte object <00-00 00-00>\\)"));
1994 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2000 void VerifyOutput(
const std::string& output,
bool should_print,
2001 const std::string& expected_substring,
2002 const std::string& function_name) {
2004 EXPECT_THAT(output.c_str(), HasSubstr(expected_substring));
2008 EXPECT_THAT(output.c_str(), HasSubstr(function_name));
2011 static_cast<void>(function_name);
2019 void TestExpectedCall(
bool should_print) {
2028 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
2029 " Function call: DoA(5)\n"
2037 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n"
2038 " Function call: Binary(2, 1)\n"
2045 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2047 const std::string note =
2048 "NOTE: You can safely ignore the above warning unless this "
2049 "call should not happen. Do not suppress it by blindly adding "
2050 "an EXPECT_CALL() if you don't mean to enforce the call. "
2052 "https://github.com/google/googletest/blob/main/docs/"
2053 "gmock_cook_book.md#"
2054 "knowing-when-to-expect-useoncall for details.";
2060 "\nGMOCK WARNING:\n"
2061 "Uninteresting mock function call - returning directly.\n"
2062 " Function call: DoA(5)\n" +
2070 "\nGMOCK WARNING:\n"
2071 "Uninteresting mock function call - returning default value.\n"
2072 " Function call: Binary(2, 1)\n"
2073 " Returns: false\n" +
2081 TEST_F(GMockVerboseFlagTest, Info) {
2083 TestExpectedCall(
true);
2084 TestUninterestingCallOnNaggyMock(
true);
2089 TEST_F(GMockVerboseFlagTest, Warning) {
2091 TestExpectedCall(
false);
2092 TestUninterestingCallOnNaggyMock(
true);
2097 TEST_F(GMockVerboseFlagTest, Error) {
2099 TestExpectedCall(
false);
2100 TestUninterestingCallOnNaggyMock(
false);
2105 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2107 TestExpectedCall(
false);
2108 TestUninterestingCallOnNaggyMock(
true);
2111 #endif // GTEST_HAS_STREAM_REDIRECTION
2116 class PrintMeNot {};
2118 void PrintTo(PrintMeNot , ::std::ostream* ) {
2119 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be "
2120 <<
"printed even to an internal buffer.";
2123 class LogTestHelper {
2125 LogTestHelper() =
default;
2130 LogTestHelper(
const LogTestHelper&) =
delete;
2131 LogTestHelper& operator=(
const LogTestHelper&) =
delete;
2134 class GMockLogTest :
public VerboseFlagPreservingFixture {
2139 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2145 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2151 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2159 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2160 MockA* a =
new MockA;
2164 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2165 MockA* a =
new MockA;
2171 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2172 MockA* a =
new MockA;
2177 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2178 MockA* a =
new MockA;
2184 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2185 MockA* a =
new MockA;
2190 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2191 MockA* a =
new MockA;
2199 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2201 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2212 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2216 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2227 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2232 "Actual: never called");
2243 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2249 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2259 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2266 "Actual: never called");
2277 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2281 Mock::VerifyAndClearExpectations(&b);
2285 Mock::VerifyAndClearExpectations(&b);
2286 Mock::VerifyAndClearExpectations(&b);
2296 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2299 Mock::VerifyAndClear(&b);
2305 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2309 Mock::VerifyAndClear(&b);
2317 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2322 Mock::VerifyAndClear(&b);
2333 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2338 Mock::VerifyAndClear(&b);
2348 TEST(VerifyAndClearTest, CanCallManyTimes) {
2351 Mock::VerifyAndClear(&b);
2352 Mock::VerifyAndClear(&b);
2355 Mock::VerifyAndClear(&b);
2362 TEST(VerifyAndClearTest, Success) {
2378 TEST(VerifyAndClearTest, Failure) {
2386 "Actual: never called");
2397 TEST(VerifyAndClearTest, Const) {
2415 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2421 Mock::VerifyAndClear(&b);
2432 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2447 Mock::VerifyAndClear(&b2);
2458 TEST(VerifyAndClearTest,
2459 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2460 std::shared_ptr<MockA>
a(
new MockA);
2461 ReferenceHoldingMock test_mock;
2465 .WillRepeatedly(SetArgPointee<0>(a));
2478 TEST(VerifyAndClearTest,
2479 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2480 std::shared_ptr<MockA>
a(
new MockA);
2481 ReferenceHoldingMock test_mock;
2484 ON_CALL(test_mock, AcceptReference(
_)).WillByDefault(SetArgPointee<0>(a));
2502 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2509 .WillOnce(
Invoke(&a, &MockA::DoA))
2510 .RetiresOnSaturation();
2520 TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) {
2523 ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0));
2524 int do_a_47_arg0 = 0;
2525 ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0));
2540 TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) {
2550 struct MockWithConstMethods {
2556 TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) {
2557 MockWithConstMethods mock;
2565 class MockConstOverload {
2571 TEST(ParameterlessExpectationsTest,
2572 CanSetExpectationsForConstOverloadedMethods) {
2573 MockConstOverload mock;
2576 ON_CALL(Const(mock), Overloaded(5)).WillByDefault(
Return(11));
2577 ON_CALL(Const(mock), Overloaded(7)).WillByDefault(
Return(13));
2583 const MockConstOverload& const_mock = mock;
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ std::string GetCapturedStdout()
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define ACTION_P(name,...)
GTEST_API_ Cardinality AtMost(int n)
#define MOCK_METHOD6(m,...)
TEST_F(TestInfoTest, Names)
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
const std::string saved_verbose_flag_
#define MOCK_METHOD0(m,...)
internal::DoAllAction< typename std::decay< Action >::type...> DoAll(Action &&...action)
#define ASSERT_EQ(val1, val2)
#define ON_CALL(obj, call)
GTEST_DISABLE_MSC_WARNINGS_POP_() template< int &...ExplicitParameterBarrier
GTEST_API_ void CaptureStdout()
#define EXPECT_ANY_THROW(statement)
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
std::ostream & operator<<(std::ostream &os, const Message &sb)
const char kInfoVerbosity[]
const char kWarningVerbosity[]
#define MOCK_METHOD2(m,...)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
expr expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c *expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr2 expr1 expr1 expr1 c
#define ASSERT_TRUE(condition)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
TEST(GTestEnvVarTest, Dummy)
#define GMOCK_FLAG_GET(name)
#define EXPECT_STREQ(s1, s2)
#define MOCK_METHOD1(m,...)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
#define MOCK_CONST_METHOD0(m,...)
#define GMOCK_FLAG_SET(name, value)
#define MOCK_CONST_METHOD2(m,...)
GTEST_API_ Cardinality Between(int min, int max)
void PrintTo(const T &value,::std::ostream *os)
#define EXPECT_THAT(value, matcher)
GTEST_API_ Cardinality AnyNumber()
internal::DoDefaultAction DoDefault()
internal::ReturnAction< R > Return(R value)
#define EXPECT_CALL(obj, call)
static GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED bool dummy2
#define EXPECT_EQ(val1, val2)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_TRUE(condition)
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
#define MOCK_CONST_METHOD1(m,...)
#define EXPECT_FALSE(condition)
const char kErrorVerbosity[]
#define ASSERT_FALSE(condition)
const char * Binary(const char *input, short n)