Loading cmds/incidentd/tests/Reporter_test.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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()); Loading libs/protoutil/include/android/util/ProtoOutputStream.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading libs/protoutil/src/ProtoOutputStream.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -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: Loading Loading
cmds/incidentd/tests/Reporter_test.cpp +8 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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()); Loading
libs/protoutil/include/android/util/ProtoOutputStream.h +2 −2 Original line number Diff line number Diff line Loading @@ -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. Loading
libs/protoutil/src/ProtoOutputStream.cpp +2 −3 Original line number Diff line number Diff line Loading @@ -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: Loading