| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/qtest.h> |
| 5 | #include <Qt3DAnimation/qmorphtarget.h> |
| 6 | #include <qobject.h> |
| 7 | #include <qsignalspy.h> |
| 8 | |
| 9 | class tst_QMorphTarget : public QObject |
| 10 | { |
| 11 | Q_OBJECT |
| 12 | |
| 13 | private Q_SLOTS: |
| 14 | |
| 15 | void checkDefaultConstruction() |
| 16 | { |
| 17 | // GIVEN |
| 18 | Qt3DAnimation::QMorphTarget morphTarget; |
| 19 | |
| 20 | // THEN |
| 21 | QCOMPARE(morphTarget.attributeNames(), QStringList()); |
| 22 | } |
| 23 | |
| 24 | void testSetAttributes() |
| 25 | { |
| 26 | // GIVEN |
| 27 | Qt3DAnimation::QMorphTarget morphTarget; |
| 28 | Qt3DCore::QAttribute attribute1; |
| 29 | Qt3DCore::QAttribute attribute2; |
| 30 | |
| 31 | attribute1.setName(Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 32 | attribute2.setName(Qt3DCore::QAttribute::defaultNormalAttributeName()); |
| 33 | |
| 34 | { |
| 35 | // WHEN |
| 36 | morphTarget.addAttribute(&attribute1); |
| 37 | |
| 38 | // THEN |
| 39 | QStringList names = morphTarget.attributeNames(); |
| 40 | QCOMPARE(names.size(), 1); |
| 41 | QCOMPARE(names.at(0), Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 42 | } |
| 43 | |
| 44 | { |
| 45 | // WHEN |
| 46 | morphTarget.addAttribute(&attribute2); |
| 47 | |
| 48 | // THEN |
| 49 | QStringList names = morphTarget.attributeNames(); |
| 50 | QCOMPARE(names.size(), 2); |
| 51 | QCOMPARE(names.at(1), Qt3DCore::QAttribute::defaultNormalAttributeName()); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | void testFromGeometry() |
| 56 | { |
| 57 | // GIVEN |
| 58 | Qt3DCore::QGeometry geometry; |
| 59 | Qt3DCore::QAttribute *attribute1 = new Qt3DCore::QAttribute; |
| 60 | Qt3DCore::QAttribute *attribute2 = new Qt3DCore::QAttribute; |
| 61 | attribute1->setName(Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 62 | attribute2->setName(Qt3DCore::QAttribute::defaultTextureCoordinateAttributeName()); |
| 63 | geometry.addAttribute(attribute1); |
| 64 | geometry.addAttribute(attribute2); |
| 65 | |
| 66 | QStringList attributes; |
| 67 | attributes.push_back(Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 68 | |
| 69 | { |
| 70 | // WHEN |
| 71 | QScopedPointer<Qt3DAnimation::QMorphTarget> morphTarget( |
| 72 | Qt3DAnimation::QMorphTarget::fromGeometry(&geometry, attributes)); |
| 73 | |
| 74 | // THEN |
| 75 | QStringList names = morphTarget->attributeNames(); |
| 76 | QCOMPARE(names.size(), 1); |
| 77 | QCOMPARE(names.at(0), Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 78 | } |
| 79 | |
| 80 | { |
| 81 | // WHEN |
| 82 | attributes.push_back(Qt3DCore::QAttribute::defaultTextureCoordinateAttributeName()); |
| 83 | QScopedPointer<Qt3DAnimation::QMorphTarget> morphTarget( |
| 84 | Qt3DAnimation::QMorphTarget::fromGeometry(&geometry, attributes)); |
| 85 | |
| 86 | // THEN |
| 87 | QStringList names = morphTarget->attributeNames(); |
| 88 | QCOMPARE(names.size(), 2); |
| 89 | QCOMPARE(names.at(0), Qt3DCore::QAttribute::defaultPositionAttributeName()); |
| 90 | QCOMPARE(names.at(1), Qt3DCore::QAttribute::defaultTextureCoordinateAttributeName()); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | }; |
| 95 | |
| 96 | QTEST_APPLESS_MAIN(tst_QMorphTarget) |
| 97 | |
| 98 | #include "tst_qmorphtarget.moc" |