summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_memory_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-09-25 20:06:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-09-25 20:06:50 +0000
commit30dc6aaf878b2c55efcf7598fdb8886e06d14e01 (patch)
tree2de58de8c2eddd4efb5dc8a8c5b54cd3faad4972 /core/fxcrt/fx_memory_unittest.cpp
parent958142efa4561b5efd52733ad6c3b889cf49b3ae (diff)
downloadpdfium-30dc6aaf878b2c55efcf7598fdb8886e06d14e01.tar.xz
Add FxAlignToBoundary<>() template helper function.
Because I nearly botched this trivial calculation in the previous CL. Change-Id: I7438f9d3476d93b7899c2d7d761234769f53f9e3 Reviewed-on: https://pdfium-review.googlesource.com/43010 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_memory_unittest.cpp')
-rw-r--r--core/fxcrt/fx_memory_unittest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/fxcrt/fx_memory_unittest.cpp b/core/fxcrt/fx_memory_unittest.cpp
index 8c577835d6..eab11113cd 100644
--- a/core/fxcrt/fx_memory_unittest.cpp
+++ b/core/fxcrt/fx_memory_unittest.cpp
@@ -83,3 +83,26 @@ TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) {
EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc));
FXMEM_DefaultFree(ptr);
}
+
+TEST(fxcrt, FXAlign) {
+ static_assert(std::numeric_limits<size_t>::max() % 2 == 1,
+ "numeric limit must be odd for this test");
+
+ size_t s0 = 0;
+ size_t s1 = 1;
+ size_t s2 = 2;
+ size_t sbig = std::numeric_limits<size_t>::max() - 2;
+ EXPECT_EQ(0u, FxAlignToBoundary<2>(s0));
+ EXPECT_EQ(2u, FxAlignToBoundary<2>(s1));
+ EXPECT_EQ(2u, FxAlignToBoundary<2>(s2));
+ EXPECT_EQ(std::numeric_limits<size_t>::max() - 1, FxAlignToBoundary<2>(sbig));
+
+ int i0 = 0;
+ int i511 = 511;
+ int i512 = 512;
+ int ineg = -513;
+ EXPECT_EQ(0, FxAlignToBoundary<512>(i0));
+ EXPECT_EQ(512, FxAlignToBoundary<512>(i511));
+ EXPECT_EQ(512, FxAlignToBoundary<512>(i512));
+ EXPECT_EQ(-512, FxAlignToBoundary<512>(ineg));
+}