| 1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DCore/private/qnode_p.h> |
| 6 | #include <Qt3DCore/private/qscene_p.h> |
| 7 | #include <Qt3DCore/qentity.h> |
| 8 | |
| 9 | #include <Qt3DRender/qsortpolicy.h> |
| 10 | #include <Qt3DRender/private/qsortpolicy_p.h> |
| 11 | |
| 12 | #include "testarbiter.h" |
| 13 | |
| 14 | // We need to call QNode::clone which is protected |
| 15 | // So we sublcass QNode instead of QObject |
| 16 | class tst_QSortPolicy: public Qt3DCore::QNode |
| 17 | { |
| 18 | Q_OBJECT |
| 19 | |
| 20 | private Q_SLOTS: |
| 21 | |
| 22 | void checkSaneDefaults() |
| 23 | { |
| 24 | QScopedPointer<Qt3DRender::QSortPolicy> defaultsortPolicy(new Qt3DRender::QSortPolicy); |
| 25 | |
| 26 | QVERIFY(defaultsortPolicy->sortTypes().isEmpty()); |
| 27 | } |
| 28 | |
| 29 | void checkPropertyUpdates() |
| 30 | { |
| 31 | // GIVEN |
| 32 | TestArbiter arbiter; |
| 33 | QScopedPointer<Qt3DRender::QSortPolicy> sortPolicy(new Qt3DRender::QSortPolicy()); |
| 34 | arbiter.setArbiterOnNode(sortPolicy.data()); |
| 35 | |
| 36 | // WHEN |
| 37 | const QList<Qt3DRender::QSortPolicy::SortType> sortTypes = { Qt3DRender::QSortPolicy::BackToFront, |
| 38 | Qt3DRender::QSortPolicy::Material, |
| 39 | Qt3DRender::QSortPolicy::Material, |
| 40 | Qt3DRender::QSortPolicy::FrontToBack }; |
| 41 | auto sortTypesInt = QList<int>(); |
| 42 | transformVector(sortTypes, sortTypesInt); |
| 43 | sortPolicy->setSortTypes(sortTypes); |
| 44 | QCoreApplication::processEvents(); |
| 45 | |
| 46 | // THEN |
| 47 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 48 | QCOMPARE(arbiter.dirtyNodes().front(), sortPolicy.data()); |
| 49 | |
| 50 | arbiter.clear(); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | QTEST_MAIN(tst_QSortPolicy) |
| 55 | |
| 56 | #include "tst_qsortpolicy.moc" |