| 14 | using namespace osrm::storage; |
| 15 | |
| 16 | BOOST_AUTO_TEST_CASE(layout_write_test) |
| 17 | { |
| 18 | std::unique_ptr<BaseDataLayout> layout = std::make_unique<ContiguousDataLayout>(); |
| 19 | |
| 20 | Block block_1{20, 8 * 20}; |
| 21 | Block block_2{1, 4 * 1}; |
| 22 | Block block_3{100, static_cast<std::uint64_t>(std::ceil(100 / 64.))}; |
| 23 | |
| 24 | layout->SetBlock("block1", block_1); |
| 25 | layout->SetBlock("block2", block_2); |
| 26 | layout->SetBlock("block3", block_3); |
| 27 | |
| 28 | // Canary and alignment change layout size |
| 29 | BOOST_CHECK_GT(layout->GetSizeOfLayout(), |
| 30 | block_1.byte_size + block_2.byte_size + block_3.byte_size); |
| 31 | |
| 32 | BOOST_CHECK_EQUAL(layout->GetBlockSize("block1"), block_1.byte_size); |
| 33 | BOOST_CHECK_EQUAL(layout->GetBlockSize("block2"), block_2.byte_size); |
| 34 | BOOST_CHECK_EQUAL(layout->GetBlockSize("block3"), block_3.byte_size); |
| 35 | |
| 36 | std::vector<char> buffer(layout->GetSizeOfLayout()); |
| 37 | auto smallest_addr = buffer.data(); |
| 38 | auto biggest_addr = buffer.data() + buffer.size(); |
| 39 | |
| 40 | { |
| 41 | auto block_1_ptr = |
| 42 | reinterpret_cast<std::uint64_t *>(layout->GetBlockPtr(buffer.data(), "block1")); |
| 43 | auto block_2_ptr = |
| 44 | reinterpret_cast<std::uint32_t *>(layout->GetBlockPtr(buffer.data(), "block2")); |
| 45 | auto block_3_ptr = |
| 46 | reinterpret_cast<std::uint64_t *>(layout->GetBlockPtr(buffer.data(), "block3")); |
| 47 | |
| 48 | BOOST_CHECK_LE(reinterpret_cast<std::size_t>(smallest_addr), |
| 49 | reinterpret_cast<std::size_t>(block_1_ptr)); |
| 50 | BOOST_CHECK_GT( |
| 51 | reinterpret_cast<std::size_t>(biggest_addr), |
| 52 | reinterpret_cast<std::size_t>(block_1_ptr + layout->GetBlockEntries("block1"))); |
| 53 | |
| 54 | BOOST_CHECK_LT(reinterpret_cast<std::size_t>(smallest_addr), |
| 55 | reinterpret_cast<std::size_t>(block_2_ptr)); |
| 56 | BOOST_CHECK_GT( |
| 57 | reinterpret_cast<std::size_t>(biggest_addr), |
| 58 | reinterpret_cast<std::size_t>(block_2_ptr + layout->GetBlockEntries("block2"))); |
| 59 | |
| 60 | BOOST_CHECK_LT(reinterpret_cast<std::size_t>(smallest_addr), |
| 61 | reinterpret_cast<std::size_t>(block_3_ptr)); |
| 62 | BOOST_CHECK_GT(reinterpret_cast<std::size_t>(biggest_addr), |
| 63 | reinterpret_cast<std::size_t>( |
| 64 | block_3_ptr + static_cast<std::size_t>( |
| 65 | std::ceil(layout->GetBlockEntries("block3") / 64)))); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_CASE(layout_list_test) |
| 70 | { |
nothing calls this directly
no test coverage detected