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"
105 #if GTEST_HAS_STREAM_REDIRECTION
113 class MockIncomplete {
121 void PrintTo(
const Incomplete&
x, ::std::ostream* os);
123 TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
128 MockIncomplete incomplete;
135 void PrintTo(
const Incomplete& , ::std::ostream* os) {
142 class NonDefaultConstructible {
144 explicit NonDefaultConstructible(
int ) {}
153 MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
172 class ReferenceHoldingMock {
174 ReferenceHoldingMock() {}
176 MOCK_METHOD1(AcceptReference,
void(std::shared_ptr<MockA>*));
187 #define Method MethodW
194 class MockCC :
public CC {
205 TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
212 TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
219 TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
226 TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
232 #undef Method // Done with macro redefinition tests.
236 TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
244 TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
254 TEST(OnCallSyntaxTest, WithIsOptional) {
264 TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
272 },
".With() cannot appear more than once in an ON_CALL()");
275 TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
284 TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
291 },
".WillByDefault() must appear exactly once in an ON_CALL()");
296 TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
305 TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
316 TEST(ExpectCallSyntaxTest, WithIsOptional) {
326 TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
333 },
".With() cannot appear more than once in an EXPECT_CALL()");
338 TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
345 },
".With() must be the first clause in an EXPECT_CALL()");
353 },
".With() must be the first clause in an EXPECT_CALL()");
358 TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
366 .WillRepeatedly(
Return());
373 TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
380 },
".Times() cannot appear more than once in an EXPECT_CALL()");
386 TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
394 },
".Times() cannot appear after ");
399 TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
411 TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
422 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
432 },
".InSequence() cannot appear after ");
437 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
445 },
".InSequence() cannot appear after ");
450 TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
458 },
".After() cannot appear after ");
464 TEST(ExpectCallSyntaxTest, WillIsOptional) {
475 TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
485 TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
492 },
".WillOnce() cannot appear after ");
497 TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
504 .WillRepeatedly(
Return());
511 TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
517 .WillRepeatedly(
Return());
518 },
".WillRepeatedly() cannot appear more than once in an "
522 TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
527 .RetiresOnSaturation()
528 .WillRepeatedly(
Return());
529 },
".WillRepeatedly() cannot appear after ");
532 TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
537 .RetiresOnSaturation();
543 TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
548 .RetiresOnSaturation()
549 .RetiresOnSaturation();
550 },
".RetiresOnSaturation() cannot appear more than once");
555 TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
564 },
"to be called once");
570 },
"to be called once");
573 #if GTEST_HAS_STREAM_REDIRECTION
577 TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
589 .WillRepeatedly(
Return(1));
602 .WillRepeatedly(
Return(2));
613 TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
630 .RetiresOnSaturation();
636 .WillRepeatedly(
Return(1));
640 .WillRepeatedly(
Return(2));
649 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
650 "Expected to be never called, but has 1 WillOnce().",
654 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
655 "Expected to be called at most once, "
656 "but has 2 WillOnce()s.",
660 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n"
661 "Expected to be called once, but has 2 WillOnce()s.",
665 "Too many actions specified in EXPECT_CALL(b, DoB())...\n"
666 "Expected to be never called, but has 0 WillOnce()s "
667 "and a WillRepeatedly().",
671 "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n"
672 "Expected to be called once, but has 1 WillOnce() "
673 "and a WillRepeatedly().",
679 TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
691 "Too few actions specified in EXPECT_CALL(b, DoB())...\n"
692 "Expected to be called between 2 and 3 times, "
693 "but has only 1 WillOnce().",
698 TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
725 },
"Uninteresting mock function call");
752 #endif // GTEST_HAS_STREAM_REDIRECTION
758 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
767 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
770 .WillByDefault(
Return(1));
777 TEST(OnCallTest, PicksLastMatchingOnCall) {
780 .WillByDefault(
Return(3));
782 .WillByDefault(
Return(2));
784 .WillByDefault(
Return(1));
793 TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
806 TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
809 .WillRepeatedly(
Return(2));
811 .WillRepeatedly(
Return(1));
817 TEST(ExpectCallTest, CatchesTooFewCalls) {
824 },
"Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n"
825 " Expected: to be called at least twice\n"
826 " Actual: called once - unsatisfied and active");
831 TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
849 },
"to be called twice");
863 TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
868 .WillRepeatedly(
Return(2));
877 .WillRepeatedly(
Return(2));
888 .WillRepeatedly(
Return(2));
889 },
"to be called at least once");
894 TEST(ExpectCallTest, NthMatchTakesNthAction) {
908 TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
912 .WillRepeatedly(
Return(2));
919 #if GTEST_HAS_STREAM_REDIRECTION
923 TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
945 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
946 "Called 3 times, but only 2 WillOnce()s are specified"
947 " - returning default value."));
949 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n"
950 "Called 4 times, but only 2 WillOnce()s are specified"
951 " - returning default value."));
954 TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) {
968 TEST(FunctionMockerMessageTest,
969 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
981 #endif // GTEST_HAS_STREAM_REDIRECTION
984 TEST(UninterestingCallTest, DoesDefaultAction) {
989 .WillByDefault(
Return(
true));
999 TEST(UnexpectedCallTest, DoesDefaultAction) {
1004 .WillByDefault(
Return(
true));
1009 "Unexpected mock function call");
1019 "Unexpected mock function call");
1025 TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
1035 "Unexpected mock function call - returning directly.\n"
1036 " Function call: DoA(9)\n"
1037 "Google Mock tried the following 1 expectation, but it didn't match:");
1040 " Expected arg #0: is equal to 1\n"
1042 " Expected: to be called once\n"
1043 " Actual: called once - saturated and active");
1052 "Unexpected mock function call - returning directly.\n"
1053 " Function call: DoA(2)\n"
1054 "Google Mock tried the following 2 expectations, but none matched:");
1057 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n"
1058 " Expected arg #0: is equal to 1\n"
1060 " Expected: to be called once\n"
1061 " Actual: called once - saturated and active");
1064 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n"
1065 " Expected arg #0: is equal to 3\n"
1067 " Expected: to be called once\n"
1068 " Actual: never called - unsatisfied and active");
1074 TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
1080 "Unexpected mock function call - returning default value.\n"
1081 " Function call: DoB(2)\n"
1083 "Google Mock tried the following 1 expectation, but it didn't match:");
1086 " Expected arg #0: is equal to 1\n"
1088 " Expected: to be called once\n"
1089 " Actual: called once - saturated and active");
1094 TEST(UnexpectedCallTest, RetiredExpectation) {
1097 .RetiresOnSaturation();
1102 " Expected: the expectation is active\n"
1103 " Actual: it is retired");
1108 TEST(UnexpectedCallTest, UnmatchedArguments) {
1114 " Expected arg #0: is equal to 1\n"
1121 TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
1132 .InSequence(s1, s2);
1144 const ::testing::TestPartResult&
r =
failures.GetTestPartResult(0);
1153 "(?s)the following immediate pre-requisites are not satisfied:\n"
1154 ".*: pre-requisite #0\n"
1155 ".*: pre-requisite #1"));
1156 #elif GTEST_USES_POSIX_RE
1160 "the following immediate pre-requisites are not satisfied:\n"
1161 "(.|\n)*: pre-requisite #0\n"
1162 "(.|\n)*: pre-requisite #1"));
1166 "the following immediate pre-requisites are not satisfied:"));
1169 #endif // GTEST_USES_PCRE
1176 TEST(UndefinedReturnValueTest,
1177 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1182 #if GTEST_HAS_EXCEPTIONS
1191 TEST(ExcessiveCallTest, DoesDefaultAction) {
1196 .WillByDefault(
Return(
true));
1201 "Mock function called more times than expected");
1211 "Mock function called more times than expected");
1217 TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
1223 "Mock function called more times than expected - returning directly.\n"
1224 " Function call: DoA(9)\n"
1225 " Expected: to be never called\n"
1226 " Actual: called once - over-saturated and active");
1231 TEST(ExcessiveCallTest, GeneratesFailureForNonVoidFunction) {
1237 "Mock function called more times than expected - "
1238 "returning default value.\n"
1239 " Function call: DoB(2)\n"
1241 " Expected: to be called once\n"
1242 " Actual: called twice - over-saturated and active");
1247 TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1258 },
"Unexpected mock function call");
1264 TEST(InSequenceTest, NestedInSequence) {
1281 },
"Unexpected mock function call");
1287 TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1299 },
"Unexpected mock function call");
1307 TEST(SequenceTest, AnyOrderIsOkByDefault) {
1335 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1359 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1380 PartialOrderTest() {
1406 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1417 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1427 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1437 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1447 TEST(SequenceTest, Retirement) {
1455 .RetiresOnSaturation();
1466 TEST(ExpectationTest, ConstrutorsWork) {
1498 TEST(ExpectationTest, AssignmentWorks) {
1513 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1514 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1517 TEST(ExpectationSetTest, ConstructorsWork) {
1524 ExpectationSet es3 = e1;
1525 ExpectationSet es4(e1);
1526 ExpectationSet es5 = e2;
1527 ExpectationSet es6(e2);
1528 ExpectationSet es7 = es2;
1546 TEST(ExpectationSetTest, AssignmentWorks) {
1556 TEST(ExpectationSetTest, InsertionWorks) {
1568 ExpectationSet::const_iterator it1 = es1.begin();
1569 ExpectationSet::const_iterator it2 = it1;
1576 TEST(ExpectationSetTest, SizeWorks) {
1590 TEST(ExpectationSetTest, IsEnumerable) {
1595 ExpectationSet::const_iterator
it = es.begin();
1604 TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1617 TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1635 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1657 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1681 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1703 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1724 TEST(AfterTest, CanBeUsedWithInSequence) {
1743 TEST(AfterTest, CanBeCalledManyTimes) {
1760 TEST(AfterTest, AcceptsUpToFiveArguments) {
1768 .After(e1, e2, e3, es1, es2);
1779 TEST(AfterTest, AcceptsDuplicatedInput) {
1793 .After(e1, e2, es, e1);
1806 TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1823 TEST(DeletingMockEarlyTest, Success1) {
1824 MockB*
const b1 =
new MockB;
1825 MockA*
const a =
new MockA;
1826 MockB*
const b2 =
new MockB;
1834 .WillRepeatedly(
Return(
true));
1837 .WillRepeatedly(
Return(2));
1851 TEST(DeletingMockEarlyTest, Success2) {
1852 MockB*
const b1 =
new MockB;
1853 MockA*
const a =
new MockA;
1854 MockB*
const b2 =
new MockB;
1864 .WillRepeatedly(
Return(2));
1879 # pragma warning(push)
1880 # pragma warning(disable:4100)
1886 # pragma warning(pop)
1889 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1890 MockA*
const a =
new MockA;
1895 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1896 MockA*
const a =
new MockA;
1899 a->ReturnResult(42);
1903 TEST(DeletingMockEarlyTest, Failure1) {
1904 MockB*
const b1 =
new MockB;
1905 MockA*
const a =
new MockA;
1906 MockB*
const b2 =
new MockB;
1916 .WillRepeatedly(
Return(2));
1922 },
"Unexpected mock function call");
1929 TEST(DeletingMockEarlyTest, Failure2) {
1930 MockB*
const b1 =
new MockB;
1931 MockA*
const a =
new MockA;
1932 MockB*
const b2 =
new MockB;
1944 "Actual: never called");
1946 "Unexpected mock function call");
1948 "Unexpected mock function call");
1953 class EvenNumberCardinality :
public CardinalityInterface {
1956 bool IsSatisfiedByCallCount(
int call_count)
const override {
1957 return call_count % 2 == 0;
1961 bool IsSaturatedByCallCount(
int )
const override {
1966 void DescribeTo(::std::ostream* os)
const override {
1967 *os <<
"called even number of times";
1975 TEST(ExpectationBaseTest,
1976 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1977 MockA*
a =
new MockA;
1981 .Times(EvenNumber())
2001 inline void operator<<(::std::ostream& os,
const Printable&) {
2005 struct Unprintable {
2006 Unprintable() :
value(0) {}
2015 const Printable&
x, Unprintable
y));
2024 VerboseFlagPreservingFixture()
2027 ~VerboseFlagPreservingFixture()
override {
2037 #if GTEST_HAS_STREAM_REDIRECTION
2042 TEST(FunctionCallMessageTest,
2043 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
2047 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2056 TEST(FunctionCallMessageTest,
2057 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
2061 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2087 TEST(FunctionCallMessageTest,
2088 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2096 "Uninteresting mock function call - returning default value.\n"
2097 " Function call: DoB()\n"
2098 " Returns: 0\n", output1.c_str());
2104 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2108 "Uninteresting mock function call - returning directly\\.\n"
2109 " Function call: VoidMethod"
2110 "\\(false, 5, \"Hi\", NULL, @.+ "
2111 "Printable, 4-byte object <00-00 00-00>\\)"));
2117 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2134 static_cast<void>(function_name);
2142 void TestExpectedCall(
bool should_print) {
2154 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
2155 " Function call: DoA(5)\n"
2165 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n"
2166 " Function call: Binary(2, 1)\n"
2173 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2176 "NOTE: You can safely ignore the above warning unless this "
2177 "call should not happen. Do not suppress it by blindly adding "
2178 "an EXPECT_CALL() if you don't mean to enforce the call. "
2180 "https://github.com/google/googletest/blob/master/googlemock/docs/"
2182 "knowing-when-to-expect for details.";
2190 "\nGMOCK WARNING:\n"
2191 "Uninteresting mock function call - returning directly.\n"
2192 " Function call: DoA(5)\n" +
2202 "\nGMOCK WARNING:\n"
2203 "Uninteresting mock function call - returning default value.\n"
2204 " Function call: Binary(2, 1)\n"
2205 " Returns: false\n" +
2213 TEST_F(GMockVerboseFlagTest, Info) {
2215 TestExpectedCall(
true);
2216 TestUninterestingCallOnNaggyMock(
true);
2221 TEST_F(GMockVerboseFlagTest, Warning) {
2223 TestExpectedCall(
false);
2224 TestUninterestingCallOnNaggyMock(
true);
2229 TEST_F(GMockVerboseFlagTest, Error) {
2231 TestExpectedCall(
false);
2232 TestUninterestingCallOnNaggyMock(
false);
2237 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2239 TestExpectedCall(
false);
2240 TestUninterestingCallOnNaggyMock(
true);
2243 #endif // GTEST_HAS_STREAM_REDIRECTION
2248 class PrintMeNot {};
2250 void PrintTo(PrintMeNot , ::std::ostream* ) {
2251 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be "
2252 <<
"printed even to an internal buffer.";
2255 class LogTestHelper {
2265 class GMockLogTest :
public VerboseFlagPreservingFixture {
2267 LogTestHelper helper_;
2270 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2273 .WillOnce(
Return(PrintMeNot()));
2274 helper_.Foo(PrintMeNot());
2277 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2280 .WillOnce(
Return(PrintMeNot()));
2281 helper_.Foo(PrintMeNot());
2284 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2287 .WillByDefault(
Return(PrintMeNot()));
2288 helper_.Foo(PrintMeNot());
2293 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2294 MockA*
a =
new MockA;
2298 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2299 MockA*
a =
new MockA;
2305 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2306 MockA*
a =
new MockA;
2311 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2312 MockA*
a =
new MockA;
2318 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2319 MockA*
a =
new MockA;
2324 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2325 MockA*
a =
new MockA;
2333 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2346 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2362 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2368 "Actual: never called");
2379 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2397 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2406 "Actual: never called");
2417 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2421 Mock::VerifyAndClearExpectations(&
b);
2426 Mock::VerifyAndClearExpectations(&
b);
2427 Mock::VerifyAndClearExpectations(&
b);
2437 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2440 Mock::VerifyAndClear(&
b);
2446 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2449 .WillByDefault(
Return(1));
2451 Mock::VerifyAndClear(&
b);
2459 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2462 .WillByDefault(
Return(1));
2464 .WillByDefault(
Return(2));
2466 Mock::VerifyAndClear(&
b);
2477 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2480 .WillByDefault(
Return(1));
2482 .WillByDefault(
Return(2));
2484 Mock::VerifyAndClear(&
b);
2494 TEST(VerifyAndClearTest, CanCallManyTimes) {
2497 .WillByDefault(
Return(1));
2498 Mock::VerifyAndClear(&
b);
2499 Mock::VerifyAndClear(&
b);
2502 .WillByDefault(
Return(1));
2503 Mock::VerifyAndClear(&
b);
2510 TEST(VerifyAndClearTest, Success) {
2513 .WillByDefault(
Return(1));
2528 TEST(VerifyAndClearTest, Failure) {
2531 .WillByDefault(
Return(1));
2538 "Actual: never called");
2552 .WillByDefault(
Return(1));
2570 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2573 .WillByDefault(
Return(1));
2578 Mock::VerifyAndClear(&
b);
2583 .WillByDefault(
Return(4));
2591 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2597 .WillByDefault(
Return(
true));
2600 .WillOnce(
Return(
false));
2603 .WillByDefault(
Return(1));
2608 .WillByDefault(
Return(3));
2612 Mock::VerifyAndClear(&
b2);
2623 TEST(VerifyAndClearTest,
2624 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2625 std::shared_ptr<MockA>
a(
new MockA);
2626 ReferenceHoldingMock test_mock;
2630 .WillRepeatedly(SetArgPointee<0>(
a));
2643 TEST(VerifyAndClearTest,
2644 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2645 std::shared_ptr<MockA>
a(
new MockA);
2646 ReferenceHoldingMock test_mock;
2649 ON_CALL(test_mock, AcceptReference(
_))
2650 .WillByDefault(SetArgPointee<0>(
a));
2668 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2673 &MockC::NonVoidMethod)));
2676 .WillOnce(
Invoke(&
a, &MockA::DoA))
2677 .RetiresOnSaturation();
2687 TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) {
2690 ON_CALL(
a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0));
2691 int do_a_47_arg0 = 0;
2692 ON_CALL(
a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0));
2707 TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) {
2717 struct MockWithConstMethods {
2723 TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) {
2724 MockWithConstMethods mock;
2732 class MockConstOverload {
2738 TEST(ParameterlessExpectationsTest,
2739 CanSetExpectationsForConstOverloadedMethods) {
2740 MockConstOverload mock;
2750 const MockConstOverload& const_mock = mock;
2761 #if GMOCK_RENAME_MAIN
2762 int gmock_main(
int argc,
char **argv) {
2765 #endif // GMOCK_RENAME_MAIN