70 using testing::Cardinality;
71 using testing::CardinalityInterface;
73 using testing::ContainsRegex;
77 using testing::Expectation;
78 using testing::ExpectationSet;
82 using testing::InSequence;
93 using testing::SaveArg;
94 using testing::Sequence;
98 using testing::internal::kAllow;
100 using testing::internal::kFail;
102 using testing::internal::kWarn;
105 #if GTEST_HAS_STREAM_REDIRECTION
106 using testing::HasSubstr;
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) {
271 .WillByDefault(
Return(Result()));
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) {
970 std::string on_call_location;
981 #endif // GTEST_HAS_STREAM_REDIRECTION
984 TEST(UninterestingCallTest, DoesDefaultAction) {
989 .WillByDefault(
Return(
true));
999 TEST(UnexpectedCallTest, DoesDefaultAction) {
1004 .WillByDefault(
Return(
true));
1007 bool result =
false;
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);
1134 ::testing::TestPartResultArray failures;
1136 ::testing::ScopedFakeTestPartResultReporter reporter(&failures);
1144 const ::testing::TestPartResult& r = failures.GetTestPartResult(0);
1145 EXPECT_EQ(::testing::TestPartResult::kNonFatalFailure, r.type());
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:"));
1167 EXPECT_THAT(r.message(), ContainsRegex(
": pre-requisite #0"));
1168 EXPECT_THAT(r.message(), ContainsRegex(
": pre-requisite #1"));
1169 #endif // GTEST_USES_PCRE
1176 TEST(UndefinedReturnValueTest,
1177 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1182 #if GTEST_HAS_EXCEPTIONS
1191 TEST(ExcessiveCallTest, DoesDefaultAction) {
1196 .WillByDefault(
Return(
true));
1199 bool result =
false;
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) {
1338 .WillByDefault(
Return(Result()));
1359 TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1362 .WillByDefault(
Return(Result()));
1380 PartialOrderTest() {
1382 .WillByDefault(
Return(Result()));
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) {
1476 Expectation e5 =
EXPECT_CALL(a, DoA(5)).InSequence(s);
1478 Expectation e6 =
EXPECT_CALL(a, DoA(6)).After(e2);
1481 Expectation e9 =
EXPECT_CALL(a, DoA(9)).RetiresOnSaturation();
1483 Expectation e10 = e2;
1498 TEST(ExpectationTest, AssignmentWorks) {
1513 TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1514 ::testing::StaticAssertTypeEq<Expectation, ExpectationSet::value_type>();
1517 TEST(ExpectationSetTest, ConstructorsWork) {
1521 const Expectation e2;
1524 ExpectationSet es3 = e1;
1525 ExpectationSet es4(e1);
1526 ExpectationSet es5 = e2;
1527 ExpectationSet es6(e2);
1528 ExpectationSet es7 = es2;
1546 TEST(ExpectationSetTest, AssignmentWorks) {
1548 ExpectationSet es2 = Expectation();
1556 TEST(ExpectationSetTest, InsertionWorks) {
1568 ExpectationSet::const_iterator it1 = es1.begin();
1569 ExpectationSet::const_iterator it2 = it1;
1576 TEST(ExpectationSetTest, SizeWorks) {
1580 es += Expectation();
1590 TEST(ExpectationSetTest, IsEnumerable) {
1594 es += Expectation();
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) {
1684 .WillByDefault(
Return(Result()));
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) {
1782 .WillByDefault(
Return(Result()));
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)
1883 ACTION_P(Delete, ptr) {
delete ptr; }
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 {
1957 bool IsSatisfiedByCallCount(
int call_count)
const override {
1958 return call_count % 2 == 0;
1963 bool IsSaturatedByCallCount(
int )
const override {
1968 void DescribeTo(::std::ostream* os)
const override {
1969 *os <<
"called even number of times";
1973 Cardinality EvenNumber() {
1974 return Cardinality(
new EvenNumberCardinality);
1977 TEST(ExpectationBaseTest,
1978 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1979 MockA* a =
new MockA;
1983 .Times(EvenNumber())
2003 inline void operator<<(::std::ostream& os,
const Printable&) {
2007 struct Unprintable {
2008 Unprintable() :
value(0) {}
2016 MOCK_METHOD6(VoidMethod,
void(
bool cond,
int n, std::string s,
void*
p,
2017 const Printable& x, Unprintable y));
2026 VerboseFlagPreservingFixture()
2027 : saved_verbose_flag_(
GMOCK_FLAG(verbose)) {}
2029 ~VerboseFlagPreservingFixture()
override {
2034 const std::string saved_verbose_flag_;
2039 #if GTEST_HAS_STREAM_REDIRECTION
2044 TEST(FunctionCallMessageTest,
2045 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
2049 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2058 TEST(FunctionCallMessageTest,
2059 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
2063 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2089 TEST(FunctionCallMessageTest,
2090 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2098 "Uninteresting mock function call - returning default value.\n"
2099 " Function call: DoB()\n"
2100 " Returns: 0\n", output1.c_str());
2106 c.VoidMethod(
false, 5,
"Hi",
nullptr, Printable(), Unprintable());
2110 "Uninteresting mock function call - returning directly\\.\n"
2111 " Function call: VoidMethod"
2112 "\\(false, 5, \"Hi\", NULL, @.+ "
2113 "Printable, 4-byte object <00-00 00-00>\\)"));
2119 class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2125 void VerifyOutput(
const std::string& output,
bool should_print,
2126 const std::string& expected_substring,
2127 const std::string& function_name) {
2129 EXPECT_THAT(output.c_str(), HasSubstr(expected_substring));
2133 EXPECT_THAT(output.c_str(), HasSubstr(function_name));
2136 static_cast<void>(function_name);
2144 void TestExpectedCall(
bool should_print) {
2156 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
2157 " Function call: DoA(5)\n"
2167 "Mock function call matches EXPECT_CALL(a, Binary(_, 1))...\n"
2168 " Function call: Binary(2, 1)\n"
2175 void TestUninterestingCallOnNaggyMock(
bool should_print) {
2177 const std::string note =
2178 "NOTE: You can safely ignore the above warning unless this "
2179 "call should not happen. Do not suppress it by blindly adding "
2180 "an EXPECT_CALL() if you don't mean to enforce the call. "
2182 "https://github.com/google/googletest/blob/master/googlemock/docs/"
2184 "knowing-when-to-expect for details.";
2192 "\nGMOCK WARNING:\n"
2193 "Uninteresting mock function call - returning directly.\n"
2194 " Function call: DoA(5)\n" +
2204 "\nGMOCK WARNING:\n"
2205 "Uninteresting mock function call - returning default value.\n"
2206 " Function call: Binary(2, 1)\n"
2207 " Returns: false\n" +
2215 TEST_F(GMockVerboseFlagTest, Info) {
2217 TestExpectedCall(
true);
2218 TestUninterestingCallOnNaggyMock(
true);
2223 TEST_F(GMockVerboseFlagTest, Warning) {
2225 TestExpectedCall(
false);
2226 TestUninterestingCallOnNaggyMock(
true);
2231 TEST_F(GMockVerboseFlagTest, Error) {
2233 TestExpectedCall(
false);
2234 TestUninterestingCallOnNaggyMock(
false);
2239 TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2241 TestExpectedCall(
false);
2242 TestUninterestingCallOnNaggyMock(
true);
2245 #endif // GTEST_HAS_STREAM_REDIRECTION
2250 class PrintMeNot {};
2252 void PrintTo(PrintMeNot , ::std::ostream* ) {
2253 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be "
2254 <<
"printed even to an internal buffer.";
2257 class LogTestHelper {
2267 class GMockLogTest :
public VerboseFlagPreservingFixture {
2269 LogTestHelper helper_;
2272 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2275 .WillOnce(
Return(PrintMeNot()));
2276 helper_.Foo(PrintMeNot());
2279 TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2282 .WillOnce(
Return(PrintMeNot()));
2283 helper_.Foo(PrintMeNot());
2286 TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2289 .WillByDefault(
Return(PrintMeNot()));
2290 helper_.Foo(PrintMeNot());
2295 TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2296 MockA* a =
new MockA;
2300 TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2301 MockA* a =
new MockA;
2307 TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2308 MockA* a =
new MockA;
2313 TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2314 MockA* a =
new MockA;
2320 TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2321 MockA* a =
new MockA;
2326 TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2327 MockA* a =
new MockA;
2335 TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2337 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2348 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2353 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2364 TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2370 "Actual: never called");
2381 TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2389 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&b));
2399 TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2408 "Actual: never called");
2419 TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2423 Mock::VerifyAndClearExpectations(&b);
2428 Mock::VerifyAndClearExpectations(&b);
2429 Mock::VerifyAndClearExpectations(&b);
2439 TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2442 Mock::VerifyAndClear(&b);
2448 TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2451 .WillByDefault(
Return(1));
2453 Mock::VerifyAndClear(&b);
2461 TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2464 .WillByDefault(
Return(1));
2466 .WillByDefault(
Return(2));
2468 Mock::VerifyAndClear(&b);
2479 TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2482 .WillByDefault(
Return(1));
2484 .WillByDefault(
Return(2));
2486 Mock::VerifyAndClear(&b);
2496 TEST(VerifyAndClearTest, CanCallManyTimes) {
2499 .WillByDefault(
Return(1));
2500 Mock::VerifyAndClear(&b);
2501 Mock::VerifyAndClear(&b);
2504 .WillByDefault(
Return(1));
2505 Mock::VerifyAndClear(&b);
2512 TEST(VerifyAndClearTest, Success) {
2515 .WillByDefault(
Return(1));
2530 TEST(VerifyAndClearTest, Failure) {
2533 .WillByDefault(
Return(1));
2540 "Actual: never called");
2551 TEST(VerifyAndClearTest, Const) {
2554 .WillByDefault(
Return(1));
2572 TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2575 .WillByDefault(
Return(1));
2580 Mock::VerifyAndClear(&b);
2585 .WillByDefault(
Return(4));
2593 TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2599 .WillByDefault(
Return(
true));
2602 .WillOnce(
Return(
false));
2605 .WillByDefault(
Return(1));
2610 .WillByDefault(
Return(3));
2614 Mock::VerifyAndClear(&b2);
2625 TEST(VerifyAndClearTest,
2626 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2627 std::shared_ptr<MockA>
a(
new MockA);
2628 ReferenceHoldingMock test_mock;
2632 .WillRepeatedly(SetArgPointee<0>(a));
2645 TEST(VerifyAndClearTest,
2646 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2647 std::shared_ptr<MockA>
a(
new MockA);
2648 ReferenceHoldingMock test_mock;
2651 ON_CALL(test_mock, AcceptReference(
_))
2652 .WillByDefault(SetArgPointee<0>(a));
2670 TEST(SynchronizationTest, CanCallMockMethodInAction) {
2675 &MockC::NonVoidMethod)));
2678 .WillOnce(
Invoke(&a, &MockA::DoA))
2679 .RetiresOnSaturation();
2689 TEST(ParameterlessExpectationsTest, CanSetExpectationsWithoutMatchers) {
2692 ON_CALL(a, DoA).WillByDefault(SaveArg<0>(&do_a_arg0));
2693 int do_a_47_arg0 = 0;
2694 ON_CALL(a, DoA(47)).WillByDefault(SaveArg<0>(&do_a_47_arg0));
2709 TEST(ParameterlessExpectationsTest, CanSetExpectationsForOverloadedMethods) {
2719 struct MockWithConstMethods {
2725 TEST(ParameterlessExpectationsTest, CanSetExpectationsForConstMethods) {
2726 MockWithConstMethods mock;
2734 class MockConstOverload {
2740 TEST(ParameterlessExpectationsTest,
2741 CanSetExpectationsForConstOverloadedMethods) {
2742 MockConstOverload mock;
2745 ON_CALL(Const(mock), Overloaded(5)).WillByDefault(
Return(11));
2746 ON_CALL(Const(mock), Overloaded(7)).WillByDefault(
Return(13));
2752 const MockConstOverload& const_mock = mock;
2763 #if GMOCK_RENAME_MAIN
2764 int gmock_main(
int argc,
char **argv) {
2767 #endif // GMOCK_RENAME_MAIN
#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,...)
GTEST_DISALLOW_COPY_AND_ASSIGN_(Test)
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
#define TEST_F(test_fixture, test_name)
#define MOCK_METHOD0(m,...)
internal::DoAllAction< typename std::decay< Action >::type...> DoAll(Action &&...action)
#define TEST(test_suite_name, test_name)
#define ASSERT_EQ(val1, val2)
#define ON_CALL(obj, call)
GTEST_API_ void CaptureStdout()
#define EXPECT_ANY_THROW(statement)
internal::InvokeWithoutArgsAction< typename std::decay< FunctionImpl >::type > InvokeWithoutArgs(FunctionImpl function_impl)
const char kInfoVerbosity[]
const char kWarningVerbosity[]
#define MOCK_METHOD2(m,...)
std::ostream & operator<<(std::ostream &os, const Expr< T > &xx)
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 EXPECT_STREQ(s1, s2)
const char * Binary(const char *input, short n)
#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,...)
internal::SetArgumentPointeeAction< N, T > SetArgPointee(T value)
#define MOCK_CONST_METHOD2(m,...)
GTEST_API_ Cardinality Between(int min, int max)
void SetCallCount(int n, ExpectationBase *exp)
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)
#define EXPECT_EQ(val1, val2)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
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)