| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com> |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | |
| 30 | #include <QtTest/QTest> |
| 31 | #include <Qt3DRender/qmemorybarrier.h> |
| 32 | #include <Qt3DRender/private/qmemorybarrier_p.h> |
| 33 | #include <QObject> |
| 34 | #include <QSignalSpy> |
| 35 | #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> |
| 36 | #include <Qt3DCore/qnodecreatedchange.h> |
| 37 | #include "testpostmanarbiter.h" |
| 38 | |
| 39 | class tst_QMemoryBarrier : public QObject |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | private Q_SLOTS: |
| 44 | |
| 45 | void initTestCase() |
| 46 | { |
| 47 | qRegisterMetaType<Qt3DRender::QMemoryBarrier::Operations>(typeName: "QMemoryBarrier::Operations" ); |
| 48 | } |
| 49 | |
| 50 | void checkDefaultConstruction() |
| 51 | { |
| 52 | // GIVEN |
| 53 | Qt3DRender::QMemoryBarrier memoryBarrier; |
| 54 | |
| 55 | // THEN |
| 56 | QCOMPARE(memoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::None); |
| 57 | } |
| 58 | |
| 59 | void checkPropertyChanges() |
| 60 | { |
| 61 | // GIVEN |
| 62 | Qt3DRender::QMemoryBarrier memoryBarrier; |
| 63 | |
| 64 | { |
| 65 | // WHEN |
| 66 | QSignalSpy spy(&memoryBarrier, SIGNAL(waitOperationsChanged(QMemoryBarrier::Operations))); |
| 67 | const Qt3DRender::QMemoryBarrier::Operations newValue(Qt3DRender::QMemoryBarrier::ShaderStorage|Qt3DRender::QMemoryBarrier::VertexAttributeArray); |
| 68 | memoryBarrier.setWaitOperations(newValue); |
| 69 | |
| 70 | // THEN |
| 71 | QVERIFY(spy.isValid()); |
| 72 | QCOMPARE(memoryBarrier.waitOperations(), newValue); |
| 73 | QCOMPARE(spy.count(), 1); |
| 74 | |
| 75 | // WHEN |
| 76 | spy.clear(); |
| 77 | memoryBarrier.setWaitOperations(newValue); |
| 78 | |
| 79 | // THEN |
| 80 | QCOMPARE(memoryBarrier.waitOperations(), newValue); |
| 81 | QCOMPARE(spy.count(), 0); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void checkCreationData() |
| 86 | { |
| 87 | // GIVEN |
| 88 | Qt3DRender::QMemoryBarrier memoryBarrier; |
| 89 | |
| 90 | memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::Command); |
| 91 | |
| 92 | // WHEN |
| 93 | QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; |
| 94 | |
| 95 | { |
| 96 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&memoryBarrier); |
| 97 | creationChanges = creationChangeGenerator.creationChanges(); |
| 98 | } |
| 99 | |
| 100 | // THEN |
| 101 | { |
| 102 | QCOMPARE(creationChanges.size(), 1); |
| 103 | |
| 104 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QMemoryBarrierData>>(src: creationChanges.first()); |
| 105 | const Qt3DRender::QMemoryBarrierData cloneData = creationChangeData->data; |
| 106 | |
| 107 | QCOMPARE(memoryBarrier.waitOperations(), cloneData.waitOperations); |
| 108 | QCOMPARE(memoryBarrier.id(), creationChangeData->subjectId()); |
| 109 | QCOMPARE(memoryBarrier.isEnabled(), true); |
| 110 | QCOMPARE(memoryBarrier.isEnabled(), creationChangeData->isNodeEnabled()); |
| 111 | QCOMPARE(memoryBarrier.metaObject(), creationChangeData->metaObject()); |
| 112 | } |
| 113 | |
| 114 | // WHEN |
| 115 | memoryBarrier.setEnabled(false); |
| 116 | |
| 117 | { |
| 118 | Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&memoryBarrier); |
| 119 | creationChanges = creationChangeGenerator.creationChanges(); |
| 120 | } |
| 121 | |
| 122 | // THEN |
| 123 | { |
| 124 | QCOMPARE(creationChanges.size(), 1); |
| 125 | |
| 126 | const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QMemoryBarrierData>>(src: creationChanges.first()); |
| 127 | const Qt3DRender::QMemoryBarrierData cloneData = creationChangeData->data; |
| 128 | |
| 129 | QCOMPARE(memoryBarrier.waitOperations(), cloneData.waitOperations); |
| 130 | QCOMPARE(memoryBarrier.id(), creationChangeData->subjectId()); |
| 131 | QCOMPARE(memoryBarrier.isEnabled(), false); |
| 132 | QCOMPARE(memoryBarrier.isEnabled(), creationChangeData->isNodeEnabled()); |
| 133 | QCOMPARE(memoryBarrier.metaObject(), creationChangeData->metaObject()); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | void checkTypesUpdate() |
| 138 | { |
| 139 | // GIVEN |
| 140 | TestArbiter arbiter; |
| 141 | Qt3DRender::QMemoryBarrier memoryBarrier; |
| 142 | arbiter.setArbiterOnNode(&memoryBarrier); |
| 143 | |
| 144 | { |
| 145 | // WHEN |
| 146 | memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::ShaderStorage); |
| 147 | QCoreApplication::processEvents(); |
| 148 | |
| 149 | // THEN |
| 150 | QCOMPARE(arbiter.events.size(), 0); |
| 151 | QCOMPARE(arbiter.dirtyNodes.size(), 1); |
| 152 | QCOMPARE(arbiter.dirtyNodes.front(), &memoryBarrier); |
| 153 | |
| 154 | arbiter.dirtyNodes.clear(); |
| 155 | } |
| 156 | |
| 157 | { |
| 158 | // WHEN |
| 159 | memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::ShaderStorage); |
| 160 | QCoreApplication::processEvents(); |
| 161 | |
| 162 | // THEN |
| 163 | QCOMPARE(arbiter.events.size(), 0); |
| 164 | QCOMPARE(arbiter.dirtyNodes.size(), 0); |
| 165 | } |
| 166 | |
| 167 | } |
| 168 | |
| 169 | }; |
| 170 | |
| 171 | QTEST_MAIN(tst_QMemoryBarrier) |
| 172 | |
| 173 | #include "tst_qmemorybarrier.moc" |
| 174 | |