diff options
author | Harald Musum <musum@yahooinc.com> | 2022-02-17 13:27:33 +0000 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-02-17 13:27:33 +0000 |
commit | b6253857ebe51ffd7fa26e4ab173c647a3ddaeb2 (patch) | |
tree | 8955d1d279e88636c2a7ee317d7b73be88c3da40 /vespalib | |
parent | be3f2a6a448d9507b0bdde5c71cf6aab7d16ff40 (diff) |
Changes after review feedback
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/array/array_test.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/vespalib/src/tests/array/array_test.cpp b/vespalib/src/tests/array/array_test.cpp index d9519d3df87..511c5ae11f1 100644 --- a/vespalib/src/tests/array/array_test.cpp +++ b/vespalib/src/tests/array/array_test.cpp @@ -331,29 +331,33 @@ TEST("test move assignment") struct UnreserveFixture { Array<int> arr; - UnreserveFixture() : arr(1025, 7, alloc::Alloc::allocMMap(0)) + UnreserveFixture() : arr(page_ints() + 1, 7, alloc::Alloc::allocMMap(0)) { - EXPECT_EQUAL(1025u, arr.size()); - EXPECT_EQUAL(round_up_to_page_size(1) == 64_Ki ? 16_Ki : 2_Ki, arr.capacity()); + EXPECT_EQUAL(page_ints() + 1, arr.size()); + EXPECT_EQUAL(2 * page_ints(), arr.capacity()); + } + + static size_t page_ints() { + return round_up_to_page_size(1) / sizeof(int); } }; TEST_F("require that try_unreserve() fails if wanted capacity >= current capacity", UnreserveFixture) { - EXPECT_FALSE(f.arr.try_unreserve(32_Ki)); + EXPECT_FALSE(f.arr.try_unreserve(2 * UnreserveFixture::page_ints())); } TEST_F("require that try_unreserve() fails if wanted capacity < current size", UnreserveFixture) { - EXPECT_FALSE(f.arr.try_unreserve(1_Ki)); + EXPECT_FALSE(f.arr.try_unreserve(UnreserveFixture::page_ints())); } TEST_F("require that try_unreserve() succeedes if mmap can be shrinked", UnreserveFixture) { int *oldPtr = &f.arr[0]; f.arr.resize(512); - EXPECT_TRUE(f.arr.try_unreserve(1023)); - EXPECT_EQUAL(round_up_to_page_size(1) == 64_Ki ? 16_Ki : 1_Ki, f.arr.capacity()); + EXPECT_TRUE(f.arr.try_unreserve(UnreserveFixture::page_ints() - 1)); + EXPECT_EQUAL(UnreserveFixture::page_ints(), f.arr.capacity()); int *newPtr = &f.arr[0]; EXPECT_EQUAL(oldPtr, newPtr); } |