Index: net/der/parser_unittest.cc |
diff --git a/net/der/parser_unittest.cc b/net/der/parser_unittest.cc |
index 1943d6b86ebeb8fa79e1aa5df8147152e30d1681..5bf16216d2e421d69ad57687539137b744c3055f 100644 |
--- a/net/der/parser_unittest.cc |
+++ b/net/der/parser_unittest.cc |
@@ -196,6 +196,39 @@ TEST(ParserTest, CannotAdvanceAfterReadOptionalTag) { |
ASSERT_FALSE(parser.Advance()); |
} |
+TEST(ParserTest, ReadBitString) { |
+ const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE}; |
+ Parser parser((Input(der))); |
davidben
2015/07/27 20:19:59
[I'm assuming the extra parens here are coming fro
eroman
2015/07/27 21:19:23
Correct.
I need those parenthesis to avoid a compi
|
+ |
+ Input bytes; |
+ uint8_t unused_bits; |
+ ASSERT_TRUE(parser.ReadBitString(&bytes, &unused_bits)); |
+ EXPECT_FALSE(parser.HasMore()); |
+ |
+ EXPECT_EQ(1u, unused_bits); |
+ ASSERT_EQ(2u, bytes.Length()); |
+ EXPECT_EQ(0xAA, bytes.UnsafeData()[0]); |
+ EXPECT_EQ(0xBE, bytes.UnsafeData()[1]); |
+} |
+ |
+TEST(ParserTest, ReadBitString_BadTag) { |
+ const uint8_t der[] = {0x05, 0x03, 0x01, 0xAA, 0xBE}; |
+ Parser parser((Input(der))); |
+ |
+ Input bytes; |
+ uint8_t unused_bits; |
+ EXPECT_FALSE(parser.ReadBitString(&bytes, &unused_bits)); |
+} |
+ |
+// Reads a BIT STRING with one unused bit -- should fail. |
+TEST(ParserTest, ReadBitStringNoUnusedBits) { |
+ const uint8_t der[] = {0x03, 0x03, 0x01, 0xAA, 0xBE}; |
+ Parser parser((Input(der))); |
+ |
+ Input bytes; |
+ EXPECT_FALSE(parser.ReadBitStringNoUnusedBits(&bytes)); |
davidben
2015/07/27 20:19:59
I dunno if you want a success test for NoUnusedBit
eroman
2015/07/27 21:19:23
Done.
I also improved the test descriptions.
|
+} |
+ |
} // namespace test |
} // namespace der |
} // namespace net |