1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 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/qsceneloader.h> |
32 | #include <Qt3DRender/private/scene_p.h> |
33 | #include <Qt3DRender/private/scenemanager_p.h> |
34 | #include <Qt3DCore/qpropertyupdatedchange.h> |
35 | #include <Qt3DCore/private/qbackendnode_p.h> |
36 | #include <Qt3DCore/private/qentity_p.h> |
37 | #include <Qt3DCore/private/qpropertyupdatedchangebase_p.h> |
38 | #include "testpostmanarbiter.h" |
39 | #include "testrenderer.h" |
40 | |
41 | class tst_SceneLoader : public Qt3DCore::QBackendNodeTester |
42 | { |
43 | Q_OBJECT |
44 | private Q_SLOTS: |
45 | |
46 | void checkInitialAndCleanedUpState() |
47 | { |
48 | // GIVEN |
49 | TestRenderer renderer; |
50 | Qt3DRender::Render::Scene sceneLoader; |
51 | Qt3DRender::Render::SceneManager sceneManager; |
52 | |
53 | // THEN |
54 | QVERIFY(sceneLoader.source().isEmpty()); |
55 | QVERIFY(sceneLoader.peerId().isNull()); |
56 | QVERIFY(sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
57 | |
58 | |
59 | // GIVEN |
60 | Qt3DRender::QSceneLoader frontendSceneLoader; |
61 | const QUrl newUrl(QStringLiteral("CorvetteMuseum" )); |
62 | frontendSceneLoader.setSource(newUrl); |
63 | |
64 | // WHEN |
65 | sceneLoader.setRenderer(&renderer); |
66 | sceneLoader.setSceneManager(&sceneManager); |
67 | simulateInitializationSync(frontend: &frontendSceneLoader, backend: &sceneLoader); |
68 | |
69 | // THEN |
70 | QVERIFY(!sceneLoader.peerId().isNull()); |
71 | QCOMPARE(sceneLoader.source(), newUrl); |
72 | |
73 | // WHEN |
74 | sceneLoader.cleanup(); |
75 | |
76 | // THEN |
77 | QVERIFY(sceneLoader.source().isEmpty()); |
78 | } |
79 | |
80 | void checkPeerPropertyMirroring() |
81 | { |
82 | // GIVEN |
83 | TestRenderer renderer; |
84 | Qt3DRender::QSceneLoader frontendSceneLoader; |
85 | frontendSceneLoader.setSource(QUrl(QStringLiteral("file:///CorvetteMuseum" ))); |
86 | |
87 | Qt3DRender::Render::Scene sceneLoader; |
88 | Qt3DRender::Render::SceneManager sceneManager; |
89 | |
90 | // WHEN |
91 | sceneLoader.setRenderer(&renderer); |
92 | sceneLoader.setSceneManager(&sceneManager); |
93 | simulateInitializationSync(frontend: &frontendSceneLoader, backend: &sceneLoader); |
94 | |
95 | // THEN |
96 | QCOMPARE(sceneLoader.peerId(), frontendSceneLoader.id()); |
97 | QCOMPARE(sceneLoader.source(), frontendSceneLoader.source()); |
98 | QVERIFY(!sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
99 | } |
100 | |
101 | void checkPropertyChanges() |
102 | { |
103 | // GIVEN |
104 | TestRenderer renderer; |
105 | Qt3DRender::Render::Scene sceneLoader; |
106 | Qt3DRender::Render::SceneManager sceneManager; |
107 | Qt3DRender::QSceneLoader frontendSceneLoader; |
108 | |
109 | sceneLoader.setRenderer(&renderer); |
110 | sceneLoader.setSceneManager(&sceneManager); |
111 | simulateInitializationSync(frontend: &frontendSceneLoader, backend: &sceneLoader); |
112 | |
113 | // THEN |
114 | QVERIFY(sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
115 | |
116 | // WHEN |
117 | const QUrl newUrl(QStringLiteral("file:///Bownling_Green_KY" )); |
118 | frontendSceneLoader.setSource(newUrl); |
119 | sceneLoader.syncFromFrontEnd(frontEnd: &frontendSceneLoader, firstTime: false); |
120 | |
121 | // THEN |
122 | QCOMPARE(sceneLoader.source(), newUrl); |
123 | QVERIFY(!sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
124 | |
125 | // WHEN |
126 | frontendSceneLoader.setEnabled(false); |
127 | sceneLoader.syncFromFrontEnd(frontEnd: &frontendSceneLoader, firstTime: false); |
128 | |
129 | // THEN |
130 | QCOMPARE(sceneLoader.isEnabled(), false); |
131 | } |
132 | |
133 | void checkProcessEmptyPath() |
134 | { |
135 | // GIVEN |
136 | TestRenderer renderer; |
137 | Qt3DRender::Render::Scene sceneLoader; |
138 | Qt3DRender::Render::SceneManager sceneManager; |
139 | Qt3DRender::QSceneLoader frontendSceneLoader; |
140 | |
141 | sceneLoader.setRenderer(&renderer); |
142 | sceneLoader.setSceneManager(&sceneManager); |
143 | simulateInitializationSync(frontend: &frontendSceneLoader, backend: &sceneLoader); |
144 | |
145 | // THEN |
146 | QVERIFY(sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
147 | |
148 | // WHEN |
149 | const QUrl newUrl(QStringLiteral("file:///Bownling_Green_KY" )); |
150 | frontendSceneLoader.setSource(newUrl); |
151 | sceneLoader.syncFromFrontEnd(frontEnd: &frontendSceneLoader, firstTime: false); |
152 | |
153 | // THEN |
154 | QCOMPARE(sceneLoader.source(), newUrl); |
155 | QVERIFY(!sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
156 | |
157 | // WHEN |
158 | frontendSceneLoader.setSource(QUrl()); |
159 | sceneLoader.syncFromFrontEnd(frontEnd: &frontendSceneLoader, firstTime: false); |
160 | |
161 | // THEN -> we should still have generated a job to reset the scene (immediately) |
162 | QCOMPARE(sceneLoader.source(), QUrl()); |
163 | QVERIFY(!sceneManager.takePendingSceneLoaderJobs().isEmpty()); |
164 | } |
165 | }; |
166 | |
167 | // Note: setSceneSubtree needs a QCoreApplication |
168 | QTEST_MAIN(tst_SceneLoader) |
169 | |
170 | #include "tst_sceneloader.moc" |
171 | |