| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 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 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include <QtTest/QtTest> |
| 31 | |
| 32 | #include <QtDataVisualization/Q3DCamera> |
| 33 | |
| 34 | using namespace QtDataVisualization; |
| 35 | |
| 36 | class tst_camera: public QObject |
| 37 | { |
| 38 | Q_OBJECT |
| 39 | |
| 40 | private slots: |
| 41 | void initTestCase(); |
| 42 | void cleanupTestCase(); |
| 43 | void init(); |
| 44 | void cleanup(); |
| 45 | |
| 46 | void construct(); |
| 47 | |
| 48 | void initialProperties(); |
| 49 | void initializeProperties(); |
| 50 | void invalidProperties(); |
| 51 | |
| 52 | void changePresets(); |
| 53 | |
| 54 | private: |
| 55 | Q3DCamera *m_camera; |
| 56 | }; |
| 57 | |
| 58 | void tst_camera::initTestCase() |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | void tst_camera::cleanupTestCase() |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | void tst_camera::init() |
| 67 | { |
| 68 | m_camera = new Q3DCamera(); |
| 69 | } |
| 70 | |
| 71 | void tst_camera::cleanup() |
| 72 | { |
| 73 | delete m_camera; |
| 74 | } |
| 75 | |
| 76 | void tst_camera::construct() |
| 77 | { |
| 78 | Q3DCamera *camera = new Q3DCamera(); |
| 79 | QVERIFY(camera); |
| 80 | delete camera; |
| 81 | } |
| 82 | |
| 83 | void tst_camera::initialProperties() |
| 84 | { |
| 85 | QVERIFY(m_camera); |
| 86 | |
| 87 | QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone); |
| 88 | QCOMPARE(m_camera->maxZoomLevel(), 500.0f); |
| 89 | QCOMPARE(m_camera->minZoomLevel(), 10.0f); |
| 90 | QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0)); |
| 91 | QCOMPARE(m_camera->wrapXRotation(), true); |
| 92 | QCOMPARE(m_camera->wrapYRotation(), false); |
| 93 | QCOMPARE(m_camera->xRotation(), 0.0f); |
| 94 | QCOMPARE(m_camera->yRotation(), 0.0f); |
| 95 | QCOMPARE(m_camera->zoomLevel(), 100.0f); |
| 96 | |
| 97 | // Common (from Q3DObject) |
| 98 | QVERIFY(!m_camera->parentScene()); |
| 99 | QCOMPARE(m_camera->position(), QVector3D(0, 0, 0)); |
| 100 | } |
| 101 | |
| 102 | void tst_camera::initializeProperties() |
| 103 | { |
| 104 | QVERIFY(m_camera); |
| 105 | |
| 106 | m_camera->setMaxZoomLevel(1000.0f); |
| 107 | m_camera->setMinZoomLevel(100.0f); |
| 108 | m_camera->setTarget(QVector3D(1.0, -1.0, 1.0)); |
| 109 | m_camera->setWrapXRotation(false); |
| 110 | m_camera->setWrapYRotation(true); |
| 111 | m_camera->setXRotation(30.0f); |
| 112 | m_camera->setYRotation(30.0f); |
| 113 | m_camera->setZoomLevel(500.0f); |
| 114 | |
| 115 | QCOMPARE(m_camera->maxZoomLevel(), 1000.0f); |
| 116 | QCOMPARE(m_camera->minZoomLevel(), 100.0f); |
| 117 | QCOMPARE(m_camera->target(), QVector3D(1.0, -1.0, 1.0)); |
| 118 | QCOMPARE(m_camera->wrapXRotation(), false); |
| 119 | QCOMPARE(m_camera->wrapYRotation(), true); |
| 120 | QCOMPARE(m_camera->xRotation(), 30.0f); |
| 121 | QCOMPARE(m_camera->yRotation(), 30.0f); |
| 122 | QCOMPARE(m_camera->zoomLevel(), 500.0f); |
| 123 | |
| 124 | m_camera->setPosition(QVector3D(1.0, 1.0, 1.0)); |
| 125 | |
| 126 | // Common (from Q3DObject) |
| 127 | QCOMPARE(m_camera->position(), QVector3D(1.0, 1.0, 1.0)); |
| 128 | } |
| 129 | |
| 130 | void tst_camera::invalidProperties() |
| 131 | { |
| 132 | m_camera->setTarget(QVector3D(-1.5, -1.5, -1.5)); |
| 133 | QCOMPARE(m_camera->target(), QVector3D(-1.0, -1.0, -1.0)); |
| 134 | |
| 135 | m_camera->setTarget(QVector3D(1.5, 1.5, 1.5)); |
| 136 | QCOMPARE(m_camera->target(), QVector3D(1.0, 1.0, 1.0)); |
| 137 | |
| 138 | m_camera->setMinZoomLevel(0.1f); |
| 139 | QCOMPARE(m_camera->minZoomLevel(), 1.0f); |
| 140 | } |
| 141 | |
| 142 | void tst_camera::changePresets() |
| 143 | { |
| 144 | m_camera->setCameraPreset(Q3DCamera::CameraPresetBehind); // Will be overridden by the the following sets |
| 145 | m_camera->setMaxZoomLevel(1000.0f); |
| 146 | m_camera->setMinZoomLevel(100.0f); |
| 147 | m_camera->setTarget(QVector3D(1.0, -1.0, 1.0)); |
| 148 | m_camera->setWrapXRotation(false); |
| 149 | m_camera->setWrapYRotation(true); |
| 150 | m_camera->setXRotation(30.0f); |
| 151 | m_camera->setYRotation(30.0f); |
| 152 | m_camera->setZoomLevel(500.0f); |
| 153 | |
| 154 | QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone); |
| 155 | QCOMPARE(m_camera->maxZoomLevel(), 1000.0f); |
| 156 | QCOMPARE(m_camera->minZoomLevel(), 100.0f); |
| 157 | QCOMPARE(m_camera->target(), QVector3D(1.0, -1.0, 1.0)); |
| 158 | QCOMPARE(m_camera->wrapXRotation(), false); |
| 159 | QCOMPARE(m_camera->wrapYRotation(), true); |
| 160 | QCOMPARE(m_camera->xRotation(), 30.0f); |
| 161 | QCOMPARE(m_camera->yRotation(), 30.0f); |
| 162 | QCOMPARE(m_camera->zoomLevel(), 500.0f); |
| 163 | |
| 164 | m_camera->setCameraPreset(Q3DCamera::CameraPresetBehind); // Sets target and rotations |
| 165 | |
| 166 | QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetBehind); |
| 167 | QCOMPARE(m_camera->maxZoomLevel(), 1000.0f); |
| 168 | QCOMPARE(m_camera->minZoomLevel(), 100.0f); |
| 169 | QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0)); |
| 170 | QCOMPARE(m_camera->wrapXRotation(), false); |
| 171 | QCOMPARE(m_camera->wrapYRotation(), true); |
| 172 | QCOMPARE(m_camera->xRotation(), 180.0f); |
| 173 | QCOMPARE(m_camera->yRotation(), 22.5f); |
| 174 | QCOMPARE(m_camera->zoomLevel(), 500.0f); |
| 175 | |
| 176 | m_camera->setCameraPosition(horizontal: 10.0f, vertical: 15.0f, zoom: 125.0f); // Overrides preset |
| 177 | |
| 178 | QCOMPARE(m_camera->cameraPreset(), Q3DCamera::CameraPresetNone); |
| 179 | QCOMPARE(m_camera->maxZoomLevel(), 1000.0f); |
| 180 | QCOMPARE(m_camera->minZoomLevel(), 100.0f); |
| 181 | QCOMPARE(m_camera->target(), QVector3D(0.0, 0.0, 0.0)); |
| 182 | QCOMPARE(m_camera->wrapXRotation(), false); |
| 183 | QCOMPARE(m_camera->wrapYRotation(), true); |
| 184 | QCOMPARE(m_camera->xRotation(), 10.0f); |
| 185 | QCOMPARE(m_camera->yRotation(), 15.0f); |
| 186 | QCOMPARE(m_camera->zoomLevel(), 125.0f); |
| 187 | } |
| 188 | |
| 189 | QTEST_MAIN(tst_camera) |
| 190 | #include "tst_camera.moc" |
| 191 | |