| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | |
| 5 | #include <QtTest/QTest> |
| 6 | #include <Qt3DExtras/qorbitcameracontroller.h> |
| 7 | #include <Qt3DRender/qcamera.h> |
| 8 | #include <QObject> |
| 9 | #include <QSignalSpy> |
| 10 | |
| 11 | class tst_QOrbitCameraController : public QObject |
| 12 | { |
| 13 | Q_OBJECT |
| 14 | |
| 15 | private Q_SLOTS: |
| 16 | |
| 17 | void checkDefaultConstruction() |
| 18 | { |
| 19 | // GIVEN |
| 20 | Qt3DExtras::QOrbitCameraController orbitCameraController; |
| 21 | |
| 22 | // THEN |
| 23 | QVERIFY(orbitCameraController.camera() == nullptr); |
| 24 | QCOMPARE(orbitCameraController.linearSpeed(), 10.0f); |
| 25 | QCOMPARE(orbitCameraController.lookSpeed(), 180.0f); |
| 26 | QCOMPARE(orbitCameraController.zoomInLimit(), 2.0f); |
| 27 | } |
| 28 | |
| 29 | void checkPropertyChanges() |
| 30 | { |
| 31 | // GIVEN |
| 32 | Qt3DExtras::QOrbitCameraController orbitCameraController; |
| 33 | |
| 34 | { |
| 35 | // WHEN |
| 36 | QSignalSpy spy(&orbitCameraController, SIGNAL(cameraChanged())); |
| 37 | Qt3DRender::QCamera *newValue = new Qt3DRender::QCamera(&orbitCameraController); |
| 38 | orbitCameraController.setCamera(newValue); |
| 39 | |
| 40 | // THEN |
| 41 | QCOMPARE(orbitCameraController.camera(), newValue); |
| 42 | QCOMPARE(spy.count(), 1); |
| 43 | |
| 44 | // WHEN |
| 45 | spy.clear(); |
| 46 | orbitCameraController.setCamera(newValue); |
| 47 | |
| 48 | // THEN |
| 49 | QCOMPARE(orbitCameraController.camera(), newValue); |
| 50 | QCOMPARE(spy.count(), 0); |
| 51 | |
| 52 | // WHEN |
| 53 | spy.clear(); |
| 54 | // Check node bookeeping |
| 55 | delete newValue; |
| 56 | |
| 57 | // THEN |
| 58 | QCOMPARE(spy.count(), 1); |
| 59 | QVERIFY(orbitCameraController.camera() == nullptr); |
| 60 | } |
| 61 | { |
| 62 | // WHEN |
| 63 | QSignalSpy spy(&orbitCameraController, SIGNAL(linearSpeedChanged())); |
| 64 | const float newValue = 0.0f; |
| 65 | orbitCameraController.setLinearSpeed(newValue); |
| 66 | |
| 67 | // THEN |
| 68 | QCOMPARE(orbitCameraController.linearSpeed(), newValue); |
| 69 | QCOMPARE(spy.count(), 1); |
| 70 | |
| 71 | // WHEN |
| 72 | spy.clear(); |
| 73 | orbitCameraController.setLinearSpeed(newValue); |
| 74 | |
| 75 | // THEN |
| 76 | QCOMPARE(orbitCameraController.linearSpeed(), newValue); |
| 77 | QCOMPARE(spy.count(), 0); |
| 78 | |
| 79 | } |
| 80 | { |
| 81 | // WHEN |
| 82 | QSignalSpy spy(&orbitCameraController, SIGNAL(lookSpeedChanged())); |
| 83 | const float newValue = 100.0f; |
| 84 | orbitCameraController.setLookSpeed(newValue); |
| 85 | |
| 86 | // THEN |
| 87 | QCOMPARE(orbitCameraController.lookSpeed(), newValue); |
| 88 | QCOMPARE(spy.count(), 1); |
| 89 | |
| 90 | // WHEN |
| 91 | spy.clear(); |
| 92 | orbitCameraController.setLookSpeed(newValue); |
| 93 | |
| 94 | // THEN |
| 95 | QCOMPARE(orbitCameraController.lookSpeed(), newValue); |
| 96 | QCOMPARE(spy.count(), 0); |
| 97 | |
| 98 | } |
| 99 | { |
| 100 | // WHEN |
| 101 | QSignalSpy spy(&orbitCameraController, SIGNAL(zoomInLimitChanged())); |
| 102 | const float newValue = 1.0f; |
| 103 | orbitCameraController.setZoomInLimit(newValue); |
| 104 | |
| 105 | // THEN |
| 106 | QCOMPARE(orbitCameraController.zoomInLimit(), newValue); |
| 107 | QCOMPARE(spy.count(), 1); |
| 108 | |
| 109 | // WHEN |
| 110 | spy.clear(); |
| 111 | orbitCameraController.setZoomInLimit(newValue); |
| 112 | |
| 113 | // THEN |
| 114 | QCOMPARE(orbitCameraController.zoomInLimit(), newValue); |
| 115 | QCOMPARE(spy.count(), 0); |
| 116 | |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | }; |
| 121 | |
| 122 | QTEST_APPLESS_MAIN(tst_QOrbitCameraController) |
| 123 | |
| 124 | #include "tst_qorbitcameracontroller.moc" |