2016-03-01 11:56:55 -05:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <osmium/osm/types.hpp>
|
|
|
|
#include <osmium/osm/location.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/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_mem_table.hpp>
|
|
|
|
#include <osmium/index/map/sparse_mmap_array.hpp>
|
|
|
|
|
|
|
|
#include <osmium/index/node_locations_map.hpp>
|
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
static_assert(osmium::index::empty_value<osmium::Location>() == osmium::Location{}, "Empty value for location is wrong");
|
|
|
|
|
2016-03-01 11:56:55 -05:00
|
|
|
template <typename TIndex>
|
|
|
|
void test_func_all(TIndex& index) {
|
2016-11-11 09:50:02 -05:00
|
|
|
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};
|
2016-03-01 11:56:55 -05:00
|
|
|
|
|
|
|
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
|
|
|
|
|
|
|
|
index.set(id1, loc1);
|
|
|
|
index.set(id2, loc2);
|
|
|
|
|
|
|
|
index.sort();
|
|
|
|
|
2016-10-03 13:08:59 -04:00
|
|
|
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
|
|
|
|
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
|
2016-03-01 11:56:55 -05:00
|
|
|
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
|
|
|
|
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
|
2016-11-11 09:50:02 -05:00
|
|
|
REQUIRE_THROWS_WITH(index.get(0), "id 0 not found");
|
|
|
|
REQUIRE_THROWS_WITH(index.get(1), "id 1 not found");
|
2016-03-01 11:56:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename TIndex>
|
|
|
|
void test_func_real(TIndex& index) {
|
2016-11-11 09:50:02 -05:00
|
|
|
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};
|
2016-03-01 11:56:55 -05:00
|
|
|
|
|
|
|
index.set(id1, loc1);
|
|
|
|
index.set(id2, loc2);
|
|
|
|
|
|
|
|
index.sort();
|
|
|
|
|
|
|
|
REQUIRE(loc1 == index.get(id1));
|
|
|
|
REQUIRE(loc2 == index.get(id2));
|
|
|
|
|
2016-10-03 13:08:59 -04:00
|
|
|
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
|
|
|
|
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
|
2016-03-01 11:56:55 -05:00
|
|
|
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
|
|
|
|
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
|
|
|
|
|
|
|
|
index.clear();
|
|
|
|
|
|
|
|
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
|
2016-10-03 13:08:59 -04:00
|
|
|
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);
|
2016-03-01 11:56:55 -05:00
|
|
|
}
|
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: Dummy") {
|
|
|
|
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
REQUIRE(0 == index1.size());
|
|
|
|
REQUIRE(0 == index1.used_memory());
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
REQUIRE(0 == index1.size());
|
|
|
|
REQUIRE(0 == index1.used_memory());
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: DenseMemArray") {
|
|
|
|
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
|
|
|
index1.reserve(1000);
|
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
index2.reserve(1000);
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
|
|
|
#ifdef __linux__
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: DenseMmapArray") {
|
|
|
|
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
#else
|
|
|
|
# pragma message("not running 'DenseMapMmap' test case on this machine")
|
|
|
|
#endif
|
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: DenseFileArray") {
|
|
|
|
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
|
|
|
#ifdef OSMIUM_WITH_SPARSEHASH
|
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: SparseMemTable") {
|
|
|
|
using index_type = osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: SparseMemMap") {
|
|
|
|
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
TEST_CASE("Map Id to location: SparseMemArray") {
|
|
|
|
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index1;
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
REQUIRE(0 == index1.size());
|
|
|
|
REQUIRE(0 == index1.used_memory());
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
test_func_all<index_type>(index1);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
REQUIRE(2 == index1.size());
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
index_type index2;
|
|
|
|
test_func_real<index_type>(index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
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();
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
const std::vector<std::string> map_type_names = map_factory.map_types();
|
|
|
|
REQUIRE(map_type_names.size() >= 5);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
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");
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
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);
|
2016-03-01 11:56:55 -05:00
|
|
|
|
2016-11-11 09:50:02 -05:00
|
|
|
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
|
|
|
|
index2->reserve(1000);
|
|
|
|
test_func_real<map_type>(*index2);
|
|
|
|
}
|
2016-03-01 11:56:55 -05:00
|
|
|
}
|
|
|
|
|