summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorWolfgang Beck <wolfgang.beck@nokia.com>2011-09-02 13:29:38 +1000
committerLincoln Ramsay <lincoln.ramsay@nokia.com>2011-10-10 09:25:25 +1000
commit6b2c7688b3f344f350125f8b9713a6a77b82c3dd (patch)
tree2eb622b436f6462b344f1b4d7fbbd39859aefa3a /tests/auto
parent3496318f01b63b4127c72999d634530313d60b57 (diff)
MTMW-98 QML API Version 2
Change-Id: I10c610ae22974d291fad663088c5a11449a86b05 Reviewed-on: http://codereview.qt-project.org/4107 Reviewed-by: Wolfgang Beck <wolfgang.beck@nokia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/sensors2qmlapi/qbackends.h105
-rw-r--r--tests/auto/sensors2qmlapi/qdeclaccelerometer.h80
-rw-r--r--tests/auto/sensors2qmlapi/qdeclambientlightsensor.h79
-rw-r--r--tests/auto/sensors2qmlapi/qdeclproximitysensor.h78
-rw-r--r--tests/auto/sensors2qmlapi/sensors2qmlapi.pro20
-rw-r--r--tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp270
7 files changed, 633 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index b303c70b..ce22928f 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,4 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += qsensor
-
+SUBDIRS += sensors2qmlapi
diff --git a/tests/auto/sensors2qmlapi/qbackends.h b/tests/auto/sensors2qmlapi/qbackends.h
new file mode 100644
index 00000000..01bfa36a
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/qbackends.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef BACKENDS_H
+#define BACKENDS_H
+
+#include "qdeclaccelerometer.h"
+#include "qdeclambientlightsensor.h"
+#include "qdeclproximitysensor.h"
+#include <qsensorplugin.h>
+#include <QtCore/QDebug>
+
+
+class TestSensorPlugin : public QObject,
+ public QSensorPluginInterface,
+ public QSensorChangesInterface,
+ public QSensorBackendFactory
+{
+ Q_OBJECT
+ Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+public:
+ void registerSensors()
+ {
+ QSensorManager::registerBackend("QAccelerometer", "QAccelerometer", this);
+ QSensorManager::registerBackend("QAmbientLightSensor", "QAmbientLightSensor", this);
+ QSensorManager::registerBackend("QProximitySensor", "QProximitySensor", this);
+ }
+
+ void sensorsChanged()
+ {
+ }
+
+ QSensorBackend *createBackend(QSensor *sensor)
+ {
+ if (sensor->identifier() == "QAccelerometer") {
+ if (TestSensorPlugin::stAccel != 0)
+ return TestSensorPlugin::stAccel;
+ else
+ TestSensorPlugin::stAccel = new QDeclAccelerometer(sensor);
+ return createBackend(sensor);
+ }
+ else if (sensor->identifier() == "QAmbientLightSensor") {
+ if (TestSensorPlugin::stAbl != 0)
+ return TestSensorPlugin::stAbl;
+ else
+ TestSensorPlugin::stAbl = new QDeclAmbientLightSensor(sensor);
+ return createBackend(sensor);
+ }
+ else if (sensor->identifier() == "QProximitySensor") {
+ if (TestSensorPlugin::stProxi != 0)
+ return TestSensorPlugin::stProxi;
+ else
+ TestSensorPlugin::stProxi = new QDeclProximitySensor(sensor);
+ return createBackend(sensor);
+ }
+
+ qWarning() << "Can't create backend" << sensor->identifier();
+ return 0;
+ }
+public:
+ static QDeclAccelerometer* stAccel;
+ static QDeclAmbientLightSensor* stAbl;
+ static QDeclProximitySensor* stProxi;
+};
+
+#endif
+
diff --git a/tests/auto/sensors2qmlapi/qdeclaccelerometer.h b/tests/auto/sensors2qmlapi/qdeclaccelerometer.h
new file mode 100644
index 00000000..5842e01f
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/qdeclaccelerometer.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLACCELEROMETER_H
+#define QDECLACCELEROMETER_H
+
+#include <qsensorbackend.h>
+#include "qaccelerometer.h"
+
+class QDeclAccelerometer : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ explicit QDeclAccelerometer(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , _active(false)
+ , _sensor(sensor)
+ {
+ }
+ virtual ~QDeclAccelerometer() {}
+
+ void start() { _active = true; }
+ void stop() { _active = false; }
+ bool isActive() { return _active; }
+
+ void test(int x, int y, int z)
+ {
+ if (sensor()->filters().count() > 0){
+ QAccelerometerFilter* af = (QAccelerometerFilter*)sensor()->filters().at(0);
+ reader.setX((qreal)x);
+ reader.setY((qreal)y);
+ reader.setZ((qreal)z);
+ af->filter(&reader);
+ }
+ }
+private:
+ bool _active;
+ QSensor* _sensor;
+ QAccelerometerReading reader;
+};
+#endif
+
diff --git a/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h b/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h
new file mode 100644
index 00000000..603ff1fb
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/qdeclambientlightsensor.h
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLAMBIENTLIGHTSENSOR_H
+#define QDECLAMBIENTLIGHTSENSOR_H
+
+#include <qsensorbackend.h>
+#include "./../../../src/imports/sensors2/qsensor2ambientlight.h"
+
+class QDeclAmbientLightSensor : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ explicit QDeclAmbientLightSensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , _active(false)
+ , _sensor(sensor)
+ {
+ }
+ virtual ~QDeclAmbientLightSensor() {}
+
+ void start() { _active = true; }
+ void stop() { _active = false; }
+ bool isActive() { return _active; }
+
+ void test(QSensor2AmbientLight::LightLevel lv)
+ {
+ if (sensor()->filters().count() > 0){
+ QAmbientLightFilter* af = (QAmbientLightFilter*)sensor()->filters().at(0);
+ reader.setLightLevel((QAmbientLightReading::LightLevel)lv);
+ af->filter(&reader);
+ }
+ }
+private:
+ bool _active;
+ QSensor* _sensor;
+ QAmbientLightReading reader;
+};
+
+#endif
+
diff --git a/tests/auto/sensors2qmlapi/qdeclproximitysensor.h b/tests/auto/sensors2qmlapi/qdeclproximitysensor.h
new file mode 100644
index 00000000..987a177d
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/qdeclproximitysensor.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QDECLPROXIMITYSENSOR_H
+#define QDECLPROXIMITYSENSOR_H
+
+#include <qsensorbackend.h>
+#include "qproximitysensor.h"
+
+class QDeclProximitySensor : public QSensorBackend
+{
+ Q_OBJECT
+public:
+ explicit QDeclProximitySensor(QSensor *sensor)
+ : QSensorBackend(sensor)
+ , _active(false)
+ , _sensor(sensor)
+ {
+ }
+ virtual ~QDeclProximitySensor() {}
+
+ void start() { _active = true; }
+ void stop() { _active = false; }
+ bool isActive() { return _active; }
+
+ void test(bool val)
+ {
+ if (sensor()->filters().count() > 0){
+ QProximityFilter* af = (QProximityFilter*)sensor()->filters().at(0);
+ reader.setClose(val);
+ af->filter(&reader);
+ }
+ }
+private:
+ bool _active;
+ QSensor* _sensor;
+ QProximityReading reader;
+};
+#endif
+
diff --git a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro
new file mode 100644
index 00000000..acd8951b
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro
@@ -0,0 +1,20 @@
+TEMPLATE = app
+TARGET = tst_sensors2qmlapi
+
+CONFIG += testcase
+QT = core testlib sensors-private declarative
+INCLUDEPATH += ./
+DEPENDPATH += ./
+
+SOURCES += tst_sensors2qmlapi.cpp \
+ ./../../../src/imports/sensors2/qsensor2ambientlight.cpp \
+ ./../../../src/imports/sensors2/qsensor2proximity.cpp \
+ ./../../../src/imports/sensors2/qsensor2tilt.cpp
+
+HEADERS += qdeclaccelerometer.h \
+ qdeclambientlightsensor.h \
+ qdeclproximitysensor.h \
+ qbackends.h \
+ ./../../../src/imports/sensors2/qsensor2ambientlight.h \
+ ./../../../src/imports/sensors2/qsensor2proximity.h \
+ ./../../../src/imports/sensors2/qsensor2tilt.h
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
new file mode 100644
index 00000000..a80b7263
--- /dev/null
+++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
@@ -0,0 +1,270 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtSensors middleware.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtTest/QSignalSpy>
+#include <QtCore/QDebug>
+#include "../../../src/imports/sensors2/qsensor2ambientlight.h"
+#include "../../../src/imports/sensors2/qsensor2proximity.h"
+#include "../../../src/imports/sensors2/qsensor2tilt.h"
+#include "qbackends.h"
+#include "qsensormanager.h"
+
+QT_USE_NAMESPACE
+QDeclAccelerometer* TestSensorPlugin::stAccel = 0;
+QDeclAmbientLightSensor* TestSensorPlugin::stAbl = 0;
+QDeclProximitySensor* TestSensorPlugin::stProxi = 0;
+
+Q_SENSORS_EXPORT void sensors_unit_test_hook(int index);
+
+class tst_Sensors2QMLAPI : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void testTilt_data();
+ void testTilt();
+ void testTilt_receivedSignalsCount();
+ void testProximity();
+ void testAmbientLight();
+
+protected:
+ TestSensorPlugin _plugin;
+ QSensor2Tilt* _tilt;
+};
+
+void tst_Sensors2QMLAPI::initTestCase()
+{
+ sensors_unit_test_hook(0); // change some flags the library uses
+ _plugin.registerSensors();
+ _tilt = 0;
+}
+
+void tst_Sensors2QMLAPI::testProximity()
+{
+ QSensor2Proximity prox;
+ QSignalSpy spy(&prox, SIGNAL(runningChanged()));
+ prox.setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 1);
+
+ spy.clear();
+ prox.setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 0);
+
+ TestSensorPlugin plugin;
+ QDeclProximitySensor* proxi = plugin.stProxi;
+
+ qDebug() << "Check close = true";
+ proxi->test(true);
+ QVERIFY((bool)prox.property("close").toBool() == true);
+
+ qDebug() << "Check close = false";
+ QSignalSpy spy1(&prox, SIGNAL(closeChanged()));
+ proxi->test(false);
+ QCOMPARE(spy1.count() , 1);
+ QVERIFY((bool)prox.property("close").toBool() == false);
+
+ spy1.clear();
+ proxi->test(false);
+ QCOMPARE(spy1.count() , 0);
+ prox.setProperty("running", QVariant(false));
+}
+
+void tst_Sensors2QMLAPI::testAmbientLight()
+{
+ QSensor2AmbientLight als;
+ QSignalSpy spy(&als, SIGNAL(runningChanged()));
+ als.setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 1);
+
+ spy.clear();
+ als.setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 0);
+
+ TestSensorPlugin plugin;
+ QDeclAmbientLightSensor* abl = plugin.stAbl;
+
+ for (int en = 5; en >= 0; en--){
+ QString enumname = "";
+ switch (en)
+ {
+ case 0: enumname = "Undefined"; break;
+ case 1: enumname = "Dark"; break;
+ case 2: enumname = "Twilight"; break;
+ case 3: enumname = "Light"; break;
+ case 4: enumname = "Bright"; break;
+ case 5: enumname = "Sunny"; break;
+ }
+ qDebug() << "Check " << enumname;
+ QSignalSpy spy1(&als, SIGNAL(lightLevelChanged()));
+ abl->test((QSensor2AmbientLight::LightLevel)en);
+ QCOMPARE(spy1.count() , 1);
+ QVERIFY((int)als.property("lightLevel").toInt() == en);
+
+ spy1.clear();
+ abl->test((QSensor2AmbientLight::LightLevel)en);
+ QCOMPARE(spy1.count() , 0);
+ }
+ als.setProperty("running", QVariant(false));
+}
+
+void tst_Sensors2QMLAPI::testTilt_data()
+{
+ QTest::addColumn<int>("pos");
+ QTest::addColumn<int>("x");
+ QTest::addColumn<int>("y");
+ QTest::addColumn<int>("z");
+ QTest::addColumn<int>("xRotation");
+ QTest::addColumn<int>("yRotation");
+
+ QTest::newRow("TopUp001") << (int)QSensor2Tilt::TopUp << 0 << 0 << 1 << -90 << 0;
+ QTest::newRow("TopDown001") << (int)QSensor2Tilt::TopDown << 0 << 0 << 1 << -90 << 0;
+ QTest::newRow("LeftUp001") << (int)QSensor2Tilt::LeftUp << 0 << 0 << 1 << -90 << 0;
+ QTest::newRow("RightUp001") << (int)QSensor2Tilt::RightUp << 0 << 0 << 1 << -90 << 0;
+ QTest::newRow("FaceUp001") << (int)QSensor2Tilt::FaceUp << 0 << 0 << 1 << 0 << 0;
+ QTest::newRow("FaceDown001") << (int)QSensor2Tilt::FaceDown << 0 << 0 << 1 << 0 << 0;
+
+ QTest::newRow("TopUp010") << (int)QSensor2Tilt::TopUp << 0 << 1 << 0 << 0 << 0;
+ QTest::newRow("TopDown010") << (int)QSensor2Tilt::TopDown << 0 << 1 << 0 << 0 << 0;
+ QTest::newRow("LeftUp010") << (int)QSensor2Tilt::LeftUp << 0 << 1 << 0 << 0 << -90;
+ QTest::newRow("RightUp010") << (int)QSensor2Tilt::RightUp << 0 << 1 << 0 << 0 << 90;
+ QTest::newRow("FaceUp010") << (int)QSensor2Tilt::FaceUp << 0 << 1 << 0 << 90 << 0;
+ QTest::newRow("FaceDown010") << (int)QSensor2Tilt::FaceDown << 0 << 1 << 0 << 90 << 0;
+
+ QTest::newRow("TopUp100") << (int)QSensor2Tilt::TopUp << 1 << 0 << 0 << 0 << -90;
+ QTest::newRow("TopDown100") << (int)QSensor2Tilt::TopDown << 1 << 0 << 0 << 0 << 90;
+ QTest::newRow("LeftUp100") << (int)QSensor2Tilt::LeftUp << 1 << 0 << 0 << 0 << 0;
+ QTest::newRow("RightUp100") << (int)QSensor2Tilt::RightUp << 1 << 0 << 0 << 0 << 0;
+ QTest::newRow("FaceUp100") << (int)QSensor2Tilt::FaceUp << 1 << 0 << 0 << 0 << -90;
+ QTest::newRow("FaceDown100") << (int)QSensor2Tilt::FaceDown << 1 << 0 << 0 << 0 << 90;
+
+ QTest::newRow("TopUp101") << (int)QSensor2Tilt::TopUp << 1 << 0 << 1 << -45 << -45;
+ QTest::newRow("TopDown101") << (int)QSensor2Tilt::TopDown << 1 << 0 << 1 << -45 << 45;
+ QTest::newRow("LeftUp101") << (int)QSensor2Tilt::LeftUp << 1 << 0 << 1 << -45 << 0;
+ QTest::newRow("RightUp101") << (int)QSensor2Tilt::RightUp << 1 << 0 << 1 << -45 << 0;
+ QTest::newRow("FaceUp101") << (int)QSensor2Tilt::FaceUp << 1 << 0 << 1 << 0 << -45;
+ QTest::newRow("FaceDown101") << (int)QSensor2Tilt::FaceDown << 1 << 0 << 1 << 0 << 45;
+
+ QTest::newRow("TopUp110") << (int)QSensor2Tilt::TopUp << 1 << 1 << 0 << 0 << -45;
+ QTest::newRow("TopDown110") << (int)QSensor2Tilt::TopDown << 1 << 1 << 0 << 0 << 45;
+ QTest::newRow("LeftUp110") << (int)QSensor2Tilt::LeftUp << 1 << 1 << 0 << 0 << -45;
+ QTest::newRow("RightUp110") << (int)QSensor2Tilt::RightUp << 1 << 1 << 0 << 0 << 45;
+ QTest::newRow("FaceUp110") << (int)QSensor2Tilt::FaceUp << 1 << 1 << 0 << 45 << -45;
+ QTest::newRow("FaceDown110") << (int)QSensor2Tilt::FaceDown << 1 << 1 << 0 << 45 << 45;
+
+ QTest::newRow("TopUp011") << (int)QSensor2Tilt::TopUp << 0 << 1 << 1 << -45 << 0;
+ QTest::newRow("TopDown011") << (int)QSensor2Tilt::TopDown << 0 << 1 << 1 << -45 << 0;
+ QTest::newRow("LeftUp011") << (int)QSensor2Tilt::LeftUp << 0 << 1 << 1 << -45 << -45;
+ QTest::newRow("RightUp011") << (int)QSensor2Tilt::RightUp << 0 << 1 << 1 << -45 << 45;
+ QTest::newRow("FaceUp011") << (int)QSensor2Tilt::FaceUp << 0 << 1 << 1 << 45 << 0;
+ QTest::newRow("FaceDown011") << (int)QSensor2Tilt::FaceDown << 0 << 1 << 1 << 45 << 0;
+}
+
+int xrotch = 0;
+int yrotch = 0;
+int datarate = 10;
+void tst_Sensors2QMLAPI::testTilt()
+{
+ QFETCH(int, pos);
+ QFETCH(int, x);
+ QFETCH(int, y);
+ QFETCH(int, z);
+ QFETCH(int, xRotation);
+ QFETCH(int, yRotation);
+
+ qDebug() << "check pos: " << pos << " x: " << x << " y: " << y << " z: " << z << " xRot: " << xRotation << " yRot: " << yRotation;
+
+ if (!_tilt)
+ _tilt = new QSensor2Tilt(this);
+
+ QSignalSpy spy(_tilt, SIGNAL(runningChanged()));
+ _tilt->setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 1);
+
+ spy.clear();
+ _tilt->setProperty("running", QVariant(true));
+ QCOMPARE(spy.count() , 0);
+
+ _tilt->setProperty("radian", QVariant(false));
+
+ QSignalSpy spymf(_tilt, SIGNAL(measureFromChanged()));
+ _tilt->setProperty("measureFrom", QVariant(pos));
+ QVERIFY((int)_tilt->property("measureFrom").toInt() == pos);
+ QCOMPARE(spymf.count() , 1);
+ spymf.clear();
+ _tilt->setProperty("measureFrom", QVariant(pos));
+ QCOMPARE(spymf.count() , 0);
+
+ QDeclAccelerometer* accel = _plugin.stAccel;
+
+ QSignalSpy spyxrot(_tilt, SIGNAL(xRotationChanged()));
+ QSignalSpy spyyrot(_tilt, SIGNAL(yRotationChanged()));
+ accel->test(x,y,z);
+ xrotch += spyxrot.count();
+ yrotch += spyyrot.count();
+
+ QCOMPARE(xRotation, (int)_tilt->property("xRotation").toFloat());
+ QCOMPARE(yRotation, (int)_tilt->property("yRotation").toFloat());
+
+ spy.clear();
+ _tilt->setProperty("running", QVariant(false));
+ QCOMPARE(spy.count() , 1);
+ spy.clear();
+ _tilt->setProperty("running", QVariant(false));
+ QCOMPARE(spy.count() , 0);
+
+ datarate++;
+ QSignalSpy spydr(_tilt, SIGNAL(dataRateChanged()));
+ _tilt->setProperty("dataRate", QVariant(datarate));
+ QCOMPARE(spydr.count() , 1);
+}
+
+void tst_Sensors2QMLAPI::testTilt_receivedSignalsCount()
+{
+ qDebug() << "Check xRotation changed: " << xrotch;
+ QCOMPARE(xrotch , 9);
+ qDebug() << "Check yRotation changed: " << yrotch;
+ QCOMPARE(yrotch , 23);
+}
+
+QTEST_MAIN(tst_Sensors2QMLAPI)
+#include "tst_sensors2qmlapi.moc"