53namespace gmock_nice_strict_test {
55using testing::GMOCK_FLAG(
verbose);
61#if GTEST_HAS_STREAM_REDIRECTION
99 MockBar(
char a1,
char a2, std::string a3, std::string a4,
int a5,
int a6,
100 const std::string& a7,
const std::string& a8,
bool a9,
bool a10) {
101 str_ = std::string() + a1 + a2 + a3 + a4 +
static_cast<char>(a5) +
102 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') + (a10 ?
'T' :
'F');
107 const std::string&
str()
const {
return str_; }
118#if GTEST_GTEST_LANG_CXX11
123 MoveOnly() =
default;
125 MoveOnly(
const MoveOnly&) =
delete;
126 operator=(
const MoveOnly&) =
delete;
128 MoveOnly(MoveOnly&&) =
default;
129 operator=(MoveOnly&&) =
default;
136#if GTEST_HAS_STREAM_REDIRECTION
139TEST(RawMockTest, WarningForUninterestingCall) {
140 const std::string saved_flag =
GMOCK_FLAG(verbose);
147 raw_foo.DoThat(
true);
149 HasSubstr(
"Uninteresting mock function call"));
156TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
157 const std::string saved_flag =
GMOCK_FLAG(verbose);
160 MockFoo*
const raw_foo =
new MockFoo;
168 HasSubstr(
"Uninteresting mock function call"));
175TEST(RawMockTest, InfoForUninterestingCall) {
178 const std::string saved_flag =
GMOCK_FLAG(verbose);
183 HasSubstr(
"Uninteresting mock function call"));
189TEST(NiceMockTest, NoWarningForUninterestingCall) {
190 NiceMock<MockFoo> nice_foo;
194 nice_foo.DoThat(
true);
200TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
201 NiceMock<MockFoo>*
const nice_foo =
new NiceMock<MockFoo>;
213TEST(NiceMockTest, InfoForUninterestingCall) {
214 NiceMock<MockFoo> nice_foo;
216 const std::string saved_flag =
GMOCK_FLAG(verbose);
221 HasSubstr(
"Uninteresting mock function call"));
229TEST(NiceMockTest, AllowsExpectedCall) {
239TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
241#if GTEST_HAS_EXCEPTIONS
243 nice_foo.ReturnNonDefaultConstructible();
245 }
catch (
const std::runtime_error& ex) {
246 EXPECT_THAT(ex.what(), HasSubstr(
"ReturnNonDefaultConstructible"));
254TEST(NiceMockTest, UnexpectedCallFails) {
263TEST(NiceMockTest, NonDefaultConstructor) {
268 nice_bar.That(5,
true);
273TEST(NiceMockTest, NonDefaultConstructor10) {
275 "g",
"h",
true,
false);
279 nice_bar.That(5,
true);
284 Mock::AllowLeak(leaked);
289#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
291TEST(NiceMockTest, MoveOnlyConstructor) {
297#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
306TEST(NiceMockTest, AcceptsClassNamedMock) {
313#if GTEST_HAS_STREAM_REDIRECTION
316TEST(NaggyMockTest, WarningForUninterestingCall) {
317 const std::string saved_flag =
GMOCK_FLAG(verbose);
324 naggy_foo.DoThat(
true);
326 HasSubstr(
"Uninteresting mock function call"));
333TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
334 const std::string saved_flag =
GMOCK_FLAG(verbose);
337 NaggyMock<MockFoo>*
const naggy_foo =
new NaggyMock<MockFoo>;
345 HasSubstr(
"Uninteresting mock function call"));
353TEST(NaggyMockTest, AllowsExpectedCall) {
361TEST(NaggyMockTest, UnexpectedCallFails) {
366 "called more times than expected");
371TEST(NaggyMockTest, NonDefaultConstructor) {
376 naggy_bar.That(5,
true);
381TEST(NaggyMockTest, NonDefaultConstructor10) {
383 "6",
"7",
true,
false);
384 EXPECT_EQ(
"01234567TF", naggy_bar.str());
387 naggy_bar.That(5,
true);
390TEST(NaggyMockTest, AllowLeak) {
392 Mock::AllowLeak(leaked);
397#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
399TEST(NaggyMockTest, MoveOnlyConstructor) {
405#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
414TEST(NaggyMockTest, AcceptsClassNamedMock) {
422TEST(StrictMockTest, AllowsExpectedCall) {
430TEST(StrictMockTest, UnexpectedCallFails) {
435 "called more times than expected");
439TEST(StrictMockTest, UninterestingCallFails) {
443 "Uninteresting mock function call");
448TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
455 "Uninteresting mock function call");
460TEST(StrictMockTest, NonDefaultConstructor) {
465 "Uninteresting mock function call");
470TEST(StrictMockTest, NonDefaultConstructor10) {
472 "g",
"h",
true,
false);
473 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
476 "Uninteresting mock function call");
479TEST(StrictMockTest, AllowLeak) {
481 Mock::AllowLeak(leaked);
486#if GTEST_GTEST_LANG_CXX11 && GTEST_HAS_STD_MOVE_
488TEST(StrictMockTest, MoveOnlyConstructor) {
494#if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
503TEST(StrictMockTest, AcceptsClassNamedMock) {
MOCK_METHOD0(DoThis, void())
virtual int DoThat(bool flag)=0
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))
MOCK_METHOD0(DoThis, void())
MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible())
MOCK_METHOD1(DoThat, int(bool flag))
NotDefaultConstructible(int)
#define EXPECT_THAT(value, matcher)
#define EXPECT_CALL(obj, call)
#define ON_CALL(obj, call)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_EQ(val1, val2)
#define TEST(test_case_name, test_name)
GTEST_API_ void CaptureStdout()
GTEST_API_ std::string GetCapturedStdout()
PolymorphicMatcher< internal::HasSubstrMatcher< std::string > > HasSubstr(const std::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)