SetAborter and SetLogger return old function.
This is very useful when implementing a log capture RAII class.
The class can reset the logger to whatever it was before on
destruction instead of assuming it was the default.
Test: atest --host libbase_test
Change-Id: I62127c84a1d275c7fb24b0d1aafd5fcbe4a19ec6
diff --git a/logging_test.cpp b/logging_test.cpp
index d8d0855..be2e042 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -619,6 +619,14 @@
EXPECT_EQ(CountLineAborter::newline_count, 1U);
}
+TEST(logging, SetAborterReturnsOldFunction) {
+ // std::function is not comparable, it only supports a null check.
+ android::base::AbortFunction old_aborter;
+ EXPECT_FALSE(old_aborter);
+ old_aborter = android::base::SetAborter(android::base::DefaultAborter);
+ EXPECT_TRUE(old_aborter);
+}
+
__attribute__((constructor)) void TestLoggingInConstructor() {
LOG(ERROR) << "foobar";
}
@@ -638,6 +646,14 @@
ASSERT_EQ(android::base::Basename(android::base::GetExecutablePath()) + ": err\n", cap_err.str());
}
+TEST(logging, SetLoggerReturnsOldFunction) {
+ // std::function is not comparable, it only supports a null check.
+ android::base::LogFunction old_function;
+ EXPECT_FALSE(old_function);
+ old_function = android::base::SetLogger(android::base::StdioLogger);
+ EXPECT_TRUE(old_function);
+}
+
TEST(logging, ForkSafe) {
#if !defined(_WIN32)
using namespace android::base;