summaryrefslogtreecommitdiffstats
path: root/tests/auto/extras
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-08-17 11:26:16 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-11-18 11:07:06 +0000
commit31af53ab9f54cd46bdbd3c2a8120fc5de5ef1a95 (patch)
tree8770e8ad0314e7f2c3908d6f52549cb64a18825a /tests/auto/extras
parent46b4313d426de9c908e720b619fbce93b5ed7cc5 (diff)
Add unit tests for QForwardRenderer
Change-Id: I45f91a0a0d6845df89df29561fca89760b255f01 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/auto/extras')
-rw-r--r--tests/auto/extras/extras.pro9
-rw-r--r--tests/auto/extras/qforwardrenderer/qforwardrenderer.pro9
-rw-r--r--tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp172
3 files changed, 187 insertions, 3 deletions
diff --git a/tests/auto/extras/extras.pro b/tests/auto/extras/extras.pro
index 381924d7b..4fe7d7578 100644
--- a/tests/auto/extras/extras.pro
+++ b/tests/auto/extras/extras.pro
@@ -1,5 +1,8 @@
TEMPLATE = subdirs
-SUBDIRS = \
- qcuboidgeometry \
- qtorusgeometry
+contains(QT_CONFIG, private_tests) {
+ SUBDIRS += \
+ qcuboidgeometry \
+ qtorusgeometry \
+ qforwardrenderer
+}
diff --git a/tests/auto/extras/qforwardrenderer/qforwardrenderer.pro b/tests/auto/extras/qforwardrenderer/qforwardrenderer.pro
new file mode 100644
index 000000000..6dc853f5a
--- /dev/null
+++ b/tests/auto/extras/qforwardrenderer/qforwardrenderer.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+TARGET = tst_qforwardrenderer
+
+QT += 3dcore 3dcore-private 3drender 3drender-private 3dextras testlib
+
+CONFIG += testcase
+
+SOURCES += tst_qforwardrenderer.cpp
diff --git a/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp
new file mode 100644
index 000000000..122aed520
--- /dev/null
+++ b/tests/auto/extras/qforwardrenderer/tst_qforwardrenderer.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** 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 <Qt3DExtras/qforwardrenderer.h>
+#include <Qt3DCore/qentity.h>
+#include <QObject>
+#include <QSignalSpy>
+
+class tst_QForwardRenderer : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+
+ void initTestCase()
+ {
+ qRegisterMetaType<Qt3DCore::QEntity*>();
+ }
+
+ void checkDefaultConstruction()
+ {
+ // GIVEN
+ Qt3DExtras::QForwardRenderer forwardRenderer;
+
+ // THEN
+ QVERIFY(forwardRenderer.surface() == nullptr);
+ QCOMPARE(forwardRenderer.viewportRect(), QRectF(0.0f, 0.0f, 1.0f, 1.0f));
+ QCOMPARE(forwardRenderer.clearColor(), QColor(Qt::white));
+ QVERIFY(forwardRenderer.camera() == nullptr);
+ QCOMPARE(forwardRenderer.externalRenderTargetSize(), QSize());
+ }
+
+ void checkPropertyChanges()
+ {
+ // GIVEN
+ Qt3DExtras::QForwardRenderer forwardRenderer;
+
+ {
+ // WHEN
+ QSignalSpy spy(&forwardRenderer, SIGNAL(surfaceChanged(QObject *)));
+ QWindow newValue;
+ forwardRenderer.setSurface(&newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.surface(), &newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ forwardRenderer.setSurface(&newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.surface(), &newValue);
+ QCOMPARE(spy.count(), 0);
+
+ // WHEN
+ forwardRenderer.setSurface(nullptr);
+
+ // THEN
+ QVERIFY(forwardRenderer.surface() == nullptr);
+ QCOMPARE(spy.count(), 1);
+ }
+ {
+ // WHEN
+ QSignalSpy spy(&forwardRenderer, SIGNAL(viewportRectChanged(QRectF)));
+ const QRectF newValue = QRectF(0.5, 0.5, 0.5, 0.5);
+ forwardRenderer.setViewportRect(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.viewportRect(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ forwardRenderer.setViewportRect(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.viewportRect(), newValue);
+ QCOMPARE(spy.count(), 0);
+
+ }
+ {
+ // WHEN
+ QSignalSpy spy(&forwardRenderer, SIGNAL(clearColorChanged(QColor)));
+ const QColor newValue = QColor(Qt::red);
+ forwardRenderer.setClearColor(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.clearColor(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ forwardRenderer.setClearColor(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.clearColor(), newValue);
+ QCOMPARE(spy.count(), 0);
+
+ }
+ {
+ // WHEN
+ QSignalSpy spy(&forwardRenderer, SIGNAL(cameraChanged(Qt3DCore::QEntity *)));
+ Qt3DCore::QEntity newValue;
+ forwardRenderer.setCamera(&newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.camera(), &newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ forwardRenderer.setCamera(&newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.camera(), &newValue);
+ QCOMPARE(spy.count(), 0);
+
+ }
+ {
+ // WHEN
+ QSignalSpy spy(&forwardRenderer, SIGNAL(externalRenderTargetSizeChanged(QSize)));
+ const QSize newValue = QSize(454, 427);
+ forwardRenderer.setExternalRenderTargetSize(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.externalRenderTargetSize(), newValue);
+ QCOMPARE(spy.count(), 1);
+
+ // WHEN
+ spy.clear();
+ forwardRenderer.setExternalRenderTargetSize(newValue);
+
+ // THEN
+ QCOMPARE(forwardRenderer.externalRenderTargetSize(), newValue);
+ QCOMPARE(spy.count(), 0);
+
+ }
+ }
+
+};
+
+QTEST_MAIN(tst_QForwardRenderer)
+
+#include "tst_qforwardrenderer.moc"