| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DCore/private/qnode_p.h> |
| 6 | #include <Qt3DCore/private/qscene_p.h> |
| 7 | |
| 8 | #include <Qt3DInput/qaxis.h> |
| 9 | #include <Qt3DInput/qaxisaccumulator.h> |
| 10 | #include <Qt3DInput/private/qaxisaccumulator_p.h> |
| 11 | |
| 12 | #include "testarbiter.h" |
| 13 | |
| 14 | class tst_QAxisAccumulator: public Qt3DInput::QAxisAccumulator |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | public: |
| 18 | tst_QAxisAccumulator() |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | private Q_SLOTS: |
| 23 | |
| 24 | void checkPropertyUpdates() |
| 25 | { |
| 26 | // GIVEN |
| 27 | TestArbiter arbiter; |
| 28 | QScopedPointer<Qt3DInput::QAxisAccumulator> accumulator(new Qt3DInput::QAxisAccumulator()); |
| 29 | arbiter.setArbiterOnNode(accumulator.data()); |
| 30 | Qt3DInput::QAxis *axis = new Qt3DInput::QAxis; |
| 31 | |
| 32 | // WHEN |
| 33 | accumulator->setSourceAxis(axis); |
| 34 | |
| 35 | // THEN |
| 36 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 37 | QCOMPARE(arbiter.dirtyNodes().front(), accumulator.data()); |
| 38 | |
| 39 | arbiter.clear(); |
| 40 | |
| 41 | |
| 42 | // WHEN |
| 43 | accumulator->setScale(2.0f); |
| 44 | |
| 45 | // THEN |
| 46 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 47 | QCOMPARE(arbiter.dirtyNodes().front(), accumulator.data()); |
| 48 | |
| 49 | arbiter.clear(); |
| 50 | |
| 51 | // WHEN |
| 52 | accumulator->setSourceAxisType(Qt3DInput::QAxisAccumulator::Acceleration); |
| 53 | |
| 54 | // THEN |
| 55 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 56 | QCOMPARE(arbiter.dirtyNodes().front(), accumulator.data()); |
| 57 | |
| 58 | arbiter.clear(); |
| 59 | } |
| 60 | |
| 61 | void checkAxisInputBookkeeping() |
| 62 | { |
| 63 | // GIVEN |
| 64 | QScopedPointer<Qt3DInput::QAxisAccumulator> accumulator(new Qt3DInput::QAxisAccumulator); |
| 65 | { |
| 66 | // WHEN |
| 67 | Qt3DInput::QAxis axis; |
| 68 | accumulator->setSourceAxis(&axis); |
| 69 | |
| 70 | // THEN |
| 71 | QCOMPARE(axis.parent(), accumulator.data()); |
| 72 | QCOMPARE(accumulator->sourceAxis(), &axis); |
| 73 | } |
| 74 | |
| 75 | // THEN (Should not crash and parameter be unset) |
| 76 | QVERIFY(accumulator->sourceAxis() == nullptr); |
| 77 | |
| 78 | { |
| 79 | // WHEN |
| 80 | Qt3DInput::QAxisAccumulator someOtherAccumulator; |
| 81 | QScopedPointer<Qt3DInput::QAxis> axis(new Qt3DInput::QAxis(&someOtherAccumulator)); |
| 82 | accumulator->setSourceAxis(axis.data()); |
| 83 | |
| 84 | // THEN |
| 85 | QCOMPARE(axis->parent(), &someOtherAccumulator); |
| 86 | QCOMPARE(accumulator->sourceAxis(), axis.data()); |
| 87 | |
| 88 | // WHEN |
| 89 | accumulator.reset(); |
| 90 | axis.reset(); |
| 91 | |
| 92 | // THEN Should not crash when the input is destroyed (tests for failed removal of destruction helper) |
| 93 | } |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | QTEST_MAIN(tst_QAxisAccumulator) |
| 98 | |
| 99 | #include "tst_qaxisaccumulator.moc" |