summaryrefslogtreecommitdiffstats
path: root/tests/auto/legacy_sensors
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-06-19 11:45:09 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-26 00:29:37 +0200
commitf9d52ca1c093d8997d44cd8356b43b2665fdbf20 (patch)
tree45fd29bd91c67794bf3e1aefbf232bbd1d2f7b8f /tests/auto/legacy_sensors
parent1d253860f9863fd015115d728c3f1bd04c5119c6 (diff)
QtMobility.sensors has a new implementation
This implementation fixes the limitations the original code had and separates the QtSensors C++ API from the QML API so that changes to one don't need to affect the other. Change-Id: I519463f3c7cfbad3bce5c291ce166b8793d5ed4a Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'tests/auto/legacy_sensors')
-rw-r--r--tests/auto/legacy_sensors/legacy_sensors.pro10
-rw-r--r--tests/auto/legacy_sensors/tst_legacy_sensors.cpp71
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/legacy_sensors/legacy_sensors.pro b/tests/auto/legacy_sensors/legacy_sensors.pro
index e96e45d0..b9c95d47 100644
--- a/tests/auto/legacy_sensors/legacy_sensors.pro
+++ b/tests/auto/legacy_sensors/legacy_sensors.pro
@@ -4,4 +4,14 @@ TARGET=tst_legacy_sensors
QT = core testlib gui qml sensors
SOURCES += tst_legacy_sensors.cpp
+VPATH += ../qsensor
+INCLUDEPATH += ../qsensor
+DEPENDPATH += ../qsensor
+
+HEADERS += \
+ test_backends.h
+
+SOURCES += \
+ test_backends.cpp
+
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
index a282b573..6745b9ce 100644
--- a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
+++ b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp
@@ -43,6 +43,7 @@
#include <QQmlEngine>
#include <QQmlComponent>
#include <QSensor>
+#include "test_backends.h"
class tst_legacy_sensors : public QObject
{
@@ -51,6 +52,8 @@ public:
tst_legacy_sensors(QObject *parent = 0)
: QObject(parent)
{
+ qputenv("QT_SENSORS_LOAD_PLUGINS", "0"); // Do not load plugins
+ register_test_backends();
}
private slots:
@@ -144,6 +147,8 @@ private slots:
QTest::newRow("1.2 Gyroscope") << "1.2" << "Gyroscope" << true;
QTest::newRow("1.2 GyroscopeReading") << "1.2" << "GyroscopeReading" << false;
+ QTest::newRow("1.3 Range") << "1.3" << "Range" << false;
+ QTest::newRow("1.3 OutputRange") << "1.3" << "OutputRange" << false;
QTest::newRow("1.3 Sensor") << "1.3" << "Sensor" << false;
QTest::newRow("1.3 SensorReading") << "1.3" << "SensorReading" << false;
QTest::newRow("1.3 Accelerometer") << "1.3" << "Accelerometer" << true;
@@ -259,6 +264,72 @@ private slots:
}
}
+ void namespace_api_data()
+ {
+ QTest::addColumn<QString>("qmlcode");
+ QTest::addColumn<QVariant>("expected");
+
+ QVariant expected;
+ QStringList sl;
+ foreach (const QByteArray &type, QSensor::sensorTypes()) {
+ sl << QString::fromLocal8Bit(type);
+ qDebug() << type;
+ }
+ expected = sl;
+ QTest::newRow("Sensors.sensorTypes()")
+ << "Item {\n"
+ "property var result\n"
+ "Component.onCompleted: {\n"
+ "result = Sensors.sensorTypes();\n"
+ "}\n"
+ "}"
+ << expected;
+
+ foreach (const QByteArray &type, QSensor::sensorTypes()) {
+ sl.clear();
+ foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) {
+ sl << QString::fromLocal8Bit(identifier);
+ }
+ expected = sl;
+ QTest::newRow(QString("Sensors.sensorsForType(\"%1\")").arg(QString::fromLocal8Bit(type)).toLocal8Bit().constData())
+ << QString(
+ "Item {\n"
+ "property var result\n"
+ "Component.onCompleted: {\n"
+ "result = Sensors.sensorsForType(\"%1\");\n"
+ "}\n"
+ "}").arg(QString::fromLocal8Bit(type))
+ << expected;
+
+ expected = QString::fromLocal8Bit(QSensor::defaultSensorForType(type));
+ QTest::newRow(QString("Sensors.defaultSensorForType(\"%1\")").arg(QString::fromLocal8Bit(type)).toLocal8Bit().constData())
+ << QString(
+ "Item {\n"
+ "property var result\n"
+ "Component.onCompleted: {\n"
+ "result = Sensors.defaultSensorForType(\"%1\");\n"
+ "}\n"
+ "}").arg(QString::fromLocal8Bit(type))
+ << expected;
+ }
+ }
+
+ void namespace_api()
+ {
+ QFETCH(QString, qmlcode);
+ QFETCH(QVariant, expected);
+
+ QQmlEngine engine;
+ QString qml = QString("import QtQuick 2.0\nimport QtMobility.sensors 1.3 as Sensors\n%1").arg(qmlcode);
+ QQmlComponent c(&engine);
+ c.setData(qml.toLocal8Bit(), QUrl::fromLocalFile(QDir::currentPath()));
+ QObject *obj = c.create();
+ QVERIFY(obj);
+ QVariant result = obj->property("result");
+ QCOMPARE(expected, result);
+ delete obj;
+ }
+
};
QTEST_MAIN(tst_legacy_sensors)