From 14ba79846a1e8a63df47b374f7808ae2447c7e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Thu, 23 Oct 2014 07:51:19 +0300 Subject: Added C++ autotests for custom items, labels and volumes. Task-number: QTRD-3368 Change-Id: Ia6199669b0b70190de5a5d057c596093a051c1a9 Change-Id: Ia6199669b0b70190de5a5d057c596093a051c1a9 Reviewed-by: Miikka Heikkinen --- tests/auto/cpptest/cpptest.pro | 5 +- .../cpptest/q3dcustom-label/q3dcustom-label.pro | 8 + tests/auto/cpptest/q3dcustom-label/tst_custom.cpp | 158 ++++++++++++++++ .../cpptest/q3dcustom-volume/q3dcustom-volume.pro | 8 + tests/auto/cpptest/q3dcustom-volume/tst_custom.cpp | 204 +++++++++++++++++++++ tests/auto/cpptest/q3dcustom/q3dcustom.pro | 8 + tests/auto/cpptest/q3dcustom/tst_custom.cpp | 128 +++++++++++++ 7 files changed, 518 insertions(+), 1 deletion(-) create mode 100644 tests/auto/cpptest/q3dcustom-label/q3dcustom-label.pro create mode 100644 tests/auto/cpptest/q3dcustom-label/tst_custom.cpp create mode 100644 tests/auto/cpptest/q3dcustom-volume/q3dcustom-volume.pro create mode 100644 tests/auto/cpptest/q3dcustom-volume/tst_custom.cpp create mode 100644 tests/auto/cpptest/q3dcustom/q3dcustom.pro create mode 100644 tests/auto/cpptest/q3dcustom/tst_custom.cpp (limited to 'tests') diff --git a/tests/auto/cpptest/cpptest.pro b/tests/auto/cpptest/cpptest.pro index b3b9b076..abd8f38e 100644 --- a/tests/auto/cpptest/cpptest.pro +++ b/tests/auto/cpptest/cpptest.pro @@ -20,4 +20,7 @@ SUBDIRS = q3dbars \ q3dscene-light \ q3dtheme \ q3dinput \ - q3dinput-touch + q3dinput-touch \ + q3dcustom \ + q3dcustom-label \ + q3dcustom-volume diff --git a/tests/auto/cpptest/q3dcustom-label/q3dcustom-label.pro b/tests/auto/cpptest/q3dcustom-label/q3dcustom-label.pro new file mode 100644 index 00000000..af584baa --- /dev/null +++ b/tests/auto/cpptest/q3dcustom-label/q3dcustom-label.pro @@ -0,0 +1,8 @@ +QT += testlib datavisualization + +TARGET = tst_cpptest +CONFIG += console testcase + +TEMPLATE = app + +SOURCES += tst_custom.cpp diff --git a/tests/auto/cpptest/q3dcustom-label/tst_custom.cpp b/tests/auto/cpptest/q3dcustom-label/tst_custom.cpp new file mode 100644 index 00000000..40bd5eac --- /dev/null +++ b/tests/auto/cpptest/q3dcustom-label/tst_custom.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include + +#include + +using namespace QtDataVisualization; + +class tst_custom: public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + void construct(); + + void initialProperties(); + void initializeProperties(); + void invalidProperties(); + +private: + QCustom3DLabel *m_custom; +}; + +void tst_custom::initTestCase() +{ +} + +void tst_custom::cleanupTestCase() +{ +} + +void tst_custom::init() +{ + m_custom = new QCustom3DLabel(); +} + +void tst_custom::cleanup() +{ + delete m_custom; +} + +void tst_custom::construct() +{ + QCustom3DLabel *custom = new QCustom3DLabel(); + QVERIFY(custom); + delete custom; + + custom = new QCustom3DLabel("label", QFont("Times New Roman", 10.0), QVector3D(1.0, 1.0, 1.0), + QVector3D(1.0, 1.0, 1.0), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QVERIFY(custom); + QCOMPARE(custom->backgroundColor(), QColor(Qt::gray)); + QCOMPARE(custom->isBackgroundEnabled(), true); + QCOMPARE(custom->isBorderEnabled(), true); + QCOMPARE(custom->isFacingCamera(), false); + QCOMPARE(custom->font(), QFont("Times New Roman", 10)); + QCOMPARE(custom->text(), QString("label")); + QCOMPARE(custom->textColor(), QColor(Qt::white)); + QCOMPARE(custom->meshFile(), QString(":/defaultMeshes/plane")); + QCOMPARE(custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isPositionAbsolute(), false); + QCOMPARE(custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isScalingAbsolute(), true); + QCOMPARE(custom->isShadowCasting(), false); + QCOMPARE(custom->textureFile(), QString()); + QCOMPARE(custom->isVisible(), true); + delete custom; +} + +void tst_custom::initialProperties() +{ + QVERIFY(m_custom); + + QCOMPARE(m_custom->backgroundColor(), QColor(Qt::gray)); + QCOMPARE(m_custom->isBackgroundEnabled(), true); + QCOMPARE(m_custom->isBorderEnabled(), true); + QCOMPARE(m_custom->isFacingCamera(), false); + QCOMPARE(m_custom->font(), QFont("Arial", 20)); + QCOMPARE(m_custom->text(), QString()); + QCOMPARE(m_custom->textColor(), QColor(Qt::white)); + + // Common (from QCustom3DItem) + QCOMPARE(m_custom->meshFile(), QString(":/defaultMeshes/plane")); + QCOMPARE(m_custom->position(), QVector3D()); + QCOMPARE(m_custom->isPositionAbsolute(), false); + QCOMPARE(m_custom->rotation(), QQuaternion()); + QCOMPARE(m_custom->scaling(), QVector3D(0.1f, 0.1f, 0.1f)); + QCOMPARE(m_custom->isScalingAbsolute(), true); + QCOMPARE(m_custom->isShadowCasting(), false); + QCOMPARE(m_custom->textureFile(), QString()); + QCOMPARE(m_custom->isVisible(), true); +} + +void tst_custom::initializeProperties() +{ + QVERIFY(m_custom); + + m_custom->setBackgroundColor(QColor(Qt::red)); + m_custom->setBackgroundEnabled(false); + m_custom->setBorderEnabled(false); + m_custom->setFacingCamera(true); + m_custom->setFont(QFont("Times New Roman", 10)); + m_custom->setText(QString("This is a Custom Label")); + m_custom->setTextColor(QColor(Qt::blue)); + + QCOMPARE(m_custom->backgroundColor(), QColor(Qt::red)); + QCOMPARE(m_custom->isBackgroundEnabled(), false); + QCOMPARE(m_custom->isBorderEnabled(), false); + QCOMPARE(m_custom->isFacingCamera(), true); + QCOMPARE(m_custom->font(), QFont("Times New Roman", 10)); + QCOMPARE(m_custom->text(), QString("This is a Custom Label")); + QCOMPARE(m_custom->textColor(), QColor(Qt::blue)); + + // Common (from QCustom3DItem) + m_custom->setPosition(QVector3D(1.0, 1.0, 1.0)); + m_custom->setPositionAbsolute(true); + m_custom->setRotation(QQuaternion(1.0, 1.0, 10.0, 100.0)); + m_custom->setScaling(QVector3D(1.0, 1.0, 1.0)); + m_custom->setShadowCasting(true); + m_custom->setVisible(false); + + QCOMPARE(m_custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isPositionAbsolute(), true); + QCOMPARE(m_custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(m_custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isShadowCasting(), true); + QCOMPARE(m_custom->isVisible(), false); +} + +void tst_custom::invalidProperties() +{ + m_custom->setScalingAbsolute(false); + QCOMPARE(m_custom->isScalingAbsolute(), true); +} + +QTEST_MAIN(tst_custom) +#include "tst_custom.moc" diff --git a/tests/auto/cpptest/q3dcustom-volume/q3dcustom-volume.pro b/tests/auto/cpptest/q3dcustom-volume/q3dcustom-volume.pro new file mode 100644 index 00000000..af584baa --- /dev/null +++ b/tests/auto/cpptest/q3dcustom-volume/q3dcustom-volume.pro @@ -0,0 +1,8 @@ +QT += testlib datavisualization + +TARGET = tst_cpptest +CONFIG += console testcase + +TEMPLATE = app + +SOURCES += tst_custom.cpp diff --git a/tests/auto/cpptest/q3dcustom-volume/tst_custom.cpp b/tests/auto/cpptest/q3dcustom-volume/tst_custom.cpp new file mode 100644 index 00000000..372e8ecf --- /dev/null +++ b/tests/auto/cpptest/q3dcustom-volume/tst_custom.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include + +#include + +using namespace QtDataVisualization; + +class tst_custom: public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + void construct(); + + void initialProperties(); + void initializeProperties(); + void invalidProperties(); + +private: + QCustom3DVolume *m_custom; +}; + +void tst_custom::initTestCase() +{ +} + +void tst_custom::cleanupTestCase() +{ +} + +void tst_custom::init() +{ + m_custom = new QCustom3DVolume(); +} + +void tst_custom::cleanup() +{ + delete m_custom; +} + +void tst_custom::construct() +{ + QCustom3DVolume *custom = new QCustom3DVolume(); + QVERIFY(custom); + delete custom; + + QVector *tdata = new QVector(1000); + + QVector table; + table << QRgb(0xff00ff) << QRgb(0x00ff00); + + custom = new QCustom3DVolume(QVector3D(1.0, 1.0, 1.0), QVector3D(1.0, 1.0, 1.0), + QQuaternion(1.0, 1.0, 10.0, 100.0), 10, 10, 10, + tdata, QImage::Format_ARGB32, table); + QVERIFY(custom); + QCOMPARE(custom->alphaMultiplier(), 1.0f); + QCOMPARE(custom->drawSliceFrames(), false); + QCOMPARE(custom->drawSliceFrames(), false); + QCOMPARE(custom->preserveOpacity(), true); + QCOMPARE(custom->sliceFrameColor(), QColor(Qt::black)); + QCOMPARE(custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(custom->sliceIndexX(), -1); + QCOMPARE(custom->sliceIndexY(), -1); + QCOMPARE(custom->sliceIndexZ(), -1); + QCOMPARE(custom->useHighDefShader(), true); + QCOMPARE(custom->textureData()->length(), 1000); + QCOMPARE(custom->textureDataWidth(), 40); + QCOMPARE(custom->textureFormat(), QImage::Format_ARGB32); + QCOMPARE(custom->textureHeight(), 10); + QCOMPARE(custom->textureWidth(), 10); + QCOMPARE(custom->textureDepth(), 10); + QCOMPARE(custom->meshFile(), QString(":/defaultMeshes/barFull")); + QCOMPARE(custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isPositionAbsolute(), false); + QCOMPARE(custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isScalingAbsolute(), true); + QCOMPARE(custom->isShadowCasting(), false); + QCOMPARE(custom->textureFile(), QString()); + QCOMPARE(custom->isVisible(), true); + delete custom; +} + +void tst_custom::initialProperties() +{ + QVERIFY(m_custom); + + QCOMPARE(m_custom->alphaMultiplier(), 1.0f); + QCOMPARE(m_custom->drawSliceFrames(), false); + QCOMPARE(m_custom->drawSliceFrames(), false); + QCOMPARE(m_custom->preserveOpacity(), true); + QCOMPARE(m_custom->sliceFrameColor(), QColor(Qt::black)); + QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); + QCOMPARE(m_custom->sliceIndexX(), -1); + QCOMPARE(m_custom->sliceIndexY(), -1); + QCOMPARE(m_custom->sliceIndexZ(), -1); + QCOMPARE(m_custom->useHighDefShader(), true); + + // Common (from QCustom3DVolume) + QCOMPARE(m_custom->meshFile(), QString(":/defaultMeshes/barFull")); + QCOMPARE(m_custom->position(), QVector3D()); + QCOMPARE(m_custom->isPositionAbsolute(), false); + QCOMPARE(m_custom->rotation(), QQuaternion()); + QCOMPARE(m_custom->scaling(), QVector3D(0.1f, 0.1f, 0.1f)); + QCOMPARE(m_custom->isScalingAbsolute(), true); + QCOMPARE(m_custom->isShadowCasting(), true); + QCOMPARE(m_custom->textureFile(), QString()); + QCOMPARE(m_custom->isVisible(), true); +} + +void tst_custom::initializeProperties() +{ + QVERIFY(m_custom); + + m_custom->setAlphaMultiplier(0.1f); + m_custom->setDrawSliceFrames(true); + m_custom->setDrawSliceFrames(true); + m_custom->setPreserveOpacity(false); + m_custom->setSliceFrameColor(QColor(Qt::red)); + m_custom->setSliceFrameGaps(QVector3D(2.0f, 2.0f, 2.0f)); + m_custom->setSliceFrameThicknesses(QVector3D(2.0f, 2.0f, 2.0f)); + m_custom->setSliceFrameWidths(QVector3D(2.0f, 2.0f, 2.0f)); + m_custom->setSliceIndexX(0); + m_custom->setSliceIndexY(0); + m_custom->setSliceIndexZ(0); + m_custom->setUseHighDefShader(false); + + QCOMPARE(m_custom->alphaMultiplier(), 0.1f); + QCOMPARE(m_custom->drawSliceFrames(), true); + QCOMPARE(m_custom->drawSliceFrames(), true); + QCOMPARE(m_custom->preserveOpacity(), false); + QCOMPARE(m_custom->sliceFrameColor(), QColor(Qt::red)); + QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(2.0f, 2.0f, 2.0f)); + QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(2.0f, 2.0f, 2.0f)); + QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(2.0f, 2.0f, 2.0f)); + QCOMPARE(m_custom->sliceIndexX(), 0); + QCOMPARE(m_custom->sliceIndexY(), 0); + QCOMPARE(m_custom->sliceIndexZ(), 0); + QCOMPARE(m_custom->useHighDefShader(), false); + + // Common (from QCustom3DVolume) + m_custom->setPosition(QVector3D(1.0, 1.0, 1.0)); + m_custom->setPositionAbsolute(true); + m_custom->setRotation(QQuaternion(1.0, 1.0, 10.0, 100.0)); + m_custom->setScaling(QVector3D(1.0, 1.0, 1.0)); + m_custom->setScalingAbsolute(false); + m_custom->setShadowCasting(false); + m_custom->setVisible(false); + + QCOMPARE(m_custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isPositionAbsolute(), true); + QCOMPARE(m_custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(m_custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isScalingAbsolute(), false); + QCOMPARE(m_custom->isShadowCasting(), false); + QCOMPARE(m_custom->isVisible(), false); +} + +void tst_custom::invalidProperties() +{ + m_custom->setAlphaMultiplier(-1.0f); + QCOMPARE(m_custom->alphaMultiplier(), 1.0f); + + m_custom->setSliceFrameGaps(QVector3D(-0.1f, -0.1f, -0.1f)); + QCOMPARE(m_custom->sliceFrameGaps(), QVector3D(0.01f, 0.01f, 0.01f)); + + m_custom->setSliceFrameThicknesses(QVector3D(-0.1f, -0.1f, -0.1f)); + QCOMPARE(m_custom->sliceFrameThicknesses(), QVector3D(0.01f, 0.01f, 0.01f)); + + m_custom->setSliceFrameWidths(QVector3D(-0.1f, -0.1f, -0.1f)); + QCOMPARE(m_custom->sliceFrameWidths(), QVector3D(0.01f, 0.01f, 0.01f)); + + m_custom->setTextureFormat(QImage::Format_ARGB8555_Premultiplied); + QCOMPARE(m_custom->textureFormat(), QImage::Format_ARGB32); +} + +QTEST_MAIN(tst_custom) +#include "tst_custom.moc" diff --git a/tests/auto/cpptest/q3dcustom/q3dcustom.pro b/tests/auto/cpptest/q3dcustom/q3dcustom.pro new file mode 100644 index 00000000..af584baa --- /dev/null +++ b/tests/auto/cpptest/q3dcustom/q3dcustom.pro @@ -0,0 +1,8 @@ +QT += testlib datavisualization + +TARGET = tst_cpptest +CONFIG += console testcase + +TEMPLATE = app + +SOURCES += tst_custom.cpp diff --git a/tests/auto/cpptest/q3dcustom/tst_custom.cpp b/tests/auto/cpptest/q3dcustom/tst_custom.cpp new file mode 100644 index 00000000..abc088f9 --- /dev/null +++ b/tests/auto/cpptest/q3dcustom/tst_custom.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include + +#include + +using namespace QtDataVisualization; + +class tst_custom: public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + void construct(); + + void initialProperties(); + void initializeProperties(); + +private: + QCustom3DItem *m_custom; +}; + +void tst_custom::initTestCase() +{ +} + +void tst_custom::cleanupTestCase() +{ +} + +void tst_custom::init() +{ + m_custom = new QCustom3DItem(); +} + +void tst_custom::cleanup() +{ + delete m_custom; +} + +void tst_custom::construct() +{ + QCustom3DItem *custom = new QCustom3DItem(); + QVERIFY(custom); + delete custom; + + custom = new QCustom3DItem(":/customitem.obj", QVector3D(1.0, 1.0, 1.0), + QVector3D(1.0, 1.0, 1.0), QQuaternion(1.0, 1.0, 10.0, 100.0), + QImage(":/customtexture.jpg")); + QVERIFY(custom); + QCOMPARE(custom->meshFile(), QString(":/customitem.obj")); + QCOMPARE(custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isPositionAbsolute(), false); + QCOMPARE(custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(custom->isScalingAbsolute(), true); + QCOMPARE(custom->isShadowCasting(), true); + QCOMPARE(custom->textureFile(), QString()); + QCOMPARE(custom->isVisible(), true); + delete custom; +} + +void tst_custom::initialProperties() +{ + QVERIFY(m_custom); + + QCOMPARE(m_custom->meshFile(), QString()); + QCOMPARE(m_custom->position(), QVector3D()); + QCOMPARE(m_custom->isPositionAbsolute(), false); + QCOMPARE(m_custom->rotation(), QQuaternion()); + QCOMPARE(m_custom->scaling(), QVector3D(0.1f, 0.1f, 0.1f)); + QCOMPARE(m_custom->isScalingAbsolute(), true); + QCOMPARE(m_custom->isShadowCasting(), true); + QCOMPARE(m_custom->textureFile(), QString()); + QCOMPARE(m_custom->isVisible(), true); +} + +void tst_custom::initializeProperties() +{ + QVERIFY(m_custom); + + m_custom->setMeshFile(":/customitem.obj"); + m_custom->setPosition(QVector3D(1.0, 1.0, 1.0)); + m_custom->setPositionAbsolute(true); + m_custom->setRotation(QQuaternion(1.0, 1.0, 10.0, 100.0)); + m_custom->setScaling(QVector3D(1.0, 1.0, 1.0)); + m_custom->setScalingAbsolute(false); + m_custom->setShadowCasting(false); + m_custom->setTextureFile(":/customtexture.jpg"); + m_custom->setVisible(false); + + QCOMPARE(m_custom->meshFile(), QString(":/customitem.obj")); + QCOMPARE(m_custom->position(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isPositionAbsolute(), true); + QCOMPARE(m_custom->rotation(), QQuaternion(1.0, 1.0, 10.0, 100.0)); + QCOMPARE(m_custom->scaling(), QVector3D(1.0, 1.0, 1.0)); + QCOMPARE(m_custom->isScalingAbsolute(), false); + QCOMPARE(m_custom->isShadowCasting(), false); + QCOMPARE(m_custom->textureFile(), QString(":/customtexture.jpg")); + QCOMPARE(m_custom->isVisible(), false); + + m_custom->setTextureImage(QImage(QSize(10, 10), QImage::Format_ARGB32)); + QCOMPARE(m_custom->textureFile(), QString()); +} + +QTEST_MAIN(tst_custom) +#include "tst_custom.moc" -- cgit v1.2.3