| 1 | // Copyright (C) 2016 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/qtextureimage.h> |
| 10 | #include <Qt3DRender/private/qtextureimage_p.h> |
| 11 | #include <QObject> |
| 12 | #include <QSignalSpy> |
| 13 | #include "testarbiter.h" |
| 14 | |
| 15 | class tst_QTextureImage : public QObject |
| 16 | { |
| 17 | Q_OBJECT |
| 18 | |
| 19 | private Q_SLOTS: |
| 20 | |
| 21 | void checkDefaultConstruction() |
| 22 | { |
| 23 | // GIVEN |
| 24 | Qt3DRender::QTextureImage textureImage; |
| 25 | |
| 26 | // THEN |
| 27 | QCOMPARE(textureImage.source(), QUrl()); |
| 28 | QCOMPARE(textureImage.status(), Qt3DRender::QTextureImage::None); |
| 29 | QCOMPARE(textureImage.isMirrored(), true); |
| 30 | } |
| 31 | |
| 32 | void checkPropertyChanges() |
| 33 | { |
| 34 | // GIVEN |
| 35 | Qt3DRender::QTextureImage textureImage; |
| 36 | |
| 37 | { |
| 38 | // WHEN |
| 39 | QSignalSpy spy(&textureImage, SIGNAL(sourceChanged(QUrl))); |
| 40 | const QUrl newValue(QStringLiteral("Boulder")); |
| 41 | textureImage.setSource(newValue); |
| 42 | |
| 43 | // THEN |
| 44 | QVERIFY(spy.isValid()); |
| 45 | QCOMPARE(textureImage.source(), newValue); |
| 46 | QCOMPARE(spy.size(), 1); |
| 47 | |
| 48 | // WHEN |
| 49 | spy.clear(); |
| 50 | textureImage.setSource(newValue); |
| 51 | |
| 52 | // THEN |
| 53 | QCOMPARE(textureImage.source(), newValue); |
| 54 | QCOMPARE(spy.size(), 0); |
| 55 | } |
| 56 | { |
| 57 | // WHEN |
| 58 | QSignalSpy spy(&textureImage, SIGNAL(mirroredChanged(bool))); |
| 59 | const bool newValue = false; |
| 60 | textureImage.setMirrored(newValue); |
| 61 | |
| 62 | // THEN |
| 63 | QVERIFY(spy.isValid()); |
| 64 | QCOMPARE(textureImage.isMirrored(), newValue); |
| 65 | QCOMPARE(spy.size(), 1); |
| 66 | |
| 67 | // WHEN |
| 68 | spy.clear(); |
| 69 | textureImage.setMirrored(newValue); |
| 70 | |
| 71 | // THEN |
| 72 | QCOMPARE(textureImage.isMirrored(), newValue); |
| 73 | QCOMPARE(spy.size(), 0); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void checkSourceUpdate() |
| 78 | { |
| 79 | // GIVEN |
| 80 | TestArbiter arbiter; |
| 81 | Qt3DRender::QTextureImage textureImage; |
| 82 | arbiter.setArbiterOnNode(&textureImage); |
| 83 | |
| 84 | { |
| 85 | // WHEN |
| 86 | textureImage.setSource(QUrl(QStringLiteral("Qt3D"))); |
| 87 | QCoreApplication::processEvents(); |
| 88 | |
| 89 | // THEN |
| 90 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 91 | QCOMPARE(arbiter.dirtyNodes().front(), &textureImage); |
| 92 | |
| 93 | arbiter.clear(); |
| 94 | } |
| 95 | |
| 96 | { |
| 97 | // WHEN |
| 98 | textureImage.setSource(QUrl(QStringLiteral("Qt3D"))); |
| 99 | QCoreApplication::processEvents(); |
| 100 | |
| 101 | // THEN |
| 102 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | void checkMirroredUpdate() |
| 108 | { |
| 109 | // GIVEN |
| 110 | TestArbiter arbiter; |
| 111 | Qt3DRender::QTextureImage textureImage; |
| 112 | arbiter.setArbiterOnNode(&textureImage); |
| 113 | |
| 114 | { |
| 115 | // WHEN |
| 116 | textureImage.setMirrored(false); |
| 117 | QCoreApplication::processEvents(); |
| 118 | |
| 119 | // THEN |
| 120 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 121 | QCOMPARE(arbiter.dirtyNodes().front(), &textureImage); |
| 122 | |
| 123 | arbiter.clear(); |
| 124 | } |
| 125 | |
| 126 | { |
| 127 | // WHEN |
| 128 | textureImage.setMirrored(false); |
| 129 | QCoreApplication::processEvents(); |
| 130 | |
| 131 | // THEN |
| 132 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | }; |
| 138 | |
| 139 | QTEST_MAIN(tst_QTextureImage) |
| 140 | |
| 141 | #include "tst_qtextureimage.moc" |