Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/command_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ bool CommandSort::run_single_pass() {
osmium::ObjectPointerCollection objects;

osmium::Box bounding_box;
osmium::io::Header merged_input_header;

uint64_t buffers_count = 0;
uint64_t buffers_size = 0;
Expand All @@ -121,6 +122,11 @@ 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();
Expand All @@ -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, merged_input_header);
header.set("sorting", "Type_then_ID");
if (bounding_box) {
header.add_box(bounding_box);
Expand All @@ -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 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);
setup_header(header, merged_input_header);
if (bounding_box) {
header.add_box(bounding_box);
}
Expand Down
30 changes: 30 additions & 0 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& options) {
Expand All @@ -227,5 +242,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);

// 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";
}
}

29 changes: 29 additions & 0 deletions test/add-locations-to-ways/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE:osmium> 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 "$<TARGET_FILE:osmium> 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)


#-----------------------------------------------------------------------------
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions test/add-locations-to-ways/run_test_check_no_stderr.cmake
Original file line number Diff line number Diff line change
@@ -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")
38 changes: 38 additions & 0 deletions test/add-locations-to-ways/run_test_check_stderr.cmake
Original file line number Diff line number Diff line change
@@ -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")
29 changes: 29 additions & 0 deletions test/cat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ 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 "$<TARGET_FILE:osmium> 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 "$<TARGET_FILE:osmium> 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()


#-----------------------------------------------------------------------------

Expand All @@ -26,5 +49,11 @@ 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)


#-----------------------------------------------------------------------------
Binary file added test/cat/input-with-locations.osm.pbf
Binary file not shown.
Binary file added test/cat/input-without-locations.osm.pbf
Binary file not shown.
34 changes: 34 additions & 0 deletions test/cat/run_test_check_no_stderr.cmake
Original file line number Diff line number Diff line change
@@ -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")
38 changes: 38 additions & 0 deletions test/cat/run_test_check_stderr.cmake
Original file line number Diff line number Diff line change
@@ -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")
46 changes: 46 additions & 0 deletions test/sort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,46 @@ 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 "$<TARGET_FILE:osmium> 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 "$<TARGET_FILE:osmium> 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 "$<TARGET_FILE:osmium> 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 "$<TARGET_FILE:osmium> 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()


#-----------------------------------------------------------------------------

Expand All @@ -32,4 +72,10 @@ 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)

#-----------------------------------------------------------------------------
Binary file added test/sort/input-with-locations.osm.pbf
Binary file not shown.
Binary file added test/sort/input-without-locations.osm.pbf
Binary file not shown.
Loading