| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 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 | |
| 30 | #include <QtTest/QTest> |
| 31 | #include <Qt3DExtras/qorbitcameracontroller.h> |
| 32 | #include <Qt3DRender/qcamera.h> |
| 33 | #include <QObject> |
| 34 | #include <QSignalSpy> |
| 35 | |
| 36 | class tst_QOrbitCameraController : public QObject |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | |
| 40 | private Q_SLOTS: |
| 41 | |
| 42 | void checkDefaultConstruction() |
| 43 | { |
| 44 | // GIVEN |
| 45 | Qt3DExtras::QOrbitCameraController orbitCameraController; |
| 46 | |
| 47 | // THEN |
| 48 | QVERIFY(orbitCameraController.camera() == nullptr); |
| 49 | QCOMPARE(orbitCameraController.linearSpeed(), 10.0f); |
| 50 | QCOMPARE(orbitCameraController.lookSpeed(), 180.0f); |
| 51 | QCOMPARE(orbitCameraController.zoomInLimit(), 2.0f); |
| 52 | } |
| 53 | |
| 54 | void checkPropertyChanges() |
| 55 | { |
| 56 | // GIVEN |
| 57 | Qt3DExtras::QOrbitCameraController orbitCameraController; |
| 58 | |
| 59 | { |
| 60 | // WHEN |
| 61 | QSignalSpy spy(&orbitCameraController, SIGNAL(cameraChanged())); |
| 62 | Qt3DRender::QCamera *newValue = new Qt3DRender::QCamera(&orbitCameraController); |
| 63 | orbitCameraController.setCamera(newValue); |
| 64 | |
| 65 | // THEN |
| 66 | QCOMPARE(orbitCameraController.camera(), newValue); |
| 67 | QCOMPARE(spy.count(), 1); |
| 68 | |
| 69 | // WHEN |
| 70 | spy.clear(); |
| 71 | orbitCameraController.setCamera(newValue); |
| 72 | |
| 73 | // THEN |
| 74 | QCOMPARE(orbitCameraController.camera(), newValue); |
| 75 | QCOMPARE(spy.count(), 0); |
| 76 | |
| 77 | // WHEN |
| 78 | spy.clear(); |
| 79 | // Check node bookeeping |
| 80 | delete newValue; |
| 81 | |
| 82 | // THEN |
| 83 | QCOMPARE(spy.count(), 1); |
| 84 | QVERIFY(orbitCameraController.camera() == nullptr); |
| 85 | } |
| 86 | { |
| 87 | // WHEN |
| 88 | QSignalSpy spy(&orbitCameraController, SIGNAL(linearSpeedChanged())); |
| 89 | const float newValue = 0.0f; |
| 90 | orbitCameraController.setLinearSpeed(newValue); |
| 91 | |
| 92 | // THEN |
| 93 | QCOMPARE(orbitCameraController.linearSpeed(), newValue); |
| 94 | QCOMPARE(spy.count(), 1); |
| 95 | |
| 96 | // WHEN |
| 97 | spy.clear(); |
| 98 | orbitCameraController.setLinearSpeed(newValue); |
| 99 | |
| 100 | // THEN |
| 101 | QCOMPARE(orbitCameraController.linearSpeed(), newValue); |
| 102 | QCOMPARE(spy.count(), 0); |
| 103 | |
| 104 | } |
| 105 | { |
| 106 | // WHEN |
| 107 | QSignalSpy spy(&orbitCameraController, SIGNAL(lookSpeedChanged())); |
| 108 | const float newValue = 100.0f; |
| 109 | orbitCameraController.setLookSpeed(newValue); |
| 110 | |
| 111 | // THEN |
| 112 | QCOMPARE(orbitCameraController.lookSpeed(), newValue); |
| 113 | QCOMPARE(spy.count(), 1); |
| 114 | |
| 115 | // WHEN |
| 116 | spy.clear(); |
| 117 | orbitCameraController.setLookSpeed(newValue); |
| 118 | |
| 119 | // THEN |
| 120 | QCOMPARE(orbitCameraController.lookSpeed(), newValue); |
| 121 | QCOMPARE(spy.count(), 0); |
| 122 | |
| 123 | } |
| 124 | { |
| 125 | // WHEN |
| 126 | QSignalSpy spy(&orbitCameraController, SIGNAL(zoomInLimitChanged())); |
| 127 | const float newValue = 1.0f; |
| 128 | orbitCameraController.setZoomInLimit(newValue); |
| 129 | |
| 130 | // THEN |
| 131 | QCOMPARE(orbitCameraController.zoomInLimit(), newValue); |
| 132 | QCOMPARE(spy.count(), 1); |
| 133 | |
| 134 | // WHEN |
| 135 | spy.clear(); |
| 136 | orbitCameraController.setZoomInLimit(newValue); |
| 137 | |
| 138 | // THEN |
| 139 | QCOMPARE(orbitCameraController.zoomInLimit(), newValue); |
| 140 | QCOMPARE(spy.count(), 0); |
| 141 | |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | }; |
| 146 | |
| 147 | QTEST_APPLESS_MAIN(tst_QOrbitCameraController) |
| 148 | |
| 149 | #include "tst_qorbitcameracontroller.moc" |
| 150 | |