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#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
32#include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
33#include <Qt3DInput/private/physicaldeviceproxy_p.h>
34#include <Qt3DInput/private/inputmanagers_p.h>
35#include <Qt3DCore/private/qbackendnode_p.h>
36#include "qbackendnodetester.h"
37#include "testdeviceproxy.h"
38#include "testpostmanarbiter.h"
39
40
41class tst_PhysicalDeviceProxy : public Qt3DCore::QBackendNodeTester
42{
43 Q_OBJECT
44
45private Q_SLOTS:
46
47 void checkInitialState()
48 {
49 // GIVEN
50 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
51
52 // THEN
53 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
54 QVERIFY(backendPhysicalDeviceProxy.peerId().isNull());
55 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QString());
56 QVERIFY(backendPhysicalDeviceProxy.manager() == nullptr);
57 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
58 }
59
60 void checkInitializeFromPeer()
61 {
62 // GIVEN
63 TestProxy PhysicalDeviceProxy;
64 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
65
66 {
67 // WHEN
68 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
69 backendPhysicalDeviceProxy.setManager(&manager);
70 simulateInitializationSync(frontend: &PhysicalDeviceProxy, backend: &backendPhysicalDeviceProxy);
71
72 // THEN
73 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), true);
74 QCOMPARE(backendPhysicalDeviceProxy.peerId(), PhysicalDeviceProxy.id());
75 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QStringLiteral("TestProxy"));
76 QVERIFY(backendPhysicalDeviceProxy.manager() == &manager);
77 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
78 }
79 {
80 // WHEN
81 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
82 backendPhysicalDeviceProxy.setManager(&manager);
83 PhysicalDeviceProxy.setEnabled(false);
84 simulateInitializationSync(frontend: &PhysicalDeviceProxy, backend: &backendPhysicalDeviceProxy);
85
86 // THEN
87 QCOMPARE(backendPhysicalDeviceProxy.peerId(), PhysicalDeviceProxy.id());
88 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
89 }
90 }
91
92 void checkLoadingRequested()
93 {
94 // GIVEN
95 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
96 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
97 TestProxy deviceProxy;
98
99 // WHEN
100 backendPhysicalDeviceProxy.setManager(&manager);
101 simulateInitializationSync(frontend: &deviceProxy, backend: &backendPhysicalDeviceProxy);
102
103 // THEN
104 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QStringLiteral("TestProxy"));
105 const QVector<Qt3DCore::QNodeId> pendingWrappers = manager.takePendingProxiesToLoad();
106 QCOMPARE(pendingWrappers.size(), 1);
107 QCOMPARE(pendingWrappers.first(), deviceProxy.id());
108 }
109
110 void checkCleanupState()
111 {
112 // GIVEN
113 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
114 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
115 TestProxy deviceProxy;
116
117 // WHEN
118 backendPhysicalDeviceProxy.setManager(&manager);
119 simulateInitializationSync(frontend: &deviceProxy, backend: &backendPhysicalDeviceProxy);
120
121 backendPhysicalDeviceProxy.cleanup();
122
123 // THEN
124 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
125 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QString());
126 QVERIFY(backendPhysicalDeviceProxy.manager() == nullptr);
127 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
128 }
129
130};
131
132QTEST_MAIN(tst_PhysicalDeviceProxy)
133
134#include "tst_physicaldeviceproxy.moc"
135

source code of qt3d/tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp