Merge "Base: Hand complete log message to aborter"

This commit is contained in:
Treehugger Robot 2016-10-05 19:53:25 +00:00 committed by Gerrit Code Review
commit 0d762648d0
2 changed files with 26 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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'.
}