diff options
author | Juan Jose Casafranca <juan.casafranca@kdab.com> | 2018-02-04 20:34:06 +0100 |
---|---|---|
committer | Juan José Casafranca <juan.casafranca@kdab.com> | 2018-09-19 13:32:08 +0000 |
commit | b3d15538a995843a000be92b03fc7b1ac8b87826 (patch) | |
tree | 4162b563087ccb9028ab720727e087b4701688a1 /tests/auto/core | |
parent | 4c7f3546b42c320c600bdba92e4e9126cbeedae3 (diff) |
Add an easy way to get a particular component from an entity
Change-Id: I188fab5019d3e05354a4c1582fb12097a569fbb8
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests/auto/core')
-rw-r--r-- | tests/auto/core/qentity/tst_qentity.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/core/qentity/tst_qentity.cpp b/tests/auto/core/qentity/tst_qentity.cpp index e27cd1fc9..d7847342b 100644 --- a/tests/auto/core/qentity/tst_qentity.cpp +++ b/tests/auto/core/qentity/tst_qentity.cpp @@ -53,6 +53,8 @@ private slots: void addComponentsSeveralParentsSingleAggregations(); void addComponentsSeveralParentsSeveralAggregations(); + void retrieveSingleComponent(); + void removeComponentSingleParentSingleAggregation(); void removeComponentSingleParentSeveralAggregations(); void removeComponentsSeveralParentsSingleAggreation(); @@ -76,6 +78,14 @@ public: {} }; +class MyQ2Component : public Qt3DCore::QComponent +{ + Q_OBJECT +public: + explicit MyQ2Component(Qt3DCore::QNode *parent = 0) + : QComponent(parent) + {} +}; class MyEntity : public Qt3DCore::QEntity { @@ -504,6 +514,29 @@ void tst_Entity::removeComponentsSeveralParentsSeveralAggregations() QCOMPARE(comp3->entities().size(), 0); } +void tst_Entity::retrieveSingleComponent() +{ + // GIVEN + QScopedPointer<Qt3DCore::QEntity> entity1(new QEntity()); + + MyQComponent *comp1 = new MyQComponent(entity1.data()); + MyQComponent *comp2 = new MyQComponent(entity1.data()); + QCoreApplication::processEvents(); + entity1->addComponent(comp1); + entity1->addComponent(comp2); + + // WHEN + QVector<MyQComponent*> myQComponentsInEntity = entity1->componentsOfType<MyQComponent>(); + QVector<MyQ2Component*> myQ2ComponentsInEntity = entity1->componentsOfType<MyQ2Component>(); + + // THEN + QVERIFY(myQComponentsInEntity.size() == 2); + QVERIFY(myQComponentsInEntity[0] == comp1); + QVERIFY(myQComponentsInEntity[1] == comp2); + + QVERIFY(myQ2ComponentsInEntity.size() == 0); +} + void tst_Entity::addSeveralTimesSameComponent() { // GIVEN |