*/
#include <QDebug>
+#include <QRegExp>
#include "routingcommon.h"
{
qDebug() << __PRETTY_FUNCTION__;
- /// @todo Implement parser
- return QString();
+ // regular expressions for matching/replacing instructions
+ const QString REGEXP_1ST_SEGMENT
+ = "^Head (north|northeast|east|southeast|south|southwest|west|northwest)";
+ const QString REGEXP_CONTINUE = "^Continue";
+ const QString REGEXP_ROUNDABOUT
+ = "^At the roundabout, take the \\d(st|nd|rd|th) exit";
+ const QString REGEXP_TURNS = "^(Turn|Slight|Sharp) (left|right)";
+ const QString REGEXP_U_TURN = "^Make a U-turn";
+
+ QString result = m_instruction;
+
+ // cut beginning of the instruction
+ // (but only if it matches with the expected value)
+
+ if (m_turnType == "") {
+ // first segment (without turn type code)
+ QRegExp regexp(REGEXP_1ST_SEGMENT);
+ result.replace(regexp, "");
+
+ } else if (m_turnType == "C") {
+ // continue straight
+ QRegExp regexp(REGEXP_CONTINUE);
+ result.replace(regexp, "");
+
+ } else if ((m_turnType == "TL") || (m_turnType == "TSLL")
+ || (m_turnType == "TSHL") || (m_turnType == "TR")
+ || (m_turnType == "TSLR") || (m_turnType == "TSHR")) {
+ // turns
+ QRegExp regexp(REGEXP_TURNS);
+ result.replace(regexp, "");
+
+ } else if (m_turnType == "TU") {
+ // u-turn
+ QRegExp regexp(REGEXP_U_TURN);
+ result.replace(regexp, "");
+
+ } else if (m_turnType.startsWith("EXIT")) {
+ // roundabout
+ QRegExp regexp(REGEXP_ROUNDABOUT);
+ result.replace(regexp, "");
+
+ } else {
+ // no match, parsing failed
+ qCritical() << __PRETTY_FUNCTION__ << "PARSING FAILED! ( turn type:"
+ << m_turnType << "instruction:" << m_instruction << ")";
+ }
+
+ // replace on/at/onto words at the beginning of the result
+ // with zero or one leading space and one following space
+ QRegExp regexp("^ ?(on|at|onto) ");
+ result.replace(regexp, "");
+
+ return result;
}
int RouteSegment::time() const
{
Q_OBJECT
-public:
- TestRouteSegment();
-
private Q_SLOTS:
void settersAndGetters();
void streetNameParser();
void streetNameParser_data();
};
-TestRouteSegment::TestRouteSegment()
-{
-}
-
void TestRouteSegment::settersAndGetters()
{
// test data
void TestRouteSegment::streetNameParser()
{
- QVERIFY2(false, "Not yet implemented!");
+ QFETCH(QString, turnType);
+ QFETCH(QString, instruction);
+ QFETCH(QString, result);
+
+ RouteSegment segment;
+ segment.setTurnType(turnType);
+ segment.setInstruction(instruction);
+
+ QCOMPARE(segment.street(), result);
}
void TestRouteSegment::streetNameParser_data()
{
-
+ QTest::addColumn<QString>("turnType");
+ QTest::addColumn<QString>("instruction");
+ QTest::addColumn<QString>("result");
+
+ QTest::newRow("first segment")
+ << "" << "Head northwest on Kiviharjunlenkki" << "Kiviharjunlenkki";
+ QTest::newRow("continue (go straight)")
+ << "C" << "Continue on 847/Heikinkatu" << "847/Heikinkatu";
+ QTest::newRow("turn left")
+ << "TL" << "Turn left at Kajaanintie" << "Kajaanintie";
+ QTest::newRow("turn slight left")
+ << "TSLL" << "Slight left at 847/Uusikatu" << "847/Uusikatu";
+ QTest::newRow("turn sharp left")
+ << "TSHL" << "Sharp left at Erottajankatu" << "Erottajankatu";
+ QTest::newRow("turn right")
+ << "TR" << "Turn right at Linnakatu" << "Linnakatu";
+ QTest::newRow("turn slight right")
+ << "TSLR" << "Slight right at 847/Lävistäjä" << "847/Lävistäjä";
+ QTest::newRow("turn sharp right")
+ << "TSHR" << "Sharp right at Arkadiankatu" << "Arkadiankatu";
+ QTest::newRow("U-turn")
+ << "TU" << "Make a U-turn" << "";
+
+ QTest::newRow("first segment, road name with numbers")
+ << "" << "Head west on 4;9;13;23/Vaajakoskentie" << "4;9;13;23/Vaajakoskentie";
+ QTest::newRow("first segment, unknown road")
+ << "" << "Head northeast" << "";
+
+ QTest::newRow("roundabout, 1st exit")
+ << "EXIT1" << "At the roundabout, take the 1st exit onto Kaitoväylä"
+ << "Kaitoväylä";
+ QTest::newRow("roundabout, 2nd exit")
+ << "EXIT2" << "At the roundabout, take the 2nd exit onto 4;9;13;23"
+ << "4;9;13;23";
+ QTest::newRow("roundabout, 3rd exit")
+ << "EXIT3" << "At the roundabout, take the 3rd exit onto 4;9;13;23"
+ << "4;9;13;23";
+ QTest::newRow("roundabout, 5th exit")
+ << "EXIT5" << "At the roundabout, take the 5th exit onto 4;9;13;23"
+ << "4;9;13;23";
}
QTEST_APPLESS_MAIN(TestRouteSegment);