diff options
author | Robert Phillips <robertphillips@google.com> | 2016-10-28 12:15:03 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-10-31 18:27:01 +0000 |
commit | 9e38047c56f8dff4440fe00002264be692440902 (patch) | |
tree | 828f65cd030f410a73707352aca6769184a855fa /tests/MathTest.cpp | |
parent | 0186661e85737ac2f4805f876c8d2d4157126f68 (diff) |
Add GrNextSizePow2
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4069
BUG=skia:5882
Change-Id: Ib9af5918716be594c3c07239eca179dbb4eb8566
Reviewed-on: https://skia-review.googlesource.com/4069
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r-- | tests/MathTest.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp index 41a4104bd4..35b4136b44 100644 --- a/tests/MathTest.cpp +++ b/tests/MathTest.cpp @@ -685,3 +685,41 @@ DEF_TEST(divmod_s32, r) { DEF_TEST(divmod_s64, r) { test_divmod<int64_t>(r); } + +static void test_nextsizepow2(skiatest::Reporter* r, size_t test, size_t expectedAns) { + size_t ans = GrNextSizePow2(test); + + REPORTER_ASSERT(r, ans == expectedAns); + //SkDebugf("0x%zx -> 0x%zx (0x%zx)\n", test, ans, expectedAns); +} + +DEF_TEST(GrNextSizePow2, reporter) { + constexpr int kNumSizeTBits = 8 * sizeof(size_t); + + size_t test = 0, expectedAns = 1; + + test_nextsizepow2(reporter, test, expectedAns); + + test = 1; expectedAns = 1; + + for (int i = 1; i < kNumSizeTBits; ++i) { + test_nextsizepow2(reporter, test, expectedAns); + + test++; + expectedAns <<= 1; + + test_nextsizepow2(reporter, test, expectedAns); + + test = expectedAns; + } + + // For the remaining three tests there is no higher power (of 2) + test = 0x1; + test <<= kNumSizeTBits-1; + test_nextsizepow2(reporter, test, test); + + test++; + test_nextsizepow2(reporter, test, test); + + test_nextsizepow2(reporter, SIZE_MAX, SIZE_MAX); +} |