| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 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 | #include <QtTest/QTest> | 
| 30 | #include <qbackendnodetester.h> | 
| 31 | #include <Qt3DRender/private/sortpolicy_p.h> | 
| 32 | #include "testrenderer.h" | 
| 33 |  | 
| 34 | class tst_SortPolicy : public Qt3DCore::QBackendNodeTester | 
| 35 | { | 
| 36 |     Q_OBJECT | 
| 37 | private Q_SLOTS: | 
| 38 |     void checkInitialState() | 
| 39 |     { | 
| 40 |         // GIVEN | 
| 41 |         TestRenderer renderer; | 
| 42 |         Qt3DRender::Render::SortPolicy backendNode; | 
| 43 |         backendNode.setRenderer(&renderer); | 
| 44 |  | 
| 45 |         // THEN | 
| 46 |         QVERIFY(backendNode.peerId().isNull()); | 
| 47 |         QVERIFY(backendNode.parentId().isNull()); | 
| 48 |         QVERIFY(backendNode.sortTypes().isEmpty()); | 
| 49 |     } | 
| 50 |  | 
| 51 |     void checkPeerPropertyMirroring() | 
| 52 |     { | 
| 53 |         // GIVEN | 
| 54 |         TestRenderer renderer; | 
| 55 |         Qt3DRender::QFrameGraphNode parent; | 
| 56 |         auto parentBackend = new Qt3DRender::Render::FrameGraphNode; | 
| 57 |         parentBackend->setRenderer(&renderer); | 
| 58 |         simulateInitialization(frontend: &parent, backend: parentBackend); | 
| 59 |  | 
| 60 |         Qt3DRender::Render::FrameGraphManager manager; | 
| 61 |         manager.appendNode(id: parent.id(), node: parentBackend); | 
| 62 |  | 
| 63 |         const auto sortTypes = QVector<Qt3DRender::QSortPolicy::SortType>() << Qt3DRender::QSortPolicy::BackToFront | 
| 64 |                                                                             << Qt3DRender::QSortPolicy::Material; | 
| 65 |         Qt3DRender::Render::SortPolicy backendNode; | 
| 66 |         backendNode.setFrameGraphManager(&manager); | 
| 67 |         Qt3DRender::QSortPolicy sortPolicy(&parent); | 
| 68 |         sortPolicy.setSortTypes(sortTypes); | 
| 69 |  | 
| 70 |         // WHEN | 
| 71 |         backendNode.setRenderer(&renderer); | 
| 72 |         simulateInitializationSync(frontend: &sortPolicy, backend: &backendNode); | 
| 73 |  | 
| 74 |         // THEN | 
| 75 |         QCOMPARE(backendNode.peerId(), sortPolicy.id()); | 
| 76 |         QCOMPARE(backendNode.parentId(), parent.id()); | 
| 77 |         QCOMPARE(backendNode.sortTypes(), sortTypes); | 
| 78 |         QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); | 
| 79 |     } | 
| 80 |  | 
| 81 |     void checkPropertyChanges() | 
| 82 |     { | 
| 83 |         // GIVEN | 
| 84 |         const auto sortTypes = QVector<Qt3DRender::QSortPolicy::SortType>() << Qt3DRender::QSortPolicy::BackToFront | 
| 85 |                                                                             << Qt3DRender::QSortPolicy::Material; | 
| 86 |         TestRenderer renderer; | 
| 87 |         Qt3DRender::Render::SortPolicy backendNode; | 
| 88 |         backendNode.setRenderer(&renderer); | 
| 89 |  | 
| 90 |         Qt3DRender::QSortPolicy sortPolicy; | 
| 91 |         sortPolicy.setSortTypes(sortTypes); | 
| 92 |  | 
| 93 |         simulateInitializationSync(frontend: &sortPolicy, backend: &backendNode); | 
| 94 |  | 
| 95 |         // WHEN | 
| 96 |         sortPolicy.setSortTypes(sortTypes); | 
| 97 |         backendNode.syncFromFrontEnd(frontEnd: &sortPolicy, firstTime: false); | 
| 98 |  | 
| 99 |         // THEN | 
| 100 |         QCOMPARE(backendNode.sortTypes(), sortTypes); | 
| 101 |         QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); | 
| 102 |     } | 
| 103 | }; | 
| 104 |  | 
| 105 |  | 
| 106 | QTEST_APPLESS_MAIN(tst_SortPolicy) | 
| 107 |  | 
| 108 | #include "tst_sortpolicy.moc" | 
| 109 |  |