diff options
author | Elliott Hughes <enh@google.com> | 2018-05-23 09:16:46 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2018-05-23 10:06:20 -0700 |
commit | 1be0d1481b26281bf699238d5699b38a52b31382 (patch) | |
tree | abe0ba22d28d621564481ef56040e27534605a11 /base/logging_test.cpp | |
parent | 9f6f8bf0dcb7f08c8c0afc1685f5d1a54b41b4cb (diff) | |
download | system_core-1be0d1481b26281bf699238d5699b38a52b31382.tar.gz system_core-1be0d1481b26281bf699238d5699b38a52b31382.tar.bz2 system_core-1be0d1481b26281bf699238d5699b38a52b31382.zip |
Add StdioLogger for command-line tools.
Bug: N/A
Test: ran tests
Change-Id: If366a4ea25aea1becdd3e443eba225e9bd52ebba
Diffstat (limited to 'base/logging_test.cpp')
-rw-r--r-- | base/logging_test.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/base/logging_test.cpp b/base/logging_test.cpp index 5f689faf3..75b4ea045 100644 --- a/base/logging_test.cpp +++ b/base/logging_test.cpp @@ -206,11 +206,9 @@ static std::string make_log_pattern(android::base::LogSeverity severity, } #endif -static void CheckMessage(const CapturedStderr& cap, android::base::LogSeverity severity, +static void CheckMessage(CapturedStderr& cap, android::base::LogSeverity severity, const char* expected, const char* expected_tag = nullptr) { - std::string output; - ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_SET)); - android::base::ReadFdToString(cap.fd(), &output); + std::string output = cap.str(); // We can't usefully check the output of any of these on Windows because we // don't have std::regex, but we can at least make sure we printed at least as @@ -623,3 +621,23 @@ TEST(logging, SetDefaultTag) { } CheckMessage(cap, android::base::LogSeverity::INFO, expected_msg, expected_tag); } + +TEST(logging, StdioLogger) { + std::string err_str; + std::string out_str; + { + CapturedStderr cap_err; + CapturedStdout cap_out; + android::base::SetLogger(android::base::StdioLogger); + LOG(INFO) << "out"; + LOG(ERROR) << "err"; + err_str = cap_err.str(); + out_str = cap_out.str(); + } + + // For INFO we expect just the literal "out\n". + ASSERT_EQ("out\n", out_str) << out_str; + // Whereas ERROR logging includes the program name. + ASSERT_EQ(android::base::Basename(android::base::GetExecutablePath()) + ": err\n", err_str) + << err_str; +} |