From f7f1e1373e652ea2de1666f4b626bf35e367d84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 21 Oct 2014 11:05:45 +0300 Subject: Added C++ autotests for series Also fixed a bug found in testing, and added tests for optional constructors for already tested classes. Task-number: QTRD-3368 Change-Id: I2214f28e2c5069ecab422fc6817acb2f0c0b192b Reviewed-by: Miikka Heikkinen --- .../auto/cpptest/q3dbars-modelproxy/tst_proxy.cpp | 58 +++++++++++++++ tests/auto/cpptest/q3dbars-series/tst_series.cpp | 84 ++++++++++++++++++++++ tests/auto/cpptest/q3dbars/tst_bars.cpp | 4 ++ .../cpptest/q3dscatter-modelproxy/tst_proxy.cpp | 22 ++++++ .../auto/cpptest/q3dscatter-series/tst_series.cpp | 33 +++++++-- tests/auto/cpptest/q3dscatter/tst_scatter.cpp | 4 ++ .../cpptest/q3dsurface-heightproxy/tst_proxy.cpp | 14 ++++ .../cpptest/q3dsurface-modelproxy/tst_proxy.cpp | 64 +++++++++++++++++ .../auto/cpptest/q3dsurface-series/tst_series.cpp | 35 +++++++++ tests/auto/cpptest/q3dsurface/tst_surface.cpp | 4 ++ 10 files changed, 318 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/cpptest/q3dbars-modelproxy/tst_proxy.cpp b/tests/auto/cpptest/q3dbars-modelproxy/tst_proxy.cpp index b3661b91..c65e151b 100644 --- a/tests/auto/cpptest/q3dbars-modelproxy/tst_proxy.cpp +++ b/tests/auto/cpptest/q3dbars-modelproxy/tst_proxy.cpp @@ -68,6 +68,64 @@ void tst_proxy::construct() QItemModelBarDataProxy *proxy = new QItemModelBarDataProxy(); QVERIFY(proxy); delete proxy; + + QTableWidget *table = new QTableWidget(); + + proxy = new QItemModelBarDataProxy(table->model()); + QVERIFY(proxy); + delete proxy; + + proxy = new QItemModelBarDataProxy(table->model(), "val"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("")); + QCOMPARE(proxy->columnRole(), QString("")); + QCOMPARE(proxy->valueRole(), QString("val")); + QCOMPARE(proxy->rotationRole(), QString("")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelBarDataProxy(table->model(), "row", "col", "val"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("col")); + QCOMPARE(proxy->valueRole(), QString("val")); + QCOMPARE(proxy->rotationRole(), QString("")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelBarDataProxy(table->model(), "row", "col", "val", "rot"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("col")); + QCOMPARE(proxy->valueRole(), QString("val")); + QCOMPARE(proxy->rotationRole(), QString("rot")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelBarDataProxy(table->model(), "row", "col", "val", + QStringList() << "rowCat", QStringList() << "colCat"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("col")); + QCOMPARE(proxy->valueRole(), QString("val")); + QCOMPARE(proxy->rotationRole(), QString("")); + QCOMPARE(proxy->rowCategories().length(), 1); + QCOMPARE(proxy->columnCategories().length(), 1); + delete proxy; + + proxy = new QItemModelBarDataProxy(table->model(), "row", "col", "val", "rot", + QStringList() << "rowCat", QStringList() << "colCat"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("col")); + QCOMPARE(proxy->valueRole(), QString("val")); + QCOMPARE(proxy->rotationRole(), QString("rot")); + QCOMPARE(proxy->rowCategories().length(), 1); + QCOMPARE(proxy->columnCategories().length(), 1); + delete proxy; } void tst_proxy::initialProperties() diff --git a/tests/auto/cpptest/q3dbars-series/tst_series.cpp b/tests/auto/cpptest/q3dbars-series/tst_series.cpp index 706baf94..e2a40ae7 100644 --- a/tests/auto/cpptest/q3dbars-series/tst_series.cpp +++ b/tests/auto/cpptest/q3dbars-series/tst_series.cpp @@ -65,20 +65,104 @@ void tst_series::construct() QBar3DSeries *series = new QBar3DSeries(); QVERIFY(series); delete series; + + QBarDataProxy *proxy = new QBarDataProxy(); + + series = new QBar3DSeries(proxy); + QVERIFY(series); + QCOMPARE(series->dataProxy(), proxy); + delete series; } void tst_series::initialProperties() { QVERIFY(m_series); + + QVERIFY(m_series->dataProxy()); + QCOMPARE(m_series->meshAngle(), 0.0f); + QCOMPARE(m_series->selectedBar(), m_series->invalidSelectionPosition()); + + // Common properties + QCOMPARE(m_series->baseColor(), QColor(Qt::black)); + QCOMPARE(m_series->baseGradient(), QLinearGradient()); + QCOMPARE(m_series->colorStyle(), Q3DTheme::ColorStyleUniform); + QCOMPARE(m_series->itemLabel(), QString("")); + QCOMPARE(m_series->itemLabelFormat(), QString("@valueLabel")); + QCOMPARE(m_series->isItemLabelVisible(), true); + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshBevelBar); + QCOMPARE(m_series->meshRotation(), QQuaternion(1, 0, 0, 0)); + QCOMPARE(m_series->isMeshSmooth(), false); + QCOMPARE(m_series->multiHighlightColor(), QColor(Qt::black)); + QCOMPARE(m_series->multiHighlightGradient(), QLinearGradient()); + QCOMPARE(m_series->name(), QString("")); + QCOMPARE(m_series->singleHighlightColor(), QColor(Qt::black)); + QCOMPARE(m_series->singleHighlightGradient(), QLinearGradient()); + QCOMPARE(m_series->type(), QAbstract3DSeries::SeriesTypeBar); + QCOMPARE(m_series->userDefinedMesh(), QString("")); + QCOMPARE(m_series->isVisible(), true); } void tst_series::initializeProperties() { QVERIFY(m_series); + + m_series->setDataProxy(new QBarDataProxy()); + m_series->setMeshAngle(15.0f); + m_series->setSelectedBar(QPoint(0, 0)); + + QCOMPARE(m_series->meshAngle(), 15.0f); + QCOMPARE(m_series->selectedBar(), QPoint(0, 0)); + + QLinearGradient gradient1; + gradient1.setColorAt(0.0, Qt::red); + gradient1.setColorAt(1.0, Qt::blue); + QLinearGradient gradient2; + gradient2.setColorAt(0.0, Qt::yellow); + gradient2.setColorAt(1.0, Qt::green); + QLinearGradient gradient3; + gradient3.setColorAt(0.0, Qt::white); + gradient3.setColorAt(1.0, Qt::gray); + + // Common properties + m_series->setBaseColor(QColor(Qt::blue)); + m_series->setBaseGradient(gradient1); + m_series->setColorStyle(Q3DTheme::ColorStyleRangeGradient); + m_series->setItemLabelFormat("%f"); + m_series->setItemLabelVisible(false); + m_series->setMesh(QAbstract3DSeries::MeshCone); + m_series->setMeshSmooth(true); + m_series->setMultiHighlightColor(QColor(Qt::green)); + m_series->setMultiHighlightGradient(gradient2); + m_series->setName("name"); + m_series->setSingleHighlightColor(QColor(Qt::red)); + m_series->setSingleHighlightGradient(gradient3); + m_series->setUserDefinedMesh(":/customitem.obj"); + m_series->setVisible(false); + + QCOMPARE(m_series->baseColor(), QColor(Qt::blue)); + QCOMPARE(m_series->baseGradient(), gradient1); + QCOMPARE(m_series->baseGradient().stops().at(0).second, QColor(Qt::red)); + QCOMPARE(m_series->colorStyle(), Q3DTheme::ColorStyleRangeGradient); + QCOMPARE(m_series->itemLabelFormat(), QString("%f")); + QCOMPARE(m_series->isItemLabelVisible(), false); + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshCone); + QCOMPARE(m_series->isMeshSmooth(), true); + QCOMPARE(m_series->multiHighlightColor(), QColor(Qt::green)); + QCOMPARE(m_series->multiHighlightGradient(), gradient2); + QCOMPARE(m_series->multiHighlightGradient().stops().at(0).second, QColor(Qt::yellow)); + QCOMPARE(m_series->name(), QString("name")); + QCOMPARE(m_series->singleHighlightColor(), QColor(Qt::red)); + QCOMPARE(m_series->singleHighlightGradient(), gradient3); + QCOMPARE(m_series->singleHighlightGradient().stops().at(0).second, QColor(Qt::white)); + QCOMPARE(m_series->userDefinedMesh(), QString(":/customitem.obj")); + QCOMPARE(m_series->isVisible(), false); } void tst_series::invalidProperties() { + m_series->setMesh(QAbstract3DSeries::MeshMinimal); + + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshBevelBar); } QTEST_MAIN(tst_series) diff --git a/tests/auto/cpptest/q3dbars/tst_bars.cpp b/tests/auto/cpptest/q3dbars/tst_bars.cpp index 630afac3..4535c026 100644 --- a/tests/auto/cpptest/q3dbars/tst_bars.cpp +++ b/tests/auto/cpptest/q3dbars/tst_bars.cpp @@ -95,6 +95,10 @@ void tst_bars::construct() Q3DBars *graph = new Q3DBars(); QVERIFY(graph); delete graph; + + graph = new Q3DBars(new QSurfaceFormat()); + QVERIFY(graph); + delete graph; } void tst_bars::initialProperties() diff --git a/tests/auto/cpptest/q3dscatter-modelproxy/tst_proxy.cpp b/tests/auto/cpptest/q3dscatter-modelproxy/tst_proxy.cpp index dcb0b1fb..9d5cea90 100644 --- a/tests/auto/cpptest/q3dscatter-modelproxy/tst_proxy.cpp +++ b/tests/auto/cpptest/q3dscatter-modelproxy/tst_proxy.cpp @@ -68,6 +68,28 @@ void tst_proxy::construct() QItemModelScatterDataProxy *proxy = new QItemModelScatterDataProxy(); QVERIFY(proxy); delete proxy; + + QTableWidget *table = new QTableWidget(); + + proxy = new QItemModelScatterDataProxy(table->model()); + QVERIFY(proxy); + delete proxy; + + proxy = new QItemModelScatterDataProxy(table->model(), "x", "y", "z"); + QVERIFY(proxy); + QCOMPARE(proxy->xPosRole(), QString("x")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("z")); + QCOMPARE(proxy->rotationRole(), QString("")); + delete proxy; + + proxy = new QItemModelScatterDataProxy(table->model(), "x", "y", "z", "rot"); + QVERIFY(proxy); + QCOMPARE(proxy->xPosRole(), QString("x")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("z")); + QCOMPARE(proxy->rotationRole(), QString("rot")); + delete proxy; } void tst_proxy::initialProperties() diff --git a/tests/auto/cpptest/q3dscatter-series/tst_series.cpp b/tests/auto/cpptest/q3dscatter-series/tst_series.cpp index 80db0ac8..df290579 100644 --- a/tests/auto/cpptest/q3dscatter-series/tst_series.cpp +++ b/tests/auto/cpptest/q3dscatter-series/tst_series.cpp @@ -36,7 +36,6 @@ private slots: void initialProperties(); void initializeProperties(); - void invalidProperties(); private: QScatter3DSeries *m_series; @@ -65,20 +64,46 @@ void tst_series::construct() QScatter3DSeries *series = new QScatter3DSeries(); QVERIFY(series); delete series; + + QScatterDataProxy *proxy = new QScatterDataProxy(); + + series = new QScatter3DSeries(proxy); + QVERIFY(series); + QCOMPARE(series->dataProxy(), proxy); + delete series; } void tst_series::initialProperties() { QVERIFY(m_series); + + QVERIFY(m_series->dataProxy()); + QCOMPARE(m_series->itemSize(), 0.0f); + QCOMPARE(m_series->selectedItem(), m_series->invalidSelectionIndex()); + + // Common properties. The ones identical between different series are tested in QBar3DSeries tests + QCOMPARE(m_series->itemLabelFormat(), QString("@xLabel, @yLabel, @zLabel")); + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshSphere); + QCOMPARE(m_series->type(), QAbstract3DSeries::SeriesTypeScatter); } void tst_series::initializeProperties() { QVERIFY(m_series); -} -void tst_series::invalidProperties() -{ + m_series->setDataProxy(new QScatterDataProxy()); + m_series->setItemSize(0.5f); + m_series->setSelectedItem(0); + + QCOMPARE(m_series->itemSize(), 0.5f); + QCOMPARE(m_series->selectedItem(), 0); + + // Common properties. The ones identical between different series are tested in QBar3DSeries tests + m_series->setMesh(QAbstract3DSeries::MeshPoint); + m_series->setMeshRotation(QQuaternion(1, 1, 10, 20)); + + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshPoint); + QCOMPARE(m_series->meshRotation(), QQuaternion(1, 1, 10, 20)); } QTEST_MAIN(tst_series) diff --git a/tests/auto/cpptest/q3dscatter/tst_scatter.cpp b/tests/auto/cpptest/q3dscatter/tst_scatter.cpp index 0bbc2122..89057788 100644 --- a/tests/auto/cpptest/q3dscatter/tst_scatter.cpp +++ b/tests/auto/cpptest/q3dscatter/tst_scatter.cpp @@ -80,6 +80,10 @@ void tst_scatter::construct() Q3DScatter *graph = new Q3DScatter(); QVERIFY(graph); delete graph; + + graph = new Q3DScatter(new QSurfaceFormat()); + QVERIFY(graph); + delete graph; } void tst_scatter::initialProperties() diff --git a/tests/auto/cpptest/q3dsurface-heightproxy/tst_proxy.cpp b/tests/auto/cpptest/q3dsurface-heightproxy/tst_proxy.cpp index 8e998568..20ed1aeb 100644 --- a/tests/auto/cpptest/q3dsurface-heightproxy/tst_proxy.cpp +++ b/tests/auto/cpptest/q3dsurface-heightproxy/tst_proxy.cpp @@ -65,6 +65,20 @@ void tst_proxy::construct() QHeightMapSurfaceDataProxy *proxy = new QHeightMapSurfaceDataProxy(); QVERIFY(proxy); delete proxy; + + proxy = new QHeightMapSurfaceDataProxy(QImage(QSize(10, 10), QImage::Format_ARGB32)); + QVERIFY(proxy); + QCoreApplication::processEvents(); + QCOMPARE(proxy->columnCount(), 10); + QCOMPARE(proxy->rowCount(), 10); + delete proxy; + + proxy = new QHeightMapSurfaceDataProxy(":/customtexture.jpg"); + QVERIFY(proxy); + QCoreApplication::processEvents(); + QCOMPARE(proxy->columnCount(), 24); + QCOMPARE(proxy->rowCount(), 24); + delete proxy; } void tst_proxy::initialProperties() diff --git a/tests/auto/cpptest/q3dsurface-modelproxy/tst_proxy.cpp b/tests/auto/cpptest/q3dsurface-modelproxy/tst_proxy.cpp index f7311ca1..6bef9478 100644 --- a/tests/auto/cpptest/q3dsurface-modelproxy/tst_proxy.cpp +++ b/tests/auto/cpptest/q3dsurface-modelproxy/tst_proxy.cpp @@ -63,11 +63,75 @@ void tst_proxy::cleanup() delete m_proxy; } + void tst_proxy::construct() { QItemModelSurfaceDataProxy *proxy = new QItemModelSurfaceDataProxy(); QVERIFY(proxy); delete proxy; + + QTableWidget *table = new QTableWidget(); + + proxy = new QItemModelSurfaceDataProxy(table->model()); + QVERIFY(proxy); + delete proxy; + + proxy = new QItemModelSurfaceDataProxy(table->model(), "y"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("")); + QCOMPARE(proxy->columnRole(), QString("")); + QCOMPARE(proxy->xPosRole(), QString("")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelSurfaceDataProxy(table->model(), "row", "column", "y"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("column")); + QCOMPARE(proxy->xPosRole(), QString("column")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("row")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelSurfaceDataProxy(table->model(), "row", "column", "x", "y", "z"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("column")); + QCOMPARE(proxy->xPosRole(), QString("x")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("z")); + QCOMPARE(proxy->rowCategories().length(), 0); + QCOMPARE(proxy->columnCategories().length(), 0); + delete proxy; + + proxy = new QItemModelSurfaceDataProxy(table->model(), "row", "column", "y", + QStringList() << "rowCat", QStringList() << "colCat"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("column")); + QCOMPARE(proxy->xPosRole(), QString("column")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("row")); + QCOMPARE(proxy->rowCategories().length(), 1); + QCOMPARE(proxy->columnCategories().length(), 1); + delete proxy; + + proxy = new QItemModelSurfaceDataProxy(table->model(), "row", "column", "x", "y", "z", + QStringList() << "rowCat", QStringList() << "colCat"); + QVERIFY(proxy); + QCOMPARE(proxy->rowRole(), QString("row")); + QCOMPARE(proxy->columnRole(), QString("column")); + QCOMPARE(proxy->xPosRole(), QString("x")); + QCOMPARE(proxy->yPosRole(), QString("y")); + QCOMPARE(proxy->zPosRole(), QString("z")); + QCOMPARE(proxy->rowCategories().length(), 1); + QCOMPARE(proxy->columnCategories().length(), 1); + delete proxy; } void tst_proxy::initialProperties() diff --git a/tests/auto/cpptest/q3dsurface-series/tst_series.cpp b/tests/auto/cpptest/q3dsurface-series/tst_series.cpp index 95c3a7df..50eed686 100644 --- a/tests/auto/cpptest/q3dsurface-series/tst_series.cpp +++ b/tests/auto/cpptest/q3dsurface-series/tst_series.cpp @@ -65,20 +65,55 @@ void tst_series::construct() QSurface3DSeries *series = new QSurface3DSeries(); QVERIFY(series); delete series; + + QSurfaceDataProxy *proxy = new QSurfaceDataProxy(); + + series = new QSurface3DSeries(proxy); + QVERIFY(series); + QCOMPARE(series->dataProxy(), proxy); + delete series; } void tst_series::initialProperties() { QVERIFY(m_series); + + QVERIFY(m_series->dataProxy()); + QCOMPARE(m_series->drawMode(), QSurface3DSeries::DrawSurfaceAndWireframe); + QCOMPARE(m_series->isFlatShadingEnabled(), true); + QCOMPARE(m_series->isFlatShadingSupported(), true); + QCOMPARE(m_series->selectedPoint(), m_series->invalidSelectionPosition()); + + // Common properties. The ones identical between different series are tested in QBar3DSeries tests + QCOMPARE(m_series->itemLabelFormat(), QString("@xLabel, @yLabel, @zLabel")); + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshSphere); + QCOMPARE(m_series->type(), QAbstract3DSeries::SeriesTypeSurface); } void tst_series::initializeProperties() { QVERIFY(m_series); + + m_series->setDataProxy(new QSurfaceDataProxy()); + m_series->setDrawMode(QSurface3DSeries::DrawWireframe); + m_series->setFlatShadingEnabled(false); + m_series->setSelectedPoint(QPoint(0, 0)); + + QCOMPARE(m_series->drawMode(), QSurface3DSeries::DrawWireframe); + QCOMPARE(m_series->isFlatShadingEnabled(), false); + QCOMPARE(m_series->selectedPoint(), QPoint(0, 0)); + + // Common properties. The ones identical between different series are tested in QBar3DSeries tests + m_series->setMesh(QAbstract3DSeries::MeshPyramid); + + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshPyramid); } void tst_series::invalidProperties() { + m_series->setMesh(QAbstract3DSeries::MeshPoint); + + QCOMPARE(m_series->mesh(), QAbstract3DSeries::MeshSphere); } QTEST_MAIN(tst_series) diff --git a/tests/auto/cpptest/q3dsurface/tst_surface.cpp b/tests/auto/cpptest/q3dsurface/tst_surface.cpp index 7b2d3ebb..600261d2 100644 --- a/tests/auto/cpptest/q3dsurface/tst_surface.cpp +++ b/tests/auto/cpptest/q3dsurface/tst_surface.cpp @@ -85,6 +85,10 @@ void tst_surface::construct() Q3DSurface *graph = new Q3DSurface(); QVERIFY(graph); delete graph; + + graph = new Q3DSurface(new QSurfaceFormat()); + QVERIFY(graph); + delete graph; } void tst_surface::initialProperties() -- cgit v1.2.3