Debian Codegraph @

tests/auto/core/qarmature/tst_qarmature.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/qarmature.h>
6 #include <Qt3DCore/private/qarmature_p.h>
7 #include <Qt3DCore/qskeleton.h>
8
9 #include <Qt3DCore/private/qnode_p.h>
10 #include <Qt3DCore/private/qscene_p.h>
11 #include <testarbiter.h>
12
13 using namespace Qt3DCore;
14
15 class tst_QArmature: public QObject
16 {
17 Q_OBJECT
18 public:
19 tst_QArmature()
20 {
21 qRegisterMetaType<Qt3DCore::QAbstractSkeleton*>();
22 }
23
24 private Q_SLOTS:
25
26 void checkPropertyUpdates()
27 {
28 // GIVEN
29 TestArbiter arbiter;
30 QScopedPointer<QArmature> armature(new QArmature());
31 arbiter.setArbiterOnNode(armature.data());
32
33 // WHEN
34 QSkeleton *skeleton = new QSkeleton(armature.data());
35 armature->setSkeleton(skeleton);
36
37 // THEN
38 QCOMPARE(arbiter.dirtyNodes().size(), 1);
39 QCOMPARE(arbiter.dirtyNodes().front(), armature.data());
40
41 arbiter.clear();
42
43 // WHEN
44 armature->setSkeleton(nullptr);
45
46 // THEN
47 QCOMPARE(arbiter.dirtyNodes().size(), 1);
48 QCOMPARE(arbiter.dirtyNodes().front(), armature.data());
49
50 arbiter.clear();
51 }
52
53 void checkSkeletonBookkeeping()
54 {
55 // GIVEN
56 QScopedPointer<QArmature> armature(new QArmature);
57 {
58 // WHEN
59 QSkeleton skeleton;
60 armature->setSkeleton(&skeleton);
61
62 // THEN
63 QCOMPARE(skeleton.parent(), armature.data());
64 QCOMPARE(armature->skeleton(), &skeleton);
65 }
66 // THEN (Should not crash and parameter be unset)
67 QVERIFY(armature->skeleton() == nullptr);
68
69 {
70 // WHEN
71 QArmature someOtherArmature;
72 QScopedPointer<QSkeleton> skeleton(new QSkeleton(&someOtherArmature));
73 armature->setSkeleton(skeleton.data());
74
75 // THEN
76 QCOMPARE(skeleton->parent(), &someOtherArmature);
77 QCOMPARE(armature->skeleton(), skeleton.data());
78
79 // WHEN
80 armature.reset();
81 skeleton.reset();
82
83 // THEN Should not crash when the joint is destroyed (tests for failed removal of destruction helper)
84 }
85 }
86 };
87
88 QTEST_MAIN(tst_QArmature)
89
90 #include "tst_qarmature.moc"