| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2015 David Rosca <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 |
*/ |
| 6 |
|
| 7 |
import QtTest 1.0 |
| 8 |
import QtQuick 2.2 |
| 9 |
import org.kde.bluezqt.fakebluez 1.0 |
| 10 |
import org.kde.bluezqt 1.0 as BluezQt |
| 11 |
|
| 12 |
TestCase { |
| 13 |
name: "Input" |
| 14 |
|
| 15 |
readonly property BluezQt.Manager manager: BluezQt.Manager |
| 16 |
|
| 17 |
property var input1props |
| 18 |
property var input2props |
| 19 |
property var input3props |
| 20 |
property var input4props |
| 21 |
property var device1props |
| 22 |
property var device2props |
| 23 |
property var device3props |
| 24 |
property var device4props |
| 25 |
|
| 26 |
function initTestCase() |
| 27 |
{ |
| 28 |
FakeBluez.start(); |
| 29 |
FakeBluez.runTest("bluez-standard"); |
| 30 |
|
| 31 |
// Create adapter |
| 32 |
var adapter1path = "/org/bluez/hci0"; |
| 33 |
var adapter1props = { |
| 34 |
Path: adapter1path, |
| 35 |
Address: "1C:E5:C3:BC:94:7E", |
| 36 |
Name: "TestAdapter", |
| 37 |
_toDBusObjectPath: [ "Path" ] |
| 38 |
} |
| 39 |
FakeBluez.runAction("devicemanager", "create-adapter", adapter1props); |
| 40 |
|
| 41 |
// Create devices |
| 42 |
input1props = { |
| 43 |
ReconnectMode: "none" |
| 44 |
} |
| 45 |
device1props = { |
| 46 |
Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75", |
| 47 |
Adapter: adapter1path, |
| 48 |
Address: "40:79:6A:0C:39:75", |
| 49 |
Name: "TestDevice", |
| 50 |
UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], |
| 51 |
Input: input1props, |
| 52 |
_toDBusObjectPath: [ "Path", "Adapter" ] |
| 53 |
} |
| 54 |
FakeBluez.runAction("devicemanager", "create-device", device1props); |
| 55 |
|
| 56 |
input2props = { |
| 57 |
ReconnectMode: "none" |
| 58 |
} |
| 59 |
device2props = { |
| 60 |
Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75", |
| 61 |
Adapter: adapter1path, |
| 62 |
Address: "50:79:6A:0C:39:75", |
| 63 |
Name: "TestDevice2", |
| 64 |
UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], |
| 65 |
Input: input2props, |
| 66 |
_toDBusObjectPath: [ "Path", "Adapter" ] |
| 67 |
} |
| 68 |
FakeBluez.runAction("devicemanager", "create-device", device2props); |
| 69 |
|
| 70 |
input3props = { |
| 71 |
ReconnectMode: "none" |
| 72 |
} |
| 73 |
device3props = { |
| 74 |
Path: "/org/bluez/hci0/dev_60_79_6A_0C_39_75", |
| 75 |
Adapter: adapter1path, |
| 76 |
Address: "60:79:6A:0C:39:75", |
| 77 |
Name: "TestDevice2", |
| 78 |
UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], |
| 79 |
Input: input3props, |
| 80 |
_toDBusObjectPath: [ "Path", "Adapter" ] |
| 81 |
} |
| 82 |
FakeBluez.runAction("devicemanager", "create-device", device3props); |
| 83 |
|
| 84 |
input4props = { |
| 85 |
ReconnectMode: "none" |
| 86 |
} |
| 87 |
device4props = { |
| 88 |
Path: "/org/bluez/hci0/dev_70_79_6A_0C_39_75", |
| 89 |
Adapter: adapter1path, |
| 90 |
Address: "70:79:6A:0C:39:75", |
| 91 |
Name: "TestDevice2", |
| 92 |
UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ], |
| 93 |
Input: input4props, |
| 94 |
_toDBusObjectPath: [ "Path", "Adapter" ] |
| 95 |
} |
| 96 |
FakeBluez.runAction("devicemanager", "create-device", device4props); |
| 97 |
|
| 98 |
tryCompare(manager, "operational", true); |
| 99 |
compare(manager.adapters.length, 1, "adapters-length"); |
| 100 |
compare(manager.devices.length, 4, "devices-length"); |
| 101 |
} |
| 102 |
|
| 103 |
function cleanupTestCase() |
| 104 |
{ |
| 105 |
FakeBluez.stop(); |
| 106 |
} |
| 107 |
|
| 108 |
function compareProperties(input, props) |
| 109 |
{ |
| 110 |
compare(modeString(input), props.ReconnectMode, "reconnectMode"); |
| 111 |
} |
| 112 |
|
| 113 |
function test_getProperties() |
| 114 |
{ |
| 115 |
const device1 = manager.deviceForUbi(device1props.Path); |
| 116 |
const device2 = manager.deviceForUbi(device2props.Path); |
| 117 |
const device3 = manager.deviceForUbi(device3props.Path); |
| 118 |
const device4 = manager.deviceForUbi(device4props.Path); |
| 119 |
|
| 120 |
compareProperties(device1.input, input1props); |
| 121 |
compareProperties(device2.input, input2props); |
| 122 |
compareProperties(device3.input, input3props); |
| 123 |
compareProperties(device4.input, input4props); |
| 124 |
} |
| 125 |
|
| 126 |
function modeString(input) |
| 127 |
{ |
| 128 |
switch (input.reconnectMode) { |
| 129 |
case BluezQt.Input.NoReconnect: |
| 130 |
return "none"; |
| 131 |
case BluezQt.Input.HostReconnect: |
| 132 |
return "host"; |
| 133 |
case BluezQt.Input.DeviceReconnect: |
| 134 |
return "device"; |
| 135 |
default: |
| 136 |
return "any"; |
| 137 |
} |
| 138 |
} |
| 139 |
} |