summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2018-02-22 21:34:45 -0500
committerSean Harmer <sean.harmer@kdab.com>2018-02-24 08:56:53 +0000
commit4ce90380ad5272de3bec178c480a132b5d4771ba (patch)
treea699ef86fca87c3cd31514b4a09fb97ad46731b8
parent8b6bc3103fc937a6904dd6e6d135e8593619f835 (diff)
Add unit test for QScreenRayCasterv5.11.0-beta1
Change-Id: I76933b23f27bc0fefcbc55342715b2ebd7f7716d Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--tests/auto/render/qscreenraycaster/qscreenraycaster.pro11
-rw-r--r--tests/auto/render/qscreenraycaster/tst_qscreenraycaster.cpp130
-rw-r--r--tests/auto/render/render.pro1
3 files changed, 142 insertions, 0 deletions
diff --git a/tests/auto/render/qscreenraycaster/qscreenraycaster.pro b/tests/auto/render/qscreenraycaster/qscreenraycaster.pro
new file mode 100644
index 000000000..d4a9c4f9f
--- /dev/null
+++ b/tests/auto/render/qscreenraycaster/qscreenraycaster.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+TARGET = tst_qscreenraycaster
+
+QT += core-private 3dcore 3dcore-private 3drender 3drender-private testlib
+
+CONFIG += testcase
+
+SOURCES += tst_qscreenraycaster.cpp
+
+include(../../core/common/common.pri)
diff --git a/tests/auto/render/qscreenraycaster/tst_qscreenraycaster.cpp b/tests/auto/render/qscreenraycaster/tst_qscreenraycaster.cpp
new file mode 100644
index 000000000..fd67da175
--- /dev/null
+++ b/tests/auto/render/qscreenraycaster/tst_qscreenraycaster.cpp
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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 <QtTest/QSignalSpy>
+#include <Qt3DCore/private/qnode_p.h>
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DCore/qpropertynodeaddedchange.h>
+#include <Qt3DCore/qpropertynoderemovedchange.h>
+#include <Qt3DRender/QScreenRayCaster>
+
+#include "testpostmanarbiter.h"
+
+class MyRayCaster : public Qt3DRender::QScreenRayCaster
+{
+ Q_OBJECT
+public:
+ MyRayCaster(Qt3DCore::QNode *parent = nullptr)
+ : Qt3DRender::QScreenRayCaster(parent)
+ {
+ qRegisterMetaType<Qt3DRender::QAbstractRayCaster::Hits>("Hits");
+ }
+
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) final
+ {
+ Qt3DRender::QScreenRayCaster::sceneChangeEvent(change);
+ }
+
+private:
+ friend class tst_RayCaster;
+};
+
+class tst_QScreenRayCaster : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QScreenRayCaster()
+ {
+ }
+
+ ~tst_QScreenRayCaster()
+ {
+ QMetaObject::invokeMethod(this, "_q_cleanup", Qt::DirectConnection);
+ }
+
+private Q_SLOTS:
+
+ void checkState()
+ {
+ // GIVEN
+ QScopedPointer<Qt3DRender::QScreenRayCaster> rayCaster(new Qt3DRender::QScreenRayCaster());
+
+ QVERIFY(!rayCaster->isEnabled());
+ QCOMPARE(rayCaster->runMode(), Qt3DRender::QAbstractRayCaster::SingleShot);
+
+ // WHEN
+ rayCaster->trigger();
+
+ // THEN
+ QVERIFY(rayCaster->isEnabled());
+
+ // WHEN
+ rayCaster->setEnabled(false);
+ rayCaster->trigger(QPoint(200, 200));
+
+ // THEN
+ QVERIFY(rayCaster->isEnabled());
+ QCOMPARE(rayCaster->position(), QPoint(200, 200));
+ }
+
+ void checkPropertyUpdates()
+ {
+ // GIVEN
+ TestArbiter arbiter;
+ QScopedPointer<Qt3DRender::QScreenRayCaster> rayCaster(new Qt3DRender::QScreenRayCaster());
+ arbiter.setArbiterOnNode(rayCaster.data());
+
+ // WHEN
+ rayCaster->setPosition({200, 200});
+ QCoreApplication::processEvents();
+
+ // THEN
+ QCOMPARE(arbiter.events.size(), 1);
+ Qt3DCore::QPropertyUpdatedChangePtr change = arbiter.events.last().staticCast<Qt3DCore::QPropertyUpdatedChange>();
+ QCOMPARE(change->propertyName(), "position");
+ QCOMPARE(change->value().value<QPoint>(), QPoint(200, 200));
+ QCOMPARE(change->type(), Qt3DCore::PropertyUpdated);
+
+ arbiter.events.clear();
+ }
+
+ void checkBackendUpdates_data()
+ {
+ QTest::addColumn<QByteArray>("signalPrototype");
+ QTest::addColumn<QByteArray>("propertyName");
+
+ QTest::newRow("hits")
+ << QByteArray(SIGNAL(hitsChanged(const Hits &)))
+ << QByteArrayLiteral("hits");
+ }
+};
+
+QTEST_MAIN(tst_QScreenRayCaster)
+
+#include "tst_qscreenraycaster.moc"
diff --git a/tests/auto/render/render.pro b/tests/auto/render/render.pro
index ef147ba7f..4045b577a 100644
--- a/tests/auto/render/render.pro
+++ b/tests/auto/render/render.pro
@@ -108,6 +108,7 @@ qtConfig(private_tests) {
blitframebuffer \
qraycaster \
raycaster \
+ qscreenraycaster \
raycastingjob \
qcamera \
renderbarrierjob