| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2018 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 <Qt3DRender/private/raycaster_p.h> | 
| 32 | #include <Qt3DRender/qpickevent.h> | 
| 33 | #include <Qt3DRender/qraycaster.h> | 
| 34 | #include <Qt3DCore/private/qbackendnode_p.h> | 
| 35 | #include "testpostmanarbiter.h" | 
| 36 | #include "testrenderer.h" | 
| 37 |  | 
| 38 | class tst_RayCaster : public Qt3DCore::QBackendNodeTester | 
| 39 | { | 
| 40 |     Q_OBJECT | 
| 41 | private Q_SLOTS: | 
| 42 |  | 
| 43 |     void checkPeerPropertyMirroring() | 
| 44 |     { | 
| 45 |         // GIVEN | 
| 46 |         TestRenderer renderer; | 
| 47 |         Qt3DRender::Render::RayCaster rayCaster; | 
| 48 |         Qt3DRender::QRayCaster caster; | 
| 49 |         caster.setRunMode(Qt3DRender::QRayCaster::Continuous); | 
| 50 |         caster.setOrigin(QVector3D(1., 2., 3.)); | 
| 51 |         caster.setDirection(QVector3D(1., 0., 0.)); | 
| 52 |         caster.setLength(42.f); | 
| 53 |  | 
| 54 |         // WHEN | 
| 55 |         rayCaster.setRenderer(&renderer); | 
| 56 |         simulateInitializationSync(frontend: &caster, backend: &rayCaster); | 
| 57 |  | 
| 58 |         // THEN | 
| 59 |         QVERIFY(!rayCaster.peerId().isNull()); | 
| 60 |         QCOMPARE(rayCaster.runMode(), Qt3DRender::QRayCaster::Continuous); | 
| 61 |         QCOMPARE(rayCaster.origin(), QVector3D(1., 2., 3.)); | 
| 62 |         QCOMPARE(rayCaster.direction(), QVector3D(1., 0., 0.)); | 
| 63 |         QCOMPARE(rayCaster.length(), 42.f); | 
| 64 |     } | 
| 65 |  | 
| 66 |     void checkInitialAndCleanedUpState() | 
| 67 |     { | 
| 68 |         // GIVEN | 
| 69 |         TestRenderer renderer; | 
| 70 |         Qt3DRender::Render::RayCaster rayCaster; | 
| 71 |  | 
| 72 |         // THEN | 
| 73 |         QVERIFY(rayCaster.peerId().isNull()); | 
| 74 |         QCOMPARE(rayCaster.runMode(), Qt3DRender::QRayCaster::SingleShot); | 
| 75 |  | 
| 76 |         // GIVEN | 
| 77 |         Qt3DRender::QRayCaster caster; | 
| 78 |         caster.setRunMode(Qt3DRender::QRayCaster::Continuous); | 
| 79 |  | 
| 80 |         // WHEN | 
| 81 |         rayCaster.setRenderer(&renderer); | 
| 82 |         simulateInitializationSync(frontend: &caster, backend: &rayCaster); | 
| 83 |         rayCaster.cleanup(); | 
| 84 |  | 
| 85 |         // THEN | 
| 86 |         QCOMPARE(rayCaster.runMode(), Qt3DRender::QRayCaster::SingleShot); | 
| 87 |     } | 
| 88 |  | 
| 89 |     void checkPropertyChanges() | 
| 90 |     { | 
| 91 |         // GIVEN | 
| 92 |         TestRenderer renderer; | 
| 93 |         { | 
| 94 |             Qt3DRender::QRayCaster caster; | 
| 95 |             Qt3DRender::Render::RayCaster rayCaster; | 
| 96 |             rayCaster.setRenderer(&renderer); | 
| 97 |             simulateInitializationSync(frontend: &caster, backend: &rayCaster); | 
| 98 |  | 
| 99 |             // WHEN | 
| 100 |             caster.setRunMode(Qt3DRender::QRayCaster::Continuous); | 
| 101 |             rayCaster.syncFromFrontEnd(frontEnd: &caster, firstTime: false); | 
| 102 |  | 
| 103 |             // THEN | 
| 104 |             QCOMPARE(rayCaster.runMode(), Qt3DRender::QRayCaster::Continuous); | 
| 105 |             QVERIFY(renderer.dirtyBits() != 0); | 
| 106 |         } | 
| 107 |     } | 
| 108 | }; | 
| 109 |  | 
| 110 |  | 
| 111 | QTEST_APPLESS_MAIN(tst_RayCaster) | 
| 112 |  | 
| 113 | #include "tst_raycaster.moc" | 
| 114 |  |