1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qgeoroutexmlparser.h>
#include <qgeocoordinate.h>
#include <qtest.h>
#include <qgeoroute.h>
#include <QMetaType>
#include <QDebug>
#include <QFile>
#include <QSignalSpy>
Q_DECLARE_METATYPE(QList<QGeoRoute>)
QT_USE_NAMESPACE
class tst_QGeoRouteXmlParser : public QObject
{
Q_OBJECT
public:
tst_QGeoRouteXmlParser()
: start(0.0, 0.0),
end(1.0, 1.0)
{
qRegisterMetaType<QList<QGeoRoute> >();
}
private:
// dummy values for creating the request object
QGeoCoordinate start;
QGeoCoordinate end;
private slots:
void test_realData1()
{
QFile f(":/route1.xml");
if (!f.open(QIODevice::ReadOnly))
QFAIL("could not open route1.xml");
QGeoRouteRequest req(start, end);
QGeoRouteXmlParser xp(req);
xp.setAutoDelete(false);
QSignalSpy resultsSpy(&xp, SIGNAL(results(QList<QGeoRoute>)));
xp.parse(f.readAll());
QTRY_COMPARE(resultsSpy.count(), 1);
QVariantList arguments = resultsSpy.first();
// xml contains exactly 1 route
QList<QGeoRoute> results = arguments.at(0).value<QList<QGeoRoute> >();
QCOMPARE(results.size(), 1);
QGeoRoute route = results.first();
QList<QGeoRouteSegment> segments;
// get all the segments on the route
segments << route.firstRouteSegment();
while (segments.last().isValid())
segments << segments.last().nextRouteSegment();
// should be 9 segments in the list (last one invalid)
QCOMPARE(segments.size(), 9);
// check the first maneuver is correct
QGeoManeuver first = segments.at(0).maneuver();
QCOMPARE(first.instructionText(), QStringLiteral("Head toward Logan Rd (95) on Padstow Rd (56). Go for 0.3 miles."));
QCOMPARE(first.position(), QGeoCoordinate(-27.5752144, 153.0879669));
QCOMPARE(first.timeToNextInstruction(), 24);
QCOMPARE(first.distanceToNextInstruction(), 403.0);
// check the last two maneuvers -- route1.xml has a directionless final maneuver
QGeoManeuver secondLast = segments.at(6).maneuver();
QVERIFY(secondLast.instructionText().contains("Turn right onto Bartley St"));
QCOMPARE(secondLast.position(), QGeoCoordinate(-27.4655991, 153.0231628));
QCOMPARE(secondLast.distanceToNextInstruction(), 181.0);
QCOMPARE(secondLast.timeToNextInstruction(), 41);
QGeoManeuver last = segments.at(7).maneuver();
QVERIFY(last.instructionText().contains("Arrive at Bartley St"));
QCOMPARE(last.position(), QGeoCoordinate(-27.4650097, 153.0230255));
QCOMPARE(last.distanceToNextInstruction(), 0.0);
QCOMPARE(last.timeToNextInstruction(), 0);
}
void test_realData2()
{
QFile f(":/route2.xml");
if (!f.open(QIODevice::ReadOnly))
QFAIL("could not open route2.xml");
QGeoRouteRequest req(start, end);
QGeoRouteXmlParser xp(req);
xp.setAutoDelete(false);
QSignalSpy resultsSpy(&xp, SIGNAL(results(QList<QGeoRoute>)));
xp.parse(f.readAll());
QTRY_COMPARE(resultsSpy.count(), 1);
QVariantList arguments = resultsSpy.first();
// xml contains exactly 1 route
QList<QGeoRoute> results = arguments.at(0).value<QList<QGeoRoute> >();
QCOMPARE(results.size(), 1);
QGeoRoute route = results.first();
QList<QGeoRouteSegment> segments;
// get all the segments on the route
segments << route.firstRouteSegment();
while (segments.last().isValid())
segments << segments.last().nextRouteSegment();
// should be 14 segments in the list (last one invalid)
QCOMPARE(segments.size(), 14);
QCOMPARE(route.path().size(), 284);
QCOMPARE(route.path().at(57), QGeoCoordinate(-27.5530605, 153.0691223));
QCOMPARE(route.path().at(283), QGeoCoordinate(-27.4622307, 153.0397949));
QVERIFY(segments.at(0).maneuver().instructionText().contains("Head toward Electronics St"));
QCOMPARE(segments.at(0).maneuver().direction(), QGeoManeuver::DirectionForward);
QVERIFY(segments.at(1).maneuver().instructionText().contains("Turn left onto Miles Platting"));
QCOMPARE(segments.at(1).maneuver().direction(), QGeoManeuver::DirectionLeft);
QVERIFY(segments.at(2).maneuver().instructionText().contains("Turn right onto Logan Rd"));
QCOMPARE(segments.at(2).maneuver().direction(), QGeoManeuver::DirectionRight);
QVERIFY(segments.at(3).maneuver().instructionText().contains("Take exit #14/M3/City"));
QCOMPARE(segments.at(3).maneuver().direction(), QGeoManeuver::DirectionLightLeft);
QVERIFY(segments.at(4).maneuver().instructionText().contains("Take exit #2/41"));
QCOMPARE(segments.at(4).maneuver().direction(), QGeoManeuver::DirectionLightLeft);
QVERIFY(segments.at(5).maneuver().instructionText().contains("Turn right onto Allen St"));
QCOMPARE(segments.at(5).maneuver().direction(), QGeoManeuver::DirectionRight);
QVERIFY(segments.at(6).maneuver().instructionText().contains("Bear right to stay on"));
QCOMPARE(segments.at(6).maneuver().direction(), QGeoManeuver::DirectionLightRight);
QVERIFY(segments.at(7).maneuver().instructionText().contains("Bear right onto Vulture St"));
QCOMPARE(segments.at(7).maneuver().direction(), QGeoManeuver::DirectionLightRight);
}
};
QTEST_GUILESS_MAIN(tst_QGeoRouteXmlParser)
#include "tst_qgeoroutexmlparser.moc"
|