diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-12-01 15:44:25 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-12-01 15:19:46 +0000 |
commit | 8f1c2ad638af066efe29ff170b835ce8de6a19f2 (patch) | |
tree | 811a732405e78e07964a4010a878d61a100613d2 /tests | |
parent | f2a46dab85ef2fb4d8289bb2552e15bf6a04d765 (diff) |
Unit tests for AxisInput
Change-Id: Ib639eec6cfaa3839f43e09e9dd3ad31f0524e700
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/input/axisinput/axisinput.pro | 11 | ||||
-rw-r--r-- | tests/auto/input/axisinput/tst_axisinput.cpp | 166 | ||||
-rw-r--r-- | tests/auto/input/commons/commons.pri | 3 | ||||
-rw-r--r-- | tests/auto/input/commons/testdevice.h | 70 | ||||
-rw-r--r-- | tests/auto/input/input.pro | 3 | ||||
-rw-r--r-- | tests/auto/input/qactioninput/qactioninput.pro | 1 | ||||
-rw-r--r-- | tests/auto/input/qactioninput/tst_qactioninput.cpp | 33 | ||||
-rw-r--r-- | tests/auto/input/qaxisinput/qaxisinput.pro | 1 | ||||
-rw-r--r-- | tests/auto/input/qaxisinput/tst_qaxisinput.cpp | 49 |
9 files changed, 272 insertions, 65 deletions
diff --git a/tests/auto/input/axisinput/axisinput.pro b/tests/auto/input/axisinput/axisinput.pro new file mode 100644 index 000000000..8378c1608 --- /dev/null +++ b/tests/auto/input/axisinput/axisinput.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +TARGET = tst_axisinput + +QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib + +CONFIG += testcase + +SOURCES += tst_axisinput.cpp + +include(../commons/commons.pri) diff --git a/tests/auto/input/axisinput/tst_axisinput.cpp b/tests/auto/input/axisinput/tst_axisinput.cpp new file mode 100644 index 000000000..f63c3d445 --- /dev/null +++ b/tests/auto/input/axisinput/tst_axisinput.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QTest> +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DCore/private/qscene_p.h> +#include <Qt3DCore/qscenepropertychange.h> +#include <Qt3DInput/private/axisinput_p.h> +#include <Qt3DInput/QAxisInput> +#include <Qt3DCore/qscenepropertychange.h> +#include "testdevice.h" + +class tst_AxisInput: public QObject +{ + Q_OBJECT + +private Q_SLOTS: + + void checkPeerPropertyMirroring() + { + // GIVEN + Qt3DInput::Input::AxisInput backendAxisInput; + Qt3DInput::QAxisInput axisInput; + TestDevice sourceDevice; + + axisInput.setKeys((1 << 8)); + axisInput.setAxis(327); + axisInput.setScale(0.5f); + axisInput.setSourceDevice(&sourceDevice); + + // WHEN + backendAxisInput.setPeer(&axisInput); + + // THEN + QCOMPARE(backendAxisInput.peerUuid(), axisInput.id()); + QCOMPARE(backendAxisInput.isEnabled(), axisInput.isEnabled()); + QCOMPARE(backendAxisInput.keys(), axisInput.keys()); + QCOMPARE(backendAxisInput.axis(), axisInput.axis()); + QCOMPARE(backendAxisInput.scale(), axisInput.scale()); + QCOMPARE(backendAxisInput.sourceDevice(), sourceDevice.id()); + } + + void checkInitialAndCleanedUpState() + { + // GIVEN + Qt3DInput::Input::AxisInput backendAxisInput; + + // THEN + QVERIFY(backendAxisInput.peerUuid().isNull()); + QCOMPARE(backendAxisInput.scale(), 0.0f); + QCOMPARE(backendAxisInput.keys(), 0); + QCOMPARE(backendAxisInput.axis(), 0); + QCOMPARE(backendAxisInput.isEnabled(), false); + QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId()); + + // GIVEN + Qt3DInput::QAxisInput axisInput; + TestDevice sourceDevice; + + axisInput.setKeys((1 << 8)); + axisInput.setAxis(327); + axisInput.setScale(0.5f); + axisInput.setSourceDevice(&sourceDevice); + + // WHEN + backendAxisInput.updateFromPeer(&axisInput); + backendAxisInput.cleanup(); + + // THEN + QVERIFY(backendAxisInput.peerUuid().isNull()); + QCOMPARE(backendAxisInput.scale(), 0.0f); + QCOMPARE(backendAxisInput.keys(), 0); + QCOMPARE(backendAxisInput.axis(), 0); + QCOMPARE(backendAxisInput.isEnabled(), false); + QCOMPARE(backendAxisInput.sourceDevice(), Qt3DCore::QNodeId()); + } + + void checkPropertyChanges() + { + // GIVEN + Qt3DInput::Input::AxisInput backendAxisInput; + + // WHEN + Qt3DCore::QScenePropertyChangePtr updateChange(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); + updateChange->setValue(32); + updateChange->setPropertyName("axis"); + backendAxisInput.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendAxisInput.axis(), 32); + + // WHEN + updateChange.reset(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); + updateChange->setValue(64); + updateChange->setPropertyName("keys"); + backendAxisInput.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendAxisInput.keys(), 64); + + // WHEN + updateChange.reset(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); + updateChange->setValue(0.5f); + updateChange->setPropertyName("scale"); + backendAxisInput.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendAxisInput.scale(), 0.5f); + + // WHEN + updateChange.reset(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); + updateChange->setPropertyName("enabled"); + updateChange->setValue(true); + backendAxisInput.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendAxisInput.isEnabled(), true); + + // WHEN + TestDevice device; + updateChange.reset(new Qt3DCore::QScenePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); + updateChange->setPropertyName("sourceDevice"); + updateChange->setValue(QVariant::fromValue(device.id())); + backendAxisInput.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backendAxisInput.sourceDevice(), device.id()); + } +}; + +QTEST_APPLESS_MAIN(tst_AxisInput) + +#include "tst_axisinput.moc" diff --git a/tests/auto/input/commons/commons.pri b/tests/auto/input/commons/commons.pri new file mode 100644 index 000000000..cc65e8a41 --- /dev/null +++ b/tests/auto/input/commons/commons.pri @@ -0,0 +1,3 @@ +HEADERS += $$PWD/testdevice.h + +INCLUDEPATH += $$PWD diff --git a/tests/auto/input/commons/testdevice.h b/tests/auto/input/commons/testdevice.h new file mode 100644 index 000000000..988e9708d --- /dev/null +++ b/tests/auto/input/commons/testdevice.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later 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 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DInput/QAbstractPhysicalDevice> + +class TestDevice : public Qt3DInput::QAbstractPhysicalDevice +{ + Q_OBJECT +public: + explicit TestDevice(Qt3DCore::QNode *parent = Q_NULLPTR) + : Qt3DInput::QAbstractPhysicalDevice(parent) + {} + + ~TestDevice() + { + QNode::cleanup(); + } + + int axisCount() const Q_DECL_FINAL { return 0; } + int buttonCount() const Q_DECL_FINAL { return 0; } + QStringList axisNames() const Q_DECL_FINAL { return QStringList(); } + QStringList buttonNames() const Q_DECL_FINAL { return QStringList(); } + int axisIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } + int buttonIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } + float axis(int axisIdentifier) const Q_DECL_FINAL { Q_UNUSED(axisIdentifier) return 0.0f; } + bool button(int buttonIdentifier) const Q_DECL_FINAL { Q_UNUSED(buttonIdentifier) return false; } + +protected: + void copy(const Qt3DCore::QNode *ref) Q_DECL_FINAL + { + QAbstractPhysicalDevice::copy(ref); + } + +private: + QT3D_CLONEABLE(TestDevice) +}; diff --git a/tests/auto/input/input.pro b/tests/auto/input/input.pro index 7fafd48c6..7c53d98c7 100644 --- a/tests/auto/input/input.pro +++ b/tests/auto/input/input.pro @@ -8,5 +8,6 @@ contains(QT_CONFIG, private_tests) { qactioninput \ qlogicaldevice \ axis \ - action + action \ + axisinput } diff --git a/tests/auto/input/qactioninput/qactioninput.pro b/tests/auto/input/qactioninput/qactioninput.pro index a110e85f7..bf8865690 100644 --- a/tests/auto/input/qactioninput/qactioninput.pro +++ b/tests/auto/input/qactioninput/qactioninput.pro @@ -9,3 +9,4 @@ CONFIG += testcase SOURCES += tst_qactioninput.cpp include(../../render/commons/commons.pri) +include(../commons/commons.pri) diff --git a/tests/auto/input/qactioninput/tst_qactioninput.cpp b/tests/auto/input/qactioninput/tst_qactioninput.cpp index 3f0f353f0..3b8022860 100644 --- a/tests/auto/input/qactioninput/tst_qactioninput.cpp +++ b/tests/auto/input/qactioninput/tst_qactioninput.cpp @@ -42,38 +42,7 @@ #include <Qt3DInput/QAbstractPhysicalDevice> #include "testpostmanarbiter.h" - -class TestDevice : public Qt3DInput::QAbstractPhysicalDevice -{ - Q_OBJECT -public: - explicit TestDevice(Qt3DCore::QNode *parent = Q_NULLPTR) - : Qt3DInput::QAbstractPhysicalDevice(parent) - {} - - ~TestDevice() - { - QNode::cleanup(); - } - - int axisCount() const Q_DECL_FINAL { return 0; } - int buttonCount() const Q_DECL_FINAL { return 0; } - QStringList axisNames() const Q_DECL_FINAL { return QStringList(); } - QStringList buttonNames() const Q_DECL_FINAL { return QStringList(); } - int axisIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } - int buttonIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } - float axis(int axisIdentifier) const Q_DECL_FINAL { Q_UNUSED(axisIdentifier) return 0.0f; } - bool button(int buttonIdentifier) const Q_DECL_FINAL { Q_UNUSED(buttonIdentifier) return false; } - -protected: - void copy(const Qt3DCore::QNode *ref) Q_DECL_FINAL - { - QAbstractPhysicalDevice::copy(ref); - } - -private: - QT3D_CLONEABLE(TestDevice) -}; +#include "testdevice.h" // We need to call QNode::clone which is protected // So we sublcass QNode instead of QObject diff --git a/tests/auto/input/qaxisinput/qaxisinput.pro b/tests/auto/input/qaxisinput/qaxisinput.pro index 11681e3b3..ed2598c24 100644 --- a/tests/auto/input/qaxisinput/qaxisinput.pro +++ b/tests/auto/input/qaxisinput/qaxisinput.pro @@ -9,3 +9,4 @@ CONFIG += testcase SOURCES += tst_qaxisinput.cpp include(../../render/commons/commons.pri) +include(../commons/commons.pri) diff --git a/tests/auto/input/qaxisinput/tst_qaxisinput.cpp b/tests/auto/input/qaxisinput/tst_qaxisinput.cpp index f3cae6b60..ec65824e9 100644 --- a/tests/auto/input/qaxisinput/tst_qaxisinput.cpp +++ b/tests/auto/input/qaxisinput/tst_qaxisinput.cpp @@ -42,38 +42,7 @@ #include <Qt3DInput/QAbstractPhysicalDevice> #include "testpostmanarbiter.h" - -class TestDevice : public Qt3DInput::QAbstractPhysicalDevice -{ - Q_OBJECT -public: - explicit TestDevice(Qt3DCore::QNode *parent = Q_NULLPTR) - : Qt3DInput::QAbstractPhysicalDevice(parent) - {} - - ~TestDevice() - { - QNode::cleanup(); - } - - int axisCount() const Q_DECL_FINAL { return 0; } - int buttonCount() const Q_DECL_FINAL { return 0; } - QStringList axisNames() const Q_DECL_FINAL { return QStringList(); } - QStringList buttonNames() const Q_DECL_FINAL { return QStringList(); } - int axisIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } - int buttonIdentifier(const QString &name) Q_DECL_FINAL { Q_UNUSED(name) return 0; } - float axis(int axisIdentifier) const Q_DECL_FINAL { Q_UNUSED(axisIdentifier) return 0.0f; } - bool button(int buttonIdentifier) const Q_DECL_FINAL { Q_UNUSED(buttonIdentifier) return false; } - -protected: - void copy(const Qt3DCore::QNode *ref) Q_DECL_FINAL - { - QAbstractPhysicalDevice::copy(ref); - } - -private: - QT3D_CLONEABLE(TestDevice) -}; +#include "testdevice.h" // We need to call QNode::clone which is protected // So we sublcass QNode instead of QObject @@ -102,6 +71,7 @@ private Q_SLOTS: Qt3DInput::QAxisInput *axisInputWithKeysAndAxis = new Qt3DInput::QAxisInput(); axisInputWithKeysAndAxis->setKeys((1 << 1) | (1 << 5)); axisInputWithKeysAndAxis->setAxis(383); + axisInputWithKeysAndAxis->setScale(327.0f); QTest::newRow("axisInputWithKeys") << axisInputWithKeysAndAxis; Qt3DInput::QAxisInput *axisInputWithKeysAndSourceDevice = new Qt3DInput::QAxisInput(); @@ -109,6 +79,7 @@ private Q_SLOTS: axisInputWithKeysAndSourceDevice->setKeys((1 << 1) | (1 << 5)); axisInputWithKeysAndSourceDevice->setSourceDevice(device); axisInputWithKeysAndSourceDevice->setAxis(427); + axisInputWithKeysAndAxis->setScale(355.0f); QTest::newRow("axisInputWithKeysAndSourceDevice") << axisInputWithKeysAndSourceDevice; } @@ -126,6 +97,7 @@ private Q_SLOTS: QCOMPARE(axisInput->id(), clone->id()); QCOMPARE(axisInput->keys(), clone->keys()); QCOMPARE(axisInput->axis(), clone->axis()); + QCOMPARE(axisInput->scale(), clone->scale()); if (axisInput->sourceDevice() != Q_NULLPTR) { QVERIFY(clone->sourceDevice() != Q_NULLPTR); @@ -153,6 +125,19 @@ private Q_SLOTS: arbiter.events.clear(); // WHEN + axisInput->setScale(1340.0f); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast<Qt3DCore::QScenePropertyChange>(); + QCOMPARE(change->propertyName(), "scale"); + QCOMPARE(change->value().toFloat(), 1340.0f); + QCOMPARE(change->type(), Qt3DCore::NodeUpdated); + + arbiter.events.clear(); + + // WHEN axisInput->setAxis(350); QCoreApplication::processEvents(); |