diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-15 11:09:56 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-15 11:09:56 +0100 |
commit | 0cbc08e2a7bf5195af8d0134e190d49d24ecabc9 (patch) | |
tree | 19304b1a33f1ad81a7b0470c95965958c2fed6f0 /tests/auto | |
parent | a7e8df28c7f667a8f1e23ff865268e7f06d43328 (diff) | |
parent | 3de900a10c6fd051ba54727be2fd1fe47ed10481 (diff) |
Merge remote-tracking branch 'origin/5.12.2' into 5.12
Change-Id: Idc824e1b8191e5fa624966e619075b1ec8c850c6
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/core/nodes/tst_nodes.cpp | 218 |
1 files changed, 216 insertions, 2 deletions
diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 75d7a7799..3f7fb4a75 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -82,11 +82,14 @@ private slots: void checkConstructionSetParentMix(); // QTBUG-60612 void checkConstructionWithParent(); + void checkConstructionWithNonRootParent(); // QTBUG-73986 void checkConstructionAsListElement(); void checkSceneIsSetOnConstructionWithParent(); // QTBUG-69352 void appendingComponentToEntity(); - void appendingParentlessComponentToEntity(); + void appendingParentlessComponentToEntityWithoutScene(); + void appendingParentlessComponentToEntityWithScene(); + void appendingParentlessComponentToNonRootEntity(); void removingComponentFromEntity(); void changeCustomProperty(); @@ -1119,6 +1122,61 @@ void tst_Nodes::checkConstructionWithParent() QCOMPARE(propertyEvent->value().value<Qt3DCore::QNodeId>(), node->id()); } +void tst_Nodes::checkConstructionWithNonRootParent() +{ + // GIVEN + ObserverSpy spy; + Qt3DCore::QScene scene; + QScopedPointer<MyQNode> root(new MyQNode()); + + // WHEN + root->setArbiterAndScene(&spy, &scene); + root->setSimulateBackendCreated(true); + QScopedPointer<MyQNode> parent(new MyQNode(root.data())); + + // THEN + QVERIFY(Qt3DCore::QNodePrivate::get(root.data())->scene() != nullptr); + QVERIFY(Qt3DCore::QNodePrivate::get(parent.data())->scene() != nullptr); + + // WHEN we create a child and then set it as a Node* property + auto *child = new MyQNode(parent.data()); + root->setNodeProperty(child); + + // THEN we should get + // - one creation change for parent, + // - one creation change for child, + // - one child added change for root->parent, + // - and one property change event, + // in that order. + QCoreApplication::processEvents(); + QCOMPARE(root->children().count(), 1); + QCOMPARE(parent->children().count(), 1); + + QCOMPARE(spy.events.size(), 4); // 2 creation changes, 1 child added changes, 1 property change + + // Ensure first event is parent node's creation change + const auto parentCreationEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!parentCreationEvent.isNull()); + QCOMPARE(parentCreationEvent->subjectId(), parent->id()); + + const auto childCreationEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!childCreationEvent.isNull()); + QCOMPARE(childCreationEvent->subjectId(), child->id()); + + const auto parentNewChildEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); + QVERIFY(!parentNewChildEvent.isNull()); + QCOMPARE(parentNewChildEvent->subjectId(), root->id()); + QCOMPARE(parentNewChildEvent->propertyName(), "children"); + QCOMPARE(parentNewChildEvent->addedNodeId(), parent->id()); + + // Ensure second and last event is property set change + const auto propertyEvent = spy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyUpdatedChange>(); + QVERIFY(!propertyEvent.isNull()); + QCOMPARE(propertyEvent->subjectId(), root->id()); + QCOMPARE(propertyEvent->propertyName(), "nodeProperty"); + QCOMPARE(propertyEvent->value().value<Qt3DCore::QNodeId>(), child->id()); +} + void tst_Nodes::checkConstructionAsListElement() { // GIVEN @@ -1209,7 +1267,7 @@ void tst_Nodes::checkSceneIsSetOnConstructionWithParent() QCOMPARE(spy.events.size(), 10); // 5 QComponentAddedChange(entity, cmp) and 5 QComponentAddedChange(cmp, entity) } -void tst_Nodes::appendingParentlessComponentToEntity() +void tst_Nodes::appendingParentlessComponentToEntityWithoutScene() { // GIVEN ObserverSpy entitySpy; @@ -1265,6 +1323,162 @@ void tst_Nodes::appendingParentlessComponentToEntity() } } +void tst_Nodes::appendingParentlessComponentToNonRootEntity() +{ + // GIVEN + ObserverSpy eventSpy; + Qt3DCore::QScene scene; + + { + QScopedPointer<MyQEntity> root(new MyQEntity()); + root->setArbiterAndScene(&eventSpy, &scene); + root->setSimulateBackendCreated(true); + + QCoreApplication::processEvents(); + + QScopedPointer<MyQEntity> entity(new MyQEntity(root.data())); + MyQComponent *comp = new MyQComponent(); + + // THEN + QVERIFY(root->parentNode() == nullptr); + QVERIFY(root->children().count() == 1); + QVERIFY(root->components().empty()); + QVERIFY(entity->parentNode() == root.data()); + QVERIFY(entity->children().count() == 0); + QVERIFY(entity->components().empty()); + QVERIFY(comp->parentNode() == nullptr); + + // WHEN + entity->addComponent(comp); + QCoreApplication::processEvents(); + + // THEN + QVERIFY(entity->components().count() == 1); + QVERIFY(entity->components().first() == comp); + QVERIFY(comp->parentNode() == entity.data()); + + QCOMPARE(eventSpy.events.size(), 5); + // - entity created + // - comp created + // - entity added as child to root + // - component added for entity + // - component added for compontent + QVERIFY(eventSpy.events.first().wasLocked()); + + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::NodeCreated); + QCOMPARE(event->subjectId(), entity->id()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::NodeCreated); + QCOMPARE(event->subjectId(), comp->id()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::PropertyValueAdded); + QCOMPARE(event->subjectId(), root->id()); + QCOMPARE(event->propertyName(), QByteArrayLiteral("children")); + QCOMPARE(event->addedNodeId(), entity->id()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QComponentAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::ComponentAdded); + QCOMPARE(event->subjectId(), entity->id()); + QCOMPARE(event->entityId(), entity->id()); + QCOMPARE(event->componentId(), comp->id()); + QCOMPARE(event->componentMetaObject(), comp->metaObject()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QComponentAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::ComponentAdded); + QCOMPARE(event->subjectId(), comp->id()); + QCOMPARE(event->entityId(), entity->id()); + QCOMPARE(event->componentId(), comp->id()); + QCOMPARE(event->componentMetaObject(), comp->metaObject()); + } + } +} + +void tst_Nodes::appendingParentlessComponentToEntityWithScene() +{ + // GIVEN + ObserverSpy eventSpy; + Qt3DCore::QScene scene; + + { + QScopedPointer<MyQEntity> entity(new MyQEntity()); + entity->setArbiterAndScene(&eventSpy, &scene); + entity->setSimulateBackendCreated(true); + + QCoreApplication::processEvents(); + + MyQComponent *comp = new MyQComponent(); + + // THEN + QVERIFY(entity->parentNode() == nullptr); + QVERIFY(entity->children().count() == 0); + QVERIFY(entity->components().empty()); + QVERIFY(comp->parentNode() == nullptr); + + // WHEN + entity->addComponent(comp); + QCoreApplication::processEvents(); + + // THEN + QVERIFY(entity->components().count() == 1); + QVERIFY(entity->components().first() == comp); + QVERIFY(comp->parentNode() == entity.data()); + + QCOMPARE(eventSpy.events.size(), 4); + // - entity created + // - child added + // - component added for entity + // - component added for compontent + QVERIFY(eventSpy.events.first().wasLocked()); + + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QNodeCreatedChangeBase>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::NodeCreated); + QCOMPARE(event->subjectId(), comp->id()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QPropertyNodeAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::PropertyValueAdded); + QCOMPARE(event->subjectId(), entity->id()); + QCOMPARE(event->propertyName(), QByteArrayLiteral("children")); + QCOMPARE(event->addedNodeId(), comp->id()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QComponentAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::ComponentAdded); + QCOMPARE(event->subjectId(), entity->id()); + QCOMPARE(event->entityId(), entity->id()); + QCOMPARE(event->componentId(), comp->id()); + QCOMPARE(event->componentMetaObject(), comp->metaObject()); + } + { + const auto event = eventSpy.events.takeFirst().change().dynamicCast<Qt3DCore::QComponentAddedChange>(); + QVERIFY(!event.isNull()); + QCOMPARE(event->type(), Qt3DCore::ComponentAdded); + QCOMPARE(event->subjectId(), comp->id()); + QCOMPARE(event->entityId(), entity->id()); + QCOMPARE(event->componentId(), comp->id()); + QCOMPARE(event->componentMetaObject(), comp->metaObject()); + } + } +} + + void tst_Nodes::appendingComponentToEntity() { // GIVEN |