1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef QGEOCODINGMANAGERENGINE_TEST_H
30#define QGEOCODINGMANAGERENGINE_TEST_H
31
32#include <qgeoserviceprovider.h>
33#include <qgeocodingmanagerengine.h>
34#include <QLocale>
35#include <qgeoaddress.h>
36#include <qgeolocation.h>
37#include <qgeocodereply.h>
38#include <QtPositioning/QGeoCoordinate>
39
40QT_USE_NAMESPACE
41
42class GeocodeReplyTest : public QGeoCodeReply
43{
44 Q_OBJECT
45public:
46 GeocodeReplyTest(QObject *parent = 0) : QGeoCodeReply(parent) {}
47
48 void callAddLocation ( const QGeoLocation & location ) {addLocation(location);}
49 void callSetError ( Error error, const QString & errorString ) {setError(error, errorString);}
50 void callSetFinished ( bool finished ) {setFinished(finished);}
51 void callSetLimit ( int limit ) {setLimit(limit);}
52 void callSetOffset ( int offset ) {setOffset(offset);}
53 void callSetLocations ( const QList<QGeoLocation> & locations ) {setLocations(locations);}
54 void callSetViewport ( const QGeoShape &viewport ) {setViewport(viewport);}
55
56};
57
58class QGeoCodingManagerEngineTest: public QGeoCodingManagerEngine
59
60{
61Q_OBJECT
62public:
63 QGeoCodingManagerEngineTest(const QVariantMap &parameters,
64 QGeoServiceProvider::Error *error, QString *errorString) :
65 QGeoCodingManagerEngine(parameters)
66 {
67 Q_UNUSED(error);
68 Q_UNUSED(errorString);
69 setLocale(QLocale(QLocale::German, QLocale::Germany));
70 }
71
72 QGeoCodeReply* geocode(const QString &searchString, int limit, int offset, const QGeoShape &bounds)
73 {
74 GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
75 geocodereply->callSetLimit(limit);
76 geocodereply->callSetOffset(offset);
77 geocodereply->callSetViewport(viewport: bounds);
78 geocodereply->callSetError(error: QGeoCodeReply::NoError,errorString: searchString);
79 geocodereply->callSetFinished(finished: true);
80 emit(this->finished(reply: geocodereply));
81
82 return static_cast<QGeoCodeReply*>(geocodereply);
83 }
84
85 QGeoCodeReply* geocode (const QGeoAddress &address, const QGeoShape &bounds)
86 {
87 GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
88 geocodereply->callSetViewport(viewport: bounds);
89 geocodereply->callSetError(error: QGeoCodeReply::NoError,errorString: address.city());
90 geocodereply->callSetFinished(finished: true);
91 emit(this->finished(reply: geocodereply));
92
93 return static_cast<QGeoCodeReply*>(geocodereply);
94 }
95
96 QGeoCodeReply* reverseGeocode(const QGeoCoordinate &coordinate, const QGeoShape &bounds)
97 {
98 GeocodeReplyTest *geocodereply = new GeocodeReplyTest();
99 geocodereply->callSetViewport(viewport: bounds);
100 geocodereply->callSetError(error: QGeoCodeReply::NoError,errorString: coordinate.toString());
101 geocodereply->callSetFinished(finished: true);
102 emit(this->finished(reply: geocodereply));
103 return static_cast<QGeoCodeReply*>(geocodereply);
104 }
105};
106
107#endif
108

source code of qtlocation/tests/auto/qgeocodingmanagerplugins/qgeocodingmanagerengine_test.h