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

Commit e0833306 authored by Yi Jin's avatar Yi Jin
Browse files

Fix several nits

1. Change the APIs of ProtoOutputStream to be able to write bytes
2. Fix the tests in incidentd, stdout is closed so can't capture the
value, use temporaryFile instead.

Test: N/A
Change-Id: Ibc31f2efd068afc6c06188d92f57ca5a754c3683
parent c35ca6de
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ using namespace android::binder;
using namespace std;
using ::testing::StrEq;
using ::testing::Test;
using ::testing::internal::CaptureStdout;
using ::testing::internal::GetCapturedStdout;

class TestListener : public IIncidentReportStatusListener
{
@@ -139,20 +137,24 @@ TEST_F(ReporterTest, RunReportEmpty) {
}

TEST_F(ReporterTest, RunReportWithHeaders) {
    TemporaryFile tf;
    IncidentReportArgs args1, args2;
    args1.addSection(1);
    args2.addSection(2);
    std::vector<int8_t> header {'a', 'b', 'c', 'd', 'e'};
    args2.addHeader(header);
    sp<ReportRequest> r1 = new ReportRequest(args1, l, STDOUT_FILENO);
    sp<ReportRequest> r2 = new ReportRequest(args2, l, STDOUT_FILENO);
    sp<ReportRequest> r1 = new ReportRequest(args1, l, tf.fd);
    sp<ReportRequest> r2 = new ReportRequest(args2, l, tf.fd);

    reporter->batch.add(r1);
    reporter->batch.add(r2);

    CaptureStdout();
    ASSERT_EQ(Reporter::REPORT_FINISHED, reporter->runReport());
    EXPECT_THAT(GetCapturedStdout(), StrEq("\n\x5" "abcde"));

    string result;
    ReadFileToString(tf.path, &result);
    EXPECT_THAT(result, StrEq("\n\x5" "abcde"));

    EXPECT_EQ(l->startInvoked, 2);
    EXPECT_EQ(l->finishInvoked, 2);
    EXPECT_TRUE(l->startSections.empty());
+2 −2
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ public:
    bool write(uint64_t fieldId, long long val);
    bool write(uint64_t fieldId, bool val);
    bool write(uint64_t fieldId, std::string val);
    bool write(uint64_t fieldId, const char* val);
    bool write(uint64_t fieldId, const char* val, size_t size);

    /**
     * Starts a sub-message write session.
+2 −3
Original line number Diff line number Diff line
@@ -225,14 +225,13 @@ ProtoOutputStream::write(uint64_t fieldId, string val)
}

bool
ProtoOutputStream::write(uint64_t fieldId, const char* val)
ProtoOutputStream::write(uint64_t fieldId, const char* val, size_t size)
{
    if (mCompact) return false;
    const uint32_t id = (uint32_t)fieldId;
    int size = 0;
    while (val[size] != '\0') size++;
    switch (fieldId & FIELD_TYPE_MASK) {
        case TYPE_STRING:
        case TYPE_BYTES:
            writeUtf8StringImpl(id, val, size);
            return true;
        default: