Skip to content

Commit f99a506

Browse files
committed
Refactored the test for invalid locations and added a test
1 parent b50c2e7 commit f99a506

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

src/osmdata.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,26 @@ osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
3636

3737
void osmdata_t::node(osmium::Node const &node)
3838
{
39-
if (!m_bbox.valid() || node.deleted() || m_bbox.contains(node.location())) {
40-
m_mid->node(node);
41-
}
42-
43-
if (node.deleted()) {
44-
node_delete(node.id());
45-
} else {
46-
// if the node is not valid, then node.location.lat/lon() can throw.
47-
// we probably ought to treat invalid locations as if they were
48-
// deleted and ignore them.
39+
if (node.visible()) {
4940
if (!node.location().valid()) {
50-
log_warn("Ignored invalid location on node {} (version {})",
41+
log_warn("Ignored node {} (version {}) with invalid location.",
5142
node.id(), node.version());
5243
return;
5344
}
45+
if (m_bbox.valid() && !m_bbox.contains(node.location())) {
46+
return;
47+
}
48+
}
5449

55-
if (!m_bbox.valid() || m_bbox.contains(node.location())) {
56-
if (m_append) {
57-
node_modify(node);
58-
} else {
59-
node_add(node);
60-
}
50+
m_mid->node(node);
51+
52+
if (node.deleted()) {
53+
node_delete(node.id());
54+
} else {
55+
if (m_append) {
56+
node_modify(node);
57+
} else {
58+
node_add(node);
6159
}
6260
}
6361
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<osm version="0.6">
3+
<node id="1" visible="true" version="1" changeset="1" timestamp="2018-10-31T10:20:19Z" user="a" uid="1" lon="3.141" lat="200.0">
4+
<tag k="amenity" v="restaurant" />
5+
</node>
6+
</osm>

tests/test-parse-osmium.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,24 @@ TEST_CASE("parse xml file with extra args")
257257
REQUIRE(counts->nodes_changed == 0);
258258
REQUIRE(counts->ways_changed == 0);
259259
}
260+
261+
TEST_CASE("invalid location")
262+
{
263+
options_t options = testing::opt_t();
264+
265+
auto const middle = std::make_shared<counting_middle_t>(false);
266+
std::shared_ptr<output_t> output{new counting_output_t{options}};
267+
268+
auto counts = std::make_shared<counts_t>();
269+
auto dependency_manager = std::unique_ptr<dependency_manager_t>(
270+
new counting_dependency_manager_t{counts});
271+
272+
testing::parse_file(options, std::move(dependency_manager), middle,
273+
{output}, "test_invalid_location.osm", false);
274+
275+
auto const *out_test = static_cast<counting_output_t *>(output.get());
276+
REQUIRE(out_test->node.added == 0);
277+
REQUIRE(out_test->way.added == 0);
278+
REQUIRE(out_test->relation.added == 0);
279+
}
280+

0 commit comments

Comments
 (0)