42 #include "gmock/gmock.h" 44 #include "gtest/gtest.h" 45 #include "gtest/gtest-spi.h" 46 #include "gtest/internal/gtest-port.h" 101 #if GTEST_HAS_STREAM_REDIRECTION 109 class MockIncomplete {
117 void PrintTo(
const Incomplete& x, ::std::ostream* os);
119 TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
124 MockIncomplete incomplete;
131 void PrintTo(
const Incomplete& , ::std::ostream* os) {
161 class ReferenceHoldingMock {
163 ReferenceHoldingMock() {}
176 #define Method MethodW 183 class MockCC :
public CC {
194 TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
201 TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
208 TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
215 TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
221 #undef Method // Done with macro redefinition tests. 225 TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
233 TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
243 TEST(OnCallSyntaxTest, WithIsOptional) {
253 TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
260 .WillByDefault(
Return(Result()));
261 },
".With() cannot appear more than once in an ON_CALL()");
264 TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
273 TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
280 },
".WillByDefault() must appear exactly once in an ON_CALL()");
285 TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
294 TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
305 TEST(ExpectCallSyntaxTest, WithIsOptional) {
315 TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
322 },
".With() cannot appear more than once in an EXPECT_CALL()");
327 TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
334 },
".With() must be the first clause in an EXPECT_CALL()");
342 },
".With() must be the first clause in an EXPECT_CALL()");
347 TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
355 .WillRepeatedly(
Return());
362 TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
369 },
".Times() cannot appear more than once in an EXPECT_CALL()");
375 TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
383 },
".Times() cannot appear after ");
388 TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
400 TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
411 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
421 },
".InSequence() cannot appear after ");
426 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
434 },
".InSequence() cannot appear after ");
439 TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
447 },
".After() cannot appear after ");
453 TEST(ExpectCallSyntaxTest, WillIsOptional) {
464 TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
474 TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
481 },
".WillOnce() cannot appear after ");
486 TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
493 .WillRepeatedly(
Return());
500 TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
506 .WillRepeatedly(
Return());
507 },
".WillRepeatedly() cannot appear more than once in an " 511 TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
516 .RetiresOnSaturation()
517 .WillRepeatedly(
Return());
518 },
".WillRepeatedly() cannot appear after ");
521 TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
526 .RetiresOnSaturation();
532 TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
537 .RetiresOnSaturation()
538 .RetiresOnSaturation();
539 },
".RetiresOnSaturation() cannot appear more than once");
544 TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
553 },
"to be called once");
559 },
"to be called once");
562 #if GTEST_HAS_STREAM_REDIRECTION 566 TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
578 .WillRepeatedly(
Return(1));
582 .Times(Between(1, 2))
591 .WillRepeatedly(
Return(2));
602 TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
619 .RetiresOnSaturation();
625 .WillRepeatedly(
Return(1));
629 .WillRepeatedly(
Return(2));
638 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 639 "Expected to be never called, but has 1 WillOnce().",
643 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 644 "Expected to be called at most once, " 645 "but has 2 WillOnce()s.",
649 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n" 650 "Expected to be called once, but has 2 WillOnce()s.",
654 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 655 "Expected to be never called, but has 0 WillOnce()s " 656 "and a WillRepeatedly().",
660 "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n" 661 "Expected to be called once, but has 1 WillOnce() " 662 "and a WillRepeatedly().",
668 TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
672 .Times(Between(2, 3))
680 "Too few actions specified in EXPECT_CALL(b, DoB())...\n" 681 "Expected to be called between 2 and 3 times, " 682 "but has only 1 WillOnce().",
687 #endif // GTEST_HAS_STREAM_REDIRECTION 693 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
702 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
705 .WillByDefault(
Return(1));
712 TEST(OnCallTest, PicksLastMatchingOnCall) {
715 .WillByDefault(
Return(3));
717 .WillByDefault(
Return(2));
719 .WillByDefault(
Return(1));
728 TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
741 TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
744 .WillRepeatedly(
Return(2));
746 .WillRepeatedly(
Return(1));
752 TEST(ExpectCallTest, CatchesTooFewCalls) {
759 },
"Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n" 760 " Expected: to be called at least twice\n" 761 " Actual: called once - unsatisfied and active");
766 TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
784 },
"to be called twice");
798 TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
803 .WillRepeatedly(
Return(2));
812 .WillRepeatedly(
Return(2));
823 .WillRepeatedly(
Return(2));
824 },
"to be called at least once");
829 TEST(ExpectCallTest, NthMatchTakesNthAction) {
843 TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
847 .WillRepeatedly(
Return(2));
854 #if GTEST_HAS_STREAM_REDIRECTION 858 TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
880 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n" 881 "Called 3 times, but only 2 WillOnce()s are specified" 882 " - returning default value."));
884 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n" 885 "Called 4 times, but only 2 WillOnce()s are specified" 886 " - returning default value."));
889 TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) {
903 TEST(FunctionMockerMessageTest,
904 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
916 #endif // GTEST_HAS_STREAM_REDIRECTION 919 TEST(UninterestingCallTest, DoesDefaultAction) {
924 .WillByDefault(
Return(
true));
934 TEST(UnexpectedCallTest, DoesDefaultAction) {
939 .WillByDefault(
Return(
true));
944 "Unexpected mock function call");
954 "Unexpected mock function call");
960 TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
970 "Unexpected mock function call - returning directly.\n" 971 " Function call: DoA(9)\n" 972 "Google Mock tried the following 1 expectation, but it didn't match:");
975 " Expected arg #0: is equal to 1\n" 977 " Expected: to be called once\n" 978 " Actual: called once - saturated and active");
987 "Unexpected mock function call - returning directly.\n" 988 " Function call: DoA(2)\n" 989 "Google Mock tried the following 2 expectations, but none matched:");
992 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n" 993 " Expected arg #0: is equal to 1\n" 995 " Expected: to be called once\n" 996 " Actual: called once - saturated and active");
999 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n" 1000 " Expected arg #0: is equal to 3\n" 1002 " Expected: to be called once\n" 1003 " Actual: never called - unsatisfied and active");
1009 TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
1015 "Unexpected mock function call - returning default value.\n" 1016 " Function call: DoB(2)\n" 1018 "Google Mock tried the following 1 expectation, but it didn't match:");
1021 " Expected arg #0: is equal to 1\n" 1023 " Expected: to be called once\n" 1024 " Actual: called once - saturated and active");
1029 TEST(UnexpectedCallTest, RetiredExpectation) {
1032 .RetiresOnSaturation();
1037 " Expected: the expectation is active\n" 1038 " Actual: it is retired");
1043 TEST(UnexpectedCallTest, UnmatchedArguments) {
1049 " Expected arg #0: is equal to 1\n" 1056 TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
1067 .InSequence(s1, s2);
1088 "(?s)the following immediate pre-requisites are not satisfied:\n" 1089 ".*: pre-requisite #0\n" 1090 ".*: pre-requisite #1"));
1091 #elif GTEST_USES_POSIX_RE 1095 "the following immediate pre-requisites are not satisfied:\n" 1096 "(.|\n)*: pre-requisite #0\n" 1097 "(.|\n)*: pre-requisite #1"));
1101 "the following immediate pre-requisites are not satisfied:"));
1104 #endif // GTEST_USES_PCRE 1111 TEST(UndefinedReturnValueTest, ReturnValueIsMandatory) {
1116 #if GTEST_HAS_EXCEPTIONS 1125 TEST(ExcessiveCallTest, DoesDefaultAction) {
1130 .WillByDefault(
Return(
true));
1133 bool result =
false;
1135 "Mock function called more times than expected");
1145 "Mock function called more times than expected");
1151 TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
1157 "Mock function called more times than expected - returning directly.\n" 1158 " Function call: DoA(9)\n" 1159 " Expected: to be never called\n" 1160 " Actual: called once - over-saturated and active");
1165 TEST(ExcessiveCallTest, GeneratesFailureForNonVoidFunction) {
1171 "Mock function called more times than expected - " 1172 "returning default value.\n" 1173 " Function call: DoB(2)\n" 1175 " Expected: to be called once\n" 1176 " Actual: called twice - over-saturated and active");
1181 TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1192 },
"Unexpected mock function call");
1198 TEST(InSequenceTest, NestedInSequence) {
1215 },
"Unexpected mock function call");
1221 TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1233 },
"Unexpected mock function call");
1241 TEST(SequenceTest, AnyOrderIsOkByDefault) {
1269 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1272 .WillByDefault(
Return(Result()));
1293 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1296 .WillByDefault(
Return(Result()));
1314 PartialOrderTest() {
1316 .WillByDefault(
Return(Result()));
1340 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1351 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1361 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1371 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1381 TEST(SequenceTest, Retirement) {
1389 .RetiresOnSaturation();
1400 TEST(ExpectationTest, ConstrutorsWork) {
1410 Expectation e5 =
EXPECT_CALL(a, DoA(5)).InSequence(s);
1412 Expectation e6 =
EXPECT_CALL(a, DoA(6)).After(e2);
1415 Expectation e9 =
EXPECT_CALL(a, DoA(9)).RetiresOnSaturation();
1417 Expectation e10 = e2;
1432 TEST(ExpectationTest, AssignmentWorks) {
1447 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1448 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1451 TEST(ExpectationSetTest, ConstructorsWork) {
1455 const Expectation e2;
1458 ExpectationSet es3 = e1;
1459 ExpectationSet es4(e1);
1460 ExpectationSet es5 = e2;
1461 ExpectationSet es6(e2);
1462 ExpectationSet es7 = es2;
1480 TEST(ExpectationSetTest, AssignmentWorks) {
1482 ExpectationSet es2 = Expectation();
1490 TEST(ExpectationSetTest, InsertionWorks) {
1510 TEST(ExpectationSetTest, SizeWorks) {
1514 es += Expectation();
1524 TEST(ExpectationSetTest, IsEnumerable) {
1528 es += Expectation();
1538 TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1551 TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1569 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1591 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1615 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1618 .WillByDefault(
Return(Result()));
1637 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1658 TEST(AfterTest, CanBeUsedWithInSequence) {
1677 TEST(AfterTest, CanBeCalledManyTimes) {
1694 TEST(AfterTest, AcceptsUpToFiveArguments) {
1702 .After(e1, e2, e3, es1, es2);
1713 TEST(AfterTest, AcceptsDuplicatedInput) {
1716 .WillByDefault(
Return(Result()));
1727 .After(e1, e2, es, e1);
1740 TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1757 TEST(DeletingMockEarlyTest, Success1) {
1758 MockB*
const b1 =
new MockB;
1759 MockA*
const a =
new MockA;
1760 MockB*
const b2 =
new MockB;
1768 .WillRepeatedly(
Return(
true));
1771 .WillRepeatedly(
Return(2));
1785 TEST(DeletingMockEarlyTest, Success2) {
1786 MockB*
const b1 =
new MockB;
1787 MockA*
const a =
new MockA;
1788 MockB*
const b2 =
new MockB;
1798 .WillRepeatedly(
Return(2));
1813 # pragma warning(push) 1814 # pragma warning(disable:4100) 1820 # pragma warning(pop) 1823 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1824 MockA*
const a =
new MockA;
1829 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1830 MockA*
const a =
new MockA;
1833 a->ReturnResult(42);
1837 TEST(DeletingMockEarlyTest, Failure1) {
1838 MockB*
const b1 =
new MockB;
1839 MockA*
const a =
new MockA;
1840 MockB*
const b2 =
new MockB;
1850 .WillRepeatedly(
Return(2));
1856 },
"Unexpected mock function call");
1863 TEST(DeletingMockEarlyTest, Failure2) {
1864 MockB*
const b1 =
new MockB;
1865 MockA*
const a =
new MockA;
1866 MockB*
const b2 =
new MockB;
1878 "Actual: never called");
1880 "Unexpected mock function call");
1882 "Unexpected mock function call");
1887 class EvenNumberCardinality :
public CardinalityInterface {
1890 virtual bool IsSatisfiedByCallCount(
int call_count)
const {
1891 return call_count % 2 == 0;
1895 virtual bool IsSaturatedByCallCount(
int )
const {
1900 virtual void DescribeTo(::std::ostream* os)
const {
1901 *os <<
"called even number of times";
1905 Cardinality EvenNumber() {
1906 return Cardinality(
new EvenNumberCardinality);
1909 TEST(ExpectationBaseTest,
1910 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1911 MockA* a =
new MockA;
1915 .Times(EvenNumber())
1935 inline void operator<<(::std::ostream& os,
const Printable&) {
1939 struct Unprintable {
1940 Unprintable() : value(0) {}
1948 MOCK_METHOD6(VoidMethod,
void(
bool cond,
int n,
string s,
void* p,
1949 const Printable& x, Unprintable y));
1958 VerboseFlagPreservingFixture()
1959 : saved_verbose_flag_(
GMOCK_FLAG(verbose)) {}
1961 ~VerboseFlagPreservingFixture() {
GMOCK_FLAG(verbose) = saved_verbose_flag_; }
1964 const string saved_verbose_flag_;
1969 #if GTEST_HAS_STREAM_REDIRECTION 1973 TEST(FunctionCallMessageTest,
1974 UninterestingCallOnNaggyMockGeneratesFyiWithStackTrace) {
1977 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
2003 TEST(FunctionCallMessageTest,
2004 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2012 "Uninteresting mock function call - returning default value.\n" 2013 " Function call: DoB()\n" 2014 " Returns: 0\n", output1.c_str());
2020 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
2024 "Uninteresting mock function call - returning directly\\.\n" 2025 " Function call: VoidMethod" 2026 "\\(false, 5, \"Hi\", NULL, @.+ " 2027 "Printable, 4-byte object <00-00 00-00>\\)"));
2033 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2040 const string& expected_substring,
2041 const string& function_name) {
2050 static_cast<void>(function_name);
2058 void TestExpectedCall(
bool should_print) {
2070 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n" 2071 " Function call: DoA(5)\n" 2081 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n" 2082 " Function call: Binary(2, 1)\n" 2089 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2098 "\nGMOCK WARNING:\n" 2099 "Uninteresting mock function call - returning directly.\n" 2100 " Function call: DoA(5)\n" 2110 "\nGMOCK WARNING:\n" 2111 "Uninteresting mock function call - returning default value.\n" 2112 " Function call: Binary(2, 1)\n" 2123 TestExpectedCall(
true);
2124 TestUninterestingCallOnNaggyMock(
true);
2129 TEST_F(GMockVerboseFlagTest, Warning) {
2131 TestExpectedCall(
false);
2132 TestUninterestingCallOnNaggyMock(
true);
2139 TestExpectedCall(
false);
2140 TestUninterestingCallOnNaggyMock(
false);
2145 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2147 TestExpectedCall(
false);
2148 TestUninterestingCallOnNaggyMock(
true);
2151 #endif // GTEST_HAS_STREAM_REDIRECTION 2156 class PrintMeNot {};
2158 void PrintTo(PrintMeNot , ::std::ostream* ) {
2159 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be " 2160 <<
"printed even to an internal buffer.";
2163 class LogTestHelper {
2173 class GMockLogTest :
public VerboseFlagPreservingFixture {
2175 LogTestHelper helper_;
2178 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2181 .WillOnce(
Return(PrintMeNot()));
2182 helper_.Foo(PrintMeNot());
2185 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2188 .WillOnce(
Return(PrintMeNot()));
2189 helper_.Foo(PrintMeNot());
2192 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2195 .WillByDefault(
Return(PrintMeNot()));
2196 helper_.Foo(PrintMeNot());
2201 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2202 MockA* a =
new MockA;
2206 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2207 MockA* a =
new MockA;
2213 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2214 MockA* a =
new MockA;
2219 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2220 MockA* a =
new MockA;
2226 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2227 MockA* a =
new MockA;
2232 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2233 MockA* a =
new MockA;
2241 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2243 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2254 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2259 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2270 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2276 "Actual: never called");
2287 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2295 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2305 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2314 "Actual: never called");
2325 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2329 Mock::VerifyAndClearExpectations(&b);
2334 Mock::VerifyAndClearExpectations(&b);
2335 Mock::VerifyAndClearExpectations(&b);
2345 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2348 Mock::VerifyAndClear(&b);
2354 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2357 .WillByDefault(
Return(1));
2359 Mock::VerifyAndClear(&b);
2367 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2370 .WillByDefault(
Return(1));
2372 .WillByDefault(
Return(2));
2374 Mock::VerifyAndClear(&b);
2385 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2388 .WillByDefault(
Return(1));
2390 .WillByDefault(
Return(2));
2392 Mock::VerifyAndClear(&b);
2402 TEST(VerifyAndClearTest, CanCallManyTimes) {
2405 .WillByDefault(
Return(1));
2406 Mock::VerifyAndClear(&b);
2407 Mock::VerifyAndClear(&b);
2410 .WillByDefault(
Return(1));
2411 Mock::VerifyAndClear(&b);
2418 TEST(VerifyAndClearTest, Success) {
2421 .WillByDefault(
Return(1));
2436 TEST(VerifyAndClearTest, Failure) {
2439 .WillByDefault(
Return(1));
2446 "Actual: never called");
2460 .WillByDefault(
Return(1));
2478 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2481 .WillByDefault(
Return(1));
2486 Mock::VerifyAndClear(&b);
2491 .WillByDefault(
Return(4));
2499 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2505 .WillByDefault(
Return(
true));
2508 .WillOnce(
Return(
false));
2511 .WillByDefault(
Return(1));
2516 .WillByDefault(
Return(3));
2520 Mock::VerifyAndClear(&b2);
2531 TEST(VerifyAndClearTest,
2532 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2533 linked_ptr<MockA> a(
new MockA);
2534 ReferenceHoldingMock test_mock;
2538 .WillRepeatedly(SetArgPointee<0>(a));
2551 TEST(VerifyAndClearTest,
2552 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2553 linked_ptr<MockA> a(
new MockA);
2554 ReferenceHoldingMock test_mock;
2557 ON_CALL(test_mock, AcceptReference(
_))
2558 .WillByDefault(SetArgPointee<0>(a));
2576 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2581 &MockC::NonVoidMethod)));
2584 .WillOnce(
Invoke(&a, &MockA::DoA))
2585 .RetiresOnSaturation();
2600 #if GMOCK_RENAME_MAIN 2601 int gmock_main(
int argc,
char **argv) {
2604 #endif // GMOCK_RENAME_MAIN
internal::GtMatcher< Rhs > Gt(Rhs x)
std::string GetCapturedStdout()
#define MOCK_METHOD0(m,...)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
internal::NeMatcher< Rhs > Ne(Rhs x)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
GTEST_API_ Cardinality AtLeast(int n)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
GTEST_API_ Cardinality AtMost(int n)
internal::EqMatcher< T > Eq(T x)
const char kErrorVerbosity[]
#define EXPECT_THAT(value, matcher)
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
#define MOCK_CONST_METHOD0(m,...)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
#define MOCK_METHOD6(m,...)
#define EXPECT_TRUE(condition)
std::ostream & operator<<(std::ostream &os, const TestPartResult &result)
#define ON_CALL(obj, call)
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
#define EXPECT_STREQ(expected, actual)
const char kInfoVerbosity[]
internal::LtMatcher< Rhs > Lt(Rhs x)
Expectation::Set::const_iterator const_iterator
TEST_F(ListenerTest, DoesFoo)
#define MOCK_METHOD2(m,...)
const char kWarningVerbosity[]
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
#define EXPECT_FALSE(condition)
const char * Binary(const char *input, short n)
AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
#define ASSERT_TRUE(condition)
const TestPartResult & GetTestPartResult(int index) const
#define EXPECT_ANY_THROW(statement)
GTEST_API_ Cardinality Between(int min, int max)
void SetCallCount(int n, ExpectationBase *exp)
#define ASSERT_EQ(val1, val2)
#define MOCK_METHOD1(m,...)
GTEST_API_ Cardinality AnyNumber()
internal::DoDefaultAction DoDefault()
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
#define EXPECT_CALL(obj, call)
int main(int argc, char **argv)
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
const internal::AnythingMatcher _
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
#define EXPECT_EQ(expected, actual)
ACTION_P(ReturnPointee, pointer)
const T & Const(const T &x)
void PrintTo(const ReferenceWrapper< T > &ref,::std::ostream *os)
#define ASSERT_FALSE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
internal::ReturnAction< R > Return(R value)
TEST(IsXDigitTest, WorksForNarrowAscii)