summaryrefslogtreecommitdiff
path: root/tests/auto
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@jollamobile.com>2014-02-04 13:56:17 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-10 00:42:29 +0100
commit20ee891ec034783b09c698916fbfc2127f92c803 (patch)
tree5fe8516cca36ec317ae5e63594293bddcb433d8b /tests/auto
parent930de8867937b5a61786e5dc6723b229bf27e529 (diff)
downloadqtlocation-20ee891ec034783b09c698916fbfc2127f92c803.tar.gz
Add direction and vertical speed properties to QML Position type.
The QML and C++ position types now provide the same functionality. Position attributes are always set/reset on every position update. This ensures that old values of speed, accuracy, direction, and vertical speed are not indefinitely reported in QML. Values are set to NaN and if appropriate the associated is valid property is set. [ChangeLog][QtPositioning][Position] Added direction and vertical speed properities. Change-Id: Ia02da8a5bc1cd68489eb58180986df512c24aa2f Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative_core/tst_position.qml10
-rw-r--r--tests/auto/declarative_core/tst_positionsource.qml20
-rw-r--r--tests/auto/positionplugin/plugin.cpp14
3 files changed, 42 insertions, 2 deletions
diff --git a/tests/auto/declarative_core/tst_position.qml b/tests/auto/declarative_core/tst_position.qml
index 8bb42960..07d92328 100644
--- a/tests/auto/declarative_core/tst_position.qml
+++ b/tests/auto/declarative_core/tst_position.qml
@@ -41,7 +41,7 @@
import QtQuick 2.0
import QtTest 1.0
-import QtPositioning 5.2
+import QtPositioning 5.3
TestCase {
id: testCase
@@ -61,6 +61,8 @@ TestCase {
SignalSpy { id: horizontalAccuracyValidSpy; target: defaultPosition; signalName: "horizontalAccuracyValidChanged" }
SignalSpy { id: verticalAccuracySpy; target: defaultPosition; signalName: "verticalAccuracyChanged" }
SignalSpy { id: verticalAccuracyValidSpy; target: defaultPosition; signalName: "verticalAccuracyValidChanged" }
+ SignalSpy { id: directionSpy; target: defaultPosition; signalName: "directionChanged" }
+ SignalSpy { id: verticalSpeedSpy; target: defaultPosition; signalName: "verticalSpeedChanged" }
function test_defaults() {
compare(defaultPosition.latitudeValid, false);
@@ -69,6 +71,10 @@ TestCase {
compare(defaultPosition.speedValid, false);
compare(defaultPosition.horizontalAccuracyValid, false);
compare(defaultPosition.verticalAccuracyValid, false);
+ verify(!defaultPosition.directionValid);
+ verify(isNaN(defaultPosition.direction));
+ verify(!defaultPosition.verticalSpeedValid);
+ verify(isNaN(defaultPosition.verticalSpeed));
}
function test_modifiers() {
@@ -83,6 +89,8 @@ TestCase {
horizontalAccuracyValidSpy.clear();
verticalAccuracySpy.clear();
verticalAccuracyValidSpy.clear();
+ directionSpy.clear();
+ verticalSpeedSpy.clear();
defaultPosition.horizontalAccuracy = 10;
compare(horizontalAccuracySpy.count, 1);
diff --git a/tests/auto/declarative_core/tst_positionsource.qml b/tests/auto/declarative_core/tst_positionsource.qml
index 6cf99d04..405c46ae 100644
--- a/tests/auto/declarative_core/tst_positionsource.qml
+++ b/tests/auto/declarative_core/tst_positionsource.qml
@@ -117,6 +117,8 @@ TestCase {
PositionSource { id: testingSource; name: "test.source"; updateInterval: 1000 }
SignalSpy { id: updateSpy; target: testingSource; signalName: "positionChanged" }
+ SignalSpy { id: directionValidSpy; target: testingSource.position; signalName: "directionValidChanged" }
+ SignalSpy { id: directionSpy; target: testingSource.position; signalName: "directionChanged" }
function test_updateInterval() {
testingSource.updateInterval = 1000;
@@ -139,20 +141,38 @@ TestCase {
function test_updates() {
updateSpy.clear();
+ compare(directionValidSpy.count, 0)
+ compare(directionSpy.count, 0)
+
testingSource.active = true;
tryCompare(updateSpy, "count", 1, 1500);
compare(testingSource.position.coordinate.longitude, 0.1);
compare(testingSource.position.coordinate.latitude, 0.1);
+ compare(directionValidSpy.count, 1)
+ compare(directionSpy.count, 1)
+ fuzzyCompare(testingSource.position.direction, 45, 0.1)
+ verify(!testingSource.position.speedValid)
+ verify(isNaN(testingSource.position.speed))
tryCompare(updateSpy, "count", 2, 1500);
compare(testingSource.position.coordinate.longitude, 0.2);
compare(testingSource.position.coordinate.latitude, 0.2);
+ compare(directionValidSpy.count, 1)
+ compare(directionSpy.count, 2)
+ fuzzyCompare(testingSource.position.direction, 45, 0.1)
+ verify(testingSource.position.speedValid)
+ verify(testingSource.position.speed > 15000)
testingSource.active = false;
wait(2500);
compare(updateSpy.count, 2);
compare(testingSource.position.coordinate.longitude, 0.2);
compare(testingSource.position.coordinate.latitude, 0.2);
+ compare(directionValidSpy.count, 1)
+ compare(directionSpy.count, 2)
+ fuzzyCompare(testingSource.position.direction, 45, 0.1)
+ verify(testingSource.position.speedValid)
+ verify(testingSource.position.speed > 15000)
}
}
diff --git a/tests/auto/positionplugin/plugin.cpp b/tests/auto/positionplugin/plugin.cpp
index a213bbb1..3d6f23ed 100644
--- a/tests/auto/positionplugin/plugin.cpp
+++ b/tests/auto/positionplugin/plugin.cpp
@@ -71,6 +71,7 @@ private:
QTimer *timeoutTimer;
QTimer *singleTimer;
QGeoPositionInfo lastPosition;
+ QDateTime lastUpdateTime;
private slots:
void updatePosition();
@@ -165,9 +166,20 @@ void DummySource::updatePosition()
{
timeoutTimer->stop();
singleTimer->stop();
+
+ const QDateTime now = QDateTime::currentDateTime();
+
QGeoCoordinate coord(lastPosition.coordinate().latitude() + 0.1,
lastPosition.coordinate().longitude() + 0.1);
- QGeoPositionInfo info(coord, QDateTime::currentDateTime());
+
+ QGeoPositionInfo info(coord, now);
+ info.setAttribute(QGeoPositionInfo::Direction, lastPosition.coordinate().azimuthTo(coord));
+ if (lastUpdateTime.isValid()) {
+ double speed = lastPosition.coordinate().distanceTo(coord) / lastUpdateTime.msecsTo(now);
+ info.setAttribute(QGeoPositionInfo::GroundSpeed, 1000 * speed);
+ }
+
+ lastUpdateTime = now;
lastPosition = info;
emit positionUpdated(info);
}