Debian Codegraph @

tests/auto/render/qboundingvolumedebug/tst_qboundingvolumedebug.cpp

raw symbols SCIP
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/QEntity>
6 #include <Qt3DCore/private/qnode_p.h>
7 #include <Qt3DCore/private/qscene_p.h>
8 #include <Qt3DCore/qbackendnodepropertychange.h>
9 #include <Qt3DRender/private/qboundingvolumedebug_p.h>
10
11 #include "testpostmanarbiter.h"
12
13 #if 0
14
15 class MyBoundingVolumeDebug : public Qt3DRender::QBoundingVolumeDebug
16 {
17 Q_OBJECT
18 public:
19 MyBoundingVolumeDebug(Qt3DCore::QNode *parent = nullptr)
20 : Qt3DRender::QBoundingVolumeDebug(parent)
21 {}
22
23 void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) final
24 {
25 Qt3DRender::QBoundingVolumeDebug::sceneChangeEvent(change);
26 }
27
28 private:
29 friend class tst_ObjectPicker;
30
31 };
32
33 // We need to call QNode::clone which is protected
34 // So we sublcass QNode instead of QObject
35 class tst_QBoundingVolumeDebug : public Qt3DCore::QNode
36 {
37 Q_OBJECT
38 public:
39 tst_QBoundingVolumeDebug()
40 {
41 }
42
43 ~tst_QBoundingVolumeDebug()
44 {
45 QNode::cleanup();
46 }
47
48 private Q_SLOTS:
49
50 void checkCloning_data()
51 {
52 QTest::addColumn<Qt3DRender::QBoundingVolumeDebug *>("bvD");
53
54 Qt3DRender::QBoundingVolumeDebug *bvD = new Qt3DRender::QBoundingVolumeDebug();
55 QTest::newRow("empty bvd") << bvD;
56 bvD = new Qt3DRender::QBoundingVolumeDebug();
57 bvD->setRecursive(true);
58 QTest::newRow("recursive_bvd") << bvD;
59 }
60
61 // TODO: Avoid cloning here
62 // void checkCloning()
63 // {
64 // // GIVEN
65 // QFETCH(Qt3DRender::QBoundingVolumeDebug *, bvD);
66
67 // // WHEN
68 // Qt3DRender::QBoundingVolumeDebug *clone = static_cast<Qt3DRender::QBoundingVolumeDebug *>(QNode::clone(bvD));
69 // QCoreApplication::processEvents();
70
71 // // THEN
72 // QVERIFY(clone != nullptr);
73 // QCOMPARE(bvD->id(), clone->id());
74 // QCOMPARE(bvD->recursive(), clone->recursive());
75 // }
76
77 void checkPropertyUpdates()
78 {
79 // GIVEN
80 QScopedPointer<Qt3DRender::QBoundingVolumeDebug> bvD(new Qt3DRender::QBoundingVolumeDebug());
81 TestArbiter arbiter(bvD.data());
82
83 // WHEN
84 bvD->setRecursive(true);
85 QCoreApplication::processEvents();
86
87 // THEN
88 QCOMPARE(arbiter.events.size(), 1);
89 Qt3DCore::QNodePropertyChangePtr change = arbiter.events.last().staticCast<Qt3DCore::QNodePropertyChange>();
90 QCOMPARE(change->propertyName(), "recursive");
91 QCOMPARE(change->value().toBool(), true);
92 QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
93
94 arbiter.events.clear();
95
96 // WHEN
97 bvD->setRecursive(true);
98 QCoreApplication::processEvents();
99
100 // THEN
101 QCOMPARE(arbiter.events.size(), 0);
102
103 // WHEN
104 bvD->setRecursive(false);
105 QCoreApplication::processEvents();
106
107 // THEN
108 QCOMPARE(arbiter.events.size(), 1);
109 change = arbiter.events.last().staticCast<Qt3DCore::QNodePropertyChange>();
110 QCOMPARE(change->propertyName(), "recursive");
111 QCOMPARE(change->value().toBool(), false);
112 QCOMPARE(change->type(), Qt3DCore::NodeUpdated);
113
114 arbiter.events.clear();
115 }
116
117 void checkBackendUpdates()
118 {
119 // GIVEN
120 QScopedPointer<Qt3DCore::QEntity> entity(new Qt3DCore::QEntity());
121 MyBoundingVolumeDebug *bvD(new MyBoundingVolumeDebug(entity.data()));
122 entity->addComponent(bvD);
123
124 // THEN
125 QCoreApplication::processEvents();
126 QCOMPARE(entity->children().count(), 1);
127 QCOMPARE(bvD->children().count(), 0);
128
129 // WHEN
130 // Create Backend Change and distribute it to frontend node
131 Qt3DCore::QBackendNodePropertyChangePtr e(new Qt3DCore::QBackendNodePropertyChange(bvD->id()));
132 e->setPropertyName("center");
133 bvD->sceneChangeEvent(e);
134 QCoreApplication::processEvents();
135
136 // THEN
137 QCOMPARE(entity->children().count(), 2);
138 QCOMPARE(bvD->children().count(), 0);
139 }
140 };
141
142 QTEST_MAIN(tst_QBoundingVolumeDebug)
143
144 #include "tst_qboundingvolumedebug.moc"