| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). | 
| 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 |  | 
| 30 | #include <QtTest/QTest> | 
| 31 |  | 
| 32 | #include <Qt3DCore/private/qnodecreatedchangegenerator_p.h> | 
| 33 | #include <Qt3DCore/qnodecreatedchange.h> | 
| 34 | #include "testdeviceproxy.h" | 
| 35 |  | 
| 36 | class tst_QAbstractPhysicalDeviceProxy : public QObject | 
| 37 | { | 
| 38 |     Q_OBJECT | 
| 39 |  | 
| 40 | private Q_SLOTS: | 
| 41 |  | 
| 42 |     void checkDefaultConstruction() | 
| 43 |     { | 
| 44 |         // GIVEN | 
| 45 |         TestProxy abstractPhysicalDeviceProxy; | 
| 46 |  | 
| 47 |         // THEN | 
| 48 |         QCOMPARE(abstractPhysicalDeviceProxy.deviceName(), QLatin1String("TestProxy" )); | 
| 49 |         QCOMPARE(abstractPhysicalDeviceProxy.status(), Qt3DInput::QAbstractPhysicalDeviceProxy::NotFound); | 
| 50 |         QCOMPARE(abstractPhysicalDeviceProxy.axisCount(), 0); | 
| 51 |         QCOMPARE(abstractPhysicalDeviceProxy.buttonCount(), 0); | 
| 52 |         QCOMPARE(abstractPhysicalDeviceProxy.axisNames(), QStringList()); | 
| 53 |         QCOMPARE(abstractPhysicalDeviceProxy.buttonNames(), QStringList()); | 
| 54 |         QVERIFY(abstractPhysicalDeviceProxy.device() == nullptr); | 
| 55 |     } | 
| 56 |  | 
| 57 |     void checkDeviceBookkeeping() | 
| 58 |     { | 
| 59 |         // GIVEN | 
| 60 |         TestProxy *abstractPhysicalDeviceProxy = new TestProxy(); | 
| 61 |  | 
| 62 |         // WHEN | 
| 63 |         TestPhysicalDevice *device = new TestPhysicalDevice(); | 
| 64 |         abstractPhysicalDeviceProxy->setDevice(device); | 
| 65 |  | 
| 66 |         // THEN | 
| 67 |         QVERIFY(abstractPhysicalDeviceProxy->device() == device); | 
| 68 |  | 
| 69 |         // WHEN | 
| 70 |         delete device; | 
| 71 |  | 
| 72 |         // THEN -> should not crash | 
| 73 |         QVERIFY(abstractPhysicalDeviceProxy->device() == nullptr); | 
| 74 |     } | 
| 75 |  | 
| 76 |     void checkCreationData() | 
| 77 |     { | 
| 78 |         // GIVEN | 
| 79 |         TestProxy abstractPhysicalDeviceProxy; | 
| 80 |  | 
| 81 |  | 
| 82 |         // WHEN | 
| 83 |         QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges; | 
| 84 |  | 
| 85 |         { | 
| 86 |             Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&abstractPhysicalDeviceProxy); | 
| 87 |             creationChanges = creationChangeGenerator.creationChanges(); | 
| 88 |         } | 
| 89 |  | 
| 90 |         // THEN | 
| 91 |         { | 
| 92 |             QCOMPARE(creationChanges.size(), 1); | 
| 93 |  | 
| 94 |             const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DInput::QAbstractPhysicalDeviceProxyData>>(src: creationChanges.first()); | 
| 95 |             const Qt3DInput::QAbstractPhysicalDeviceProxyData cloneData = creationChangeData->data; | 
| 96 |  | 
| 97 |             QCOMPARE(abstractPhysicalDeviceProxy.deviceName(), cloneData.deviceName); | 
| 98 |             QCOMPARE(abstractPhysicalDeviceProxy.id(), creationChangeData->subjectId()); | 
| 99 |             QCOMPARE(abstractPhysicalDeviceProxy.isEnabled(), true); | 
| 100 |             QCOMPARE(abstractPhysicalDeviceProxy.isEnabled(), creationChangeData->isNodeEnabled()); | 
| 101 |             QCOMPARE(abstractPhysicalDeviceProxy.metaObject(), creationChangeData->metaObject()); | 
| 102 |         } | 
| 103 |  | 
| 104 |         // WHEN | 
| 105 |         abstractPhysicalDeviceProxy.setEnabled(false); | 
| 106 |  | 
| 107 |         { | 
| 108 |             Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&abstractPhysicalDeviceProxy); | 
| 109 |             creationChanges = creationChangeGenerator.creationChanges(); | 
| 110 |         } | 
| 111 |  | 
| 112 |         // THEN | 
| 113 |         { | 
| 114 |             QCOMPARE(creationChanges.size(), 1); | 
| 115 |  | 
| 116 |             const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DInput::QAbstractPhysicalDeviceProxyData>>(src: creationChanges.first()); | 
| 117 |             const Qt3DInput::QAbstractPhysicalDeviceProxyData cloneData = creationChangeData->data; | 
| 118 |  | 
| 119 |             QCOMPARE(abstractPhysicalDeviceProxy.deviceName(), cloneData.deviceName); | 
| 120 |             QCOMPARE(abstractPhysicalDeviceProxy.id(), creationChangeData->subjectId()); | 
| 121 |             QCOMPARE(abstractPhysicalDeviceProxy.isEnabled(), false); | 
| 122 |             QCOMPARE(abstractPhysicalDeviceProxy.isEnabled(), creationChangeData->isNodeEnabled()); | 
| 123 |             QCOMPARE(abstractPhysicalDeviceProxy.metaObject(), creationChangeData->metaObject()); | 
| 124 |         } | 
| 125 |     } | 
| 126 |  | 
| 127 | }; | 
| 128 |  | 
| 129 | QTEST_MAIN(tst_QAbstractPhysicalDeviceProxy) | 
| 130 |  | 
| 131 | #include "tst_qabstractphysicaldeviceproxy.moc" | 
| 132 |  |