From 7e33dbeec78dfa051df52619672133da6a799240 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 23 May 2018 23:41:00 +0000 Subject: Remove GetBits32(). Replace it with CFX_BitStream. Change-Id: Ib74657f888b8dec8b6fdad7b49e28d250991c590 Reviewed-on: https://pdfium-review.googlesource.com/32852 Commit-Queue: Lei Zhang Reviewed-by: dsinclair --- core/fxcrt/cfx_bitstream_unittest.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'core/fxcrt/cfx_bitstream_unittest.cpp') diff --git a/core/fxcrt/cfx_bitstream_unittest.cpp b/core/fxcrt/cfx_bitstream_unittest.cpp index 991cd43147..e70455bc67 100644 --- a/core/fxcrt/cfx_bitstream_unittest.cpp +++ b/core/fxcrt/cfx_bitstream_unittest.cpp @@ -3,9 +3,21 @@ // found in the LICENSE file. #include "core/fxcrt/cfx_bitstream.h" -#include "core/fxcrt/fx_extension.h" #include "testing/gtest/include/gtest/gtest.h" +namespace { + +uint32_t ReferenceGetBits32(const uint8_t* pData, int bitpos, int nbits) { + int result = 0; + for (int i = 0; i < nbits; i++) { + if (pData[(bitpos + i) / 8] & (1 << (7 - (bitpos + i) % 8))) + result |= 1 << (nbits - i - 1); + } + return result; +} + +} // namespace + TEST(fxcrt, BitStream) { static const uint8_t kData[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; @@ -106,14 +118,15 @@ TEST(fxcrt, BitStream) { EXPECT_EQ(0U, bitstream.BitsRemaining()); } -TEST(fxcrt, BitStreamSameAsGetBit32) { +TEST(fxcrt, BitStreamSameAsReferenceGetBits32) { unsigned char kData[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56}; CFX_BitStream bitstream(kData); - for (uint32_t nbits = 1; nbits <= 32; ++nbits) { + for (int nbits = 1; nbits <= 32; ++nbits) { for (size_t bitpos = 0; bitpos < sizeof(kData) * 8 - nbits; ++bitpos) { bitstream.Rewind(); bitstream.SkipBits(bitpos); - EXPECT_EQ(bitstream.GetBits(nbits), GetBits32(kData, bitpos, nbits)); + EXPECT_EQ(bitstream.GetBits(nbits), + ReferenceGetBits32(kData, bitpos, nbits)); } } } -- cgit v1.2.3