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 | //TESTED_COMPONENT=src/location |
30 | |
31 | #include <QtTest/QtTest> |
32 | #include <QSignalSpy> |
33 | #include <QtPositioning/qgeopositioninfosource.h> |
34 | #include <QtPositioning/qgeosatelliteinfosource.h> |
35 | #include <QtPositioning/qgeoareamonitorsource.h> |
36 | #include <QtPositioning/qgeocoordinate.h> |
37 | |
38 | QT_USE_NAMESPACE |
39 | |
40 | class tst_PositionPlugin : public QObject |
41 | { |
42 | Q_OBJECT |
43 | |
44 | private slots: |
45 | void initTestCase(); |
46 | |
47 | void availableSources(); |
48 | void create(); |
49 | void getUpdates(); |
50 | }; |
51 | |
52 | void tst_PositionPlugin::initTestCase() |
53 | { |
54 | #if QT_CONFIG(library) |
55 | /* |
56 | * Set custom path since CI doesn't install test plugins |
57 | */ |
58 | #ifdef Q_OS_WIN |
59 | QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() + |
60 | QStringLiteral("/../../../../plugins" )); |
61 | #else |
62 | QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath() |
63 | + QStringLiteral("/../../../plugins" )); |
64 | #endif |
65 | #endif |
66 | } |
67 | |
68 | void tst_PositionPlugin::availableSources() |
69 | { |
70 | QVERIFY(QGeoPositionInfoSource::availableSources().contains("test.source" )); |
71 | QVERIFY(!QGeoSatelliteInfoSource::availableSources().contains("test.source" )); |
72 | QVERIFY(!QGeoAreaMonitorSource::availableSources().contains("test.source" )); |
73 | } |
74 | |
75 | void tst_PositionPlugin::create() |
76 | { |
77 | QGeoPositionInfoSource *src = 0; |
78 | src = QGeoPositionInfoSource::createSource(sourceName: "test.source" , parent: 0); |
79 | QVERIFY(src != 0); |
80 | |
81 | QVERIFY(src->minimumUpdateInterval() == 1000); |
82 | |
83 | src = QGeoPositionInfoSource::createSource(sourceName: "invalid source that will never exist" , parent: 0); |
84 | QVERIFY(src == 0); |
85 | |
86 | QGeoSatelliteInfoSource *ssrc = 0; |
87 | ssrc = QGeoSatelliteInfoSource::createSource(sourceName: "test.source" , parent: 0); |
88 | QVERIFY(ssrc == 0); |
89 | } |
90 | |
91 | void tst_PositionPlugin::getUpdates() |
92 | { |
93 | QGeoPositionInfoSource *src = QGeoPositionInfoSource::createSource(sourceName: "test.source" , parent: 0); |
94 | src->setUpdateInterval(1000); |
95 | |
96 | QSignalSpy spy(src, SIGNAL(positionUpdated(QGeoPositionInfo))); |
97 | src->startUpdates(); |
98 | QTest::qWait(ms: 1500); |
99 | QCOMPARE(spy.count(), 1); |
100 | QCOMPARE(spy[0].size(), 1); |
101 | |
102 | QGeoPositionInfo info = qvariant_cast<QGeoPositionInfo>(v: spy[0][0]); |
103 | QCOMPARE(info.coordinate().latitude(), 0.1); |
104 | QCOMPARE(info.coordinate().longitude(), 0.1); |
105 | } |
106 | |
107 | |
108 | |
109 | QTEST_GUILESS_MAIN(tst_PositionPlugin) |
110 | #include "tst_positionplugin.moc" |
111 | |