| 1 | /**************************************************************************** | 
|---|---|
| 2 | ** | 
| 3 | ** Copyright (C) 2014 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 <Qt3DCore/private/qchangearbiter_p.h> | 
| 35 | #include <Qt3DCore/private/qscene_p.h> | 
| 36 | #include <Qt3DCore/qnode.h> | 
| 37 | #include <Qt3DCore/qentity.h> | 
| 38 | #include <Qt3DCore/qcomponent.h> | 
| 39 | #include <Qt3DCore/qbackendnode.h> | 
| 40 | #include <Qt3DCore/private/qnode_p.h> | 
| 41 | #include <Qt3DCore/private/qbackendnode_p.h> | 
| 42 | #include <QThread> | 
| 43 | #include <QWaitCondition> | 
| 44 | #include "testpostmanarbiter.h" | 
| 45 | |
| 46 | class tst_QChangeArbiter : public QObject | 
| 47 | { | 
| 48 | Q_OBJECT | 
| 49 | |
| 50 | private slots: | 
| 51 | void recordsDirtyNodes(); | 
| 52 | }; | 
| 53 | |
| 54 | // used to test property change notifications | 
| 55 | class PropertyTestNode : public Qt3DCore::QNode | 
| 56 | { | 
| 57 | Q_OBJECT | 
| 58 | Q_PROPERTY(int prop1 READ prop1 WRITE setProp1 NOTIFY prop1Changed) | 
| 59 | Q_PROPERTY(float prop2 READ prop2 WRITE setProp2 NOTIFY prop2Changed) | 
| 60 | |
| 61 | public: | 
| 62 | explicit PropertyTestNode(Qt3DCore::QNode *parent = 0) : Qt3DCore::QNode(parent) | 
| 63 | {} | 
| 64 | |
| 65 | int prop1() const { return m_prop1; } | 
| 66 | void setProp1(int v) | 
| 67 | { | 
| 68 | if (m_prop1 != v) { | 
| 69 | m_prop1 = v; | 
| 70 | Q_EMIT prop1Changed(v); | 
| 71 | } | 
| 72 | } | 
| 73 | |
| 74 | float prop2() const { return m_prop2; } | 
| 75 | void setProp2(float v) | 
| 76 | { | 
| 77 | if (m_prop2 != v) { | 
| 78 | m_prop2 = v; | 
| 79 | Q_EMIT prop2Changed(v); | 
| 80 | } | 
| 81 | } | 
| 82 | |
| 83 | Q_SIGNALS: | 
| 84 | void prop1Changed(int v); | 
| 85 | void prop2Changed(float v); | 
| 86 | |
| 87 | private: | 
| 88 | int m_prop1 = 0; | 
| 89 | float m_prop2 = 0.0f; | 
| 90 | }; | 
| 91 | |
| 92 | void tst_QChangeArbiter::recordsDirtyNodes() | 
| 93 | { | 
| 94 | // GIVEN | 
| 95 | QScopedPointer<TestArbiter> arbiter(new TestArbiter()); | 
| 96 | QScopedPointer<Qt3DCore::QScene> scene(new Qt3DCore::QScene()); | 
| 97 | // arbiter->setScene(scene.data()); | 
| 98 | scene->setArbiter(arbiter.data()); | 
| 99 | |
| 100 | // WHEN | 
| 101 | auto *root = new PropertyTestNode(); | 
| 102 | auto *child = new PropertyTestNode(root); | 
| 103 | |
| 104 | root->setProp1(883); | 
| 105 | child->setProp2(1584); | 
| 106 | |
| 107 | // THEN | 
| 108 | QCOMPARE(arbiter->dirtyNodes.size(), 0); | 
| 109 | |
| 110 | // WHEN | 
| 111 | Qt3DCore::QNodePrivate::get(q: root)->setArbiter(arbiter.data()); | 
| 112 | root->setProp1(884); | 
| 113 | child->setProp2(1585); | 
| 114 | |
| 115 | // THEN | 
| 116 | QCOMPARE(arbiter->dirtyNodes.size(), 1); | 
| 117 | QCOMPARE(arbiter->dirtyNodes.front(), root); | 
| 118 | |
| 119 | arbiter->dirtyNodes.clear(); | 
| 120 | |
| 121 | // WHEN | 
| 122 | Qt3DCore::QNodePrivate::get(q: child)->setArbiter(arbiter.data()); | 
| 123 | child->setProp2(1586); | 
| 124 | |
| 125 | // THEN | 
| 126 | QCOMPARE(arbiter->dirtyNodes.size(), 1); | 
| 127 | QCOMPARE(arbiter->dirtyNodes.front(), child); | 
| 128 | |
| 129 | arbiter->dirtyNodes.clear(); | 
| 130 | |
| 131 | // WHEN | 
| 132 | root->setProp1(887); | 
| 133 | child->setProp2(1587); | 
| 134 | |
| 135 | // THEN | 
| 136 | QCOMPARE(arbiter->dirtyNodes.size(), 2); | 
| 137 | } | 
| 138 | |
| 139 | QTEST_MAIN(tst_QChangeArbiter) | 
| 140 | |
| 141 | #include "tst_qchangearbiter.moc" | 
| 142 | 
