From fb05d2eb013eb0a5b2bb80c28e0272ec723d1fb5 Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Tue, 30 May 2017 22:39:09 +0100 Subject: Fix componentAdded/componentRemoved notifications dispatch to components When a component is added to an entity, two change notifications were sent but they both were directed to the entity. This makes sure one message is sent to the entity and one to the component, as was intended. Same for remove notifications. Fixed the unit tests which where incorrectly testing for the subject id of the change notification. Change-Id: Ic697c08e92e884abf28e675e4ae2b44a93ca45d5 Reviewed-by: Paul Lemire --- tests/auto/core/nodes/tst_nodes.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/core/nodes/tst_nodes.cpp b/tests/auto/core/nodes/tst_nodes.cpp index 49618821c..717bb3200 100644 --- a/tests/auto/core/nodes/tst_nodes.cpp +++ b/tests/auto/core/nodes/tst_nodes.cpp @@ -958,15 +958,22 @@ void tst_Nodes::appendingParentlessComponentToEntity() // return early in such a case. // Check that we received ComponentAdded - for (const auto event: { entitySpy.events.takeFirst().change().dynamicCast(), - componentSpy.events.takeLast().change().dynamicCast() }) { + const auto event = entitySpy.events.takeFirst().change().dynamicCast(); 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 = componentSpy.events.takeFirst().change().dynamicCast(); + 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()); + } } } @@ -997,15 +1004,22 @@ void tst_Nodes::appendingComponentToEntity() QVERIFY(comp->parentNode() == entity.data()); QCOMPARE(entitySpy.events.size(), 1); QVERIFY(entitySpy.events.first().wasLocked()); - for (const auto event: { entitySpy.events.takeFirst().change().dynamicCast(), - componentSpy.events.takeFirst().change().dynamicCast() }) { + const auto event = entitySpy.events.takeFirst().change().dynamicCast(); 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 = componentSpy.events.takeFirst().change().dynamicCast(); + 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()); + } } } @@ -1040,14 +1054,22 @@ void tst_Nodes::removingComponentFromEntity() QCOMPARE(entitySpy.events.size(), 1); QVERIFY(entitySpy.events.first().wasLocked()); QCOMPARE(componentSpy.events.size(), 1); - for (const auto event: { entitySpy.events.takeFirst().change().dynamicCast(), - componentSpy.events.takeFirst().change().dynamicCast() }) { + { + const auto event = entitySpy.events.takeFirst().change().dynamicCast(); QCOMPARE(event->type(), Qt3DCore::ComponentRemoved); QCOMPARE(event->subjectId(), entity->id()); QCOMPARE(event->entityId(), entity->id()); QCOMPARE(event->componentId(), comp->id()); QCOMPARE(event->componentMetaObject(), comp->metaObject()); } + { + const auto event = componentSpy.events.takeFirst().change().dynamicCast(); + QCOMPARE(event->type(), Qt3DCore::ComponentRemoved); + QCOMPARE(event->subjectId(), comp->id()); + QCOMPARE(event->entityId(), entity->id()); + QCOMPARE(event->componentId(), comp->id()); + QCOMPARE(event->componentMetaObject(), comp->metaObject()); + } } } -- cgit v1.2.3