| 1 | // Copyright (C) 2016 Paul Lemire <[email protected]> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | |
| 5 | #include <QtTest/QTest> |
| 6 | #include <Qt3DRender/qcomputecommand.h> |
| 7 | #include <Qt3DRender/private/qcomputecommand_p.h> |
| 8 | #include <QObject> |
| 9 | #include <QSignalSpy> |
| 10 | #include "testarbiter.h" |
| 11 | |
| 12 | class tst_QComputeCommand : public QObject |
| 13 | { |
| 14 | Q_OBJECT |
| 15 | |
| 16 | private Q_SLOTS: |
| 17 | |
| 18 | void checkDefaultConstruction() |
| 19 | { |
| 20 | // GIVEN |
| 21 | Qt3DRender::QComputeCommand computeCommand; |
| 22 | |
| 23 | // THEN |
| 24 | QCOMPARE(computeCommand.workGroupX(), 1); |
| 25 | QCOMPARE(computeCommand.workGroupY(), 1); |
| 26 | QCOMPARE(computeCommand.workGroupZ(), 1); |
| 27 | QCOMPARE(computeCommand.runType(), Qt3DRender::QComputeCommand::Continuous); |
| 28 | } |
| 29 | |
| 30 | void checkPropertyChanges() |
| 31 | { |
| 32 | // GIVEN |
| 33 | Qt3DRender::QComputeCommand computeCommand; |
| 34 | |
| 35 | { |
| 36 | // WHEN |
| 37 | QSignalSpy spy(&computeCommand, SIGNAL(workGroupXChanged())); |
| 38 | const int newValue = 128; |
| 39 | computeCommand.setWorkGroupX(newValue); |
| 40 | |
| 41 | // THEN |
| 42 | QVERIFY(spy.isValid()); |
| 43 | QCOMPARE(computeCommand.workGroupX(), newValue); |
| 44 | QCOMPARE(spy.size(), 1); |
| 45 | |
| 46 | // WHEN |
| 47 | spy.clear(); |
| 48 | computeCommand.setWorkGroupX(newValue); |
| 49 | |
| 50 | // THEN |
| 51 | QCOMPARE(computeCommand.workGroupX(), newValue); |
| 52 | QCOMPARE(spy.size(), 0); |
| 53 | } |
| 54 | { |
| 55 | // WHEN |
| 56 | QSignalSpy spy(&computeCommand, SIGNAL(workGroupYChanged())); |
| 57 | const int newValue = 256; |
| 58 | computeCommand.setWorkGroupY(newValue); |
| 59 | |
| 60 | // THEN |
| 61 | QVERIFY(spy.isValid()); |
| 62 | QCOMPARE(computeCommand.workGroupY(), newValue); |
| 63 | QCOMPARE(spy.size(), 1); |
| 64 | |
| 65 | // WHEN |
| 66 | spy.clear(); |
| 67 | computeCommand.setWorkGroupY(newValue); |
| 68 | |
| 69 | // THEN |
| 70 | QCOMPARE(computeCommand.workGroupY(), newValue); |
| 71 | QCOMPARE(spy.size(), 0); |
| 72 | } |
| 73 | { |
| 74 | // WHEN |
| 75 | QSignalSpy spy(&computeCommand, SIGNAL(workGroupZChanged())); |
| 76 | const int newValue = 512; |
| 77 | computeCommand.setWorkGroupZ(newValue); |
| 78 | |
| 79 | // THEN |
| 80 | QVERIFY(spy.isValid()); |
| 81 | QCOMPARE(computeCommand.workGroupZ(), newValue); |
| 82 | QCOMPARE(spy.size(), 1); |
| 83 | |
| 84 | // WHEN |
| 85 | spy.clear(); |
| 86 | computeCommand.setWorkGroupZ(newValue); |
| 87 | |
| 88 | // THEN |
| 89 | QCOMPARE(computeCommand.workGroupZ(), newValue); |
| 90 | QCOMPARE(spy.size(), 0); |
| 91 | } |
| 92 | { |
| 93 | // WHEN |
| 94 | QSignalSpy spy(&computeCommand, SIGNAL(runTypeChanged())); |
| 95 | const Qt3DRender::QComputeCommand::RunType newValue = Qt3DRender::QComputeCommand::Manual; |
| 96 | computeCommand.setRunType(newValue); |
| 97 | |
| 98 | // THEN |
| 99 | QVERIFY(spy.isValid()); |
| 100 | QCOMPARE(computeCommand.runType(), newValue); |
| 101 | QCOMPARE(spy.size(), 1); |
| 102 | |
| 103 | // WHEN |
| 104 | spy.clear(); |
| 105 | computeCommand.setRunType(newValue); |
| 106 | |
| 107 | // THEN |
| 108 | QCOMPARE(computeCommand.runType(), newValue); |
| 109 | QCOMPARE(spy.size(), 0); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | void checkWorkGroupXUpdate() |
| 114 | { |
| 115 | // GIVEN |
| 116 | TestArbiter arbiter; |
| 117 | Qt3DRender::QComputeCommand computeCommand; |
| 118 | arbiter.setArbiterOnNode(&computeCommand); |
| 119 | |
| 120 | { |
| 121 | // WHEN |
| 122 | computeCommand.setWorkGroupX(256); |
| 123 | QCoreApplication::processEvents(); |
| 124 | |
| 125 | // THEN |
| 126 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 127 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 128 | |
| 129 | arbiter.clear(); |
| 130 | } |
| 131 | |
| 132 | { |
| 133 | // WHEN |
| 134 | computeCommand.setWorkGroupX(256); |
| 135 | QCoreApplication::processEvents(); |
| 136 | |
| 137 | // THEN |
| 138 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 139 | } |
| 140 | |
| 141 | } |
| 142 | |
| 143 | void checkWorkGroupYUpdate() |
| 144 | { |
| 145 | // GIVEN |
| 146 | TestArbiter arbiter; |
| 147 | Qt3DRender::QComputeCommand computeCommand; |
| 148 | arbiter.setArbiterOnNode(&computeCommand); |
| 149 | |
| 150 | { |
| 151 | // WHEN |
| 152 | computeCommand.setWorkGroupY(512); |
| 153 | |
| 154 | // THEN |
| 155 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 156 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 157 | |
| 158 | arbiter.clear(); |
| 159 | } |
| 160 | |
| 161 | { |
| 162 | // WHEN |
| 163 | computeCommand.setWorkGroupY(512); |
| 164 | |
| 165 | // THEN |
| 166 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 167 | } |
| 168 | |
| 169 | } |
| 170 | |
| 171 | void checkWorkGroupZUpdate() |
| 172 | { |
| 173 | // GIVEN |
| 174 | TestArbiter arbiter; |
| 175 | Qt3DRender::QComputeCommand computeCommand; |
| 176 | arbiter.setArbiterOnNode(&computeCommand); |
| 177 | |
| 178 | { |
| 179 | // WHEN |
| 180 | computeCommand.setWorkGroupZ(64); |
| 181 | QCoreApplication::processEvents(); |
| 182 | |
| 183 | // THEN |
| 184 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 185 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 186 | |
| 187 | arbiter.clear(); |
| 188 | } |
| 189 | |
| 190 | { |
| 191 | // WHEN |
| 192 | computeCommand.setWorkGroupZ(64); |
| 193 | QCoreApplication::processEvents(); |
| 194 | |
| 195 | // THEN |
| 196 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 197 | } |
| 198 | |
| 199 | } |
| 200 | |
| 201 | void checkRunTypeUpdate() |
| 202 | { |
| 203 | // GIVEN |
| 204 | TestArbiter arbiter; |
| 205 | Qt3DRender::QComputeCommand computeCommand; |
| 206 | arbiter.setArbiterOnNode(&computeCommand); |
| 207 | |
| 208 | { |
| 209 | // WHEN |
| 210 | computeCommand.setRunType(Qt3DRender::QComputeCommand::Manual); |
| 211 | QCoreApplication::processEvents(); |
| 212 | |
| 213 | // THEN |
| 214 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 215 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 216 | |
| 217 | arbiter.clear(); |
| 218 | } |
| 219 | |
| 220 | { |
| 221 | // WHEN |
| 222 | computeCommand.setRunType(Qt3DRender::QComputeCommand::Manual); |
| 223 | QCoreApplication::processEvents(); |
| 224 | |
| 225 | // THEN |
| 226 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | void checkTrigger() |
| 231 | { |
| 232 | // GIVEN |
| 233 | TestArbiter arbiter; |
| 234 | Qt3DRender::QComputeCommand computeCommand; |
| 235 | arbiter.setArbiterOnNode(&computeCommand); |
| 236 | computeCommand.setRunType(Qt3DRender::QComputeCommand::Manual); |
| 237 | computeCommand.setEnabled(false); |
| 238 | QCoreApplication::processEvents(); |
| 239 | arbiter.clear(); |
| 240 | |
| 241 | { |
| 242 | // WHEN |
| 243 | computeCommand.trigger(1); |
| 244 | QCoreApplication::processEvents(); |
| 245 | |
| 246 | // THEN |
| 247 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 248 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 249 | QCOMPARE(computeCommand.isEnabled(), true); |
| 250 | |
| 251 | computeCommand.setEnabled(false); |
| 252 | QCoreApplication::processEvents(); |
| 253 | arbiter.clear(); |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | // WHEN |
| 258 | computeCommand.trigger(2); |
| 259 | QCoreApplication::processEvents(); |
| 260 | |
| 261 | // THEN |
| 262 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 263 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 264 | QCOMPARE(computeCommand.isEnabled(), true); |
| 265 | |
| 266 | computeCommand.setEnabled(false); |
| 267 | QCoreApplication::processEvents(); |
| 268 | arbiter.clear(); |
| 269 | } |
| 270 | |
| 271 | { |
| 272 | // WHEN |
| 273 | computeCommand.trigger(10, 11, 12, 1); |
| 274 | QCoreApplication::processEvents(); |
| 275 | |
| 276 | // THEN |
| 277 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 278 | QCOMPARE(arbiter.dirtyNodes().front(), &computeCommand); |
| 279 | QCOMPARE(computeCommand.isEnabled(), true); |
| 280 | QCOMPARE(computeCommand.workGroupX(), 10); |
| 281 | QCOMPARE(computeCommand.workGroupY(), 11); |
| 282 | QCOMPARE(computeCommand.workGroupZ(), 12); |
| 283 | |
| 284 | computeCommand.setEnabled(false); |
| 285 | arbiter.clear(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | }; |
| 290 | |
| 291 | QTEST_MAIN(tst_QComputeCommand) |
| 292 | |
| 293 | #include "tst_qcomputecommand.moc" |