summaryrefslogtreecommitdiffstats
path: root/tests/auto/extras/qorbitcameracontroller/tst_qorbitcameracontroller.cpp
blob: f10d6e8b3814d634d911786be38ba51d62018e3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only


#include <QtTest/QTest>
#include <Qt3DExtras/qorbitcameracontroller.h>
#include <Qt3DRender/qcamera.h>
#include <QObject>
#include <QSignalSpy>

class tst_QOrbitCameraController : public QObject
{
    Q_OBJECT

private Q_SLOTS:

    void checkDefaultConstruction()
    {
        // GIVEN
        Qt3DExtras::QOrbitCameraController orbitCameraController;

        // THEN
        QVERIFY(orbitCameraController.camera() == nullptr);
        QCOMPARE(orbitCameraController.linearSpeed(), 10.0f);
        QCOMPARE(orbitCameraController.lookSpeed(), 180.0f);
        QCOMPARE(orbitCameraController.zoomInLimit(), 2.0f);
    }

    void checkPropertyChanges()
    {
        // GIVEN
        Qt3DExtras::QOrbitCameraController orbitCameraController;

        {
            // WHEN
            QSignalSpy spy(&orbitCameraController, SIGNAL(cameraChanged()));
            Qt3DRender::QCamera *newValue = new Qt3DRender::QCamera(&orbitCameraController);
            orbitCameraController.setCamera(newValue);

            // THEN
            QCOMPARE(orbitCameraController.camera(), newValue);
            QCOMPARE(spy.count(), 1);

            // WHEN
            spy.clear();
            orbitCameraController.setCamera(newValue);

            // THEN
            QCOMPARE(orbitCameraController.camera(), newValue);
            QCOMPARE(spy.count(), 0);

            // WHEN
            spy.clear();
            // Check node bookeeping
            delete newValue;

            // THEN
            QCOMPARE(spy.count(), 1);
            QVERIFY(orbitCameraController.camera() == nullptr);
        }
        {
            // WHEN
            QSignalSpy spy(&orbitCameraController, SIGNAL(linearSpeedChanged()));
            const float newValue = 0.0f;
            orbitCameraController.setLinearSpeed(newValue);

            // THEN
            QCOMPARE(orbitCameraController.linearSpeed(), newValue);
            QCOMPARE(spy.count(), 1);

            // WHEN
            spy.clear();
            orbitCameraController.setLinearSpeed(newValue);

            // THEN
            QCOMPARE(orbitCameraController.linearSpeed(), newValue);
            QCOMPARE(spy.count(), 0);

        }
        {
            // WHEN
            QSignalSpy spy(&orbitCameraController, SIGNAL(lookSpeedChanged()));
            const float newValue = 100.0f;
            orbitCameraController.setLookSpeed(newValue);

            // THEN
            QCOMPARE(orbitCameraController.lookSpeed(), newValue);
            QCOMPARE(spy.count(), 1);

            // WHEN
            spy.clear();
            orbitCameraController.setLookSpeed(newValue);

            // THEN
            QCOMPARE(orbitCameraController.lookSpeed(), newValue);
            QCOMPARE(spy.count(), 0);

        }
        {
            // WHEN
            QSignalSpy spy(&orbitCameraController, SIGNAL(zoomInLimitChanged()));
            const float newValue = 1.0f;
            orbitCameraController.setZoomInLimit(newValue);

            // THEN
            QCOMPARE(orbitCameraController.zoomInLimit(), newValue);
            QCOMPARE(spy.count(), 1);

            // WHEN
            spy.clear();
            orbitCameraController.setZoomInLimit(newValue);

            // THEN
            QCOMPARE(orbitCameraController.zoomInLimit(), newValue);
            QCOMPARE(spy.count(), 0);

        }
    }

};

QTEST_APPLESS_MAIN(tst_QOrbitCameraController)

#include "tst_qorbitcameracontroller.moc"