Skip to content

Commit ce282fe

Browse files
authored
Merge pull request #1531 from joto/input-check-versions
Fix input data check: Two versions of same object are not allowed
2 parents fde0a78 + 79ecae8 commit ce282fe

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

src/input.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "osmdata.hpp"
2222
#include "progress-display.hpp"
2323

24-
type_id_version check_input(type_id_version const &last, type_id_version curr)
24+
type_id check_input(type_id const &last, type_id curr)
2525
{
2626
if (curr.id < 0) {
2727
throw std::runtime_error{
@@ -40,14 +40,10 @@ type_id_version check_input(type_id_version const &last, type_id_version curr)
4040
osmium::item_type_to_name(last.type), curr.id, last.id)};
4141
}
4242

43-
if (last.version < curr.version) {
44-
return curr;
45-
}
46-
4743
throw std::runtime_error{
48-
"Input data is not ordered: {} id {} version {} after {}."_format(
49-
osmium::item_type_to_name(last.type), curr.id, curr.version,
50-
last.version)};
44+
"Input data is not ordered:"
45+
" {} id {} appears more than once."_format(
46+
osmium::item_type_to_name(last.type), curr.id)};
5147
}
5248

5349
if (item_type_to_nwr_index(last.type) <=
@@ -60,10 +56,9 @@ type_id_version check_input(type_id_version const &last, type_id_version curr)
6056
osmium::item_type_to_name(last.type))};
6157
}
6258

63-
type_id_version check_input(type_id_version const &last,
64-
osmium::OSMObject const &object)
59+
type_id check_input(type_id const &last, osmium::OSMObject const &object)
6560
{
66-
return check_input(last, {object.type(), object.id(), object.version()});
61+
return check_input(last, {object.type(), object.id()});
6762
}
6863

6964
/**
@@ -130,7 +125,7 @@ class data_source_t
130125
osmium::memory::Buffer m_buffer{};
131126
iterator m_it{};
132127
iterator m_end{};
133-
type_id_version m_last = {osmium::item_type::node, 0, 0};
128+
type_id m_last = {osmium::item_type::node, 0};
134129

135130
}; // class data_source_t
136131

@@ -274,7 +269,7 @@ static void process_single_file(osmium::io::File const &file,
274269
progress_display_t *progress, bool append)
275270
{
276271
osmium::io::Reader reader{file};
277-
type_id_version last{osmium::item_type::node, 0, 0};
272+
type_id last{osmium::item_type::node, 0};
278273

279274
input_context_t ctx{osmdata, progress, append};
280275
while (osmium::memory::Buffer buffer = reader.read()) {

src/input.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@
2828

2929
class osmdata_t;
3030

31-
struct type_id_version
31+
struct type_id
3232
{
3333
osmium::item_type type;
3434
osmid_t id;
35-
osmium::object_version_type version;
3635
};
3736

3837
/**
39-
* Compare two tuples (type, id, version) throw a descriptive error if either
40-
* the curr id is negative or if the data is not ordered.
38+
* Compare two tuples (type, id). Throw a descriptive error if either the
39+
* curr id is negative or if the data is not ordered.
4140
*/
42-
type_id_version check_input(type_id_version const &last, type_id_version curr);
41+
type_id check_input(type_id const &last, type_id curr);
4342

44-
type_id_version check_input(type_id_version const &last,
45-
osmium::OSMObject const &object);
43+
type_id check_input(type_id const &last, osmium::OSMObject const &object);
4644

