49 Mock& operator=(
const Mock&) =
delete;
53namespace gmock_nice_strict_test {
55using testing::HasSubstr;
60#if GTEST_HAS_STREAM_REDIRECTION
103 explicit MockBar(
const std::string& s) : str_(s) {}
105 MockBar(
char a1,
char a2, std::string a3, std::string a4,
int a5,
int a6,
106 const std::string& a7,
const std::string& a8,
bool a9,
bool a10) {
107 str_ = std::string() + a1 + a2 + a3 + a4 +
static_cast<char>(a5) +
108 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') +
114 const std::string&
str()
const {
return str_; }
142#if GTEST_HAS_STREAM_REDIRECTION
145TEST(RawMockTest, WarningForUninterestingCall) {
153 raw_foo.DoThat(
true);
155 HasSubstr(
"Uninteresting mock function call"));
162TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
166 MockFoo*
const raw_foo =
new MockFoo;
173 HasSubstr(
"Uninteresting mock function call"));
180TEST(RawMockTest, InfoForUninterestingCall) {
188 HasSubstr(
"Uninteresting mock function call"));
193TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
201TEST(NiceMockTest, NoWarningForUninterestingCall) {
202 NiceMock<MockFoo> nice_foo;
206 nice_foo.DoThat(
true);
212TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
213 NiceMock<MockFoo>*
const nice_foo =
new NiceMock<MockFoo>;
225TEST(NiceMockTest, InfoForUninterestingCall) {
226 NiceMock<MockFoo> nice_foo;
233 HasSubstr(
"Uninteresting mock function call"));
241TEST(NiceMockTest, AllowsExpectedCall) {
251TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
253#if GTEST_HAS_EXCEPTIONS
255 nice_foo.ReturnNonDefaultConstructible();
257 }
catch (
const std::runtime_error& ex) {
258 EXPECT_THAT(ex.what(), HasSubstr(
"ReturnNonDefaultConstructible"));
266TEST(NiceMockTest, UnexpectedCallFails) {
275TEST(NiceMockTest, NonDefaultConstructor) {
280 nice_bar.That(5,
true);
285TEST(NiceMockTest, NonDefaultConstructor10) {
291 nice_bar.That(5,
true);
296 Mock::AllowLeak(leaked);
301TEST(NiceMockTest, MoveOnlyConstructor) {
307TEST(NiceMockTest, AcceptsClassNamedMock) {
313TEST(NiceMockTest, IsNiceInDestructor) {
320TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
327#if GTEST_HAS_STREAM_REDIRECTION
330TEST(NaggyMockTest, WarningForUninterestingCall) {
338 naggy_foo.DoThat(
true);
340 HasSubstr(
"Uninteresting mock function call"));
347TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
351 NaggyMock<MockFoo>*
const naggy_foo =
new NaggyMock<MockFoo>;
359 HasSubstr(
"Uninteresting mock function call"));
367TEST(NaggyMockTest, AllowsExpectedCall) {
375TEST(NaggyMockTest, UnexpectedCallFails) {
380 "called more times than expected");
385TEST(NaggyMockTest, NonDefaultConstructor) {
390 naggy_bar.That(5,
true);
395TEST(NaggyMockTest, NonDefaultConstructor10) {
398 EXPECT_EQ(
"01234567TF", naggy_bar.str());
401 naggy_bar.That(5,
true);
404TEST(NaggyMockTest, AllowLeak) {
406 Mock::AllowLeak(leaked);
411TEST(NaggyMockTest, MoveOnlyConstructor) {
417TEST(NaggyMockTest, AcceptsClassNamedMock) {
423TEST(NaggyMockTest, IsNaggyInDestructor) {
434 HasSubstr(
"Uninteresting mock function call"));
439TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
447TEST(StrictMockTest, AllowsExpectedCall) {
455TEST(StrictMockTest, UnexpectedCallFails) {
460 "called more times than expected");
464TEST(StrictMockTest, UninterestingCallFails) {
468 "Uninteresting mock function call");
473TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
480 "Uninteresting mock function call");
485TEST(StrictMockTest, NonDefaultConstructor) {
490 "Uninteresting mock function call");
495TEST(StrictMockTest, NonDefaultConstructor10) {
498 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
501 "Uninteresting mock function call");
504TEST(StrictMockTest, AllowLeak) {
506 Mock::AllowLeak(leaked);
511TEST(StrictMockTest, MoveOnlyConstructor) {
517TEST(StrictMockTest, AcceptsClassNamedMock) {
523TEST(StrictMockTest, IsStrictInDestructor) {
530 "Uninteresting mock function call");
533TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
Definition gmock-nice-strict_test.cc:41
MOCK_METHOD0(DoThis, void())
Definition gmock-nice-strict.h:192
Definition gmock-nice-strict.h:151
Definition gmock-nice-strict.h:234
Definition gmock-nice-strict_test.cc:71
~CallsMockMethodInDestructor()
Definition gmock-nice-strict_test.cc:73
MOCK_METHOD(void, OnDestroy,())
Definition gmock-nice-strict_test.cc:79
virtual int DoThat(bool flag)=0
Definition gmock-nice-strict_test.cc:101
const std::string & str() const
Definition gmock-nice-strict_test.cc:114
virtual ~MockBar()=default
MOCK_METHOD0(This, int())
MockBar(const std::string &s)
Definition gmock-nice-strict_test.cc:103
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)
Definition gmock-nice-strict_test.cc:105
MOCK_METHOD2(That, std::string(int, bool))
Definition gmock-nice-strict_test.cc:128
MoveOnly(const MoveOnly &)=delete
MoveOnly & operator=(MoveOnly &&)=default
MoveOnly & operator=(const MoveOnly &)=delete
MoveOnly(MoveOnly &&)=default
Definition gmock-nice-strict_test.cc:126
MockBaz(MoveOnly)
Definition gmock-nice-strict_test.cc:139
Definition gmock-nice-strict_test.cc:87
MOCK_METHOD0(DoThis, void())
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible())
MOCK_METHOD1(DoThat, int(bool flag))
void Delete()
Definition gmock-nice-strict_test.cc:90
Definition gmock-nice-strict_test.cc:66
NotDefaultConstructible(int)
Definition gmock-nice-strict_test.cc:68
#define EXPECT_THAT(value, matcher)
#define GMOCK_FLAG_GET(name)
Definition gmock-port.h:134
#define GMOCK_FLAG_SET(name, value)
Definition gmock-port.h:135
#define EXPECT_CALL(obj, call)
Definition gmock-spec-builders.h:2145
#define ON_CALL(obj, call)
Definition gmock-spec-builders.h:2142
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
Definition gtest-death-test.h:337
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition gtest-spi.h:217
#define FAIL()
Definition gtest.h:1754
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1868
#define TEST(test_suite_name, test_name)
Definition gtest.h:2176
#define EXPECT_TRUE(condition)
Definition gtest.h:1807
#define EXPECT_FALSE(condition)
Definition gtest.h:1811
GTEST_API_ void CaptureStdout()
GTEST_API_ std::string GetCapturedStdout()
Definition gmock-actions.h:151
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
Definition gmock-actions.h:1948