diff options
Diffstat (limited to 'tests/auto/render/uniform/tst_uniform.cpp')
-rw-r--r-- | tests/auto/render/uniform/tst_uniform.cpp | 292 |
1 files changed, 292 insertions, 0 deletions
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" |