Debian Codegraph @

tests/auto/input/physicaldeviceproxy/tst_physicaldeviceproxy.cpp

raw symbols SCIP
1 // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5 #include <QtTest/QTest>
6 #include <Qt3DInput/private/qabstractphysicaldeviceproxy_p.h>
7 #include <Qt3DInput/private/qabstractphysicaldeviceproxy_p_p.h>
8 #include <Qt3DInput/private/physicaldeviceproxy_p.h>
9 #include <Qt3DInput/private/inputmanagers_p.h>
10 #include <Qt3DCore/private/qbackendnode_p.h>
11 #include "qbackendnodetester.h"
12 #include "testdeviceproxy.h"
13 #include "testarbiter.h"
14
15
16 class tst_PhysicalDeviceProxy : public Qt3DCore::QBackendNodeTester
17 {
18 Q_OBJECT
19
20 private Q_SLOTS:
21
22 void checkInitialState()
23 {
24 // GIVEN
25 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
26
27 // THEN
28 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
29 QVERIFY(backendPhysicalDeviceProxy.peerId().isNull());
30 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QString());
31 QVERIFY(backendPhysicalDeviceProxy.manager() == nullptr);
32 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
33 }
34
35 void checkInitializeFromPeer()
36 {
37 // GIVEN
38 TestProxy PhysicalDeviceProxy;
39 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
40
41 {
42 // WHEN
43 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
44 backendPhysicalDeviceProxy.setManager(&manager);
45 simulateInitializationSync(&PhysicalDeviceProxy, &backendPhysicalDeviceProxy);
46
47 // THEN
48 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), true);
49 QCOMPARE(backendPhysicalDeviceProxy.peerId(), PhysicalDeviceProxy.id());
50 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QStringLiteral("TestProxy"));
51 QVERIFY(backendPhysicalDeviceProxy.manager() == &manager);
52 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
53 }
54 {
55 // WHEN
56 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
57 backendPhysicalDeviceProxy.setManager(&manager);
58 PhysicalDeviceProxy.setEnabled(false);
59 simulateInitializationSync(&PhysicalDeviceProxy, &backendPhysicalDeviceProxy);
60
61 // THEN
62 QCOMPARE(backendPhysicalDeviceProxy.peerId(), PhysicalDeviceProxy.id());
63 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
64 }
65 }
66
67 void checkLoadingRequested()
68 {
69 // GIVEN
70 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
71 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
72 TestProxy deviceProxy;
73
74 // WHEN
75 backendPhysicalDeviceProxy.setManager(&manager);
76 simulateInitializationSync(&deviceProxy, &backendPhysicalDeviceProxy);
77
78 // THEN
79 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QStringLiteral("TestProxy"));
80 const QList<Qt3DCore::QNodeId> pendingWrappers = manager.takePendingProxiesToLoad();
81 QCOMPARE(pendingWrappers.size(), 1);
82 QCOMPARE(pendingWrappers.first(), deviceProxy.id());
83 }
84
85 void checkCleanupState()
86 {
87 // GIVEN
88 Qt3DInput::Input::PhysicalDeviceProxy backendPhysicalDeviceProxy;
89 Qt3DInput::Input::PhysicalDeviceProxyManager manager;
90 TestProxy deviceProxy;
91
92 // WHEN
93 backendPhysicalDeviceProxy.setManager(&manager);
94 simulateInitializationSync(&deviceProxy, &backendPhysicalDeviceProxy);
95
96 backendPhysicalDeviceProxy.cleanup();
97
98 // THEN
99 QCOMPARE(backendPhysicalDeviceProxy.isEnabled(), false);
100 QCOMPARE(backendPhysicalDeviceProxy.deviceName(), QString());
101 QVERIFY(backendPhysicalDeviceProxy.manager() == nullptr);
102 QVERIFY(backendPhysicalDeviceProxy.physicalDeviceId().isNull());
103 }
104
105 };
106
107 QTEST_MAIN(tst_PhysicalDeviceProxy)
108
109 #include "tst_physicaldeviceproxy.moc"