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/qfirstpersoncameracontroller.h> |
32 | #include <Qt3DRender/qcamera.h> |
33 | #include <QObject> |
34 | #include <QSignalSpy> |
35 | |
36 | class tst_QFirstPersonCameraController : public QObject |
37 | { |
38 | Q_OBJECT |
39 | |
40 | private Q_SLOTS: |
41 | |
42 | void checkDefaultConstruction() |
43 | { |
44 | // GIVEN |
45 | Qt3DExtras::QFirstPersonCameraController firstPersonCameraController; |
46 | |
47 | // THEN |
48 | QVERIFY(firstPersonCameraController.camera() == nullptr); |
49 | QCOMPARE(firstPersonCameraController.linearSpeed(), 10.0f); |
50 | QCOMPARE(firstPersonCameraController.lookSpeed(), 180.0f); |
51 | QCOMPARE(firstPersonCameraController.acceleration(), -1.0f); |
52 | QCOMPARE(firstPersonCameraController.deceleration(), -1.0f); |
53 | } |
54 | |
55 | void checkPropertyChanges() |
56 | { |
57 | // GIVEN |
58 | Qt3DExtras::QFirstPersonCameraController firstPersonCameraController; |
59 | |
60 | { |
61 | // WHEN |
62 | QSignalSpy spy(&firstPersonCameraController, SIGNAL(cameraChanged())); |
63 | Qt3DRender::QCamera *newValue = new Qt3DRender::QCamera(&firstPersonCameraController); |
64 | firstPersonCameraController.setCamera(newValue); |
65 | |
66 | // THEN |
67 | QCOMPARE(firstPersonCameraController.camera(), newValue); |
68 | QCOMPARE(spy.count(), 1); |
69 | |
70 | // WHEN |
71 | spy.clear(); |
72 | firstPersonCameraController.setCamera(newValue); |
73 | |
74 | // THEN |
75 | QCOMPARE(firstPersonCameraController.camera(), newValue); |
76 | QCOMPARE(spy.count(), 0); |
77 | |
78 | // WHEN |
79 | spy.clear(); |
80 | // Check node bookeeping |
81 | delete newValue; |
82 | |
83 | // THEN |
84 | QCOMPARE(spy.count(), 1); |
85 | QVERIFY(firstPersonCameraController.camera() == nullptr); |
86 | } |
87 | { |
88 | // WHEN |
89 | QSignalSpy spy(&firstPersonCameraController, SIGNAL(linearSpeedChanged())); |
90 | const float newValue = 300.0f; |
91 | firstPersonCameraController.setLinearSpeed(newValue); |
92 | |
93 | // THEN |
94 | QCOMPARE(firstPersonCameraController.linearSpeed(), newValue); |
95 | QCOMPARE(spy.count(), 1); |
96 | |
97 | // WHEN |
98 | spy.clear(); |
99 | firstPersonCameraController.setLinearSpeed(newValue); |
100 | |
101 | // THEN |
102 | QCOMPARE(firstPersonCameraController.linearSpeed(), newValue); |
103 | QCOMPARE(spy.count(), 0); |
104 | |
105 | } |
106 | { |
107 | // WHEN |
108 | QSignalSpy spy(&firstPersonCameraController, SIGNAL(lookSpeedChanged())); |
109 | const float newValue = 0.001f; |
110 | firstPersonCameraController.setLookSpeed(newValue); |
111 | |
112 | // THEN |
113 | QCOMPARE(firstPersonCameraController.lookSpeed(), newValue); |
114 | QCOMPARE(spy.count(), 1); |
115 | |
116 | // WHEN |
117 | spy.clear(); |
118 | firstPersonCameraController.setLookSpeed(newValue); |
119 | |
120 | // THEN |
121 | QCOMPARE(firstPersonCameraController.lookSpeed(), newValue); |
122 | QCOMPARE(spy.count(), 0); |
123 | |
124 | } |
125 | { |
126 | // WHEN |
127 | QSignalSpy spy(&firstPersonCameraController, SIGNAL(accelerationChanged(float))); |
128 | const float newValue = 0.001f; |
129 | firstPersonCameraController.setAcceleration(newValue); |
130 | |
131 | // THEN |
132 | QCOMPARE(firstPersonCameraController.acceleration(), newValue); |
133 | QCOMPARE(spy.count(), 1); |
134 | |
135 | // WHEN |
136 | spy.clear(); |
137 | firstPersonCameraController.setAcceleration(newValue); |
138 | |
139 | // THEN |
140 | QCOMPARE(firstPersonCameraController.acceleration(), newValue); |
141 | QCOMPARE(spy.count(), 0); |
142 | |
143 | } |
144 | { |
145 | // WHEN |
146 | QSignalSpy spy(&firstPersonCameraController, SIGNAL(decelerationChanged(float))); |
147 | const float newValue = 0.001f; |
148 | firstPersonCameraController.setDeceleration(newValue); |
149 | |
150 | // THEN |
151 | QCOMPARE(firstPersonCameraController.deceleration(), newValue); |
152 | QCOMPARE(spy.count(), 1); |
153 | |
154 | // WHEN |
155 | spy.clear(); |
156 | firstPersonCameraController.setDeceleration(newValue); |
157 | |
158 | // THEN |
159 | QCOMPARE(firstPersonCameraController.deceleration(), newValue); |
160 | QCOMPARE(spy.count(), 0); |
161 | |
162 | } |
163 | } |
164 | |
165 | }; |
166 | |
167 | QTEST_APPLESS_MAIN(tst_QFirstPersonCameraController) |
168 | |
169 | #include "tst_qfirstpersoncameracontroller.moc" |
170 | |