forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-parse-diff.cpp
More file actions
129 lines (104 loc) · 2.82 KB
/
Copy pathtest-parse-diff.cpp
File metadata and controls
129 lines (104 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "middle.hpp"
#include "tests/mockups.hpp"
#include "options.hpp"
#include "osmdata.hpp"
#include "osmtypes.hpp"
#include "output.hpp"
#include "parse-osmium.hpp"
void exit_nicely()
{
fprintf(stderr, "Error occurred, cleaning up\n");
exit(1);
}
struct type_stats {
unsigned added = 0;
unsigned modified = 0;
unsigned deleted = 0;
};
struct test_output_t : public dummy_output_t {
type_stats node, way, rel;
explicit test_output_t(const options_t &options_)
: dummy_output_t(options_) {
}
virtual ~test_output_t() = default;
std::shared_ptr<output_t>
clone(std::shared_ptr<middle_query_t> const &mid) const override
{
test_output_t *clone = new test_output_t(m_options);
clone->m_mid = mid;
return std::shared_ptr<output_t>(clone);
}
int node_add(osmium::Node const &) override
{
++node.added;
return 0;
}
int way_add(osmium::Way *) override
{
++way.added;
return 0;
}
int relation_add(osmium::Relation const &) override
{
++rel.added;
return 0;
}
int node_modify(osmium::Node const &) override
{
++node.modified;
return 0;
}
int way_modify(osmium::Way *) override {
++way.modified;
return 0;
}
int relation_modify(osmium::Relation const &) override {
++rel.modified;
return 0;
}
int node_delete(osmid_t) override {
++node.deleted;
return 0;
}
int way_delete(osmid_t) override {
++way.deleted;
return 0;
}
int relation_delete(osmid_t) override {
++rel.deleted;
return 0;
}
};
void assert_equal(uint64_t actual, uint64_t expected) {
if (actual != expected) {
std::cerr << "Expected " << expected << ", but got " << actual << ".\n";
exit(1);
}
}
int main() {
std::string inputfile = "tests/008-ch.osc.gz";
options_t options;
std::shared_ptr<reprojection> projection(reprojection::create_projection(PROJ_SPHERE_MERC));
options.projection = projection;
auto out_test = std::make_shared<test_output_t>(options);
osmdata_t osmdata(std::make_shared<dummy_slim_middle_t>(), out_test);
boost::optional<std::string> bbox;
parse_osmium_t parser(bbox, true, &osmdata);
parser.stream_file(inputfile, "");
assert_equal(out_test->node.added, 0);
assert_equal(out_test->node.modified, 1176);
assert_equal(out_test->node.deleted, 16773);
assert_equal(out_test->way.added, 0);
assert_equal(out_test->way.modified, 161);
assert_equal(out_test->way.deleted, 4);
assert_equal(out_test->rel.added, 0);
assert_equal(out_test->rel.modified, 11);
assert_equal(out_test->rel.deleted, 1);
return 0;
}