From ba7ee6ff11de405bf271c9c2f653e6a6c96c4607 Mon Sep 17 00:00:00 2001 From: Yi Jin Date: Wed, 11 Apr 2018 16:11:05 -0700 Subject: [PATCH] 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 --- cmds/incidentd/tests/PrivacyBuffer_test.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmds/incidentd/tests/PrivacyBuffer_test.cpp b/cmds/incidentd/tests/PrivacyBuffer_test.cpp index 685759ffcf39c..871226b7a6a9d 100644 --- a/cmds/incidentd/tests/PrivacyBuffer_test.cpp +++ b/cmds/incidentd/tests/PrivacyBuffer_test.cpp @@ -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);