Upgrade libosmium to v2.15.6
This commit is contained in:
+20
-13
@@ -131,20 +131,20 @@ add_unit_test(area test_area_id)
|
||||
add_unit_test(area test_assembler)
|
||||
add_unit_test(area test_node_ref_segment)
|
||||
|
||||
add_unit_test(osm test_area)
|
||||
add_unit_test(osm test_box)
|
||||
add_unit_test(osm test_changeset)
|
||||
add_unit_test(osm test_crc)
|
||||
add_unit_test(osm test_area ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_box ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_changeset ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_crc ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_entity_bits)
|
||||
add_unit_test(osm test_location)
|
||||
add_unit_test(osm test_metadata)
|
||||
add_unit_test(osm test_node)
|
||||
add_unit_test(osm test_node ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_node_ref)
|
||||
add_unit_test(osm test_object_comparisons)
|
||||
add_unit_test(osm test_relation)
|
||||
add_unit_test(osm test_relation ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(osm test_timestamp)
|
||||
add_unit_test(osm test_types_from_string)
|
||||
add_unit_test(osm test_way)
|
||||
add_unit_test(osm test_way ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
|
||||
add_unit_test(memory test_buffer_basics)
|
||||
add_unit_test(memory test_buffer_node)
|
||||
@@ -170,27 +170,34 @@ add_unit_test(geom test_tile)
|
||||
add_unit_test(geom test_wkb)
|
||||
add_unit_test(geom test_wkt)
|
||||
|
||||
add_unit_test(handler test_apply LIBS "${OSMIUM_XML_LIBRARIES};${OSMIUM_PBF_LIBRARIES}")
|
||||
add_unit_test(handler test_check_order_handler)
|
||||
add_unit_test(handler test_dynamic_handler)
|
||||
|
||||
add_unit_test(index test_dump_and_load_index)
|
||||
add_unit_test(index test_dump_sparse_as_array)
|
||||
add_unit_test(index test_file_based_index)
|
||||
add_unit_test(index test_id_set)
|
||||
add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND})
|
||||
add_unit_test(index test_file_based_index)
|
||||
add_unit_test(index test_nwr_array)
|
||||
add_unit_test(index test_object_pointer_collection)
|
||||
add_unit_test(index test_relations_map)
|
||||
|
||||
add_unit_test(io test_compression_factory)
|
||||
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_nocompression)
|
||||
add_unit_test(io test_output_utils)
|
||||
add_unit_test(io test_string_table)
|
||||
|
||||
add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES})
|
||||
add_unit_test(io test_gzip ENABLE_IF ${ZLIB_FOUND} LIBS ${ZLIB_LIBRARIES})
|
||||
add_unit_test(io test_opl_parser ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
add_unit_test(io test_pbf ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_PBF_LIBRARIES})
|
||||
add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES};${OSMIUM_PBF_LIBRARIES}")
|
||||
add_unit_test(io test_reader_fileformat ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
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 ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
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)
|
||||
add_unit_test(io test_writer ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES})
|
||||
add_unit_test(io test_writer_with_mock_compression ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES})
|
||||
add_unit_test(io test_writer_with_mock_encoder ENABLE_IF ${Threads_FOUND} LIBS ${OSMIUM_XML_LIBRARIES})
|
||||
|
||||
+7
-3
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Catch v1.12.1
|
||||
* Generated: 2018-03-02 21:17:41.036711
|
||||
* Catch v1.12.2
|
||||
* Generated: 2018-05-14 15:10:01.112442
|
||||
* ----------------------------------------------------------
|
||||
* This file has been merged from multiple headers. Please don't edit it directly
|
||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
@@ -6599,6 +6599,7 @@ namespace Catch {
|
||||
|
||||
#endif // not Windows
|
||||
|
||||
#include <cassert>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
@@ -8466,7 +8467,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
inline Version libraryVersion() {
|
||||
static Version version( 1, 12, 1, "", 0 );
|
||||
static Version version( 1, 12, 2, "", 0 );
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -9171,6 +9172,8 @@ std::string toString( std::nullptr_t ) {
|
||||
// #included from: catch_result_builder.hpp
|
||||
#define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
ResultBuilder::ResultBuilder( char const* macroName,
|
||||
@@ -10664,6 +10667,7 @@ namespace Catch {
|
||||
// #included from: ../reporters/catch_reporter_console.hpp
|
||||
#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
#include <cfloat>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
+33
-28
@@ -153,39 +153,44 @@ int main(int argc, char* argv[]) {
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
const std::string output_format{"SQLite"};
|
||||
const std::string input_filename{argv[1]};
|
||||
const std::string output_filename{"multipolygon.db"};
|
||||
try {
|
||||
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"}};
|
||||
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
|
||||
gdalcpp::Dataset dataset{output_format, output_filename, gdalcpp::SRS{}, {"SPATIALITE=TRUE"}};
|
||||
|
||||
osmium::area::ProblemReporterOGR problem_reporter{dataset};
|
||||
osmium::area::AssemblerLegacy::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::AssemblerLegacy> collector{assembler_config};
|
||||
osmium::area::ProblemReporterOGR problem_reporter{dataset};
|
||||
osmium::area::AssemblerLegacy::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::AssemblerLegacy> collector{assembler_config};
|
||||
|
||||
std::cerr << "Pass 1...\n";
|
||||
osmium::io::Reader reader1{input_filename};
|
||||
collector.read_relations(reader1);
|
||||
reader1.close();
|
||||
std::cerr << "Pass 1 done\n";
|
||||
std::cerr << "Pass 1...\n";
|
||||
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.ignore_errors();
|
||||
index_type 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::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
|
||||
osmium::apply(area_buffer, test_handler);
|
||||
}));
|
||||
reader2.close();
|
||||
std::cerr << "Pass 2 done\n";
|
||||
std::cerr << "Pass 2...\n";
|
||||
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);
|
||||
}));
|
||||
reader2.close();
|
||||
std::cerr << "Pass 2 done\n";
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-13
@@ -79,23 +79,28 @@ int main(int argc, char* argv[]) {
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
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());
|
||||
try {
|
||||
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"}};
|
||||
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
|
||||
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.ignore_errors();
|
||||
index_type 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();
|
||||
osmium::apply(reader, location_handler, handler);
|
||||
reader.close();
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ int main(int argc, char* argv[]) {
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return Catch::Session().run(argc, argv);
|
||||
try {
|
||||
return Catch::Session().run(argc, argv);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ static std::string read_file(const char* test_id) {
|
||||
assert(fd >= 0);
|
||||
|
||||
std::string input(10000, '\0');
|
||||
const auto n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
|
||||
const auto n = ::read(fd, &*input.begin(), 10000);
|
||||
assert(n >= 0);
|
||||
input.resize(static_cast<std::string::size_type>(n));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osm version="0.6" generator="osmium_change_tags">
|
||||
<osm version="0.6" upload="false" generator="osmium_change_tags">
|
||||
<node id="10" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.01" lon="7.11"/>
|
||||
<node id="11" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.04" lon="7.11"/>
|
||||
<node id="12" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.04" lon="7.14"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="CGImap 0.3.3 (31041 thorn-01.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
|
||||
<osm version="0.6" generator="CGImap 0.3.3 (31041 thorn-01.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="https://www.openstreetmap.org/copyright" license="https://opendatacommons.org/licenses/odbl/1-0/">
|
||||
<node id="5599384" visible="true" version="5" changeset="829716" timestamp="2009-03-18T17:16:26Z" user="burts" uid="97529" lat="51.0271601" lon="13.7252197"/>
|
||||
<node id="250384970" visible="true" version="3" changeset="855544" timestamp="2009-01-30T21:58:37Z" user="saftl" uid="7989" lat="51.0288568" lon="13.7248159">
|
||||
<tag k="created_by" v="JOSM"/>
|
||||
@@ -56,4 +56,4 @@
|
||||
<tag k="smoothness" v="good"/>
|
||||
<tag k="surface" v="asphalt"/>
|
||||
</way>
|
||||
</osm>
|
||||
</osm>
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#ifndef OSMIUM_TEST_CRC_HPP
|
||||
#define OSMIUM_TEST_CRC_HPP
|
||||
|
||||
#ifdef OSMIUM_TEST_CRC_USE_BOOST
|
||||
|
||||
/* Use the CRC32 implementation from boost. */
|
||||
#include <boost/crc.hpp>
|
||||
using crc_type = boost::crc_32_type;
|
||||
|
||||
#else
|
||||
|
||||
/* Use the CRC32 implementation from zlib. */
|
||||
#include <osmium/osm/crc_zlib.hpp>
|
||||
using crc_type = osmium::CRC_zlib;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // OSMIUM_TEST_CRC_HPP
|
||||
+24
@@ -2,6 +2,30 @@
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
|
||||
// This function counts the number of open file descriptors. It is used in
|
||||
// some tests to make sure that we are not leaking file descriptors.
|
||||
inline int count_fds() noexcept {
|
||||
int count = 0;
|
||||
for (int fd = 0; fd < 100; ++fd) {
|
||||
if (fcntl(fd, F_GETFD) == 0) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#else
|
||||
// Dummy for Windows which doesn't have fcntl
|
||||
inline int count_fds() noexcept {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline std::string with_data_dir(const char* filename) {
|
||||
const char* data_dir = getenv("OSMIUM_TEST_DATA_DIR");
|
||||
|
||||
|
||||
+377
-319
@@ -7,230 +7,293 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("create node using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create node using builders: add node with only id") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add node with only id") {
|
||||
const auto pos = osmium::builder::add_node(buffer, _id(22));
|
||||
const auto pos = osmium::builder::add_node(buffer, _id(22));
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 22);
|
||||
REQUIRE(node.version() == 0);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{});
|
||||
REQUIRE(node.changeset() == 0);
|
||||
REQUIRE(node.uid() == 0);
|
||||
REQUIRE(std::string{node.user()}.empty());
|
||||
REQUIRE(node.location() == osmium::Location{});
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
SECTION("add node with complete info but no tags") {
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(1),
|
||||
_version(17),
|
||||
_timestamp(osmium::Timestamp{"2015-01-01T10:20:30Z"}),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_location(loc),
|
||||
_user("foo")
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 0);
|
||||
}
|
||||
|
||||
SECTION("visible/deleted flag") {
|
||||
osmium::builder::add_node(buffer, _id(1), _deleted());
|
||||
osmium::builder::add_node(buffer, _id(2), _deleted(true));
|
||||
osmium::builder::add_node(buffer, _id(3), _deleted(false));
|
||||
osmium::builder::add_node(buffer, _id(4), _visible());
|
||||
osmium::builder::add_node(buffer, _id(5), _visible(true));
|
||||
osmium::builder::add_node(buffer, _id(6), _visible(false));
|
||||
|
||||
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.select<osmium::Node>().cend());
|
||||
}
|
||||
|
||||
SECTION("order of attributes doesn't matter") {
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_timestamp("2015-01-01T10:20:30Z"),
|
||||
_version(17),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_user(std::string{"foo"}),
|
||||
_id(1),
|
||||
_location(3.14, 1.59)
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 22);
|
||||
REQUIRE(node.version() == 0);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{});
|
||||
REQUIRE(node.changeset() == 0);
|
||||
REQUIRE(node.uid() == 0);
|
||||
REQUIRE(node.user()[0] == '\0');
|
||||
REQUIRE(node.location() == osmium::Location{});
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create node using builders: add node with complete info but no tags") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add tags using _tag") {
|
||||
std::pair<const char*, const char*> t1 = {"name", "Node Inn"};
|
||||
std::pair<std::string, std::string> t2 = {"phone", "+1-123-555-4567"};
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(1),
|
||||
_version(17),
|
||||
_timestamp(osmium::Timestamp{"2015-01-01T10:20:30Z"}),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_location(loc),
|
||||
_user("foo")
|
||||
);
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity", "restaurant"),
|
||||
_tag(t1),
|
||||
_tag(t2),
|
||||
_tag(std::string{"cuisine"}, std::string{"italian"})
|
||||
);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 0);
|
||||
}
|
||||
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
TEST_CASE("create node using builders: visible/deleted flag") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(std::string{it->value()} == "Node Inn");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(std::string{it->value()} == "+1-123-555-4567");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
osmium::builder::add_node(buffer, _id(1), _deleted());
|
||||
osmium::builder::add_node(buffer, _id(2), _deleted(true));
|
||||
osmium::builder::add_node(buffer, _id(3), _deleted(false));
|
||||
osmium::builder::add_node(buffer, _id(4), _visible());
|
||||
osmium::builder::add_node(buffer, _id(5), _visible(true));
|
||||
osmium::builder::add_node(buffer, _id(6), _visible(false));
|
||||
|
||||
SECTION("add tags using _tags from initializer list") {
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tags({{"amenity", "post_box"}})
|
||||
);
|
||||
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.select<osmium::Node>().cend());
|
||||
}
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
TEST_CASE("create node using builders: order of attributes doesn't matter") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
REQUIRE(node.id() == 3);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
const osmium::Location loc{3.14, 1.59};
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_timestamp("2015-01-01T10:20:30Z"),
|
||||
_version(17),
|
||||
_cid(21),
|
||||
_uid(222),
|
||||
_user(std::string{"foo"}),
|
||||
_id(1),
|
||||
_location(3.14, 1.59)
|
||||
);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
SECTION("add tags using _tags from TagList") {
|
||||
const auto pos1 = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tag("a", "d"),
|
||||
_tag("b", "e"),
|
||||
_tag("c", "f")
|
||||
);
|
||||
REQUIRE(node.id() == 1);
|
||||
REQUIRE(node.version() == 17);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-01-01T10:20:30Z"});
|
||||
REQUIRE(node.changeset() == 21);
|
||||
REQUIRE(node.uid() == 222);
|
||||
REQUIRE(std::string{node.user()} == "foo");
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
const auto& node1 = buffer.get<osmium::Node>(pos1);
|
||||
TEST_CASE("create node with tags using builders: add tags using _tag") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos2 = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tags(node1.tags())
|
||||
);
|
||||
std::pair<const char*, const char*> t1 = {"name", "Node Inn"};
|
||||
std::pair<std::string, std::string> t2 = {"phone", "+1-123-555-4567"};
|
||||
|
||||
const auto& node2 = buffer.get<osmium::Node>(pos2);
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity", "restaurant"),
|
||||
_tag(t1),
|
||||
_tag(t2),
|
||||
_tag(std::string{"cuisine"}, std::string{"italian"})
|
||||
);
|
||||
|
||||
REQUIRE(node2.id() == 4);
|
||||
REQUIRE(node2.tags().size() == 3);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
auto it = node2.tags().cbegin();
|
||||
REQUIRE(std::string{it++->key()} == "a");
|
||||
REQUIRE(std::string{it++->key()} == "b");
|
||||
REQUIRE(std::string{it++->key()} == "c");
|
||||
REQUIRE(it == node2.tags().cend());
|
||||
REQUIRE(std::distance(node2.cbegin(), node2.cend()) == 1);
|
||||
}
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
|
||||
SECTION("add tags using mixed tag sources") {
|
||||
const std::vector<pair_of_cstrings> tags = {
|
||||
{"t5", "t5"},
|
||||
{"t6", "t6"}
|
||||
};
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(std::string{it->value()} == "Node Inn");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(std::string{it->value()} == "+1-123-555-4567");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tag("t1", "t1"),
|
||||
_tags({{"t2", "t2"}, {"t3", "t3"}}),
|
||||
_tag("t4", "t4"),
|
||||
_tags(tags)
|
||||
);
|
||||
TEST_CASE("create node with tags using builders: add tags using _tag with equal sign in single cstring") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(2),
|
||||
_tag("amenity=restaurant"),
|
||||
_tag("name="),
|
||||
_tag("phone"),
|
||||
_tag(std::string{"cuisine=italian"})
|
||||
);
|
||||
|
||||
REQUIRE(node.id() == 4);
|
||||
REQUIRE(node.tags().size() == 6);
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "t1");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t2");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t3");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t4");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t5");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t6");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
REQUIRE(node.id() == 2);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "restaurant");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "name");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "phone");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "cuisine");
|
||||
REQUIRE(std::string{it->value()} == "italian");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _tags from initializer list") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tags({{"amenity", "post_box"}})
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 3);
|
||||
REQUIRE(node.tags().size() == 1);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _tags from TagList") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos1 = osmium::builder::add_node(buffer,
|
||||
_id(3),
|
||||
_tag("a", "d"),
|
||||
_tag("b", "e"),
|
||||
_tag("c", "f")
|
||||
);
|
||||
|
||||
const auto& node1 = buffer.get<osmium::Node>(pos1);
|
||||
|
||||
const auto pos2 = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tags(node1.tags())
|
||||
);
|
||||
|
||||
const auto& node2 = buffer.get<osmium::Node>(pos2);
|
||||
|
||||
REQUIRE(node2.id() == 4);
|
||||
REQUIRE(node2.tags().size() == 3);
|
||||
|
||||
auto it = node2.tags().cbegin();
|
||||
REQUIRE(std::string{it++->key()} == "a");
|
||||
REQUIRE(std::string{it++->key()} == "b");
|
||||
REQUIRE(std::string{it++->key()} == "c");
|
||||
REQUIRE(it == node2.tags().cend());
|
||||
REQUIRE(std::distance(node2.cbegin(), node2.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using mixed tag sources") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const std::vector<pair_of_cstrings> tags = {
|
||||
{"t5", "t5"},
|
||||
{"t6", "t6"}
|
||||
};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(4),
|
||||
_tag("t1=t1"),
|
||||
_tags({{"t2", "t2"}, {"t3", "t3"}}),
|
||||
_tag("t4", "t4"),
|
||||
_tags(tags)
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 4);
|
||||
REQUIRE(node.tags().size() == 6);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "t1");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t2");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t3");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t4");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t5");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "t6");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create node with tags using builders: add tags using _t with string") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto pos = osmium::builder::add_node(buffer,
|
||||
_id(5),
|
||||
_t("amenity=post_box,,empty,also_empty=,operator=Deutsche Post")
|
||||
);
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(pos);
|
||||
|
||||
REQUIRE(node.id() == 5);
|
||||
REQUIRE(node.tags().size() == 4);
|
||||
|
||||
auto it = node.tags().cbegin();
|
||||
REQUIRE(std::string{it->key()} == "amenity");
|
||||
REQUIRE(std::string{it->value()} == "post_box");
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "empty");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "also_empty");
|
||||
REQUIRE(it->value()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(std::string{it->key()} == "operator");
|
||||
REQUIRE(std::string{it->value()} == "Deutsche Post");
|
||||
++it;
|
||||
REQUIRE(it == node.tags().cend());
|
||||
REQUIRE(std::distance(node.cbegin(), node.cend()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("create way using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add way without nodes") {
|
||||
@@ -264,8 +327,6 @@ TEST_CASE("create way with nodes") {
|
||||
{ 8, osmium::Location{8.8, 0.8} }
|
||||
};
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer wbuffer{1024 * 10};
|
||||
osmium::builder::add_way(wbuffer,
|
||||
_id(1),
|
||||
@@ -383,170 +444,167 @@ TEST_CASE("create way with nodes") {
|
||||
REQUIRE(it == way.nodes().cend());
|
||||
}
|
||||
|
||||
TEST_CASE("create relation using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
TEST_CASE("create relation using builders: create relation") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("create relation") {
|
||||
osmium::builder::attr::member_type m{osmium::item_type::way, 113, "inner"};
|
||||
osmium::builder::attr::member_type m{osmium::item_type::way, 113, "inner"};
|
||||
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::node, 123, ""),
|
||||
_member(osmium::item_type::node, 132),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::builder::attr::member_type{osmium::item_type::way, 112, "inner"}),
|
||||
_member(m)
|
||||
);
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::node, 123, ""),
|
||||
_member(osmium::item_type::node, 132),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::builder::attr::member_type{osmium::item_type::way, 112, "inner"}),
|
||||
_member(m)
|
||||
);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 5);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 5);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
auto it = relation.members().begin();
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 132);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 132);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 113);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 113);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
SECTION("create relation member from existing relation member") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::item_type::way, 112, "inner")
|
||||
);
|
||||
TEST_CASE("create relation using builders: create relation member from existing relation member") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const auto& relation1 = buffer.get<osmium::Relation>(0);
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_member(osmium::item_type::way, 111, "outer"),
|
||||
_member(osmium::item_type::way, 112, "inner")
|
||||
);
|
||||
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(124),
|
||||
_member(*relation1.members().begin()),
|
||||
_members(std::next(relation1.members().begin()), relation1.members().end())
|
||||
);
|
||||
const auto& relation1 = buffer.get<osmium::Relation>(0);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(124),
|
||||
_member(*relation1.members().begin()),
|
||||
_members(std::next(relation1.members().begin()), relation1.members().end())
|
||||
);
|
||||
|
||||
REQUIRE(relation.id() == 124);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(relation.id() == 124);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
auto it = relation.members().begin();
|
||||
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 112);
|
||||
REQUIRE(std::string{it->role()} == "inner");
|
||||
++it;
|
||||
|
||||
SECTION("create relation with members from initializer list") {
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members({
|
||||
{osmium::item_type::node, 123, ""},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
})
|
||||
);
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
TEST_CASE("create relation using builders: create relation with members from initializer list") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
SECTION("create relation with members from iterators and some tags") {
|
||||
const std::vector<member_type> members = {
|
||||
{osmium::item_type::node, 123},
|
||||
const auto pos = osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members({
|
||||
{osmium::item_type::node, 123, ""},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
SECTION("using iterators") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members.begin(), members.end()),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
SECTION("using container") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
const auto& relation = buffer.get<osmium::Relation>(pos);
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 1);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(relation.tags().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 2);
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(std::string{it->role()}.empty());
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
TEST_CASE("create relation using builders: create relation with members from iterators and some tags") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
const std::vector<member_type> members = {
|
||||
{osmium::item_type::node, 123},
|
||||
{osmium::item_type::way, 111, "outer"}
|
||||
};
|
||||
|
||||
SECTION("using iterators") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members.begin(), members.end()),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
SECTION("using container") {
|
||||
osmium::builder::add_relation(buffer,
|
||||
_id(123),
|
||||
_members(members),
|
||||
_tag("a", "x"),
|
||||
_tag("b", "y")
|
||||
);
|
||||
}
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(0);
|
||||
|
||||
REQUIRE(relation.id() == 123);
|
||||
REQUIRE(relation.members().size() == 2);
|
||||
REQUIRE(relation.tags().size() == 2);
|
||||
REQUIRE(std::distance(relation.cbegin(), relation.cend()) == 2);
|
||||
|
||||
auto it = relation.members().begin();
|
||||
REQUIRE(it->type() == osmium::item_type::node);
|
||||
REQUIRE(it->ref() == 123);
|
||||
REQUIRE(it->role()[0] == '\0');
|
||||
++it;
|
||||
REQUIRE(it->type() == osmium::item_type::way);
|
||||
REQUIRE(it->ref() == 111);
|
||||
REQUIRE(std::string{it->role()} == "outer");
|
||||
++it;
|
||||
REQUIRE(it == relation.members().end());
|
||||
}
|
||||
|
||||
TEST_CASE("create area using builders") {
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
|
||||
SECTION("add area without rings") {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("create objects using builder") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
std::string user;
|
||||
@@ -441,3 +443,40 @@ TEST_CASE("set_user with length on changeset") {
|
||||
REQUIRE(std::string{"user"} == changeset.user());
|
||||
}
|
||||
|
||||
TEST_CASE("clear_user should clear the user field but nothing else") {
|
||||
osmium::memory::Buffer buffer{1024 * 10};
|
||||
std::string user = "user";
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder builder{buffer};
|
||||
builder.set_id(17)
|
||||
.set_visible(true)
|
||||
.set_version(1)
|
||||
.set_changeset(123)
|
||||
.set_uid(555)
|
||||
.set_timestamp("2015-07-01T00:00:01Z")
|
||||
.set_location(osmium::Location{1.2, 3.4})
|
||||
.set_user(user);
|
||||
builder.add_tags({{"highway", "primary"}, {"oneway", "yes"}});
|
||||
}
|
||||
|
||||
auto& node = buffer.get<osmium::Node>(buffer.commit());
|
||||
|
||||
REQUIRE(std::string{"user"} == node.user());
|
||||
|
||||
node.clear_user();
|
||||
|
||||
REQUIRE(std::string{""} == node.user());
|
||||
REQUIRE(node.uid() == 555);
|
||||
REQUIRE(node.tags().size() == 2);
|
||||
|
||||
auto it = node.tags().begin();
|
||||
REQUIRE(it->key() == std::string{"highway"});
|
||||
REQUIRE(it->value() == std::string{"primary"});
|
||||
++it;
|
||||
REQUIRE(it->key() == std::string{"oneway"});
|
||||
REQUIRE(it->value() == std::string{"yes"});
|
||||
++it;
|
||||
REQUIRE(it == node.tags().end());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <osmium/geom/coordinates.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Default constructed coordinates are invalid") {
|
||||
const osmium::geom::Coordinates c;
|
||||
REQUIRE_FALSE(c.valid());
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Projection using MercatorProjection class to WKT") {
|
||||
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory{2};
|
||||
|
||||
|
||||
+9
-9
@@ -5,18 +5,18 @@
|
||||
|
||||
#include <osmium/geom/geojson.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("GeoJSON point geometry") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
const std::string json{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
|
||||
}
|
||||
|
||||
SECTION("point") {
|
||||
const std::string json{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
TEST_CASE("GeoJSON empty point geometry") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
TEST_CASE("GeoJSON linestring geometry") {
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create point") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
|
||||
+9
-10
@@ -5,19 +5,18 @@
|
||||
|
||||
#include <osmium/geom/ogr.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
TEST_CASE("OGR point geometry") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
std::unique_ptr<OGRPoint> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
}
|
||||
|
||||
SECTION("point") {
|
||||
std::unique_ptr<OGRPoint> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
TEST_CASE("OGR empty point geometry") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
TEST_CASE("OGR linestring geometry") {
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ std::string to_wkb(const OGRGeometry* geometry) {
|
||||
std::string buffer;
|
||||
buffer.resize(geometry->WkbSize());
|
||||
|
||||
geometry->exportToWkb(wkbNDR, const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(buffer.data())));
|
||||
geometry->exportToWkb(wkbNDR, reinterpret_cast<unsigned char*>(&*buffer.begin()));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ TEST_CASE("compare WKB point against GDAL/OGR") {
|
||||
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
||||
osmium::geom::OGRFactory<> ogr_factory;
|
||||
|
||||
osmium::Location loc{3.2, 4.2};
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
const std::string wkb{wkb_factory.create_point(loc)};
|
||||
const std::unique_ptr<OGRPoint> geometry = ogr_factory.create_point(loc);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
|
||||
+29
-31
@@ -4,8 +4,6 @@
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/projection.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
TEST_CASE("Indentity Projection") {
|
||||
osmium::geom::IdentityProjection projection;
|
||||
REQUIRE(4326 == projection.epsg());
|
||||
@@ -76,35 +74,35 @@ TEST_CASE("Projection 3857") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MercatorProjection") {
|
||||
TEST_CASE("MercatorProjection: Zero coordinates") {
|
||||
osmium::geom::MercatorProjection projection;
|
||||
|
||||
SECTION("Zero coordinates") {
|
||||
const osmium::Location loc{0.0, 0.0};
|
||||
const osmium::geom::Coordinates c{0.0, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
SECTION("Max longitude") {
|
||||
const osmium::Location loc{180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
SECTION("Min longitude") {
|
||||
const osmium::Location loc{-180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{-20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
SECTION("Max latitude") {
|
||||
const osmium::Location loc{0.0, 85.0511288};
|
||||
const osmium::geom::Coordinates c{0.0, 20037508.34};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
const osmium::Location loc{0.0, 0.0};
|
||||
const osmium::geom::Coordinates c{0.0, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
TEST_CASE("MercatorProjection: Max longitude") {
|
||||
osmium::geom::MercatorProjection projection;
|
||||
const osmium::Location loc{180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
TEST_CASE("MercatorProjection: Min longitude") {
|
||||
osmium::geom::MercatorProjection projection;
|
||||
const osmium::Location loc{-180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{-20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
TEST_CASE("MercatorProjection: Max latitude") {
|
||||
osmium::geom::MercatorProjection projection;
|
||||
const osmium::Location loc{0.0, 85.0511288};
|
||||
const osmium::geom::Coordinates c{0.0, 20037508.34};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -41,7 +41,7 @@ TEST_CASE("Tile from x180.0 y90.0 at zoom 4") {
|
||||
|
||||
osmium::geom::Tile t{4, l};
|
||||
|
||||
REQUIRE(t.x == (1u << 4u) - 1);
|
||||
REQUIRE(t.x == (1U << 4U) - 1);
|
||||
REQUIRE(t.y == 0);
|
||||
REQUIRE(t.z == 4);
|
||||
REQUIRE(t.valid());
|
||||
@@ -52,7 +52,7 @@ TEST_CASE("Tile from x0.0 y0.0 at zoom 4") {
|
||||
|
||||
osmium::geom::Tile t{4, l};
|
||||
|
||||
const auto n = 1u << (4u - 1u);
|
||||
const auto n = 1U << (4U - 1U);
|
||||
REQUIRE(t.x == n);
|
||||
REQUIRE(t.y == n);
|
||||
REQUIRE(t.z == 4);
|
||||
@@ -60,12 +60,12 @@ TEST_CASE("Tile from x0.0 y0.0 at zoom 4") {
|
||||
}
|
||||
|
||||
TEST_CASE("Tile from max values at zoom 4") {
|
||||
osmium::geom::Tile t{4u, 15u, 15u};
|
||||
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 << 30u) - 1, (1u << 30u) - 1};
|
||||
osmium::geom::Tile t{30U, (1U << 30U) - 1, (1U << 30U) - 1};
|
||||
REQUIRE(t.valid());
|
||||
}
|
||||
|
||||
@@ -100,8 +100,12 @@ TEST_CASE("Tile order") {
|
||||
TEST_CASE("Check a random list of tiles") {
|
||||
std::istringstream input_data(s);
|
||||
while (input_data) {
|
||||
double lon, lat;
|
||||
uint32_t x, y, zoom;
|
||||
double lon;
|
||||
double lat;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t zoom;
|
||||
|
||||
input_data >> lon;
|
||||
input_data >> lat;
|
||||
input_data >> x;
|
||||
|
||||
+124
-124
@@ -6,134 +6,134 @@
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
#include <osmium/util/endian.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent), point in WKB") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
|
||||
SECTION("point") {
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
#ifndef OSMIUM_USE_SLOW_MERCATOR_PROJECTION
|
||||
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 == "010100000028706E7BF9BD1541D6A90093E48F1C41");
|
||||
}
|
||||
|
||||
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 == "0101000020110F000028706E7BF9BD1541D6A90093E48F1C41");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl)};
|
||||
REQUIRE(wkb == "0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkb == "0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
}
|
||||
|
||||
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 two same locations") {
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
SECTION("unique forwards (default)") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
|
||||
}
|
||||
|
||||
SECTION("unique backwards") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const 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), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE("WKB geometry (byte-order-independent)") {
|
||||
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
SECTION("empty point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
SECTION("empty linestring") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), const osmium::geometry_error&);
|
||||
}
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent), point in EWKB") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
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");
|
||||
}
|
||||
|
||||
#ifndef OSMIUM_USE_SLOW_MERCATOR_PROJECTION
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent), point in web mercator WKB") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
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.substr(0, 10) == "0101000000"); // little endian, point type
|
||||
REQUIRE(wkb.substr(10 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
|
||||
REQUIRE(wkb.substr(26 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent), point in web mercator EWKB") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
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.substr(0, 10) == "0101000020"); // little endian, point type (extended)
|
||||
REQUIRE(wkb.substr(10, 8) == "110F0000"); // SRID 3857
|
||||
REQUIRE(wkb.substr(18 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
|
||||
REQUIRE(wkb.substr(34 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl)};
|
||||
REQUIRE(wkb == "0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(wkb == "0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
|
||||
}
|
||||
|
||||
{
|
||||
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(wkb == "010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring as ewkb") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
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");
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring with two same locations") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
SECTION("unique forwards (default)") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
|
||||
}
|
||||
|
||||
SECTION("unique backwards") {
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const 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");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring with undefined location") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
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), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_CASE("WKB geometry (byte-order-independent) of empty point") {
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
|
||||
}
|
||||
|
||||
TEST_CASE("WKB geometry (byte-order-independent) of empty linestring") {
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), const osmium::geometry_error&);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), const osmium::geometry_error&);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("WKT geometry for point") {
|
||||
const osmium::geom::WKTFactory<> factory;
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <osmium/handler.hpp>
|
||||
#include <osmium/handler/node_locations_for_ways.hpp>
|
||||
#include <osmium/index/map/flex_mem.hpp>
|
||||
#include <osmium/io/any_compression.hpp>
|
||||
#include <osmium/io/pbf_input.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
TEST_CASE("apply with lambdas on reader") {
|
||||
osmium::io::File file{with_data_dir("t/relations/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
int count_n = 0;
|
||||
int count_w = 0;
|
||||
int count_r = 0;
|
||||
int count_o = 0;
|
||||
int count_a = 0;
|
||||
|
||||
osmium::apply(reader,
|
||||
[&](const osmium::Node& node) {
|
||||
count_n += node.version();
|
||||
},
|
||||
[&](const osmium::Way& way) {
|
||||
if (way.id() == 20) {
|
||||
++count_w;
|
||||
}
|
||||
},
|
||||
[&](const osmium::Relation& relation) {
|
||||
if (relation.id() > 30) {
|
||||
++count_r;
|
||||
}
|
||||
},
|
||||
[&](const osmium::OSMObject& object) {
|
||||
if (object.id() % 10 == 0) {
|
||||
++count_o;
|
||||
}
|
||||
},
|
||||
[&](const osmium::Way& way) {
|
||||
if (way.id() == 21) {
|
||||
++count_w;
|
||||
}
|
||||
},
|
||||
[&](const osmium::Area& /*area*/) {
|
||||
++count_a;
|
||||
}
|
||||
);
|
||||
|
||||
REQUIRE(count_n == 5);
|
||||
REQUIRE(count_w == 2);
|
||||
REQUIRE(count_r == 2);
|
||||
REQUIRE(count_o == 3);
|
||||
REQUIRE(count_a == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("apply with lambda on buffer") {
|
||||
osmium::io::File file{with_data_dir("t/relations/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
const auto buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
std::size_t members = 0;
|
||||
|
||||
osmium::apply(buffer, [&](const osmium::Relation& relation) {
|
||||
members += relation.members().size();
|
||||
});
|
||||
|
||||
REQUIRE(members == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("apply on non-const buffer can change data") {
|
||||
osmium::io::File file{with_data_dir("t/relations/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
auto buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
int nodes = 0;
|
||||
|
||||
osmium::apply(buffer,
|
||||
[&](osmium::Node& node) {
|
||||
node.set_version(123);
|
||||
},
|
||||
[&](const osmium::Node& node) {
|
||||
++nodes;
|
||||
REQUIRE(node.version() == 123);
|
||||
}
|
||||
);
|
||||
|
||||
REQUIRE(nodes == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("apply with handler and lambda") {
|
||||
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using location_handler_type = osmium::handler::NodeLocationsForWays<index_type>;
|
||||
|
||||
osmium::io::File file{with_data_dir("t/relations/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
auto buffer = reader.read();
|
||||
reader.close();
|
||||
|
||||
index_type index;
|
||||
location_handler_type location_handler{index};
|
||||
|
||||
int64_t x = 0;
|
||||
int64_t y = 0;
|
||||
|
||||
osmium::apply(buffer,
|
||||
[&](const osmium::Way& way) {
|
||||
REQUIRE_FALSE(way.nodes().front().location().valid());
|
||||
},
|
||||
location_handler,
|
||||
[&](const osmium::Way& way) {
|
||||
REQUIRE(way.nodes().front().location().valid());
|
||||
for (const auto& wn : way.nodes()) {
|
||||
x += wn.location().x();
|
||||
y += wn.location().y();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
REQUIRE(x == 44000000);
|
||||
REQUIRE(y == 40000000);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/index/detail/tmpfile.hpp>
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
#include <osmium/index/map/dense_mem_array.hpp>
|
||||
#include <osmium/index/map/dense_mmap_array.hpp>
|
||||
#include <osmium/index/map/sparse_file_array.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/index/map/sparse_mmap_array.hpp>
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
using dense_file_array = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
using sparse_file_array = osmium::index::map::SparseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
template <class TMemoryIndex, class TFileIndex>
|
||||
void test_index(std::function<void(TMemoryIndex&, const int)> dump_method) {
|
||||
const int fd = osmium::detail::create_tmp_file();
|
||||
REQUIRE(osmium::file_size(fd) == 0);
|
||||
const osmium::unsigned_object_id_type id1 = 12;
|
||||
const osmium::unsigned_object_id_type id2 = 3;
|
||||
const osmium::unsigned_object_id_type id3 = 7;
|
||||
const osmium::Location loc1{1.2, 4.5};
|
||||
const osmium::Location loc2{3.5, -7.2};
|
||||
const osmium::Location loc3{-12.7, 14.5};
|
||||
|
||||
TMemoryIndex index;
|
||||
index.set(id1, loc1);
|
||||
index.set(id2, loc2);
|
||||
index.set(id3, loc3);
|
||||
|
||||
// implementation of TMemoryIndex::sort should be empty if it is a dense index
|
||||
index.sort();
|
||||
dump_method(index, fd);
|
||||
|
||||
REQUIRE(osmium::file_size(fd) >= (3 * sizeof(typename TFileIndex::element_type)));
|
||||
|
||||
// load index from file
|
||||
TFileIndex file_index{fd};
|
||||
|
||||
// test retrievals
|
||||
REQUIRE(loc1 == file_index.get(id1));
|
||||
REQUIRE(loc2 == file_index.get(id2));
|
||||
REQUIRE(loc3 == file_index.get(id3));
|
||||
REQUIRE_THROWS_AS(file_index.get(5), const osmium::not_found&);
|
||||
REQUIRE_THROWS_AS(file_index.get(6), const osmium::not_found&);
|
||||
REQUIRE_THROWS_AS(file_index.get(200), const osmium::not_found&);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
using dense_mmap_array = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump DenseMmapArray, load as DenseFileArray") {
|
||||
auto dump_method = [](dense_mmap_array& index, const int fd) { index.dump_as_array(fd);};
|
||||
test_index<dense_mmap_array, dense_file_array>(dump_method);
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'DenseMmapArray' test case on this machine")
|
||||
#endif
|
||||
|
||||
using dense_mem_array = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump DenseMemArray, load as DenseFileArray") {
|
||||
auto dump_method = [](dense_mem_array& index, const int fd) { index.dump_as_array(fd);};
|
||||
test_index<dense_mem_array, dense_file_array>(dump_method);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
using sparse_mmap_array = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump SparseMmapArray, load as SparseFileArray") {
|
||||
auto dump_method = [](sparse_mmap_array& index, const int fd) { index.dump_as_list(fd);};
|
||||
test_index<sparse_mmap_array, sparse_file_array>(dump_method);
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'SparseMmapArray' test case on this machine")
|
||||
#endif
|
||||
|
||||
using sparse_mem_array = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump SparseMemArray, load as SparseFileArray") {
|
||||
auto dump_method = [](sparse_mem_array& index, const int fd) { index.dump_as_list(fd);};
|
||||
test_index<sparse_mem_array, sparse_file_array>(dump_method);
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/index/detail/tmpfile.hpp>
|
||||
#include <osmium/index/map/dense_file_array.hpp>
|
||||
#include <osmium/index/map/sparse_mem_array.hpp>
|
||||
#include <osmium/index/map/sparse_mmap_array.hpp>
|
||||
#include <osmium/index/node_locations_map.hpp>
|
||||
#include <osmium/osm/node_ref.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/util/file.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using dense_file_array = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
template <class TSparseIndex>
|
||||
void test_index() {
|
||||
const int fd = osmium::detail::create_tmp_file();
|
||||
constexpr const size_t value_size = sizeof(typename TSparseIndex::element_type::second_type);
|
||||
constexpr const size_t buffer_size = (10L * 1024L * 1024L) / value_size;
|
||||
|
||||
REQUIRE(osmium::file_size(fd) == 0);
|
||||
|
||||
std::vector<osmium::NodeRef> refs = {
|
||||
osmium::NodeRef{1, osmium::Location{1.2, 4.5}},
|
||||
osmium::NodeRef{6, osmium::Location{3.5, -7.2}},
|
||||
osmium::NodeRef{2 * buffer_size, osmium::Location{10.2, 64.5}},
|
||||
osmium::NodeRef{2 * buffer_size + 1, osmium::Location{39.5, -71.2}},
|
||||
osmium::NodeRef{3 * buffer_size - 1, osmium::Location{-1.2, 54.6}},
|
||||
osmium::NodeRef{3 * buffer_size, osmium::Location{-171.2, 9.3}},
|
||||
osmium::NodeRef{3 * buffer_size + 1, osmium::Location{-171.21, 9.26}},
|
||||
osmium::NodeRef{3 * buffer_size + 2, osmium::Location{-171.22, 9.25}},
|
||||
osmium::NodeRef{3 * buffer_size + 3, osmium::Location{-171.24, 9.23}},
|
||||
osmium::NodeRef{3 * buffer_size + 4, osmium::Location{-171.25, 9.22}},
|
||||
osmium::NodeRef{3 * buffer_size + 5, osmium::Location{-171.26, 9.21}}
|
||||
};
|
||||
|
||||
TSparseIndex sparse_index;
|
||||
for (const auto& r : refs) {
|
||||
sparse_index.set(r.ref(), r.location());
|
||||
}
|
||||
sparse_index.sort();
|
||||
sparse_index.dump_as_array(fd);
|
||||
|
||||
dense_file_array dense_index{fd};
|
||||
const auto max_id_in_refs = std::max_element(refs.begin(), refs.end())->ref();
|
||||
|
||||
// Array index should be as large as necessary.
|
||||
REQUIRE(osmium::file_size(fd) >= max_id_in_refs * sizeof(osmium::Location));
|
||||
|
||||
// check beyond largest ID
|
||||
REQUIRE_THROWS_AS(dense_index.get(max_id_in_refs + 1), const osmium::not_found&);
|
||||
|
||||
// check if written values can be retrieved
|
||||
for (const auto& r : refs) {
|
||||
REQUIRE(dense_index.get(r.ref()) == r.location());
|
||||
}
|
||||
|
||||
// check if all other values are invalid locations
|
||||
size_t invalid_count = 0;
|
||||
for (osmium::object_id_type id = 0; id <= max_id_in_refs; ++id) {
|
||||
if (!dense_index.get_noexcept(id).valid()) {
|
||||
++invalid_count;
|
||||
}
|
||||
}
|
||||
REQUIRE(invalid_count == max_id_in_refs - refs.size() + 1);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
using sparse_mmap_array = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump SparseMmapArray as array and load it as DenseFileArray") {
|
||||
test_index<sparse_mmap_array>();
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'SparseMmapArray' test case on this machine")
|
||||
#endif
|
||||
|
||||
using sparse_mem_array = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
TEST_CASE("Dump SparseMemArray as array and load it as DenseFileArray") {
|
||||
test_index<sparse_mem_array>();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/util/file.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
TEST_CASE("File based dense index") {
|
||||
const int fd = osmium::detail::create_tmp_file();
|
||||
|
||||
|
||||
+101
-11
@@ -43,15 +43,42 @@ TEST_CASE("Basic functionality of IdSetDense") {
|
||||
REQUIRE(s.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Copying IdSetDense") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s1;
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s2;
|
||||
|
||||
REQUIRE(s1.empty());
|
||||
REQUIRE(s2.empty());
|
||||
|
||||
s1.set(17);
|
||||
s1.set(28);
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.size() == 2);
|
||||
|
||||
s2 = s1;
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.get(28));
|
||||
REQUIRE(s1.size() == 2);
|
||||
REQUIRE(s2.get(17));
|
||||
REQUIRE(s2.get(28));
|
||||
REQUIRE(s2.size() == 2);
|
||||
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s3{s1};
|
||||
REQUIRE(s3.get(17));
|
||||
REQUIRE(s3.get(28));
|
||||
REQUIRE(s3.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Iterating over IdSetDense") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
s.set(7);
|
||||
s.set(35);
|
||||
s.set(35);
|
||||
s.set(20);
|
||||
s.set(1ull << 33u);
|
||||
s.set(1ULL << 33U);
|
||||
s.set(21);
|
||||
s.set((1ull << 27u) + 13u);
|
||||
s.set((1ULL << 27U) + 13U);
|
||||
|
||||
REQUIRE(s.size() == 6);
|
||||
|
||||
@@ -69,10 +96,10 @@ TEST_CASE("Iterating over IdSetDense") {
|
||||
REQUIRE(*it == 35);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == (1ull << 27u) + 13u);
|
||||
REQUIRE(*it == (1ULL << 27U) + 13U);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 1ull << 33u);
|
||||
REQUIRE(*it == 1ULL << 33U);
|
||||
++it;
|
||||
REQUIRE(it == s.end());
|
||||
}
|
||||
@@ -98,10 +125,10 @@ TEST_CASE("Large gap") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
|
||||
s.set(3);
|
||||
s.set(1u << 30u);
|
||||
s.set(1U << 30U);
|
||||
|
||||
REQUIRE(s.get(1u << 30u));
|
||||
REQUIRE_FALSE(s.get(1u << 29u));
|
||||
REQUIRE(s.get(1U << 30U));
|
||||
REQUIRE_FALSE(s.get(1U << 29U));
|
||||
}
|
||||
|
||||
TEST_CASE("Basic functionality of IdSetSmall") {
|
||||
@@ -120,20 +147,55 @@ TEST_CASE("Basic functionality of IdSetSmall") {
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
const auto size = s.size();
|
||||
|
||||
// Setting the same id as last time doesn't grow the size
|
||||
s.set(28);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
REQUIRE(size == s.size());
|
||||
|
||||
s.clear();
|
||||
REQUIRE(s.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Copying IdSetSmall") {
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s1;
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s2;
|
||||
|
||||
REQUIRE(s1.empty());
|
||||
REQUIRE(s2.empty());
|
||||
|
||||
s1.set(17);
|
||||
s1.set(28);
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.size() == 2);
|
||||
|
||||
s2 = s1;
|
||||
REQUIRE(s1.get(17));
|
||||
REQUIRE(s1.get(28));
|
||||
REQUIRE(s1.size() == 2);
|
||||
REQUIRE(s2.get(17));
|
||||
REQUIRE(s2.get(28));
|
||||
REQUIRE(s2.size() == 2);
|
||||
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s3{s1};
|
||||
REQUIRE(s3.get(17));
|
||||
REQUIRE(s3.get(28));
|
||||
REQUIRE(s3.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Iterating over IdSetSmall") {
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
|
||||
s.set(7);
|
||||
s.set(35);
|
||||
s.set(35);
|
||||
s.set(20);
|
||||
s.set(1ull << 33u);
|
||||
s.set(1ULL << 33U);
|
||||
s.set(21);
|
||||
s.set((1ull << 27u) + 13u);
|
||||
s.set((1ULL << 27U) + 13U);
|
||||
|
||||
// needs to be called before size() and iterator will work properly
|
||||
s.sort_unique();
|
||||
@@ -154,11 +216,39 @@ TEST_CASE("Iterating over IdSetSmall") {
|
||||
REQUIRE(*it == 35);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == (1ull << 27u) + 13u);
|
||||
REQUIRE(*it == (1ULL << 27U) + 13U);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 1ull << 33u);
|
||||
REQUIRE(*it == 1ULL << 33U);
|
||||
++it;
|
||||
REQUIRE(it == s.end());
|
||||
}
|
||||
|
||||
TEST_CASE("Merge two IdSetSmall") {
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s1;
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s2;
|
||||
|
||||
s1.set(23);
|
||||
s1.set(2);
|
||||
s1.set(7);
|
||||
s1.set(55);
|
||||
s1.set(42);
|
||||
s1.set(7);
|
||||
|
||||
s2.set(2);
|
||||
s2.set(32);
|
||||
s2.set(8);
|
||||
s2.set(55);
|
||||
s2.set(1);
|
||||
|
||||
s1.sort_unique();
|
||||
REQUIRE(s1.size() == 5);
|
||||
s2.sort_unique();
|
||||
REQUIRE(s2.size() == 5);
|
||||
s1.merge_sorted(s2);
|
||||
REQUIRE(s1.size() == 8);
|
||||
|
||||
const auto ids = {1, 2, 7, 8, 23, 32, 42, 55};
|
||||
REQUIRE(std::equal(s1.cbegin(), s1.cend(), ids.begin()));
|
||||
}
|
||||
|
||||
|
||||
+19
-1
@@ -14,6 +14,10 @@
|
||||
#include <osmium/osm/location.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static_assert(osmium::index::empty_value<osmium::Location>() == osmium::Location{}, "Empty value for location is wrong");
|
||||
|
||||
template <typename TIndex>
|
||||
@@ -126,7 +130,7 @@ TEST_CASE("Map Id to location: DenseMmapArray") {
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'DenseMapMmap' test case on this machine")
|
||||
# pragma message("not running 'DenseMmapArray' test case on this machine")
|
||||
#endif
|
||||
|
||||
TEST_CASE("Map Id to location: DenseFileArray") {
|
||||
@@ -179,6 +183,20 @@ TEST_CASE("Map Id to location: SparseMemArray") {
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
TEST_CASE("Map Id to location: SparseMmapArray") {
|
||||
using index_type = osmium::index::map::SparseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'SparseMmapArray' test case on this machine")
|
||||
#endif
|
||||
|
||||
TEST_CASE("Map Id to location: FlexMem sparse") {
|
||||
using index_type = osmium::index::map::FlexMem<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/index/nwr_array.hpp>
|
||||
|
||||
TEST_CASE("nwr_array") {
|
||||
osmium::nwr_array<int> a;
|
||||
a(osmium::item_type::node) = 1;
|
||||
a(osmium::item_type::way) = 2;
|
||||
a(osmium::item_type::relation) = 3;
|
||||
|
||||
REQUIRE(a(osmium::item_type::node) == 1);
|
||||
REQUIRE(a(osmium::item_type::way) == 2);
|
||||
REQUIRE(a(osmium::item_type::relation) == 3);
|
||||
|
||||
auto it = a.cbegin();
|
||||
REQUIRE(*it++ == 1);
|
||||
REQUIRE(*it++ == 2);
|
||||
REQUIRE(*it++ == 3);
|
||||
REQUIRE(it == a.cend());
|
||||
}
|
||||
|
||||
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
n1 v1 dV c1 t2014-01-01T00:00:00Z i1 utest T x1.02 y1.02
|
||||
+113
-7
@@ -3,15 +3,63 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <osmium/io/bzip2_compression.hpp>
|
||||
#include <osmium/io/detail/read_write.hpp>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Invalid file descriptor of bzip2-compressed file") {
|
||||
REQUIRE_THROWS_AS(osmium::io::Bzip2Decompressor{-1}, const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Non-open file descriptor of bzip2-compressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
REQUIRE_THROWS_AS(osmium::io::Bzip2Decompressor{12345}, const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Empty bzip2-compressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/empty_file");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::Bzip2Decompressor decomp{fd};
|
||||
REQUIRE_THROWS_AS(decomp.read(), const osmium::bzip2_error&);
|
||||
decomp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read bzip2-compressed file") {
|
||||
const std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
|
||||
const int count = count_fds();
|
||||
|
||||
const int fd = ::open(input_file.c_str(), O_RDONLY);
|
||||
const std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
std::string all;
|
||||
{
|
||||
osmium::io::Bzip2Decompressor decomp{fd};
|
||||
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
|
||||
size += data.size();
|
||||
all += data;
|
||||
}
|
||||
decomp.close();
|
||||
}
|
||||
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read bzip2-compressed file without explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
@@ -24,7 +72,65 @@ TEST_CASE("Read bzip2-compressed file") {
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(9 == size);
|
||||
REQUIRE("TESTDATA\n" == all);
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Corrupted bzip2-compressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/corrupt_data_bzip2.txt.bz2");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::Bzip2Decompressor decomp{fd};
|
||||
REQUIRE_THROWS_AS(decomp.read(), const osmium::bzip2_error&);
|
||||
decomp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Invalid file descriptor for bzip2-compressed file") {
|
||||
REQUIRE_THROWS_AS(osmium::io::Bzip2Compressor(-1, osmium::io::fsync::yes), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Non-open file descriptor for bzip2-compressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
REQUIRE_THROWS_AS(osmium::io::Bzip2Compressor(12345, osmium::io::fsync::yes), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Write bzip2-compressed file with explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_gzip_out.txt.bz2";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::Bzip2Compressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
comp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) > 10);
|
||||
}
|
||||
|
||||
TEST_CASE("Write bzip2-compressed file with implicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_gzip_out.txt.bz2";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
{
|
||||
osmium::io::Bzip2Compressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
}
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) > 10);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
#include <osmium/io/file.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
TEST_CASE("Default file format") {
|
||||
const osmium::io::File f;
|
||||
@@ -294,7 +295,7 @@ TEST_CASE("URL without format") {
|
||||
}
|
||||
|
||||
TEST_CASE("URL without format and filename") {
|
||||
const osmium::io::File f{"http://planet.osm.org/pbf/planet-latest.osm.pbf"};
|
||||
const osmium::io::File f{"https://planet.osm.org/pbf/planet-latest.osm.pbf"};
|
||||
REQUIRE(osmium::io::file_format::pbf == f.format());
|
||||
REQUIRE(osmium::io::file_compression::none == f.compression());
|
||||
REQUIRE_FALSE(f.has_multiple_object_versions());
|
||||
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <osmium/io/detail/read_write.hpp>
|
||||
#include <osmium/io/gzip_compression.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Invalid file descriptor of gzip-compressed file") {
|
||||
REQUIRE_THROWS_AS(osmium::io::GzipDecompressor{-1}, const osmium::gzip_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Non-open file descriptor of gzip-compressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
osmium::io::GzipDecompressor decomp{12345};
|
||||
REQUIRE_THROWS_AS(decomp.read(), const osmium::gzip_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Empty gzip-compressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/empty_file");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::GzipDecompressor decomp{fd};
|
||||
REQUIRE(decomp.read().empty());
|
||||
decomp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read gzip-compressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/data_gzip.txt.gz");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
std::string all;
|
||||
{
|
||||
osmium::io::GzipDecompressor decomp{fd};
|
||||
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
|
||||
size += data.size();
|
||||
all += data;
|
||||
}
|
||||
decomp.close();
|
||||
}
|
||||
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read gzip-compressed file without explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/data_gzip.txt.gz");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
std::string all;
|
||||
{
|
||||
osmium::io::GzipDecompressor decomp{fd};
|
||||
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
|
||||
size += data.size();
|
||||
all += data;
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Corrupted gzip-compressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/corrupt_data_gzip.txt.gz");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::GzipDecompressor decomp{fd};
|
||||
decomp.read();
|
||||
REQUIRE_THROWS_AS(decomp.close(), const osmium::gzip_error&);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Invalid file descriptor for gzip-compressed file") {
|
||||
REQUIRE_THROWS_AS(osmium::io::GzipCompressor(-1, osmium::io::fsync::yes), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Non-open file descriptor for gzip-compressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
REQUIRE_THROWS_AS(osmium::io::GzipCompressor(12345, osmium::io::fsync::yes), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Write gzip-compressed file with explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_gzip_out.txt.gz";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::GzipCompressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
comp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) > 10);
|
||||
}
|
||||
|
||||
TEST_CASE("Write gzip-compressed file with implicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_gzip_out.txt.gz";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
{
|
||||
osmium::io::GzipCompressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
}
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) > 10);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <osmium/io/compression.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Invalid file descriptor of uncompressed file") {
|
||||
osmium::io::NoDecompressor decomp{-1};
|
||||
REQUIRE_THROWS_AS(decomp.read(), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Non-open file descriptor of uncompressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
osmium::io::NoDecompressor decomp{12345};
|
||||
REQUIRE_THROWS_AS(decomp.read(), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Empty uncompressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/empty_file");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::NoDecompressor decomp{fd};
|
||||
REQUIRE(decomp.read().empty());
|
||||
decomp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read uncompressed file") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/data.txt");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
std::string all;
|
||||
{
|
||||
osmium::io::NoDecompressor decomp{fd};
|
||||
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
|
||||
size += data.size();
|
||||
all += data;
|
||||
}
|
||||
decomp.close();
|
||||
}
|
||||
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Read uncompressed file without explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string input_file = with_data_dir("t/io/data.txt");
|
||||
const int fd = osmium::io::detail::open_for_reading(input_file);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
size_t size = 0;
|
||||
std::string all;
|
||||
{
|
||||
osmium::io::NoDecompressor decomp{fd};
|
||||
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
|
||||
size += data.size();
|
||||
all += data;
|
||||
}
|
||||
}
|
||||
|
||||
REQUIRE(size >= 9);
|
||||
all.resize(8);
|
||||
REQUIRE("TESTDATA" == all);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Invalid file descriptor for uncompressed file") {
|
||||
osmium::io::NoCompressor comp{-1, osmium::io::fsync::yes};
|
||||
REQUIRE_THROWS_AS(comp.write("foo"), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Compressor: Non-open file descriptor for uncompressed file") {
|
||||
// 12345 is just a random file descriptor that should not be open
|
||||
osmium::io::NoCompressor comp{12345, osmium::io::fsync::yes};
|
||||
REQUIRE_THROWS_AS(comp.write("foo"), const std::system_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("Write uncompressed file with explicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_uncompressed_out.txt";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
osmium::io::NoCompressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
comp.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("Write uncompressed file with implicit close") {
|
||||
const int count = count_fds();
|
||||
|
||||
const std::string output_file = "test_uncompressed_out.txt";
|
||||
const int fd = osmium::io::detail::open_for_writing(output_file, osmium::io::overwrite::allow);
|
||||
REQUIRE(fd > 0);
|
||||
|
||||
{
|
||||
osmium::io::NoCompressor comp{fd, osmium::io::fsync::yes};
|
||||
comp.write("foo");
|
||||
}
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE(osmium::file_size(output_file) == 3);
|
||||
}
|
||||
|
||||
+51
-1
@@ -8,6 +8,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace oid = osmium::io::detail;
|
||||
|
||||
@@ -717,7 +720,6 @@ TEST_CASE("Parse node") {
|
||||
REQUIRE(node.location() == loc);
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Parse way") {
|
||||
@@ -1041,6 +1043,54 @@ TEST_CASE("Parse line with external interface") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("Duplicate attributes") {
|
||||
osmium::memory::Buffer buffer{1024};
|
||||
REQUIRE_THROWS_WITH(osmium::opl_parse("n123 v1 v2", buffer),
|
||||
"OPL error: Duplicate attribute: version (v) on line 0 column 0");
|
||||
REQUIRE_THROWS_WITH(osmium::opl_parse("w123 c1 c2", buffer),
|
||||
"OPL error: Duplicate attribute: changeset_id (c) on line 0 column 0");
|
||||
REQUIRE_THROWS_WITH(osmium::opl_parse("r123 Ta=b Tc=d", buffer),
|
||||
"OPL error: Duplicate attribute: tags (T) on line 0 column 0");
|
||||
REQUIRE_THROWS_WITH(osmium::opl_parse("c123 k1 k2", buffer),
|
||||
"OPL error: Duplicate attribute: num_changes (k) on line 0 column 0");
|
||||
|
||||
for (const char *attr : {"v1", "dV", "c2", "t2020-01-01T00:00:01Z", "i3", "utest", "Ta=b", "x1.0", "y2.0"}) {
|
||||
auto line = std::string{"n1 "} + attr;
|
||||
REQUIRE_NOTHROW(osmium::opl_parse(line.c_str(), buffer));
|
||||
line += " ";
|
||||
line += attr;
|
||||
REQUIRE_THROWS_AS(osmium::opl_parse(line.c_str(), buffer),
|
||||
const osmium::opl_error &);
|
||||
}
|
||||
|
||||
for (const char *attr : {"v1", "dV", "c2", "t2020-01-01T00:00:01Z", "i3", "utest", "Ta=b", "Nn1"}) {
|
||||
auto line = std::string{"w1 "} + attr;
|
||||
REQUIRE_NOTHROW(osmium::opl_parse(line.c_str(), buffer));
|
||||
line += " ";
|
||||
line += attr;
|
||||
REQUIRE_THROWS_AS(osmium::opl_parse(line.c_str(), buffer),
|
||||
const osmium::opl_error &);
|
||||
}
|
||||
|
||||
for (const char *attr : {"v1", "dV", "c2", "t2020-01-01T00:00:01Z", "i3", "utest", "Ta=b", "Mn1@foo"}) {
|
||||
auto line = std::string{"r1 "} + attr;
|
||||
REQUIRE_NOTHROW(osmium::opl_parse(line.c_str(), buffer));
|
||||
line += " ";
|
||||
line += attr;
|
||||
REQUIRE_THROWS_AS(osmium::opl_parse(line.c_str(), buffer),
|
||||
const osmium::opl_error &);
|
||||
}
|
||||
|
||||
for (const char *attr : {"k1", "s2020-01-01T00:00:01Z", "e2020-01-01T00:00:02Z", "d1", "i3", "utest", "Ta=b", "x1", "y2", "X3", "Y4"}) {
|
||||
auto line = std::string{"c1 "} + attr;
|
||||
REQUIRE_NOTHROW(osmium::opl_parse(line.c_str(), buffer));
|
||||
line += " ";
|
||||
line += attr;
|
||||
REQUIRE_THROWS_AS(osmium::opl_parse(line.c_str(), buffer),
|
||||
const osmium::opl_error &);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Parse OPL using Reader") {
|
||||
osmium::io::File file{with_data_dir("t/io/data.opl")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
+175
-115
@@ -2,151 +2,211 @@
|
||||
|
||||
#include <osmium/io/detail/string_util.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("output formatted") {
|
||||
|
||||
TEST_CASE("output formatted with small results") {
|
||||
std::string out;
|
||||
|
||||
SECTION("small results") {
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%d", 17);
|
||||
REQUIRE(out == "17");
|
||||
}
|
||||
|
||||
SECTION("several parameters") {
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%d %s", 17, "foo");
|
||||
REQUIRE(out == "17 foo");
|
||||
|
||||
}
|
||||
|
||||
SECTION("string already containing something") {
|
||||
out += "foo";
|
||||
osmium::io::detail::append_printf_formatted_string(out, " %d", 23);
|
||||
REQUIRE(out == "foo 23");
|
||||
}
|
||||
|
||||
SECTION("large results") {
|
||||
const char* str =
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%s", str);
|
||||
|
||||
REQUIRE(out == str);
|
||||
}
|
||||
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%d", 17);
|
||||
REQUIRE(out == "17");
|
||||
}
|
||||
|
||||
TEST_CASE("UTF8 encoding") {
|
||||
TEST_CASE("output formatted with several parameters in format string") {
|
||||
std::string out;
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%d %s", 17, "foo");
|
||||
REQUIRE(out == "17 foo");
|
||||
}
|
||||
|
||||
TEST_CASE("output formatted into string already containing something") {
|
||||
std::string out{"foo"};
|
||||
osmium::io::detail::append_printf_formatted_string(out, " %d", 23);
|
||||
REQUIRE(out == "foo 23");
|
||||
}
|
||||
|
||||
TEST_CASE("output formatted with large results") {
|
||||
const char* str =
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
|
||||
|
||||
std::string out;
|
||||
osmium::io::detail::append_printf_formatted_string(out, "%s", str);
|
||||
REQUIRE(out == str);
|
||||
}
|
||||
|
||||
SECTION("append to string") {
|
||||
out += "1234";
|
||||
osmium::io::detail::append_utf8_encoded_string(out, "abc");
|
||||
REQUIRE(out == "1234abc");
|
||||
}
|
||||
TEST_CASE("UTF8 encoding: append to string") {
|
||||
std::string out{"1234"};
|
||||
osmium::io::detail::append_utf8_encoded_string(out, "abc");
|
||||
REQUIRE(out == "1234abc");
|
||||
}
|
||||
|
||||
SECTION("don't encode alphabetic characters") {
|
||||
const char* s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
TEST_CASE("UTF8 encoding: don't encode alphabetic characters") {
|
||||
const char* s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
std::string out;
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
SECTION("don't encode numeric characters") {
|
||||
const char* s = "0123456789";
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
TEST_CASE("UTF8 encoding: don't encode numeric characters") {
|
||||
const char* s = "0123456789";
|
||||
std::string out;
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
SECTION("don't encode lots of often used characters characters") {
|
||||
const char* s = ".-;:_#+";
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
TEST_CASE("UTF8 encoding: don't encode lots of often used characters characters") {
|
||||
const char* s = ".-;:_#+";
|
||||
std::string out;
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
SECTION("encode characters that are special in OPL") {
|
||||
osmium::io::detail::append_utf8_encoded_string(out, " \n,=@");
|
||||
REQUIRE(out == "%20%%0a%%2c%%3d%%40%");
|
||||
}
|
||||
TEST_CASE("UTF8 encoding: encode characters that are special in OPL") {
|
||||
std::string out;
|
||||
osmium::io::detail::append_utf8_encoded_string(out, " \n,=@");
|
||||
REQUIRE(out == "%20%%0a%%2c%%3d%%40%");
|
||||
}
|
||||
|
||||
// workaround for missing support for u8 string literals on Windows
|
||||
#if !defined(_MSC_VER)
|
||||
|
||||
SECTION("encode multibyte character") {
|
||||
osmium::io::detail::append_utf8_encoded_string(out, u8"\u30dc_\U0001d11e_\U0001f6eb");
|
||||
REQUIRE(out == "%30dc%_%1d11e%_%1f6eb%");
|
||||
}
|
||||
|
||||
TEST_CASE("UTF8 encoding: encode multibyte character") {
|
||||
std::string out;
|
||||
osmium::io::detail::append_utf8_encoded_string(out, u8"\u30dc_\U0001d11e_\U0001f6eb");
|
||||
REQUIRE(out == "%30dc%_%1d11e%_%1f6eb%");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("html encoding") {
|
||||
|
||||
TEST_CASE("html encoding does not encode normal characters") {
|
||||
const char* s = "abc123,.-";
|
||||
std::string out;
|
||||
|
||||
SECTION("do not encode normal characters") {
|
||||
const char* s = "abc123,.-";
|
||||
osmium::io::detail::append_xml_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
SECTION("encode special XML characters") {
|
||||
const char* s = "& \" \' < > \n \r \t";
|
||||
osmium::io::detail::append_xml_encoded_string(out, s);
|
||||
REQUIRE(out == "& " ' < > 
 
 	");
|
||||
}
|
||||
|
||||
osmium::io::detail::append_xml_encoded_string(out, s);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
TEST_CASE("debug encoding") {
|
||||
|
||||
TEST_CASE("html encoding encodes special XML characters") {
|
||||
const char* s = "& \" \' < > \n \r \t";
|
||||
std::string out;
|
||||
|
||||
SECTION("do not encode normal characters") {
|
||||
const char* s = "abc123,.-";
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "[", "]");
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
SECTION("encode some unicode characters") {
|
||||
const char* s = u8"\n_\u30dc_\U0001d11e_\U0001f6eb";
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "[", "]");
|
||||
REQUIRE(out == "[<U+000A>]_[<U+30DC>]_[<U+1D11E>]_[<U+1F6EB>]");
|
||||
}
|
||||
|
||||
osmium::io::detail::append_xml_encoded_string(out, s);
|
||||
REQUIRE(out == "& " ' < > 
 
 	");
|
||||
}
|
||||
|
||||
TEST_CASE("encoding of non-printable characters in the first 127 characters") {
|
||||
TEST_CASE("debug encoding does not encode normal characters") {
|
||||
const char* s = "abc123,.-";
|
||||
std::string out;
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "[", "]");
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
std::locale cloc("C");
|
||||
TEST_CASE("debug encoding encodes some unicode characters") {
|
||||
const char* s = u8"\n_\u30dc_\U0001d11e_\U0001f6eb";
|
||||
std::string out;
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "[", "]");
|
||||
REQUIRE(out == "[<U+000A>]_[<U+30DC>]_[<U+1D11E>]_[<U+1F6EB>]");
|
||||
}
|
||||
|
||||
TEST_CASE("utf8 encoding of non-printable characters in the first 127 characters") {
|
||||
std::locale cloc{"C"};
|
||||
char s[] = "a\0";
|
||||
|
||||
for (char c = 1; c < 0x7f; ++c) {
|
||||
std::string out;
|
||||
s[0] = c;
|
||||
|
||||
SECTION("utf8 encode") {
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
|
||||
if (!std::isprint(c, cloc)) {
|
||||
REQUIRE(out[0] == '%');
|
||||
}
|
||||
osmium::io::detail::append_utf8_encoded_string(out, s);
|
||||
if (!std::isprint(c, cloc)) {
|
||||
REQUIRE(out[0] == '%');
|
||||
}
|
||||
|
||||
SECTION("debug encode") {
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "", "");
|
||||
|
||||
if (!std::isprint(c, cloc)) {
|
||||
REQUIRE(out[0] == '<');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("debug encoding of non-printable characters in the first 127 characters") {
|
||||
std::locale cloc{"C"};
|
||||
char s[] = "a\0";
|
||||
|
||||
for (char c = 1; c < 0x7f; ++c) {
|
||||
std::string out;
|
||||
s[0] = c;
|
||||
osmium::io::detail::append_debug_encoded_string(out, s, "", "");
|
||||
if (!std::isprint(c, cloc)) {
|
||||
REQUIRE(out[0] == '<');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("test codepoint to utf8 encoding") {
|
||||
const char s[] = u8"\n_\u01a2_\u30dc_\U0001d11e_\U0001f680";
|
||||
|
||||
std::string out;
|
||||
osmium::io::detail::append_codepoint_as_utf8(0x0aU, std::back_inserter(out)); // 1 utf8 byte
|
||||
REQUIRE(out.size() == 1);
|
||||
osmium::io::detail::append_codepoint_as_utf8('_', std::back_inserter(out));
|
||||
REQUIRE(out.size() == 2);
|
||||
osmium::io::detail::append_codepoint_as_utf8(0x01a2U, std::back_inserter(out)); // 2 utf8 bytes
|
||||
REQUIRE(out.size() == 4);
|
||||
osmium::io::detail::append_codepoint_as_utf8('_', std::back_inserter(out));
|
||||
REQUIRE(out.size() == 5);
|
||||
osmium::io::detail::append_codepoint_as_utf8(0x30dcU, std::back_inserter(out)); // 3 utf8 bytes
|
||||
REQUIRE(out.size() == 8);
|
||||
osmium::io::detail::append_codepoint_as_utf8('_', std::back_inserter(out));
|
||||
REQUIRE(out.size() == 9);
|
||||
osmium::io::detail::append_codepoint_as_utf8(0x1d11eU, std::back_inserter(out)); // 4 utf8 bytes
|
||||
REQUIRE(out.size() == 13);
|
||||
osmium::io::detail::append_codepoint_as_utf8('_', std::back_inserter(out));
|
||||
REQUIRE(out.size() == 14);
|
||||
osmium::io::detail::append_codepoint_as_utf8(0x1f680U, std::back_inserter(out)); // 4 utf8 bytes
|
||||
REQUIRE(out.size() == 18);
|
||||
REQUIRE(out == s);
|
||||
}
|
||||
|
||||
TEST_CASE("test utf8 to codepoint decoding") {
|
||||
const char s[] = u8"\n_\u01a2_\u30dc_\U0001d11e_\U0001f680";
|
||||
|
||||
auto it = s;
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == 0x0aU);
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == '_');
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == 0x01a2U);
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == '_');
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == 0x30dcU);
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == '_');
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == 0x1d11eU);
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == '_');
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == 0x1f680U);
|
||||
|
||||
REQUIRE(*it++ == '\0');
|
||||
REQUIRE(it == std::end(s));
|
||||
}
|
||||
|
||||
TEST_CASE("Roundtrip unicode characters") {
|
||||
char s[4] = {0};
|
||||
|
||||
const uint32_t max_code_point = 0x10ffffU;
|
||||
for (uint32_t cp = 0; cp <= max_code_point; ++cp) {
|
||||
const auto end = osmium::io::detail::append_codepoint_as_utf8(cp, s);
|
||||
const char* it = s;
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)) == cp);
|
||||
REQUIRE(end == it);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("invalid codepoint") {
|
||||
const char s[] = {static_cast<char>(0xff), static_cast<char>(0xff), static_cast<char>(0xff), static_cast<char>(0xff)};
|
||||
const char* it = s;
|
||||
REQUIRE_THROWS_AS(osmium::io::detail::next_utf8_codepoint(&it, std::end(s)), const std::runtime_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("incomplete Unicode codepoint") {
|
||||
const char s[] = u8"\U0001f680";
|
||||
|
||||
auto it = s;
|
||||
REQUIRE(osmium::io::detail::next_utf8_codepoint(&it, std::end(s) - 1) == 0x1f680U);
|
||||
REQUIRE(std::distance(s, it) == 4);
|
||||
|
||||
for (int i : {0, 1, 2, 3}) {
|
||||
it = s;
|
||||
REQUIRE_THROWS_AS(osmium::io::detail::next_utf8_codepoint(&it, s + i), const std::out_of_range&);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+86
@@ -9,6 +9,8 @@
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/visitor.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
struct CountHandler : public osmium::handler::Handler {
|
||||
|
||||
int count = 0;
|
||||
@@ -42,29 +44,46 @@ struct ZeroPositionNodeCountHandler : public osmium::handler::Handler {
|
||||
|
||||
TEST_CASE("Reader can be initialized with file") {
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
|
||||
const int count = count_fds();
|
||||
osmium::io::Reader reader{file};
|
||||
osmium::handler::Handler handler;
|
||||
|
||||
osmium::apply(reader, handler);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader can be initialized with string") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
|
||||
osmium::handler::Handler handler;
|
||||
|
||||
osmium::apply(reader, handler);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader can be initialized with user-provided pool") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::thread::Pool pool{4};
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
osmium::io::Reader reader{file, pool};
|
||||
osmium::handler::Handler handler;
|
||||
|
||||
osmium::apply(reader, handler);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should throw after eof") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
@@ -85,18 +104,26 @@ TEST_CASE("Reader should throw after eof") {
|
||||
|
||||
reader.close();
|
||||
REQUIRE(reader.eof());
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should not hang when apply() is called twice on reader") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
osmium::handler::Handler handler;
|
||||
|
||||
osmium::apply(reader, handler);
|
||||
REQUIRE_THROWS_AS(osmium::apply(reader, handler), const osmium::io_error&);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should work with a buffer with uncompressed data") {
|
||||
const int count = count_fds();
|
||||
|
||||
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm"));
|
||||
REQUIRE(fd >= 0);
|
||||
|
||||
@@ -104,6 +131,7 @@ TEST_CASE("Reader should work with a buffer with uncompressed data") {
|
||||
char buffer[buffer_size];
|
||||
const auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
osmium::io::detail::reliable_close(fd);
|
||||
|
||||
osmium::io::File file{buffer, static_cast<size_t>(length), "osm"};
|
||||
osmium::io::Reader reader{file};
|
||||
@@ -112,9 +140,14 @@ TEST_CASE("Reader should work with a buffer with uncompressed data") {
|
||||
REQUIRE(handler.count == 0);
|
||||
osmium::apply(reader, handler);
|
||||
REQUIRE(handler.count == 1);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should work with a buffer with gzip-compressed data") {
|
||||
const int count = count_fds();
|
||||
|
||||
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.gz"));
|
||||
REQUIRE(fd >= 0);
|
||||
|
||||
@@ -122,6 +155,7 @@ TEST_CASE("Reader should work with a buffer with gzip-compressed data") {
|
||||
char buffer[buffer_size];
|
||||
const auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
osmium::io::detail::reliable_close(fd);
|
||||
|
||||
osmium::io::File file{buffer, static_cast<size_t>(length), "osm.gz"};
|
||||
osmium::io::Reader reader{file};
|
||||
@@ -130,9 +164,14 @@ TEST_CASE("Reader should work with a buffer with gzip-compressed data") {
|
||||
REQUIRE(handler.count == 0);
|
||||
osmium::apply(reader, handler);
|
||||
REQUIRE(handler.count == 1);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should work with a buffer with bzip2-compressed data") {
|
||||
const int count = count_fds();
|
||||
|
||||
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.bz2"));
|
||||
REQUIRE(fd >= 0);
|
||||
|
||||
@@ -140,6 +179,7 @@ TEST_CASE("Reader should work with a buffer with bzip2-compressed data") {
|
||||
char buffer[buffer_size];
|
||||
const auto length = ::read(fd, buffer, buffer_size);
|
||||
REQUIRE(length > 0);
|
||||
osmium::io::detail::reliable_close(fd);
|
||||
|
||||
osmium::io::File file{buffer, static_cast<size_t>(length), "osm.bz2"};
|
||||
osmium::io::Reader reader{file};
|
||||
@@ -148,9 +188,14 @@ TEST_CASE("Reader should work with a buffer with bzip2-compressed data") {
|
||||
REQUIRE(handler.count == 0);
|
||||
osmium::apply(reader, handler);
|
||||
REQUIRE(handler.count == 1);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should decode zero node positions in history (XML)") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::Reader reader{with_data_dir("t/io/deleted_nodes.osh"),
|
||||
osmium::osm_entity_bits::node};
|
||||
ZeroPositionNodeCountHandler handler;
|
||||
@@ -162,9 +207,14 @@ TEST_CASE("Reader should decode zero node positions in history (XML)") {
|
||||
|
||||
REQUIRE(handler.count == 0);
|
||||
REQUIRE(handler.total_count == 2);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should decode zero node positions in history (PBF)") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::Reader reader{with_data_dir("t/io/deleted_nodes.osh.pbf"),
|
||||
osmium::osm_entity_bits::node};
|
||||
ZeroPositionNodeCountHandler handler;
|
||||
@@ -176,30 +226,51 @@ TEST_CASE("Reader should decode zero node positions in history (PBF)") {
|
||||
|
||||
REQUIRE(handler.count == 0);
|
||||
REQUIRE(handler.total_count == 2);
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should fail with nonexistent file") {
|
||||
const int count = count_fds();
|
||||
|
||||
REQUIRE_THROWS(osmium::io::Reader{with_data_dir("t/io/nonexistent-file.osm")});
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should fail with nonexistent file (gz)") {
|
||||
const int count = count_fds();
|
||||
|
||||
REQUIRE_THROWS(osmium::io::Reader{with_data_dir("t/io/nonexistent-file.osm.gz")});
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should fail with nonexistent file (pbf)") {
|
||||
const int count = count_fds();
|
||||
|
||||
REQUIRE_THROWS(osmium::io::Reader{with_data_dir("t/io/nonexistent-file.osm.pbf")});
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should work when there is an exception in main thread before getting header") {
|
||||
const int count = count_fds();
|
||||
|
||||
try {
|
||||
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
|
||||
REQUIRE_FALSE(reader.eof());
|
||||
throw std::runtime_error{"foo"};
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Reader should work when there is an exception in main thread while reading") {
|
||||
const int count = count_fds();
|
||||
|
||||
try {
|
||||
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
|
||||
REQUIRE_FALSE(reader.eof());
|
||||
@@ -207,15 +278,24 @@ TEST_CASE("Reader should work when there is an exception in main thread while re
|
||||
throw std::runtime_error{"foo"};
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Applying rvalue handler on reader") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
|
||||
struct NullHandler : public osmium::handler::Handler { };
|
||||
osmium::apply(reader, NullHandler{});
|
||||
|
||||
reader.close();
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Can call read() exactly once on Reader with entity_bits nothing") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing};
|
||||
REQUIRE_FALSE(reader.eof());
|
||||
@@ -233,9 +313,13 @@ TEST_CASE("Can call read() exactly once on Reader with entity_bits nothing") {
|
||||
|
||||
reader.close();
|
||||
REQUIRE(reader.eof());
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Can not read after close") {
|
||||
const int count = count_fds();
|
||||
|
||||
osmium::io::File file{with_data_dir("t/io/data.osm")};
|
||||
osmium::io::Reader reader{file};
|
||||
|
||||
@@ -254,5 +338,7 @@ TEST_CASE("Can not read after close") {
|
||||
reader.close();
|
||||
REQUIRE(reader.eof());
|
||||
REQUIRE_THROWS_AS(reader.read(), const osmium::io_error&);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <osmium/io/compression.hpp>
|
||||
#include <osmium/io/xml_input.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -13,7 +14,7 @@
|
||||
// constructor it can be instructed to throw an exception in specific parts
|
||||
// of its code. This is then used to test the internals of the Reader.
|
||||
|
||||
class MockDecompressor : public osmium::io::Decompressor {
|
||||
class MockDecompressor final : public osmium::io::Decompressor {
|
||||
|
||||
std::string m_fail_in;
|
||||
int m_read_count = 0;
|
||||
@@ -33,15 +34,15 @@ public:
|
||||
MockDecompressor(MockDecompressor&&) = delete;
|
||||
MockDecompressor& operator=(MockDecompressor&&) = delete;
|
||||
|
||||
~MockDecompressor() noexcept final = default;
|
||||
~MockDecompressor() noexcept = default;
|
||||
|
||||
void add_node(std::string& s, int i) {
|
||||
static void add_node(std::string& s, int i) {
|
||||
s += "<node id='";
|
||||
s += std::to_string(i);
|
||||
s += "' version='1' timestamp='2014-01-01T00:00:00Z' uid='1' user='test' changeset='1' lon='1.02' lat='1.02'/>\n";
|
||||
}
|
||||
|
||||
std::string read() final {
|
||||
std::string read() override {
|
||||
std::string buffer;
|
||||
++m_read_count;
|
||||
|
||||
@@ -67,7 +68,7 @@ public:
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void close() final {
|
||||
void close() override {
|
||||
if (m_fail_in == "close") {
|
||||
throw std::runtime_error{"error close"};
|
||||
}
|
||||
@@ -80,9 +81,9 @@ TEST_CASE("Test Reader using MockDecompressor") {
|
||||
std::string fail_in;
|
||||
|
||||
osmium::io::CompressionFactory::instance().register_compression(osmium::io::file_compression::gzip,
|
||||
[](int, osmium::io::fsync) { return nullptr; },
|
||||
[&](int) { return new MockDecompressor(fail_in); },
|
||||
[](const char*, size_t) { return nullptr; }
|
||||
[](int /*unused*/, osmium::io::fsync /*unused*/) { return nullptr; },
|
||||
[&](int /*unused*/) { return new MockDecompressor(fail_in); },
|
||||
[](const char* /*unused*/, size_t /*unused*/) { return nullptr; }
|
||||
);
|
||||
|
||||
SECTION("fail in constructor") {
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <osmium/thread/queue.hpp>
|
||||
#include <osmium/thread/util.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <osmium/io/detail/string_table.hpp>
|
||||
#include <osmium/util/misc.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Empty StringStore") {
|
||||
const osmium::io::detail::StringStore ss{100};
|
||||
|
||||
|
||||
+42
-1
@@ -9,7 +9,10 @@
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
static osmium::memory::Buffer get_buffer() {
|
||||
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
|
||||
@@ -31,7 +34,7 @@ static osmium::memory::Buffer get_and_check_buffer() {
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Empty writes") {
|
||||
auto buffer = get_and_check_buffer();
|
||||
const int count = count_fds();
|
||||
|
||||
std::string filename;
|
||||
|
||||
@@ -54,9 +57,13 @@ TEST_CASE("Writer: Empty writes") {
|
||||
osmium::io::Reader reader_check{filename};
|
||||
osmium::memory::Buffer buffer_check = reader_check.read();
|
||||
REQUIRE_FALSE(buffer_check);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Successful writes writing buffer") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
|
||||
const auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
|
||||
@@ -68,6 +75,8 @@ TEST_CASE("Writer: Successful writes writing buffer") {
|
||||
writer(std::move(buffer));
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
REQUIRE_THROWS_AS(writer(osmium::memory::Buffer{}), const osmium::io_error&);
|
||||
|
||||
osmium::io::Reader reader_check{filename};
|
||||
@@ -79,6 +88,8 @@ TEST_CASE("Writer: Successful writes writing buffer") {
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Successful writes writing items") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
|
||||
const auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
|
||||
@@ -92,6 +103,8 @@ TEST_CASE("Writer: Successful writes writing items") {
|
||||
}
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
osmium::io::Reader reader_check{filename};
|
||||
const osmium::memory::Buffer buffer_check = reader_check.read();
|
||||
REQUIRE(buffer_check);
|
||||
@@ -101,6 +114,8 @@ TEST_CASE("Writer: Successful writes writing items") {
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Successful writes using output iterator") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
|
||||
const auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
|
||||
@@ -113,6 +128,8 @@ TEST_CASE("Writer: Successful writes using output iterator") {
|
||||
std::copy(buffer.cbegin(), buffer.cend(), it);
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
|
||||
osmium::io::Reader reader_check{filename};
|
||||
const osmium::memory::Buffer buffer_check = reader_check.read();
|
||||
REQUIRE(buffer_check);
|
||||
@@ -122,6 +139,8 @@ TEST_CASE("Writer: Successful writes using output iterator") {
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Interrupted writer after open") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_and_check_buffer();
|
||||
|
||||
bool error = false;
|
||||
@@ -133,9 +152,13 @@ TEST_CASE("Writer: Interrupted writer after open") {
|
||||
}
|
||||
|
||||
REQUIRE(error);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer: Interrupted writer after write") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_and_check_buffer();
|
||||
|
||||
bool error = false;
|
||||
@@ -148,37 +171,55 @@ TEST_CASE("Writer: Interrupted writer after write") {
|
||||
}
|
||||
|
||||
REQUIRE(error);
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer with user-provided pool with default number of threads") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
osmium::thread::Pool pool;
|
||||
osmium::io::Writer writer{"test-writer-pool-with-default-threads.osm", pool, osmium::io::overwrite::allow};
|
||||
writer(std::move(buffer));
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer with user-provided pool with negative number of threads") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
osmium::thread::Pool pool{-2};
|
||||
osmium::io::Writer writer{"test-writer-pool-with-negative-threads.osm", pool, osmium::io::overwrite::allow};
|
||||
writer(std::move(buffer));
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer with user-provided pool with outlier negative number of threads") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
osmium::thread::Pool pool{-1000};
|
||||
osmium::io::Writer writer{"test-writer-pool-with-outlier-negative-threads.osm", osmium::io::overwrite::allow, pool};
|
||||
writer(std::move(buffer));
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
TEST_CASE("Writer with user-provided pool with outlier positive number of threads") {
|
||||
const int count = count_fds();
|
||||
|
||||
auto buffer = get_buffer();
|
||||
osmium::thread::Pool pool{1000};
|
||||
osmium::io::Writer writer{"test-writer-pool-with-outlier-positive-threads.osm", osmium::io::overwrite::allow, pool};
|
||||
writer(std::move(buffer));
|
||||
writer.close();
|
||||
|
||||
REQUIRE(count == count_fds());
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
class MockCompressor : public osmium::io::Compressor {
|
||||
class MockCompressor final : public osmium::io::Compressor {
|
||||
|
||||
std::string m_fail_in;
|
||||
|
||||
@@ -30,15 +30,15 @@ public:
|
||||
MockCompressor(MockCompressor&&) = delete;
|
||||
MockCompressor& operator=(MockCompressor&&) = delete;
|
||||
|
||||
~MockCompressor() noexcept final = default;
|
||||
~MockCompressor() noexcept = default;
|
||||
|
||||
void write(const std::string& /*data*/) final {
|
||||
void write(const std::string& /*data*/) override {
|
||||
if (m_fail_in == "write") {
|
||||
throw std::logic_error{"write"};
|
||||
}
|
||||
}
|
||||
|
||||
void close() final {
|
||||
void close() override {
|
||||
if (m_fail_in == "close") {
|
||||
throw std::logic_error{"close"};
|
||||
}
|
||||
@@ -51,9 +51,9 @@ TEST_CASE("Write with mock compressor") {
|
||||
std::string fail_in;
|
||||
|
||||
osmium::io::CompressionFactory::instance().register_compression(osmium::io::file_compression::gzip,
|
||||
[&](int, osmium::io::fsync) { return new MockCompressor(fail_in); },
|
||||
[](int) { return nullptr; },
|
||||
[](const char*, size_t) { return nullptr; }
|
||||
[&](int /*unused*/, osmium::io::fsync /*unused*/) { return new MockCompressor(fail_in); },
|
||||
[](int /*unused*/) { return nullptr; },
|
||||
[](const char* /*unused*/, size_t /*unused*/) { return nullptr; }
|
||||
);
|
||||
|
||||
osmium::io::Header header;
|
||||
|
||||
@@ -88,7 +88,7 @@ TEST_CASE("Reserve space in a growing buffer") {
|
||||
}
|
||||
|
||||
TEST_CASE("Create buffer from existing data with good alignment works") {
|
||||
std::array<unsigned char, 128> data;
|
||||
std::array<unsigned char, 128> data = {{0}};
|
||||
|
||||
osmium::memory::Buffer buffer{data.data(), data.size()};
|
||||
REQUIRE(buffer.capacity() == 128);
|
||||
@@ -96,7 +96,7 @@ TEST_CASE("Create buffer from existing data with good alignment works") {
|
||||
}
|
||||
|
||||
TEST_CASE("Create buffer from existing data with good alignment and committed value works") {
|
||||
std::array<unsigned char, 128> data;
|
||||
std::array<unsigned char, 128> data = {{0}};
|
||||
|
||||
osmium::memory::Buffer buffer{data.data(), data.size(), 32};
|
||||
REQUIRE(buffer.capacity() == 128);
|
||||
@@ -105,7 +105,7 @@ TEST_CASE("Create buffer from existing data with good alignment and committed va
|
||||
}
|
||||
|
||||
TEST_CASE("Create buffer from existing data with bad alignment fails") {
|
||||
std::array<unsigned char, 128> data;
|
||||
std::array<unsigned char, 128> data = {{0}};
|
||||
|
||||
const auto l1 = [&](){
|
||||
osmium::memory::Buffer buffer{data.data(), 127};
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
void check_node_1(const osmium::Node& node) {
|
||||
REQUIRE(1 == node.id());
|
||||
REQUIRE(3 == node.version());
|
||||
@@ -50,6 +54,8 @@ void check_node_2(const osmium::Node& node) {
|
||||
REQUIRE(std::string("name") == tag.key());
|
||||
REQUIRE(std::string("OSM Savings") == tag.value());
|
||||
break;
|
||||
default:
|
||||
REQUIRE(false);
|
||||
}
|
||||
++n;
|
||||
}
|
||||
|
||||
+170
-153
@@ -3,6 +3,8 @@
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
struct CallbackClass {
|
||||
|
||||
int count = 0;
|
||||
@@ -14,161 +16,176 @@ struct CallbackClass {
|
||||
|
||||
}; // struct CallbackClass
|
||||
|
||||
TEST_CASE("Purge data from buffer") {
|
||||
|
||||
constexpr size_t buffer_size = 10000;
|
||||
TEST_CASE("Purge data from empty buffer") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
SECTION("purge empty buffer") {
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(buffer.committed() == 0);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with one object but nothing to delete") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
const size_t committed = buffer.committed();
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(committed == buffer.committed());
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with one object which gets deleted") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(buffer.committed() == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with two objects, first gets deleted") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
const size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
const size_t size2 = buffer.committed() - size1;
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 1);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
REQUIRE(buffer.committed() == size2);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with two objects, second gets deleted") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
REQUIRE(buffer.committed() == size1);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with three objects, middle one gets deleted") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 1);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
}
|
||||
|
||||
SECTION("purge buffer with three objects, all get deleted") {
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
}
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(buffer.committed() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with one object but nothing to delete") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
const size_t committed = buffer.committed();
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(committed == buffer.committed());
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with one object which gets deleted") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(buffer.committed() == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with two objects, first gets deleted") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
const size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
const size_t size2 = buffer.committed() - size1;
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 1);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
REQUIRE(buffer.committed() == size2);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with two objects, second gets deleted") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
const size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
REQUIRE(buffer.committed() == size1);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with three objects, middle one gets deleted") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 1);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Purge buffer with three objects, all get deleted") {
|
||||
constexpr const size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
|
||||
REQUIRE(callback.count == 0);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -10,20 +10,20 @@ TEST_CASE("padded length") {
|
||||
REQUIRE(osmium::memory::padded_length(8) == 8);
|
||||
REQUIRE(osmium::memory::padded_length(9) == 16);
|
||||
|
||||
REQUIRE(osmium::memory::padded_length(2147483647ul) == 2147483648ul);
|
||||
REQUIRE(osmium::memory::padded_length(2147483648ul) == 2147483648ul);
|
||||
REQUIRE(osmium::memory::padded_length(2147483650ul) == 2147483656ul);
|
||||
REQUIRE(osmium::memory::padded_length(2147483647UL) == 2147483648UL);
|
||||
REQUIRE(osmium::memory::padded_length(2147483648UL) == 2147483648UL);
|
||||
REQUIRE(osmium::memory::padded_length(2147483650UL) == 2147483656UL);
|
||||
|
||||
// The following checks only make sense on a 64 bit system (with
|
||||
// sizeof(size_t) == 8), because the numbers are too large for 32 bit.
|
||||
// The casts to size_t do nothing on a 64 bit system, on a 32 bit system
|
||||
// they bring the numbers into the right range and everything still works.
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967295ull)) == static_cast<std::size_t>(4294967296ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967296ull)) == static_cast<std::size_t>(4294967296ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967297ull)) == static_cast<std::size_t>(4294967304ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967295ULL)) == static_cast<std::size_t>(4294967296ULL));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967296ULL)) == static_cast<std::size_t>(4294967296ULL));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(4294967297ULL)) == static_cast<std::size_t>(4294967304ULL));
|
||||
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(7999999999ull)) == static_cast<std::size_t>(8000000000ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000000ull)) == static_cast<std::size_t>(8000000000ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000001ull)) == static_cast<std::size_t>(8000000008ull));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(7999999999ULL)) == static_cast<std::size_t>(8000000000ULL));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000000ULL)) == static_cast<std::size_t>(8000000000ULL));
|
||||
REQUIRE(osmium::memory::padded_length(static_cast<std::size_t>(8000000001ULL)) == static_cast<std::size_t>(8000000008ULL));
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/area.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -71,7 +73,7 @@ TEST_CASE("Build area") {
|
||||
REQUIRE(outer == 1);
|
||||
REQUIRE(inner == 1);
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(area);
|
||||
REQUIRE(crc32().checksum() == 0x2b2b7fa0);
|
||||
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/geom/relations.hpp>
|
||||
#include <osmium/osm/box.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
TEST_CASE("Default constructor creates invalid box") {
|
||||
@@ -64,7 +64,7 @@ TEST_CASE("Extend box with valid") {
|
||||
REQUIRE(b.contains(loc2));
|
||||
REQUIRE(b.contains(loc3));
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(b);
|
||||
REQUIRE(crc32().checksum() == 0xd381a838);
|
||||
}
|
||||
|
||||
+58
-14
@@ -1,10 +1,12 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/changeset.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -29,12 +31,12 @@ TEST_CASE("Build changeset") {
|
||||
REQUIRE(7 == cs1.num_changes());
|
||||
REQUIRE(3 == cs1.num_comments());
|
||||
REQUIRE(cs1.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs1.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs1.closed_at());
|
||||
REQUIRE(osmium::Timestamp{100} == cs1.created_at());
|
||||
REQUIRE(osmium::Timestamp{200} == cs1.closed_at());
|
||||
REQUIRE(1 == cs1.tags().size());
|
||||
REQUIRE(std::string("user") == cs1.user());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(cs1);
|
||||
REQUIRE(crc32().checksum() == 0x502e8c0e);
|
||||
|
||||
@@ -58,8 +60,8 @@ TEST_CASE("Build changeset") {
|
||||
REQUIRE(21 == cs2.num_changes());
|
||||
REQUIRE(0 == cs2.num_comments());
|
||||
REQUIRE_FALSE(cs2.closed());
|
||||
REQUIRE(osmium::Timestamp(120) == cs2.created_at());
|
||||
REQUIRE(osmium::Timestamp() == cs2.closed_at());
|
||||
REQUIRE(osmium::Timestamp{120} == cs2.created_at());
|
||||
REQUIRE(osmium::Timestamp{} == cs2.closed_at());
|
||||
REQUIRE(2 == cs2.tags().size());
|
||||
REQUIRE(std::string("user") == cs2.user());
|
||||
|
||||
@@ -73,13 +75,13 @@ TEST_CASE("Build changeset") {
|
||||
auto cit = cs2.discussion().begin();
|
||||
|
||||
REQUIRE(cit != cs2.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(300));
|
||||
REQUIRE(cit->date() == osmium::Timestamp{300});
|
||||
REQUIRE(cit->uid() == 10);
|
||||
REQUIRE(std::string("user2") == cit->user());
|
||||
REQUIRE(std::string("foo") == cit->text());
|
||||
|
||||
REQUIRE(++cit != cs2.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(400));
|
||||
REQUIRE(cit->date() == osmium::Timestamp{400});
|
||||
REQUIRE(cit->uid() == 9);
|
||||
REQUIRE(std::string("user") == cit->user());
|
||||
REQUIRE(std::string("bar") == cit->text());
|
||||
@@ -107,9 +109,9 @@ TEST_CASE("Create changeset without helper") {
|
||||
}
|
||||
|
||||
osmium::builder::ChangesetDiscussionBuilder disc_builder{builder};
|
||||
disc_builder.add_comment(osmium::Timestamp(300), 10, "user2");
|
||||
disc_builder.add_comment(osmium::Timestamp{300}, 10, "user2");
|
||||
disc_builder.add_comment_text("foo");
|
||||
disc_builder.add_comment(osmium::Timestamp(400), 9, "user");
|
||||
disc_builder.add_comment(osmium::Timestamp{400}, 9, "user");
|
||||
disc_builder.add_comment_text("bar");
|
||||
}
|
||||
|
||||
@@ -120,21 +122,21 @@ TEST_CASE("Create changeset without helper") {
|
||||
REQUIRE(7 == cs.num_changes());
|
||||
REQUIRE(2 == cs.num_comments());
|
||||
REQUIRE(cs.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs.closed_at());
|
||||
REQUIRE(osmium::Timestamp{100} == cs.created_at());
|
||||
REQUIRE(osmium::Timestamp{200} == cs.closed_at());
|
||||
REQUIRE(2 == cs.tags().size());
|
||||
REQUIRE(std::string("user") == cs.user());
|
||||
|
||||
auto cit = cs.discussion().begin();
|
||||
|
||||
REQUIRE(cit != cs.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(300));
|
||||
REQUIRE(cit->date() == osmium::Timestamp{300});
|
||||
REQUIRE(cit->uid() == 10);
|
||||
REQUIRE(std::string("user2") == cit->user());
|
||||
REQUIRE(std::string("foo") == cit->text());
|
||||
|
||||
REQUIRE(++cit != cs.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(400));
|
||||
REQUIRE(cit->date() == osmium::Timestamp{400});
|
||||
REQUIRE(cit->uid() == 9);
|
||||
REQUIRE(std::string("user") == cit->user());
|
||||
REQUIRE(std::string("bar") == cit->text());
|
||||
@@ -142,3 +144,45 @@ TEST_CASE("Create changeset without helper") {
|
||||
REQUIRE(++cit == cs.discussion().end());
|
||||
}
|
||||
|
||||
TEST_CASE("Change changeset") {
|
||||
osmium::memory::Buffer buffer{10 * 1000};
|
||||
|
||||
osmium::builder::add_changeset(buffer,
|
||||
_cid(42),
|
||||
_created_at(time_t(100)),
|
||||
_closed_at(time_t(200)),
|
||||
_num_changes(7),
|
||||
_num_comments(3),
|
||||
_uid(9),
|
||||
_user("user"),
|
||||
_tag("comment", "foo")
|
||||
);
|
||||
|
||||
auto& cs = buffer.get<osmium::Changeset>(0);
|
||||
|
||||
cs.set_id(12);
|
||||
cs.set_created_at(time_t(200));
|
||||
cs.set_closed_at(time_t(300));
|
||||
cs.set_num_changes(3);
|
||||
cs.set_num_comments(4);
|
||||
cs.set_uid(10);
|
||||
cs.clear_user();
|
||||
|
||||
REQUIRE(12 == cs.id());
|
||||
REQUIRE(10 == cs.uid());
|
||||
REQUIRE(3 == cs.num_changes());
|
||||
REQUIRE(4 == cs.num_comments());
|
||||
REQUIRE(cs.closed());
|
||||
REQUIRE(osmium::Timestamp{200} == cs.created_at());
|
||||
REQUIRE(osmium::Timestamp{300} == cs.closed_at());
|
||||
REQUIRE(1 == cs.tags().size());
|
||||
REQUIRE(std::string("") == cs.user());
|
||||
REQUIRE(cs.tags().size() == 1);
|
||||
|
||||
auto it = cs.tags().begin();
|
||||
REQUIRE(it->key() == std::string{"comment"});
|
||||
REQUIRE(it->value() == std::string{"foo"});
|
||||
++it;
|
||||
REQUIRE(it == cs.tags().end());
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -1,11 +1,11 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/osm/crc.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
TEST_CASE("CRC of bool") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
crc32.update_bool(true);
|
||||
crc32.update_bool(false);
|
||||
@@ -14,7 +14,7 @@ TEST_CASE("CRC of bool") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of char") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
crc32.update_int8('x');
|
||||
crc32.update_int8('y');
|
||||
@@ -23,7 +23,7 @@ TEST_CASE("CRC of char") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of int16") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
crc32.update_int16(0x0123U);
|
||||
crc32.update_int16(0x1234U);
|
||||
@@ -32,7 +32,7 @@ TEST_CASE("CRC of int16") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of int32") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
crc32.update_int32(0x01234567UL);
|
||||
crc32.update_int32(0x12345678UL);
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("CRC of int32") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of int64") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
crc32.update_int64(0x0123456789abcdefULL);
|
||||
crc32.update_int64(0x123456789abcdef0ULL);
|
||||
@@ -50,7 +50,7 @@ TEST_CASE("CRC of int64") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of string") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
const char* str = "foobar";
|
||||
crc32.update_string(str);
|
||||
@@ -59,7 +59,7 @@ TEST_CASE("CRC of string") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of Timestamp") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
const osmium::Timestamp t{"2015-07-12T13:10:46Z"};
|
||||
crc32.update(t);
|
||||
@@ -68,7 +68,7 @@ TEST_CASE("CRC of Timestamp") {
|
||||
}
|
||||
|
||||
TEST_CASE("CRC of Location") {
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
|
||||
const osmium::Location loc{3.46, 2.001};
|
||||
crc32.update(loc);
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
|
||||
#include <osmium/osm/location.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
// fails on MSVC and doesn't really matter
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <osmium/osm/metadata_options.hpp>
|
||||
#include <osmium/osm/object.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
TEST_CASE("Metadata options: default") {
|
||||
const osmium::metadata_options m{};
|
||||
REQUIRE_FALSE(m.none());
|
||||
|
||||
+16
-11
@@ -1,10 +1,12 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -29,8 +31,8 @@ TEST_CASE("Build node") {
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
REQUIRE(node.type_is_in(osmium::osm_entity_bits::node));
|
||||
REQUIRE(node.type_is_in(osmium::osm_entity_bits::nwr));
|
||||
REQUIRE(17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(17L == node.id());
|
||||
REQUIRE(17UL == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(node.visible());
|
||||
REQUIRE_FALSE(node.deleted());
|
||||
@@ -41,13 +43,16 @@ TEST_CASE("Build node") {
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(2 == node.tags().size());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(node);
|
||||
REQUIRE(crc32().checksum() == 0x7dc553f9);
|
||||
|
||||
node.set_visible(false);
|
||||
REQUIRE_FALSE(node.visible());
|
||||
REQUIRE(node.deleted());
|
||||
|
||||
node.remove_tags();
|
||||
REQUIRE(node.tags().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("default values for node attributes") {
|
||||
@@ -56,8 +61,8 @@ TEST_CASE("default values for node attributes") {
|
||||
osmium::builder::add_node(buffer, _id(0));
|
||||
|
||||
const osmium::Node& node = buffer.get<osmium::Node>(0);
|
||||
REQUIRE(0l == node.id());
|
||||
REQUIRE(0ul == node.positive_id());
|
||||
REQUIRE(0L == node.id());
|
||||
REQUIRE(0UL == node.positive_id());
|
||||
REQUIRE(0 == node.version());
|
||||
REQUIRE(node.visible());
|
||||
REQUIRE(0 == node.changeset());
|
||||
@@ -81,8 +86,8 @@ TEST_CASE("set node attributes from strings") {
|
||||
.set_timestamp("2014-03-17T16:23:08Z")
|
||||
.set_uid("21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(-17L == node.id());
|
||||
REQUIRE(17UL == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
@@ -103,8 +108,8 @@ TEST_CASE("set node attributes from strings using set_attribute()") {
|
||||
.set_attribute("timestamp", "2014-03-17T16:23:08Z")
|
||||
.set_attribute("uid", "21");
|
||||
|
||||
REQUIRE(-17l == node.id());
|
||||
REQUIRE(17ul == node.positive_id());
|
||||
REQUIRE(-17L == node.id());
|
||||
REQUIRE(17UL == node.positive_id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(node.visible());
|
||||
REQUIRE(333 == node.changeset());
|
||||
@@ -133,7 +138,7 @@ TEST_CASE("Setting attributes from bad data on strings should fail") {
|
||||
TEST_CASE("set large id") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
const int64_t id = 3000000000l;
|
||||
const int64_t id = 3000000000L;
|
||||
osmium::builder::add_node(buffer, _id(id));
|
||||
|
||||
auto& node = buffer.get<osmium::Node>(0);
|
||||
|
||||
@@ -90,7 +90,7 @@ TEST_CASE("Node comparisons") {
|
||||
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"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000LL), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend()));
|
||||
}
|
||||
@@ -122,7 +122,7 @@ TEST_CASE("Node comparisons") {
|
||||
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"))));
|
||||
nodes.emplace_back(buffer.get<osmium::Node>(osmium::builder::add_node(buffer, _id(10000000000LL), _version(2), _timestamp("2016-01-01T00:00:00Z"))));
|
||||
|
||||
REQUIRE(std::is_sorted(nodes.cbegin(), nodes.cend(), osmium::object_order_type_id_reverse_version{}));
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,10 +1,12 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/relation.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -58,7 +60,7 @@ TEST_CASE("Build relation") {
|
||||
++n;
|
||||
}
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(relation);
|
||||
REQUIRE(crc32().checksum() == 0x2c2352e);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -10,6 +11,7 @@ TEST_CASE("Timestamp can be default initialized to invalid value") {
|
||||
const osmium::Timestamp t{};
|
||||
REQUIRE(0 == uint32_t(t));
|
||||
REQUIRE(t.to_iso().empty());
|
||||
REQUIRE(t.to_iso_all() == "1970-01-01T00:00:00Z");
|
||||
REQUIRE_FALSE(t.valid());
|
||||
}
|
||||
|
||||
@@ -17,6 +19,7 @@ TEST_CASE("Timestamp invalid value is zero") {
|
||||
const osmium::Timestamp t{static_cast<time_t>(0)};
|
||||
REQUIRE(0 == uint32_t(t));
|
||||
REQUIRE(t.to_iso().empty());
|
||||
REQUIRE(t.to_iso_all() == "1970-01-01T00:00:00Z");
|
||||
REQUIRE_FALSE(t.valid());
|
||||
}
|
||||
|
||||
@@ -119,6 +122,7 @@ TEST_CASE("Valid timestamps") {
|
||||
for (const auto& tc : test_cases) {
|
||||
const osmium::Timestamp t{tc};
|
||||
REQUIRE(tc == t.to_iso());
|
||||
REQUIRE(tc == t.to_iso_all());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <osmium/osm/types.hpp>
|
||||
#include <osmium/osm/types_from_string.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
TEST_CASE("set ID from string") {
|
||||
REQUIRE(osmium::string_to_object_id("0") == 0);
|
||||
REQUIRE(osmium::string_to_object_id("17") == 17);
|
||||
|
||||
+9
-3
@@ -1,11 +1,13 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "test_crc.hpp"
|
||||
|
||||
#include <osmium/builder/attr.hpp>
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/crc.hpp>
|
||||
#include <osmium/osm/way.hpp>
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <string>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -25,7 +27,7 @@ TEST_CASE("Build way") {
|
||||
_nodes({1, 3, 2})
|
||||
);
|
||||
|
||||
const osmium::Way& way = buffer.get<osmium::Way>(0);
|
||||
auto& way = buffer.get<osmium::Way>(0);
|
||||
|
||||
REQUIRE(osmium::item_type::way == way.type());
|
||||
REQUIRE(way.type_is_in(osmium::osm_entity_bits::way));
|
||||
@@ -44,9 +46,13 @@ TEST_CASE("Build way") {
|
||||
REQUIRE(2 == way.nodes()[2].ref());
|
||||
REQUIRE_FALSE(way.is_closed());
|
||||
|
||||
osmium::CRC<boost::crc_32_type> crc32;
|
||||
osmium::CRC<crc_type> crc32;
|
||||
crc32.update(way);
|
||||
REQUIRE(crc32().checksum() == 0x65f6ba91);
|
||||
|
||||
way.remove_tags();
|
||||
REQUIRE(way.tags().empty());
|
||||
REQUIRE(3 == way.nodes().size());
|
||||
}
|
||||
|
||||
TEST_CASE("build closed way") {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osm version="0.6" generator="testdata" upload="false">
|
||||
<node id="10" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.0" lon="1.0"/>
|
||||
<node id="11" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.0" lon="1.1"/>
|
||||
<node id="12" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.0" lon="1.2"/>
|
||||
<node id="13" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.0" lon="1.3"/>
|
||||
<node id="14" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lat="1.0" lon="1.4">
|
||||
<tag k="amenity" v="bench" />
|
||||
</node>
|
||||
<way id="20" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
|
||||
<tag k="public_transport" v="platform"/>
|
||||
<nd ref="10"/>
|
||||
<nd ref="11"/>
|
||||
</way>
|
||||
<way id="21" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
|
||||
<tag k="public_transport" v="platform"/>
|
||||
<nd ref="13"/>
|
||||
<nd ref="12"/>
|
||||
</way>
|
||||
<relation id="31" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
|
||||
<tag k="type" v="public_transport"/>
|
||||
<tag k="public_transport" v="stop_area"/>
|
||||
<member type="way" ref="20" role="platform"/>
|
||||
<member type="way" ref="21" role="platform"/>
|
||||
<member type="node" ref="14" role=""/>
|
||||
<member type="relation" ref="30" role="building"/>
|
||||
<member type="node" ref="15" role=""/>
|
||||
<member type="relation" ref="32" role="building"/>
|
||||
<member type="relation" ref="33" role="building"/>
|
||||
<member type="way" ref="22" role="platform"/>
|
||||
</relation>
|
||||
<relation id="32" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1">
|
||||
<tag k="type" v="multipolygon"/>
|
||||
<tag k="public_transport" v="platform"/>
|
||||
<member type="way" ref="23" role="outer"/>
|
||||
<member type="way" ref="24" role="inner"/>
|
||||
</relation>
|
||||
</osm>
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <osmium/relations/relations_database.hpp>
|
||||
#include <osmium/storage/item_stash.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
osmium::memory::Buffer fill_buffer() {
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
osmium::memory::Buffer buffer{1024 * 1024, osmium::memory::Buffer::auto_grow::yes};
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <osmium/osm/relation.hpp>
|
||||
#include <osmium/relations/relations_manager.hpp>
|
||||
|
||||
#include <iterator>
|
||||
|
||||
struct EmptyRM : public osmium::relations::RelationsManager<EmptyRM, true, true, true> {
|
||||
};
|
||||
|
||||
@@ -82,7 +84,7 @@ struct CallbackRM : public osmium::relations::RelationsManager<CallbackRM, true,
|
||||
return member.type() == osmium::item_type::node;
|
||||
}
|
||||
|
||||
void complete_relation(const osmium::Relation& relation) noexcept {
|
||||
void complete_relation(const osmium::Relation& relation) {
|
||||
for (const auto& member : relation.members()) {
|
||||
if (member.type() == osmium::item_type::node) {
|
||||
++count_nodes;
|
||||
@@ -96,6 +98,16 @@ struct CallbackRM : public osmium::relations::RelationsManager<CallbackRM, true,
|
||||
|
||||
};
|
||||
|
||||
struct AnyRM : public osmium::relations::RelationsManager<AnyRM, true, true, true> {
|
||||
bool new_relation(const osmium::Relation& /*relation*/) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool new_member(const osmium::Relation& /*relation*/, const osmium::RelationMember& /*member*/, std::size_t /*n*/) noexcept {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("Use RelationsManager without any overloaded functions in derived class") {
|
||||
osmium::io::File file{with_data_dir("t/relations/data.osm")};
|
||||
|
||||
@@ -134,7 +146,7 @@ TEST_CASE("Relations manager derived class") {
|
||||
|
||||
bool callback_called = false;
|
||||
osmium::io::Reader reader{file};
|
||||
osmium::apply(reader, manager.handler([&](osmium::memory::Buffer&&) {
|
||||
osmium::apply(reader, manager.handler([&](osmium::memory::Buffer&& /*unused*/) {
|
||||
callback_called = true;
|
||||
}));
|
||||
reader.close();
|
||||
@@ -247,3 +259,64 @@ TEST_CASE("Handle duplicate members correctly") {
|
||||
REQUIRE(manager.count_not_in_any == 2); // 2 relations
|
||||
}
|
||||
|
||||
TEST_CASE("Check handling of missing members") {
|
||||
osmium::io::File file{with_data_dir("t/relations/missing_members.osm")};
|
||||
|
||||
AnyRM manager;
|
||||
|
||||
osmium::relations::read_relations(file, manager);
|
||||
|
||||
osmium::io::Reader reader{file};
|
||||
osmium::apply(reader, manager.handler());
|
||||
reader.close();
|
||||
|
||||
|
||||
size_t nodes = 0;
|
||||
size_t ways = 0;
|
||||
size_t relations = 0;
|
||||
size_t missing_nodes = 0;
|
||||
size_t missing_ways = 0;
|
||||
size_t missing_relations = 0;
|
||||
|
||||
manager.for_each_incomplete_relation([&](const osmium::relations::RelationHandle& handle){
|
||||
if (handle->id() != 31) {
|
||||
// count relation 31 only
|
||||
return;
|
||||
}
|
||||
for (const auto& member : handle->members()) {
|
||||
// RelationMember::ref() is supposed to returns 0 if we are interested in the member.
|
||||
// RelationsManagerBase::get_member_object() is supposed to return a nullptr if the
|
||||
// member is not available (missing in the input file).
|
||||
const osmium::OSMObject* object = manager.get_member_object(member);
|
||||
switch (member.type()) {
|
||||
case osmium::item_type::node :
|
||||
++nodes;
|
||||
if (member.ref() != 0 && !object) {
|
||||
++missing_nodes;
|
||||
}
|
||||
break;
|
||||
case osmium::item_type::way :
|
||||
++ways;
|
||||
if (member.ref() != 0 && !object) {
|
||||
++missing_ways;
|
||||
}
|
||||
break;
|
||||
case osmium::item_type::relation :
|
||||
++relations;
|
||||
if (member.ref() != 0 && !object) {
|
||||
++missing_relations;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
REQUIRE(nodes == 2);
|
||||
REQUIRE(ways == 3);
|
||||
REQUIRE(relations == 3);
|
||||
REQUIRE(missing_nodes == 1);
|
||||
REQUIRE(missing_ways == 1);
|
||||
REQUIRE(missing_relations == 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <osmium/storage/item_stash.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
osmium::memory::Buffer generate_test_data() {
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
+29
-26
@@ -8,6 +8,11 @@
|
||||
#include <osmium/tags/taglist.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <regex>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
template <class TFilter>
|
||||
void check_filter(const osmium::TagList& tag_list,
|
||||
@@ -183,39 +188,37 @@ TEST_CASE("KeyValueFilter") {
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("RegexFilter") {
|
||||
TEST_CASE("RegexFilter matches some tags") {
|
||||
osmium::memory::Buffer buffer{10240};
|
||||
|
||||
SECTION("RegexFilter matches some tags") {
|
||||
osmium::tags::RegexFilter filter{false};
|
||||
filter.add(true, "highway", std::regex{".*_link"});
|
||||
osmium::tags::RegexFilter filter{false};
|
||||
filter.add(true, "highway", std::regex{".*_link"});
|
||||
|
||||
const osmium::TagList& tag_list1 = make_tag_list(buffer, {
|
||||
{ "highway", "primary_link" },
|
||||
{ "source", "GPS" }
|
||||
});
|
||||
const osmium::TagList& tag_list2 = make_tag_list(buffer, {
|
||||
{ "highway", "primary" },
|
||||
{ "source", "GPS" }
|
||||
});
|
||||
const osmium::TagList& tag_list1 = make_tag_list(buffer, {
|
||||
{ "highway", "primary_link" },
|
||||
{ "source", "GPS" }
|
||||
});
|
||||
const osmium::TagList& tag_list2 = make_tag_list(buffer, {
|
||||
{ "highway", "primary" },
|
||||
{ "source", "GPS" }
|
||||
});
|
||||
|
||||
check_filter(tag_list1, filter, {true, false});
|
||||
check_filter(tag_list2, filter, {false, false});
|
||||
}
|
||||
check_filter(tag_list1, filter, {true, false});
|
||||
check_filter(tag_list2, filter, {false, false});
|
||||
}
|
||||
|
||||
SECTION("RegexFilter matches some tags with lvalue regex") {
|
||||
osmium::tags::RegexFilter filter{false};
|
||||
std::regex r{".*straße"};
|
||||
filter.add(true, "name", r);
|
||||
TEST_CASE("RegexFilter matches some tags with lvalue regex") {
|
||||
osmium::memory::Buffer buffer{10240};
|
||||
osmium::tags::RegexFilter filter{false};
|
||||
std::regex r{".*straße"};
|
||||
filter.add(true, "name", r);
|
||||
|
||||
const osmium::TagList& tag_list = make_tag_list(buffer, {
|
||||
{ "highway", "primary" },
|
||||
{ "name", "Hauptstraße" }
|
||||
});
|
||||
|
||||
check_filter(tag_list, filter, {false, true});
|
||||
}
|
||||
const osmium::TagList& tag_list = make_tag_list(buffer, {
|
||||
{ "highway", "primary" },
|
||||
{ "name", "Hauptstraße" }
|
||||
});
|
||||
|
||||
check_filter(tag_list, filter, {false, true});
|
||||
}
|
||||
|
||||
TEST_CASE("KeyPrefixFilter matches some keys") {
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <osmium/osm/tag.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
using namespace osmium::builder::attr; // NOLINT(google-build-using-namespace)
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/tags/matcher.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
static_assert(std::is_default_constructible<osmium::TagMatcher>::value, "TagMatcher should be default constructible");
|
||||
static_assert(std::is_copy_constructible<osmium::TagMatcher>::value, "TagMatcher should be copy constructible");
|
||||
|
||||
+99
-4
@@ -5,6 +5,8 @@
|
||||
#include <osmium/tags/tags_filter.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Tags filter") {
|
||||
osmium::memory::Buffer buffer{10240};
|
||||
@@ -67,11 +69,104 @@ TEST_CASE("Tags filter") {
|
||||
REQUIRE(2 == std::distance(it, end));
|
||||
|
||||
REQUIRE(it != end);
|
||||
REQUIRE(std::string("highway") == it->key());
|
||||
REQUIRE(std::string("primary") == it->value());
|
||||
REQUIRE(std::string{"highway"} == it->key());
|
||||
REQUIRE(std::string{"primary"} == it->value());
|
||||
++it;
|
||||
REQUIRE(std::string("source") == it->key());
|
||||
REQUIRE(std::string("GPS") == it->value());
|
||||
REQUIRE(std::string{"source"} == it->key());
|
||||
REQUIRE(std::string{"GPS"} == it->value());
|
||||
REQUIRE(++it == end);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct result_type {
|
||||
|
||||
int v = 0;
|
||||
bool b = false;
|
||||
|
||||
result_type() noexcept = default;
|
||||
|
||||
result_type(int v_, bool b_) noexcept :
|
||||
v(v_),
|
||||
b(b_) {
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
return b;
|
||||
}
|
||||
|
||||
}; // struct result_type
|
||||
|
||||
bool operator==(const result_type& lhs, const result_type& rhs) noexcept {
|
||||
return lhs.v == rhs.v && lhs.b == rhs.b;
|
||||
}
|
||||
|
||||
TEST_CASE("TagsFilterBase") {
|
||||
osmium::memory::Buffer buffer{10240};
|
||||
|
||||
const auto pos1 = osmium::builder::add_tag_list(buffer,
|
||||
osmium::builder::attr::_tags({
|
||||
{ "highway", "primary" },
|
||||
{ "name", "Main Street" },
|
||||
{ "source", "GPS" }
|
||||
}));
|
||||
const auto pos2 = osmium::builder::add_tag_list(buffer,
|
||||
osmium::builder::attr::_tags({
|
||||
{ "amenity", "restaurant" },
|
||||
{ "name", "The Golden Goose" }
|
||||
}));
|
||||
const osmium::TagList& tag_list1 = buffer.get<osmium::TagList>(pos1);
|
||||
const osmium::TagList& tag_list2 = buffer.get<osmium::TagList>(pos2);
|
||||
|
||||
SECTION("Filter based on key only: okay") {
|
||||
osmium::TagsFilterBase<result_type> filter;
|
||||
filter.add_rule(result_type{1, true}, osmium::TagMatcher{osmium::StringMatcher::equal{"highway"}});
|
||||
filter.add_rule(result_type{2, true}, osmium::TagMatcher{osmium::StringMatcher::equal{"amenity"}});
|
||||
REQUIRE(filter(*tag_list1.begin()) == result_type(1, true));
|
||||
REQUIRE(filter(*tag_list2.begin()) == result_type(2, true));
|
||||
REQUIRE(filter(*std::next(tag_list1.begin())) == result_type(0, false));
|
||||
REQUIRE(filter(*std::next(tag_list2.begin())) == result_type(0, false));
|
||||
}
|
||||
|
||||
SECTION("Filter based string: shortcut") {
|
||||
osmium::TagsFilterBase<result_type> filter;
|
||||
filter.add_rule({3, true}, "highway");
|
||||
filter.add_rule({4, true}, "amenity", "restaurant");
|
||||
REQUIRE(filter(*tag_list1.begin()) == result_type(3, true));
|
||||
REQUIRE(filter(*tag_list2.begin()) == result_type(4, true));
|
||||
REQUIRE(filter(*std::next(tag_list1.begin())) == result_type(0, false));
|
||||
REQUIRE(filter(*std::next(tag_list2.begin())) == result_type(0, false));
|
||||
}
|
||||
|
||||
SECTION("Filter based on key only: fail") {
|
||||
osmium::TagsFilterBase<result_type> filter;
|
||||
filter.add_rule({5, true}, osmium::StringMatcher::equal{"foo"});
|
||||
filter.add_rule({6, true}, osmium::StringMatcher::equal{"bar"});
|
||||
REQUIRE(filter(*tag_list1.begin()) == result_type(0, false));
|
||||
REQUIRE(filter(*tag_list2.begin()) == result_type(0, false));
|
||||
REQUIRE(filter(*std::next(tag_list1.begin())) == result_type(0, false));
|
||||
REQUIRE(filter(*std::next(tag_list2.begin())) == result_type(0, false));
|
||||
}
|
||||
|
||||
SECTION("KeyFilter iterator filters tags") {
|
||||
osmium::TagsFilterBase<result_type> filter;
|
||||
filter.add_rule({7, true}, osmium::StringMatcher::equal{"highway"})
|
||||
.add_rule({8, true}, osmium::StringMatcher::equal{"source"});
|
||||
|
||||
using iterator = osmium::TagsFilterBase<result_type>::iterator;
|
||||
|
||||
iterator it{std::cref(filter), tag_list1.begin(), tag_list1.end()};
|
||||
|
||||
const iterator end{std::cref(filter), tag_list1.end(), tag_list1.end()};
|
||||
|
||||
REQUIRE(2 == std::distance(it, end));
|
||||
|
||||
REQUIRE(it != end);
|
||||
REQUIRE(std::string{"highway"} == it->key());
|
||||
REQUIRE(std::string{"primary"} == it->value());
|
||||
++it;
|
||||
REQUIRE(std::string{"source"} == it->key());
|
||||
REQUIRE(std::string{"GPS"} == it->value());
|
||||
REQUIRE(++it == end);
|
||||
}
|
||||
|
||||
|
||||
+33
-45
@@ -1,11 +1,8 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/thread/pool.hpp>
|
||||
#include <osmium/util/compatibility.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
struct test_job_with_result {
|
||||
int operator()() const {
|
||||
@@ -14,7 +11,7 @@ struct test_job_with_result {
|
||||
};
|
||||
|
||||
struct test_job_throw {
|
||||
OSMIUM_NORETURN void operator()() const {
|
||||
[[noreturn]] void operator()() const {
|
||||
throw std::runtime_error{"exception in pool thread"};
|
||||
}
|
||||
};
|
||||
@@ -68,51 +65,42 @@ TEST_CASE("if outlier positive number of threads requested, threads configured")
|
||||
REQUIRE(pool.num_threads() > 0);
|
||||
}
|
||||
|
||||
TEST_CASE("thread") {
|
||||
|
||||
TEST_CASE("can get access to default thread pool") {
|
||||
auto& pool = osmium::thread::Pool::default_instance();
|
||||
|
||||
SECTION("can get access to thread pool") {
|
||||
REQUIRE(pool.queue_empty());
|
||||
}
|
||||
|
||||
SECTION("can send job to thread pool") {
|
||||
auto future = pool.submit(test_job_with_result{});
|
||||
|
||||
REQUIRE(future.get() == 42);
|
||||
}
|
||||
|
||||
SECTION("can throw from job in thread pool") {
|
||||
auto future = pool.submit(test_job_throw{});
|
||||
|
||||
REQUIRE_THROWS_AS(future.get(), const std::runtime_error&);
|
||||
}
|
||||
|
||||
REQUIRE(pool.queue_empty());
|
||||
}
|
||||
|
||||
TEST_CASE("thread (user-provided pool)") {
|
||||
TEST_CASE("can send job to default thread pool") {
|
||||
auto& pool = osmium::thread::Pool::default_instance();
|
||||
auto future = pool.submit(test_job_with_result{});
|
||||
REQUIRE(future.get() == 42);
|
||||
}
|
||||
|
||||
TEST_CASE("can throw from job in default thread pool") {
|
||||
auto& pool = osmium::thread::Pool::default_instance();
|
||||
auto future = pool.submit(test_job_throw{});
|
||||
REQUIRE_THROWS_AS(future.get(), const std::runtime_error&);
|
||||
}
|
||||
|
||||
TEST_CASE("can get access to user provided thread pool") {
|
||||
osmium::thread::Pool pool{7};
|
||||
|
||||
SECTION("can get access to thread pool") {
|
||||
REQUIRE(pool.queue_empty());
|
||||
}
|
||||
|
||||
SECTION("can access user-provided number of threads") {
|
||||
REQUIRE(pool.num_threads() == 7);
|
||||
}
|
||||
|
||||
SECTION("can send job to thread pool") {
|
||||
auto future = pool.submit(test_job_with_result{});
|
||||
|
||||
REQUIRE(future.get() == 42);
|
||||
}
|
||||
|
||||
SECTION("can throw from job in thread pool") {
|
||||
auto future = pool.submit(test_job_throw{});
|
||||
|
||||
REQUIRE_THROWS_AS(future.get(), const std::runtime_error&);
|
||||
}
|
||||
|
||||
REQUIRE(pool.queue_empty());
|
||||
}
|
||||
|
||||
TEST_CASE("can access user-provided number of threads from pool") {
|
||||
osmium::thread::Pool pool{7};
|
||||
REQUIRE(pool.num_threads() == 7);
|
||||
}
|
||||
|
||||
TEST_CASE("can send job to user provided thread pool") {
|
||||
osmium::thread::Pool pool{7};
|
||||
auto future = pool.submit(test_job_with_result{});
|
||||
REQUIRE(future.get() == 42);
|
||||
}
|
||||
|
||||
TEST_CASE("can throw from job in user provided thread pool") {
|
||||
osmium::thread::Pool pool{7};
|
||||
auto future = pool.submit(test_job_throw{});
|
||||
REQUIRE_THROWS_AS(future.get(), const std::runtime_error&);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <osmium/thread/util.hpp>
|
||||
|
||||
#include <future>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
// Define assert() to throw this error. This enables the tests to check that
|
||||
// the assert() fails.
|
||||
struct assert_error : public std::runtime_error {
|
||||
explicit assert_error(const char* what_arg) : std::runtime_error(what_arg) {
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef assert
|
||||
#undef assert
|
||||
#endif
|
||||
|
||||
#define assert(x) if (!(x)) { throw assert_error{#x}; }
|
||||
|
||||
#include <osmium/util/cast.hpp>
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ TEST_CASE("use_pool_threads_for_pbf_parsing") {
|
||||
|
||||
TEST_CASE("get_max_queue_size") {
|
||||
osmium::detail::env = nullptr;
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 0) == 0);
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 0) == 2);
|
||||
REQUIRE(osmium::detail::name == "OSMIUM_MAX_NAME_QUEUE_SIZE");
|
||||
|
||||
REQUIRE(osmium::config::get_max_queue_size("NAME", 7) == 7);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <osmium/util/double.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("Check double2string function") {
|
||||
std::string s1;
|
||||
osmium::double2string(s1, 1.123, 7);
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <osmium/io/detail/read_write.hpp>
|
||||
#include <osmium/util/file.hpp>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("file_size(int) and file_offset() of known file") {
|
||||
std::string file_name{with_data_dir("t/util/known_file_size")};
|
||||
const int fd = osmium::io::detail::open_for_reading(file_name);
|
||||
|
||||
+2
-20
@@ -2,31 +2,13 @@
|
||||
|
||||
#include <osmium/util/memory.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("Check memory usage") {
|
||||
#ifdef __linux__
|
||||
const int size_in_mbytes = 10;
|
||||
|
||||
osmium::MemoryUsage m1;
|
||||
REQUIRE(m1.current() > 1);
|
||||
REQUIRE(m1.peak() > 1);
|
||||
|
||||
// Memory reporting on M68k architecture doesn't work properly.
|
||||
# ifndef __m68k__
|
||||
{
|
||||
std::vector<int> v;
|
||||
v.reserve(size_in_mbytes * 1024 * 1024);
|
||||
|
||||
osmium::MemoryUsage m2;
|
||||
REQUIRE(m2.current() >= m1.current() + size_in_mbytes);
|
||||
REQUIRE(m2.peak() >= m1.peak() + size_in_mbytes);
|
||||
REQUIRE(m2.peak() - m2.current() <= 1);
|
||||
}
|
||||
|
||||
osmium::MemoryUsage m3;
|
||||
REQUIRE(m3.current() > 1);
|
||||
REQUIRE(m3.current() <= m3.peak());
|
||||
REQUIRE(m3.peak() >= m1.peak() + size_in_mbytes);
|
||||
# endif
|
||||
#else
|
||||
osmium::MemoryUsage m;
|
||||
REQUIRE(m.current() == 0);
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST_CASE("Anonymous mapping: moving a memory mapping should work") {
|
||||
osmium::MemoryMapping mapping2{std::move(mapping1)};
|
||||
REQUIRE(!!mapping2);
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
mapping1.unmap();
|
||||
mapping1.unmap(); // NOLINT(clang-analyzer-cplusplus.Move) okay here, we are checking our own code
|
||||
|
||||
const auto* addr2 = mapping2.get_addr<int>();
|
||||
REQUIRE(*addr2 == 42);
|
||||
@@ -271,7 +271,7 @@ TEST_CASE("Typed anonymous mapping: moving a memory mapping should work") {
|
||||
osmium::TypedMemoryMapping<uint32_t> mapping2{std::move(mapping1)};
|
||||
REQUIRE(!!mapping2);
|
||||
REQUIRE(!mapping1); // NOLINT(bugprone-use-after-move,misc-use-after-move) okay here, we are checking our own code
|
||||
mapping1.unmap();
|
||||
mapping1.unmap(); // NOLINT(clang-analyzer-cplusplus.Move) okay here, we are checking our own code
|
||||
|
||||
const auto addr2 = mapping2.begin();
|
||||
REQUIRE(*addr2 == 42);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <osmium/osm/timestamp.hpp>
|
||||
#include <osmium/util/minmax.hpp>
|
||||
|
||||
#include <limits>
|
||||
|
||||
TEST_CASE("min_op numeric") {
|
||||
osmium::min_op<int> x;
|
||||
REQUIRE(x() == std::numeric_limits<int>::max());
|
||||
|
||||
+4
-4
@@ -46,22 +46,22 @@ TEST_CASE("string to integer conversion") {
|
||||
REQUIRE(osmium::detail::str_to_int<uint16_t>("65536") == 0);
|
||||
|
||||
test_conv<int32_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483646") == 2147483646ll);
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483646") == 2147483646LL);
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483647") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int32_t>("2147483648") == 0);
|
||||
|
||||
test_conv<uint32_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967294") == 4294967294ull);
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967294") == 4294967294ULL);
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967295") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint32_t>("4294967296") == 0);
|
||||
|
||||
test_conv<int64_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775806") == 9223372036854775806ll);
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775806") == 9223372036854775806LL);
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775807") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<int64_t>("9223372036854775808") == 0);
|
||||
|
||||
test_conv<uint64_t>();
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775806") == 9223372036854775806ull);
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775806") == 9223372036854775806ULL);
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775807") == 0);
|
||||
REQUIRE(osmium::detail::str_to_int<uint64_t>("9223372036854775808") == 0);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
TEST_CASE("Set a single option value from string") {
|
||||
osmium::Options o;
|
||||
|
||||
REQUIRE(o.empty());
|
||||
|
||||
o.set("foo", "bar");
|
||||
REQUIRE("bar" == o.get("foo"));
|
||||
REQUIRE(o.get("empty").empty());
|
||||
@@ -17,6 +19,7 @@ TEST_CASE("Set a single option value from string") {
|
||||
REQUIRE(o.is_not_false("empty"));
|
||||
|
||||
REQUIRE(1 == o.size());
|
||||
REQUIRE_FALSE(o.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Set option values from booleans") {
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
#include <osmium/util/string.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("split_string string") {
|
||||
const std::string str{"foo,baramba,baz"};
|
||||
const std::vector<std::string> result = {"foo", "baramba", "baz"};
|
||||
|
||||
@@ -3,7 +3,13 @@
|
||||
#include <osmium/util/string_matcher.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#ifdef OSMIUM_WITH_REGEX
|
||||
#include <regex>
|
||||
#endif
|
||||
|
||||
static_assert(std::is_default_constructible<osmium::StringMatcher>::value, "StringMatcher should be default constructible");
|
||||
static_assert(std::is_copy_constructible<osmium::StringMatcher>::value, "StringMatcher should be copy constructible");
|
||||
|
||||
Reference in New Issue
Block a user