1 #include "catch.hpp"
2 
3 #include <osmium/memory/item.hpp>
4 
5 TEST_CASE("padded length") {
6     REQUIRE(osmium::memory::padded_length(0) ==  0);
7     REQUIRE(osmium::memory::padded_length(1) ==  8);
8     REQUIRE(osmium::memory::padded_length(2) ==  8);
9     REQUIRE(osmium::memory::padded_length(7) ==  8);
10     REQUIRE(osmium::memory::padded_length(8) ==  8);
11     REQUIRE(osmium::memory::padded_length(9) == 16);
12 
13     REQUIRE(osmium::memory::padded_length(2147483647UL) == 2147483648UL);
14     REQUIRE(osmium::memory::padded_length(2147483648UL) == 2147483648UL);
15     REQUIRE(osmium::memory::padded_length(2147483650UL) == 2147483656UL);
16 
17     // The following checks only make sense on a 64 bit system (with
18     // sizeof(size_t) == 8), because the numbers are too large for 32 bit.
19     // The casts to size_t do nothing on a 64 bit system, on a 32 bit system
20     // they bring the numbers into the right range and everything still works.
21     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967295ULL)) == static_cast<std::size_t>(4294967296ULL));
22     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967296ULL)) == static_cast<std::size_t>(4294967296ULL));
23     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967297ULL)) == static_cast<std::size_t>(4294967304ULL));
24 
25     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(7999999999ULL)) == static_cast<std::size_t>(8000000000ULL));
26     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000000ULL)) == static_cast<std::size_t>(8000000000ULL));
27     REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000001ULL)) == static_cast<std::size_t>(8000000008ULL));
28 }
29 
30