Merge commit 'babbda98a6ea1d53a8bc5015ef5dfb313c47186a' into libosmium-2.10.0
This commit is contained in:
+22
-28
@@ -112,12 +112,6 @@ if(NOT Threads_FOUND)
|
||||
set(Threads_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
if(GEOS_FOUND AND PROJ_FOUND)
|
||||
set(GEOS_AND_PROJ_FOUND TRUE)
|
||||
else()
|
||||
set(GEOS_AND_PROJ_FOUND FALSE)
|
||||
endif()
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
@@ -127,45 +121,45 @@ endif()
|
||||
add_unit_test(area test_area_id)
|
||||
add_unit_test(area test_node_ref_segment)
|
||||
|
||||
add_unit_test(basic test_area)
|
||||
add_unit_test(basic test_box)
|
||||
add_unit_test(basic test_changeset)
|
||||
add_unit_test(basic test_crc)
|
||||
add_unit_test(basic test_entity_bits)
|
||||
add_unit_test(basic test_location)
|
||||
add_unit_test(basic test_node)
|
||||
add_unit_test(basic test_node_ref)
|
||||
add_unit_test(basic test_object_comparisons)
|
||||
add_unit_test(basic test_relation)
|
||||
add_unit_test(basic test_timestamp)
|
||||
add_unit_test(basic test_types_from_string)
|
||||
add_unit_test(basic test_way)
|
||||
add_unit_test(osm test_area)
|
||||
add_unit_test(osm test_box)
|
||||
add_unit_test(osm test_changeset)
|
||||
add_unit_test(osm test_crc)
|
||||
add_unit_test(osm test_entity_bits)
|
||||
add_unit_test(osm test_location)
|
||||
add_unit_test(osm test_node)
|
||||
add_unit_test(osm test_node_ref)
|
||||
add_unit_test(osm test_object_comparisons)
|
||||
add_unit_test(osm test_relation)
|
||||
add_unit_test(osm test_timestamp)
|
||||
add_unit_test(osm test_types_from_string)
|
||||
add_unit_test(osm test_way)
|
||||
|
||||
add_unit_test(buffer test_buffer_basics)
|
||||
add_unit_test(buffer test_buffer_node)
|
||||
add_unit_test(buffer test_buffer_purge)
|
||||
add_unit_test(memory test_buffer_basics)
|
||||
add_unit_test(memory test_buffer_node)
|
||||
add_unit_test(memory test_buffer_purge)
|
||||
|
||||
add_unit_test(builder test_attr)
|
||||
|
||||
add_unit_test(geom test_factory_with_projection
|
||||
ENABLE_IF ${GEOS_AND_PROJ_FOUND}
|
||||
LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY})
|
||||
add_unit_test(builder test_object_builder)
|
||||
|
||||
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})
|
||||
add_unit_test(geom test_geojson)
|
||||
add_unit_test(geom test_geos ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
|
||||
add_unit_test(geom test_geos_wkb ENABLE_IF ${GEOS_FOUND} LIBS ${GEOS_LIBRARY})
|
||||
add_unit_test(geom test_mercator)
|
||||
add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY})
|
||||
add_unit_test(geom test_ogr_wkb ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY})
|
||||
add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY})
|
||||
add_unit_test(geom test_tile ENABLE_IF ${GEOS_FOUND})
|
||||
add_unit_test(geom test_tile)
|
||||
add_unit_test(geom test_wkb)
|
||||
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(io test_compression_factory)
|
||||
add_unit_test(io test_bzip2 ENABLE_IF ${BZIP2_FOUND} LIBS ${BZIP2_LIBRARIES})
|
||||
add_unit_test(io test_file_formats)
|
||||
add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES};${OSMIUM_PBF_LIBRARIES}")
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ header_buffer_type parse_xml(std::string input) {
|
||||
osmium::io::detail::add_to_queue(input_queue, std::move(input));
|
||||
osmium::io::detail::add_to_queue(input_queue, std::string{});
|
||||
|
||||
osmium::io::detail::XMLParser parser{input_queue, output_queue, header_promise, osmium::osm_entity_bits::all};
|
||||
osmium::io::detail::XMLParser parser{input_queue, output_queue, header_promise, osmium::io::detail::reader_options{}};
|
||||
parser.parse();
|
||||
|
||||
header_buffer_type result;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
# CMake Config
|
||||
#
|
||||
# Libosmium example tests
|
||||
#
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
message(STATUS "Configuring example tests")
|
||||
|
||||
file(GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/t/*)
|
||||
|
||||
foreach(_dir ${_dirs})
|
||||
message(STATUS " adding test: ${_dir}")
|
||||
add_subdirectory("${_dir}")
|
||||
endforeach()
|
||||
|
||||
message(STATUS "Configuring example tests - done")
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
add_test(NAME examples_pub_names
|
||||
COMMAND osmium_pub_names ${CMAKE_CURRENT_SOURCE_DIR}/pubs.osm)
|
||||
|
||||
set_tests_properties(examples_pub_names PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "^Im Holze\n$")
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<osm version="0.6">
|
||||
<node id="167199652" version="3" timestamp="2010-12-27T13:15:02Z" uid="57645" user="KartoGrapHiti" changeset="6777507" lat="53.0526516" lon="8.8919477">
|
||||
<tag k="amenity" v="pub"/>
|
||||
<tag k="name" v="Im Holze"/>
|
||||
</node>
|
||||
</osm>
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
add_test(NAME examples_road_length
|
||||
COMMAND osmium_road_length ${CMAKE_CURRENT_SOURCE_DIR}/road.osm)
|
||||
|
||||
set_tests_properties(examples_road_length PROPERTIES
|
||||
PASS_REGULAR_EXPRESSION "^Length: 0\\.405.*km\n$"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<osm version="0.6" generator="CGImap 0.3.3 (31041 thorn-01.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
|
||||
<node id="5599384" visible="true" version="5" changeset="829716" timestamp="2009-03-18T17:16:26Z" user="burts" uid="97529" lat="51.0271601" lon="13.7252197"/>
|
||||
<node id="250384970" visible="true" version="3" changeset="855544" timestamp="2009-01-30T21:58:37Z" user="saftl" uid="7989" lat="51.0288568" lon="13.7248159">
|
||||
<tag k="created_by" v="JOSM"/>
|
||||
</node>
|
||||
<node id="250996316" visible="true" version="5" changeset="838711" timestamp="2009-03-21T13:10:39Z" user="burts" uid="97529" lat="51.0274683" lon="13.7251464"/>
|
||||
<node id="250996321" visible="true" version="3" changeset="855544" timestamp="2009-01-30T21:59:14Z" user="saftl" uid="7989" lat="51.0284283" lon="13.7249179">
|
||||
<tag k="created_by" v="JOSM"/>
|
||||
</node>
|
||||
<node id="252587568" visible="true" version="3" changeset="855544" timestamp="2009-01-30T21:58:45Z" user="saftl" uid="7989" lat="51.0275477" lon="13.7251275">
|
||||
<tag k="created_by" v="JOSM"/>
|
||||
</node>
|
||||
<node id="5599381" visible="true" version="6" changeset="15768585" timestamp="2013-04-18T01:20:26Z" user="Wolle DD" uid="1161559" lat="51.0307642" lon="13.7243263"/>
|
||||
<node id="1122039499" visible="true" version="2" changeset="26063898" timestamp="2014-10-14T04:09:11Z" user="Seandebasti" uid="550560" lat="51.0285248" lon="13.7248970"/>
|
||||
<node id="1122039521" visible="true" version="2" changeset="12753110" timestamp="2012-08-16T17:03:47Z" user="TEAM_CN_TUD" uid="716608" lat="51.0277456" lon="13.7250806"/>
|
||||
<node id="5599382" visible="true" version="6" changeset="8191054" timestamp="2011-05-19T16:19:51Z" user="stw1701" uid="102899" lat="51.0297991" lon="13.7245892"/>
|
||||
<node id="1299329303" visible="true" version="1" changeset="8242335" timestamp="2011-05-25T07:46:01Z" user="bigbug21" uid="15748" lat="51.0290875" lon="13.7247628"/>
|
||||
<node id="1868844753" visible="true" version="2" changeset="13260925" timestamp="2012-09-26T15:26:31Z" user="TEAM_CN_TUD" uid="716608" lat="51.0289617" lon="13.7247917"/>
|
||||
<node id="1868844765" visible="true" version="2" changeset="13260925" timestamp="2012-09-26T15:26:31Z" user="TEAM_CN_TUD" uid="716608" lat="51.0292872" lon="13.7247140"/>
|
||||
<node id="1868844782" visible="true" version="2" changeset="13260925" timestamp="2012-09-26T15:26:31Z" user="TEAM_CN_TUD" uid="716608" lat="51.0295717" lon="13.7246429"/>
|
||||
<node id="1922091528" visible="true" version="2" changeset="13260925" timestamp="2012-09-26T15:26:31Z" user="TEAM_CN_TUD" uid="716608" lat="51.0281700" lon="13.7249813"/>
|
||||
<node id="1953249124" visible="true" version="1" changeset="13418280" timestamp="2012-10-08T20:18:35Z" user="TEAM_CN_TUD" uid="716608" lat="51.0292437" lon="13.7247246"/>
|
||||
<node id="2015120752" visible="true" version="1" changeset="13883494" timestamp="2012-11-15T14:22:31Z" user="TEAM_CN_TUD" uid="716608" lat="51.0293536" lon="13.7246974"/>
|
||||
<node id="2056871900" visible="true" version="1" changeset="14207491" timestamp="2012-12-09T00:03:11Z" user="bigbug21" uid="15748" lat="51.0305821" lon="13.7243895"/>
|
||||
<node id="2458246647" visible="true" version="1" changeset="17836591" timestamp="2013-09-14T17:05:06Z" user="bigbug21" uid="15748" lat="51.0295979" lon="13.7246367"/>
|
||||
<node id="250384969" visible="true" version="4" changeset="17857555" timestamp="2013-09-15T20:17:55Z" user="4b696d" uid="1420318" lat="51.0282021" lon="13.7249734"/>
|
||||
<node id="3128723784" visible="true" version="1" changeset="26063898" timestamp="2014-10-14T04:09:07Z" user="Seandebasti" uid="550560" lat="51.0281018" lon="13.7249973"/>
|
||||
<way id="4428564" visible="true" version="21" changeset="26063898" timestamp="2014-10-14T04:09:13Z" user="Seandebasti" uid="550560">
|
||||
<nd ref="5599381"/>
|
||||
<nd ref="2056871900"/>
|
||||
<nd ref="5599382"/>
|
||||
<nd ref="2458246647"/>
|
||||
<nd ref="1868844782"/>
|
||||
<nd ref="2015120752"/>
|
||||
<nd ref="1868844765"/>
|
||||
<nd ref="1953249124"/>
|
||||
<nd ref="1299329303"/>
|
||||
<nd ref="1868844753"/>
|
||||
<nd ref="250384970"/>
|
||||
<nd ref="1122039499"/>
|
||||
<nd ref="250996321"/>
|
||||
<nd ref="250384969"/>
|
||||
<nd ref="1922091528"/>
|
||||
<nd ref="3128723784"/>
|
||||
<nd ref="1122039521"/>
|
||||
<nd ref="252587568"/>
|
||||
<nd ref="250996316"/>
|
||||
<nd ref="5599384"/>
|
||||
<tag k="highway" v="residential"/>
|
||||
<tag k="lit" v="yes"/>
|
||||
<tag k="maxspeed" v="30"/>
|
||||
<tag k="name" v="Helmholtzstraße"/>
|
||||
<tag k="postal_code" v="01069"/>
|
||||
<tag k="sidewalk" v="both"/>
|
||||
<tag k="smoothness" v="good"/>
|
||||
<tag k="surface" v="asphalt"/>
|
||||
</way>
|
||||
</osm>
|
||||
+34
-16
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Catch v1.5.6
|
||||
* Generated: 2016-06-09 19:20:41.460328
|
||||
* Catch v1.5.8
|
||||
* Generated: 2016-10-26 12:07:30.938259
|
||||
* ----------------------------------------------------------
|
||||
* This file has been merged from multiple headers. Please don't edit it directly
|
||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
@@ -3223,10 +3223,11 @@ namespace Catch {
|
||||
|
||||
bool matches( TestCaseInfo const& testCase ) const {
|
||||
// All patterns in a filter must match for the filter to be a match
|
||||
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it )
|
||||
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
|
||||
if( !(*it)->matches( testCase ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4719,8 +4720,11 @@ namespace Catch {
|
||||
std::string line;
|
||||
while( std::getline( f, line ) ) {
|
||||
line = trim(line);
|
||||
if( !line.empty() && !startsWith( line, "#" ) )
|
||||
addTestOrTags( config, "\"" + line + "\"," );
|
||||
if( !line.empty() && !startsWith( line, "#" ) ) {
|
||||
if( !startsWith( line, "\"" ) )
|
||||
line = "\"" + line + "\"";
|
||||
addTestOrTags( config, line + "," );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5368,7 +5372,10 @@ namespace Catch {
|
||||
++it ) {
|
||||
matchedTests++;
|
||||
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
|
||||
Catch::cout() << testCaseInfo.name << std::endl;
|
||||
if( startsWith( testCaseInfo.name, "#" ) )
|
||||
Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
|
||||
else
|
||||
Catch::cout() << testCaseInfo.name << std::endl;
|
||||
}
|
||||
return matchedTests;
|
||||
}
|
||||
@@ -6454,7 +6461,7 @@ namespace Catch {
|
||||
namespace Catch {
|
||||
|
||||
struct RandomNumberGenerator {
|
||||
typedef int result_type;
|
||||
typedef std::ptrdiff_t result_type;
|
||||
|
||||
result_type operator()( result_type n ) const { return std::rand() % n; }
|
||||
|
||||
@@ -7571,7 +7578,7 @@ namespace Catch {
|
||||
return os;
|
||||
}
|
||||
|
||||
Version libraryVersion( 1, 5, 6, "", 0 );
|
||||
Version libraryVersion( 1, 5, 8, "", 0 );
|
||||
|
||||
}
|
||||
|
||||
@@ -7802,8 +7809,11 @@ namespace Catch {
|
||||
bool contains( std::string const& s, std::string const& infix ) {
|
||||
return s.find( infix ) != std::string::npos;
|
||||
}
|
||||
char toLowerCh(char c) {
|
||||
return static_cast<char>( ::tolower( c ) );
|
||||
}
|
||||
void toLowerInPlace( std::string& s ) {
|
||||
std::transform( s.begin(), s.end(), s.begin(), ::tolower );
|
||||
std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
|
||||
}
|
||||
std::string toLower( std::string const& s ) {
|
||||
std::string lc = s;
|
||||
@@ -8951,9 +8961,10 @@ namespace Catch {
|
||||
break;
|
||||
|
||||
default:
|
||||
// Escape control chars - based on contribution by @espenalb in PR #465
|
||||
// Escape control chars - based on contribution by @espenalb in PR #465 and
|
||||
// by @mrpi PR #588
|
||||
if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
|
||||
os << "&#x" << std::uppercase << std::hex << static_cast<int>( c );
|
||||
os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
|
||||
else
|
||||
os << c;
|
||||
}
|
||||
@@ -9008,13 +9019,20 @@ namespace Catch {
|
||||
: m_tagIsOpen( false ),
|
||||
m_needsNewline( false ),
|
||||
m_os( &Catch::cout() )
|
||||
{}
|
||||
{
|
||||
// We encode control characters, which requires
|
||||
// XML 1.1
|
||||
// see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
|
||||
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
|
||||
}
|
||||
|
||||
XmlWriter( std::ostream& os )
|
||||
: m_tagIsOpen( false ),
|
||||
m_needsNewline( false ),
|
||||
m_os( &os )
|
||||
{}
|
||||
{
|
||||
*m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
|
||||
}
|
||||
|
||||
~XmlWriter() {
|
||||
while( !m_tags.empty() )
|
||||
@@ -9181,7 +9199,7 @@ namespace Catch {
|
||||
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
|
||||
StreamingReporterBase::testCaseStarting(testInfo);
|
||||
m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) );
|
||||
m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.name );
|
||||
|
||||
if ( m_config->showDurations() == ShowDurations::Always )
|
||||
m_testCaseTimer.start();
|
||||
@@ -9243,7 +9261,7 @@ namespace Catch {
|
||||
.writeText( assertionResult.getMessage() );
|
||||
break;
|
||||
case ResultWas::FatalErrorCondition:
|
||||
m_xml.scopedElement( "Fatal Error Condition" )
|
||||
m_xml.scopedElement( "FatalErrorCondition" )
|
||||
.writeAttribute( "filename", assertionResult.getSourceInfo().file )
|
||||
.writeAttribute( "line", assertionResult.getSourceInfo().line )
|
||||
.writeText( assertionResult.getMessage() );
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/entity_bits.hpp>
|
||||
|
||||
TEST_CASE("entity_bits") {
|
||||
|
||||
SECTION("can_be_set_and_checked") {
|
||||
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
|
||||
REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
|
||||
|
||||
entities |= osmium::osm_entity_bits::relation;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::object));
|
||||
|
||||
entities |= osmium::osm_entity_bits::area;
|
||||
REQUIRE(entities == osmium::osm_entity_bits::object);
|
||||
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::changeset));
|
||||
|
||||
entities &= osmium::osm_entity_bits::node;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::node));
|
||||
REQUIRE(! (entities & osmium::osm_entity_bits::way));
|
||||
REQUIRE(entities == osmium::osm_entity_bits::node);
|
||||
|
||||
REQUIRE(osmium::osm_entity_bits::nothing == osmium::osm_entity_bits::from_item_type(osmium::item_type::undefined));
|
||||
REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node));
|
||||
REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way));
|
||||
REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation));
|
||||
REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset));
|
||||
REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,444 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/memory/buffer.hpp>
|
||||
#include <osmium/osm.hpp>
|
||||
|
||||
TEST_CASE("create objects using builder") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
std::string user;
|
||||
|
||||
SECTION("complete node with tags") {
|
||||
SECTION("user length 0") {
|
||||
user = "";
|
||||
}
|
||||
SECTION("user length 1") {
|
||||
user = "1";
|
||||
}
|
||||
SECTION("user length 2") {
|
||||
user = "12";
|
||||
}
|
||||
SECTION("user length 3") {
|
||||
user = "123";
|
||||
}
|
||||
SECTION("user length 4") {
|
||||
user = "1234";
|
||||
}
|
||||
SECTION("user length 5") {
|
||||
user = "12345";
|
||||
}
|
||||
SECTION("user length 6") {
|
||||
user = "123456";
|
||||
}
|
||||
SECTION("user length 7") {
|
||||
user = "1234567";
|
||||
}
|
||||
SECTION("user length 8") {
|
||||
user = "12345678";
|
||||
}
|
||||
SECTION("user length 9") {
|
||||
user = "123456789";
|
||||
}
|
||||
SECTION("user length 10") {
|
||||
user = "1234567890";
|
||||
}
|
||||
SECTION("user length 11") {
|
||||
user = "12345678901";
|
||||
}
|
||||
SECTION("user length 12") {
|
||||
user = "123456789012";
|
||||
}
|
||||
SECTION("user length 13") {
|
||||
user = "1234567890123";
|
||||
}
|
||||
SECTION("user length 14") {
|
||||
user = "12345678901234";
|
||||
}
|
||||
SECTION("user length 15") {
|
||||
user = "123456789012345";
|
||||
}
|
||||
SECTION("user length 16") {
|
||||
user = "1234567890123456";
|
||||
}
|
||||
SECTION("user length 17") {
|
||||
user = "12345678901234567";
|
||||
}
|
||||
SECTION("user length 18") {
|
||||
user = "123456789012345678";
|
||||
}
|
||||
|
||||
osmium::Location loc{1.2, 3.4};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder builder{buffer};
|
||||
|
||||
builder.set_id(17)
|
||||
.set_visible(true)
|
||||
.set_version(1)
|
||||
.set_changeset(123)
|
||||
.set_uid(555)
|
||||
.set_timestamp("2015-07-01T00:00:01Z")
|
||||
.set_location(loc)
|
||||
.set_user(user);
|
||||
|
||||
builder.add_tags({{"highway", "primary"}, {"oneway", "yes"}});
|
||||
}
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(buffer.commit());
|
||||
|
||||
REQUIRE(node.id() == 17);
|
||||
REQUIRE(node.version() == 1);
|
||||
REQUIRE(node.changeset() == 123);
|
||||
REQUIRE(node.uid() == 555);
|
||||
REQUIRE(node.timestamp() == osmium::Timestamp{"2015-07-01T00:00:01Z"});
|
||||
REQUIRE(node.location() == loc);
|
||||
|
||||
REQUIRE(user == node.user());
|
||||
|
||||
REQUIRE(node.tags().size() == 2);
|
||||
}
|
||||
|
||||
SECTION("complete way with tags") {
|
||||
SECTION("user length 0") {
|
||||
user = "";
|
||||
}
|
||||
SECTION("user length 1") {
|
||||
user = "1";
|
||||
}
|
||||
SECTION("user length 2") {
|
||||
user = "12";
|
||||
}
|
||||
SECTION("user length 3") {
|
||||
user = "123";
|
||||
}
|
||||
SECTION("user length 4") {
|
||||
user = "1234";
|
||||
}
|
||||
SECTION("user length 5") {
|
||||
user = "12345";
|
||||
}
|
||||
SECTION("user length 6") {
|
||||
user = "123456";
|
||||
}
|
||||
SECTION("user length 7") {
|
||||
user = "1234567";
|
||||
}
|
||||
SECTION("user length 8") {
|
||||
user = "12345678";
|
||||
}
|
||||
SECTION("user length 9") {
|
||||
user = "123456789";
|
||||
}
|
||||
SECTION("user length 10") {
|
||||
user = "1234567890";
|
||||
}
|
||||
SECTION("user length 11") {
|
||||
user = "12345678901";
|
||||
}
|
||||
SECTION("user length 12") {
|
||||
user = "123456789012";
|
||||
}
|
||||
SECTION("user length 13") {
|
||||
user = "1234567890123";
|
||||
}
|
||||
SECTION("user length 14") {
|
||||
user = "12345678901234";
|
||||
}
|
||||
SECTION("user length 15") {
|
||||
user = "123456789012345";
|
||||
}
|
||||
SECTION("user length 16") {
|
||||
user = "1234567890123456";
|
||||
}
|
||||
SECTION("user length 17") {
|
||||
user = "12345678901234567";
|
||||
}
|
||||
SECTION("user length 18") {
|
||||
user = "123456789012345678";
|
||||
}
|
||||
|
||||
{
|
||||
osmium::builder::WayBuilder builder{buffer};
|
||||
|
||||
builder.set_id(17)
|
||||
.set_visible(true)
|
||||
.set_version(1)
|
||||
.set_changeset(123)
|
||||
.set_uid(555)
|
||||
.set_timestamp("2015-07-01T00:00:01Z")
|
||||
.set_user(user);
|
||||
|
||||
builder.add_tags({{"highway", "primary"}, {"oneway", "yes"}});
|
||||
}
|
||||
|
||||
const auto& way = buffer.get<osmium::Way>(buffer.commit());
|
||||
|
||||
REQUIRE(way.id() == 17);
|
||||
REQUIRE(way.version() == 1);
|
||||
REQUIRE(way.changeset() == 123);
|
||||
REQUIRE(way.uid() == 555);
|
||||
REQUIRE(way.timestamp() == osmium::Timestamp{"2015-07-01T00:00:01Z"});
|
||||
|
||||
REQUIRE(user == way.user());
|
||||
|
||||
REQUIRE(way.tags().size() == 2);
|
||||
}
|
||||
|
||||
SECTION("complete relation with tags") {
|
||||
SECTION("user length 0") {
|
||||
user = "";
|
||||
}
|
||||
SECTION("user length 1") {
|
||||
user = "1";
|
||||
}
|
||||
SECTION("user length 2") {
|
||||
user = "12";
|
||||
}
|
||||
SECTION("user length 3") {
|
||||
user = "123";
|
||||
}
|
||||
SECTION("user length 4") {
|
||||
user = "1234";
|
||||
}
|
||||
SECTION("user length 5") {
|
||||
user = "12345";
|
||||
}
|
||||
SECTION("user length 6") {
|
||||
user = "123456";
|
||||
}
|
||||
SECTION("user length 7") {
|
||||
user = "1234567";
|
||||
}
|
||||
SECTION("user length 8") {
|
||||
user = "12345678";
|
||||
}
|
||||
SECTION("user length 9") {
|
||||
user = "123456789";
|
||||
}
|
||||
SECTION("user length 10") {
|
||||
user = "1234567890";
|
||||
}
|
||||
SECTION("user length 11") {
|
||||
user = "12345678901";
|
||||
}
|
||||
SECTION("user length 12") {
|
||||
user = "123456789012";
|
||||
}
|
||||
SECTION("user length 13") {
|
||||
user = "1234567890123";
|
||||
}
|
||||
SECTION("user length 14") {
|
||||
user = "12345678901234";
|
||||
}
|
||||
SECTION("user length 15") {
|
||||
user = "123456789012345";
|
||||
}
|
||||
SECTION("user length 16") {
|
||||
user = "1234567890123456";
|
||||
}
|
||||
SECTION("user length 17") {
|
||||
user = "12345678901234567";
|
||||
}
|
||||
SECTION("user length 18") {
|
||||
user = "123456789012345678";
|
||||
}
|
||||
|
||||
{
|
||||
osmium::builder::RelationBuilder builder{buffer};
|
||||
|
||||
builder.set_id(17)
|
||||
.set_visible(true)
|
||||
.set_version(1)
|
||||
.set_changeset(123)
|
||||
.set_uid(555)
|
||||
.set_timestamp("2015-07-01T00:00:01Z")
|
||||
.set_user(user);
|
||||
|
||||
builder.add_tags({{"highway", "primary"}, {"oneway", "yes"}});
|
||||
}
|
||||
|
||||
const auto& relation = buffer.get<osmium::Relation>(buffer.commit());
|
||||
|
||||
REQUIRE(relation.id() == 17);
|
||||
REQUIRE(relation.version() == 1);
|
||||
REQUIRE(relation.changeset() == 123);
|
||||
REQUIRE(relation.uid() == 555);
|
||||
REQUIRE(relation.timestamp() == osmium::Timestamp{"2015-07-01T00:00:01Z"});
|
||||
|
||||
REQUIRE(user == relation.user());
|
||||
|
||||
REQUIRE(relation.tags().size() == 2);
|
||||
}
|
||||
|
||||
SECTION("complete changeset with tags") {
|
||||
osmium::Location bl{-1.2, -3.4};
|
||||
osmium::Location tr{1.2, 3.4};
|
||||
|
||||
SECTION("user length 0") {
|
||||
user = "";
|
||||
}
|
||||
SECTION("user length 1") {
|
||||
user = "1";
|
||||
}
|
||||
SECTION("user length 2") {
|
||||
user = "12";
|
||||
}
|
||||
SECTION("user length 3") {
|
||||
user = "123";
|
||||
}
|
||||
SECTION("user length 4") {
|
||||
user = "1234";
|
||||
}
|
||||
SECTION("user length 5") {
|
||||
user = "12345";
|
||||
}
|
||||
SECTION("user length 6") {
|
||||
user = "123456";
|
||||
}
|
||||
SECTION("user length 7") {
|
||||
user = "1234567";
|
||||
}
|
||||
SECTION("user length 8") {
|
||||
user = "12345678";
|
||||
}
|
||||
SECTION("user length 9") {
|
||||
user = "123456789";
|
||||
}
|
||||
SECTION("user length 10") {
|
||||
user = "1234567890";
|
||||
}
|
||||
SECTION("user length 11") {
|
||||
user = "12345678901";
|
||||
}
|
||||
SECTION("user length 12") {
|
||||
user = "123456789012";
|
||||
}
|
||||
SECTION("user length 13") {
|
||||
user = "1234567890123";
|
||||
}
|
||||
SECTION("user length 14") {
|
||||
user = "12345678901234";
|
||||
}
|
||||
SECTION("user length 15") {
|
||||
user = "123456789012345";
|
||||
}
|
||||
SECTION("user length 16") {
|
||||
user = "1234567890123456";
|
||||
}
|
||||
SECTION("user length 17") {
|
||||
user = "12345678901234567";
|
||||
}
|
||||
SECTION("user length 18") {
|
||||
user = "123456789012345678";
|
||||
}
|
||||
|
||||
{
|
||||
osmium::builder::ChangesetBuilder builder{buffer};
|
||||
|
||||
builder.set_id(17)
|
||||
.set_uid(222)
|
||||
.set_created_at(osmium::Timestamp{"2016-07-03T01:23:45Z"})
|
||||
.set_closed_at(osmium::Timestamp{"2016-07-03T01:23:48Z"})
|
||||
.set_num_changes(3)
|
||||
.set_num_comments(2)
|
||||
.set_bounds(osmium::Box{bl, tr})
|
||||
.set_user(user);
|
||||
}
|
||||
|
||||
const auto& changeset = buffer.get<osmium::Changeset>(buffer.commit());
|
||||
|
||||
REQUIRE(changeset.id() == 17);
|
||||
REQUIRE(changeset.uid() == 222);
|
||||
REQUIRE(changeset.created_at() == osmium::Timestamp{"2016-07-03T01:23:45Z"});
|
||||
REQUIRE(changeset.closed_at() == osmium::Timestamp{"2016-07-03T01:23:48Z"});
|
||||
REQUIRE(changeset.num_changes() == 3);
|
||||
REQUIRE(changeset.num_comments() == 2);
|
||||
|
||||
const auto& box = changeset.bounds();
|
||||
REQUIRE(box.bottom_left() == bl);
|
||||
REQUIRE(box.top_right() == tr);
|
||||
|
||||
REQUIRE(user == changeset.user());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("no call to set_user on node") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder builder{buffer};
|
||||
}
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(buffer.commit());
|
||||
|
||||
REQUIRE(*node.user() == '\0');
|
||||
}
|
||||
|
||||
TEST_CASE("set_user with length on node") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
std::string user = "userx";
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder builder{buffer};
|
||||
builder.set_user(user.c_str(), 4);
|
||||
}
|
||||
|
||||
const auto& node = buffer.get<osmium::Node>(buffer.commit());
|
||||
|
||||
REQUIRE(std::string{"user"} == node.user());
|
||||
}
|
||||
|
||||
TEST_CASE("no call to set_user on way") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
|
||||
{
|
||||
osmium::builder::WayBuilder builder{buffer};
|
||||
}
|
||||
|
||||
const auto& way = buffer.get<osmium::Way>(buffer.commit());
|
||||
|
||||
REQUIRE(*way.user() == '\0');
|
||||
}
|
||||
|
||||
TEST_CASE("set_user with length on way") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
std::string user = "userx";
|
||||
|
||||
{
|
||||
osmium::builder::WayBuilder builder{buffer};
|
||||
builder.set_user(user.c_str(), 4);
|
||||
}
|
||||
|
||||
const auto& way = buffer.get<osmium::Way>(buffer.commit());
|
||||
|
||||
REQUIRE(std::string{"user"} == way.user());
|
||||
}
|
||||
|
||||
TEST_CASE("no call to set_user on changeset") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
|
||||
{
|
||||
osmium::builder::ChangesetBuilder builder{buffer};
|
||||
}
|
||||
|
||||
const auto& changeset = buffer.get<osmium::Changeset>(buffer.commit());
|
||||
|
||||
REQUIRE(*changeset.user() == '\0');
|
||||
}
|
||||
|
||||
TEST_CASE("set_user with length on changeset") {
|
||||
osmium::memory::Buffer buffer{1024*10};
|
||||
std::string user = "userx";
|
||||
|
||||
{
|
||||
osmium::builder::ChangesetBuilder builder{buffer};
|
||||
builder.set_user(user.c_str(), 4);
|
||||
}
|
||||
|
||||
const auto& changeset = buffer.get<osmium::Changeset>(buffer.commit());
|
||||
|
||||
REQUIRE(std::string{"user"} == changeset.user());
|
||||
}
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#ifndef TEST_GEOM_HELPER_HPP
|
||||
#define TEST_GEOM_HELPER_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <geos/io/WKBWriter.h>
|
||||
|
||||
inline std::string geos_to_wkb(const geos::geom::Geometry* geometry) {
|
||||
std::stringstream ss;
|
||||
geos::io::WKBWriter wkb_writer;
|
||||
wkb_writer.writeHEX(*geometry, ss);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
#endif // TEST_GEOM_HELPER_HPP
|
||||
+5
-5
@@ -5,12 +5,12 @@
|
||||
#include <osmium/geom/projection.hpp>
|
||||
|
||||
TEST_CASE("CRS") {
|
||||
osmium::geom::CRS wgs84{4326};
|
||||
osmium::geom::CRS mercator{3857};
|
||||
const osmium::geom::CRS wgs84{4326};
|
||||
const osmium::geom::CRS mercator{3857};
|
||||
|
||||
osmium::geom::Coordinates c{osmium::geom::deg_to_rad(1.2), osmium::geom::deg_to_rad(3.4)};
|
||||
auto ct = osmium::geom::transform(wgs84, mercator, c);
|
||||
auto c2 = osmium::geom::transform(mercator, wgs84, ct);
|
||||
const osmium::geom::Coordinates c{osmium::geom::deg_to_rad(1.2), osmium::geom::deg_to_rad(3.4)};
|
||||
const auto ct = osmium::geom::transform(wgs84, mercator, c);
|
||||
const auto c2 = osmium::geom::transform(mercator, wgs84, ct);
|
||||
|
||||
REQUIRE(c.x == Approx(c2.x));
|
||||
REQUIRE(c.y == Approx(c2.y));
|
||||
|
||||
+3
-5
@@ -6,11 +6,9 @@
|
||||
|
||||
TEST_CASE("Geometry exception") {
|
||||
|
||||
SECTION("geometry_error") {
|
||||
osmium::geometry_error e("some error message", "node", 17);
|
||||
REQUIRE(e.id() == 17);
|
||||
REQUIRE(std::string(e.what()) == "some error message (node_id=17)");
|
||||
}
|
||||
osmium::geometry_error e{"some error message", "node", 17};
|
||||
REQUIRE(e.id() == 17);
|
||||
REQUIRE(std::string{e.what()} == "some error message (node_id=17)");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,41 +1,21 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/geos.hpp>
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/projection.hpp>
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
#include <osmium/geom/wkt.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
TEST_CASE("Projection") {
|
||||
|
||||
SECTION("point_mercator") {
|
||||
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory(2);
|
||||
|
||||
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt);
|
||||
}
|
||||
|
||||
SECTION("point_epsg_3857") {
|
||||
osmium::geom::WKTFactory<osmium::geom::Projection> factory(osmium::geom::Projection(3857), 2);
|
||||
|
||||
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string {"POINT(356222.37 467961.14)"} == wkt);
|
||||
}
|
||||
|
||||
SECTION("wkb_with_parameter") {
|
||||
osmium::geom::WKBFactory<osmium::geom::Projection> wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<osmium::geom::Projection> geos_factory(osmium::geom::Projection(3857));
|
||||
|
||||
std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2));
|
||||
std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2));
|
||||
REQUIRE(geos_to_wkb(geos_point.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("cleanup") {
|
||||
// trying to make valgrind happy, but there is still a memory leak in proj library
|
||||
pj_deallocate_grids();
|
||||
}
|
||||
TEST_CASE("Projection using MercatorProjection class to WKT") {
|
||||
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory{2};
|
||||
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(wkt == "POINT(356222.37 467961.14)");
|
||||
}
|
||||
|
||||
TEST_CASE("Projection using Projection class to WKT") {
|
||||
osmium::geom::WKTFactory<osmium::geom::Projection> factory{osmium::geom::Projection{3857}, 2};
|
||||
|
||||
const std::string wkt{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(wkt == "POINT(356222.37 467961.14)");
|
||||
}
|
||||
|
||||
|
||||
+92
-111
@@ -5,162 +5,143 @@
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
TEST_CASE("GeoJSON_Geometry") {
|
||||
|
||||
SECTION("point") {
|
||||
TEST_CASE("GeoJSON point geometry") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
|
||||
std::string json {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
|
||||
SECTION("point") {
|
||||
const std::string json{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), osmium::invalid_location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
TEST_CASE("GeoJSON linestring geometry") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
osmium::memory::Buffer buffer{1000};
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl)};
|
||||
SECTION("linestring, default") {
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
const std::string json{factory.create_linestring(wnl)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.6,4.9]]}"} == json);
|
||||
}
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
SECTION("linestring, unique, backwards") {
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
const std::string json{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.2,4.2]]}"} == json);
|
||||
}
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
SECTION("linestring, all") {
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
const std::string json{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.5,4.7],[3.6,4.9]]}"} == json);
|
||||
}
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
SECTION("linestring, all, backwards") {
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
const std::string json{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.5,4.7],[3.2,4.2]]}"} == json);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("empty_linestring") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
SECTION("empty_linestring") {
|
||||
const auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
auto& wnl = create_test_wnl_empty(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
SECTION("linestring_with_two_same_locations") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
}
|
||||
|
||||
{
|
||||
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
|
||||
SECTION("linestring with two same locations") {
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
|
||||
|
||||
{
|
||||
const std::string json{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
|
||||
}
|
||||
|
||||
{
|
||||
const std::string json{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("linestring with undefined location") {
|
||||
const auto& wnl = create_test_wnl_undefined_location(buffer);
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("linestring_with_undefined_location") {
|
||||
TEST_CASE("GeoJSON area geometry") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
osmium::memory::Buffer buffer{1000};
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
auto& wnl = create_test_wnl_undefined_location(buffer);
|
||||
SECTION("area_1outer_0inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
|
||||
}
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 2);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
|
||||
SECTION("area_1outer_0inner") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 2);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
|
||||
{
|
||||
std::string json {factory.create_multipolygon(area)};
|
||||
std::string json{factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[3.2,4.2],[3.5,4.7],[3.6,4.9],[3.2,4.2]]]]}"} == json);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("area_1outer_1inner") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
SECTION("area_1outer_1inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 3);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
REQUIRE(!area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 3);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
{
|
||||
std::string json {factory.create_multipolygon(area)};
|
||||
std::string json{factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[8,1],[8,8],[1,8],[1,1]]]]}"} == json);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("area_2outer_2inner") {
|
||||
osmium::geom::GeoJSONFactory<> factory;
|
||||
SECTION("area_2outer_2inner") {
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(1000);
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
REQUIRE(area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 5);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
REQUIRE(area.is_multipolygon());
|
||||
REQUIRE(std::distance(area.cbegin(), area.cend()) == 5);
|
||||
REQUIRE(area.subitems<osmium::OuterRing>().size() == area.num_rings().first);
|
||||
REQUIRE(area.subitems<osmium::InnerRing>().size() == area.num_rings().second);
|
||||
|
||||
int outer_ring=0;
|
||||
int inner_ring=0;
|
||||
for (const auto& outer : area.outer_rings()) {
|
||||
if (outer_ring == 0) {
|
||||
REQUIRE(outer.front().ref() == 1);
|
||||
} else if (outer_ring == 1) {
|
||||
REQUIRE(outer.front().ref() == 100);
|
||||
} else {
|
||||
REQUIRE(false);
|
||||
}
|
||||
for (const auto& inner : area.inner_rings(outer)) {
|
||||
if (outer_ring == 0 && inner_ring == 0) {
|
||||
REQUIRE(inner.front().ref() == 5);
|
||||
} else if (outer_ring == 0 && inner_ring == 1) {
|
||||
REQUIRE(inner.front().ref() == 10);
|
||||
int outer_ring=0;
|
||||
int inner_ring=0;
|
||||
for (const auto& outer : area.outer_rings()) {
|
||||
if (outer_ring == 0) {
|
||||
REQUIRE(outer.front().ref() == 1);
|
||||
} else if (outer_ring == 1) {
|
||||
REQUIRE(outer.front().ref() == 100);
|
||||
} else {
|
||||
REQUIRE(false);
|
||||
}
|
||||
++inner_ring;
|
||||
for (const auto& inner : area.inner_rings(outer)) {
|
||||
if (outer_ring == 0 && inner_ring == 0) {
|
||||
REQUIRE(inner.front().ref() == 5);
|
||||
} else if (outer_ring == 0 && inner_ring == 1) {
|
||||
REQUIRE(inner.front().ref() == 10);
|
||||
} else {
|
||||
REQUIRE(false);
|
||||
}
|
||||
++inner_ring;
|
||||
}
|
||||
inner_ring = 0;
|
||||
++outer_ring;
|
||||
}
|
||||
inner_ring = 0;
|
||||
++outer_ring;
|
||||
}
|
||||
|
||||
{
|
||||
std::string json {factory.create_multipolygon(area)};
|
||||
std::string json{factory.create_multipolygon(area)};
|
||||
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[4,1],[4,4],[1,4],[1,1]],[[5,5],[5,7],[7,7],[5,5]]],[[[10,10],[11,10],[11,11],[10,11],[10,10]]]]}"} == json);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+31
-25
@@ -1,6 +1,10 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/geos.hpp>
|
||||
|
||||
#ifdef OSMIUM_WITH_GEOS
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
|
||||
#include "area_helper.hpp"
|
||||
@@ -9,7 +13,7 @@
|
||||
TEST_CASE("GEOS geometry factory - create point") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
const std::unique_ptr<geos::geom::Point> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
REQUIRE(4326 == point->getSRID());
|
||||
@@ -18,7 +22,7 @@ TEST_CASE("GEOS geometry factory - create point") {
|
||||
TEST_CASE("GEOS geometry factory - create point in web mercator") {
|
||||
osmium::geom::GEOSFactory<osmium::geom::MercatorProjection> factory;
|
||||
|
||||
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
const std::unique_ptr<geos::geom::Point> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(Approx(356222.3705384755l) == point->getX());
|
||||
REQUIRE(Approx(467961.143605213l) == point->getY());
|
||||
REQUIRE(3857 == point->getSRID());
|
||||
@@ -26,9 +30,9 @@ TEST_CASE("GEOS geometry factory - create point in web mercator") {
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create point with externally created GEOS factory") {
|
||||
geos::geom::GeometryFactory geos_factory;
|
||||
osmium::geom::GEOSFactory<> factory(geos_factory);
|
||||
osmium::geom::GEOSFactory<> factory{geos_factory};
|
||||
|
||||
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
const std::unique_ptr<geos::geom::Point> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
REQUIRE(0 == point->getSRID());
|
||||
@@ -37,45 +41,45 @@ TEST_CASE("GEOS geometry factory - create point with externally created GEOS fac
|
||||
TEST_CASE("GEOS geometry factory - can not create from invalid location") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), osmium::invalid_location);
|
||||
}
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create linestring") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
SECTION("from way node list") {
|
||||
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl)};
|
||||
const std::unique_ptr<geos::geom::LineString> linestring{factory.create_linestring(wnl)};
|
||||
REQUIRE(3 == linestring->getNumPoints());
|
||||
|
||||
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
const auto p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
REQUIRE(3.2 == p0->getX());
|
||||
std::unique_ptr<geos::geom::Point> p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
|
||||
const auto p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
|
||||
REQUIRE(3.6 == p2->getX());
|
||||
}
|
||||
|
||||
SECTION("without duplicates and backwards") {
|
||||
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
const std::unique_ptr<geos::geom::LineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(3 == linestring->getNumPoints());
|
||||
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
const auto p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
REQUIRE(3.6 == p0->getX());
|
||||
std::unique_ptr<geos::geom::Point> p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
|
||||
const auto p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
|
||||
REQUIRE(3.2 == p2->getX());
|
||||
}
|
||||
|
||||
SECTION("with duplicates") {
|
||||
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
const std::unique_ptr<geos::geom::LineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(4 == linestring->getNumPoints());
|
||||
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
const auto p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
REQUIRE(3.2 == p0->getX());
|
||||
}
|
||||
|
||||
SECTION("with duplicates and backwards") {
|
||||
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
const std::unique_ptr<geos::geom::LineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(4 == linestring->getNumPoints());
|
||||
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
const auto p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
|
||||
REQUIRE(3.6 == p0->getX());
|
||||
}
|
||||
}
|
||||
@@ -83,10 +87,10 @@ TEST_CASE("GEOS geometry factory - create linestring") {
|
||||
TEST_CASE("GEOS geometry factory - create area with one outer and no inner rings") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<geos::geom::MultiPolygon> mp{factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
@@ -96,17 +100,17 @@ TEST_CASE("GEOS geometry factory - create area with one outer and no inner rings
|
||||
const geos::geom::LineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(4 == l0e->getNumPoints());
|
||||
|
||||
std::unique_ptr<geos::geom::Point> l0e_p0 = std::unique_ptr<geos::geom::Point>(l0e->getPointN(1));
|
||||
const auto l0e_p0 = std::unique_ptr<geos::geom::Point>(l0e->getPointN(1));
|
||||
REQUIRE(3.5 == l0e_p0->getX());
|
||||
}
|
||||
|
||||
TEST_CASE("GEOS geometry factory - create area with one outer and one inner ring") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<geos::geom::MultiPolygon> mp{factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
@@ -123,10 +127,10 @@ TEST_CASE("GEOS geometry factory - create area with one outer and one inner ring
|
||||
TEST_CASE("GEOS geometry factory - create area with two outer and two inner rings") {
|
||||
osmium::geom::GEOSFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<geos::geom::MultiPolygon> mp{factory.create_multipolygon(area)};
|
||||
REQUIRE(2 == mp->getNumGeometries());
|
||||
|
||||
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
|
||||
@@ -144,3 +148,5 @@ TEST_CASE("GEOS geometry factory - create area with two outer and two inner ring
|
||||
REQUIRE(5 == l1e->getNumPoints());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/geom/geos.hpp>
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
TEST_CASE("WKB_Geometry_with_GEOS") {
|
||||
|
||||
SECTION("point") {
|
||||
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<> geos_factory;
|
||||
|
||||
std::string wkb {wkb_factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
|
||||
std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2));
|
||||
REQUIRE(geos_to_wkb(geos_point.get()) == wkb);
|
||||
}
|
||||
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<> geos_factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
std::string wkb = wkb_factory.create_linestring(wnl);
|
||||
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
|
||||
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
|
||||
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
{
|
||||
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
|
||||
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("area_1outer_0inner") {
|
||||
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<> geos_factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
std::string wkb = wkb_factory.create_multipolygon(area);
|
||||
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("area_1outer_1inner") {
|
||||
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<> geos_factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
std::string wkb = wkb_factory.create_multipolygon(area);
|
||||
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("area_2outer_2inner") {
|
||||
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::GEOSFactory<> geos_factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
std::string wkb = wkb_factory.create_multipolygon(area);
|
||||
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
|
||||
REQUIRE(geos_to_wkb(geos.get()) == wkb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+63
-69
@@ -5,121 +5,115 @@
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
TEST_CASE("OGR_Geometry") {
|
||||
|
||||
SECTION("point") {
|
||||
TEST_CASE("OGR point geometry") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
|
||||
std::unique_ptr<OGRPoint> point {factory.create_point(osmium::Location(3.2, 4.2))};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
SECTION("point") {
|
||||
std::unique_ptr<OGRPoint> point{factory.create_point(osmium::Location{3.2, 4.2})};
|
||||
REQUIRE(3.2 == point->getX());
|
||||
REQUIRE(4.2 == point->getY());
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("empty_point") {
|
||||
TEST_CASE("OGR linestring geometry") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
|
||||
}
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
auto &wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl)};
|
||||
SECTION("linestring, default") {
|
||||
std::unique_ptr<OGRLineString> linestring{factory.create_linestring(wnl)};
|
||||
REQUIRE(3 == linestring->getNumPoints());
|
||||
|
||||
REQUIRE(3.2 == linestring->getX(0));
|
||||
REQUIRE(3.6 == linestring->getX(2));
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
SECTION("linestring, unique nodes, backwards") {
|
||||
std::unique_ptr<OGRLineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
REQUIRE(3 == linestring->getNumPoints());
|
||||
|
||||
REQUIRE(3.6 == linestring->getX(0));
|
||||
REQUIRE(3.2 == linestring->getX(2));
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
SECTION("linestring, all nodes") {
|
||||
std::unique_ptr<OGRLineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
REQUIRE(4 == linestring->getNumPoints());
|
||||
|
||||
REQUIRE(3.2 == linestring->getX(0));
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
SECTION("linestring, all nodes, backwards") {
|
||||
std::unique_ptr<OGRLineString> linestring{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
REQUIRE(4 == linestring->getNumPoints());
|
||||
|
||||
REQUIRE(3.6 == linestring->getX(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("area_1outer_0inner") {
|
||||
TEST_CASE("OGR area geometry") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
SECTION("area_1outer_0inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(0 == p0->getNumInteriorRings());
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(0 == p0->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(4 == l0e->getNumPoints());
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(4 == l0e->getNumPoints());
|
||||
|
||||
REQUIRE(3.5 == l0e->getX(1));
|
||||
}
|
||||
REQUIRE(3.5 == l0e->getX(1));
|
||||
}
|
||||
|
||||
SECTION("area_1outer_1inner") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
SECTION("area_1outer_1inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(1 == mp->getNumGeometries());
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(1 == p0->getNumInteriorRings());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(1 == p0->getNumInteriorRings());
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
const OGRLineString* l0i0 = p0->getInteriorRing(0);
|
||||
REQUIRE(5 == l0i0->getNumPoints());
|
||||
}
|
||||
|
||||
const OGRLineString* l0i0 = p0->getInteriorRing(0);
|
||||
REQUIRE(5 == l0i0->getNumPoints());
|
||||
}
|
||||
SECTION("area_2outer_2inner") {
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
SECTION("area_2outer_2inner") {
|
||||
osmium::geom::OGRFactory<> factory;
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(2 == mp->getNumGeometries());
|
||||
|
||||
osmium::memory::Buffer buffer(10000);
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(2 == p0->getNumInteriorRings());
|
||||
|
||||
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
|
||||
REQUIRE(2 == mp->getNumGeometries());
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
|
||||
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
|
||||
REQUIRE(p0);
|
||||
REQUIRE(2 == p0->getNumInteriorRings());
|
||||
const OGRPolygon* p1 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(1));
|
||||
REQUIRE(p1);
|
||||
REQUIRE(0 == p1->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l0e = p0->getExteriorRing();
|
||||
REQUIRE(5 == l0e->getNumPoints());
|
||||
|
||||
const OGRPolygon* p1 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(1));
|
||||
REQUIRE(p1);
|
||||
REQUIRE(0 == p1->getNumInteriorRings());
|
||||
|
||||
const OGRLineString* l1e = p1->getExteriorRing();
|
||||
REQUIRE(5 == l1e->getNumPoints());
|
||||
}
|
||||
const OGRLineString* l1e = p1->getExteriorRing();
|
||||
REQUIRE(5 == l1e->getNumPoints());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <osmium/geom/ogr.hpp>
|
||||
#include <osmium/geom/wkb.hpp>
|
||||
|
||||
#include "area_helper.hpp"
|
||||
#include "wnl_helper.hpp"
|
||||
|
||||
std::string to_wkb(const OGRGeometry* geometry) {
|
||||
std::string buffer;
|
||||
buffer.resize(geometry->WkbSize());
|
||||
|
||||
geometry->exportToWkb(wkbNDR, const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(buffer.data())));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
TEST_CASE("compare WKB point against GDAL/OGR") {
|
||||
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
||||
osmium::geom::OGRFactory<> ogr_factory;
|
||||
|
||||
osmium::Location loc{3.2, 4.2};
|
||||
const std::string wkb{wkb_factory.create_point(loc)};
|
||||
const std::unique_ptr<OGRPoint> geometry = ogr_factory.create_point(loc);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
TEST_CASE("compare WKB linestring against GDAL/OGR") {
|
||||
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
||||
osmium::geom::OGRFactory<> ogr_factory;
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
SECTION("linestring") {
|
||||
const std::string wkb{wkb_factory.create_linestring(wnl)};
|
||||
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("linestring, unique nodes, backwards") {
|
||||
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
||||
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("linestring, all nodes, forwards") {
|
||||
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
||||
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("linestring, all nodes, backwards") {
|
||||
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
||||
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("compare WKB area against GDAL/OGR") {
|
||||
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
||||
osmium::geom::OGRFactory<> ogr_factory;
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
SECTION("area_1outer_0inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
||||
|
||||
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("area_1outer_1inner") {
|
||||
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
||||
|
||||
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
SECTION("area_2outer_2inner") {
|
||||
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
||||
|
||||
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
||||
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
||||
REQUIRE(to_wkb(geometry.get()) == wkb);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+58
-81
@@ -6,144 +6,121 @@
|
||||
#include <osmium/geom/mercator_projection.hpp>
|
||||
#include <osmium/geom/projection.hpp>
|
||||
|
||||
TEST_CASE("Projection") {
|
||||
|
||||
SECTION("identity_projection") {
|
||||
TEST_CASE("Indentity Projection") {
|
||||
osmium::geom::IdentityProjection projection;
|
||||
REQUIRE(4326 == projection.epsg());
|
||||
REQUIRE("+proj=longlat +datum=WGS84 +no_defs" == projection.proj_string());
|
||||
}
|
||||
|
||||
SECTION("project_location_4326") {
|
||||
osmium::geom::Projection projection(4326);
|
||||
TEST_CASE("Projection 4326") {
|
||||
osmium::geom::Projection projection{4326};
|
||||
REQUIRE(4326 == projection.epsg());
|
||||
REQUIRE("+init=epsg:4326" == projection.proj_string());
|
||||
|
||||
const osmium::Location loc(1.0, 2.0);
|
||||
const osmium::geom::Coordinates c {1.0, 2.0};
|
||||
const osmium::Location loc{1.0, 2.0};
|
||||
const osmium::geom::Coordinates c{1.0, 2.0};
|
||||
REQUIRE(c == projection(loc));
|
||||
}
|
||||
|
||||
SECTION("project_location_4326_string") {
|
||||
osmium::geom::Projection projection("+init=epsg:4326");
|
||||
TEST_CASE("Projection 4326 from init string") {
|
||||
osmium::geom::Projection projection{"+init=epsg:4326"};
|
||||
REQUIRE(-1 == projection.epsg());
|
||||
REQUIRE("+init=epsg:4326" == projection.proj_string());
|
||||
|
||||
const osmium::Location loc(1.0, 2.0);
|
||||
const osmium::geom::Coordinates c {1.0, 2.0};
|
||||
const osmium::Location loc{1.0, 2.0};
|
||||
const osmium::geom::Coordinates c{1.0, 2.0};
|
||||
REQUIRE(c == projection(loc));
|
||||
}
|
||||
|
||||
SECTION("unknown_projection_string") {
|
||||
REQUIRE_THROWS_AS(osmium::geom::Projection projection("abc"), osmium::projection_error);
|
||||
TEST_CASE("Creating projection from unknown init string") {
|
||||
REQUIRE_THROWS_AS(osmium::geom::Projection projection{"abc"}, osmium::projection_error);
|
||||
}
|
||||
|
||||
SECTION("unknown_epsg_code") {
|
||||
REQUIRE_THROWS_AS(osmium::geom::Projection projection(9999999), osmium::projection_error);
|
||||
TEST_CASE("Creating projection from unknown EPSG code") {
|
||||
REQUIRE_THROWS_AS(osmium::geom::Projection projection{9999999}, osmium::projection_error);
|
||||
}
|
||||
|
||||
SECTION("project_location_3857") {
|
||||
osmium::geom::Projection projection(3857);
|
||||
TEST_CASE("Projection 3857") {
|
||||
osmium::geom::Projection projection{3857};
|
||||
REQUIRE(3857 == projection.epsg());
|
||||
REQUIRE("+init=epsg:3857" == projection.proj_string());
|
||||
|
||||
{
|
||||
const osmium::Location loc(0.0, 0.0);
|
||||
const osmium::geom::Coordinates c {0.0, 0.0};
|
||||
SECTION("Zero coordinates") {
|
||||
const osmium::Location loc{0.0, 0.0};
|
||||
const osmium::geom::Coordinates c{0.0, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(180.0, 0.0);
|
||||
const osmium::geom::Coordinates c {20037508.34, 0.0};
|
||||
|
||||
SECTION("Max longitude") {
|
||||
const osmium::Location loc{180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(180.0, 0.0);
|
||||
const osmium::geom::Coordinates c {20037508.34, 0.0};
|
||||
|
||||
SECTION("Min longitude") {
|
||||
const osmium::Location loc{-180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{-20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(0.0, 85.0511288);
|
||||
const osmium::geom::Coordinates c {0.0, 20037508.34};
|
||||
|
||||
SECTION("Max latitude") {
|
||||
const osmium::Location loc{0.0, 85.0511288};
|
||||
const osmium::geom::Coordinates c{0.0, 20037508.34};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("project_location_mercator") {
|
||||
TEST_CASE("MercatorProjection") {
|
||||
osmium::geom::MercatorProjection projection;
|
||||
|
||||
{
|
||||
const osmium::Location loc(0.0, 0.0);
|
||||
const osmium::geom::Coordinates c {0.0, 0.0};
|
||||
SECTION("Zero coordinates") {
|
||||
const osmium::Location loc{0.0, 0.0};
|
||||
const osmium::geom::Coordinates c{0.0, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(180.0, 0.0);
|
||||
const osmium::geom::Coordinates c {20037508.34, 0.0};
|
||||
|
||||
SECTION("Max longitude") {
|
||||
const osmium::Location loc{180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(180.0, 0.0);
|
||||
const osmium::geom::Coordinates c {20037508.34, 0.0};
|
||||
|
||||
SECTION("Min longitude") {
|
||||
const osmium::Location loc{-180.0, 0.0};
|
||||
const osmium::geom::Coordinates c{-20037508.34, 0.0};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(0.0, 85.0511288);
|
||||
const osmium::geom::Coordinates c {0.0, 20037508.34};
|
||||
|
||||
SECTION("Max latitude") {
|
||||
const osmium::Location loc{0.0, 85.0511288};
|
||||
const osmium::geom::Coordinates c{0.0, 20037508.34};
|
||||
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.1));
|
||||
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.1));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("compare_mercators") {
|
||||
TEST_CASE("Compare mercator implementations") {
|
||||
osmium::geom::MercatorProjection projection_merc;
|
||||
osmium::geom::Projection projection_3857(3857);
|
||||
REQUIRE(3857 == projection_3857.epsg());
|
||||
REQUIRE("+init=epsg:3857" == projection_3857.proj_string());
|
||||
osmium::geom::Projection projection_3857{3857};
|
||||
|
||||
{
|
||||
const osmium::Location loc(4.2, 27.3);
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(160.789, -42.42);
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(-0.001, 0.001);
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
}
|
||||
{
|
||||
const osmium::Location loc(-85.2, -85.2);
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
}
|
||||
}
|
||||
SECTION("random coordinates") {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen{rd()};
|
||||
std::uniform_real_distribution<> dis_x{-180.0, 180.0};
|
||||
std::uniform_real_distribution<> dis_y{-90.0, 90.0};
|
||||
|
||||
SECTION("compare_mercators") {
|
||||
osmium::geom::MercatorProjection projection_merc;
|
||||
osmium::geom::Projection projection_3857(3857);
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<> dis_x(-180.0, 180.0);
|
||||
std::uniform_real_distribution<> dis_y(-90.0, 90.0);
|
||||
|
||||
for (int n = 0; n < 100000; ++n) {
|
||||
const osmium::Location loc(dis_x(gen), dis_y(gen));
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
for (int n = 0; n < 10000; ++n) {
|
||||
const osmium::Location loc{dis_x(gen), dis_y(gen)};
|
||||
REQUIRE(projection_merc(loc).x == Approx(projection_3857(loc).x).epsilon(0.1));
|
||||
REQUIRE(projection_merc(loc).y == Approx(projection_3857(loc).y).epsilon(0.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include <osmium/geom/tile.hpp>
|
||||
|
||||
#include "helper.hpp"
|
||||
|
||||
#include "test_tile_data.hpp"
|
||||
|
||||
TEST_CASE("Tile from x0.0 y0.0 at zoom 0") {
|
||||
|
||||
+9
-9
@@ -10,28 +10,28 @@ TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
|
||||
const osmium::Location loc{3.2, 4.2};
|
||||
|
||||
SECTION("point") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
SECTION("point in web mercator") {
|
||||
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
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);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
|
||||
|
||||
const std::string wkb{factory.create_point(loc)};
|
||||
REQUIRE(wkb == "0101000020E61000009A99999999990940CDCCCCCCCCCC1040");
|
||||
}
|
||||
|
||||
SECTION("point in ewkb in web mercator") {
|
||||
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
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");
|
||||
@@ -44,7 +44,7 @@ TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
osmium::memory::Buffer buffer{10000};
|
||||
|
||||
SECTION("linestring") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
{
|
||||
@@ -69,7 +69,7 @@ TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
}
|
||||
|
||||
SECTION("linestring as ewkb") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
|
||||
|
||||
const auto& wnl = create_test_wnl_okay(buffer);
|
||||
|
||||
@@ -78,7 +78,7 @@ TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
}
|
||||
|
||||
SECTION("linestring with two same locations") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const auto& wnl = create_test_wnl_same_location(buffer);
|
||||
|
||||
@@ -102,7 +102,7 @@ TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
}
|
||||
|
||||
SECTION("linestring with undefined location") {
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
const auto& wnl = create_test_wnl_undefined_location(buffer);
|
||||
|
||||
@@ -115,7 +115,7 @@ TEST_CASE("WKB geometry factory (byte-order-dependant)") {
|
||||
|
||||
TEST_CASE("WKB geometry (byte-order-independent)") {
|
||||
|
||||
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
|
||||
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
|
||||
|
||||
SECTION("empty point") {
|
||||
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), osmium::invalid_location);
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
inline const osmium::WayNodeList& create_test_wnl_okay(osmium::memory::Buffer& buffer) {
|
||||
auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
{1, {3.2, 4.2}},
|
||||
{3, {3.5, 4.7}},
|
||||
{4, {3.5, 4.7}},
|
||||
@@ -25,7 +25,7 @@ inline const osmium::WayNodeList& create_test_wnl_empty(osmium::memory::Buffer&
|
||||
}
|
||||
|
||||
inline const osmium::WayNodeList& create_test_wnl_same_location(osmium::memory::Buffer& buffer) {
|
||||
auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
{1, {3.5, 4.7}},
|
||||
{2, {3.5, 4.7}}
|
||||
}));
|
||||
@@ -34,7 +34,7 @@ inline const osmium::WayNodeList& create_test_wnl_same_location(osmium::memory::
|
||||
}
|
||||
|
||||
inline const osmium::WayNodeList& create_test_wnl_undefined_location(osmium::memory::Buffer& buffer) {
|
||||
auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
const auto pos = osmium::builder::add_way_node_list(buffer, _nodes({
|
||||
{1, {3.5, 4.7}},
|
||||
{2, osmium::Location()}
|
||||
}));
|
||||
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/index/id_set.hpp>
|
||||
#include <osmium/osm/types.hpp>
|
||||
|
||||
TEST_CASE("Basic functionality of IdSetDense") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
|
||||
REQUIRE_FALSE(s.get(17));
|
||||
REQUIRE_FALSE(s.get(28));
|
||||
REQUIRE(s.empty());
|
||||
REQUIRE(s.size() == 0);
|
||||
|
||||
s.set(17);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE_FALSE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
REQUIRE(s.size() == 1);
|
||||
|
||||
s.set(28);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
REQUIRE(s.size() == 2);
|
||||
|
||||
s.set(17);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.size() == 2);
|
||||
|
||||
REQUIRE_FALSE(s.check_and_set(17));
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.size() == 2);
|
||||
|
||||
s.unset(17);
|
||||
REQUIRE_FALSE(s.get(17));
|
||||
REQUIRE(s.size() == 1);
|
||||
|
||||
REQUIRE(s.check_and_set(32));
|
||||
REQUIRE(s.get(32));
|
||||
REQUIRE(s.size() == 2);
|
||||
|
||||
s.clear();
|
||||
REQUIRE(s.empty());
|
||||
REQUIRE(s.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Iterating over IdSetDense") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
s.set(7);
|
||||
s.set(35);
|
||||
s.set(35);
|
||||
s.set(20);
|
||||
s.set(1LL << 33);
|
||||
s.set(21);
|
||||
s.set((1LL << 27) + 13);
|
||||
|
||||
REQUIRE(s.size() == 6);
|
||||
|
||||
auto it = s.begin();
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 7);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 20);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 21);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 35);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == (1LL << 27) + 13);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 1LL << 33);
|
||||
++it;
|
||||
REQUIRE(it == s.end());
|
||||
}
|
||||
|
||||
TEST_CASE("Test with larger Ids") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
|
||||
const osmium::unsigned_object_id_type start = 25;
|
||||
const osmium::unsigned_object_id_type end = 100000000;
|
||||
const osmium::unsigned_object_id_type step = 123456;
|
||||
|
||||
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
|
||||
s.set(i);
|
||||
}
|
||||
|
||||
for (osmium::unsigned_object_id_type i = start; i < end; i += step) {
|
||||
REQUIRE(s.get(i));
|
||||
REQUIRE_FALSE(s.get(i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Large gap") {
|
||||
osmium::index::IdSetDense<osmium::unsigned_object_id_type> s;
|
||||
|
||||
s.set(3);
|
||||
s.set(1 << 30);
|
||||
|
||||
REQUIRE(s.get(1 << 30));
|
||||
REQUIRE_FALSE(s.get(1 << 29));
|
||||
}
|
||||
|
||||
TEST_CASE("Basic functionality of IdSetSmall") {
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
|
||||
|
||||
REQUIRE_FALSE(s.get(17));
|
||||
REQUIRE_FALSE(s.get(28));
|
||||
REQUIRE(s.empty());
|
||||
|
||||
s.set(17);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE_FALSE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
|
||||
s.set(28);
|
||||
REQUIRE(s.get(17));
|
||||
REQUIRE(s.get(28));
|
||||
REQUIRE_FALSE(s.empty());
|
||||
|
||||
s.clear();
|
||||
REQUIRE(s.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Iterating over IdSetSmall") {
|
||||
osmium::index::IdSetSmall<osmium::unsigned_object_id_type> s;
|
||||
s.set(7);
|
||||
s.set(35);
|
||||
s.set(35);
|
||||
s.set(20);
|
||||
s.set(1LL << 33);
|
||||
s.set(21);
|
||||
s.set((1LL << 27) + 13);
|
||||
|
||||
// needs to be called before size() and iterator will work properly
|
||||
s.sort_unique();
|
||||
|
||||
REQUIRE(s.size() == 6);
|
||||
|
||||
auto it = s.begin();
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 7);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 20);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 21);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 35);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == (1LL << 27) + 13);
|
||||
++it;
|
||||
REQUIRE(it != s.end());
|
||||
REQUIRE(*it == 1LL << 33);
|
||||
++it;
|
||||
REQUIRE(it == s.end());
|
||||
}
|
||||
|
||||
+96
-91
@@ -15,12 +15,14 @@
|
||||
|
||||
#include <osmium/index/node_locations_map.hpp>
|
||||
|
||||
static_assert(osmium::index::empty_value<osmium::Location>() == osmium::Location{}, "Empty value for location is wrong");
|
||||
|
||||
template <typename TIndex>
|
||||
void test_func_all(TIndex& index) {
|
||||
osmium::unsigned_object_id_type id1 = 12;
|
||||
osmium::unsigned_object_id_type id2 = 3;
|
||||
osmium::Location loc1{1.2, 4.5};
|
||||
osmium::Location loc2{3.5, -7.2};
|
||||
const osmium::unsigned_object_id_type id1 = 12;
|
||||
const osmium::unsigned_object_id_type id2 = 3;
|
||||
const osmium::Location loc1{1.2, 4.5};
|
||||
const osmium::Location loc2{3.5, -7.2};
|
||||
|
||||
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
|
||||
|
||||
@@ -33,14 +35,16 @@ void test_func_all(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_THROWS_WITH(index.get(0), "id 0 not found");
|
||||
REQUIRE_THROWS_WITH(index.get(1), "id 1 not found");
|
||||
}
|
||||
|
||||
template <typename TIndex>
|
||||
void test_func_real(TIndex& index) {
|
||||
osmium::unsigned_object_id_type id1 = 12;
|
||||
osmium::unsigned_object_id_type id2 = 3;
|
||||
osmium::Location loc1{1.2, 4.5};
|
||||
osmium::Location loc2{3.5, -7.2};
|
||||
const osmium::unsigned_object_id_type id1 = 12;
|
||||
const osmium::unsigned_object_id_type id2 = 3;
|
||||
const osmium::Location loc1{1.2, 4.5};
|
||||
const osmium::Location loc2{3.5, -7.2};
|
||||
|
||||
index.set(id1, loc1);
|
||||
index.set(id2, loc2);
|
||||
@@ -66,115 +70,116 @@ void test_func_real(TIndex& index) {
|
||||
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
|
||||
}
|
||||
|
||||
TEST_CASE("IdToLocation") {
|
||||
TEST_CASE("Map Id to location: Dummy") {
|
||||
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
SECTION("Dummy") {
|
||||
using index_type = osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
index_type index1;
|
||||
|
||||
index_type index1;
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
test_func_all<index_type>(index1);
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
}
|
||||
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
}
|
||||
TEST_CASE("Map Id to location: DenseMemArray") {
|
||||
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
SECTION("DenseMemArray") {
|
||||
using index_type = osmium::index::map::DenseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
index_type index1;
|
||||
index1.reserve(1000);
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index1;
|
||||
index1.reserve(1000);
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
index2.reserve(1000);
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
index_type index2;
|
||||
index2.reserve(1000);
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
SECTION("DenseMmapArray") {
|
||||
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
TEST_CASE("Map Id to location: DenseMmapArray") {
|
||||
using index_type = osmium::index::map::DenseMmapArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
#else
|
||||
# pragma message("not running 'DenseMapMmap' test case on this machine")
|
||||
#endif
|
||||
|
||||
SECTION("DenseFileArray") {
|
||||
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
TEST_CASE("Map Id to location: DenseFileArray") {
|
||||
using index_type = osmium::index::map::DenseFileArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#ifdef OSMIUM_WITH_SPARSEHASH
|
||||
|
||||
SECTION("SparseMemTable") {
|
||||
using index_type = osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
TEST_CASE("Map Id to location: SparseMemTable") {
|
||||
using index_type = osmium::index::map::SparseMemTable<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
SECTION("SparseMemMap") {
|
||||
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
TEST_CASE("Map Id to location: SparseMemMap") {
|
||||
using index_type = osmium::index::map::SparseMemMap<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
SECTION("SparseMemArray") {
|
||||
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
REQUIRE(2 == index1.size());
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
SECTION("Dynamic map choice") {
|
||||
using map_type = osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
|
||||
|
||||
const std::vector<std::string> map_type_names = map_factory.map_types();
|
||||
REQUIRE(map_type_names.size() >= 5);
|
||||
|
||||
for (const auto& map_type_name : map_type_names) {
|
||||
std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name);
|
||||
index1->reserve(1000);
|
||||
test_func_all<map_type>(*index1);
|
||||
|
||||
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
|
||||
index2->reserve(1000);
|
||||
test_func_real<map_type>(*index2);
|
||||
}
|
||||
}
|
||||
index_type index1;
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
TEST_CASE("Map Id to location: SparseMemArray") {
|
||||
using index_type = osmium::index::map::SparseMemArray<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
|
||||
index_type index1;
|
||||
|
||||
REQUIRE(0 == index1.size());
|
||||
REQUIRE(0 == index1.used_memory());
|
||||
|
||||
test_func_all<index_type>(index1);
|
||||
|
||||
REQUIRE(2 == index1.size());
|
||||
|
||||
index_type index2;
|
||||
test_func_real<index_type>(index2);
|
||||
}
|
||||
|
||||
TEST_CASE("Map Id to location: Dynamic map choice") {
|
||||
using map_type = osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location>;
|
||||
const auto& map_factory = osmium::index::MapFactory<osmium::unsigned_object_id_type, osmium::Location>::instance();
|
||||
|
||||
const std::vector<std::string> map_type_names = map_factory.map_types();
|
||||
REQUIRE(map_type_names.size() >= 5);
|
||||
|
||||
REQUIRE_THROWS_AS(map_factory.create_map(""), osmium::map_factory_error);
|
||||
REQUIRE_THROWS_AS(map_factory.create_map("does not exist"), osmium::map_factory_error);
|
||||
REQUIRE_THROWS_WITH(map_factory.create_map(""), "Need non-empty map type name");
|
||||
REQUIRE_THROWS_WITH(map_factory.create_map("does not exist"), "Support for map type 'does not exist' not compiled into this binary");
|
||||
|
||||
for (const auto& map_type_name : map_type_names) {
|
||||
std::unique_ptr<map_type> index1 = map_factory.create_map(map_type_name);
|
||||
index1->reserve(1000);
|
||||
test_func_all<map_type>(*index1);
|
||||
|
||||
std::unique_ptr<map_type> index2 = map_factory.create_map(map_type_name);
|
||||
index2->reserve(1000);
|
||||
test_func_real<map_type>(*index2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/io/compression.hpp>
|
||||
|
||||
TEST_CASE("Compression factory") {
|
||||
const auto& factory = osmium::io::CompressionFactory::instance();
|
||||
|
||||
SECTION("compressor") {
|
||||
REQUIRE(factory.create_compressor(osmium::io::file_compression::none, -1, osmium::io::fsync::no));
|
||||
}
|
||||
|
||||
SECTION("decompressor") {
|
||||
REQUIRE(factory.create_decompressor(osmium::io::file_compression::none, nullptr, 0));
|
||||
}
|
||||
|
||||
SECTION("fail on undefined compression") {
|
||||
REQUIRE_THROWS_AS({
|
||||
factory.create_compressor(osmium::io::file_compression::gzip, -1, osmium::io::fsync::no);
|
||||
}, osmium::unsupported_file_format_error);
|
||||
REQUIRE_THROWS_WITH({
|
||||
factory.create_compressor(osmium::io::file_compression::gzip, -1, osmium::io::fsync::no);
|
||||
}, "Support for compression 'gzip' not compiled into this binary");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ public:
|
||||
MockParser(osmium::io::detail::future_string_queue_type& input_queue,
|
||||
osmium::io::detail::future_buffer_queue_type& output_queue,
|
||||
std::promise<osmium::io::Header>& header_promise,
|
||||
osmium::osm_entity_bits::type read_types,
|
||||
osmium::io::detail::reader_options options,
|
||||
const std::string& fail_in) :
|
||||
Parser(input_queue, output_queue, header_promise, read_types),
|
||||
Parser(input_queue, output_queue, header_promise, options),
|
||||
m_fail_in(fail_in) {
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ TEST_CASE("Test Reader using MockParser") {
|
||||
[&](osmium::io::detail::future_string_queue_type& input_queue,
|
||||
osmium::io::detail::future_buffer_queue_type& output_queue,
|
||||
std::promise<osmium::io::Header>& header_promise,
|
||||
osmium::osm_entity_bits::type read_which_entities) {
|
||||
return std::unique_ptr<osmium::io::detail::Parser>(new MockParser(input_queue, output_queue, header_promise, read_which_entities, fail_in));
|
||||
osmium::io::detail::reader_options options) {
|
||||
return std::unique_ptr<osmium::io::detail::Parser>(new MockParser(input_queue, output_queue, header_promise, options, fail_in));
|
||||
});
|
||||
|
||||
SECTION("no failure") {
|
||||
|
||||
+58
-72
@@ -3,7 +3,7 @@
|
||||
#include <osmium/builder/osm_object_builder.hpp>
|
||||
#include <osmium/osm/node.hpp>
|
||||
|
||||
void check_node_1(osmium::Node& node) {
|
||||
void check_node_1(const osmium::Node& node) {
|
||||
REQUIRE(1 == node.id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
@@ -11,9 +11,9 @@ void check_node_1(osmium::Node& node) {
|
||||
REQUIRE(21 == node.uid());
|
||||
REQUIRE(123 == uint32_t(node.timestamp()));
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(std::string("testuser") == node.user());
|
||||
REQUIRE(std::string{"testuser"} == node.user());
|
||||
|
||||
for (osmium::memory::Item& item : node) {
|
||||
for (const osmium::memory::Item& item : node) {
|
||||
REQUIRE(osmium::item_type::tag_list == item.type());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ void check_node_1(osmium::Node& node) {
|
||||
REQUIRE(0 == std::distance(node.tags().begin(), node.tags().end()));
|
||||
}
|
||||
|
||||
void check_node_2(osmium::Node& node) {
|
||||
void check_node_2(const osmium::Node& node) {
|
||||
REQUIRE(2 == node.id());
|
||||
REQUIRE(3 == node.version());
|
||||
REQUIRE(true == node.visible());
|
||||
@@ -30,9 +30,9 @@ void check_node_2(osmium::Node& node) {
|
||||
REQUIRE(21 == node.uid());
|
||||
REQUIRE(123 == uint32_t(node.timestamp()));
|
||||
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
|
||||
REQUIRE(std::string("testuser") == node.user());
|
||||
REQUIRE(std::string{"testuser"} == node.user());
|
||||
|
||||
for (osmium::memory::Item& item : node) {
|
||||
for (const osmium::memory::Item& item : node) {
|
||||
REQUIRE(osmium::item_type::tag_list == item.type());
|
||||
}
|
||||
|
||||
@@ -61,60 +61,52 @@ TEST_CASE("Node in Buffer") {
|
||||
constexpr size_t buffer_size = 10000;
|
||||
unsigned char data[buffer_size];
|
||||
|
||||
osmium::memory::Buffer buffer(data, buffer_size, 0);
|
||||
osmium::memory::Buffer buffer{data, buffer_size, 0};
|
||||
|
||||
SECTION("Add node to buffer") {
|
||||
|
||||
{
|
||||
// add node 1
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
|
||||
node.set_id(1);
|
||||
node.set_version(3);
|
||||
node.set_visible(true);
|
||||
node.set_changeset(333);
|
||||
node.set_uid(21);
|
||||
node.set_timestamp(123);
|
||||
node.set_location(osmium::Location(3.5, 4.7));
|
||||
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
node_builder.set_id(1)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123)
|
||||
.set_location(osmium::Location{3.5, 4.7})
|
||||
.set_user("testuser");
|
||||
}
|
||||
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
// add node 2
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
|
||||
node.set_id(2);
|
||||
node.set_version(3);
|
||||
node.set_visible(true);
|
||||
node.set_changeset(333);
|
||||
node.set_uid(21);
|
||||
node.set_timestamp(123);
|
||||
node.set_location(osmium::Location(3.5, 4.7));
|
||||
node_builder.set_id(2)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123)
|
||||
.set_location(osmium::Location{3.5, 4.7})
|
||||
.set_user("testuser");
|
||||
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
{
|
||||
osmium::builder::TagListBuilder tag_builder(buffer, &node_builder);
|
||||
tag_builder.add_tag("amenity", "bank");
|
||||
tag_builder.add_tag("name", "OSM Savings");
|
||||
}
|
||||
|
||||
buffer.commit();
|
||||
osmium::builder::TagListBuilder tag_builder{node_builder};
|
||||
tag_builder.add_tag("amenity", "bank");
|
||||
tag_builder.add_tag("name", "OSM Savings");
|
||||
}
|
||||
|
||||
buffer.commit();
|
||||
|
||||
REQUIRE(2 == std::distance(buffer.begin(), buffer.end()));
|
||||
int item_no = 0;
|
||||
for (osmium::memory::Item& item : buffer) {
|
||||
for (const osmium::memory::Item& item : buffer) {
|
||||
REQUIRE(osmium::item_type::node == item.type());
|
||||
|
||||
osmium::Node& node = static_cast<osmium::Node&>(item);
|
||||
const osmium::Node& node = static_cast<const osmium::Node&>(item);
|
||||
|
||||
switch (item_no) {
|
||||
case 0:
|
||||
@@ -137,24 +129,21 @@ TEST_CASE("Node in Buffer") {
|
||||
|
||||
{
|
||||
// add node 1
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
|
||||
node.set_id(1);
|
||||
node.set_version(3);
|
||||
node.set_visible(true);
|
||||
node.set_changeset(333);
|
||||
node.set_uid(21);
|
||||
node.set_timestamp(123);
|
||||
node.set_location(osmium::Location(3.5, 4.7));
|
||||
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
node_builder.set_id(1)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123)
|
||||
.set_location(osmium::Location{3.5, 4.7})
|
||||
.set_user("testuser");
|
||||
}
|
||||
|
||||
osmium::memory::Buffer buffer2(buffer_size, osmium::memory::Buffer::auto_grow::yes);
|
||||
buffer.commit();
|
||||
|
||||
osmium::memory::Buffer buffer2{buffer_size, osmium::memory::Buffer::auto_grow::yes};
|
||||
|
||||
buffer2.add_buffer(buffer);
|
||||
buffer2.commit();
|
||||
@@ -169,24 +158,21 @@ TEST_CASE("Node in Buffer") {
|
||||
|
||||
{
|
||||
// add node 1
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
osmium::Node& node = node_builder.object();
|
||||
REQUIRE(osmium::item_type::node == node.type());
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
|
||||
node.set_id(1);
|
||||
node.set_version(3);
|
||||
node.set_visible(true);
|
||||
node.set_changeset(333);
|
||||
node.set_uid(21);
|
||||
node.set_timestamp(123);
|
||||
node.set_location(osmium::Location(3.5, 4.7));
|
||||
|
||||
node_builder.add_user("testuser");
|
||||
|
||||
buffer.commit();
|
||||
node_builder.set_id(1)
|
||||
.set_version(3)
|
||||
.set_visible(true)
|
||||
.set_changeset(333)
|
||||
.set_uid(21)
|
||||
.set_timestamp(123)
|
||||
.set_location(osmium::Location{3.5, 4.7})
|
||||
.set_user("testuser");
|
||||
}
|
||||
|
||||
osmium::memory::Buffer buffer2(buffer_size, osmium::memory::Buffer::auto_grow::yes);
|
||||
buffer.commit();
|
||||
|
||||
osmium::memory::Buffer buffer2{buffer_size, osmium::memory::Buffer::auto_grow::yes};
|
||||
|
||||
std::copy(buffer.begin(), buffer.end(), std::back_inserter(buffer2));
|
||||
|
||||
+35
-47
@@ -17,9 +17,9 @@ struct CallbackClass {
|
||||
TEST_CASE("Purge data from buffer") {
|
||||
|
||||
constexpr size_t buffer_size = 10000;
|
||||
osmium::memory::Buffer buffer{buffer_size};
|
||||
|
||||
SECTION("purge empty buffer") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
|
||||
|
||||
CallbackClass callback;
|
||||
@@ -30,15 +30,13 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with one object but nothing to delete") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
size_t committed = buffer.committed();
|
||||
const size_t committed = buffer.committed();
|
||||
|
||||
CallbackClass callback;
|
||||
buffer.purge_removed(&callback);
|
||||
@@ -49,12 +47,10 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with one object which gets deleted") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
|
||||
@@ -68,21 +64,19 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with two objects, first gets deleted") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
size_t size1 = buffer.committed();
|
||||
const size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
}
|
||||
buffer.commit();
|
||||
size_t size2 = buffer.committed() - size1;
|
||||
const size_t size2 = buffer.committed() - size1;
|
||||
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
|
||||
|
||||
CallbackClass callback;
|
||||
@@ -94,18 +88,16 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with two objects, second gets deleted") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser_longer_name");
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
size_t size1 = buffer.committed();
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
@@ -120,24 +112,22 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with three objects, middle one gets deleted") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser_longer_name");
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("sn");
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
@@ -151,26 +141,24 @@ TEST_CASE("Purge data from buffer") {
|
||||
}
|
||||
|
||||
SECTION("purge buffer with three objects, all get deleted") {
|
||||
osmium::memory::Buffer buffer(buffer_size);
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser_longer_name");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser_longer_name");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("testuser");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("testuser");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
{
|
||||
osmium::builder::NodeBuilder node_builder(buffer);
|
||||
node_builder.add_user("sn");
|
||||
node_builder.object().set_removed(true);
|
||||
osmium::builder::NodeBuilder node_builder{buffer};
|
||||
node_builder.set_user("sn");
|
||||
node_builder.set_removed(true);
|
||||
}
|
||||
buffer.commit();
|
||||
|
||||
Vendored
Vendored
+32
-33
@@ -9,7 +9,7 @@
|
||||
using namespace osmium::builder::attr;
|
||||
|
||||
TEST_CASE("Build changeset") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
osmium::memory::Buffer buffer{10 * 1000};
|
||||
|
||||
osmium::builder::add_changeset(buffer,
|
||||
_cid(42),
|
||||
@@ -88,58 +88,57 @@ TEST_CASE("Build changeset") {
|
||||
}
|
||||
|
||||
TEST_CASE("Create changeset without helper") {
|
||||
osmium::memory::Buffer buffer(10 * 1000);
|
||||
osmium::builder::ChangesetBuilder builder(buffer);
|
||||
|
||||
osmium::Changeset& cs1 = builder.object();
|
||||
cs1.set_id(42)
|
||||
.set_created_at(100)
|
||||
.set_closed_at(200)
|
||||
.set_num_changes(7)
|
||||
.set_num_comments(2)
|
||||
.set_uid(9);
|
||||
|
||||
builder.add_user("user");
|
||||
osmium::memory::Buffer buffer{10 * 1000};
|
||||
{
|
||||
osmium::builder::TagListBuilder tl_builder(buffer, &builder);
|
||||
tl_builder.add_tag("key1", "val1");
|
||||
tl_builder.add_tag("key2", "val2");
|
||||
}
|
||||
osmium::builder::ChangesetBuilder builder{buffer};
|
||||
|
||||
{
|
||||
osmium::builder::ChangesetDiscussionBuilder disc_builder(buffer, &builder);
|
||||
builder.set_id(42)
|
||||
.set_created_at(100)
|
||||
.set_closed_at(200)
|
||||
.set_num_changes(7)
|
||||
.set_num_comments(2)
|
||||
.set_uid(9)
|
||||
.set_user("user");
|
||||
|
||||
{
|
||||
osmium::builder::TagListBuilder tl_builder{builder};
|
||||
tl_builder.add_tag("key1", "val1");
|
||||
tl_builder.add_tag("key2", "val2");
|
||||
}
|
||||
|
||||
osmium::builder::ChangesetDiscussionBuilder disc_builder{builder};
|
||||
disc_builder.add_comment(osmium::Timestamp(300), 10, "user2");
|
||||
disc_builder.add_comment_text("foo");
|
||||
disc_builder.add_comment(osmium::Timestamp(400), 9, "user");
|
||||
disc_builder.add_comment_text("bar");
|
||||
}
|
||||
|
||||
buffer.commit();
|
||||
const auto& cs = buffer.get<osmium::Changeset>(buffer.commit());
|
||||
|
||||
REQUIRE(42 == cs1.id());
|
||||
REQUIRE(9 == cs1.uid());
|
||||
REQUIRE(7 == cs1.num_changes());
|
||||
REQUIRE(2 == cs1.num_comments());
|
||||
REQUIRE(true == cs1.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs1.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs1.closed_at());
|
||||
REQUIRE(2 == cs1.tags().size());
|
||||
REQUIRE(std::string("user") == cs1.user());
|
||||
REQUIRE(42 == cs.id());
|
||||
REQUIRE(9 == cs.uid());
|
||||
REQUIRE(7 == cs.num_changes());
|
||||
REQUIRE(2 == cs.num_comments());
|
||||
REQUIRE(true == cs.closed());
|
||||
REQUIRE(osmium::Timestamp(100) == cs.created_at());
|
||||
REQUIRE(osmium::Timestamp(200) == cs.closed_at());
|
||||
REQUIRE(2 == cs.tags().size());
|
||||
REQUIRE(std::string("user") == cs.user());
|
||||
|
||||
auto cit = cs1.discussion().begin();
|
||||
auto cit = cs.discussion().begin();
|
||||
|
||||
REQUIRE(cit != cs1.discussion().end());
|
||||
REQUIRE(cit != cs.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(300));
|
||||
REQUIRE(cit->uid() == 10);
|
||||
REQUIRE(std::string("user2") == cit->user());
|
||||
REQUIRE(std::string("foo") == cit->text());
|
||||
|
||||
REQUIRE(++cit != cs1.discussion().end());
|
||||
REQUIRE(++cit != cs.discussion().end());
|
||||
REQUIRE(cit->date() == osmium::Timestamp(400));
|
||||
REQUIRE(cit->uid() == 9);
|
||||
REQUIRE(std::string("user") == cit->user());
|
||||
REQUIRE(std::string("bar") == cit->text());
|
||||
|
||||
REQUIRE(++cit == cs1.discussion().end());
|
||||
REQUIRE(++cit == cs.discussion().end());
|
||||
}
|
||||
|
||||
Vendored
@@ -0,0 +1,62 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <osmium/osm/entity_bits.hpp>
|
||||
|
||||
static_assert((osmium::osm_entity_bits::node
|
||||
|osmium::osm_entity_bits::way
|
||||
|osmium::osm_entity_bits::relation)
|
||||
== osmium::osm_entity_bits::nwr, "entity_bits nwr failed");
|
||||
|
||||
static_assert((osmium::osm_entity_bits::node
|
||||
|osmium::osm_entity_bits::way
|
||||
|osmium::osm_entity_bits::relation
|
||||
|osmium::osm_entity_bits::area)
|
||||
== osmium::osm_entity_bits::nwra, "entity_bits nwra failed");
|
||||
|
||||
static_assert((osmium::osm_entity_bits::nwra
|
||||
|osmium::osm_entity_bits::changeset)
|
||||
== osmium::osm_entity_bits::all, "entity_bits all failed");
|
||||
|
||||
static_assert((osmium::osm_entity_bits::all
|
||||
&osmium::osm_entity_bits::node)
|
||||
== osmium::osm_entity_bits::node, "entity_bits node failed");
|
||||
|
||||
static_assert((~osmium::osm_entity_bits::all) == osmium::osm_entity_bits::nothing, "entity_bits nothing is the inverse of all");
|
||||
static_assert((~osmium::osm_entity_bits::nothing) == osmium::osm_entity_bits::all, "entity_bits all is the inverse of nothing");
|
||||
static_assert((~osmium::osm_entity_bits::changeset) == osmium::osm_entity_bits::nwra, "entity_bits nwra is the inverse of changeset");
|
||||
|
||||
TEST_CASE("Bitwise 'and' and 'or' on entity bits") {
|
||||
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
|
||||
REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
|
||||
|
||||
entities |= osmium::osm_entity_bits::relation;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::object));
|
||||
|
||||
entities |= osmium::osm_entity_bits::area;
|
||||
REQUIRE(entities == osmium::osm_entity_bits::object);
|
||||
|
||||
REQUIRE_FALSE((entities & osmium::osm_entity_bits::changeset));
|
||||
|
||||
entities &= osmium::osm_entity_bits::node;
|
||||
REQUIRE((entities & osmium::osm_entity_bits::node));
|
||||
REQUIRE_FALSE((entities & osmium::osm_entity_bits::way));
|
||||
REQUIRE(entities == osmium::osm_entity_bits::node);
|
||||
}
|
||||
|
||||
TEST_CASE("Bitwise 'not' on entity bits") {
|
||||
REQUIRE(~osmium::osm_entity_bits::all == osmium::osm_entity_bits::nothing);
|
||||
REQUIRE(~osmium::osm_entity_bits::nothing == osmium::osm_entity_bits::all);
|
||||
REQUIRE(~osmium::osm_entity_bits::node == (osmium::osm_entity_bits::way | osmium::osm_entity_bits::relation | osmium::osm_entity_bits::area | osmium::osm_entity_bits::changeset));
|
||||
REQUIRE(~osmium::osm_entity_bits::nwr == (osmium::osm_entity_bits::area | osmium::osm_entity_bits::changeset));
|
||||
REQUIRE(~osmium::osm_entity_bits::nwra == osmium::osm_entity_bits::changeset);
|
||||
}
|
||||
|
||||
TEST_CASE("Converting item types to entity bits") {
|
||||
REQUIRE(osmium::osm_entity_bits::nothing == osmium::osm_entity_bits::from_item_type(osmium::item_type::undefined));
|
||||
REQUIRE(osmium::osm_entity_bits::node == osmium::osm_entity_bits::from_item_type(osmium::item_type::node));
|
||||
REQUIRE(osmium::osm_entity_bits::way == osmium::osm_entity_bits::from_item_type(osmium::item_type::way));
|
||||
REQUIRE(osmium::osm_entity_bits::relation == osmium::osm_entity_bits::from_item_type(osmium::item_type::relation));
|
||||
REQUIRE(osmium::osm_entity_bits::changeset == osmium::osm_entity_bits::from_item_type(osmium::item_type::changeset));
|
||||
REQUIRE(osmium::osm_entity_bits::area == osmium::osm_entity_bits::from_item_type(osmium::item_type::area));
|
||||
}
|
||||
|
||||
+73
-44
@@ -166,41 +166,44 @@ TEST_CASE("Location hash") {
|
||||
}
|
||||
}
|
||||
|
||||
#define CR(s, v, r) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
REQUIRE(std::atof(strp) == Approx( v / 10000000.0)); \
|
||||
REQUIRE(std::atof(strm) == Approx(-v / 10000000.0)); \
|
||||
const char** data = &strp; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
data = &strm; \
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == -v); \
|
||||
REQUIRE(std::string{*data} == r); \
|
||||
}
|
||||
void C(const char* s, long v, const char* r = "") {
|
||||
std::string strm{"-"};
|
||||
strm += s;
|
||||
REQUIRE(std::atof(strm.c_str() + 1) == Approx( v / 10000000.0));
|
||||
REQUIRE(std::atof(strm.c_str() ) == Approx(-v / 10000000.0));
|
||||
const char* x = strm.c_str() + 1;
|
||||
const char** data = &x;
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == v);
|
||||
REQUIRE(std::string{*data} == r);
|
||||
x = strm.c_str();
|
||||
data = &x;
|
||||
REQUIRE(osmium::detail::string_to_location_coordinate(data) == -v);
|
||||
REQUIRE(std::string{*data} == r);
|
||||
}
|
||||
|
||||
#define C(s, v) CR(s, v, "")
|
||||
|
||||
#define F(s) { \
|
||||
const char* strm = "-" s; \
|
||||
const char* strp = strm + 1; \
|
||||
const char** data = &strp; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
data = &strm; \
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location); \
|
||||
}
|
||||
void F(const char* s) {
|
||||
std::string strm{"-"};
|
||||
strm += s;
|
||||
const char* x = strm.c_str();
|
||||
const char** data = &x;
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location);
|
||||
++x;
|
||||
data = &x;
|
||||
REQUIRE_THROWS_AS(osmium::detail::string_to_location_coordinate(data), osmium::invalid_location);
|
||||
}
|
||||
|
||||
TEST_CASE("Parsing coordinates from strings") {
|
||||
F("x");
|
||||
F(".");
|
||||
F(".e2");
|
||||
F("--");
|
||||
F("");
|
||||
F(" ");
|
||||
F(" 123");
|
||||
|
||||
CR("123 ", 1230000000, " ");
|
||||
CR("123x", 1230000000, "x");
|
||||
CR("1.2x", 12000000, "x");
|
||||
C("123 ", 1230000000, " ");
|
||||
C("123x", 1230000000, "x");
|
||||
C("1.2x", 12000000, "x");
|
||||
|
||||
C("0", 0);
|
||||
|
||||
@@ -223,14 +226,19 @@ TEST_CASE("Parsing coordinates from strings") {
|
||||
F("1234");
|
||||
F("1234.");
|
||||
F("12345678901234567890");
|
||||
F("1.1234568111111111111111111111111111111");
|
||||
F("112.34568111111111111111111111111111111");
|
||||
|
||||
C("0.", 0);
|
||||
C(".0", 0);
|
||||
C("0.0", 0);
|
||||
C("1.", 10000000);
|
||||
C("1.0", 10000000);
|
||||
C("1.2", 12000000);
|
||||
C("0.1", 1000000);
|
||||
C(".1", 1000000);
|
||||
C("0.01", 100000);
|
||||
C(".01", 100000);
|
||||
C("0.001", 10000);
|
||||
C("0.0001", 1000);
|
||||
C("0.00001", 100);
|
||||
@@ -251,6 +259,24 @@ TEST_CASE("Parsing coordinates from strings") {
|
||||
C("179.99999999", 1800000000);
|
||||
C("200.123", 2001230000);
|
||||
|
||||
C("8.109E-4" , 8109);
|
||||
C("8.1090E-4" , 8109);
|
||||
C("8.10909E-4" , 8109);
|
||||
C("8.109095E-4" , 8109);
|
||||
C("8.1090959E-4" , 8109);
|
||||
C("8.10909598E-4" , 8109);
|
||||
C("8.109095988E-4" , 8109);
|
||||
C("8.1090959887E-4" , 8109);
|
||||
C("8.10909598870E-4" , 8109);
|
||||
C("8.109095988709E-4" , 8109);
|
||||
C("8.1090959887098E-4" , 8109);
|
||||
C("8.10909598870983E-4" , 8109);
|
||||
C("8.109095988709837E-4" , 8109);
|
||||
C("81.09095988709837E-4" , 81091);
|
||||
C("810.9095988709837E-4" , 810910);
|
||||
C(".8109095988709837E-4" , 811);
|
||||
C(".08109095988709837E-4" , 81);
|
||||
|
||||
C("1e2", 1000000000);
|
||||
C("1e1", 100000000);
|
||||
C("1e0", 10000000);
|
||||
@@ -263,8 +289,10 @@ TEST_CASE("Parsing coordinates from strings") {
|
||||
C("1e-7", 1);
|
||||
|
||||
C("1.0e2", 1000000000);
|
||||
C("1.e2", 1000000000);
|
||||
C("1.1e1", 110000000);
|
||||
C("0.1e1", 10000000);
|
||||
C(".1e1", 10000000);
|
||||
C("1.2e0", 12000000);
|
||||
C("1.9e-1", 1900000);
|
||||
C("2.0e-2", 200000);
|
||||
@@ -291,32 +319,35 @@ TEST_CASE("Parsing coordinates from strings") {
|
||||
F("5.0e2");
|
||||
F("3e2");
|
||||
F("1e");
|
||||
F("1e-");
|
||||
F("1e1234567");
|
||||
F("0.5e");
|
||||
F("1e10");
|
||||
|
||||
CR("1e2 ", 1000000000, " ");
|
||||
CR("1.1e2 ", 1100000000, " ");
|
||||
CR("1.1e2x", 1100000000, "x");
|
||||
CR("1.1e2:", 1100000000, ":");
|
||||
C("1e2 ", 1000000000, " ");
|
||||
C("1.1e2 ", 1100000000, " ");
|
||||
C("1.1e2x", 1100000000, "x");
|
||||
C("1.1e2:", 1100000000, ":");
|
||||
}
|
||||
|
||||
#undef C
|
||||
#undef CR
|
||||
#undef F
|
||||
TEST_CASE("Writing zero coordinate into string") {
|
||||
std::string buffer;
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), 0);
|
||||
REQUIRE(buffer == "0");
|
||||
}
|
||||
|
||||
#define CW(v, s) buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), v); \
|
||||
CHECK(buffer == s); \
|
||||
buffer.clear(); \
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), -v); \
|
||||
CHECK(buffer == "-" s);
|
||||
|
||||
TEST_CASE("Writing coordinates into string") {
|
||||
void CW(long v, const char* s) {
|
||||
std::string buffer;
|
||||
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), 0);
|
||||
CHECK(buffer == "0");
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), v);
|
||||
REQUIRE(buffer == s);
|
||||
buffer.clear();
|
||||
osmium::detail::append_location_coordinate_to_string(std::back_inserter(buffer), -v);
|
||||
REQUIRE(buffer[0] == '-');
|
||||
REQUIRE_FALSE(std::strcmp(buffer.c_str() + 1, s));
|
||||
}
|
||||
|
||||
TEST_CASE("Writing coordinate into string") {
|
||||
CW( 10000000, "1");
|
||||
CW( 90000000, "9");
|
||||
CW( 100000000, "10");
|
||||
@@ -338,8 +369,6 @@ TEST_CASE("Writing coordinates into string") {
|
||||
CW(1799999999, "179.9999999");
|
||||
}
|
||||
|
||||
#undef CW
|
||||
|
||||
TEST_CASE("set lon/lat from string") {
|
||||
osmium::Location loc;
|
||||
loc.set_lon("1.2");
|
||||
Vendored
Vendored
+1
-1
@@ -68,7 +68,7 @@ TEST_CASE("build way with helpers") {
|
||||
|
||||
{
|
||||
osmium::builder::WayBuilder builder(buffer);
|
||||
builder.add_user("username");
|
||||
builder.set_user("username");
|
||||
builder.add_tags({
|
||||
{"amenity", "restaurant"},
|
||||
{"name", "Zum goldenen Schwanen"}
|
||||
Reference in New Issue
Block a user