summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-07-05 10:26:27 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-09-07 12:52:48 +0000
commit78caee8115d35df27922b6581e10ed8fcbfa248d (patch)
treeff4fd696fb2ab6a246f619a6ca5fba5486a95c9d
parent7141de3a5ae94d422385846a047b9fe8dcee00a2 (diff)
Unit tests for UniformValue
Change-Id: I5cd96122a29a2e74e2576cd6f812234e94ecaf99 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/auto/render/render.pro3
-rw-r--r--tests/auto/render/uniform/tst_uniform.cpp292
-rw-r--r--tests/auto/render/uniform/uniform.pro13
3 files changed, 307 insertions, 1 deletions
diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro
index 95cf94d2f..34b282610 100644
--- a/tests/auto/render/render.pro
+++ b/tests/auto/render/render.pro
@@ -58,5 +58,6 @@ qtConfig(private_tests) {
qrendertargetoutput \
qcameralens \
qcomputecommand \
- qrendercapture
+ qrendercapture \
+ uniform
}
diff --git a/tests/auto/render/uniform/tst_uniform.cpp b/tests/auto/render/uniform/tst_uniform.cpp
new file mode 100644
index 000000000..4a7f086e9
--- /dev/null
+++ b/tests/auto/render/uniform/tst_uniform.cpp
@@ -0,0 +1,292 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <Qt3DRender/private/uniform_p.h>
+
+using namespace Qt3DRender;
+using namespace Qt3DRender::Render;
+
+class tst_Uniform : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+
+ void checkInitialState()
+ {
+ // GIVEN
+ UniformValue v;
+ // THEN
+ QVERIFY(v.constData<float>()[0] == 0.0f);
+ QVERIFY(v.constData<float>()[1] == 0.0f);
+ QVERIFY(v.constData<float>()[2] == 0.0f);
+ QVERIFY(v.constData<float>()[3] == 0.0f);
+ }
+
+ void checkDefaultCTors()
+ {
+ {
+ // GIVEN
+ UniformValue v(883);
+ // THEN
+ QCOMPARE(v.constData<int>()[0], 883);
+ QCOMPARE(v.constData<int>()[1], 0);
+ QCOMPARE(v.constData<int>()[2], 0);
+ QCOMPARE(v.constData<int>()[3], 0);
+ }
+ {
+ // GIVEN
+ UniformValue v(1584U);
+ // THEN
+ QCOMPARE(v.constData<uint>()[0], 1584U);
+ QCOMPARE(v.constData<uint>()[1], 0U);
+ QCOMPARE(v.constData<uint>()[2], 0U);
+ QCOMPARE(v.constData<uint>()[3], 0U);
+ }
+ {
+ // GIVEN
+ UniformValue v(454.0f);
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 454.0f);
+ QCOMPARE(v.constData<float>()[1], 0.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v(350.0);
+ // THEN
+ // Note: Uniform value does a double -> float conversion
+ QCOMPARE(v.constData<float>()[0], 350.0f);
+ QCOMPARE(v.constData<float>()[1], 0.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v(true);
+ // THEN
+ QCOMPARE(v.constData<bool>()[0], true);
+ QCOMPARE(v.constData<bool>()[1], false);
+ QCOMPARE(v.constData<bool>()[2], false);
+ QCOMPARE(v.constData<bool>()[3], false);
+ }
+ {
+ // GIVEN
+ UniformValue v(QVector2D(355.0f, 383.0f));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 355.0f);
+ QCOMPARE(v.constData<float>()[1], 383.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v(QVector3D(572.0f, 355.0f, 383.0f));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 572.0f);
+ QCOMPARE(v.constData<float>()[1], 355.0f);
+ QCOMPARE(v.constData<float>()[2], 383.0f);
+ QCOMPARE(v.constData<float>()[4], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v(QVector4D(355.0f, 383.0f, 1340.0f, 1603.0f));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 355.0f);
+ QCOMPARE(v.constData<float>()[1], 383.0f);
+ QCOMPARE(v.constData<float>()[2], 1340.0f);
+ QCOMPARE(v.constData<float>()[3], 1603.0f);
+ }
+ }
+
+ void checkFromVariant()
+ {
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant(883));
+ // THEN
+ QCOMPARE(v.constData<int>()[0], 883);
+ QCOMPARE(v.constData<int>()[1], 0);
+ QCOMPARE(v.constData<int>()[2], 0);
+ QCOMPARE(v.constData<int>()[3], 0);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant(1584U));
+ // THEN
+ QCOMPARE(v.constData<uint>()[0], 1584U);
+ QCOMPARE(v.constData<uint>()[1], 0U);
+ QCOMPARE(v.constData<uint>()[2], 0U);
+ QCOMPARE(v.constData<uint>()[3], 0U);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant(454.0f));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 454.0f);
+ QCOMPARE(v.constData<float>()[1], 0.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant(350.0));
+ // THEN
+ // Note: Uniform value does a double -> float conversion
+ QCOMPARE(v.constData<float>()[0], 350.0f);
+ QCOMPARE(v.constData<float>()[1], 0.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant(true));
+ // THEN
+ QCOMPARE(v.constData<bool>()[0], true);
+ QCOMPARE(v.constData<bool>()[1], false);
+ QCOMPARE(v.constData<bool>()[2], false);
+ QCOMPARE(v.constData<bool>()[3], false);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QVector2D(355.0f, 383.0f)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 355.0f);
+ QCOMPARE(v.constData<float>()[1], 383.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QVector3D(572.0f, 355.0f, 383.0f)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 572.0f);
+ QCOMPARE(v.constData<float>()[1], 355.0f);
+ QCOMPARE(v.constData<float>()[2], 383.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QVector4D(355.0f, 383.0f, 1340.0f, 1603.0f)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 355.0f);
+ QCOMPARE(v.constData<float>()[1], 383.0f);
+ QCOMPARE(v.constData<float>()[2], 1340.0f);
+ QCOMPARE(v.constData<float>()[3], 1603.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QPoint(427, 396)));
+ // THEN
+ QCOMPARE(v.constData<int>()[0], 427);
+ QCOMPARE(v.constData<int>()[1], 396);
+ QCOMPARE(v.constData<int>()[2], 0);
+ QCOMPARE(v.constData<int>()[3], 0);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QSize(427, 396)));
+ // THEN
+ QCOMPARE(v.constData<int>()[0], 427);
+ QCOMPARE(v.constData<int>()[1], 396);
+ QCOMPARE(v.constData<int>()[2], 0);
+ QCOMPARE(v.constData<int>()[3], 0);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QRect(427, 396, 454, 1584)));
+ // THEN
+ QCOMPARE(v.constData<int>()[0], 427);
+ QCOMPARE(v.constData<int>()[1], 396);
+ QCOMPARE(v.constData<int>()[2], 454);
+ QCOMPARE(v.constData<int>()[3], 1584);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QPointF(427, 396)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 427.0f);
+ QCOMPARE(v.constData<float>()[1], 396.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QSizeF(427, 396)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 427.0f);
+ QCOMPARE(v.constData<float>()[1], 396.0f);
+ QCOMPARE(v.constData<float>()[2], 0.0f);
+ QCOMPARE(v.constData<float>()[3], 0.0f);
+ }
+ {
+ // GIVEN
+ UniformValue v = UniformValue::fromVariant(QVariant::fromValue(QRectF(427, 396, 454, 1584)));
+ // THEN
+ QCOMPARE(v.constData<float>()[0], 427.0f);
+ QCOMPARE(v.constData<float>()[1], 396.0f);
+ QCOMPARE(v.constData<float>()[2], 454.0f);
+ QCOMPARE(v.constData<float>()[3], 1584.0f);
+ }
+ }
+
+ void checkComparison()
+ {
+ // GIVEN
+ const UniformValue v1(QVector3D(454.0f, 883.0f, 572.0f));
+ UniformValue v2(454.0f);
+
+ // THEN
+ QVERIFY(!(v1 == v2));
+ QVERIFY(v1 != v2);
+
+ // WHEN
+ v2 = UniformValue::fromVariant(QVector3D(454.0f, 883.0f, 572.0f));
+ // THEN
+ QVERIFY(v1 == v2);
+ QVERIFY(!(v1 != v2));
+
+ // WHEN
+ v2 = UniformValue::fromVariant(QVector3D(454.0f, 883.0f, 572.0f));
+ // THEN
+ QVERIFY(v1 == v2);
+ QVERIFY(!(v1 != v2));
+
+ // WHEN
+ v2 = UniformValue::fromVariant(454.0f);
+ // THEN
+ QVERIFY(!(v1 == v2));
+ QVERIFY(v1 != v2);
+ }
+};
+
+
+QTEST_APPLESS_MAIN(tst_Uniform)
+
+#include "tst_uniform.moc"
diff --git a/tests/auto/render/uniform/uniform.pro b/tests/auto/render/uniform/uniform.pro
new file mode 100644
index 000000000..44dd0266a
--- /dev/null
+++ b/tests/auto/render/uniform/uniform.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+
+TARGET = tst_uniform
+
+QT += 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += \
+ tst_uniform.cpp
+
+include(../../core/common/common.pri)
+include(../commons/commons.pri)