diff --git a/platform/location.hpp b/platform/location.hpp index e5943b373b..4d3f8fa047 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -144,7 +144,7 @@ namespace location // If there is nothing to pronounce m_turnNotifications is empty. // If there is something to pronounce the size of m_turnNotifications may be one or even more // depends on the number of notifications to prononce. - vector m_turnNotifications; + vector m_turnNotifications; // The next street name. string m_targetName; diff --git a/routing/routing_tests/turns_sound_test.cpp b/routing/routing_tests/turns_sound_test.cpp index 05c8a9ba4c..96f88784c8 100644 --- a/routing/routing_tests/turns_sound_test.cpp +++ b/routing/routing_tests/turns_sound_test.cpp @@ -90,6 +90,14 @@ UNIT_TEST(TurnsSoundMetersTest) TurnsSound turnSound; turnSound.Enable(true); turnSound.SetLengthUnits(routing::turns::sound::LengthUnits::Meters); + string const engShortJson = + "\ + {\ + \"in_600_meters\":\"In 600 meters.\",\ + \"make_a_right_turn\":\"Make a right turn.\"\ + }"; + turnSound.SetLocaleWithJson(engShortJson); + turnSound.Reset(); turnSound.SetSpeedMetersPerSecond(30.); @@ -114,9 +122,7 @@ UNIT_TEST(TurnsSoundMetersTest) // So we start playing the first notification when the distance till the turn is less // then 20 seconds * 30 meters per seconds + 100 meters = 700 meters. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */); - vector const expectedNotification1 = { - {600 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::TurnRight, LengthUnits::Meters}}; + vector const expectedNotification1 = {{"In 600 meters. Make a right turn."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ()); // 650 meters till the turn. No sound notifications is required. @@ -136,9 +142,7 @@ UNIT_TEST(TurnsSoundMetersTest) // 99 meters till the turn. It's time to pronounce the second voice notification. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */); - vector const expectedNotification2 = { - {0 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::TurnRight, LengthUnits::Meters}}; + vector const expectedNotification2 = {{"Make a right turn."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ()); // 99 meters till the turn again. No sound notifications is required. @@ -167,6 +171,15 @@ UNIT_TEST(TurnsSoundMetersTwoTurnsTest) TurnsSound turnSound; turnSound.Enable(true); turnSound.SetLengthUnits(routing::turns::sound::LengthUnits::Meters); + string const engShortJson = + "\ + {\ + \"in_700_meters\":\"In 700 meters.\",\ + \"make_a_sharp_right_turn\":\"Make a sharp right turn.\",\ + \"enter_the_roundabout\":\"Enter the roundabout.\"\ + }"; + turnSound.SetLocaleWithJson(engShortJson); + turnSound.Reset(); turnSound.SetSpeedMetersPerSecond(35.); @@ -182,9 +195,7 @@ UNIT_TEST(TurnsSoundMetersTwoTurnsTest) // 700 meters till the turn. It's time to pronounce the first voice notification. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 700. /* distanceToTurnMeters */); - vector const expectedNotification1 = { - {700 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::TurnSharpRight, LengthUnits::Meters}}; + vector const expectedNotification1 = {{"In 700 meters. Make a sharp right turn."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ()); turnSound.SetSpeedMetersPerSecond(32.); @@ -195,9 +206,7 @@ UNIT_TEST(TurnsSoundMetersTwoTurnsTest) // 99 meters till the turn. It's time to pronounce the second voice notification. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem1, 99. /* distanceToTurnMeters */); - vector const expectedNotification2 = { - {0 /* m_distanceUnits */, 0 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::TurnSharpRight, LengthUnits::Meters}}; + vector const expectedNotification2 = {{"Make a sharp right turn."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ()); turnSound.SetSpeedMetersPerSecond(10.); @@ -215,9 +224,7 @@ UNIT_TEST(TurnsSoundMetersTwoTurnsTest) // 40 meters till the second turn. It's time to pronounce the second voice notification // without the first one. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem2, 40. /* distanceToTurnMeters */); - vector const expectedNotification3 = { - {0 /* m_distanceUnits */, 2 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::EnterRoundAbout, LengthUnits::Meters}}; + vector const expectedNotification3 = {{"Enter the roundabout."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification3, ()); TEST(turnSound.IsEnabled(), ()); @@ -228,6 +235,14 @@ UNIT_TEST(TurnsSoundFeetTest) TurnsSound turnSound; turnSound.Enable(true); turnSound.SetLengthUnits(routing::turns::sound::LengthUnits::Feet); + string const engShortJson = + "\ + {\ + \"in_2000_feet\":\"In 2000 feet.\",\ + \"enter_the_roundabout\":\"Enter the roundabout.\"\ + }"; + turnSound.SetLocaleWithJson(engShortJson); + turnSound.Reset(); turnSound.SetSpeedMetersPerSecond(30.); @@ -252,9 +267,7 @@ UNIT_TEST(TurnsSoundFeetTest) // So we start playing the first notification when the distance till the turn is less // then 20 seconds * 30 meters per seconds + 100 meters = 700 meters. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 699. /* distanceToTurnMeters */); - vector const expectedNotification1 = { - {2000 /* m_distanceUnits */, 3 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::EnterRoundAbout, LengthUnits::Feet}}; + vector const expectedNotification1 = {{"In 2000 feet. Enter the roundabout."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification1, ()); // 650 meters till the turn. No sound notifications is required. @@ -272,9 +285,7 @@ UNIT_TEST(TurnsSoundFeetTest) // 99 meters till the turn. It's time to pronounce the second voice notification. turnSound.UpdateRouteFollowingInfo(followInfo, turnItem, 99. /* distanceToTurnMeters */); - vector const expectedNotification2 = { - {0 /* m_distanceUnits */, 3 /* m_exitNum */, false /* m_useThenInsteadOfDistance */, - TurnDirection::EnterRoundAbout, LengthUnits::Feet}}; + vector const expectedNotification2 = {{"Enter the roundabout."}}; TEST_EQUAL(followInfo.m_turnNotifications, expectedNotification2, ()); // 99 meters till the turn again. No sound notifications is required. diff --git a/routing/turns_sound.cpp b/routing/turns_sound.cpp index b8b38602d6..0296a7ee59 100644 --- a/routing/turns_sound.cpp +++ b/routing/turns_sound.cpp @@ -76,8 +76,8 @@ void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnIt // First turn sound notification. uint32_t const distToPronounce = m_settings.RoundByPresetSoundedDistancesUnits(turnNotificationDistUnits); - info.m_turnNotifications.emplace_back(distToPronounce, turn.m_exitNum, false, turn.m_turn, - m_settings.GetLengthUnits()); + info.m_turnNotifications.emplace_back(GenerateTurnText(distToPronounce, turn.m_exitNum, false, turn.m_turn, + m_settings.GetLengthUnits())); // @TODO(vbykoianko) Check if there's a turn immediately after the current turn. // If so add an extra item to info.m_turnNotifications with "then parameter". m_nextTurnNotificationProgress = PronouncedNotification::First; @@ -95,8 +95,8 @@ void TurnsSound::UpdateRouteFollowingInfo(location::FollowingInfo & info, TurnIt if (m_nextTurnNotificationProgress == PronouncedNotification::First && distanceToTurnMeters < distanceToPronounceNotificationMeters) { - info.m_turnNotifications.emplace_back(0, turn.m_exitNum, false, turn.m_turn, - m_settings.GetLengthUnits()); + info.m_turnNotifications.emplace_back(GenerateTurnText(0, turn.m_exitNum, false, turn.m_turn, + m_settings.GetLengthUnits())); // @TODO(vbykoianko) Check if there's a turn immediately after the current turn. // If so add an extra item to info.m_turnNotifications with "then parameter". diff --git a/routing/turns_sound.hpp b/routing/turns_sound.hpp index 91851bcff0..49b760f7a5 100644 --- a/routing/turns_sound.hpp +++ b/routing/turns_sound.hpp @@ -67,6 +67,8 @@ public: inline LengthUnits GetLengthUnits() const { return m_settings.GetLengthUnits(); } inline void SetLocale(string const & locale) { m_getTtsText.SetLocale(locale); } inline string GetLocale() const { return m_getTtsText.GetLocale(); } + /// SetLocaleWithJson is used for writing unit tests only. + void SetLocaleWithJson(string const & jsonBuffer) { m_getTtsText.SetLocaleWithJson(jsonBuffer); } void SetSpeedMetersPerSecond(double speed); /// \brief UpdateRouteFollowingInfo updates information about the next turn notification.