1/****************************************************************************
2**
3** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QTest>
30#include <Qt3DCore/private/qnode_p.h>
31#include <Qt3DCore/private/qscene_p.h>
32#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
33
34#include <Qt3DInput/QAnalogAxisInput>
35#include <Qt3DInput/QAbstractPhysicalDevice>
36#include <Qt3DInput/private/qanalogaxisinput_p.h>
37
38#include "testpostmanarbiter.h"
39#include "testdevice.h"
40
41class tst_QAnalogAxisInput: public QObject
42{
43 Q_OBJECT
44public:
45 tst_QAnalogAxisInput()
46 {
47 qRegisterMetaType<Qt3DInput::QAbstractPhysicalDevice*>(typeName: "Qt3DInput::QAbstractPhysicalDevice*");
48 }
49
50private Q_SLOTS:
51 void checkCloning_data()
52 {
53 QTest::addColumn<Qt3DInput::QAnalogAxisInput *>(name: "axisInput");
54
55 Qt3DInput::QAnalogAxisInput *defaultConstructed = new Qt3DInput::QAnalogAxisInput();
56 QTest::newRow(dataTag: "defaultConstructed") << defaultConstructed;
57
58 Qt3DInput::QAnalogAxisInput *axisInputWithAxis = new Qt3DInput::QAnalogAxisInput();
59 axisInputWithAxis->setAxis(383);
60 QTest::newRow(dataTag: "axisInputWithAxis") << axisInputWithAxis;
61
62 Qt3DInput::QAnalogAxisInput *axisInputWithAxisAndSourceDevice = new Qt3DInput::QAnalogAxisInput();
63 TestDevice *device = new TestDevice();
64 axisInputWithAxisAndSourceDevice->setSourceDevice(device);
65 axisInputWithAxisAndSourceDevice->setAxis(427);
66 QTest::newRow(dataTag: "axisInputWithAxisAndSourceDevice") << axisInputWithAxisAndSourceDevice;
67 }
68
69 void checkCloning()
70 {
71 // GIVEN
72 QFETCH(Qt3DInput::QAnalogAxisInput *, axisInput);
73
74 // WHEN
75 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(axisInput);
76 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges = creationChangeGenerator.creationChanges();
77
78 // THEN
79 QCOMPARE(creationChanges.size(), 1 + (axisInput->sourceDevice() ? 1 : 0));
80
81 const Qt3DCore::QNodeCreatedChangePtr<Qt3DInput::QAnalogAxisInputData> creationChangeData =
82 qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DInput::QAnalogAxisInputData>>(src: creationChanges.first());
83 const Qt3DInput::QAnalogAxisInputData &cloneData = creationChangeData->data;
84 QCOMPARE(axisInput->id(), creationChangeData->subjectId());
85 QCOMPARE(axisInput->isEnabled(), creationChangeData->isNodeEnabled());
86 QCOMPARE(axisInput->metaObject(), creationChangeData->metaObject());
87 QCOMPARE(axisInput->axis(), cloneData.axis);
88 QCOMPARE(axisInput->sourceDevice() ? axisInput->sourceDevice()->id() : Qt3DCore::QNodeId(), cloneData.sourceDeviceId);
89 }
90
91 void checkPropertyUpdates()
92 {
93 // GIVEN
94 TestArbiter arbiter;
95 QScopedPointer<Qt3DInput::QAnalogAxisInput> axisInput(new Qt3DInput::QAnalogAxisInput());
96 arbiter.setArbiterOnNode(axisInput.data());
97
98 // WHEN
99 axisInput->setAxis(350);
100
101 // THEN
102 QCOMPARE(arbiter.dirtyNodes.size(), 1);
103 QCOMPARE(arbiter.dirtyNodes.front(), axisInput.data());
104
105 arbiter.dirtyNodes.clear();
106
107 // WHEN
108 TestDevice *device = new TestDevice(axisInput.data());
109 QCoreApplication::processEvents();
110 arbiter.events.clear();
111
112 axisInput->setSourceDevice(device);
113
114 // THEN
115 QCOMPARE(arbiter.dirtyNodes.size(), 1);
116 QCOMPARE(arbiter.dirtyNodes.front(), axisInput.data());
117
118 arbiter.dirtyNodes.clear();
119 }
120};
121
122QTEST_MAIN(tst_QAnalogAxisInput)
123
124#include "tst_qanalogaxisinput.moc"
125

source code of qt3d/tests/auto/input/qanalogaxisinput/tst_qanalogaxisinput.cpp