From be4e63b220108a959f1d016403aa95389060630e Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Fri, 17 Aug 2012 12:02:20 +1000 Subject: Rename QtMobility.sensors 1.3 to QtSensors 5.0 Change-Id: I2b24533d38db1f8e205de19b67fe0b21625bbf6b Reviewed-by: Lorn Potter --- tests/auto/legacy_sensors/tst_legacy_sensors.cpp | 157 ++++++----------- tests/auto/legacy_sensors_qml/tst_qsensor.qml | 204 +++++++++++++++++++++++ tests/auto/qsensor/tst_qsensor.cpp | 8 +- tests/auto/qtsensors5/tst_qtsensors5.cpp | 6 +- 4 files changed, 258 insertions(+), 117 deletions(-) create mode 100644 tests/auto/legacy_sensors_qml/tst_qsensor.qml (limited to 'tests') diff --git a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp index cf9913c8..0e4e9e58 100644 --- a/tests/auto/legacy_sensors/tst_legacy_sensors.cpp +++ b/tests/auto/legacy_sensors/tst_legacy_sensors.cpp @@ -70,10 +70,7 @@ private slots: QTest::addColumn("version"); QTest::addColumn("exists"); - QTest::newRow("1.0") << "1.0" << false; - QTest::newRow("1.1") << "1.1" << true; - QTest::newRow("1.2") << "1.2" << true; - QTest::newRow("1.3") << "1.3" << true; + QTest::newRow("5.0") << "5.0" << true; } void versions() @@ -82,7 +79,7 @@ private slots: QFETCH(bool, exists); QQmlEngine engine; - QString qml = QString("import QtQuick 2.0\nimport QtMobility.sensors %1\nItem {}").arg(version); + QString qml = QString("import QtQuick 2.0\nimport QtSensors %1\nItem {}").arg(version); QQmlComponent c(&engine); c.setData(qml.toLocal8Bit(), QUrl::fromLocalFile(QDir::currentPath())); if (!exists) @@ -95,7 +92,7 @@ private slots: QCOMPARE(errors.count(), 0); } else { QCOMPARE(errors.count(), 1); - QString expected = QString("module \"QtMobility.sensors\" version %1 is not installed").arg(version); + QString expected = QString("module \"QtSensors\" version %1 is not installed").arg(version); QString actual = errors.first().description(); QCOMPARE(expected, actual); } @@ -107,76 +104,36 @@ private slots: QTest::addColumn("element"); QTest::addColumn("exists"); - QTest::newRow("1.1 SensorReading") << "1.1" << "SensorReading" << false; - QTest::newRow("1.1 Accelerometer") << "1.1" << "Accelerometer" << true; - QTest::newRow("1.1 AccelerometerReading") << "1.1" << "AccelerometerReading" << true; - QTest::newRow("1.1 AmbientLightSensor") << "1.1" << "AmbientLightSensor" << true; - QTest::newRow("1.1 AmbientLightReading") << "1.1" << "AmbientLightReading" << true; - QTest::newRow("1.1 Compass") << "1.1" << "Compass" << true; - QTest::newRow("1.1 CompassReading") << "1.1" << "CompassReading" << true; - QTest::newRow("1.1 Magnetometer") << "1.1" << "Magnetometer" << true; - QTest::newRow("1.1 MagnetometerReading") << "1.1" << "MagnetometerReading" << true; - QTest::newRow("1.1 OrientationSensor") << "1.1" << "OrientationSensor" << true; - QTest::newRow("1.1 OrientationReading") << "1.1" << "OrientationReading" << true; - QTest::newRow("1.1 ProximitySensor") << "1.1" << "ProximitySensor" << true; - QTest::newRow("1.1 ProximityReading") << "1.1" << "ProximityReading" << true; - QTest::newRow("1.1 RotationSensor") << "1.1" << "RotationSensor" << true; - QTest::newRow("1.1 RotationReading") << "1.1" << "RotationReading" << true; - QTest::newRow("1.1 TapSensor") << "1.1" << "TapSensor" << true; - QTest::newRow("1.1 TapReading") << "1.1" << "TapReading" << true; + QTest::newRow("5.0 Range") << "5.0" << "Range" << false; + QTest::newRow("5.0 OutputRange") << "5.0" << "OutputRange" << false; + QTest::newRow("5.0 Sensor") << "5.0" << "Sensor" << false; + QTest::newRow("5.0 SensorReading") << "5.0" << "SensorReading" << false; + QTest::newRow("5.0 Accelerometer") << "5.0" << "Accelerometer" << true; + QTest::newRow("5.0 AccelerometerReading") << "5.0" << "AccelerometerReading" << false; + QTest::newRow("5.0 AmbientLightSensor") << "5.0" << "AmbientLightSensor" << true; + QTest::newRow("5.0 AmbientLightReading") << "5.0" << "AmbientLightReading" << false; + QTest::newRow("5.0 Compass") << "5.0" << "Compass" << true; + QTest::newRow("5.0 CompassReading") << "5.0" << "CompassReading" << false; + QTest::newRow("5.0 Magnetometer") << "5.0" << "Magnetometer" << true; + QTest::newRow("5.0 MagnetometerReading") << "5.0" << "MagnetometerReading" << false; + QTest::newRow("5.0 OrientationSensor") << "5.0" << "OrientationSensor" << true; + QTest::newRow("5.0 OrientationReading") << "5.0" << "OrientationReading" << false; + QTest::newRow("5.0 ProximitySensor") << "5.0" << "ProximitySensor" << true; + QTest::newRow("5.0 ProximityReading") << "5.0" << "ProximityReading" << false; + QTest::newRow("5.0 RotationSensor") << "5.0" << "RotationSensor" << true; + QTest::newRow("5.0 RotationReading") << "5.0" << "RotationReading" << false; + QTest::newRow("5.0 TapSensor") << "5.0" << "TapSensor" << true; + QTest::newRow("5.0 TapReading") << "5.0" << "TapReading" << false; + QTest::newRow("5.0 LightSensor") << "5.0" << "LightSensor" << true; + QTest::newRow("5.0 LightReading") << "5.0" << "LightReading" << false; + QTest::newRow("5.0 Gyroscope") << "5.0" << "Gyroscope" << true; + QTest::newRow("5.0 GyroscopeReading") << "5.0" << "GyroscopeReading" << false; + QTest::newRow("5.0 IRProximitySensor") << "5.0" << "IRProximitySensor" << true; + QTest::newRow("5.0 IRProximityReading") << "5.0" << "IRProximityReading" << false; + QTest::newRow("5.0 TiltSensor") << "5.0" << "TiltSensor" << true; + QTest::newRow("5.0 TiltReading") << "5.0" << "TiltReading" << false; - QTest::newRow("1.2 SensorReading") << "1.2" << "SensorReading" << false; - QTest::newRow("1.2 Accelerometer") << "1.2" << "Accelerometer" << true; - QTest::newRow("1.2 AccelerometerReading") << "1.2" << "AccelerometerReading" << false; - QTest::newRow("1.2 AmbientLightSensor") << "1.2" << "AmbientLightSensor" << true; - QTest::newRow("1.2 AmbientLightReading") << "1.2" << "AmbientLightReading" << false; - QTest::newRow("1.2 Compass") << "1.2" << "Compass" << true; - QTest::newRow("1.2 CompassReading") << "1.2" << "CompassReading" << false; - QTest::newRow("1.2 Magnetometer") << "1.2" << "Magnetometer" << true; - QTest::newRow("1.2 MagnetometerReading") << "1.2" << "MagnetometerReading" << false; - QTest::newRow("1.2 OrientationSensor") << "1.2" << "OrientationSensor" << true; - QTest::newRow("1.2 OrientationReading") << "1.2" << "OrientationReading" << false; - QTest::newRow("1.2 ProximitySensor") << "1.2" << "ProximitySensor" << true; - QTest::newRow("1.2 ProximityReading") << "1.2" << "ProximityReading" << false; - QTest::newRow("1.2 RotationSensor") << "1.2" << "RotationSensor" << true; - QTest::newRow("1.2 RotationReading") << "1.2" << "RotationReading" << false; - QTest::newRow("1.2 TapSensor") << "1.2" << "TapSensor" << true; - QTest::newRow("1.2 TapReading") << "1.2" << "TapReading" << false; - QTest::newRow("1.2 LightSensor") << "1.2" << "LightSensor" << true; - QTest::newRow("1.2 LightReading") << "1.2" << "LightReading" << false; - 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; - QTest::newRow("1.3 AccelerometerReading") << "1.3" << "AccelerometerReading" << false; - QTest::newRow("1.3 AmbientLightSensor") << "1.3" << "AmbientLightSensor" << true; - QTest::newRow("1.3 AmbientLightReading") << "1.3" << "AmbientLightReading" << false; - QTest::newRow("1.3 Compass") << "1.3" << "Compass" << true; - QTest::newRow("1.3 CompassReading") << "1.3" << "CompassReading" << false; - QTest::newRow("1.3 Magnetometer") << "1.3" << "Magnetometer" << true; - QTest::newRow("1.3 MagnetometerReading") << "1.3" << "MagnetometerReading" << false; - QTest::newRow("1.3 OrientationSensor") << "1.3" << "OrientationSensor" << true; - QTest::newRow("1.3 OrientationReading") << "1.3" << "OrientationReading" << false; - QTest::newRow("1.3 ProximitySensor") << "1.3" << "ProximitySensor" << true; - QTest::newRow("1.3 ProximityReading") << "1.3" << "ProximityReading" << false; - QTest::newRow("1.3 RotationSensor") << "1.3" << "RotationSensor" << true; - QTest::newRow("1.3 RotationReading") << "1.3" << "RotationReading" << false; - QTest::newRow("1.3 TapSensor") << "1.3" << "TapSensor" << true; - QTest::newRow("1.3 TapReading") << "1.3" << "TapReading" << false; - QTest::newRow("1.3 LightSensor") << "1.3" << "LightSensor" << true; - QTest::newRow("1.3 LightReading") << "1.3" << "LightReading" << false; - QTest::newRow("1.3 Gyroscope") << "1.3" << "Gyroscope" << true; - 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; - - QTest::newRow("1.3 SensorGesture") << "1.3" << "SensorGesture" << true; + QTest::newRow("5.0 SensorGesture") << "5.0" << "SensorGesture" << true; } void elements() @@ -186,7 +143,7 @@ private slots: QFETCH(bool, exists); QQmlEngine engine; - QString qml = QString("import QtQuick 2.0\nimport QtMobility.sensors %1\n%2 {}").arg(version).arg(element); + QString qml = QString("import QtQuick 2.0\nimport QtSensors %1\n%2 {}").arg(version).arg(element); QQmlComponent c(&engine); c.setData(qml.toLocal8Bit(), QUrl::fromLocalFile(QDir::currentPath())); if (!exists) @@ -211,38 +168,18 @@ private slots: QTest::addColumn("element"); QTest::addColumn("validSyntax"); - QTest::newRow("1.1 Accelerometer") << "1.1" << "Accelerometer" << false; - QTest::newRow("1.1 AmbientLightSensor") << "1.1" << "AmbientLightSensor" << false; - QTest::newRow("1.1 Compass") << "1.1" << "Compass" << false; - QTest::newRow("1.1 Magnetometer") << "1.1" << "Magnetometer" << false; - QTest::newRow("1.1 OrientationSensor") << "1.1" << "OrientationSensor" << false; - QTest::newRow("1.1 ProximitySensor") << "1.1" << "ProximitySensor" << false; - QTest::newRow("1.1 RotationSensor") << "1.1" << "RotationSensor" << false; - QTest::newRow("1.1 TapSensor") << "1.1" << "TapSensor" << false; - - QTest::newRow("1.2 Accelerometer") << "1.2" << "Accelerometer" << false; - QTest::newRow("1.2 AmbientLightSensor") << "1.2" << "AmbientLightSensor" << false; - QTest::newRow("1.2 Compass") << "1.2" << "Compass" << false; - QTest::newRow("1.2 Magnetometer") << "1.2" << "Magnetometer" << false; - QTest::newRow("1.2 OrientationSensor") << "1.2" << "OrientationSensor" << false; - QTest::newRow("1.2 ProximitySensor") << "1.2" << "ProximitySensor" << false; - QTest::newRow("1.2 RotationSensor") << "1.2" << "RotationSensor" << false; - QTest::newRow("1.2 TapSensor") << "1.2" << "TapSensor" << false; - QTest::newRow("1.2 LightSensor") << "1.2" << "LightSensor" << false; - QTest::newRow("1.2 Gyroscope") << "1.2" << "Gyroscope" << false; - - QTest::newRow("1.3 Accelerometer") << "1.3" << "Accelerometer" << true; - QTest::newRow("1.3 AmbientLightSensor") << "1.3" << "AmbientLightSensor" << true; - QTest::newRow("1.3 Compass") << "1.3" << "Compass" << true; - QTest::newRow("1.3 Magnetometer") << "1.3" << "Magnetometer" << true; - QTest::newRow("1.3 OrientationSensor") << "1.3" << "OrientationSensor" << true; - QTest::newRow("1.3 ProximitySensor") << "1.3" << "ProximitySensor" << true; - QTest::newRow("1.3 RotationSensor") << "1.3" << "RotationSensor" << true; - QTest::newRow("1.3 TapSensor") << "1.3" << "TapSensor" << true; - 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; + QTest::newRow("5.0 Accelerometer") << "5.0" << "Accelerometer" << true; + QTest::newRow("5.0 AmbientLightSensor") << "5.0" << "AmbientLightSensor" << true; + QTest::newRow("5.0 Compass") << "5.0" << "Compass" << true; + QTest::newRow("5.0 Magnetometer") << "5.0" << "Magnetometer" << true; + QTest::newRow("5.0 OrientationSensor") << "5.0" << "OrientationSensor" << true; + QTest::newRow("5.0 ProximitySensor") << "5.0" << "ProximitySensor" << true; + QTest::newRow("5.0 RotationSensor") << "5.0" << "RotationSensor" << true; + QTest::newRow("5.0 TapSensor") << "5.0" << "TapSensor" << true; + QTest::newRow("5.0 LightSensor") << "5.0" << "LightSensor" << true; + QTest::newRow("5.0 Gyroscope") << "5.0" << "Gyroscope" << true; + QTest::newRow("5.0 IRProximitySensor") << "5.0" << "IRProximitySensor" << true; + QTest::newRow("5.0 TiltSensor") << "5.0" << "TiltSensor" << true; } void alwaysOn() @@ -252,7 +189,7 @@ private slots: QFETCH(bool, validSyntax); QQmlEngine engine; - QString qml = QString("import QtQuick 2.0\nimport QtMobility.sensors %1\n%2 {\nalwaysOn: true\n}").arg(version).arg(element); + QString qml = QString("import QtQuick 2.0\nimport QtSensors %1\n%2 {\nalwaysOn: true\n}").arg(version).arg(element); QQmlComponent c(&engine); if (!validSyntax) QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); @@ -325,7 +262,7 @@ private slots: QFETCH(QVariant, expected); QQmlEngine engine; - QString qml = QString("import QtQuick 2.0\nimport QtMobility.sensors 1.3 as Sensors\n%1").arg(qmlcode); + QString qml = QString("import QtQuick 2.0\nimport QtSensors 5.0 as Sensors\n%1").arg(qmlcode); QQmlComponent c(&engine); c.setData(qml.toLocal8Bit(), QUrl::fromLocalFile(QDir::currentPath())); QObject *obj = c.create(); diff --git a/tests/auto/legacy_sensors_qml/tst_qsensor.qml b/tests/auto/legacy_sensors_qml/tst_qsensor.qml new file mode 100644 index 00000000..a7623217 --- /dev/null +++ b/tests/auto/legacy_sensors_qml/tst_qsensor.qml @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 +import QtSensors 5.0 as Sensors +import TestHelper 1.0 + +TestCase { + id: test + name: "tst_qsensor" + + TestHelper { + id: helper + } + + Component { + id: cTestSensor + TestSensor{} + } + + function initTestCase() {} + + function cleanupTestCase() {} + + function init() {} + + function cleanup() {} + + function sortlist(list) + { + var array = new Array(); + for (var ii in list) + array.push(list[ii]); + array.sort(); + return array; + } + + function test_001_TypeRegistered() + { + var expected = [ "test sensor", "test sensor 2" ]; + var actual = Sensors.sensorTypes(); + // FIXME .sort() is broken! + actual = sortlist(actual); // The actual list is not in a defined order + compare(actual, expected); + } + + function test_002_SensorRegistered() + { + var expected = [ "test sensor 2", "test sensor 3", "test sensor impl" ]; + var actual = Sensors.sensorsForType("test sensor"); + // FIXME .sort() is broken! + actual = sortlist(actual); // The actual list is not in a defined order + compare(actual, expected); + } + + function test_003_SensorDefault() + { + var expected = "test sensor impl"; + var actual = Sensors.defaultSensorForType("test sensor"); + compare(actual, expected); + } + + function test_004_NoSensorsForType() + { + var expected = []; + var actual = Sensors.sensorsForType("bogus type"); + compare(actual, expected); + } + + function test_005_NoDefaultForType() + { + var expected = ""; + var actual = Sensors.defaultSensorForType("bogus type"); + compare(actual, expected); + } + + function test_006_Creation() + { + var sensor = cTestSensor.createObject(); + compare(sensor.connectedToBackend, true); + var expected = "test sensor impl"; + var actual = sensor.sensorid; + compare(actual, expected); + sensor.destroy(); + } + + function test_008_Timestamp() + { + var sensor = cTestSensor.createObject(); + compare(sensor.connectedToBackend, true); + var timestamp = sensor.reading.timestamp; + compare(timestamp, 0); + sensor.doThis = "setOne"; + sensor.start(); + timestamp = sensor.reading.timestamp; + compare(timestamp, 1); + sensor.destroy(); + } + + function test_009_Start() + { + var sensor = cTestSensor.createObject(); + sensor.start(); + compare(sensor.active, true); + sensor.start(); + compare(sensor.active, true); + sensor.destroy(); + } + + function test_010_Stop() + { + var sensor = cTestSensor.createObject(); + sensor.stop(); + compare(sensor.active, false); + sensor.start(); + compare(sensor.active, true); + sensor.stop(); + compare(sensor.active, false); + sensor.destroy(); + } + + function test_011_Start2() + { + var sensor = cTestSensor.createObject(); + + sensor.doThis = "stop"; + sensor.start(); + compare(sensor.active, false); + sensor.stop(); + + sensor.doThis = "error"; + sensor.start(); + compare(sensor.error, 1); + // Yes, this is non-intuitive but the sensor + // decides if an error is fatal or not. + // In this case our test sensor is reporting a + // non-fatal error so the sensor will start. + compare(sensor.active, true); + sensor.stop(); + + sensor.doThis = "setOne"; + sensor.start(); + compare(sensor.reading.timestamp, 1); + sensor.stop(); + + sensor.doThis = "setTwo"; + sensor.start(); + compare(sensor.reading.timestamp, 2); + sensor.stop(); + sensor.destroy(); + } + + function test_012_SetBadDataRate() + { + var sensor = cTestSensor.createObject(); + + ignoreWarning("setDataRate: 1 is not supported by the sensor. "); + sensor.dataRate = 1; + compare(sensor.dataRate, 0); + + ignoreWarning("setDataRate: 1000 is not supported by the sensor. "); + sensor.dataRate = 1000; + compare(sensor.dataRate, 0); + sensor.destroy(); + } +} diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 5b4c40b8..a4591aa4 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -41,12 +41,12 @@ //TESTED_COMPONENT=src/sensors -#include +#include #include -#include -#include +#include +#include #include -#include +#include #include "qsensor.h" #include "test_sensor.h" diff --git a/tests/auto/qtsensors5/tst_qtsensors5.cpp b/tests/auto/qtsensors5/tst_qtsensors5.cpp index 719876fd..8d62f485 100644 --- a/tests/auto/qtsensors5/tst_qtsensors5.cpp +++ b/tests/auto/qtsensors5/tst_qtsensors5.cpp @@ -43,11 +43,11 @@ #include #include -class tst_qtsensors5 : public QObject +class tst_QtSensors : public QObject { Q_OBJECT public: - tst_qtsensors5(QObject *parent = 0) + tst_QtSensors(QObject *parent = 0) : QObject(parent) { } @@ -62,6 +62,6 @@ private slots: } }; -QTEST_MAIN(tst_qtsensors5) +QTEST_MAIN(tst_QtSensors) #include "tst_qtsensors5.moc" -- cgit v1.2.3