Use modern c++ code style for incidentd.
This cl does not contain code logic changes.
Bug: 77333635
Test: manual and incidentd_test
Change-Id: Iea0a402b1051defd45159ca267e6dd705f9ffa49
diff --git a/cmds/incidentd/tests/FdBuffer_test.cpp b/cmds/incidentd/tests/FdBuffer_test.cpp
index 7a05d7e..9d208df 100644
--- a/cmds/incidentd/tests/FdBuffer_test.cpp
+++ b/cmds/incidentd/tests/FdBuffer_test.cpp
@@ -24,15 +24,16 @@
#include <signal.h>
#include <string.h>
+using namespace android;
+using namespace android::base;
+using namespace android::os::incidentd;
+using ::testing::Test;
+
const int READ_TIMEOUT = 5 * 1000;
const int BUFFER_SIZE = 16 * 1024;
const int QUICK_TIMEOUT_MS = 100;
const std::string HEAD = "[OK]";
-using namespace android;
-using namespace android::base;
-using ::testing::Test;
-
class FdBufferTest : public Test {
public:
virtual void SetUp() override {
diff --git a/cmds/incidentd/tests/PrivacyBuffer_test.cpp b/cmds/incidentd/tests/PrivacyBuffer_test.cpp
index 10c2981..685759f 100644
--- a/cmds/incidentd/tests/PrivacyBuffer_test.cpp
+++ b/cmds/incidentd/tests/PrivacyBuffer_test.cpp
@@ -27,7 +27,7 @@
using namespace android;
using namespace android::base;
using namespace android::os;
-using namespace std;
+using namespace android::os::incidentd;
using ::testing::StrEq;
using ::testing::Test;
using ::testing::internal::CaptureStdout;
@@ -36,12 +36,12 @@
const uint8_t OTHER_TYPE = 1;
const uint8_t STRING_TYPE = 9;
const uint8_t MESSAGE_TYPE = 11;
-const string STRING_FIELD_0 = "\x02\viamtestdata";
-const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
-const string STRING_FIELD_2 = "\x12\vandroidwins";
-const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
-const string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
-const string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
+const std::string STRING_FIELD_0 = "\x02\viamtestdata";
+const std::string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
+const std::string STRING_FIELD_2 = "\x12\vandroidwins";
+const std::string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
+const std::string FIX32_FIELD_4 = "\x25\xff\xff\xff\xff"; // -1
+const std::string MESSAGE_FIELD_5 = "\x2a\x10" + VARINT_FIELD_1 + STRING_FIELD_2;
class PrivacyBufferTest : public Test {
public:
@@ -56,20 +56,20 @@
virtual void SetUp() override { ASSERT_NE(tf.fd, -1); }
- void writeToFdBuffer(string str) {
+ void writeToFdBuffer(std::string str) {
ASSERT_TRUE(WriteStringToFile(str, tf.path));
ASSERT_EQ(NO_ERROR, buffer.read(tf.fd, 10000));
ASSERT_EQ(str.size(), buffer.size());
}
- void assertBuffer(PrivacyBuffer& buf, string expected) {
+ void assertBuffer(PrivacyBuffer& buf, std::string expected) {
ASSERT_EQ(buf.size(), expected.size());
CaptureStdout();
ASSERT_EQ(buf.flush(STDOUT_FILENO), NO_ERROR);
ASSERT_THAT(GetCapturedStdout(), StrEq(expected));
}
- void assertStrip(uint8_t dest, string expected, Privacy* policy) {
+ void assertStrip(uint8_t dest, std::string expected, Privacy* policy) {
PrivacySpec spec = PrivacySpec::new_spec(dest);
EncodedBuffer::iterator bufData = buffer.data();
PrivacyBuffer privacyBuf(policy, bufData);
@@ -77,7 +77,7 @@
assertBuffer(privacyBuf, expected);
}
- void assertStripByFields(uint8_t dest, string expected, int size, Privacy* privacy, ...) {
+ void assertStripByFields(uint8_t dest, std::string expected, int size, Privacy* privacy, ...) {
Privacy* list[size + 1];
list[0] = privacy;
va_list args;
@@ -194,7 +194,7 @@
TEST_F(PrivacyBufferTest, StripVarintAndString) {
writeToFdBuffer(STRING_FIELD_0 + VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3 +
FIX32_FIELD_4);
- string expected = STRING_FIELD_0 + FIX64_FIELD_3 + FIX32_FIELD_4;
+ std::string expected = STRING_FIELD_0 + FIX64_FIELD_3 + FIX32_FIELD_4;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(1, OTHER_TYPE, DEST_LOCAL),
create_privacy(2, STRING_TYPE, DEST_LOCAL));
}
@@ -202,7 +202,7 @@
TEST_F(PrivacyBufferTest, StripVarintAndFixed64) {
writeToFdBuffer(STRING_FIELD_0 + VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3 +
FIX32_FIELD_4);
- string expected = STRING_FIELD_0 + STRING_FIELD_2 + FIX32_FIELD_4;
+ std::string expected = STRING_FIELD_0 + STRING_FIELD_2 + FIX32_FIELD_4;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(1, OTHER_TYPE, DEST_LOCAL),
create_privacy(3, OTHER_TYPE, DEST_LOCAL));
}
@@ -210,14 +210,14 @@
TEST_F(PrivacyBufferTest, StripVarintInNestedMessage) {
writeToFdBuffer(STRING_FIELD_0 + MESSAGE_FIELD_5);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
- string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_EXPLICIT, expected, 1, create_message_privacy(5, list));
}
TEST_F(PrivacyBufferTest, StripFix64AndVarintInNestedMessage) {
writeToFdBuffer(STRING_FIELD_0 + FIX64_FIELD_3 + MESSAGE_FIELD_5);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
- string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = STRING_FIELD_0 + "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_EXPLICIT, expected, 2, create_privacy(3, OTHER_TYPE, DEST_LOCAL),
create_message_privacy(5, list));
}
@@ -262,7 +262,7 @@
Privacy* field5 = create_message_privacy(5, NULL);
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), field5, NULL};
field5->children = list;
- string expected = "\x2a\x1c" + STRING_FIELD_2 + "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = "\x2a\x1c" + STRING_FIELD_2 + "\x2a\xd" + STRING_FIELD_2;
assertStrip(DEST_EXPLICIT, expected, field5);
}
@@ -271,6 +271,6 @@
Privacy* list[] = {create_privacy(1, OTHER_TYPE, DEST_LOCAL), NULL};
Privacy* autoMsg = create_privacy(5, MESSAGE_TYPE, DEST_AUTOMATIC);
autoMsg->children = list;
- string expected = "\x2a\xd" + STRING_FIELD_2;
+ std::string expected = "\x2a\xd" + STRING_FIELD_2;
assertStripByFields(DEST_AUTOMATIC, expected, 1, autoMsg);
}
diff --git a/cmds/incidentd/tests/Reporter_test.cpp b/cmds/incidentd/tests/Reporter_test.cpp
index 42d94f0..cf107c8 100644
--- a/cmds/incidentd/tests/Reporter_test.cpp
+++ b/cmds/incidentd/tests/Reporter_test.cpp
@@ -30,6 +30,7 @@
using namespace android::base;
using namespace android::binder;
using namespace android::os;
+using namespace android::os::incidentd;
using namespace std;
using ::testing::StrEq;
using ::testing::Test;
diff --git a/cmds/incidentd/tests/Section_test.cpp b/cmds/incidentd/tests/Section_test.cpp
index 2f6698b..9f92353 100644
--- a/cmds/incidentd/tests/Section_test.cpp
+++ b/cmds/incidentd/tests/Section_test.cpp
@@ -25,25 +25,26 @@
#include <gtest/gtest.h>
#include <string.h>
+using namespace android;
+using namespace android::base;
+using namespace android::binder;
+using namespace android::os;
+using namespace android::os::incidentd;
+using namespace android::util;
+using ::testing::StrEq;
+using ::testing::Test;
+using ::testing::internal::CaptureStdout;
+using ::testing::internal::GetCapturedStdout;
+
const int TIMEOUT_PARSER = -1;
const int NOOP_PARSER = 0;
const int REVERSE_PARSER = 1;
const int QUICK_TIMEOUT_MS = 100;
-const string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
-const string STRING_FIELD_2 = "\x12\vandroidwins";
-const string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
-
-using namespace android::base;
-using namespace android::binder;
-using namespace android::os;
-using namespace android::util;
-using namespace std;
-using ::testing::StrEq;
-using ::testing::Test;
-using ::testing::internal::CaptureStdout;
-using ::testing::internal::GetCapturedStdout;
+const std::string VARINT_FIELD_1 = "\x08\x96\x01"; // 150
+const std::string STRING_FIELD_2 = "\x12\vandroidwins";
+const std::string FIX64_FIELD_3 = "\x19\xff\xff\xff\xff\xff\xff\xff\xff"; // -1
// NOTICE: this test requires /system/bin/incident_helper is installed.
class SectionTest : public Test {
@@ -101,7 +102,7 @@
requests.add(new ReportRequest(args2, new SimpleListener(), tf.fd));
requests.setMainFd(STDOUT_FILENO);
- string content;
+ std::string content;
CaptureStdout();
ASSERT_EQ(NO_ERROR, hs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\n\x5"
@@ -163,9 +164,9 @@
size_t fileLen = testFile.size();
size_t totalLen = 1 + get_varint_size(fileLen) + fileLen + 3 + gzFile.size();
uint8_t header[20];
- header[0] = '\x2'; // header 0 << 3 + 2
+ header[0] = '\x2'; // header 0 << 3 + 2
uint8_t* ptr = write_raw_varint(header + 1, totalLen);
- *ptr = '\n'; // header 1 << 3 + 2
+ *ptr = '\n'; // header 1 << 3 + 2
ptr = write_raw_varint(++ptr, fileLen);
expected.assign((const char*)header, ptr - header);
expected += testFile + "\x12\x9F\x6" + gzFile;
@@ -227,7 +228,7 @@
requests.setMainFd(STDOUT_FILENO);
CaptureStdout();
ASSERT_EQ(NO_ERROR, ls.Execute(&requests));
- string results = GetCapturedStdout();
+ std::string results = GetCapturedStdout();
EXPECT_FALSE(results.empty());
}
@@ -236,7 +237,7 @@
requests.setMainFd(STDOUT_FILENO);
CaptureStdout();
ASSERT_EQ(NO_ERROR, ls.Execute(&requests));
- string results = GetCapturedStdout();
+ std::string results = GetCapturedStdout();
EXPECT_FALSE(results.empty());
}
@@ -304,7 +305,7 @@
ASSERT_EQ(NO_ERROR, fs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\x02\r" + STRING_FIELD_2));
- string content, expect;
+ std::string content, expect;
expect = VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3;
char c = (char)expect.size();
EXPECT_TRUE(ReadFileToString(output1.path, &content));
@@ -346,7 +347,7 @@
ASSERT_EQ(NO_ERROR, fs.Execute(&requests));
EXPECT_THAT(GetCapturedStdout(), StrEq("\x02\r" + STRING_FIELD_2));
- string content, expect;
+ std::string content, expect;
expect = STRING_FIELD_2 + FIX64_FIELD_3;
char c = (char)expect.size();
diff --git a/cmds/incidentd/tests/Throttler_test.cpp b/cmds/incidentd/tests/Throttler_test.cpp
index 213dcef..8488c99 100644
--- a/cmds/incidentd/tests/Throttler_test.cpp
+++ b/cmds/incidentd/tests/Throttler_test.cpp
@@ -20,6 +20,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+using namespace android::os::incidentd;
+
TEST(ThrottlerTest, DataSizeExceeded) {
Throttler t(100, 100000);
EXPECT_FALSE(t.shouldThrottle());
diff --git a/cmds/incidentd/tests/section_list.cpp b/cmds/incidentd/tests/section_list.cpp
index bd2d15c..1d7f2b6 100644
--- a/cmds/incidentd/tests/section_list.cpp
+++ b/cmds/incidentd/tests/section_list.cpp
@@ -1,6 +1,10 @@
// This file is a dummy section_list.cpp used for test only.
#include "section_list.h"
+namespace android {
+namespace os {
+namespace incidentd {
+
const Section* SECTION_LIST[] = {NULL};
Privacy sub_field_1{1, 1, NULL, DEST_LOCAL, NULL};
@@ -16,3 +20,7 @@
const Privacy** PRIVACY_POLICY_LIST = const_cast<const Privacy**>(final_list);
const int PRIVACY_POLICY_COUNT = 2;
+
+} // namespace incidentd
+} // namespace os
+} // namespace android
\ No newline at end of file