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/QHeightMapSurfaceDataProxy> |
33 | |
34 | using namespace QtDataVisualization; |
35 | |
36 | class tst_proxy: 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 | QHeightMapSurfaceDataProxy *m_proxy; |
54 | }; |
55 | |
56 | void tst_proxy::initTestCase() |
57 | { |
58 | } |
59 | |
60 | void tst_proxy::cleanupTestCase() |
61 | { |
62 | } |
63 | |
64 | void tst_proxy::init() |
65 | { |
66 | m_proxy = new QHeightMapSurfaceDataProxy(); |
67 | } |
68 | |
69 | void tst_proxy::cleanup() |
70 | { |
71 | delete m_proxy; |
72 | } |
73 | |
74 | void tst_proxy::construct() |
75 | { |
76 | QHeightMapSurfaceDataProxy *proxy = new QHeightMapSurfaceDataProxy(); |
77 | QVERIFY(proxy); |
78 | delete proxy; |
79 | |
80 | QImage image(QSize(10, 10), QImage::Format_ARGB32); |
81 | image.fill(pixel: 0); |
82 | proxy = new QHeightMapSurfaceDataProxy(image); |
83 | QSignalSpy spy(proxy, SIGNAL(columnCountChanged(int))); |
84 | QVERIFY(proxy); |
85 | spy.wait(timeout: 1000); |
86 | QCOMPARE(proxy->columnCount(), 10); |
87 | QCOMPARE(proxy->rowCount(), 10); |
88 | delete proxy; |
89 | |
90 | proxy = new QHeightMapSurfaceDataProxy(":/customtexture.jpg" ); |
91 | QVERIFY(proxy); |
92 | spy.wait(timeout: 1000); |
93 | QCOMPARE(proxy->columnCount(), 24); |
94 | QCOMPARE(proxy->rowCount(), 24); |
95 | delete proxy; |
96 | } |
97 | |
98 | void tst_proxy::initialProperties() |
99 | { |
100 | QVERIFY(m_proxy); |
101 | |
102 | QCOMPARE(m_proxy->heightMap(), QImage()); |
103 | QCOMPARE(m_proxy->heightMapFile(), QString("" )); |
104 | QCOMPARE(m_proxy->maxXValue(), 10.0f); |
105 | QCOMPARE(m_proxy->maxZValue(), 10.0f); |
106 | QCOMPARE(m_proxy->minXValue(), 0.0f); |
107 | QCOMPARE(m_proxy->minZValue(), 0.0f); |
108 | |
109 | QCOMPARE(m_proxy->columnCount(), 0); |
110 | QCOMPARE(m_proxy->rowCount(), 0); |
111 | QVERIFY(!m_proxy->series()); |
112 | |
113 | QCOMPARE(m_proxy->type(), QAbstractDataProxy::DataTypeSurface); |
114 | } |
115 | |
116 | void tst_proxy::initializeProperties() |
117 | { |
118 | QVERIFY(m_proxy); |
119 | |
120 | m_proxy->setHeightMapFile(":/customtexture.jpg" ); |
121 | m_proxy->setMaxXValue(11.0f); |
122 | m_proxy->setMaxZValue(11.0f); |
123 | m_proxy->setMinXValue(-10.0f); |
124 | m_proxy->setMinZValue(-10.0f); |
125 | |
126 | QCoreApplication::processEvents(); |
127 | |
128 | QCOMPARE(m_proxy->heightMapFile(), QString(":/customtexture.jpg" )); |
129 | QCOMPARE(m_proxy->maxXValue(), 11.0f); |
130 | QCOMPARE(m_proxy->maxZValue(), 11.0f); |
131 | QCOMPARE(m_proxy->minXValue(), -10.0f); |
132 | QCOMPARE(m_proxy->minZValue(), -10.0f); |
133 | |
134 | QCOMPARE(m_proxy->columnCount(), 24); |
135 | QCOMPARE(m_proxy->rowCount(), 24); |
136 | |
137 | m_proxy->setHeightMapFile("" ); |
138 | |
139 | QCoreApplication::processEvents(); |
140 | |
141 | QCOMPARE(m_proxy->columnCount(), 0); |
142 | QCOMPARE(m_proxy->rowCount(), 0); |
143 | |
144 | m_proxy->setHeightMap(QImage(":/customtexture.jpg" )); |
145 | |
146 | QCoreApplication::processEvents(); |
147 | |
148 | QCOMPARE(m_proxy->columnCount(), 24); |
149 | QCOMPARE(m_proxy->rowCount(), 24); |
150 | } |
151 | |
152 | void tst_proxy::invalidProperties() |
153 | { |
154 | m_proxy->setMaxXValue(-10.0f); |
155 | m_proxy->setMaxZValue(-10.0f); |
156 | QCOMPARE(m_proxy->maxXValue(), -10.0f); |
157 | QCOMPARE(m_proxy->maxZValue(), -10.0f); |
158 | QCOMPARE(m_proxy->minXValue(), -11.0f); |
159 | QCOMPARE(m_proxy->minZValue(), -11.0f); |
160 | |
161 | m_proxy->setMinXValue(10.0f); |
162 | m_proxy->setMinZValue(10.0f); |
163 | QCOMPARE(m_proxy->maxXValue(), 11.0f); |
164 | QCOMPARE(m_proxy->maxZValue(), 11.0f); |
165 | QCOMPARE(m_proxy->minXValue(), 10.0f); |
166 | QCOMPARE(m_proxy->minZValue(), 10.0f); |
167 | } |
168 | |
169 | QTEST_MAIN(tst_proxy) |
170 | #include "tst_proxy.moc" |
171 | |