summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Ottens <kevin.ottens@kdab.com>2016-08-22 17:26:50 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-08-24 19:33:19 +0000
commit4aa0fffe553007cc0b8ec8aa0454d7824f1ca3cd (patch)
treee3e9175ecba72b3272cd4fe53136cf9e2c6c155e
parent61d1ef40a84e2adfc1ade836158eb67dee9d5ceb (diff)
Tests for ActionInput, InputChord & InputSequence
Change-Id: I7e560a35f989890c2555808d0a86e0fa05b0e60b Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/auto/input/actioninput/actioninput.pro12
-rw-r--r--tests/auto/input/actioninput/tst_actioninput.cpp126
-rw-r--r--tests/auto/input/input.pro3
-rw-r--r--tests/auto/input/inputchord/inputchord.pro11
-rw-r--r--tests/auto/input/inputchord/tst_inputchord.cpp143
-rw-r--r--tests/auto/input/inputsequence/inputsequence.pro11
-rw-r--r--tests/auto/input/inputsequence/tst_inputsequence.cpp157
7 files changed, 463 insertions, 0 deletions
diff --git a/tests/auto/input/actioninput/actioninput.pro b/tests/auto/input/actioninput/actioninput.pro
new file mode 100644
index 000000000..169154323
--- /dev/null
+++ b/tests/auto/input/actioninput/actioninput.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+
+TARGET = tst_actioninput
+
+QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_actioninput.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)
diff --git a/tests/auto/input/actioninput/tst_actioninput.cpp b/tests/auto/input/actioninput/tst_actioninput.cpp
new file mode 100644
index 000000000..6c9f60908
--- /dev/null
+++ b/tests/auto/input/actioninput/tst_actioninput.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <qbackendnodetester.h>
+#include "testdevice.h"
+
+#include <Qt3DCore/QPropertyUpdatedChange>
+#include <Qt3DInput/private/actioninput_p.h>
+#include <Qt3DInput/QActionInput>
+
+class tst_ActionInput : public Qt3DCore::QBackendNodeTester
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void shouldMirrorPeerProperties()
+ {
+ // GIVEN
+ Qt3DInput::Input::ActionInput backendActionInput;
+ Qt3DInput::QActionInput actionInput;
+ TestDevice sourceDevice;
+
+ actionInput.setButtons(QVector<int>() << (1 << 8));
+ actionInput.setSourceDevice(&sourceDevice);
+
+ // WHEN
+ simulateInitialization(&actionInput, &backendActionInput);
+
+ // THEN
+ QCOMPARE(backendActionInput.peerId(), actionInput.id());
+ QCOMPARE(backendActionInput.isEnabled(), actionInput.isEnabled());
+ QCOMPARE(backendActionInput.buttons(), actionInput.buttons());
+ QCOMPARE(backendActionInput.sourceDevice(), sourceDevice.id());
+ }
+
+ void shouldHaveInitialAndCleanedUpStates()
+ {
+ // GIVEN
+ Qt3DInput::Input::ActionInput backendActionInput;
+
+ // THEN
+ QVERIFY(backendActionInput.peerId().isNull());
+ QVERIFY(backendActionInput.buttons().isEmpty());
+ QCOMPARE(backendActionInput.isEnabled(), false);
+ QCOMPARE(backendActionInput.sourceDevice(), Qt3DCore::QNodeId());
+
+ // GIVEN
+ Qt3DInput::QActionInput actionInput;
+ TestDevice sourceDevice;
+
+ actionInput.setButtons(QVector<int>() << (1 << 8));
+ actionInput.setSourceDevice(&sourceDevice);
+
+ // WHEN
+ simulateInitialization(&actionInput, &backendActionInput);
+ backendActionInput.cleanup();
+
+ // THEN
+ QVERIFY(backendActionInput.buttons().isEmpty());
+ QCOMPARE(backendActionInput.isEnabled(), false);
+ QCOMPARE(backendActionInput.sourceDevice(), Qt3DCore::QNodeId());
+ }
+
+ void shouldHandlePropertyChanges()
+ {
+ // GIVEN
+ Qt3DInput::Input::ActionInput backendActionInput;
+
+ // WHEN
+ Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setValue(QVariant::fromValue(QVector<int>() << 64));
+ updateChange->setPropertyName("buttons");
+ backendActionInput.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendActionInput.buttons(), QVector<int>() << 64);
+
+ // WHEN
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("enabled");
+ updateChange->setValue(true);
+ backendActionInput.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendActionInput.isEnabled(), true);
+
+ // WHEN
+ TestDevice device;
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("sourceDevice");
+ updateChange->setValue(QVariant::fromValue(device.id()));
+ backendActionInput.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendActionInput.sourceDevice(), device.id());
+ }
+};
+
+QTEST_APPLESS_MAIN(tst_ActionInput)
+
+#include "tst_actioninput.moc"
diff --git a/tests/auto/input/input.pro b/tests/auto/input/input.pro
index 58d2f6aa7..37af1fab9 100644
--- a/tests/auto/input/input.pro
+++ b/tests/auto/input/input.pro
@@ -13,7 +13,10 @@ contains(QT_CONFIG, private_tests) {
axis \
action \
abstractaxisinput \
+ actioninput \
analogaxisinput \
buttonaxisinput \
+ inputsequence \
+ inputchord \
keyboardhandler
}
diff --git a/tests/auto/input/inputchord/inputchord.pro b/tests/auto/input/inputchord/inputchord.pro
new file mode 100644
index 000000000..323b7fa80
--- /dev/null
+++ b/tests/auto/input/inputchord/inputchord.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+TARGET = tst_inputchord
+
+QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_inputchord.cpp
+
+include(../../core/common/common.pri)
diff --git a/tests/auto/input/inputchord/tst_inputchord.cpp b/tests/auto/input/inputchord/tst_inputchord.cpp
new file mode 100644
index 000000000..35316e6fb
--- /dev/null
+++ b/tests/auto/input/inputchord/tst_inputchord.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <qbackendnodetester.h>
+
+#include <Qt3DCore/QPropertyUpdatedChange>
+#include <Qt3DCore/QPropertyNodeAddedChange>
+#include <Qt3DCore/QPropertyNodeRemovedChange>
+#include <Qt3DInput/private/inputchord_p.h>
+#include <Qt3DInput/QActionInput>
+#include <Qt3DInput/QInputChord>
+
+class tst_InputChord : public Qt3DCore::QBackendNodeTester
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void shouldMirrorPeerProperties()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputChord backendInputChord;
+ Qt3DInput::QInputChord inputChord;
+ Qt3DInput::QActionInput actionInput;
+
+ inputChord.setTimeout(250);
+ inputChord.addChord(&actionInput);
+
+ // WHEN
+ simulateInitialization(&inputChord, &backendInputChord);
+
+ // THEN
+ QCOMPARE(backendInputChord.peerId(), inputChord.id());
+ QCOMPARE(backendInputChord.isEnabled(), inputChord.isEnabled());
+ QCOMPARE(backendInputChord.timeout(), inputChord.timeout());
+ QCOMPARE(backendInputChord.chords().size(), inputChord.chords().size());
+
+ const int inputsCount = backendInputChord.chords().size();
+ if (inputsCount > 0) {
+ for (int i = 0; i < inputsCount; ++i)
+ QCOMPARE(backendInputChord.chords().at(i), inputChord.chords().at(i)->id());
+ }
+ }
+
+ void shouldHaveInitialAndCleanedUpStates()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputChord backendInputChord;
+
+ // THEN
+ QVERIFY(backendInputChord.peerId().isNull());
+ QCOMPARE(backendInputChord.isEnabled(), false);
+ QCOMPARE(backendInputChord.timeout(), 0);
+ QCOMPARE(backendInputChord.chords().size(), 0);
+
+ // GIVEN
+ Qt3DInput::QInputChord inputChord;
+ Qt3DInput::QActionInput actionInput;
+
+ inputChord.setTimeout(250);
+ inputChord.addChord(&actionInput);
+
+ // WHEN
+ simulateInitialization(&inputChord, &backendInputChord);
+ backendInputChord.cleanup();
+
+ // THEN
+ QCOMPARE(backendInputChord.isEnabled(), false);
+ QCOMPARE(backendInputChord.timeout(), 0);
+ QCOMPARE(backendInputChord.chords().size(), 0);
+ }
+
+ void shouldHandlePropertyChanges()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputChord backendInputChord;
+
+ // WHEN
+ Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setValue(250);
+ updateChange->setPropertyName("timeout");
+ backendInputChord.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendInputChord.timeout(), 250);
+
+ // WHEN
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("enabled");
+ updateChange->setValue(true);
+ backendInputChord.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendInputChord.isEnabled(), true);
+
+ // WHEN
+ Qt3DInput::QActionInput input;
+ const Qt3DCore::QNodeId inputId = input.id();
+ const auto nodeAddedChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &input);
+ nodeAddedChange->setPropertyName("chord");
+ backendInputChord.sceneChangeEvent(nodeAddedChange);
+
+ // THEN
+ QCOMPARE(backendInputChord.chords().size(), 1);
+ QCOMPARE(backendInputChord.chords().first(), inputId);
+
+ // WHEN
+ const auto nodeRemovedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &input);
+ nodeRemovedChange->setPropertyName("chord");
+ backendInputChord.sceneChangeEvent(nodeRemovedChange);
+
+ // THEN
+ QCOMPARE(backendInputChord.chords().size(), 0);
+ }
+};
+
+QTEST_APPLESS_MAIN(tst_InputChord)
+
+#include "tst_inputchord.moc"
diff --git a/tests/auto/input/inputsequence/inputsequence.pro b/tests/auto/input/inputsequence/inputsequence.pro
new file mode 100644
index 000000000..e547dfe2e
--- /dev/null
+++ b/tests/auto/input/inputsequence/inputsequence.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+TARGET = tst_inputsequence
+
+QT += core-private 3dcore 3dcore-private 3dinput 3dinput-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_inputsequence.cpp
+
+include(../../core/common/common.pri)
diff --git a/tests/auto/input/inputsequence/tst_inputsequence.cpp b/tests/auto/input/inputsequence/tst_inputsequence.cpp
new file mode 100644
index 000000000..d32f25ae9
--- /dev/null
+++ b/tests/auto/input/inputsequence/tst_inputsequence.cpp
@@ -0,0 +1,157 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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 https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <qbackendnodetester.h>
+
+#include <Qt3DCore/QPropertyUpdatedChange>
+#include <Qt3DCore/QPropertyNodeAddedChange>
+#include <Qt3DCore/QPropertyNodeRemovedChange>
+#include <Qt3DInput/private/inputsequence_p.h>
+#include <Qt3DInput/QActionInput>
+#include <Qt3DInput/QInputSequence>
+
+class tst_InputSequence : public Qt3DCore::QBackendNodeTester
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void shouldMirrorPeerProperties()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputSequence backendInputSequence;
+ Qt3DInput::QInputSequence inputSequence;
+ Qt3DInput::QActionInput actionInput;
+
+ inputSequence.setTimeout(250);
+ inputSequence.setButtonInterval(100);
+ inputSequence.addSequence(&actionInput);
+
+ // WHEN
+ simulateInitialization(&inputSequence, &backendInputSequence);
+
+ // THEN
+ QCOMPARE(backendInputSequence.peerId(), inputSequence.id());
+ QCOMPARE(backendInputSequence.isEnabled(), inputSequence.isEnabled());
+ QCOMPARE(backendInputSequence.timeout(), inputSequence.timeout());
+ QCOMPARE(backendInputSequence.buttonInterval(), inputSequence.buttonInterval());
+ QCOMPARE(backendInputSequence.sequences().size(), inputSequence.sequences().size());
+
+ const int inputsCount = backendInputSequence.sequences().size();
+ if (inputsCount > 0) {
+ for (int i = 0; i < inputsCount; ++i)
+ QCOMPARE(backendInputSequence.sequences().at(i), inputSequence.sequences().at(i)->id());
+ }
+ }
+
+ void shouldHaveInitialAndCleanedUpStates()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputSequence backendInputSequence;
+
+ // THEN
+ QVERIFY(backendInputSequence.peerId().isNull());
+ QCOMPARE(backendInputSequence.isEnabled(), false);
+ QCOMPARE(backendInputSequence.timeout(), 0);
+ QCOMPARE(backendInputSequence.buttonInterval(), 0);
+ QCOMPARE(backendInputSequence.sequences().size(), 0);
+
+ // GIVEN
+ Qt3DInput::QInputSequence inputSequence;
+ Qt3DInput::QActionInput actionInput;
+
+ inputSequence.setTimeout(250);
+ inputSequence.setButtonInterval(100);
+ inputSequence.addSequence(&actionInput);
+
+ // WHEN
+ simulateInitialization(&inputSequence, &backendInputSequence);
+ backendInputSequence.cleanup();
+
+ // THEN
+ QCOMPARE(backendInputSequence.isEnabled(), false);
+ QCOMPARE(backendInputSequence.timeout(), 0);
+ QCOMPARE(backendInputSequence.buttonInterval(), 0);
+ QCOMPARE(backendInputSequence.sequences().size(), 0);
+ }
+
+ void shouldHandlePropertyChanges()
+ {
+ // GIVEN
+ Qt3DInput::Input::InputSequence backendInputSequence;
+
+ // WHEN
+ Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setValue(250);
+ updateChange->setPropertyName("timeout");
+ backendInputSequence.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendInputSequence.timeout(), 250);
+
+ // WHEN
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setValue(150);
+ updateChange->setPropertyName("buttonInterval");
+ backendInputSequence.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendInputSequence.buttonInterval(), 150);
+
+ // WHEN
+ updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
+ updateChange->setPropertyName("enabled");
+ updateChange->setValue(true);
+ backendInputSequence.sceneChangeEvent(updateChange);
+
+ // THEN
+ QCOMPARE(backendInputSequence.isEnabled(), true);
+
+ // WHEN
+ Qt3DInput::QActionInput input;
+ const Qt3DCore::QNodeId inputId = input.id();
+ const auto nodeAddedChange = Qt3DCore::QPropertyNodeAddedChangePtr::create(Qt3DCore::QNodeId(), &input);
+ nodeAddedChange->setPropertyName("sequence");
+ backendInputSequence.sceneChangeEvent(nodeAddedChange);
+
+ // THEN
+ QCOMPARE(backendInputSequence.sequences().size(), 1);
+ QCOMPARE(backendInputSequence.sequences().first(), inputId);
+
+ // WHEN
+ const auto nodeRemovedChange = Qt3DCore::QPropertyNodeRemovedChangePtr::create(Qt3DCore::QNodeId(), &input);
+ nodeRemovedChange->setPropertyName("sequence");
+ backendInputSequence.sceneChangeEvent(nodeRemovedChange);
+
+ // THEN
+ QCOMPARE(backendInputSequence.sequences().size(), 0);
+ }
+};
+
+QTEST_APPLESS_MAIN(tst_InputSequence)
+
+#include "tst_inputsequence.moc"