Add 64-bit version of BitBuffer::ReadBits
Bug: webrtc:11933 Change-Id: Ie935192d2c81d7c24b83561711d59a7eff53db04 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/215966 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33997}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
bd09a46aa1
commit
39284360b0
@ -142,6 +142,38 @@ TEST(BitBufferTest, ReadBits) {
|
||||
EXPECT_FALSE(buffer.ReadBits(&val, 1));
|
||||
}
|
||||
|
||||
TEST(BitBufferTest, ReadBits64) {
|
||||
const uint8_t bytes[] = {0x4D, 0x32, 0xAB, 0x54, 0x00, 0xFF, 0xFE, 0x01,
|
||||
0xAB, 0xCD, 0xEF, 0x01, 0x23, 0x45, 0x67, 0x89};
|
||||
BitBuffer buffer(bytes, 16);
|
||||
uint64_t val;
|
||||
|
||||
// Peek and read first 33 bits.
|
||||
EXPECT_TRUE(buffer.PeekBits(&val, 33));
|
||||
EXPECT_EQ(0x4D32AB5400FFFE01ull >> (64 - 33), val);
|
||||
val = 0;
|
||||
EXPECT_TRUE(buffer.ReadBits(&val, 33));
|
||||
EXPECT_EQ(0x4D32AB5400FFFE01ull >> (64 - 33), val);
|
||||
|
||||
// Peek and read next 31 bits.
|
||||
constexpr uint64_t kMask31Bits = (1ull << 32) - 1;
|
||||
EXPECT_TRUE(buffer.PeekBits(&val, 31));
|
||||
EXPECT_EQ(0x4D32AB5400FFFE01ull & kMask31Bits, val);
|
||||
val = 0;
|
||||
EXPECT_TRUE(buffer.ReadBits(&val, 31));
|
||||
EXPECT_EQ(0x4D32AB5400FFFE01ull & kMask31Bits, val);
|
||||
|
||||
// Peek and read remaining 64 bits.
|
||||
EXPECT_TRUE(buffer.PeekBits(&val, 64));
|
||||
EXPECT_EQ(0xABCDEF0123456789ull, val);
|
||||
val = 0;
|
||||
EXPECT_TRUE(buffer.ReadBits(&val, 64));
|
||||
EXPECT_EQ(0xABCDEF0123456789ull, val);
|
||||
|
||||
// Nothing more to read.
|
||||
EXPECT_FALSE(buffer.ReadBits(&val, 1));
|
||||
}
|
||||
|
||||
TEST(BitBufferDeathTest, SetOffsetValues) {
|
||||
uint8_t bytes[4] = {0};
|
||||
BitBufferWriter buffer(bytes, 4);
|
||||
|
||||
Reference in New Issue
Block a user