Changeset View
Changeset View
Standalone View
Standalone View
tests/devicetest.cpp
Show All 36 Lines | 34 | private Q_SLOTS: | |||
---|---|---|---|---|---|
37 | void testUnpairedDevice(); | 37 | void testUnpairedDevice(); | ||
38 | void testPairedDevice(); | 38 | void testPairedDevice(); | ||
39 | void cleanupTestCase(); | 39 | void cleanupTestCase(); | ||
40 | 40 | | |||
41 | private: | 41 | private: | ||
42 | QString deviceId; | 42 | QString deviceId; | ||
43 | QString deviceName; | 43 | QString deviceName; | ||
44 | QString deviceType; | 44 | QString deviceType; | ||
45 | NetworkPackage* identityPackage; | 45 | NetworkPacket* identityPacket; | ||
46 | 46 | | |||
47 | }; | 47 | }; | ||
48 | 48 | | |||
49 | void DeviceTest::initTestCase() | 49 | void DeviceTest::initTestCase() | ||
50 | { | 50 | { | ||
51 | deviceId = QStringLiteral("testdevice"); | 51 | deviceId = QStringLiteral("testdevice"); | ||
52 | deviceName = QStringLiteral("Test Device"); | 52 | deviceName = QStringLiteral("Test Device"); | ||
53 | deviceType = QStringLiteral("smartphone"); | 53 | deviceType = QStringLiteral("smartphone"); | ||
54 | QString stringPackage = QStringLiteral("{\"id\":1439365924847,\"type\":\"kdeconnect.identity\",\"body\":{\"deviceId\":\"testdevice\",\"deviceName\":\"Test Device\",\"protocolVersion\":6,\"deviceType\":\"phone\"}}"); | 54 | QString stringPacket = QStringLiteral("{\"id\":1439365924847,\"type\":\"kdeconnect.identity\",\"body\":{\"deviceId\":\"testdevice\",\"deviceName\":\"Test Device\",\"protocolVersion\":6,\"deviceType\":\"phone\"}}"); | ||
55 | identityPackage = new NetworkPackage(QStringLiteral("kdeconnect.identity")); | 55 | identityPacket = new NetworkPacket(QStringLiteral("kdeconnect.identity")); | ||
56 | NetworkPackage::unserialize(stringPackage.toLatin1(), identityPackage); | 56 | NetworkPacket::unserialize(stringPacket.toLatin1(), identityPacket); | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | void DeviceTest::testPairedDevice() | 59 | void DeviceTest::testPairedDevice() | ||
60 | { | 60 | { | ||
61 | KdeConnectConfig* kcc = KdeConnectConfig::instance(); | 61 | KdeConnectConfig* kcc = KdeConnectConfig::instance(); | ||
62 | kcc->addTrustedDevice(deviceId, deviceName, deviceType); | 62 | kcc->addTrustedDevice(deviceId, deviceName, deviceType); | ||
63 | kcc->setDeviceProperty(deviceId, QStringLiteral("certificate"), QString::fromLatin1(kcc->certificate().toPem())); // Using same certificate from kcc, instead of generating one | 63 | kcc->setDeviceProperty(deviceId, QStringLiteral("certificate"), QString::fromLatin1(kcc->certificate().toPem())); // Using same certificate from kcc, instead of generating one | ||
64 | 64 | | |||
65 | Device device(this, deviceId); | 65 | Device device(this, deviceId); | ||
66 | 66 | | |||
67 | QCOMPARE(device.id(), deviceId); | 67 | QCOMPARE(device.id(), deviceId); | ||
68 | QCOMPARE(device.name(), deviceName); | 68 | QCOMPARE(device.name(), deviceName); | ||
69 | QCOMPARE(device.type(), deviceType); | 69 | QCOMPARE(device.type(), deviceType); | ||
70 | 70 | | |||
71 | QCOMPARE(device.isTrusted(), true); | 71 | QCOMPARE(device.isTrusted(), true); | ||
72 | 72 | | |||
73 | QCOMPARE(device.isReachable(), false); | 73 | QCOMPARE(device.isReachable(), false); | ||
74 | 74 | | |||
75 | // Add link | 75 | // Add link | ||
76 | LanLinkProvider linkProvider; | 76 | LanLinkProvider linkProvider; | ||
77 | QSslSocket socket; | 77 | QSslSocket socket; | ||
78 | LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally); | 78 | LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally); | ||
79 | device.addLink(*identityPackage, link); | 79 | device.addLink(*identityPacket, link); | ||
80 | 80 | | |||
81 | QCOMPARE(device.isReachable(), true); | 81 | QCOMPARE(device.isReachable(), true); | ||
82 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), true); | 82 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), true); | ||
83 | 83 | | |||
84 | // Remove link | 84 | // Remove link | ||
85 | device.removeLink(link); | 85 | device.removeLink(link); | ||
86 | 86 | | |||
87 | QCOMPARE(device.isReachable(), false); | 87 | QCOMPARE(device.isReachable(), false); | ||
88 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), false); | 88 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), false); | ||
89 | 89 | | |||
90 | device.unpair(); | 90 | device.unpair(); | ||
91 | QCOMPARE(device.isTrusted(), false); | 91 | QCOMPARE(device.isTrusted(), false); | ||
92 | 92 | | |||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | void DeviceTest::testUnpairedDevice() | 95 | void DeviceTest::testUnpairedDevice() | ||
96 | { | 96 | { | ||
97 | LanLinkProvider linkProvider; | 97 | LanLinkProvider linkProvider; | ||
98 | QSslSocket socket; | 98 | QSslSocket socket; | ||
99 | LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally); | 99 | LanDeviceLink* link = new LanDeviceLink(deviceId, &linkProvider, &socket, LanDeviceLink::Locally); | ||
100 | 100 | | |||
101 | Device device(this, *identityPackage, link); | 101 | Device device(this, *identityPacket, link); | ||
102 | 102 | | |||
103 | QCOMPARE(device.id(), deviceId); | 103 | QCOMPARE(device.id(), deviceId); | ||
104 | QCOMPARE(device.name(), deviceName); | 104 | QCOMPARE(device.name(), deviceName); | ||
105 | QCOMPARE(device.type(), deviceType); | 105 | QCOMPARE(device.type(), deviceType); | ||
106 | 106 | | |||
107 | QCOMPARE(device.isTrusted(), false); | 107 | QCOMPARE(device.isTrusted(), false); | ||
108 | 108 | | |||
109 | QCOMPARE(device.isReachable(), true); | 109 | QCOMPARE(device.isReachable(), true); | ||
110 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), true); | 110 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), true); | ||
111 | 111 | | |||
112 | // Remove link | 112 | // Remove link | ||
113 | device.removeLink(link); | 113 | device.removeLink(link); | ||
114 | 114 | | |||
115 | QCOMPARE(device.isReachable(), false); | 115 | QCOMPARE(device.isReachable(), false); | ||
116 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), false); | 116 | QCOMPARE(device.availableLinks().contains(linkProvider.name()), false); | ||
117 | } | 117 | } | ||
118 | 118 | | |||
119 | void DeviceTest::cleanupTestCase() | 119 | void DeviceTest::cleanupTestCase() | ||
120 | { | 120 | { | ||
121 | delete identityPackage; | 121 | delete identityPacket; | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | QTEST_GUILESS_MAIN(DeviceTest) | 124 | QTEST_GUILESS_MAIN(DeviceTest) | ||
125 | 125 | | |||
126 | #include "devicetest.moc" | 126 | #include "devicetest.moc" |