| 1 | // Copyright (C) 2015 Paul Lemire [email protected] |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DRender/private/boundingvolumedebug_p.h> |
| 6 | #include <Qt3DRender/private/qboundingvolumedebug_p.h> |
| 7 | #include <Qt3DCore/private/qbackendnode_p.h> |
| 8 | #include <Qt3DCore/qnodepropertychange.h> |
| 9 | #include "testpostmanarbiter.h" |
| 10 | #include "testrenderer.h" |
| 11 | |
| 12 | class tst_BoundingVolumeDebug : public QObject |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | private Q_SLOTS: |
| 16 | |
| 17 | void checkPeerPropertyMirroring() |
| 18 | { |
| 19 | // GIVEN |
| 20 | Qt3DRender::Render::BoundingVolumeDebug boundingVolumeDebug; |
| 21 | Qt3DRender::QBoundingVolumeDebug fbvH; |
| 22 | fbvH.setRecursive(true); |
| 23 | |
| 24 | // WHEN |
| 25 | boundingVolumeDebug.setPeer(&fbvH); |
| 26 | |
| 27 | // THEN |
| 28 | QVERIFY(!boundingVolumeDebug.peerId().isNull()); |
| 29 | QCOMPARE(boundingVolumeDebug.isRecursive(), true); |
| 30 | } |
| 31 | |
| 32 | void checkInitialAndCleanedUpState() |
| 33 | { |
| 34 | // GIVEN |
| 35 | Qt3DRender::Render::BoundingVolumeDebug boundingVolumeDebug; |
| 36 | |
| 37 | // THEN |
| 38 | QVERIFY(boundingVolumeDebug.peerId().isNull()); |
| 39 | QCOMPARE(boundingVolumeDebug.isRecursive(), false); |
| 40 | QCOMPARE(boundingVolumeDebug.radius(), 0.0f); |
| 41 | QCOMPARE(boundingVolumeDebug.center(), QVector3D()); |
| 42 | |
| 43 | // GIVEN |
| 44 | Qt3DRender::QBoundingVolumeDebug fbvH; |
| 45 | fbvH.setEnabled(true); |
| 46 | |
| 47 | // WHEN |
| 48 | boundingVolumeDebug.updateFromPeer(&fbvH); |
| 49 | boundingVolumeDebug.setRadius(427.0f); |
| 50 | boundingVolumeDebug.setCenter(QVector3D(454.0f, 383.0f, 355.0f)); |
| 51 | boundingVolumeDebug.cleanup(); |
| 52 | |
| 53 | // THEN |
| 54 | QVERIFY(boundingVolumeDebug.peerId().isNull()); |
| 55 | QCOMPARE(boundingVolumeDebug.isRecursive(), false); |
| 56 | QCOMPARE(boundingVolumeDebug.radius(), 0.0f); |
| 57 | QCOMPARE(boundingVolumeDebug.center(), QVector3D()); |
| 58 | } |
| 59 | |
| 60 | void checkPropertyChanges() |
| 61 | { |
| 62 | // GIVEN |
| 63 | TestRenderer renderer; |
| 64 | Qt3DRender::Render::BoundingVolumeDebug boundingVolumeDebug; |
| 65 | boundingVolumeDebug.setRenderer(&renderer); |
| 66 | QVERIFY(!boundingVolumeDebug.isRecursive()); |
| 67 | |
| 68 | // WHEN |
| 69 | Qt3DCore::QNodePropertyChangePtr updateChange(new Qt3DCore::QNodePropertyChange(Qt3DCore::NodeUpdated, Qt3DCore::QSceneChange::Node, Qt3DCore::QNodeId())); |
| 70 | updateChange->setValue(true); |
| 71 | updateChange->setPropertyName("recursive"); |
| 72 | boundingVolumeDebug.sceneChangeEvent(updateChange); |
| 73 | |
| 74 | // THEN |
| 75 | QCOMPARE(boundingVolumeDebug.isRecursive(), true); |
| 76 | QVERIFY(renderer.dirtyBits() != 0); |
| 77 | } |
| 78 | |
| 79 | void checkBackendPropertyNotifications() |
| 80 | { |
| 81 | // GIVEN |
| 82 | TestArbiter arbiter; |
| 83 | Qt3DRender::Render::BoundingVolumeDebug boundingVolumeDebug; |
| 84 | Qt3DCore::QBackendNodePrivate::get(&boundingVolumeDebug)->setArbiter(&arbiter); |
| 85 | |
| 86 | // WHEN |
| 87 | boundingVolumeDebug.setRadius(1340.0f); |
| 88 | |
| 89 | // THEN |
| 90 | QCOMPARE(arbiter.events.count(), 1); |
| 91 | Qt3DCore::QNodePropertyChangePtr change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>(); |
| 92 | QCOMPARE(change->propertyName(), "radius"); |
| 93 | QCOMPARE(change->value().toFloat(), 1340.0f); |
| 94 | |
| 95 | arbiter.events.clear(); |
| 96 | |
| 97 | // WHEN |
| 98 | boundingVolumeDebug.setRadius(1340.0f); |
| 99 | |
| 100 | // THEN |
| 101 | QCOMPARE(arbiter.events.count(), 0); |
| 102 | |
| 103 | |
| 104 | // WHEN |
| 105 | boundingVolumeDebug.setCenter(QVector3D(1.0f, 2.0f, 3.0f)); |
| 106 | |
| 107 | // THEN |
| 108 | QCOMPARE(arbiter.events.count(), 1); |
| 109 | change = arbiter.events.first().staticCast<Qt3DCore::QNodePropertyChange>(); |
| 110 | QCOMPARE(change->propertyName(), "center"); |
| 111 | QCOMPARE(change->value().value<QVector3D>(), QVector3D(1.0f, 2.0f, 3.0f)); |
| 112 | |
| 113 | arbiter.events.clear(); |
| 114 | |
| 115 | // WHEN |
| 116 | boundingVolumeDebug.setCenter(QVector3D(1.0f, 2.0f, 3.0f)); |
| 117 | |
| 118 | |
| 119 | // THEN |
| 120 | QCOMPARE(arbiter.events.count(), 0); |
| 121 | } |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | QTEST_APPLESS_MAIN(tst_BoundingVolumeDebug) |
| 126 | |
| 127 | #include "tst_boundingvolumedebug.moc" |