Merge commit '0c6dee4befebf823d839d1092bcae79afbf4f12e' into merge/libosmium-2.11.0

This commit is contained in:
Michael Krasnyk
2017-01-20 14:05:21 +01:00
231 changed files with 2732 additions and 1500 deletions
+4
View File
@@ -138,10 +138,12 @@ add_unit_test(osm test_way)
add_unit_test(memory test_buffer_basics)
add_unit_test(memory test_buffer_node)
add_unit_test(memory test_buffer_purge)
add_unit_test(memory test_type_is_compatible)
add_unit_test(builder test_attr)
add_unit_test(builder test_object_builder)
add_unit_test(geom test_coordinates)
add_unit_test(geom test_crs ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
add_unit_test(geom test_exception)
add_unit_test(geom test_factory_with_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
@@ -158,6 +160,8 @@ add_unit_test(geom test_wkt)
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_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})
@@ -0,0 +1,7 @@
add_test(NAME examples_amenity_list
COMMAND osmium_amenity_list ${CMAKE_CURRENT_SOURCE_DIR}/node.osm)
set_tests_properties(examples_amenity_list PROPERTIES
PASS_REGULAR_EXPRESSION " 8\\.8721, 53\\.0966 post_office")
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6">
<node id="24960505" version="5" timestamp="2013-02-28T23:26:39Z" uid="715371" user="cracklinrain" changeset="15203542" lat="53.096629" lon="8.8720536">
<tag k="amenity" v="post_office"/>
<tag k="wheelchair" v="yes"/>
</node>
</osm>
+9 -5
View File
@@ -1,6 +1,6 @@
/*
* Catch v1.5.8
* Generated: 2016-10-26 12:07:30.938259
* Catch v1.5.9
* Generated: 2016-11-29 12:14:38.049276
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@@ -3428,6 +3428,7 @@ namespace Catch {
#include <streambuf>
#include <ostream>
#include <fstream>
#include <memory>
namespace Catch {
@@ -3995,9 +3996,12 @@ namespace Clara {
inline void convertInto( std::string const& _source, std::string& _dest ) {
_dest = _source;
}
char toLowerCh(char c) {
return static_cast<char>( ::tolower( c ) );
}
inline void convertInto( std::string const& _source, bool& _dest ) {
std::string sourceLC = _source;
std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower );
std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
_dest = true;
else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
@@ -7578,7 +7582,7 @@ namespace Catch {
return os;
}
Version libraryVersion( 1, 5, 8, "", 0 );
Version libraryVersion( 1, 5, 9, "", 0 );
}
@@ -9166,6 +9170,7 @@ namespace Catch {
public:
XmlReporter( ReporterConfig const& _config )
: StreamingReporterBase( _config ),
m_xml(_config.stream()),
m_sectionDepth( 0 )
{
m_reporterPrefs.shouldRedirectStdOut = true;
@@ -9185,7 +9190,6 @@ namespace Catch {
virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
StreamingReporterBase::testRunStarting( testInfo );
m_xml.setStream( stream );
m_xml.startElement( "Catch" );
if( !m_config->name().empty() )
m_xml.writeAttribute( "name", m_config->name() );
+17 -20
View File
@@ -2,24 +2,21 @@
#include <osmium/osm/area.hpp>
TEST_CASE("area_id") {
SECTION("object_id_to_area_id_conversion") {
REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way));
REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation));
REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way));
REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation));
REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way));
REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation));
}
SECTION("area_id_to_object_id_conversion") {
REQUIRE( 23 == osmium::area_id_to_object_id( 46));
REQUIRE( 23 == osmium::area_id_to_object_id( 47));
REQUIRE( 0 == osmium::area_id_to_object_id( 0));
REQUIRE( 0 == osmium::area_id_to_object_id( 1));
REQUIRE(-12 == osmium::area_id_to_object_id(-24));
REQUIRE(-12 == osmium::area_id_to_object_id(-25));
}
TEST_CASE("object_id to area_id conversion") {
REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way));
REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation));
REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way));
REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation));
REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way));
REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation));
}
TEST_CASE("area_id to object_id conversion") {
REQUIRE( 23 == osmium::area_id_to_object_id( 46));
REQUIRE( 23 == osmium::area_id_to_object_id( 47));
REQUIRE( 0 == osmium::area_id_to_object_id( 0));
REQUIRE( 0 == osmium::area_id_to_object_id( 1));
REQUIRE(-12 == osmium::area_id_to_object_id(-24));
REQUIRE(-12 == osmium::area_id_to_object_id(-25));
}
+151 -155
View File
@@ -4,164 +4,160 @@
using osmium::area::detail::NodeRefSegment;
TEST_CASE("NodeRefSegmentClass") {
SECTION("instantiation_with_default_parameters") {
NodeRefSegment s;
REQUIRE(s.first().ref() == 0);
REQUIRE(s.first().location() == osmium::Location());
REQUIRE(s.second().ref() == 0);
REQUIRE(s.second().location() == osmium::Location());
}
SECTION("instantiation") {
osmium::NodeRef nr1(1, { 1.2, 3.4 });
osmium::NodeRef nr2(2, { 1.4, 3.1 });
osmium::NodeRef nr3(3, { 1.2, 3.6 });
osmium::NodeRef nr4(4, { 1.2, 3.7 });
NodeRefSegment s1(nr1, nr2);
REQUIRE(s1.first().ref() == 1);
REQUIRE(s1.second().ref() == 2);
NodeRefSegment s2(nr2, nr3);
REQUIRE(s2.first().ref() == 3);
REQUIRE(s2.second().ref() == 2);
NodeRefSegment s3(nr3, nr4);
REQUIRE(s3.first().ref() == 3);
REQUIRE(s3.second().ref() == 4);
}
SECTION("intersection") {
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}});
NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}});
NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}});
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}});
NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}});
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}});
NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}});
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s2, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s3) == osmium::Location());
REQUIRE(calculate_intersection(s3, s1) == osmium::Location());
REQUIRE(calculate_intersection(s2, s3) == osmium::Location());
REQUIRE(calculate_intersection(s3, s2) == osmium::Location());
REQUIRE(calculate_intersection(s1, s4) == osmium::Location());
REQUIRE(calculate_intersection(s4, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s6, s7) == osmium::Location());
REQUIRE(calculate_intersection(s7, s6) == osmium::Location());
}
SECTION("intersection of collinear segments") {
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 0.0}}); // *---*
NodeRefSegment s2({ 3, {2.0, 0.0}}, { 4, {4.0, 0.0}}); // *---*
NodeRefSegment s3({ 5, {0.0, 0.0}}, { 6, {1.0, 0.0}}); // *-*
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {2.0, 0.0}}); // *-*
NodeRefSegment s5({ 9, {1.0, 0.0}}, {10, {3.0, 0.0}}); // *---*
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {4.0, 0.0}}); // *-------*
NodeRefSegment s7({13, {0.0, 0.0}}, {14, {5.0, 0.0}}); // *---------*
NodeRefSegment s8({13, {1.0, 0.0}}, {14, {5.0, 0.0}}); // *-------*
NodeRefSegment s9({13, {3.0, 0.0}}, {14, {4.0, 0.0}}); // *-*
REQUIRE(calculate_intersection(s1, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s2) == osmium::Location());
REQUIRE(calculate_intersection(s2, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s3) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s3, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s4) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s4, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s1, s8) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s8, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s9) == osmium::Location());
REQUIRE(calculate_intersection(s9, s1) == osmium::Location());
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s6, s5) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s7, s8) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s8, s7) == osmium::Location(1.0, 0.0));
}
SECTION("intersection of very long segments") {
NodeRefSegment s1({ 1, {90.0, 90.0}}, { 2, {-90.0, -90.0}});
NodeRefSegment s2({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(0.0, 0.0));
NodeRefSegment s3({ 1, {-90.0, -90.0}}, { 2, {90.0, 90.0}});
NodeRefSegment s4({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
REQUIRE(calculate_intersection(s3, s4) == osmium::Location(0.0, 0.0));
NodeRefSegment s5({ 1, {-90.00000001, -90.0}}, { 2, {90.0, 90.0}});
NodeRefSegment s6({ 1, {-90.0, 90.0}}, { 2, {90.0, -90.0}});
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(0.0, 0.0));
}
SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE( osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE( osmium::location_less()(node_ref1, node_ref3));
REQUIRE( osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
TEST_CASE("Default construction of NodeRefSegment") {
NodeRefSegment s;
REQUIRE(s.first().ref() == 0);
REQUIRE(s.first().location() == osmium::Location());
REQUIRE(s.second().ref() == 0);
REQUIRE(s.second().location() == osmium::Location());
}
TEST_CASE("Ordering of NodeRefSegments") {
osmium::NodeRef nr0(0, { 0.0, 0.0 });
osmium::NodeRef nr1(1, { 1.0, 0.0 });
osmium::NodeRef nr2(2, { 0.0, 1.0 });
osmium::NodeRef nr3(3, { 2.0, 0.0 });
osmium::NodeRef nr4(4, { 0.0, 2.0 });
osmium::NodeRef nr5(5, { 1.0, 1.0 });
osmium::NodeRef nr6(6, { 2.0, 2.0 });
osmium::NodeRef nr7(6, { 1.0, 2.0 });
TEST_CASE("Construction of NodeRefSegment with NodeRefs") {
osmium::NodeRef nr1{1, {1.2, 3.4}};
osmium::NodeRef nr2{2, {1.4, 3.1}};
osmium::NodeRef nr3{3, {1.2, 3.6}};
osmium::NodeRef nr4{4, {1.2, 3.7}};
NodeRefSegment s1(nr0, nr1);
NodeRefSegment s2(nr0, nr2);
NodeRefSegment s3(nr0, nr3);
NodeRefSegment s4(nr0, nr4);
NodeRefSegment s5(nr0, nr5);
NodeRefSegment s6(nr0, nr6);
NodeRefSegment s7(nr0, nr7);
NodeRefSegment s1{nr1, nr2};
REQUIRE(s1.first().ref() == 1);
REQUIRE(s1.second().ref() == 2);
NodeRefSegment s2{nr2, nr3};
REQUIRE(s2.first().ref() == 3);
REQUIRE(s2.second().ref() == 2);
NodeRefSegment s3{nr3, nr4};
REQUIRE(s3.first().ref() == 3);
REQUIRE(s3.second().ref() == 4);
}
TEST_CASE("Intersection of NodeRefSegments") {
NodeRefSegment s1{{ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}};
NodeRefSegment s2{{ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}};
NodeRefSegment s3{{ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}};
NodeRefSegment s4{{ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}};
NodeRefSegment s5{{ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}};
NodeRefSegment s6{{11, {0.0, 0.0}}, {12, {1.0, 1.0}}};
NodeRefSegment s7{{13, {1.0, 1.0}}, {14, {3.0, 3.0}}};
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s2, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s3) == osmium::Location());
REQUIRE(calculate_intersection(s3, s1) == osmium::Location());
REQUIRE(calculate_intersection(s2, s3) == osmium::Location());
REQUIRE(calculate_intersection(s3, s2) == osmium::Location());
REQUIRE(calculate_intersection(s1, s4) == osmium::Location());
REQUIRE(calculate_intersection(s4, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s6, s7) == osmium::Location());
REQUIRE(calculate_intersection(s7, s6) == osmium::Location());
}
TEST_CASE("Intersection of collinear NodeRefSegments") {
NodeRefSegment s1{{ 1, {0.0, 0.0}}, { 2, {2.0, 0.0}}}; // *---*
NodeRefSegment s2{{ 3, {2.0, 0.0}}, { 4, {4.0, 0.0}}}; // *---*
NodeRefSegment s3{{ 5, {0.0, 0.0}}, { 6, {1.0, 0.0}}}; // *-*
NodeRefSegment s4{{ 7, {1.0, 0.0}}, { 8, {2.0, 0.0}}}; // *-*
NodeRefSegment s5{{ 9, {1.0, 0.0}}, {10, {3.0, 0.0}}}; // *---*
NodeRefSegment s6{{11, {0.0, 0.0}}, {12, {4.0, 0.0}}}; // *-------*
NodeRefSegment s7{{13, {0.0, 0.0}}, {14, {5.0, 0.0}}}; // *---------*
NodeRefSegment s8{{13, {1.0, 0.0}}, {14, {5.0, 0.0}}}; // *-------*
NodeRefSegment s9{{13, {3.0, 0.0}}, {14, {4.0, 0.0}}}; // *-*
REQUIRE(calculate_intersection(s1, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s2) == osmium::Location());
REQUIRE(calculate_intersection(s2, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s3) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s3, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s4) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s4, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s5, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s6) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s6, s1) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s1, s7) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s7, s1) == osmium::Location(2.0, 0.0));
REQUIRE(calculate_intersection(s1, s8) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s8, s1) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s1, s9) == osmium::Location());
REQUIRE(calculate_intersection(s9, s1) == osmium::Location());
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s6, s5) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s7, s8) == osmium::Location(1.0, 0.0));
REQUIRE(calculate_intersection(s8, s7) == osmium::Location(1.0, 0.0));
}
TEST_CASE("Intersection of very long NodeRefSegments") {
NodeRefSegment s1{{1, {90.0, 90.0}}, {2, {-90.0, -90.0}}};
NodeRefSegment s2{{1, {-90.0, 90.0}}, {2, {90.0, -90.0}}};
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(0.0, 0.0));
NodeRefSegment s3{{1, {-90.0, -90.0}}, {2, {90.0, 90.0}}};
NodeRefSegment s4{{1, {-90.0, 90.0}}, {2, {90.0, -90.0}}};
REQUIRE(calculate_intersection(s3, s4) == osmium::Location(0.0, 0.0));
NodeRefSegment s5{{1, {-90.00000001, -90.0}}, {2, {90.0, 90.0}}};
NodeRefSegment s6{{1, {-90.0, 90.0}}, {2, {90.0, -90.0}}};
REQUIRE(calculate_intersection(s5, s6) == osmium::Location(0.0, 0.0));
}
TEST_CASE("Ordering of NodeRefSegements") {
osmium::NodeRef node_ref1{1, {1.0, 3.0}};
osmium::NodeRef node_ref2{2, {1.4, 2.9}};
osmium::NodeRef node_ref3{3, {1.2, 3.0}};
osmium::NodeRef node_ref4{4, {1.2, 3.3}};
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE( osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE( osmium::location_less()(node_ref1, node_ref3));
REQUIRE( osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
TEST_CASE("More ordering of NodeRefSegments") {
osmium::NodeRef nr0{0, {0.0, 0.0}};
osmium::NodeRef nr1{1, {1.0, 0.0}};
osmium::NodeRef nr2{2, {0.0, 1.0}};
osmium::NodeRef nr3{3, {2.0, 0.0}};
osmium::NodeRef nr4{4, {0.0, 2.0}};
osmium::NodeRef nr5{5, {1.0, 1.0}};
osmium::NodeRef nr6{6, {2.0, 2.0}};
osmium::NodeRef nr7{6, {1.0, 2.0}};
NodeRefSegment s1{nr0, nr1};
NodeRefSegment s2{nr0, nr2};
NodeRefSegment s3{nr0, nr3};
NodeRefSegment s4{nr0, nr4};
NodeRefSegment s5{nr0, nr5};
NodeRefSegment s6{nr0, nr6};
NodeRefSegment s7{nr0, nr7};
// s1
REQUIRE_FALSE(s1 < s1);
+9 -9
View File
@@ -17,7 +17,7 @@ TEST_CASE("create node using builders") {
using namespace osmium::builder::attr;
osmium::memory::Buffer buffer(1024*10);
osmium::memory::Buffer buffer{1024 * 10};
SECTION("add node with only id") {
const auto pos = osmium::builder::add_node(buffer, _id(22));
@@ -35,11 +35,11 @@ TEST_CASE("create node using builders") {
}
SECTION("add node with complete info but no tags") {
const auto loc = osmium::Location(3.14, 1.59);
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")),
_timestamp(osmium::Timestamp{"2015-01-01T10:20:30Z"}),
_cid(21),
_uid(222),
_location(loc),
@@ -78,7 +78,7 @@ TEST_CASE("create node using builders") {
}
SECTION("order of attributes doesn't matter") {
const auto loc = osmium::Location(3.14, 1.59);
const osmium::Location loc{3.14, 1.59};
const auto pos = osmium::builder::add_node(buffer,
_timestamp("2015-01-01T10:20:30Z"),
_version(17),
@@ -224,7 +224,7 @@ TEST_CASE("create way using builders") {
using namespace osmium::builder::attr;
osmium::memory::Buffer buffer(1024*10);
osmium::memory::Buffer buffer{1024 * 10};
SECTION("add way without nodes") {
const auto pos = osmium::builder::add_way(buffer,
@@ -259,7 +259,7 @@ TEST_CASE("create way with nodes") {
using namespace osmium::builder::attr;
osmium::memory::Buffer wbuffer(1024*10);
osmium::memory::Buffer wbuffer{1024 * 10};
osmium::builder::add_way(wbuffer,
_id(1),
_nodes({1, 2, 4, 8})
@@ -267,7 +267,7 @@ TEST_CASE("create way with nodes") {
const osmium::NodeRefList& nodes = wbuffer.get<osmium::Way>(0).nodes();
osmium::memory::Buffer buffer(1024*10);
osmium::memory::Buffer buffer{1024 * 10};
SECTION("add nodes using an OSM object id or NodeRef") {
osmium::builder::add_way(buffer,
@@ -380,7 +380,7 @@ TEST_CASE("create relation using builders") {
using namespace osmium::builder::attr;
osmium::memory::Buffer buffer(1024*10);
osmium::memory::Buffer buffer{1024 * 10};
SECTION("create relation") {
osmium::builder::attr::member_type m{osmium::item_type::way, 113, "inner"};
@@ -540,7 +540,7 @@ TEST_CASE("create area using builders") {
using namespace osmium::builder::attr;
osmium::memory::Buffer buffer(1024*10);
osmium::memory::Buffer buffer{1024 * 10};
SECTION("add area without rings") {
const auto pos = osmium::builder::add_area(buffer,
+10 -10
View File
@@ -6,7 +6,7 @@
#include <osmium/osm.hpp>
TEST_CASE("create objects using builder") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
std::string user;
SECTION("complete node with tags") {
@@ -68,7 +68,7 @@ TEST_CASE("create objects using builder") {
user = "123456789012345678";
}
osmium::Location loc{1.2, 3.4};
const osmium::Location loc{1.2, 3.4};
{
osmium::builder::NodeBuilder builder{buffer};
@@ -272,8 +272,8 @@ TEST_CASE("create objects using builder") {
}
SECTION("complete changeset with tags") {
osmium::Location bl{-1.2, -3.4};
osmium::Location tr{1.2, 3.4};
const osmium::Location bl{-1.2, -3.4};
const osmium::Location tr{1.2, 3.4};
SECTION("user length 0") {
user = "";
@@ -365,7 +365,7 @@ TEST_CASE("create objects using builder") {
}
TEST_CASE("no call to set_user on node") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
{
osmium::builder::NodeBuilder builder{buffer};
@@ -377,7 +377,7 @@ TEST_CASE("no call to set_user on node") {
}
TEST_CASE("set_user with length on node") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
std::string user = "userx";
{
@@ -391,7 +391,7 @@ TEST_CASE("set_user with length on node") {
}
TEST_CASE("no call to set_user on way") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
{
osmium::builder::WayBuilder builder{buffer};
@@ -403,7 +403,7 @@ TEST_CASE("no call to set_user on way") {
}
TEST_CASE("set_user with length on way") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
std::string user = "userx";
{
@@ -417,7 +417,7 @@ TEST_CASE("set_user with length on way") {
}
TEST_CASE("no call to set_user on changeset") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
{
osmium::builder::ChangesetBuilder builder{buffer};
@@ -429,7 +429,7 @@ TEST_CASE("no call to set_user on changeset") {
}
TEST_CASE("set_user with length on changeset") {
osmium::memory::Buffer buffer{1024*10};
osmium::memory::Buffer buffer{1024 * 10};
std::string user = "userx";
{
+71
View File
@@ -0,0 +1,71 @@
#include "catch.hpp"
#include <osmium/geom/coordinates.hpp>
TEST_CASE("Default constructed coordinates are invalid") {
const osmium::geom::Coordinates c;
REQUIRE_FALSE(c.valid());
}
TEST_CASE("Coordinates constructed from doubles are valid") {
const osmium::geom::Coordinates c{1.2, 3.4};
REQUIRE(c.valid());
REQUIRE(c.x == Approx(1.2));
REQUIRE(c.y == Approx(3.4));
}
TEST_CASE("Coordinates constructed from a location are valid") {
const osmium::Location loc{1.2, 3.4};
const osmium::geom::Coordinates c{loc};
REQUIRE(c.valid());
REQUIRE(c.x == Approx(1.2));
REQUIRE(c.y == Approx(3.4));
}
TEST_CASE("Comparing coordinates") {
const osmium::geom::Coordinates ci1;
const osmium::geom::Coordinates ci2;
const osmium::geom::Coordinates cv1{1.2, 3.4};
const osmium::geom::Coordinates cv2{1.2, 3.4};
const osmium::geom::Coordinates cv3{2.1, 4.3};
REQUIRE(ci1 == ci2);
REQUIRE_FALSE(ci1 == cv1);
REQUIRE(cv1 == cv2);
REQUIRE_FALSE(cv1 == cv3);
}
TEST_CASE("Write coordinates to string") {
const osmium::geom::Coordinates c{0.1234567, 1.89898989};
std::string out;
SECTION("precision 7") {
c.append_to_string(out, ',', 7);
REQUIRE(out == "0.1234567,1.8989899");
}
SECTION("precision 3") {
c.append_to_string(out, ',', 3);
REQUIRE(out == "0.123,1.899");
}
SECTION("with prefix and suffix") {
c.append_to_string(out, '(', ',', ')', 3);
REQUIRE(out == "(0.123,1.899)");
}
}
TEST_CASE("Write invalid coordinates to string") {
const osmium::geom::Coordinates c;
std::string out;
SECTION("with infix only") {
c.append_to_string(out, ',', 7);
REQUIRE(out == "invalid");
}
SECTION("with prefix and suffix") {
c.append_to_string(out, '(', ',', ')', 3);
REQUIRE(out == "(invalid)");
}
}
-2
View File
@@ -1,7 +1,5 @@
#include "catch.hpp"
#include <random>
#include <osmium/geom/projection.hpp>
TEST_CASE("CRS") {
+16
View File
@@ -6,6 +6,14 @@
#include "test_tile_data.hpp"
TEST_CASE("Helper functions") {
REQUIRE(osmium::geom::num_tiles_in_zoom(0) == 1);
REQUIRE(osmium::geom::num_tiles_in_zoom(1) == 2);
REQUIRE(osmium::geom::num_tiles_in_zoom(12) == 4096);
REQUIRE(osmium::geom::tile_extent_in_zoom(1) == osmium::geom::detail::max_coordinate_epsg3857);
}
TEST_CASE("Tile from x0.0 y0.0 at zoom 0") {
osmium::Location l{0.0, 0.0};
@@ -61,6 +69,14 @@ TEST_CASE("Tile from max values at zoom 30") {
REQUIRE(t.valid());
}
TEST_CASE("Tile from coordinates") {
osmium::geom::Coordinates c{9.99312, 53.55078};
osmium::geom::Tile t{12, osmium::geom::lonlat_to_mercator(c)};
REQUIRE(t.valid());
REQUIRE(t.x == 2161);
REQUIRE(t.y == 1323);
}
TEST_CASE("Tile equality") {
osmium::geom::Tile a{4, 3, 4};
osmium::geom::Tile b{4, 3, 4};
+10 -8
View File
@@ -18,13 +18,6 @@ TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
}
SECTION("point in web mercator") {
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb == "010100000028706E7BF9BD1541B03E0D93E48F1C41");
}
SECTION("point in ewkb") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
@@ -32,12 +25,21 @@ TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
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 == "0101000020110F000028706E7BF9BD1541B03E0D93E48F1C41");
REQUIRE(wkb == "0101000020110F000028706E7BF9BD1541D6A90093E48F1C41");
}
#endif
}
@@ -37,6 +37,11 @@ void test_func_all(TIndex& index) {
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE_THROWS_WITH(index.get(0), "id 0 not found");
REQUIRE_THROWS_WITH(index.get(1), "id 1 not found");
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
template <typename TIndex>
@@ -54,11 +59,19 @@ void test_func_real(TIndex& index) {
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE(loc1 == index.get_noexcept(id1));
REQUIRE(loc2 == index.get_noexcept(id2));
REQUIRE_THROWS_AS(index.get(0), osmium::not_found);
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
index.clear();
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
@@ -68,6 +81,13 @@ void test_func_real(TIndex& index) {
REQUIRE_THROWS_AS(index.get(1), osmium::not_found);
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
REQUIRE(index.get_noexcept(id1) == osmium::Location{});
REQUIRE(index.get_noexcept(id2) == osmium::Location{});
REQUIRE(index.get_noexcept(0) == osmium::Location{});
REQUIRE(index.get_noexcept(1) == osmium::Location{});
REQUIRE(index.get_noexcept(5) == osmium::Location{});
REQUIRE(index.get_noexcept(100) == osmium::Location{});
}
TEST_CASE("Map Id to location: Dummy") {
@@ -0,0 +1,86 @@
#include "catch.hpp"
#include <osmium/builder/attr.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/object_pointer_collection.hpp>
#include <osmium/osm/object_comparisons.hpp>
#include <osmium/visitor.hpp>
using namespace osmium::builder::attr;
TEST_CASE("Create ObjectPointerCollection") {
osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::add_node(buffer,
_id(3),
_version(3)
);
osmium::builder::add_node(buffer,
_id(1),
_version(2)
);
osmium::builder::add_node(buffer,
_id(1),
_version(4)
);
osmium::ObjectPointerCollection collection;
REQUIRE(collection.empty());
REQUIRE(collection.size() == 0);
osmium::apply(buffer, collection);
REQUIRE_FALSE(collection.empty());
REQUIRE(collection.size() == 3);
auto it = collection.cbegin();
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_version{});
REQUIRE(collection.size() == 3);
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.sort(osmium::object_order_type_id_reverse_version{});
it = collection.cbegin();
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 4);
++it;
REQUIRE(it->id() == 1);
REQUIRE(it->version() == 2);
++it;
REQUIRE(it->id() == 3);
REQUIRE(it->version() == 3);
++it;
REQUIRE(it == collection.cend());
collection.clear();
REQUIRE(collection.empty());
REQUIRE(collection.size() == 0);
}
@@ -0,0 +1,50 @@
#include "catch.hpp"
#include <type_traits>
#include <osmium/index/relations_map.hpp>
static_assert(std::is_default_constructible<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be default constructible");
static_assert(std::is_copy_constructible<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be copy constructible");
static_assert(std::is_copy_constructible<osmium::index::RelationsMapStash>::value == false, "RelationsMapStash should not be copy constructible");
static_assert(std::is_copy_assignable<osmium::index::RelationsMapIndex>::value == false, "RelationsMapIndex should not be copy assignable");
static_assert(std::is_copy_assignable<osmium::index::RelationsMapStash>::value == false, "RelationsMapStash should not be copy assignable");
TEST_CASE("RelationsMapStash lvalue") {
osmium::index::RelationsMapStash stash;
REQUIRE(stash.empty());
REQUIRE(stash.size() == 0);
stash.add(1, 2);
stash.add(2, 3);
REQUIRE_FALSE(stash.empty());
REQUIRE(stash.size() == 2);
auto index= stash.build_index();
REQUIRE_FALSE(index.empty());
REQUIRE(index.size() == 2);
index.for_each_parent(1, [](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
});
}
osmium::index::RelationsMapIndex func() {
osmium::index::RelationsMapStash stash;
stash.add(1, 2);
stash.add(2, 3);
return stash.build_index();
}
TEST_CASE("RelationsMapStash rvalue") {
const osmium::index::RelationsMapIndex index{func()};
index.for_each_parent(1, [](osmium::unsigned_object_id_type id) {
REQUIRE(id == 2);
});
}
+13 -17
View File
@@ -7,27 +7,23 @@
#include <osmium/io/bzip2_compression.hpp>
TEST_CASE("Bzip2") {
TEST_CASE("Read bzip2-compressed file") {
std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
SECTION("read_compressed_file") {
std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2");
const int fd = ::open(input_file.c_str(), O_RDONLY);
REQUIRE(fd > 0);
int fd = ::open(input_file.c_str(), O_RDONLY);
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;
}
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;
}
REQUIRE(9 == size);
REQUIRE("TESTDATA\n" == all);
}
REQUIRE(9 == size);
REQUIRE("TESTDATA\n" == all);
}
+263 -267
View File
@@ -4,272 +4,268 @@
#include <osmium/io/file.hpp>
TEST_CASE("FileFormats") {
SECTION("default_file_format") {
osmium::io::File f;
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_empty") {
osmium::io::File f {""};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_dash") {
osmium::io::File f {"-"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_bz2") {
osmium::io::File f {"-", "osm.bz2"};
REQUIRE("" == f.filename());
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm") {
osmium::io::File f {"test.osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_pbf") {
osmium::io::File f {"test.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test.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());
f.check();
}
SECTION("detect_file_format_by_suffix_opl") {
osmium::io::File f {"test.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test.osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test.osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_opl_bz2") {
osmium::io::File f {"test.osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test.osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_opl_gz") {
osmium::io::File f {"test.osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test.osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm") {
osmium::io::File f {"test", "osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_pbf") {
osmium::io::File f {"test", "pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test", "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());
f.check();
}
SECTION("override_file_format_by_suffix_opl") {
osmium::io::File f {"test", "opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test", "osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test", "osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_opl_bz2") {
osmium::io::File f {"test", "osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test", "osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osh_opl_gz") {
osmium::io::File f {"test", "osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test", "osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("format_options_pbf_history") {
osmium::io::File f {"test", "pbf,history=true"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("format_options_pbf_foo") {
osmium::io::File f {"test.osm", "pbf,foo=bar"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("bar" == f.get("foo"));
f.check();
}
SECTION("format_options_xml_abc_something") {
osmium::io::File f {"test.bla", "xml,abc,some=thing"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("true" == f.get("abc"));
REQUIRE("thing" == f.get("some"));
REQUIRE(2 == std::distance(f.begin(), f.end()));
f.check();
}
SECTION("unknown_format_foo_bar") {
osmium::io::File f {"test.foo.bar"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_foo") {
osmium::io::File f {"test", "foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_osm_foo") {
osmium::io::File f {"test", "osm.foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_bla_equals_foo") {
osmium::io::File f {"test", "bla=foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("url without format") {
osmium::io::File f {"http://www.example.com/api"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("url without format and filename") {
osmium::io::File f {"http://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());
f.check();
}
SECTION("url with format") {
osmium::io::File f {"http://www.example.com/api", "osh"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Default file format") {
osmium::io::File f;
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("File format when empty (stdin/stdout)") {
osmium::io::File f{""};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("File format from dash (stdin/stdout)") {
osmium::io::File f{"-"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("File format from dash with osm.bz2") {
osmium::io::File f{"-", "osm.bz2"};
REQUIRE("" == f.filename());
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osm'") {
osmium::io::File f{"test.osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'pbf'") {
osmium::io::File f{"test.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osm.pbf'") {
osmium::io::File f{"test.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());
f.check();
}
TEST_CASE("Detect file format by suffix 'opl'") {
osmium::io::File f{"test.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osm.opl'") {
osmium::io::File f{"test.osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osm.gz'") {
osmium::io::File f{"test.osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'opl.bz2'") {
osmium::io::File f{"test.osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osc.gz'") {
osmium::io::File f{"test.osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'opl.gz'") {
osmium::io::File f{"test.osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Detect file format by suffix 'osh.pbf'") {
osmium::io::File f{"test.osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osm'") {
osmium::io::File f{"test", "osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'pbf'") {
osmium::io::File f{"test", "pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osm.pbf'") {
osmium::io::File f{"test", "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());
f.check();
}
TEST_CASE("Override file format by suffix 'opl'") {
osmium::io::File f{"test", "opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osm.opl'") {
osmium::io::File f{"test", "osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osm.gz'") {
osmium::io::File f{"test", "osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osm.opl.bz2'") {
osmium::io::File f{"test", "osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osc.gz'") {
osmium::io::File f{"test", "osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osh.opl.gz'") {
osmium::io::File f{"test", "osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Override file format by suffix 'osh.pbf'") {
osmium::io::File f{"test", "osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Format option pbf history") {
osmium::io::File f{"test", "pbf,history=true"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("Format option pbf foo") {
osmium::io::File f{"test.osm", "pbf,foo=bar"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("bar" == f.get("foo"));
f.check();
}
TEST_CASE("Format option xml abc something") {
osmium::io::File f{"test.bla", "xml,abc,some=thing"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("true" == f.get("abc"));
REQUIRE("thing" == f.get("some"));
REQUIRE(2 == std::distance(f.begin(), f.end()));
f.check();
}
TEST_CASE("Unknown format 'foo.bar'") {
osmium::io::File f{"test.foo.bar"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("Unknown format 'foo'") {
osmium::io::File f{"test", "foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("Unknown format 'osm.foo'") {
osmium::io::File f{"test", "osm.foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("Unknown format 'bla=foo'") {
osmium::io::File f{"test", "bla=foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
TEST_CASE("URL without format") {
osmium::io::File f{"http://www.example.com/api"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
TEST_CASE("URL without format and filename") {
osmium::io::File f{"http://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());
f.check();
}
TEST_CASE("URL with format") {
osmium::io::File f{"http://www.example.com/api", "osh"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
+12 -13
View File
@@ -6,29 +6,28 @@
TEST_CASE("output iterator") {
SECTION("should be copy constructable") {
osmium::io::Header header;
osmium::io::Writer writer("test.osm", header, osmium::io::overwrite::allow);
osmium::io::OutputIterator<osmium::io::Writer> out1(writer);
osmium::io::Header header;
osmium::io::OutputIterator<osmium::io::Writer> out2(out1);
SECTION("should be copy constructable") {
osmium::io::Writer writer{"test.osm", header, osmium::io::overwrite::allow};
osmium::io::OutputIterator<osmium::io::Writer> out1{writer};
osmium::io::OutputIterator<osmium::io::Writer> out2{out1};
}
SECTION("should be copy assignable") {
osmium::io::Header header;
osmium::io::Writer writer1("test1.osm", header, osmium::io::overwrite::allow);
osmium::io::Writer writer2("test2.osm", header, osmium::io::overwrite::allow);
osmium::io::Writer writer1{"test1.osm", header, osmium::io::overwrite::allow};
osmium::io::Writer writer2{"test2.osm", header, osmium::io::overwrite::allow};
osmium::io::OutputIterator<osmium::io::Writer> out1(writer1);
osmium::io::OutputIterator<osmium::io::Writer> out2(writer2);
osmium::io::OutputIterator<osmium::io::Writer> out1{writer1};
osmium::io::OutputIterator<osmium::io::Writer> out2{writer2};
out2 = out1;
}
SECTION("should be incrementable") {
osmium::io::Header header;
osmium::io::Writer writer("test.osm", header, osmium::io::overwrite::allow);
osmium::io::OutputIterator<osmium::io::Writer> out(writer);
osmium::io::Writer writer{"test.osm", header, osmium::io::overwrite::allow};
osmium::io::OutputIterator<osmium::io::Writer> out{writer};
++out;
}
+157 -161
View File
@@ -12,7 +12,7 @@ struct CountHandler : public osmium::handler::Handler {
int count = 0;
void node(osmium::Node&) {
void node(const osmium::Node&) {
++count;
}
@@ -24,13 +24,13 @@ struct ZeroPositionNodeCountHandler : public osmium::handler::Handler {
// location.
int count = 0;
int total_count = 0; // total number of nodes seen
const osmium::Location zero = osmium::Location(int32_t(0), int32_t(0));
const osmium::Location zero = osmium::Location{int32_t(0), int32_t(0)};
void node(osmium::Node &n) {
void node(const osmium::Node& node) {
// no nodes in the history file have a zero location, and
// no visible nodes should have an undefined location.
if ((n.location() == zero) ||
(n.visible() && !n.location())) {
if ((node.location() == zero) ||
(node.visible() && !node.location())) {
++count;
}
++total_count;
@@ -39,174 +39,170 @@ struct ZeroPositionNodeCountHandler : public osmium::handler::Handler {
}; // class ZeroPositionNodeCountHandler
TEST_CASE("Reader") {
TEST_CASE("Reader can be initialized with file") {
osmium::io::File file{with_data_dir("t/io/data.osm")};
osmium::io::Reader reader{file};
osmium::handler::Handler handler;
SECTION("reader can be initialized with file") {
osmium::io::File file(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader(file);
osmium::handler::Handler handler;
osmium::apply(reader, handler);
}
osmium::apply(reader, handler);
TEST_CASE("Reader can be initialized with string") {
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
osmium::handler::Handler handler;
osmium::apply(reader, handler);
}
TEST_CASE("Reader should throw after eof") {
osmium::io::File file{with_data_dir("t/io/data.osm")};
osmium::io::Reader reader{file};
REQUIRE(!reader.eof());
while (osmium::memory::Buffer buffer = reader.read()) {
}
SECTION("reader can be initialized with string") {
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::handler::Handler handler;
REQUIRE(reader.eof());
REQUIRE_THROWS_AS({
reader.read();
}, osmium::io_error);
}
TEST_CASE("Reader should not hang when apply() is called twice on reader") {
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);
}
}, osmium::io_error);
}
SECTION("should throw after eof") {
osmium::io::File file(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader(file);
TEST_CASE("Reader should work with a buffer with uncompressed data") {
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
const auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file{buffer, static_cast<size_t>(length), "osm"};
osmium::io::Reader reader{file};
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
TEST_CASE("Reader should work with a buffer with gzip-compressed data") {
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.gz"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
const auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file{buffer, static_cast<size_t>(length), "osm.gz"};
osmium::io::Reader reader{file};
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
TEST_CASE("Reader should work with a buffer with bzip2-compressed data") {
const int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.bz2"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
const auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file{buffer, static_cast<size_t>(length), "osm.bz2"};
osmium::io::Reader reader{file};
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
TEST_CASE("Reader should decode zero node positions in history (XML)") {
osmium::io::Reader reader{with_data_dir("t/io/deleted_nodes.osh"),
osmium::osm_entity_bits::node};
ZeroPositionNodeCountHandler handler;
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 2);
}
TEST_CASE("Reader should decode zero node positions in history (PBF)") {
osmium::io::Reader reader{with_data_dir("t/io/deleted_nodes.osh.pbf"),
osmium::osm_entity_bits::node};
ZeroPositionNodeCountHandler handler;
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 2);
}
TEST_CASE("Reader should fail with nonexistent file") {
REQUIRE_THROWS({
osmium::io::Reader reader{with_data_dir("t/io/nonexistent-file.osm")};
});
}
TEST_CASE("Reader should fail with nonexistent file (gz)") {
REQUIRE_THROWS({
osmium::io::Reader reader{with_data_dir("t/io/nonexistent-file.osm.gz")};
});
}
TEST_CASE("Reader should fail with nonexistent file (pbf)") {
REQUIRE_THROWS({
osmium::io::Reader reader{with_data_dir("t/io/nonexistent-file.osm.pbf")};
});
}
TEST_CASE("Reader should work when there is an exception in main thread before getting header") {
try {
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
REQUIRE(!reader.eof());
while (osmium::memory::Buffer buffer = reader.read()) {
}
REQUIRE(reader.eof());
REQUIRE_THROWS_AS({
reader.read();
}, osmium::io_error);
throw std::runtime_error{"foo"};
} catch (...) {
}
SECTION("should not hang when apply() is called twice on reader") {
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);
}, osmium::io_error);
}
SECTION("should work with a buffer with uncompressed data") {
int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
SECTION("should work with a buffer with gzip-compressed data") {
int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.gz"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.gz");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
SECTION("should work with a buffer with bzip2-compressed data") {
int fd = osmium::io::detail::open_for_reading(with_data_dir("t/io/data.osm.bz2"));
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
auto length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.bz2");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
SECTION("should decode zero node positions in history (XML)") {
osmium::io::Reader reader(with_data_dir("t/io/deleted_nodes.osh"),
osmium::osm_entity_bits::node);
ZeroPositionNodeCountHandler handler;
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 2);
}
SECTION("should decode zero node positions in history (PBF)") {
osmium::io::Reader reader(with_data_dir("t/io/deleted_nodes.osh.pbf"),
osmium::osm_entity_bits::node);
ZeroPositionNodeCountHandler handler;
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 0);
REQUIRE(handler.total_count == 2);
}
}
TEST_CASE("Reader failure modes") {
SECTION("should fail with nonexistent file") {
REQUIRE_THROWS({
osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm"));
});
TEST_CASE("Reader should work when there is an exception in main thread while reading") {
try {
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
REQUIRE(!reader.eof());
auto header = reader.header();
throw std::runtime_error{"foo"};
} catch (...) {
}
SECTION("should fail with nonexistent file (gz)") {
REQUIRE_THROWS({
osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm.gz"));
});
}
SECTION("should fail with nonexistent file (pbf)") {
REQUIRE_THROWS({
osmium::io::Reader reader(with_data_dir("t/io/nonexistent-file.osm.pbf"));
});
}
SECTION("should work when there is an exception in main thread before getting header") {
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
REQUIRE(!reader.eof());
throw std::runtime_error("foo");
} catch (...) {
}
}
SECTION("should work when there is an exception in main thread while reading") {
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
REQUIRE(!reader.eof());
auto header = reader.header();
throw std::runtime_error("foo");
} catch (...) {
}
}
}
TEST_CASE("Applying rvalue handler on reader") {
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
struct NullHandler : public osmium::handler::Handler { };
osmium::apply(reader, NullHandler{});
}
@@ -23,7 +23,7 @@ public:
Decompressor(),
m_fail_in(fail_in) {
if (m_fail_in == "constructor") {
throw std::runtime_error("error constructor");
throw std::runtime_error{"error constructor"};
}
}
@@ -41,7 +41,7 @@ public:
if (m_read_count == 1) {
if (m_fail_in == "first read") {
throw std::runtime_error("error first read");
throw std::runtime_error{"error first read"};
} else {
buffer += "<?xml version='1.0' encoding='UTF-8'?>\n<osm version='0.6' generator='testdata'>\n";
for (int i = 0; i < 1000; ++i) {
@@ -50,7 +50,7 @@ public:
}
} else if (m_read_count == 2) {
if (m_fail_in == "second read") {
throw std::runtime_error("error second read");
throw std::runtime_error{"error second read"};
} else {
for (int i = 1000; i < 2000; ++i) {
add_node(buffer, i);
@@ -65,7 +65,7 @@ public:
void close() final {
if (m_fail_in == "close") {
throw std::runtime_error("error close");
throw std::runtime_error{"error close"};
}
}
@@ -85,7 +85,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
fail_in = "constructor";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm.gz")};
REQUIRE(false);
} catch (const std::runtime_error& e) {
REQUIRE(std::string{e.what()} == "error constructor");
@@ -96,7 +96,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
fail_in = "first read";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm.gz")};
reader.read();
REQUIRE(false);
} catch (const std::runtime_error& e) {
@@ -108,7 +108,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
fail_in = "second read";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm.gz")};
reader.read();
reader.read();
REQUIRE(false);
@@ -121,7 +121,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
fail_in = "close";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm.gz")};
reader.read();
reader.read();
reader.read();
@@ -135,7 +135,7 @@ TEST_CASE("Test Reader using MockDecompressor") {
SECTION("not failing") {
fail_in = "not";
osmium::io::Reader reader(with_data_dir("t/io/data.osm.gz"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm.gz")};
reader.read();
reader.close();
REQUIRE(true);
@@ -34,7 +34,7 @@ public:
osmium::thread::set_thread_name("_osmium_mock_in");
if (m_fail_in == "header") {
throw std::runtime_error("error in header");
throw std::runtime_error{"error in header"};
}
set_header_value(osmium::io::Header{});
@@ -44,7 +44,7 @@ public:
send_to_output_queue(std::move(buffer));
if (m_fail_in == "read") {
throw std::runtime_error("error in read");
throw std::runtime_error{"error in read"};
}
}
@@ -65,7 +65,7 @@ TEST_CASE("Test Reader using MockParser") {
SECTION("no failure") {
fail_in = "";
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
auto header = reader.header();
REQUIRE(reader.read());
REQUIRE(!reader.read());
@@ -76,7 +76,7 @@ TEST_CASE("Test Reader using MockParser") {
SECTION("throw in header") {
fail_in = "header";
try {
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
reader.header();
} catch (const std::runtime_error& e) {
REQUIRE(std::string{e.what()} == "error in header");
@@ -85,7 +85,7 @@ TEST_CASE("Test Reader using MockParser") {
SECTION("throw in read") {
fail_in = "read";
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
reader.header();
try {
reader.read();
@@ -97,10 +97,10 @@ TEST_CASE("Test Reader using MockParser") {
SECTION("throw in user code") {
fail_in = "";
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
reader.header();
try {
throw std::runtime_error("error in user code");
throw std::runtime_error{"error in user code"};
} catch (const std::runtime_error& e) {
REQUIRE(std::string{e.what()} == "error in user code");
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include <osmium/io/detail/string_table.hpp>
TEST_CASE("String store") {
osmium::io::detail::StringStore ss(100);
osmium::io::detail::StringStore ss{100};
SECTION("empty") {
REQUIRE(ss.begin() == ss.end());
+11 -13
View File
@@ -10,15 +10,14 @@
#include <osmium/memory/buffer.hpp>
TEST_CASE("Writer") {
osmium::io::Header header;
header.set("generator", "test_writer.cpp");
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer);
REQUIRE(buffer.committed() > 0);
auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
const auto num = std::distance(buffer.select<osmium::OSMObject>().cbegin(), buffer.select<osmium::OSMObject>().cend());
REQUIRE(num > 0);
REQUIRE(buffer.select<osmium::OSMObject>().cbegin()->id() == 1);
@@ -28,7 +27,7 @@ TEST_CASE("Writer") {
SECTION("Empty buffer") {
filename = "test-writer-out-empty-buffer.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
osmium::memory::Buffer empty_buffer(1024);
writer(std::move(empty_buffer));
writer.close();
@@ -36,13 +35,13 @@ TEST_CASE("Writer") {
SECTION("Invalid buffer") {
filename = "test-writer-out-invalid-buffer.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
osmium::memory::Buffer invalid_buffer;
writer(std::move(invalid_buffer));
writer.close();
}
osmium::io::Reader reader_check(filename);
osmium::io::Reader reader_check{filename};
osmium::memory::Buffer buffer_check = reader_check.read();
REQUIRE(!buffer_check);
}
@@ -51,7 +50,7 @@ TEST_CASE("Writer") {
SECTION("Writer buffer") {
filename = "test-writer-out-buffer.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
writer(std::move(buffer));
writer.close();
@@ -62,7 +61,7 @@ TEST_CASE("Writer") {
SECTION("Writer item") {
filename = "test-writer-out-item.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
for (const auto& item : buffer) {
writer(item);
}
@@ -71,13 +70,13 @@ TEST_CASE("Writer") {
SECTION("Writer output iterator") {
filename = "test-writer-out-iterator.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
auto it = osmium::io::make_output_iterator(writer);
std::copy(buffer.cbegin(), buffer.cend(), it);
writer.close();
}
osmium::io::Reader reader_check(filename);
osmium::io::Reader reader_check{filename};
osmium::memory::Buffer buffer_check = reader_check.read();
REQUIRE(buffer_check);
REQUIRE(buffer_check.committed() > 0);
@@ -89,7 +88,7 @@ TEST_CASE("Writer") {
int error = 0;
try {
filename = "test-writer-out-fail1.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
throw 1;
} catch (int e) {
error = e;
@@ -102,7 +101,7 @@ TEST_CASE("Writer") {
int error = 0;
try {
filename = "test-writer-out-fail2.osm";
osmium::io::Writer writer(filename, header, osmium::io::overwrite::allow);
osmium::io::Writer writer{filename, header, osmium::io::overwrite::allow};
writer(std::move(buffer));
throw 2;
} catch (int e) {
@@ -114,4 +113,3 @@ TEST_CASE("Writer") {
}
@@ -19,7 +19,7 @@ public:
Compressor(osmium::io::fsync::no),
m_fail_in(fail_in) {
if (m_fail_in == "constructor") {
throw std::logic_error("constructor");
throw std::logic_error{"constructor"};
}
}
@@ -27,13 +27,13 @@ public:
void write(const std::string&) final {
if (m_fail_in == "write") {
throw std::logic_error("write");
throw std::logic_error{"write"};
}
}
void close() final {
if (m_fail_in == "close") {
throw std::logic_error("close");
throw std::logic_error{"close"};
}
}
@@ -52,7 +52,7 @@ TEST_CASE("Write with mock compressor") {
osmium::io::Header header;
header.set("generator", "test_writer_with_mock_compression.cpp");
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer);
REQUIRE(buffer.committed() > 0);
@@ -24,21 +24,21 @@ public:
void write_header(const osmium::io::Header&) final {
if (m_fail_in == "header") {
throw std::logic_error("header");
throw std::logic_error{"header"};
}
send_to_output_queue(std::string{"header"});
}
void write_buffer(osmium::memory::Buffer&&) final {
if (m_fail_in == "write") {
throw std::logic_error("write");
throw std::logic_error{"write"};
}
send_to_output_queue(std::string{"write"});
}
void write_end() final {
if (m_fail_in == "write_end") {
throw std::logic_error("write_end");
throw std::logic_error{"write_end"};
}
send_to_output_queue(std::string{"end"});
}
@@ -58,7 +58,7 @@ TEST_CASE("Test Writer with MockOutputFormat") {
osmium::io::Header header;
header.set("generator", "test_writer_with_mock_encoder.cpp");
osmium::io::Reader reader(with_data_dir("t/io/data.osm"));
osmium::io::Reader reader{with_data_dir("t/io/data.osm")};
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer);
REQUIRE(buffer.committed() > 0);
@@ -0,0 +1,72 @@
#include "catch.hpp"
#include <osmium/memory/item_iterator.hpp>
#include <osmium/osm.hpp>
static_assert(osmium::memory::detail::type_is_compatible<osmium::Node>(osmium::item_type::node), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Way>(osmium::item_type::node), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Relation>(osmium::item_type::node), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Area>(osmium::item_type::node), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMObject>(osmium::item_type::node), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Changeset>(osmium::item_type::node), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMEntity>(osmium::item_type::node), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::memory::Item>(osmium::item_type::node), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Node>(osmium::item_type::way), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::Way>(osmium::item_type::way), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Relation>(osmium::item_type::way), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Area>(osmium::item_type::way), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMObject>(osmium::item_type::way), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Changeset>(osmium::item_type::way), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMEntity>(osmium::item_type::way), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::memory::Item>(osmium::item_type::way), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Node>(osmium::item_type::relation), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Way>(osmium::item_type::relation), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::Relation>(osmium::item_type::relation), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Area>(osmium::item_type::relation), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMObject>(osmium::item_type::relation), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Changeset>(osmium::item_type::relation), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMEntity>(osmium::item_type::relation), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::memory::Item>(osmium::item_type::relation), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Node>(osmium::item_type::area), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Way>(osmium::item_type::area), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Relation>(osmium::item_type::area), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::Area>(osmium::item_type::area), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMObject>(osmium::item_type::area), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Changeset>(osmium::item_type::area), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMEntity>(osmium::item_type::area), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::memory::Item>(osmium::item_type::area), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Node>(osmium::item_type::changeset), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Way>(osmium::item_type::changeset), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Relation>(osmium::item_type::changeset), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::Area>(osmium::item_type::changeset), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::OSMObject>(osmium::item_type::changeset), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::Changeset>(osmium::item_type::changeset), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OSMEntity>(osmium::item_type::changeset), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::memory::Item>(osmium::item_type::changeset), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::OuterRing>(osmium::item_type::outer_ring), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::InnerRing>(osmium::item_type::inner_ring), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::WayNodeList>(osmium::item_type::way_node_list), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::OuterRing>(osmium::item_type::inner_ring), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::InnerRing>(osmium::item_type::outer_ring), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::WayNodeList>(osmium::item_type::outer_ring), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::TagList>(osmium::item_type::tag_list), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::InnerRing>(osmium::item_type::inner_ring), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::TagList>(osmium::item_type::inner_ring), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::InnerRing>(osmium::item_type::tag_list), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::RelationMemberList>(osmium::item_type::relation_member_list), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::RelationMemberList>(osmium::item_type::relation_member_list_with_full_members), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::RelationMemberList>(osmium::item_type::tag_list), "");
static_assert(osmium::memory::detail::type_is_compatible<osmium::ChangesetDiscussion>(osmium::item_type::changeset_discussion), "");
static_assert(!osmium::memory::detail::type_is_compatible<osmium::ChangesetDiscussion>(osmium::item_type::relation_member_list), "");
+6
View File
@@ -74,5 +74,11 @@ TEST_CASE("Build area") {
osmium::CRC<boost::crc_32_type> crc32;
crc32.update(area);
REQUIRE(crc32().checksum() == 0x2b2b7fa0);
osmium::Box envelope = area.envelope();
REQUIRE(envelope.bottom_left().lon() == Approx(3.2));
REQUIRE(envelope.bottom_left().lat() == Approx(4.2));
REQUIRE(envelope.top_right().lon() == Approx(3.6));
REQUIRE(envelope.top_right().lat() == Approx(4.9));
}
+73 -56
View File
@@ -5,81 +5,92 @@
#include <osmium/osm/node_ref.hpp>
#include <osmium/osm/node_ref_list.hpp>
TEST_CASE("NodeRef") {
TEST_CASE("Default construct a NodeRef") {
osmium::NodeRef node_ref;
REQUIRE(node_ref.ref() == 0);
REQUIRE(node_ref.location() == osmium::Location{});
}
SECTION("instantiation_with_default_parameters") {
osmium::NodeRef node_ref;
REQUIRE(node_ref.ref() == 0);
// REQUIRE(!node_ref.has_location());
}
TEST_CASE("Construct a NodeRef with an id") {
osmium::NodeRef node_ref{7};
REQUIRE(node_ref.ref() == 7);
}
SECTION("instantiation_with_id") {
osmium::NodeRef node_ref(7);
REQUIRE(node_ref.ref() == 7);
}
TEST_CASE("Equality comparison fo NodeRefs") {
osmium::NodeRef node_ref1{7, {1.2, 3.4}};
osmium::NodeRef node_ref2{7, {1.4, 3.1}};
osmium::NodeRef node_ref3{9, {1.2, 3.4}};
REQUIRE(node_ref1 == node_ref2);
REQUIRE(node_ref1 != node_ref3);
REQUIRE(!osmium::location_equal()(node_ref1, node_ref2));
REQUIRE(!osmium::location_equal()(node_ref2, node_ref3));
REQUIRE(osmium::location_equal()(node_ref1, node_ref3));
}
SECTION("equality") {
osmium::NodeRef node_ref1(7, { 1.2, 3.4 });
osmium::NodeRef node_ref2(7, { 1.4, 3.1 });
osmium::NodeRef node_ref3(9, { 1.2, 3.4 });
REQUIRE(node_ref1 == node_ref2);
REQUIRE(node_ref1 != node_ref3);
REQUIRE(!osmium::location_equal()(node_ref1, node_ref2));
REQUIRE(!osmium::location_equal()(node_ref2, node_ref3));
REQUIRE(osmium::location_equal()(node_ref1, node_ref3));
}
TEST_CASE("Set location on a NodeRef") {
osmium::NodeRef node_ref{7};
REQUIRE(!node_ref.location().valid());
REQUIRE(node_ref.location() == osmium::Location());
node_ref.set_location(osmium::Location(13.5, -7.2));
REQUIRE(node_ref.location().lon() == 13.5);
REQUIRE(node_ref.location().valid());
}
SECTION("set_location") {
osmium::NodeRef node_ref(7);
REQUIRE(!node_ref.location().valid());
REQUIRE(node_ref.location() == osmium::Location());
node_ref.set_location(osmium::Location(13.5, -7.2));
REQUIRE(node_ref.location().lon() == 13.5);
REQUIRE(node_ref.location().valid());
}
TEST_CASE("Ordering of NodeRefs") {
osmium::NodeRef node_ref1{1, {1.0, 3.0}};
osmium::NodeRef node_ref2{2, {1.4, 2.9}};
osmium::NodeRef node_ref3{3, {1.2, 3.0}};
osmium::NodeRef node_ref4{4, {1.2, 3.3}};
SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE(osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE(osmium::location_less()(node_ref1, node_ref3));
REQUIRE(osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE(osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE(osmium::location_less()(node_ref1, node_ref3));
REQUIRE(osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
TEST_CASE("WayNodeList") {
osmium::memory::Buffer buffer(1024);
osmium::memory::Buffer buffer{1024};
SECTION("Empty list") {
{
osmium::builder::WayNodeListBuilder builder(buffer);
osmium::builder::WayNodeListBuilder builder{buffer};
}
REQUIRE(buffer.commit() == 0);
REQUIRE(buffer.committed( )> 0);
REQUIRE(buffer.committed() > 0);
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
REQUIRE(nrl.empty());
REQUIRE(nrl.size() == 0);
}
SECTION("Change a WayNodeList") {
osmium::builder::add_way_node_list(buffer, osmium::builder::attr::_nodes({
{1, {0.0, 0.0}},
{2, {0.0, 1.0}},
{3, {1.0, 1.0}}
}));
osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
REQUIRE(nrl.size() == 3);
REQUIRE(nrl[1].location() == osmium::Location(0.0, 1.0));
nrl[1].set_location(osmium::Location(13.5, -7.2));
REQUIRE(nrl[1].location() == osmium::Location(13.5, -7.2));
}
SECTION("Small area") {
osmium::builder::add_way_node_list(buffer, osmium::builder::attr::_nodes({
{ 1, {0, 0}},
{ 2, {0, 1}},
{ 3, {1, 1}},
{ 4, {1, 0}},
{ 1, {0, 0}},
{1, {0.0, 0.0}},
{2, {0.0, 1.0}},
{3, {1.0, 1.0}},
{4, {1.0, 0.0}},
{1, {0.0, 0.0}},
}));
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
@@ -88,13 +99,19 @@ TEST_CASE("WayNodeList") {
REQUIRE(nrl.is_closed());
REQUIRE(nrl.ends_have_same_id());
REQUIRE(nrl.ends_have_same_location());
osmium::Box envelope = nrl.envelope();
REQUIRE(envelope.bottom_left().lon() == Approx(0));
REQUIRE(envelope.bottom_left().lat() == Approx(0));
REQUIRE(envelope.top_right().lon() == Approx(1));
REQUIRE(envelope.top_right().lat() == Approx(1));
}
SECTION("Not an area") {
osmium::builder::add_way_node_list(buffer, osmium::builder::attr::_nodes({
{ 1, {0, 0}},
{ 2, {1, 0}},
{ 1, {0, 0}},
{1, {0.0, 0.0}},
{2, {1.0, 0.0}},
{1, {0.0, 0.0}},
}));
const osmium::WayNodeList& nrl = buffer.get<osmium::WayNodeList>(0);
+10 -4
View File
@@ -10,7 +10,7 @@
using namespace osmium::builder::attr;
TEST_CASE("Build way") {
osmium::memory::Buffer buffer(10000);
osmium::memory::Buffer buffer{10000};
osmium::builder::add_way(buffer,
_id(17),
@@ -50,7 +50,7 @@ TEST_CASE("Build way") {
}
TEST_CASE("build closed way") {
osmium::memory::Buffer buffer(10000);
osmium::memory::Buffer buffer{10000};
osmium::builder::add_way(buffer,
_tag("highway", "residential"),
@@ -64,7 +64,7 @@ TEST_CASE("build closed way") {
}
TEST_CASE("build way with helpers") {
osmium::memory::Buffer buffer(10000);
osmium::memory::Buffer buffer{10000};
{
osmium::builder::WayBuilder builder(buffer);
@@ -90,6 +90,12 @@ TEST_CASE("build way with helpers") {
REQUIRE(2 == way.nodes().size());
REQUIRE(22 == way.nodes()[0].ref());
REQUIRE(4.1 == way.nodes()[1].location().lon());
REQUIRE(4.1 == Approx(way.nodes()[1].location().lon()));
osmium::Box envelope = way.envelope();
REQUIRE(envelope.bottom_left().lon() == Approx(3.5));
REQUIRE(envelope.bottom_left().lat() == Approx(2.2));
REQUIRE(envelope.top_right().lon() == Approx(4.1));
REQUIRE(envelope.top_right().lat() == Approx(4.7));
}
+96 -67
View File
@@ -10,56 +10,56 @@
#include <osmium/tags/regex_filter.hpp>
template <class TFilter>
void check_filter(const osmium::TagList& tag_list, const TFilter filter, const std::vector<bool>& reference) {
void check_filter(const osmium::TagList& tag_list,
const TFilter filter,
const std::vector<bool>& reference) {
REQUIRE(tag_list.size() == reference.size());
auto t_it = tag_list.begin();
for (auto it = reference.begin(); it != reference.end(); ++t_it, ++it) {
REQUIRE(filter(*t_it) == *it);
}
typename TFilter::iterator fi_begin(filter, tag_list.begin(), tag_list.end());
typename TFilter::iterator fi_end(filter, tag_list.end(), tag_list.end());
typename TFilter::iterator fi_begin{filter, tag_list.begin(), tag_list.end()};
typename TFilter::iterator fi_end{filter, tag_list.end(), tag_list.end()};
REQUIRE(std::distance(fi_begin, fi_end) == std::count(reference.begin(), reference.end(), true));
}
const osmium::TagList& make_tag_list(osmium::memory::Buffer& buffer, std::initializer_list<std::pair<const char*, const char*>> tags) {
const osmium::TagList& make_tag_list(osmium::memory::Buffer& buffer,
std::initializer_list<std::pair<const char*, const char*>> tags) {
const auto pos = osmium::builder::add_tag_list(buffer, osmium::builder::attr::_tags(tags));
return buffer.get<osmium::TagList>(pos);
}
TEST_CASE("Filter") {
TEST_CASE("KeyFilter") {
osmium::memory::Buffer buffer{10240};
osmium::tags::KeyFilter filter{false};
SECTION("KeyFilter_matches_some_tags") {
osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "railway");
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" },
{ "source", "GPS" }
});
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" }, // match
{ "name", "Main Street" }, // no match
{ "source", "GPS" } // no match
});
SECTION("KeyFilter matches some tags") {
filter.add(true, "highway")
.add(true, "railway");
const std::vector<bool> results = { true, false, false };
check_filter(tag_list, filter, results);
}
SECTION("KeyFilter_iterator_filters_tags") {
osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "source");
SECTION("KeyFilter iterator filters tags") {
filter.add(true, "highway")
.add(true, "source");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = make_tag_list(buffer, {
{ "highway", "primary" }, // match
{ "name", "Main Street" }, // no match
{ "source", "GPS" } // no match
});
osmium::tags::KeyFilter::iterator it{filter, tag_list.begin(),
tag_list.end()};
osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end());
const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end());
const osmium::tags::KeyFilter::iterator end{filter, tag_list.end(),
tag_list.end()};
REQUIRE(2 == std::distance(it, end));
@@ -72,12 +72,18 @@ TEST_CASE("Filter") {
REQUIRE(++it == end);
}
SECTION("KeyValueFilter_matches_some_tags") {
osmium::tags::KeyValueFilter filter(false);
}
filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway");
TEST_CASE("KeyValueFilter") {
osmium::memory::Buffer buffer{10240};
SECTION("KeyValueFilter matches some tags") {
osmium::tags::KeyValueFilter filter{false};
filter.add(true, "highway", "residential")
.add(true, "highway", "primary")
.add(true, "railway");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
@@ -89,14 +95,14 @@ TEST_CASE("Filter") {
check_filter(tag_list, filter, results);
}
SECTION("KeyValueFilter_ordering_matters") {
SECTION("KeyValueFilter ordering matters") {
osmium::tags::KeyValueFilter filter1(false);
filter1.add(true, "highway").add(false, "highway", "road");
filter1.add(true, "highway")
.add(false, "highway", "road");
osmium::tags::KeyValueFilter filter2(false);
filter2.add(false, "highway", "road").add(true, "highway");
osmium::memory::Buffer buffer(10240);
filter2.add(false, "highway", "road")
.add(true, "highway");
const osmium::TagList& tag_list1 = make_tag_list(buffer, {
{ "highway", "road" },
@@ -113,12 +119,12 @@ TEST_CASE("Filter") {
check_filter(tag_list2, filter2, {true, false});
}
SECTION("KeyValueFilter_matches_against_taglist_with_any") {
osmium::tags::KeyValueFilter filter(false);
SECTION("KeyValueFilter matches against taglist with any") {
osmium::tags::KeyValueFilter filter{false};
filter.add(true, "highway", "primary").add(true, "name");
filter.add(true, "highway", "primary")
.add(true, "name");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
@@ -130,12 +136,12 @@ TEST_CASE("Filter") {
REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_all") {
osmium::tags::KeyValueFilter filter(false);
SECTION("KeyValueFilter matches against taglist with_all") {
osmium::tags::KeyValueFilter filter{false};
filter.add(true, "highway", "primary").add(true, "name");
filter.add(true, "highway", "primary")
.add(true, "name");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
@@ -146,12 +152,12 @@ TEST_CASE("Filter") {
REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_none") {
osmium::tags::KeyValueFilter filter(false);
SECTION("KeyValueFilter matches against taglist with none") {
osmium::tags::KeyValueFilter filter{false};
filter.add(true, "highway", "road").add(true, "source");
filter.add(true, "highway", "road")
.add(true, "source");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
@@ -162,8 +168,7 @@ TEST_CASE("Filter") {
REQUIRE( osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") {
osmium::memory::Buffer buffer(10240);
SECTION("KeyValueFilter matches against taglist with any called with rvalue") {
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
@@ -171,14 +176,20 @@ TEST_CASE("Filter") {
});
REQUIRE(osmium::tags::match_any_of(tag_list,
osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name")));
osmium::tags::KeyValueFilter()
.add(true, "highway", "primary")
.add(true, "name")));
}
SECTION("RegexFilter_matches_some_tags") {
osmium::tags::RegexFilter filter(false);
filter.add(true, "highway", std::regex(".*_link"));
}
TEST_CASE("RegexFilter") {
osmium::memory::Buffer buffer{10240};
SECTION("RegexFilter matches some tags") {
osmium::tags::RegexFilter filter{false};
filter.add(true, "highway", std::regex{".*_link"});
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list1 = make_tag_list(buffer, {
{ "highway", "primary_link" },
{ "source", "GPS" }
@@ -192,12 +203,11 @@ TEST_CASE("Filter") {
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");
SECTION("RegexFilter matches some tags with lvalue regex") {
osmium::tags::RegexFilter filter{false};
std::regex r{".*straße"};
filter.add(true, "name", r);
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Hauptstraße" }
@@ -206,17 +216,36 @@ TEST_CASE("Filter") {
check_filter(tag_list, filter, {false, true});
}
SECTION("KeyPrefixFilter_matches_some_tags") {
osmium::tags::KeyPrefixFilter filter(false);
filter.add(true, "name:");
}
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name:de", "Hauptstraße" }
});
TEST_CASE("KeyPrefixFilter matches some keys") {
osmium::memory::Buffer buffer{10240};
check_filter(tag_list, filter, {false, true});
}
osmium::tags::KeyPrefixFilter filter{false};
filter.add(true, "name:");
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "name:de", "Hauptstraße" }
});
check_filter(tag_list, filter, {false, true});
}
TEST_CASE("Generic Filterw with regex matches some keys") {
osmium::memory::Buffer buffer{10240};
osmium::tags::Filter<std::regex> filter{false};
filter.add(true, std::regex{"restriction.+conditional"});
const osmium::TagList& tag_list = make_tag_list(buffer, {
{ "highway", "primary" },
{ "restrictionconditional", "only_right_turn @ (Mo-Fr 07:00-14:00)" },
{ "restriction:conditional", "only_right_turn @ (Mo-Fr 07:00-14:00)" },
{ "restriction:psv:conditional", "only_right_turn @ (Mo-Fr 07:00-14:00)" }
});
check_filter(tag_list, filter, {false, false, true, true});
}
+3
View File
@@ -11,6 +11,8 @@ TEST_CASE("Check memory usage") {
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);
@@ -25,6 +27,7 @@ TEST_CASE("Check memory usage") {
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);