| 1 | // Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | // TODO Remove in Qt6 |
| 5 | #include <QtCore/qcompilerdetection.h> |
| 6 | QT_WARNING_DISABLE_DEPRECATED |
| 7 | |
| 8 | #include <QtTest/QTest> |
| 9 | #include <Qt3DRender/qtexture.h> |
| 10 | #include <Qt3DRender/private/qtexture_p.h> |
| 11 | #include <QObject> |
| 12 | #include <QSignalSpy> |
| 13 | #include "testarbiter.h" |
| 14 | |
| 15 | class tst_QSharedGLTexture : public QObject |
| 16 | { |
| 17 | Q_OBJECT |
| 18 | |
| 19 | private Q_SLOTS: |
| 20 | |
| 21 | void checkDefaultConstruction() |
| 22 | { |
| 23 | // GIVEN |
| 24 | Qt3DRender::QSharedGLTexture glTexture; |
| 25 | |
| 26 | // THEN |
| 27 | QCOMPARE(glTexture.textureId(), -1); |
| 28 | QCOMPARE(glTexture.target(), Qt3DRender::QAbstractTexture::TargetAutomatic); |
| 29 | } |
| 30 | |
| 31 | void checkPropertyChanges() |
| 32 | { |
| 33 | // GIVEN |
| 34 | Qt3DRender::QSharedGLTexture glTexture; |
| 35 | |
| 36 | { |
| 37 | // WHEN |
| 38 | QSignalSpy spy(&glTexture, SIGNAL(textureIdChanged(int))); |
| 39 | const int newValue = 883; |
| 40 | glTexture.setTextureId(newValue); |
| 41 | |
| 42 | // THEN |
| 43 | QVERIFY(spy.isValid()); |
| 44 | QCOMPARE(glTexture.textureId(), newValue); |
| 45 | QCOMPARE(spy.size(), 1); |
| 46 | |
| 47 | // WHEN |
| 48 | spy.clear(); |
| 49 | glTexture.setTextureId(newValue); |
| 50 | |
| 51 | // THEN |
| 52 | QCOMPARE(glTexture.textureId(), newValue); |
| 53 | QCOMPARE(spy.size(), 0); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void checkTextureIdUpdate() |
| 58 | { |
| 59 | // GIVEN |
| 60 | TestArbiter arbiter; |
| 61 | Qt3DRender::QSharedGLTexture glTexture; |
| 62 | arbiter.setArbiterOnNode(&glTexture); |
| 63 | |
| 64 | { |
| 65 | // WHEN |
| 66 | glTexture.setTextureId(1584); |
| 67 | QCoreApplication::processEvents(); |
| 68 | |
| 69 | // THEN |
| 70 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 71 | QCOMPARE(arbiter.dirtyNodes().front(), &glTexture); |
| 72 | |
| 73 | arbiter.clear(); |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | // WHEN |
| 78 | glTexture.setTextureId(1584); |
| 79 | QCoreApplication::processEvents(); |
| 80 | |
| 81 | // THEN |
| 82 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | |
| 87 | }; |
| 88 | |
| 89 | QTEST_MAIN(tst_QSharedGLTexture) |
| 90 | |
| 91 | #include "tst_qsharedgltexture.moc" |