1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Paul Lemire <paul.lemire350@gmail.com> |
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 | |
30 | #include <QtTest/QTest> |
31 | #include <Qt3DRender/qproximityfilter.h> |
32 | #include <Qt3DRender/private/qproximityfilter_p.h> |
33 | #include <Qt3DRender/private/proximityfilter_p.h> |
34 | #include "qbackendnodetester.h" |
35 | #include "testrenderer.h" |
36 | |
37 | class tst_ProximityFilter : public Qt3DCore::QBackendNodeTester |
38 | { |
39 | Q_OBJECT |
40 | |
41 | private Q_SLOTS: |
42 | |
43 | void checkInitialState() |
44 | { |
45 | // GIVEN |
46 | Qt3DRender::Render::ProximityFilter backendProximityFilter; |
47 | |
48 | // THEN |
49 | QCOMPARE(backendProximityFilter.isEnabled(), false); |
50 | QVERIFY(backendProximityFilter.peerId().isNull()); |
51 | QCOMPARE(backendProximityFilter.distanceThreshold(), 0.0f); |
52 | QCOMPARE(backendProximityFilter.entityId(), Qt3DCore::QNodeId()); |
53 | } |
54 | |
55 | void checkInitializeFromPeer() |
56 | { |
57 | // GIVEN |
58 | TestRenderer renderer; |
59 | Qt3DRender::QProximityFilter proximityFilter; |
60 | Qt3DCore::QEntity entity; |
61 | proximityFilter.setDistanceThreshold(1340.0f); |
62 | proximityFilter.setEntity(&entity); |
63 | |
64 | { |
65 | // WHEN |
66 | Qt3DRender::Render::ProximityFilter backendProximityFilter; |
67 | backendProximityFilter.setRenderer(&renderer); |
68 | simulateInitializationSync(frontend: &proximityFilter, backend: &backendProximityFilter); |
69 | |
70 | // THEN |
71 | QCOMPARE(backendProximityFilter.isEnabled(), true); |
72 | QCOMPARE(backendProximityFilter.peerId(), proximityFilter.id()); |
73 | QCOMPARE(backendProximityFilter.distanceThreshold(), 1340.f); |
74 | QCOMPARE(backendProximityFilter.entityId(), entity.id()); |
75 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
76 | } |
77 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
78 | { |
79 | // WHEN |
80 | Qt3DRender::Render::ProximityFilter backendProximityFilter; |
81 | backendProximityFilter.setRenderer(&renderer); |
82 | proximityFilter.setEnabled(false); |
83 | simulateInitializationSync(frontend: &proximityFilter, backend: &backendProximityFilter); |
84 | |
85 | // THEN |
86 | QCOMPARE(backendProximityFilter.peerId(), proximityFilter.id()); |
87 | QCOMPARE(backendProximityFilter.isEnabled(), false); |
88 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
89 | } |
90 | } |
91 | |
92 | void checkSceneChangeEvents() |
93 | { |
94 | // GIVEN |
95 | Qt3DRender::QProximityFilter proximityFilter; |
96 | Qt3DRender::Render::ProximityFilter backendProximityFilter; |
97 | TestRenderer renderer; |
98 | backendProximityFilter.setRenderer(&renderer); |
99 | simulateInitializationSync(frontend: &proximityFilter, backend: &backendProximityFilter); |
100 | |
101 | { |
102 | // WHEN |
103 | const bool newValue = false; |
104 | proximityFilter.setEnabled(newValue); |
105 | backendProximityFilter.syncFromFrontEnd(frontEnd: &proximityFilter, firstTime: false); |
106 | |
107 | // THEN |
108 | QCOMPARE(backendProximityFilter.isEnabled(), newValue); |
109 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
110 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
111 | } |
112 | { |
113 | // WHEN |
114 | const float newValue = 383.0f; |
115 | proximityFilter.setDistanceThreshold(newValue); |
116 | backendProximityFilter.syncFromFrontEnd(frontEnd: &proximityFilter, firstTime: false); |
117 | |
118 | |
119 | // THEN |
120 | QCOMPARE(backendProximityFilter.distanceThreshold(), newValue); |
121 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
122 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
123 | } |
124 | { |
125 | // WHEN |
126 | Qt3DCore::QEntity e; |
127 | proximityFilter.setEntity(&e); |
128 | backendProximityFilter.syncFromFrontEnd(frontEnd: &proximityFilter, firstTime: false); |
129 | |
130 | // THEN |
131 | QCOMPARE(backendProximityFilter.entityId(), e.id()); |
132 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
133 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
134 | } |
135 | } |
136 | |
137 | }; |
138 | |
139 | QTEST_MAIN(tst_ProximityFilter) |
140 | |
141 | #include "tst_proximityfilter.moc" |
142 | |