44#include "gtest/gtest.h"
45#include "gtest/gtest-spi.h"
46#include "gtest/internal/gtest-port.h"
79using testing::GMOCK_FLAG(verbose);
102#if GTEST_HAS_STREAM_REDIRECTION
104using testing::internal::CaptureStdout;
105using testing::internal::GetCapturedStdout;
110class MockIncomplete {
118void PrintTo(
const Incomplete& x, ::std::ostream* os);
120TEST(MockMethodTest, CanInstantiateWithIncompleteArgType) {
125 MockIncomplete incomplete;
132void PrintTo(
const Incomplete& , ::std::ostream* os) {
139class NonDefaultConstructible {
141 explicit NonDefaultConstructible(
int ) {}
150 MOCK_METHOD0(ReturnNonDefaultConstructible, NonDefaultConstructible());
169class ReferenceHoldingMock {
171 ReferenceHoldingMock() {}
173 MOCK_METHOD1(AcceptReference,
void(linked_ptr<MockA>*));
184#define Method MethodW
191class MockCC :
public CC {
202TEST(OnCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
209TEST(OnCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
216TEST(ExpectCallSyntaxTest, CompilesWithMethodNameExpandedFromMacro) {
223TEST(ExpectCallSyntaxTest, WorksWithMethodNameExpandedFromMacro) {
233TEST(OnCallSyntaxTest, EvaluatesFirstArgumentOnce) {
241TEST(OnCallSyntaxTest, EvaluatesSecondArgumentOnce) {
251TEST(OnCallSyntaxTest, WithIsOptional) {
261TEST(OnCallSyntaxTest, WithCanAppearAtMostOnce) {
268 .WillByDefault(
Return(Result()));
269 },
".With() cannot appear more than once in an ON_CALL()");
272TEST(OnCallSyntaxTest, WillByDefaultIsMandatory) {
281TEST(OnCallSyntaxTest, WillByDefaultCanAppearAtMostOnce) {
288 },
".WillByDefault() must appear exactly once in an ON_CALL()");
293TEST(ExpectCallSyntaxTest, EvaluatesFirstArgumentOnce) {
302TEST(ExpectCallSyntaxTest, EvaluatesSecondArgumentOnce) {
313TEST(ExpectCallSyntaxTest, WithIsOptional) {
323TEST(ExpectCallSyntaxTest, WithCanAppearAtMostOnce) {
330 },
".With() cannot appear more than once in an EXPECT_CALL()");
335TEST(ExpectCallSyntaxTest, WithMustBeFirstClause) {
342 },
".With() must be the first clause in an EXPECT_CALL()");
350 },
".With() must be the first clause in an EXPECT_CALL()");
355TEST(ExpectCallSyntaxTest, TimesCanBeInferred) {
363 .WillRepeatedly(
Return());
370TEST(ExpectCallSyntaxTest, TimesCanAppearAtMostOnce) {
377 },
".Times() cannot appear more than once in an EXPECT_CALL()");
383TEST(ExpectCallSyntaxTest, TimesMustBeBeforeInSequence) {
391 },
".Times() cannot appear after ");
396TEST(ExpectCallSyntaxTest, InSequenceIsOptional) {
408TEST(ExpectCallSyntaxTest, InSequenceCanAppearMultipleTimes) {
419TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeAfter) {
429 },
".InSequence() cannot appear after ");
434TEST(ExpectCallSyntaxTest, InSequenceMustBeBeforeWillOnce) {
442 },
".InSequence() cannot appear after ");
447TEST(ExpectCallSyntaxTest, AfterMustBeBeforeWillOnce) {
455 },
".After() cannot appear after ");
461TEST(ExpectCallSyntaxTest, WillIsOptional) {
472TEST(ExpectCallSyntaxTest, WillCanAppearMultipleTimes) {
482TEST(ExpectCallSyntaxTest, WillMustBeBeforeWillRepeatedly) {
489 },
".WillOnce() cannot appear after ");
494TEST(ExpectCallSyntaxTest, WillRepeatedlyIsOptional) {
501 .WillRepeatedly(
Return());
508TEST(ExpectCallSyntaxTest, WillRepeatedlyCannotAppearMultipleTimes) {
514 .WillRepeatedly(
Return());
515 },
".WillRepeatedly() cannot appear more than once in an "
519TEST(ExpectCallSyntaxTest, WillRepeatedlyMustBeBeforeRetiresOnSaturation) {
524 .RetiresOnSaturation()
525 .WillRepeatedly(
Return());
526 },
".WillRepeatedly() cannot appear after ");
529TEST(ExpectCallSyntaxTest, RetiresOnSaturationIsOptional) {
534 .RetiresOnSaturation();
540TEST(ExpectCallSyntaxTest, RetiresOnSaturationCannotAppearMultipleTimes) {
545 .RetiresOnSaturation()
546 .RetiresOnSaturation();
547 },
".RetiresOnSaturation() cannot appear more than once");
552TEST(ExpectCallSyntaxTest, DefaultCardinalityIsOnce) {
561 },
"to be called once");
567 },
"to be called once");
570#if GTEST_HAS_STREAM_REDIRECTION
574TEST(ExpectCallSyntaxTest, DoesNotWarnOnAdequateActionCount) {
586 .WillRepeatedly(
Return(1));
599 .WillRepeatedly(
Return(2));
610TEST(ExpectCallSyntaxTest, WarnsOnTooManyActions) {
627 .RetiresOnSaturation();
633 .WillRepeatedly(
Return(1));
637 .WillRepeatedly(
Return(2));
643 const std::string
output = GetCapturedStdout();
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().",
676TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
685 const std::string
output = GetCapturedStdout();
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().",
701TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCall) {
710TEST(OnCallTest, TakesBuiltInDefaultActionWhenNoOnCallMatches) {
713 .WillByDefault(
Return(1));
720TEST(OnCallTest, PicksLastMatchingOnCall) {
723 .WillByDefault(
Return(3));
725 .WillByDefault(
Return(2));
727 .WillByDefault(
Return(1));
736TEST(ExpectCallTest, AllowsAnyCallWhenNoSpec) {
749TEST(ExpectCallTest, PicksLastMatchingExpectCall) {
752 .WillRepeatedly(
Return(2));
754 .WillRepeatedly(
Return(1));
760TEST(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");
774TEST(ExpectCallTest, InfersCardinalityWhenThereIsNoWillRepeatedly) {
792 },
"to be called twice");
806TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
811 .WillRepeatedly(
Return(2));
820 .WillRepeatedly(
Return(2));
831 .WillRepeatedly(
Return(2));
832 },
"to be called at least once");
837TEST(ExpectCallTest, NthMatchTakesNthAction) {
851TEST(ExpectCallTest, TakesRepeatedActionWhenWillListIsExhausted) {
855 .WillRepeatedly(
Return(2));
862#if GTEST_HAS_STREAM_REDIRECTION
866TEST(ExpectCallTest, TakesDefaultActionWhenWillListIsExhausted) {
880 const std::string output1 = GetCapturedStdout();
886 const std::string output2 = GetCapturedStdout();
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."));
897TEST(FunctionMockerMessageTest, ReportsExpectCallLocationForExhausedActions) {
906 const std::string
output = GetCapturedStdout();
911TEST(FunctionMockerMessageTest,
912 ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
913 std::string on_call_location;
927TEST(UninterestingCallTest, DoesDefaultAction) {
932 .WillByDefault(
Return(
true));
942TEST(UnexpectedCallTest, DoesDefaultAction) {
947 .WillByDefault(
Return(
true));
952 "Unexpected mock function call");
962 "Unexpected mock function call");
968TEST(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");
1017TEST(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");
1037TEST(UnexpectedCallTest, RetiredExpectation) {
1040 .RetiresOnSaturation();
1045 " Expected: the expectation is active\n"
1046 " Actual: it is retired");
1051TEST(UnexpectedCallTest, UnmatchedArguments) {
1057 " Expected arg #0: is equal to 1\n"
1064TEST(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:"));
1119TEST(UndefinedReturnValueTest,
1120 ReturnValueIsMandatoryWhenNotDefaultConstructible) {
1125#if GTEST_HAS_EXCEPTIONS
1134TEST(ExcessiveCallTest, DoesDefaultAction) {
1139 .WillByDefault(
Return(
true));
1144 "Mock function called more times than expected");
1154 "Mock function called more times than expected");
1160TEST(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");
1174TEST(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");
1190TEST(InSequenceTest, AllExpectationInScopeAreInSequence) {
1201 },
"Unexpected mock function call");
1207TEST(InSequenceTest, NestedInSequence) {
1224 },
"Unexpected mock function call");
1230TEST(InSequenceTest, ExpectationsOutOfScopeAreNotAffected) {
1242 },
"Unexpected mock function call");
1250TEST(SequenceTest, AnyOrderIsOkByDefault) {
1278TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo1) {
1281 .WillByDefault(
Return(Result()));
1302TEST(SequenceTest, CallsMustBeInStrictOrderWhenSaidSo2) {
1305 .WillByDefault(
Return(Result()));
1323 PartialOrderTest() {
1325 .WillByDefault(
Return(Result()));
1349TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag1) {
1360TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag2) {
1370TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag3) {
1380TEST_F(PartialOrderTest, CallsMustConformToSpecifiedDag4) {
1390TEST(SequenceTest, Retirement) {
1398 .RetiresOnSaturation();
1409TEST(ExpectationTest, ConstrutorsWork) {
1424 Expectation e9 =
EXPECT_CALL(
a, DoA(9)).RetiresOnSaturation();
1426 Expectation e10 = e2;
1441TEST(ExpectationTest, AssignmentWorks) {
1456TEST(ExpectationSetTest, MemberTypesAreCorrect) {
1460TEST(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;
1489TEST(ExpectationSetTest, AssignmentWorks) {
1491 ExpectationSet es2 = Expectation();
1499TEST(ExpectationSetTest, InsertionWorks) {
1511 ExpectationSet::const_iterator it1 = es1.begin();
1512 ExpectationSet::const_iterator it2 = it1;
1519TEST(ExpectationSetTest, SizeWorks) {
1523 es += Expectation();
1533TEST(ExpectationSetTest, IsEnumerable) {
1537 es += Expectation();
1538 ExpectationSet::const_iterator it = es.begin();
1547TEST(AfterTest, SucceedsWhenPartialOrderIsSatisfied) {
1560TEST(AfterTest, SucceedsWhenTotalOrderIsSatisfied) {
1578TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo1) {
1600TEST(AfterTest, CallsMustBeInStrictOrderWhenSpecifiedSo2) {
1624TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo) {
1627 .WillByDefault(
Return(Result()));
1646TEST(AfterTest, CallsMustSatisfyPartialOrderWhenSpecifiedSo2) {
1667TEST(AfterTest, CanBeUsedWithInSequence) {
1686TEST(AfterTest, CanBeCalledManyTimes) {
1703TEST(AfterTest, AcceptsUpToFiveArguments) {
1711 .After(e1, e2, e3, es1, es2);
1722TEST(AfterTest, AcceptsDuplicatedInput) {
1725 .WillByDefault(
Return(Result()));
1736 .After(e1, e2, es, e1);
1749TEST(AfterTest, ChangesToExpectationSetHaveNoEffectAfterwards) {
1766TEST(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));
1794TEST(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)
1826ACTION_P(Delete, ptr) {
delete ptr; }
1829# pragma warning(pop)
1832TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
1833 MockA*
const a =
new MockA;
1838TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningValue) {
1839 MockA*
const a =
new MockA;
1842 a->ReturnResult(42);
1846TEST(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");
1872TEST(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");
1896class 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";
1914Cardinality EvenNumber() {
1915 return Cardinality(
new EvenNumberCardinality);
1918TEST(ExpectationBaseTest,
1919 AllPrerequisitesAreSatisfiedWorksForNonMonotonicCardinality) {
1920 MockA*
a =
new MockA;
1924 .Times(EvenNumber())
1944inline void operator<<(::std::ostream& os,
const Printable&) {
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
1983TEST(FunctionCallMessageTest,
1984 UninterestingCallOnNaggyMockGeneratesNoStackTraceWhenVerboseWarning) {
1988 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
1989 const std::string
output = GetCapturedStdout();
1997TEST(FunctionCallMessageTest,
1998 UninterestingCallOnNaggyMockGeneratesFyiWithStackTraceWhenVerboseInfo) {
2002 c.VoidMethod(
false, 5,
"Hi", NULL, Printable(), Unprintable());
2003 const std::string
output = GetCapturedStdout();
2020 const std::string output2 = GetCapturedStdout();
2028TEST(FunctionCallMessageTest,
2029 UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
2034 const std::string output1 = GetCapturedStdout();
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());
2046 const std::string output2 = GetCapturedStdout();
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>\\)"));
2058class GMockVerboseFlagTest :
public VerboseFlagPreservingFixture {
2064 void VerifyOutput(
const std::string& output,
bool should_print,
2065 const string& expected_substring,
2066 const string& function_name) {
2075 static_cast<void>(function_name);
2083 void TestExpectedCall(
bool should_print) {
2093 GetCapturedStdout(),
2095 "Mock function call matches EXPECT_CALL(a, DoA(5))...\n"
2096 " Function call: DoA(5)\n"
2104 GetCapturedStdout(),
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.";
2127 GetCapturedStdout(),
2129 "\nGMOCK WARNING:\n"
2130 "Uninteresting mock function call - returning directly.\n"
2131 " Function call: DoA(5)\n" +
2139 GetCapturedStdout(),
2141 "\nGMOCK WARNING:\n"
2142 "Uninteresting mock function call - returning default value.\n"
2143 " Function call: Binary(2, 1)\n"
2144 " Returns: false\n" +
2152TEST_F(GMockVerboseFlagTest, Info) {
2154 TestExpectedCall(
true);
2155 TestUninterestingCallOnNaggyMock(
true);
2160TEST_F(GMockVerboseFlagTest, Warning) {
2162 TestExpectedCall(
false);
2163 TestUninterestingCallOnNaggyMock(
true);
2168TEST_F(GMockVerboseFlagTest, Error) {
2170 TestExpectedCall(
false);
2171 TestUninterestingCallOnNaggyMock(
false);
2176TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
2178 TestExpectedCall(
false);
2179 TestUninterestingCallOnNaggyMock(
true);
2189void PrintTo(PrintMeNot , ::std::ostream* ) {
2190 ADD_FAILURE() <<
"Google Mock is printing a value that shouldn't be "
2191 <<
"printed even to an internal buffer.";
2194class LogTestHelper {
2204class GMockLogTest :
public VerboseFlagPreservingFixture {
2206 LogTestHelper helper_;
2209TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsWarning) {
2212 .WillOnce(
Return(PrintMeNot()));
2213 helper_.Foo(PrintMeNot());
2216TEST_F(GMockLogTest, DoesNotPrintGoodCallInternallyIfVerbosityIsError) {
2219 .WillOnce(
Return(PrintMeNot()));
2220 helper_.Foo(PrintMeNot());
2223TEST_F(GMockLogTest, DoesNotPrintWarningInternallyIfVerbosityIsError) {
2226 .WillByDefault(
Return(PrintMeNot()));
2227 helper_.Foo(PrintMeNot());
2232TEST(AllowLeakTest, AllowsLeakingUnusedMockObject) {
2233 MockA*
a =
new MockA;
2237TEST(AllowLeakTest, CanBeCalledBeforeOnCall) {
2238 MockA*
a =
new MockA;
2244TEST(AllowLeakTest, CanBeCalledAfterOnCall) {
2245 MockA*
a =
new MockA;
2250TEST(AllowLeakTest, CanBeCalledBeforeExpectCall) {
2251 MockA*
a =
new MockA;
2257TEST(AllowLeakTest, CanBeCalledAfterExpectCall) {
2258 MockA*
a =
new MockA;
2263TEST(AllowLeakTest, WorksWhenBothOnCallAndExpectCallArePresent) {
2264 MockA*
a =
new MockA;
2272TEST(VerifyAndClearExpectationsTest, NoMethodHasExpectations) {
2285TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndSucceed) {
2301TEST(VerifyAndClearExpectationsTest, SomeMethodsHaveExpectationsAndFail) {
2307 "Actual: never called");
2318TEST(VerifyAndClearExpectationsTest, AllMethodsHaveExpectations) {
2336TEST(VerifyAndClearExpectationsTest, AMethodHasManyExpectations) {
2345 "Actual: never called");
2356TEST(VerifyAndClearExpectationsTest, CanCallManyTimes) {
2360 Mock::VerifyAndClearExpectations(&
b);
2365 Mock::VerifyAndClearExpectations(&
b);
2366 Mock::VerifyAndClearExpectations(&
b);
2376TEST(VerifyAndClearTest, NoMethodHasDefaultActions) {
2379 Mock::VerifyAndClear(&
b);
2385TEST(VerifyAndClearTest, SomeMethodsHaveDefaultActions) {
2388 .WillByDefault(
Return(1));
2390 Mock::VerifyAndClear(&
b);
2398TEST(VerifyAndClearTest, AllMethodsHaveDefaultActions) {
2401 .WillByDefault(
Return(1));
2403 .WillByDefault(
Return(2));
2405 Mock::VerifyAndClear(&
b);
2416TEST(VerifyAndClearTest, AMethodHasManyDefaultActions) {
2419 .WillByDefault(
Return(1));
2421 .WillByDefault(
Return(2));
2423 Mock::VerifyAndClear(&
b);
2433TEST(VerifyAndClearTest, CanCallManyTimes) {
2436 .WillByDefault(
Return(1));
2437 Mock::VerifyAndClear(&
b);
2438 Mock::VerifyAndClear(&
b);
2441 .WillByDefault(
Return(1));
2442 Mock::VerifyAndClear(&
b);
2449TEST(VerifyAndClearTest, Success) {
2452 .WillByDefault(
Return(1));
2467TEST(VerifyAndClearTest, Failure) {
2470 .WillByDefault(
Return(1));
2477 "Actual: never called");
2488TEST(VerifyAndClearTest, Const) {
2491 .WillByDefault(
Return(1));
2509TEST(VerifyAndClearTest, CanSetDefaultActionsAndExpectationsAfterwards) {
2512 .WillByDefault(
Return(1));
2517 Mock::VerifyAndClear(&
b);
2522 .WillByDefault(
Return(4));
2530TEST(VerifyAndClearTest, DoesNotAffectOtherMockObjects) {
2536 .WillByDefault(
Return(
true));
2539 .WillOnce(
Return(
false));
2542 .WillByDefault(
Return(1));
2547 .WillByDefault(
Return(3));
2551 Mock::VerifyAndClear(&b2);
2562TEST(VerifyAndClearTest,
2563 DestroyingChainedMocksDoesNotDeadlockThroughExpectations) {
2564 linked_ptr<MockA>
a(
new MockA);
2565 ReferenceHoldingMock test_mock;
2582TEST(VerifyAndClearTest,
2583 DestroyingChainedMocksDoesNotDeadlockThroughDefaultAction) {
2584 linked_ptr<MockA>
a(
new MockA);
2585 ReferenceHoldingMock test_mock;
2588 ON_CALL(test_mock, AcceptReference(
_))
2607TEST(SynchronizationTest, CanCallMockMethodInAction) {
2612 &MockC::NonVoidMethod)));
2615 .WillOnce(
Invoke(&
a, &MockA::DoA))
2616 .RetiresOnSaturation();
2631#if GMOCK_RENAME_MAIN
2632int gmock_main(
int argc,
char **argv) {
2640 testing::GMOCK_FLAG(catch_leaked_mocks) =
true;
#define s(x, c)
Definition aesb.c:47
std::ostream & operator<<(std::ostream &os, const Student &s)
Definition archivertest.cpp:30
cryptonote::block b
Definition block.cpp:40
Definition gmock-spec-builders.h:660
Definition gmock-generated-nice-strict.h:176
Definition gmock-spec-builders.h:619
Definition gmock-cardinalities.h:59
Definition gmock-cardinalities.h:83
Definition gmock-spec-builders.h:563
Definition gmock-spec-builders.h:487
Definition gmock-spec-builders.h:660
Definition gtest-message.h:85
Definition gmock-spec-builders.h:371
Definition gmock-generated-nice-strict.h:176
Definition gtest-spi.h:52
Definition gmock-spec-builders.h:619
Definition gtest-test-part.h:126
int size() const
Definition gtest-test-part.cc:83
const TestPartResult & GetTestPartResult(int index) const
Definition gtest-test-part.cc:73
@ kNonFatalFailure
Definition gtest-test-part.h:53
Definition gmock-spec-builders.h:690
int call_count_
Definition gmock-spec-builders.h:862
Definition gmock-spec-builders_test.cc:52
void SetCallCount(int n, ExpectationBase *exp)
Definition gmock-spec-builders_test.cc:55
Definition gtest-linked_ptr.h:146
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition gtest-death-test.h:286
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:204
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2216
#define ASSERT_EQ(val1, val2)
Definition gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define ASSERT_FALSE(condition)
Definition gtest.h:1868
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition gtest.h:2232
#define EXPECT_ANY_THROW(statement)
Definition gtest.h:1847
#define EXPECT_TRUE(condition)
Definition gtest.h:1859
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1995
#define TEST(test_case_name, test_name)
Definition gtest.h:2187
#define ADD_FAILURE()
Definition gtest.h:1808
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
#define EXPECT_FALSE(condition)
Definition gtest.h:1862
#define EXPECT_PRED_FORMAT2(pred_format, v1, v2)
Definition gtest_pred_impl.h:161
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition gtest-port.h:874
#define ACTION_P(name, p0)
Definition gmock-generated-actions.h:1353
#define MOCK_METHOD0(m,...)
Definition gmock-generated-function-mockers.h:675
#define MOCK_METHOD2(m,...)
Definition gmock-generated-function-mockers.h:677
#define MOCK_METHOD1(m,...)
Definition gmock-generated-function-mockers.h:676
#define MOCK_CONST_METHOD0(m,...)
Definition gmock-generated-function-mockers.h:687
#define MOCK_METHOD6(m,...)
Definition gmock-generated-function-mockers.h:681
#define EXPECT_THAT(value, matcher)
Definition gmock-matchers.h:4390
#define GMOCK_FLAG(name)
Definition gmock-port.h:70
#define EXPECT_CALL(obj, call)
Definition gmock-spec-builders.h:1845
#define ON_CALL(obj, call)
Definition gmock-spec-builders.h:1841
#define Method
Definition gmock-spec-builders_test.cc:184
internal::EqMatcher< T > Eq(T x)
Definition gmock-matchers.h:3742
internal::IgnoreResultAction< A > IgnoreResult(const A &an_action)
Definition gmock-actions.h:1187
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Definition gmock-actions.h:1168
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
Definition gmock-matchers.h:3984
const internal::AnythingMatcher _
Definition gmock-matchers.h:3729
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
Definition gmock-matchers.h:4016
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Definition gmock-more-actions.h:114
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
Definition gmock-generated-actions.h:696
internal::NeMatcher< Rhs > Ne(Rhs x)
Definition gmock-matchers.h:3790
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
Definition gmock-actions.h:1109
internal::DoDefaultAction DoDefault()
Definition gmock-actions.h:1099
GTEST_API_ Cardinality AnyNumber()
Definition gmock-cardinalities.cc:146
void PrintTo(EnumWithPrintTo e, std::ostream *os)
Definition gtest-printers_test.cc:93
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1618
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1606
output
Definition gmock_output_test.py:175
@ note
Definition message_store.h:67
c
Definition pymoduletest.py:79
e
Definition pymoduletest.py:79
const char * Binary(const char *input, short n)
Definition gmock-generated-actions_test.cc:95
Definition gmock-actions.h:64
GTEST_API_::std::string FormatFileLocation(const char *file, int line)
Definition gtest-port.cc:880
const char kErrorVerbosity[]
Definition gmock-internal-utils.h:318
::std::string string
Definition gtest-port.h:1097
const char kInfoVerbosity[]
Definition gmock-internal-utils.h:314
const char kWarningVerbosity[]
Definition gmock-internal-utils.h:316
Definition gmock-actions.h:53
internal::GtMatcher< Rhs > Gt(Rhs x)
Definition gmock-matchers.h:3772
GTEST_API_ Cardinality AtLeast(int n)
Definition gmock-cardinalities.cc:140
internal::EqMatcher< T > Eq(T x)
Definition gmock-matchers.h:3742
GTEST_API_ AssertionResult IsNotSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1618
PolymorphicAction< internal::InvokeWithoutArgsAction< FunctionImpl > > InvokeWithoutArgs(FunctionImpl function_impl)
Definition gmock-actions.h:1168
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
Definition gmock-matchers.h:3984
GTEST_API_ void InitGoogleMock(int *argc, char **argv)
Definition gmock.cc:173
GTEST_API_ AssertionResult IsSubstring(const char *needle_expr, const char *haystack_expr, const char *needle, const char *haystack)
Definition gtest.cc:1606
internal::LtMatcher< Rhs > Lt(Rhs x)
Definition gmock-matchers.h:3784
GTEST_API_ Cardinality Between(int min, int max)
Definition gmock-cardinalities.cc:149
const internal::AnythingMatcher _
Definition gmock-matchers.h:3729
GTEST_API_ Cardinality AtMost(int n)
Definition gmock-cardinalities.cc:143
bool StaticAssertTypeEq()
Definition gtest.h:2150
PolymorphicMatcher< internal::MatchesRegexMatcher > ContainsRegex(const internal::RE *regex)
Definition gmock-matchers.h:4016
const T & Const(const T &x)
Definition gmock-spec-builders.h:1826
GTEST_API_ Cardinality AnyNumber()
Definition gmock-cardinalities.cc:146
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Definition gmock-more-actions.h:114
internal::DoBothAction< Action1, Action2 > DoAll(Action1 a1, Action2 a2)
Definition gmock-generated-actions.h:696
internal::NeMatcher< Rhs > Ne(Rhs x)
Definition gmock-matchers.h:3790
internal::ReturnAction< R > Return(R value)
Definition gmock-actions.h:1061
PolymorphicAction< internal::SetArgumentPointeeAction< N, T, internal::IsAProtocolMessage< T >::value > > SetArgPointee(const T &x)
Definition gmock-actions.h:1109
internal::DoDefaultAction DoDefault()
Definition gmock-actions.h:1099
r
Definition testupnpigd.py:61
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
tools::wallet2::message_signature_result_t result
Definition signature.cpp:62
Definition fwdtest.cpp:28
int main(void)
Definition testportlistingparse.c:138