35 #include "gmock/gmock-spec-builders.h"
42 #include "gmock/gmock.h"
43 #include "gmock/internal/gmock-port.h"
44 #include "gtest/gtest.h"
45 #include "gtest/gtest-spi.h"
46 #include "gtest/internal/gtest-port.h"
52 class ExpectationTester {
104 #if GTEST_HAS_STREAM_REDIRECTION
112 class MockIncomplete {
120 void PrintTo(
const Incomplete&
x, ::std::ostream* os);
122 TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
127 MockIncomplete incomplete;
134 void PrintTo(
const Incomplete& , ::std::ostream* os) {
141 class NonDefaultConstructible {
143 explicit NonDefaultConstructible(
int ) {}
152 MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
171 class ReferenceHoldingMock {
173 ReferenceHoldingMock() {}
175 MOCK_METHOD1(AcceptReference,
void(std::shared_ptr<MockA>*));
186 #define Method MethodW
193 class MockCC :
public CC {
204 TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
211 TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
218 TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
225 TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
231 #undef Method // Done with macro redefinition tests.
235 TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
243 TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
253 TEST(OnCallSyntaxTest, WithIsOptional) {
263 TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
271 },
".With() cannot appear more than once in an ON_CALL()");
274 TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
283 TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
290 },
".WillByDefault() must appear exactly once in an ON_CALL()");
295 TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
304 TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
315 TEST(ExpectCallSyntaxTest, WithIsOptional) {
325 TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
332 },
".With() cannot appear more than once in an EXPECT_CALL()");
337 TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
344 },
".With() must be the first clause in an EXPECT_CALL()");
352 },
".With() must be the first clause in an EXPECT_CALL()");
357 TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
365 .WillRepeatedly(
Return());
372 TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
379 },
".Times() cannot appear more than once in an EXPECT_CALL()");
385 TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
393 },
".Times() may only appear *before* ");
398 TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
410 TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
421 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
431 },
".InSequence() cannot appear after ");
436 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
444 },
".InSequence() cannot appear after ");
449 TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
457 },
".After() cannot appear after ");
463 TEST(ExpectCallSyntaxTest, WillIsOptional) {
474 TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
484 TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
491 },
".WillOnce() cannot appear after ");
496 TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
503 .WillRepeatedly(
Return());
510 TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
516 .WillRepeatedly(
Return());
517 },
".WillRepeatedly() cannot appear more than once in an "
521 TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
526 .RetiresOnSaturation()
527 .WillRepeatedly(
Return());
528 },
".WillRepeatedly() cannot appear after ");
531 TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
536 .RetiresOnSaturation();
542 TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
547 .RetiresOnSaturation()
548 .RetiresOnSaturation();
549 },
".RetiresOnSaturation() cannot appear more than once");
554 TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
563 },
"to be called once");
569 },
"to be called once");
572 #if GTEST_HAS_STREAM_REDIRECTION
576 TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
588 .WillRepeatedly(
Return(1));
601 .WillRepeatedly(
Return(2));
612 TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
629 .RetiresOnSaturation();
635 .WillRepeatedly(
Return(1));
639 .WillRepeatedly(
Return(2));
648 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
649 "Expected to be never called, but has 1 WillOnce().",
653 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
654 "Expected to be called at most once, "
655 "but has 2 WillOnce()s.",
659 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n"
660 "Expected to be called once, but has 2 WillOnce()s.",
664 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
665 "Expected to be never called, but has 0 WillOnce()s "
666 "and a WillRepeatedly().",
670 "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n"
671 "Expected to be called once, but has 1 WillOnce() "
672 "and a WillRepeatedly().",
678 TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
690 "Too few actions specified in EXPECT_CALL(b, DoB())...\n"
691 "Expected to be called between 2 and 3 times, "
692 "but has only 1 WillOnce().",
697 TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
724 },
"Uninteresting mock function call");
751 #endif // GTEST_HAS_STREAM_REDIRECTION
757 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
766 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
769 .WillByDefault(
Return(1));
776 TEST(OnCallTest, PicksLastMatchingOnCall) {
779 .WillByDefault(
Return(3));
781 .WillByDefault(
Return(2));
783 .WillByDefault(
Return(1));
792 TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
805 TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
808 .WillRepeatedly(
Return(2));
810 .WillRepeatedly(
Return(1));
816 TEST(ExpectCallTest, CatchesTooFewCalls) {
823 },
"Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n"
824 " Expected: to be called at least twice\n"
825 " Actual: called once - unsatisfied and active");
830 TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
848 },
"to be called twice");
862 TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
867 .WillRepeatedly(
Return(2));
876 .WillRepeatedly(
Return(2));
887 .WillRepeatedly(
Return(2));
888 },
"to be called at least once");
893 TEST(ExpectCallTest, NthMatchTakesNthAction) {
907 TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
911 .WillRepeatedly(
Return(2));
918 #if GTEST_HAS_STREAM_REDIRECTION
922 TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
944 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
945 "Called 3 times, but only 2 WillOnce()s are specified"
946 " - returning default value."));
948 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
949 "Called 4 times, but only 2 WillOnce()s are specified"
950 " - returning default value."));
953 TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) {
967 TEST(FunctionMockerMessageTest,
968 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
980 #endif // GTEST_HAS_STREAM_REDIRECTION
983 TEST(UninterestingCallTest, DoesDefaultAction) {
988 .WillByDefault(
Return(
true));
998 TEST(UnexpectedCallTest, DoesDefaultAction) {
1003 .WillByDefault(
Return(
true));
1008 "Unexpected mock function call");
1018 "Unexpected mock function call");
1024 TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
1034 "Unexpected mock function call - returning directly.\n"
1035 " Function call: DoA(9)\n"
1036 "Google Mock tried the following 1 expectation, but it didn't match:");
1039 " Expected arg #0: is equal to 1\n"
1041 " Expected: to be called once\n"
1042 " Actual: called once - saturated and active");
1051 "Unexpected mock function call - returning directly.\n"
1052 " Function call: DoA(2)\n"
1053 "Google Mock tried the following 2 expectations, but none matched:");
1056 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n"
1057 " Expected arg #0: is equal to 1\n"
1059 " Expected: to be called once\n"
1060 " Actual: called once - saturated and active");
1063 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n"
1064 " Expected arg #0: is equal to 3\n"
1066 " Expected: to be called once\n"
1067 " Actual: never called - unsatisfied and active");
1073 TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
1079 "Unexpected mock function call - returning default value.\n"
1080 " Function call: DoB(2)\n"
1082 "Google Mock tried the following 1 expectation, but it didn't match:");
1085 " Expected arg #0: is equal to 1\n"
1087 " Expected: to be called once\n"
1088 " Actual: called once - saturated and active");
1093 TEST(UnexpectedCallTest, RetiredExpectation) {
1096 .RetiresOnSaturation();
1101 " Expected: the expectation is active\n"
1102 " Actual: it is retired");
1107 TEST(UnexpectedCallTest, UnmatchedArguments) {
1113 " Expected arg #0: is equal to 1\n"
1120 TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
1131 .InSequence(s1, s2);
1143 const ::testing::TestPartResult&
r =
failures.GetTestPartResult(0);
1152 "(?s)the following immediate pre-requisites are not satisfied:\n"
1153 ".*: pre-requisite #0\n"
1154 ".*: pre-requisite #1"));
1155 #elif GTEST_USES_POSIX_RE
1159 "the following immediate pre-requisites are not satisfied:\n"
1160 "(.|\n)*: pre-requisite #0\n"
1161 "(.|\n)*: pre-requisite #1"));
1165 "the following immediate pre-requisites are not satisfied:"));
1168 #endif // GTEST_USES_PCRE
1175 TEST(UndefinedReturnValueTest,
1176 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1181 #if GTEST_HAS_EXCEPTIONS
1190 TEST(ExcessiveCallTest, DoesDefaultAction) {
1195 .WillByDefault(
Return(
true));
1200 "Mock function called more times than expected");
1210 "Mock function called more times than expected");
1216 TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
1222 "Mock function called more times than expected - returning directly.\n"
1223 " Function call: DoA(9)\n"
1224 " Expected: to be never called\n"
1225 " Actual: called once - over-saturated and active");
1230 TEST(ExcessiveCallTest, GeneratesFailureForNonVoidFunction) {
1236 "Mock function called more times than expected - "
1237 "returning default value.\n"
1238 " Function call: DoB(2)\n"
1240 " Expected: to be called once\n"
1241 " Actual: called twice - over-saturated and active");
1246 TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1257 },
"Unexpected mock function call");
1263 TEST(InSequenceTest, NestedInSequence) {
1280 },
"Unexpected mock function call");
1286 TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1298 },
"Unexpected mock function call");
1306 TEST(SequenceTest, AnyOrderIsOkByDefault) {
1334 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1358 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1379 PartialOrderTest() {
1405 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1416 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1426 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1436 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1446 TEST(SequenceTest, Retirement) {
1454 .RetiresOnSaturation();
1465 TEST(ExpectationTest, ConstrutorsWork) {
1497 TEST(ExpectationTest, AssignmentWorks) {
1512 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1513 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1516 TEST(ExpectationSetTest, ConstructorsWork) {
1523 ExpectationSet es3 = e1;
1524 ExpectationSet es4(e1);
1525 ExpectationSet es5 = e2;
1526 ExpectationSet es6(e2);
1527 ExpectationSet es7 = es2;
1545 TEST(ExpectationSetTest, AssignmentWorks) {
1555 TEST(ExpectationSetTest, InsertionWorks) {
1567 ExpectationSet::const_iterator it1 = es1.begin();
1568 ExpectationSet::const_iterator it2 = it1;
1575 TEST(ExpectationSetTest, SizeWorks) {
1589 TEST(ExpectationSetTest, IsEnumerable) {
1594 ExpectationSet::const_iterator
it = es.begin();
1603 TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1616 TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1634 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1656 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1680 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1702 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1723 TEST(AfterTest, CanBeUsedWithInSequence) {
1742 TEST(AfterTest, CanBeCalledManyTimes) {
1759 TEST(AfterTest, AcceptsUpToFiveArguments) {
1767 .After(e1, e2, e3, es1, es2);
1778 TEST(AfterTest, AcceptsDuplicatedInput) {
1792 .After(e1, e2, es, e1);
1805 TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1822 TEST(DeletingMockEarlyTest, Success1) {
1823 MockB*
const b1 =
new MockB;
1824 MockA*
const a =
new MockA;
1825 MockB*
const b2 =
new MockB;
1833 .WillRepeatedly(
Return(
true));
1836 .WillRepeatedly(
Return(2));
1850 TEST(DeletingMockEarlyTest, Success2) {
1851 MockB*
const b1 =
new MockB;
1852 MockA*
const a =
new MockA;
1853 MockB*
const b2 =
new MockB;
1863 .WillRepeatedly(
Return(2));
1878 # pragma warning(push)
1879 # pragma warning(disable:4100)
1885 # pragma warning(pop)
1888 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1889 MockA*
const a =
new MockA;
1894 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1895 MockA*
const a =
new MockA;
1898 a->ReturnResult(42);
1902 TEST(DeletingMockEarlyTest, Failure1) {
1903 MockB*
const b1 =
new MockB;
1904 MockA*
const a =
new MockA;
1905 MockB*
const b2 =
new MockB;
1915 .WillRepeatedly(
Return(2));
1921 },
"Unexpected mock function call");
1928 TEST(DeletingMockEarlyTest, Failure2) {
1929 MockB*
const b1 =
new MockB;
1930 MockA*
const a =
new MockA;
1931 MockB*
const b2 =
new MockB;
1943 "Actual: never called");
1945 "Unexpected mock function call");
1947 "Unexpected mock function call");
1952 class EvenNumberCardinality :
public CardinalityInterface {
1956 bool IsSatisfiedByCallCount(
int call_count)
const override {
1957 return call_count % 2 == 0;
1962 bool IsSaturatedByCallCount(
int )
const override {
1967 void DescribeTo(::std::ostream* os)
const override {
1968 *os <<
"called even number of times";
1976 TEST(ExpectationBaseTest,
1977 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1978 MockA*
a =
new MockA;
1982 .Times(EvenNumber())
2002 inline void operator<<(::std::ostream& os,
const Printable&) {
2006 struct Unprintable {
2007 Unprintable() :
value(0) {}
2016 const Printable&
x, Unprintable
y));
2025 VerboseFlagPreservingFixture()
2028 ~VerboseFlagPreservingFixture()
override {
2038 #if GTEST_HAS_STREAM_REDIRECTION
2043 TEST(FunctionCallMessageTest,
2044 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
2048 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2057 TEST(FunctionCallMessageTest,
2058 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
2062 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2088 TEST(FunctionCallMessageTest,
2089 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2097 "Uninteresting mock function call - returning default value.\n"
2098 " Function call: DoB()\n"
2099 " Returns: 0\n", output1.c_str());
2105 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2109 "Uninteresting mock function call - returning directly\\.\n"
2110 " Function call: VoidMethod"
2111 "\\(false, 5, \"Hi\", NULL, @.+ "
2112 "Printable, 4-byte object <00-00 00-00>\\)"));
2118 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2135 static_cast<void>(function_name);
2143 void TestExpectedCall(
bool should_print) {
2155 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
2156 " Function call: DoA(5)\n"
2166 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n"
2167 " Function call: Binary(2, 1)\n"
2174 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2177 "NOTE: You can safely ignore the above warning unless this "
2178 "call should not happen. Do not suppress it by blindly adding "
2179 "an EXPECT_CALL() if you don't mean to enforce the call. "
2181 "https://github.com/google/googletest/blob/master/docs/"
2182 "gmock_cook_book.md#"
2183 "knowing-when-to-expect for details.";
2191 "\nGMOCK WARNING:\n"
2192 "Uninteresting mock function call - returning directly.\n"
2193 " Function call: DoA(5)\n" +
2203 "\nGMOCK WARNING:\n"
2204 "Uninteresting mock function call - returning default value.\n"
2205 " Function call: Binary(2, 1)\n"
2206 " Returns: false\n" +
2214 TEST_F(GMockVerboseFlagTest, Info) {
2216 TestExpectedCall(
true);
2217 TestUninterestingCallOnNaggyMock(
true);
2222 TEST_F(GMockVerboseFlagTest, Warning) {
2224 TestExpectedCall(
false);
2225 TestUninterestingCallOnNaggyMock(
true);
2230 TEST_F(GMockVerboseFlagTest, Error) {
2232 TestExpectedCall(
false);
2233 TestUninterestingCallOnNaggyMock(
false);
2238 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2240 TestExpectedCall(
false);
2241 TestUninterestingCallOnNaggyMock(
true);
2244 #endif // GTEST_HAS_STREAM_REDIRECTION
2249 class PrintMeNot {};
2251 void PrintTo(PrintMeNot , ::std::ostream* ) {
2252 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be "
2253 <<
"printed even to an internal buffer.";
2256 class LogTestHelper {
2266 class GMockLogTest :
public VerboseFlagPreservingFixture {
2268 LogTestHelper helper_;
2271 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2274 .WillOnce(
Return(PrintMeNot()));
2275 helper_.Foo(PrintMeNot());
2278 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2281 .WillOnce(
Return(PrintMeNot()));
2282 helper_.Foo(PrintMeNot());
2285 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2288 .WillByDefault(
Return(PrintMeNot()));
2289 helper_.Foo(PrintMeNot());
2294 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2295 MockA*
a =
new MockA;
2299 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2300 MockA*
a =
new MockA;
2306 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2307 MockA*
a =
new MockA;
2312 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2313 MockA*
a =
new MockA;
2319 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2320 MockA*
a =
new MockA;
2325 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2326 MockA*
a =
new MockA;
2334 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2347 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2363 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2369 "Actual: never called");
2380 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2398 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2407 "Actual: never called");
2418 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2422 Mock::VerifyAndClearExpectations(&
b);
2427 Mock::VerifyAndClearExpectations(&
b);
2428 Mock::VerifyAndClearExpectations(&
b);
2438 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2441 Mock::VerifyAndClear(&
b);
2447 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2450 .WillByDefault(
Return(1));
2452 Mock::VerifyAndClear(&
b);
2460 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2463 .WillByDefault(
Return(1));
2465 .WillByDefault(
Return(2));
2467 Mock::VerifyAndClear(&
b);
2478 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2481 .WillByDefault(
Return(1));
2483 .WillByDefault(
Return(2));
2485 Mock::VerifyAndClear(&
b);
2495 TEST(VerifyAndClearTest, CanCallManyTimes) {
2498 .WillByDefault(
Return(1));
2499 Mock::VerifyAndClear(&
b);
2500 Mock::VerifyAndClear(&
b);
2503 .WillByDefault(
Return(1));
2504 Mock::VerifyAndClear(&
b);
2511 TEST(VerifyAndClearTest, Success) {
2514 .WillByDefault(
Return(1));
2529 TEST(VerifyAndClearTest, Failure) {
2532 .WillByDefault(
Return(1));
2539 "Actual: never called");
2553 .WillByDefault(
Return(1));
2571 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2574 .WillByDefault(
Return(1));
2579 Mock::VerifyAndClear(&
b);
2584 .WillByDefault(
Return(4));
2592 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2598 .WillByDefault(
Return(
true));
2601 .WillOnce(
Return(
false));
2604 .WillByDefault(
Return(1));
2609 .WillByDefault(
Return(3));
2613 Mock::VerifyAndClear(&
b2);
2624 TEST(VerifyAndClearTest,
2625 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2626 std::shared_ptr<MockA>
a(
new MockA);
2627 ReferenceHoldingMock test_mock;
2631 .WillRepeatedly(SetArgPointee<0>(
a));
2644 TEST(VerifyAndClearTest,
2645 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2646 std::shared_ptr<MockA>
a(
new MockA);
2647 ReferenceHoldingMock test_mock;
2650 ON_CALL(test_mock, AcceptReference(
_))
2651 .WillByDefault(SetArgPointee<0>(
a));
2669 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2674 &MockC::NonVoidMethod)));
2677 .WillOnce(
Invoke(&
a, &MockA::DoA))
2678 .RetiresOnSaturation();
2688 TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) {
2691 ON_CALL(
a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0));
2692 int do_a_47_arg0 = 0;
2693 ON_CALL(
a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0));
2708 TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) {
2718 struct MockWithConstMethods {
2724 TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) {
2725 MockWithConstMethods mock;
2733 class MockConstOverload {
2739 TEST(ParameterlessExpectationsTest,
2740 CanSetExpectationsForConstOverloadedMethods) {
2741 MockConstOverload mock;
2751 const MockConstOverload& const_mock = mock;
2762 #if GMOCK_RENAME_MAIN
2763 int gmock_main(
int argc,
char **argv) {
2766 #endif // GMOCK_RENAME_MAIN