From c0402345f7d40bacccd01000fa095658cf3751b8 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 13 Apr 2015 15:44:38 +0200 Subject: [PATCH] Squashed 'third_party/libosmium/' changes from f074d94..8bcd4ea 8bcd4ea Add explicit cast operator from osmium::Timestamp to uint32_t. 0b24814 Fixed the full_queue_sleep_duration const (again). 5e19dd2 Try different workaround for windows... df5d6c9 Fix build error on Windows. 1553adf Workaround for missing support for u8 string literals on Windows. aa5e44a Do not build benchmarks in Appveyor to speed up build. 2b22b31 Remove warning generated by assert by casting to largest type. 148c5e3 Fix inclusion of our own css file into doxygen documentation. 13bce6f Split out test thats fails on Windows and do not run it on appveyor. ca04757 Make CMake add_unit_test() function more flexible. 6c04a63 Tell CMake to output json file with compile commands. c0dd848 Fix indentation in some tests. dfa7e4b Formatting: Consistently use spaces around equal signs. 08fe6db Add change log, release version 2.1.0. 667192e Add XML tests. 28acfc7 Make sorting the PBF stringtables optional. 8184781 Fix PBFInputFormat. Use member variable instead of static variable. 2b48945 Fix comment. 6d37054 Rename m_done to m_quit_input_thread to clarify what it is for. bc23083 Fix race condition in PBF reader. 7fc380e Add various docs, noexcepts, asserts, and tests. aeaf4d7 Not a good idea to how overbroad patterns in .gitignore. c1ef2f9 Bugfix: Multipolygon collector was accessing non-existent NodeRef. 0ef9a13 Add noexcept and docs to some functions in NodeRefList class. da4d764 Workaround for Doxygen bug. e67d5d9 use absolute paths to osmium in YouCompleteMe configuration 38abeac remove template parameter from NodeRefList c47adf0 Add check that osm xml file has or as top-level element. 5e4af90 Updated version number to 2.0.0. 5b2bc3e Workaround in cmake test for sparsehash size. git-subtree-dir: third_party/libosmium git-subtree-split: 8bcd4ea771696812bbb08ebc58e3ee22d0538070 --- .gitignore | 2 - .ycm_extra_conf.py | 10 +- CHANGELOG.md | 31 ++ CMakeLists.txt | 8 +- appveyor.yml | 5 +- cmake/FindOsmium.cmake | 10 +- doc/Doxyfile.in | 8 +- include/osmium/area/assembler.hpp | 6 +- include/osmium/area/detail/segment_list.hpp | 2 +- .../osmium/area/multipolygon_collector.hpp | 2 +- include/osmium/builder/builder.hpp | 7 +- include/osmium/builder/osm_object_builder.hpp | 14 +- include/osmium/geom/factory.hpp | 2 +- include/osmium/geom/haversine.hpp | 2 +- include/osmium/geom/wkb.hpp | 2 +- include/osmium/handler/dump.hpp | 2 +- .../handler/node_locations_for_ways.hpp | 6 +- include/osmium/index/map.hpp | 3 +- include/osmium/index/map/sparse_mem_table.hpp | 4 +- include/osmium/index/multimap.hpp | 3 +- include/osmium/io/bzip2_compression.hpp | 2 +- include/osmium/io/detail/pbf_input_format.hpp | 53 ++- .../osmium/io/detail/pbf_output_format.hpp | 50 ++- include/osmium/io/detail/pbf_parser.hpp | 24 +- include/osmium/io/detail/pbf_stringtable.hpp | 42 +- include/osmium/io/detail/xml_input_format.hpp | 20 +- .../osmium/io/detail/xml_output_format.hpp | 2 +- include/osmium/io/gzip_compression.hpp | 2 +- include/osmium/io/reader.hpp | 4 +- include/osmium/memory/item.hpp | 5 +- include/osmium/osm/area.hpp | 39 +- include/osmium/osm/box.hpp | 77 +++- include/osmium/osm/changeset.hpp | 3 +- include/osmium/osm/node_ref.hpp | 2 +- include/osmium/osm/node_ref_list.hpp | 91 +++- include/osmium/osm/relation.hpp | 2 +- include/osmium/osm/timestamp.hpp | 4 + include/osmium/osm/way.hpp | 6 +- include/osmium/relations/collector.hpp | 2 +- include/osmium/thread/pool.hpp | 2 +- include/osmium/thread/queue.hpp | 8 +- include/osmium/thread/sorted_queue.hpp | 4 +- include/osmium/util/cast.hpp | 3 +- include/osmium/util/verbose_output.hpp | 2 +- test/CMakeLists.txt | 88 ++-- test/data-tests/testdata-xml.cpp | 98 +++- test/t/area/test_area_id.cpp | 32 +- test/t/area/test_node_ref_segment.cpp | 168 +++---- test/t/basic/test_box.cpp | 128 +++--- test/t/basic/test_entity_bits.cpp | 36 +- test/t/basic/test_location.cpp | 234 +++++----- test/t/basic/test_node_ref.cpp | 82 ++-- test/t/basic/test_object_comparisons.cpp | 266 +++++------ test/t/basic/test_timestamp.cpp | 73 +-- test/t/buffer/test_buffer_node.cpp | 122 ++--- test/t/geom/test_factory_with_projection.cpp | 42 +- test/t/geom/test_mercator.cpp | 50 +-- test/t/index/test_id_to_location.cpp | 158 +++---- test/t/index/test_typed_mmap.cpp | 119 ++--- test/t/index/test_typed_mmap_grow.cpp | 34 ++ test/t/io/test_bzip2.cpp | 30 +- test/t/io/test_file_formats.cpp | 420 +++++++++--------- test/t/tags/test_filter.cpp | 290 ++++++------ test/t/tags/test_operators.cpp | 92 ++-- test/t/tags/test_tag_list.cpp | 110 ++--- test/t/thread/test_pool.cpp | 6 +- test/t/util/test_double.cpp | 40 +- test/t/util/test_options.cpp | 68 +-- test/t/util/test_string.cpp | 70 +-- 69 files changed, 1906 insertions(+), 1528 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 test/t/index/test_typed_mmap_grow.cpp diff --git a/.gitignore b/.gitignore index 36118e129..50139035b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -core *.swp -build* .ycm_extra_conf.pyc diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py index b0f9d3eaf..2b8730616 100644 --- a/.ycm_extra_conf.py +++ b/.ycm_extra_conf.py @@ -6,6 +6,10 @@ # #----------------------------------------------------------------------------- +from os.path import realpath, dirname + +basedir = dirname(realpath(__file__)) + # some default flags # for more information install clang-3.2-doc package and # check UsersManual.html @@ -26,9 +30,9 @@ flags = [ 'c++', # libosmium include dirs -'-Iinclude', -'-Itest/include', -'-Itest/data-test/include', +'-I%s/include' % basedir, +'-I%s/test/include' % basedir, +'-I%s/test/data-test/include' % basedir, # include third party libraries '-I/usr/include/gdal', diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..4c345a498 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,31 @@ + +# Change Log + +All notable changes to this project will be documented in this file. +This project adheres to [Semantic Versioning](http://semver.org/). + +## [unreleased] - + +## [2.1.0] - 2015-03-31 + +### Added + +- When writing PBF files, sorting the PBF stringtables is now optional. +- More tests and documentation. + +### Changed + +- Some functions are now declared `noexcept`. +- XML parser fails now if the top-level element is not `osm` or `osmChange`. + +### Fixed + +- Race condition in PBF reader. +- Multipolygon collector was accessing non-existent NodeRef. +- Doxygen documentation wan't showing all classes/functions due to a bug in + Doxygen (up to version 1.8.8). This version contains a workaround to fix + this. + +[unreleased]: https://github.com/osmcode/libosmium/compare/v2.1.0...HEAD +[2.1.0]: https://github.com/osmcode/libosmium/compare/v2.0.0...v2.1.0 + diff --git a/CMakeLists.txt b/CMakeLists.txt index b48f27166..5e70a9935 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + #----------------------------------------------------------------------------- # @@ -23,9 +25,9 @@ set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel;Dev" project(libosmium) -set(LIBOSMIUM_VERSION_MAJOR 0) -set(LIBOSMIUM_VERSION_MINOR 0) -set(LIBOSMIUM_VERSION_PATCH 1) +set(LIBOSMIUM_VERSION_MAJOR 2) +set(LIBOSMIUM_VERSION_MINOR 1) +set(LIBOSMIUM_VERSION_PATCH 0) set(LIBOSMIUM_VERSION ${LIBOSMIUM_VERSION_MAJOR}.${LIBOSMIUM_VERSION_MINOR}.${LIBOSMIUM_VERSION_PATCH}) diff --git a/appveyor.yml b/appveyor.yml index b3b3f51e4..06c8e6974 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -66,11 +66,12 @@ build_script: - mkdir build - cd build - echo %config% - - cmake .. -LA -G "Visual Studio 14 Win64" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include + - cmake .. -LA -G "Visual Studio 14 Win64" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBUILD_BENCHMARKS=OFF -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include - msbuild libosmium.sln /p:Configuration=%config% /toolsversion:14.0 /p:Platform=x64 /p:PlatformToolset=v140 #- cmake .. -LA -G "NMake Makefiles" -DOsmium_DEBUG=TRUE -DCMAKE_BUILD_TYPE=%config% -DBOOST_ROOT=%LODEPSDIR%\boost -DBoost_PROGRAM_OPTIONS_LIBRARY=%LODEPSDIR%\boost\lib\libboost_program_options-vc140-mt-1_57.lib -DOSMPBF_LIBRARY=%LODEPSDIR%\osmpbf\lib\osmpbf.lib -DOSMPBF_INCLUDE_DIR=%LODEPSDIR%\osmpbf\include -DPROTOBUF_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf.lib -DPROTOBUF_LITE_LIBRARY=%LODEPSDIR%\protobuf\lib\libprotobuf-lite.lib -DPROTOBUF_INCLUDE_DIR=%LODEPSDIR%\protobuf\include -DZLIB_LIBRARY=%LODEPSDIR%\zlib\lib\zlibwapi.lib -DZLIB_INCLUDE_DIR=%LODEPSDIR%\zlib\include -DEXPAT_LIBRARY=%LODEPSDIR%\expat\lib\libexpat.lib -DEXPAT_INCLUDE_DIR=%LODEPSDIR%\expat\include -DBZIP2_LIBRARIES=%LIBBZIP2% -DBZIP2_INCLUDE_DIR=%LODEPSDIR%\bzip2\include -DGDAL_LIBRARY=%LODEPSDIR%\gdal\lib\gdal_i.lib -DGDAL_INCLUDE_DIR=%LODEPSDIR%\gdal\include -DGEOS_LIBRARY=%LODEPSDIR%\geos\lib\geos.lib -DGEOS_INCLUDE_DIR=%LODEPSDIR%\geos\include -DPROJ_LIBRARY=%LODEPSDIR%\proj\lib\proj.lib -DPROJ_INCLUDE_DIR=%LODEPSDIR%\proj\include -DSPARSEHASH_INCLUDE_DIR=%LODEPSDIR%\sparsehash\include -DGETOPT_LIBRARY=%LODEPSDIR%\wingetopt\lib\wingetopt.lib -DGETOPT_INCLUDE_DIR=%LODEPSDIR%\wingetopt\include #- nmake test_script: - - ctest --output-on-failure -C %config% + # -LE fails_on_windows exempts tests we know will fail + - ctest --output-on-failure -C %config% -LE fails_on_windows diff --git a/cmake/FindOsmium.cmake b/cmake/FindOsmium.cmake index 4c3370843..1de41a022 100644 --- a/cmake/FindOsmium.cmake +++ b/cmake/FindOsmium.cmake @@ -226,7 +226,6 @@ if(Osmium_USE_SPARSEHASH) if(SPARSEHASH_INCLUDE_DIR) # Find size of sparsetable::size_type. This does not work on older # CMake versions because they can do this check only in C, not in C++. - # Until we find a better way, we'll live with that. include(CheckTypeSize) set(CMAKE_REQUIRED_INCLUDES ${SPARSEHASH_INCLUDE_DIR}) set(CMAKE_EXTRA_INCLUDE_FILES "google/sparsetable") @@ -234,14 +233,19 @@ if(Osmium_USE_SPARSEHASH) set(CMAKE_EXTRA_INCLUDE_FILES) set(CMAKE_REQUIRED_INCLUDES) + # Falling back to checking size_t if google::sparsetable::size_type + # could not be checked. + if(SPARSETABLE_SIZE_TYPE STREQUAL "") + check_type_size("void*" VOID_PTR_SIZE) + set(SPARSETABLE_SIZE_TYPE ${VOID_PTR_SIZE}) + endif() + # Sparsetable::size_type must be at least 8 bytes (64bit), otherwise # OSM object IDs will not fit. if(SPARSETABLE_SIZE_TYPE GREATER 7) set(SPARSEHASH_FOUND 1) add_definitions(-DOSMIUM_WITH_SPARSEHASH=${SPARSEHASH_FOUND}) list(APPEND OSMIUM_INCLUDE_DIRS ${SPARSEHASH_INCLUDE_DIR}) - elseif(SPARSETABLE_SIZE_TYPE STREQUAL "") - message(WARNING "Osmium: Disabled Google SparseHash library because we can't detect whether we are on a 64bit system.") else() message(WARNING "Osmium: Disabled Google SparseHash library on 32bit system (size_type=${SPARSETABLE_SIZE_TYPE}).") endif() diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 6535259f3..c03e255e9 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -694,7 +694,7 @@ CITE_BIB_FILES = # messages are off. # The default value is: NO. -QUIET = NO +QUIET = YES # The WARNINGS tag can be used to turn on/off the warning messages that are # generated to standard error ( stderr) by doxygen. If WARNINGS is set to YES @@ -860,7 +860,7 @@ IMAGE_PATH = # code is scanned, but not when the output code is generated. If lines are added # or removed, the anchors will not be placed correctly. -INPUT_FILTER = +INPUT_FILTER = "grep -v static_assert" # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. Doxygen will compare the file name with each pattern and apply the @@ -876,7 +876,7 @@ FILTER_PATTERNS = # producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). # The default value is: NO. -FILTER_SOURCE_FILES = NO +FILTER_SOURCE_FILES = YES # The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file # pattern. A pattern will override the setting for FILTER_PATTERN (if any) and @@ -1080,7 +1080,7 @@ HTML_STYLESHEET = # see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = doc/osmium.css +HTML_EXTRA_STYLESHEET = "@PROJECT_SOURCE_DIR@/doc/osmium.css" # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or # other source files which should be copied to the HTML output directory. Note diff --git a/include/osmium/area/assembler.hpp b/include/osmium/area/assembler.hpp index db769ddf8..0a5f12323 100644 --- a/include/osmium/area/assembler.hpp +++ b/include/osmium/area/assembler.hpp @@ -65,7 +65,7 @@ namespace osmium { // Enables debug output to stderr bool debug; - explicit AssemblerConfig(osmium::area::ProblemReporter* pr = nullptr, bool d=false) : + explicit AssemblerConfig(osmium::area::ProblemReporter* pr = nullptr, bool d = false) : problem_reporter(pr), debug(d) { } @@ -74,7 +74,7 @@ namespace osmium { * Enable or disable debug output to stderr. This is for Osmium * developers only. */ - void enable_debug_output(bool d=true) { + void enable_debug_output(bool d = true) { debug = d; } @@ -445,7 +445,7 @@ namespace osmium { } bool add_to_existing_ring(osmium::area::detail::NodeRefSegment segment) { - int n=0; + int n = 0; for (auto& ring : m_rings) { if (debug()) { std::cerr << " check against ring " << n << " " << ring; diff --git a/include/osmium/area/detail/segment_list.hpp b/include/osmium/area/detail/segment_list.hpp index 12ec97fa9..ca6071ede 100644 --- a/include/osmium/area/detail/segment_list.hpp +++ b/include/osmium/area/detail/segment_list.hpp @@ -99,7 +99,7 @@ namespace osmium { * Enable or disable debug output to stderr. This is for Osmium * developers only. */ - void enable_debug_output(bool debug=true) noexcept { + void enable_debug_output(bool debug = true) noexcept { m_debug = debug; } diff --git a/include/osmium/area/multipolygon_collector.hpp b/include/osmium/area/multipolygon_collector.hpp index 0bd10f78b..84a52622b 100644 --- a/include/osmium/area/multipolygon_collector.hpp +++ b/include/osmium/area/multipolygon_collector.hpp @@ -142,7 +142,7 @@ namespace osmium { * Overwritten from the base class. */ void way_not_in_any_relation(const osmium::Way& way) { - if (way.ends_have_same_location() && way.nodes().size() > 3) { + if (way.nodes().size() > 3 && way.ends_have_same_location()) { // way is closed and has enough nodes, build simple multipolygon try { TAssembler assembler(m_assembler_config); diff --git a/include/osmium/builder/builder.hpp b/include/osmium/builder/builder.hpp index bf9cdccfc..dcb95e2ac 100644 --- a/include/osmium/builder/builder.hpp +++ b/include/osmium/builder/builder.hpp @@ -100,7 +100,7 @@ namespace osmium { * parent item (if any). * */ - void add_padding(bool self=false) { + void add_padding(bool self = false) { auto padding = osmium::memory::align_bytes - (size() % osmium::memory::align_bytes); if (padding != osmium::memory::align_bytes) { std::fill_n(m_buffer.reserve_space(padding), padding, 0); @@ -171,12 +171,11 @@ namespace osmium { template class ObjectBuilder : public Builder { - static_assert(std::is_base_of::value, - "ObjectBuilder can only build objects derived from osmium::memory::Item"); + static_assert(std::is_base_of::value, "ObjectBuilder can only build objects derived from osmium::memory::Item"); public: - explicit ObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit ObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : Builder(buffer, parent, sizeof(TItem)) { new (&item()) TItem(); } diff --git a/include/osmium/builder/osm_object_builder.hpp b/include/osmium/builder/osm_object_builder.hpp index b88765e2a..058f89e8e 100644 --- a/include/osmium/builder/osm_object_builder.hpp +++ b/include/osmium/builder/osm_object_builder.hpp @@ -61,7 +61,7 @@ namespace osmium { public: - explicit TagListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit TagListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : ObjectBuilder(buffer, parent) { } @@ -97,7 +97,7 @@ namespace osmium { public: - explicit NodeRefListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit NodeRefListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : ObjectBuilder(buffer, parent) { } @@ -110,7 +110,7 @@ namespace osmium { static_cast(this)->add_size(sizeof(osmium::NodeRef)); } - void add_node_ref(const object_id_type ref, const osmium::Location location=Location()) { + void add_node_ref(const object_id_type ref, const osmium::Location location = Location()) { add_node_ref(NodeRef(ref, location)); } @@ -160,7 +160,7 @@ namespace osmium { public: - explicit RelationMemberListBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit RelationMemberListBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : ObjectBuilder(buffer, parent) { } @@ -215,7 +215,7 @@ namespace osmium { public: - explicit OSMObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit OSMObjectBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : ObjectBuilder(buffer, parent) { static_cast(this)->reserve_space_for(); static_cast(this)->add_size(sizeof(string_size_type)); @@ -237,7 +237,7 @@ namespace osmium { public: - explicit WayBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit WayBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : OSMObjectBuilder(buffer, parent) { } @@ -254,7 +254,7 @@ namespace osmium { public: - explicit AreaBuilder(osmium::memory::Buffer& buffer, Builder* parent=nullptr) : + explicit AreaBuilder(osmium::memory::Buffer& buffer, Builder* parent = nullptr) : OSMObjectBuilder(buffer, parent) { } diff --git a/include/osmium/geom/factory.hpp b/include/osmium/geom/factory.hpp index a0a208075..518cbfbc2 100644 --- a/include/osmium/geom/factory.hpp +++ b/include/osmium/geom/factory.hpp @@ -214,7 +214,7 @@ namespace osmium { return m_impl.linestring_finish(num_points); } - linestring_type create_linestring(const osmium::WayNodeList& wnl, use_nodes un=use_nodes::unique, direction dir=direction::forward) { + linestring_type create_linestring(const osmium::WayNodeList& wnl, use_nodes un = use_nodes::unique, direction dir = direction::forward) { linestring_start(); size_t num_points = 0; diff --git a/include/osmium/geom/haversine.hpp b/include/osmium/geom/haversine.hpp index 14e18c59a..e62a31b03 100644 --- a/include/osmium/geom/haversine.hpp +++ b/include/osmium/geom/haversine.hpp @@ -74,7 +74,7 @@ namespace osmium { * Calculate length of way. */ inline double distance(const osmium::WayNodeList& wnl) { - double sum_length=0; + double sum_length = 0; for (auto it = wnl.begin(); it != wnl.end(); ++it) { if (std::next(it) != wnl.end()) { diff --git a/include/osmium/geom/wkb.hpp b/include/osmium/geom/wkb.hpp index 31fce71f9..2f32fe33b 100644 --- a/include/osmium/geom/wkb.hpp +++ b/include/osmium/geom/wkb.hpp @@ -161,7 +161,7 @@ namespace osmium { typedef std::string multipolygon_type; typedef std::string ring_type; - explicit WKBFactoryImpl(wkb_type wtype=wkb_type::wkb, out_type otype=out_type::binary) : + explicit WKBFactoryImpl(wkb_type wtype = wkb_type::wkb, out_type otype = out_type::binary) : m_wkb_type(wtype), m_out_type(otype) { } diff --git a/include/osmium/handler/dump.hpp b/include/osmium/handler/dump.hpp index 564035c56..a23236e10 100644 --- a/include/osmium/handler/dump.hpp +++ b/include/osmium/handler/dump.hpp @@ -136,7 +136,7 @@ namespace osmium { public: - explicit Dump(std::ostream& out, bool with_size=true, const std::string& prefix="") : + explicit Dump(std::ostream& out, bool with_size = true, const std::string& prefix = "") : m_out(&out), m_with_size(with_size), m_prefix(prefix) { diff --git a/include/osmium/handler/node_locations_for_ways.hpp b/include/osmium/handler/node_locations_for_ways.hpp index d1224a0d5..9b9fcbf3f 100644 --- a/include/osmium/handler/node_locations_for_ways.hpp +++ b/include/osmium/handler/node_locations_for_ways.hpp @@ -63,11 +63,9 @@ namespace osmium { template class NodeLocationsForWays : public osmium::handler::Handler { - static_assert(std::is_base_of, TStoragePosIDs>::value, - "Index class must be derived from osmium::index::map::Map"); + static_assert(std::is_base_of, TStoragePosIDs>::value, "Index class must be derived from osmium::index::map::Map"); - static_assert(std::is_base_of, TStorageNegIDs>::value, - "Index class must be derived from osmium::index::map::Map"); + static_assert(std::is_base_of, TStorageNegIDs>::value, "Index class must be derived from osmium::index::map::Map"); public: diff --git a/include/osmium/index/map.hpp b/include/osmium/index/map.hpp index a9fe0c3bd..7b44b8e33 100644 --- a/include/osmium/index/map.hpp +++ b/include/osmium/index/map.hpp @@ -84,8 +84,7 @@ namespace osmium { template class Map { - static_assert(std::is_integral::value && std::is_unsigned::value, - "TId template parameter for class Map must be unsigned integral type"); + static_assert(std::is_integral::value && std::is_unsigned::value, "TId template parameter for class Map must be unsigned integral type"); Map(const Map&) = delete; Map& operator=(const Map&) = delete; diff --git a/include/osmium/index/map/sparse_mem_table.hpp b/include/osmium/index/map/sparse_mem_table.hpp index 8998a91f5..09ee81bbc 100644 --- a/include/osmium/index/map/sparse_mem_table.hpp +++ b/include/osmium/index/map/sparse_mem_table.hpp @@ -83,7 +83,7 @@ namespace osmium { * The storage will grow by at least this size * every time it runs out of space. */ - explicit SparseMemTable(const TId grow_size=10000) : + explicit SparseMemTable(const TId grow_size = 10000) : m_grow_size(grow_size), m_elements(grow_size) { } @@ -123,7 +123,7 @@ namespace osmium { void dump_as_list(const int fd) override final { std::vector> v; - int n=0; + int n = 0; for (const TValue value : m_elements) { if (value != osmium::index::empty_value()) { v.emplace_back(n, value); diff --git a/include/osmium/index/multimap.hpp b/include/osmium/index/multimap.hpp index e5c6b4f4e..c817b6fb6 100644 --- a/include/osmium/index/multimap.hpp +++ b/include/osmium/index/multimap.hpp @@ -50,8 +50,7 @@ namespace osmium { template class Multimap { - static_assert(std::is_integral::value && std::is_unsigned::value, - "TId template parameter for class Multimap must be unsigned integral type"); + static_assert(std::is_integral::value && std::is_unsigned::value, "TId template parameter for class Multimap must be unsigned integral type"); typedef typename std::pair element_type; diff --git a/include/osmium/io/bzip2_compression.hpp b/include/osmium/io/bzip2_compression.hpp index de1364c69..7e86c1543 100644 --- a/include/osmium/io/bzip2_compression.hpp +++ b/include/osmium/io/bzip2_compression.hpp @@ -82,7 +82,7 @@ namespace osmium { namespace detail { - OSMIUM_NORETURN inline void throw_bzip2_error(BZFILE* bzfile, const char* msg, int bzlib_error=0) { + OSMIUM_NORETURN inline void throw_bzip2_error(BZFILE* bzfile, const char* msg, int bzlib_error = 0) { std::string error("bzip2 error: "); error += msg; error += ": "; diff --git a/include/osmium/io/detail/pbf_input_format.hpp b/include/osmium/io/detail/pbf_input_format.hpp index 8b997ec25..ba8fb42a2 100644 --- a/include/osmium/io/detail/pbf_input_format.hpp +++ b/include/osmium/io/detail/pbf_input_format.hpp @@ -84,8 +84,9 @@ namespace osmium { class PBFInputFormat : public osmium::io::detail::InputFormat { bool m_use_thread_pool; + bool m_eof { false }; queue_type m_queue; - std::atomic m_done; + std::atomic m_quit_input_thread; std::thread m_reader; osmium::thread::Queue& m_input_queue; std::string m_input_buffer; @@ -151,7 +152,7 @@ namespace osmium { void parse_osm_data(osmium::osm_entity_bits::type read_types) { osmium::thread::set_thread_name("_osmium_pbf_in"); - int n=0; + int n = 0; while (auto size = read_blob_header("OSMData")) { if (m_use_thread_pool) { @@ -164,11 +165,20 @@ namespace osmium { } ++n; - if (m_done) { + if (m_quit_input_thread) { return; } } - m_done = true; + + // Send an empty buffer to signal the reader that we are + // done. + std::promise promise; + m_queue.push(promise.get_future()); + promise.set_value(osmium::memory::Buffer{}); + } + + void signal_input_thread_to_quit() { + m_quit_input_thread = true; } public: @@ -184,7 +194,7 @@ namespace osmium { osmium::io::detail::InputFormat(file, read_which_entities), m_use_thread_pool(osmium::config::use_pool_threads_for_pbf_parsing()), m_queue(20, "pbf_parser_results"), // XXX - m_done(false), + m_quit_input_thread(false), m_input_queue(input_queue), m_input_buffer() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -199,30 +209,37 @@ namespace osmium { } ~PBFInputFormat() { - m_done = true; + signal_input_thread_to_quit(); if (m_reader.joinable()) { m_reader.join(); } } /** - * Returns the next buffer with OSM data read from the PBF file. - * Blocks if data is not available yet. + * Returns the next buffer with OSM data read from the PBF + * file. Blocks if data is not available yet. * Returns an empty buffer at end of input. */ osmium::memory::Buffer read() override { - if (!m_done || !m_queue.empty()) { - std::future buffer_future; - m_queue.wait_and_pop(buffer_future); - try { - return buffer_future.get(); - } catch (...) { - m_done = true; - throw; - } + osmium::memory::Buffer buffer; + if (m_eof) { + return buffer; } - return osmium::memory::Buffer(); + std::future buffer_future; + m_queue.wait_and_pop(buffer_future); + + try { + buffer = std::move(buffer_future.get()); + if (!buffer) { + m_eof = true; + } + return buffer; + } catch (...) { + m_eof = true; + signal_input_thread_to_quit(); + throw; + } } }; // class PBFInputFormat diff --git a/include/osmium/io/detail/pbf_output_format.hpp b/include/osmium/io/detail/pbf_output_format.hpp index 73bc61673..288008f6a 100644 --- a/include/osmium/io/detail/pbf_output_format.hpp +++ b/include/osmium/io/detail/pbf_output_format.hpp @@ -294,6 +294,14 @@ namespace osmium { */ bool m_use_compression {true}; + /** + * Should the string tables in the data blocks be sorted? + * + * Not sorting the string tables makes writing PBF files + * slightly faster. + */ + bool m_sort_stringtables { true }; + /** * While the .osm.pbf-format is able to carry all meta information, it is * also able to omit this information to reduce size. @@ -340,6 +348,21 @@ namespace osmium { ///// Blob writing ///// + void delta_encode_string_ids() { + if (pbf_nodes && pbf_nodes->has_dense()) { + OSMPBF::DenseNodes* dense = pbf_nodes->mutable_dense(); + + if (dense->has_denseinfo()) { + OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo(); + + for (int i = 0, l=denseinfo->user_sid_size(); iuser_sid(i); + denseinfo->set_user_sid(i, m_delta_user_sid.update(user_sid)); + } + } + } + } + /** * Before a PrimitiveBlock gets serialized, all interim StringTable-ids needs to be * mapped to the associated real StringTable ids. This is done in this function. @@ -351,7 +374,7 @@ namespace osmium { // test, if the node-block has been allocated if (pbf_nodes) { // iterate over all nodes, passing them to the map_common_string_ids function - for (int i=0, l=pbf_nodes->nodes_size(); inodes_size(); imutable_nodes(i)); } @@ -363,7 +386,7 @@ namespace osmium { // in the densenodes structure keys and vals are encoded in an intermixed // array, individual nodes are seperated by a value of 0 (0 in the StringTable // is always unused). String-ids of 0 are thus kept alone. - for (int i=0, l=dense->keys_vals_size(); ikeys_vals_size(); i 0 to real string ids auto sid = dense->keys_vals(i); if (sid > 0) { @@ -377,7 +400,7 @@ namespace osmium { OSMPBF::DenseInfo* denseinfo = dense->mutable_denseinfo(); // iterate over all username string-ids - for (int i=0, l=denseinfo->user_sid_size(); iuser_sid_size(); i 0 to real string ids auto user_sid = string_table.map_string_id(denseinfo->user_sid(i)); @@ -391,7 +414,7 @@ namespace osmium { // test, if the ways-block has been allocated if (pbf_ways) { // iterate over all ways, passing them to the map_common_string_ids function - for (int i=0, l=pbf_ways->ways_size(); iways_size(); imutable_ways(i)); } } @@ -399,7 +422,7 @@ namespace osmium { // test, if the relations-block has been allocated if (pbf_relations) { // iterate over all relations - for (int i=0, l=pbf_relations->relations_size(); irelations_size(); imutable_relations(i); @@ -408,7 +431,7 @@ namespace osmium { // iterate over all relation members, mapping the interim string-ids // of the role to real string ids - for (int mi=0; mi < relation->roles_sid_size(); ++mi) { + for (int mi = 0; mi < relation->roles_sid_size(); ++mi) { relation->set_roles_sid(mi, string_table.map_string_id(relation->roles_sid(mi))); } } @@ -431,7 +454,7 @@ namespace osmium { } // iterate over all tags and map the interim-ids of the key and the value to real ids - for (int i=0, l=in->keys_size(); ikeys_size(); iset_keys(i, string_table.map_string_id(in->keys(i))); in->set_vals(i, string_table.map_string_id(in->vals(i))); } @@ -518,11 +541,13 @@ namespace osmium { pbf_primitive_block.set_granularity(location_granularity()); pbf_primitive_block.set_date_granularity(date_granularity()); - // store the interim StringTable into the protobuf object - string_table.store_stringtable(pbf_primitive_block.mutable_stringtable()); + string_table.store_stringtable(pbf_primitive_block.mutable_stringtable(), m_sort_stringtables); - // map all interim string ids to real ids - map_string_ids(); + if (m_sort_stringtables) { + map_string_ids(); + } else { + delta_encode_string_ids(); + } std::promise promise; m_output_queue.push(promise.get_future()); @@ -743,6 +768,9 @@ namespace osmium { if (file.get("pbf_compression") == "none" || file.get("pbf_compression") == "false") { m_use_compression = false; } + if (file.get("pbf_sort_stringtables") == "false") { + m_sort_stringtables = false; + } if (file.get("pbf_add_metadata") == "false") { m_should_add_metadata = false; } diff --git a/include/osmium/io/detail/pbf_parser.hpp b/include/osmium/io/detail/pbf_parser.hpp index d99819d3d..65a11e155 100644 --- a/include/osmium/io/detail/pbf_parser.hpp +++ b/include/osmium/io/detail/pbf_parser.hpp @@ -106,7 +106,7 @@ namespace osmium { m_date_factor = pbf_primitive_block.date_granularity() / 1000; m_granularity = pbf_primitive_block.granularity(); - for (int i=0; i < pbf_primitive_block.primitivegroup_size(); ++i) { + for (int i = 0; i < pbf_primitive_block.primitivegroup_size(); ++i) { const OSMPBF::PrimitiveGroup& group = pbf_primitive_block.primitivegroup(i); if (group.has_dense()) { @@ -148,7 +148,7 @@ namespace osmium { } void parse_node_group(const OSMPBF::PrimitiveGroup& group) { - for (int i=0; i < group.nodes_size(); ++i) { + for (int i = 0; i < group.nodes_size(); ++i) { osmium::builder::NodeBuilder builder(m_buffer); const OSMPBF::Node& pbf_node = group.nodes(i); parse_attributes(builder, pbf_node); @@ -161,7 +161,7 @@ namespace osmium { if (pbf_node.keys_size() > 0) { osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); - for (int tag=0; tag < pbf_node.keys_size(); ++tag) { + for (int tag = 0; tag < pbf_node.keys_size(); ++tag) { tl_builder.add_tag(m_stringtable->s(static_cast(pbf_node.keys(tag))), m_stringtable->s(static_cast(pbf_node.vals(tag)))); } @@ -172,7 +172,7 @@ namespace osmium { } void parse_way_group(const OSMPBF::PrimitiveGroup& group) { - for (int i=0; i < group.ways_size(); ++i) { + for (int i = 0; i < group.ways_size(); ++i) { osmium::builder::WayBuilder builder(m_buffer); const OSMPBF::Way& pbf_way = group.ways(i); parse_attributes(builder, pbf_way); @@ -180,7 +180,7 @@ namespace osmium { if (pbf_way.refs_size() > 0) { osmium::builder::WayNodeListBuilder wnl_builder(m_buffer, &builder); int64_t ref = 0; - for (int n=0; n < pbf_way.refs_size(); ++n) { + for (int n = 0; n < pbf_way.refs_size(); ++n) { ref += pbf_way.refs(n); wnl_builder.add_node_ref(ref); } @@ -188,7 +188,7 @@ namespace osmium { if (pbf_way.keys_size() > 0) { osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); - for (int tag=0; tag < pbf_way.keys_size(); ++tag) { + for (int tag = 0; tag < pbf_way.keys_size(); ++tag) { tl_builder.add_tag(m_stringtable->s(static_cast(pbf_way.keys(tag))), m_stringtable->s(static_cast(pbf_way.vals(tag)))); } @@ -199,7 +199,7 @@ namespace osmium { } void parse_relation_group(const OSMPBF::PrimitiveGroup& group) { - for (int i=0; i < group.relations_size(); ++i) { + for (int i = 0; i < group.relations_size(); ++i) { osmium::builder::RelationBuilder builder(m_buffer); const OSMPBF::Relation& pbf_relation = group.relations(i); parse_attributes(builder, pbf_relation); @@ -207,7 +207,7 @@ namespace osmium { if (pbf_relation.types_size() > 0) { osmium::builder::RelationMemberListBuilder rml_builder(m_buffer, &builder); int64_t ref = 0; - for (int n=0; n < pbf_relation.types_size(); ++n) { + for (int n = 0; n < pbf_relation.types_size(); ++n) { ref += pbf_relation.memids(n); rml_builder.add_member(osmpbf_membertype_to_item_type(pbf_relation.types(n)), ref, m_stringtable->s(pbf_relation.roles_sid(n))); } @@ -215,7 +215,7 @@ namespace osmium { if (pbf_relation.keys_size() > 0) { osmium::builder::TagListBuilder tl_builder(m_buffer, &builder); - for (int tag=0; tag < pbf_relation.keys_size(); ++tag) { + for (int tag = 0; tag < pbf_relation.keys_size(); ++tag) { tl_builder.add_tag(m_stringtable->s(static_cast(pbf_relation.keys(tag))), m_stringtable->s(static_cast(pbf_relation.vals(tag)))); } @@ -264,7 +264,7 @@ namespace osmium { const OSMPBF::DenseNodes& dense = group.dense(); - for (int i=0; i < dense.id_size(); ++i) { + for (int i = 0; i < dense.id_size(); ++i) { bool visible = true; last_dense_id += dense.id(i); @@ -361,7 +361,7 @@ namespace osmium { } osmium::io::Header header; - for (int i=0; i < pbf_header_block.required_features_size(); ++i) { + for (int i = 0; i < pbf_header_block.required_features_size(); ++i) { const std::string& feature = pbf_header_block.required_features(i); if (feature == "OsmSchema-V0.6") continue; @@ -377,7 +377,7 @@ namespace osmium { throw osmium::pbf_error(std::string("required feature not supported: ") + feature); } - for (int i=0; i < pbf_header_block.optional_features_size(); ++i) { + for (int i = 0; i < pbf_header_block.optional_features_size(); ++i) { const std::string& feature = pbf_header_block.optional_features(i); header.set("pbf_optional_feature_" + std::to_string(i), feature); } diff --git a/include/osmium/io/detail/pbf_stringtable.hpp b/include/osmium/io/detail/pbf_stringtable.hpp index c56d549de..5f540f127 100644 --- a/include/osmium/io/detail/pbf_stringtable.hpp +++ b/include/osmium/io/detail/pbf_stringtable.hpp @@ -145,30 +145,44 @@ namespace osmium { * implementation) is that the string table is sorted first by reverse count (ie descending) * and then by reverse lexicographic order. */ - void store_stringtable(OSMPBF::StringTable* st) { + void store_stringtable(OSMPBF::StringTable* st, bool sort) { // add empty StringTable entry at index 0 // StringTable index 0 is reserved as delimiter in the densenodes key/value list // this line also ensures that there's always a valid StringTable st->add_s(""); - std::multimap sortedbycount; + if (sort) { + std::multimap sortedbycount; - m_id2id_map.resize(m_size+1); + m_id2id_map.resize(m_size+1); - std::transform(m_strings.begin(), m_strings.end(), - std::inserter(sortedbycount, sortedbycount.begin()), - [](const std::pair& p) { - return std::pair(p.second, p.first); - }); + std::transform(m_strings.begin(), m_strings.end(), + std::inserter(sortedbycount, sortedbycount.begin()), + [](const std::pair& p) { + return std::pair(p.second, p.first); + }); - string_id_type n=0; + string_id_type n = 0; - for (const auto& mapping : sortedbycount) { - // add the string of the current item to the pbf StringTable - st->add_s(mapping.second); + for (const auto& mapping : sortedbycount) { + // add the string of the current item to the pbf StringTable + st->add_s(mapping.second); - // store the mapping from the interim-id to the real id - m_id2id_map[mapping.first.interim_id] = ++n; + // store the mapping from the interim-id to the real id + m_id2id_map[mapping.first.interim_id] = ++n; + } + } else { + std::vector> sortedbyid; + sortedbyid.reserve(m_strings.size()); + + for (const auto& p : m_strings) { + sortedbyid.emplace_back(p.second.interim_id, p.first.c_str()); + } + + std::sort(sortedbyid.begin(), sortedbyid.end()); + for (const auto& mapping : sortedbyid) { + st->add_s(mapping.second); + } } } diff --git a/include/osmium/io/detail/xml_input_format.hpp b/include/osmium/io/detail/xml_input_format.hpp index 96003d874..c03f84d9b 100644 --- a/include/osmium/io/detail/xml_input_format.hpp +++ b/include/osmium/io/detail/xml_input_format.hpp @@ -74,8 +74,8 @@ namespace osmium { /** * Exception thrown when the XML parser failed. The exception contains - * information about the place where the error happened and the type of - * error. + * (if available) information about the place where the error happened + * and the type of error. */ struct xml_error : public io_error { @@ -84,7 +84,7 @@ namespace osmium { XML_Error error_code; std::string error_string; - xml_error(XML_Parser parser) : + explicit xml_error(XML_Parser parser) : io_error(std::string("XML parsing error at line ") + std::to_string(XML_GetCurrentLineNumber(parser)) + ", column " @@ -97,8 +97,20 @@ namespace osmium { error_string(XML_ErrorString(error_code)) { } + explicit xml_error(const std::string& message) : + io_error(message), + line(0), + column(0), + error_code(), + error_string(message) { + } + }; // struct xml_error + /** + * Exception thrown when an OSM XML files contains no version attribute + * on the 'osm' element or if the version is unknown. + */ struct format_version_error : public io_error { std::string version; @@ -434,6 +446,8 @@ namespace osmium { if (m_header.get("version") == "") { throw osmium::format_version_error(); } + } else { + throw osmium::xml_error(std::string("Unknown top-level element: ") + element); } m_context = context::top; break; diff --git a/include/osmium/io/detail/xml_output_format.hpp b/include/osmium/io/detail/xml_output_format.hpp index 73a7263ce..65ba171b8 100644 --- a/include/osmium/io/detail/xml_output_format.hpp +++ b/include/osmium/io/detail/xml_output_format.hpp @@ -130,7 +130,7 @@ namespace osmium { const bool m_write_change_ops; void write_spaces(int num) { - for (; num!=0; --num) { + for (; num != 0; --num) { *m_out += ' '; } } diff --git a/include/osmium/io/gzip_compression.hpp b/include/osmium/io/gzip_compression.hpp index 8bc1e5a50..272397707 100644 --- a/include/osmium/io/gzip_compression.hpp +++ b/include/osmium/io/gzip_compression.hpp @@ -76,7 +76,7 @@ namespace osmium { namespace detail { - OSMIUM_NORETURN inline void throw_gzip_error(gzFile gzfile, const char* msg, int zlib_error=0) { + OSMIUM_NORETURN inline void throw_gzip_error(gzFile gzfile, const char* msg, int zlib_error = 0) { std::string error("gzip error: "); error += msg; error += ": "; diff --git a/include/osmium/io/reader.hpp b/include/osmium/io/reader.hpp index 0bb4f1cb8..c68a8e180 100644 --- a/include/osmium/io/reader.hpp +++ b/include/osmium/io/reader.hpp @@ -109,7 +109,7 @@ namespace osmium { } if (pid == 0) { // child // close all file descriptors except one end of the pipe - for (int i=0; i < 32; ++i) { + for (int i = 0; i < 32; ++i) { if (i != pipefd[1]) { ::close(i); } @@ -260,7 +260,7 @@ namespace osmium { // m_input->read() can return an invalid buffer to signal EOF, // or a valid buffer with or without data. A valid buffer - // without data is not an error, it just means we have to get + // without data is not an error, it just means we have to // keep getting the next buffer until there is one with data. while (true) { osmium::memory::Buffer buffer = m_input->read(); diff --git a/include/osmium/memory/item.hpp b/include/osmium/memory/item.hpp index df15d0133..2679ca6f2 100644 --- a/include/osmium/memory/item.hpp +++ b/include/osmium/memory/item.hpp @@ -55,8 +55,7 @@ namespace osmium { template inline T padded_length(T length) noexcept { - static_assert(std::is_integral::value && std::is_unsigned::value, - "Template parameter must be unsigned integral type"); + static_assert(std::is_integral::value && std::is_unsigned::value, "Template parameter must be unsigned integral type"); return (length + align_bytes - 1) & ~(align_bytes - 1); } @@ -119,7 +118,7 @@ namespace osmium { protected: - explicit Item(item_size_type size=0, item_type type=item_type()) noexcept : + explicit Item(item_size_type size = 0, item_type type = item_type()) noexcept : m_size(size), m_type(type), m_removed(false), diff --git a/include/osmium/osm/area.hpp b/include/osmium/osm/area.hpp index afd127ee6..3e129d0fb 100644 --- a/include/osmium/osm/area.hpp +++ b/include/osmium/osm/area.hpp @@ -53,12 +53,14 @@ namespace osmium { /** * An outer ring of an Area. */ - class OuterRing : public NodeRefList { + class OuterRing : public NodeRefList { public: + static constexpr osmium::item_type itemtype = osmium::item_type::outer_ring; + OuterRing(): - NodeRefList() { + NodeRefList(itemtype) { } }; // class OuterRing @@ -68,12 +70,14 @@ namespace osmium { /** * An inner ring of an Area. */ - class InnerRing : public NodeRefList { + class InnerRing : public NodeRefList { public: + static constexpr osmium::item_type itemtype = osmium::item_type::inner_ring; + InnerRing(): - NodeRefList() { + NodeRefList(itemtype) { } }; // class InnerRing @@ -87,7 +91,7 @@ namespace osmium { * @param type Type of object (way or relation) * @returns Area id */ - inline osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) { + inline osmium::object_id_type object_id_to_area_id(osmium::object_id_type id, osmium::item_type type) noexcept { osmium::object_id_type area_id = std::abs(id) * 2; if (type == osmium::item_type::relation) { ++area_id; @@ -101,7 +105,7 @@ namespace osmium { * @param id Area id * @returns Way or Relation id. */ - inline osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) { + inline osmium::object_id_type area_id_to_object_id(osmium::object_id_type id) noexcept { return id / 2; } @@ -131,15 +135,17 @@ namespace osmium { /** * Return the Id of the way or relation this area was created from. */ - osmium::object_id_type orig_id() const { + osmium::object_id_type orig_id() const noexcept { return osmium::area_id_to_object_id(id()); } /** * Count the number of outer and inner rings of this area. + * + * @returns Pair (number outer rings, number inner rings) */ std::pair num_rings() const { - std::pair counter; + std::pair counter { 0, 0 }; for (auto it = cbegin(); it != cend(); ++it) { switch (it->type()) { @@ -170,16 +176,31 @@ namespace osmium { } /** - * Is this area a multipolygon, ie. has it more than one outer ring? + * Check whether this area is a multipolygon, ie. whether it has more + * than one outer ring? */ bool is_multipolygon() const { return num_rings().first > 1; } + /** + * Get iterator for iterating over all inner rings in a specified outer + * ring. + * + * @param it Iterator specifying outer ring. + * @returns Iterator to first inner ring in specified outer ring. + */ osmium::memory::ItemIterator inner_ring_cbegin(const osmium::memory::ItemIterator& it) const { return it.cast(); } + /** + * Get iterator for iterating over all inner rings in a specified outer + * ring. + * + * @param it Iterator specifying outer ring. + * @returns Iterator one past last inner ring in specified outer ring. + */ osmium::memory::ItemIterator inner_ring_cend(const osmium::memory::ItemIterator& it) const { return std::next(it).cast(); } diff --git a/include/osmium/osm/box.hpp b/include/osmium/osm/box.hpp index 37baf7e33..631f91911 100644 --- a/include/osmium/osm/box.hpp +++ b/include/osmium/osm/box.hpp @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include @@ -41,7 +42,10 @@ DEALINGS IN THE SOFTWARE. namespace osmium { /** - * Bounding box. + * Bounding box. A box is defined by two locations (bottom left location + * and top right location) or, alternatively by four coordinates (minx, + * miny, maxx, and maxy). If both locations are undefined, the box is + * undefined, too. */ class Box { @@ -59,14 +63,33 @@ namespace osmium { m_top_right() { } + /** + * Create box from minimum and maximum coordinates. + * + * @pre @code minx <= maxx && miny <= maxy @endcode + */ Box(double minx, double miny, double maxx, double maxy) : m_bottom_left(minx, miny), m_top_right(maxx, maxy) { + assert(minx <= maxx && miny <= maxy); } + /** + * Create box from bottom left and top right locations. + * + * @pre Either both locations must be defined or neither. + * @pre If both locations are defined, the + * bottom left location must actually be to the left and below + * the top right location. Same coordinates for bottom/top or + * left/right are also okay. + */ Box(const osmium::Location& bottom_left, const osmium::Location& top_right) : m_bottom_left(bottom_left), m_top_right(top_right) { + assert( + (!!bottom_left && !!top_right) || + (bottom_left.x() <= top_right.x() && bottom_left.y() <= top_right.y()) + ); } Box(const Box&) = default; @@ -76,8 +99,13 @@ namespace osmium { ~Box() = default; /** - * Extend this bounding box by the given location. If the - * location is undefined, the bounding box is unchanged. + * Extend this bounding box by the specified location. If the + * location is undefined, the bounding box is unchanged. If + * the box is undefined it will only contain the location after + * this call. + * + * @param location The location we want to extend the box by. + * @returns A reference to this box. */ Box& extend(const Location& location) noexcept { if (location) { @@ -103,8 +131,11 @@ namespace osmium { } /** - * Extend this bounding box by the given box. If the - * box is undefined, the bounding box is unchanged. + * Extend this bounding box by the specified box. If the + * specified box is undefined, the bounding box is unchanged. + * + * @param box The box to extend by. + * @returns A reference to this box. */ Box& extend(const Box& box) noexcept { extend(box.bottom_left()); @@ -113,14 +144,14 @@ namespace osmium { } /** - * Box are defined, ie. contains defined coordinates. + * Box is defined, ie. contains defined locations. */ explicit constexpr operator bool() const noexcept { return static_cast(m_bottom_left); } /** - * Box are valid, ie. defined and inside usual bounds + * Box is valid, ie. defined and inside usual bounds * (-180<=lon<=180, -90<=lat<=90). */ OSMIUM_CONSTEXPR bool valid() const noexcept { @@ -128,37 +159,43 @@ namespace osmium { } /** - * Bottom-left location. + * Access bottom-left location. */ OSMIUM_CONSTEXPR Location bottom_left() const noexcept { return m_bottom_left; } /** - * Bottom-left location. + * Access bottom-left location. */ Location& bottom_left() noexcept { return m_bottom_left; } /** - * Top-right location. + * Access top-right location. */ OSMIUM_CONSTEXPR Location top_right() const noexcept { return m_top_right; } /** - * Top-right location. + * Access top-right location. */ Location& top_right() noexcept { return m_top_right; } /** - * Is the location inside the box? + * Check whether the location is inside the box. + * + * @pre Location must be defined. + * @pre Box must be defined. */ - bool contains(const osmium::Location& location) const { + bool contains(const osmium::Location& location) const noexcept { + assert(bottom_left()); + assert(top_right()); + assert(location); return location.x() >= bottom_left().x() && location.y() >= bottom_left().y() && location.x() <= top_right().x() && location.y() <= top_right().y(); } @@ -166,7 +203,7 @@ namespace osmium { /** * Calculate size of the box in square degrees. * - * @throws osmium::invalid_location unless all coordinates are valid + * @throws osmium::invalid_location unless all coordinates are valid. */ double size() const { return (m_top_right.lon() - m_bottom_left.lon()) * @@ -176,14 +213,19 @@ namespace osmium { }; // class Box /** - * Boxes are equal if both locations are equal. + * Boxes are equal if both locations are equal. Undefined boxes will + * compare equal. */ inline OSMIUM_CONSTEXPR bool operator==(const Box& lhs, const Box& rhs) noexcept { - return lhs.bottom_left() == rhs.bottom_left() && lhs.top_right() == rhs.top_right(); + return lhs.bottom_left() == rhs.bottom_left() && + lhs.top_right() == rhs.top_right(); } /** - * Output a box to a stream. + * Output a box to a stream. The format is "(LON, LAT, LON, LAT)" or + * "(undefined)" if the box is undefined. + * + * @returns Reference to basic_ostream given as first parameter. */ template inline std::basic_ostream& operator<<(std::basic_ostream& out, const osmium::Box& box) { @@ -202,6 +244,7 @@ namespace osmium { } return out; } + } // namespace osmium #endif // OSMIUM_OSM_BOX_HPP diff --git a/include/osmium/osm/changeset.hpp b/include/osmium/osm/changeset.hpp index cc1c52d4a..0ab4e9bad 100644 --- a/include/osmium/osm/changeset.hpp +++ b/include/osmium/osm/changeset.hpp @@ -298,8 +298,7 @@ namespace osmium { }; // class Changeset - static_assert(sizeof(Changeset) % osmium::memory::align_bytes == 0, - "Class osmium::Changeset has wrong size to be aligned properly!"); + static_assert(sizeof(Changeset) % osmium::memory::align_bytes == 0, "Class osmium::Changeset has wrong size to be aligned properly!"); /** * Changesets are equal if their IDs are equal. diff --git a/include/osmium/osm/node_ref.hpp b/include/osmium/osm/node_ref.hpp index 1a66607a1..76afa75fc 100644 --- a/include/osmium/osm/node_ref.hpp +++ b/include/osmium/osm/node_ref.hpp @@ -54,7 +54,7 @@ namespace osmium { public: - NodeRef(const osmium::object_id_type ref=0, const osmium::Location& location=Location()) noexcept : + NodeRef(const osmium::object_id_type ref = 0, const osmium::Location& location = Location()) noexcept : m_ref(ref), m_location(location) { } diff --git a/include/osmium/osm/node_ref_list.hpp b/include/osmium/osm/node_ref_list.hpp index f45bf6b59..f0dfedbc1 100644 --- a/include/osmium/osm/node_ref_list.hpp +++ b/include/osmium/osm/node_ref_list.hpp @@ -44,51 +44,92 @@ DEALINGS IN THE SOFTWARE. namespace osmium { /** - * A vector of NodeRef objects. Usually this is not instatiated directly, + * A vector of NodeRef objects. Usually this is not instantiated directly, * but one of its subclasses are used. */ - template class NodeRefList : public osmium::memory::Item { public: - static constexpr osmium::item_type itemtype = TItemType; - - NodeRefList() noexcept : - osmium::memory::Item(sizeof(NodeRefList), TItemType) { + NodeRefList(osmium::item_type itemtype) noexcept : + osmium::memory::Item(sizeof(NodeRefList), itemtype) { } + /** + * Checks whether the node list is empty. + */ bool empty() const noexcept { return sizeof(NodeRefList) == byte_size(); } + /** + * Returns the number of nodes in the list. + */ size_t size() const noexcept { - assert((osmium::memory::Item::byte_size() - sizeof(NodeRefList)) % sizeof(NodeRef) == 0); - return (osmium::memory::Item::byte_size() - sizeof(NodeRefList)) / sizeof(NodeRef); + auto size_node_refs = osmium::memory::Item::byte_size() - sizeof(NodeRefList); + assert(size_node_refs % sizeof(NodeRef) == 0); + return size_node_refs / sizeof(NodeRef); } - const NodeRef& operator[](size_t n) const { + /** + * Access specified element. + * + * @param n Get this element of the list. + * @pre @code n < size() @endcode + */ + const NodeRef& operator[](size_t n) const noexcept { + assert(n < size()); const NodeRef* node_ref = &*(cbegin()); return node_ref[n]; } - const NodeRef& front() const { + /** + * Access the first element. + * + * @pre @code !empty() @endcode + */ + const NodeRef& front() const noexcept { + assert(!empty()); return operator[](0); } - const NodeRef& back() const { + /** + * Access the last element. + * + * @pre @code !empty() @endcode + */ + const NodeRef& back() const noexcept { + assert(!empty()); return operator[](size()-1); } - bool is_closed() const { + /** + * Checks whether the first and last node in the list have the same ID. + * + * @pre @code !empty() @endcode + */ + bool is_closed() const noexcept { return front().ref() == back().ref(); } - bool ends_have_same_id() const { + /** + * Checks whether the first and last node in the list have the same ID. + * + * @pre @code !empty() @endcode + */ + bool ends_have_same_id() const noexcept { return front().ref() == back().ref(); } + /** + * Checks whether the first and last node in the list have the same + * location. The ID is not checked. + * + * @pre @code !empty() @endcode + * @pre @code front().location() && back().location() @endcode + */ bool ends_have_same_location() const { + assert(front().location() && back().location()); return front().location() == back().location(); } @@ -96,35 +137,43 @@ namespace osmium { typedef const NodeRef* const_iterator; typedef std::reverse_iterator const_reverse_iterator; - iterator begin() { + /// Returns an iterator to the beginning. + iterator begin() noexcept { return iterator(data() + sizeof(NodeRefList)); } - iterator end() { + /// Returns an iterator to the end. + iterator end() noexcept { return iterator(data() + byte_size()); } - const_iterator cbegin() const { + /// Returns an iterator to the beginning. + const_iterator cbegin() const noexcept { return const_iterator(data() + sizeof(NodeRefList)); } - const_iterator cend() const { + /// Returns an iterator to the end. + const_iterator cend() const noexcept { return const_iterator(data() + byte_size()); } - const_iterator begin() const { + /// Returns an iterator to the beginning. + const_iterator begin() const noexcept { return cbegin(); } - const_iterator end() const { + /// Returns an iterator to the end. + const_iterator end() const noexcept { return cend(); } - const_reverse_iterator crbegin() const { + /// Returns a reverse_iterator to the beginning. + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); } - const_reverse_iterator crend() const { + /// Returns a reverse_iterator to the end. + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); } diff --git a/include/osmium/osm/relation.hpp b/include/osmium/osm/relation.hpp index 6c0381539..e5b42fed5 100644 --- a/include/osmium/osm/relation.hpp +++ b/include/osmium/osm/relation.hpp @@ -101,7 +101,7 @@ namespace osmium { static constexpr item_type collection_type = item_type::relation_member_list; - RelationMember(const object_id_type ref=0, const item_type type=item_type(), const bool full=false) noexcept : + RelationMember(const object_id_type ref = 0, const item_type type = item_type(), const bool full = false) noexcept : m_ref(ref), m_type(type), m_flags(full ? 1 : 0) { diff --git a/include/osmium/osm/timestamp.hpp b/include/osmium/osm/timestamp.hpp index f36ea36a1..6b6a6e189 100644 --- a/include/osmium/osm/timestamp.hpp +++ b/include/osmium/osm/timestamp.hpp @@ -113,6 +113,10 @@ namespace osmium { return static_cast(m_timestamp); } + explicit constexpr operator uint32_t() const noexcept { + return m_timestamp; + } + template void operator+=(T time_difference) noexcept { m_timestamp += time_difference; diff --git a/include/osmium/osm/way.hpp b/include/osmium/osm/way.hpp index 6d3e2dea0..3c5f1f6dc 100644 --- a/include/osmium/osm/way.hpp +++ b/include/osmium/osm/way.hpp @@ -49,12 +49,14 @@ namespace osmium { /** * List of node references (id and location) in a way. */ - class WayNodeList : public NodeRefList { + class WayNodeList : public NodeRefList { public: + static constexpr osmium::item_type itemtype = osmium::item_type::way_node_list; + WayNodeList(): - NodeRefList() { + NodeRefList(itemtype) { } }; // class WayNodeList diff --git a/include/osmium/relations/collector.hpp b/include/osmium/relations/collector.hpp index d4af916b7..e3c498087 100644 --- a/include/osmium/relations/collector.hpp +++ b/include/osmium/relations/collector.hpp @@ -389,7 +389,7 @@ namespace osmium { RelationMeta relation_meta(offset); - int n=0; + int n = 0; for (auto& member : m_relations_buffer.get(offset).members()) { if (static_cast(this)->keep_member(relation_meta, member)) { member_meta(member.type()).emplace_back(member.ref(), m_relations.size(), n); diff --git a/include/osmium/thread/pool.hpp b/include/osmium/thread/pool.hpp index bc1e9a82b..87dd1fb93 100644 --- a/include/osmium/thread/pool.hpp +++ b/include/osmium/thread/pool.hpp @@ -128,7 +128,7 @@ namespace osmium { } try { - for (int i=0; i < m_num_threads; ++i) { + for (int i = 0; i < m_num_threads; ++i) { m_threads.push_back(std::thread(&Pool::worker_thread, this)); } } catch (...) { diff --git a/include/osmium/thread/queue.hpp b/include/osmium/thread/queue.hpp index 12e593274..baaf2dc76 100644 --- a/include/osmium/thread/queue.hpp +++ b/include/osmium/thread/queue.hpp @@ -49,7 +49,7 @@ namespace osmium { namespace thread { - OSMIUM_CONSTEXPR std::chrono::milliseconds full_queue_sleep_duration { 10 }; // XXX + static const std::chrono::milliseconds full_queue_sleep_duration { 10 }; // XXX /** * A thread-safe queue. @@ -137,7 +137,7 @@ namespace osmium { m_data_available.wait(lock, [this] { return !m_queue.empty(); }); - value=std::move(m_queue.front()); + value = std::move(m_queue.front()); m_queue.pop(); } @@ -148,7 +148,7 @@ namespace osmium { })) { return; } - value=std::move(m_queue.front()); + value = std::move(m_queue.front()); m_queue.pop(); } @@ -157,7 +157,7 @@ namespace osmium { if (m_queue.empty()) { return false; } - value=std::move(m_queue.front()); + value = std::move(m_queue.front()); m_queue.pop(); return true; } diff --git a/include/osmium/thread/sorted_queue.hpp b/include/osmium/thread/sorted_queue.hpp index e0181eb61..e76ade101 100644 --- a/include/osmium/thread/sorted_queue.hpp +++ b/include/osmium/thread/sorted_queue.hpp @@ -107,7 +107,7 @@ namespace osmium { m_data_available.wait(lock, [this] { return !empty_intern(); }); - value=std::move(m_queue.front()); + value = std::move(m_queue.front()); m_queue.pop_front(); ++m_offset; } @@ -122,7 +122,7 @@ namespace osmium { if (empty_intern()) { return false; } - value=std::move(m_queue.front()); + value = std::move(m_queue.front()); m_queue.pop_front(); ++m_offset; return true; diff --git a/include/osmium/util/cast.hpp b/include/osmium/util/cast.hpp index 80adadf80..4866fdec4 100644 --- a/include/osmium/util/cast.hpp +++ b/include/osmium/util/cast.hpp @@ -37,6 +37,7 @@ DEALINGS IN THE SOFTWARE. # include #endif +#include #include #include @@ -93,7 +94,7 @@ namespace osmium { template ::value && !std::is_same::value && (sizeof(T) <= sizeof(F)) && std::is_signed::value && std::is_unsigned::value, int>::type = 0> inline T static_cast_with_assert(const F value) { - assert(value <= std::numeric_limits::max()); + assert(static_cast(value) <= static_cast(std::numeric_limits::max())); return static_cast(value); } diff --git a/include/osmium/util/verbose_output.hpp b/include/osmium/util/verbose_output.hpp index 178781e23..249d67fbf 100644 --- a/include/osmium/util/verbose_output.hpp +++ b/include/osmium/util/verbose_output.hpp @@ -87,7 +87,7 @@ namespace osmium { public: - explicit VerboseOutput(bool verbose=false) noexcept : + explicit VerboseOutput(bool verbose = false) noexcept : m_start(time(NULL)), m_verbose(verbose), m_newline(true) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 334fe3130..7ba455b02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,6 +8,7 @@ message(STATUS "Configuring unit tests") +include(CMakeParseArguments) include_directories(include) add_library(testlib STATIC test_main.cpp) @@ -19,40 +20,62 @@ set(ALL_TESTS "") # # Define function for adding tests # -# Call with parameters: -# TGROUP - test group (directory) -# TNAME - name of test -# ARGV2 - flag to enable test (optional) -# ARGV3 - libraries to add (optional) +# add_unit_tests(group name [ENABLE_IF bool] [LIBS libs] [LABELS labels]) +# +# group - test group (directory) +# name - name of test +# bool - boolean variable telling whether the test should be run (optional) +# libs - lib or libs that should be used when compiling test (optional) +# labels - additional labels this test should get (optional) # #----------------------------------------------------------------------------- -function(add_unit_test TGROUP TNAME) - set(ALL_TESTS "${ALL_TESTS};${TGROUP}/${TNAME}" PARENT_SCOPE) - if((${ARGC} EQUAL 2) OR (${ARGV2})) +function(add_unit_test _tgroup _tname) + set(_testid "${_tgroup}_${_tname}") + set(_tpath "${_tgroup}/${_tname}") + + set(ALL_TESTS "${ALL_TESTS};${_tpath}" PARENT_SCOPE) + + cmake_parse_arguments(_param "" "ENABLE_IF" "LIBS;LABELS" ${ARGN}) + + if(Osmium_DEBUG) + message("${_testid} ENABLE_IF=[${_param_ENABLE_IF}] LIBS=[${_param_LIBS}] LABELS=[${_param_LABELS}]") + endif() + + if((NOT(DEFINED _param_ENABLE_IF)) OR (_param_ENABLE_IF)) if(Osmium_DEBUG) - message("Adding test ${TGROUP}/${TNAME}") + message("Adding test: ${_tpath}") endif() - set(TESTNAME "${TGROUP}_${TNAME}") - add_executable(${TESTNAME} t/${TGROUP}/${TNAME}.cpp) - target_link_libraries(${TESTNAME} testlib) - if((${ARGV2}) AND (DEFINED ARGV3)) + add_executable(${_testid} t/${_tpath}.cpp) + target_link_libraries(${_testid} testlib) + + if(DEFINED _param_LIBS) if(Osmium_DEBUG) - message(" Adding libs ${ARGV3}") + message(" Adding libs: ${_param_LIBS}") endif() - target_link_libraries(${TESTNAME} ${ARGV3}) + target_link_libraries(${_testid} ${_param_LIBS}) endif() - add_test(NAME ${TESTNAME} + + add_test(NAME ${_testid} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND ${TESTNAME} + COMMAND ${_testid} ) - set_tests_properties(${TESTNAME} PROPERTIES - LABELS "unit;fast;${TGROUP}" + + set(_labels "unit;fast;${_tgroup}") + if(DEFINED _param_LABELS) + if(Osmium_DEBUG) + message(" Adding labels: ${_param_LABELS}") + endif() + set(_labels "${_labels};${_param_LABELS}") + endif() + + set_tests_properties(${_testid} PROPERTIES + LABELS "${_labels}" ENVIRONMENT "OSMIUM_TEST_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}" ) else() - message("Skipped test ${TGROUP}/${TNAME} because a dependency was not found") + message("Skipped test ${_tpath} because a dependency was not found") set(OSMIUM_SKIPPED_TESTS - "${OSMIUM_SKIPPED_TESTS} ${TGROUP}/${TNAME}" + "${OSMIUM_SKIPPED_TESTS} ${_tpath}" CACHE STRING "Tests that were skipped because of missing dependecies") endif() endfunction() @@ -85,31 +108,32 @@ else() set(GEOS_AND_PROJ_FOUND FALSE) endif() add_unit_test(geom test_factory_with_projection - ${GEOS_AND_PROJ_FOUND} - "${GEOS_LIBRARY};${PROJ_LIBRARY}") + ENABLE_IF ${GEOS_AND_PROJ_FOUND} + LIBS ${GEOS_LIBRARY} ${PROJ_LIBRARY}) add_unit_test(geom test_geojson) -add_unit_test(geom test_geos ${GEOS_FOUND} ${GEOS_LIBRARY}) -add_unit_test(geom test_geos_wkb ${GEOS_FOUND} ${GEOS_LIBRARY}) +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 ${GDAL_FOUND} ${GDAL_LIBRARY}) -add_unit_test(geom test_projection ${PROJ_FOUND} ${PROJ_LIBRARY}) +add_unit_test(geom test_ogr ENABLE_IF ${GDAL_FOUND} LIBS ${GDAL_LIBRARY}) +add_unit_test(geom test_projection ENABLE_IF ${PROJ_FOUND} LIBS ${PROJ_LIBRARY}) add_unit_test(geom test_wkb) add_unit_test(geom test_wkt) -add_unit_test(index test_id_to_location ${SPARSEHASH_FOUND}) +add_unit_test(index test_id_to_location ENABLE_IF ${SPARSEHASH_FOUND}) add_unit_test(index test_typed_mmap) +add_unit_test(index test_typed_mmap_grow LABELS "fails_on_windows") -add_unit_test(io test_bzip2 ${BZIP2_FOUND} ${BZIP2_LIBRARIES}) +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 TRUE "${OSMIUM_XML_LIBRARIES}") -add_unit_test(io test_output_iterator ${Threads_FOUND} ${CMAKE_THREAD_LIBS_INIT}) +add_unit_test(io test_reader LIBS "${OSMIUM_XML_LIBRARIES}") +add_unit_test(io test_output_iterator ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT}) add_unit_test(tags test_filter) add_unit_test(tags test_operators) add_unit_test(tags test_tag_list) -add_unit_test(thread test_pool ${Threads_FOUND} ${CMAKE_THREAD_LIBS_INIT}) +add_unit_test(thread test_pool ENABLE_IF ${Threads_FOUND} LIBS ${CMAKE_THREAD_LIBS_INIT}) add_unit_test(util test_cast_with_assert) add_unit_test(util test_double) diff --git a/test/data-tests/testdata-xml.cpp b/test/data-tests/testdata-xml.cpp index 94af6f961..5af4c4f27 100644 --- a/test/data-tests/testdata-xml.cpp +++ b/test/data-tests/testdata-xml.cpp @@ -285,7 +285,6 @@ TEST_CASE("Reading OSM XML 121") { }, osmium::gzip_error); } -#if 0 SECTION("Using Reader") { REQUIRE_THROWS_AS({ osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz")); @@ -294,10 +293,105 @@ TEST_CASE("Reading OSM XML 121") { reader.close(); }, osmium::gzip_error); } -#endif } +// ============================================= + +TEST_CASE("Reading OSM XML 122") { + + SECTION("Direct") { + REQUIRE_THROWS_AS( { + read_xml("122-no_osm_element"); + }, osmium::xml_error); + } + + SECTION("Using Reader") { + REQUIRE_THROWS_AS({ + osmium::io::Reader reader(filename("122-no_osm_element")); + osmium::io::Header header = reader.header(); + osmium::memory::Buffer buffer = reader.read(); + reader.close(); + }, osmium::xml_error); + } + +} + +// ============================================= + +TEST_CASE("Reading OSM XML 140") { + + SECTION("Using Reader") { + osmium::io::Reader reader(filename("140-unicode")); + osmium::memory::Buffer buffer = reader.read(); + reader.close(); + + int count = 0; + for (auto it = buffer.begin(); it != buffer.end(); ++it) { + ++count; + REQUIRE(it->id() == count); + const osmium::TagList& t = it->tags(); + + const char* uc = t["unicode_char"]; + + auto len = atoi(t["unicode_utf8_length"]); + REQUIRE(len == strlen(uc)); + + REQUIRE(!strcmp(uc, t["unicode_xml"])); + +// workaround for missing support for u8 string literals on Windows +#if !defined(_MSC_VER) + switch (count) { + case 1: + REQUIRE(!strcmp(uc, u8"a")); + break; + case 2: + REQUIRE(!strcmp(uc, u8"\u00e4")); + break; + case 3: + REQUIRE(!strcmp(uc, u8"\u30dc")); + break; + case 4: + REQUIRE(!strcmp(uc, u8"\U0001d11e")); + break; + case 5: + REQUIRE(!strcmp(uc, u8"\U0001f6eb")); + break; + default: + REQUIRE(false); // should not be here + } +#endif + } + REQUIRE(count == 5); + } + +} + + +// ============================================= + +TEST_CASE("Reading OSM XML 141") { + + SECTION("Using Reader") { + osmium::io::Reader reader(filename("141-entities")); + osmium::memory::Buffer buffer = reader.read(); + reader.close(); + REQUIRE(buffer.committed() > 0); + REQUIRE(buffer.get(0).type() == osmium::item_type::node); + + const osmium::Node& node = buffer.get(0); + const osmium::TagList& tags = node.tags(); + + REQUIRE(!strcmp(tags["less-than"], "<")); + REQUIRE(!strcmp(tags["greater-than"], ">")); + REQUIRE(!strcmp(tags["apostrophe"], "'")); + REQUIRE(!strcmp(tags["ampersand"], "&")); + REQUIRE(!strcmp(tags["quote"], "\"")); + } + +} + + // ============================================= TEST_CASE("Reading OSM XML 200") { diff --git a/test/t/area/test_area_id.cpp b/test/t/area/test_area_id.cpp index 45bf87cbe..fbd8d784c 100644 --- a/test/t/area/test_area_id.cpp +++ b/test/t/area/test_area_id.cpp @@ -4,22 +4,22 @@ TEST_CASE("area_id") { -SECTION("object_id_to_area_id_conversion") { - REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way)); - REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation)); - REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way)); - REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation)); - REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way)); - REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation)); -} + SECTION("object_id_to_area_id_conversion") { + REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way)); + REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation)); + REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way)); + REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation)); + REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way)); + REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation)); + } -SECTION("area_id_to_object_id_conversion") { - REQUIRE( 23 == osmium::area_id_to_object_id( 46)); - REQUIRE( 23 == osmium::area_id_to_object_id( 47)); - REQUIRE( 0 == osmium::area_id_to_object_id( 0)); - REQUIRE( 0 == osmium::area_id_to_object_id( 1)); - REQUIRE(-12 == osmium::area_id_to_object_id(-24)); - REQUIRE(-12 == osmium::area_id_to_object_id(-25)); -} + SECTION("area_id_to_object_id_conversion") { + REQUIRE( 23 == osmium::area_id_to_object_id( 46)); + REQUIRE( 23 == osmium::area_id_to_object_id( 47)); + REQUIRE( 0 == osmium::area_id_to_object_id( 0)); + REQUIRE( 0 == osmium::area_id_to_object_id( 1)); + REQUIRE(-12 == osmium::area_id_to_object_id(-24)); + REQUIRE(-12 == osmium::area_id_to_object_id(-25)); + } } diff --git a/test/t/area/test_node_ref_segment.cpp b/test/t/area/test_node_ref_segment.cpp index fd67e6c49..309768744 100644 --- a/test/t/area/test_node_ref_segment.cpp +++ b/test/t/area/test_node_ref_segment.cpp @@ -6,110 +6,110 @@ using osmium::area::detail::NodeRefSegment; TEST_CASE("NodeRefSegmentClass") { -SECTION("instantiation_with_default_parameters") { - NodeRefSegment s; - REQUIRE(s.first().ref() == 0); - REQUIRE(s.first().location() == osmium::Location()); - REQUIRE(s.second().ref() == 0); - REQUIRE(s.second().location() == osmium::Location()); -} + SECTION("instantiation_with_default_parameters") { + NodeRefSegment s; + REQUIRE(s.first().ref() == 0); + REQUIRE(s.first().location() == osmium::Location()); + REQUIRE(s.second().ref() == 0); + REQUIRE(s.second().location() == osmium::Location()); + } -SECTION("instantiation") { - osmium::NodeRef nr1(1, { 1.2, 3.4 }); - osmium::NodeRef nr2(2, { 1.4, 3.1 }); - osmium::NodeRef nr3(3, { 1.2, 3.6 }); - osmium::NodeRef nr4(4, { 1.2, 3.7 }); + SECTION("instantiation") { + osmium::NodeRef nr1(1, { 1.2, 3.4 }); + osmium::NodeRef nr2(2, { 1.4, 3.1 }); + osmium::NodeRef nr3(3, { 1.2, 3.6 }); + osmium::NodeRef nr4(4, { 1.2, 3.7 }); - NodeRefSegment s1(nr1, nr2, nullptr, nullptr); - REQUIRE(s1.first().ref() == 1); - REQUIRE(s1.second().ref() == 2); + NodeRefSegment s1(nr1, nr2, nullptr, nullptr); + REQUIRE(s1.first().ref() == 1); + REQUIRE(s1.second().ref() == 2); - NodeRefSegment s2(nr2, nr3, nullptr, nullptr); - REQUIRE(s2.first().ref() == 3); - REQUIRE(s2.second().ref() == 2); + NodeRefSegment s2(nr2, nr3, nullptr, nullptr); + REQUIRE(s2.first().ref() == 3); + REQUIRE(s2.second().ref() == 2); - NodeRefSegment s3(nr3, nr4, nullptr, nullptr); - REQUIRE(s3.first().ref() == 3); - REQUIRE(s3.second().ref() == 4); -} + NodeRefSegment s3(nr3, nr4, nullptr, nullptr); + REQUIRE(s3.first().ref() == 3); + REQUIRE(s3.second().ref() == 4); + } -SECTION("intersection") { - NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr); - NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr); - NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr); - NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr); - NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr); + SECTION("intersection") { + NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr); + NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr); + NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr); + NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr); + NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr); + NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr); + NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr); - REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0)); - REQUIRE(calculate_intersection(s1, s3) == osmium::Location()); - REQUIRE(calculate_intersection(s2, s3) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s4) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0)); - REQUIRE(calculate_intersection(s1, s1) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s6) == osmium::Location()); - REQUIRE(calculate_intersection(s1, s7) == osmium::Location()); -} + REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0)); + REQUIRE(calculate_intersection(s1, s3) == osmium::Location()); + REQUIRE(calculate_intersection(s2, s3) == osmium::Location()); + REQUIRE(calculate_intersection(s1, s4) == osmium::Location()); + REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0)); + REQUIRE(calculate_intersection(s1, s1) == osmium::Location()); + REQUIRE(calculate_intersection(s1, s6) == osmium::Location()); + REQUIRE(calculate_intersection(s1, s7) == osmium::Location()); + } -SECTION("to_left_of") { - osmium::Location loc { 2.0, 2.0 }; + SECTION("to_left_of") { + osmium::Location loc { 2.0, 2.0 }; - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); - REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc)); + REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); - REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false); -} + REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false); + REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false); + } -SECTION("ordering") { - osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); - osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); - osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); - osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); + SECTION("ordering") { + osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); + osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); + osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); + osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); - REQUIRE(node_ref1 < node_ref2); - REQUIRE(node_ref2 < node_ref3); - REQUIRE(node_ref1 < node_ref3); - REQUIRE(node_ref1 >= node_ref1); + REQUIRE(node_ref1 < node_ref2); + REQUIRE(node_ref2 < node_ref3); + REQUIRE(node_ref1 < node_ref3); + REQUIRE(node_ref1 >= node_ref1); - REQUIRE( osmium::location_less()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); - REQUIRE( osmium::location_less()(node_ref1, node_ref3)); - REQUIRE( osmium::location_less()(node_ref3, node_ref4)); - REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); -} + REQUIRE( osmium::location_less()(node_ref1, node_ref2)); + REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); + REQUIRE( osmium::location_less()(node_ref1, node_ref3)); + REQUIRE( osmium::location_less()(node_ref3, node_ref4)); + REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); + } } diff --git a/test/t/basic/test_box.cpp b/test/t/basic/test_box.cpp index 73a45f4e2..8182fbf35 100644 --- a/test/t/basic/test_box.cpp +++ b/test/t/basic/test_box.cpp @@ -7,75 +7,85 @@ TEST_CASE("Box") { -SECTION("instantiation") { - osmium::Box b; - REQUIRE(!b); - REQUIRE(!b.bottom_left()); - REQUIRE(!b.top_right()); - REQUIRE_THROWS_AS(b.size(), osmium::invalid_location); -} + SECTION("instantiation") { + osmium::Box b; + REQUIRE(!b); + REQUIRE(!b.bottom_left()); + REQUIRE(!b.top_right()); + REQUIRE_THROWS_AS(b.size(), osmium::invalid_location); + } -SECTION("instantiation_and_extend_with_undefined") { - osmium::Box b; - REQUIRE(!b); - b.extend(osmium::Location()); - REQUIRE(!b.bottom_left()); - REQUIRE(!b.top_right()); -} + SECTION("instantiation_and_extend_with_undefined") { + osmium::Box b; + REQUIRE(!b); + b.extend(osmium::Location()); + REQUIRE(!b.bottom_left()); + REQUIRE(!b.top_right()); + } -SECTION("instantiation_and_extend") { - osmium::Box b; - b.extend(osmium::Location(1.2, 3.4)); - REQUIRE(!!b); - REQUIRE(!!b.bottom_left()); - REQUIRE(!!b.top_right()); - b.extend(osmium::Location(3.4, 4.5)); - b.extend(osmium::Location(5.6, 7.8)); - REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); - REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); + SECTION("instantiation_and_extend") { + osmium::Box b; + osmium::Location loc1 { 1.2, 3.4 }; + b.extend(loc1); + REQUIRE(!!b); + REQUIRE(!!b.bottom_left()); + REQUIRE(!!b.top_right()); + REQUIRE(b.contains(loc1)); - // extend with undefined doesn't change anything - b.extend(osmium::Location()); - REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); - REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); -} + osmium::Location loc2 { 3.4, 4.5 }; + osmium::Location loc3 { 5.6, 7.8 }; -SECTION("output_defined") { - osmium::Box b; - b.extend(osmium::Location(1.2, 3.4)); - b.extend(osmium::Location(5.6, 7.8)); - std::stringstream out; - out << b; - REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)"); - REQUIRE(b.size() == Approx(19.36).epsilon(0.000001)); -} + b.extend(loc2); + b.extend(loc3); + REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); + REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); -SECTION("output_undefined") { - osmium::Box b; - std::stringstream out; - out << b; - REQUIRE(out.str() == "(undefined)"); -} + // extend with undefined doesn't change anything + b.extend(osmium::Location()); + REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4)); + REQUIRE(b.top_right() == osmium::Location(5.6, 7.8)); -SECTION("box_inside_box") { - osmium::Box outer; - outer.extend(osmium::Location(1, 1)); - outer.extend(osmium::Location(10, 10)); + REQUIRE(b.contains(loc1)); + REQUIRE(b.contains(loc2)); + REQUIRE(b.contains(loc3)); + } - osmium::Box inner; - inner.extend(osmium::Location(2, 2)); - inner.extend(osmium::Location(4, 4)); + SECTION("output_defined") { + osmium::Box b; + b.extend(osmium::Location(1.2, 3.4)); + b.extend(osmium::Location(5.6, 7.8)); + std::stringstream out; + out << b; + REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)"); + REQUIRE(b.size() == Approx(19.36).epsilon(0.000001)); + } - osmium::Box overlap; - overlap.extend(osmium::Location(3, 3)); - overlap.extend(osmium::Location(5, 5)); + SECTION("output_undefined") { + osmium::Box b; + std::stringstream out; + out << b; + REQUIRE(out.str() == "(undefined)"); + } - REQUIRE( osmium::geom::contains(inner, outer)); - REQUIRE(!osmium::geom::contains(outer, inner)); + SECTION("box_inside_box") { + osmium::Box outer; + outer.extend(osmium::Location(1, 1)); + outer.extend(osmium::Location(10, 10)); - REQUIRE(!osmium::geom::contains(overlap, inner)); - REQUIRE(!osmium::geom::contains(inner, overlap)); -} + osmium::Box inner; + inner.extend(osmium::Location(2, 2)); + inner.extend(osmium::Location(4, 4)); + + osmium::Box overlap; + overlap.extend(osmium::Location(3, 3)); + overlap.extend(osmium::Location(5, 5)); + + REQUIRE( osmium::geom::contains(inner, outer)); + REQUIRE(!osmium::geom::contains(outer, inner)); + + REQUIRE(!osmium::geom::contains(overlap, inner)); + REQUIRE(!osmium::geom::contains(inner, overlap)); + } } diff --git a/test/t/basic/test_entity_bits.cpp b/test/t/basic/test_entity_bits.cpp index a200f480b..f15068b1c 100644 --- a/test/t/basic/test_entity_bits.cpp +++ b/test/t/basic/test_entity_bits.cpp @@ -4,28 +4,28 @@ 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)); + 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::relation; + REQUIRE((entities & osmium::osm_entity_bits::object)); - entities |= osmium::osm_entity_bits::area; - 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)); + 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); + 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::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)); -} + 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)); + } } diff --git a/test/t/basic/test_location.cpp b/test/t/basic/test_location.cpp index 25545a4ba..3fd8d155a 100644 --- a/test/t/basic/test_location.cpp +++ b/test/t/basic/test_location.cpp @@ -10,145 +10,145 @@ TEST_CASE("Location") { // fails on MSVC and doesn't really matter // static_assert(std::is_literal_type::value, "osmium::Location not literal type"); -SECTION("instantiation_with_default_parameters") { - osmium::Location loc; - REQUIRE(!loc); - REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location); - REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location); -} + SECTION("instantiation_with_default_parameters") { + osmium::Location loc; + REQUIRE(!loc); + REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location); + REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location); + } -SECTION("instantiation_with_double_parameters") { - osmium::Location loc1(1.2, 4.5); - REQUIRE(!!loc1); - REQUIRE(12000000 == loc1.x()); - REQUIRE(45000000 == loc1.y()); - REQUIRE(1.2 == loc1.lon()); - REQUIRE(4.5 == loc1.lat()); + SECTION("instantiation_with_double_parameters") { + osmium::Location loc1(1.2, 4.5); + REQUIRE(!!loc1); + REQUIRE(12000000 == loc1.x()); + REQUIRE(45000000 == loc1.y()); + REQUIRE(1.2 == loc1.lon()); + REQUIRE(4.5 == loc1.lat()); - osmium::Location loc2(loc1); - REQUIRE(4.5 == loc2.lat()); + osmium::Location loc2(loc1); + REQUIRE(4.5 == loc2.lat()); - osmium::Location loc3 = loc1; - REQUIRE(4.5 == loc3.lat()); -} + osmium::Location loc3 = loc1; + REQUIRE(4.5 == loc3.lat()); + } -SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") { - osmium::Location loc { 2.2, 3.3 }; - REQUIRE(2.2 == loc.lon()); - REQUIRE(3.3 == loc.lat()); -} + SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") { + osmium::Location loc { 2.2, 3.3 }; + REQUIRE(2.2 == loc.lon()); + REQUIRE(3.3 == loc.lat()); + } -SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") { - osmium::Location loc({ 4.4, 5.5 }); - REQUIRE(4.4 == loc.lon()); - REQUIRE(5.5 == loc.lat()); -} + SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") { + osmium::Location loc({ 4.4, 5.5 }); + REQUIRE(4.4 == loc.lon()); + REQUIRE(5.5 == loc.lat()); + } -SECTION("instantiation_with_double_parameters_operator_equal") { - osmium::Location loc = { 5.5, 6.6 }; - REQUIRE(5.5 == loc.lon()); - REQUIRE(6.6 == loc.lat()); -} + SECTION("instantiation_with_double_parameters_operator_equal") { + osmium::Location loc = { 5.5, 6.6 }; + REQUIRE(5.5 == loc.lon()); + REQUIRE(6.6 == loc.lat()); + } -SECTION("equality") { - osmium::Location loc1(1.2, 4.5); - osmium::Location loc2(1.2, 4.5); - osmium::Location loc3(1.5, 1.5); - REQUIRE(loc1 == loc2); - REQUIRE(loc1 != loc3); -} + SECTION("equality") { + osmium::Location loc1(1.2, 4.5); + osmium::Location loc2(1.2, 4.5); + osmium::Location loc3(1.5, 1.5); + REQUIRE(loc1 == loc2); + REQUIRE(loc1 != loc3); + } -SECTION("order") { - REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0)); - REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0)); + SECTION("order") { + REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0)); + REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0)); - REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2)); - REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0)); - REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0)); -} + REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2)); + REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0)); + REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0)); + } -SECTION("validity") { - REQUIRE(osmium::Location(0.0, 0.0).valid()); - REQUIRE(osmium::Location(1.2, 4.5).valid()); - REQUIRE(osmium::Location(-1.2, 4.5).valid()); - REQUIRE(osmium::Location(-180.0, -90.0).valid()); - REQUIRE(osmium::Location(180.0, -90.0).valid()); - REQUIRE(osmium::Location(-180.0, 90.0).valid()); - REQUIRE(osmium::Location(180.0, 90.0).valid()); + SECTION("validity") { + REQUIRE(osmium::Location(0.0, 0.0).valid()); + REQUIRE(osmium::Location(1.2, 4.5).valid()); + REQUIRE(osmium::Location(-1.2, 4.5).valid()); + REQUIRE(osmium::Location(-180.0, -90.0).valid()); + REQUIRE(osmium::Location(180.0, -90.0).valid()); + REQUIRE(osmium::Location(-180.0, 90.0).valid()); + REQUIRE(osmium::Location(180.0, 90.0).valid()); - REQUIRE(!osmium::Location(200.0, 4.5).valid()); - REQUIRE(!osmium::Location(-1.2, -100.0).valid()); - REQUIRE(!osmium::Location(-180.0, 90.005).valid()); -} + REQUIRE(!osmium::Location(200.0, 4.5).valid()); + REQUIRE(!osmium::Location(-1.2, -100.0).valid()); + REQUIRE(!osmium::Location(-180.0, 90.005).valid()); + } -SECTION("output_to_iterator_comma_separator") { - char buffer[100]; - osmium::Location loc(-3.2, 47.3); - *loc.as_string(buffer, ',') = 0; - REQUIRE(std::string("-3.2,47.3") == buffer); -} + SECTION("output_to_iterator_comma_separator") { + char buffer[100]; + osmium::Location loc(-3.2, 47.3); + *loc.as_string(buffer, ',') = 0; + REQUIRE(std::string("-3.2,47.3") == buffer); + } -SECTION("output_to_iterator_space_separator") { - char buffer[100]; - osmium::Location loc(0.0, 7.0); - *loc.as_string(buffer, ' ') = 0; - REQUIRE(std::string("0 7") == buffer); -} + SECTION("output_to_iterator_space_separator") { + char buffer[100]; + osmium::Location loc(0.0, 7.0); + *loc.as_string(buffer, ' ') = 0; + REQUIRE(std::string("0 7") == buffer); + } -SECTION("output_to_iterator_check_precision") { - char buffer[100]; - osmium::Location loc(-179.9999999, -90.0); - *loc.as_string(buffer, ' ') = 0; - REQUIRE(std::string("-179.9999999 -90") == buffer); -} + SECTION("output_to_iterator_check_precision") { + char buffer[100]; + osmium::Location loc(-179.9999999, -90.0); + *loc.as_string(buffer, ' ') = 0; + REQUIRE(std::string("-179.9999999 -90") == buffer); + } -SECTION("output_to_iterator_undefined_location") { - char buffer[100]; - osmium::Location loc; - REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location); -} + SECTION("output_to_iterator_undefined_location") { + char buffer[100]; + osmium::Location loc; + REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location); + } -SECTION("output_to_string_comman_separator") { - std::string s; - osmium::Location loc(-3.2, 47.3); - loc.as_string(std::back_inserter(s), ','); - REQUIRE(s == "-3.2,47.3"); -} + SECTION("output_to_string_comman_separator") { + std::string s; + osmium::Location loc(-3.2, 47.3); + loc.as_string(std::back_inserter(s), ','); + REQUIRE(s == "-3.2,47.3"); + } -SECTION("output_to_string_space_separator") { - std::string s; - osmium::Location loc(0.0, 7.0); - loc.as_string(std::back_inserter(s), ' '); - REQUIRE(s == "0 7"); -} + SECTION("output_to_string_space_separator") { + std::string s; + osmium::Location loc(0.0, 7.0); + loc.as_string(std::back_inserter(s), ' '); + REQUIRE(s == "0 7"); + } -SECTION("output_to_string_check_precision") { - std::string s; - osmium::Location loc(-179.9999999, -90.0); - loc.as_string(std::back_inserter(s), ' '); - REQUIRE(s == "-179.9999999 -90"); -} + SECTION("output_to_string_check_precision") { + std::string s; + osmium::Location loc(-179.9999999, -90.0); + loc.as_string(std::back_inserter(s), ' '); + REQUIRE(s == "-179.9999999 -90"); + } -SECTION("output_to_string_undefined_location") { - std::string s; - osmium::Location loc; - REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location); -} + SECTION("output_to_string_undefined_location") { + std::string s; + osmium::Location loc; + REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location); + } -SECTION("output_defined") { - osmium::Location p(-3.2, 47.3); - std::stringstream out; - out << p; - REQUIRE(out.str() == "(-3.2,47.3)"); -} + SECTION("output_defined") { + osmium::Location p(-3.2, 47.3); + std::stringstream out; + out << p; + REQUIRE(out.str() == "(-3.2,47.3)"); + } -SECTION("output_undefined") { - osmium::Location p; - std::stringstream out; - out << p; - REQUIRE(out.str() == "(undefined,undefined)"); -} + SECTION("output_undefined") { + osmium::Location p; + std::stringstream out; + out << p; + REQUIRE(out.str() == "(undefined,undefined)"); + } } diff --git a/test/t/basic/test_node_ref.cpp b/test/t/basic/test_node_ref.cpp index 5c7b670f1..ac7ccbf4b 100644 --- a/test/t/basic/test_node_ref.cpp +++ b/test/t/basic/test_node_ref.cpp @@ -4,54 +4,54 @@ TEST_CASE("NodeRef") { -SECTION("instantiation_with_default_parameters") { - osmium::NodeRef node_ref; - REQUIRE(node_ref.ref() == 0); + SECTION("instantiation_with_default_parameters") { + osmium::NodeRef node_ref; + REQUIRE(node_ref.ref() == 0); // REQUIRE(!node_ref.has_location()); -} + } -SECTION("instantiation_with_id") { - osmium::NodeRef node_ref(7); - REQUIRE(node_ref.ref() == 7); -} + SECTION("instantiation_with_id") { + osmium::NodeRef node_ref(7); + REQUIRE(node_ref.ref() == 7); + } -SECTION("equality") { - osmium::NodeRef node_ref1(7, { 1.2, 3.4 }); - osmium::NodeRef node_ref2(7, { 1.4, 3.1 }); - osmium::NodeRef node_ref3(9, { 1.2, 3.4 }); - REQUIRE(node_ref1 == node_ref2); - REQUIRE(node_ref1 != node_ref3); - REQUIRE(!osmium::location_equal()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_equal()(node_ref2, node_ref3)); - REQUIRE(osmium::location_equal()(node_ref1, node_ref3)); -} + SECTION("equality") { + osmium::NodeRef node_ref1(7, { 1.2, 3.4 }); + osmium::NodeRef node_ref2(7, { 1.4, 3.1 }); + osmium::NodeRef node_ref3(9, { 1.2, 3.4 }); + REQUIRE(node_ref1 == node_ref2); + REQUIRE(node_ref1 != node_ref3); + REQUIRE(!osmium::location_equal()(node_ref1, node_ref2)); + REQUIRE(!osmium::location_equal()(node_ref2, node_ref3)); + REQUIRE(osmium::location_equal()(node_ref1, node_ref3)); + } -SECTION("set_location") { - osmium::NodeRef node_ref(7); - REQUIRE(!node_ref.location().valid()); - REQUIRE(node_ref.location() == osmium::Location()); - node_ref.set_location(osmium::Location(13.5, -7.2)); - REQUIRE(node_ref.location().lon() == 13.5); - REQUIRE(node_ref.location().valid()); -} + SECTION("set_location") { + osmium::NodeRef node_ref(7); + REQUIRE(!node_ref.location().valid()); + REQUIRE(node_ref.location() == osmium::Location()); + node_ref.set_location(osmium::Location(13.5, -7.2)); + REQUIRE(node_ref.location().lon() == 13.5); + REQUIRE(node_ref.location().valid()); + } -SECTION("ordering") { - osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); - osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); - osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); - osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); + SECTION("ordering") { + osmium::NodeRef node_ref1(1, { 1.0, 3.0 }); + osmium::NodeRef node_ref2(2, { 1.4, 2.9 }); + osmium::NodeRef node_ref3(3, { 1.2, 3.0 }); + osmium::NodeRef node_ref4(4, { 1.2, 3.3 }); - REQUIRE(node_ref1 < node_ref2); - REQUIRE(node_ref2 < node_ref3); - REQUIRE(node_ref1 < node_ref3); - REQUIRE(node_ref1 >= node_ref1); + REQUIRE(node_ref1 < node_ref2); + REQUIRE(node_ref2 < node_ref3); + REQUIRE(node_ref1 < node_ref3); + REQUIRE(node_ref1 >= node_ref1); - REQUIRE(osmium::location_less()(node_ref1, node_ref2)); - REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); - REQUIRE(osmium::location_less()(node_ref1, node_ref3)); - REQUIRE(osmium::location_less()(node_ref3, node_ref4)); - REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); -} + REQUIRE(osmium::location_less()(node_ref1, node_ref2)); + REQUIRE(!osmium::location_less()(node_ref2, node_ref3)); + REQUIRE(osmium::location_less()(node_ref1, node_ref3)); + REQUIRE(osmium::location_less()(node_ref3, node_ref4)); + REQUIRE(!osmium::location_less()(node_ref1, node_ref1)); + } } diff --git a/test/t/basic/test_object_comparisons.cpp b/test/t/basic/test_object_comparisons.cpp index ffffbccb3..2bfdcad90 100644 --- a/test/t/basic/test_object_comparisons.cpp +++ b/test/t/basic/test_object_comparisons.cpp @@ -6,142 +6,142 @@ TEST_CASE("Object_Comparisons") { -SECTION("order") { - osmium::memory::Buffer buffer(10 * 1000); + SECTION("order") { + osmium::memory::Buffer buffer(10 * 1000); - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - buffer.commit(); + { + // add node 1 + osmium::builder::NodeBuilder node_builder(buffer); + node_builder.add_user("testuser"); + buffer.commit(); + } + + { + // add node 2 + osmium::builder::NodeBuilder node_builder(buffer); + node_builder.add_user("testuser"); + buffer.commit(); + } + + auto it = buffer.begin(); + osmium::Node& node1 = static_cast(*it); + osmium::Node& node2 = static_cast(*(++it)); + + node1.set_id(10); + node1.set_version(1); + node2.set_id(15); + node2.set_version(2); + REQUIRE(true == (node1 < node2)); + REQUIRE(false == (node1 > node2)); + node1.set_id(20); + node1.set_version(1); + node2.set_id(20); + node2.set_version(2); + REQUIRE(true == (node1 < node2)); + REQUIRE(false == (node1 > node2)); + node1.set_id(-10); + node1.set_version(2); + node2.set_id(-15); + node2.set_version(1); + REQUIRE(true == (node1 < node2)); + REQUIRE(false == (node1 > node2)); } - { - // add node 2 - osmium::builder::NodeBuilder node_builder(buffer); - node_builder.add_user("testuser"); - buffer.commit(); + SECTION("order_types") { + osmium::memory::Buffer buffer(10 * 1000); + + { + // add node 1 + osmium::builder::NodeBuilder node_builder(buffer); + osmium::Node& node = node_builder.object(); + REQUIRE(osmium::item_type::node == node.type()); + + node.set_id(3); + node.set_version(3); + node_builder.add_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()); + + node.set_id(3); + node.set_version(4); + node_builder.add_user("testuser"); + + buffer.commit(); + } + + { + // add node 3 + osmium::builder::NodeBuilder node_builder(buffer); + osmium::Node& node = node_builder.object(); + REQUIRE(osmium::item_type::node == node.type()); + + node.set_id(3); + node.set_version(4); + node_builder.add_user("testuser"); + + buffer.commit(); + } + + { + // add way + osmium::builder::WayBuilder way_builder(buffer); + osmium::Way& way = way_builder.object(); + REQUIRE(osmium::item_type::way == way.type()); + + way.set_id(2); + way.set_version(2); + way_builder.add_user("testuser"); + + buffer.commit(); + } + + { + // add relation + osmium::builder::RelationBuilder relation_builder(buffer); + osmium::Relation& relation = relation_builder.object(); + REQUIRE(osmium::item_type::relation == relation.type()); + + relation.set_id(1); + relation.set_version(1); + relation_builder.add_user("testuser"); + + buffer.commit(); + } + + auto it = buffer.begin(); + const osmium::Node& node1 = static_cast(*it); + const osmium::Node& node2 = static_cast(*(++it)); + const osmium::Node& node3 = static_cast(*(++it)); + const osmium::Way& way = static_cast(*(++it)); + const osmium::Relation& relation = static_cast(*(++it)); + + REQUIRE(true == (node1 < node2)); + REQUIRE(true == (node2 < way)); + REQUIRE(false == (node2 > way)); + REQUIRE(true == (way < relation)); + REQUIRE(true == (node1 < relation)); + + REQUIRE(true == osmium::object_order_type_id_version()(node1, node2)); + REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1)); + REQUIRE(true == osmium::object_order_type_id_version()(node1, way)); + REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way)); + + REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2)); + REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3)); + + REQUIRE(true == osmium::object_equal_type_id()(node1, node2)); + REQUIRE(true == osmium::object_equal_type_id()(node2, node3)); + + REQUIRE(false == osmium::object_equal_type_id_version()(node1, way)); + REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation)); + REQUIRE(false == osmium::object_equal_type_id()(node1, relation)); } - auto it = buffer.begin(); - osmium::Node& node1 = static_cast(*it); - osmium::Node& node2 = static_cast(*(++it)); - - node1.set_id(10); - node1.set_version(1); - node2.set_id(15); - node2.set_version(2); - REQUIRE(true == (node1 < node2)); - REQUIRE(false == (node1 > node2)); - node1.set_id(20); - node1.set_version(1); - node2.set_id(20); - node2.set_version(2); - REQUIRE(true == (node1 < node2)); - REQUIRE(false == (node1 > node2)); - node1.set_id(-10); - node1.set_version(2); - node2.set_id(-15); - node2.set_version(1); - REQUIRE(true == (node1 < node2)); - REQUIRE(false == (node1 > node2)); -} - -SECTION("order_types") { - osmium::memory::Buffer buffer(10 * 1000); - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(3); - node.set_version(3); - node_builder.add_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()); - - node.set_id(3); - node.set_version(4); - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add node 3 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - node.set_id(3); - node.set_version(4); - node_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add way - osmium::builder::WayBuilder way_builder(buffer); - osmium::Way& way = way_builder.object(); - REQUIRE(osmium::item_type::way == way.type()); - - way.set_id(2); - way.set_version(2); - way_builder.add_user("testuser"); - - buffer.commit(); - } - - { - // add relation - osmium::builder::RelationBuilder relation_builder(buffer); - osmium::Relation& relation = relation_builder.object(); - REQUIRE(osmium::item_type::relation == relation.type()); - - relation.set_id(1); - relation.set_version(1); - relation_builder.add_user("testuser"); - - buffer.commit(); - } - - auto it = buffer.begin(); - const osmium::Node& node1 = static_cast(*it); - const osmium::Node& node2 = static_cast(*(++it)); - const osmium::Node& node3 = static_cast(*(++it)); - const osmium::Way& way = static_cast(*(++it)); - const osmium::Relation& relation = static_cast(*(++it)); - - REQUIRE(true == (node1 < node2)); - REQUIRE(true == (node2 < way)); - REQUIRE(false == (node2 > way)); - REQUIRE(true == (way < relation)); - REQUIRE(true == (node1 < relation)); - - REQUIRE(true == osmium::object_order_type_id_version()(node1, node2)); - REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1)); - REQUIRE(true == osmium::object_order_type_id_version()(node1, way)); - REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way)); - - REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2)); - REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3)); - - REQUIRE(true == osmium::object_equal_type_id()(node1, node2)); - REQUIRE(true == osmium::object_equal_type_id()(node2, node3)); - - REQUIRE(false == osmium::object_equal_type_id_version()(node1, way)); - REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation)); - REQUIRE(false == osmium::object_equal_type_id()(node1, relation)); -} - } diff --git a/test/t/basic/test_timestamp.cpp b/test/t/basic/test_timestamp.cpp index 453b94b2e..6a04a4d09 100644 --- a/test/t/basic/test_timestamp.cpp +++ b/test/t/basic/test_timestamp.cpp @@ -6,40 +6,53 @@ TEST_CASE("Timestamp") { -SECTION("can be default initialized to invalid value") { - osmium::Timestamp t; - REQUIRE(0 == t); - REQUIRE("" == t.to_iso()); -} + SECTION("can be default initialized to invalid value") { + osmium::Timestamp t; + REQUIRE(0 == t); + REQUIRE("" == t.to_iso()); + } -SECTION("invalid value is zero") { - osmium::Timestamp t(static_cast(0)); - REQUIRE(0 == t); - REQUIRE("" == t.to_iso()); -} + SECTION("invalid value is zero") { + osmium::Timestamp t(static_cast(0)); + REQUIRE(0 == t); + REQUIRE("" == t.to_iso()); + } -SECTION("can be initialized from time_t") { - osmium::Timestamp t(static_cast(1)); - REQUIRE(1 == t); - REQUIRE("1970-01-01T00:00:01Z" == t.to_iso()); -} + SECTION("can be initialized from time_t") { + osmium::Timestamp t(static_cast(1)); + REQUIRE(1 == t); + REQUIRE("1970-01-01T00:00:01Z" == t.to_iso()); + } -SECTION("can be initialized from string") { - osmium::Timestamp t("2000-01-01T00:00:00Z"); - REQUIRE("2000-01-01T00:00:00Z" == t.to_iso()); -} + SECTION("can be initialized from string") { + osmium::Timestamp t("2000-01-01T00:00:00Z"); + REQUIRE("2000-01-01T00:00:00Z" == t.to_iso()); + } -SECTION("can be compared") { - osmium::Timestamp t1(10); - osmium::Timestamp t2(50); - REQUIRE(t1 < t2); -} + SECTION("can be implicitly cast to time_t") { + osmium::Timestamp t(4242); + time_t x = t; + REQUIRE(x == 4242); + } -SECTION("can be written to stream") { - std::stringstream ss; - osmium::Timestamp t(1); - ss << t; - REQUIRE("1970-01-01T00:00:01Z" == ss.str()); -} + SECTION("uint32_t can be initialized from Timestamp") { + osmium::Timestamp t(4242); + uint32_t x { t }; + + REQUIRE(x == 4242); + } + + SECTION("can be compared") { + osmium::Timestamp t1(10); + osmium::Timestamp t2(50); + REQUIRE(t1 < t2); + } + + SECTION("can be written to stream") { + std::stringstream ss; + osmium::Timestamp t(1); + ss << t; + REQUIRE("1970-01-01T00:00:01Z" == ss.str()); + } } diff --git a/test/t/buffer/test_buffer_node.cpp b/test/t/buffer/test_buffer_node.cpp index aabe6cbea..9bc8f701d 100644 --- a/test/t/buffer/test_buffer_node.cpp +++ b/test/t/buffer/test_buffer_node.cpp @@ -58,78 +58,78 @@ void check_node_2(osmium::Node& node) { TEST_CASE("Buffer_Node") { -SECTION("buffer_node") { - constexpr size_t buffer_size = 10000; - unsigned char data[buffer_size]; + SECTION("buffer_node") { + constexpr size_t buffer_size = 10000; + unsigned char data[buffer_size]; - osmium::memory::Buffer buffer(data, buffer_size, 0); - - { - // add node 1 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - 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(); - } - - { - // add node 2 - osmium::builder::NodeBuilder node_builder(buffer); - osmium::Node& node = node_builder.object(); - REQUIRE(osmium::item_type::node == node.type()); - - 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.add_user("testuser"); + osmium::memory::Buffer buffer(data, buffer_size, 0); { - osmium::builder::TagListBuilder tag_builder(buffer, &node_builder); - tag_builder.add_tag("amenity", "bank"); - tag_builder.add_tag("name", "OSM Savings"); + // add node 1 + osmium::builder::NodeBuilder node_builder(buffer); + osmium::Node& node = node_builder.object(); + REQUIRE(osmium::item_type::node == node.type()); + + 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(); } - buffer.commit(); - } + { + // add node 2 + osmium::builder::NodeBuilder node_builder(buffer); + osmium::Node& node = node_builder.object(); + REQUIRE(osmium::item_type::node == node.type()); - REQUIRE(2 == std::distance(buffer.begin(), buffer.end())); - int item_no = 0; - for (osmium::memory::Item& item : buffer) { - REQUIRE(osmium::item_type::node == item.type()); + 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)); - osmium::Node& node = static_cast(item); + node_builder.add_user("testuser"); - switch (item_no) { - case 0: - check_node_1(node); - break; - case 1: - check_node_2(node); - break; - default: - break; + { + osmium::builder::TagListBuilder tag_builder(buffer, &node_builder); + tag_builder.add_tag("amenity", "bank"); + tag_builder.add_tag("name", "OSM Savings"); + } + + buffer.commit(); } - ++item_no; + REQUIRE(2 == std::distance(buffer.begin(), buffer.end())); + int item_no = 0; + for (osmium::memory::Item& item : buffer) { + REQUIRE(osmium::item_type::node == item.type()); + + osmium::Node& node = static_cast(item); + + switch (item_no) { + case 0: + check_node_1(node); + break; + case 1: + check_node_2(node); + break; + default: + break; + } + + ++item_no; + + } } } - -} diff --git a/test/t/geom/test_factory_with_projection.cpp b/test/t/geom/test_factory_with_projection.cpp index 9bc8c0681..42fc864bb 100644 --- a/test/t/geom/test_factory_with_projection.cpp +++ b/test/t/geom/test_factory_with_projection.cpp @@ -10,32 +10,32 @@ TEST_CASE("Projection") { -SECTION("point_mercator") { - osmium::geom::WKTFactory factory(2); + SECTION("point_mercator") { + osmium::geom::WKTFactory factory(2); - std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))}; - REQUIRE(std::string{"POINT(356222.37 467961.14)"} == wkt); -} + 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 factory(osmium::geom::Projection(3857), 2); + SECTION("point_epsg_3857") { + osmium::geom::WKTFactory 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); -} + 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 wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); - osmium::geom::GEOSFactory geos_factory(osmium::geom::Projection(3857)); + SECTION("wkb_with_parameter") { + osmium::geom::WKBFactory wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex); + osmium::geom::GEOSFactory geos_factory(osmium::geom::Projection(3857)); - std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2)); - std::unique_ptr geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2)); - REQUIRE(geos_to_wkb(geos_point.get()) == wkb); -} + std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2)); + std::unique_ptr 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(); -} + SECTION("cleanup") { + // trying to make valgrind happy, but there is still a memory leak in proj library + pj_deallocate_grids(); + } } diff --git a/test/t/geom/test_mercator.cpp b/test/t/geom/test_mercator.cpp index a6ce2ee4a..cc16e55cf 100644 --- a/test/t/geom/test_mercator.cpp +++ b/test/t/geom/test_mercator.cpp @@ -4,34 +4,34 @@ TEST_CASE("Mercator") { -SECTION("mercator_projection") { - osmium::geom::MercatorProjection projection; - REQUIRE(3857 == projection.epsg()); - REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string()); -} + SECTION("mercator_projection") { + osmium::geom::MercatorProjection projection; + REQUIRE(3857 == projection.epsg()); + REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string()); + } -SECTION("low_level_mercator_functions") { - osmium::geom::Coordinates c1(17.839, -3.249); - osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1)); - REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001)); - REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001)); + SECTION("low_level_mercator_functions") { + osmium::geom::Coordinates c1(17.839, -3.249); + osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1)); + REQUIRE(r1.x == Approx(c1.x).epsilon(0.000001)); + REQUIRE(r1.y == Approx(c1.y).epsilon(0.000001)); - osmium::geom::Coordinates c2(-89.2, 15.915); - osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2)); - REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001)); - REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001)); + osmium::geom::Coordinates c2(-89.2, 15.915); + osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2)); + REQUIRE(r2.x == Approx(c2.x).epsilon(0.000001)); + REQUIRE(r2.y == Approx(c2.y).epsilon(0.000001)); - osmium::geom::Coordinates c3(180.0, 85.0); - osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3)); - REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001)); - REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001)); -} + osmium::geom::Coordinates c3(180.0, 85.0); + osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3)); + REQUIRE(r3.x == Approx(c3.x).epsilon(0.000001)); + REQUIRE(r3.y == Approx(c3.y).epsilon(0.000001)); + } -SECTION("mercator_bounds") { - osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT); - osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax); - REQUIRE(c.x == Approx(c.y).epsilon(0.001)); - REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001)); -} + SECTION("mercator_bounds") { + osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT); + osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax); + REQUIRE(c.x == Approx(c.y).epsilon(0.001)); + REQUIRE(osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0)) == Approx(osmium::geom::MERCATOR_MAX_LAT).epsilon(0.0000001)); + } } diff --git a/test/t/index/test_id_to_location.cpp b/test/t/index/test_id_to_location.cpp index fbb3f6a97..4aca238b6 100644 --- a/test/t/index/test_id_to_location.cpp +++ b/test/t/index/test_id_to_location.cpp @@ -58,113 +58,113 @@ void test_func_real(TIndex& index) { TEST_CASE("IdToLocation") { -SECTION("Dummy") { - typedef osmium::index::map::Dummy index_type; + SECTION("Dummy") { + typedef osmium::index::map::Dummy index_type; - 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(index1); + test_func_all(index1); - REQUIRE(0 == index1.size()); - REQUIRE(0 == index1.used_memory()); -} + REQUIRE(0 == index1.size()); + REQUIRE(0 == index1.used_memory()); + } -SECTION("DenseMemArray") { - typedef osmium::index::map::DenseMemArray index_type; + SECTION("DenseMemArray") { + typedef osmium::index::map::DenseMemArray index_type; - index_type index1; - index1.reserve(1000); - test_func_all(index1); + index_type index1; + index1.reserve(1000); + test_func_all(index1); - index_type index2; - index2.reserve(1000); - test_func_real(index2); -} + index_type index2; + index2.reserve(1000); + test_func_real(index2); + } #ifdef __linux__ -SECTION("DenseMmapArray") { - typedef osmium::index::map::DenseMmapArray index_type; + SECTION("DenseMmapArray") { + typedef osmium::index::map::DenseMmapArray index_type; - index_type index1; - test_func_all(index1); + index_type index1; + test_func_all(index1); - index_type index2; - test_func_real(index2); -} + index_type index2; + test_func_real(index2); + } #else # pragma message("not running 'DenseMapMmap' test case on this machine") #endif -SECTION("DenseFileArray") { - typedef osmium::index::map::DenseFileArray index_type; + SECTION("DenseFileArray") { + typedef osmium::index::map::DenseFileArray index_type; - index_type index1; - test_func_all(index1); + index_type index1; + test_func_all(index1); - index_type index2; - test_func_real(index2); -} + index_type index2; + test_func_real(index2); + } #ifdef OSMIUM_WITH_SPARSEHASH -SECTION("SparseMemTable") { - typedef osmium::index::map::SparseMemTable index_type; + SECTION("SparseMemTable") { + typedef osmium::index::map::SparseMemTable index_type; - index_type index1; - test_func_all(index1); + index_type index1; + test_func_all(index1); - index_type index2; - test_func_real(index2); -} + index_type index2; + test_func_real(index2); + } #endif -SECTION("SparseMemMap") { - typedef osmium::index::map::SparseMemMap index_type; + SECTION("SparseMemMap") { + typedef osmium::index::map::SparseMemMap index_type; - index_type index1; - test_func_all(index1); + index_type index1; + test_func_all(index1); - index_type index2; - test_func_real(index2); -} - -SECTION("SparseMemArray") { - typedef osmium::index::map::SparseMemArray index_type; - - index_type index1; - - REQUIRE(0 == index1.size()); - REQUIRE(0 == index1.used_memory()); - - test_func_all(index1); - - REQUIRE(2 == index1.size()); - - index_type index2; - test_func_real(index2); -} - -SECTION("Dynamic map choice") { - typedef osmium::index::map::Map map_type; - const auto& map_factory = osmium::index::MapFactory::instance(); - - std::vector 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 index1 = map_factory.create_map(map_type_name); - index1->reserve(1000); - test_func_all(*index1); - - std::unique_ptr index2 = map_factory.create_map(map_type_name); - index2->reserve(1000); - test_func_real(*index2); + index_type index2; + test_func_real(index2); + } + + SECTION("SparseMemArray") { + typedef osmium::index::map::SparseMemArray index_type; + + index_type index1; + + REQUIRE(0 == index1.size()); + REQUIRE(0 == index1.used_memory()); + + test_func_all(index1); + + REQUIRE(2 == index1.size()); + + index_type index2; + test_func_real(index2); + } + + SECTION("Dynamic map choice") { + typedef osmium::index::map::Map map_type; + const auto& map_factory = osmium::index::MapFactory::instance(); + + std::vector 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 index1 = map_factory.create_map(map_type_name); + index1->reserve(1000); + test_func_all(*index1); + + std::unique_ptr index2 = map_factory.create_map(map_type_name); + index2->reserve(1000); + test_func_real(*index2); + } } -} } diff --git a/test/t/index/test_typed_mmap.cpp b/test/t/index/test_typed_mmap.cpp index df95dc267..bcc17bd2d 100644 --- a/test/t/index/test_typed_mmap.cpp +++ b/test/t/index/test_typed_mmap.cpp @@ -3,97 +3,74 @@ #include #if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) - #include "win_mkstemp.hpp" +#include "win_mkstemp.hpp" #endif TEST_CASE("TypedMmap") { -SECTION("Mmap") { - uint64_t* data = osmium::detail::typed_mmap::map(10); + SECTION("Mmap") { + uint64_t* data = osmium::detail::typed_mmap::map(10); - data[0] = 4ul; - data[3] = 9ul; - data[9] = 25ul; + data[0] = 4ul; + data[3] = 9ul; + data[9] = 25ul; - REQUIRE(4ul == data[0]); - REQUIRE(9ul == data[3]); - REQUIRE(25ul == data[9]); + REQUIRE(4ul == data[0]); + REQUIRE(9ul == data[3]); + REQUIRE(25ul == data[9]); - osmium::detail::typed_mmap::unmap(data, 10); -} - -SECTION("MmapSizeZero") { - REQUIRE_THROWS_AS(osmium::detail::typed_mmap::map(0), std::system_error); -} - -SECTION("MmapHugeSize") { - // this is a horrible hack to only run the test on 64bit machines. - if (sizeof(size_t) >= 8) { - REQUIRE_THROWS_AS(osmium::detail::typed_mmap::map(1ULL << (sizeof(size_t) * 6)), std::system_error); + osmium::detail::typed_mmap::unmap(data, 10); + } + + SECTION("MmapSizeZero") { + REQUIRE_THROWS_AS(osmium::detail::typed_mmap::map(0), std::system_error); + } + + SECTION("MmapHugeSize") { + // this is a horrible hack to only run the test on 64bit machines. + if (sizeof(size_t) >= 8) { + REQUIRE_THROWS_AS(osmium::detail::typed_mmap::map(1ULL << (sizeof(size_t) * 6)), std::system_error); + } } -} #ifdef __linux__ -SECTION("Remap") { - uint64_t* data = osmium::detail::typed_mmap::map(10); + SECTION("Remap") { + uint64_t* data = osmium::detail::typed_mmap::map(10); - data[0] = 4ul; - data[3] = 9ul; - data[9] = 25ul; + data[0] = 4ul; + data[3] = 9ul; + data[9] = 25ul; - uint64_t* new_data = osmium::detail::typed_mmap::remap(data, 10, 1000); + uint64_t* new_data = osmium::detail::typed_mmap::remap(data, 10, 1000); - REQUIRE(4ul == new_data[0]); - REQUIRE(9ul == new_data[3]); - REQUIRE(25ul == new_data[9]); -} + REQUIRE(4ul == new_data[0]); + REQUIRE(9ul == new_data[3]); + REQUIRE(25ul == new_data[9]); + } #else # pragma message("not running 'Remap' test case on this machine") #endif -SECTION("FileSize") { - const int size = 100; - char filename[] = "test_mmap_file_size_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - REQUIRE(0 == osmium::detail::typed_mmap::file_size(fd)); - REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t))); - REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); + SECTION("FileSize") { + const int size = 100; + char filename[] = "test_mmap_file_size_XXXXXX"; + const int fd = mkstemp(filename); + REQUIRE(fd > 0); + REQUIRE(0 == osmium::detail::typed_mmap::file_size(fd)); + REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t))); + REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); - osmium::detail::typed_mmap::grow_file(size / 2, fd); - REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); + osmium::detail::typed_mmap::grow_file(size / 2, fd); + REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); - osmium::detail::typed_mmap::grow_file(size, fd); - REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); + osmium::detail::typed_mmap::grow_file(size, fd); + REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); - osmium::detail::typed_mmap::grow_file(size * 2, fd); - REQUIRE((size * 2) == osmium::detail::typed_mmap::file_size(fd)); + osmium::detail::typed_mmap::grow_file(size * 2, fd); + REQUIRE((size * 2) == osmium::detail::typed_mmap::file_size(fd)); - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); -} - -SECTION("GrowAndMap") { - const int size = 100; - char filename[] = "test_mmap_grow_and_map_XXXXXX"; - const int fd = mkstemp(filename); - REQUIRE(fd > 0); - - uint64_t* data = osmium::detail::typed_mmap::grow_and_map(size, fd); - REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); - - data[0] = 1ul; - data[1] = 8ul; - data[99] = 27ul; - - REQUIRE(1ul == data[0]); - REQUIRE(8ul == data[1]); - REQUIRE(27ul == data[99]); - - osmium::detail::typed_mmap::unmap(data, size); - - REQUIRE(0 == close(fd)); - REQUIRE(0 == unlink(filename)); -} + REQUIRE(0 == close(fd)); + REQUIRE(0 == unlink(filename)); + } } diff --git a/test/t/index/test_typed_mmap_grow.cpp b/test/t/index/test_typed_mmap_grow.cpp new file mode 100644 index 000000000..92ee0b40e --- /dev/null +++ b/test/t/index/test_typed_mmap_grow.cpp @@ -0,0 +1,34 @@ +#include "catch.hpp" + +#include + +#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) +#include "win_mkstemp.hpp" +#endif + +TEST_CASE("TypedMmapGrow") { + + SECTION("GrowAndMap") { + const int size = 100; + char filename[] = "test_mmap_grow_and_map_XXXXXX"; + const int fd = mkstemp(filename); + REQUIRE(fd > 0); + + uint64_t* data = osmium::detail::typed_mmap::grow_and_map(size, fd); + REQUIRE(size == osmium::detail::typed_mmap::file_size(fd)); + + data[0] = 1ul; + data[1] = 8ul; + data[99] = 27ul; + + REQUIRE(1ul == data[0]); + REQUIRE(8ul == data[1]); + REQUIRE(27ul == data[99]); + + osmium::detail::typed_mmap::unmap(data, size); + + REQUIRE(0 == close(fd)); + REQUIRE(0 == unlink(filename)); + } + +} diff --git a/test/t/io/test_bzip2.cpp b/test/t/io/test_bzip2.cpp index e6342e11d..5cc30b427 100644 --- a/test/t/io/test_bzip2.cpp +++ b/test/t/io/test_bzip2.cpp @@ -9,25 +9,25 @@ TEST_CASE("Bzip2") { -SECTION("read_compressed_file") { - std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2"); + SECTION("read_compressed_file") { + std::string input_file = with_data_dir("t/io/data_bzip2.txt.bz2"); - int fd = ::open(input_file.c_str(), O_RDONLY); - REQUIRE(fd > 0); + int fd = ::open(input_file.c_str(), O_RDONLY); + REQUIRE(fd > 0); - size_t size = 0; - std::string all; - { - osmium::io::Bzip2Decompressor decomp(fd); - for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) { - size += data.size(); - all += data; + size_t size = 0; + std::string all; + { + osmium::io::Bzip2Decompressor decomp(fd); + for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) { + size += data.size(); + all += data; + } } + + REQUIRE(9 == size); + REQUIRE("TESTDATA\n" == all); } - REQUIRE(9 == size); - REQUIRE("TESTDATA\n" == all); -} - } diff --git a/test/t/io/test_file_formats.cpp b/test/t/io/test_file_formats.cpp index 03f95784c..e8785d6a4 100644 --- a/test/t/io/test_file_formats.cpp +++ b/test/t/io/test_file_formats.cpp @@ -6,246 +6,246 @@ TEST_CASE("FileFormats") { -SECTION("default_file_format") { - osmium::io::File f; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("default_file_format") { + osmium::io::File f; + REQUIRE(osmium::io::file_format::unknown == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("stdin_stdout_empty") { - osmium::io::File f {""}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("stdin_stdout_empty") { + osmium::io::File f {""}; + REQUIRE(osmium::io::file_format::unknown == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("stdin_stdout_dash") { - osmium::io::File f {"-"}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("stdin_stdout_dash") { + osmium::io::File f {"-"}; + REQUIRE(osmium::io::file_format::unknown == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("stdin_stdout_bz2") { - osmium::io::File f {"-", "osm.bz2"}; - REQUIRE("" == f.filename()); - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("stdin_stdout_bz2") { + osmium::io::File f {"-", "osm.bz2"}; + REQUIRE("" == f.filename()); + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osm") { - osmium::io::File f {"test.osm"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osm") { + osmium::io::File f {"test.osm"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_pbf") { - osmium::io::File f {"test.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_pbf") { + osmium::io::File f {"test.pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osm_pbf") { - osmium::io::File f {"test.osm.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osm_pbf") { + osmium::io::File f {"test.osm.pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_opl") { - osmium::io::File f {"test.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_opl") { + osmium::io::File f {"test.opl"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osm_opl") { - osmium::io::File f {"test.osm.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osm_opl") { + osmium::io::File f {"test.osm.opl"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osm_gz") { - osmium::io::File f {"test.osm.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osm_gz") { + osmium::io::File f {"test.osm.gz"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_opl_bz2") { - osmium::io::File f {"test.osm.opl.bz2"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_opl_bz2") { + osmium::io::File f {"test.osm.opl.bz2"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osc_gz") { - osmium::io::File f {"test.osc.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osc_gz") { + osmium::io::File f {"test.osc.gz"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_opl_gz") { - osmium::io::File f {"test.osh.opl.gz"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_opl_gz") { + osmium::io::File f {"test.osh.opl.gz"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("detect_file_format_by_suffix_osh_pbf") { - osmium::io::File f {"test.osh.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("detect_file_format_by_suffix_osh_pbf") { + osmium::io::File f {"test.osh.pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osm") { - osmium::io::File f {"test", "osm"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osm") { + osmium::io::File f {"test", "osm"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_pbf") { - osmium::io::File f {"test", "pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_pbf") { + osmium::io::File f {"test", "pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osm_pbf") { - osmium::io::File f {"test", "osm.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osm_pbf") { + osmium::io::File f {"test", "osm.pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_opl") { - osmium::io::File f {"test", "opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_opl") { + osmium::io::File f {"test", "opl"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osm_opl") { - osmium::io::File f {"test", "osm.opl"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osm_opl") { + osmium::io::File f {"test", "osm.opl"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osm_gz") { - osmium::io::File f {"test", "osm.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osm_gz") { + osmium::io::File f {"test", "osm.gz"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osm_opl_bz2") { - osmium::io::File f {"test", "osm.opl.bz2"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); - REQUIRE(false == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osm_opl_bz2") { + osmium::io::File f {"test", "osm.opl.bz2"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::bzip2 == f.compression()); + REQUIRE(false == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osc_gz") { - osmium::io::File f {"test", "osc.gz"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osc_gz") { + osmium::io::File f {"test", "osc.gz"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osh_opl_gz") { - osmium::io::File f {"test", "osh.opl.gz"}; - REQUIRE(osmium::io::file_format::opl == f.format()); - REQUIRE(osmium::io::file_compression::gzip == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osh_opl_gz") { + osmium::io::File f {"test", "osh.opl.gz"}; + REQUIRE(osmium::io::file_format::opl == f.format()); + REQUIRE(osmium::io::file_compression::gzip == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("override_file_format_by_suffix_osh_pbf") { - osmium::io::File f {"test", "osh.pbf"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("override_file_format_by_suffix_osh_pbf") { + osmium::io::File f {"test", "osh.pbf"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("format_options_pbf_history") { - osmium::io::File f {"test", "pbf,history=true"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE(true == f.has_multiple_object_versions()); - f.check(); -} + SECTION("format_options_pbf_history") { + osmium::io::File f {"test", "pbf,history=true"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE(true == f.has_multiple_object_versions()); + f.check(); + } -SECTION("format_options_pbf_foo") { - osmium::io::File f {"test.osm", "pbf,foo=bar"}; - REQUIRE(osmium::io::file_format::pbf == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE("bar" == f.get("foo")); - f.check(); -} + SECTION("format_options_pbf_foo") { + osmium::io::File f {"test.osm", "pbf,foo=bar"}; + REQUIRE(osmium::io::file_format::pbf == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE("bar" == f.get("foo")); + f.check(); + } -SECTION("format_options_xml_abc_something") { - osmium::io::File f {"test.bla", "xml,abc,some=thing"}; - REQUIRE(osmium::io::file_format::xml == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE("true" == f.get("abc")); - REQUIRE("thing" == f.get("some")); - REQUIRE(2 == std::distance(f.begin(), f.end())); - f.check(); -} + SECTION("format_options_xml_abc_something") { + osmium::io::File f {"test.bla", "xml,abc,some=thing"}; + REQUIRE(osmium::io::file_format::xml == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE("true" == f.get("abc")); + REQUIRE("thing" == f.get("some")); + REQUIRE(2 == std::distance(f.begin(), f.end())); + f.check(); + } -SECTION("unknown_format_foo_bar") { - osmium::io::File f {"test.foo.bar"}; - REQUIRE(osmium::io::file_format::unknown == f.format()); - REQUIRE(osmium::io::file_compression::none == f.compression()); - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("unknown_format_foo_bar") { + osmium::io::File f {"test.foo.bar"}; + REQUIRE(osmium::io::file_format::unknown == f.format()); + REQUIRE(osmium::io::file_compression::none == f.compression()); + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("unknown_format_foo") { - osmium::io::File f {"test", "foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("unknown_format_foo") { + osmium::io::File f {"test", "foo"}; + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("unknown_format_osm_foo") { - osmium::io::File f {"test", "osm.foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("unknown_format_osm_foo") { + osmium::io::File f {"test", "osm.foo"}; + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } -SECTION("unknown_format_bla_equals_foo") { - osmium::io::File f {"test", "bla=foo"}; - REQUIRE_THROWS_AS(f.check(), std::runtime_error); -} + SECTION("unknown_format_bla_equals_foo") { + osmium::io::File f {"test", "bla=foo"}; + REQUIRE_THROWS_AS(f.check(), std::runtime_error); + } } diff --git a/test/t/tags/test_filter.cpp b/test/t/tags/test_filter.cpp index e65f63d3b..eefa5b076 100644 --- a/test/t/tags/test_filter.cpp +++ b/test/t/tags/test_filter.cpp @@ -25,192 +25,192 @@ void check_filter(const osmium::TagList& tag_list, const TFilter filter, const s TEST_CASE("Filter") { -SECTION("KeyFilter_matches_some_tags") { - osmium::tags::KeyFilter filter(false); - filter.add(true, "highway").add(true, "railway"); + SECTION("KeyFilter_matches_some_tags") { + osmium::tags::KeyFilter filter(false); + filter.add(true, "highway").add(true, "railway"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, // match - { "name", "Main Street" }, // no match - { "source", "GPS" } // no match - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, // match + { "name", "Main Street" }, // no match + { "source", "GPS" } // no match + }); - std::vector results = { true, false, false }; + std::vector results = { true, false, false }; - check_filter(tag_list, filter, results); -} + check_filter(tag_list, filter, results); + } -SECTION("KeyFilter_iterator_filters_tags") { - osmium::tags::KeyFilter filter(false); - filter.add(true, "highway").add(true, "source"); + SECTION("KeyFilter_iterator_filters_tags") { + osmium::tags::KeyFilter filter(false); + filter.add(true, "highway").add(true, "source"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, // match - { "name", "Main Street" }, // no match - { "source", "GPS" } // no match - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, // match + { "name", "Main Street" }, // no match + { "source", "GPS" } // no match + }); - osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end()); - const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end()); + osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end()); + const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end()); - REQUIRE(2 == std::distance(it, end)); + REQUIRE(2 == std::distance(it, end)); - REQUIRE(it != end); - REQUIRE(std::string("highway") == it->key()); - REQUIRE(std::string("primary") == it->value()); - ++it; - REQUIRE(std::string("source") == it->key()); - REQUIRE(std::string("GPS") == it->value()); - REQUIRE(++it == end); -} + REQUIRE(it != end); + REQUIRE(std::string("highway") == it->key()); + REQUIRE(std::string("primary") == it->value()); + ++it; + REQUIRE(std::string("source") == it->key()); + REQUIRE(std::string("GPS") == it->value()); + REQUIRE(++it == end); + } -SECTION("KeyValueFilter_matches_some_tags") { - osmium::tags::KeyValueFilter filter(false); + SECTION("KeyValueFilter_matches_some_tags") { + osmium::tags::KeyValueFilter filter(false); - filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway"); + filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "railway", "tram" }, + { "source", "GPS" } + }); - std::vector results = {true, true, false}; + std::vector results = {true, true, false}; - check_filter(tag_list, filter, results); -} + check_filter(tag_list, filter, results); + } -SECTION("KeyValueFilter_ordering_matters") { - osmium::tags::KeyValueFilter filter1(false); - filter1.add(true, "highway").add(false, "highway", "road"); + SECTION("KeyValueFilter_ordering_matters") { + osmium::tags::KeyValueFilter filter1(false); + filter1.add(true, "highway").add(false, "highway", "road"); - osmium::tags::KeyValueFilter filter2(false); - filter2.add(false, "highway", "road").add(true, "highway"); + osmium::tags::KeyValueFilter filter2(false); + filter2.add(false, "highway", "road").add(true, "highway"); - osmium::memory::Buffer buffer(10240); + osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { - { "highway", "road" }, - { "name", "Main Street" } - }); + const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { + { "highway", "road" }, + { "name", "Main Street" } + }); - const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); + const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name", "Main Street" } + }); - check_filter(tag_list1, filter1, {true, false}); - check_filter(tag_list1, filter2, {false, false}); - check_filter(tag_list2, filter2, {true, false}); -} + check_filter(tag_list1, filter1, {true, false}); + check_filter(tag_list1, filter2, {false, false}); + check_filter(tag_list2, filter2, {true, false}); + } -SECTION("KeyValueFilter_matches_against_taglist_with_any") { - osmium::tags::KeyValueFilter filter(false); + SECTION("KeyValueFilter_matches_against_taglist_with_any") { + osmium::tags::KeyValueFilter filter(false); - filter.add(true, "highway", "primary").add(true, "name"); + filter.add(true, "highway", "primary").add(true, "name"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "railway", "tram" }, + { "source", "GPS" } + }); - REQUIRE( osmium::tags::match_any_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); -} + REQUIRE( osmium::tags::match_any_of(tag_list, filter)); + REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); + REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); + } -SECTION("KeyValueFilter_matches_against_taglist_with_all") { - osmium::tags::KeyValueFilter filter(false); + SECTION("KeyValueFilter_matches_against_taglist_with_all") { + osmium::tags::KeyValueFilter filter(false); - filter.add(true, "highway", "primary").add(true, "name"); + filter.add(true, "highway", "primary").add(true, "name"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name", "Main Street" } + }); - REQUIRE( osmium::tags::match_any_of(tag_list, filter)); - REQUIRE( osmium::tags::match_all_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); -} + REQUIRE( osmium::tags::match_any_of(tag_list, filter)); + REQUIRE( osmium::tags::match_all_of(tag_list, filter)); + REQUIRE(!osmium::tags::match_none_of(tag_list, filter)); + } -SECTION("KeyValueFilter_matches_against_taglist_with_none") { - osmium::tags::KeyValueFilter filter(false); + SECTION("KeyValueFilter_matches_against_taglist_with_none") { + osmium::tags::KeyValueFilter filter(false); - filter.add(true, "highway", "road").add(true, "source"); + filter.add(true, "highway", "road").add(true, "source"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name", "Main Street" } + }); - REQUIRE(!osmium::tags::match_any_of(tag_list, filter)); - REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); - REQUIRE( osmium::tags::match_none_of(tag_list, filter)); -} + REQUIRE(!osmium::tags::match_any_of(tag_list, filter)); + REQUIRE(!osmium::tags::match_all_of(tag_list, filter)); + REQUIRE( osmium::tags::match_none_of(tag_list, filter)); + } -SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") { - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "railway", "tram" }, - { "source", "GPS" } - }); + SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") { + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "railway", "tram" }, + { "source", "GPS" } + }); - REQUIRE(osmium::tags::match_any_of(tag_list, - osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name"))); -} + REQUIRE(osmium::tags::match_any_of(tag_list, + osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name"))); + } -SECTION("RegexFilter_matches_some_tags") { - osmium::tags::RegexFilter filter(false); - filter.add(true, "highway", std::regex(".*_link")); + SECTION("RegexFilter_matches_some_tags") { + osmium::tags::RegexFilter filter(false); + filter.add(true, "highway", std::regex(".*_link")); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary_link" }, - { "source", "GPS" } - }); - const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "source", "GPS" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, { + { "highway", "primary_link" }, + { "source", "GPS" } + }); + const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "source", "GPS" } + }); - check_filter(tag_list1, filter, {true, false}); - check_filter(tag_list2, filter, {false, false}); -} + check_filter(tag_list1, filter, {true, false}); + check_filter(tag_list2, filter, {false, false}); + } -SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") { - osmium::tags::RegexFilter filter(false); - std::regex r(".*straße"); - filter.add(true, "name", r); + SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") { + osmium::tags::RegexFilter filter(false); + std::regex r(".*straße"); + filter.add(true, "name", r); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Hauptstraße" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name", "Hauptstraße" } + }); - check_filter(tag_list, filter, {false, true}); -} + check_filter(tag_list, filter, {false, true}); + } -SECTION("KeyPrefixFilter_matches_some_tags") { - osmium::tags::KeyPrefixFilter filter(false); - filter.add(true, "name:"); + SECTION("KeyPrefixFilter_matches_some_tags") { + osmium::tags::KeyPrefixFilter filter(false); + filter.add(true, "name:"); - osmium::memory::Buffer buffer(10240); - const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name:de", "Hauptstraße" } - }); + osmium::memory::Buffer buffer(10240); + const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name:de", "Hauptstraße" } + }); - check_filter(tag_list, filter, {false, true}); -} + check_filter(tag_list, filter, {false, true}); + } } diff --git a/test/t/tags/test_operators.cpp b/test/t/tags/test_operators.cpp index e2c22a405..33a53c2a2 100644 --- a/test/t/tags/test_operators.cpp +++ b/test/t/tags/test_operators.cpp @@ -8,54 +8,54 @@ TEST_CASE("Operators") { -SECTION("Equal") { - osmium::memory::Buffer buffer1(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer1); - tl_builder.add_tag("highway", "primary"); - tl_builder.add_tag("name", "Main Street"); - tl_builder.add_tag("source", "GPS"); + SECTION("Equal") { + osmium::memory::Buffer buffer1(10240); + { + osmium::builder::TagListBuilder tl_builder(buffer1); + tl_builder.add_tag("highway", "primary"); + tl_builder.add_tag("name", "Main Street"); + tl_builder.add_tag("source", "GPS"); + } + buffer1.commit(); + + osmium::memory::Buffer buffer2(10240); + { + osmium::builder::TagListBuilder tl_builder(buffer2); + tl_builder.add_tag("highway", "primary"); + } + buffer2.commit(); + + const osmium::TagList& tl1 = buffer1.get(0); + const osmium::TagList& tl2 = buffer2.get(0); + + auto tagit1 = tl1.begin(); + auto tagit2 = tl2.begin(); + REQUIRE(*tagit1 == *tagit2); + ++tagit1; + REQUIRE(!(*tagit1 == *tagit2)); } - buffer1.commit(); - osmium::memory::Buffer buffer2(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer2); - tl_builder.add_tag("highway", "primary"); + SECTION("Order") { + osmium::memory::Buffer buffer(10240); + { + osmium::builder::TagListBuilder tl_builder(buffer); + tl_builder.add_tag("highway", "residential"); + tl_builder.add_tag("highway", "primary"); + tl_builder.add_tag("name", "Main Street"); + tl_builder.add_tag("amenity", "post_box"); + } + buffer.commit(); + + const osmium::TagList& tl = buffer.get(0); + const osmium::Tag& t1 = *(tl.begin()); + const osmium::Tag& t2 = *(std::next(tl.begin(), 1)); + const osmium::Tag& t3 = *(std::next(tl.begin(), 2)); + const osmium::Tag& t4 = *(std::next(tl.begin(), 3)); + + REQUIRE(t2 < t1); + REQUIRE(t1 < t3); + REQUIRE(t2 < t3); + REQUIRE(t4 < t1); } - buffer2.commit(); - - const osmium::TagList& tl1 = buffer1.get(0); - const osmium::TagList& tl2 = buffer2.get(0); - - auto tagit1 = tl1.begin(); - auto tagit2 = tl2.begin(); - REQUIRE(*tagit1 == *tagit2); - ++tagit1; - REQUIRE(!(*tagit1 == *tagit2)); -} - -SECTION("Order") { - osmium::memory::Buffer buffer(10240); - { - osmium::builder::TagListBuilder tl_builder(buffer); - tl_builder.add_tag("highway", "residential"); - tl_builder.add_tag("highway", "primary"); - tl_builder.add_tag("name", "Main Street"); - tl_builder.add_tag("amenity", "post_box"); - } - buffer.commit(); - - const osmium::TagList& tl = buffer.get(0); - const osmium::Tag& t1 = *(tl.begin()); - const osmium::Tag& t2 = *(std::next(tl.begin(), 1)); - const osmium::Tag& t3 = *(std::next(tl.begin(), 2)); - const osmium::Tag& t4 = *(std::next(tl.begin(), 3)); - - REQUIRE(t2 < t1); - REQUIRE(t1 < t3); - REQUIRE(t2 < t3); - REQUIRE(t4 < t1); -} } diff --git a/test/t/tags/test_tag_list.cpp b/test/t/tags/test_tag_list.cpp index b25d8cac7..c2512d125 100644 --- a/test/t/tags/test_tag_list.cpp +++ b/test/t/tags/test_tag_list.cpp @@ -6,71 +6,71 @@ TEST_CASE("tag_list") { -SECTION("can_be_created_from_initializer_list") { - osmium::memory::Buffer buffer(10240); + SECTION("can_be_created_from_initializer_list") { + osmium::memory::Buffer buffer(10240); - const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { - { "highway", "primary" }, - { "name", "Main Street" }, - { "source", "GPS" } - }); + const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, { + { "highway", "primary" }, + { "name", "Main Street" }, + { "source", "GPS" } + }); - REQUIRE(osmium::item_type::tag_list == tl.type()); - REQUIRE(3 == tl.size()); - REQUIRE(std::string("highway") == tl.begin()->key()); - REQUIRE(std::string("primary") == tl.begin()->value()); -} - -SECTION("can_be_created_from_map") { - osmium::memory::Buffer buffer(10240); - - const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map({ - { "highway", "primary" }, - { "name", "Main Street" } - })); - - REQUIRE(osmium::item_type::tag_list == tl.type()); - REQUIRE(2 == tl.size()); - - if (std::string("highway") == tl.begin()->key()) { + REQUIRE(osmium::item_type::tag_list == tl.type()); + REQUIRE(3 == tl.size()); + REQUIRE(std::string("highway") == tl.begin()->key()); REQUIRE(std::string("primary") == tl.begin()->value()); - REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key()); - REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value()); - } else { - REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key()); - REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value()); - REQUIRE(std::string("name") == tl.begin()->key()); - REQUIRE(std::string("Main Street") == tl.begin()->value()); } -} -SECTION("can_be_created_with_callback") { - osmium::memory::Buffer buffer(10240); + SECTION("can_be_created_from_map") { + osmium::memory::Buffer buffer(10240); - const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { - tlb.add_tag("highway", "primary"); - tlb.add_tag("bridge", "true"); - }); + const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map({ + { "highway", "primary" }, + { "name", "Main Street" } + })); - REQUIRE(osmium::item_type::tag_list == tl.type()); - REQUIRE(2 == tl.size()); - REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key()); - REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value()); -} + REQUIRE(osmium::item_type::tag_list == tl.type()); + REQUIRE(2 == tl.size()); -SECTION("returns_value_by_key") { - osmium::memory::Buffer buffer(10240); + if (std::string("highway") == tl.begin()->key()) { + REQUIRE(std::string("primary") == tl.begin()->value()); + REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key()); + REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value()); + } else { + REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key()); + REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value()); + REQUIRE(std::string("name") == tl.begin()->key()); + REQUIRE(std::string("Main Street") == tl.begin()->value()); + } + } - const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { - tlb.add_tag("highway", "primary"); - tlb.add_tag("bridge", "true"); - }); + SECTION("can_be_created_with_callback") { + osmium::memory::Buffer buffer(10240); - REQUIRE(std::string("primary") == tl.get_value_by_key("highway")); - REQUIRE(nullptr == tl.get_value_by_key("name")); - REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo")); + const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { + tlb.add_tag("highway", "primary"); + tlb.add_tag("bridge", "true"); + }); - REQUIRE(std::string("true") == tl["bridge"]); -} + REQUIRE(osmium::item_type::tag_list == tl.type()); + REQUIRE(2 == tl.size()); + REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key()); + REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value()); + } + + SECTION("returns_value_by_key") { + osmium::memory::Buffer buffer(10240); + + const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) { + tlb.add_tag("highway", "primary"); + tlb.add_tag("bridge", "true"); + }); + + REQUIRE(std::string("primary") == tl.get_value_by_key("highway")); + REQUIRE(nullptr == tl.get_value_by_key("name")); + REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo")); + + REQUIRE(std::string("true") == tl["bridge"]); + } } diff --git a/test/t/thread/test_pool.cpp b/test/t/thread/test_pool.cpp index 4bbf9ee59..66bb3734a 100644 --- a/test/t/thread/test_pool.cpp +++ b/test/t/thread/test_pool.cpp @@ -36,7 +36,7 @@ TEST_CASE("thread") { SECTION("can send job to thread pool") { auto& pool = osmium::thread::Pool::instance(); result = 0; - auto future = pool.submit(test_job_ok{}); + auto future = pool.submit(test_job_ok {}); // wait a bit for the other thread to get a chance to run std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -50,7 +50,7 @@ TEST_CASE("thread") { SECTION("can send job to thread pool") { auto& pool = osmium::thread::Pool::instance(); - auto future = pool.submit(test_job_with_result{}); + auto future = pool.submit(test_job_with_result {}); REQUIRE(future.get() == 42); } @@ -60,7 +60,7 @@ TEST_CASE("thread") { result = 0; bool got_exception = false; - auto future = pool.submit(test_job_throw{}); + auto future = pool.submit(test_job_throw {}); REQUIRE_THROWS_AS(future.get(), std::runtime_error); } diff --git a/test/t/util/test_double.cpp b/test/t/util/test_double.cpp index 79e8509b0..6cc87a03a 100644 --- a/test/t/util/test_double.cpp +++ b/test/t/util/test_double.cpp @@ -4,30 +4,30 @@ TEST_CASE("Double") { -SECTION("double2string") { - std::string s1; - osmium::util::double2string(s1, 1.123, 7); - REQUIRE(s1 == "1.123"); + SECTION("double2string") { + std::string s1; + osmium::util::double2string(s1, 1.123, 7); + REQUIRE(s1 == "1.123"); - std::string s2; - osmium::util::double2string(s2, 1.000, 7); - REQUIRE(s2 == "1"); + std::string s2; + osmium::util::double2string(s2, 1.000, 7); + REQUIRE(s2 == "1"); - std::string s3; - osmium::util::double2string(s3, 0.0, 7); - REQUIRE(s3 == "0"); + std::string s3; + osmium::util::double2string(s3, 0.0, 7); + REQUIRE(s3 == "0"); - std::string s4; - osmium::util::double2string(s4, 0.020, 7); - REQUIRE(s4 == "0.02"); + std::string s4; + osmium::util::double2string(s4, 0.020, 7); + REQUIRE(s4 == "0.02"); - std::string s5; - osmium::util::double2string(s5, -0.020, 7); - REQUIRE(s5 == "-0.02"); + std::string s5; + osmium::util::double2string(s5, -0.020, 7); + REQUIRE(s5 == "-0.02"); - std::string s6; - osmium::util::double2string(s6, -0.0, 7); - REQUIRE(s6 == "-0"); -} + std::string s6; + osmium::util::double2string(s6, -0.0, 7); + REQUIRE(s6 == "-0"); + } } diff --git a/test/t/util/test_options.cpp b/test/t/util/test_options.cpp index 203b9db48..969f20103 100644 --- a/test/t/util/test_options.cpp +++ b/test/t/util/test_options.cpp @@ -6,43 +6,43 @@ TEST_CASE("Options") { -SECTION("set_simple") { - osmium::util::Options o; - o.set("foo", "bar"); - REQUIRE("bar" == o.get("foo")); - REQUIRE("" == o.get("empty")); - REQUIRE("default" == o.get("empty", "default")); - REQUIRE(!o.is_true("foo")); - REQUIRE(!o.is_true("empty")); - REQUIRE(1 == o.size()); -} + SECTION("set_simple") { + osmium::util::Options o; + o.set("foo", "bar"); + REQUIRE("bar" == o.get("foo")); + REQUIRE("" == o.get("empty")); + REQUIRE("default" == o.get("empty", "default")); + REQUIRE(!o.is_true("foo")); + REQUIRE(!o.is_true("empty")); + REQUIRE(1 == o.size()); + } -SECTION("set_from_bool") { - osmium::util::Options o; - o.set("t", true); - o.set("f", false); - REQUIRE("true" == o.get("t")); - REQUIRE("false" == o.get("f")); - REQUIRE("" == o.get("empty")); - REQUIRE(o.is_true("t")); - REQUIRE(!o.is_true("f")); - REQUIRE(2 == o.size()); -} + SECTION("set_from_bool") { + osmium::util::Options o; + o.set("t", true); + o.set("f", false); + REQUIRE("true" == o.get("t")); + REQUIRE("false" == o.get("f")); + REQUIRE("" == o.get("empty")); + REQUIRE(o.is_true("t")); + REQUIRE(!o.is_true("f")); + REQUIRE(2 == o.size()); + } -SECTION("set_from_single_string_with_equals") { - osmium::util::Options o; - o.set("foo=bar"); - REQUIRE("bar" == o.get("foo")); - REQUIRE(1 == o.size()); -} + SECTION("set_from_single_string_with_equals") { + osmium::util::Options o; + o.set("foo=bar"); + REQUIRE("bar" == o.get("foo")); + REQUIRE(1 == o.size()); + } -SECTION("set_from_single_string_without_equals") { - osmium::util::Options o; - o.set("foo"); - REQUIRE("true" == o.get("foo")); - REQUIRE(o.is_true("foo")); - REQUIRE(1 == o.size()); -} + SECTION("set_from_single_string_without_equals") { + osmium::util::Options o; + o.set("foo"); + REQUIRE("true" == o.get("foo")); + REQUIRE(o.is_true("foo")); + REQUIRE(1 == o.size()); + } } diff --git a/test/t/util/test_string.cpp b/test/t/util/test_string.cpp index c7b75cf24..fa4978779 100644 --- a/test/t/util/test_string.cpp +++ b/test/t/util/test_string.cpp @@ -4,54 +4,54 @@ TEST_CASE("split_string") { -SECTION("split_string string") { - std::string str { "foo,baramba,baz" }; - std::vector result = {"foo", "baramba", "baz"}; + SECTION("split_string string") { + std::string str { "foo,baramba,baz" }; + std::vector result = {"foo", "baramba", "baz"}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string string without sep") { - std::string str { "foo" }; - std::vector result = {"foo"}; + SECTION("split_string string without sep") { + std::string str { "foo" }; + std::vector result = {"foo"}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string string with empty at end") { - std::string str { "foo,bar," }; - std::vector result = {"foo", "bar", ""}; + SECTION("split_string string with empty at end") { + std::string str { "foo,bar," }; + std::vector result = {"foo", "bar", ""}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string string with empty in middle") { - std::string str { "foo,,bar" }; - std::vector result = {"foo", "", "bar"}; + SECTION("split_string string with empty in middle") { + std::string str { "foo,,bar" }; + std::vector result = {"foo", "", "bar"}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string string with empty at start") { - std::string str { ",bar,baz" }; - std::vector result = {"", "bar", "baz"}; + SECTION("split_string string with empty at start") { + std::string str { ",bar,baz" }; + std::vector result = {"", "bar", "baz"}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string sep") { - std::string str { "," }; - std::vector result = {"", ""}; + SECTION("split_string sep") { + std::string str { "," }; + std::vector result = {"", ""}; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } -SECTION("split_string empty string") { - std::string str { "" }; - std::vector result; + SECTION("split_string empty string") { + std::string str { "" }; + std::vector result; - REQUIRE(result == osmium::split_string(str, ',')); -} + REQUIRE(result == osmium::split_string(str, ',')); + } }