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/QCustom3DVolume> |
33 | |
34 | using namespace QtDataVisualization; |
35 | |
36 | class tst_custom: 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 | private: |
53 | QCustom3DVolume *m_custom; |
54 | }; |
55 | |
56 | void tst_custom::initTestCase() |
57 | { |
58 | } |
59 | |
60 | void tst_custom::cleanupTestCase() |
61 | { |
62 | } |
63 | |
64 | void tst_custom::init() |
65 | { |
66 | m_custom = new QCustom3DVolume(); |
67 | } |
68 | |
69 | void tst_custom::cleanup() |
70 | { |
71 | delete m_custom; |
72 | } |
73 | |
74 | void tst_custom::construct() |
75 | { |
76 | QCustom3DVolume *custom = new QCustom3DVolume(); |
77 | QVERIFY(custom); |
78 | delete custom; |
79 | |
80 | QVector<uchar> *tdata = new QVector<uchar>(1000); |
81 | |
82 | QVector<QRgb> table; |
83 | table << QRgb(0xff00ff) << QRgb(0x00ff00); |
84 | |
85 | custom = new QCustom3DVolume(QVector3D(1.0, 1.0, 1.0), QVector3D(1.0, 1.0, 1.0), |
86 | QQuaternion(1.0, 1.0, 10.0, 100.0), 10, 10, 10, |
87 | tdata, QImage::Format_ARGB32, table); |
88 | QVERIFY(custom); |
89 | QCOMPARE(custom->alphaMultiplier(), 1.0f); |
90 | QCOMPARE(custom->drawSliceFrames(), false); |
91 | QCOMPARE(custom->drawSliceFrames(), false); |
92 | QCOMPARE(custom->preserveOpacity(), true); |
93 | QCOMPARE(custom->sliceFrameColor(), QColor(Qt::black)); |
94 | QCOMPARE(custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); |
95 | QCOMPARE(custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); |
96 | QCOMPARE(custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); |
97 | QCOMPARE(custom->sliceIndexX(), -1); |
98 | QCOMPARE(custom->sliceIndexY(), -1); |
99 | QCOMPARE(custom->sliceIndexZ(), -1); |
100 | QCOMPARE(custom->useHighDefShader(), true); |
101 | QCOMPARE(custom->textureData()->length(), 1000); |
102 | QCOMPARE(custom->textureDataWidth(), 40); |
103 | QCOMPARE(custom->textureFormat(), QImage::Format_ARGB32); |
104 | QCOMPARE(custom->textureHeight(), 10); |
105 | QCOMPARE(custom->textureWidth(), 10); |
106 | QCOMPARE(custom->textureDepth(), 10); |
107 | QCOMPARE(custom->meshFile(), QString(":/defaultMeshes/barFull" )); |
108 | QCOMPARE(custom->position(), QVector3D(1.0, 1.0, 1.0)); |
109 | QCOMPARE(custom->isPositionAbsolute(), false); |
110 | QCOMPARE(custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); |
111 | QCOMPARE(custom->scaling(), QVector3D(1.0, 1.0, 1.0)); |
112 | QCOMPARE(custom->isScalingAbsolute(), true); |
113 | QCOMPARE(custom->isShadowCasting(), false); |
114 | QCOMPARE(custom->textureFile(), QString()); |
115 | QCOMPARE(custom->isVisible(), true); |
116 | delete custom; |
117 | } |
118 | |
119 | void tst_custom::initialProperties() |
120 | { |
121 | QVERIFY(m_custom); |
122 | |
123 | QCOMPARE(m_custom->alphaMultiplier(), 1.0f); |
124 | QCOMPARE(m_custom->drawSliceFrames(), false); |
125 | QCOMPARE(m_custom->drawSliceFrames(), false); |
126 | QCOMPARE(m_custom->preserveOpacity(), true); |
127 | QCOMPARE(m_custom->sliceFrameColor(), QColor(Qt::black)); |
128 | QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); |
129 | QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); |
130 | QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); |
131 | QCOMPARE(m_custom->sliceIndexX(), -1); |
132 | QCOMPARE(m_custom->sliceIndexY(), -1); |
133 | QCOMPARE(m_custom->sliceIndexZ(), -1); |
134 | QCOMPARE(m_custom->useHighDefShader(), true); |
135 | |
136 | // Common (from QCustom3DVolume) |
137 | QCOMPARE(m_custom->meshFile(), QString(":/defaultMeshes/barFull" )); |
138 | QCOMPARE(m_custom->position(), QVector3D()); |
139 | QCOMPARE(m_custom->isPositionAbsolute(), false); |
140 | QCOMPARE(m_custom->rotation(), QQuaternion()); |
141 | QCOMPARE(m_custom->scaling(), QVector3D(0.1f, 0.1f, 0.1f)); |
142 | QCOMPARE(m_custom->isScalingAbsolute(), true); |
143 | QCOMPARE(m_custom->isShadowCasting(), true); |
144 | QCOMPARE(m_custom->textureFile(), QString()); |
145 | QCOMPARE(m_custom->isVisible(), true); |
146 | } |
147 | |
148 | void tst_custom::initializeProperties() |
149 | { |
150 | QVERIFY(m_custom); |
151 | |
152 | m_custom->setAlphaMultiplier(0.1f); |
153 | m_custom->setDrawSliceFrames(true); |
154 | m_custom->setDrawSliceFrames(true); |
155 | m_custom->setPreserveOpacity(false); |
156 | m_custom->setSliceFrameColor(QColor(Qt::red)); |
157 | m_custom->setSliceFrameGaps(QVector3D(2.0f, 2.0f, 2.0f)); |
158 | m_custom->setSliceFrameThicknesses(QVector3D(2.0f, 2.0f, 2.0f)); |
159 | m_custom->setSliceFrameWidths(QVector3D(2.0f, 2.0f, 2.0f)); |
160 | m_custom->setSliceIndexX(0); |
161 | m_custom->setSliceIndexY(0); |
162 | m_custom->setSliceIndexZ(0); |
163 | m_custom->setUseHighDefShader(false); |
164 | |
165 | QCOMPARE(m_custom->alphaMultiplier(), 0.1f); |
166 | QCOMPARE(m_custom->drawSliceFrames(), true); |
167 | QCOMPARE(m_custom->drawSliceFrames(), true); |
168 | QCOMPARE(m_custom->preserveOpacity(), false); |
169 | QCOMPARE(m_custom->sliceFrameColor(), QColor(Qt::red)); |
170 | QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(2.0f, 2.0f, 2.0f)); |
171 | QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(2.0f, 2.0f, 2.0f)); |
172 | QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(2.0f, 2.0f, 2.0f)); |
173 | QCOMPARE(m_custom->sliceIndexX(), 0); |
174 | QCOMPARE(m_custom->sliceIndexY(), 0); |
175 | QCOMPARE(m_custom->sliceIndexZ(), 0); |
176 | QCOMPARE(m_custom->useHighDefShader(), false); |
177 | |
178 | // Common (from QCustom3DVolume) |
179 | m_custom->setPosition(QVector3D(1.0, 1.0, 1.0)); |
180 | m_custom->setPositionAbsolute(true); |
181 | m_custom->setRotation(QQuaternion(1.0, 1.0, 10.0, 100.0)); |
182 | m_custom->setScaling(QVector3D(1.0, 1.0, 1.0)); |
183 | m_custom->setScalingAbsolute(false); |
184 | m_custom->setShadowCasting(false); |
185 | m_custom->setVisible(false); |
186 | |
187 | QCOMPARE(m_custom->position(), QVector3D(1.0, 1.0, 1.0)); |
188 | QCOMPARE(m_custom->isPositionAbsolute(), true); |
189 | QCOMPARE(m_custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); |
190 | QCOMPARE(m_custom->scaling(), QVector3D(1.0, 1.0, 1.0)); |
191 | QCOMPARE(m_custom->isScalingAbsolute(), false); |
192 | QCOMPARE(m_custom->isShadowCasting(), false); |
193 | QCOMPARE(m_custom->isVisible(), false); |
194 | } |
195 | |
196 | void tst_custom::invalidProperties() |
197 | { |
198 | m_custom->setAlphaMultiplier(-1.0f); |
199 | QCOMPARE(m_custom->alphaMultiplier(), 1.0f); |
200 | |
201 | m_custom->setSliceFrameGaps(QVector3D(-0.1f, -0.1f, -0.1f)); |
202 | QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); |
203 | |
204 | m_custom->setSliceFrameThicknesses(QVector3D(-0.1f, -0.1f, -0.1f)); |
205 | QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); |
206 | |
207 | m_custom->setSliceFrameWidths(QVector3D(-0.1f, -0.1f, -0.1f)); |
208 | QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); |
209 | |
210 | m_custom->setTextureFormat(QImage::Format_ARGB8555_Premultiplied); |
211 | QCOMPARE(m_custom->textureFormat(), QImage::Format_ARGB32); |
212 | } |
213 | |
214 | QTEST_MAIN(tst_custom) |
215 | #include "tst_custom.moc" |
216 | |