First Commit

This commit is contained in:
Hamza committed 2026-02-26 13:00:32 +01:00
commit 8a6c7106e3
1312 files changed
+425396

No files matched your search

@@ -0,0 +1,84 @@
#include "catch.hpp"
#include <osmium/index/detail/tmpfile.hpp>
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/dense_mem_array.hpp>
#include <osmium/index/map/dense_mmap_array.hpp>
#include <osmium/index/map/sparse_file_array.hpp>
#include <osmium/index/map/sparse_mem_array.hpp>
#include <osmium/index/map/sparse_mmap_array.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
using dense_file_array = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
using sparse_file_array = osmium::index::map::SparseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
template <class TMemoryIndex, class TFileIndex>
void test_index(std::function<void(TMemoryIndex&, const int)> dump_method) {
const int fd = osmium::detail::create_tmp_file();
REQUIRE(osmium::file_size(fd) == 0);
const osmium::unsigned_object_id_type id1 = 12;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::unsigned_object_id_type id3 = 7;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
const osmium::Location loc3{-12.7, 14.5};
TMemoryIndex index;
index.set(id1, loc1);
index.set(id2, loc2);
index.set(id3, loc3);
// implementation of TMemoryIndex::sort should be empty if it is a dense index
index.sort();
dump_method(index, fd);
REQUIRE(osmium::file_size(fd) >= (3 * sizeof(typename TFileIndex::element_type)));
// load index from file
TFileIndex file_index{fd};
// test retrievals
REQUIRE(loc1 == file_index.get(id1));
REQUIRE(loc2 == file_index.get(id2));
REQUIRE(loc3 == file_index.get(id3));
REQUIRE_THROWS_AS(file_index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(file_index.get(6), osmium::not_found);
REQUIRE_THROWS_AS(file_index.get(200), osmium::not_found);
}
#ifdef __linux__
using dense_mmap_array = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump DenseMmapArray, load as DenseFileArray") {
auto dump_method = [](dense_mmap_array& index, const int fd) { index.dump_as_array(fd);};
test_index<dense_mmap_array, dense_file_array>(dump_method);
}
#else
# pragma message("not running 'DenseMmapArray' test case on this machine")
#endif
using dense_mem_array = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump DenseMemArray, load as DenseFileArray") {
auto dump_method = [](dense_mem_array& index, const int fd) { index.dump_as_array(fd);};
test_index<dense_mem_array, dense_file_array>(dump_method);
}
#ifdef __linux__
using sparse_mmap_array = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump SparseMmapArray, load as SparseFileArray") {
auto dump_method = [](sparse_mmap_array& index, const int fd) { index.dump_as_list(fd);};
test_index<sparse_mmap_array, sparse_file_array>(dump_method);
}
#else
# pragma message("not running 'SparseMmapArray' test case on this machine")
#endif
using sparse_mem_array = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump SparseMemArray, load as SparseFileArray") {
auto dump_method = [](sparse_mem_array& index, const int fd) { index.dump_as_list(fd);};
test_index<sparse_mem_array, sparse_file_array>(dump_method);
}
@@ -0,0 +1,85 @@
#include "catch.hpp"
#include <osmium/index/detail/tmpfile.hpp>
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/sparse_mem_array.hpp>
#include <osmium/index/map/sparse_mmap_array.hpp>
#include <osmium/index/node_locations_map.hpp>
#include <osmium/osm/node_ref.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/util/file.hpp>
#include <vector>
using dense_file_array = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
template <class TSparseIndex>
void test_index() {
const int fd = osmium::detail::create_tmp_file();
constexpr const size_t value_size = sizeof(typename TSparseIndex::element_type::second_type);
constexpr const size_t buffer_size = (10L * 1024L * 1024L) / value_size;
REQUIRE(osmium::file_size(fd) == 0);
std::vector<osmium::NodeRef> refs = {
osmium::NodeRef{1, osmium::Location{1.2, 4.5}},
osmium::NodeRef{6, osmium::Location{3.5, -7.2}},
osmium::NodeRef{2 * buffer_size, osmium::Location{10.2, 64.5}},
osmium::NodeRef{2 * buffer_size + 1, osmium::Location{39.5, -71.2}},
osmium::NodeRef{3 * buffer_size - 1, osmium::Location{-1.2, 54.6}},
osmium::NodeRef{3 * buffer_size, osmium::Location{-171.2, 9.3}},
osmium::NodeRef{3 * buffer_size + 1, osmium::Location{-171.21, 9.26}},
osmium::NodeRef{3 * buffer_size + 2, osmium::Location{-171.22, 9.25}},
osmium::NodeRef{3 * buffer_size + 3, osmium::Location{-171.24, 9.23}},
osmium::NodeRef{3 * buffer_size + 4, osmium::Location{-171.25, 9.22}},
osmium::NodeRef{3 * buffer_size + 5, osmium::Location{-171.26, 9.21}}
};
TSparseIndex sparse_index;
for (const auto& r : refs) {
sparse_index.set(r.ref(), r.location());
}
sparse_index.sort();
sparse_index.dump_as_array(fd);
const dense_file_array dense_index{fd};
const auto max_id_in_refs = std::max_element(refs.begin(), refs.end())->ref();
// Array index should be as large as necessary.
REQUIRE(osmium::file_size(fd) >= max_id_in_refs * sizeof(osmium::Location));
// check beyond largest ID
REQUIRE_THROWS_AS(dense_index.get(max_id_in_refs + 1), osmium::not_found);
// check if written values can be retrieved
for (const auto& r : refs) {
REQUIRE(dense_index.get(r.ref()) == r.location());
}
// check if all other values are invalid locations
size_t invalid_count = 0;
for (osmium::object_id_type id = 0; id <= max_id_in_refs; ++id) {
if (!dense_index.get_noexcept(id).valid()) {
++invalid_count;
}
}
REQUIRE(invalid_count == max_id_in_refs - refs.size() + 1);
}
#ifdef __linux__
using sparse_mmap_array = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump SparseMmapArray as array and load it as DenseFileArray") {
test_index<sparse_mmap_array>();
}
#else
# pragma message("not running 'SparseMmapArray' test case on this machine")
#endif
using sparse_mem_array = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
TEST_CASE("Dump SparseMemArray as array and load it as DenseFileArray") {
test_index<sparse_mem_array>();
}
@@ -0,0 +1,160 @@
#include "catch.hpp"
#include <osmium/index/detail/tmpfile.hpp>
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/sparse_file_array.hpp>
#include <osmium/index/node_locations_map.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
#include <osmium/util/file.hpp>
#include <iterator>
TEST_CASE("File based dense index") {
const int fd = osmium::detail::create_tmp_file();
REQUIRE(osmium::file_size(fd) == 0);
const osmium::unsigned_object_id_type id1 = 6;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
constexpr const size_t S = sizeof(index_type::element_type);
{
index_type index{fd};
REQUIRE(index.size() == 0);
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 3), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 6), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
index.set(id1, loc1);
REQUIRE(index.size() == 7);
index.set(id2, loc2);
REQUIRE(index.size() == 7);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.size() == 7);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 7);
REQUIRE(osmium::file_size(fd) >= (6 * S));
}
{
const index_type index{fd};
REQUIRE(osmium::file_size(fd) >= (6 * S));
REQUIRE(index.size() == 7);
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.size() == 7);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 7);
const auto* it = index.cbegin();
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == loc2);
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == osmium::Location{});
REQUIRE(*it++ == loc1);
REQUIRE(it++ == index.cend());
}
}
TEST_CASE("File based sparse index") {
const int fd = osmium::detail::create_tmp_file();
REQUIRE(osmium::file_size(fd) == 0);
const osmium::unsigned_object_id_type id1 = 6;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
using index_type = osmium::index::map::SparseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
constexpr const size_t S = sizeof(index_type::element_type);
{
index_type index{fd};
REQUIRE(index.size() == 0);
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 3), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 6), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
index.set(id1, loc1);
REQUIRE(index.size() == 1);
index.set(id2, loc2);
REQUIRE(index.size() == 2);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.size() == 2);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 2);
REQUIRE(osmium::file_size(fd) >= (2 * S));
}
{
const index_type index{fd};
REQUIRE(osmium::file_size(fd) >= (2 * S));
REQUIRE(index.size() == 2);
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get( 0), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 1), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 5), osmium::not_found);
REQUIRE_THROWS_AS(index.get( 7), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.size() == 2);
REQUIRE(std::distance(index.cbegin(), index.cend()) == 2);
}
}
+254
View File
@@ -0,0 +1,254 @@
#include "catch.hpp"
#include <osmium/index/id_set.hpp>
#include <osmium/osm/types.hpp>
TEST_CASE("Basic functionality of IdSetDense") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
REQUIRE_FALSE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE(s.empty());
REQUIRE(s.size() == 0); // NOLINT(readability-container-size-empty)
s.set(17);
REQUIRE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE_FALSE(s.empty());
REQUIRE(s.size() == 1);
s.set(28);
REQUIRE(s.get(17));
REQUIRE(s.get(28));
REQUIRE_FALSE(s.empty());
REQUIRE(s.size() == 2);
s.set(17);
REQUIRE(s.get(17));
REQUIRE(s.size() == 2);
REQUIRE_FALSE(s.check_and_set(17));
REQUIRE(s.get(17));
REQUIRE(s.size() == 2);
s.unset(17);
REQUIRE_FALSE(s.get(17));
REQUIRE(s.size() == 1);
REQUIRE(s.check_and_set(32));
REQUIRE(s.get(32));
REQUIRE(s.size() == 2);
s.clear();
REQUIRE(s.empty());
}
TEST_CASE("Copying IdSetDense") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s1;
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s2;
REQUIRE(s1.empty());
REQUIRE(s2.empty());
s1.set(17);
s1.set(28);
REQUIRE(s1.get(17));
REQUIRE(s1.get(17));
REQUIRE(s1.size() == 2);
s2 = s1;
REQUIRE(s1.get(17));
REQUIRE(s1.get(28));
REQUIRE(s1.size() == 2);
REQUIRE(s2.get(17));
REQUIRE(s2.get(28));
REQUIRE(s2.size() == 2);
const osmium::index::IdSetDense<osmium::unsigned_object_id_type> s3{s1};
REQUIRE(s3.get(17));
REQUIRE(s3.get(28));
REQUIRE(s3.size() == 2);
}
TEST_CASE("Iterating over IdSetDense") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
s.set(7);
s.set(35);
s.set(35);
s.set(20);
s.set(1ULL << 33U);
s.set(21);
s.set((1ULL << 27U) + 13U);
REQUIRE(s.size() == 6);
auto it = s.begin();
REQUIRE(it != s.end());
REQUIRE(*it == 7);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 20);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 21);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 35);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == (1ULL << 27U) + 13U);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 1ULL << 33U);
++it;
REQUIRE(it == s.end());
}
TEST_CASE("Test with larger Ids") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
const osmium::unsigned_object_id_type start = 25;
const osmium::unsigned_object_id_type end = 100000000;
const osmium::unsigned_object_id_type step = 123456;
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
s.set(i);
}
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
REQUIRE(s.get(i));
REQUIRE_FALSE(s.get(i + 1));
}
}
TEST_CASE("Large gap") {
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
s.set(3);
s.set(1U << 30U);
REQUIRE(s.get(1U << 30U));
REQUIRE_FALSE(s.get(1U << 29U));
}
TEST_CASE("Basic functionality of IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
REQUIRE_FALSE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE(s.empty());
s.set(17);
REQUIRE(s.get(17));
REQUIRE_FALSE(s.get(28));
REQUIRE_FALSE(s.empty());
s.set(28);
REQUIRE(s.get(17));
REQUIRE(s.get(28));
REQUIRE_FALSE(s.empty());
const auto size = s.size();
// Setting the same id as last time doesn't grow the size
s.set(28);
REQUIRE(s.get(17));
REQUIRE(s.get(28));
REQUIRE_FALSE(s.empty());
REQUIRE(size == s.size());
s.clear();
REQUIRE(s.empty());
}
TEST_CASE("Copying IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s1;
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s2;
REQUIRE(s1.empty());
REQUIRE(s2.empty());
s1.set(17);
s1.set(28);
REQUIRE(s1.get(17));
REQUIRE(s1.get(17));
REQUIRE(s1.size() == 2);
s2 = s1;
REQUIRE(s1.get(17));
REQUIRE(s1.get(28));
REQUIRE(s1.size() == 2);
REQUIRE(s2.get(17));
REQUIRE(s2.get(28));
REQUIRE(s2.size() == 2);
const osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s3{s1};
REQUIRE(s3.get(17));
REQUIRE(s3.get(28));
REQUIRE(s3.size() == 2);
}
TEST_CASE("Iterating over IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
s.set(7);
s.set(35);
s.set(35);
s.set(20);
s.set(1ULL << 33U);
s.set(21);
s.set((1ULL << 27U) + 13U);
// needs to be called before size() and iterator will work properly
s.sort_unique();
REQUIRE(s.size() == 6);
auto it = s.begin();
REQUIRE(it != s.end());
REQUIRE(*it == 7);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 20);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 21);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 35);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == (1ULL << 27U) + 13U);
++it;
REQUIRE(it != s.end());
REQUIRE(*it == 1ULL << 33U);
++it;
REQUIRE(it == s.end());
}
TEST_CASE("Merge two IdSetSmall") {
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s1;
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s2;
s1.set(23);
s1.set(2);
s1.set(7);
s1.set(55);
s1.set(42);
s1.set(7);
s2.set(2);
s2.set(32);
s2.set(8);
s2.set(55);
s2.set(1);
s1.sort_unique();
REQUIRE(s1.size() == 5);
s2.sort_unique();
REQUIRE(s2.size() == 5);
s1.merge_sorted(s2);
REQUIRE(s1.size() == 8);
const auto ids = {1, 2, 7, 8, 23, 32, 42, 55};
REQUIRE(std::equal(s1.cbegin(), s1.cend(), ids.begin()));
}
@@ -0,0 +1,259 @@
#include "catch.hpp"
#include <osmium/index/map/dense_file_array.hpp>
#include <osmium/index/map/dense_mem_array.hpp>
#include <osmium/index/map/dense_mmap_array.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/flex_mem.hpp>
#include <osmium/index/map/sparse_file_array.hpp>
#include <osmium/index/map/sparse_mem_array.hpp>
#include <osmium/index/map/sparse_mem_map.hpp>
#include <osmium/index/map/sparse_mmap_array.hpp>
#include <osmium/index/node_locations_map.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/osm/types.hpp>
#include <memory>
#include <string>
#include <vector>
static_assert(osmium::index::empty_value<osmium::Location>() == osmium::Location{}, "Empty value for location is wrong");
template <typename TIndex>
void test_func_all(TIndex& index) {
const osmium::unsigned_object_id_type id1 = 12;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE_THROWS_WITH(index.get(0), "id 0 not found");
REQUIRE_THROWS_WITH(index.get(1), "id 1 not found");
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
template <typename TIndex>
void test_func_real(TIndex& index) {
const osmium::unsigned_object_id_type id1 = 12;
const osmium::unsigned_object_id_type id2 = 3;
const osmium::Location loc1{1.2, 4.5};
const osmium::Location loc2{3.5, -7.2};
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE(loc1 == index.get_noexcept(id1));
REQUIRE(loc2 == index.get_noexcept(id2));
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
index.clear();
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(id2), osmium::not_found);
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.get_noexcept(id1) == osmium::Location{});
REQUIRE(index.get_noexcept(id2) == osmium::Location{});
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
TEST_CASE("Map Id to location: Dummy") {
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
}
TEST_CASE("Map Id to location: DenseMemArray") {
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
index1.reserve(1000);
test_func_all<index_type>(index1);
index_type index2;
index2.reserve(1000);
test_func_real<index_type>(index2);
}
#ifdef __linux__
TEST_CASE("Map Id to location: DenseMmapArray") {
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#else
# pragma message("not running 'DenseMmapArray' test case on this machine")
#endif
TEST_CASE("Map Id to location: DenseFileArray") {
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: SparseMemMap") {
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: SparseMemArray") {
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(2 == index1.size());
index_type index2;
test_func_real<index_type>(index2);
}
#ifdef __linux__
TEST_CASE("Map Id to location: SparseMmapArray") {
using index_type = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#else
# pragma message("not running 'SparseMmapArray' test case on this machine")
#endif
TEST_CASE("Map Id to location: FlexMem sparse") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: FlexMem dense") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
index_type index1{true};
test_func_all<index_type>(index1);
index_type index2{true};
test_func_real<index_type>(index2);
}
TEST_CASE("Map Id to location: FlexMem switch") {
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
const osmium::Location loc1{1.1, 1.2};
const osmium::Location loc2{2.2, -9.4};
index_type index;
REQUIRE(index.size() == 0);
index.set(17, loc1);
index.set(99, loc2);
REQUIRE_FALSE(index.is_dense());
REQUIRE(index.size() == 2);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(17) == loc1);
REQUIRE(index.get_noexcept(99) == loc2);
REQUIRE(index.get_noexcept(2000000000) == osmium::Location{});
index.switch_to_dense();
REQUIRE(index.is_dense());
REQUIRE(index.size() >= 2);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(17) == loc1);
REQUIRE(index.get_noexcept(99) == loc2);
REQUIRE(index.get_noexcept(2000000000) == osmium::Location{});
}
TEST_CASE("Map Id to location: Dynamic map choice") {
using map_type = osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
const std::vector<std::string> map_type_names = map_factory.map_types();
REQUIRE(map_type_names.size() >= 6);
REQUIRE_THROWS_AS(map_factory.create_map(""), osmium::map_factory_error);
REQUIRE_THROWS_AS(map_factory.create_map("does not exist"), osmium::map_factory_error);
REQUIRE_THROWS_WITH(map_factory.create_map(""), "Need non-empty map type name");
REQUIRE_THROWS_WITH(map_factory.create_map("does not exist"), "Support for map type 'does not exist' not compiled into this binary");
for (const auto& map_type_name : map_type_names) {
std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name);
index1->reserve(1000);
test_func_all<map_type>(*index1);
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
index2->reserve(1000);
test_func_real<map_type>(*index2);
}
}
+21
View File
@@ -0,0 +1,21 @@
#include "catch.hpp"
#include <osmium/index/nwr_array.hpp>
TEST_CASE("nwr_array") {
osmium::nwr_array<int> a;
a(osmium::item_type::node) = 1;
a(osmium::item_type::way) = 2;
a(osmium::item_type::relation) = 3;
REQUIRE(a(osmium::item_type::node) == 1);
REQUIRE(a(osmium::item_type::way) == 2);
REQUIRE(a(osmium::item_type::relation) == 3);
auto it = a.cbegin();
REQUIRE(*it++ == 1);
REQUIRE(*it++ == 2);
REQUIRE(*it++ == 3);
REQUIRE(it == a.cend());
}
@@ -0,0 +1,84 @@
#include "catch.hpp"
#include <osmium/builder/attr.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/object_pointer_collection.hpp>
#include <osmium/osm/object_comparisons.hpp>
#include <osmium/visitor.hpp>
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
TEST_CASE("Create ObjectPointerCollection") {
osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::add_node(buffer,
_id(3),
_version(3)
);
osmium::builder::add_node(buffer,
_id(1),
_version(2)
);
osmium::builder::add_node(buffer,
_id(1),
_version(4)
);
osmium::ObjectPointerCollection collection;
REQUIRE(collection.empty());
REQUIRE(collection.size() == 0); // NOLINT(readability-container-size-empty)
osmium::apply(buffer, collection);
REQUIRE_FALSE(collection.empty());
REQUIRE(collection.size() == 3);
auto it = collection.cbegin();
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_version{});
REQUIRE(collection.size() == 3);
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_reverse_version{});
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.clear();
REQUIRE(collection.empty());
}
@@ -0,0 +1,107 @@
#include "catch.hpp"
#include <osmium/index/relations_map.hpp>
#include <type_traits>
static_assert(!std::is_default_constructible<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be default constructible");
static_assert(!std::is_copy_constructible<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be copy constructible");
static_assert(!std::is_copy_constructible<osmium::index::RelationsMapStash>::value, "RelationsMapStash should not be copy constructible");
static_assert(!std::is_copy_assignable<osmium::index::RelationsMapIndex>::value, "RelationsMapIndex should not be copy assignable");
static_assert(!std::is_copy_assignable<osmium::index::RelationsMapStash>::value, "RelationsMapStash should not be copy assignable");
TEST_CASE("RelationsMapStash lvalue") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0); // NOLINT(readability-container-size-empty)
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_member_to_parent_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(1, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 1);
}
osmium::index::RelationsMapIndex func() {
osmium::index::RelationsMapStash stash;
stash.add(1, 2);
stash.add(2, 3);
return stash.build_member_to_parent_index();
}
TEST_CASE("RelationsMapStash rvalue") {
const osmium::index::RelationsMapIndex index{func()};
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
REQUIRE(count == 1);
}
TEST_CASE("RelationsMapStash reverse index") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_parent_to_member_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
index.for_each(3, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
++count;
});
REQUIRE(count == 2);
}
TEST_CASE("RelationsMapStash both indexes") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
const auto index = stash.build_indexes();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
int count = 0;
index.member_to_parent().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 3);
++count;
});
index.parent_to_member().for_each(2, [&](osmium::unsigned_object_id_type id) {
REQUIRE(id == 1);
++count;
});
REQUIRE(count == 2);
}