Warning, /frameworks/bluez-qt/autotests/qml/tst_input.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 import QtTest 1.0
0008 import QtQuick 2.2
0009 import org.kde.bluezqt.fakebluez 1.0
0010 import org.kde.bluezqt 1.0 as BluezQt
0011 
0012 TestCase {
0013     name: "Input"
0014     property QtObject manager : BluezQt.Manager;
0015     property var input1props;
0016     property var input2props;
0017     property var input3props;
0018     property var input4props;
0019     property var device1props;
0020     property var device2props;
0021     property var device3props;
0022     property var device4props;
0023 
0024     function initTestCase()
0025     {
0026         FakeBluez.start();
0027         FakeBluez.runTest("bluez-standard");
0028 
0029         // Create adapter
0030         var adapter1path = "/org/bluez/hci0";
0031         var adapter1props = {
0032             Path: adapter1path,
0033             Address: "1C:E5:C3:BC:94:7E",
0034             Name: "TestAdapter",
0035             _toDBusObjectPath: [ "Path" ]
0036         }
0037         FakeBluez.runAction("devicemanager", "create-adapter", adapter1props);
0038 
0039         // Create devices
0040         input1props = {
0041             ReconnectMode: "none"
0042         }
0043         device1props = {
0044             Path: "/org/bluez/hci0/dev_40_79_6A_0C_39_75",
0045             Adapter: adapter1path,
0046             Address: "40:79:6A:0C:39:75",
0047             Name: "TestDevice",
0048             UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ],
0049             Input: input1props,
0050             _toDBusObjectPath: [ "Path", "Adapter" ]
0051         }
0052         FakeBluez.runAction("devicemanager", "create-device", device1props);
0053 
0054         input2props = {
0055             ReconnectMode: "none"
0056         }
0057         device2props = {
0058             Path: "/org/bluez/hci0/dev_50_79_6A_0C_39_75",
0059             Adapter: adapter1path,
0060             Address: "50:79:6A:0C:39:75",
0061             Name: "TestDevice2",
0062             UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ],
0063             Input: input2props,
0064             _toDBusObjectPath: [ "Path", "Adapter" ]
0065         }
0066         FakeBluez.runAction("devicemanager", "create-device", device2props);
0067 
0068         input3props = {
0069             ReconnectMode: "none"
0070         }
0071         device3props = {
0072             Path: "/org/bluez/hci0/dev_60_79_6A_0C_39_75",
0073             Adapter: adapter1path,
0074             Address: "60:79:6A:0C:39:75",
0075             Name: "TestDevice2",
0076             UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ],
0077             Input: input3props,
0078             _toDBusObjectPath: [ "Path", "Adapter" ]
0079         }
0080         FakeBluez.runAction("devicemanager", "create-device", device3props);
0081 
0082         input4props = {
0083             ReconnectMode: "none"
0084         }
0085         device4props = {
0086             Path: "/org/bluez/hci0/dev_70_79_6A_0C_39_75",
0087             Adapter: adapter1path,
0088             Address: "70:79:6A:0C:39:75",
0089             Name: "TestDevice2",
0090             UUIDs: [ "00001124-0000-1000-8000-00805F9B34FB" ],
0091             Input: input4props,
0092             _toDBusObjectPath: [ "Path", "Adapter" ]
0093         }
0094         FakeBluez.runAction("devicemanager", "create-device", device4props);
0095 
0096         tryCompare(manager, "operational", true);
0097         compare(manager.adapters.length, 1, "adapters-length");
0098         compare(manager.devices.length, 4, "devices-length");
0099     }
0100 
0101     function cleanupTestCase()
0102     {
0103         FakeBluez.stop();
0104     }
0105 
0106     function compareProperties(input, props)
0107     {
0108         compare(modeString(input), props.ReconnectMode, "reconnectMode");
0109     }
0110 
0111     function test_getProperties()
0112     {
0113         var device1 = manager.deviceForUbi(device1props.Path);
0114         var device2 = manager.deviceForUbi(device2props.Path);
0115         var device3 = manager.deviceForUbi(device3props.Path);
0116         var device4 = manager.deviceForUbi(device4props.Path);
0117 
0118         compareProperties(device1.input, input1props);
0119         compareProperties(device2.input, input2props);
0120         compareProperties(device3.input, input3props);
0121         compareProperties(device4.input, input4props);
0122     }
0123 
0124     function modeString(input)
0125     {
0126         switch (input.reconnectMode) {
0127         case BluezQt.Input.NoReconnect:
0128             return "none";
0129         case BluezQt.Input.HostReconnect:
0130             return "host";
0131         case BluezQt.Input.DeviceReconnect:
0132             return "device";
0133         default:
0134             return "any";
0135         }
0136     }
0137 }
0138