Skip to content

Commit 84aadc0

Browse files
committed
Add debug access to pending way/relation ids in dependency manager
This makes it easier to test the class without a fake pending_processor
1 parent bb2cf86 commit 84aadc0

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

src/dependency-manager.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,44 @@ class full_dependency_manager_t : public dependency_manager_t
102102

103103
void process_pending(middle_t::pending_processor &pf) override;
104104

105+
/**
106+
* Get access to the pending way ids. This is for debugging only.
107+
*
108+
* Note that the list of pending way ids will be empty after calling
109+
* this.
110+
*
111+
* \tparam TOutputIterator Some output iterator type, for instance
112+
* created with std::back_inserter(some vector).
113+
* \param it output iterator to which all ids should be written. *it
114+
* must be of type osmid_t.
115+
*/
116+
template <typename TOutputIterator>
117+
void get_pending_way_ids(TOutputIterator &&it) {
118+
osmid_t id;
119+
while (id_tracker::is_valid(id = m_ways_pending_tracker.pop_mark())) {
120+
*it++ = id;
121+
}
122+
}
123+
124+
/**
125+
* Get access to the pending relation ids. This is for debugging only.
126+
*
127+
* Note that the list of pending relation ids will be empty after calling
128+
* this.
129+
*
130+
* \tparam TOutputIterator Some output iterator type, for instance
131+
* created with std::back_inserter(some vector).
132+
* \param it output iterator to which all ids should be written. *it
133+
* must be of type osmid_t.
134+
*/
135+
template <typename TOutputIterator>
136+
void get_pending_relation_ids(TOutputIterator &&it) {
137+
osmid_t id;
138+
while (id_tracker::is_valid(id = m_rels_pending_tracker.pop_mark())) {
139+
*it++ = id;
140+
}
141+
}
142+
105143
private:
106144
middle_t* m_object_store;
107145

tests/test-middle.cpp

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,20 +1007,6 @@ TEMPLATE_TEST_CASE("middle: add relation with attributes", "",
10071007
}
10081008
}
10091009

1010-
struct test_pending_processor : public middle_t::pending_processor
1011-
{
1012-
test_pending_processor() = default;
1013-
1014-
void enqueue_ways(osmid_t id) override { m_way_ids.push_back(id); }
1015-
void enqueue_relations(osmid_t id) override { m_rel_ids.push_back(id); }
1016-
1017-
void process_ways() override {}
1018-
void process_relations() override {}
1019-
1020-
std::vector<osmid_t> m_way_ids;
1021-
std::vector<osmid_t> m_rel_ids;
1022-
};
1023-
10241010
TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10251011
options_slim_dense_cache, options_flat_node_cache)
10261012
{
@@ -1065,11 +1051,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10651051
check_way(mid, way21);
10661052
check_way_nodes(mid, way21.id(), {&node11, &node12});
10671053

1068-
// Nothing pending yet
10691054
REQUIRE_FALSE(dependency_manager.has_pending());
1070-
test_pending_processor proc;
1071-
dependency_manager.process_pending(proc);
1072-
REQUIRE(proc.m_way_ids.empty());
10731055

10741056
mid->commit();
10751057
}
@@ -1089,9 +1071,9 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10891071
mid->flush();
10901072

10911073
REQUIRE(dependency_manager.has_pending());
1092-
test_pending_processor proc;
1093-
dependency_manager.process_pending(proc);
1094-
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20}));
1074+
idlist_t way_ids;
1075+
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1076+
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
10951077

10961078
check_way(mid, way20);
10971079
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1122,9 +1104,9 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11221104
mid->flush();
11231105

11241106
REQUIRE(dependency_manager.has_pending());
1125-
test_pending_processor proc;
1126-
dependency_manager.process_pending(proc);
1127-
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20, 22}));
1107+
idlist_t way_ids;
1108+
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1109+
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20, 22}));
11281110

11291111
check_way(mid, way20);
11301112
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1162,9 +1144,6 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11621144
mid->flush();
11631145

11641146
REQUIRE_FALSE(dependency_manager.has_pending());
1165-
test_pending_processor proc;
1166-
dependency_manager.process_pending(proc);
1167-
REQUIRE(proc.m_way_ids.empty());
11681147

11691148
mid->commit();
11701149
}
@@ -1228,10 +1207,10 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12281207
mid->flush();
12291208

12301209
REQUIRE(dependency_manager.has_pending());
1231-
test_pending_processor proc;
1232-
dependency_manager.process_pending(proc);
1210+
idlist_t rel_ids;
1211+
dependency_manager.get_pending_relation_ids(std::back_inserter(rel_ids));
12331212

1234-
REQUIRE_THAT(proc.m_rel_ids, Catch::Equals<osmid_t>({30}));
1213+
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({30}));
12351214
check_relation(mid, rel30);
12361215

12371216
mid->commit();
@@ -1249,10 +1228,12 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12491228
mid->flush();
12501229

12511230
REQUIRE(dependency_manager.has_pending());
1252-
test_pending_processor proc;
1253-
dependency_manager.process_pending(proc);
1254-
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20}));
1255-
REQUIRE_THAT(proc.m_rel_ids, Catch::Equals<osmid_t>({31}));
1231+
idlist_t way_ids;
1232+
dependency_manager.get_pending_way_ids(std::back_inserter(way_ids));
1233+
REQUIRE_THAT(way_ids, Catch::Equals<osmid_t>({20}));
1234+
idlist_t rel_ids;
1235+
dependency_manager.get_pending_relation_ids(std::back_inserter(rel_ids));
1236+
REQUIRE_THAT(rel_ids, Catch::Equals<osmid_t>({31}));
12561237
check_relation(mid, rel31);
12571238
}
12581239
}

0 commit comments

Comments
 (0)