Changeset View
Changeset View
Standalone View
Standalone View
autotests/bolt/lib/devicetest.cpp
- This file was added.
1 | #include <QObject> | ||||
---|---|---|---|---|---|
2 | #include <QTest> | ||||
3 | #include <QSignalSpy> | ||||
4 | | ||||
5 | #include "fakeserver.h" | ||||
6 | #include "fakemanager.h" | ||||
7 | #include "fakedevice.h" | ||||
8 | | ||||
9 | #include "device.h" | ||||
10 | #include "manager.h" | ||||
11 | | ||||
12 | #include <memory> | ||||
13 | | ||||
14 | class DeviceTest : public QObject | ||||
15 | { | ||||
16 | Q_OBJECT | ||||
17 | public: | ||||
18 | DeviceTest() | ||||
19 | : QObject() | ||||
20 | { | ||||
21 | FakeServer::enableFakeEnv(); | ||||
22 | qRegisterMetaType<QSharedPointer<Bolt::Device>>(); | ||||
23 | } | ||||
24 | | ||||
25 | private Q_SLOTS: | ||||
26 | void testAuthorize() | ||||
27 | { | ||||
28 | QScopedPointer<FakeServer> fakeServer; | ||||
29 | try { | ||||
30 | fakeServer.reset(new FakeServer); | ||||
31 | } catch (const FakeServerException &e) { | ||||
32 | qWarning("Fake server exception: %s", e.what()); | ||||
33 | QFAIL("Caught server exception"); | ||||
34 | } | ||||
35 | | ||||
36 | auto fakeManager = fakeServer->manager(); | ||||
37 | FakeDevice *fakeDevice = nullptr; | ||||
38 | try { | ||||
39 | fakeDevice = fakeManager->addDevice( | ||||
40 | std::make_unique<FakeDevice>(QStringLiteral("Device1"))); | ||||
41 | } catch (const FakeDeviceException &e) { | ||||
42 | qWarning("Fake device exception: %s", e.what()); | ||||
43 | QFAIL("Caught device exception"); | ||||
44 | } | ||||
45 | fakeDevice->setAuthFlags(QStringLiteral("none")); | ||||
46 | | ||||
47 | Bolt::Manager manager; | ||||
48 | QVERIFY(manager.isAvailable()); | ||||
49 | | ||||
50 | auto device = manager.device(fakeDevice->uid()); | ||||
51 | QVERIFY(device); | ||||
52 | QCOMPARE(device->authFlags(), Bolt::Auth::None); | ||||
53 | device->authorize(Bolt::Auth::NoKey | Bolt::Auth::Boot); | ||||
54 | | ||||
55 | QTRY_COMPARE(fakeDevice->authFlags(), QStringLiteral("nokey | boot")); | ||||
56 | } | ||||
57 | }; | ||||
58 | | ||||
59 | #include "devicetest.moc" | ||||
60 | | ||||
61 | QTEST_GUILESS_MAIN(DeviceTest) |