diff options
author | 2018-08-31 14:13:51 -0700 | |
---|---|---|
committer | 2018-09-04 14:56:24 -0700 | |
commit | 12fe72b7579d9857f97c6cbf8b771e0c2c6d7715 (patch) | |
tree | 686b2f5088809e6de74fd090e99fd8e36b39068f | |
parent | a6aa0e7959f170f6a2e85d895ddf6330905f8e77 (diff) |
Update for modified CapturedStderr.
Also fix off by one error exposed by changing the test.
Test: Built and ran unit tests.
Change-Id: Id983b8301fe33c21bfe1db1e67ef00681f852557
-rw-r--r-- | libs/binder/BufferedTextOutput.cpp | 2 | ||||
-rw-r--r-- | libs/binder/tests/binderTextOutputTest.cpp | 27 |
2 files changed, 11 insertions, 18 deletions
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp index d516eb1d54..857bbf9510 100644 --- a/libs/binder/BufferedTextOutput.cpp +++ b/libs/binder/BufferedTextOutput.cpp @@ -189,7 +189,7 @@ status_t BufferedTextOutput::print(const char* txt, size_t len) // them out without going through the buffer. // Slurp up all of the lines. - const char* lastLine = txt+1; + const char* lastLine = txt; while (txt < end) { if (*txt++ == '\n') lastLine = txt; } diff --git a/libs/binder/tests/binderTextOutputTest.cpp b/libs/binder/tests/binderTextOutputTest.cpp index f6dd22d798..ce99f59d7c 100644 --- a/libs/binder/tests/binderTextOutputTest.cpp +++ b/libs/binder/tests/binderTextOutputTest.cpp @@ -28,15 +28,14 @@ #include <binder/TextOutput.h> #include <binder/Debug.h> -static void CheckMessage(const CapturedStderr& cap, +static void CheckMessage(CapturedStderr& cap, const char* expected, bool singleline) { - std::string output; - ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_SET)); - android::base::ReadFdToString(cap.fd(), &output); + cap.Stop(); + std::string output = cap.str(); if (singleline) output.erase(std::remove(output.begin(), output.end(), '\n')); - ASSERT_STREQ(output.c_str(), expected); + ASSERT_EQ(output, expected); } #define CHECK_LOG_(input, expect, singleline) \ @@ -60,28 +59,22 @@ static void CheckMessage(const CapturedStderr& cap, TEST(TextOutput, HandlesStdEndl) { CapturedStderr cap; android::aerr << "foobar" << std::endl; - std::string output; - ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_SET)); - android::base::ReadFdToString(cap.fd(), &output); - ASSERT_STREQ(output.c_str(), "foobar\n"); + cap.Stop(); + ASSERT_EQ(cap.str(), "foobar\n"); } TEST(TextOutput, HandlesCEndl) { CapturedStderr cap; android::aerr << "foobar" << "\n"; - std::string output; - ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_SET)); - android::base::ReadFdToString(cap.fd(), &output); - ASSERT_STREQ(output.c_str(), "foobar\n"); + cap.Stop(); + ASSERT_EQ(cap.str(), "foobar\n"); } TEST(TextOutput, HandlesAndroidEndl) { CapturedStderr cap; android::aerr << "foobar" << android::endl; - std::string output; - ASSERT_EQ(0, lseek(cap.fd(), 0, SEEK_SET)); - android::base::ReadFdToString(cap.fd(), &output); - ASSERT_STREQ(output.c_str(), "foobar\n"); + cap.Stop(); + ASSERT_EQ(cap.str(), "foobar\n"); } TEST(TextOutput, HandleEmptyString) { |