1 #ifndef MOCK_DATAFACADE_HPP
2 #define MOCK_DATAFACADE_HPP
3 
4 // implements all data storage when shared memory _IS_ used
5 
6 #include "contractor/query_edge.hpp"
7 #include "extractor/class_data.hpp"
8 #include "extractor/maneuver_override.hpp"
9 #include "extractor/travel_mode.hpp"
10 #include "extractor/turn_lane_types.hpp"
11 #include "guidance/turn_bearing.hpp"
12 #include "guidance/turn_instruction.hpp"
13 
14 #include "engine/algorithm.hpp"
15 #include "engine/datafacade/algorithm_datafacade.hpp"
16 #include "engine/datafacade/datafacade_base.hpp"
17 
18 #include "util/guidance/bearing_class.hpp"
19 #include "util/guidance/entry_class.hpp"
20 #include "util/typedefs.hpp"
21 
22 namespace osrm
23 {
24 namespace test
25 {
26 
27 class MockBaseDataFacade : public engine::datafacade::BaseDataFacade
28 {
29     using StringView = util::StringView;
30 
31   public:
ExcludeNode(const NodeID) const32     bool ExcludeNode(const NodeID) const override { return false; };
33 
GetCoordinateOfNode(const NodeID) const34     util::Coordinate GetCoordinateOfNode(const NodeID /* id */) const override
35     {
36         return {util::FixedLongitude{0}, util::FixedLatitude{0}};
37     }
GetOSMNodeIDOfNode(const NodeID) const38     OSMNodeID GetOSMNodeIDOfNode(const NodeID /* id */) const override { return OSMNodeID{0}; }
EdgeIsCompressed(const EdgeID) const39     bool EdgeIsCompressed(const EdgeID /* id */) const { return false; }
GetGeometryIndex(const NodeID) const40     GeometryID GetGeometryIndex(const NodeID /* id */) const override
41     {
42         return GeometryID{SPECIAL_GEOMETRYID, false};
43     }
GetComponentID(const NodeID) const44     ComponentID GetComponentID(const NodeID /* id */) const override
45     {
46         return ComponentID{INVALID_COMPONENTID, false};
47     }
GetWeightPenaltyForEdgeID(const unsigned) const48     TurnPenalty GetWeightPenaltyForEdgeID(const unsigned /* id */) const override final
49     {
50         return 0;
51     }
GetDurationPenaltyForEdgeID(const unsigned) const52     TurnPenalty GetDurationPenaltyForEdgeID(const unsigned /* id */) const override final
53     {
54         return 0;
55     }
GetTimestamp() const56     std::string GetTimestamp() const override { return ""; }
GetUncompressedForwardGeometry(const EdgeID) const57     NodeForwardRange GetUncompressedForwardGeometry(const EdgeID /* id */) const override
58     {
59         static NodeID data[] = {0, 1, 2, 3};
60         static extractor::SegmentDataView::SegmentNodeVector nodes(data, 4);
61         return boost::make_iterator_range(nodes.cbegin(), nodes.cend());
62     }
GetUncompressedReverseGeometry(const EdgeID id) const63     NodeReverseRange GetUncompressedReverseGeometry(const EdgeID id) const override
64     {
65         return NodeReverseRange(GetUncompressedForwardGeometry(id));
66     }
GetUncompressedForwardWeights(const EdgeID) const67     WeightForwardRange GetUncompressedForwardWeights(const EdgeID /* id */) const override
68     {
69         static std::uint64_t data[] = {1, 2, 3};
70         static const extractor::SegmentDataView::SegmentWeightVector weights(
71             util::vector_view<std::uint64_t>(data, 3), 3);
72         return WeightForwardRange(weights.begin(), weights.end());
73     }
GetUncompressedReverseWeights(const EdgeID id) const74     WeightReverseRange GetUncompressedReverseWeights(const EdgeID id) const override
75     {
76         return WeightReverseRange(GetUncompressedForwardWeights(id));
77     }
GetUncompressedForwardDurations(const EdgeID) const78     DurationForwardRange GetUncompressedForwardDurations(const EdgeID /*id*/) const override
79     {
80         static std::uint64_t data[] = {1, 2, 3};
81         static const extractor::SegmentDataView::SegmentDurationVector durations(
82             util::vector_view<std::uint64_t>(data, 3), 3);
83         return DurationForwardRange(durations.begin(), durations.end());
84     }
GetUncompressedReverseDurations(const EdgeID id) const85     DurationReverseRange GetUncompressedReverseDurations(const EdgeID id) const override
86     {
87         return DurationReverseRange(GetUncompressedForwardDurations(id));
88     }
GetUncompressedForwardDatasources(const EdgeID) const89     DatasourceForwardRange GetUncompressedForwardDatasources(const EdgeID /*id*/) const override
90     {
91         return {};
92     }
GetUncompressedReverseDatasources(const EdgeID) const93     DatasourceReverseRange GetUncompressedReverseDatasources(const EdgeID /*id*/) const override
94     {
95         return DatasourceReverseRange(DatasourceForwardRange());
96     }
97 
GetDatasourceName(const DatasourceID) const98     StringView GetDatasourceName(const DatasourceID) const override final { return {}; }
99 
100     osrm::guidance::TurnInstruction
GetTurnInstructionForEdgeID(const EdgeID) const101     GetTurnInstructionForEdgeID(const EdgeID /* id */) const override
102     {
103         return osrm::guidance::TurnInstruction::NO_TURN();
104     }
GetEdgesInBox(const util::Coordinate,const util::Coordinate) const105     std::vector<RTreeLeaf> GetEdgesInBox(const util::Coordinate /* south_west */,
106                                          const util::Coordinate /*north_east */) const override
107     {
108         return {};
109     }
110 
111     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::Coordinate,const float,const int,const int,const engine::Approach,const bool) const112     NearestPhantomNodesInRange(const util::Coordinate /*input_coordinate*/,
113                                const float /*max_distance*/,
114                                const int /*bearing*/,
115                                const int /*bearing_range*/,
116                                const engine::Approach /*approach*/,
117                                const bool /*use_all_edges*/) const override
118     {
119         return {};
120     }
121 
122     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodesInRange(const util::Coordinate,const float,const engine::Approach,const bool) const123     NearestPhantomNodesInRange(const util::Coordinate /*input_coordinate*/,
124                                const float /*max_distance*/,
125                                const engine::Approach /*approach*/,
126                                const bool /*use_all_edges*/) const override
127     {
128         return {};
129     }
130 
131     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate,const unsigned,const double,const int,const int,const engine::Approach) const132     NearestPhantomNodes(const util::Coordinate /*input_coordinate*/,
133                         const unsigned /*max_results*/,
134                         const double /*max_distance*/,
135                         const int /*bearing*/,
136                         const int /*bearing_range*/,
137                         const engine::Approach /*approach*/) const override
138     {
139         return {};
140     }
141 
142     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate,const unsigned,const int,const int,const engine::Approach) const143     NearestPhantomNodes(const util::Coordinate /*input_coordinate*/,
144                         const unsigned /*max_results*/,
145                         const int /*bearing*/,
146                         const int /*bearing_range*/,
147                         const engine::Approach /*approach*/) const override
148     {
149         return {};
150     }
151 
152     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate,const unsigned,const engine::Approach) const153     NearestPhantomNodes(const util::Coordinate /*input_coordinate*/,
154                         const unsigned /*max_results*/,
155                         const engine::Approach /*approach*/) const override
156     {
157         return {};
158     }
159 
160     std::vector<engine::PhantomNodeWithDistance>
NearestPhantomNodes(const util::Coordinate,const unsigned,const double,const engine::Approach) const161     NearestPhantomNodes(const util::Coordinate /*input_coordinate*/,
162                         const unsigned /*max_results*/,
163                         const double /*max_distance*/,
164                         const engine::Approach /*approach*/) const override
165     {
166         return {};
167     }
168 
169     std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate,const engine::Approach,const bool) const170     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
171                                                       const engine::Approach /*approach*/,
172                                                       const bool /* use_all_edges */) const override
173     {
174         return {};
175     }
176 
177     std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate,const double,const engine::Approach,const bool) const178     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
179                                                       const double /*max_distance*/,
180                                                       const engine::Approach /*approach*/,
181                                                       const bool /* use_all_edges */) const override
182     {
183         return {};
184     }
185 
186     std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate,const double,const int,const int,const engine::Approach,const bool) const187     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
188                                                       const double /*max_distance*/,
189                                                       const int /*bearing*/,
190                                                       const int /*bearing_range*/,
191                                                       const engine::Approach /*approach*/,
192                                                       const bool /* use_all_edges */) const override
193     {
194         return {};
195     }
196 
197     std::pair<engine::PhantomNode, engine::PhantomNode>
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate,const int,const int,const engine::Approach,const bool) const198     NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate /*input_coordinate*/,
199                                                       const int /*bearing*/,
200                                                       const int /*bearing_range*/,
201                                                       const engine::Approach /*approach*/,
202                                                       const bool /* use_all_edges */) const override
203     {
204         return {};
205     }
206 
GetCheckSum() const207     std::uint32_t GetCheckSum() const override { return 0; }
208 
GetTravelMode(const NodeID) const209     extractor::TravelMode GetTravelMode(const NodeID /* id */) const override
210     {
211         return extractor::TRAVEL_MODE_INACCESSIBLE;
212     }
213 
GetClassData(const NodeID) const214     extractor::ClassData GetClassData(const NodeID /*id*/) const override final { return 0; }
215 
GetClasses(const extractor::ClassData) const216     std::vector<std::string> GetClasses(const extractor::ClassData /*data*/) const override final
217     {
218         return {};
219     }
220 
GetNameIndex(const NodeID) const221     NameID GetNameIndex(const NodeID /* id */) const override { return 0; }
222 
GetNameForID(const NameID) const223     StringView GetNameForID(const NameID) const override final { return {}; }
GetRefForID(const NameID) const224     StringView GetRefForID(const NameID) const override final { return {}; }
GetPronunciationForID(const NameID) const225     StringView GetPronunciationForID(const NameID) const override final { return {}; }
GetDestinationsForID(const NameID) const226     StringView GetDestinationsForID(const NameID) const override final { return {}; }
GetExitsForID(const NameID) const227     StringView GetExitsForID(const NameID) const override final { return {}; }
228 
GetContinueStraightDefault() const229     bool GetContinueStraightDefault() const override { return true; }
GetMapMatchingMaxSpeed() const230     double GetMapMatchingMaxSpeed() const override { return 180 / 3.6; }
GetWeightName() const231     const char *GetWeightName() const override final { return "duration"; }
GetWeightPrecision() const232     unsigned GetWeightPrecision() const override final { return 1; }
GetWeightMultiplier() const233     double GetWeightMultiplier() const override final { return 10.; }
IsLeftHandDriving(const NodeID) const234     bool IsLeftHandDriving(const NodeID /*id*/) const override { return false; }
IsSegregated(const NodeID) const235     bool IsSegregated(const NodeID /*id*/) const override { return false; }
236 
PreTurnBearing(const EdgeID) const237     guidance::TurnBearing PreTurnBearing(const EdgeID /*eid*/) const override final
238     {
239         return guidance::TurnBearing{0.0};
240     }
PostTurnBearing(const EdgeID) const241     guidance::TurnBearing PostTurnBearing(const EdgeID /*eid*/) const override final
242     {
243         return guidance::TurnBearing{0.0};
244     }
245 
HasLaneData(const EdgeID) const246     bool HasLaneData(const EdgeID /*id*/) const override final { return true; };
GetLaneData(const EdgeID) const247     util::guidance::LaneTupleIdPair GetLaneData(const EdgeID /*id*/) const override final
248     {
249         return {{0, 0}, 0};
250     }
251     extractor::TurnLaneDescription
GetTurnDescription(const LaneDescriptionID) const252     GetTurnDescription(const LaneDescriptionID /*lane_description_id*/) const override final
253     {
254         return {};
255     }
256 
GetBearingClass(const NodeID) const257     util::guidance::BearingClass GetBearingClass(const NodeID /*node*/) const override
258     {
259         util::guidance::BearingClass result;
260         result.add(0);
261         result.add(90);
262         result.add(180);
263         result.add(270);
264         return result;
265     }
266 
GetEntryClass(const EdgeID) const267     util::guidance::EntryClass GetEntryClass(const EdgeID /*id*/) const override
268     {
269         util::guidance::EntryClass result;
270         result.activate(1);
271         result.activate(2);
272         result.activate(3);
273         return result;
274     }
275 
276     std::vector<extractor::ManeuverOverride>
GetOverridesThatStartAt(const NodeID) const277     GetOverridesThatStartAt(const NodeID /* edge_based_node_id */) const override
278     {
279         return {};
280     }
281 };
282 
283 template <typename AlgorithmT> class MockAlgorithmDataFacade;
284 
285 template <>
286 class MockAlgorithmDataFacade<engine::datafacade::CH>
287     : public engine::datafacade::AlgorithmDataFacade<engine::datafacade::CH>
288 {
289   private:
290     EdgeData foo;
291 
292   public:
GetNumberOfNodes() const293     unsigned GetNumberOfNodes() const override { return 0; }
GetNumberOfEdges() const294     unsigned GetNumberOfEdges() const override { return 0; }
GetOutDegree(const NodeID) const295     unsigned GetOutDegree(const NodeID /* n */) const override { return 0; }
GetTarget(const EdgeID) const296     NodeID GetTarget(const EdgeID /* e */) const override { return SPECIAL_NODEID; }
GetEdgeData(const EdgeID) const297     const EdgeData &GetEdgeData(const EdgeID /* e */) const override { return foo; }
GetAdjacentEdgeRange(const NodeID) const298     EdgeRange GetAdjacentEdgeRange(const NodeID /* node */) const override
299     {
300         return EdgeRange(static_cast<EdgeID>(0), static_cast<EdgeID>(0), {});
301     }
FindEdge(const NodeID,const NodeID) const302     EdgeID FindEdge(const NodeID /* from */, const NodeID /* to */) const override
303     {
304         return SPECIAL_EDGEID;
305     }
FindEdgeInEitherDirection(const NodeID,const NodeID) const306     EdgeID FindEdgeInEitherDirection(const NodeID /* from */, const NodeID /* to */) const override
307     {
308         return SPECIAL_EDGEID;
309     }
310 
FindSmallestEdge(const NodeID,const NodeID,std::function<bool (EdgeData)>) const311     EdgeID FindSmallestEdge(const NodeID /* from */,
312                             const NodeID /* to */,
313                             std::function<bool(EdgeData)> /* filter */) const override
314     {
315         return SPECIAL_EDGEID;
316     }
317 
FindEdgeIndicateIfReverse(const NodeID,const NodeID,bool &) const318     EdgeID FindEdgeIndicateIfReverse(const NodeID /* from */,
319                                      const NodeID /* to */,
320                                      bool & /* result */) const override
321     {
322         return SPECIAL_EDGEID;
323     }
324 };
325 
326 template <typename AlgorithmT>
327 class MockDataFacade final : public MockBaseDataFacade, public MockAlgorithmDataFacade<AlgorithmT>
328 {
329 };
330 
331 } // namespace test
332 } // namespace osrm
333 
334 #endif // MOCK_DATAFACADE_HPP
335