summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-01-05 10:06:22 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-01-10 20:58:12 +0100
commit557208854035e96eb7052f085bdd8e234fa372d5 (patch)
treecb5886a65b7a64d0bc43aa2da5f20883066b63b7 /tests
parent7f3ad309eedcb88f1f579420948c99846ab0a034 (diff)
tst_cloning: Add unit test for cloning
Change-Id: I008e81fa698195b732c535a2728bd117ddd1b325 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/cloning/cloning.pro8
-rw-r--r--tests/auto/core/cloning/tst_cloning.cpp147
-rw-r--r--tests/auto/core/core.pro6
-rw-r--r--tests/auto/core/nodes/tst_nodes.cpp38
4 files changed, 159 insertions, 40 deletions
diff --git a/tests/auto/core/cloning/cloning.pro b/tests/auto/core/cloning/cloning.pro
new file mode 100644
index 000000000..d6ecaf489
--- /dev/null
+++ b/tests/auto/core/cloning/cloning.pro
@@ -0,0 +1,8 @@
+TARGET = tst_cloning
+CONFIG += testcase
+TEMPLATE = app
+
+SOURCES += \
+ tst_cloning.cpp
+
+QT += testlib core-private 3dcore 3dcore-private
diff --git a/tests/auto/core/cloning/tst_cloning.cpp b/tests/auto/core/cloning/tst_cloning.cpp
new file mode 100644
index 000000000..92368ad25
--- /dev/null
+++ b/tests/auto/core/cloning/tst_cloning.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 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:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <Qt3DCore/qentity.h>
+#include <Qt3DCore/qcomponent.h>
+#include <Qt3DCore/private/qnode_p.h>
+#include <Qt3DCore/qscene.h>
+
+class tst_Cloning : public QObject
+{
+ Q_OBJECT
+public:
+ tst_Cloning() : QObject() {}
+ ~tst_Cloning() {}
+
+private slots:
+ void checkEntityCloning();
+};
+
+class MyQNode : public Qt3D::QNode
+{
+ Q_OBJECT
+public:
+ explicit MyQNode(Qt3D::QNode *parent = 0) : QNode(parent)
+ {}
+
+ void setCustomProperty(const QString &s) { m_customProperty = s; }
+ QString customProperty() const { return m_customProperty; }
+
+ QT3D_CLONEABLE(MyQNode)
+
+ QString m_customProperty;
+
+ static QNode *clone(QNode *node) {
+ return QNode::clone(node);
+ }
+
+protected:
+ void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE
+ {
+ Qt3D::QNode::copy(ref);
+ const MyQNode *refNode = qobject_cast<const MyQNode *>(ref);
+ setCustomProperty(refNode->customProperty());
+ }
+};
+
+class MyQComponent : public Qt3D::QComponent
+{
+ Q_OBJECT
+public:
+ explicit MyQComponent(Qt3D::QNode *parent = 0) : QComponent(parent)
+ {}
+
+ QT3D_CLONEABLE(MyQComponent)
+};
+
+void tst_Cloning::checkEntityCloning()
+{
+ Qt3D::QScene *scene = new Qt3D::QScene();
+ MyQNode *root = new MyQNode();
+ Qt3D::QNodePrivate::get(root)->setScene(scene);
+
+ Qt3D::QEntity *entity = new Qt3D::QEntity(root);
+
+ MyQComponent *comp1 = new MyQComponent();
+ MyQComponent *comp2 = new MyQComponent();
+ MyQComponent *comp3 = new MyQComponent();
+
+ MyQNode *childNode = new MyQNode(entity);
+ entity->addComponent(comp1);
+ entity->addComponent(comp2);
+ entity->addComponent(comp3);
+
+ root->setCustomProperty(QStringLiteral("Corvette"));
+
+ // VERIFY Initial state
+ QVERIFY(root->customProperty() == QStringLiteral("Corvette"));
+ QCOMPARE(root->children().count(), 1);
+ QCOMPARE(entity->children().count(), 4);
+ QCOMPARE(entity->components().count(), 3);
+
+ MyQNode *cloneRoot = qobject_cast<MyQNode *>(MyQNode::clone(root));
+
+ QCOMPARE(cloneRoot->children().count(), 1);
+ QCOMPARE(cloneRoot->id(), root->id());
+ QVERIFY(cloneRoot->customProperty() == root->customProperty());
+
+ Qt3D::QEntity *cloneEntity = qobject_cast<Qt3D::QEntity *>(cloneRoot->children().first());
+ QVERIFY(cloneEntity != Q_NULLPTR);
+ QCOMPARE(cloneEntity->id(), entity->id());
+ QCOMPARE(cloneEntity->children().count(), 4);
+ QCOMPARE(cloneEntity->components().count(), 3);
+
+ QList<Qt3D::QNodeId> ids = QList<Qt3D::QNodeId>() << comp1->id() << comp2->id() << comp3->id() << childNode->id();
+
+ Q_FOREACH (QObject *c, cloneEntity->children()) {
+ Qt3D::QNode *n = qobject_cast<Qt3D::QNode *>(c);
+ QVERIFY(ids.contains(n->id()));
+ ids.removeAll(n->id());
+ }
+
+ delete cloneRoot;
+}
+
+QTEST_APPLESS_MAIN(tst_Cloning)
+
+#include "tst_cloning.moc"
+
diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro
index 9d4ca453e..47cc2760c 100644
--- a/tests/auto/core/core.pro
+++ b/tests/auto/core/core.pro
@@ -11,8 +11,10 @@ SUBDIRS = \
qentity \
qaspectengine \
qchangearbiter \
- qscene
+ qscene \
contains(QT_CONFIG, private_tests) {
- SUBDIRS += qframeallocator
+ SUBDIRS += \
+ qframeallocator \
+ cloning
}
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp
index b0c143d21..7560171bd 100644
--- a/tests/auto/core/nodes/tst_nodes.cpp
+++ b/tests/auto/core/nodes/tst_nodes.cpp
@@ -62,7 +62,6 @@ private slots:
void removingChildEntitiesFromNode();
void appendingComponentsToEntity();
void removingComponentsFromEntity();
- void checkCloning();
void checkDestruction();
};
@@ -322,43 +321,6 @@ void tst_Nodes::removingComponentsFromEntity()
QCOMPARE(entity->children().count(), 0);
}
-void tst_Nodes::checkCloning()
-{
-// Qt3D::QScene *scene = new Qt3D::QScene();
-// MyQNode *root = new MyQNode();
-// root->setScene(scene);
-// Qt3D::QEntity *entity = new Qt3D::QEntity(root);
-// root->addChild(entity);
-
-// MyQComponent *comp1 = new MyQComponent();
-// MyQComponent *comp2 = new MyQComponent();
-// MyQComponent *comp3 = new MyQComponent();
-
-// MyQNode *childNode = new MyQNode();
-// entity->addChild(childNode);
-// entity->addComponent(comp1);
-// entity->addComponent(comp2);
-// entity->addComponent(comp3);
-
-// root->setCustomProperty(QStringLiteral("Corvette"));
-
-// QVERIFY(root->customProperty() == QStringLiteral("Corvette"));
-// QCOMPARE(root->children().count(), 1);
-// QCOMPARE(entity->children().count(), 4);
-// QCOMPARE(entity->components().count(), 3);
-
-// Qt3D::QNode *rootClone = root->clone();
-// QVERIFY(rootClone->id() == root->id());
-// QVERIFY(qobject_cast<MyQNode *>(rootClone) != Q_NULLPTR);
-// QVERIFY(qobject_cast<MyQNode *>(rootClone)->customProperty() == root->customProperty());
-
-// Qt3D::QEntity *entityClone = qobject_cast<Qt3D::QEntity *>(rootClone->children().first());
-// QVERIFY(entity->id() == entityClone->id());
-// QCOMPARE(root->children().count(), rootClone->children().count());
-// QCOMPARE(entityClone->children().count(), entity->children().count());
-// QCOMPARE(entityClone->components().count(), entity->components().count());
-}
-
void tst_Nodes::checkDestruction()
{
MyQNode *root = new MyQNode();