47 GTEST_DISALLOW_COPY_AND_ASSIGN_(
Mock);
51namespace gmock_nice_strict_test {
54using testing::HasSubstr;
59#if GTEST_HAS_STREAM_REDIRECTION
96 GTEST_DISALLOW_COPY_AND_ASSIGN_(
MockFoo);
101 explicit MockBar(
const std::string& s) : str_(s) {}
103 MockBar(
char a1,
char a2, std::string a3, std::string a4,
int a5,
int a6,
104 const std::string& a7,
const std::string& a8,
bool a9,
bool a10) {
105 str_ = std::string() + a1 + a2 + a3 + a4 +
static_cast<char>(a5) +
106 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') + (a10 ?
'T' :
'F');
111 const std::string&
str()
const {
return str_; }
119 GTEST_DISALLOW_COPY_AND_ASSIGN_(
MockBar);
139#if GTEST_HAS_STREAM_REDIRECTION
142TEST(RawMockTest, WarningForUninterestingCall) {
143 const std::string saved_flag =
GMOCK_FLAG(verbose);
150 raw_foo.DoThat(
true);
152 HasSubstr(
"Uninteresting mock function call"));
159TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
160 const std::string saved_flag =
GMOCK_FLAG(verbose);
163 MockFoo*
const raw_foo =
new MockFoo;
171 HasSubstr(
"Uninteresting mock function call"));
178TEST(RawMockTest, InfoForUninterestingCall) {
181 const std::string saved_flag =
GMOCK_FLAG(verbose);
186 HasSubstr(
"Uninteresting mock function call"));
191TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
199TEST(NiceMockTest, NoWarningForUninterestingCall) {
200 NiceMock<MockFoo> nice_foo;
204 nice_foo.DoThat(
true);
210TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
211 NiceMock<MockFoo>*
const nice_foo =
new NiceMock<MockFoo>;
223TEST(NiceMockTest, InfoForUninterestingCall) {
224 NiceMock<MockFoo> nice_foo;
226 const std::string saved_flag =
GMOCK_FLAG(verbose);
231 HasSubstr(
"Uninteresting mock function call"));
239TEST(NiceMockTest, AllowsExpectedCall) {
249TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
251#if GTEST_HAS_EXCEPTIONS
253 nice_foo.ReturnNonDefaultConstructible();
255 }
catch (
const std::runtime_error& ex) {
256 EXPECT_THAT(ex.what(), HasSubstr(
"ReturnNonDefaultConstructible"));
264TEST(NiceMockTest, UnexpectedCallFails) {
273TEST(NiceMockTest, NonDefaultConstructor) {
278 nice_bar.That(5,
true);
283TEST(NiceMockTest, NonDefaultConstructor10) {
285 "g",
"h",
true,
false);
289 nice_bar.That(5,
true);
294 Mock::AllowLeak(leaked);
299TEST(NiceMockTest, MoveOnlyConstructor) {
305TEST(NiceMockTest, AcceptsClassNamedMock) {
311TEST(NiceMockTest, IsNiceInDestructor) {
318TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
325#if GTEST_HAS_STREAM_REDIRECTION
328TEST(NaggyMockTest, WarningForUninterestingCall) {
329 const std::string saved_flag =
GMOCK_FLAG(verbose);
336 naggy_foo.DoThat(
true);
338 HasSubstr(
"Uninteresting mock function call"));
345TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
346 const std::string saved_flag =
GMOCK_FLAG(verbose);
349 NaggyMock<MockFoo>*
const naggy_foo =
new NaggyMock<MockFoo>;
357 HasSubstr(
"Uninteresting mock function call"));
365TEST(NaggyMockTest, AllowsExpectedCall) {
373TEST(NaggyMockTest, UnexpectedCallFails) {
378 "called more times than expected");
383TEST(NaggyMockTest, NonDefaultConstructor) {
388 naggy_bar.That(5,
true);
393TEST(NaggyMockTest, NonDefaultConstructor10) {
395 "6",
"7",
true,
false);
396 EXPECT_EQ(
"01234567TF", naggy_bar.str());
399 naggy_bar.That(5,
true);
402TEST(NaggyMockTest, AllowLeak) {
404 Mock::AllowLeak(leaked);
409TEST(NaggyMockTest, MoveOnlyConstructor) {
415TEST(NaggyMockTest, AcceptsClassNamedMock) {
421TEST(NaggyMockTest, IsNaggyInDestructor) {
422 const std::string saved_flag =
GMOCK_FLAG(verbose);
432 HasSubstr(
"Uninteresting mock function call"));
437TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
445TEST(StrictMockTest, AllowsExpectedCall) {
453TEST(StrictMockTest, UnexpectedCallFails) {
458 "called more times than expected");
462TEST(StrictMockTest, UninterestingCallFails) {
466 "Uninteresting mock function call");
471TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
478 "Uninteresting mock function call");
483TEST(StrictMockTest, NonDefaultConstructor) {
488 "Uninteresting mock function call");
493TEST(StrictMockTest, NonDefaultConstructor10) {
495 "g",
"h",
true,
false);
496 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
499 "Uninteresting mock function call");
502TEST(StrictMockTest, AllowLeak) {
504 Mock::AllowLeak(leaked);
509TEST(StrictMockTest, MoveOnlyConstructor) {
515TEST(StrictMockTest, AcceptsClassNamedMock) {
521TEST(StrictMockTest, IsStrictInDestructor) {
528 "Uninteresting mock function call");
531TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)
#define EXPECT_THAT(value, matcher)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
GTEST_API_ void CaptureStdout()
GTEST_API_ std::string GetCapturedStdout()
TEST(NiceMockTest, AllowsExpectedCall)
MOCK_METHOD0(DoThis, void())
NotDefaultConstructible(int)
~CallsMockMethodInDestructor()
MOCK_METHOD(void, OnDestroy,())
virtual int DoThat(bool flag)=0
MOCK_METHOD0(DoThis, void())
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible())
MOCK_METHOD1(DoThat, int(bool flag))
const std::string & str() const
MOCK_METHOD0(This, int())
MockBar(const std::string &s)
MockBar(char a1, char a2, std::string a3, std::string a4, int a5, int a6, const std::string &a7, const std::string &a8, bool a9, bool a10)
MOCK_METHOD2(That, std::string(int, bool))
MoveOnly(const MoveOnly &)=delete
MoveOnly & operator=(MoveOnly &&)=default
MoveOnly & operator=(const MoveOnly &)=delete
MoveOnly(MoveOnly &&)=default