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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QtTest>
#include <QtGraphs/QHeightMapSurfaceDataProxy>
#include <QtGraphs/QSurface3DSeries>
class tst_proxy: public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
void construct();
void initialProperties();
void initializeProperties();
void invalidProperties();
private:
QHeightMapSurfaceDataProxy *m_proxy;
QSurface3DSeries *m_series;
};
void tst_proxy::initTestCase()
{
}
void tst_proxy::cleanupTestCase()
{
}
void tst_proxy::init()
{
m_proxy = new QHeightMapSurfaceDataProxy();
m_series = new QSurface3DSeries(m_proxy);
}
void tst_proxy::cleanup()
{
delete m_series;
m_proxy = 0;
}
void tst_proxy::construct()
{
QHeightMapSurfaceDataProxy *proxy = new QHeightMapSurfaceDataProxy();
QSurface3DSeries *series = new QSurface3DSeries(proxy);
QVERIFY(proxy);
QVERIFY(series);
delete series;
proxy = 0;
QImage image(QSize(10, 10), QImage::Format_ARGB32);
image.fill(0);
proxy = new QHeightMapSurfaceDataProxy(image);
series = new QSurface3DSeries(proxy);
QCoreApplication::processEvents();
QVERIFY(proxy);
QVERIFY(series);
QCoreApplication::processEvents();
QCOMPARE(proxy->columnCount(), 10);
QCOMPARE(proxy->rowCount(), 10);
delete series;
proxy = 0;
proxy = new QHeightMapSurfaceDataProxy(":/customtexture.jpg");
series = new QSurface3DSeries(proxy);
QCoreApplication::processEvents();
QVERIFY(proxy);
QVERIFY(series);
QCoreApplication::processEvents();
QCOMPARE(proxy->columnCount(), 24);
QCOMPARE(proxy->rowCount(), 24);
delete series;
proxy = 0;
}
void tst_proxy::initialProperties()
{
QVERIFY(m_proxy);
QVERIFY(m_series);
QCOMPARE(m_proxy->heightMap(), QImage());
QCOMPARE(m_proxy->heightMapFile(), QString(""));
QCOMPARE(m_proxy->maxXValue(), 10.0f);
QCOMPARE(m_proxy->maxZValue(), 10.0f);
QCOMPARE(m_proxy->minXValue(), 0.0f);
QCOMPARE(m_proxy->minZValue(), 0.0f);
QCOMPARE(m_proxy->columnCount(), 0);
QCOMPARE(m_proxy->rowCount(), 0);
QCOMPARE(m_proxy->type(), QAbstractDataProxy::DataType::Surface);
}
void tst_proxy::initializeProperties()
{
QVERIFY(m_proxy);
QVERIFY(m_series);
QSignalSpy heightMapSpy(m_proxy, &QHeightMapSurfaceDataProxy::heightMapChanged);
QSignalSpy heightMapFileSpy(m_proxy, &QHeightMapSurfaceDataProxy::heightMapFileChanged);
QSignalSpy minXValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::minXValueChanged);
QSignalSpy maxXValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::maxXValueChanged);
QSignalSpy minYValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::minYValueChanged);
QSignalSpy maxYValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::maxYValueChanged);
QSignalSpy minZValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::minZValueChanged);
QSignalSpy maxZValueSpy(m_proxy, &QHeightMapSurfaceDataProxy::maxZValueChanged);
m_proxy->setHeightMapFile(":/customtexture.jpg");
m_proxy->setMaxXValue(11.0f);
m_proxy->setMaxZValue(11.0f);
m_proxy->setMinXValue(-10.0f);
m_proxy->setMinZValue(-10.0f);
m_proxy->setMinYValue(-10.0f);
m_proxy->setMaxYValue(11.0f);
QCoreApplication::processEvents();
QCOMPARE(m_proxy->heightMapFile(), QString(":/customtexture.jpg"));
QCOMPARE(m_proxy->maxXValue(), 11.0f);
QCOMPARE(m_proxy->maxZValue(), 11.0f);
QCOMPARE(m_proxy->minXValue(), -10.0f);
QCOMPARE(m_proxy->minZValue(), -10.0f);
QCOMPARE(m_proxy->columnCount(), 24);
QCOMPARE(m_proxy->rowCount(), 24);
QCOMPARE(heightMapFileSpy.size(), 1);
QCOMPARE(minXValueSpy.size(), 1);
QCOMPARE(minZValueSpy.size(), 1);
QCOMPARE(maxXValueSpy.size(), 1);
QCOMPARE(maxZValueSpy.size(), 1);
QCOMPARE(minYValueSpy.size(), 1);
QCOMPARE(maxYValueSpy.size(), 1);
m_proxy->setHeightMapFile("");
QCoreApplication::processEvents();
QCOMPARE(m_proxy->columnCount(), 0);
QCOMPARE(m_proxy->rowCount(), 0);
m_proxy->setHeightMap(QImage(":/customtexture.jpg"));
QCoreApplication::processEvents();
QCOMPARE(m_proxy->columnCount(), 24);
QCOMPARE(m_proxy->rowCount(), 24);
QCOMPARE(heightMapSpy.size(), 3);
QCOMPARE(heightMapFileSpy.size(), 2);
}
void tst_proxy::invalidProperties()
{
#ifdef Q_CC_MSVC
QTest::ignoreMessage(QtWarningMsg, "QHeightMapSurfaceDataProxy::setHeightMapFile height map file"
" :/nonexistenttexture.jpg does not exist.");
QTest::ignoreMessage(QtWarningMsg, "QHeightMapSurfaceDataProxyPrivate::setMaxXValue tried to set"
" maximum X to equal or smaller than minimum X for value range."
" Minimum automatically adjusted to a valid one: 0.000000 --> -11.000000");
QTest::ignoreMessage(QtWarningMsg, "QHeightMapSurfaceDataProxyPrivate::setMaxZValue tried to set"
" maximum Z to equal or smaller than minimum Z for value range."
" Minimum automatically adjusted to a valid one: 0.000000 --> -11.000000");
QTest::ignoreMessage(QtWarningMsg, "QHeightMapSurfaceDataProxyPrivate::setMinXValue tried to set"
" minimum X to equal or larger than maximum X for value range."
" Maximum automatically adjusted to a valid one: -10.000000 --> 11.000000");
QTest::ignoreMessage(QtWarningMsg, "QHeightMapSurfaceDataProxyPrivate::setMinZValue tried to set"
" minimum Z to equal or larger than maximum Z for value range."
" Maximum automatically adjusted to a valid one: -10.000000 --> 11.000000");
#else
QTest::ignoreMessage(QtWarningMsg, "setHeightMapFile height map file"
" :/nonexistenttexture.jpg does not exist.");
QTest::ignoreMessage(QtWarningMsg, "setMaxXValue tried to set"
" maximum X to equal or smaller than minimum X for value range."
" Minimum automatically adjusted to a valid one: 0.000000 --> -11.000000");
QTest::ignoreMessage(QtWarningMsg, "setMaxZValue tried to set"
" maximum Z to equal or smaller than minimum Z for value range."
" Minimum automatically adjusted to a valid one: 0.000000 --> -11.000000");
QTest::ignoreMessage(QtWarningMsg, "setMinXValue tried to set"
" minimum X to equal or larger than maximum X for value range."
" Maximum automatically adjusted to a valid one: -10.000000 --> 11.000000");
QTest::ignoreMessage(QtWarningMsg, "setMinZValue tried to set"
" minimum Z to equal or larger than maximum Z for value range."
" Maximum automatically adjusted to a valid one: -10.000000 --> 11.000000");
#endif
m_proxy->setHeightMapFile(":/nonexistenttexture.jpg");
QEXPECT_FAIL("", "Nonexistent file given", Continue);
QCOMPARE(m_proxy->heightMapFile(), QString(":/nonexistenttexture.jpg"));
m_proxy->setMaxXValue(-10.0f);
m_proxy->setMaxZValue(-10.0f);
QCOMPARE(m_proxy->maxXValue(), -10.0f);
QCOMPARE(m_proxy->maxZValue(), -10.0f);
QCOMPARE(m_proxy->minXValue(), -11.0f);
QCOMPARE(m_proxy->minZValue(), -11.0f);
m_proxy->setMinXValue(10.0f);
m_proxy->setMinZValue(10.0f);
QCOMPARE(m_proxy->maxXValue(), 11.0f);
QCOMPARE(m_proxy->maxZValue(), 11.0f);
QCOMPARE(m_proxy->minXValue(), 10.0f);
QCOMPARE(m_proxy->minZValue(), 10.0f);
}
QTEST_MAIN(tst_proxy)
#include "tst_proxy.moc"
|