summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/CMakeLists.txt2
-rw-r--r--tests/auto/common/test_backends.cpp185
-rw-r--r--tests/auto/common/test_backends.h (renamed from tests/auto/qsensor/test_backends.h)19
-rw-r--r--tests/auto/qml/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qml_cpp/CMakeLists.txt (renamed from tests/auto/sensors2qmlapi/CMakeLists.txt)7
-rw-r--r--tests/auto/qml/qml_cpp/qtemplategestureplugin.cpp (renamed from tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp)0
-rw-r--r--tests/auto/qml/qml_cpp/qtemplategestureplugin.h (renamed from tests/auto/sensors2qmlapi/qtemplategestureplugin.h)0
-rw-r--r--tests/auto/qml/qml_cpp/qtemplaterecognizer.cpp (renamed from tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp)0
-rw-r--r--tests/auto/qml/qml_cpp/qtemplaterecognizer.h (renamed from tests/auto/sensors2qmlapi/qtemplaterecognizer.h)0
-rw-r--r--tests/auto/qml/qml_cpp/tst_sensors_qmlcpp.cpp (renamed from tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp)18
-rw-r--r--tests/auto/qml/qml_quick/CMakeLists.txt17
-rw-r--r--tests/auto/qml/qml_quick/tst_sensors_basic.qml125
-rw-r--r--tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp (renamed from tests/auto/qsensor/test_backends.cpp)69
-rw-r--r--tests/auto/qsensor/CMakeLists.txt2
-rw-r--r--tests/auto/qsensor/tst_qsensor.cpp2
-rw-r--r--tests/auto/qsensorgestureplugins/CMakeLists.txt2
-rw-r--r--tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp2
17 files changed, 388 insertions, 64 deletions
diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt
index 8f1c9ec7..c325e2f7 100644
--- a/tests/auto/CMakeLists.txt
+++ b/tests/auto/CMakeLists.txt
@@ -3,7 +3,7 @@ add_subdirectory(qsensorgestures)
add_subdirectory(qsensorgestureplugins)
add_subdirectory(cmake)
if(TARGET Qt::Quick)
- add_subdirectory(sensors2qmlapi)
+ add_subdirectory(qml)
endif()
if(UNIX AND NOT APPLE)
add_subdirectory(qsensorgestures_gestures)
diff --git a/tests/auto/common/test_backends.cpp b/tests/auto/common/test_backends.cpp
new file mode 100644
index 00000000..aed4746e
--- /dev/null
+++ b/tests/auto/common/test_backends.cpp
@@ -0,0 +1,185 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QList>
+#include "qsensorbackend.h"
+
+typedef QSensorBackend* (*CreateFunc) (QSensor *sensor);
+class Record
+{
+public:
+ QByteArray type;
+ CreateFunc func;
+};
+static QList<Record> records;
+
+static bool registerTestBackend(const char *className, CreateFunc func)
+{
+ Record record;
+ record.type = className;
+ record.func = func;
+ records << record;
+ return true;
+}
+
+#define REGISTER_TOO
+#include "test_backends.h"
+#include <QDebug>
+
+// The sensor-to-backend mapping is maintained in order to be able to change
+// the sensor reading values in the backend
+static QMap<QSensor*, QSensorBackend*> sensorToBackend;
+
+void set_test_backend_reading(QSensor* sensor, const QJsonObject& values)
+{
+ QSensorBackend* backend = sensorToBackend.value(sensor);
+ backend->reading()->setTimestamp(values["timestamp"].toInt()); // timestamp is common to all
+ if (sensor->type() == "QAccelerometer") {
+ QAccelerometerReading* reading = static_cast<QAccelerometerReading*>(backend->reading());
+ reading->setX(values["x"].toDouble());
+ reading->setY(values["y"].toDouble());
+ reading->setZ(values["z"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QPressureSensor") {
+ QPressureReading* reading = static_cast<QPressureReading*>(backend->reading());
+ reading->setPressure(values["pressure"].toDouble());
+ reading->setTemperature(values["temperature"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QGyroscope") {
+ QGyroscopeReading* reading = static_cast<QGyroscopeReading*>(backend->reading());
+ reading->setX(values["x"].toDouble());
+ reading->setY(values["y"].toDouble());
+ reading->setZ(values["z"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QTapSensor") {
+ QTapReading* reading = static_cast<QTapReading*>(backend->reading());
+ reading->setDoubleTap(values["doubleTap"].toBool());
+ reading->setTapDirection(QTapReading::TapDirection(values["tapDirection"].toInt()));
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QCompass") {
+ QCompassReading* reading = static_cast<QCompassReading*>(backend->reading());
+ reading->setAzimuth(values["azimuth"].toDouble());
+ reading->setCalibrationLevel(values["calibrationLevel"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QProximitySensor") {
+ QProximityReading* reading = static_cast<QProximityReading*>(backend->reading());
+ reading->setClose(values["near"].toBool());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QOrientationSensor") {
+ QOrientationReading* reading = static_cast<QOrientationReading*>(backend->reading());
+ reading->setOrientation(QOrientationReading::Orientation(values["orientation"].toInt()));
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QDistanceSensor") {
+ QDistanceReading* reading = static_cast<QDistanceReading*>(backend->reading());
+ reading->setDistance(values["distance"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QAmbientLightSensor") {
+ QAmbientLightReading* reading = static_cast<QAmbientLightReading*>(backend->reading());
+ reading->setLightLevel(QAmbientLightReading::LightLevel(values["lightLevel"].toInt()));
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QMagnetometer") {
+ QMagnetometerReading* reading = static_cast<QMagnetometerReading*>(backend->reading());
+ reading->setX(values["x"].toDouble());
+ reading->setY(values["y"].toDouble());
+ reading->setZ(values["z"].toDouble());
+ reading->setCalibrationLevel(values["calibrationLevel"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QLidSensor") {
+ QLidReading* reading = static_cast<QLidReading*>(backend->reading());
+ reading->setBackLidClosed(values["backLidClosed"].toBool());
+ reading->setFrontLidClosed(values["frontLidClosed"].toBool());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QTiltSensor") {
+ QTiltReading* reading = static_cast<QTiltReading*>(backend->reading());
+ reading->setYRotation(values["yRotation"].toDouble());
+ reading->setXRotation(values["xRotation"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QRotationSensor") {
+ QRotationReading* reading = static_cast<QRotationReading*>(backend->reading());
+ reading->setFromEuler(values["x"].toDouble(), values["y"].toDouble(), values["z"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QHumiditySensor") {
+ QHumidityReading* reading = static_cast<QHumidityReading*>(backend->reading());
+ reading->setRelativeHumidity(values["relativeHumidity"].toDouble());
+ reading->setAbsoluteHumidity(values["absoluteHumidity"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QHolsterSensor") {
+ QHolsterReading* reading = static_cast<QHolsterReading*>(backend->reading());
+ reading->setHolstered(values["holstered"].toBool());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QAmbientTemperatureSensor") {
+ QAmbientTemperatureReading* reading = static_cast<QAmbientTemperatureReading*>(backend->reading());
+ reading->setTemperature(values["temperature"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QLightSensor") {
+ QLightReading* reading = static_cast<QLightReading*>(backend->reading());
+ reading->setLux(values["illuminance"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QAltimeter") {
+ QAltimeterReading* reading = static_cast<QAltimeterReading*>(backend->reading());
+ reading->setAltitude(values["altitude"].toDouble());
+ backend->newReadingAvailable();
+ } else if (sensor->type() == "QIRProximitySensor") {
+ QIRProximityReading* reading = static_cast<QIRProximityReading*>(backend->reading());
+ reading->setReflectance(values["reflectance"].toDouble());
+ backend->newReadingAvailable();
+ } else {
+ qWarning() << "Unsupported test sensor backend:" << sensor->type();
+ }
+}
+
+class BackendFactory : public QSensorBackendFactory
+{
+ QSensorBackend *createBackend(QSensor *sensor) override
+ {
+ for (const Record &record : records) {
+ if (sensor->identifier() == record.type) {
+ QSensorBackend* backend = record.func(sensor);
+ sensorToBackend.insert(sensor, backend);
+ return backend;
+ }
+ }
+ return nullptr;
+ }
+};
+static BackendFactory factory;
+
+void register_test_backends()
+{
+ sensorToBackend.clear();
+ for (const Record &record : records)
+ QSensorManager::registerBackend(record.type, record.type, &factory);
+}
+
+void unregister_test_backends()
+{
+ sensorToBackend.clear();
+ for (const Record &record : records)
+ QSensorManager::unregisterBackend(record.type, record.type);
+}
+
diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/common/test_backends.h
index 11dbe102..492fe7c1 100644
--- a/tests/auto/qsensor/test_backends.h
+++ b/tests/auto/common/test_backends.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSensors module of the Qt Toolkit.
@@ -30,9 +30,11 @@
#define TEST_BACKENDS_H
#include <qsensorbackend.h>
+#include <QtCore/QJsonObject>
void register_test_backends();
void unregister_test_backends();
+void set_test_backend_reading(QSensor* sensor, const QJsonObject& values);
#include <qaccelerometer.h>
#include <qaltimeter.h>
@@ -50,6 +52,9 @@ void unregister_test_backends();
#include <qtapsensor.h>
#include <qirproximitysensor.h>
#include <qtiltsensor.h>
+#include <qdistancesensor.h>
+#include <qlidsensor.h>
+#include <qhumiditysensor.h>
#define PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)\
class SensorClass ## _impl : public QSensorBackend\
@@ -141,6 +146,18 @@ PREPARE_SENSORINTERFACE(QTiltSensor, QTiltReading, QTiltFilter, {
reading->setYRotation(1.0);
reading->setXRotation(1.0);
})
+PREPARE_SENSORINTERFACE(QDistanceSensor, QDistanceReading, QDistanceFilter, {
+ reading->setDistance(1.0);
+})
+PREPARE_SENSORINTERFACE(QLidSensor, QLidReading, QLidFilter, {
+ reading->setBackLidClosed(true);
+ reading->setFrontLidClosed(true);
+})
+PREPARE_SENSORINTERFACE(QHumiditySensor, QHumidityReading, QHumidityFilter, {
+ reading->setRelativeHumidity(1.0);
+ reading->setAbsoluteHumidity(1.0);
+})
+
#define TEST_SENSORINTERFACE(SensorClass, ReadingClass, readingcode)\
do {\
diff --git a/tests/auto/qml/CMakeLists.txt b/tests/auto/qml/CMakeLists.txt
new file mode 100644
index 00000000..142c1228
--- /dev/null
+++ b/tests/auto/qml/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(qml_cpp)
+add_subdirectory(qml_quick)
diff --git a/tests/auto/sensors2qmlapi/CMakeLists.txt b/tests/auto/qml/qml_cpp/CMakeLists.txt
index 075cdc35..1ceb7662 100644
--- a/tests/auto/sensors2qmlapi/CMakeLists.txt
+++ b/tests/auto/qml/qml_cpp/CMakeLists.txt
@@ -1,12 +1,9 @@
-#####################################################################
-## tst_sensors2qmlapi Test:
-#####################################################################
-qt_internal_add_test(tst_sensors2qmlapi
+qt_internal_add_test(tst_sensors_qmlcpp
SOURCES
qtemplategestureplugin.cpp qtemplategestureplugin.h
qtemplaterecognizer.cpp qtemplaterecognizer.h
- tst_sensors2qmlapi.cpp
+ tst_sensors_qmlcpp.cpp
PUBLIC_LIBRARIES
Qt::Qml
LIBRARIES
diff --git a/tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp b/tests/auto/qml/qml_cpp/qtemplategestureplugin.cpp
index fc90696c..fc90696c 100644
--- a/tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp
+++ b/tests/auto/qml/qml_cpp/qtemplategestureplugin.cpp
diff --git a/tests/auto/sensors2qmlapi/qtemplategestureplugin.h b/tests/auto/qml/qml_cpp/qtemplategestureplugin.h
index 94f6aaea..94f6aaea 100644
--- a/tests/auto/sensors2qmlapi/qtemplategestureplugin.h
+++ b/tests/auto/qml/qml_cpp/qtemplategestureplugin.h
diff --git a/tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp b/tests/auto/qml/qml_cpp/qtemplaterecognizer.cpp
index caf53d9c..caf53d9c 100644
--- a/tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp
+++ b/tests/auto/qml/qml_cpp/qtemplaterecognizer.cpp
diff --git a/tests/auto/sensors2qmlapi/qtemplaterecognizer.h b/tests/auto/qml/qml_cpp/qtemplaterecognizer.h
index 10e5bc33..10e5bc33 100644
--- a/tests/auto/sensors2qmlapi/qtemplaterecognizer.h
+++ b/tests/auto/qml/qml_cpp/qtemplaterecognizer.h
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/qml/qml_cpp/tst_sensors_qmlcpp.cpp
index 91f51159..acc4d924 100644
--- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
+++ b/tests/auto/qml/qml_cpp/tst_sensors_qmlcpp.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSensors module of the Qt Toolkit.
@@ -30,8 +30,8 @@
#include <QtTest/QSignalSpy>
#include <QtCore/QDebug>
-#include "../../../src/sensorsquick/qmlsensor_p.h"
-#include "../../../src/sensorsquick/qmlsensorgesture_p.h"
+#include <QtSensorsQuick/private/qmlsensor_p.h>
+#include <QtSensorsQuick/private/qmlsensorgesture_p.h>
#include "qtemplategestureplugin.h"
#include "qtemplaterecognizer.h"
@@ -43,7 +43,7 @@ QT_USE_NAMESPACE
QT_BEGIN_NAMESPACE
-class tst_Sensors2QMLAPI : public QObject
+class tst_sensors_qmlcpp : public QObject
{
Q_OBJECT
@@ -53,12 +53,12 @@ private slots:
void testSensorRanges();
};
-void tst_Sensors2QMLAPI::initTestCase()
+void tst_sensors_qmlcpp::initTestCase()
{
qputenv("QT_SENSORS_LOAD_PLUGINS", "0"); // Do not load plugins
}
-void tst_Sensors2QMLAPI::testGesture()
+void tst_sensors_qmlcpp::testGesture()
{
QTemplateGesturePlugin* plugin = new QTemplateGesturePlugin();
QList <QSensorGestureRecognizer *> recognizers = plugin->createRecognizers();
@@ -235,7 +235,7 @@ private:
QSensor *m_sensor = nullptr;
};
-void tst_Sensors2QMLAPI::testSensorRanges()
+void tst_sensors_qmlcpp::testSensorRanges()
{
QScopedPointer<QmlDummySensor> qmlSensor(new QmlDummySensor);
qmlSensor->componentComplete();
@@ -284,5 +284,5 @@ void tst_Sensors2QMLAPI::testSensorRanges()
QT_END_NAMESPACE
-QTEST_MAIN(tst_Sensors2QMLAPI)
-#include "tst_sensors2qmlapi.moc"
+QTEST_MAIN(tst_sensors_qmlcpp)
+#include "tst_sensors_qmlcpp.moc"
diff --git a/tests/auto/qml/qml_quick/CMakeLists.txt b/tests/auto/qml/qml_quick/CMakeLists.txt
new file mode 100644
index 00000000..23ef6981
--- /dev/null
+++ b/tests/auto/qml/qml_quick/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Collect test data
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/tst_*qml)
+list(APPEND test_data ${test_data_glob})
+
+qt_internal_add_test(tst_sensors_qmlquick
+ QMLTEST
+ SOURCES
+ ../../common/test_backends.cpp ../../common/test_backends.h
+ tst_sensors_qmlquick.cpp
+ LIBRARIES
+ Qt::Quick
+ Qt::Sensors
+ Qt::SensorsQuickPrivate
+ TESTDATA ${test_data}
+)
diff --git a/tests/auto/qml/qml_quick/tst_sensors_basic.qml b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
new file mode 100644
index 00000000..0655fc36
--- /dev/null
+++ b/tests/auto/qml/qml_quick/tst_sensors_basic.qml
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtTest
+import QtSensors
+
+TestCase {
+ id: testCase
+
+ SignalSpy {
+ id: sensorActiveSpy
+ signalName: "activeChanged"
+ }
+
+ SignalSpy {
+ id: sensorReadingSpy
+ signalName: "readingChanged"
+ }
+
+ function init() {
+ TestControl.registerTestBackends()
+ }
+
+ function cleanup() {
+ TestControl.unregisterTestBackends()
+ }
+
+ function test_reading(data) {
+
+ var sensor = Qt.createQmlObject(
+ "import QtSensors; "
+ + data.tag + "{"
+ + "identifier: " + "\"Q" + data.tag + "\""
+ + "}"
+ ,testCase)
+ sensorActiveSpy.target = sensor
+ sensorReadingSpy.target = sensor
+
+ // verify initial values of sensor
+ // note: 'reading' values are 'undefined by design' before activation, and therefore aren't tested
+ compare(sensor.type, "Q" + data.tag)
+ compare(sensor.active, false)
+ compare(sensor.alwaysOn, false )
+ compare(sensor.busy, false)
+ compare(sensor.description, "")
+ compare(sensor.error, 0)
+ compare(sensor.skipDuplicates, false)
+
+ // start the sensor and verify activation
+ sensor.start()
+ compare(sensor.active, true)
+ compare(sensorActiveSpy.count, 1)
+ compare(sensorReadingSpy.count, 1)
+
+ // verify the initial reading values
+ for (var prop in data.initialReading)
+ fuzzyCompare(sensor.reading[prop], data.initialReading[prop], 0.0001, data.tag + "::" + prop)
+
+ // change reading values and verify them
+ TestControl.setSensorReading(sensor, data.newReading)
+ compare(sensorReadingSpy.count, 2)
+ for (prop in data.newReading)
+ fuzzyCompare(sensor.reading[prop], data.newReading[prop], 0.0001, data.tag + "::" + prop)
+
+ // stop the sensor and verify deactivation
+ sensor.stop()
+ compare(sensor.active, false)
+ compare(sensorActiveSpy.count, 2)
+ compare(sensorReadingSpy.count, 2)
+
+ // tidy up
+ sensor.destroy()
+ sensorActiveSpy.clear()
+ sensorReadingSpy.clear()
+ }
+
+ function test_reading_data() {
+ return [
+ {tag: "Accelerometer", initialReading: {timestamp: 0, x: 1.0, y: 1.0, z: 1.0}, newReading: {timestamp: 1, x: 2.0, y: 3.0, z: 4.0}},
+ {tag: "PressureSensor", initialReading: {pressure: 1.0, temperature: 1.0}, newReading: {pressure: 2.0, temperature: 3.0}},
+ {tag: "Gyroscope", initialReading: {x : 1.0, y: 1.0, z: 1.0}, newReading: {x : 2.0, y: 3.0, z: 4.0}},
+ {tag: "TapSensor", initialReading: {doubleTap: true, tapDirection: TapReading.Z_Both}, newReading: {doubleTap: false, tapDirection: TapReading.X_Both}},
+ {tag: "Compass", initialReading: {azimuth: 1.0, calibrationLevel: 1.0}, newReading: {azimuth: 2.0, calibrationLevel: 3.0}},
+ {tag: "ProximitySensor", initialReading: {near: true}, newReading: {near: false}},
+ {tag: "OrientationSensor", initialReading: {orientation: OrientationReading.LeftUp}, newReading: {orientation: OrientationReading.RightUp}},
+ {tag: "DistanceSensor", initialReading: {distance: 1.0}, newReading: {distance: 2.0}},
+ {tag: "AmbientLightSensor", initialReading: {lightLevel: AmbientLightReading.Twilight}, newReading: {lightLevel: AmbientLightReading.Sunny}},
+ {tag: "Magnetometer", initialReading: {x : 1.0, y: 1.0, z: 1.0, calibrationLevel: 1.0}, newReading: {x : 2.0, y: 3.0, z: 4.0, calibrationLevel: 5.0}},
+ {tag: "LidSensor", initialReading: {backLidClosed:true, frontLidClosed: true}, newReading: {backLidClosed:false, frontLidClosed: false}},
+ {tag: "TiltSensor", initialReading: {yRotation: 1.0, xRotation: 1.0}, newReading: {yRotation: 2.0, xRotation: 3.0}},
+ {tag: "RotationSensor", initialReading: {x: 1.0, y: 1.0, z: 1.0}, newReading: {x: 2.0, y: 3.0, z: 4.0}},
+ {tag: "HumiditySensor", initialReading: {relativeHumidity: 1.0, absoluteHumidity: 1.0}, newReading: {relativeHumidity: 2.0, absoluteHumidity: 3.0}},
+ {tag: "HolsterSensor", initialReading: {holstered: true}, newReading: {holstered: false}},
+ {tag: "AmbientTemperatureSensor", initialReading: {temperature: 30.0}, newReading: {temperature: 40.0}},
+ {tag: "LightSensor", initialReading: {illuminance: 1.0}, newReading: {illuminance: 2.0}},
+ {tag: "Altimeter", initialReading: {altitude: 8848}, newReading: {altitude: 9959}},
+ {tag: "IRProximitySensor", initialReading: {reflectance: 0.5}, newReading: {reflectance: 0.6}}
+ ];
+ }
+}
diff --git a/tests/auto/qsensor/test_backends.cpp b/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp
index 991f0874..7e52d3b8 100644
--- a/tests/auto/qsensor/test_backends.cpp
+++ b/tests/auto/qml/qml_quick/tst_sensors_qmlquick.cpp
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the QtSensors module of the Qt Toolkit.
+** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
@@ -26,56 +26,37 @@
**
****************************************************************************/
-#include <QList>
+#include <QtQuickTest>
+#include <QtQml/QQmlEngine>
+#include <QtQml/QQmlContext>
+#include <QtSensorsQuick/private/qmlsensor_p.h>
+#include "../../common/test_backends.h"
-#include "qsensorbackend.h"
-
-typedef QSensorBackend* (*CreateFunc) (QSensor *sensor);
-class Record
+class TestSetup : public QObject
{
-public:
- QByteArray type;
- CreateFunc func;
-};
-static QList<Record> records;
+ Q_OBJECT
-static bool registerTestBackend(const char *className, CreateFunc func)
-{
- Record record;
- record.type = className;
- record.func = func;
- records << record;
- return true;
-}
+public:
+ TestSetup() {}
-#define REGISTER_TOO
-#include "test_backends.h"
-#include <QDebug>
+public slots:
+ void qmlEngineAvailable(QQmlEngine *engine) {
+ engine->rootContext()->setContextProperty("TestControl", this);
+ }
-class BackendFactory : public QSensorBackendFactory
-{
- QSensorBackend *createBackend(QSensor *sensor) override
- {
- for (const Record &record : records) {
- if (sensor->identifier() == record.type)
- return record.func(sensor);
- }
- return 0;
+ void registerTestBackends() {
+ register_test_backends();
}
-};
-static BackendFactory factory;
-void register_test_backends()
-{
- for (const Record &record : records) {
- QSensorManager::registerBackend(record.type, record.type, &factory);
+ void unregisterTestBackends() {
+ unregister_test_backends();
}
-}
-void unregister_test_backends()
-{
- for (const Record &record : records) {
- QSensorManager::unregisterBackend(record.type, record.type);
+ void setSensorReading(const QmlSensor* qmlSensor, const QJsonObject& values) {
+ set_test_backend_reading(qmlSensor->sensor(), values);
}
-}
+};
+
+QUICK_TEST_MAIN_WITH_SETUP(tst_sensors_qmlquick, TestSetup)
+#include "tst_sensors_qmlquick.moc"
diff --git a/tests/auto/qsensor/CMakeLists.txt b/tests/auto/qsensor/CMakeLists.txt
index 3cdb4cf8..b7734565 100644
--- a/tests/auto/qsensor/CMakeLists.txt
+++ b/tests/auto/qsensor/CMakeLists.txt
@@ -4,7 +4,7 @@
qt_internal_add_test(tst_qsensor
SOURCES
- test_backends.cpp test_backends.h
+ ../common/test_backends.cpp ../common/test_backends.h
test_sensor.cpp test_sensor.h test_sensor_p.h
test_sensor2.cpp test_sensor2.h test_sensor2_p.h
test_sensor2impl.cpp test_sensor2impl.h
diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp
index 9b3e33b2..7eb9bba9 100644
--- a/tests/auto/qsensor/tst_qsensor.cpp
+++ b/tests/auto/qsensor/tst_qsensor.cpp
@@ -39,7 +39,7 @@
#include "test_sensor.h"
#include "test_sensor2.h"
#include "test_sensorimpl.h"
-#include "test_backends.h"
+#include "../common/test_backends.h"
QT_BEGIN_NAMESPACE
diff --git a/tests/auto/qsensorgestureplugins/CMakeLists.txt b/tests/auto/qsensorgestureplugins/CMakeLists.txt
index 676098df..249415a1 100644
--- a/tests/auto/qsensorgestureplugins/CMakeLists.txt
+++ b/tests/auto/qsensorgestureplugins/CMakeLists.txt
@@ -4,7 +4,7 @@
qt_internal_add_test(tst_qsensorgesturepluginstest
SOURCES
- ../qsensor/test_backends.cpp ../qsensor/test_backends.h
+ ../common/test_backends.cpp ../common/test_backends.h
tst_qsensorgesturepluginstest.cpp
INCLUDE_DIRECTORIES
../qsensor
diff --git a/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp b/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp
index 43cebedc..12303955 100644
--- a/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp
+++ b/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp
@@ -38,7 +38,7 @@
#include <qsensorgesturerecognizer.h>
#include <qsensorgestureplugininterface.h>
-#include "test_backends.h"
+#include "../common/test_backends.h"
class Tst_qsensorgesturePluginsTest : public QObject
{