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

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

Add tests to cover handling negative varint.

The gtest will fail if the fix of b/77291057 isn't there. Should make
this change in with the fix, but later than none.

Bug: 77291057
Test: atest incidentd_test
Change-Id: I48ece311f78ee18d97486839a3b8b434c9419cf3
parent f6fb0fc0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ 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;
const std::string NEGATIVE_VARINT_FIELD_6 = "\x30\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01";  // -1

class PrivacyBufferTest : public Test {
public:
@@ -161,6 +162,11 @@ TEST_F(PrivacyBufferTest, StripLengthDelimitedField_Message) {
    assertStripByFields(DEST_EXPLICIT, "", 1, create_privacy(5, MESSAGE_TYPE, DEST_LOCAL));
}

TEST_F(PrivacyBufferTest, StripNegativeVarint) {
    writeToFdBuffer(NEGATIVE_VARINT_FIELD_6);
    assertStripByFields(DEST_EXPLICIT, "", 1, create_privacy(6, OTHER_TYPE, DEST_LOCAL));
}

TEST_F(PrivacyBufferTest, NoStripVarintField) {
    writeToFdBuffer(VARINT_FIELD_1);
    assertStripByFields(DEST_EXPLICIT, VARINT_FIELD_1, 1,
@@ -191,6 +197,12 @@ TEST_F(PrivacyBufferTest, NoStripLengthDelimitedField_Message) {
                        create_privacy(5, MESSAGE_TYPE, DEST_AUTOMATIC));
}

TEST_F(PrivacyBufferTest, NoStripNegativeVarintField) {
    writeToFdBuffer(NEGATIVE_VARINT_FIELD_6);
    assertStripByFields(DEST_EXPLICIT, NEGATIVE_VARINT_FIELD_6, 1,
                        create_privacy(6, OTHER_TYPE, DEST_AUTOMATIC));
}

TEST_F(PrivacyBufferTest, StripVarintAndString) {
    writeToFdBuffer(STRING_FIELD_0 + VARINT_FIELD_1 + STRING_FIELD_2 + FIX64_FIELD_3 +
                    FIX32_FIELD_4);