From 07c9a9d3963b6caf48f6b218ce7d98fe7db3121d Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 11:22:32 +0200 Subject: [PATCH 01/35] Peform detection and warning, both on the output side --- src/cmd.hpp | 10 ++++++++++ src/io.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/cmd.hpp b/src/cmd.hpp index d2f574f1..799ccf1b 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -234,6 +234,12 @@ class with_osm_output { osmium::io::File m_output_file; osmium::io::overwrite m_output_overwrite = osmium::io::overwrite::no; osmium::io::fsync m_fsync = osmium::io::fsync::no; + + // detected locations on ways in input data + mutable bool m_found_locations_on_ways = false; + + // warning about lost locations printed + mutable bool m_warned_locations_on_ways = false; public: @@ -262,6 +268,10 @@ class with_osm_output { return m_output_overwrite; } + void check_for_locations_on_ways(const osmium::Way& way); + + void warn_if_locations_on_ways_will_be_lost() const; + }; // class with_osm_output diff --git a/src/io.cpp b/src/io.cpp index d36859bf..8eb19880 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -29,10 +29,12 @@ along with this program. If not, see . #include #include #include +#include #include #include +#include #include #include @@ -229,3 +231,39 @@ void with_osm_output::setup_header(osmium::io::Header& header, const osmium::io: init_header(header, input_header, m_output_headers); } +void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) { + if (m_found_locations_on_ways) { + return; + } + + for (const auto& node : way.nodes()) { + if (node.location().valid()) { + m_found_locations_on_ways = true; + return; + } + } +} + +void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { + if (!m_found_locations_on_ways || m_warned_locations_on_ways) { + return; + } + + const auto& options = m_output_file.options(); + if (options.get("locations_on_ways") == "true") { + return; + } + + std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; + + if (m_output_file.format() == osmium::file_format::pbf || + m_output_file.format() == osmium::file_format::xml || + m_output_file.format() == osmium::file_format::opl) { + std::cerr << "Use --output-format=" << m_output_file.format_as_string() << ",locations_on_ways to preserve node locations on ways.\n"; + } else { + std::cerr << "Output format does not support preserving node locations on ways.\n"; + } + + m_warned_locations_on_ways = true; +} + From 2c9ba8cdce60c7bdabf01edc1ffe99aaa70f37b5 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 11:28:21 +0200 Subject: [PATCH 02/35] Add check_buffer_for_locations_on_ways --- src/cmd.hpp | 4 ++++ src/io.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/cmd.hpp b/src/cmd.hpp index 799ccf1b..5affc9b0 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -28,7 +28,9 @@ along with this program. If not, see . #include #include #include +#include #include +#include #include #include @@ -270,6 +272,8 @@ class with_osm_output { void check_for_locations_on_ways(const osmium::Way& way); + void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer); + void warn_if_locations_on_ways_will_be_lost() const; }; // class with_osm_output diff --git a/src/io.cpp b/src/io.cpp index 8eb19880..125f98ca 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -244,6 +244,19 @@ void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) { } } +void with_osm_output::check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) { + if (m_found_locations_on_ways) { + return; + } + + for (const auto& way : buffer.select()) { + check_for_locations_on_ways(way); + if (m_found_locations_on_ways) { + return; + } + } +} + void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { if (!m_found_locations_on_ways || m_warned_locations_on_ways) { return; From 75957adb8263e00c29a4244be979d4cd5e497916 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 11:38:11 +0200 Subject: [PATCH 03/35] Make methods const, fix build errors --- src/cmd.hpp | 4 ++-- src/command_cat.cpp | 4 ++++ src/io.cpp | 18 ++++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/cmd.hpp b/src/cmd.hpp index 5affc9b0..1b73d8ee 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -270,9 +270,9 @@ class with_osm_output { return m_output_overwrite; } - void check_for_locations_on_ways(const osmium::Way& way); + void check_for_locations_on_ways(const osmium::Way& way) const; - void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer); + void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const; void warn_if_locations_on_ways_will_be_lost() const; diff --git a/src/command_cat.cpp b/src/command_cat.cpp index a4d627e7..40679b56 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -100,6 +100,8 @@ void CommandCat::copy(osmium::ProgressBar& progress_bar, osmium::io::Reader& rea while (osmium::memory::Buffer buffer = reader.read()) { progress_bar.update(reader.offset()); + check_buffer_for_locations_on_ways(buffer); + m_clean.apply_to(buffer); writer(std::move(buffer)); @@ -112,6 +114,8 @@ std::size_t CommandCat::read_buffers(osmium::ProgressBar& progress_bar, osmium:: while (osmium::memory::Buffer buffer = reader.read()) { progress_bar.update(reader.offset()); + check_buffer_for_locations_on_ways(buffer); + m_clean.apply_to(buffer); size += buffer.committed(); diff --git a/src/io.cpp b/src/io.cpp index 125f98ca..e9dac4a3 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -208,6 +208,7 @@ void with_osm_output::show_output_arguments(osmium::VerboseOutput& vout) { } void with_osm_output::setup_header(osmium::io::Header& header) const { + warn_if_locations_on_ways_will_be_lost(); header.set("generator", m_generator); for (const auto& h : m_output_headers) { header.set(h); @@ -227,11 +228,12 @@ void init_header(osmium::io::Header& header, const osmium::io::Header& input_hea } void with_osm_output::setup_header(osmium::io::Header& header, const osmium::io::Header& input_header) const { + warn_if_locations_on_ways_will_be_lost(); header.set("generator", m_generator); init_header(header, input_header, m_output_headers); } -void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) { +void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) const { if (m_found_locations_on_ways) { return; } @@ -244,7 +246,7 @@ void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) { } } -void with_osm_output::check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) { +void with_osm_output::check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const { if (m_found_locations_on_ways) { return; } @@ -262,20 +264,12 @@ void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { return; } - const auto& options = m_output_file.options(); - if (options.get("locations_on_ways") == "true") { + if (m_output_format.find("locations_on_ways") != std::string::npos) { return; } std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; - - if (m_output_file.format() == osmium::file_format::pbf || - m_output_file.format() == osmium::file_format::xml || - m_output_file.format() == osmium::file_format::opl) { - std::cerr << "Use --output-format=" << m_output_file.format_as_string() << ",locations_on_ways to preserve node locations on ways.\n"; - } else { - std::cerr << "Output format does not support preserving node locations on ways.\n"; - } + std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; m_warned_locations_on_ways = true; } From fb5af6df7b31ae1b5a47c00691a7e0f98fa9e5c3 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 11:51:35 +0200 Subject: [PATCH 04/35] Move from setup_header() to warn_about_locations_on_ways() --- src/cmd.hpp | 2 ++ src/command_cat.cpp | 3 +++ src/io.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cmd.hpp b/src/cmd.hpp index 1b73d8ee..19407499 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -275,6 +275,8 @@ class with_osm_output { void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const; void warn_if_locations_on_ways_will_be_lost() const; + + void warn_about_locations_on_ways() const; }; // class with_osm_output diff --git a/src/command_cat.cpp b/src/command_cat.cpp index 40679b56..c425c659 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -185,6 +185,7 @@ bool CommandCat::run() { copy(progress_bar, reader, writer); progress_bar.done(); } + warn_about_locations_on_ways(); bytes_written = writer.close(); reader.close(); } else { // multiple input files @@ -210,6 +211,7 @@ bool CommandCat::run() { m_vout << "Writing data...\n"; osmium::ProgressBar progress_bar_writer{size, display_progress()}; write_buffers(progress_bar_writer, buffers, writer); + warn_about_locations_on_ways(); bytes_written = writer.close(); progress_bar_writer.done(); } else { @@ -222,6 +224,7 @@ bool CommandCat::run() { progress_bar.file_done(reader.file_size()); reader.close(); } + warn_about_locations_on_ways(); bytes_written = writer.close(); progress_bar.done(); } diff --git a/src/io.cpp b/src/io.cpp index e9dac4a3..a2abb4ff 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -208,7 +208,6 @@ void with_osm_output::show_output_arguments(osmium::VerboseOutput& vout) { } void with_osm_output::setup_header(osmium::io::Header& header) const { - warn_if_locations_on_ways_will_be_lost(); header.set("generator", m_generator); for (const auto& h : m_output_headers) { header.set(h); @@ -228,7 +227,6 @@ void init_header(osmium::io::Header& header, const osmium::io::Header& input_hea } void with_osm_output::setup_header(osmium::io::Header& header, const osmium::io::Header& input_header) const { - warn_if_locations_on_ways_will_be_lost(); header.set("generator", m_generator); init_header(header, input_header, m_output_headers); } @@ -274,3 +272,7 @@ void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { m_warned_locations_on_ways = true; } +void with_osm_output::warn_about_locations_on_ways() const { + warn_if_locations_on_ways_will_be_lost(); +} + From 3d00dc880c5842d364cfc3848ad2342b318978ca Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:03:59 +0200 Subject: [PATCH 05/35] Add public getters and cat cmd unit tests --- src/cmd.hpp | 8 ++++ test/CMakeLists.txt | 1 + test/cat/input-with-locations.osm | 12 ++++++ test/cat/test_warning.cpp | 62 +++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 test/cat/input-with-locations.osm create mode 100644 test/cat/test_warning.cpp diff --git a/src/cmd.hpp b/src/cmd.hpp index 19407499..cd662615 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -270,6 +270,14 @@ class with_osm_output { return m_output_overwrite; } + bool found_locations_on_ways() const { + return m_found_locations_on_ways; + } + + bool warned_locations_on_ways() const { + return m_warned_locations_on_ways; + } + void check_for_locations_on_ways(const osmium::Way& way) const; void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f3eb779f..edbe109c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories(../include) set(ALL_UNIT_TESTS cat/test_setup.cpp + cat/test_warning.cpp diff/test_setup.cpp extract/test_unit.cpp time-filter/test_setup.cpp diff --git a/test/cat/input-with-locations.osm b/test/cat/input-with-locations.osm new file mode 100644 index 00000000..12cd563f --- /dev/null +++ b/test/cat/input-with-locations.osm @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/cat/test_warning.cpp b/test/cat/test_warning.cpp new file mode 100644 index 00000000..1cd192b4 --- /dev/null +++ b/test/cat/test_warning.cpp @@ -0,0 +1,62 @@ +#include "test.hpp" // IWYU pragma: keep + +#include "command_cat.hpp" + +#include +#include + +TEST_CASE("locations on ways warning") { + const CommandFactory factory; + CommandCat cmd{factory}; + + SECTION("detection logic with way containing locations") { + cmd.setup({"test/cat/input-with-locations.osm", "-f", "xml"}); + + REQUIRE(cmd.found_locations_on_ways() == false); + REQUIRE(cmd.warned_locations_on_ways() == false); + + osmium::memory::Buffer buffer{1024}; + osmium::builder::WayBuilder builder{buffer}; + builder.set_id(123); + builder.set_version(1); + builder.set_changeset(1); + builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); + builder.set_uid(1); + builder.set_user("test"); + + osmium::builder::WayNodeListBuilder wnl_builder{builder}; + wnl_builder.add_node_ref(10, osmium::Location{1.0, 1.0}); + wnl_builder.add_node_ref(11, osmium::Location{2.0, 1.0}); + + const auto& way = buffer.get(0); + cmd.check_for_locations_on_ways(way); + + REQUIRE(cmd.found_locations_on_ways() == true); + REQUIRE(cmd.warned_locations_on_ways() == false); + } + + SECTION("detection logic with way without locations") { + cmd.setup({"test/cat/input.osm", "-f", "xml"}); + + REQUIRE(cmd.found_locations_on_ways() == false); + + osmium::memory::Buffer buffer{1024}; + osmium::builder::WayBuilder builder{buffer}; + builder.set_id(123); + builder.set_version(1); + builder.set_changeset(1); + builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); + builder.set_uid(1); + builder.set_user("test"); + + osmium::builder::WayNodeListBuilder wnl_builder{builder}; + wnl_builder.add_node_ref(10); + wnl_builder.add_node_ref(11); + + const auto& way = buffer.get(0); + cmd.check_for_locations_on_ways(way); + + REQUIRE(cmd.found_locations_on_ways() == false); + } + +} \ No newline at end of file From cb950e35df2fd771058afe94550ec30212637ef5 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:06:43 +0200 Subject: [PATCH 06/35] Add format param to the unit tests --- test/cat/test_warning.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/cat/test_warning.cpp b/test/cat/test_warning.cpp index 1cd192b4..cc153f59 100644 --- a/test/cat/test_warning.cpp +++ b/test/cat/test_warning.cpp @@ -7,10 +7,13 @@ TEST_CASE("locations on ways warning") { const CommandFactory factory; - CommandCat cmd{factory}; - SECTION("detection logic with way containing locations") { - cmd.setup({"test/cat/input-with-locations.osm", "-f", "xml"}); + auto format = GENERATE("xml", "pbf", "opl"); + + SECTION("detection logic with way containing locations - " + std::string(format)) { + CommandCat cmd{factory}; + std::vector args = {"test/cat/input-with-locations.osm", "-f", format}; + cmd.setup(args); REQUIRE(cmd.found_locations_on_ways() == false); REQUIRE(cmd.warned_locations_on_ways() == false); @@ -35,8 +38,10 @@ TEST_CASE("locations on ways warning") { REQUIRE(cmd.warned_locations_on_ways() == false); } - SECTION("detection logic with way without locations") { - cmd.setup({"test/cat/input.osm", "-f", "xml"}); + SECTION("detection logic with way without locations - " + std::string(format)) { + CommandCat cmd{factory}; + std::vector args = {"test/cat/input.osm", "-f", format}; + cmd.setup(args); REQUIRE(cmd.found_locations_on_ways() == false); From 51071e2110526886d3b469294c4236245517281b Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:10:42 +0200 Subject: [PATCH 07/35] Modify the sort cmd --- src/command_sort.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 8ff3dc49..33a9c693 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -126,6 +126,7 @@ bool CommandSort::run_single_pass() { buffers_size += buffer.committed(); buffers_capacity += buffer.capacity(); progress_bar.update(reader.offset()); + check_buffer_for_locations_on_ways(buffer); osmium::apply(buffer, objects); data.push_back(std::move(buffer)); } @@ -161,6 +162,7 @@ bool CommandSort::run_single_pass() { std::copy(objects.begin(), objects.end(), out); m_vout << "Closing output file...\n"; + warn_about_locations_on_ways(); writer.close(); show_memory_used(); @@ -212,6 +214,9 @@ bool CommandSort::run_multi_pass() { buffers_size += buffer.committed(); buffers_capacity += buffer.capacity(); progress_bar.update(reader.offset()); + if (entity == osmium::osm_entity_bits::way) { + check_buffer_for_locations_on_ways(buffer); + } osmium::apply(buffer, objects); data.push_back(std::move(buffer)); } @@ -245,6 +250,7 @@ bool CommandSort::run_multi_pass() { progress_bar.done(); m_vout << "Closing output file...\n"; + warn_about_locations_on_ways(); writer.close(); show_memory_used(); From 7dfa762676d41236e00d95b6cd8474e59625ee5c Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:15:31 +0200 Subject: [PATCH 08/35] Add parametrized unit tests for sort --- test/CMakeLists.txt | 1 + test/sort/test_warning.cpp | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/sort/test_warning.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index edbe109c..fbd91097 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,7 @@ set(ALL_UNIT_TESTS cat/test_warning.cpp diff/test_setup.cpp extract/test_unit.cpp + sort/test_warning.cpp time-filter/test_setup.cpp util/test_unit.cpp ) diff --git a/test/sort/test_warning.cpp b/test/sort/test_warning.cpp new file mode 100644 index 00000000..dae860dc --- /dev/null +++ b/test/sort/test_warning.cpp @@ -0,0 +1,67 @@ +#include "test.hpp" // IWYU pragma: keep + +#include "command_sort.hpp" + +#include +#include + +TEST_CASE("sort locations on ways warning") { + const CommandFactory factory; + + auto format = GENERATE("xml", "pbf", "opl"); + + SECTION("detection logic with way containing locations - " + std::string(format)) { + CommandSort cmd{factory}; + std::vector args = {"test/sort/input-simple1.osm", "-f", format}; + cmd.setup(args); + + REQUIRE(cmd.found_locations_on_ways() == false); + REQUIRE(cmd.warned_locations_on_ways() == false); + + osmium::memory::Buffer buffer{1024}; + osmium::builder::WayBuilder builder{buffer}; + builder.set_id(123); + builder.set_version(1); + builder.set_changeset(1); + builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); + builder.set_uid(1); + builder.set_user("test"); + + osmium::builder::WayNodeListBuilder wnl_builder{builder}; + wnl_builder.add_node_ref(10, osmium::Location{1.0, 1.0}); + wnl_builder.add_node_ref(11, osmium::Location{2.0, 1.0}); + + const auto& way = buffer.get(0); + cmd.check_for_locations_on_ways(way); + + REQUIRE(cmd.found_locations_on_ways() == true); + REQUIRE(cmd.warned_locations_on_ways() == false); + } + + SECTION("detection logic with way without locations - " + std::string(format)) { + CommandSort cmd{factory}; + std::vector args = {"test/sort/input-simple1.osm", "-f", format}; + cmd.setup(args); + + REQUIRE(cmd.found_locations_on_ways() == false); + + osmium::memory::Buffer buffer{1024}; + osmium::builder::WayBuilder builder{buffer}; + builder.set_id(123); + builder.set_version(1); + builder.set_changeset(1); + builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); + builder.set_uid(1); + builder.set_user("test"); + + osmium::builder::WayNodeListBuilder wnl_builder{builder}; + wnl_builder.add_node_ref(10); + wnl_builder.add_node_ref(11); + + const auto& way = buffer.get(0); + cmd.check_for_locations_on_ways(way); + + REQUIRE(cmd.found_locations_on_ways() == false); + } + +} \ No newline at end of file From 8fe280039a31c7797fbb971871f788f80287faa6 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:22:51 +0200 Subject: [PATCH 09/35] Add integration tests for cat --- test/cat/CMakeLists.txt | 16 ++++++++++++ test/cat/run_test_check_stderr.cmake | 38 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 test/cat/run_test_check_stderr.cmake diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index 05192ff0..c2c0c3a9 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,6 +14,18 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() +function(check_warning _name _input _format _expected_stderr) + set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o /tmp/test-warning-output.osm --overwrite") + add_test( + NAME "cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -26,5 +38,9 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) +check_warning(warning-xml input-with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output.") +check_warning(warning-pbf input-with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output.") +check_warning(warning-opl input-with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output.") + #----------------------------------------------------------------------------- diff --git a/test/cat/run_test_check_stderr.cmake b/test/cat/run_test_check_stderr.cmake new file mode 100644 index 00000000..fa44ea3a --- /dev/null +++ b/test/cat/run_test_check_stderr.cmake @@ -0,0 +1,38 @@ +# +# Runs a test command and checks that stderr contains expected warning message. +# Used for testing warning functionality. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +if(NOT expected_stderr) + message(FATAL_ERROR "Variable 'expected_stderr' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "${expected_stderr}" _found_pos) +if(_found_pos EQUAL -1) + message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file From 00f056b164eab9745ec22744831978631576cae4 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:26:50 +0200 Subject: [PATCH 10/35] Add integration tests for sort --- test/sort/CMakeLists.txt | 25 ++++++++++++++++++ test/sort/input-with-locations.osm | 12 +++++++++ test/sort/run_test_check_stderr.cmake | 38 +++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 test/sort/input-with-locations.osm create mode 100644 test/sort/run_test_check_stderr.cmake diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index ba8d7ef4..4d9e88b9 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,6 +16,27 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() +function(check_sort_warning _name _input _format _expected_stderr) + set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output.osm --overwrite") + add_test( + NAME "sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output-mp.osm --overwrite") + add_test( + NAME "sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -32,4 +53,8 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) +check_sort_warning(warning-xml input-with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output.") +check_sort_warning(warning-pbf input-with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output.") +check_sort_warning(warning-opl input-with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output.") + #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm b/test/sort/input-with-locations.osm new file mode 100644 index 00000000..12cd563f --- /dev/null +++ b/test/sort/input-with-locations.osm @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/sort/run_test_check_stderr.cmake b/test/sort/run_test_check_stderr.cmake new file mode 100644 index 00000000..fa44ea3a --- /dev/null +++ b/test/sort/run_test_check_stderr.cmake @@ -0,0 +1,38 @@ +# +# Runs a test command and checks that stderr contains expected warning message. +# Used for testing warning functionality. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +if(NOT expected_stderr) + message(FATAL_ERROR "Variable 'expected_stderr' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "${expected_stderr}" _found_pos) +if(_found_pos EQUAL -1) + message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file From aa7974b7566baac47cb5b64a4e26782661f7d5cc Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 12:42:38 +0200 Subject: [PATCH 11/35] Remove warn_about_locations_on_ways() --- src/cmd.hpp | 2 -- src/command_cat.cpp | 6 +++--- src/command_sort.cpp | 4 ++-- src/io.cpp | 3 --- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/cmd.hpp b/src/cmd.hpp index cd662615..14a44c7b 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -283,8 +283,6 @@ class with_osm_output { void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const; void warn_if_locations_on_ways_will_be_lost() const; - - void warn_about_locations_on_ways() const; }; // class with_osm_output diff --git a/src/command_cat.cpp b/src/command_cat.cpp index c425c659..87f816f2 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -185,7 +185,7 @@ bool CommandCat::run() { copy(progress_bar, reader, writer); progress_bar.done(); } - warn_about_locations_on_ways(); + warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); reader.close(); } else { // multiple input files @@ -211,7 +211,7 @@ bool CommandCat::run() { m_vout << "Writing data...\n"; osmium::ProgressBar progress_bar_writer{size, display_progress()}; write_buffers(progress_bar_writer, buffers, writer); - warn_about_locations_on_ways(); + warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); progress_bar_writer.done(); } else { @@ -224,7 +224,7 @@ bool CommandCat::run() { progress_bar.file_done(reader.file_size()); reader.close(); } - warn_about_locations_on_ways(); + warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); progress_bar.done(); } diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 33a9c693..dcfb6ff3 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -162,7 +162,7 @@ bool CommandSort::run_single_pass() { std::copy(objects.begin(), objects.end(), out); m_vout << "Closing output file...\n"; - warn_about_locations_on_ways(); + warn_if_locations_on_ways_will_be_lost(); writer.close(); show_memory_used(); @@ -250,7 +250,7 @@ bool CommandSort::run_multi_pass() { progress_bar.done(); m_vout << "Closing output file...\n"; - warn_about_locations_on_ways(); + warn_if_locations_on_ways_will_be_lost(); writer.close(); show_memory_used(); diff --git a/src/io.cpp b/src/io.cpp index a2abb4ff..96aaf6be 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -272,7 +272,4 @@ void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { m_warned_locations_on_ways = true; } -void with_osm_output::warn_about_locations_on_ways() const { - warn_if_locations_on_ways_will_be_lost(); -} From 743c15f07663fe7cb7f8eb5763633b4b6931ad2b Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 15:19:41 +0200 Subject: [PATCH 12/35] Sort alphabetically and add 2 entries --- .gitattributes | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index f725b6e6..4b0ede08 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,8 +4,10 @@ *.osh -crlf *.pg -crlf *-result.txt -crlf +test/cat/output* -crlf +test/diff/output* -crlf test/export/*.geojson -crlf test/export/*.geojsonseq -crlf test/export/*.txt -crlf -test/diff/output* -crlf test/show/output* -crlf +test/sort/output* -crlf From bb98b63a519bcb8acdf8c8712027be223f72f44a Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 21:53:45 +0200 Subject: [PATCH 13/35] Check the PBF header only --- src/cmd.hpp | 22 --------- src/command_cat.cpp | 9 +--- src/command_sort.cpp | 6 --- src/io.cpp | 49 ++++---------------- test/CMakeLists.txt | 2 - test/cat/CMakeLists.txt | 16 ------- test/cat/input-with-locations.osm | 12 ----- test/cat/run_test_check_stderr.cmake | 38 --------------- test/cat/test_warning.cpp | 67 --------------------------- test/sort/CMakeLists.txt | 25 ---------- test/sort/input-with-locations.osm | 12 ----- test/sort/run_test_check_stderr.cmake | 38 --------------- test/sort/test_warning.cpp | 67 --------------------------- 13 files changed, 11 insertions(+), 352 deletions(-) delete mode 100644 test/cat/input-with-locations.osm delete mode 100644 test/cat/run_test_check_stderr.cmake delete mode 100644 test/cat/test_warning.cpp delete mode 100644 test/sort/input-with-locations.osm delete mode 100644 test/sort/run_test_check_stderr.cmake delete mode 100644 test/sort/test_warning.cpp diff --git a/src/cmd.hpp b/src/cmd.hpp index 14a44c7b..d2f574f1 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -28,9 +28,7 @@ along with this program. If not, see . #include #include #include -#include #include -#include #include #include @@ -236,12 +234,6 @@ class with_osm_output { osmium::io::File m_output_file; osmium::io::overwrite m_output_overwrite = osmium::io::overwrite::no; osmium::io::fsync m_fsync = osmium::io::fsync::no; - - // detected locations on ways in input data - mutable bool m_found_locations_on_ways = false; - - // warning about lost locations printed - mutable bool m_warned_locations_on_ways = false; public: @@ -270,20 +262,6 @@ class with_osm_output { return m_output_overwrite; } - bool found_locations_on_ways() const { - return m_found_locations_on_ways; - } - - bool warned_locations_on_ways() const { - return m_warned_locations_on_ways; - } - - void check_for_locations_on_ways(const osmium::Way& way) const; - - void check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const; - - void warn_if_locations_on_ways_will_be_lost() const; - }; // class with_osm_output diff --git a/src/command_cat.cpp b/src/command_cat.cpp index 87f816f2..77c3a5da 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -100,8 +100,6 @@ void CommandCat::copy(osmium::ProgressBar& progress_bar, osmium::io::Reader& rea while (osmium::memory::Buffer buffer = reader.read()) { progress_bar.update(reader.offset()); - check_buffer_for_locations_on_ways(buffer); - m_clean.apply_to(buffer); writer(std::move(buffer)); @@ -114,8 +112,6 @@ std::size_t CommandCat::read_buffers(osmium::ProgressBar& progress_bar, osmium:: while (osmium::memory::Buffer buffer = reader.read()) { progress_bar.update(reader.offset()); - check_buffer_for_locations_on_ways(buffer); - m_clean.apply_to(buffer); size += buffer.committed(); @@ -166,7 +162,7 @@ bool CommandCat::run() { report_filename(&m_vout, m_input_files[0], reader); - setup_header(header); + setup_header(header, reader.header()); osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; if (m_buffer_data) { @@ -185,7 +181,6 @@ bool CommandCat::run() { copy(progress_bar, reader, writer); progress_bar.done(); } - warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); reader.close(); } else { // multiple input files @@ -211,7 +206,6 @@ bool CommandCat::run() { m_vout << "Writing data...\n"; osmium::ProgressBar progress_bar_writer{size, display_progress()}; write_buffers(progress_bar_writer, buffers, writer); - warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); progress_bar_writer.done(); } else { @@ -224,7 +218,6 @@ bool CommandCat::run() { progress_bar.file_done(reader.file_size()); reader.close(); } - warn_if_locations_on_ways_will_be_lost(); bytes_written = writer.close(); progress_bar.done(); } diff --git a/src/command_sort.cpp b/src/command_sort.cpp index dcfb6ff3..8ff3dc49 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -126,7 +126,6 @@ bool CommandSort::run_single_pass() { buffers_size += buffer.committed(); buffers_capacity += buffer.capacity(); progress_bar.update(reader.offset()); - check_buffer_for_locations_on_ways(buffer); osmium::apply(buffer, objects); data.push_back(std::move(buffer)); } @@ -162,7 +161,6 @@ bool CommandSort::run_single_pass() { std::copy(objects.begin(), objects.end(), out); m_vout << "Closing output file...\n"; - warn_if_locations_on_ways_will_be_lost(); writer.close(); show_memory_used(); @@ -214,9 +212,6 @@ bool CommandSort::run_multi_pass() { buffers_size += buffer.committed(); buffers_capacity += buffer.capacity(); progress_bar.update(reader.offset()); - if (entity == osmium::osm_entity_bits::way) { - check_buffer_for_locations_on_ways(buffer); - } osmium::apply(buffer, objects); data.push_back(std::move(buffer)); } @@ -250,7 +245,6 @@ bool CommandSort::run_multi_pass() { progress_bar.done(); m_vout << "Closing output file...\n"; - warn_if_locations_on_ways_will_be_lost(); writer.close(); show_memory_used(); diff --git a/src/io.cpp b/src/io.cpp index 96aaf6be..1eef75e4 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -29,12 +29,10 @@ along with this program. If not, see . #include #include #include -#include #include #include -#include #include #include @@ -229,47 +227,20 @@ void init_header(osmium::io::Header& header, const osmium::io::Header& input_hea void with_osm_output::setup_header(osmium::io::Header& header, const osmium::io::Header& input_header) const { header.set("generator", m_generator); init_header(header, input_header, m_output_headers); -} - -void with_osm_output::check_for_locations_on_ways(const osmium::Way& way) const { - if (m_found_locations_on_ways) { - return; - } - for (const auto& node : way.nodes()) { - if (node.location().valid()) { - m_found_locations_on_ways = true; - return; + // Check if input PBF has locations_on_ways but output format won't preserve them + bool has_locations_on_ways = false; + for (const auto& option : input_header) { + if (option.first.find("pbf_optional_feature") != std::string::npos && + option.second == "LocationsOnWays") { + has_locations_on_ways = true; + break; } } -} - -void with_osm_output::check_buffer_for_locations_on_ways(const osmium::memory::Buffer& buffer) const { - if (m_found_locations_on_ways) { - return; - } - for (const auto& way : buffer.select()) { - check_for_locations_on_ways(way); - if (m_found_locations_on_ways) { - return; - } + if (has_locations_on_ways && m_output_format.find("locations_on_ways") == std::string::npos) { + std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; + std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; } } -void with_osm_output::warn_if_locations_on_ways_will_be_lost() const { - if (!m_found_locations_on_ways || m_warned_locations_on_ways) { - return; - } - - if (m_output_format.find("locations_on_ways") != std::string::npos) { - return; - } - - std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; - std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; - - m_warned_locations_on_ways = true; -} - - diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fbd91097..f3eb779f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,10 +13,8 @@ include_directories(../include) set(ALL_UNIT_TESTS cat/test_setup.cpp - cat/test_warning.cpp diff/test_setup.cpp extract/test_unit.cpp - sort/test_warning.cpp time-filter/test_setup.cpp util/test_unit.cpp ) diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index c2c0c3a9..05192ff0 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,18 +14,6 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() -function(check_warning _name _input _format _expected_stderr) - set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o /tmp/test-warning-output.osm --overwrite") - add_test( - NAME "cat-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_stderr.cmake - ) -endfunction() - #----------------------------------------------------------------------------- @@ -38,9 +26,5 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) -check_warning(warning-xml input-with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output.") -check_warning(warning-pbf input-with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output.") -check_warning(warning-opl input-with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output.") - #----------------------------------------------------------------------------- diff --git a/test/cat/input-with-locations.osm b/test/cat/input-with-locations.osm deleted file mode 100644 index 12cd563f..00000000 --- a/test/cat/input-with-locations.osm +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/test/cat/run_test_check_stderr.cmake b/test/cat/run_test_check_stderr.cmake deleted file mode 100644 index fa44ea3a..00000000 --- a/test/cat/run_test_check_stderr.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# -# Runs a test command and checks that stderr contains expected warning message. -# Used for testing warning functionality. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -if(NOT expected_stderr) - message(FATAL_ERROR "Variable 'expected_stderr' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "${expected_stderr}" _found_pos) -if(_found_pos EQUAL -1) - message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file diff --git a/test/cat/test_warning.cpp b/test/cat/test_warning.cpp deleted file mode 100644 index cc153f59..00000000 --- a/test/cat/test_warning.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "test.hpp" // IWYU pragma: keep - -#include "command_cat.hpp" - -#include -#include - -TEST_CASE("locations on ways warning") { - const CommandFactory factory; - - auto format = GENERATE("xml", "pbf", "opl"); - - SECTION("detection logic with way containing locations - " + std::string(format)) { - CommandCat cmd{factory}; - std::vector args = {"test/cat/input-with-locations.osm", "-f", format}; - cmd.setup(args); - - REQUIRE(cmd.found_locations_on_ways() == false); - REQUIRE(cmd.warned_locations_on_ways() == false); - - osmium::memory::Buffer buffer{1024}; - osmium::builder::WayBuilder builder{buffer}; - builder.set_id(123); - builder.set_version(1); - builder.set_changeset(1); - builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); - builder.set_uid(1); - builder.set_user("test"); - - osmium::builder::WayNodeListBuilder wnl_builder{builder}; - wnl_builder.add_node_ref(10, osmium::Location{1.0, 1.0}); - wnl_builder.add_node_ref(11, osmium::Location{2.0, 1.0}); - - const auto& way = buffer.get(0); - cmd.check_for_locations_on_ways(way); - - REQUIRE(cmd.found_locations_on_ways() == true); - REQUIRE(cmd.warned_locations_on_ways() == false); - } - - SECTION("detection logic with way without locations - " + std::string(format)) { - CommandCat cmd{factory}; - std::vector args = {"test/cat/input.osm", "-f", format}; - cmd.setup(args); - - REQUIRE(cmd.found_locations_on_ways() == false); - - osmium::memory::Buffer buffer{1024}; - osmium::builder::WayBuilder builder{buffer}; - builder.set_id(123); - builder.set_version(1); - builder.set_changeset(1); - builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); - builder.set_uid(1); - builder.set_user("test"); - - osmium::builder::WayNodeListBuilder wnl_builder{builder}; - wnl_builder.add_node_ref(10); - wnl_builder.add_node_ref(11); - - const auto& way = buffer.get(0); - cmd.check_for_locations_on_ways(way); - - REQUIRE(cmd.found_locations_on_ways() == false); - } - -} \ No newline at end of file diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index 4d9e88b9..ba8d7ef4 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,27 +16,6 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() -function(check_sort_warning _name _input _format _expected_stderr) - set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output.osm --overwrite") - add_test( - NAME "sort-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake - ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o /tmp/test-sort-warning-output-mp.osm --overwrite") - add_test( - NAME "sort-${_name}-mp" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd_mp} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake - ) -endfunction() - #----------------------------------------------------------------------------- @@ -53,8 +32,4 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) -check_sort_warning(warning-xml input-with-locations.osm xml "Warning! Input file contains locations on ways that will be lost in output.") -check_sort_warning(warning-pbf input-with-locations.osm pbf "Warning! Input file contains locations on ways that will be lost in output.") -check_sort_warning(warning-opl input-with-locations.osm opl "Warning! Input file contains locations on ways that will be lost in output.") - #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm b/test/sort/input-with-locations.osm deleted file mode 100644 index 12cd563f..00000000 --- a/test/sort/input-with-locations.osm +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/test/sort/run_test_check_stderr.cmake b/test/sort/run_test_check_stderr.cmake deleted file mode 100644 index fa44ea3a..00000000 --- a/test/sort/run_test_check_stderr.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# -# Runs a test command and checks that stderr contains expected warning message. -# Used for testing warning functionality. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -if(NOT expected_stderr) - message(FATAL_ERROR "Variable 'expected_stderr' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "${expected_stderr}" _found_pos) -if(_found_pos EQUAL -1) - message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file diff --git a/test/sort/test_warning.cpp b/test/sort/test_warning.cpp deleted file mode 100644 index dae860dc..00000000 --- a/test/sort/test_warning.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "test.hpp" // IWYU pragma: keep - -#include "command_sort.hpp" - -#include -#include - -TEST_CASE("sort locations on ways warning") { - const CommandFactory factory; - - auto format = GENERATE("xml", "pbf", "opl"); - - SECTION("detection logic with way containing locations - " + std::string(format)) { - CommandSort cmd{factory}; - std::vector args = {"test/sort/input-simple1.osm", "-f", format}; - cmd.setup(args); - - REQUIRE(cmd.found_locations_on_ways() == false); - REQUIRE(cmd.warned_locations_on_ways() == false); - - osmium::memory::Buffer buffer{1024}; - osmium::builder::WayBuilder builder{buffer}; - builder.set_id(123); - builder.set_version(1); - builder.set_changeset(1); - builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); - builder.set_uid(1); - builder.set_user("test"); - - osmium::builder::WayNodeListBuilder wnl_builder{builder}; - wnl_builder.add_node_ref(10, osmium::Location{1.0, 1.0}); - wnl_builder.add_node_ref(11, osmium::Location{2.0, 1.0}); - - const auto& way = buffer.get(0); - cmd.check_for_locations_on_ways(way); - - REQUIRE(cmd.found_locations_on_ways() == true); - REQUIRE(cmd.warned_locations_on_ways() == false); - } - - SECTION("detection logic with way without locations - " + std::string(format)) { - CommandSort cmd{factory}; - std::vector args = {"test/sort/input-simple1.osm", "-f", format}; - cmd.setup(args); - - REQUIRE(cmd.found_locations_on_ways() == false); - - osmium::memory::Buffer buffer{1024}; - osmium::builder::WayBuilder builder{buffer}; - builder.set_id(123); - builder.set_version(1); - builder.set_changeset(1); - builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"}); - builder.set_uid(1); - builder.set_user("test"); - - osmium::builder::WayNodeListBuilder wnl_builder{builder}; - wnl_builder.add_node_ref(10); - wnl_builder.add_node_ref(11); - - const auto& way = buffer.get(0); - cmd.check_for_locations_on_ways(way); - - REQUIRE(cmd.found_locations_on_ways() == false); - } - -} \ No newline at end of file From ca613a83dc2837ff70064a2a2d45ab7a848885e1 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 22:00:21 +0200 Subject: [PATCH 14/35] Add cat tests --- test/cat/CMakeLists.txt | 15 ++++++++++ test/cat/input-with-locations.osm.pbf | Bin 0 -> 181 bytes test/cat/run_test_check_stderr.cmake | 38 ++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 test/cat/input-with-locations.osm.pbf create mode 100644 test/cat/run_test_check_stderr.cmake diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index 05192ff0..e590c786 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,6 +14,18 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() +function(check_warning _name _input _format _expected_stderr) + set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o /tmp/test-warning-output.osm --overwrite") + add_test( + NAME "cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -26,5 +38,8 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) +check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") +check_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") + #----------------------------------------------------------------------------- diff --git a/test/cat/input-with-locations.osm.pbf b/test/cat/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c GIT binary patch literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN literal 0 HcmV?d00001 diff --git a/test/cat/run_test_check_stderr.cmake b/test/cat/run_test_check_stderr.cmake new file mode 100644 index 00000000..fa44ea3a --- /dev/null +++ b/test/cat/run_test_check_stderr.cmake @@ -0,0 +1,38 @@ +# +# Runs a test command and checks that stderr contains expected warning message. +# Used for testing warning functionality. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +if(NOT expected_stderr) + message(FATAL_ERROR "Variable 'expected_stderr' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "${expected_stderr}" _found_pos) +if(_found_pos EQUAL -1) + message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file From ea40f08caab8f973a40c336239ed695f17718def Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 30 Aug 2025 22:07:18 +0200 Subject: [PATCH 15/35] Add sort tests, use build dir for temp files --- src/command_sort.cpp | 16 +++++++++-- test/cat/CMakeLists.txt | 2 +- test/sort/CMakeLists.txt | 24 ++++++++++++++++ test/sort/input-with-locations.osm.pbf | Bin 0 -> 429 bytes test/sort/run_test_check_stderr.cmake | 38 +++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 test/sort/input-with-locations.osm.pbf create mode 100644 test/sort/run_test_check_stderr.cmake diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 8ff3dc49..0657077b 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -110,6 +110,8 @@ bool CommandSort::run_single_pass() { osmium::ObjectPointerCollection objects; osmium::Box bounding_box; + osmium::io::Header first_input_header; + bool first_file = true; uint64_t buffers_count = 0; uint64_t buffers_size = 0; @@ -120,6 +122,10 @@ bool CommandSort::run_single_pass() { for (const auto& file : m_input_files) { osmium::io::Reader reader{file, osmium::osm_entity_bits::object}; const osmium::io::Header header{reader.header()}; + if (first_file) { + first_input_header = header; + first_file = false; + } bounding_box.extend(header.joined_boxes()); while (osmium::memory::Buffer buffer = reader.read()) { ++buffers_count; @@ -146,7 +152,7 @@ bool CommandSort::run_single_pass() { m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header); + setup_header(header, first_input_header); header.set("sorting", "Type_then_ID"); if (bounding_box) { header.add_box(bounding_box); @@ -173,18 +179,24 @@ bool CommandSort::run_multi_pass() { osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; osmium::Box bounding_box; + osmium::io::Header first_input_header; + bool first_file = true; m_vout << "Reading input file headers...\n"; for (const auto& file : m_input_files) { osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; const osmium::io::Header header{reader.header()}; + if (first_file) { + first_input_header = header; + first_file = false; + } bounding_box.extend(header.joined_boxes()); reader.close(); } m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header); + setup_header(header, first_input_header); if (bounding_box) { header.add_box(bounding_box); } diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index e590c786..69301235 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -15,7 +15,7 @@ function(check_convert _name _input _output _format) endfunction() function(check_warning _name _input _format _expected_stderr) - set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o /tmp/test-warning-output.osm --overwrite") + set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/warning-${_name}.osm --overwrite") add_test( NAME "cat-${_name}" COMMAND ${CMAKE_COMMAND} diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index ba8d7ef4..a3282dcd 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,6 +16,27 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() +function(check_sort_warning _name _input _format _expected_stderr) + set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}.osm --overwrite") + add_test( + NAME "sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}-mp.osm --overwrite") + add_test( + NAME "sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -32,4 +53,7 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) +check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") +check_sort_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") + #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm.pbf b/test/sort/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..abd5068d96d3034795f400b4282f0293437b2bdb GIT binary patch literal 429 zcmZQzVBqEA^bhv+NKH&hEt2pQu$6MHm=pZyv;H|=zjGdEeXsBuUoZ}SROES9+wbdX ze^1?OkG`Mu_tQCf=DhZ|^W6Sxbn=p(oYg;fR_E+h^DD+%E*LW~#Ip)7WME+6=3)n$ z?2=fLDB&&ODCJ%;=kcQlNe_}VJ$3a2jYN%}B?%>8ne-qjDMchH`a|MLO+7YEH8nO> zg=V0jxa}WK`mwWgnDR)O{%Vfol&PGOtmK}Vos3zMBm`GUzO%{Tg{4nX1DNB;F zBCDz;pQWlDpIalRwVH0~)P#_PD+wh@NlD+5CJAsPB_*&hylCZ6LN(1vz*Nc(#hsT# zf}ST$xghimdEJRNd5c-PF{lwe2f5iqqlU-dDh8XvDz4lFc2DYM{4(3)tgA zkANOuw_?qsBtIXoXOJMcH2Km)0nwzCDM=|oj~*w8%-E28DJYE7jn$1eO Date: Sat, 30 Aug 2025 23:38:19 +0200 Subject: [PATCH 16/35] Add no-warning tests --- test/cat/CMakeLists.txt | 14 +++++++++ test/cat/input-without-locations.osm.pbf | Bin 0 -> 164 bytes test/cat/run_test_check_no_stderr.cmake | 34 ++++++++++++++++++++++ test/sort/CMakeLists.txt | 22 ++++++++++++++ test/sort/input-without-locations.osm.pbf | Bin 0 -> 401 bytes test/sort/run_test_check_no_stderr.cmake | 34 ++++++++++++++++++++++ 6 files changed, 104 insertions(+) create mode 100644 test/cat/input-without-locations.osm.pbf create mode 100644 test/cat/run_test_check_no_stderr.cmake create mode 100644 test/sort/input-without-locations.osm.pbf create mode 100644 test/sort/run_test_check_no_stderr.cmake diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index 69301235..39cf1fc5 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -26,6 +26,17 @@ function(check_warning _name _input _format _expected_stderr) ) endfunction() +function(check_no_warning _name _input _format) + set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/no-warning-${_name}.osm --overwrite") + add_test( + NAME "cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_no_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -41,5 +52,8 @@ check_convert(opl output1.osm.opl output1.osm.opl opl) check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") check_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") +check_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) +check_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) + #----------------------------------------------------------------------------- diff --git a/test/cat/input-without-locations.osm.pbf b/test/cat/input-without-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..5884b660628ed454889aa4c40fc78687c41b70e9 GIT binary patch literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! literal 0 HcmV?d00001 diff --git a/test/cat/run_test_check_no_stderr.cmake b/test/cat/run_test_check_no_stderr.cmake new file mode 100644 index 00000000..8e5e9306 --- /dev/null +++ b/test/cat/run_test_check_no_stderr.cmake @@ -0,0 +1,34 @@ +# +# Runs a test command and checks that stderr is empty (no warning message). +# Used for testing that no false positive warnings appear. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos) +if(NOT _found_pos EQUAL -1) + message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: No warning message found") \ No newline at end of file diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index a3282dcd..0a18e626 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -37,6 +37,25 @@ function(check_sort_warning _name _input _format _expected_stderr) ) endfunction() +function(check_sort_no_warning _name _input _format) + set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}.osm --overwrite") + add_test( + NAME "sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}-mp.osm --overwrite") + add_test( + NAME "sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake + ) +endfunction() + #----------------------------------------------------------------------------- @@ -56,4 +75,7 @@ check_sort1(history-only-version input-history-only-version.osm output-history-o check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") check_sort_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") +check_sort_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) +check_sort_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) + #----------------------------------------------------------------------------- diff --git a/test/sort/input-without-locations.osm.pbf b/test/sort/input-without-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..843f5cd872d43e731e2006a315e373d9228d464c GIT binary patch literal 401 zcmZQzVBqEA^bhv+NKH&hEt0Sh(2+8!m=pZyv;H|=zjGdEeXsBuUoZ}SROES9+wbdX ze^1@Kq$g+f&z;pdd)54k@sf(Ns9iEcv4f3O;b&cO;zCsZi zB;iUzNm5eMx1>n|97#zDEDSGNIh0UMa}qF>vO{s_C6S=#NmDKeJp;Ki7VJt*H#Jo^ zHC;C~^=WPUijCrQc(?Zzuo)ULFtB8E$D Date: Sun, 31 Aug 2025 10:49:27 +0200 Subject: [PATCH 17/35] Implement for add-locations-to-ways cmd --- src/command_add_locations_to_ways.cpp | 17 +++++--- test/add-locations-to-ways/CMakeLists.txt | 29 +++++++++++++ .../input-with-locations.osm.pbf | Bin 0 -> 181 bytes .../input-without-locations.osm.pbf | Bin 0 -> 164 bytes .../run_test_check_no_stderr.cmake | 34 ++++++++++++++++ .../run_test_check_stderr.cmake | 38 ++++++++++++++++++ 6 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 test/add-locations-to-ways/input-with-locations.osm.pbf create mode 100644 test/add-locations-to-ways/input-without-locations.osm.pbf create mode 100644 test/add-locations-to-ways/run_test_check_no_stderr.cmake create mode 100644 test/add-locations-to-ways/run_test_check_stderr.cmake diff --git a/src/command_add_locations_to_ways.cpp b/src/command_add_locations_to_ways.cpp index 871b9932..41120245 100644 --- a/src/command_add_locations_to_ways.cpp +++ b/src/command_add_locations_to_ways.cpp @@ -198,7 +198,7 @@ bool CommandAddLocationsToWays::run() { m_vout << "Copying input file '" << m_input_files[0].filename() << "'...\n"; osmium::io::Reader reader{m_input_files[0]}; osmium::io::Header header{reader.header()}; - setup_header(header); + setup_header(header, reader.header()); writer.set_header(header); osmium::ProgressBar progress_bar{reader.file_size(), display_progress()}; @@ -208,15 +208,22 @@ bool CommandAddLocationsToWays::run() { writer.close(); reader.close(); } else { // multiple input files - osmium::io::Header header; - setup_header(header); - writer.set_header(header); - + osmium::io::Header first_input_header; + bool first_file = true; + osmium::ProgressBar progress_bar{file_size_sum(m_input_files), display_progress()}; for (const auto& input_file : m_input_files) { progress_bar.remove(); m_vout << "Copying input file '" << input_file.filename() << "'...\n"; osmium::io::Reader reader{input_file}; + + if (first_file) { + first_input_header = reader.header(); + osmium::io::Header header; + setup_header(header, first_input_header); + writer.set_header(header); + first_file = false; + } copy_data(progress_bar, reader, writer, location_handler); diff --git a/test/add-locations-to-ways/CMakeLists.txt b/test/add-locations-to-ways/CMakeLists.txt index 7ce8cbc4..f3e9cd8f 100644 --- a/test/add-locations-to-ways/CMakeLists.txt +++ b/test/add-locations-to-ways/CMakeLists.txt @@ -10,9 +10,38 @@ function(check_add_locations_to_ways _name _options _input _output) check_output(add-locations-to-ways ${_name} "add-locations-to-ways ${_options} --generator=test --output-header=xml_josm_upload=false --output-format=xml add-locations-to-ways/${_input}" "add-locations-to-ways/${_output}") endfunction() +function(check_add_locations_warning _name _input _format _expected_stderr) + set(_cmd "$ add-locations-to-ways --no-progress --generator=test add-locations-to-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/add-locations-to-ways/warning-${_name}.osm --overwrite") + add_test( + NAME "add-locations-to-ways-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/add-locations-to-ways/run_test_check_stderr.cmake + ) +endfunction() + +function(check_add_locations_no_warning _name _input _format) + set(_cmd "$ add-locations-to-ways --no-progress --generator=test add-locations-to-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/add-locations-to-ways/no-warning-${_name}.osm --overwrite") + add_test( + NAME "add-locations-to-ways-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D dir:PATH=${PROJECT_SOURCE_DIR}/test + -P ${CMAKE_SOURCE_DIR}/test/add-locations-to-ways/run_test_check_no_stderr.cmake + ) +endfunction() + check_add_locations_to_ways(taggednodes "" input.osm output.osm) check_add_locations_to_ways(allnodes "-n" input.osm output-n.osm) check_add_locations_to_ways(membernodes "--keep-member-nodes" input-rel.osm output-rel.osm) +check_add_locations_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") +check_add_locations_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") + +check_add_locations_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) +check_add_locations_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) + #----------------------------------------------------------------------------- diff --git a/test/add-locations-to-ways/input-with-locations.osm.pbf b/test/add-locations-to-ways/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c GIT binary patch literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN literal 0 HcmV?d00001 diff --git a/test/add-locations-to-ways/input-without-locations.osm.pbf b/test/add-locations-to-ways/input-without-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..5884b660628ed454889aa4c40fc78687c41b70e9 GIT binary patch literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! literal 0 HcmV?d00001 diff --git a/test/add-locations-to-ways/run_test_check_no_stderr.cmake b/test/add-locations-to-ways/run_test_check_no_stderr.cmake new file mode 100644 index 00000000..8e5e9306 --- /dev/null +++ b/test/add-locations-to-ways/run_test_check_no_stderr.cmake @@ -0,0 +1,34 @@ +# +# Runs a test command and checks that stderr is empty (no warning message). +# Used for testing that no false positive warnings appear. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos) +if(NOT _found_pos EQUAL -1) + message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: No warning message found") \ No newline at end of file diff --git a/test/add-locations-to-ways/run_test_check_stderr.cmake b/test/add-locations-to-ways/run_test_check_stderr.cmake new file mode 100644 index 00000000..fa44ea3a --- /dev/null +++ b/test/add-locations-to-ways/run_test_check_stderr.cmake @@ -0,0 +1,38 @@ +# +# Runs a test command and checks that stderr contains expected warning message. +# Used for testing warning functionality. +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT dir) + message(FATAL_ERROR "Variable 'dir' not defined") +endif() + +if(NOT expected_stderr) + message(FATAL_ERROR "Variable 'expected_stderr' not defined") +endif() + +message("Executing: ${cmd}") +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + WORKING_DIRECTORY ${dir} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "${expected_stderr}" _found_pos) +if(_found_pos EQUAL -1) + message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file From f01c2ac56071922a38de605202b0d331f960688d Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sun, 31 Aug 2025 11:08:22 +0200 Subject: [PATCH 18/35] Add test/add-locations-to-ways --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 4b0ede08..ce865ee1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,6 +4,7 @@ *.osh -crlf *.pg -crlf *-result.txt -crlf +test/add-locations-to-ways/output* -crlf test/cat/output* -crlf test/diff/output* -crlf test/export/*.geojson -crlf From 4e5658cd2939bc6104cc2f7a6322c94bea6fad09 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Wed, 3 Sep 2025 16:24:10 +0200 Subject: [PATCH 19/35] Move warning from cmds to io.cpp --- src/command_add_locations_to_ways.cpp | 17 +++++----------- src/command_cat.cpp | 2 +- src/command_sort.cpp | 28 +++++++++++++-------------- src/io.cpp | 15 ++++++++++++++ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/command_add_locations_to_ways.cpp b/src/command_add_locations_to_ways.cpp index 41120245..871b9932 100644 --- a/src/command_add_locations_to_ways.cpp +++ b/src/command_add_locations_to_ways.cpp @@ -198,7 +198,7 @@ bool CommandAddLocationsToWays::run() { m_vout << "Copying input file '" << m_input_files[0].filename() << "'...\n"; osmium::io::Reader reader{m_input_files[0]}; osmium::io::Header header{reader.header()}; - setup_header(header, reader.header()); + setup_header(header); writer.set_header(header); osmium::ProgressBar progress_bar{reader.file_size(), display_progress()}; @@ -208,22 +208,15 @@ bool CommandAddLocationsToWays::run() { writer.close(); reader.close(); } else { // multiple input files - osmium::io::Header first_input_header; - bool first_file = true; - + osmium::io::Header header; + setup_header(header); + writer.set_header(header); + osmium::ProgressBar progress_bar{file_size_sum(m_input_files), display_progress()}; for (const auto& input_file : m_input_files) { progress_bar.remove(); m_vout << "Copying input file '" << input_file.filename() << "'...\n"; osmium::io::Reader reader{input_file}; - - if (first_file) { - first_input_header = reader.header(); - osmium::io::Header header; - setup_header(header, first_input_header); - writer.set_header(header); - first_file = false; - } copy_data(progress_bar, reader, writer, location_handler); diff --git a/src/command_cat.cpp b/src/command_cat.cpp index 77c3a5da..a4d627e7 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -162,7 +162,7 @@ bool CommandCat::run() { report_filename(&m_vout, m_input_files[0], reader); - setup_header(header, reader.header()); + setup_header(header); osmium::io::Writer writer{m_output_file, header, m_output_overwrite, m_fsync}; if (m_buffer_data) { diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 0657077b..7d8d10c7 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -110,8 +110,7 @@ bool CommandSort::run_single_pass() { osmium::ObjectPointerCollection objects; osmium::Box bounding_box; - osmium::io::Header first_input_header; - bool first_file = true; + osmium::io::Header merged_input_header; uint64_t buffers_count = 0; uint64_t buffers_size = 0; @@ -122,11 +121,12 @@ bool CommandSort::run_single_pass() { for (const auto& file : m_input_files) { osmium::io::Reader reader{file, osmium::osm_entity_bits::object}; const osmium::io::Header header{reader.header()}; - if (first_file) { - first_input_header = header; - first_file = false; - } bounding_box.extend(header.joined_boxes()); + + // Merge input header info for warning detection + for (const auto& option : header) { + merged_input_header.set(option.first, option.second); + } while (osmium::memory::Buffer buffer = reader.read()) { ++buffers_count; buffers_size += buffer.committed(); @@ -152,7 +152,7 @@ bool CommandSort::run_single_pass() { m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header, first_input_header); + setup_header(header, merged_input_header); header.set("sorting", "Type_then_ID"); if (bounding_box) { header.add_box(bounding_box); @@ -179,24 +179,24 @@ bool CommandSort::run_multi_pass() { osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; osmium::Box bounding_box; - osmium::io::Header first_input_header; - bool first_file = true; + osmium::io::Header merged_input_header; m_vout << "Reading input file headers...\n"; for (const auto& file : m_input_files) { osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; const osmium::io::Header header{reader.header()}; - if (first_file) { - first_input_header = header; - first_file = false; - } bounding_box.extend(header.joined_boxes()); + + // Merge input header info for warning detection + for (const auto& option : header) { + merged_input_header.set(option.first, option.second); + } reader.close(); } m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header, first_input_header); + setup_header(header, merged_input_header); if (bounding_box) { header.add_box(bounding_box); } diff --git a/src/io.cpp b/src/io.cpp index 1eef75e4..25df8c6a 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -210,6 +210,21 @@ void with_osm_output::setup_header(osmium::io::Header& header) const { for (const auto& h : m_output_headers) { header.set(h); } + + // Check if input PBF has locations_on_ways but output format won't preserve them + bool has_locations_on_ways = false; + for (const auto& option : header) { + if (option.first.find("pbf_optional_feature") != std::string::npos && + option.second == "LocationsOnWays") { + has_locations_on_ways = true; + break; + } + } + + if (has_locations_on_ways && m_output_format.find("locations_on_ways") == std::string::npos) { + std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; + std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; + } } void init_header(osmium::io::Header& header, const osmium::io::Header& input_header, const std::vector& options) { From 9ab08b62c3400b226b7dfeaef52a4db88cb0f4ec Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Wed, 3 Sep 2025 17:00:31 +0200 Subject: [PATCH 20/35] Revert file --- .gitattributes | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index ce865ee1..f725b6e6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,11 +4,8 @@ *.osh -crlf *.pg -crlf *-result.txt -crlf -test/add-locations-to-ways/output* -crlf -test/cat/output* -crlf -test/diff/output* -crlf test/export/*.geojson -crlf test/export/*.geojsonseq -crlf test/export/*.txt -crlf +test/diff/output* -crlf test/show/output* -crlf -test/sort/output* -crlf From 8bef8f9c5c441eba2f5d097eb224599785d4dc33 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Thu, 4 Sep 2025 20:56:48 +0200 Subject: [PATCH 21/35] Add has_locations_on_ways --- src/command_cat.cpp | 4 ++ src/command_sort.cpp | 24 ++++------ src/io.cpp | 30 ------------ src/util.cpp | 18 +++++++ src/util.hpp | 1 + test/add-locations-to-ways/CMakeLists.txt | 28 ----------- .../input-with-locations.osm.pbf | Bin 181 -> 0 bytes .../input-without-locations.osm.pbf | Bin 164 -> 0 bytes .../run_test_check_no_stderr.cmake | 34 ------------- .../run_test_check_stderr.cmake | 38 --------------- test/cat/CMakeLists.txt | 28 ----------- test/cat/input-with-locations.osm.pbf | Bin 181 -> 0 bytes test/cat/input-without-locations.osm.pbf | Bin 164 -> 0 bytes test/cat/run_test_check_no_stderr.cmake | 34 ------------- test/cat/run_test_check_stderr.cmake | 38 --------------- test/sort/CMakeLists.txt | 45 ------------------ test/sort/input-with-locations.osm.pbf | Bin 429 -> 0 bytes test/sort/input-without-locations.osm.pbf | Bin 401 -> 0 bytes test/sort/run_test_check_no_stderr.cmake | 34 ------------- test/sort/run_test_check_stderr.cmake | 38 --------------- 20 files changed, 33 insertions(+), 361 deletions(-) delete mode 100644 test/add-locations-to-ways/input-with-locations.osm.pbf delete mode 100644 test/add-locations-to-ways/input-without-locations.osm.pbf delete mode 100644 test/add-locations-to-ways/run_test_check_no_stderr.cmake delete mode 100644 test/add-locations-to-ways/run_test_check_stderr.cmake delete mode 100644 test/cat/input-with-locations.osm.pbf delete mode 100644 test/cat/input-without-locations.osm.pbf delete mode 100644 test/cat/run_test_check_no_stderr.cmake delete mode 100644 test/cat/run_test_check_stderr.cmake delete mode 100644 test/sort/input-with-locations.osm.pbf delete mode 100644 test/sort/input-without-locations.osm.pbf delete mode 100644 test/sort/run_test_check_no_stderr.cmake delete mode 100644 test/sort/run_test_check_stderr.cmake diff --git a/src/command_cat.cpp b/src/command_cat.cpp index a4d627e7..14eae44c 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -154,6 +154,10 @@ void report_filename(osmium::VerboseOutput* vout, const osmium::io::File& file, } // anonymous namespace bool CommandCat::run() { + if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + } + std::size_t bytes_written = 0; if (m_input_files.size() == 1) { // single input file diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 7d8d10c7..4939542a 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -104,13 +104,16 @@ void CommandSort::show_arguments() { } bool CommandSort::run_single_pass() { + if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + } + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; std::vector data; osmium::ObjectPointerCollection objects; osmium::Box bounding_box; - osmium::io::Header merged_input_header; uint64_t buffers_count = 0; uint64_t buffers_size = 0; @@ -122,11 +125,6 @@ bool CommandSort::run_single_pass() { osmium::io::Reader reader{file, osmium::osm_entity_bits::object}; const osmium::io::Header header{reader.header()}; bounding_box.extend(header.joined_boxes()); - - // Merge input header info for warning detection - for (const auto& option : header) { - merged_input_header.set(option.first, option.second); - } while (osmium::memory::Buffer buffer = reader.read()) { ++buffers_count; buffers_size += buffer.committed(); @@ -152,7 +150,7 @@ bool CommandSort::run_single_pass() { m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header, merged_input_header); + setup_header(header); header.set("sorting", "Type_then_ID"); if (bounding_box) { header.add_box(bounding_box); @@ -176,27 +174,25 @@ bool CommandSort::run_single_pass() { } bool CommandSort::run_multi_pass() { + if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + } + osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; osmium::Box bounding_box; - osmium::io::Header merged_input_header; m_vout << "Reading input file headers...\n"; for (const auto& file : m_input_files) { osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; const osmium::io::Header header{reader.header()}; bounding_box.extend(header.joined_boxes()); - - // Merge input header info for warning detection - for (const auto& option : header) { - merged_input_header.set(option.first, option.second); - } reader.close(); } m_vout << "Opening output file...\n"; osmium::io::Header header; - setup_header(header, merged_input_header); + setup_header(header); if (bounding_box) { header.add_box(bounding_box); } diff --git a/src/io.cpp b/src/io.cpp index 25df8c6a..d36859bf 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -210,21 +210,6 @@ void with_osm_output::setup_header(osmium::io::Header& header) const { for (const auto& h : m_output_headers) { header.set(h); } - - // Check if input PBF has locations_on_ways but output format won't preserve them - bool has_locations_on_ways = false; - for (const auto& option : header) { - if (option.first.find("pbf_optional_feature") != std::string::npos && - option.second == "LocationsOnWays") { - has_locations_on_ways = true; - break; - } - } - - if (has_locations_on_ways && m_output_format.find("locations_on_ways") == std::string::npos) { - std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; - std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; - } } void init_header(osmium::io::Header& header, const osmium::io::Header& input_header, const std::vector& options) { @@ -242,20 +227,5 @@ void init_header(osmium::io::Header& header, const osmium::io::Header& input_hea void with_osm_output::setup_header(osmium::io::Header& header, const osmium::io::Header& input_header) const { header.set("generator", m_generator); init_header(header, input_header, m_output_headers); - - // Check if input PBF has locations_on_ways but output format won't preserve them - bool has_locations_on_ways = false; - for (const auto& option : input_header) { - if (option.first.find("pbf_optional_feature") != std::string::npos && - option.second == "LocationsOnWays") { - has_locations_on_ways = true; - break; - } - } - - if (has_locations_on_ways && m_output_format.find("locations_on_ways") == std::string::npos) { - std::cerr << "Warning! Input file contains locations on ways that will be lost in output.\n"; - std::cerr << "Use --output-format with locations_on_ways option to preserve node locations on ways.\n"; - } } diff --git a/src/util.cpp b/src/util.cpp index 1a3468af..6965e6f3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -25,6 +25,7 @@ along with this program. If not, see . #include "exception.hpp" #include +#include #include #include #include @@ -276,3 +277,20 @@ double show_gbytes(std::size_t value) noexcept { return static_cast(show_mbytes(value)) / 1000; // NOLINT(bugprone-integer-division) } +bool has_locations_on_ways(const std::vector& input_files) { + for (const auto& file : input_files) { + osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; + const osmium::io::Header& header = reader.header(); + + for (const auto& option : header) { + if (option.first.find("pbf_optional_feature") != std::string::npos && + option.second == "LocationsOnWays") { + reader.close(); + return true; + } + } + reader.close(); + } + return false; +} + diff --git a/src/util.hpp b/src/util.hpp index 13c6140a..8bd9512b 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -53,5 +53,6 @@ const char* object_type_as_string(const osmium::OSMObject& object) noexcept; bool ends_with(const std::string& str, const std::string& suffix); std::size_t show_mbytes(std::size_t value) noexcept; double show_gbytes(std::size_t value) noexcept; +bool has_locations_on_ways(const std::vector& input_files); #endif // UTIL_HPP diff --git a/test/add-locations-to-ways/CMakeLists.txt b/test/add-locations-to-ways/CMakeLists.txt index f3e9cd8f..23bd027d 100644 --- a/test/add-locations-to-ways/CMakeLists.txt +++ b/test/add-locations-to-ways/CMakeLists.txt @@ -10,38 +10,10 @@ function(check_add_locations_to_ways _name _options _input _output) check_output(add-locations-to-ways ${_name} "add-locations-to-ways ${_options} --generator=test --output-header=xml_josm_upload=false --output-format=xml add-locations-to-ways/${_input}" "add-locations-to-ways/${_output}") endfunction() -function(check_add_locations_warning _name _input _format _expected_stderr) - set(_cmd "$ add-locations-to-ways --no-progress --generator=test add-locations-to-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/add-locations-to-ways/warning-${_name}.osm --overwrite") - add_test( - NAME "add-locations-to-ways-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/add-locations-to-ways/run_test_check_stderr.cmake - ) -endfunction() - -function(check_add_locations_no_warning _name _input _format) - set(_cmd "$ add-locations-to-ways --no-progress --generator=test add-locations-to-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/add-locations-to-ways/no-warning-${_name}.osm --overwrite") - add_test( - NAME "add-locations-to-ways-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -P ${CMAKE_SOURCE_DIR}/test/add-locations-to-ways/run_test_check_no_stderr.cmake - ) -endfunction() check_add_locations_to_ways(taggednodes "" input.osm output.osm) check_add_locations_to_ways(allnodes "-n" input.osm output-n.osm) check_add_locations_to_ways(membernodes "--keep-member-nodes" input-rel.osm output-rel.osm) -check_add_locations_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") -check_add_locations_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") - -check_add_locations_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) -check_add_locations_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) - #----------------------------------------------------------------------------- diff --git a/test/add-locations-to-ways/input-with-locations.osm.pbf b/test/add-locations-to-ways/input-with-locations.osm.pbf deleted file mode 100644 index ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN diff --git a/test/add-locations-to-ways/input-without-locations.osm.pbf b/test/add-locations-to-ways/input-without-locations.osm.pbf deleted file mode 100644 index 5884b660628ed454889aa4c40fc78687c41b70e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! diff --git a/test/add-locations-to-ways/run_test_check_no_stderr.cmake b/test/add-locations-to-ways/run_test_check_no_stderr.cmake deleted file mode 100644 index 8e5e9306..00000000 --- a/test/add-locations-to-ways/run_test_check_no_stderr.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# -# Runs a test command and checks that stderr is empty (no warning message). -# Used for testing that no false positive warnings appear. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos) -if(NOT _found_pos EQUAL -1) - message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: No warning message found") \ No newline at end of file diff --git a/test/add-locations-to-ways/run_test_check_stderr.cmake b/test/add-locations-to-ways/run_test_check_stderr.cmake deleted file mode 100644 index fa44ea3a..00000000 --- a/test/add-locations-to-ways/run_test_check_stderr.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# -# Runs a test command and checks that stderr contains expected warning message. -# Used for testing warning functionality. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -if(NOT expected_stderr) - message(FATAL_ERROR "Variable 'expected_stderr' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "${expected_stderr}" _found_pos) -if(_found_pos EQUAL -1) - message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index 39cf1fc5..deca4f08 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,28 +14,6 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() -function(check_warning _name _input _format _expected_stderr) - set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/warning-${_name}.osm --overwrite") - add_test( - NAME "cat-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_stderr.cmake - ) -endfunction() - -function(check_no_warning _name _input _format) - set(_cmd "$ cat --no-progress --generator=test cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/no-warning-${_name}.osm --overwrite") - add_test( - NAME "cat-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -P ${CMAKE_SOURCE_DIR}/test/cat/run_test_check_no_stderr.cmake - ) -endfunction() #----------------------------------------------------------------------------- @@ -49,11 +27,5 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) -check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") -check_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") - -check_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) -check_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) - #----------------------------------------------------------------------------- diff --git a/test/cat/input-with-locations.osm.pbf b/test/cat/input-with-locations.osm.pbf deleted file mode 100644 index ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN diff --git a/test/cat/input-without-locations.osm.pbf b/test/cat/input-without-locations.osm.pbf deleted file mode 100644 index 5884b660628ed454889aa4c40fc78687c41b70e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! diff --git a/test/cat/run_test_check_no_stderr.cmake b/test/cat/run_test_check_no_stderr.cmake deleted file mode 100644 index 8e5e9306..00000000 --- a/test/cat/run_test_check_no_stderr.cmake +++ /dev/null @@ -1,34 +0,0 @@ -# -# Runs a test command and checks that stderr is empty (no warning message). -# Used for testing that no false positive warnings appear. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "Warning! Input file contains locations on ways" _found_pos) -if(NOT _found_pos EQUAL -1) - message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: No warning message found") \ No newline at end of file diff --git a/test/cat/run_test_check_stderr.cmake b/test/cat/run_test_check_stderr.cmake deleted file mode 100644 index fa44ea3a..00000000 --- a/test/cat/run_test_check_stderr.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# -# Runs a test command and checks that stderr contains expected warning message. -# Used for testing warning functionality. -# - -if(NOT cmd) - message(FATAL_ERROR "Variable 'cmd' not defined") -endif() - -if(NOT dir) - message(FATAL_ERROR "Variable 'dir' not defined") -endif() - -if(NOT expected_stderr) - message(FATAL_ERROR "Variable 'expected_stderr' not defined") -endif() - -message("Executing: ${cmd}") -separate_arguments(cmd) - -execute_process( - COMMAND ${cmd} - WORKING_DIRECTORY ${dir} - RESULT_VARIABLE _return_code - OUTPUT_VARIABLE _stdout - ERROR_VARIABLE _stderr -) - -if(NOT _return_code EQUAL 0) - message(FATAL_ERROR "Command failed with return code ${_return_code}") -endif() - -string(FIND "${_stderr}" "${expected_stderr}" _found_pos) -if(_found_pos EQUAL -1) - message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") -endif() - -message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index 0a18e626..20d9e309 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,45 +16,6 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() -function(check_sort_warning _name _input _format _expected_stderr) - set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}.osm --overwrite") - add_test( - NAME "sort-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake - ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}-mp.osm --overwrite") - add_test( - NAME "sort-${_name}-mp" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd_mp} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_stderr.cmake - ) -endfunction() - -function(check_sort_no_warning _name _input _format) - set(_cmd "$ sort --no-progress --generator=test sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}.osm --overwrite") - add_test( - NAME "sort-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake - ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}-mp.osm --overwrite") - add_test( - NAME "sort-${_name}-mp" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd_mp} - -D dir:PATH=${PROJECT_SOURCE_DIR}/test - -P ${CMAKE_SOURCE_DIR}/test/sort/run_test_check_no_stderr.cmake - ) -endfunction() #----------------------------------------------------------------------------- @@ -72,10 +33,4 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) -check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "Warning! Input file contains locations on ways that will be lost in output.") -check_sort_warning(warning-pbf-to-opl input-with-locations.osm.pbf opl "Warning! Input file contains locations on ways that will be lost in output.") - -check_sort_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) -check_sort_no_warning(no-warning-pbf-to-opl input-without-locations.osm.pbf opl) - #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm.pbf b/test/sort/input-with-locations.osm.pbf deleted file mode 100644 index abd5068d96d3034795f400b4282f0293437b2bdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 429 zcmZQzVBqEA^bhv+NKH&hEt2pQu$6MHm=pZyv;H|=zjGdEeXsBuUoZ}SROES9+wbdX ze^1?OkG`Mu_tQCf=DhZ|^W6Sxbn=p(oYg;fR_E+h^DD+%E*LW~#Ip)7WME+6=3)n$ z?2=fLDB&&ODCJ%;=kcQlNe_}VJ$3a2jYN%}B?%>8ne-qjDMchH`a|MLO+7YEH8nO> zg=V0jxa}WK`mwWgnDR)O{%Vfol&PGOtmK}Vos3zMBm`GUzO%{Tg{4nX1DNB;F zBCDz;pQWlDpIalRwVH0~)P#_PD+wh@NlD+5CJAsPB_*&hylCZ6LN(1vz*Nc(#hsT# zf}ST$xghimdEJRNd5c-PF{lwe2f5iqqlU-dDh8XvDz4lFc2DYM{4(3)tgA zkANOuw_?qsBtIXoXOJMcH2Km)0nwzCDM=|oj~*w8%-E28DJYE7jn$1eOf(Ns9iEcv4f3O;b&cO;zCsZi zB;iUzNm5eMx1>n|97#zDEDSGNIh0UMa}qF>vO{s_C6S=#NmDKeJp;Ki7VJt*H#Jo^ zHC;C~^=WPUijCrQc(?Zzuo)ULFtB8E$D Date: Thu, 4 Sep 2025 21:13:50 +0200 Subject: [PATCH 22/35] Change tests --- test/add-locations-to-ways/CMakeLists.txt | 1 - .../input-with-locations.osm.pbf | Bin 0 -> 181 bytes .../input-without-locations.osm.pbf | Bin 0 -> 164 bytes test/cat/CMakeLists.txt | 24 +++++++++++ test/cat/input-with-locations.osm.pbf | Bin 0 -> 181 bytes test/cat/input-without-locations.osm.pbf | Bin 0 -> 164 bytes test/run_test_check_no_stderr.cmake | 27 ++++++++++++ test/run_test_check_stderr.cmake | 31 ++++++++++++++ test/sort/CMakeLists.txt | 39 ++++++++++++++++++ test/sort/input-with-locations.osm.pbf | Bin 0 -> 429 bytes test/sort/input-without-locations.osm.pbf | Bin 0 -> 401 bytes 11 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 test/add-locations-to-ways/input-with-locations.osm.pbf create mode 100644 test/add-locations-to-ways/input-without-locations.osm.pbf create mode 100644 test/cat/input-with-locations.osm.pbf create mode 100644 test/cat/input-without-locations.osm.pbf create mode 100644 test/run_test_check_no_stderr.cmake create mode 100644 test/run_test_check_stderr.cmake create mode 100644 test/sort/input-with-locations.osm.pbf create mode 100644 test/sort/input-without-locations.osm.pbf diff --git a/test/add-locations-to-ways/CMakeLists.txt b/test/add-locations-to-ways/CMakeLists.txt index 23bd027d..7ce8cbc4 100644 --- a/test/add-locations-to-ways/CMakeLists.txt +++ b/test/add-locations-to-ways/CMakeLists.txt @@ -10,7 +10,6 @@ function(check_add_locations_to_ways _name _options _input _output) check_output(add-locations-to-ways ${_name} "add-locations-to-ways ${_options} --generator=test --output-header=xml_josm_upload=false --output-format=xml add-locations-to-ways/${_input}" "add-locations-to-ways/${_output}") endfunction() - check_add_locations_to_ways(taggednodes "" input.osm output.osm) check_add_locations_to_ways(allnodes "-n" input.osm output-n.osm) check_add_locations_to_ways(membernodes "--keep-member-nodes" input-rel.osm output-rel.osm) diff --git a/test/add-locations-to-ways/input-with-locations.osm.pbf b/test/add-locations-to-ways/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c GIT binary patch literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN literal 0 HcmV?d00001 diff --git a/test/add-locations-to-ways/input-without-locations.osm.pbf b/test/add-locations-to-ways/input-without-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..5884b660628ed454889aa4c40fc78687c41b70e9 GIT binary patch literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! literal 0 HcmV?d00001 diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index deca4f08..fe85b5ee 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,6 +14,26 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() +function(check_warning _name _input _format _expected_stderr) + set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/warning-${_name}.osm --overwrite") + add_test( + NAME "cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake + ) +endfunction() + +function(check_no_warning _name _input _format) + set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/no-warning-${_name}.osm --overwrite") + add_test( + NAME "cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake + ) +endfunction() #----------------------------------------------------------------------------- @@ -27,5 +47,9 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) +check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") + +check_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) + #----------------------------------------------------------------------------- diff --git a/test/cat/input-with-locations.osm.pbf b/test/cat/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c GIT binary patch literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN literal 0 HcmV?d00001 diff --git a/test/cat/input-without-locations.osm.pbf b/test/cat/input-without-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..5884b660628ed454889aa4c40fc78687c41b70e9 GIT binary patch literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! literal 0 HcmV?d00001 diff --git a/test/run_test_check_no_stderr.cmake b/test/run_test_check_no_stderr.cmake new file mode 100644 index 00000000..1232c136 --- /dev/null +++ b/test/run_test_check_no_stderr.cmake @@ -0,0 +1,27 @@ +# +# Simple test script to check that stderr does not contain warning message +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "WARNING:" _found_pos) +if(NOT _found_pos EQUAL -1) + message(FATAL_ERROR "Unexpected warning message found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: No warning message found") \ No newline at end of file diff --git a/test/run_test_check_stderr.cmake b/test/run_test_check_stderr.cmake new file mode 100644 index 00000000..676e0559 --- /dev/null +++ b/test/run_test_check_stderr.cmake @@ -0,0 +1,31 @@ +# +# Simple test script to check that stderr contains expected warning message +# + +if(NOT cmd) + message(FATAL_ERROR "Variable 'cmd' not defined") +endif() + +if(NOT expected_stderr) + message(FATAL_ERROR "Variable 'expected_stderr' not defined") +endif() + +separate_arguments(cmd) + +execute_process( + COMMAND ${cmd} + RESULT_VARIABLE _return_code + OUTPUT_VARIABLE _stdout + ERROR_VARIABLE _stderr +) + +if(NOT _return_code EQUAL 0) + message(FATAL_ERROR "Command failed with return code ${_return_code}") +endif() + +string(FIND "${_stderr}" "${expected_stderr}" _found_pos) +if(_found_pos EQUAL -1) + message(FATAL_ERROR "Expected stderr message '${expected_stderr}' not found in stderr output: '${_stderr}'") +endif() + +message(STATUS "Test passed: Found expected stderr message") \ No newline at end of file diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index 20d9e309..a41ce86d 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,6 +16,41 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() +function(check_sort_warning _name _input _format _expected_stderr) + set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}.osm --overwrite") + add_test( + NAME "sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}-mp.osm --overwrite") + add_test( + NAME "sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake + ) +endfunction() + +function(check_sort_no_warning _name _input _format) + set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}.osm --overwrite") + add_test( + NAME "sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}-mp.osm --overwrite") + add_test( + NAME "sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake + ) +endfunction() #----------------------------------------------------------------------------- @@ -33,4 +68,8 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) +check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") + +check_sort_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) + #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm.pbf b/test/sort/input-with-locations.osm.pbf new file mode 100644 index 0000000000000000000000000000000000000000..abd5068d96d3034795f400b4282f0293437b2bdb GIT binary patch literal 429 zcmZQzVBqEA^bhv+NKH&hEt2pQu$6MHm=pZyv;H|=zjGdEeXsBuUoZ}SROES9+wbdX ze^1?OkG`Mu_tQCf=DhZ|^W6Sxbn=p(oYg;fR_E+h^DD+%E*LW~#Ip)7WME+6=3)n$ z?2=fLDB&&ODCJ%;=kcQlNe_}VJ$3a2jYN%}B?%>8ne-qjDMchH`a|MLO+7YEH8nO> zg=V0jxa}WK`mwWgnDR)O{%Vfol&PGOtmK}Vos3zMBm`GUzO%{Tg{4nX1DNB;F zBCDz;pQWlDpIalRwVH0~)P#_PD+wh@NlD+5CJAsPB_*&hylCZ6LN(1vz*Nc(#hsT# zf}ST$xghimdEJRNd5c-PF{lwe2f5iqqlU-dDh8XvDz4lFc2DYM{4(3)tgA zkANOuw_?qsBtIXoXOJMcH2Km)0nwzCDM=|oj~*w8%-E28DJYE7jn$1eOf(Ns9iEcv4f3O;b&cO;zCsZi zB;iUzNm5eMx1>n|97#zDEDSGNIh0UMa}qF>vO{s_C6S=#NmDKeJp;Ki7VJt*H#Jo^ zHC;C~^=WPUijCrQc(?Zzuo)ULFtB8E$D Date: Tue, 9 Sep 2025 08:41:33 +0200 Subject: [PATCH 23/35] Temp reduce CI builds --- .github/workflows/ci.yml | 11 ----------- src/command_cat.cpp | 4 +--- src/command_sort.cpp | 8 ++------ src/util.cpp | 27 ++++++++++++++++++--------- src/util.hpp | 1 + 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c6b7177..8a023907 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,16 +10,7 @@ jobs: fail-fast: false matrix: image: - - "ubuntu:20.04" # gcc 9.3.0, clang 10.0.0, cmake 3.16.3 - - "ubuntu:22.04" # gcc 12.2.0, clang 15.0.7, cmake 3.24.2 - "ubuntu:24.04" # gcc 14.2.0, clang 18.1.3, cmake 3.28.3 - - "debian:bullseye" # gcc 10.2.1, clang 11.0.1, cmake 3.18.4 - - "debian:bookworm" # gcc 12.2.0, clang 15.0.6, cmake 3.25.1 - - "debian:testing" - - "debian:experimental" - - "fedora:39" - - "fedora:40" - - "fedora:41" build_type: [Dev] cpp_compiler: [g++] cpp_version: [c++14] @@ -163,7 +154,6 @@ jobs: fail-fast: false matrix: os: - - macos-14 - macos-15 build_type: [Dev] include: @@ -188,7 +178,6 @@ jobs: fail-fast: false matrix: os: - - windows-2022 - windows-2025 steps: - run: | diff --git a/src/command_cat.cpp b/src/command_cat.cpp index 14eae44c..0be212de 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -154,9 +154,7 @@ void report_filename(osmium::VerboseOutput* vout, const osmium::io::File& file, } // anonymous namespace bool CommandCat::run() { - if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { - warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); - } + warn_locations_on_ways_lost(m_input_files, m_output_format); std::size_t bytes_written = 0; diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 4939542a..6436273f 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -104,9 +104,7 @@ void CommandSort::show_arguments() { } bool CommandSort::run_single_pass() { - if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { - warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); - } + warn_locations_on_ways_lost(m_input_files, m_output_format); osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; @@ -174,9 +172,7 @@ bool CommandSort::run_single_pass() { } bool CommandSort::run_multi_pass() { - if (has_locations_on_ways(m_input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { - warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); - } + warn_locations_on_ways_lost(m_input_files, m_output_format); osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; diff --git a/src/util.cpp b/src/util.cpp index 6965e6f3..651da541 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -279,18 +279,27 @@ double show_gbytes(std::size_t value) noexcept { bool has_locations_on_ways(const std::vector& input_files) { for (const auto& file : input_files) { - osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; - const osmium::io::Header& header = reader.header(); - - for (const auto& option : header) { - if (option.first.find("pbf_optional_feature") != std::string::npos && - option.second == "LocationsOnWays") { - reader.close(); - return true; + try { + osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; + const osmium::io::Header& header = reader.header(); + + for (const auto& option : header) { + if (option.first.find("pbf_optional_feature") != std::string::npos && + option.second == "LocationsOnWays") { + return true; + } } + } catch (...) { + // Ignore files that can't be opened for header check + continue; } - reader.close(); } return false; } +void warn_locations_on_ways_lost(const std::vector& input_files, const std::string& output_format) { + if (has_locations_on_ways(input_files) && output_format.find("locations_on_ways") == std::string::npos) { + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + } +} + diff --git a/src/util.hpp b/src/util.hpp index 8bd9512b..08afeab1 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -54,5 +54,6 @@ bool ends_with(const std::string& str, const std::string& suffix); std::size_t show_mbytes(std::size_t value) noexcept; double show_gbytes(std::size_t value) noexcept; bool has_locations_on_ways(const std::vector& input_files); +void warn_locations_on_ways_lost(const std::vector& input_files, const std::string& output_format); #endif // UTIL_HPP From eea021cebdfaadfb91fbba9d463a1739ddea78c5 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Tue, 9 Sep 2025 09:50:23 +0200 Subject: [PATCH 24/35] Add virtual method --- .../run_test_check_no_stderr.cmake | 0 {test => cmake}/run_test_check_stderr.cmake | 0 src/cmd.cpp | 9 +++ src/cmd.hpp | 6 ++ src/command_cat.cpp | 2 +- src/command_cat.hpp | 4 + src/command_sort.cpp | 4 +- src/command_sort.hpp | 4 + src/util.cpp | 6 -- src/util.hpp | 1 - test/CMakeLists.txt | 2 +- test/add-locations-to-ways/CMakeLists.txt | 18 ----- test/add-locations-to-ways/input-rel.osm | 18 ----- test/add-locations-to-ways/input.osm | 22 ------ test/add-locations-to-ways/output-n.osm | 22 ------ test/add-locations-to-ways/output-rel.osm | 16 ---- test/add-locations-to-ways/output.osm | 18 ----- test/cat/CMakeLists.txt | 26 ------- test/cat/input-with-locations.osm.pbf | Bin 181 -> 0 bytes test/cat/input-without-locations.osm.pbf | Bin 164 -> 0 bytes test/locations-on-ways/CMakeLists.txt | 72 ++++++++++++++++++ .../input-with-locations.osm.pbf | Bin .../input-without-locations.osm.pbf | Bin test/sort/CMakeLists.txt | 40 ---------- test/sort/input-with-locations.osm.pbf | Bin 429 -> 0 bytes test/sort/input-without-locations.osm.pbf | Bin 401 -> 0 bytes 26 files changed, 99 insertions(+), 191 deletions(-) rename {test => cmake}/run_test_check_no_stderr.cmake (100%) rename {test => cmake}/run_test_check_stderr.cmake (100%) delete mode 100644 test/add-locations-to-ways/CMakeLists.txt delete mode 100644 test/add-locations-to-ways/input-rel.osm delete mode 100644 test/add-locations-to-ways/input.osm delete mode 100644 test/add-locations-to-ways/output-n.osm delete mode 100644 test/add-locations-to-ways/output-rel.osm delete mode 100644 test/add-locations-to-ways/output.osm delete mode 100644 test/cat/input-with-locations.osm.pbf delete mode 100644 test/cat/input-without-locations.osm.pbf create mode 100644 test/locations-on-ways/CMakeLists.txt rename test/{add-locations-to-ways => locations-on-ways}/input-with-locations.osm.pbf (100%) rename test/{add-locations-to-ways => locations-on-ways}/input-without-locations.osm.pbf (100%) delete mode 100644 test/sort/input-with-locations.osm.pbf delete mode 100644 test/sort/input-without-locations.osm.pbf diff --git a/test/run_test_check_no_stderr.cmake b/cmake/run_test_check_no_stderr.cmake similarity index 100% rename from test/run_test_check_no_stderr.cmake rename to cmake/run_test_check_no_stderr.cmake diff --git a/test/run_test_check_stderr.cmake b/cmake/run_test_check_stderr.cmake similarity index 100% rename from test/run_test_check_stderr.cmake rename to cmake/run_test_check_stderr.cmake diff --git a/src/cmd.cpp b/src/cmd.cpp index 7e232565..e9db60c1 100644 --- a/src/cmd.cpp +++ b/src/cmd.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include "cmd.hpp" #include "exception.hpp" +#include "util.hpp" #include #include @@ -177,3 +178,11 @@ std::string check_index_type(const std::string& index_type_name, bool allow_none return index_type_name; } + +void with_osm_output::warn_locations_on_ways_lost(const std::vector& input_files, const Command& command) const { + if (command.should_warn_locations_lost() && + has_locations_on_ways(input_files) && + m_output_format.find("locations_on_ways") == std::string::npos) { + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + } +} diff --git a/src/cmd.hpp b/src/cmd.hpp index d2f574f1..59c2c749 100644 --- a/src/cmd.hpp +++ b/src/cmd.hpp @@ -118,6 +118,10 @@ class Command { void print_arguments(const std::string& command); void show_memory_used(); + virtual bool should_warn_locations_lost() const { + return false; + } + osmium::osm_entity_bits::type osm_entity_bits() const { return m_osm_entity_bits; } @@ -262,6 +266,8 @@ class with_osm_output { return m_output_overwrite; } + void warn_locations_on_ways_lost(const std::vector& input_files, const Command& command) const; + }; // class with_osm_output diff --git a/src/command_cat.cpp b/src/command_cat.cpp index 0be212de..f6e84f9e 100644 --- a/src/command_cat.cpp +++ b/src/command_cat.cpp @@ -154,7 +154,7 @@ void report_filename(osmium::VerboseOutput* vout, const osmium::io::File& file, } // anonymous namespace bool CommandCat::run() { - warn_locations_on_ways_lost(m_input_files, m_output_format); + warn_locations_on_ways_lost(m_input_files, *this); std::size_t bytes_written = 0; diff --git a/src/command_cat.hpp b/src/command_cat.hpp index 8532daf9..5bb9d393 100644 --- a/src/command_cat.hpp +++ b/src/command_cat.hpp @@ -61,6 +61,10 @@ class CommandCat : public CommandWithMultipleOSMInputs, public with_osm_output { return "osmium cat [OPTIONS] OSM-FILE..."; } + bool should_warn_locations_lost() const override { + return true; + } + }; // class CommandCat #endif // COMMAND_CAT_HPP diff --git a/src/command_sort.cpp b/src/command_sort.cpp index 6436273f..bbe8ee5a 100644 --- a/src/command_sort.cpp +++ b/src/command_sort.cpp @@ -104,7 +104,7 @@ void CommandSort::show_arguments() { } bool CommandSort::run_single_pass() { - warn_locations_on_ways_lost(m_input_files, m_output_format); + warn_locations_on_ways_lost(m_input_files, *this); osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; @@ -172,7 +172,7 @@ bool CommandSort::run_single_pass() { } bool CommandSort::run_multi_pass() { - warn_locations_on_ways_lost(m_input_files, m_output_format); + warn_locations_on_ways_lost(m_input_files, *this); osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; diff --git a/src/command_sort.hpp b/src/command_sort.hpp index 8c2ad804..6ecb3d21 100644 --- a/src/command_sort.hpp +++ b/src/command_sort.hpp @@ -56,6 +56,10 @@ class CommandSort : public CommandWithMultipleOSMInputs, public with_osm_output return "osmium sort [OPTIONS] OSM-FILE..."; } + bool should_warn_locations_lost() const override { + return true; + } + }; // class CommandSort diff --git a/src/util.cpp b/src/util.cpp index 651da541..eaf2c2d3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -297,9 +297,3 @@ bool has_locations_on_ways(const std::vector& input_files) { return false; } -void warn_locations_on_ways_lost(const std::vector& input_files, const std::string& output_format) { - if (has_locations_on_ways(input_files) && output_format.find("locations_on_ways") == std::string::npos) { - warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); - } -} - diff --git a/src/util.hpp b/src/util.hpp index 08afeab1..8bd9512b 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -54,6 +54,5 @@ bool ends_with(const std::string& str, const std::string& suffix); std::size_t show_mbytes(std::size_t value) noexcept; double show_gbytes(std::size_t value) noexcept; bool has_locations_on_ways(const std::vector& input_files); -void warn_locations_on_ways_lost(const std::vector& input_files, const std::string& output_format); #endif // UTIL_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f3eb779f..c6aba05d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,7 +99,7 @@ foreach(_cmd IN LISTS OSMIUM_COMMANDS) endif() endforeach() -foreach(_extra_tests formats help misc) +foreach(_extra_tests formats help locations-on-ways misc) message(STATUS "Adding tests in ${_extra_tests}") add_subdirectory(${_extra_tests}) endforeach() diff --git a/test/add-locations-to-ways/CMakeLists.txt b/test/add-locations-to-ways/CMakeLists.txt deleted file mode 100644 index 7ce8cbc4..00000000 --- a/test/add-locations-to-ways/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -#----------------------------------------------------------------------------- -# -# CMake Config -# -# Osmium Tool Tests - add-locations-to-ways -# -#----------------------------------------------------------------------------- - -function(check_add_locations_to_ways _name _options _input _output) - check_output(add-locations-to-ways ${_name} "add-locations-to-ways ${_options} --generator=test --output-header=xml_josm_upload=false --output-format=xml add-locations-to-ways/${_input}" "add-locations-to-ways/${_output}") -endfunction() - -check_add_locations_to_ways(taggednodes "" input.osm output.osm) -check_add_locations_to_ways(allnodes "-n" input.osm output-n.osm) -check_add_locations_to_ways(membernodes "--keep-member-nodes" input-rel.osm output-rel.osm) - - -#----------------------------------------------------------------------------- diff --git a/test/add-locations-to-ways/input-rel.osm b/test/add-locations-to-ways/input-rel.osm deleted file mode 100644 index a6eb93a1..00000000 --- a/test/add-locations-to-ways/input-rel.osm +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/test/add-locations-to-ways/input.osm b/test/add-locations-to-ways/input.osm deleted file mode 100644 index 6d8a2380..00000000 --- a/test/add-locations-to-ways/input.osm +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/add-locations-to-ways/output-n.osm b/test/add-locations-to-ways/output-n.osm deleted file mode 100644 index 2004eab5..00000000 --- a/test/add-locations-to-ways/output-n.osm +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/add-locations-to-ways/output-rel.osm b/test/add-locations-to-ways/output-rel.osm deleted file mode 100644 index f954f5bd..00000000 --- a/test/add-locations-to-ways/output-rel.osm +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/test/add-locations-to-ways/output.osm b/test/add-locations-to-ways/output.osm deleted file mode 100644 index 9332f7b7..00000000 --- a/test/add-locations-to-ways/output.osm +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index fe85b5ee..a68b3b11 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,28 +14,6 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() -function(check_warning _name _input _format _expected_stderr) - set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/warning-${_name}.osm --overwrite") - add_test( - NAME "cat-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake - ) -endfunction() - -function(check_no_warning _name _input _format) - set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/cat/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/cat/no-warning-${_name}.osm --overwrite") - add_test( - NAME "cat-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake - ) -endfunction() - - #----------------------------------------------------------------------------- check_cat(cat12 input1.osm input2.osm output-cat12.osm) @@ -47,9 +25,5 @@ check_convert(bzip2 input1.osm.bz2 output1.osm.opl opl) check_convert(pbf input1.osm.pbf output1.osm.opl opl) check_convert(opl output1.osm.opl output1.osm.opl opl) -check_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") - -check_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) - #----------------------------------------------------------------------------- diff --git a/test/cat/input-with-locations.osm.pbf b/test/cat/input-with-locations.osm.pbf deleted file mode 100644 index ffc72ac17c3f03e5e2aaf33d8dda9170510fbf5c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 181 zcmV;m080M=000dN2~Sf^NM&JUWpWrv5Iq`2c$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiEjm_sLIAEXmBzEB4O|Ppm9%V&u&)&dn^%)i=~Lw9qpE0AB?Yp#T5?3knBM zQ%yu+bYU1w5KS6Lc%0+n;9}rnDM>9Z5poo==VE4JV$zc3VrFDy6k=cSVaX{j1_mi+ jCI$v25TOMkoOl{;9pQvwFE$X#z!1dDz`y_i5RVWZo4-cN diff --git a/test/cat/input-without-locations.osm.pbf b/test/cat/input-without-locations.osm.pbf deleted file mode 100644 index 5884b660628ed454889aa4c40fc78687c41b70e9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 164 zcmV;V09*e6000dN2~Sf^NM&JUWpWre5G)!rc$`z>^DoW~PR>ZpP1FrD&@)rwa!JiA zPW8)ANiA+-tGcp7dU;e=r? SHW10c5X8*DzyJUcj}RW3syzV! diff --git a/test/locations-on-ways/CMakeLists.txt b/test/locations-on-ways/CMakeLists.txt new file mode 100644 index 00000000..32f53a4b --- /dev/null +++ b/test/locations-on-ways/CMakeLists.txt @@ -0,0 +1,72 @@ +# +# Test LocationsOnWays warning functionality across multiple commands +# + +function(check_warning_cat _name _input _format _expected_stderr) + set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-cat-${_name}.osm --overwrite") + add_test( + NAME "locations-on-ways-cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_stderr.cmake + ) +endfunction() + +function(check_no_warning_cat _name _input _format) + set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-cat-${_name}.osm --overwrite") + add_test( + NAME "locations-on-ways-cat-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake + ) +endfunction() + +function(check_warning_sort _name _input _format _expected_stderr) + set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}.osm --overwrite") + add_test( + NAME "locations-on-ways-sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}-mp.osm --overwrite") + add_test( + NAME "locations-on-ways-sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -D expected_stderr:STRING=${_expected_stderr} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_stderr.cmake + ) +endfunction() + +function(check_no_warning_sort _name _input _format) + set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}.osm --overwrite") + add_test( + NAME "locations-on-ways-sort-${_name}" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake + ) + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}-mp.osm --overwrite") + add_test( + NAME "locations-on-ways-sort-${_name}-mp" + COMMAND ${CMAKE_COMMAND} + -D cmd:FILEPATH=${_cmd_mp} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake + ) +endfunction() + +#----------------------------------------------------------------------------- + +# Test cases with files that HAVE locations on ways - should warn when output format doesn't preserve them +check_warning_cat(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") +check_warning_sort(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") + +# Test cases with files that DON'T have locations on ways - should NOT warn +check_no_warning_cat(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) +check_no_warning_sort(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) + +#----------------------------------------------------------------------------- \ No newline at end of file diff --git a/test/add-locations-to-ways/input-with-locations.osm.pbf b/test/locations-on-ways/input-with-locations.osm.pbf similarity index 100% rename from test/add-locations-to-ways/input-with-locations.osm.pbf rename to test/locations-on-ways/input-with-locations.osm.pbf diff --git a/test/add-locations-to-ways/input-without-locations.osm.pbf b/test/locations-on-ways/input-without-locations.osm.pbf similarity index 100% rename from test/add-locations-to-ways/input-without-locations.osm.pbf rename to test/locations-on-ways/input-without-locations.osm.pbf diff --git a/test/sort/CMakeLists.txt b/test/sort/CMakeLists.txt index a41ce86d..ba8d7ef4 100644 --- a/test/sort/CMakeLists.txt +++ b/test/sort/CMakeLists.txt @@ -16,42 +16,6 @@ function(check_sort1 _name _input _output _format) check_output(sort ${_name}_mp "sort --generator=test -f ${_format} -s multipass sort/${_input}" "sort/${_output}") endfunction() -function(check_sort_warning _name _input _format _expected_stderr) - set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}.osm --overwrite") - add_test( - NAME "sort-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake - ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/warning-${_name}-mp.osm --overwrite") - add_test( - NAME "sort-${_name}-mp" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd_mp} - -D expected_stderr:STRING=${_expected_stderr} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_stderr.cmake - ) -endfunction() - -function(check_sort_no_warning _name _input _format) - set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}.osm --overwrite") - add_test( - NAME "sort-${_name}" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake - ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/sort/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/sort/no-warning-${_name}-mp.osm --overwrite") - add_test( - NAME "sort-${_name}-mp" - COMMAND ${CMAKE_COMMAND} - -D cmd:FILEPATH=${_cmd_mp} - -P ${CMAKE_SOURCE_DIR}/test/run_test_check_no_stderr.cmake - ) -endfunction() - #----------------------------------------------------------------------------- @@ -68,8 +32,4 @@ check_sort1(mixed-metadata input-simple-onefile.osm output-simple-onefile.osm os check_sort1(history-partially-only-version input-history-partially-only-version.osm output-history-partially-only-version.osm osm) check_sort1(history-only-version input-history-only-version.osm output-history-only-version.osm osm) -check_sort_warning(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") - -check_sort_no_warning(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) - #----------------------------------------------------------------------------- diff --git a/test/sort/input-with-locations.osm.pbf b/test/sort/input-with-locations.osm.pbf deleted file mode 100644 index abd5068d96d3034795f400b4282f0293437b2bdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 429 zcmZQzVBqEA^bhv+NKH&hEt2pQu$6MHm=pZyv;H|=zjGdEeXsBuUoZ}SROES9+wbdX ze^1?OkG`Mu_tQCf=DhZ|^W6Sxbn=p(oYg;fR_E+h^DD+%E*LW~#Ip)7WME+6=3)n$ z?2=fLDB&&ODCJ%;=kcQlNe_}VJ$3a2jYN%}B?%>8ne-qjDMchH`a|MLO+7YEH8nO> zg=V0jxa}WK`mwWgnDR)O{%Vfol&PGOtmK}Vos3zMBm`GUzO%{Tg{4nX1DNB;F zBCDz;pQWlDpIalRwVH0~)P#_PD+wh@NlD+5CJAsPB_*&hylCZ6LN(1vz*Nc(#hsT# zf}ST$xghimdEJRNd5c-PF{lwe2f5iqqlU-dDh8XvDz4lFc2DYM{4(3)tgA zkANOuw_?qsBtIXoXOJMcH2Km)0nwzCDM=|oj~*w8%-E28DJYE7jn$1eOf(Ns9iEcv4f3O;b&cO;zCsZi zB;iUzNm5eMx1>n|97#zDEDSGNIh0UMa}qF>vO{s_C6S=#NmDKeJp;Ki7VJt*H#Jo^ zHC;C~^=WPUijCrQc(?Zzuo)ULFtB8E$D Date: Tue, 9 Sep 2025 10:41:36 +0200 Subject: [PATCH 25/35] Revert temp changes --- .github/workflows/ci.yml | 11 +++++++++++ cmake/run_test_check_no_stderr.cmake | 2 +- cmake/run_test_check_stderr.cmake | 2 +- test/add-locations-to-ways/CMakeLists.txt | 18 ++++++++++++++++++ test/add-locations-to-ways/input-rel.osm | 18 ++++++++++++++++++ test/add-locations-to-ways/input.osm | 22 ++++++++++++++++++++++ test/add-locations-to-ways/output-n.osm | 22 ++++++++++++++++++++++ test/add-locations-to-ways/output-rel.osm | 16 ++++++++++++++++ test/add-locations-to-ways/output.osm | 18 ++++++++++++++++++ test/cat/CMakeLists.txt | 1 + 10 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 test/add-locations-to-ways/CMakeLists.txt create mode 100644 test/add-locations-to-ways/input-rel.osm create mode 100644 test/add-locations-to-ways/input.osm create mode 100644 test/add-locations-to-ways/output-n.osm create mode 100644 test/add-locations-to-ways/output-rel.osm create mode 100644 test/add-locations-to-ways/output.osm diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a023907..9c6b7177 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,16 @@ jobs: fail-fast: false matrix: image: + - "ubuntu:20.04" # gcc 9.3.0, clang 10.0.0, cmake 3.16.3 + - "ubuntu:22.04" # gcc 12.2.0, clang 15.0.7, cmake 3.24.2 - "ubuntu:24.04" # gcc 14.2.0, clang 18.1.3, cmake 3.28.3 + - "debian:bullseye" # gcc 10.2.1, clang 11.0.1, cmake 3.18.4 + - "debian:bookworm" # gcc 12.2.0, clang 15.0.6, cmake 3.25.1 + - "debian:testing" + - "debian:experimental" + - "fedora:39" + - "fedora:40" + - "fedora:41" build_type: [Dev] cpp_compiler: [g++] cpp_version: [c++14] @@ -154,6 +163,7 @@ jobs: fail-fast: false matrix: os: + - macos-14 - macos-15 build_type: [Dev] include: @@ -178,6 +188,7 @@ jobs: fail-fast: false matrix: os: + - windows-2022 - windows-2025 steps: - run: | diff --git a/cmake/run_test_check_no_stderr.cmake b/cmake/run_test_check_no_stderr.cmake index 1232c136..660bd9bc 100644 --- a/cmake/run_test_check_no_stderr.cmake +++ b/cmake/run_test_check_no_stderr.cmake @@ -1,5 +1,5 @@ # -# Simple test script to check that stderr does not contain warning message +# Test script to check that stderr does not contain a warning message # if(NOT cmd) diff --git a/cmake/run_test_check_stderr.cmake b/cmake/run_test_check_stderr.cmake index 676e0559..4448b3ed 100644 --- a/cmake/run_test_check_stderr.cmake +++ b/cmake/run_test_check_stderr.cmake @@ -1,5 +1,5 @@ # -# Simple test script to check that stderr contains expected warning message +# Test script to check that stderr contains the expected warning message # if(NOT cmd) diff --git a/test/add-locations-to-ways/CMakeLists.txt b/test/add-locations-to-ways/CMakeLists.txt new file mode 100644 index 00000000..7ce8cbc4 --- /dev/null +++ b/test/add-locations-to-ways/CMakeLists.txt @@ -0,0 +1,18 @@ +#----------------------------------------------------------------------------- +# +# CMake Config +# +# Osmium Tool Tests - add-locations-to-ways +# +#----------------------------------------------------------------------------- + +function(check_add_locations_to_ways _name _options _input _output) + check_output(add-locations-to-ways ${_name} "add-locations-to-ways ${_options} --generator=test --output-header=xml_josm_upload=false --output-format=xml add-locations-to-ways/${_input}" "add-locations-to-ways/${_output}") +endfunction() + +check_add_locations_to_ways(taggednodes "" input.osm output.osm) +check_add_locations_to_ways(allnodes "-n" input.osm output-n.osm) +check_add_locations_to_ways(membernodes "--keep-member-nodes" input-rel.osm output-rel.osm) + + +#----------------------------------------------------------------------------- diff --git a/test/add-locations-to-ways/input-rel.osm b/test/add-locations-to-ways/input-rel.osm new file mode 100644 index 00000000..a6eb93a1 --- /dev/null +++ b/test/add-locations-to-ways/input-rel.osm @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/add-locations-to-ways/input.osm b/test/add-locations-to-ways/input.osm new file mode 100644 index 00000000..6d8a2380 --- /dev/null +++ b/test/add-locations-to-ways/input.osm @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/add-locations-to-ways/output-n.osm b/test/add-locations-to-ways/output-n.osm new file mode 100644 index 00000000..2004eab5 --- /dev/null +++ b/test/add-locations-to-ways/output-n.osm @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/add-locations-to-ways/output-rel.osm b/test/add-locations-to-ways/output-rel.osm new file mode 100644 index 00000000..f954f5bd --- /dev/null +++ b/test/add-locations-to-ways/output-rel.osm @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/test/add-locations-to-ways/output.osm b/test/add-locations-to-ways/output.osm new file mode 100644 index 00000000..9332f7b7 --- /dev/null +++ b/test/add-locations-to-ways/output.osm @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/test/cat/CMakeLists.txt b/test/cat/CMakeLists.txt index a68b3b11..05192ff0 100644 --- a/test/cat/CMakeLists.txt +++ b/test/cat/CMakeLists.txt @@ -14,6 +14,7 @@ function(check_convert _name _input _output _format) check_output(cat ${_name} "cat --no-progress --generator=test cat/${_input} -f ${_format}" "cat/${_output}") endfunction() + #----------------------------------------------------------------------------- check_cat(cat12 input1.osm input2.osm output-cat12.osm) From 3efe9aefcabf713a637e22eae0a48f4a9e8c3f17 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Tue, 9 Sep 2025 12:44:47 +0200 Subject: [PATCH 26/35] Fix uninit shared ptr --- src/command_apply_changes.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 22d712dc..a35747c8 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -355,12 +355,14 @@ bool CommandApplyChanges::run() { } else { m_vout << "Applying changes and writing them to output...\n"; const auto input = osmium::io::make_input_iterator_range(reader); + auto input_begin = input.begin(); + auto input_end = input.end(); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); std::set_union(objects.begin(), objects.end(), - input.begin(), - input.end(), + input_begin, + input_end, output_it, osmium::object_order_type_id_reverse_version()); } From 198020802057dda7b1a628dc9661193001a409d6 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 10:34:22 +0200 Subject: [PATCH 27/35] Remove input_begin, input_end --- src/cmd.cpp | 6 +++--- src/command_apply_changes.cpp | 6 ++---- src/util.cpp | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/cmd.cpp b/src/cmd.cpp index e9db60c1..9c82a7c4 100644 --- a/src/cmd.cpp +++ b/src/cmd.cpp @@ -180,9 +180,9 @@ std::string check_index_type(const std::string& index_type_name, bool allow_none } void with_osm_output::warn_locations_on_ways_lost(const std::vector& input_files, const Command& command) const { - if (command.should_warn_locations_lost() && - has_locations_on_ways(input_files) && + if (command.should_warn_locations_lost() && + has_locations_on_ways(input_files) && m_output_format.find("locations_on_ways") == std::string::npos) { - warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways.\n"); + warning("Input file contains locations on ways that will be lost in output. Use --output-format with locations_on_ways option to preserve node locations on ways."); } } diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index a35747c8..22d712dc 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -355,14 +355,12 @@ bool CommandApplyChanges::run() { } else { m_vout << "Applying changes and writing them to output...\n"; const auto input = osmium::io::make_input_iterator_range(reader); - auto input_begin = input.begin(); - auto input_end = input.end(); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); std::set_union(objects.begin(), objects.end(), - input_begin, - input_end, + input.begin(), + input.end(), output_it, osmium::object_order_type_id_reverse_version()); } diff --git a/src/util.cpp b/src/util.cpp index eaf2c2d3..e7899ad3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -282,7 +282,7 @@ bool has_locations_on_ways(const std::vector& input_files) { try { osmium::io::Reader reader{file, osmium::osm_entity_bits::nothing}; const osmium::io::Header& header = reader.header(); - + for (const auto& option : header) { if (option.first.find("pbf_optional_feature") != std::string::npos && option.second == "LocationsOnWays") { From 5d06e86256ea4778bdf8250713d4ef440de31bd9 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 10:54:31 +0200 Subject: [PATCH 28/35] Revert input_begin, input_end for gcc 15 --- src/command_apply_changes.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 22d712dc..a35747c8 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -355,12 +355,14 @@ bool CommandApplyChanges::run() { } else { m_vout << "Applying changes and writing them to output...\n"; const auto input = osmium::io::make_input_iterator_range(reader); + auto input_begin = input.begin(); + auto input_end = input.end(); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); std::set_union(objects.begin(), objects.end(), - input.begin(), - input.end(), + input_begin, + input_end, output_it, osmium::object_order_type_id_reverse_version()); } From dab577ecabe7f7b737fd6cb9465e044d57906a08 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 11:03:01 +0200 Subject: [PATCH 29/35] Change tests to use multiple files --- test/locations-on-ways/CMakeLists.txt | 46 +++++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/test/locations-on-ways/CMakeLists.txt b/test/locations-on-ways/CMakeLists.txt index 32f53a4b..b1ecf6f5 100644 --- a/test/locations-on-ways/CMakeLists.txt +++ b/test/locations-on-ways/CMakeLists.txt @@ -2,8 +2,12 @@ # Test LocationsOnWays warning functionality across multiple commands # -function(check_warning_cat _name _input _format _expected_stderr) - set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-cat-${_name}.osm --overwrite") +function(check_warning_cat _name _format _expected_stderr) + set(_input_paths "") + foreach(_file ${ARGN}) + set(_input_paths "${_input_paths} ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_file}") + endforeach() + set(_cmd "$ cat --no-progress --generator=test${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-cat-${_name}.osm --overwrite") add_test( NAME "locations-on-ways-cat-${_name}" COMMAND ${CMAKE_COMMAND} @@ -13,8 +17,12 @@ function(check_warning_cat _name _input _format _expected_stderr) ) endfunction() -function(check_no_warning_cat _name _input _format) - set(_cmd "$ cat --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-cat-${_name}.osm --overwrite") +function(check_no_warning_cat _name _format) + set(_input_paths "") + foreach(_file ${ARGN}) + set(_input_paths "${_input_paths} ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_file}") + endforeach() + set(_cmd "$ cat --no-progress --generator=test${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-cat-${_name}.osm --overwrite") add_test( NAME "locations-on-ways-cat-${_name}" COMMAND ${CMAKE_COMMAND} @@ -23,8 +31,12 @@ function(check_no_warning_cat _name _input _format) ) endfunction() -function(check_warning_sort _name _input _format _expected_stderr) - set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}.osm --overwrite") +function(check_warning_sort _name _format _expected_stderr) + set(_input_paths "") + foreach(_file ${ARGN}) + set(_input_paths "${_input_paths} ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_file}") + endforeach() + set(_cmd "$ sort --no-progress --generator=test${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}.osm --overwrite") add_test( NAME "locations-on-ways-sort-${_name}" COMMAND ${CMAKE_COMMAND} @@ -32,7 +44,7 @@ function(check_warning_sort _name _input _format _expected_stderr) -D expected_stderr:STRING=${_expected_stderr} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_stderr.cmake ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}-mp.osm --overwrite") + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}-mp.osm --overwrite") add_test( NAME "locations-on-ways-sort-${_name}-mp" COMMAND ${CMAKE_COMMAND} @@ -42,15 +54,19 @@ function(check_warning_sort _name _input _format _expected_stderr) ) endfunction() -function(check_no_warning_sort _name _input _format) - set(_cmd "$ sort --no-progress --generator=test ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}.osm --overwrite") +function(check_no_warning_sort _name _format) + set(_input_paths "") + foreach(_file ${ARGN}) + set(_input_paths "${_input_paths} ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_file}") + endforeach() + set(_cmd "$ sort --no-progress --generator=test${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}.osm --overwrite") add_test( NAME "locations-on-ways-sort-${_name}" COMMAND ${CMAKE_COMMAND} -D cmd:FILEPATH=${_cmd} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass ${CMAKE_SOURCE_DIR}/test/locations-on-ways/${_input} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}-mp.osm --overwrite") + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}-mp.osm --overwrite") add_test( NAME "locations-on-ways-sort-${_name}-mp" COMMAND ${CMAKE_COMMAND} @@ -62,11 +78,13 @@ endfunction() #----------------------------------------------------------------------------- # Test cases with files that HAVE locations on ways - should warn when output format doesn't preserve them -check_warning_cat(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") -check_warning_sort(warning-pbf-to-xml input-with-locations.osm.pbf xml "WARNING: Input file contains locations on ways that will be lost in output.") +# Uses multiple files where one has locations on ways +check_warning_cat(warning-pbf-to-xml xml "WARNING: Input file contains locations on ways that will be lost in output." input-with-locations.osm.pbf input-without-locations.osm.pbf) +check_warning_sort(warning-pbf-to-xml xml "WARNING: Input file contains locations on ways that will be lost in output." input-with-locations.osm.pbf input-without-locations.osm.pbf) # Test cases with files that DON'T have locations on ways - should NOT warn -check_no_warning_cat(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) -check_no_warning_sort(no-warning-pbf-to-xml input-without-locations.osm.pbf xml) +# Uses multiple files where none have locations on ways +check_no_warning_cat(no-warning-pbf-to-xml xml input-without-locations.osm.pbf input-without-locations.osm.pbf) +check_no_warning_sort(no-warning-pbf-to-xml xml input-without-locations.osm.pbf input-without-locations.osm.pbf) #----------------------------------------------------------------------------- \ No newline at end of file From bde61f66a2757b49eb3ff3f9936b3635f5f9fb2c Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 11:13:01 +0200 Subject: [PATCH 30/35] Rename multipass tests to _mp --- test/locations-on-ways/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/locations-on-ways/CMakeLists.txt b/test/locations-on-ways/CMakeLists.txt index b1ecf6f5..bd368656 100644 --- a/test/locations-on-ways/CMakeLists.txt +++ b/test/locations-on-ways/CMakeLists.txt @@ -44,9 +44,9 @@ function(check_warning_sort _name _format _expected_stderr) -D expected_stderr:STRING=${_expected_stderr} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_stderr.cmake ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}-mp.osm --overwrite") + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/warning-sort-${_name}_mp.osm --overwrite") add_test( - NAME "locations-on-ways-sort-${_name}-mp" + NAME "locations-on-ways-sort-${_name}_mp" COMMAND ${CMAKE_COMMAND} -D cmd:FILEPATH=${_cmd_mp} -D expected_stderr:STRING=${_expected_stderr} @@ -66,9 +66,9 @@ function(check_no_warning_sort _name _format) -D cmd:FILEPATH=${_cmd} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake ) - set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}-mp.osm --overwrite") + set(_cmd_mp "$ sort --no-progress --generator=test -s multipass${_input_paths} -f ${_format} -o ${CMAKE_BINARY_DIR}/test/locations-on-ways/no-warning-sort-${_name}_mp.osm --overwrite") add_test( - NAME "locations-on-ways-sort-${_name}-mp" + NAME "locations-on-ways-sort-${_name}_mp" COMMAND ${CMAKE_COMMAND} -D cmd:FILEPATH=${_cmd_mp} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_check_no_stderr.cmake From 29c8c64414ddb08d2856c169c8608f1b0f85ee05 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 11:37:21 +0200 Subject: [PATCH 31/35] Use const auto --- src/command_apply_changes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index a35747c8..46e8960a 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -355,8 +355,8 @@ bool CommandApplyChanges::run() { } else { m_vout << "Applying changes and writing them to output...\n"; const auto input = osmium::io::make_input_iterator_range(reader); - auto input_begin = input.begin(); - auto input_end = input.end(); + const auto input_begin = input.begin(); + const auto input_end = input.end(); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); std::set_union(objects.begin(), From fc519fdd0242c1f47d4ef9ca48fa92bef70d1bd2 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 12:39:08 +0200 Subject: [PATCH 32/35] Remove input_begin, input_end again --- src/command_apply_changes.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 46e8960a..22d712dc 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -355,14 +355,12 @@ bool CommandApplyChanges::run() { } else { m_vout << "Applying changes and writing them to output...\n"; const auto input = osmium::io::make_input_iterator_range(reader); - const auto input_begin = input.begin(); - const auto input_end = input.end(); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); std::set_union(objects.begin(), objects.end(), - input_begin, - input_end, + input.begin(), + input.end(), output_it, osmium::object_order_type_id_reverse_version()); } From 30c7ea41e3dce23c17239d70fc9b1720c6e1b4db Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 12:48:35 +0200 Subject: [PATCH 33/35] Add warn_locations_on_ways_lost --- src/command_apply_changes.cpp | 2 ++ src/command_apply_changes.hpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 22d712dc..c024a84c 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -279,6 +279,8 @@ bool CommandApplyChanges::run() { m_output_file.set("locations_on_ways"); } + warn_locations_on_ways_lost(m_input_files, *this); + m_vout << "Opening output file...\n"; osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; diff --git a/src/command_apply_changes.hpp b/src/command_apply_changes.hpp index af2a4e16..3c06afd8 100644 --- a/src/command_apply_changes.hpp +++ b/src/command_apply_changes.hpp @@ -67,6 +67,10 @@ class CommandApplyChanges : public CommandWithSingleOSMInput, public with_osm_ou return "osmium apply-changes [OPTIONS] OSM-FILE OSM-CHANGE-FILE..."; } + bool should_warn_locations_lost() const override { + return true; + } + }; // class CommandApplyChanges From c14f8673bfe7656959147bee0cc7e4d7f9c20d25 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 13:09:36 +0200 Subject: [PATCH 34/35] Fix the call --- src/command_apply_changes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index c024a84c..3dc94578 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -279,7 +279,7 @@ bool CommandApplyChanges::run() { m_output_file.set("locations_on_ways"); } - warn_locations_on_ways_lost(m_input_files, *this); + warn_locations_on_ways_lost({m_input_file}, *this); m_vout << "Opening output file...\n"; osmium::io::Writer writer{m_output_file, m_output_overwrite, m_fsync}; From 4cbf18094e8369b303e2763418f6220a87477e71 Mon Sep 17 00:00:00 2001 From: Alexander Farber Date: Sat, 27 Sep 2025 17:13:48 +0200 Subject: [PATCH 35/35] Suppress false positive GCC 15 warning --- src/command_apply_changes.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp index 3dc94578..2d7043e1 100644 --- a/src/command_apply_changes.cpp +++ b/src/command_apply_changes.cpp @@ -359,12 +359,20 @@ bool CommandApplyChanges::run() { const auto input = osmium::io::make_input_iterator_range(reader); auto output_it = boost::make_function_output_iterator(copy_first_with_id(&writer)); + // Suppress false positive GCC 15 warning with boost::make_function_output_iterator +#if defined(__GNUC__) && (__GNUC__ >= 15) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif std::set_union(objects.begin(), objects.end(), input.begin(), input.end(), output_it, osmium::object_order_type_id_reverse_version()); +#if defined(__GNUC__) && (__GNUC__ >= 15) +#pragma GCC diagnostic pop +#endif } }