| 1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | |
| 5 | #include <QtTest/QTest> |
| 6 | #include <Qt3DRender/qdispatchcompute.h> |
| 7 | #include <Qt3DRender/private/qdispatchcompute_p.h> |
| 8 | #include <QObject> |
| 9 | #include <QSignalSpy> |
| 10 | #include "testarbiter.h" |
| 11 | |
| 12 | class tst_QDispatchCompute : public QObject |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | |
| 16 | private Q_SLOTS: |
| 17 | |
| 18 | void checkDefaultConstruction() |
| 19 | { |
| 20 | // GIVEN |
| 21 | Qt3DRender::QDispatchCompute dispatchCompute; |
| 22 | |
| 23 | // THEN |
| 24 | QCOMPARE(dispatchCompute.workGroupX(), 1); |
| 25 | QCOMPARE(dispatchCompute.workGroupY(), 1); |
| 26 | QCOMPARE(dispatchCompute.workGroupZ(), 1); |
| 27 | } |
| 28 | |
| 29 | void checkPropertyChanges() |
| 30 | { |
| 31 | // GIVEN |
| 32 | Qt3DRender::QDispatchCompute dispatchCompute; |
| 33 | |
| 34 | { |
| 35 | // WHEN |
| 36 | QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupXChanged())); |
| 37 | const int newValue = 128; |
| 38 | dispatchCompute.setWorkGroupX(newValue); |
| 39 | |
| 40 | // THEN |
| 41 | QVERIFY(spy.isValid()); |
| 42 | QCOMPARE(dispatchCompute.workGroupX(), newValue); |
| 43 | QCOMPARE(spy.size(), 1); |
| 44 | |
| 45 | // WHEN |
| 46 | spy.clear(); |
| 47 | dispatchCompute.setWorkGroupX(newValue); |
| 48 | |
| 49 | // THEN |
| 50 | QCOMPARE(dispatchCompute.workGroupX(), newValue); |
| 51 | QCOMPARE(spy.size(), 0); |
| 52 | } |
| 53 | { |
| 54 | // WHEN |
| 55 | QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupYChanged())); |
| 56 | const int newValue = 1024; |
| 57 | dispatchCompute.setWorkGroupY(newValue); |
| 58 | |
| 59 | // THEN |
| 60 | QVERIFY(spy.isValid()); |
| 61 | QCOMPARE(dispatchCompute.workGroupY(), newValue); |
| 62 | QCOMPARE(spy.size(), 1); |
| 63 | |
| 64 | // WHEN |
| 65 | spy.clear(); |
| 66 | dispatchCompute.setWorkGroupY(newValue); |
| 67 | |
| 68 | // THEN |
| 69 | QCOMPARE(dispatchCompute.workGroupY(), newValue); |
| 70 | QCOMPARE(spy.size(), 0); |
| 71 | } |
| 72 | { |
| 73 | // WHEN |
| 74 | QSignalSpy spy(&dispatchCompute, SIGNAL(workGroupZChanged())); |
| 75 | const int newValue = 32; |
| 76 | dispatchCompute.setWorkGroupZ(newValue); |
| 77 | |
| 78 | // THEN |
| 79 | QVERIFY(spy.isValid()); |
| 80 | QCOMPARE(dispatchCompute.workGroupZ(), newValue); |
| 81 | QCOMPARE(spy.size(), 1); |
| 82 | |
| 83 | // WHEN |
| 84 | spy.clear(); |
| 85 | dispatchCompute.setWorkGroupZ(newValue); |
| 86 | |
| 87 | // THEN |
| 88 | QCOMPARE(dispatchCompute.workGroupZ(), newValue); |
| 89 | QCOMPARE(spy.size(), 0); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | void checkWorkGroupXUpdate() |
| 94 | { |
| 95 | // GIVEN |
| 96 | TestArbiter arbiter; |
| 97 | Qt3DRender::QDispatchCompute dispatchCompute; |
| 98 | arbiter.setArbiterOnNode(&dispatchCompute); |
| 99 | |
| 100 | { |
| 101 | // WHEN |
| 102 | dispatchCompute.setWorkGroupX(883); |
| 103 | QCoreApplication::processEvents(); |
| 104 | |
| 105 | // THEN |
| 106 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 107 | QCOMPARE(arbiter.dirtyNodes().front(), &dispatchCompute); |
| 108 | |
| 109 | arbiter.clear(); |
| 110 | } |
| 111 | |
| 112 | { |
| 113 | // WHEN |
| 114 | dispatchCompute.setWorkGroupX(883); |
| 115 | QCoreApplication::processEvents(); |
| 116 | |
| 117 | // THEN |
| 118 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 119 | } |
| 120 | |
| 121 | } |
| 122 | |
| 123 | void checkWorkGroupYUpdate() |
| 124 | { |
| 125 | // GIVEN |
| 126 | TestArbiter arbiter; |
| 127 | Qt3DRender::QDispatchCompute dispatchCompute; |
| 128 | arbiter.setArbiterOnNode(&dispatchCompute); |
| 129 | |
| 130 | { |
| 131 | // WHEN |
| 132 | dispatchCompute.setWorkGroupY(1340); |
| 133 | QCoreApplication::processEvents(); |
| 134 | |
| 135 | // THEN |
| 136 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 137 | QCOMPARE(arbiter.dirtyNodes().front(), &dispatchCompute); |
| 138 | |
| 139 | arbiter.clear(); |
| 140 | } |
| 141 | |
| 142 | { |
| 143 | // WHEN |
| 144 | dispatchCompute.setWorkGroupY(1340); |
| 145 | QCoreApplication::processEvents(); |
| 146 | |
| 147 | // THEN |
| 148 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 149 | } |
| 150 | |
| 151 | } |
| 152 | |
| 153 | void checkWorkGroupZUpdate() |
| 154 | { |
| 155 | // GIVEN |
| 156 | TestArbiter arbiter; |
| 157 | Qt3DRender::QDispatchCompute dispatchCompute; |
| 158 | arbiter.setArbiterOnNode(&dispatchCompute); |
| 159 | |
| 160 | { |
| 161 | // WHEN |
| 162 | dispatchCompute.setWorkGroupZ(1584); |
| 163 | QCoreApplication::processEvents(); |
| 164 | |
| 165 | // THEN |
| 166 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 167 | QCOMPARE(arbiter.dirtyNodes().front(), &dispatchCompute); |
| 168 | |
| 169 | arbiter.clear(); |
| 170 | } |
| 171 | |
| 172 | { |
| 173 | // WHEN |
| 174 | dispatchCompute.setWorkGroupZ(1584); |
| 175 | QCoreApplication::processEvents(); |
| 176 | |
| 177 | // THEN |
| 178 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 179 | } |
| 180 | |
| 181 | } |
| 182 | |
| 183 | }; |
| 184 | |
| 185 | QTEST_MAIN(tst_QDispatchCompute) |
| 186 | |
| 187 | #include "tst_qdispatchcompute.moc" |