aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-03-01 07:10:07 +0000
committerzhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386>2013-03-01 07:10:07 +0000
commitc896504e4175f08cd229ea151861558ba9380f50 (patch)
treec78f2e310a74687fb6ca7d0ea214c30979895146 /test
parent20d1a235bcfba95d1f436c9335bd46e9d62b64a2 (diff)
downloadgoogletest-c896504e4175f08cd229ea151861558ba9380f50.tar.gz
googletest-c896504e4175f08cd229ea151861558ba9380f50.tar.bz2
googletest-c896504e4175f08cd229ea151861558ba9380f50.zip
Improves the tests for nice, naggy, and strict mocks.
Diffstat (limited to 'test')
-rw-r--r--test/gmock-nice-strict_test.cc54
-rw-r--r--test/gmock-spec-builders_test.cc40
-rw-r--r--test/gmock_output_test_.cc3
3 files changed, 74 insertions, 23 deletions
diff --git a/test/gmock-nice-strict_test.cc b/test/gmock-nice-strict_test.cc
index 9b83d88e..d0adcbbe 100644
--- a/test/gmock-nice-strict_test.cc
+++ b/test/gmock-nice-strict_test.cc
@@ -110,6 +110,56 @@ class MockBar {
#if GTEST_HAS_STREAM_REDIRECTION
+// Tests that a raw mock generates warnings for uninteresting calls.
+TEST(RawMockTest, WarningForUninterestingCall) {
+ const string saved_flag = GMOCK_FLAG(verbose);
+ GMOCK_FLAG(verbose) = "warning";
+
+ MockFoo raw_foo;
+
+ CaptureStdout();
+ raw_foo.DoThis();
+ raw_foo.DoThat(true);
+ EXPECT_THAT(GetCapturedStdout(),
+ HasSubstr("Uninteresting mock function call"));
+
+ GMOCK_FLAG(verbose) = saved_flag;
+}
+
+// Tests that a raw mock generates warnings for uninteresting calls
+// that delete the mock object.
+TEST(RawMockTest, WarningForUninterestingCallAfterDeath) {
+ const string saved_flag = GMOCK_FLAG(verbose);
+ GMOCK_FLAG(verbose) = "warning";
+
+ MockFoo* const raw_foo = new MockFoo;
+
+ ON_CALL(*raw_foo, DoThis())
+ .WillByDefault(Invoke(raw_foo, &MockFoo::Delete));
+
+ CaptureStdout();
+ raw_foo->DoThis();
+ EXPECT_THAT(GetCapturedStdout(),
+ HasSubstr("Uninteresting mock function call"));
+
+ GMOCK_FLAG(verbose) = saved_flag;
+}
+
+// Tests that a raw mock generates informational logs for
+// uninteresting calls.
+TEST(RawMockTest, InfoForUninterestingCall) {
+ MockFoo raw_foo;
+
+ const string saved_flag = GMOCK_FLAG(verbose);
+ GMOCK_FLAG(verbose) = "info";
+ CaptureStdout();
+ raw_foo.DoThis();
+ EXPECT_THAT(GetCapturedStdout(),
+ HasSubstr("Uninteresting mock function call"));
+
+ GMOCK_FLAG(verbose) = saved_flag;
+}
+
// Tests that a nice mock generates no warning for uninteresting calls.
TEST(NiceMockTest, NoWarningForUninterestingCall) {
NiceMock<MockFoo> nice_foo;
@@ -145,10 +195,6 @@ TEST(NiceMockTest, InfoForUninterestingCall) {
EXPECT_THAT(GetCapturedStdout(),
HasSubstr("Uninteresting mock function call"));
- CaptureStdout();
- nice_foo.DoThat(true);
- EXPECT_THAT(GetCapturedStdout(),
- HasSubstr("Uninteresting mock function call"));
GMOCK_FLAG(verbose) = saved_flag;
}
diff --git a/test/gmock-spec-builders_test.cc b/test/gmock-spec-builders_test.cc
index 8a8632dc..4a333df7 100644
--- a/test/gmock-spec-builders_test.cc
+++ b/test/gmock-spec-builders_test.cc
@@ -85,6 +85,7 @@ using testing::IsSubstring;
using testing::Lt;
using testing::Message;
using testing::Mock;
+using testing::NaggyMock;
using testing::Ne;
using testing::Return;
using testing::Sequence;
@@ -899,11 +900,12 @@ TEST(FunctionMockerTest, ReportsExpectCallLocationForExhausedActions) {
EXPECT_PRED_FORMAT2(IsSubstring, expect_call_location, output);
}
-TEST(FunctionMockerTest, ReportsDefaultActionLocationOfUninterestingCalls) {
+TEST(FunctionMockerTest,
+ ReportsDefaultActionLocationOfUninterestingCallsForNaggyMock) {
std::string on_call_location;
CaptureStdout();
{
- MockB b;
+ NaggyMock<MockB> b;
on_call_location = FormatFileLocation(__FILE__, __LINE__ + 1);
ON_CALL(b, DoB(_)).WillByDefault(Return(0));
b.DoB(0);
@@ -1966,10 +1968,11 @@ class VerboseFlagPreservingFixture : public testing::Test {
#if GTEST_HAS_STREAM_REDIRECTION
-// Tests that an uninteresting mock function call generates a warning
-// containing the stack trace.
-TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
- MockC c;
+// Tests that an uninteresting mock function call on a naggy mock
+// generates a warning containing the stack trace.
+TEST(FunctionCallMessageTest,
+ UninterestingCallOnNaggyMockGeneratesFyiWithStackTrace) {
+ NaggyMock<MockC> c;
CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
const std::string output = GetCapturedStdout();
@@ -1995,11 +1998,12 @@ TEST(FunctionCallMessageTest, UninterestingCallGeneratesFyiWithStackTrace) {
# endif // NDEBUG
}
-// Tests that an uninteresting mock function call causes the function
-// arguments and return value to be printed.
-TEST(FunctionCallMessageTest, UninterestingCallPrintsArgumentsAndReturnValue) {
+// Tests that an uninteresting mock function call on a naggy mock
+// causes the function arguments and return value to be printed.
+TEST(FunctionCallMessageTest,
+ UninterestingCallOnNaggyMockPrintsArgumentsAndReturnValue) {
// A non-void mock function.
- MockB b;
+ NaggyMock<MockB> b;
CaptureStdout();
b.DoB();
const std::string output1 = GetCapturedStdout();
@@ -2011,7 +2015,7 @@ TEST(FunctionCallMessageTest, UninterestingCallPrintsArgumentsAndReturnValue) {
// Makes sure the return value is printed.
// A void mock function.
- MockC c;
+ NaggyMock<MockC> c;
CaptureStdout();
c.VoidMethod(false, 5, "Hi", NULL, Printable(), Unprintable());
const std::string output2 = GetCapturedStdout();
@@ -2081,9 +2085,9 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
"Binary");
}
- // Tests how the flag affects uninteresting calls.
- void TestUninterestingCall(bool should_print) {
- MockA a;
+ // Tests how the flag affects uninteresting calls on a naggy mock.
+ void TestUninterestingCallOnNaggyMock(bool should_print) {
+ NaggyMock<MockA> a;
// A void-returning function.
CaptureStdout();
@@ -2117,7 +2121,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
TEST_F(GMockVerboseFlagTest, Info) {
GMOCK_FLAG(verbose) = kInfoVerbosity;
TestExpectedCall(true);
- TestUninterestingCall(true);
+ TestUninterestingCallOnNaggyMock(true);
}
// Tests that --gmock_verbose=warning causes uninteresting calls to be
@@ -2125,7 +2129,7 @@ TEST_F(GMockVerboseFlagTest, Info) {
TEST_F(GMockVerboseFlagTest, Warning) {
GMOCK_FLAG(verbose) = kWarningVerbosity;
TestExpectedCall(false);
- TestUninterestingCall(true);
+ TestUninterestingCallOnNaggyMock(true);
}
// Tests that --gmock_verbose=warning causes neither expected nor
@@ -2133,7 +2137,7 @@ TEST_F(GMockVerboseFlagTest, Warning) {
TEST_F(GMockVerboseFlagTest, Error) {
GMOCK_FLAG(verbose) = kErrorVerbosity;
TestExpectedCall(false);
- TestUninterestingCall(false);
+ TestUninterestingCallOnNaggyMock(false);
}
// Tests that --gmock_verbose=SOME_INVALID_VALUE has the same effect
@@ -2141,7 +2145,7 @@ TEST_F(GMockVerboseFlagTest, Error) {
TEST_F(GMockVerboseFlagTest, InvalidFlagIsTreatedAsWarning) {
GMOCK_FLAG(verbose) = "invalid"; // Treated as "warning".
TestExpectedCall(false);
- TestUninterestingCall(true);
+ TestUninterestingCallOnNaggyMock(true);
}
#endif // GTEST_HAS_STREAM_REDIRECTION
diff --git a/test/gmock_output_test_.cc b/test/gmock_output_test_.cc
index c8e6b831..44cba342 100644
--- a/test/gmock_output_test_.cc
+++ b/test/gmock_output_test_.cc
@@ -43,6 +43,7 @@ using testing::_;
using testing::AnyNumber;
using testing::Ge;
using testing::InSequence;
+using testing::NaggyMock;
using testing::Ref;
using testing::Return;
using testing::Sequence;
@@ -61,7 +62,7 @@ class MockFoo {
class GMockOutputTest : public testing::Test {
protected:
- MockFoo foo_;
+ NaggyMock<MockFoo> foo_;
};
TEST_F(GMockOutputTest, ExpectedCall) {