36 #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" 102 #if GTEST_HAS_STREAM_REDIRECTION 110 class MockIncomplete {
118 void PrintTo(
const Incomplete&
x, ::std::ostream* os);
120 TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
125 MockIncomplete incomplete;
132 void PrintTo(
const Incomplete& , ::std::ostream* os) {
139 class NonDefaultConstructible {
141 explicit NonDefaultConstructible(
int ) {}
150 MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
169 class ReferenceHoldingMock {
171 ReferenceHoldingMock() {}
184 #define Method MethodW 191 class MockCC :
public CC {
202 TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
209 TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
216 TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
223 TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
229 #undef Method // Done with macro redefinition tests. 233 TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
241 TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
251 TEST(OnCallSyntaxTest, WithIsOptional) {
261 TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
268 .WillByDefault(
Return(Result()));
269 },
".With() cannot appear more than once in an ON_CALL()");
272 TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
281 TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
288 },
".WillByDefault() must appear exactly once in an ON_CALL()");
293 TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
302 TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
313 TEST(ExpectCallSyntaxTest, WithIsOptional) {
323 TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
330 },
".With() cannot appear more than once in an EXPECT_CALL()");
335 TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
342 },
".With() must be the first clause in an EXPECT_CALL()");
350 },
".With() must be the first clause in an EXPECT_CALL()");
355 TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
363 .WillRepeatedly(
Return());
370 TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
377 },
".Times() cannot appear more than once in an EXPECT_CALL()");
383 TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
391 },
".Times() cannot appear after ");
396 TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
408 TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
419 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
429 },
".InSequence() cannot appear after ");
434 TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
442 },
".InSequence() cannot appear after ");
447 TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
455 },
".After() cannot appear after ");
461 TEST(ExpectCallSyntaxTest, WillIsOptional) {
472 TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
482 TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
489 },
".WillOnce() cannot appear after ");
494 TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
501 .WillRepeatedly(
Return());
508 TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
514 .WillRepeatedly(
Return());
515 },
".WillRepeatedly() cannot appear more than once in an " 519 TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
524 .RetiresOnSaturation()
525 .WillRepeatedly(
Return());
526 },
".WillRepeatedly() cannot appear after ");
529 TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
534 .RetiresOnSaturation();
540 TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
545 .RetiresOnSaturation()
546 .RetiresOnSaturation();
547 },
".RetiresOnSaturation() cannot appear more than once");
552 TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
561 },
"to be called once");
567 },
"to be called once");
570 #if GTEST_HAS_STREAM_REDIRECTION 574 TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
586 .WillRepeatedly(
Return(1));
599 .WillRepeatedly(
Return(2));
610 TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
627 .RetiresOnSaturation();
633 .WillRepeatedly(
Return(1));
637 .WillRepeatedly(
Return(2));
646 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 647 "Expected to be never called, but has 1 WillOnce().",
651 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 652 "Expected to be called at most once, " 653 "but has 2 WillOnce()s.",
657 "Too many actions specified in EXPECT_CALL(b, DoB(1))...\n" 658 "Expected to be called once, but has 2 WillOnce()s.",
662 "Too many actions specified in EXPECT_CALL(b, DoB())...\n" 663 "Expected to be never called, but has 0 WillOnce()s " 664 "and a WillRepeatedly().",
668 "Too many actions specified in EXPECT_CALL(b, DoB(2))...\n" 669 "Expected to be called once, but has 1 WillOnce() " 670 "and a WillRepeatedly().",
676 TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
688 "Too few actions specified in EXPECT_CALL(b, DoB())...\n" 689 "Expected to be called between 2 and 3 times, " 690 "but has only 1 WillOnce().",
695 #endif // GTEST_HAS_STREAM_REDIRECTION 701 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
710 TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
713 .WillByDefault(
Return(1));
720 TEST(OnCallTest, PicksLastMatchingOnCall) {
723 .WillByDefault(
Return(3));
725 .WillByDefault(
Return(2));
727 .WillByDefault(
Return(1));
736 TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
749 TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
752 .WillRepeatedly(
Return(2));
754 .WillRepeatedly(
Return(1));
760 TEST(ExpectCallTest, CatchesTooFewCalls) {
767 },
"Actual function call count doesn't match EXPECT_CALL(b, DoB(5))...\n" 768 " Expected: to be called at least twice\n" 769 " Actual: called once - unsatisfied and active");
774 TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
792 },
"to be called twice");
806 TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
811 .WillRepeatedly(
Return(2));
820 .WillRepeatedly(
Return(2));
831 .WillRepeatedly(
Return(2));
832 },
"to be called at least once");
837 TEST(ExpectCallTest, NthMatchTakesNthAction) {
851 TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
855 .WillRepeatedly(
Return(2));
862 #if GTEST_HAS_STREAM_REDIRECTION 866 TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
888 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n" 889 "Called 3 times, but only 2 WillOnce()s are specified" 890 " - returning default value."));
892 HasSubstr(
"Actions ran out in EXPECT_CALL(b, DoB())...\n" 893 "Called 4 times, but only 2 WillOnce()s are specified" 894 " - returning default value."));
897 TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) {
911 TEST(FunctionMockerMessageTest,
912 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
924 #endif // GTEST_HAS_STREAM_REDIRECTION 927 TEST(UninterestingCallTest, DoesDefaultAction) {
932 .WillByDefault(
Return(
true));
942 TEST(UnexpectedCallTest, DoesDefaultAction) {
947 .WillByDefault(
Return(
true));
952 "Unexpected mock function call");
962 "Unexpected mock function call");
968 TEST(UnexpectedCallTest, GeneratesFailureForVoidFunction) {
978 "Unexpected mock function call - returning directly.\n" 979 " Function call: DoA(9)\n" 980 "Google Mock tried the following 1 expectation, but it didn't match:");
983 " Expected arg #0: is equal to 1\n" 985 " Expected: to be called once\n" 986 " Actual: called once - saturated and active");
995 "Unexpected mock function call - returning directly.\n" 996 " Function call: DoA(2)\n" 997 "Google Mock tried the following 2 expectations, but none matched:");
1000 "tried expectation #0: EXPECT_CALL(a2, DoA(1))...\n" 1001 " Expected arg #0: is equal to 1\n" 1003 " Expected: to be called once\n" 1004 " Actual: called once - saturated and active");
1007 "tried expectation #1: EXPECT_CALL(a2, DoA(3))...\n" 1008 " Expected arg #0: is equal to 3\n" 1010 " Expected: to be called once\n" 1011 " Actual: never called - unsatisfied and active");
1017 TEST(UnexpectedCallTest, GeneartesFailureForNonVoidFunction) {
1023 "Unexpected mock function call - returning default value.\n" 1024 " Function call: DoB(2)\n" 1026 "Google Mock tried the following 1 expectation, but it didn't match:");
1029 " Expected arg #0: is equal to 1\n" 1031 " Expected: to be called once\n" 1032 " Actual: called once - saturated and active");
1037 TEST(UnexpectedCallTest, RetiredExpectation) {
1040 .RetiresOnSaturation();
1045 " Expected: the expectation is active\n" 1046 " Actual: it is retired");
1051 TEST(UnexpectedCallTest, UnmatchedArguments) {
1057 " Expected arg #0: is equal to 1\n" 1064 TEST(UnexpectedCallTest, UnsatisifiedPrerequisites) {
1075 .InSequence(s1, s2);
1096 "(?s)the following immediate pre-requisites are not satisfied:\n" 1097 ".*: pre-requisite #0\n" 1098 ".*: pre-requisite #1"));
1099 #elif GTEST_USES_POSIX_RE 1103 "the following immediate pre-requisites are not satisfied:\n" 1104 "(.|\n)*: pre-requisite #0\n" 1105 "(.|\n)*: pre-requisite #1"));
1109 "the following immediate pre-requisites are not satisfied:"));
1112 #endif // GTEST_USES_PCRE 1119 TEST(UndefinedReturnValueTest,
1120 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1125 #if GTEST_HAS_EXCEPTIONS 1134 TEST(ExcessiveCallTest, DoesDefaultAction) {
1139 .WillByDefault(
Return(
true));
1142 bool result =
false;
1144 "Mock function called more times than expected");
1154 "Mock function called more times than expected");
1160 TEST(ExcessiveCallTest, GeneratesFailureForVoidFunction) {
1166 "Mock function called more times than expected - returning directly.\n" 1167 " Function call: DoA(9)\n" 1168 " Expected: to be never called\n" 1169 " Actual: called once - over-saturated and active");
1174 TEST(ExcessiveCallTest, GeneratesFailureForNonVoidFunction) {
1180 "Mock function called more times than expected - " 1181 "returning default value.\n" 1182 " Function call: DoB(2)\n" 1184 " Expected: to be called once\n" 1185 " Actual: called twice - over-saturated and active");
1190 TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1201 },
"Unexpected mock function call");
1207 TEST(InSequenceTest, NestedInSequence) {
1224 },
"Unexpected mock function call");
1230 TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1242 },
"Unexpected mock function call");
1250 TEST(SequenceTest, AnyOrderIsOkByDefault) {
1278 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1281 .WillByDefault(
Return(Result()));
1302 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1305 .WillByDefault(
Return(Result()));
1323 PartialOrderTest() {
1325 .WillByDefault(
Return(Result()));
1349 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1360 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1370 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1380 TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1390 TEST(SequenceTest, Retirement) {
1398 .RetiresOnSaturation();
1409 TEST(ExpectationTest, ConstrutorsWork) {
1419 Expectation e5 =
EXPECT_CALL(a, DoA(5)).InSequence(s);
1421 Expectation e6 =
EXPECT_CALL(a, DoA(6)).After(e2);
1424 Expectation e9 =
EXPECT_CALL(a, DoA(9)).RetiresOnSaturation();
1426 Expectation e10 = e2;
1441 TEST(ExpectationTest, AssignmentWorks) {
1456 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1457 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1460 TEST(ExpectationSetTest, ConstructorsWork) {
1464 const Expectation e2;
1467 ExpectationSet es3 = e1;
1468 ExpectationSet es4(e1);
1469 ExpectationSet es5 = e2;
1470 ExpectationSet es6(e2);
1471 ExpectationSet es7 = es2;
1489 TEST(ExpectationSetTest, AssignmentWorks) {
1491 ExpectationSet es2 = Expectation();
1499 TEST(ExpectationSetTest, InsertionWorks) {
1519 TEST(ExpectationSetTest, SizeWorks) {
1523 es += Expectation();
1533 TEST(ExpectationSetTest, IsEnumerable) {
1537 es += Expectation();
1547 TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1560 TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1578 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1600 TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1624 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1627 .WillByDefault(
Return(Result()));
1646 TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1667 TEST(AfterTest, CanBeUsedWithInSequence) {
1686 TEST(AfterTest, CanBeCalledManyTimes) {
1703 TEST(AfterTest, AcceptsUpToFiveArguments) {
1711 .After(e1, e2, e3, es1, es2);
1722 TEST(AfterTest, AcceptsDuplicatedInput) {
1725 .WillByDefault(
Return(Result()));
1736 .After(e1, e2, es, e1);
1749 TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1766 TEST(DeletingMockEarlyTest, Success1) {
1767 MockB*
const b1 =
new MockB;
1768 MockA*
const a =
new MockA;
1769 MockB*
const b2 =
new MockB;
1777 .WillRepeatedly(
Return(
true));
1780 .WillRepeatedly(
Return(2));
1794 TEST(DeletingMockEarlyTest, Success2) {
1795 MockB*
const b1 =
new MockB;
1796 MockA*
const a =
new MockA;
1797 MockB*
const b2 =
new MockB;
1807 .WillRepeatedly(
Return(2));
1822 # pragma warning(push) 1823 # pragma warning(disable:4100) 1829 # pragma warning(pop) 1832 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1833 MockA*
const a =
new MockA;
1838 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1839 MockA*
const a =
new MockA;
1842 a->ReturnResult(42);
1846 TEST(DeletingMockEarlyTest, Failure1) {
1847 MockB*
const b1 =
new MockB;
1848 MockA*
const a =
new MockA;
1849 MockB*
const b2 =
new MockB;
1859 .WillRepeatedly(
Return(2));
1865 },
"Unexpected mock function call");
1872 TEST(DeletingMockEarlyTest, Failure2) {
1873 MockB*
const b1 =
new MockB;
1874 MockA*
const a =
new MockA;
1875 MockB*
const b2 =
new MockB;
1887 "Actual: never called");
1889 "Unexpected mock function call");
1891 "Unexpected mock function call");
1896 class EvenNumberCardinality :
public CardinalityInterface {
1899 virtual bool IsSatisfiedByCallCount(
int call_count)
const {
1900 return call_count % 2 == 0;
1904 virtual bool IsSaturatedByCallCount(
int )
const {
1909 virtual void DescribeTo(::std::ostream* os)
const {
1910 *os <<
"called even number of times";
1914 Cardinality EvenNumber() {
1915 return Cardinality(
new EvenNumberCardinality);
1918 TEST(ExpectationBaseTest,
1919 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1920 MockA*
a =
new MockA;
1924 .Times(EvenNumber())
1944 inline void operator<<(::std::ostream& os,
const Printable&) {
1948 struct Unprintable {
1949 Unprintable() :
value(0) {}
1957 MOCK_METHOD6(VoidMethod,
void(
bool cond,
int n,
string s,
void* p,
1958 const Printable& x, Unprintable
y));
1967 VerboseFlagPreservingFixture()
1968 : saved_verbose_flag_(
GMOCK_FLAG(verbose)) {}
1970 ~VerboseFlagPreservingFixture() {
GMOCK_FLAG(verbose) = saved_verbose_flag_; }
1973 const string saved_verbose_flag_;
1978 #if GTEST_HAS_STREAM_REDIRECTION 1983 TEST(FunctionCallMessageTest,
1984 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
1988 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
1997 TEST(FunctionCallMessageTest,
1998 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
2002 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
2028 TEST(FunctionCallMessageTest,
2029 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2037 "Uninteresting mock function call - returning default value.\n" 2038 " Function call: DoB()\n" 2039 " Returns: 0\n", output1.c_str());
2045 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
2049 "Uninteresting mock function call - returning directly\\.\n" 2050 " Function call: VoidMethod" 2051 "\\(false, 5, \"Hi\", NULL, @.+ " 2052 "Printable, 4-byte object <00-00 00-00>\\)"));
2058 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2065 const string& expected_substring,
2066 const string& function_name) {
2075 static_cast<void>(function_name);
2083 void TestExpectedCall(
bool should_print) {
2095 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n" 2096 " Function call: DoA(5)\n" 2106 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n" 2107 " Function call: Binary(2, 1)\n" 2114 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2117 "NOTE: You can safely ignore the above warning unless this " 2118 "call should not happen. Do not suppress it by blindly adding " 2119 "an EXPECT_CALL() if you don't mean to enforce the call. " 2120 "See https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#" 2121 "knowing-when-to-expect for details.";
2129 "\nGMOCK WARNING:\n" 2130 "Uninteresting mock function call - returning directly.\n" 2131 " Function call: DoA(5)\n" +
2141 "\nGMOCK WARNING:\n" 2142 "Uninteresting mock function call - returning default value.\n" 2143 " Function call: Binary(2, 1)\n" 2144 " Returns: false\n" +
2152 TEST_F(GMockVerboseFlagTest, Info) {
2154 TestExpectedCall(
true);
2155 TestUninterestingCallOnNaggyMock(
true);
2160 TEST_F(GMockVerboseFlagTest, Warning) {
2162 TestExpectedCall(
false);
2163 TestUninterestingCallOnNaggyMock(
true);
2168 TEST_F(GMockVerboseFlagTest, Error) {
2170 TestExpectedCall(
false);
2171 TestUninterestingCallOnNaggyMock(
false);
2176 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2178 TestExpectedCall(
false);
2179 TestUninterestingCallOnNaggyMock(
true);
2182 #endif // GTEST_HAS_STREAM_REDIRECTION 2187 class PrintMeNot {};
2189 void PrintTo(PrintMeNot , ::std::ostream* ) {
2190 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be " 2191 <<
"printed even to an internal buffer.";
2194 class LogTestHelper {
2204 class GMockLogTest :
public VerboseFlagPreservingFixture {
2206 LogTestHelper helper_;
2209 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2212 .WillOnce(
Return(PrintMeNot()));
2213 helper_.Foo(PrintMeNot());
2216 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2219 .WillOnce(
Return(PrintMeNot()));
2220 helper_.Foo(PrintMeNot());
2223 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2226 .WillByDefault(
Return(PrintMeNot()));
2227 helper_.Foo(PrintMeNot());
2232 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2233 MockA*
a =
new MockA;
2237 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2238 MockA*
a =
new MockA;
2244 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2245 MockA*
a =
new MockA;
2250 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2251 MockA*
a =
new MockA;
2257 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2258 MockA*
a =
new MockA;
2263 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2264 MockA*
a =
new MockA;
2272 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2274 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2285 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2290 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2301 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2307 "Actual: never called");
2318 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2326 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2336 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2345 "Actual: never called");
2356 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2360 Mock::VerifyAndClearExpectations(&b);
2365 Mock::VerifyAndClearExpectations(&b);
2366 Mock::VerifyAndClearExpectations(&b);
2376 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2379 Mock::VerifyAndClear(&b);
2385 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2388 .WillByDefault(
Return(1));
2390 Mock::VerifyAndClear(&b);
2398 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2401 .WillByDefault(
Return(1));
2403 .WillByDefault(
Return(2));
2405 Mock::VerifyAndClear(&b);
2416 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2419 .WillByDefault(
Return(1));
2421 .WillByDefault(
Return(2));
2423 Mock::VerifyAndClear(&b);
2433 TEST(VerifyAndClearTest, CanCallManyTimes) {
2436 .WillByDefault(
Return(1));
2437 Mock::VerifyAndClear(&b);
2438 Mock::VerifyAndClear(&b);
2441 .WillByDefault(
Return(1));
2442 Mock::VerifyAndClear(&b);
2449 TEST(VerifyAndClearTest, Success) {
2452 .WillByDefault(
Return(1));
2467 TEST(VerifyAndClearTest, Failure) {
2470 .WillByDefault(
Return(1));
2477 "Actual: never called");
2491 .WillByDefault(
Return(1));
2509 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2512 .WillByDefault(
Return(1));
2517 Mock::VerifyAndClear(&b);
2522 .WillByDefault(
Return(4));
2530 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2536 .WillByDefault(
Return(
true));
2539 .WillOnce(
Return(
false));
2542 .WillByDefault(
Return(1));
2547 .WillByDefault(
Return(3));
2551 Mock::VerifyAndClear(&b2);
2562 TEST(VerifyAndClearTest,
2563 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2564 linked_ptr<MockA>
a(
new MockA);
2565 ReferenceHoldingMock test_mock;
2569 .WillRepeatedly(SetArgPointee<0>(a));
2582 TEST(VerifyAndClearTest,
2583 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2584 linked_ptr<MockA>
a(
new MockA);
2585 ReferenceHoldingMock test_mock;
2588 ON_CALL(test_mock, AcceptReference(
_))
2589 .WillByDefault(SetArgPointee<0>(a));
2607 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2612 &MockC::NonVoidMethod)));
2615 .WillOnce(
Invoke(&a, &MockA::DoA))
2616 .RetiresOnSaturation();
2631 #if GMOCK_RENAME_MAIN 2632 int gmock_main(
int argc,
char **
argv) {
2635 #endif // GMOCK_RENAME_MAIN
#define EXPECT_ANY_THROW(statement)
internal::GtMatcher< Rhs > Gt(Rhs x)
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
internal::NeMatcher< Rhs > Ne(Rhs x)
GTEST_API_ Cardinality AtLeast(int n)
#define ASSERT_EQ(val1, val2)
GTEST_API_ Cardinality AtMost(int n)
internal::EqMatcher< T > Eq(T x)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
const char kErrorVerbosity[]
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
::std::string FormatFileLocation(const char *file, int line)
#define EXPECT_EQ(val1, val2)
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
std::ostream & operator<<(std::ostream &os, const Message &sb)
The non test part of the code is expected to have failures gtest_output_test_ cc
const char * Binary(const char *input, short n)
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
const char kInfoVerbosity[]
internal::LtMatcher< Rhs > Lt(Rhs x)
Expectation::Set::const_iterator const_iterator
TEST_F(ListenerTest, DoesFoo)
#define EXPECT_STREQ(s1, s2)
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 MOCK_METHOD6(m,...)
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
static const char *const value
const TestPartResult & GetTestPartResult(int index) const
GTEST_API_ Cardinality Between(int min, int max)
void SetCallCount(int n, ExpectationBase *exp)
#define EXPECT_TRUE(condition)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define EXPECT_THAT(value, matcher)
GTEST_API_ Cardinality AnyNumber()
internal::DoDefaultAction DoDefault()
#define ON_CALL(obj, call)
int main(int argc, char **argv)
#define MOCK_METHOD1(m,...)
#define MOCK_CONST_METHOD0(m,...)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
#define EXPECT_CALL(obj, call)
std::string GetCapturedStdout()
const internal::AnythingMatcher _
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
#define ASSERT_FALSE(condition)
#define EXPECT_FALSE(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
#define MOCK_METHOD2(m,...)
#define ASSERT_TRUE(condition)
ACTION_P(ReturnPointee, pointer)
const T & Const(const T &x)
void PrintTo(const ReferenceWrapper< T > &ref,::std::ostream *os)
internal::ReturnAction< R > Return(R value)
TEST(IsXDigitTest, WorksForNarrowAscii)
#define MOCK_METHOD0(m,...)