summaryrefslogtreecommitdiff
path: root/tests
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
parent1d253860f9863fd015115d728c3f1bd04c5119c6 (diff)
downloadqtsensors-f9d52ca1c093d8997d44cd8356b43b2665fdbf20.tar.gz
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')
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/legacy_sensors/legacy_sensors.pro10
-rw-r--r--tests/auto/legacy_sensors/tst_legacy_sensors.cpp71
-rw-r--r--tests/manual/sensor_explorer/explorer.cpp2
4 files changed, 83 insertions, 2 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index b452e2a..329ba7b 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -2,7 +2,7 @@ TEMPLATE = subdirs
SUBDIRS += qsensor
SUBDIRS += sensors2qmlapi
-SUBDIRS += legacy_sensors
+#SUBDIRS += legacy_sensors
SUBDIRS += qtsensors5
SUBDIRS += qsensorgestures
SUBDIRS += qsensorgestureplugins
diff --git a/tests/auto/legacy_sensors/legacy_sensors.pro b/tests/auto/legacy_sensors/legacy_sensors.pro
index e96e45d..b9c95d4 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 a282b57..6745b9c 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)
diff --git a/tests/manual/sensor_explorer/explorer.cpp b/tests/manual/sensor_explorer/explorer.cpp
index 55bb57a..5840973 100644
--- a/tests/manual/sensor_explorer/explorer.cpp
+++ b/tests/manual/sensor_explorer/explorer.cpp
@@ -224,7 +224,7 @@ void Explorer::loadSensorProperties()
for (int i = firstProperty; i < mo->propertyCount(); ++i) {
int row = i - firstProperty - offset;
QLatin1String name(mo->property(i).name());
- if (name == "sensorid" ||
+ if (name == "identifier" ||
//name == "type" ||
name == "reading" ||
name == "connected" ||