summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-03-02 14:13:39 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-03 09:22:38 +0200
commit4c61854d60fb5d2c68c6dcb1fb5bdf5c0dead3e2 (patch)
treeb41d70a37b8a1ff76c32025d8562a94581a3bd22 /tests
parentfb68fb8c052ae08fabed8f49256e79b0d0915fb0 (diff)
downloadqtsensors-4c61854d60fb5d2c68c6dcb1fb5bdf5c0dead3e2.tar.gz
Add TiltSensor to QtMobility.sensors 1.3
This has been adapted from the TiltSensor type in QtSensors 5.0 import but the code there has been split into multiple pieces. There's a C++ class, a generic backend and a QML interface. Change-Id: Ic09465a5f76250a02a13938abe4789958137376f Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/legacy_sensors/tst_legacy_sensors.cpp3
-rw-r--r--tests/auto/qsensor/test_backends.h5
-rw-r--r--tests/auto/qsensor/tst_qsensor.cpp5
-rw-r--r--tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp75
4 files changed, 13 insertions, 75 deletions
diff --git a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
index 6745b9c..ec2de81 100644
--- a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
+++ b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
@@ -173,6 +173,8 @@ private slots:
QTest::newRow("1.3 GyroscopeReading") << "1.3" << "GyroscopeReading" << false;
QTest::newRow("1.3 IRProximitySensor") << "1.3" << "IRProximitySensor" << true;
QTest::newRow("1.3 IRProximityReading") << "1.3" << "IRProximityReading" << false;
+ QTest::newRow("1.3 TiltSensor") << "1.3" << "TiltSensor" << true;
+ QTest::newRow("1.3 TiltReading") << "1.3" << "TiltReading" << false;
}
void elements()
@@ -238,6 +240,7 @@ private slots:
QTest::newRow("1.3 LightSensor") << "1.3" << "LightSensor" << true;
QTest::newRow("1.3 Gyroscope") << "1.3" << "Gyroscope" << true;
QTest::newRow("1.3 IRProximitySensor") << "1.3" << "IRProximitySensor" << true;
+ QTest::newRow("1.3 TiltSensor") << "1.3" << "TiltSensor" << true;
}
void alwaysOn()
diff --git a/tests/auto/qsensor/test_backends.h b/tests/auto/qsensor/test_backends.h
index 0d8e2ba..a36a858 100644
--- a/tests/auto/qsensor/test_backends.h
+++ b/tests/auto/qsensor/test_backends.h
@@ -58,6 +58,7 @@ void unregister_test_backends();
#include <qrotationsensor.h>
#include <qtapsensor.h>
#include <qirproximitysensor.h>
+#include <qtiltsensor.h>
#define PREPARE_SENSORINTERFACE_DECLS(SensorClass, ReadingClass, FilterClass, readingcode)\
class SensorClass ## _impl : public QSensorBackend\
@@ -132,6 +133,10 @@ PREPARE_SENSORINTERFACE(QTapSensor, QTapReading, QTapFilter, {
PREPARE_SENSORINTERFACE(QIRProximitySensor, QIRProximityReading, QIRProximityFilter, {
reading->setReflectance(0.5);
})
+PREPARE_SENSORINTERFACE(QTiltSensor, QTiltReading, QTiltFilter, {
+ reading->setYRotation(1.0);
+ reading->setXRotation(1.0);
+})
#define TEST_SENSORINTERFACE(SensorClass, ReadingClass, readingcode)\
do {\
diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp
index abb0a6d..5b4c40b 100644
--- a/tests/auto/qsensor/tst_qsensor.cpp
+++ b/tests/auto/qsensor/tst_qsensor.cpp
@@ -892,6 +892,11 @@ private slots:
QCOMPARE(reading->isDoubleTap(), true);
})
+ TEST_SENSORINTERFACE(QTiltSensor, QTiltReading, {
+ QCOMPARE(reading->yRotation(), 1.0);
+ QCOMPARE(reading->xRotation(), 1.0);
+ })
+
TEST_SENSORINTERFACE(QIRProximitySensor, QIRProximityReading, {
QCOMPARE(reading->reflectance(), 0.5);
})
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
index 8828d19..42ef629 100644
--- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
+++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
@@ -69,10 +69,8 @@ private slots:
void testTilt();
void testTilt_receivedSignalsCount();
void testTiltSettings();
- void testTiltAccuracy();
void testTiltCalibration();
void testTiltRunningMode();
- void testTiltUnit();
void testProximity();
void testAmbientLight();
void testGesture();
@@ -239,11 +237,6 @@ void tst_Sensors2QMLAPI::testTilt()
_tilt->setProperty("enabled", true);
QCOMPARE(spy.count() , 0);
- _tilt->setProperty("unit", QSensor2Tilt::Radians);
- QSignalSpy spyunitch(_tilt, SIGNAL(unitChanged()));
- _tilt->setProperty("unit", QSensor2Tilt::Degrees);
- QCOMPARE(spyunitch.count() , 1);
-
QByteArray settings;
settings.append(QString::number(-5.0));
settings.append(";");
@@ -310,44 +303,6 @@ void tst_Sensors2QMLAPI::testTiltSettings()
QCOMPARE(settings, val);
}
-void tst_Sensors2QMLAPI::testTiltAccuracy()
-{
- if (!_tilt)
- _tilt = new QSensor2Tilt(this);
-
- QByteArray settings;
- settings.append(QString::number(0.0));
- settings.append(";");
- settings.append(QString::number(0.0));
- _tilt->setProperty("settings", settings);
- _tilt->setProperty("enabled", true);
-
- QDeclAccelerometer* accel = _plugin.stAccel;
-
- //be sure we set rotation to 0
- _tilt->setProperty("accuracy", 0.0);
- QVERIFY(0.01 > _tilt->property("accuracy").toFloat());
-
- accel->test(0,0,1);
-
- //now set accuracy a little bigger then Pi / 4 in deg
- _tilt->setProperty("accuracy", 180 / 4.0 + 0.1);
- QSignalSpy spyxrot(_tilt, SIGNAL(xRotationChanged()));
- QSignalSpy spyyrot(_tilt, SIGNAL(yRotationChanged()));
-
- accel->test(1, 1, 0);
- QCOMPARE(spyxrot.count() , 0);
- QCOMPARE(spyyrot.count() , 0);
-
- spyxrot.clear();
- spyyrot.clear();
- _tilt->setProperty("accuracy", 180 / 4.0 + 0.1 - 0.1);
- accel->test(1, 1, 0);
- QCOMPARE(spyxrot.count() , 1);
- QCOMPARE(spyyrot.count() , 1);
-
-}
-
void tst_Sensors2QMLAPI::testTilt_receivedSignalsCount()
{
QCOMPARE(xrotch , 23);
@@ -365,12 +320,10 @@ void tst_Sensors2QMLAPI::testTiltCalibration()
settings.append(QString::number(0.0));
_tilt->setProperty("settings", settings);
_tilt->setProperty("enabled", true);
- _tilt->setProperty("unit", QSensor2Tilt::Degrees);
QDeclAccelerometer* accel = _plugin.stAccel;
//be sure we set rotation to 0
- _tilt->setProperty("accuracy", 0.0);
accel->test(-3.59904, 5.52114, 7.07059);
_tilt->calibrate();
accel->test(-3.59904, 5.52114, 7.07059);
@@ -393,34 +346,6 @@ void tst_Sensors2QMLAPI::testTiltCalibration()
_tilt->setProperty("enabled", false);
}
-void tst_Sensors2QMLAPI::testTiltUnit()
-{
- if (!_tilt)
- _tilt = new QSensor2Tilt(this);
- QDeclAccelerometer* accel = _plugin.stAccel;
- _tilt->setProperty("enabled", false);
- _tilt->setProperty("accuracy", 0.0);
- _tilt->setProperty("unit", QVariant(QSensor2Tilt::Radians));
- accel->test(-3.59904, 5.52114, 7.07059);
- qreal xRotation = _tilt->property("xRotation").toReal();
- qreal yRotation = _tilt->property("yRotation").toReal();
- xRotation += 0.159136;
- yRotation -= 0.43440;
- QVERIFY(xRotation < 0.0001);
- QVERIFY(yRotation < 0.0001);
- QCOMPARE(_tilt->property("unit").toInt(), (int)QSensor2Tilt::Radians);
-
- _tilt->setProperty("unit", QVariant(QSensor2Tilt::Degrees));
- accel->test(-3.59904, 5.52114, 7.07059);
- xRotation = _tilt->property("xRotation").toReal();
- yRotation = _tilt->property("yRotation").toReal();
- xRotation += 9.11778;
- yRotation -= 24.8898;
- QVERIFY(xRotation < 0.0001);
- QVERIFY(yRotation < 0.0001);
- QCOMPARE(_tilt->property("unit").toInt(), (int)QSensor2Tilt::Degrees);
-}
-
void tst_Sensors2QMLAPI::testTiltRunningMode()
{
if (!_tilt)