| 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/Q3DSurface> |
| 33 | |
| 34 | #include "cpptestutil.h" |
| 35 | |
| 36 | using namespace QtDataVisualization; |
| 37 | |
| 38 | class tst_surface: public QObject |
| 39 | { |
| 40 | Q_OBJECT |
| 41 | |
| 42 | private slots: |
| 43 | void initTestCase(); |
| 44 | void cleanupTestCase(); |
| 45 | void init(); |
| 46 | void cleanup(); |
| 47 | |
| 48 | void construct(); |
| 49 | |
| 50 | void initialProperties(); |
| 51 | void initializeProperties(); |
| 52 | void invalidProperties(); |
| 53 | |
| 54 | void addSeries(); |
| 55 | void addMultipleSeries(); |
| 56 | void selectSeries(); |
| 57 | void removeSeries(); |
| 58 | void removeMultipleSeries(); |
| 59 | |
| 60 | private: |
| 61 | Q3DSurface *m_graph; |
| 62 | }; |
| 63 | |
| 64 | QSurface3DSeries *newSeries() |
| 65 | { |
| 66 | QSurface3DSeries *series = new QSurface3DSeries; |
| 67 | QSurfaceDataArray *data = new QSurfaceDataArray; |
| 68 | QSurfaceDataRow *dataRow1 = new QSurfaceDataRow; |
| 69 | QSurfaceDataRow *dataRow2 = new QSurfaceDataRow; |
| 70 | *dataRow1 << QVector3D(0.0f, 0.1f, 0.5f) << QVector3D(1.0f, 0.5f, 0.5f); |
| 71 | *dataRow2 << QVector3D(0.0f, 1.8f, 1.0f) << QVector3D(1.0f, 1.2f, 1.0f); |
| 72 | *data << dataRow1 << dataRow2; |
| 73 | series->dataProxy()->resetArray(newArray: data); |
| 74 | |
| 75 | return series; |
| 76 | } |
| 77 | |
| 78 | void tst_surface::initTestCase() |
| 79 | { |
| 80 | if (!CpptestUtil::isOpenGLSupported()) |
| 81 | QSKIP("OpenGL not supported on this platform" ); |
| 82 | } |
| 83 | |
| 84 | void tst_surface::cleanupTestCase() |
| 85 | { |
| 86 | } |
| 87 | |
| 88 | void tst_surface::init() |
| 89 | { |
| 90 | m_graph = new Q3DSurface(); |
| 91 | } |
| 92 | |
| 93 | void tst_surface::cleanup() |
| 94 | { |
| 95 | delete m_graph; |
| 96 | } |
| 97 | |
| 98 | void tst_surface::construct() |
| 99 | { |
| 100 | Q3DSurface *graph = new Q3DSurface(); |
| 101 | QVERIFY(graph); |
| 102 | delete graph; |
| 103 | |
| 104 | QSurfaceFormat format; |
| 105 | graph = new Q3DSurface(&format); |
| 106 | QVERIFY(graph); |
| 107 | delete graph; |
| 108 | } |
| 109 | |
| 110 | void tst_surface::initialProperties() |
| 111 | { |
| 112 | QVERIFY(m_graph); |
| 113 | QCOMPARE(m_graph->seriesList().length(), 0); |
| 114 | QVERIFY(!m_graph->selectedSeries()); |
| 115 | QCOMPARE(m_graph->flipHorizontalGrid(), false); |
| 116 | QCOMPARE(m_graph->axisX()->orientation(), QAbstract3DAxis::AxisOrientationX); |
| 117 | QCOMPARE(m_graph->axisY()->orientation(), QAbstract3DAxis::AxisOrientationY); |
| 118 | QCOMPARE(m_graph->axisZ()->orientation(), QAbstract3DAxis::AxisOrientationZ); |
| 119 | |
| 120 | // Common properties |
| 121 | QCOMPARE(m_graph->activeTheme()->type(), Q3DTheme::ThemeQt); |
| 122 | QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionItem); |
| 123 | QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualityMedium); |
| 124 | QVERIFY(m_graph->scene()); |
| 125 | QCOMPARE(m_graph->measureFps(), false); |
| 126 | QCOMPARE(m_graph->isOrthoProjection(), false); |
| 127 | QCOMPARE(m_graph->selectedElement(), QAbstract3DGraph::ElementNone); |
| 128 | QCOMPARE(m_graph->aspectRatio(), 2.0); |
| 129 | QCOMPARE(m_graph->optimizationHints(), QAbstract3DGraph::OptimizationDefault); |
| 130 | QCOMPARE(m_graph->isPolar(), false); |
| 131 | QCOMPARE(m_graph->radialLabelOffset(), 1.0); |
| 132 | QCOMPARE(m_graph->horizontalAspectRatio(), 0.0); |
| 133 | QCOMPARE(m_graph->isReflection(), false); |
| 134 | QCOMPARE(m_graph->reflectivity(), 0.5); |
| 135 | QCOMPARE(m_graph->locale(), QLocale("C" )); |
| 136 | QCOMPARE(m_graph->queriedGraphPosition(), QVector3D(0, 0, 0)); |
| 137 | QCOMPARE(m_graph->margin(), -1.0); |
| 138 | } |
| 139 | |
| 140 | void tst_surface::initializeProperties() |
| 141 | { |
| 142 | m_graph->setFlipHorizontalGrid(true); |
| 143 | |
| 144 | QCOMPARE(m_graph->flipHorizontalGrid(), true); |
| 145 | |
| 146 | Q3DTheme *theme = new Q3DTheme(Q3DTheme::ThemeDigia); |
| 147 | m_graph->setActiveTheme(theme); |
| 148 | m_graph->setSelectionMode(QAbstract3DGraph::SelectionItem | QAbstract3DGraph::SelectionRow | QAbstract3DGraph::SelectionSlice); |
| 149 | m_graph->setShadowQuality(QAbstract3DGraph::ShadowQualitySoftHigh); |
| 150 | QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualitySoftHigh); |
| 151 | m_graph->setMeasureFps(true); |
| 152 | m_graph->setOrthoProjection(true); |
| 153 | m_graph->setAspectRatio(1.0); |
| 154 | m_graph->setOptimizationHints(QAbstract3DGraph::OptimizationStatic); |
| 155 | m_graph->setPolar(true); |
| 156 | m_graph->setRadialLabelOffset(0.1f); |
| 157 | m_graph->setHorizontalAspectRatio(1.0); |
| 158 | m_graph->setReflection(true); |
| 159 | m_graph->setReflectivity(0.1); |
| 160 | m_graph->setLocale(QLocale("FI" )); |
| 161 | m_graph->setMargin(1.0); |
| 162 | |
| 163 | QCOMPARE(m_graph->activeTheme()->type(), Q3DTheme::ThemeDigia); |
| 164 | QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionItem | QAbstract3DGraph::SelectionRow | QAbstract3DGraph::SelectionSlice); |
| 165 | QCOMPARE(m_graph->shadowQuality(), QAbstract3DGraph::ShadowQualityNone); // Ortho disables shadows |
| 166 | QCOMPARE(m_graph->measureFps(), true); |
| 167 | QCOMPARE(m_graph->isOrthoProjection(), true); |
| 168 | QCOMPARE(m_graph->aspectRatio(), 1.0); |
| 169 | QCOMPARE(m_graph->optimizationHints(), QAbstract3DGraph::OptimizationStatic); |
| 170 | QCOMPARE(m_graph->isPolar(), true); |
| 171 | QCOMPARE(m_graph->radialLabelOffset(), 0.1f); |
| 172 | QCOMPARE(m_graph->horizontalAspectRatio(), 1.0); |
| 173 | QCOMPARE(m_graph->isReflection(), true); |
| 174 | QCOMPARE(m_graph->reflectivity(), 0.1); |
| 175 | QCOMPARE(m_graph->locale(), QLocale("FI" )); |
| 176 | QCOMPARE(m_graph->margin(), 1.0); |
| 177 | } |
| 178 | |
| 179 | void tst_surface::invalidProperties() |
| 180 | { |
| 181 | m_graph->setSelectionMode(QAbstract3DGraph::SelectionColumn | QAbstract3DGraph::SelectionRow | QAbstract3DGraph::SelectionSlice); |
| 182 | m_graph->setAspectRatio(-1.0); |
| 183 | m_graph->setHorizontalAspectRatio(-1.0); |
| 184 | m_graph->setReflectivity(-1.0); |
| 185 | m_graph->setLocale(QLocale("XX" )); |
| 186 | |
| 187 | QCOMPARE(m_graph->selectionMode(), QAbstract3DGraph::SelectionItem); |
| 188 | QCOMPARE(m_graph->aspectRatio(), -1.0/*2.0*/); // TODO: Fix once QTRD-3367 is done |
| 189 | QCOMPARE(m_graph->horizontalAspectRatio(), -1.0/*0.0*/); // TODO: Fix once QTRD-3367 is done |
| 190 | QCOMPARE(m_graph->reflectivity(), -1.0/*0.5*/); // TODO: Fix once QTRD-3367 is done |
| 191 | QCOMPARE(m_graph->locale(), QLocale("C" )); |
| 192 | } |
| 193 | |
| 194 | void tst_surface::addSeries() |
| 195 | { |
| 196 | m_graph->addSeries(series: newSeries()); |
| 197 | |
| 198 | QCOMPARE(m_graph->seriesList().length(), 1); |
| 199 | QVERIFY(!m_graph->selectedSeries()); |
| 200 | } |
| 201 | |
| 202 | void tst_surface::addMultipleSeries() |
| 203 | { |
| 204 | QSurface3DSeries *series = newSeries(); |
| 205 | QSurface3DSeries *series2 = newSeries(); |
| 206 | QSurface3DSeries *series3 = newSeries(); |
| 207 | |
| 208 | m_graph->addSeries(series); |
| 209 | m_graph->addSeries(series: series2); |
| 210 | m_graph->addSeries(series: series3); |
| 211 | |
| 212 | QCOMPARE(m_graph->seriesList().length(), 3); |
| 213 | } |
| 214 | |
| 215 | void tst_surface::selectSeries() |
| 216 | { |
| 217 | QSurface3DSeries *series = newSeries(); |
| 218 | |
| 219 | m_graph->addSeries(series); |
| 220 | m_graph->seriesList()[0]->setSelectedPoint(QPoint(0, 0)); |
| 221 | |
| 222 | QCOMPARE(m_graph->seriesList().length(), 1); |
| 223 | QCOMPARE(m_graph->selectedSeries(), series); |
| 224 | |
| 225 | m_graph->clearSelection(); |
| 226 | QVERIFY(!m_graph->selectedSeries()); |
| 227 | } |
| 228 | |
| 229 | void tst_surface::removeSeries() |
| 230 | { |
| 231 | QSurface3DSeries *series = newSeries(); |
| 232 | |
| 233 | m_graph->addSeries(series); |
| 234 | m_graph->removeSeries(series); |
| 235 | QCOMPARE(m_graph->seriesList().length(), 0); |
| 236 | |
| 237 | delete series; |
| 238 | } |
| 239 | |
| 240 | void tst_surface::removeMultipleSeries() |
| 241 | { |
| 242 | QSurface3DSeries *series = newSeries(); |
| 243 | QSurface3DSeries *series2 = newSeries(); |
| 244 | QSurface3DSeries *series3 = newSeries(); |
| 245 | |
| 246 | m_graph->addSeries(series); |
| 247 | m_graph->addSeries(series: series2); |
| 248 | m_graph->addSeries(series: series3); |
| 249 | |
| 250 | m_graph->seriesList()[0]->setSelectedPoint(QPoint(0, 0)); |
| 251 | QCOMPARE(m_graph->selectedSeries(), series); |
| 252 | |
| 253 | m_graph->removeSeries(series); |
| 254 | QCOMPARE(m_graph->seriesList().length(), 2); |
| 255 | QVERIFY(!m_graph->selectedSeries()); |
| 256 | |
| 257 | m_graph->removeSeries(series: series2); |
| 258 | QCOMPARE(m_graph->seriesList().length(), 1); |
| 259 | |
| 260 | m_graph->removeSeries(series: series3); |
| 261 | QCOMPARE(m_graph->seriesList().length(), 0); |
| 262 | |
| 263 | delete series; |
| 264 | delete series2; |
| 265 | delete series3; |
| 266 | } |
| 267 | |
| 268 | QTEST_MAIN(tst_surface) |
| 269 | #include "tst_surface.moc" |
| 270 | |