diff --git a/integration_tests/osrm_route_test.cpp b/integration_tests/osrm_route_test.cpp index 745b279785..28f8ea3c83 100644 --- a/integration_tests/osrm_route_test.cpp +++ b/integration_tests/osrm_route_test.cpp @@ -9,14 +9,14 @@ namespace UNIT_TEST(RussiaMoscowLenigradskiy39GerPanfilovtsev22RouteTest) { shared_ptr routerComponents = integration::GetAllMaps(); - TEST(integration::CalculateRouteAndTestRouteLength(routerComponents, {37.53758809983519, 67.536162466434234}, - {0., 0.}, {37.40993977728661, 67.644784047393685}, 14296.), ()); + integration::CalculateRouteAndTestRouteLength(routerComponents, {37.53758809983519, 67.536162466434234}, + {0., 0.}, {37.40993977728661, 67.644784047393685}, 14296.); } - UNIT_TEST(RussiaMoscowGerPanfilovtsev22SolodshaPravdiRouteTest) + UNIT_TEST(RussiaMoscowGerPanfilovtsev22SolodchaPravdiRouteTest) { shared_ptr routerComponents = integration::GetAllMaps(); - TEST(integration::CalculateRouteAndTestRouteLength(routerComponents, {37.409929478750627, 67.644798619710073}, - {0., 0.}, {39.836562407458047, 65.774372510437971}, 253275.), ()); + integration::CalculateRouteAndTestRouteLength(routerComponents, {37.409929478750627, 67.644798619710073}, + {0., 0.}, {39.836562407458047, 65.774372510437971}, 253275.); } } diff --git a/integration_tests/osrm_test_tools.cpp b/integration_tests/osrm_test_tools.cpp index 7291d4335e..e65532ab6c 100644 --- a/integration_tests/osrm_test_tools.cpp +++ b/integration_tests/osrm_test_tools.cpp @@ -1,6 +1,6 @@ #include "osrm_test_tools.hpp" -#include "../std/new.hpp" +#include "../../testing/testing.hpp" #include "../indexer/index.hpp" @@ -27,14 +27,8 @@ namespace integration OsrmRouter(index, fn) {} ResultCode SyncCalculateRoute(m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt, Route & route) { - m_startPt = startPt; - m_startDr = startDr; - m_finalPt = finalPt; - m_cachedFinalNodes.clear(); - m_isFinalChanged = false; - m_requestCancel = false; - - return OsrmRouter::CalculateRouteImpl(startPt, startDr, finalPt, route); + SetFinalPoint(finalPt); + return CalculateRouteImpl(startPt, startDr, finalPt, route); } }; @@ -121,14 +115,7 @@ namespace integration shared_ptr LoadMaps(vector const & mapNames) { - try{ - return shared_ptr(new OsrmRouterComponents(mapNames)); - } - catch(bad_alloc &) - { - ASSERT(false, ()); - return nullptr; - } + return shared_ptr(new OsrmRouterComponents(mapNames)); } shared_ptr LoadAllMaps() @@ -149,73 +136,113 @@ namespace integration RouteResultT CalculateRoute(shared_ptr routerComponents, m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt) { - try - { - ASSERT(routerComponents.get(), ()); - OsrmRouterWrapper * osrmRouter = routerComponents->GetOsrmRouter(); - ASSERT(osrmRouter, ()); - shared_ptr route(new Route("mapsme")); - OsrmRouter::ResultCode result = osrmRouter->SyncCalculateRoute(startPt, startDr, finalPt, *route.get()); - return RouteResultT(route, result); - } - catch(bad_alloc &) - { - ASSERT(false, ()); - return RouteResultT(nullptr, OsrmRouter::InternalError); - } + ASSERT(routerComponents.get(), ()); + OsrmRouterWrapper * osrmRouter = routerComponents->GetOsrmRouter(); + ASSERT(osrmRouter, ()); + shared_ptr route(new Route("mapsme")); + OsrmRouter::ResultCode result = osrmRouter->SyncCalculateRoute(startPt, startDr, finalPt, *route.get()); + return RouteResultT(route, result); } - bool TestTurn(shared_ptr const route, uint32_t etalonTurnNumber, m2::PointD const & etalonTurnPnt, - turns::TurnDirection etalonTurnDirection, uint32_t etalonRoundAboutExitNum) + void TestTurnCount(shared_ptr const route, uint32_t referenceTurnCount) { ASSERT(route.get(), ()); - turns::TurnsGeomT const & turnsGeom = route->GetTurnsGeometry(); - if (etalonTurnNumber >= turnsGeom.size()) - return false; - - Route::TurnsT const & turns = route->GetTurns(); - ASSERT_LESS(etalonTurnNumber, turns.size(), ()); - Route::TurnItem const & turn = turns[etalonTurnNumber]; - if (turn.m_turn != etalonTurnDirection) - return false; - if (turn.m_exitNum != etalonRoundAboutExitNum) - return false; - - turns::TurnGeom const & turnGeom = turnsGeom[etalonTurnNumber]; - ASSERT_LESS(turnGeom.m_turnIndex, turnGeom.m_points.size(), ()); - m2::PointD turnGeomPnt = turnGeom.m_points[turnGeom.m_turnIndex]; - - double const dist = ms::DistanceOnEarth(etalonTurnPnt.y, etalonTurnPnt.x, turnGeomPnt.y, turnGeomPnt.x); - if (dist > turnInaccuracy) - return false; - return true; + TEST_EQUAL(route->GetTurnsGeometry().size(), referenceTurnCount, ()); } - bool TestTurnCount(shared_ptr const route, uint32_t etalonTurnCount) + void TestRouteLength(shared_ptr const route, double referenceRouteLength, double routeLenInaccuracy) { ASSERT(route.get(), ()); - return route->GetTurnsGeometry().size() == etalonTurnCount; - } - - bool TestRouteLength(shared_ptr const route, double etalonRouteLength) - { - ASSERT(route.get(), ()); - double const delta = etalonRouteLength * routeLengthInaccurace; + double const delta = referenceRouteLength * routeLenInaccuracy; double const routeLength = route->GetDistance(); - if (routeLength - delta <= etalonRouteLength && routeLength + delta >= etalonRouteLength) - return true; - else - return false; + TEST_LESS_OR_EQUAL(routeLength - delta, referenceRouteLength, ()); + TEST_GREATER_OR_EQUAL(routeLength + delta, referenceRouteLength, ()); } - bool CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, - m2::PointD const & startDr, m2::PointD const & finalPt, double etalonRouteLength) + void CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, + m2::PointD const & startDr, m2::PointD const & finalPt, double referenceRouteLength, + double routeLenInaccuracy) { RouteResultT routeResult = CalculateRoute(routerComponents, startPt, startDr, finalPt); shared_ptr const route = routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; - if (result != OsrmRouter::NoError) - return false; - return TestRouteLength(route, etalonRouteLength); + TEST_EQUAL(result, OsrmRouter::NoError, ()); + TestRouteLength(route, referenceRouteLength, routeLenInaccuracy); + } + + const TestTurn & TestTurn::TestValid() const + { + TEST(m_isValid, ()); + return *this; + } + + const TestTurn & TestTurn::TestNotValid() const + { + TEST(!m_isValid, ()); + return *this; + } + + const TestTurn & TestTurn::TestPoint(m2::PointD const & referencePnt, double inaccuracy) const + { + double const dist = ms::DistanceOnEarth(referencePnt.y, referencePnt.x, m_pnt.y, m_pnt.x); + TEST_LESS(dist, inaccuracy, ()); + return *this; + } + + const TestTurn & TestTurn::TestDirection(routing::turns::TurnDirection referenceDirection) const + { + TEST_EQUAL(m_direction, referenceDirection, ()); + return *this; + } + + const TestTurn & TestTurn::TestOneOfDirections(set referenceDirections) const + { + TEST(referenceDirections.find(m_direction) != referenceDirections.end(), ()); + return *this; + } + + const TestTurn & TestTurn::TestRoundAboutExitNum(uint32_t referenceRoundAboutExitNum) const + { + TEST_EQUAL(m_roundAboutExitNum, referenceRoundAboutExitNum, ()); + return *this; + } + + TestTurn GetNthTurn(shared_ptr const route, uint32_t referenceTurnNumber) + { + ASSERT(route.get(), ()); + + turns::TurnsGeomT const & turnsGeom = route->GetTurnsGeometry(); + if (referenceTurnNumber >= turnsGeom.size()) + return TestTurn(); + + Route::TurnsT const & turns = route->GetTurns(); + if (referenceTurnNumber >= turns.size()) + return TestTurn(); + + turns::TurnGeom const & turnGeom = turnsGeom[referenceTurnNumber]; + ASSERT_LESS(turnGeom.m_turnIndex, turnGeom.m_points.size(), ()); + Route::TurnItem const & turn = turns[referenceTurnNumber]; + return TestTurn(turnGeom.m_points[turnGeom.m_turnIndex], turn.m_turn, turn.m_exitNum); + } + + TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & referenceTurnPnt, double inaccuracy) + { + ASSERT(route.get(), ()); + turns::TurnsGeomT const & turnsGeom = route->GetTurnsGeometry(); + Route::TurnsT const & turns = route->GetTurns(); + ASSERT_EQUAL(turnsGeom.size() + 1, turns.size(), ()); + + for (int i = 0; i != turnsGeom.size(); ++i) + { + turns::TurnGeom const & turnGeom = turnsGeom[i]; + ASSERT_LESS(turnGeom.m_turnIndex, turnGeom.m_points.size(), ()); + m2::PointD const turnPnt = turnGeom.m_points[turnGeom.m_turnIndex]; + if (ms::DistanceOnEarth(turnPnt.y, turnPnt.x, referenceTurnPnt.y, referenceTurnPnt.x) <= inaccuracy) + { + Route::TurnItem const & turn = turns[i]; + return TestTurn(turnPnt, turn.m_turn, turn.m_exitNum); + } + } + return TestTurn(); } } diff --git a/integration_tests/osrm_test_tools.hpp b/integration_tests/osrm_test_tools.hpp index 476a271f71..2793a78e48 100644 --- a/integration_tests/osrm_test_tools.hpp +++ b/integration_tests/osrm_test_tools.hpp @@ -3,6 +3,7 @@ #include "../std/shared_ptr.hpp" #include "../std/string.hpp" #include "../std/vector.hpp" +#include "../std/set.hpp" #include "../routing/osrm_router.hpp" @@ -15,25 +16,21 @@ * Use LoadMaps() only if you want to test something on a special map set. * 2. Loading maps and calculating routes is a time consumption process. * Do this only if you really need it. - * 3. If you want to check that a turn is absent use TestTurnCount. + * 3. If you want to check that a turn is absent you have two options + * - use GetTurnByPoint(...).TestNotValid(); + * - or use TestTurnCount. * 4. The easiest way to gather all the information for writing an integration test is * - to put a break point in OsrmRouter::CalculateRouteImpl; * - to make a route with MapWithMe desktop application; - * - to get all necessary parameters and result of route calculation; + * - to get all necessary parameters and result of the route calculation; * - to place them into the test you're writing. - * 5. The recommended way for naming tests for route from one place to another one is + * 5. The recommended way for naming tests for a route from one place to another one is * + * 6. It's a good idea to use short routes for testing turns. The thing is geometry of long routes + * could be changes for one dataset (osrm version) to another one. + * The shorter route the less chance it'll be changed. */ -/// Inaccuracy of turn point in meters -double const turnInaccuracy = 2.; -/// Inaccurace of the route length. It is used for checking if routes have etalon(sample) length. -/// So the a created route has etalon length if -/// etalonLength - etalonRouteLength * routeLengthInaccurace <= route->GetDistance() -/// && etalonRouteLength + etalonRouteLength * routeLengthInaccurace >= route->GetDistance() -/// is equal to true. -double const routeLengthInaccurace = .01; - typedef pair, routing::OsrmRouter::ResultCode> RouteResultT; namespace integration @@ -42,17 +39,45 @@ namespace integration shared_ptr GetAllMaps(); shared_ptr LoadMaps(vector const & mapNames); - RouteResultT CalculateRoute(shared_ptr routerComponents, - m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt); + m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt); - bool TestTurn(shared_ptr const route, uint32_t etalonTurnNumber, m2::PointD const & etalonTurnPnt, - routing::turns::TurnDirection etalonTurnDirection, uint32_t etalonRoundAboutExitNum = 0); + void TestTurnCount(shared_ptr const route, uint32_t referenceTurnCount); - bool TestTurnCount(shared_ptr const route, uint32_t etalonTurnCount); + /// Testing route length. + /// It is used for checking if routes have reference(sample) length. + /// The a created route will pass the test iff + /// referenceRouteLength - referenceRouteLength * routeLenInaccuracy <= route->GetDistance() + /// && referenceRouteLength + referenceRouteLength * routeLenInaccuracy >= route->GetDistance() + void TestRouteLength(shared_ptr const route, double referenceRouteLength, double routeLenInaccuracy = 0.01); + void CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, + m2::PointD const & startDr, m2::PointD const & finalPt, double referenceRouteLength, + double routeLenInaccuracy = 0.01); - bool TestRouteLength(shared_ptr const route, double etalonRouteLength); + class TestTurn + { + friend TestTurn GetNthTurn(shared_ptr const route, uint32_t turnNumber); + friend TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & turnPnt, double inaccuracy); - bool CalculateRouteAndTestRouteLength(shared_ptr routerComponents, m2::PointD const & startPt, - m2::PointD const & startDr, m2::PointD const & finalPt, double etalonRouteLength); + m2::PointD const m_pnt; + routing::turns::TurnDirection const m_direction; + uint32_t const m_roundAboutExitNum; + bool const m_isValid; + + TestTurn() : m_pnt({0., 0.}), m_direction(routing::turns::NoTurn), m_roundAboutExitNum(0), m_isValid(false) {} + TestTurn(m2::PointD const & pnt, routing::turns::TurnDirection direction, uint32_t roundAboutExitNum) : + m_pnt(pnt), m_direction(direction), m_roundAboutExitNum(roundAboutExitNum), m_isValid(true) {} + public: + const TestTurn & TestValid() const; + const TestTurn & TestNotValid() const; + const TestTurn & TestPoint(m2::PointD const & referencePnt, double inaccuracy = 3.) const; + const TestTurn & TestDirection(routing::turns::TurnDirection referenceDirection) const; + const TestTurn & TestOneOfDirections(set referenceDirections) const; + const TestTurn & TestRoundAboutExitNum(uint32_t referenceRoundAboutExitNum) const; + }; + + /// Extracting appropriate TestTurn if any. If not TestTurn::isValid() returns false. + /// inaccuracy is set in meters. + TestTurn GetNthTurn(shared_ptr const route, uint32_t turnNumber); + TestTurn GetTurnByPoint(shared_ptr const route, m2::PointD const & turnPnt, double inaccuracy = 3.); } diff --git a/integration_tests/osrm_turn_test.cpp b/integration_tests/osrm_turn_test.cpp index 5c7ebde715..128dc7014b 100644 --- a/integration_tests/osrm_turn_test.cpp +++ b/integration_tests/osrm_turn_test.cpp @@ -4,6 +4,7 @@ #include "../routing/route.hpp" + using namespace routing; UNIT_TEST(RussiaMoscowLenigradskiy39UturnTurnTest) @@ -17,14 +18,15 @@ UNIT_TEST(RussiaMoscowLenigradskiy39UturnTurnTest) OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); - TEST(integration::TestTurn(route, 0, {37.545981835916507, 67.530713137468041}, turns::TurnLeft), ()); - TEST(integration::TestTurn(route, 1, {37.546738218864334, 67.531659957257347}, turns::TurnLeft), ()); - TEST(integration::TestTurn(route, 2, {37.539925407915746, 67.537083383925875}, turns::TurnRight), ()); - TEST(!integration::TestTurn(route, 2, {37., 67.}, turns::TurnRight), ()); + integration::GetNthTurn(route, 0).TestValid().TestPoint({37.545981835916507, 67.530713137468041}) + .TestOneOfDirections({turns::TurnSlightLeft , turns::TurnLeft}); + integration::GetNthTurn(route, 1).TestValid().TestPoint({37.546738218864334, 67.531659957257347}).TestDirection(turns::TurnLeft); + integration::GetNthTurn(route, 2).TestValid().TestPoint({37.539925407915746, 67.537083383925875}).TestDirection(turns::TurnRight); - TEST(integration::TestRouteLength(route, 2033.), ()); - TEST(!integration::TestRouteLength(route, 2533.), ()); - TEST(!integration::TestRouteLength(route, 1533.), ()); + integration::GetTurnByPoint(route, {37., 67.}).TestNotValid(); + integration::GetTurnByPoint(route, {37.546738218864334, 67.531659957257347}).TestValid().TestDirection(turns::TurnLeft); + + integration::TestRouteLength(route, 2033.); } UNIT_TEST(RussiaMoscowSalameiNerisUturnTurnTest) @@ -36,15 +38,13 @@ UNIT_TEST(RussiaMoscowSalameiNerisUturnTurnTest) OsrmRouter::ResultCode const result = routeResult.second; TEST_EQUAL(result, OsrmRouter::NoError, ()); + integration::GetNthTurn(route, 0).TestValid().TestPoint({37.388482521388539, 67.633382734905041}, 5.) + .TestOneOfDirections({turns::GoStraight, turns::TurnSlightRight}); + integration::GetNthTurn(route, 1).TestValid().TestPoint({37.387117276989784, 67.633369323859881}).TestDirection(turns::TurnLeft); + integration::GetNthTurn(route, 2).TestValid().TestPoint({37.387380133475205, 67.632781920081243}).TestDirection(turns::TurnLeft); + integration::GetNthTurn(route, 3).TestValid().TestPoint({37.390526364673121, 67.633106467374461}).TestDirection(turns::TurnRight); - TEST(integration::TestTurn(route, 0, {37.388482521388539, 67.633382734905041}, turns::TurnSlightRight), ()); - TEST(integration::TestTurn(route, 1, {37.387117276989784, 67.633369323859881}, turns::TurnLeft), ()); - TEST(integration::TestTurn(route, 2, {37.387380133475205, 67.632781920081243}, turns::TurnLeft), ()); - TEST(integration::TestTurn(route, 3, {37.390526364673121, 67.633106467374461}, turns::TurnRight), ()); - - TEST(integration::TestTurnCount(route, 4), ()); - - TEST(integration::TestRouteLength(route, 1637.), ()); - + integration::TestTurnCount(route, 4); + integration::TestRouteLength(route, 1637.); } diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 18bc1b581a..dacd74c291 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -505,12 +505,6 @@ void OsrmRouter::CalculateRouteAsync(ReadyCallback const & callback) startPt = m_startPt; finalPt = m_finalPt; startDr = m_startDr; - - if (m_isFinalChanged) - m_cachedFinalNodes.clear(); - m_isFinalChanged = false; - - m_requestCancel = false; } try @@ -564,9 +558,24 @@ bool IsRouteExist(RawRouteData const & r) void OsrmRouter::FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets, RawDataFacadeT &facade, vector &result) { + SearchEngineData engineData; NMManyToManyRouting pathFinder(&facade, engineData); + { + threads::MutexGuard params(m_paramsMutex); + UNUSED_VALUE(params); + if (m_isFinalChanged) + m_cachedFinalNodes.clear(); + m_isFinalChanged = false; + m_requestCancel = false; + } + + // 1. Find country file name and check that we are in the same MWM. + //string fName = m_countryFn(startPt); + //if (fName != m_countryFn(finalPt)) + // return PointsInDifferentMWM; + PhantomNodeArray sourcesTaskVector(sources.size()); PhantomNodeArray targetsTaskVector(targets.size()); for (int i = 0; i < sources.size(); ++i) diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index a3918e5b30..14768215a4 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -23,11 +23,6 @@ struct PathData; class FeatureType; struct RawRouteData; -namespace integration -{ - class OsrmRouterWrapper; -} - namespace routing { @@ -126,8 +121,10 @@ public: */ class RoutingIndexManager { +protected: + typedef function CountryFileFnT; +private: CountryFileFnT m_countryFn; - map m_mapping; public: @@ -137,10 +134,7 @@ public: RoutingMappingPtrT GetMappingByName(string const & fName, Index const * pIndex); - friend class integration::OsrmRouterWrapper; - typedef function CountryFileFnT; - CountryFileFnT m_countryFn; - +public: void Clear() { m_mapping.clear(); diff --git a/std/new.hpp b/std/new.hpp deleted file mode 100644 index fc519b585f..0000000000 --- a/std/new.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "common_defines.hpp" - -#ifdef new -#undef new -#endif - -#include - -using std::bad_alloc; -using std::bad_array_new_length; - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif