| 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 <qbackendnodetester.h> |
| 31 | #include <Qt3DCore/private/qnode_p.h> |
| 32 | #include <Qt3DCore/private/qscene_p.h> |
| 33 | #include <Qt3DInput/private/axis_p.h> |
| 34 | #include <Qt3DInput/private/axisaccumulator_p.h> |
| 35 | #include <Qt3DInput/private/axisaccumulatorjob_p.h> |
| 36 | #include <Qt3DInput/private/qabstractaxisinput_p.h> |
| 37 | #include <Qt3DInput/private/inputmanagers_p.h> |
| 38 | #include <Qt3DInput/QAnalogAxisInput> |
| 39 | #include <Qt3DInput/QAxis> |
| 40 | #include <Qt3DInput/QAxisAccumulator> |
| 41 | #include <Qt3DCore/private/qbackendnode_p.h> |
| 42 | #include "testpostmanarbiter.h" |
| 43 | |
| 44 | class tst_AxisAccumulatorJob : public Qt3DCore::QBackendNodeTester |
| 45 | { |
| 46 | Q_OBJECT |
| 47 | |
| 48 | private Q_SLOTS: |
| 49 | void checkIntegration() |
| 50 | { |
| 51 | // GIVEN |
| 52 | const auto sourceAxisType = Qt3DInput::QAxisAccumulator::Velocity; |
| 53 | const float axisValue = 1.0f; |
| 54 | const float scale = 10.0f; |
| 55 | const float dt = 0.1f; |
| 56 | const float valueResultEnabled = 1.0f; |
| 57 | const float valueResultDisabled = 0.0f; |
| 58 | |
| 59 | // Set up an axis |
| 60 | Qt3DInput::QAxis *axis = new Qt3DInput::QAxis; |
| 61 | Qt3DInput::Input::AxisManager axisManager; |
| 62 | Qt3DInput::Input::Axis *backendAxis = axisManager.getOrCreateResource(id: axis->id()); |
| 63 | backendAxis->setEnabled(true); |
| 64 | backendAxis->setAxisValue(axisValue); |
| 65 | |
| 66 | // Hook up a bunch of accumulators to this axis |
| 67 | Qt3DInput::Input::AxisAccumulatorManager axisAccumulatorManager; |
| 68 | QVector<Qt3DInput::Input::AxisAccumulator *> accumulators; |
| 69 | for (int i = 0; i < 10; ++i) { |
| 70 | auto axisAccumulator = new Qt3DInput::QAxisAccumulator; |
| 71 | Qt3DInput::Input::AxisAccumulator *backendAxisAccumulator |
| 72 | = axisAccumulatorManager.getOrCreateResource(id: axisAccumulator->id()); |
| 73 | accumulators.push_back(t: backendAxisAccumulator); |
| 74 | |
| 75 | axisAccumulator->setEnabled(i % 2 == 0); // Enable only even accumulators |
| 76 | axisAccumulator->setSourceAxis(axis); |
| 77 | axisAccumulator->setScale(scale); |
| 78 | axisAccumulator->setSourceAxisType(sourceAxisType); |
| 79 | simulateInitializationSync(frontend: axisAccumulator, backend: backendAxisAccumulator); |
| 80 | } |
| 81 | |
| 82 | // WHEN |
| 83 | Qt3DInput::Input::AxisAccumulatorJob job(&axisAccumulatorManager, &axisManager); |
| 84 | job.setDeltaTime(dt); |
| 85 | job.run(); |
| 86 | |
| 87 | |
| 88 | // THEN |
| 89 | for (const auto accumulator : accumulators) { |
| 90 | QCOMPARE(accumulator->value(), accumulator->isEnabled() ? valueResultEnabled |
| 91 | : valueResultDisabled); |
| 92 | } |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | QTEST_APPLESS_MAIN(tst_AxisAccumulatorJob) |
| 97 | |
| 98 | #include "tst_axisaccumulatorjob.moc" |
| 99 |
