summaryrefslogtreecommitdiffstats
path: root/tests/auto/cpptest/q3dscene-camera/tst_camera.cpp
blob: ee321b22dacc3156a443f9e3271a27ee712ea751 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the QtDataVisualization module.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
**
****************************************************************************/

#include <QtTest/QtTest>

#include <QtDataVisualization/Q3DCamera>

using namespace QtDataVisualization;

class tst_camera: public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void cleanupTestCase();
    void init();
    void cleanup();

    void construct();

    void initialProperties();
    void initializeProperties();
    void invalidProperties();

    void changePresets();

private:
    Q3DCamera *m_camera;
};

void tst_camera::initTestCase()
{
}

void tst_camera::cleanupTestCase()
{
}

void tst_camera::init()
{
    m_camera = new Q3DCamera();
}

void tst_camera::cleanup()
{
    delete m_camera;
}

void tst_camera::construct()
{
    Q3DCamera *camera = new Q3DCamera();
    QVERIFY(camera);
    delete camera;
}

void tst_camera::initialProperties()
{
    QVERIFY(m_camera);

    QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone);
    QCOMPARE(m_camera->maxZoomLevel(), 500.0f);
    QCOMPARE(m_camera->minZoomLevel(), 10.0f);
    QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0));
    QCOMPARE(m_camera->wrapXRotation(), true);
    QCOMPARE(m_camera->wrapYRotation(), false);
    QCOMPARE(m_camera->xRotation(), 0.0f);
    QCOMPARE(m_camera->yRotation(), 0.0f);
    QCOMPARE(m_camera->zoomLevel(), 100.0f);

    // Common (from Q3DObject)
    QVERIFY(!m_camera->parentScene());
    QCOMPARE(m_camera->position(), QVector3D(0, 0, 0));
}

void tst_camera::initializeProperties()
{
    QVERIFY(m_camera);

    m_camera->setMaxZoomLevel(1000.0f);
    m_camera->setMinZoomLevel(100.0f);
    m_camera->setTarget(QVector3D(1.0, -1.0, 1.0));
    m_camera->setWrapXRotation(false);
    m_camera->setWrapYRotation(true);
    m_camera->setXRotation(30.0f);
    m_camera->setYRotation(30.0f);
    m_camera->setZoomLevel(500.0f);

    QCOMPARE(m_camera->maxZoomLevel(), 1000.0f);
    QCOMPARE(m_camera->minZoomLevel(), 100.0f);
    QCOMPARE(m_camera->target(), QVector3D(1.0, -1.0, 1.0));
    QCOMPARE(m_camera->wrapXRotation(), false);
    QCOMPARE(m_camera->wrapYRotation(), true);
    QCOMPARE(m_camera->xRotation(), 30.0f);
    QCOMPARE(m_camera->yRotation(), 30.0f);
    QCOMPARE(m_camera->zoomLevel(), 500.0f);

    m_camera->setPosition(QVector3D(1.0, 1.0, 1.0));

    // Common (from Q3DObject)
    QCOMPARE(m_camera->position(), QVector3D(1.0, 1.0, 1.0));
}

void tst_camera::invalidProperties()
{
    m_camera->setTarget(QVector3D(-1.5, -1.5, -1.5));
    QCOMPARE(m_camera->target(), QVector3D(-1.0, -1.0, -1.0));

    m_camera->setTarget(QVector3D(1.5, 1.5, 1.5));
    QCOMPARE(m_camera->target(), QVector3D(1.0, 1.0, 1.0));

    m_camera->setMinZoomLevel(0.1f);
    QCOMPARE(m_camera->minZoomLevel(), 1.0f);
}

void tst_camera::changePresets()
{
    m_camera->setCameraPreset(Q3DCamera::CameraPresetBehind); // Will be overridden by the the following sets
    m_camera->setMaxZoomLevel(1000.0f);
    m_camera->setMinZoomLevel(100.0f);
    m_camera->setTarget(QVector3D(1.0, -1.0, 1.0));
    m_camera->setWrapXRotation(false);
    m_camera->setWrapYRotation(true);
    m_camera->setXRotation(30.0f);
    m_camera->setYRotation(30.0f);
    m_camera->setZoomLevel(500.0f);

    QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone);
    QCOMPARE(m_camera->maxZoomLevel(), 1000.0f);
    QCOMPARE(m_camera->minZoomLevel(), 100.0f);
    QCOMPARE(m_camera->target(), QVector3D(1.0, -1.0, 1.0));
    QCOMPARE(m_camera->wrapXRotation(), false);
    QCOMPARE(m_camera->wrapYRotation(), true);
    QCOMPARE(m_camera->xRotation(), 30.0f);
    QCOMPARE(m_camera->yRotation(), 30.0f);
    QCOMPARE(m_camera->zoomLevel(), 500.0f);

    m_camera->setCameraPreset(Q3DCamera::CameraPresetBehind); // Sets target and rotations

    QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetBehind);
    QCOMPARE(m_camera->maxZoomLevel(), 1000.0f);
    QCOMPARE(m_camera->minZoomLevel(), 100.0f);
    QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0));
    QCOMPARE(m_camera->wrapXRotation(), false);
    QCOMPARE(m_camera->wrapYRotation(), true);
    QCOMPARE(m_camera->xRotation(), 180.0f);
    QCOMPARE(m_camera->yRotation(), 22.5f);
    QCOMPARE(m_camera->zoomLevel(), 500.0f);

    m_camera->setCameraPosition(10.0f, 15.0f, 125.0f); // Overrides preset

    QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone);
    QCOMPARE(m_camera->maxZoomLevel(), 1000.0f);
    QCOMPARE(m_camera->minZoomLevel(), 100.0f);
    QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0));
    QCOMPARE(m_camera->wrapXRotation(), false);
    QCOMPARE(m_camera->wrapYRotation(), true);
    QCOMPARE(m_camera->xRotation(), 10.0f);
    QCOMPARE(m_camera->yRotation(), 15.0f);
    QCOMPARE(m_camera->zoomLevel(), 125.0f);
}

QTEST_MAIN(tst_camera)
#include "tst_camera.moc"