Changeset View
Changeset View
Standalone View
Standalone View
autotests/noinputnooutputagenttest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Manuel Weichselbaumer <mincequi@web.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "noinputnooutputagenttest.h" | ||||
22 | #include "autotests.h" | ||||
23 | #include "device.h" | ||||
24 | #include "manager.h" | ||||
25 | #include "initmanagerjob.h" | ||||
26 | #include "pendingcall.h" | ||||
27 | #include "services.h" | ||||
28 | #include "noinputnooutputagent.h" | ||||
29 | | ||||
30 | #include <QtTest/QTest> | ||||
31 | #include <QtTest/QSignalSpy> | ||||
32 | #include <QDBusObjectPath> | ||||
33 | | ||||
34 | namespace BluezQt | ||||
35 | { | ||||
36 | extern void bluezqt_initFakeBluezTestRun(); | ||||
37 | } | ||||
38 | | ||||
39 | using namespace BluezQt; | ||||
40 | | ||||
41 | NoInputNoOutputAgentTest::NoInputNoOutputAgentTest() | ||||
42 | : m_agent(nullptr) | ||||
43 | { | ||||
44 | Autotests::registerMetatypes(); | ||||
45 | } | ||||
46 | | ||||
47 | void NoInputNoOutputAgentTest::initTestCase() | ||||
48 | { | ||||
49 | bluezqt_initFakeBluezTestRun(); | ||||
50 | | ||||
51 | FakeBluez::start(); | ||||
52 | FakeBluez::runTest(QStringLiteral("bluez-standard")); | ||||
53 | | ||||
54 | // Create adapter | ||||
55 | QVariantMap adapterProps; | ||||
56 | adapterProps[QStringLiteral("Path")] = QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/hci0"))); | ||||
57 | adapterProps[QStringLiteral("Address")] = QStringLiteral("1C:E5:C3:BC:94:7E"); | ||||
58 | adapterProps[QStringLiteral("Name")] = QStringLiteral("TestAdapter"); | ||||
59 | FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-adapter"), adapterProps); | ||||
60 | | ||||
61 | // Create device | ||||
62 | m_device = QDBusObjectPath(QStringLiteral("/org/bluez/hci0/dev_40_79_6A_0C_39_75")); | ||||
63 | QVariantMap deviceProps; | ||||
64 | deviceProps[QStringLiteral("Path")] = QVariant::fromValue(m_device); | ||||
65 | deviceProps[QStringLiteral("Adapter")] = adapterProps.value(QStringLiteral("Path")); | ||||
66 | deviceProps[QStringLiteral("Address")] = QStringLiteral("40:79:6A:0C:39:75"); | ||||
67 | deviceProps[QStringLiteral("Name")] = QStringLiteral("TestDevice"); | ||||
68 | FakeBluez::runAction(QStringLiteral("devicemanager"), QStringLiteral("create-device"), deviceProps); | ||||
69 | | ||||
70 | Manager *manager = new Manager(this); | ||||
71 | InitManagerJob *job = manager->init(); | ||||
72 | job->exec(); | ||||
73 | | ||||
74 | QVERIFY(!job->error()); | ||||
75 | QCOMPARE(manager->adapters().count(), 1); | ||||
76 | QCOMPARE(manager->devices().count(), 1); | ||||
77 | | ||||
78 | m_agent = new NoInputNoOutputAgent({Services::AdvancedAudioDistribution, Services::AudioVideoRemoteControl}, this); | ||||
79 | manager->registerAgent(m_agent)->waitForFinished(); | ||||
80 | } | ||||
81 | | ||||
82 | void NoInputNoOutputAgentTest::cleanupTestCase() | ||||
83 | { | ||||
84 | FakeBluez::stop(); | ||||
85 | } | ||||
86 | | ||||
87 | void NoInputNoOutputAgentTest::authorizeServiceTest() | ||||
88 | { | ||||
89 | QSignalSpy agentSpy(m_agent, SIGNAL(serviceAuthorized(DevicePtr,QString,bool))); | ||||
90 | | ||||
91 | QVariantMap props; | ||||
92 | props.insert(QStringLiteral("Device"), QVariant::fromValue(m_device)); | ||||
93 | props.insert(QStringLiteral("UUID"), Services::AdvancedAudioDistribution); | ||||
94 | FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("authorize-service"), props); | ||||
95 | agentSpy.wait(); | ||||
96 | auto args = agentSpy.takeFirst(); | ||||
97 | QCOMPARE(args.at(0).value<DevicePtr>()->ubi(), m_device.path()); | ||||
98 | QCOMPARE(args.at(1).toString(), Services::AdvancedAudioDistribution); | ||||
99 | QCOMPARE(args.at(2).toBool(), true); | ||||
100 | | ||||
101 | props.insert(QStringLiteral("UUID"), Services::ObexFileTransfer); | ||||
102 | FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("authorize-service"), props); | ||||
103 | agentSpy.wait(); | ||||
104 | args = agentSpy.takeFirst(); | ||||
105 | QCOMPARE(args.at(1).toString(), Services::ObexFileTransfer); | ||||
106 | QCOMPARE(args.at(2).toBool(), false); | ||||
107 | | ||||
108 | props.insert(QStringLiteral("UUID"), Services::AudioVideoRemoteControl); | ||||
109 | FakeBluez::runAction(QStringLiteral("agentmanager"), QStringLiteral("authorize-service"), props); | ||||
110 | agentSpy.wait(); | ||||
111 | args = agentSpy.takeFirst(); | ||||
112 | QCOMPARE(args.at(1).toString(), Services::AudioVideoRemoteControl); | ||||
113 | QCOMPARE(args.at(2).toBool(), true); | ||||
114 | } | ||||
115 | | ||||
116 | QTEST_MAIN(NoInputNoOutputAgentTest) |