summaryrefslogtreecommitdiffstats
path: root/tests/auto/common/test_backends.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/common/test_backends.cpp')
-rw-r--r--tests/auto/common/test_backends.cpp104
1 files changed, 36 insertions, 68 deletions
diff --git a/tests/auto/common/test_backends.cpp b/tests/auto/common/test_backends.cpp
index 15419b0e..92e69bb3 100644
--- a/tests/auto/common/test_backends.cpp
+++ b/tests/auto/common/test_backends.cpp
@@ -1,34 +1,12 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QVariantMap>
#include "qsensorbackend.h"
+
typedef QSensorBackend* (*CreateFunc) (QSensor *sensor);
class Record
{
@@ -62,99 +40,89 @@ void set_test_backend_busy(QSensor* sensor, bool busy)
backend->sensorBusy(busy);
}
-void set_test_backend_reading(QSensor* sensor, const QJsonObject& values)
+void set_test_backend_reading(QSensor* sensor, const QVariantMap& values)
{
Q_ASSERT(sensor->isConnectedToBackend());
QSensorBackend* backend = sensorToBackend.value(sensor);
- backend->reading()->setTimestamp(values["timestamp"].toInt()); // timestamp is common to all
+ // timestamp is common to all readings
+ if (values.contains("timestamp"))
+ backend->reading()->setTimestamp(values["timestamp"].toInt());
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());
+ if (values.contains("x")) reading->setX(values["x"].value<qreal>());
+ if (values.contains("y")) reading->setY(values["y"].value<qreal>());
+ if (values.contains("z")) reading->setZ(values["z"].value<qreal>());
backend->newReadingAvailable();
} else if (sensor->type() == "QPressureSensor") {
QPressureReading* reading = static_cast<QPressureReading*>(backend->reading());
- reading->setPressure(values["pressure"].toDouble());
- reading->setTemperature(values["temperature"].toDouble());
+ if (values.contains("pressure")) reading->setPressure(values["pressure"].value<qreal>());
+ if (values.contains("temperature")) reading->setTemperature(values["temperature"].value<qreal>());
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());
+ if (values.contains("x")) reading->setX(values["x"].value<qreal>());
+ if (values.contains("y")) reading->setY(values["y"].value<qreal>());
+ if (values.contains("z")) reading->setZ(values["z"].value<qreal>());
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()));
+ if (values.contains("doubleTap")) reading->setDoubleTap(values["doubleTap"].value<bool>());
+ if (values.contains("tapDirection")) 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());
+ if (values.contains("azimuth")) reading->setAzimuth(values["azimuth"].value<qreal>());
+ if (values.contains("calibrationLevel")) reading->setCalibrationLevel(values["calibrationLevel"].value<qreal>());
backend->newReadingAvailable();
} else if (sensor->type() == "QProximitySensor") {
QProximityReading* reading = static_cast<QProximityReading*>(backend->reading());
- reading->setClose(values["near"].toBool());
+ reading->setClose(values["near"].value<bool>());
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());
+ if (values.contains("x")) reading->setX(values["x"].value<qreal>());
+ if (values.contains("y")) reading->setY(values["y"].value<qreal>());
+ if (values.contains("z")) reading->setZ(values["z"].value<qreal>());
+ if (values.contains("calibrationLevel")) reading->setCalibrationLevel(values["calibrationLevel"].value<qreal>());
backend->newReadingAvailable();
} else if (sensor->type() == "QLidSensor") {
QLidReading* reading = static_cast<QLidReading*>(backend->reading());
- reading->setBackLidClosed(values["backLidClosed"].toBool());
- reading->setFrontLidClosed(values["frontLidClosed"].toBool());
+ if (values.contains("backLidClosed")) reading->setBackLidClosed(values["backLidClosed"].value<bool>());
+ if (values.contains("frontLidClosed")) reading->setFrontLidClosed(values["frontLidClosed"].value<bool>());
backend->newReadingAvailable();
} else if (sensor->type() == "QTiltSensor") {
QTiltReading* reading = static_cast<QTiltReading*>(backend->reading());
- reading->setYRotation(values["yRotation"].toDouble());
- reading->setXRotation(values["xRotation"].toDouble());
+ if (values.contains("yRotation")) reading->setYRotation(values["yRotation"].value<qreal>());
+ if (values.contains("xRotation")) reading->setXRotation(values["xRotation"].value<qreal>());
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());
+ reading->setFromEuler(values["x"].value<qreal>(), values["y"].value<qreal>(), values["z"].value<qreal>());
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());
+ if (values.contains("relativeHumidity")) reading->setRelativeHumidity(values["relativeHumidity"].value<qreal>());
+ if (values.contains("absoluteHumidity")) reading->setAbsoluteHumidity(values["absoluteHumidity"].value<qreal>());
backend->newReadingAvailable();
} else if (sensor->type() == "QAmbientTemperatureSensor") {
QAmbientTemperatureReading* reading = static_cast<QAmbientTemperatureReading*>(backend->reading());
- reading->setTemperature(values["temperature"].toDouble());
+ reading->setTemperature(values["temperature"].value<qreal>());
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());
+ reading->setLux(values["illuminance"].value<qreal>());
backend->newReadingAvailable();
} else if (sensor->type() == "QIRProximitySensor") {
QIRProximityReading* reading = static_cast<QIRProximityReading*>(backend->reading());
- reading->setReflectance(values["reflectance"].toDouble());
+ reading->setReflectance(values["reflectance"].value<qreal>());
backend->newReadingAvailable();
} else {
qWarning() << "Unsupported test sensor backend:" << sensor->type();