From 2dc90d389bd3c7972a07bae749f0943c934ef3ec Mon Sep 17 00:00:00 2001 From: Mauro Persano Date: Sun, 7 Aug 2016 20:07:54 -0300 Subject: Add basic unit tests for texture classes Change-Id: Ia3cfdbc085204dba45019394996bcd09fe415bd8 Reviewed-by: Paul Lemire --- tests/auto/render/render.pro | 1 + tests/auto/render/texture/texture.pro | 12 ++ tests/auto/render/texture/tst_texture.cpp | 235 ++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 tests/auto/render/texture/texture.pro create mode 100644 tests/auto/render/texture/tst_texture.cpp (limited to 'tests') diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro index be5a39d2c..3c9f4d462 100644 --- a/tests/auto/render/render.pro +++ b/tests/auto/render/render.pro @@ -7,6 +7,7 @@ contains(QT_CONFIG, private_tests) { renderpass \ qgraphicsutils \ shader \ + texture \ renderviewutils \ renderviews \ material \ diff --git a/tests/auto/render/texture/texture.pro b/tests/auto/render/texture/texture.pro new file mode 100644 index 000000000..04231844f --- /dev/null +++ b/tests/auto/render/texture/texture.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +TARGET = tst_texture + +QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib + +CONFIG += testcase + +SOURCES += tst_texture.cpp + +include(../../core/common/common.pri) +include(../commons/commons.pri) diff --git a/tests/auto/render/texture/tst_texture.cpp b/tests/auto/render/texture/tst_texture.cpp new file mode 100644 index 000000000..0594909c1 --- /dev/null +++ b/tests/auto/render/texture/tst_texture.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +#include "testpostmanarbiter.h" +#include "testrenderer.h" + +class DummyTexture : public Qt3DRender::QAbstractTexture +{ + Q_OBJECT + +public: + explicit DummyTexture(Qt3DCore::QNode *parent = nullptr) + : QAbstractTexture(TargetAutomatic, parent) + { + } +}; + +class tst_RenderTexture : public Qt3DCore::QBackendNodeTester +{ + Q_OBJECT + +private: + template + void checkPropertyMirroring(); + +private slots: + void checkFrontendPropertyNotifications(); + void checkPropertyMirroring(); + void checkPropertyChanges(); +}; + +void tst_RenderTexture::checkFrontendPropertyNotifications() +{ + // GIVEN + TestArbiter arbiter; + DummyTexture texture; + arbiter.setArbiterOnNode(&texture); + + // WHEN + texture.setWidth(512); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "width"); + QCOMPARE(change->value().value(), 512); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + texture.setWidth(512); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + texture.setHeight(256); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "height"); + QCOMPARE(change->value().value(), 256); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + texture.setHeight(256); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + texture.setDepth(128); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "depth"); + QCOMPARE(change->value().value(), 128); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + texture.setDepth(128); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); + + // WHEN + texture.setLayers(16); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 1); + change = arbiter.events.first().staticCast(); + QCOMPARE(change->propertyName(), "layers"); + QCOMPARE(change->value().value(), 16); + QCOMPARE(change->type(), Qt3DCore::PropertyUpdated); + + arbiter.events.clear(); + + // WHEN + texture.setLayers(16); + QCoreApplication::processEvents(); + + // THEN + QCOMPARE(arbiter.events.size(), 0); +} + +template +void tst_RenderTexture::checkPropertyMirroring() +{ + // GIVEN + Qt3DRender::Render::Texture backend; + + FrontendTextureType frontend; + frontend.setWidth(256); + frontend.setHeight(128); + frontend.setDepth(16); + frontend.setLayers(8); + + // WHEN + simulateInitialization(&frontend, &backend); + + // THEN + QCOMPARE(backend.peerId(), frontend.id()); + QCOMPARE(backend.target(), Target); + QCOMPARE(backend.width(), frontend.width()); + QCOMPARE(backend.height(), frontend.height()); + QCOMPARE(backend.depth(), frontend.depth()); + QCOMPARE(backend.layers(), frontend.layers()); +} + +void tst_RenderTexture::checkPropertyMirroring() +{ + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); + checkPropertyMirroring(); +} + +void tst_RenderTexture::checkPropertyChanges() +{ + // GIVEN + TestRenderer renderer; + Qt3DRender::Render::Texture backend; + backend.setRenderer(&renderer); + + // WHEN + Qt3DCore::QPropertyUpdatedChangePtr updateChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setValue(256); + updateChange->setPropertyName("width"); + backend.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backend.width(), 256); + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setValue(128); + updateChange->setPropertyName("height"); + backend.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backend.height(), 128); + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setValue(16); + updateChange->setPropertyName("depth"); + backend.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backend.depth(), 16); + + // WHEN + updateChange.reset(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId())); + updateChange->setValue(32); + updateChange->setPropertyName("layers"); + backend.sceneChangeEvent(updateChange); + + // THEN + QCOMPARE(backend.layers(), 32); +} + +QTEST_APPLESS_MAIN(tst_RenderTexture) + +#include "tst_texture.moc" -- cgit v1.2.3