summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2016-02-25 16:52:58 +0000
committerSean Harmer <sean.harmer@kdab.com>2016-03-17 19:18:23 +0000
commitb7fc70a4b87e147d0981b70d55b73927d71a667d (patch)
tree30e33d154e80b4168a2b2daf7e3fa6bd91335d6f /tests
parent7ff2cc9c1f037fa9159bc24d8a47778ebac2390a (diff)
Add a small test to try basic aspect behavior
Change-Id: I414cb42daf515928303a100545d4940ac32e7c70 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/qaspectengine/tst_qaspectengine.cpp105
1 files changed, 101 insertions, 4 deletions
diff --git a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp
index 27d7f960d..efc1749e2 100644
--- a/tests/auto/core/qaspectengine/tst_qaspectengine.cpp
+++ b/tests/auto/core/qaspectengine/tst_qaspectengine.cpp
@@ -34,6 +34,54 @@
using namespace Qt3DCore;
+class PrintRootAspect : public QAbstractAspect
+{
+ Q_OBJECT
+public:
+ explicit PrintRootAspect(QObject *parent = 0)
+ : QAbstractAspect(parent)
+ , m_rootEntity(nullptr)
+ {
+ qDebug() << Q_FUNC_INFO;
+ }
+
+private:
+ void onRootEntityChanged(QEntity *rootEntity) Q_DECL_OVERRIDE
+ {
+ qDebug() << Q_FUNC_INFO;
+ m_rootEntity = rootEntity;
+ }
+
+ void onRegistered() Q_DECL_OVERRIDE
+ {
+ qDebug() << Q_FUNC_INFO;
+ }
+
+ void onEngineStartup() Q_DECL_OVERRIDE
+ {
+ qDebug() << Q_FUNC_INFO;
+ }
+
+ void onEngineShutdown() Q_DECL_OVERRIDE
+ {
+ qDebug() << Q_FUNC_INFO;
+ }
+
+ void onCleanup() Q_DECL_OVERRIDE
+ {
+ qDebug() << Q_FUNC_INFO;
+ }
+
+ QVector<QAspectJobPtr> jobsToExecute(qint64) Q_DECL_OVERRIDE \
+ {
+ if (m_rootEntity)
+ qDebug() << Q_FUNC_INFO << m_rootEntity->objectName();
+ return QVector<QAspectJobPtr>();
+ }
+
+ QEntity *m_rootEntity;
+};
+
#define FAKE_ASPECT(ClassName) \
class ClassName : public QAbstractAspect \
{ \
@@ -41,14 +89,14 @@ class ClassName : public QAbstractAspect \
public: \
explicit ClassName(QObject *parent = 0) \
: QAbstractAspect(parent) {} \
-\
+ \
private: \
void onRootEntityChanged(QEntity *) Q_DECL_OVERRIDE {} \
void onRegistered() Q_DECL_OVERRIDE {} \
void onEngineStartup() Q_DECL_OVERRIDE {} \
void onEngineShutdown() Q_DECL_OVERRIDE {} \
void onCleanup() Q_DECL_OVERRIDE {} \
-\
+ \
QVector<QAspectJobPtr> jobsToExecute(qint64) Q_DECL_OVERRIDE \
{ \
return QVector<QAspectJobPtr>(); \
@@ -63,7 +111,7 @@ private: \
} \
\
return QVariant(); \
- }\
+ } \
};
FAKE_ASPECT(FakeAspect)
@@ -108,6 +156,55 @@ private Q_SLOTS:
delete engine;
}
+ void shouldNotCrashInNormalStartupShutdownSequence()
+ {
+ // GIVEN
+ // An initialized aspect engine...
+ QAspectEngine engine;
+ // ...and a simple aspect
+ PrintRootAspect *aspect = new PrintRootAspect;
+
+ // WHEN
+ // We register the aspect
+ engine.registerAspect(aspect);
+
+ // THEN
+ const auto registeredAspects = engine.aspects();
+ QCOMPARE(registeredAspects.size(), 1);
+ QCOMPARE(registeredAspects.first(), aspect);
+
+ // WHEN
+ QEntityPtr entity(new QEntity);
+ entity->setObjectName("RootEntity");
+ // we set a scene root entity
+ engine.setRootEntity(entity);
+
+ QEventLoop eventLoop;
+ QTimer::singleShot(100, &eventLoop, SLOT(quit()));
+ eventLoop.exec();
+
+ // THEN
+ // we don't crash and...
+ const auto rootEntity = engine.rootEntity();
+ QCOMPARE(rootEntity, entity);
+
+ // WHEN
+ // we set an empty/null scene root...
+ engine.setRootEntity(QEntityPtr());
+ QTimer::singleShot(1000, &eventLoop, SLOT(quit()));
+
+ // ...and allow events to process...
+ eventLoop.exec();
+
+ // THEN
+ // ... we don't crash.
+
+ // TODO: Add more tests to check for
+ // * re-setting a scene
+ // * deregistering aspects
+ // * destroying the aspect engine
+ }
+
void shouldNotCrashOnShutdownWhenComponentIsCreatedWithParentBeforeItsEntity()
{
// GIVEN
@@ -126,7 +223,7 @@ private Q_SLOTS:
// THEN
// Nothing particular happen on exit, especially no crash
- };
+ }
void shouldRegisterAspectsByName()
{