Merge commit '879f7eb04200d7d2c28af565229bf6e3d54274fd' into retry/libosmium
This commit is contained in:
+38
-6
@@ -85,6 +85,40 @@ function(add_unit_test _tgroup _tname)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Prepare some variables so querying it for tests work properly.
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
if(NOT GEOS_FOUND)
|
||||
set(GEOS_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT PROJ_FOUND)
|
||||
set(PROJ_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT SPARSEHASH_FOUND)
|
||||
set(SPARSEHASH_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT BZIP2_FOUND)
|
||||
set(BZIP2_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(NOT Threads_FOUND)
|
||||
set(Threads_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(GEOS_FOUND AND PROJ_FOUND)
|
||||
set(GEOS_AND_PROJ_FOUND TRUE)
|
||||
else()
|
||||
set(GEOS_AND_PROJ_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# Add all tests.
|
||||
@@ -93,6 +127,7 @@ endfunction()
|
||||
add_unit_test(area test_area_id)
|
||||
add_unit_test(area test_node_ref_segment)
|
||||
|
||||
add_unit_test(basic test_area)
|
||||
add_unit_test(basic test_box)
|
||||
add_unit_test(basic test_changeset)
|
||||
add_unit_test(basic test_crc)
|
||||
@@ -112,11 +147,6 @@ add_unit_test(buffer test_buffer_purge)
|
||||
|
||||
add_unit_test(builder test_attr)
|
||||
|
||||
if(GEOS_FOUND AND PROJ_FOUND)
|
||||
set(GEOS_AND_PROJ_FOUND TRUE)
|
||||
else()
|
||||
set(GEOS_AND_PROJ_FOUND FALSE)
|
||||
endif()
|
||||
add_unit_test(geom test_factory_with_projection
|
||||
ENABLE_IF ${GEOS_AND_PROJ_FOUND}
|
||||
LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY})
|
||||
@@ -129,17 +159,19 @@ add_unit_test(geom test_geos_wkb ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
|
||||
add_unit_test(geom test_mercator)
|
||||
add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY})
|
||||
add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
|
||||
add_unit_test(geom test_tile)
|
||||
add_unit_test(geom test_tile ENABLE_IF ${GEOS_FOUND})
|
||||
add_unit_test(geom test_wkb)
|
||||
add_unit_test(geom test_wkt)
|
||||
|
||||
add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND})
|
||||
add_unit_test(index test_file_based_index)
|
||||
|
||||
add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES})
|
||||
add_unit_test(io test_file_formats)
|
||||
add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES};${OSMIUM_PBF_LIBRARIES}")
|
||||
add_unit_test(io test_reader_with_mock_decompression ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES})
|
||||
add_unit_test(io test_reader_with_mock_parser ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
add_unit_test(io test_opl_parser)
|
||||
add_unit_test(io test_output_utils)
|
||||
add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
add_unit_test(io test_string_table)
|
||||
|
||||
Vendored
-8
@@ -3,11 +3,3 @@ Osmium uses Catch (https://github.com/philsquared/Catch/) for its unit tests.
|
||||
Only one header file is needed (catch.hpp) which can be downloaded from
|
||||
http://builds.catch-lib.net/ and put into the include directory.
|
||||
|
||||
Osmium needs a few changes to catch.hpp, they were patched in. To be able to
|
||||
compare with the original version, it is stored in include/catch_orig.hpp.
|
||||
|
||||
Changes are:
|
||||
* Disable more warnings in GCC
|
||||
* CATCH_CONFIG_CPP11_NULLPTR must be set for MSVC
|
||||
* Problem with test running in loop: https://github.com/philsquared/Catch/issues/271
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
|
||||
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
|
||||
using index_neg_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using index_pos_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using location_handler_type = osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type>;
|
||||
|
||||
#include "check_basics_handler.hpp"
|
||||
#include "check_wkt_handler.hpp"
|
||||
|
||||
+32
-28
@@ -1,7 +1,9 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <gdalcpp.hpp>
|
||||
|
||||
@@ -17,21 +19,20 @@
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
|
||||
typedef osmium::handler::NodeLocationsForWays<index_type> location_handler_type;
|
||||
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
|
||||
|
||||
struct less_charptr {
|
||||
|
||||
bool operator()(const char* a, const char* b) const {
|
||||
bool operator()(const char* a, const char* b) const noexcept {
|
||||
return std::strcmp(a, b) < 0;
|
||||
}
|
||||
|
||||
}; // less_charptr
|
||||
|
||||
typedef std::map<const char*, const char*, less_charptr> tagmap_type;
|
||||
using tagmap_type = std::map<const char*, const char*, less_charptr>;
|
||||
|
||||
inline tagmap_type create_map(const osmium::TagList& taglist) {
|
||||
tagmap_type create_map(const osmium::TagList& taglist) {
|
||||
tagmap_type map;
|
||||
|
||||
for (auto& tag : taglist) {
|
||||
@@ -52,7 +53,7 @@ class TestHandler : public osmium::handler::Handler {
|
||||
|
||||
std::ofstream m_out;
|
||||
|
||||
bool m_first_out {true};
|
||||
bool m_first_out{true};
|
||||
|
||||
public:
|
||||
|
||||
@@ -77,7 +78,7 @@ public:
|
||||
}
|
||||
|
||||
void node(const osmium::Node& node) {
|
||||
gdalcpp::Feature feature(m_layer_point, m_ogr_factory.create_point(node));
|
||||
gdalcpp::Feature feature{m_layer_point, m_ogr_factory.create_point(node)};
|
||||
feature.set_field("id", static_cast<double>(node.id()));
|
||||
feature.set_field("type", node.tags().get_value_by_key("type"));
|
||||
feature.add_to_layer();
|
||||
@@ -85,11 +86,11 @@ public:
|
||||
|
||||
void way(const osmium::Way& way) {
|
||||
try {
|
||||
gdalcpp::Feature feature(m_layer_lines, m_ogr_factory.create_linestring(way));
|
||||
gdalcpp::Feature feature{m_layer_lines, m_ogr_factory.create_linestring(way)};
|
||||
feature.set_field("id", static_cast<double>(way.id()));
|
||||
feature.set_field("type", way.tags().get_value_by_key("type"));
|
||||
feature.add_to_layer();
|
||||
} catch (osmium::geometry_error&) {
|
||||
} catch (const osmium::geometry_error&) {
|
||||
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
|
||||
}
|
||||
}
|
||||
@@ -103,10 +104,10 @@ public:
|
||||
}
|
||||
m_out << "{\n \"test_id\": " << (area.orig_id() / 1000) << ",\n \"area_id\": " << area.id() << ",\n \"from_id\": " << area.orig_id() << ",\n \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n \"wkt\": \"";
|
||||
try {
|
||||
std::string wkt = m_wkt_factory.create_multipolygon(area);
|
||||
const std::string wkt = m_wkt_factory.create_multipolygon(area);
|
||||
m_out << wkt << "\",\n \"tags\": {";
|
||||
|
||||
auto tagmap = create_map(area.tags());
|
||||
const auto tagmap = create_map(area.tags());
|
||||
bool first = true;
|
||||
for (auto& tag : tagmap) {
|
||||
if (first) {
|
||||
@@ -117,11 +118,11 @@ public:
|
||||
m_out << '"' << tag.first << "\": \"" << tag.second << '"';
|
||||
}
|
||||
m_out << "}\n}";
|
||||
} catch (osmium::geometry_error&) {
|
||||
} catch (const osmium::geometry_error&) {
|
||||
m_out << "INVALID\"\n}";
|
||||
}
|
||||
try {
|
||||
gdalcpp::Feature feature(m_layer_mpoly, m_ogr_factory.create_multipolygon(area));
|
||||
gdalcpp::Feature feature{m_layer_mpoly, m_ogr_factory.create_multipolygon(area)};
|
||||
feature.set_field("id", static_cast<double>(area.orig_id()));
|
||||
|
||||
std::string from_type;
|
||||
@@ -132,7 +133,7 @@ public:
|
||||
}
|
||||
feature.set_field("from_type", from_type.c_str());
|
||||
feature.add_to_layer();
|
||||
} catch (osmium::geometry_error&) {
|
||||
} catch (const osmium::geometry_error&) {
|
||||
std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
|
||||
}
|
||||
}
|
||||
@@ -144,35 +145,38 @@ public:
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " INFILE\n";
|
||||
exit(1);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
std::string output_format("SQLite");
|
||||
std::string input_filename(argv[1]);
|
||||
std::string output_filename("multipolygon.db");
|
||||
const std::string output_format{"SQLite"};
|
||||
const std::string input_filename{argv[1]};
|
||||
const std::string output_filename{"multipolygon.db"};
|
||||
|
||||
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
|
||||
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" }};
|
||||
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, {"SPATIALITE=TRUE"}};
|
||||
|
||||
osmium::area::ProblemReporterOGR problem_reporter(dataset);
|
||||
osmium::area::Assembler::config_type assembler_config(&problem_reporter);
|
||||
assembler_config.enable_debug_output();
|
||||
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);
|
||||
osmium::area::ProblemReporterOGR problem_reporter{dataset};
|
||||
osmium::area::Assembler::config_type assembler_config;
|
||||
assembler_config.problem_reporter = &problem_reporter;
|
||||
assembler_config.check_roles = true;
|
||||
assembler_config.create_empty_areas = true;
|
||||
assembler_config.debug_level = 2;
|
||||
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector{assembler_config};
|
||||
|
||||
std::cerr << "Pass 1...\n";
|
||||
osmium::io::Reader reader1(input_filename);
|
||||
osmium::io::Reader reader1{input_filename};
|
||||
collector.read_relations(reader1);
|
||||
reader1.close();
|
||||
std::cerr << "Pass 1 done\n";
|
||||
|
||||
index_type index;
|
||||
location_handler_type location_handler(index);
|
||||
location_handler_type location_handler{index};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
TestHandler test_handler(dataset);
|
||||
TestHandler test_handler{dataset};
|
||||
|
||||
std::cerr << "Pass 2...\n";
|
||||
osmium::io::Reader reader2(input_filename);
|
||||
osmium::io::Reader reader2{input_filename};
|
||||
osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
|
||||
osmium::apply(area_buffer, test_handler);
|
||||
}));
|
||||
|
||||
+12
-11
@@ -1,6 +1,7 @@
|
||||
/* The code in this file is released into the Public Domain. */
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <gdalcpp.hpp>
|
||||
|
||||
@@ -12,8 +13,8 @@
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
typedef osmium::handler::NodeLocationsForWays<index_type> location_handler_type;
|
||||
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
|
||||
|
||||
class TestOverviewHandler : public osmium::handler::Handler {
|
||||
|
||||
@@ -64,7 +65,7 @@ public:
|
||||
}
|
||||
|
||||
feature.add_to_layer();
|
||||
} catch (osmium::geometry_error&) {
|
||||
} catch (const osmium::geometry_error&) {
|
||||
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
|
||||
}
|
||||
}
|
||||
@@ -76,24 +77,24 @@ public:
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " INFILE\n";
|
||||
exit(1);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
std::string output_format("SQLite");
|
||||
std::string input_filename(argv[1]);
|
||||
std::string output_filename("testdata-overview.db");
|
||||
const std::string output_format{"SQLite"};
|
||||
const std::string input_filename{argv[1]};
|
||||
const std::string output_filename{"testdata-overview.db"};
|
||||
::unlink(output_filename.c_str());
|
||||
|
||||
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
|
||||
gdalcpp::Dataset dataset(output_format, output_filename, gdalcpp::SRS{}, { "SPATIALITE=TRUE" });
|
||||
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, {"SPATIALITE=TRUE"}};
|
||||
|
||||
osmium::io::Reader reader(input_filename);
|
||||
osmium::io::Reader reader{input_filename};
|
||||
|
||||
index_type index;
|
||||
location_handler_type location_handler(index);
|
||||
location_handler_type location_handler{index};
|
||||
location_handler.ignore_errors();
|
||||
|
||||
TestOverviewHandler handler(dataset);
|
||||
TestOverviewHandler handler{dataset};
|
||||
|
||||
osmium::apply(reader, location_handler, handler);
|
||||
reader.close();
|
||||
|
||||
@@ -15,11 +15,9 @@ int main(int argc, char* argv[]) {
|
||||
std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n";
|
||||
} else {
|
||||
std::cerr << "Please set TESTCASES_DIR environment variable.\n";
|
||||
exit(1);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
int result = Catch::Session().run(argc, argv);
|
||||
|
||||
return result;
|
||||
return Catch::Session().run(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
+60
-58
@@ -5,7 +5,9 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
#include <osmium/io/detail/queue_util.hpp>
|
||||
@@ -14,14 +16,14 @@
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
std::string S_(const char* s) {
|
||||
return std::string(s);
|
||||
return std::string{s};
|
||||
}
|
||||
|
||||
std::string filename(const char* test_id, const char* suffix = "osm") {
|
||||
const char* testdir = getenv("TESTDIR");
|
||||
if (!testdir) {
|
||||
std::cerr << "You have to set TESTDIR environment variable before running testdata-xml\n";
|
||||
exit(2);
|
||||
std::exit(2);
|
||||
}
|
||||
|
||||
std::string f;
|
||||
@@ -47,11 +49,11 @@ struct header_buffer_type {
|
||||
// file contents fit into small buffers.
|
||||
|
||||
std::string read_file(const char* test_id) {
|
||||
int fd = osmium::io::detail::open_for_reading(filename(test_id));
|
||||
const int fd = osmium::io::detail::open_for_reading(filename(test_id));
|
||||
assert(fd >= 0);
|
||||
|
||||
std::string input(10000, '\0');
|
||||
auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
|
||||
const auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
|
||||
assert(n >= 0);
|
||||
input.resize(static_cast<std::string::size_type>(n));
|
||||
|
||||
@@ -61,10 +63,10 @@ std::string read_file(const char* test_id) {
|
||||
}
|
||||
|
||||
std::string read_gz_file(const char* test_id, const char* suffix) {
|
||||
int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
|
||||
const int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
|
||||
assert(fd >= 0);
|
||||
|
||||
osmium::io::GzipDecompressor gzip_decompressor(fd);
|
||||
osmium::io::GzipDecompressor gzip_decompressor{fd};
|
||||
std::string input = gzip_decompressor.read();
|
||||
gzip_decompressor.close();
|
||||
|
||||
@@ -81,7 +83,7 @@ header_buffer_type parse_xml(std::string input) {
|
||||
osmium::io::detail::add_to_queue(input_queue, std::move(input));
|
||||
osmium::io::detail::add_to_queue(input_queue, std::string{});
|
||||
|
||||
osmium::io::detail::XMLParser parser(input_queue, output_queue, header_promise, osmium::osm_entity_bits::all);
|
||||
osmium::io::detail::XMLParser parser{input_queue, output_queue, header_promise, osmium::osm_entity_bits::all};
|
||||
parser.parse();
|
||||
|
||||
header_buffer_type result;
|
||||
@@ -117,9 +119,9 @@ TEST_CASE("Reading OSM XML 100") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
osmium::io::Reader reader(filename("100-correct_but_no_data"));
|
||||
osmium::io::Reader reader{filename("100-correct_but_no_data")};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
@@ -129,9 +131,9 @@ TEST_CASE("Reading OSM XML 100") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader asking for header only") {
|
||||
osmium::io::Reader reader(filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing);
|
||||
osmium::io::Reader reader{filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
reader.close();
|
||||
}
|
||||
@@ -146,15 +148,15 @@ TEST_CASE("Reading OSM XML 101") {
|
||||
REQUIRE_THROWS_AS(read_xml("101-missing_version"), osmium::format_version_error);
|
||||
try {
|
||||
read_xml("101-missing_version");
|
||||
} catch (osmium::format_version_error& e) {
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version.empty());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("101-missing_version"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("101-missing_version")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::format_version_error);
|
||||
@@ -170,16 +172,16 @@ TEST_CASE("Reading OSM XML 102") {
|
||||
REQUIRE_THROWS_AS(read_xml("102-wrong_version"), osmium::format_version_error);
|
||||
try {
|
||||
read_xml("102-wrong_version");
|
||||
} catch (osmium::format_version_error& e) {
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version == "0.1");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("102-wrong_version"));
|
||||
osmium::io::Reader reader{filename("102-wrong_version")};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::format_version_error);
|
||||
@@ -195,15 +197,15 @@ TEST_CASE("Reading OSM XML 103") {
|
||||
REQUIRE_THROWS_AS(read_xml("103-old_version"), osmium::format_version_error);
|
||||
try {
|
||||
read_xml("103-old_version");
|
||||
} catch (osmium::format_version_error& e) {
|
||||
} catch (const osmium::format_version_error& e) {
|
||||
REQUIRE(e.version == "0.5");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("103-old_version"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("103-old_version")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::format_version_error);
|
||||
@@ -219,7 +221,7 @@ TEST_CASE("Reading OSM XML 104") {
|
||||
REQUIRE_THROWS_AS(read_xml("104-empty_file"), osmium::xml_error);
|
||||
try {
|
||||
read_xml("104-empty_file");
|
||||
} catch (osmium::xml_error& e) {
|
||||
} catch (const osmium::xml_error& e) {
|
||||
REQUIRE(e.line == 1);
|
||||
REQUIRE(e.column == 0);
|
||||
}
|
||||
@@ -227,8 +229,8 @@ TEST_CASE("Reading OSM XML 104") {
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("104-empty_file"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("104-empty_file")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::xml_error);
|
||||
@@ -245,8 +247,8 @@ TEST_CASE("Reading OSM XML 105") {
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("105-incomplete_xml_file"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("105-incomplete_xml_file")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::xml_error);
|
||||
@@ -270,9 +272,9 @@ TEST_CASE("Reading OSM XML 120") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
osmium::io::Reader reader(filename("120-correct_gzip_file_without_data", "osm.gz"));
|
||||
osmium::io::Reader reader{filename("120-correct_gzip_file_without_data", "osm.gz")};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
@@ -296,8 +298,8 @@ TEST_CASE("Reading OSM XML 121") {
|
||||
SECTION("Using Reader") {
|
||||
// can throw osmium::gzip_error or osmium::xml_error
|
||||
REQUIRE_THROWS({
|
||||
osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("121-truncated_gzip_file", "osm.gz")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
});
|
||||
@@ -317,8 +319,8 @@ TEST_CASE("Reading OSM XML 122") {
|
||||
|
||||
SECTION("Using Reader") {
|
||||
REQUIRE_THROWS_AS({
|
||||
osmium::io::Reader reader(filename("122-no_osm_element"));
|
||||
osmium::io::Header header = reader.header();
|
||||
osmium::io::Reader reader{filename("122-no_osm_element")};
|
||||
const osmium::io::Header header{reader.header()};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
}, osmium::xml_error);
|
||||
@@ -331,19 +333,19 @@ TEST_CASE("Reading OSM XML 122") {
|
||||
TEST_CASE("Reading OSM XML 140") {
|
||||
|
||||
SECTION("Using Reader") {
|
||||
osmium::io::Reader reader(filename("140-unicode"));
|
||||
osmium::io::Reader reader{filename("140-unicode")};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
int count = 0;
|
||||
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
|
||||
for (const auto& node : buffer.select<osmium::Node>()) {
|
||||
++count;
|
||||
REQUIRE(it->id() == count);
|
||||
const osmium::TagList& t = it->tags();
|
||||
REQUIRE(node.id() == count);
|
||||
const osmium::TagList& t = node.tags();
|
||||
|
||||
const char* uc = t["unicode_char"];
|
||||
|
||||
auto len = atoi(t["unicode_utf8_length"]);
|
||||
const auto len = atoi(t["unicode_utf8_length"]);
|
||||
REQUIRE(len == strlen(uc));
|
||||
|
||||
REQUIRE(S_(uc) == t["unicode_xml"]);
|
||||
@@ -382,7 +384,7 @@ TEST_CASE("Reading OSM XML 140") {
|
||||
TEST_CASE("Reading OSM XML 141") {
|
||||
|
||||
SECTION("Using Reader") {
|
||||
osmium::io::Reader reader(filename("141-entities"));
|
||||
osmium::io::Reader reader{filename("141-entities")};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
@@ -406,40 +408,40 @@ TEST_CASE("Reading OSM XML 141") {
|
||||
TEST_CASE("Reading OSM XML 142") {
|
||||
|
||||
SECTION("Using Reader to read nodes") {
|
||||
osmium::io::Reader reader(filename("142-whitespace"));
|
||||
osmium::io::Reader reader{filename("142-whitespace")};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
int count = 0;
|
||||
for (auto it = buffer.begin<osmium::Node>(); it != buffer.end<osmium::Node>(); ++it) {
|
||||
for (const auto& node : buffer.select<osmium::Node>()) {
|
||||
++count;
|
||||
REQUIRE(it->id() == count);
|
||||
REQUIRE(it->tags().size() == 1);
|
||||
const osmium::Tag& tag = *(it->tags().begin());
|
||||
REQUIRE(node.id() == count);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
const osmium::Tag& tag = *(node.tags().begin());
|
||||
|
||||
switch (count) {
|
||||
case 1:
|
||||
REQUIRE(S_(it->user()) == "user name");
|
||||
REQUIRE(S_(node.user()) == "user name");
|
||||
REQUIRE(S_(tag.key()) == "key with space");
|
||||
REQUIRE(S_(tag.value()) == "value with space");
|
||||
break;
|
||||
case 2:
|
||||
REQUIRE(S_(it->user()) == "line\nfeed");
|
||||
REQUIRE(S_(node.user()) == "line\nfeed");
|
||||
REQUIRE(S_(tag.key()) == "key with\nlinefeed");
|
||||
REQUIRE(S_(tag.value()) == "value with\nlinefeed");
|
||||
break;
|
||||
case 3:
|
||||
REQUIRE(S_(it->user()) == "carriage\rreturn");
|
||||
REQUIRE(S_(node.user()) == "carriage\rreturn");
|
||||
REQUIRE(S_(tag.key()) == "key with\rcarriage\rreturn");
|
||||
REQUIRE(S_(tag.value()) == "value with\rcarriage\rreturn");
|
||||
break;
|
||||
case 4:
|
||||
REQUIRE(S_(it->user()) == "tab\tulator");
|
||||
REQUIRE(S_(node.user()) == "tab\tulator");
|
||||
REQUIRE(S_(tag.key()) == "key with\ttab");
|
||||
REQUIRE(S_(tag.value()) == "value with\ttab");
|
||||
break;
|
||||
case 5:
|
||||
REQUIRE(S_(it->user()) == "unencoded linefeed");
|
||||
REQUIRE(S_(node.user()) == "unencoded linefeed");
|
||||
REQUIRE(S_(tag.key()) == "key with unencoded linefeed");
|
||||
REQUIRE(S_(tag.value()) == "value with unencoded linefeed");
|
||||
break;
|
||||
@@ -451,12 +453,12 @@ TEST_CASE("Reading OSM XML 142") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader to read relation") {
|
||||
osmium::io::Reader reader(filename("142-whitespace"));
|
||||
osmium::io::Reader reader{filename("142-whitespace")};
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
auto it = buffer.begin<osmium::Relation>();
|
||||
REQUIRE(it != buffer.end<osmium::Relation>());
|
||||
auto it = buffer.select<osmium::Relation>().begin();
|
||||
REQUIRE(it != buffer.select<osmium::Relation>().end());
|
||||
REQUIRE(it->id() == 21);
|
||||
const auto& members = it->members();
|
||||
REQUIRE(members.size() == 5);
|
||||
@@ -505,9 +507,9 @@ TEST_CASE("Reading OSM XML 200") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader") {
|
||||
osmium::io::Reader reader(filename("200-nodes"));
|
||||
osmium::io::Reader reader{filename("200-nodes")};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
@@ -519,9 +521,9 @@ TEST_CASE("Reading OSM XML 200") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader asking for nodes") {
|
||||
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::node);
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::node};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
@@ -533,9 +535,9 @@ TEST_CASE("Reading OSM XML 200") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader asking for header only") {
|
||||
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::nothing);
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::nothing};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
REQUIRE_THROWS({
|
||||
@@ -546,9 +548,9 @@ TEST_CASE("Reading OSM XML 200") {
|
||||
}
|
||||
|
||||
SECTION("Using Reader asking for ways") {
|
||||
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::way);
|
||||
osmium::io::Reader reader{filename("200-nodes"), osmium::osm_entity_bits::way};
|
||||
|
||||
osmium::io::Header header = reader.header();
|
||||
const osmium::io::Header header{reader.header()};
|
||||
REQUIRE(header.get("generator") == "testdata");
|
||||
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
|
||||
+463
-157
File diff suppressed because it is too large
Load Diff
+138
-59
@@ -20,93 +20,111 @@ TEST_CASE("NodeRefSegmentClass") {
|
||||
osmium::NodeRef nr3(3, { 1.2, 3.6 });
|
||||
osmium::NodeRef nr4(4, { 1.2, 3.7 });
|
||||
|
||||
NodeRefSegment s1(nr1, nr2, nullptr, nullptr);
|
||||
NodeRefSegment s1(nr1, nr2);
|
||||
REQUIRE(s1.first().ref() == 1);
|
||||
REQUIRE(s1.second().ref() == 2);
|
||||
|
||||
NodeRefSegment s2(nr2, nr3, nullptr, nullptr);
|
||||
NodeRefSegment s2(nr2, nr3);
|
||||
REQUIRE(s2.first().ref() == 3);
|
||||
REQUIRE(s2.second().ref() == 2);
|
||||
|
||||
NodeRefSegment s3(nr3, nr4, nullptr, nullptr);
|
||||
NodeRefSegment s3(nr3, nr4);
|
||||
REQUIRE(s3.first().ref() == 3);
|
||||
REQUIRE(s3.second().ref() == 4);
|
||||
}
|
||||
|
||||
SECTION("intersection") {
|
||||
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}});
|
||||
NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}});
|
||||
NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}});
|
||||
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}});
|
||||
NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}});
|
||||
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}});
|
||||
NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}});
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0));
|
||||
REQUIRE(calculate_intersection(s2, s1) == osmium::Location(1.0, 1.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s3) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s3, s1) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s2, s3) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s3, s2) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s4) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s4, s1) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0));
|
||||
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(2.0, 2.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(1.0, 1.0));
|
||||
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(1.0, 1.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(1.0, 1.0));
|
||||
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(1.0, 1.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s6, s7) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s7, s6) == osmium::Location());
|
||||
}
|
||||
|
||||
SECTION("intersection of collinear segments") {
|
||||
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 0.0}}); // *---*
|
||||
NodeRefSegment s2({ 3, {2.0, 0.0}}, { 4, {4.0, 0.0}}); // *---*
|
||||
NodeRefSegment s3({ 5, {0.0, 0.0}}, { 6, {1.0, 0.0}}); // *-*
|
||||
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {2.0, 0.0}}); // *-*
|
||||
NodeRefSegment s5({ 9, {1.0, 0.0}}, {10, {3.0, 0.0}}); // *---*
|
||||
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {4.0, 0.0}}); // *-------*
|
||||
NodeRefSegment s7({13, {0.0, 0.0}}, {14, {5.0, 0.0}}); // *---------*
|
||||
NodeRefSegment s8({13, {1.0, 0.0}}, {14, {5.0, 0.0}}); // *-------*
|
||||
NodeRefSegment s9({13, {3.0, 0.0}}, {14, {4.0, 0.0}}); // *-*
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s1) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s1, s6) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s1, s7) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s2) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s2, s1) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s3) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s3, s1) == osmium::Location(1.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s4) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s4, s1) == osmium::Location(1.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(1.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(2.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(2.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(2.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(2.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s8) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s8, s1) == osmium::Location(1.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s1, s9) == osmium::Location());
|
||||
REQUIRE(calculate_intersection(s9, s1) == osmium::Location());
|
||||
|
||||
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s6, s5) == osmium::Location(1.0, 0.0));
|
||||
|
||||
REQUIRE(calculate_intersection(s7, s8) == osmium::Location(1.0, 0.0));
|
||||
REQUIRE(calculate_intersection(s8, s7) == osmium::Location(1.0, 0.0));
|
||||
}
|
||||
|
||||
SECTION("intersection of very long segments") {
|
||||
NodeRefSegment s1({ 1, {90.0, 90.0}}, { 2, {-90.0, -90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s2({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s1({ 1, {90.0, 90.0}}, { 2, {-90.0, -90.0}});
|
||||
NodeRefSegment s2({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
|
||||
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(0.0, 0.0));
|
||||
|
||||
NodeRefSegment s3({ 1, {-90.0, -90.0}}, { 2, {90.0, 90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s4({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s3({ 1, {-90.0, -90.0}}, { 2, {90.0, 90.0}});
|
||||
NodeRefSegment s4({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
|
||||
REQUIRE(calculate_intersection(s3, s4) == osmium::Location(0.0, 0.0));
|
||||
|
||||
NodeRefSegment s5({ 1, {-90.0000001, -90.0}}, { 2, {90.0, 90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s6({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}}, nullptr, nullptr);
|
||||
NodeRefSegment s5({ 1, {-90.00000001, -90.0}}, { 2, {90.0, 90.0}});
|
||||
NodeRefSegment s6({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
|
||||
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(0.0, 0.0));
|
||||
}
|
||||
|
||||
SECTION("to_left_of") {
|
||||
osmium::Location loc { 2.0, 2.0 };
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
|
||||
REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false);
|
||||
}
|
||||
|
||||
SECTION("ordering") {
|
||||
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
|
||||
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
|
||||
@@ -127,3 +145,64 @@ TEST_CASE("NodeRefSegmentClass") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Ordering of NodeRefSegments") {
|
||||
osmium::NodeRef nr0(0, { 0.0, 0.0 });
|
||||
osmium::NodeRef nr1(1, { 1.0, 0.0 });
|
||||
osmium::NodeRef nr2(2, { 0.0, 1.0 });
|
||||
osmium::NodeRef nr3(3, { 2.0, 0.0 });
|
||||
osmium::NodeRef nr4(4, { 0.0, 2.0 });
|
||||
osmium::NodeRef nr5(5, { 1.0, 1.0 });
|
||||
osmium::NodeRef nr6(6, { 2.0, 2.0 });
|
||||
osmium::NodeRef nr7(6, { 1.0, 2.0 });
|
||||
|
||||
NodeRefSegment s1(nr0, nr1);
|
||||
NodeRefSegment s2(nr0, nr2);
|
||||
NodeRefSegment s3(nr0, nr3);
|
||||
NodeRefSegment s4(nr0, nr4);
|
||||
NodeRefSegment s5(nr0, nr5);
|
||||
NodeRefSegment s6(nr0, nr6);
|
||||
NodeRefSegment s7(nr0, nr7);
|
||||
|
||||
// s1
|
||||
REQUIRE_FALSE(s1 < s1);
|
||||
REQUIRE(s2 < s1);
|
||||
REQUIRE(s1 < s3);
|
||||
REQUIRE(s4 < s1);
|
||||
REQUIRE(s5 < s1);
|
||||
REQUIRE(s6 < s1);
|
||||
REQUIRE(s7 < s1);
|
||||
|
||||
// s2
|
||||
REQUIRE_FALSE(s2 < s2);
|
||||
REQUIRE(s2 < s3);
|
||||
REQUIRE(s2 < s4);
|
||||
REQUIRE(s2 < s5);
|
||||
REQUIRE(s2 < s6);
|
||||
REQUIRE(s2 < s7);
|
||||
|
||||
// s3
|
||||
REQUIRE_FALSE(s3 < s3);
|
||||
REQUIRE(s4 < s3);
|
||||
REQUIRE(s5 < s3);
|
||||
REQUIRE(s6 < s3);
|
||||
REQUIRE(s7 < s3);
|
||||
|
||||
// s4
|
||||
REQUIRE_FALSE(s4 < s4);
|
||||
REQUIRE(s4 < s5);
|
||||
REQUIRE(s4 < s6);
|
||||
REQUIRE(s4 < s7);
|
||||
|
||||
// s5
|
||||
REQUIRE_FALSE(s5 < s5);
|
||||
REQUIRE(s5 < s6);
|
||||
REQUIRE(s7 < s5);
|
||||
|
||||
// s6
|
||||
REQUIRE_FALSE(s6 < s6);
|
||||
REQUIRE(s7 < s6);
|
||||
|
||||
// s7
|
||||
REQUIRE_FALSE(s7 < s7);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/area.hpp>
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build area") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
|
||||
osmium::builder::add_area(buffer,
|
||||
_id(17),
|
||||
_version(3),
|
||||
_visible(),
|
||||
_cid(333),
|
||||
_uid(21),
|
||||
_timestamp(time_t(123)),
|
||||
_user("foo"),
|
||||
_tag("landuse", "forest"),
|
||||
_tag("name", "Sherwood Forest"),
|
||||
_outer_ring({
|
||||
{1, {3.2, 4.2}},
|
||||
{2, {3.5, 4.7}},
|
||||
{3, {3.6, 4.9}},
|
||||
{1, {3.2, 4.2}}
|
||||
}),
|
||||
_inner_ring({
|
||||
{5, {1.0, 1.0}},
|
||||
{6, {8.0, 1.0}},
|
||||
{7, {8.0, 8.0}},
|
||||
{8, {1.0, 8.0}},
|
||||
{5, {1.0, 1.0}}
|
||||
})
|
||||
);
|
||||
|
||||
const osmium::Area& area = buffer.get<osmium::Area>(0);
|
||||
|
||||
REQUIRE(17 == area.id());
|
||||
REQUIRE(3 == area.version());
|
||||
REQUIRE(true == area.visible());
|
||||
REQUIRE(333 == area.changeset());
|
||||
REQUIRE(21 == area.uid());
|
||||
REQUIRE(std::string("foo") == area.user());
|
||||
REQUIRE(123 == uint32_t(area.timestamp()));
|
||||
REQUIRE(2 == area.tags().size());
|
||||
|
||||
int inner = 0;
|
||||
int outer = 0;
|
||||
for (const auto& subitem : area) {
|
||||
switch (subitem.type()) {
|
||||
case osmium::item_type::outer_ring: {
|
||||
const auto& ring = static_cast<const osmium::OuterRing&>(subitem);
|
||||
REQUIRE(ring.size() == 4);
|
||||
++outer;
|
||||
}
|
||||
break;
|
||||
case osmium::item_type::inner_ring: {
|
||||
const auto& ring = static_cast<const osmium::OuterRing&>(subitem);
|
||||
REQUIRE(ring.size() == 5);
|
||||
++inner;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(outer == 1);
|
||||
REQUIRE(inner == 1);
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(area);
|
||||
REQUIRE(crc32().checksum() == 0x2b2b7fa0);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ TEST_CASE("entity_bits") {
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::way));
|
||||
REQUIRE(entities == osmium::osm_entity_bits::node);
|
||||
|
||||
REQUIRE(osmium::osm_entity_bits::nothing == osmium::osm_entity_bits::from_item_type(osmium::item_type::undefined));
|
||||
REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node));
|
||||
REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way));
|
||||
REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation));
|
||||
|
||||
+219
-1
@@ -137,7 +137,7 @@ TEST_CASE("Location") {
|
||||
}
|
||||
|
||||
SECTION("output_defined") {
|
||||
osmium::Location p(-3.2, 47.3);
|
||||
osmium::Location p(-3.20, 47.30);
|
||||
std::stringstream out;
|
||||
out << p;
|
||||
REQUIRE(out.str() == "(-3.2,47.3)");
|
||||
@@ -152,3 +152,221 @@ TEST_CASE("Location") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Location hash") {
|
||||
if (sizeof(size_t) == 8) {
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 0}) == 0);
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 1}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 0}) == 0x100000000);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 1}) == 0x100000001);
|
||||
} else {
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 0}) == 0);
|
||||
REQUIRE(std::hash<osmium::Location>{}({0, 1}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 0}) == 1);
|
||||
REQUIRE(std::hash<osmium::Location>{}({1, 1}) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#define CR(s, v, r) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
REQUIRE(std::atof(strp) == Approx( v / 10000000.0)); \
|
||||
REQUIRE(std::atof(strm) == Approx(-v / 10000000.0)); \
|
||||
const char** data = &strp; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
data = &strm; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == -v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
}
|
||||
|
||||
#define C(s, v) CR(s, v, "")
|
||||
|
||||
#define F(s) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
const char** data = &strp; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
data = &strm; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing coordinates from strings") {
|
||||
F("x");
|
||||
F(".");
|
||||
F("--");
|
||||
F("");
|
||||
F(" ");
|
||||
F(" 123");
|
||||
|
||||
CR("123 ", 1230000000, " ");
|
||||
CR("123x", 1230000000, "x");
|
||||
CR("1.2x", 12000000, "x");
|
||||
|
||||
C("0", 0);
|
||||
|
||||
C("1", 10000000);
|
||||
C("2", 20000000);
|
||||
|
||||
C("9", 90000000);
|
||||
C("10", 100000000);
|
||||
C("11", 110000000);
|
||||
|
||||
C("90", 900000000);
|
||||
C("100", 1000000000);
|
||||
C("101", 1010000000);
|
||||
|
||||
C("00", 0);
|
||||
C("01", 10000000);
|
||||
C("001", 10000000);
|
||||
C("0001", 10000000);
|
||||
|
||||
F("1234");
|
||||
F("1234.");
|
||||
F("12345678901234567890");
|
||||
|
||||
C("0.", 0);
|
||||
C("0.0", 0);
|
||||
C("1.", 10000000);
|
||||
C("1.0", 10000000);
|
||||
C("1.2", 12000000);
|
||||
C("0.1", 1000000);
|
||||
C("0.01", 100000);
|
||||
C("0.001", 10000);
|
||||
C("0.0001", 1000);
|
||||
C("0.00001", 100);
|
||||
C("0.000001", 10);
|
||||
C("0.0000001", 1);
|
||||
|
||||
C("1.1234567", 11234567);
|
||||
C("1.12345670", 11234567);
|
||||
C("1.12345674", 11234567);
|
||||
C("1.123456751", 11234568);
|
||||
C("1.12345679", 11234568);
|
||||
C("1.12345680", 11234568);
|
||||
C("1.12345681", 11234568);
|
||||
|
||||
C("180.0000000", 1800000000);
|
||||
C("180.0000001", 1800000001);
|
||||
C("179.9999999", 1799999999);
|
||||
C("179.99999999", 1800000000);
|
||||
C("200.123", 2001230000);
|
||||
|
||||
C("1e2", 1000000000);
|
||||
C("1e1", 100000000);
|
||||
C("1e0", 10000000);
|
||||
C("1e-1", 1000000);
|
||||
C("1e-2", 100000);
|
||||
C("1e-3", 10000);
|
||||
C("1e-4", 1000);
|
||||
C("1e-5", 100);
|
||||
C("1e-6", 10);
|
||||
C("1e-7", 1);
|
||||
|
||||
C("1.0e2", 1000000000);
|
||||
C("1.1e1", 110000000);
|
||||
C("0.1e1", 10000000);
|
||||
C("1.2e0", 12000000);
|
||||
C("1.9e-1", 1900000);
|
||||
C("2.0e-2", 200000);
|
||||
C("2.1e-3", 21000);
|
||||
C("9.0e-4", 9000);
|
||||
C("9.1e-5", 910);
|
||||
C("1.0e-6", 10);
|
||||
C("1.0e-7", 1);
|
||||
C("1.4e-7", 1);
|
||||
C("1.5e-7", 2);
|
||||
C("1.9e-7", 2);
|
||||
C("0.5e-7", 1);
|
||||
C("0.1e-7", 0);
|
||||
C("0.0e-7", 0);
|
||||
C("1.9e-8", 0);
|
||||
C("1.9e-9", 0);
|
||||
C("1.9e-10", 0);
|
||||
|
||||
F("e");
|
||||
F(" e");
|
||||
F(" 1.1e2");
|
||||
F("1.0e3");
|
||||
F("5e4");
|
||||
F("5.0e2");
|
||||
F("3e2");
|
||||
F("1e");
|
||||
F("0.5e");
|
||||
F("1e10");
|
||||
|
||||
CR("1e2 ", 1000000000, " ");
|
||||
CR("1.1e2 ", 1100000000, " ");
|
||||
CR("1.1e2x", 1100000000, "x");
|
||||
CR("1.1e2:", 1100000000, ":");
|
||||
}
|
||||
|
||||
#undef C
|
||||
#undef CR
|
||||
#undef F
|
||||
|
||||
#define CW(v, s) buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), v); \
|
||||
CHECK(buffer == s); \
|
||||
buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), -v); \
|
||||
CHECK(buffer == "-" s);
|
||||
|
||||
TEST_CASE("Writing coordinates into string") {
|
||||
std::string buffer;
|
||||
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), 0);
|
||||
CHECK(buffer == "0");
|
||||
|
||||
CW( 10000000, "1");
|
||||
CW( 90000000, "9");
|
||||
CW( 100000000, "10");
|
||||
CW(1000000000, "100");
|
||||
CW(2000000000, "200");
|
||||
|
||||
CW( 1000000, "0.1");
|
||||
CW( 100000, "0.01");
|
||||
CW( 10000, "0.001");
|
||||
CW( 1000, "0.0001");
|
||||
CW( 100, "0.00001");
|
||||
CW( 10, "0.000001");
|
||||
CW( 1, "0.0000001");
|
||||
|
||||
CW( 1230000, "0.123");
|
||||
CW( 9999999, "0.9999999");
|
||||
CW( 40101010, "4.010101");
|
||||
CW( 494561234, "49.4561234");
|
||||
CW(1799999999, "179.9999999");
|
||||
}
|
||||
|
||||
#undef CW
|
||||
|
||||
TEST_CASE("set lon/lat from string") {
|
||||
osmium::Location loc;
|
||||
loc.set_lon("1.2");
|
||||
loc.set_lat("3.4");
|
||||
REQUIRE(loc.lon() == Approx(1.2));
|
||||
REQUIRE(loc.lat() == Approx(3.4));
|
||||
}
|
||||
|
||||
TEST_CASE("set lon/lat from string with trailing characters") {
|
||||
osmium::Location loc;
|
||||
REQUIRE_THROWS_AS({
|
||||
loc.set_lon("1.2x");
|
||||
}, osmium::invalid_location);
|
||||
REQUIRE_THROWS_AS({
|
||||
loc.set_lat("3.4e1 ");
|
||||
}, osmium::invalid_location);
|
||||
}
|
||||
|
||||
TEST_CASE("set lon/lat from string with trailing characters using partial") {
|
||||
osmium::Location loc;
|
||||
const char* x = "1.2x";
|
||||
const char* y = "3.4 ";
|
||||
loc.set_lon_partial(&x);
|
||||
loc.set_lat_partial(&y);
|
||||
REQUIRE(loc.lon() == Approx(1.2));
|
||||
REQUIRE(loc.lat() == Approx(3.4));
|
||||
REQUIRE(*x == 'x');
|
||||
REQUIRE(*y == ' ');
|
||||
}
|
||||
|
||||
|
||||
+55
-13
@@ -9,7 +9,7 @@
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_id(17),
|
||||
@@ -36,7 +36,7 @@ TEST_CASE("Build node") {
|
||||
REQUIRE(false == node.deleted());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(21 == node.uid());
|
||||
REQUIRE(std::string("foo") == node.user());
|
||||
REQUIRE(std::string{"foo"} == node.user());
|
||||
REQUIRE(123 == uint32_t(node.timestamp()));
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(2 == node.tags().size());
|
||||
@@ -51,7 +51,7 @@ TEST_CASE("Build node") {
|
||||
}
|
||||
|
||||
TEST_CASE("default values for node attributes") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
@@ -62,22 +62,23 @@ TEST_CASE("default values for node attributes") {
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(0 == node.changeset());
|
||||
REQUIRE(0 == node.uid());
|
||||
REQUIRE(std::string("") == node.user());
|
||||
REQUIRE(std::string{} == node.user());
|
||||
REQUIRE(0 == uint32_t(node.timestamp()));
|
||||
REQUIRE(osmium::Location() == node.location());
|
||||
REQUIRE(0 == node.tags().size());
|
||||
}
|
||||
|
||||
TEST_CASE("set node attributes from strings") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
node.set_id("-17")
|
||||
.set_version("3")
|
||||
.set_visible(true)
|
||||
.set_visible("true")
|
||||
.set_changeset("333")
|
||||
.set_timestamp("2014-03-17T16:23:08Z")
|
||||
.set_uid("21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
@@ -85,11 +86,52 @@ TEST_CASE("set node attributes from strings") {
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(std::string{"2014-03-17T16:23:08Z"} == node.timestamp().to_iso());
|
||||
REQUIRE(21 == node.uid());
|
||||
}
|
||||
|
||||
TEST_CASE("set node attributes from strings using set_attribute()") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
node.set_attribute("id", "-17")
|
||||
.set_attribute("version", "3")
|
||||
.set_attribute("visible", "true")
|
||||
.set_attribute("changeset", "333")
|
||||
.set_attribute("timestamp", "2014-03-17T16:23:08Z")
|
||||
.set_attribute("uid", "21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
REQUIRE(std::string{"2014-03-17T16:23:08Z"} == node.timestamp().to_iso());
|
||||
REQUIRE(21 == node.uid());
|
||||
}
|
||||
|
||||
TEST_CASE("Setting attributes from bad data on strings should fail") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
REQUIRE_THROWS(node.set_id("bar"));
|
||||
REQUIRE_THROWS(node.set_id("123x"));
|
||||
REQUIRE_THROWS(node.set_version("123x"));
|
||||
REQUIRE_THROWS(node.set_visible("foo"));
|
||||
REQUIRE_THROWS(node.set_changeset("123x"));
|
||||
REQUIRE_THROWS(node.set_changeset("NULL"));
|
||||
REQUIRE_THROWS(node.set_timestamp("2014-03-17T16:23:08Zx"));
|
||||
REQUIRE_THROWS(node.set_timestamp("2014-03-17T16:23:99Z"));
|
||||
REQUIRE_THROWS(node.set_uid("123x"));
|
||||
REQUIRE_THROWS(node.set_uid("anonymous"));
|
||||
}
|
||||
|
||||
TEST_CASE("set large id") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
int64_t id = 3000000000l;
|
||||
osmium::builder::add_node(buffer, _id(id));
|
||||
@@ -104,7 +146,7 @@ TEST_CASE("set large id") {
|
||||
}
|
||||
|
||||
TEST_CASE("set tags on node") {
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::builder::add_node(buffer,
|
||||
_user("foo"),
|
||||
@@ -114,11 +156,11 @@ TEST_CASE("set tags on node") {
|
||||
|
||||
const osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
REQUIRE(nullptr == node.tags().get_value_by_key("fail"));
|
||||
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity"));
|
||||
REQUIRE(std::string("pub") == node.get_value_by_key("amenity"));
|
||||
REQUIRE(std::string{"pub"} == node.tags().get_value_by_key("amenity"));
|
||||
REQUIRE(std::string{"pub"} == node.get_value_by_key("amenity"));
|
||||
|
||||
REQUIRE(std::string("default") == node.tags().get_value_by_key("fail", "default"));
|
||||
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity", "default"));
|
||||
REQUIRE(std::string("pub") == node.get_value_by_key("amenity", "default"));
|
||||
REQUIRE(std::string{"default"} == node.tags().get_value_by_key("fail", "default"));
|
||||
REQUIRE(std::string{"pub"} == node.tags().get_value_by_key("amenity", "default"));
|
||||
REQUIRE(std::string{"pub"} == node.get_value_by_key("amenity", "default"));
|
||||
}
|
||||
|
||||
|
||||
+59
-55
@@ -1,76 +1,80 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
#include <osmium/osm/object_comparisons.hpp>
|
||||
|
||||
TEST_CASE("Object_Comparisons") {
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
using namespace osmium::builder::attr;
|
||||
TEST_CASE("Node comparisons") {
|
||||
|
||||
SECTION("order") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
std::vector<std::reference_wrapper<osmium::Node>> nodes;
|
||||
|
||||
osmium::builder::add_node(buffer, _id(10), _version(1));
|
||||
osmium::builder::add_node(buffer, _id(15), _version(2));
|
||||
SECTION("nodes are ordered by id, version, and timestamp") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(3), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 15), _version(1), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000ll), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
auto it = buffer.begin();
|
||||
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
|
||||
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
|
||||
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE_FALSE(node1 > node2);
|
||||
node1.set_id(20);
|
||||
node1.set_version(1);
|
||||
node2.set_id(20);
|
||||
node2.set_version(2);
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE_FALSE(node1 > node2);
|
||||
node1.set_id(-10);
|
||||
node1.set_version(2);
|
||||
node2.set_id(-15);
|
||||
node2.set_version(1);
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE_FALSE(node1 > node2);
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend()));
|
||||
}
|
||||
|
||||
SECTION("order_types") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
SECTION("equal nodes are not different") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
osmium::builder::add_node(buffer, _id(3), _version(3));
|
||||
osmium::builder::add_node(buffer, _id(3), _version(4));
|
||||
osmium::builder::add_node(buffer, _id(3), _version(4));
|
||||
osmium::builder::add_way(buffer, _id(2), _version(2));
|
||||
osmium::builder::add_relation(buffer, _id(1), _version(1));
|
||||
REQUIRE(nodes[0] == nodes[1]);
|
||||
REQUIRE_FALSE(nodes[0] < nodes[1]);
|
||||
REQUIRE_FALSE(nodes[0] > nodes[1]);
|
||||
}
|
||||
|
||||
auto it = buffer.begin();
|
||||
const osmium::Node& node1 = static_cast<const osmium::Node&>(*it);
|
||||
const osmium::Node& node2 = static_cast<const osmium::Node&>(*(++it));
|
||||
const osmium::Node& node3 = static_cast<const osmium::Node&>(*(++it));
|
||||
const osmium::Way& way = static_cast<const osmium::Way&>(*(++it));
|
||||
const osmium::Relation& relation = static_cast<const osmium::Relation&>(*(++it));
|
||||
SECTION("IDs are ordered by absolute value") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( -1))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(-10))));
|
||||
|
||||
REQUIRE(node1 < node2);
|
||||
REQUIRE(node2 < way);
|
||||
REQUIRE_FALSE(node2 > way);
|
||||
REQUIRE(way < relation);
|
||||
REQUIRE(node1 < relation);
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend()));
|
||||
}
|
||||
|
||||
REQUIRE(osmium::object_order_type_id_version()(node1, node2));
|
||||
REQUIRE(osmium::object_order_type_id_reverse_version()(node2, node1));
|
||||
REQUIRE(osmium::object_order_type_id_version()(node1, way));
|
||||
REQUIRE(osmium::object_order_type_id_reverse_version()(node1, way));
|
||||
SECTION("reverse version ordering") {
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 0), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 1), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(3), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 10), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:01:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 12), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id( 15), _version(1), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000ll), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, node2));
|
||||
REQUIRE(osmium::object_equal_type_id_version()(node2, node3));
|
||||
|
||||
REQUIRE(osmium::object_equal_type_id()(node1, node2));
|
||||
REQUIRE(osmium::object_equal_type_id()(node2, node3));
|
||||
|
||||
REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, way));
|
||||
REQUIRE_FALSE(osmium::object_equal_type_id_version()(node1, relation));
|
||||
REQUIRE_FALSE(osmium::object_equal_type_id()(node1, relation));
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Object comparisons") {
|
||||
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
std::vector<std::reference_wrapper<osmium::OSMObject>> objects;
|
||||
|
||||
SECTION("types are ordered nodes, then ways, then relations") {
|
||||
objects.emplace_back(buffer.get<osmium::Node>( osmium::builder::add_node( buffer, _id(3))));
|
||||
objects.emplace_back(buffer.get<osmium::Way>( osmium::builder::add_way( buffer, _id(2))));
|
||||
objects.emplace_back(buffer.get<osmium::Relation>(osmium::builder::add_relation(buffer, _id(1))));
|
||||
|
||||
REQUIRE(std::is_sorted(objects.cbegin(), objects.cend()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -75,3 +75,47 @@ TEST_CASE("Timestamp") {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Valid timestamps") {
|
||||
|
||||
std::vector<std::string> test_cases = {
|
||||
"1970-01-01T00:00:01Z",
|
||||
"2000-01-01T00:00:00Z",
|
||||
"2006-12-31T23:59:59Z",
|
||||
"2030-12-31T23:59:59Z",
|
||||
"2016-02-28T23:59:59Z",
|
||||
"2016-03-31T23:59:59Z"
|
||||
};
|
||||
|
||||
for (const auto& tc : test_cases) {
|
||||
osmium::Timestamp t{tc};
|
||||
REQUIRE(tc == t.to_iso());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Invalid timestamps") {
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{""}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"x"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"xxxxxxxxxxxxxxxxxxxx"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01x00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00:00x"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000x01-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01x01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00x00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00x00Z"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"0000-00-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-00-01T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-00T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T24:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:60:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-01T00:00:61Z"}, std::invalid_argument);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-01-32T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-02-30T00:00:00Z"}, std::invalid_argument);
|
||||
REQUIRE_THROWS_AS(osmium::Timestamp{"2000-03-32T00:00:00Z"}, std::invalid_argument);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,17 @@ TEST_CASE("set type and ID from string") {
|
||||
REQUIRE(r_2.first == osmium::item_type::relation);
|
||||
REQUIRE(r_2.second == -2);
|
||||
|
||||
auto x3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(x3.first == osmium::item_type::undefined);
|
||||
REQUIRE(x3.second == 3);
|
||||
auto d3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr);
|
||||
REQUIRE(d3.first == osmium::item_type::undefined);
|
||||
REQUIRE(d3.second == 3);
|
||||
|
||||
auto u3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr, osmium::item_type::undefined);
|
||||
REQUIRE(u3.first == osmium::item_type::undefined);
|
||||
REQUIRE(u3.second == 3);
|
||||
|
||||
auto n3 = osmium::string_to_object_id("3", osmium::osm_entity_bits::nwr, osmium::item_type::node);
|
||||
REQUIRE(n3.first == osmium::item_type::node);
|
||||
REQUIRE(n3.second == 3);
|
||||
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
REQUIRE_THROWS_AS(osmium::string_to_object_id("n", osmium::osm_entity_bits::nwr), std::range_error);
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ TEST_CASE("Build way") {
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
crc32.update(way);
|
||||
REQUIRE(crc32().checksum() == 0x7676d0c2);
|
||||
REQUIRE(crc32().checksum() == 0x65f6ba91);
|
||||
}
|
||||
|
||||
TEST_CASE("build closed way") {
|
||||
|
||||
+2
-2
@@ -67,14 +67,14 @@ TEST_CASE("create node using builders") {
|
||||
osmium::builder::add_node(buffer, _id(5), _visible(true));
|
||||
osmium::builder::add_node(buffer, _id(6), _visible(false));
|
||||
|
||||
auto it = buffer.cbegin<osmium::Node>();
|
||||
auto it = buffer.select<osmium::Node>().cbegin();
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE(it++->visible());
|
||||
REQUIRE_FALSE(it++->visible());
|
||||
REQUIRE(it == buffer.cend<osmium::Node>());
|
||||
REQUIRE(it == buffer.select<osmium::Node>().cend());
|
||||
}
|
||||
|
||||
SECTION("order of attributes doesn't matter") {
|
||||
|
||||
+11
-11
@@ -96,7 +96,7 @@ SECTION("area_1outer_0inner") {
|
||||
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 2);
|
||||
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
|
||||
{
|
||||
std::string json {factory.create_multipolygon(area)};
|
||||
@@ -112,8 +112,8 @@ SECTION("area_1outer_1inner") {
|
||||
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 3);
|
||||
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
|
||||
REQUIRE(std::distance(area.cbegin<osmium::InnerRing>(), area.cend<osmium::InnerRing>()) == area.num_rings().second);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
{
|
||||
std::string json {factory.create_multipolygon(area)};
|
||||
@@ -129,24 +129,24 @@ SECTION("area_2outer_2inner") {
|
||||
|
||||
REQUIRE(area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 5);
|
||||
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
|
||||
REQUIRE(std::distance(area.cbegin<osmium::InnerRing>(), area.cend<osmium::InnerRing>()) == area.num_rings().second);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
int outer_ring=0;
|
||||
int inner_ring=0;
|
||||
for (auto it_outer = area.cbegin<osmium::OuterRing>(); it_outer != area.cend<osmium::OuterRing>(); ++it_outer) {
|
||||
for (const auto& outer : area.outer_rings()) {
|
||||
if (outer_ring == 0) {
|
||||
REQUIRE(it_outer->front().ref() == 1);
|
||||
REQUIRE(outer.front().ref() == 1);
|
||||
} else if (outer_ring == 1) {
|
||||
REQUIRE(it_outer->front().ref() == 100);
|
||||
REQUIRE(outer.front().ref() == 100);
|
||||
} else {
|
||||
REQUIRE(false);
|
||||
}
|
||||
for (auto it_inner = area.inner_ring_cbegin(it_outer); it_inner != area.inner_ring_cend(it_outer); ++it_inner) {
|
||||
for (const auto& inner : area.inner_rings(outer)) {
|
||||
if (outer_ring == 0 && inner_ring == 0) {
|
||||
REQUIRE(it_inner->front().ref() == 5);
|
||||
REQUIRE(inner.front().ref() == 5);
|
||||
} else if (outer_ring == 0 && inner_ring == 1) {
|
||||
REQUIRE(it_inner->front().ref() == 10);
|
||||
REQUIRE(inner.front().ref() == 10);
|
||||
} else {
|
||||
REQUIRE(false);
|
||||
}
|
||||
|
||||
+11
-6
@@ -1,6 +1,7 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/geos.hpp>
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
@@ -11,16 +12,16 @@ TEST_CASE("GEOS geometry factory - create point") {
|
||||
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
REQUIRE(-1 == point->getSRID());
|
||||
REQUIRE(4326 == point->getSRID());
|
||||
}
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create point with non-default srid") {
|
||||
osmium::geom::GEOSFactory<> factory(4326);
|
||||
TEST_CASE("GEOS geometry factory - create point in web mercator") {
|
||||
osmium::geom::GEOSFactory<osmium::geom::MercatorProjection> factory;
|
||||
|
||||
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
REQUIRE(4326 == point->getSRID());
|
||||
REQUIRE(Approx(356222.3705384755l) == point->getX());
|
||||
REQUIRE(Approx(467961.143605213l) == point->getY());
|
||||
REQUIRE(3857 == point->getSRID());
|
||||
}
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create point with externally created GEOS factory") {
|
||||
@@ -89,6 +90,7 @@ TEST_CASE("GEOS geometry factory - create area with one outer and no inner rings
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(0 == p0->getNumInteriorRing());
|
||||
|
||||
const geos::geom::LineString* l0e = p0->getExteriorRing();
|
||||
@@ -108,6 +110,7 @@ TEST_CASE("GEOS geometry factory - create area with one outer and one inner ring
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(1 == p0->getNumInteriorRing());
|
||||
|
||||
const geos::geom::LineString* l0e = p0->getExteriorRing();
|
||||
@@ -127,12 +130,14 @@ TEST_CASE("GEOS geometry factory - create area with two outer and two inner ring
|
||||
REQUIRE(2 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(2 == p0->getNumInteriorRing());
|
||||
|
||||
const geos::geom::LineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
|
||||
const geos::geom::Polygon* p1 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(1));
|
||||
REQUIRE(p1);
|
||||
REQUIRE(0 == p1->getNumInteriorRing());
|
||||
|
||||
const geos::geom::LineString* l1e = p1->getExteriorRing();
|
||||
|
||||
@@ -68,6 +68,7 @@ SECTION("area_1outer_0inner") {
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(0 == p0->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
@@ -86,6 +87,7 @@ SECTION("area_1outer_1inner") {
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(1 == p0->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
@@ -105,12 +107,14 @@ SECTION("area_2outer_2inner") {
|
||||
REQUIRE(2 == mp->getNumGeometries());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(2 == p0->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
|
||||
const OGRPolygon* p1 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(1));
|
||||
REQUIRE(p1);
|
||||
REQUIRE(0 == p1->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l1e = p1->getExteriorRing();
|
||||
|
||||
+89
-79
@@ -8,86 +8,96 @@
|
||||
|
||||
#include "test_tile_data.hpp"
|
||||
|
||||
TEST_CASE("Tile") {
|
||||
TEST_CASE("Tile from x0.0 y0.0 at zoom 0") {
|
||||
osmium::Location l{0.0, 0.0};
|
||||
|
||||
SECTION("x0.0 y0.0 zoom 0") {
|
||||
osmium::Location l(0.0, 0.0);
|
||||
|
||||
osmium::geom::Tile t(0, l);
|
||||
|
||||
REQUIRE(t.x == 0);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 0);
|
||||
}
|
||||
|
||||
SECTION("x180.0 y90.0 zoom 0") {
|
||||
osmium::Location l(180.0, 90.0);
|
||||
|
||||
osmium::geom::Tile t(0, l);
|
||||
|
||||
REQUIRE(t.x == 0);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 0);
|
||||
}
|
||||
|
||||
SECTION("x180.0 y90.0 zoom 4") {
|
||||
osmium::Location l(180.0, 90.0);
|
||||
|
||||
osmium::geom::Tile t(4, l);
|
||||
|
||||
REQUIRE(t.x == (1 << 4) - 1);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 4);
|
||||
}
|
||||
|
||||
SECTION("x0.0 y0.0 zoom 4") {
|
||||
osmium::Location l(0.0, 0.0);
|
||||
|
||||
osmium::geom::Tile t(4, l);
|
||||
|
||||
auto n = 1 << (4-1);
|
||||
REQUIRE(t.x == n);
|
||||
REQUIRE(t.y == n);
|
||||
REQUIRE(t.z == 4);
|
||||
}
|
||||
|
||||
SECTION("equality") {
|
||||
osmium::geom::Tile a(4, 3, 4);
|
||||
osmium::geom::Tile b(4, 3, 4);
|
||||
osmium::geom::Tile c(4, 4, 3);
|
||||
REQUIRE(a == b);
|
||||
REQUIRE(a != c);
|
||||
REQUIRE(b != c);
|
||||
}
|
||||
|
||||
SECTION("order") {
|
||||
osmium::geom::Tile a(2, 3, 4);
|
||||
osmium::geom::Tile b(4, 3, 4);
|
||||
osmium::geom::Tile c(4, 4, 3);
|
||||
osmium::geom::Tile d(4, 4, 2);
|
||||
REQUIRE(a < b);
|
||||
REQUIRE(a < c);
|
||||
REQUIRE(b < c);
|
||||
REQUIRE(d < c);
|
||||
}
|
||||
|
||||
SECTION("tilelist") {
|
||||
std::istringstream input_data(s);
|
||||
while (input_data) {
|
||||
double lon, lat;
|
||||
uint32_t x, y, zoom;
|
||||
input_data >> lon;
|
||||
input_data >> lat;
|
||||
input_data >> x;
|
||||
input_data >> y;
|
||||
input_data >> zoom;
|
||||
|
||||
osmium::Location l(lon, lat);
|
||||
osmium::geom::Tile t(zoom, l);
|
||||
REQUIRE(t.x == x);
|
||||
REQUIRE(t.y == y);
|
||||
}
|
||||
}
|
||||
osmium::geom::Tile t{0, l};
|
||||
|
||||
REQUIRE(t.x == 0);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 0);
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from x180.0 y90.0 at zoom 0") {
|
||||
osmium::Location l{180.0, 90.0};
|
||||
|
||||
osmium::geom::Tile t{0, l};
|
||||
|
||||
REQUIRE(t.x == 0);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 0);
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from x180.0 y90.0 at zoom 4") {
|
||||
osmium::Location l{180.0, 90.0};
|
||||
|
||||
osmium::geom::Tile t{4, l};
|
||||
|
||||
REQUIRE(t.x == (1 << 4) - 1);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 4);
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from x0.0 y0.0 at zoom 4") {
|
||||
osmium::Location l{0.0, 0.0};
|
||||
|
||||
osmium::geom::Tile t{4, l};
|
||||
|
||||
auto n = 1 << (4-1);
|
||||
REQUIRE(t.x == n);
|
||||
REQUIRE(t.y == n);
|
||||
REQUIRE(t.z == 4);
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from max values at zoom 4") {
|
||||
osmium::geom::Tile t{4u, 15u, 15u};
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from max values at zoom 30") {
|
||||
osmium::geom::Tile t{30u, (1u<<30) - 1, (1u<<30) - 1};
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Tile equality") {
|
||||
osmium::geom::Tile a{4, 3, 4};
|
||||
osmium::geom::Tile b{4, 3, 4};
|
||||
osmium::geom::Tile c{4, 4, 3};
|
||||
REQUIRE(a == b);
|
||||
REQUIRE(a != c);
|
||||
REQUIRE(b != c);
|
||||
}
|
||||
|
||||
TEST_CASE("Tile order") {
|
||||
osmium::geom::Tile a{4, 3, 4};
|
||||
osmium::geom::Tile b{6, 3, 4};
|
||||
osmium::geom::Tile c{6, 4, 3};
|
||||
osmium::geom::Tile d{6, 4, 2};
|
||||
REQUIRE(a < b);
|
||||
REQUIRE(a < c);
|
||||
REQUIRE(b < c);
|
||||
REQUIRE(d < c);
|
||||
}
|
||||
|
||||
TEST_CASE("Check a random list of tiles") {
|
||||
std::istringstream input_data(s);
|
||||
while (input_data) {
|
||||
double lon, lat;
|
||||
uint32_t x, y, zoom;
|
||||
input_data >> lon;
|
||||
input_data >> lat;
|
||||
input_data >> x;
|
||||
input_data >> y;
|
||||
input_data >> zoom;
|
||||
|
||||
osmium::Location l{lon, lat};
|
||||
osmium::geom::Tile t{zoom, l};
|
||||
REQUIRE(t.x == x);
|
||||
REQUIRE(t.y == y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+92
-72
@@ -1,115 +1,135 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
||||
TEST_CASE("WKB_Geometry_byte_order_dependent") {
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
|
||||
SECTION("point") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
SECTION("point") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string{"01010000009A99999999990940CDCCCCCCCCCC1040"} == wkb);
|
||||
}
|
||||
|
||||
SECTION("point_ewkb") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
|
||||
std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string{"0101000020E61000009A99999999990940CDCCCCCCCCCC1040"} == wkb);
|
||||
}
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl)};
|
||||
REQUIRE(std::string{"0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb);
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb);
|
||||
SECTION("point in web mercator") {
|
||||
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "010100000028706E7BF9BD1541B03E0D93E48F1C41");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb);
|
||||
SECTION("point in ewkb") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "0101000020E61000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb);
|
||||
SECTION("point in ewkb in web mercator") {
|
||||
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "0101000020110F000028706E7BF9BD1541B03E0D93E48F1C41");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("linestring_ewkb") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
std::string ewkb {factory.create_linestring(wnl)};
|
||||
REQUIRE(std::string{"0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == ewkb);
|
||||
}
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
SECTION("linestring_with_two_same_locations") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl)};
|
||||
REQUIRE(wkb == "0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_same_location(buffer);
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkb == "0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb);
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb);
|
||||
SECTION("linestring as ewkb") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
const std::string ewkb{factory.create_linestring(wnl)};
|
||||
REQUIRE(ewkb == "0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("linestring_with_undefined_location") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
SECTION("linestring with two same locations") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_undefined_location(buffer);
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
SECTION("unique forwards (default)") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
}
|
||||
|
||||
SECTION("unique backwards") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
SECTION("all forwards") {
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
|
||||
}
|
||||
|
||||
SECTION("all backwards") {
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("linestring with undefined location") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
const auto& wnl = create_test_wnl_undefined_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE("WKB_Geometry_byte_order_independent") {
|
||||
TEST_CASE("WKB geometry (byte-order-independent)") {
|
||||
|
||||
SECTION("empty_point") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
SECTION("empty point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("empty_linestring") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
SECTION("empty linestring") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+97
-100
@@ -1,136 +1,133 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
TEST_CASE("WKT_Geometry") {
|
||||
TEST_CASE("WKT geometry for point") {
|
||||
|
||||
SECTION("point") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string{"POINT(3.2 4.2)"} == wkt);
|
||||
SECTION("point") {
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(wkt == "POINT(3.2 4.2)");
|
||||
}
|
||||
|
||||
SECTION("empty point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
TEST_CASE("WKT geometry for point in ekwt") {
|
||||
osmium::geom::WKTFactory<> factory(7, osmium::geom::wkt_type::ewkt);
|
||||
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(wkt == "SRID=4326;POINT(3.2 4.2)");
|
||||
}
|
||||
|
||||
TEST_CASE("WKT geometry for point in ekwt in web mercator") {
|
||||
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory(2, osmium::geom::wkt_type::ewkt);
|
||||
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(wkt == "SRID=3857;POINT(356222.37 467961.14)");
|
||||
}
|
||||
|
||||
TEST_CASE("WKT geometry factory") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
SECTION("linestring") {
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
SECTION("unique forwards (default)") {
|
||||
const std::string wkt{factory.create_linestring(wnl)};
|
||||
REQUIRE(wkt == "LINESTRING(3.2 4.2,3.5 4.7,3.6 4.9)");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl)};
|
||||
REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.6 4.9)"} == wkt);
|
||||
SECTION("unique backwards") {
|
||||
const std::string wkt{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkt == "LINESTRING(3.6 4.9,3.5 4.7,3.2 4.2)");
|
||||
}
|
||||
|
||||
SECTION("all forwards") {
|
||||
const std::string wkt{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkt == "LINESTRING(3.2 4.2,3.5 4.7,3.5 4.7,3.6 4.9)");
|
||||
}
|
||||
|
||||
SECTION("all backwards") {
|
||||
const std::string wkt{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkt == "LINESTRING(3.6 4.9,3.5 4.7,3.5 4.7,3.2 4.2)");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.2 4.2)"} == wkt);
|
||||
SECTION("empty linestring") {
|
||||
const auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.5 4.7,3.6 4.9)"} == wkt);
|
||||
SECTION("linestring with two same locations") {
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
SECTION("unique forwards") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
|
||||
try {
|
||||
factory.create_linestring(wnl);
|
||||
} catch (const osmium::geometry_error& e) {
|
||||
REQUIRE(e.id() == 0);
|
||||
REQUIRE(std::string(e.what()) == "need at least two points for linestring");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("unique backwards") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
SECTION("all forwards") {
|
||||
const std::string wkt{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkt == "LINESTRING(3.5 4.7,3.5 4.7)");
|
||||
}
|
||||
|
||||
SECTION("all backwards") {
|
||||
const std::string wkt{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkt == "LINESTRING(3.5 4.7,3.5 4.7)");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.5 4.7,3.2 4.2)"} == wkt);
|
||||
}
|
||||
}
|
||||
SECTION("linestring with undefined location") {
|
||||
const auto& wnl = create_test_wnl_undefined_location(buffer);
|
||||
|
||||
SECTION("empty_linestring") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
SECTION("linestring_with_two_same_locations") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
|
||||
try {
|
||||
factory.create_linestring(wnl);
|
||||
} catch (osmium::geometry_error& e) {
|
||||
REQUIRE(e.id() == 0);
|
||||
REQUIRE(std::string(e.what()) == "need at least two points for linestring");
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
SECTION("area with one outer and no inner rings") {
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt);
|
||||
const std::string wkt{factory.create_multipolygon(area)};
|
||||
REQUIRE(wkt == "MULTIPOLYGON(((3.2 4.2,3.5 4.7,3.6 4.9,3.2 4.2)))");
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt);
|
||||
SECTION("area with one outer and one inner ring") {
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
const std::string wkt{factory.create_multipolygon(area)};
|
||||
REQUIRE(wkt == "MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,8 1,8 8,1 8,1 1)))");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("linestring_with_undefined_location") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
SECTION("area with two outer and two inner rings") {
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_undefined_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("area_1outer_0inner") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"MULTIPOLYGON(((3.2 4.2,3.5 4.7,3.6 4.9,3.2 4.2)))"} == wkt);
|
||||
const std::string wkt{factory.create_multipolygon(area)};
|
||||
REQUIRE(wkt == "MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,4 1,4 4,1 4,1 1),(5 5,5 7,7 7,5 5)),((10 10,11 10,11 11,10 11,10 10)))");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("area_1outer_1inner") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,8 1,8 8,1 8,1 1)))"} == wkt);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("area_2outer_2inner") {
|
||||
osmium::geom::WKTFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
{
|
||||
std::string wkt {factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,4 1,4 4,1 4,1 1),(5 5,5 7,7 7,5 5)),((10 10,11 10,11 11,10 11,10 10)))"} == wkt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/index/detail/tmpfile.hpp>
|
||||
#include <osmium/util/file.hpp>
|
||||
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
#include <osmium/index/map/sparse_file_array.hpp>
|
||||
|
||||
#include <osmium/index/node_locations_map.hpp>
|
||||
|
||||
TEST_CASE("File based index") {
|
||||
|
||||
int fd = osmium::detail::create_tmp_file();
|
||||
|
||||
REQUIRE(osmium::util::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);
|
||||
|
||||
SECTION("dense index") {
|
||||
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::util::file_size(fd) >= (6 * S));
|
||||
}
|
||||
|
||||
{
|
||||
index_type index(fd);
|
||||
REQUIRE(osmium::util::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);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("sparse index") {
|
||||
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::util::file_size(fd) >= (2 * S));
|
||||
}
|
||||
|
||||
{
|
||||
index_type index(fd);
|
||||
REQUIRE(osmium::util::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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-13
@@ -19,8 +19,8 @@ template <typename TIndex>
|
||||
void test_func_all(TIndex& index) {
|
||||
osmium::unsigned_object_id_type id1 = 12;
|
||||
osmium::unsigned_object_id_type id2 = 3;
|
||||
osmium::Location loc1(1.2, 4.5);
|
||||
osmium::Location loc2(3.5, -7.2);
|
||||
osmium::Location loc1{1.2, 4.5};
|
||||
osmium::Location loc2{3.5, -7.2};
|
||||
|
||||
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
|
||||
|
||||
@@ -29,6 +29,8 @@ void test_func_all(TIndex& index) {
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -37,8 +39,8 @@ template <typename TIndex>
|
||||
void test_func_real(TIndex& index) {
|
||||
osmium::unsigned_object_id_type id1 = 12;
|
||||
osmium::unsigned_object_id_type id2 = 3;
|
||||
osmium::Location loc1(1.2, 4.5);
|
||||
osmium::Location loc2(3.5, -7.2);
|
||||
osmium::Location loc1{1.2, 4.5};
|
||||
osmium::Location loc2{3.5, -7.2};
|
||||
|
||||
index.set(id1, loc1);
|
||||
index.set(id2, loc2);
|
||||
@@ -48,18 +50,26 @@ void test_func_real(TIndex& index) {
|
||||
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(100), osmium::not_found);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_CASE("IdToLocation") {
|
||||
|
||||
SECTION("Dummy") {
|
||||
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
|
||||
@@ -73,7 +83,7 @@ TEST_CASE("IdToLocation") {
|
||||
}
|
||||
|
||||
SECTION("DenseMemArray") {
|
||||
typedef osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
index1.reserve(1000);
|
||||
@@ -86,7 +96,7 @@ TEST_CASE("IdToLocation") {
|
||||
|
||||
#ifdef __linux__
|
||||
SECTION("DenseMmapArray") {
|
||||
typedef osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
@@ -99,7 +109,7 @@ TEST_CASE("IdToLocation") {
|
||||
#endif
|
||||
|
||||
SECTION("DenseFileArray") {
|
||||
typedef osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
@@ -111,7 +121,7 @@ TEST_CASE("IdToLocation") {
|
||||
#ifdef OSMIUM_WITH_SPARSEHASH
|
||||
|
||||
SECTION("SparseMemTable") {
|
||||
typedef osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
@@ -123,7 +133,7 @@ TEST_CASE("IdToLocation") {
|
||||
#endif
|
||||
|
||||
SECTION("SparseMemMap") {
|
||||
typedef osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
@@ -133,7 +143,7 @@ TEST_CASE("IdToLocation") {
|
||||
}
|
||||
|
||||
SECTION("SparseMemArray") {
|
||||
typedef osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location> index_type;
|
||||
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
|
||||
@@ -149,10 +159,10 @@ TEST_CASE("IdToLocation") {
|
||||
}
|
||||
|
||||
SECTION("Dynamic map choice") {
|
||||
typedef osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location> map_type;
|
||||
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();
|
||||
|
||||
std::vector<std::string> map_type_names = map_factory.map_types();
|
||||
const std::vector<std::string> map_type_names = map_factory.map_types();
|
||||
REQUIRE(map_type_names.size() >= 5);
|
||||
|
||||
for (const auto& map_type_name : map_type_names) {
|
||||
|
||||
+1075
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@ class MockDecompressor : public osmium::io::Decompressor {
|
||||
|
||||
public:
|
||||
|
||||
MockDecompressor(const std::string& fail_in) :
|
||||
explicit MockDecompressor(const std::string& fail_in) :
|
||||
Decompressor(),
|
||||
m_fail_in(fail_in) {
|
||||
if (m_fail_in == "constructor") {
|
||||
@@ -87,7 +87,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
|
||||
try {
|
||||
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
|
||||
REQUIRE(false);
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error constructor");
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
|
||||
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
|
||||
reader.read();
|
||||
REQUIRE(false);
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error first read");
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
|
||||
reader.read();
|
||||
reader.read();
|
||||
REQUIRE(false);
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error second read");
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
|
||||
reader.read();
|
||||
reader.close();
|
||||
REQUIRE(false);
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error close");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ TEST_CASE("Test Reader using MockParser") {
|
||||
try {
|
||||
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
|
||||
reader.header();
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error in header");
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ TEST_CASE("Test Reader using MockParser") {
|
||||
reader.header();
|
||||
try {
|
||||
reader.read();
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error in read");
|
||||
}
|
||||
reader.close();
|
||||
@@ -101,7 +101,7 @@ TEST_CASE("Test Reader using MockParser") {
|
||||
reader.header();
|
||||
try {
|
||||
throw std::runtime_error("error in user code");
|
||||
} catch (std::runtime_error& e) {
|
||||
} catch (const std::runtime_error& e) {
|
||||
REQUIRE(std::string{e.what()} == "error in user code");
|
||||
}
|
||||
REQUIRE(reader.read());
|
||||
|
||||
+38
-2
@@ -7,6 +7,8 @@ TEST_CASE("String store") {
|
||||
|
||||
SECTION("empty") {
|
||||
REQUIRE(ss.begin() == ss.end());
|
||||
REQUIRE(ss.get_chunk_size() == 100);
|
||||
REQUIRE(ss.get_chunk_count() == 1);
|
||||
}
|
||||
|
||||
SECTION("add zero-length string") {
|
||||
@@ -17,6 +19,8 @@ TEST_CASE("String store") {
|
||||
REQUIRE(s1 == *it);
|
||||
REQUIRE(std::string(*it) == "");
|
||||
REQUIRE(++it == ss.end());
|
||||
|
||||
REQUIRE(ss.get_chunk_count() == 1);
|
||||
}
|
||||
|
||||
SECTION("add strings") {
|
||||
@@ -30,6 +34,9 @@ TEST_CASE("String store") {
|
||||
REQUIRE(s1 == *it++);
|
||||
REQUIRE(s2 == *it++);
|
||||
REQUIRE(it == ss.end());
|
||||
|
||||
ss.clear();
|
||||
REQUIRE(ss.begin() == ss.end());
|
||||
}
|
||||
|
||||
SECTION("add zero-length string and longer strings") {
|
||||
@@ -45,9 +52,9 @@ TEST_CASE("String store") {
|
||||
}
|
||||
|
||||
SECTION("add many strings") {
|
||||
for (const char* teststring : {"a", "abc", "abcd", "abcde"}) {
|
||||
for (const char* teststring : {"", "a", "abc", "abcd", "abcde"}) {
|
||||
int i = 0;
|
||||
for (; i < 100; ++i) {
|
||||
for (; i < 200; ++i) {
|
||||
ss.add(teststring);
|
||||
}
|
||||
|
||||
@@ -57,7 +64,9 @@ TEST_CASE("String store") {
|
||||
}
|
||||
|
||||
REQUIRE(i == 0);
|
||||
REQUIRE(ss.get_chunk_count() > 1);
|
||||
ss.clear();
|
||||
REQUIRE(ss.get_chunk_count() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,5 +99,32 @@ TEST_CASE("String table") {
|
||||
REQUIRE(st.size() == 1);
|
||||
}
|
||||
|
||||
SECTION("add empty string") {
|
||||
REQUIRE(st.add("") == 1);
|
||||
REQUIRE(st.size() == 2);
|
||||
REQUIRE(st.add("") == 1);
|
||||
REQUIRE(st.size() == 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("lots of strings in string table so chunk overflows") {
|
||||
osmium::io::detail::StringTable st{100};
|
||||
REQUIRE(st.size() == 1);
|
||||
|
||||
const int n = 1000;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto s = std::to_string(i);
|
||||
st.add(s.c_str());
|
||||
}
|
||||
|
||||
REQUIRE(st.size() == n + 1);
|
||||
|
||||
auto it = st.begin();
|
||||
REQUIRE(std::string{} == *it++);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
REQUIRE(atoi(*it++) == i);
|
||||
}
|
||||
REQUIRE(it == st.end());
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -18,9 +18,9 @@ TEST_CASE("Writer") {
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer);
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
auto num = std::distance(buffer.cbegin<osmium::OSMObject>(), buffer.cend<osmium::OSMObject>());
|
||||
auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
|
||||
REQUIRE(num > 0);
|
||||
REQUIRE(buffer.cbegin<osmium::OSMObject>()->id() == 1);
|
||||
REQUIRE(buffer.select<osmium::OSMObject>().cbegin()->id() == 1);
|
||||
|
||||
std::string filename;
|
||||
|
||||
@@ -81,9 +81,8 @@ TEST_CASE("Writer") {
|
||||
osmium::memory::Buffer buffer_check = reader_check.read();
|
||||
REQUIRE(buffer_check);
|
||||
REQUIRE(buffer_check.committed() > 0);
|
||||
REQUIRE(std::distance(buffer_check.cbegin<osmium::OSMObject>(), buffer_check.cend<osmium::OSMObject>()) == num);
|
||||
REQUIRE(buffer_check.cbegin<osmium::OSMObject>()->id() == 1);
|
||||
|
||||
REQUIRE(buffer_check.select<osmium::OSMObject>().size() == num);
|
||||
REQUIRE(buffer_check.select<osmium::OSMObject>().cbegin()->id() == 1);
|
||||
}
|
||||
|
||||
SECTION("Interrupted writer after open") {
|
||||
|
||||
@@ -15,7 +15,7 @@ class MockCompressor : public osmium::io::Compressor {
|
||||
|
||||
public:
|
||||
|
||||
MockCompressor(const std::string& fail_in) :
|
||||
explicit MockCompressor(const std::string& fail_in) :
|
||||
Compressor(osmium::io::fsync::no),
|
||||
m_fail_in(fail_in) {
|
||||
if (m_fail_in == "constructor") {
|
||||
@@ -56,8 +56,7 @@ TEST_CASE("Write with mock compressor") {
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer);
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
auto num = std::distance(buffer.cbegin<osmium::OSMObject>(), buffer.cend<osmium::OSMObject>());
|
||||
REQUIRE(num > 0);
|
||||
REQUIRE(buffer.select<osmium::OSMObject>().size() > 0);
|
||||
|
||||
SECTION("fail on construction") {
|
||||
|
||||
|
||||
@@ -62,8 +62,7 @@ TEST_CASE("Test Writer with MockOutputFormat") {
|
||||
osmium::memory::Buffer buffer = reader.read();
|
||||
REQUIRE(buffer);
|
||||
REQUIRE(buffer.committed() > 0);
|
||||
auto num = std::distance(buffer.cbegin<osmium::OSMObject>(), buffer.cend<osmium::OSMObject>());
|
||||
REQUIRE(num > 0);
|
||||
REQUIRE(buffer.select<osmium::OSMObject>().size() > 0);
|
||||
|
||||
SECTION("error in header") {
|
||||
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ void check_filter(const osmium::TagList& tag_list, const TFilter filter, const s
|
||||
}
|
||||
|
||||
const osmium::TagList& make_tag_list(osmium::memory::Buffer& buffer, std::initializer_list<std::pair<const char*, const char*>> tags) {
|
||||
auto pos = osmium::builder::add_tag_list(buffer, osmium::builder::attr::_tags(tags));
|
||||
const auto pos = osmium::builder::add_tag_list(buffer, osmium::builder::attr::_tags(tags));
|
||||
return buffer.get<osmium::TagList>(pos);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ TEST_CASE("Filter") {
|
||||
{ "source", "GPS" } // no match
|
||||
});
|
||||
|
||||
std::vector<bool> results = { true, false, false };
|
||||
const std::vector<bool> results = { true, false, false };
|
||||
|
||||
check_filter(tag_list, filter, results);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ TEST_CASE("Filter") {
|
||||
{ "source", "GPS" }
|
||||
});
|
||||
|
||||
std::vector<bool> results = {true, true, false};
|
||||
const std::vector<bool> results = {true, true, false};
|
||||
|
||||
check_filter(tag_list, filter, results);
|
||||
}
|
||||
|
||||
+7
-1
@@ -167,10 +167,16 @@ TEST_CASE("create tag list") {
|
||||
});
|
||||
}
|
||||
|
||||
const osmium::TagList& tl = *buffer.begin<osmium::TagList>();
|
||||
const osmium::TagList& tl = *buffer.select<osmium::TagList>().cbegin();
|
||||
REQUIRE(osmium::item_type::tag_list == tl.type());
|
||||
REQUIRE(2 == tl.size());
|
||||
|
||||
REQUIRE(tl.has_key("highway"));
|
||||
REQUIRE_FALSE(tl.has_key("unknown"));
|
||||
REQUIRE(tl.has_tag("highway", "primary"));
|
||||
REQUIRE_FALSE(tl.has_tag("highway", "false"));
|
||||
REQUIRE_FALSE(tl.has_tag("foo", "bar"));
|
||||
|
||||
auto it = tl.begin();
|
||||
REQUIRE(std::string("highway") == it->key());
|
||||
REQUIRE(std::string("primary") == it->value());
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Define assert() to throw this error. This enables the tests to check that
|
||||
// the assert() fails.
|
||||
struct assert_error : public std::runtime_error {
|
||||
assert_error(const char* what_arg) : std::runtime_error(what_arg) {
|
||||
explicit assert_error(const char* what_arg) : std::runtime_error(what_arg) {
|
||||
}
|
||||
};
|
||||
#define assert(x) if (!(x)) { throw(assert_error(#x)); }
|
||||
|
||||
@@ -70,25 +70,3 @@ TEST_CASE("delta encode and decode") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("delta encode iterator") {
|
||||
std::vector<int> data = { 4, 5, 13, 22, 12 };
|
||||
|
||||
auto l = [](std::vector<int>::const_iterator it) -> int {
|
||||
return *it;
|
||||
};
|
||||
|
||||
typedef osmium::util::DeltaEncodeIterator<std::vector<int>::const_iterator, decltype(l), int> it_type;
|
||||
it_type it(data.begin(), data.end(), l);
|
||||
it_type end(data.end(), data.end(), l);
|
||||
|
||||
REQUIRE(*it == 4);
|
||||
++it;
|
||||
REQUIRE(*it++ == 1);
|
||||
REQUIRE(*it == 8);
|
||||
++it;
|
||||
REQUIRE(*it++ == 9);
|
||||
REQUIRE(*it == -10);
|
||||
++it;
|
||||
REQUIRE(it == end);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +33,10 @@ TEST_CASE("anonymous mapping") {
|
||||
mapping.unmap(); // second unmap is okay
|
||||
}
|
||||
|
||||
SECTION("memory mapping of zero length should work") {
|
||||
osmium::util::MemoryMapping mapping(0, osmium::util::MemoryMapping::mapping_mode::write_private);
|
||||
REQUIRE(mapping.get_addr() != nullptr);
|
||||
|
||||
REQUIRE(mapping.size() == osmium::util::get_pagesize());
|
||||
|
||||
REQUIRE(!!mapping);
|
||||
mapping.unmap();
|
||||
REQUIRE(!mapping);
|
||||
SECTION("memory mapping of zero length should fail") {
|
||||
REQUIRE_THROWS({
|
||||
osmium::util::MemoryMapping mapping(0, osmium::util::MemoryMapping::mapping_mode::write_private);
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("moving a memory mapping should work") {
|
||||
|
||||
Reference in New Issue
Block a user