@@ -92,19 +92,29 @@ struct counting_output_t : public output_null_t
9292 unsigned sum_members = 0 ;
9393};
9494
95+ struct counts_t {
96+ std::size_t nodes_changed = 0 ;
97+ std::size_t ways_changed = 0 ;
98+ std::size_t relations_changed = 0 ;
99+ };
100+
95101/* *
96102 * This pseudo-dependency manager is just used for testing. It counts how
97103 * often the *_changed() member functions are called.
98104 */
99- struct counting_dependency_manager_t : public dependency_manager_t
105+ class counting_dependency_manager_t : public dependency_manager_t
100106{
101- void node_changed (osmid_t ) override { ++nodes_changed; }
102- void way_changed (osmid_t ) override { ++ways_changed; }
103- void relation_changed (osmid_t ) override { ++relations_changed; }
107+ public:
108+ counting_dependency_manager_t (std::shared_ptr<counts_t > counts)
109+ : m_counts(std::move(counts))
110+ {}
104111
105- std::size_t nodes_changed = 0 ;
106- std::size_t ways_changed = 0 ;
107- std::size_t relations_changed = 0 ;
112+ void node_changed (osmid_t ) override { ++m_counts->nodes_changed ; }
113+ void way_changed (osmid_t ) override { ++m_counts->ways_changed ; }
114+ void relation_changed (osmid_t ) override { ++m_counts->relations_changed ; }
115+
116+ private:
117+ std::shared_ptr<counts_t > m_counts;
108118};
109119
110120TEST_CASE (" parse xml file" )
@@ -114,10 +124,12 @@ TEST_CASE("parse xml file")
114124 auto const middle = std::make_shared<counting_slim_middle_t >();
115125 std::shared_ptr<output_t > output{new counting_output_t {options}};
116126
117- counting_dependency_manager_t dependency_manager;
127+ auto counts = std::make_shared<counts_t >();
128+ auto dependency_manager = std::unique_ptr<dependency_manager_t >(
129+ new counting_dependency_manager_t {counts});
118130
119- testing::parse_file (options, & dependency_manager, middle, {output} ,
120- " test_multipolygon.osm" );
131+ testing::parse_file (options, std::move ( dependency_manager) , middle,
132+ {output}, " test_multipolygon.osm" );
121133
122134 auto const *out_test = static_cast <counting_output_t *>(output.get ());
123135 REQUIRE (out_test->sum_ids == 4728 );
@@ -141,9 +153,9 @@ TEST_CASE("parse xml file")
141153 REQUIRE (mid_test->relation .added == 40 );
142154 REQUIRE (mid_test->relation .deleted == 0 );
143155
144- REQUIRE (dependency_manager. nodes_changed == 0 );
145- REQUIRE (dependency_manager. ways_changed == 0 );
146- REQUIRE (dependency_manager. relations_changed == 0 );
156+ REQUIRE (counts-> nodes_changed == 0 );
157+ REQUIRE (counts-> ways_changed == 0 );
158+ REQUIRE (counts-> relations_changed == 0 );
147159}
148160
149161TEST_CASE (" parse diff file" )
@@ -153,10 +165,12 @@ TEST_CASE("parse diff file")
153165 auto const middle = std::make_shared<counting_slim_middle_t >();
154166 std::shared_ptr<output_t > output{new counting_output_t {options}};
155167
156- counting_dependency_manager_t dependency_manager;
168+ auto counts = std::make_shared<counts_t >();
169+ auto dependency_manager = std::unique_ptr<dependency_manager_t >(
170+ new counting_dependency_manager_t {counts});
157171
158- testing::parse_file (options, & dependency_manager, middle, {output} ,
159- " 008-ch.osc.gz" );
172+ testing::parse_file (options, std::move ( dependency_manager) , middle,
173+ {output}, " 008-ch.osc.gz" );
160174
161175 auto const *out_test = static_cast <counting_output_t *>(output.get ());
162176 REQUIRE (out_test->node .added == 0 );
@@ -177,9 +191,9 @@ TEST_CASE("parse diff file")
177191 REQUIRE (mid_test->relation .added == 11 );
178192 REQUIRE (mid_test->relation .deleted == 12 );
179193
180- REQUIRE (dependency_manager. nodes_changed == 1176 );
181- REQUIRE (dependency_manager. ways_changed == 161 );
182- REQUIRE (dependency_manager. relations_changed == 11 );
194+ REQUIRE (counts-> nodes_changed == 1176 );
195+ REQUIRE (counts-> ways_changed == 161 );
196+ REQUIRE (counts-> relations_changed == 11 );
183197}
184198
185199TEST_CASE (" parse xml file with extra args" )
@@ -190,10 +204,12 @@ TEST_CASE("parse xml file with extra args")
190204 auto const middle = std::make_shared<counting_slim_middle_t >();
191205 std::shared_ptr<output_t > output{new counting_output_t {options}};
192206
193- counting_dependency_manager_t dependency_manager;
207+ auto counts = std::make_shared<counts_t >();
208+ auto dependency_manager = std::unique_ptr<dependency_manager_t >(
209+ new counting_dependency_manager_t {counts});
194210
195- testing::parse_file (options, & dependency_manager, middle, {output} ,
196- " test_multipolygon.osm" );
211+ testing::parse_file (options, std::move ( dependency_manager) , middle,
212+ {output}, " test_multipolygon.osm" );
197213
198214 auto const *out_test = static_cast <counting_output_t *>(output.get ());
199215 REQUIRE (out_test->sum_ids == 73514 );
@@ -217,7 +233,7 @@ TEST_CASE("parse xml file with extra args")
217233 REQUIRE (mid_test->relation .added == 40 );
218234 REQUIRE (mid_test->relation .deleted == 0 );
219235
220- REQUIRE (dependency_manager. nodes_changed == 0 );
221- REQUIRE (dependency_manager. ways_changed == 0 );
222- REQUIRE (dependency_manager. relations_changed == 0 );
236+ REQUIRE (counts-> nodes_changed == 0 );
237+ REQUIRE (counts-> ways_changed == 0 );
238+ REQUIRE (counts-> relations_changed == 0 );
223239}
0 commit comments