summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-03-30 14:54:26 +0100
committerPaul Lemire <paul.lemire@kdab.com>2017-08-03 14:34:56 +0000
commit1071f3e6a2b4d39ca677cb11d50c5e36b4428ea5 (patch)
treeeb7959fb84195e7cee347677949d97efed4a52ce /tests
parent5156fcf380eafd4dcd732907439de5c0e351e60c (diff)
Add private module qt3dcoretest
Static library containing helpers for unit tests to avoid having to build the same files 200 times. Change-Id: I89d63abbd7777a96276154298c2748e2d6774514 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro7
-rw-r--r--tests/auto/coretest/coretest.pro25
-rw-r--r--tests/auto/coretest/qbackendnodetester.cpp73
-rw-r--r--tests/auto/coretest/qbackendnodetester_p.h78
-rw-r--r--tests/auto/coretest/testpostmanarbiter.cpp90
-rw-r--r--tests/auto/coretest/testpostmanarbiter_p.h92
6 files changed, 365 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 7cbb53089..cc7e5590a 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,6 +1,7 @@
TEMPLATE = subdirs
SUBDIRS = \
+ coretest \
core \
render \
quick3d \
@@ -10,3 +11,9 @@ SUBDIRS = \
extras
installed_cmake.depends = cmake
+
+for(subdir, SUBDIRS) {
+ !equals(subdir, coretest) {
+ $${subdir}.depends += coretest
+ }
+}
diff --git a/tests/auto/coretest/coretest.pro b/tests/auto/coretest/coretest.pro
new file mode 100644
index 000000000..9bcc56c1b
--- /dev/null
+++ b/tests/auto/coretest/coretest.pro
@@ -0,0 +1,25 @@
+TARGET = Qt3DCoreTest
+MODULE = 3dcoretest
+CONFIG += static internal_module
+
+DEFINES += QT_NO_CAST_FROM_ASCII QT_NO_FOREACH
+PRECOMPILED_HEADER =
+INCLUDEPATH += $$PWD
+
+SOURCES += \
+ $$PWD/testpostmanarbiter.cpp
+
+HEADERS += \
+ $$PWD/testpostmanarbiter_p.h
+
+qtConfig(private_tests) {
+ SOURCES += \
+ $$PWD/qbackendnodetester.cpp
+
+ HEADERS += \
+ $$PWD/qbackendnodetester_p.h
+}
+
+QT += core-private 3dcore 3dcore-private
+
+load(qt_module)
diff --git a/tests/auto/coretest/qbackendnodetester.cpp b/tests/auto/coretest/qbackendnodetester.cpp
new file mode 100644
index 000000000..be9767828
--- /dev/null
+++ b/tests/auto/coretest/qbackendnodetester.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qbackendnodetester_p.h"
+#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DCore/qnode.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+
+QBackendNodeTester::QBackendNodeTester(QObject *parent)
+ : QObject(parent)
+{
+}
+
+void QBackendNodeTester::setPeerId(QBackendNode *backend, QNodeId id)
+{
+ Q_ASSERT(backend);
+ backend->setPeerId(id);
+}
+
+void QBackendNodeTester::simulateInitialization(QNode *frontend, QBackendNode *backend)
+{
+ Q_ASSERT(frontend);
+ Q_ASSERT(backend);
+ const auto change = frontend->createNodeCreationChange();
+ backend->setPeerId(change->subjectId());
+ backend->setEnabled(change->isNodeEnabled());
+ backend->initializeFromPeer(change);
+}
+
+void QBackendNodeTester::sceneChangeEvent(QBackendNode *backend, const Qt3DCore::QSceneChangePtr &e)
+{
+ backend->sceneChangeEvent(e);
+}
+
+} // namespace Qt3DCore
+
+QT_END_NAMESPACE
diff --git a/tests/auto/coretest/qbackendnodetester_p.h b/tests/auto/coretest/qbackendnodetester_p.h
new file mode 100644
index 000000000..020cfcdf1
--- /dev/null
+++ b/tests/auto/coretest/qbackendnodetester_p.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DCORE_QBACKENDNODETESTER_P_H
+#define QT3DCORE_QBACKENDNODETESTER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QObject>
+#include <Qt3DCore/qnodeid.h>
+#include <Qt3DCore/qscenechange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+
+class QBackendNode;
+class QNode;
+
+class QBackendNodeTester : public QObject
+{
+ Q_OBJECT
+public:
+ explicit QBackendNodeTester(QObject *parent = 0);
+
+ // Proxies to allow test classes to call private methods on QBackendNode
+ void setPeerId(QBackendNode *backend, QNodeId id);
+ void simulateInitialization(QNode *frontend, QBackendNode *backend);
+ void sceneChangeEvent(QBackendNode *backend, const Qt3DCore::QSceneChangePtr &e);
+};
+
+} // namespace Qt3DCore
+
+QT_END_NAMESPACE
+
+#endif // QT3DCORE_QBACKENDNODETESTER_P_H
diff --git a/tests/auto/coretest/testpostmanarbiter.cpp b/tests/auto/coretest/testpostmanarbiter.cpp
new file mode 100644
index 000000000..b4c1b03af
--- /dev/null
+++ b/tests/auto/coretest/testpostmanarbiter.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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 "testpostmanarbiter_p.h"
+#include <Qt3DCore/private/qnode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+TestPostman::TestPostman(TestArbiter *arbiter)
+ : m_arbiter(arbiter)
+{}
+
+void TestPostman::setScene(Qt3DCore::QScene *)
+{}
+
+void TestPostman::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &)
+{}
+
+void TestPostman::notifyBackend(const Qt3DCore::QSceneChangePtr &e)
+{
+ m_arbiter->sceneChangeEventWithLock(e);
+}
+
+bool TestPostman::shouldNotifyFrontend(const Qt3DCore::QSceneChangePtr &)
+{
+ return false;
+}
+
+TestArbiter::TestArbiter()
+ : m_postman(new TestPostman(this))
+{
+}
+
+TestArbiter::~TestArbiter()
+{
+}
+
+void TestArbiter::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+{
+ events.push_back(e);
+}
+
+void TestArbiter::sceneChangeEventWithLock(const Qt3DCore::QSceneChangePtr &e)
+{
+ events.push_back(e);
+}
+
+void TestArbiter::sceneChangeEventWithLock(const Qt3DCore::QSceneChangeList &e)
+{
+ events += QVector<Qt3DCore::QSceneChangePtr>::fromStdVector(e);
+}
+
+Qt3DCore::QAbstractPostman *TestArbiter::postman() const
+{
+ return m_postman;
+}
+
+void TestArbiter::setArbiterOnNode(Qt3DCore::QNode *node)
+{
+ Qt3DCore::QNodePrivate::get(node)->setArbiter(this);
+ for (Qt3DCore::QNode *n : node->childNodes())
+ setArbiterOnNode(n);
+}
+
+QT_END_NAMESPACE
diff --git a/tests/auto/coretest/testpostmanarbiter_p.h b/tests/auto/coretest/testpostmanarbiter_p.h
new file mode 100644
index 000000000..7785b864a
--- /dev/null
+++ b/tests/auto/coretest/testpostmanarbiter_p.h
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 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$
+**
+****************************************************************************/
+
+#ifndef QT3DCORE_TESTPOSTMANARBITER_P_H
+#define QT3DCORE_TESTPOSTMANARBITER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DCore/private/qpostman_p.h>
+#include <Qt3DCore/private/qchangearbiter_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DCore {
+ class QNode;
+} // Qt3D
+
+class TestArbiter;
+
+class TestPostman : public Qt3DCore::QAbstractPostman
+{
+public:
+ explicit TestPostman(TestArbiter *arbiter);
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) Q_DECL_FINAL;
+ void setScene(Qt3DCore::QScene *) Q_DECL_FINAL;
+ void notifyBackend(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL;
+ bool shouldNotifyFrontend(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL;
+
+private:
+ TestArbiter *m_arbiter;
+};
+
+class TestArbiter : public Qt3DCore::QAbstractArbiter
+{
+public:
+ TestArbiter();
+ ~TestArbiter();
+
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL;
+
+ void sceneChangeEventWithLock(const Qt3DCore::QSceneChangePtr &e) Q_DECL_FINAL;
+
+ void sceneChangeEventWithLock(const Qt3DCore::QSceneChangeList &e) Q_DECL_FINAL;
+
+ Qt3DCore::QAbstractPostman *postman() const Q_DECL_FINAL;
+
+ QVector<Qt3DCore::QSceneChangePtr> events;
+
+ void setArbiterOnNode(Qt3DCore::QNode *node);
+
+private:
+ TestPostman *m_postman;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT3DCORE_TESTPOSTMANARBITER_P_H