Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12fe72b7 authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Update for modified CapturedStderr.

Also fix off by one error exposed by changing the test.

Test: Built and ran unit tests.
Change-Id: Id983b8301fe33c21bfe1db1e67ef00681f852557
parent a6aa0e79
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
                }
+10 −17
Original line number Diff line number Diff line
@@ -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) {