35 #include "gmock/gmock.h" 36 #include "gtest/gtest.h" 37 #include "gtest/gtest-spi.h" 52 namespace gmock_nice_strict_test {
61 #if GTEST_HAS_STREAM_REDIRECTION 72 virtual void DoThis() = 0;
73 virtual int DoThat(
bool flag) = 0;
90 explicit MockBar(
const string& s) : str_(s) {}
92 MockBar(
char a1,
char a2,
string a3,
string a4,
int a5,
int a6,
93 const string& a7,
const string& a8,
bool a9,
bool a10) {
94 str_ =
string() + a1 + a2 + a3 + a4 +
static_cast<char>(a5) +
95 static_cast<char>(a6) + a7 + a8 + (a9 ?
'T' :
'F') + (a10 ?
'T' :
'F');
100 const string&
str()
const {
return str_; }
111 #if GTEST_HAS_STREAM_REDIRECTION 114 TEST(RawMockTest, WarningForUninterestingCall) {
115 const string saved_flag =
GMOCK_FLAG(verbose);
124 HasSubstr(
"Uninteresting mock function call"));
131 TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
132 const string saved_flag =
GMOCK_FLAG(verbose);
143 HasSubstr(
"Uninteresting mock function call"));
150 TEST(RawMockTest, InfoForUninterestingCall) {
153 const string saved_flag =
GMOCK_FLAG(verbose);
158 HasSubstr(
"Uninteresting mock function call"));
164 TEST(NiceMockTest, NoWarningForUninterestingCall) {
169 nice_foo.DoThat(
true);
175 TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) {
188 TEST(NiceMockTest, InfoForUninterestingCall) {
191 const string saved_flag =
GMOCK_FLAG(verbose);
196 HasSubstr(
"Uninteresting mock function call"));
201 #endif // GTEST_HAS_STREAM_REDIRECTION 204 TEST(NiceMockTest, AllowsExpectedCall) {
212 TEST(NiceMockTest, UnexpectedCallFails) {
221 TEST(NiceMockTest, NonDefaultConstructor) {
226 nice_bar.That(5,
true);
231 TEST(NiceMockTest, NonDefaultConstructor10) {
233 "g",
"h",
true,
false);
237 nice_bar.That(5,
true);
240 #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE 249 TEST(NiceMockTest, AcceptsClassNamedMock) {
254 #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE 256 #if GTEST_HAS_STREAM_REDIRECTION 259 TEST(NaggyMockTest, WarningForUninterestingCall) {
260 const string saved_flag =
GMOCK_FLAG(verbose);
267 naggy_foo.DoThat(
true);
269 HasSubstr(
"Uninteresting mock function call"));
276 TEST(NaggyMockTest, WarningForUninterestingCallAfterDeath) {
277 const string saved_flag =
GMOCK_FLAG(verbose);
288 HasSubstr(
"Uninteresting mock function call"));
293 #endif // GTEST_HAS_STREAM_REDIRECTION 296 TEST(NaggyMockTest, AllowsExpectedCall) {
304 TEST(NaggyMockTest, UnexpectedCallFails) {
309 "called more times than expected");
314 TEST(NaggyMockTest, NonDefaultConstructor) {
319 naggy_bar.That(5,
true);
324 TEST(NaggyMockTest, NonDefaultConstructor10) {
326 "6",
"7",
true,
false);
327 EXPECT_EQ(
"01234567TF", naggy_bar.str());
330 naggy_bar.That(5,
true);
333 #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE 342 TEST(NaggyMockTest, AcceptsClassNamedMock) {
347 #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE 350 TEST(StrictMockTest, AllowsExpectedCall) {
358 TEST(StrictMockTest, UnexpectedCallFails) {
363 "called more times than expected");
367 TEST(StrictMockTest, UninterestingCallFails) {
371 "Uninteresting mock function call");
376 TEST(StrictMockTest, UninterestingCallFailsAfterDeath) {
383 "Uninteresting mock function call");
388 TEST(StrictMockTest, NonDefaultConstructor) {
393 "Uninteresting mock function call");
398 TEST(StrictMockTest, NonDefaultConstructor10) {
400 "g",
"h",
true,
false);
401 EXPECT_EQ(
"abcdefghTF", strict_bar.str());
404 "Uninteresting mock function call");
407 #if !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE 416 TEST(StrictMockTest, AcceptsClassNamedMock) {
421 #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE
std::string GetCapturedStdout()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
MOCK_METHOD0(DoThis, void())
#define EXPECT_THAT(value, matcher)
GTEST_DISALLOW_COPY_AND_ASSIGN_(Mock)
#define ON_CALL(obj, call)
MOCK_METHOD1(VoidFromString, void(char *str))
const string & str() const
MockBar(char a1, char a2, string a3, string a4, int a5, int a6, const string &a7, const string &a8, bool a9, bool a10)
#define MOCK_METHOD2(m,...)
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
TEST(StrictMockTest, AcceptsClassNamedMock)
#define EXPECT_CALL(obj, call)
#define EXPECT_EQ(expected, actual)
virtual int DoThat(bool flag)=0