Skip to content

Commit 7dfa762

Browse files
committed
Add parametrized unit tests for sort
1 parent 51071e2 commit 7dfa762

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(ALL_UNIT_TESTS
1616
cat/test_warning.cpp
1717
diff/test_setup.cpp
1818
extract/test_unit.cpp
19+
sort/test_warning.cpp
1920
time-filter/test_setup.cpp
2021
util/test_unit.cpp
2122
)

test/sort/test_warning.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "test.hpp" // IWYU pragma: keep
2+
3+
#include "command_sort.hpp"
4+
5+
#include <osmium/memory/buffer.hpp>
6+
#include <osmium/builder/osm_object_builder.hpp>
7+
8+
TEST_CASE("sort locations on ways warning") {
9+
const CommandFactory factory;
10+
11+
auto format = GENERATE("xml", "pbf", "opl");
12+
13+
SECTION("detection logic with way containing locations - " + std::string(format)) {
14+
CommandSort cmd{factory};
15+
std::vector<std::string> args = {"test/sort/input-simple1.osm", "-f", format};
16+
cmd.setup(args);
17+
18+
REQUIRE(cmd.found_locations_on_ways() == false);
19+
REQUIRE(cmd.warned_locations_on_ways() == false);
20+
21+
osmium::memory::Buffer buffer{1024};
22+
osmium::builder::WayBuilder builder{buffer};
23+
builder.set_id(123);
24+
builder.set_version(1);
25+
builder.set_changeset(1);
26+
builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"});
27+
builder.set_uid(1);
28+
builder.set_user("test");
29+
30+
osmium::builder::WayNodeListBuilder wnl_builder{builder};
31+
wnl_builder.add_node_ref(10, osmium::Location{1.0, 1.0});
32+
wnl_builder.add_node_ref(11, osmium::Location{2.0, 1.0});
33+
34+
const auto& way = buffer.get<osmium::Way>(0);
35+
cmd.check_for_locations_on_ways(way);
36+
37+
REQUIRE(cmd.found_locations_on_ways() == true);
38+
REQUIRE(cmd.warned_locations_on_ways() == false);
39+
}
40+
41+
SECTION("detection logic with way without locations - " + std::string(format)) {
42+
CommandSort cmd{factory};
43+
std::vector<std::string> args = {"test/sort/input-simple1.osm", "-f", format};
44+
cmd.setup(args);
45+
46+
REQUIRE(cmd.found_locations_on_ways() == false);
47+
48+
osmium::memory::Buffer buffer{1024};
49+
osmium::builder::WayBuilder builder{buffer};
50+
builder.set_id(123);
51+
builder.set_version(1);
52+
builder.set_changeset(1);
53+
builder.set_timestamp(osmium::Timestamp{"2015-01-01T01:00:00Z"});
54+
builder.set_uid(1);
55+
builder.set_user("test");
56+
57+
osmium::builder::WayNodeListBuilder wnl_builder{builder};
58+
wnl_builder.add_node_ref(10);
59+
wnl_builder.add_node_ref(11);
60+
61+
const auto& way = buffer.get<osmium::Way>(0);
62+
cmd.check_for_locations_on_ways(way);
63+
64+
REQUIRE(cmd.found_locations_on_ways() == false);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)