Chromium Code Reviews| Index: net/der/parse_values_unittest.cc |
| diff --git a/net/der/parse_values_unittest.cc b/net/der/parse_values_unittest.cc |
| index ea1b5c4e8cca4e28bd85f533fe54b39f05577e50..d27ee0559b36fe4997d76d192e8cc37d1a867d92 100644 |
| --- a/net/der/parse_values_unittest.cc |
| +++ b/net/der/parse_values_unittest.cc |
| @@ -195,6 +195,60 @@ TEST(ParseValuesTest, ParseUint64) { |
| } |
| } |
| +// Tests parsing an empty BIT STRING. |
| +TEST(ParseValuesTest, ParseBitString_Empty_NoUnusedBits) { |
|
nharper
2015/07/21 23:23:47
Test names shouldn't contain underscores (accordin
eroman
2015/07/22 17:05:23
Ah, thanks for pointing this out! (I was not aware
|
| + const uint8_t kData[] = {0x00}; |
| + |
| + Input bytes; |
| + uint8_t unused_bits; |
| + ASSERT_TRUE(ParseBitString(Input(kData), &bytes, &unused_bits)); |
| + |
| + EXPECT_EQ(0u, unused_bits); |
| + EXPECT_EQ(0u, bytes.Length()); |
| +} |
| + |
| +// Tests parsing an empty BIT STRING that incorrectly claims one unused bit. |
| +TEST(ParseValuesTest, ParseBitString_Empty_OneUnusedBit) { |
| + const uint8_t kData[] = {0x01}; |
| + |
| + Input bytes; |
| + uint8_t unused_bits; |
| + ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); |
|
nharper
2015/07/21 23:23:47
I generally prefer the EXPECT_* macros to ASSERT_*
eroman
2015/07/22 17:05:23
Done.
These are the result of copy-paste from suc
|
| +} |
| + |
| +// Tests parsing an empty BIT STRING that is not minmally encoded (the entire |
| +// last byte is comprised of unused bits). |
| +TEST(ParseValuesTest, ParseBitString_NonEmpty_TooManyUnusedBits) { |
| + const uint8_t kData[] = {0x08, 0x00}; |
| + |
| + Input bytes; |
| + uint8_t unused_bits; |
| + ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); |
| +} |
| + |
| +// Tests parsing a BIT STRING of 7 bits each of which are 1. |
| +TEST(ParseValuesTest, ParseBitString_SevenOneBits) { |
| + const uint8_t kData[] = {0x01, 0xFE}; |
| + |
| + Input bytes; |
| + uint8_t unused_bits; |
| + ASSERT_TRUE(ParseBitString(Input(kData), &bytes, &unused_bits)); |
| + |
| + EXPECT_EQ(1u, unused_bits); |
| + EXPECT_EQ(1u, bytes.Length()); |
| + EXPECT_EQ(0xFE, bytes.UnsafeData()[0]); |
| +} |
| + |
| +// Tests parsing a BIT STRING of 7 bits each of which are 1. The unused bit |
| +// however is set to 1, which is an invalid encoding. |
| +TEST(ParseValuesTest, ParseBitString_SevenOneBits_UnusedBitIsOne) { |
| + const uint8_t kData[] = {0x01, 0xFF}; |
| + |
| + Input bytes; |
| + uint8_t unused_bits; |
| + ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); |
| +} |
| + |
| } // namespace test |
| } // namespace der |
| } // namespace net |