summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bitstream_unittest.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-23 23:41:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-23 23:41:00 +0000
commit7e33dbeec78dfa051df52619672133da6a799240 (patch)
treedbcd9f395ed0b89de890af24deae9fa1744fdd8e /core/fxcrt/cfx_bitstream_unittest.cpp
parent105ea1c0f896a4a2718f1356cae0dce8c01859cc (diff)
downloadpdfium-7e33dbeec78dfa051df52619672133da6a799240.tar.xz
Remove GetBits32().
Replace it with CFX_BitStream. Change-Id: Ib74657f888b8dec8b6fdad7b49e28d250991c590 Reviewed-on: https://pdfium-review.googlesource.com/32852 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bitstream_unittest.cpp')
-rw-r--r--core/fxcrt/cfx_bitstream_unittest.cpp21
1 files changed, 17 insertions, 4 deletions
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));
}
}
}