From f9d52ca1c093d8997d44cd8356b43b2665fdbf20 Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Tue, 19 Jun 2012 11:45:09 +1000 Subject: 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 --- tests/auto/legacy_sensors/legacy_sensors.pro | 10 ++++ tests/auto/legacy_sensors/tst_legacy_sensors.cpp | 71 ++++++++++++++++++++++++ 2 files changed, 81 insertions(+) (limited to 'tests/auto/legacy_sensors') 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 #include #include +#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("qmlcode"); + QTest::addColumn("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) -- cgit v1.2.3