summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-06-08 16:46:33 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-15 09:39:08 +0000
commit7a82ee1645ef0df9c766031edd20ea99d5ea7b6e (patch)
tree6ba9bd20bdc08a7b98a416d9b6495cbfa39516e0 /tests/auto
parent3fc0d1114a17d37a84ffc620394180c19a579deb (diff)
Make sensor possible to indicate it is no longer busy
The current implementation allowed sensor backend to only indicate that it is busy, but not to tell when it was freed again. This commit allows sensor backend to indicate also that it's busy state has cleared. It is up to the sensor implementation to decide if it makes sense / is possible to do that or not. Task-number: QTBUG-92513 Task-number: QTBUG-92505 Change-Id: Ied4857850e81346031fd83aa347d9955081118e8 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit f8445fdcbf75e455443304bc290c48c37961e9f1) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/common/test_backends.cpp9
-rw-r--r--tests/auto/common/test_backends.h1
-rw-r--r--tests/auto/qml/qml_quick/tst_sensors_basic.qml24
-rw-r--r--tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp4
-rw-r--r--tests/auto/qsensor/tst_qsensor.cpp18
5 files changed, 55 insertions, 1 deletions
diff --git a/tests/auto/common/test_backends.cpp b/tests/auto/common/test_backends.cpp
index aed4746e..15419b0e 100644
--- a/tests/auto/common/test_backends.cpp
+++ b/tests/auto/common/test_backends.cpp
@@ -55,8 +55,16 @@ static bool registerTestBackend(const char *className, CreateFunc func)
// the sensor reading values in the backend
static QMap<QSensor*, QSensorBackend*> sensorToBackend;
+void set_test_backend_busy(QSensor* sensor, bool busy)
+{
+ Q_ASSERT(sensor->isConnectedToBackend());
+ QSensorBackend* backend = sensorToBackend.value(sensor);
+ backend->sensorBusy(busy);
+}
+
void set_test_backend_reading(QSensor* sensor, const QJsonObject& values)
{
+ Q_ASSERT(sensor->isConnectedToBackend());
QSensorBackend* backend = sensorToBackend.value(sensor);
backend->reading()->setTimestamp(values["timestamp"].toInt()); // timestamp is common to all
if (sensor->type() == "QAccelerometer") {
@@ -182,4 +190,3 @@ void unregister_test_backends()
for (const Record &record : records)
QSensorManager::unregisterBackend(record.type, record.type);
}
-
diff --git a/tests/auto/common/test_backends.h b/tests/auto/common/test_backends.h
index 492fe7c1..66699b5c 100644
--- a/tests/auto/common/test_backends.h
+++ b/tests/auto/common/test_backends.h
@@ -35,6 +35,7 @@
void register_test_backends();
void unregister_test_backends();
void set_test_backend_reading(QSensor* sensor, const QJsonObject& values);
+void set_test_backend_busy(QSensor* sensor, bool busy);
#include <qaccelerometer.h>
#include <qaltimeter.h>
diff --git a/tests/auto/qml/qml_quick/tst_sensors_basic.qml b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
index 0655fc36..298ecef8 100644
--- a/tests/auto/qml/qml_quick/tst_sensors_basic.qml
+++ b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
@@ -42,6 +42,11 @@ TestCase {
signalName: "readingChanged"
}
+ SignalSpy {
+ id: sensorBusySpy
+ signalName: "busyChanged"
+ }
+
function init() {
TestControl.registerTestBackends()
}
@@ -50,6 +55,25 @@ TestCase {
TestControl.unregisterTestBackends()
}
+ function test_busy() {
+ var sensor = Qt.createQmlObject("import QtSensors; Accelerometer {identifier: \"QAccelerometer\"}", testCase);
+ sensorBusySpy.target = sensor
+ compare(sensor.busy, false)
+ verify(sensor.start())
+
+ // set sensor busy and verify 'busy' property and its signaling
+ TestControl.setSensorBusy(sensor, true)
+ compare(sensorBusySpy.count, 1)
+ TestControl.setSensorBusy(sensor, false)
+ compare(sensorBusySpy.count, 2)
+ TestControl.setSensorBusy(sensor, false)
+ compare(sensorBusySpy.count, 2)
+
+ // tidy up
+ sensor.destroy()
+ sensorBusySpy.clear()
+ }
+
function test_reading(data) {
var sensor = Qt.createQmlObject(
diff --git a/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp b/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp
index 7e52d3b8..8162601d 100644
--- a/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp
+++ b/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp
@@ -55,6 +55,10 @@ public slots:
void setSensorReading(const QmlSensor* qmlSensor, const QJsonObject& values) {
set_test_backend_reading(qmlSensor->sensor(), values);
}
+
+ void setSensorBusy(const QmlSensor* qmlSensor, bool busy) {
+ set_test_backend_busy(qmlSensor->sensor(), busy);
+ }
};
QUICK_TEST_MAIN_WITH_SETUP(tst_sensors_qmlquick, TestSetup)
diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp
index 7eb9bba9..69c5c5f1 100644
--- a/tests/auto/qsensor/tst_qsensor.cpp
+++ b/tests/auto/qsensor/tst_qsensor.cpp
@@ -933,6 +933,24 @@ private slots:
// Now we can start the second instance
sensor2.start();
QVERIFY(sensor2.isActive());
+
+ // test 'busy' going back and forth and verify indication to frontend
+ register_test_backends();
+ QAccelerometer accelerometer;
+ accelerometer.setIdentifier("QAccelerometer");
+ QSignalSpy busySpy(&accelerometer, SIGNAL(busyChanged()));
+ QVERIFY(accelerometer.connectToBackend());
+ QVERIFY(!accelerometer.isBusy());
+ QCOMPARE(busySpy.count(), 0);
+
+ set_test_backend_busy(&accelerometer, true);
+ QCOMPARE(busySpy.count(), 1);
+ QVERIFY(accelerometer.isBusy());
+
+ set_test_backend_busy(&accelerometer, false);
+ QCOMPARE(busySpy.count(), 2);
+ QVERIFY(!accelerometer.isBusy());
+ unregister_test_backends();
}
void testIdenfifierChanged()