4745
/**
4846
* Prepare input file(s). Does format checks as far as this is possible

tests/test-check-input.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,25 @@
1313

1414
TEST_CASE("it's good if input data is ordered", "[NoDB]")
1515
{
16-
type_id_version const tiv1{osmium::item_type::node, 1, 1};
17-
type_id_version const tiv2{osmium::item_type::node, 1, 2};
18-
type_id_version const tiv3{osmium::item_type::node, 2, 1};
19-
type_id_version const tiv4{osmium::item_type::way, 1, 1};
20-
type_id_version const tiv5{osmium::item_type::way, 2, 1};
21-
type_id_version const tiv6{osmium::item_type::relation, 1, 1};
22-
type_id_version const tiv7{osmium::item_type::relation, 1, 2};
16+
type_id const tiv1{osmium::item_type::node, 1};
17+
type_id const tiv2{osmium::item_type::node, 2};
18+
type_id const tiv3{osmium::item_type::way, 1};
19+
type_id const tiv4{osmium::item_type::way, 2};
20+
type_id const tiv5{osmium::item_type::relation, 1};
21+
type_id const tiv6{osmium::item_type::relation, 2};
2322

2423
REQUIRE_NOTHROW(check_input(tiv1, tiv2));
2524
REQUIRE_NOTHROW(check_input(tiv2, tiv3));
2625
REQUIRE_NOTHROW(check_input(tiv3, tiv4));
2726
REQUIRE_NOTHROW(check_input(tiv4, tiv5));
2827
REQUIRE_NOTHROW(check_input(tiv5, tiv6));
29-
REQUIRE_NOTHROW(check_input(tiv6, tiv7));
3028
}
3129

3230
TEST_CASE("negative OSM object ids are not allowed", "[NoDB]")
3331
{
34-
type_id_version const tivn{osmium::item_type::node, -17, 1};
35-
type_id_version const tivw{osmium::item_type::way, -1, 1};
36-
type_id_version const tivr{osmium::item_type::relation, -999, 17};
32+
type_id const tivn{osmium::item_type::node, -17};
33+
type_id const tivw{osmium::item_type::way, -1};
34+
type_id const tivr{osmium::item_type::relation, -999};
3735

3836
REQUIRE_THROWS_WITH(
3937
check_input(tivn, tivn),
@@ -47,18 +45,18 @@ TEST_CASE("negative OSM object ids are not allowed", "[NoDB]")
4745

4846
TEST_CASE("objects of the same type must be ordered", "[NoDB]")
4947
{
50-
type_id_version const tiv1{osmium::item_type::node, 42, 1};
51-
type_id_version const tiv2{osmium::item_type::node, 3, 1};
48+
type_id const tiv1{osmium::item_type::node, 42};
49+
type_id const tiv2{osmium::item_type::node, 3};
5250

5351
REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
5452
"Input data is not ordered: node id 3 after 42.");
5553
}
5654

5755
TEST_CASE("a node after a way or relation is not allowed", "[NoDB]")
5856
{
59-
type_id_version const tiv1w{osmium::item_type::way, 42, 1};
60-
type_id_version const tiv1r{osmium::item_type::relation, 42, 1};
61-
type_id_version const tiv2{osmium::item_type::node, 100, 1};
57+
type_id const tiv1w{osmium::item_type::way, 42};
58+
type_id const tiv1r{osmium::item_type::relation, 42};
59+
type_id const tiv2{osmium::item_type::node, 100};
6260

6361
REQUIRE_THROWS_WITH(check_input(tiv1w, tiv2),
6462
"Input data is not ordered: node after way.");
@@ -68,20 +66,20 @@ TEST_CASE("a node after a way or relation is not allowed", "[NoDB]")
6866

6967
TEST_CASE("a way after a relation is not allowed", "[NoDB]")
7068
{
71-
type_id_version const tiv1{osmium::item_type::relation, 42, 1};
72-
type_id_version const tiv2{osmium::item_type::way, 100, 1};
69+
type_id const tiv1{osmium::item_type::relation, 42};
70+
type_id const tiv2{osmium::item_type::way, 100};
7371

7472
REQUIRE_THROWS_WITH(check_input(tiv1, tiv2),
7573
"Input data is not ordered: way after relation.");
7674
}
7775

78-
TEST_CASE("versions must be ordered", "[NoDB]")
76+
TEST_CASE("no object may appear twice", "[NoDB]")
7977
{
80-
type_id_version const tiv1{osmium::item_type::way, 42, 2};
81-
type_id_version const tiv2{osmium::item_type::way, 42, 1};
78+
type_id const tiv1{osmium::item_type::way, 42};
79+
type_id const tiv2{osmium::item_type::way, 42};
8280

8381
REQUIRE_THROWS_WITH(
8482
check_input(tiv1, tiv2),
85-
"Input data is not ordered: way id 42 version 1 after 2.");
83+
"Input data is not ordered: way id 42 appears more than once.");
8684
}
8785

0 commit comments

Comments
 (0)