1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2015 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 | #include <QtTest/QTest> |
30 | #include <qbackendnodetester.h> |
31 | #include <Qt3DRender/private/objectpicker_p.h> |
32 | #include <Qt3DRender/qpickevent.h> |
33 | #include <Qt3DRender/qobjectpicker.h> |
34 | #include <Qt3DCore/private/qbackendnode_p.h> |
35 | #include "testpostmanarbiter.h" |
36 | #include "testrenderer.h" |
37 | |
38 | class tst_ObjectPicker : public Qt3DCore::QBackendNodeTester |
39 | { |
40 | Q_OBJECT |
41 | private Q_SLOTS: |
42 | |
43 | void checkInitialSync() |
44 | { |
45 | // GIVEN |
46 | TestRenderer renderer; |
47 | Qt3DRender::Render::ObjectPicker objectPicker; |
48 | Qt3DRender::QObjectPicker picker; |
49 | |
50 | // WHEN |
51 | objectPicker.setRenderer(&renderer); |
52 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
53 | |
54 | // THEN |
55 | QVERIFY(renderer.dirtyBits() != 0); |
56 | } |
57 | |
58 | void checkPeerPropertyMirroring() |
59 | { |
60 | // GIVEN |
61 | TestRenderer renderer; |
62 | Qt3DRender::Render::ObjectPicker objectPicker; |
63 | Qt3DRender::QObjectPicker picker; |
64 | picker.setHoverEnabled(true); |
65 | picker.setPriority(883); |
66 | |
67 | // WHEN |
68 | objectPicker.setRenderer(&renderer); |
69 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
70 | |
71 | // THEN |
72 | QVERIFY(!objectPicker.peerId().isNull()); |
73 | QCOMPARE(objectPicker.isHoverEnabled(), true); |
74 | QCOMPARE(objectPicker.priority(), 883); |
75 | } |
76 | |
77 | void checkInitialAndCleanedUpState() |
78 | { |
79 | // GIVEN |
80 | TestRenderer renderer; |
81 | Qt3DRender::Render::ObjectPicker objectPicker; |
82 | |
83 | // THEN |
84 | QVERIFY(objectPicker.peerId().isNull()); |
85 | QCOMPARE(objectPicker.isHoverEnabled(), false); |
86 | QCOMPARE(objectPicker.isDragEnabled(), false); |
87 | QCOMPARE(objectPicker.priority(), 0); |
88 | |
89 | // GIVEN |
90 | Qt3DRender::QObjectPicker picker; |
91 | picker.setHoverEnabled(true); |
92 | picker.setDragEnabled(true); |
93 | picker.setPriority(1584); |
94 | |
95 | // WHEN |
96 | objectPicker.setRenderer(&renderer); |
97 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
98 | objectPicker.cleanup(); |
99 | |
100 | // THEN |
101 | QCOMPARE(objectPicker.isHoverEnabled(), false); |
102 | QCOMPARE(objectPicker.isDragEnabled(), false); |
103 | QCOMPARE(objectPicker.priority(), 0); |
104 | } |
105 | |
106 | void checkPropertyChanges() |
107 | { |
108 | // GIVEN |
109 | TestRenderer renderer; |
110 | { |
111 | Qt3DRender::QObjectPicker picker; |
112 | Qt3DRender::Render::ObjectPicker objectPicker; |
113 | objectPicker.setRenderer(&renderer); |
114 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
115 | |
116 | // WHEN |
117 | picker.setHoverEnabled(true); |
118 | objectPicker.syncFromFrontEnd(frontEnd: &picker, firstTime: false); |
119 | |
120 | // THEN |
121 | QCOMPARE(objectPicker.isHoverEnabled(), true); |
122 | QVERIFY(renderer.dirtyBits() != 0); |
123 | } |
124 | { |
125 | Qt3DRender::QObjectPicker picker; |
126 | Qt3DRender::Render::ObjectPicker objectPicker; |
127 | objectPicker.setRenderer(&renderer); |
128 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
129 | |
130 | // WHEN |
131 | picker.setDragEnabled(true); |
132 | objectPicker.syncFromFrontEnd(frontEnd: &picker, firstTime: false); |
133 | |
134 | |
135 | // THEN |
136 | QCOMPARE(objectPicker.isDragEnabled(), true); |
137 | QVERIFY(renderer.dirtyBits() != 0); |
138 | } |
139 | { |
140 | Qt3DRender::QObjectPicker picker; |
141 | Qt3DRender::Render::ObjectPicker objectPicker; |
142 | objectPicker.setRenderer(&renderer); |
143 | simulateInitializationSync(frontend: &picker, backend: &objectPicker); |
144 | |
145 | // WHEN |
146 | picker.setPriority(15); |
147 | objectPicker.syncFromFrontEnd(frontEnd: &picker, firstTime: false); |
148 | |
149 | // THEN |
150 | QCOMPARE(objectPicker.priority(), 15); |
151 | QVERIFY(renderer.dirtyBits() != 0); |
152 | } |
153 | } |
154 | }; |
155 | |
156 | |
157 | QTEST_APPLESS_MAIN(tst_ObjectPicker) |
158 | |
159 | #include "tst_objectpicker.moc" |
160 | |