51 namespace gmock_nice_strict_test {
54 using testing::HasSubstr;
59 #if GTEST_HAS_STREAM_REDIRECTION
77 virtual int DoThat(
bool flag) = 0;
97 MockBar(
char a1,
char a2, std::string a3, std::string a4,
int a5,
int a6,
98 const std::string& a7,
const std::string& a8,
bool a9,
bool a10) {
99 str_ = std::string() + a1 + a2 + a3 + a4 +
static_cast<char>(a5) +
100 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') + (a10 ?
'T' :
'F');
105 const std::string&
str()
const {
return str_; }
133 #if GTEST_HAS_STREAM_REDIRECTION
136 TEST(RawMockTest, WarningForUninterestingCall) {
137 const std::string saved_flag =
GMOCK_FLAG(verbose);
144 raw_foo.DoThat(
true);
146 HasSubstr(
"Uninteresting mock function call"));
153 TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
154 const std::string saved_flag =
GMOCK_FLAG(verbose);
157 MockFoo*
const raw_foo =
new MockFoo;
165 HasSubstr(
"Uninteresting mock function call"));
172 TEST(RawMockTest, InfoForUninterestingCall) {
175 const std::string saved_flag =
GMOCK_FLAG(verbose);
180 HasSubstr(
"Uninteresting mock function call"));
185 TEST(RawMockTest, IsNaggy_IsNice_IsStrict) {
193 TEST(NiceMockTest, NoWarningForUninterestingCall) {
194 NiceMock<MockFoo> nice_foo;
198 nice_foo.DoThat(
true);
204 TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
205 NiceMock<MockFoo>*
const nice_foo =
new NiceMock<MockFoo>;
217 TEST(NiceMockTest, InfoForUninterestingCall) {
218 NiceMock<MockFoo> nice_foo;
220 const std::string saved_flag =
GMOCK_FLAG(verbose);
225 HasSubstr(
"Uninteresting mock function call"));
230 #endif // GTEST_HAS_STREAM_REDIRECTION
233 TEST(NiceMockTest, AllowsExpectedCall) {
243 TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
245 #if GTEST_HAS_EXCEPTIONS
247 nice_foo.ReturnNonDefaultConstructible();
249 }
catch (
const std::runtime_error& ex) {
250 EXPECT_THAT(ex.what(), HasSubstr(
"ReturnNonDefaultConstructible"));
258 TEST(NiceMockTest, UnexpectedCallFails) {
267 TEST(NiceMockTest, NonDefaultConstructor) {
272 nice_bar.That(5,
true);
277 TEST(NiceMockTest, NonDefaultConstructor10) {
279 "g",
"h",
true,
false);
283 nice_bar.That(5,
true);
286 TEST(NiceMockTest, AllowLeak) {
288 Mock::AllowLeak(leaked);
293 TEST(NiceMockTest, MoveOnlyConstructor) {
299 TEST(NiceMockTest, AcceptsClassNamedMock) {
305 TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
312 #if GTEST_HAS_STREAM_REDIRECTION
315 TEST(NaggyMockTest, WarningForUninterestingCall) {
316 const std::string saved_flag =
GMOCK_FLAG(verbose);
323 naggy_foo.DoThat(
true);
325 HasSubstr(
"Uninteresting mock function call"));
332 TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
333 const std::string saved_flag =
GMOCK_FLAG(verbose);
336 NaggyMock<MockFoo>*
const naggy_foo =
new NaggyMock<MockFoo>;
344 HasSubstr(
"Uninteresting mock function call"));
349 #endif // GTEST_HAS_STREAM_REDIRECTION
352 TEST(NaggyMockTest, AllowsExpectedCall) {
360 TEST(NaggyMockTest, UnexpectedCallFails) {
365 "called more times than expected");
370 TEST(NaggyMockTest, NonDefaultConstructor) {
375 naggy_bar.That(5,
true);
380 TEST(NaggyMockTest, NonDefaultConstructor10) {
382 "6",
"7",
true,
false);
383 EXPECT_EQ(
"01234567TF", naggy_bar.str());
386 naggy_bar.That(5,
true);
389 TEST(NaggyMockTest, AllowLeak) {
391 Mock::AllowLeak(leaked);
396 TEST(NaggyMockTest, MoveOnlyConstructor) {
402 TEST(NaggyMockTest, AcceptsClassNamedMock) {
408 TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
416 TEST(StrictMockTest, AllowsExpectedCall) {
424 TEST(StrictMockTest, UnexpectedCallFails) {
429 "called more times than expected");
433 TEST(StrictMockTest, UninterestingCallFails) {
437 "Uninteresting mock function call");
442 TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
449 "Uninteresting mock function call");
454 TEST(StrictMockTest, NonDefaultConstructor) {
459 "Uninteresting mock function call");
464 TEST(StrictMockTest, NonDefaultConstructor10) {
466 "g",
"h",
true,
false);
467 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
470 "Uninteresting mock function call");
473 TEST(StrictMockTest, AllowLeak) {
475 Mock::AllowLeak(leaked);
480 TEST(StrictMockTest, MoveOnlyConstructor) {
486 TEST(StrictMockTest, AcceptsClassNamedMock) {
492 TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
MOCK_METHOD0(This, int())
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ std::string GetCapturedStdout()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
TEST(NiceMockTest, AllowsExpectedCall)
MOCK_METHOD0(DoThis, void())
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)
#define ON_CALL(obj, call)
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock)
NotDefaultConstructible(int)
GTEST_API_ void CaptureStdout()
std::decay< FunctionImpl >::type Invoke(FunctionImpl &&function_impl)
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar)
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo)
MoveOnly & operator=(const MoveOnly &)=delete
const std::string & str() const
#define EXPECT_THAT(value, matcher)
MOCK_METHOD0(DoThis, void())
#define EXPECT_CALL(obj, call)
#define EXPECT_EQ(val1, val2)
#define EXPECT_TRUE(condition)
MockBar(const std::string &s)
MOCK_METHOD1(DoThat, int(bool flag))
MOCK_METHOD2(That, std::string(int, bool))
#define EXPECT_FALSE(condition)
virtual int DoThat(bool flag)=0