aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock-spec-builders_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/test/gmock-spec-builders_test.cc')
-rw-r--r--googlemock/test/gmock-spec-builders_test.cc69
1 files changed, 63 insertions, 6 deletions
diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc
index 59ea87c8..c649bfd9 100644
--- a/googlemock/test/gmock-spec-builders_test.cc
+++ b/googlemock/test/gmock-spec-builders_test.cc
@@ -93,11 +93,13 @@ using testing::Sequence;
using testing::SetArgPointee;
using testing::internal::ExpectationTester;
using testing::internal::FormatFileLocation;
+using testing::internal::kAllow;
using testing::internal::kErrorVerbosity;
+using testing::internal::kFail;
using testing::internal::kInfoVerbosity;
+using testing::internal::kWarn;
using testing::internal::kWarningVerbosity;
using testing::internal::linked_ptr;
-using testing::internal::string;
#if GTEST_HAS_STREAM_REDIRECTION
using testing::HasSubstr;
@@ -692,6 +694,61 @@ TEST(ExpectCallSyntaxTest, WarnsOnTooFewActions) {
b.DoB();
}
+TEST(ExpectCallSyntaxTest, WarningIsErrorWithFlag) {
+ int original_behavior = testing::GMOCK_FLAG(default_mock_behavior);
+
+ testing::GMOCK_FLAG(default_mock_behavior) = kAllow;
+ CaptureStdout();
+ {
+ MockA a;
+ a.DoA(0);
+ }
+ std::string output = GetCapturedStdout();
+ EXPECT_TRUE(output.empty()) << output;
+
+ testing::GMOCK_FLAG(default_mock_behavior) = kWarn;
+ CaptureStdout();
+ {
+ MockA a;
+ a.DoA(0);
+ }
+ std::string warning_output = GetCapturedStdout();
+ EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
+ EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
+ warning_output);
+
+ testing::GMOCK_FLAG(default_mock_behavior) = kFail;
+ EXPECT_NONFATAL_FAILURE({
+ MockA a;
+ a.DoA(0);
+ }, "Uninteresting mock function call");
+
+ // Out of bounds values are converted to kWarn
+ testing::GMOCK_FLAG(default_mock_behavior) = -1;
+ CaptureStdout();
+ {
+ MockA a;
+ a.DoA(0);
+ }
+ warning_output = GetCapturedStdout();
+ EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
+ EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
+ warning_output);
+ testing::GMOCK_FLAG(default_mock_behavior) = 3;
+ CaptureStdout();
+ {
+ MockA a;
+ a.DoA(0);
+ }
+ warning_output = GetCapturedStdout();
+ EXPECT_PRED_FORMAT2(IsSubstring, "GMOCK WARNING", warning_output);
+ EXPECT_PRED_FORMAT2(IsSubstring, "Uninteresting mock function call",
+ warning_output);
+
+ testing::GMOCK_FLAG(default_mock_behavior) = original_behavior;
+}
+
+
#endif // GTEST_HAS_STREAM_REDIRECTION
// Tests the semantics of ON_CALL().
@@ -1954,7 +2011,7 @@ class MockC {
public:
MockC() {}
- MOCK_METHOD6(VoidMethod, void(bool cond, int n, string s, void* p,
+ MOCK_METHOD6(VoidMethod, void(bool cond, int n, std::string s, void* p,
const Printable& x, Unprintable y));
MOCK_METHOD0(NonVoidMethod, int()); // NOLINT
@@ -1970,7 +2027,7 @@ class VerboseFlagPreservingFixture : public testing::Test {
~VerboseFlagPreservingFixture() { GMOCK_FLAG(verbose) = saved_verbose_flag_; }
private:
- const string saved_verbose_flag_;
+ const std::string saved_verbose_flag_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(VerboseFlagPreservingFixture);
};
@@ -2062,8 +2119,8 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// contain the given function name in the stack trace. When it's
// false, the output should be empty.)
void VerifyOutput(const std::string& output, bool should_print,
- const string& expected_substring,
- const string& function_name) {
+ const std::string& expected_substring,
+ const std::string& function_name) {
if (should_print) {
EXPECT_THAT(output.c_str(), HasSubstr(expected_substring));
# ifndef NDEBUG
@@ -2113,7 +2170,7 @@ class GMockVerboseFlagTest : public VerboseFlagPreservingFixture {
// Tests how the flag affects uninteresting calls on a naggy mock.
void TestUninterestingCallOnNaggyMock(bool should_print) {
NaggyMock<MockA> a;
- const string note =
+ const std::string note =
"NOTE: You can safely ignore the above warning unless this "
"call should not happen. Do not suppress it by blindly adding "
"an EXPECT_CALL() if you don't mean to enforce the call. "