1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtSensors module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef TEST_BACKENDS_H
30#define TEST_BACKENDS_H
31
32#include <qsensorbackend.h>
33
34void register_test_backends();
35void unregister_test_backends();
36
37#include <qaccelerometer.h>
38#include <qaltimeter.h>
39#include <qambientlightsensor.h>
40#include <qambienttemperaturesensor.h>
41#include <qcompass.h>
42#include <qgyroscope.h>
43#include <qholstersensor.h>
44#include <qlightsensor.h>
45#include <qmagnetometer.h>
46#include <qorientationsensor.h>
47#include <qpressuresensor.h>
48#include <qproximitysensor.h>
49#include <qrotationsensor.h>
50#include <qtapsensor.h>
51#include <qirproximitysensor.h>
52#include <qtiltsensor.h>
53
54#define PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)\
55 class SensorClass ## _impl : public QSensorBackend\
56 {\
57 public:\
58 SensorClass ## _impl(QSensor *sensor);\
59 void start() override;\
60 void stop() override;\
61 };\
62 class SensorClass ## _testfilter : public FilterClass { bool filter(ReadingClass *) override; };
63
64#define PREPARE_SENSORINTERFACE_IMPLS(SensorClass, ReadingClass, FilterClass, readingcode)\
65 SensorClass ## _impl::SensorClass ##_impl(QSensor *sensor) : QSensorBackend(sensor) {}\
66 void SensorClass ## _impl::start() {\
67 ReadingClass *reading = setReading<ReadingClass>(0);\
68 readingcode\
69 newReadingAvailable();\
70 }\
71 void SensorClass ##_impl::stop() {}\
72 bool SensorClass ## _testfilter::filter(ReadingClass *) { return true; }\
73 static QSensorBackend *create_ ## SensorClass ## _impl(QSensor *sensor) { return new SensorClass ## _impl(sensor); }\
74 static bool registered_ ## SensorClass = registerTestBackend(#SensorClass, create_ ## SensorClass ## _impl);
75
76#ifdef REGISTER_TOO
77#define PREPARE_SENSORINTERFACE(SensorClass, ReadingClass, FilterClass, readingcode)\
78 PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)\
79 PREPARE_SENSORINTERFACE_IMPLS(SensorClass, ReadingClass, FilterClass, readingcode)
80#else
81#define PREPARE_SENSORINTERFACE(SensorClass, ReadingClass, FilterClass, readingcode)\
82 PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)
83#endif
84
85PREPARE_SENSORINTERFACE(QAccelerometer, QAccelerometerReading, QAccelerometerFilter, {
86 reading->setX(1.0);
87 reading->setY(1.0);
88 reading->setZ(1.0);
89})
90PREPARE_SENSORINTERFACE(QAltimeter, QAltimeterReading, QAltimeterFilter, {
91 reading->setAltitude(8848);
92})
93PREPARE_SENSORINTERFACE(QAmbientLightSensor, QAmbientLightReading, QAmbientLightFilter, {
94 reading->setLightLevel(QAmbientLightReading::Twilight);
95})
96PREPARE_SENSORINTERFACE(QAmbientTemperatureSensor, QAmbientTemperatureReading, QAmbientTemperatureFilter, {
97 reading->setTemperature(30);
98})
99PREPARE_SENSORINTERFACE(QCompass, QCompassReading, QCompassFilter, {
100 reading->setAzimuth(1.0);
101 reading->setCalibrationLevel(1.0);
102})
103PREPARE_SENSORINTERFACE(QGyroscope, QGyroscopeReading, QGyroscopeFilter, {
104 reading->setX(1.0);
105 reading->setY(1.0);
106 reading->setZ(1.0);
107})
108PREPARE_SENSORINTERFACE(QHolsterSensor, QHolsterReading, QHolsterFilter, {
109 reading->setHolstered(true);
110})
111PREPARE_SENSORINTERFACE(QLightSensor, QLightReading, QLightFilter, {
112 reading->setLux(1.0);
113})
114PREPARE_SENSORINTERFACE(QMagnetometer, QMagnetometerReading, QMagnetometerFilter, {
115 reading->setX(1.0);
116 reading->setY(1.0);
117 reading->setZ(1.0);
118 reading->setCalibrationLevel(1.0);
119})
120PREPARE_SENSORINTERFACE(QOrientationSensor, QOrientationReading, QOrientationFilter, {
121 reading->setOrientation(QOrientationReading::LeftUp);
122})
123PREPARE_SENSORINTERFACE(QPressureSensor, QPressureReading, QPressureFilter, {
124 reading->setPressure(1.0);
125 reading->setTemperature(1.0);
126})
127PREPARE_SENSORINTERFACE(QProximitySensor, QProximityReading, QProximityFilter, {
128 reading->setClose(true);
129})
130PREPARE_SENSORINTERFACE(QRotationSensor, QRotationReading, QRotationFilter, {
131 reading->setFromEuler(1.0, 1.0, 1.0);
132})
133PREPARE_SENSORINTERFACE(QTapSensor, QTapReading, QTapFilter, {
134 reading->setTapDirection(QTapReading::Z_Both);
135 reading->setDoubleTap(true);
136})
137PREPARE_SENSORINTERFACE(QIRProximitySensor, QIRProximityReading, QIRProximityFilter, {
138 reading->setReflectance(0.5);
139})
140PREPARE_SENSORINTERFACE(QTiltSensor, QTiltReading, QTiltFilter, {
141 reading->setYRotation(1.0);
142 reading->setXRotation(1.0);
143})
144
145#define TEST_SENSORINTERFACE(SensorClass, ReadingClass, readingcode)\
146 do {\
147 SensorClass sensor;\
148 SensorClass ## _testfilter filter;\
149 sensor.addFilter(&filter);\
150 sensor.start();\
151 ReadingClass *reading = sensor.reading();\
152 readingcode\
153 } while (0);
154
155#endif
156

source code of qtsensors/tests/auto/qsensor/test_backends.h