summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-05-17 17:31:46 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-05-21 17:09:00 +0200
commit86c28b98bd024221b3e5eac971ac5641ac09e1a9 (patch)
tree29a349874f82bf1220c5abbfdf986a0eca6d6c6d /tests
parent6cc553b1579f6448e2a2734bbb4348e30b6ff09e (diff)
downloadqtlocation-86c28b98bd024221b3e5eac971ac5641ac09e1a9.tar.gz
test.source plugin: reduce minimumUpdateInterval()
Minimum update interval is reduced to 200ms instead of 1 second. This allows to save some time on running the unit tests. Task-number: QTBUG-93030 Change-Id: I85cbac0fed49fc58059ed40461a386c694c5f73f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative_positioning_core/tst_positionsource.qml62
-rw-r--r--tests/auto/positionplugin/plugin.cpp13
-rw-r--r--tests/auto/positionplugintest/tst_positionplugin.cpp7
-rw-r--r--tests/auto/qdeclarativepositionsource/tst_qdeclarativepositionsource.cpp78
4 files changed, 94 insertions, 66 deletions
diff --git a/tests/auto/declarative_positioning_core/tst_positionsource.qml b/tests/auto/declarative_positioning_core/tst_positionsource.qml
index 6b30d2ea..74233fcd 100644
--- a/tests/auto/declarative_positioning_core/tst_positionsource.qml
+++ b/tests/auto/declarative_positioning_core/tst_positionsource.qml
@@ -106,7 +106,7 @@ TestCase {
PositionSource {
id: testingSourceWParams
name: "test.source"
- updateInterval: 1000
+ updateInterval: 200
PluginParameter {
id: altitudeParameter
name: "test.source.altitude"
@@ -129,7 +129,7 @@ TestCase {
SignalSpy { id: updateSpyWParams; target: testingSourceWParams; signalName: "positionChanged" }
- PositionSource { id: testingSourceV1; name: "test.source"; updateInterval: 1000 }
+ PositionSource { id: testingSourceV1; name: "test.source"; updateInterval: 200 }
// use property bindings instead of SignalSpy
property bool directionV1Valid: testingSourceV1.position.directionValid
@@ -147,12 +147,12 @@ TestCase {
SignalSpy { id: updateSpyV1; target: testingSourceV1; signalName: "positionChanged" }
function test_updateInterval() {
- testingSource.updateInterval = 1000;
- compare(testingSource.updateInterval, 1000);
- testingSource.updateInterval = 1200;
- compare(testingSource.updateInterval, 1200);
- testingSource.updateInterval = 800;
- compare(testingSource.updateInterval, 1000);
+ testingSource.updateInterval = 200;
+ compare(testingSource.updateInterval, 200);
+ testingSource.updateInterval = 300;
+ compare(testingSource.updateInterval, 300);
+ testingSource.updateInterval = 100;
+ compare(testingSource.updateInterval, 200);
}
function test_preferredPositioningMethods() {
@@ -172,7 +172,7 @@ TestCase {
testingSourceV1.active = true;
- tryCompare(updateSpyV1, "count", 1, 1500);
+ tryCompare(updateSpyV1, "count", 1, 300);
compare(testingSourceV1.position.coordinate.longitude, 0.1);
compare(testingSourceV1.position.coordinate.latitude, 0.1);
compare(directionV1ValidChangedCount, 1)
@@ -181,7 +181,7 @@ TestCase {
verify(!testingSourceV1.position.speedValid)
verify(isNaN(testingSourceV1.position.speed))
- tryCompare(updateSpyV1, "count", 2, 1500);
+ tryCompare(updateSpyV1, "count", 2, 300);
compare(testingSourceV1.position.coordinate.longitude, 0.2);
compare(testingSourceV1.position.coordinate.latitude, 0.2);
compare(directionV1ValidChangedCount, 1)
@@ -191,7 +191,7 @@ TestCase {
verify(testingSourceV1.position.speed > 10000)
testingSourceV1.active = false;
- wait(2500);
+ wait(300);
compare(updateSpyV1.count, 2);
compare(testingSourceV1.position.coordinate.longitude, 0.2);
compare(testingSourceV1.position.coordinate.latitude, 0.2);
@@ -210,7 +210,7 @@ TestCase {
compare(testingSourceWParams.backendProperty("altitude"), altitudeParameter.value)
testingSourceWParams.active = true;
- tryCompare(updateSpyWParams, "count", 1, 1500);
+ tryCompare(updateSpyWParams, "count", 1, 300);
compare(testingSourceWParams.position.coordinate.longitude, 0.1);
compare(testingSourceWParams.position.coordinate.latitude, 0.1);
compare(testingSourceWParams.position.coordinate.altitude, altitudeParameter.value);
@@ -221,7 +221,7 @@ TestCase {
verify(isNaN(testingSourceWParams.position.speed))
testingSourceWParams.setBackendProperty("altitude", 24.24)
- tryCompare(updateSpyWParams, "count", 2, 1500);
+ tryCompare(updateSpyWParams, "count", 2, 300);
compare(testingSourceWParams.position.coordinate.longitude, 0.2);
compare(testingSourceWParams.position.coordinate.latitude, 0.2);
compare(testingSourceWParams.position.coordinate.altitude, 24.24);
@@ -233,7 +233,7 @@ TestCase {
compare(testingSourceWParams.backendProperty("altitude"), 24.24)
testingSourceWParams.active = false;
- wait(2500);
+ wait(300);
compare(updateSpyWParams.count, 2);
compare(testingSourceWParams.position.coordinate.longitude, 0.2);
compare(testingSourceWParams.position.coordinate.latitude, 0.2);
@@ -310,18 +310,18 @@ TestCase {
compare(preferredMethodsObserver, PositionSource.SatellitePositioningMethods)
compare(preferredMethodsObserverSpy.count, 1)
- testSourceForBindings.updateInterval = 1100;
- compare(updateIntervalObserver, 1100)
+ testSourceForBindings.updateInterval = 210;
+ compare(updateIntervalObserver, 210)
compare(updateIntervalObserverSpy.count, 1)
testSourceForBindings.start();
compare(activeObserver, true)
compare(activeObserverSpy.count, 1)
- tryCompare(positionObserverSpy, "count", 1, 1500);
+ tryCompare(positionObserverSpy, "count", 1, 300);
verify(testSourceForBindings.position.coordinate !== QtPositioning.coordinate())
- testSourceForBindings.update(100) // small timeout will result in an error
+ testSourceForBindings.update(50) // small timeout will result in an error
tryCompare(errorObserverSpy, "count", 1, 200)
compare(errorObserver, PositionSource.UpdateTimeoutError)
@@ -340,7 +340,7 @@ TestCase {
property bool activeSetter: false
property string nameSetter: "test.source"
- property int updateIntervalSetter: 1000
+ property int updateIntervalSetter: 200
property int preferredMethodsSetter: PositionSource.NonSatellitePositioningMethods
PositionSource {
@@ -354,17 +354,17 @@ TestCase {
function test_bindPositionSourceProperties() {
compare(sourceWithBindings.name, "test.source")
compare(sourceWithBindings.active, false)
- compare(sourceWithBindings.updateInterval, 1000)
+ compare(sourceWithBindings.updateInterval, 200)
compare(sourceWithBindings.preferredPositioningMethods, PositionSource.NonSatellitePositioningMethods)
- updateIntervalSetter = 1100;
+ updateIntervalSetter = 210;
preferredMethodsSetter = PositionSource.AllPositioningMethods
activeSetter = true
wait(0) // to trigger event processing
compare(sourceWithBindings.active, true)
- compare(sourceWithBindings.updateInterval, 1100)
+ compare(sourceWithBindings.updateInterval, 210)
compare(sourceWithBindings.preferredPositioningMethods, PositionSource.AllPositioningMethods)
activeSetter = false;
@@ -375,7 +375,7 @@ TestCase {
sourceWithBindings.update(updateIntervalSetter)
compare(sourceWithBindings.active, true)
- wait(1500)
+ wait(300)
compare(sourceWithBindings.active, false)
activeSetter = true;
@@ -391,24 +391,24 @@ TestCase {
verify(updateIntervalSpy.valid)
nameSetter = "invalid name"
- updateIntervalSetter = 800;
- compare(sourceWithBindings.updateInterval, 800)
+ updateIntervalSetter = 100;
+ compare(sourceWithBindings.updateInterval, 100)
compare(updateIntervalSpy.count, 1)
nameSetter = "test.source"
- // "test.source" has a minimum update interval of 1000
- compare(sourceWithBindings.updateInterval, 1000)
+ // "test.source" has a minimum update interval of 200
+ compare(sourceWithBindings.updateInterval, 200)
compare(updateIntervalSpy.count, 2)
nameSetter = "dummy.source"
// "dummy.source" has a minimum udpate interval of 100, so we expect
- // the updateInterval to be set to 800
- compare(sourceWithBindings.updateInterval, 800)
+ // the updateInterval to be set to 100
+ compare(sourceWithBindings.updateInterval, 100)
compare(updateIntervalSpy.count, 3)
// The binding still works
- updateIntervalSetter = 1100
- compare(sourceWithBindings.updateInterval, 1100)
+ updateIntervalSetter = 110
+ compare(sourceWithBindings.updateInterval, 110)
compare(updateIntervalSpy.count, 4)
}
diff --git a/tests/auto/positionplugin/plugin.cpp b/tests/auto/positionplugin/plugin.cpp
index c53722a8..32dc3dee 100644
--- a/tests/auto/positionplugin/plugin.cpp
+++ b/tests/auto/positionplugin/plugin.cpp
@@ -85,7 +85,7 @@ DummySource::DummySource(const QVariantMap &parameters, QObject *parent) :
crd.setAltitude(alti);
lastPosition.setCoordinate(crd);
}
- timer->setInterval(1000);
+ timer->setInterval(200);
connect(timer, SIGNAL(timeout()),
this, SLOT(updatePosition()));
connect(singleTimer, SIGNAL(timeout()),
@@ -118,10 +118,11 @@ QVariant DummySource::backendProperty(const QString &name) const
void DummySource::setUpdateInterval(int msec)
{
+ const int minInterval = minimumUpdateInterval();
if (msec == 0) {
- timer->setInterval(1000);
- } else if (msec < 1000) {
- msec = 1000;
+ timer->setInterval(minInterval);
+ } else if (msec < minInterval) {
+ msec = minInterval;
timer->setInterval(msec);
} else {
timer->setInterval(msec);
@@ -132,7 +133,7 @@ void DummySource::setUpdateInterval(int msec)
int DummySource::minimumUpdateInterval() const
{
- return 1000;
+ return 200;
}
QGeoPositionInfo DummySource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const
@@ -173,7 +174,7 @@ void DummySource::requestUpdate(int timeout)
timer->start();
}
- singleTimer->setInterval(1000);
+ singleTimer->setInterval(minimumUpdateInterval());
singleTimer->start();
}
diff --git a/tests/auto/positionplugintest/tst_positionplugin.cpp b/tests/auto/positionplugintest/tst_positionplugin.cpp
index 26a925c7..4afcd662 100644
--- a/tests/auto/positionplugintest/tst_positionplugin.cpp
+++ b/tests/auto/positionplugintest/tst_positionplugin.cpp
@@ -78,7 +78,7 @@ void tst_PositionPlugin::create()
src.reset(QGeoPositionInfoSource::createSource("test.source", 0));
QVERIFY(src != nullptr);
- QVERIFY(src->minimumUpdateInterval() == 1000);
+ QVERIFY(src->minimumUpdateInterval() == 200);
src.reset(QGeoPositionInfoSource::createSource("invalid source that will never exist", 0));
QVERIFY(src == 0);
@@ -91,12 +91,11 @@ void tst_PositionPlugin::create()
void tst_PositionPlugin::getUpdates()
{
std::unique_ptr<QGeoPositionInfoSource> src(QGeoPositionInfoSource::createSource("test.source", 0));
- src->setUpdateInterval(1000);
+ src->setUpdateInterval(200);
QSignalSpy spy(src.get(), SIGNAL(positionUpdated(QGeoPositionInfo)));
src->startUpdates();
- QTest::qWait(1500);
- QCOMPARE(spy.count(), 1);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 5000);
QCOMPARE(spy[0].size(), 1);
QGeoPositionInfo info = qvariant_cast<QGeoPositionInfo>(spy[0][0]);
diff --git a/tests/auto/qdeclarativepositionsource/tst_qdeclarativepositionsource.cpp b/tests/auto/qdeclarativepositionsource/tst_qdeclarativepositionsource.cpp
index 15083ab5..cd556ab4 100644
--- a/tests/auto/qdeclarativepositionsource/tst_qdeclarativepositionsource.cpp
+++ b/tests/auto/qdeclarativepositionsource/tst_qdeclarativepositionsource.cpp
@@ -138,7 +138,7 @@ void tst_DeclarativePositionSource::positionBinding()
// "test.source" udpates its position, starting from (0, 0) coordinate, and
// adding 0.1 lat and 0.1 log at every step
m_positionSource->setName("test.source");
- m_positionSource->setUpdateInterval(1000);
+ m_positionSource->setUpdateInterval(200);
const QGeoCoordinate c1(0, 0);
const QGeoCoordinate c2(0.1, 0.1, 0);
QCOMPARE(m_positionSource->position()->coordinate(), c1);
@@ -155,8 +155,12 @@ void tst_DeclarativePositionSource::positionBinding()
QTestPrivate::testReadOnlyPropertyBasics<QDeclarativePositionSource, QDeclarativePosition *>(
*m_positionSource.get(), &pos1, &pos2, "position",
[&]() {
+ QSignalSpy spy(m_positionSource.get(),
+ &QDeclarativePositionSource::positionChanged);
m_positionSource->update();
- QTest::qWait(1500); // the update will happen after 1000 ms
+ // Wait for the update to happen. It should take around 200 ms,
+ // but we want to be on a safe side in case of high CI load.
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 5000);
},
[](const QDeclarativePosition *p1, const QDeclarativePosition *p2) {
return p1->coordinate() == p2->coordinate();
@@ -207,13 +211,13 @@ void tst_DeclarativePositionSource::activeBinding()
QCOMPARE(activeLambdaObserver.value(), false);
// calling update() does not break the binding
- m_positionSource->update(100);
+ m_positionSource->update(50);
QCOMPARE(activeSpy.count(), 3);
QCOMPARE(activeObserver.value(), true);
QCOMPARE(activeLambdaObserver.value(), true);
QTRY_COMPARE_WITH_TIMEOUT(m_positionSource->sourceError(),
- QDeclarativePositionSource::UpdateTimeoutError, 300);
+ QDeclarativePositionSource::UpdateTimeoutError, 5000);
QCOMPARE(activeSpy.count(), 4);
QCOMPARE(activeObserver.value(), false);
@@ -293,13 +297,17 @@ void tst_DeclarativePositionSource::activeBindingBreak()
QTest::qWait(0); // to trigger singleShot timer in setActive
QCOMPARE(m_positionSource->isActive(), true);
- m_positionSource->update(1100);
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
m_positionSource->stop();
QVERIFY(!m_positionSource->bindableActive().hasBinding());
QCOMPARE(m_positionSource->isActive(), true);
- QTest::qWait(1500); // wait for the single update to complete
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), false);
QVERIFY(!m_positionSource->bindableActive().hasBinding());
@@ -314,19 +322,19 @@ void tst_DeclarativePositionSource::intervalOnSourceDependency()
QSignalSpy intervalSpy(m_positionSource.get(),
&QDeclarativePositionSource::updateIntervalChanged);
- m_positionSource->setUpdateInterval(200);
- QCOMPARE(m_positionSource->updateInterval(), 200);
+ m_positionSource->setUpdateInterval(100);
+ QCOMPARE(m_positionSource->updateInterval(), 100);
QCOMPARE(intervalSpy.count(), 1);
- // "test.source" has a minimum update interval of 1000
+ // "test.source" has a minimum update interval of 200
m_positionSource->setName("test.source");
- QCOMPARE(m_positionSource->updateInterval(), 1000);
+ QCOMPARE(m_positionSource->updateInterval(), 200);
QCOMPARE(intervalSpy.count(), 2);
// "dummy.source" has a minimum update interval of 100, so we expect our
// desired interval to be applied
m_positionSource->setName("dummy.source");
- QCOMPARE(m_positionSource->updateInterval(), 200);
+ QCOMPARE(m_positionSource->updateInterval(), 100);
QCOMPARE(intervalSpy.count(), 3);
}
@@ -370,8 +378,12 @@ void tst_DeclarativePositionSource::updateAfterStart()
m_positionSource->start();
QCOMPARE(m_positionSource->isActive(), true);
- m_positionSource->update(1100);
- QTest::qWait(1500); // wait for the single update to complete
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->stop();
@@ -387,11 +399,15 @@ void tst_DeclarativePositionSource::startAfterUpdate()
QCOMPARE(m_positionSource->isActive(), false);
- m_positionSource->update(1100);
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->start();
- QTest::qWait(1500); // wait for the single update to complete
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->stop();
@@ -408,13 +424,17 @@ void tst_DeclarativePositionSource::stopAfterUpdate()
QCOMPARE(m_positionSource->isActive(), false);
- m_positionSource->update(1100);
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->stop();
QCOMPARE(m_positionSource->isActive(), true);
- QTest::qWait(1500); // wait for the single update to complete
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), false);
}
@@ -428,7 +448,9 @@ void tst_DeclarativePositionSource::startStopAfterUpdate()
QCOMPARE(m_positionSource->isActive(), false);
- m_positionSource->update(1100);
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->start();
@@ -436,7 +458,9 @@ void tst_DeclarativePositionSource::startStopAfterUpdate()
QCOMPARE(m_positionSource->isActive(), true);
- QTest::qWait(1500); // wait for the single update to complete
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), false);
}
@@ -449,11 +473,11 @@ void tst_DeclarativePositionSource::updateTimedOut()
QCOMPARE(m_positionSource->isActive(), false);
- m_positionSource->update(200); // to small timeout -> will return an error
+ m_positionSource->update(50); // too small timeout -> will return an error
QCOMPARE(m_positionSource->isActive(), true);
QTRY_COMPARE_WITH_TIMEOUT(m_positionSource->sourceError(),
- QDeclarativePositionSource::UpdateTimeoutError, 300);
+ QDeclarativePositionSource::UpdateTimeoutError, 5000);
QCOMPARE(m_positionSource->isActive(), false);
}
@@ -468,11 +492,11 @@ void tst_DeclarativePositionSource::updateWithStartTimedOut()
m_positionSource->start();
- m_positionSource->update(200); // to small timeout -> will return an error
+ m_positionSource->update(50); // too small timeout -> will return an error
QCOMPARE(m_positionSource->isActive(), true);
QTRY_COMPARE_WITH_TIMEOUT(m_positionSource->sourceError(),
- QDeclarativePositionSource::UpdateTimeoutError, 300);
+ QDeclarativePositionSource::UpdateTimeoutError, 5000);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->stop();
@@ -491,12 +515,16 @@ void tst_DeclarativePositionSource::startUpdateStopWithNoIntervals()
QCOMPARE(m_positionSource->isActive(), false);
m_positionSource->start();
- m_positionSource->update(1100);
+ QSignalSpy posSpy(m_positionSource.get(), &QDeclarativePositionSource::positionChanged);
+ QSignalSpy errSpy(m_positionSource.get(), &QDeclarativePositionSource::sourceErrorChanged);
+ m_positionSource->update(210);
QCOMPARE(m_positionSource->isActive(), true);
m_positionSource->stop();
QCOMPARE(m_positionSource->isActive(), true);
- QTest::qWait(1500); // wait for the single update to complete
+ // Wait for the single update to complete. It can be either position update
+ // or timeout.
+ QTRY_VERIFY_WITH_TIMEOUT(posSpy.count() > 0 || errSpy.count() > 0, 5000);
QCOMPARE(m_positionSource->isActive(), false);
}