| 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/qfirstpersoncameracontroller.h> |
| 7 |
#include <Qt3DRender/qcamera.h> |
| 8 |
#include <QObject> |
| 9 |
#include <QSignalSpy> |
| 10 |
|
| 11 |
class tst_QFirstPersonCameraController : public QObject |
| 12 |
{ |
| 13 |
Q_OBJECT |
| 14 |
|
| 15 |
private Q_SLOTS: |
| 16 |
|
| 17 |
void checkDefaultConstruction() |
| 18 |
{ |
| 19 |
// GIVEN |
| 20 |
Qt3DExtras::QFirstPersonCameraController firstPersonCameraController; |
| 21 |
|
| 22 |
// THEN |
| 23 |
QVERIFY(firstPersonCameraController.camera() == nullptr); |
| 24 |
QCOMPARE(firstPersonCameraController.linearSpeed(), 10.0f); |
| 25 |
QCOMPARE(firstPersonCameraController.lookSpeed(), 180.0f); |
| 26 |
QCOMPARE(firstPersonCameraController.acceleration(), -1.0f); |
| 27 |
QCOMPARE(firstPersonCameraController.deceleration(), -1.0f); |
| 28 |
} |
| 29 |
|
| 30 |
void checkPropertyChanges() |
| 31 |
{ |
| 32 |
// GIVEN |
| 33 |
Qt3DExtras::QFirstPersonCameraController firstPersonCameraController; |
| 34 |
|
| 35 |
{ |
| 36 |
// WHEN |
| 37 |
QSignalSpy spy(&firstPersonCameraController, SIGNAL(cameraChanged())); |
| 38 |
Qt3DRender::QCamera *newValue = new Qt3DRender::QCamera(&firstPersonCameraController); |
| 39 |
firstPersonCameraController.setCamera(newValue); |
| 40 |
|
| 41 |
// THEN |
| 42 |
QCOMPARE(firstPersonCameraController.camera(), newValue); |
| 43 |
QCOMPARE(spy.count(), 1); |
| 44 |
|
| 45 |
// WHEN |
| 46 |
spy.clear(); |
| 47 |
firstPersonCameraController.setCamera(newValue); |
| 48 |
|
| 49 |
// THEN |
| 50 |
QCOMPARE(firstPersonCameraController.camera(), newValue); |
| 51 |
QCOMPARE(spy.count(), 0); |
| 52 |
|
| 53 |
// WHEN |
| 54 |
spy.clear(); |
| 55 |
// Check node bookeeping |
| 56 |
delete newValue; |
| 57 |
|
| 58 |
// THEN |
| 59 |
QCOMPARE(spy.count(), 1); |
| 60 |
QVERIFY(firstPersonCameraController.camera() == nullptr); |
| 61 |
} |
| 62 |
{ |
| 63 |
// WHEN |
| 64 |
QSignalSpy spy(&firstPersonCameraController, SIGNAL(linearSpeedChanged())); |
| 65 |
const float newValue = 300.0f; |
| 66 |
firstPersonCameraController.setLinearSpeed(newValue); |
| 67 |
|
| 68 |
// THEN |
| 69 |
QCOMPARE(firstPersonCameraController.linearSpeed(), newValue); |
| 70 |
QCOMPARE(spy.count(), 1); |
| 71 |
|
| 72 |
// WHEN |
| 73 |
spy.clear(); |
| 74 |
firstPersonCameraController.setLinearSpeed(newValue); |
| 75 |
|
| 76 |
// THEN |
| 77 |
QCOMPARE(firstPersonCameraController.linearSpeed(), newValue); |
| 78 |
QCOMPARE(spy.count(), 0); |
| 79 |
|
| 80 |
} |
| 81 |
{ |
| 82 |
// WHEN |
| 83 |
QSignalSpy spy(&firstPersonCameraController, SIGNAL(lookSpeedChanged())); |
| 84 |
const float newValue = 0.001f; |
| 85 |
firstPersonCameraController.setLookSpeed(newValue); |
| 86 |
|
| 87 |
// THEN |
| 88 |
QCOMPARE(firstPersonCameraController.lookSpeed(), newValue); |
| 89 |
QCOMPARE(spy.count(), 1); |
| 90 |
|
| 91 |
// WHEN |
| 92 |
spy.clear(); |
| 93 |
firstPersonCameraController.setLookSpeed(newValue); |
| 94 |
|
| 95 |
// THEN |
| 96 |
QCOMPARE(firstPersonCameraController.lookSpeed(), newValue); |
| 97 |
QCOMPARE(spy.count(), 0); |
| 98 |
|
| 99 |
} |
| 100 |
{ |
| 101 |
// WHEN |
| 102 |
QSignalSpy spy(&firstPersonCameraController, SIGNAL(accelerationChanged(float))); |
| 103 |
const float newValue = 0.001f; |
| 104 |
firstPersonCameraController.setAcceleration(newValue); |
| 105 |
|
| 106 |
// THEN |
| 107 |
QCOMPARE(firstPersonCameraController.acceleration(), newValue); |
| 108 |
QCOMPARE(spy.count(), 1); |
| 109 |
|
| 110 |
// WHEN |
| 111 |
spy.clear(); |
| 112 |
firstPersonCameraController.setAcceleration(newValue); |
| 113 |
|
| 114 |
// THEN |
| 115 |
QCOMPARE(firstPersonCameraController.acceleration(), newValue); |
| 116 |
QCOMPARE(spy.count(), 0); |
| 117 |
|
| 118 |
} |
| 119 |
{ |
| 120 |
// WHEN |
| 121 |
QSignalSpy spy(&firstPersonCameraController, SIGNAL(decelerationChanged(float))); |
| 122 |
const float newValue = 0.001f; |
| 123 |
firstPersonCameraController.setDeceleration(newValue); |
| 124 |
|
| 125 |
// THEN |
| 126 |
QCOMPARE(firstPersonCameraController.deceleration(), newValue); |
| 127 |
QCOMPARE(spy.count(), 1); |
| 128 |
|
| 129 |
// WHEN |
| 130 |
spy.clear(); |
| 131 |
firstPersonCameraController.setDeceleration(newValue); |
| 132 |
|
| 133 |
// THEN |
| 134 |
QCOMPARE(firstPersonCameraController.deceleration(), newValue); |
| 135 |
QCOMPARE(spy.count(), 0); |
| 136 |
|
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
}; |
| 141 |
|
| 142 |
QTEST_APPLESS_MAIN(tst_QFirstPersonCameraController) |
| 143 |
|
| 144 |
#include "tst_qfirstpersoncameracontroller.moc" |