| 1 | // Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DRender/qsetfence.h> |
| 6 | #include <Qt3DRender/private/qsetfence_p.h> |
| 7 | #include <QObject> |
| 8 | #include <QSignalSpy> |
| 9 | #include <Qt3DCore/private/qscene_p.h> |
| 10 | #include "testarbiter.h" |
| 11 | |
| 12 | class MySetFence : public Qt3DRender::QSetFence |
| 13 | { |
| 14 | public: |
| 15 | }; |
| 16 | |
| 17 | class tst_QSetFence : public QObject |
| 18 | { |
| 19 | Q_OBJECT |
| 20 | |
| 21 | private Q_SLOTS: |
| 22 | |
| 23 | void initTestCase() |
| 24 | { |
| 25 | qRegisterMetaType<Qt3DRender::QSetFence::HandleType>("HandleType"); |
| 26 | } |
| 27 | |
| 28 | void checkDefaultConstruction() |
| 29 | { |
| 30 | // GIVEN |
| 31 | Qt3DRender::QSetFence setFence; |
| 32 | |
| 33 | // THEN |
| 34 | QCOMPARE(setFence.handleType(), Qt3DRender::QSetFence::NoHandle); |
| 35 | QCOMPARE(setFence.handle(), QVariant()); |
| 36 | } |
| 37 | |
| 38 | void checkPropertyChanges() |
| 39 | { |
| 40 | // GIVEN |
| 41 | Qt3DCore::QScene scene; |
| 42 | MySetFence setFence; |
| 43 | |
| 44 | Qt3DCore::QNodePrivate::get(&setFence)->setScene(&scene); |
| 45 | |
| 46 | { |
| 47 | // WHEN |
| 48 | QSignalSpy spy(&setFence, SIGNAL(handleTypeChanged(HandleType))); |
| 49 | |
| 50 | // THEN |
| 51 | QVERIFY(spy.isValid()); |
| 52 | |
| 53 | // THEN |
| 54 | auto *dNode = static_cast<Qt3DRender::QSetFencePrivate *>(Qt3DRender::QSetFencePrivate::get(&setFence)); |
| 55 | dNode->setHandleType(Qt3DRender::QSetFence::OpenGLFenceId); |
| 56 | |
| 57 | // THEN |
| 58 | QCOMPARE(setFence.handleType(), Qt3DRender::QSetFence::OpenGLFenceId); |
| 59 | QCOMPARE(spy.size(), 1); |
| 60 | |
| 61 | // WHEN |
| 62 | spy.clear(); |
| 63 | dNode->setHandleType(Qt3DRender::QSetFence::OpenGLFenceId); |
| 64 | |
| 65 | // THEN |
| 66 | QCOMPARE(spy.size(), 0); |
| 67 | } |
| 68 | |
| 69 | { |
| 70 | // WHEN |
| 71 | QSignalSpy spy(&setFence, SIGNAL(handleChanged(QVariant))); |
| 72 | |
| 73 | // THEN |
| 74 | QVERIFY(spy.isValid()); |
| 75 | |
| 76 | // WHEN |
| 77 | auto *dNode = static_cast<Qt3DRender::QSetFencePrivate *>(Qt3DRender::QSetFencePrivate::get(&setFence)); |
| 78 | dNode->setHandle(QVariant(984)); |
| 79 | |
| 80 | // THEN |
| 81 | QCOMPARE(setFence.handle(),QVariant(984)); |
| 82 | QCOMPARE(spy.size(), 1); |
| 83 | |
| 84 | // WHEN |
| 85 | spy.clear(); |
| 86 | dNode->setHandle(QVariant(984)); |
| 87 | |
| 88 | // THEN |
| 89 | QCOMPARE(spy.size(), 0); |
| 90 | } |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | QTEST_MAIN(tst_QSetFence) |
| 95 | |
| 96 | #include "tst_qsetfence.moc" |