| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2018 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | // TODO Remove in Qt6 | 
| 30 | #include <QtCore/qcompilerdetection.h> | 
| 31 | QT_WARNING_DISABLE_DEPRECATED | 
| 32 |  | 
| 33 | #include <QtTest/QTest> | 
| 34 | #include <Qt3DRender/qtexture.h> | 
| 35 | #include <Qt3DRender/private/qtexture_p.h> | 
| 36 | #include <QObject> | 
| 37 | #include <QSignalSpy> | 
| 38 | #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> | 
| 39 | #include <Qt3DCore/qnodecreatedchange.h> | 
| 40 | #include "testpostmanarbiter.h" | 
| 41 |  | 
| 42 | class tst_QSharedGLTexture : public QObject | 
| 43 | { | 
| 44 |     Q_OBJECT | 
| 45 |  | 
| 46 | private Q_SLOTS: | 
| 47 |  | 
| 48 |     void checkDefaultConstruction() | 
| 49 |     { | 
| 50 |         // GIVEN | 
| 51 |         Qt3DRender::QSharedGLTexture glTexture; | 
| 52 |  | 
| 53 |         // THEN | 
| 54 |         QCOMPARE(glTexture.textureId(), -1); | 
| 55 |         QCOMPARE(glTexture.target(), Qt3DRender::QAbstractTexture::TargetAutomatic); | 
| 56 |     } | 
| 57 |  | 
| 58 |     void checkPropertyChanges() | 
| 59 |     { | 
| 60 |         // GIVEN | 
| 61 |         Qt3DRender::QSharedGLTexture glTexture; | 
| 62 |  | 
| 63 |         { | 
| 64 |             // WHEN | 
| 65 |             QSignalSpy spy(&glTexture, SIGNAL(textureIdChanged(int))); | 
| 66 |             const int newValue = 883; | 
| 67 |             glTexture.setTextureId(newValue); | 
| 68 |  | 
| 69 |             // THEN | 
| 70 |             QVERIFY(spy.isValid()); | 
| 71 |             QCOMPARE(glTexture.textureId(), newValue); | 
| 72 |             QCOMPARE(spy.count(), 1); | 
| 73 |  | 
| 74 |             // WHEN | 
| 75 |             spy.clear(); | 
| 76 |             glTexture.setTextureId(newValue); | 
| 77 |  | 
| 78 |             // THEN | 
| 79 |             QCOMPARE(glTexture.textureId(), newValue); | 
| 80 |             QCOMPARE(spy.count(), 0); | 
| 81 |         } | 
| 82 |     } | 
| 83 |  | 
| 84 |     void checkCreationData() | 
| 85 |     { | 
| 86 |         // GIVEN | 
| 87 |         Qt3DRender::QSharedGLTexture glTexture; | 
| 88 |  | 
| 89 |         glTexture.setTextureId(1200); | 
| 90 |  | 
| 91 |         // WHEN | 
| 92 |         QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; | 
| 93 |  | 
| 94 |         { | 
| 95 |             Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&glTexture); | 
| 96 |             creationChanges = creationChangeGenerator.creationChanges(); | 
| 97 |         } | 
| 98 |  | 
| 99 |         // THEN | 
| 100 |         { | 
| 101 |             QCOMPARE(creationChanges.size(), 1); | 
| 102 |  | 
| 103 |             const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QAbstractTextureData>>(src: creationChanges.first()); | 
| 104 |             const Qt3DRender::QAbstractTextureData cloneData = creationChangeData->data; | 
| 105 |  | 
| 106 |             QCOMPARE(glTexture.id(), creationChangeData->subjectId()); | 
| 107 |             QCOMPARE(glTexture.isEnabled(), true); | 
| 108 |             QCOMPARE(glTexture.isEnabled(), creationChangeData->isNodeEnabled()); | 
| 109 |             QCOMPARE(glTexture.metaObject(), creationChangeData->metaObject()); | 
| 110 |             QCOMPARE(cloneData.sharedTextureId, 1200); | 
| 111 |         } | 
| 112 |  | 
| 113 |         // WHEN | 
| 114 |         glTexture.setEnabled(false); | 
| 115 |  | 
| 116 |         { | 
| 117 |             Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&glTexture); | 
| 118 |             creationChanges = creationChangeGenerator.creationChanges(); | 
| 119 |         } | 
| 120 |  | 
| 121 |         // THEN | 
| 122 |         { | 
| 123 |             QCOMPARE(creationChanges.size(), 1); | 
| 124 |  | 
| 125 |             const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QAbstractTextureData>>(src: creationChanges.first()); | 
| 126 |             const Qt3DRender::QAbstractTextureData cloneData = creationChangeData->data; | 
| 127 |  | 
| 128 |             QCOMPARE(glTexture.id(), creationChangeData->subjectId()); | 
| 129 |             QCOMPARE(glTexture.isEnabled(), false); | 
| 130 |             QCOMPARE(glTexture.isEnabled(), creationChangeData->isNodeEnabled()); | 
| 131 |             QCOMPARE(glTexture.metaObject(), creationChangeData->metaObject()); | 
| 132 |             QCOMPARE(cloneData.sharedTextureId, 1200); | 
| 133 |         } | 
| 134 |     } | 
| 135 |  | 
| 136 |     void checkTextureIdUpdate() | 
| 137 |     { | 
| 138 |         // GIVEN | 
| 139 |         TestArbiter arbiter; | 
| 140 |         Qt3DRender::QSharedGLTexture glTexture; | 
| 141 |         arbiter.setArbiterOnNode(&glTexture); | 
| 142 |  | 
| 143 |         { | 
| 144 |             // WHEN | 
| 145 |             glTexture.setTextureId(1584); | 
| 146 |             QCoreApplication::processEvents(); | 
| 147 |  | 
| 148 |             // THEN | 
| 149 |             QCOMPARE(arbiter.events.size(), 0); | 
| 150 |             QCOMPARE(arbiter.dirtyNodes.size(), 1); | 
| 151 |             QCOMPARE(arbiter.dirtyNodes.front(), &glTexture); | 
| 152 |  | 
| 153 |             arbiter.dirtyNodes.clear(); | 
| 154 |         } | 
| 155 |  | 
| 156 |         { | 
| 157 |             // WHEN | 
| 158 |             glTexture.setTextureId(1584); | 
| 159 |             QCoreApplication::processEvents(); | 
| 160 |  | 
| 161 |             // THEN | 
| 162 |             QCOMPARE(arbiter.events.size(), 0); | 
| 163 |             QCOMPARE(arbiter.dirtyNodes.size(), 0); | 
| 164 |         } | 
| 165 |  | 
| 166 |     } | 
| 167 |  | 
| 168 | }; | 
| 169 |  | 
| 170 | QTEST_MAIN(tst_QSharedGLTexture) | 
| 171 |  | 
| 172 | #include "tst_qsharedgltexture.moc" | 
| 173 |  |