1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
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.h> |
30 | #include <Qt3DAnimation/qmorphtarget.h> |
31 | #include <qobject.h> |
32 | #include <qsignalspy.h> |
33 | |
34 | class tst_QMorphTarget : public QObject |
35 | { |
36 | Q_OBJECT |
37 | |
38 | private Q_SLOTS: |
39 | |
40 | void checkDefaultConstruction() |
41 | { |
42 | // GIVEN |
43 | Qt3DAnimation::QMorphTarget morphTarget; |
44 | |
45 | // THEN |
46 | QCOMPARE(morphTarget.attributeNames(), QStringList()); |
47 | } |
48 | |
49 | void testSetAttributes() |
50 | { |
51 | // GIVEN |
52 | Qt3DAnimation::QMorphTarget morphTarget; |
53 | Qt3DRender::QAttribute attribute1; |
54 | Qt3DRender::QAttribute attribute2; |
55 | |
56 | attribute1.setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); |
57 | attribute2.setName(Qt3DRender::QAttribute::defaultNormalAttributeName()); |
58 | |
59 | { |
60 | // WHEN |
61 | morphTarget.addAttribute(attribute: &attribute1); |
62 | |
63 | // THEN |
64 | QStringList names = morphTarget.attributeNames(); |
65 | QCOMPARE(names.size(), 1); |
66 | QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); |
67 | } |
68 | |
69 | { |
70 | // WHEN |
71 | morphTarget.addAttribute(attribute: &attribute2); |
72 | |
73 | // THEN |
74 | QStringList names = morphTarget.attributeNames(); |
75 | QCOMPARE(names.size(), 2); |
76 | QCOMPARE(names.at(1), Qt3DRender::QAttribute::defaultNormalAttributeName()); |
77 | } |
78 | } |
79 | |
80 | void testFromGeometry() |
81 | { |
82 | // GIVEN |
83 | Qt3DRender::QGeometry geometry; |
84 | Qt3DRender::QAttribute *attribute1 = new Qt3DRender::QAttribute; |
85 | Qt3DRender::QAttribute *attribute2 = new Qt3DRender::QAttribute; |
86 | attribute1->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); |
87 | attribute2->setName(Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); |
88 | geometry.addAttribute(attribute: attribute1); |
89 | geometry.addAttribute(attribute: attribute2); |
90 | |
91 | QStringList attributes; |
92 | attributes.push_back(t: Qt3DRender::QAttribute::defaultPositionAttributeName()); |
93 | |
94 | { |
95 | // WHEN |
96 | QScopedPointer<Qt3DAnimation::QMorphTarget> morphTarget( |
97 | Qt3DAnimation::QMorphTarget::fromGeometry(geometry: &geometry, attributes)); |
98 | |
99 | // THEN |
100 | QStringList names = morphTarget->attributeNames(); |
101 | QCOMPARE(names.size(), 1); |
102 | QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); |
103 | } |
104 | |
105 | { |
106 | // WHEN |
107 | attributes.push_back(t: Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); |
108 | QScopedPointer<Qt3DAnimation::QMorphTarget> morphTarget( |
109 | Qt3DAnimation::QMorphTarget::fromGeometry(geometry: &geometry, attributes)); |
110 | |
111 | // THEN |
112 | QStringList names = morphTarget->attributeNames(); |
113 | QCOMPARE(names.size(), 2); |
114 | QCOMPARE(names.at(0), Qt3DRender::QAttribute::defaultPositionAttributeName()); |
115 | QCOMPARE(names.at(1), Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName()); |
116 | } |
117 | } |
118 | |
119 | }; |
120 | |
121 | QTEST_APPLESS_MAIN(tst_QMorphTarget) |
122 | |
123 | #include "tst_qmorphtarget.moc" |
124 | |