summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/logging.cpp2
-rw-r--r--base/logging_test.cpp24
2 files changed, 26 insertions, 0 deletions
diff --git a/base/logging.cpp b/base/logging.cpp
index ece10ecdd..dab86fe89 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -415,6 +415,8 @@ LogMessage::~LogMessage() {
msg[nl] = '\0';
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(),
data_->GetSeverity(), &msg[i]);
+ // Undo the zero-termination so we can give the complete message to the aborter.
+ msg[nl] = '\n';
i = nl + 1;
}
}
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index 9fc77368f..1ee181a42 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -606,3 +606,27 @@ TEST(logging, LOG_FATAL_NOOP_ABORTER) {
ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar");
}
+
+struct CountLineAborter {
+ static void CountLineAborterFunction(const char* msg) {
+ while (*msg != 0) {
+ if (*msg == '\n') {
+ newline_count++;
+ }
+ msg++;
+ }
+ }
+ static size_t newline_count;
+};
+size_t CountLineAborter::newline_count = 0;
+
+TEST(logging, LOG_FATAL_ABORTER_MESSAGE) {
+ CountLineAborter::newline_count = 0;
+ android::base::SetAborter(CountLineAborter::CountLineAborterFunction);
+
+ android::base::ScopedLogSeverity sls(android::base::ERROR);
+ CapturedStderr cap;
+ LOG(FATAL) << "foo\nbar";
+
+ EXPECT_EQ(CountLineAborter::newline_count, 1U + 1U); // +1 for final '\n'.
+}