diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-08-31 16:03:17 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-31 20:21:44 +0000 |
commit | 2a1c8ac53f249bfe2789ea95170f11d308992449 (patch) | |
tree | be3fae81a04ac8fdfc851bf2f9f25cf60967835d /core/fxcrt/fx_extension_unittest.cpp | |
parent | 203188ac4275f83cf984b8a807b07b74ab139236 (diff) | |
download | pdfium-2a1c8ac53f249bfe2789ea95170f11d308992449.tar.xz |
Move fx_extension implementation to cpp file
This CL moves the GetBits32 implemenation into fx_extension.cpp. It
also moves some of the fx_basic unittests to the correct unittest files.
Change-Id: I2cf8657c228375508db0f02baa628d62a3b2ab25
Reviewed-on: https://pdfium-review.googlesource.com/12673
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_extension_unittest.cpp')
-rw-r--r-- | core/fxcrt/fx_extension_unittest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/fxcrt/fx_extension_unittest.cpp b/core/fxcrt/fx_extension_unittest.cpp index 38b66ba2d2..0500a14b6f 100644 --- a/core/fxcrt/fx_extension_unittest.cpp +++ b/core/fxcrt/fx_extension_unittest.cpp @@ -5,6 +5,19 @@ #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, FXSYS_HexCharToInt) { EXPECT_EQ(10, FXSYS_HexCharToInt('a')); EXPECT_EQ(10, FXSYS_HexCharToInt('A')); @@ -89,3 +102,13 @@ TEST(fxcrt, FXSYS_ToUTF16BE) { EXPECT_EQ(8U, FXSYS_ToUTF16BE(0x2003E, buf)); EXPECT_STREQ("D840DC3E", buf); } + +TEST(fxcrt, GetBits32) { + unsigned char data[] = {0xDE, 0x3F, 0xB1, 0x7C, 0x12, 0x9A, 0x04, 0x56}; + for (int nbits = 1; nbits <= 32; ++nbits) { + for (int bitpos = 0; bitpos < (int)sizeof(data) * 8 - nbits; ++bitpos) { + EXPECT_EQ(ReferenceGetBits32(data, bitpos, nbits), + GetBits32(data, bitpos, nbits)); + } + } +} |