Changeset View
Changeset View
Standalone View
Standalone View
autotests/mediatest.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 "mediatest.h" | ||||
22 | #include "a2dp-codecs.h" | ||||
23 | #include "autotests.h" | ||||
24 | #include "initmanagerjob.h" | ||||
25 | #include "manager.h" | ||||
26 | #include "media.h" | ||||
27 | #include "mediaendpoint.h" | ||||
28 | #include "pendingcall.h" | ||||
29 | | ||||
30 | #include <QDebug> | ||||
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 | void TestEndpoint::release() | ||||
42 | { | ||||
43 | m_releaseCalled = true; | ||||
44 | } | ||||
45 | | ||||
46 | void MediaTest::initTestCase() | ||||
47 | { | ||||
48 | bluezqt_initFakeBluezTestRun(); | ||||
49 | FakeBluez::start(); | ||||
50 | FakeBluez::runTest(QStringLiteral("bluez-standard")); | ||||
51 | | ||||
52 | Manager *manager = new Manager(this); | ||||
53 | InitManagerJob *initJob = manager->init(); | ||||
54 | initJob->exec(); | ||||
55 | QVERIFY(!initJob->error()); | ||||
56 | QVERIFY(manager->media()); | ||||
57 | | ||||
58 | m_endpoint = new TestEndpoint({MediaEndpoint::Role::AudioSink, MediaEndpoint::Codec::Sbc}, this); | ||||
59 | manager->media()->registerEndpoint(m_endpoint)->waitForFinished(); | ||||
60 | } | ||||
61 | | ||||
62 | void MediaTest::cleanupTestCase() | ||||
63 | { | ||||
64 | FakeBluez::stop(); | ||||
65 | } | ||||
66 | | ||||
67 | void MediaTest::setConfigurationTest() | ||||
68 | { | ||||
69 | QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationSet(QString,QVariantMap))); | ||||
70 | | ||||
71 | QVariantMap props; | ||||
72 | props.insert(QStringLiteral("Key"), QVariant::fromValue(int(123))); | ||||
73 | | ||||
74 | QVariantMap params; | ||||
75 | params.insert(QStringLiteral("Transport"), QVariant::fromValue(m_endpoint->objectPath())); | ||||
76 | params.insert(QStringLiteral("Properties"), props); | ||||
77 | FakeBluez::runAction(QStringLiteral("media"), QStringLiteral("set-configuration"), params); | ||||
78 | endpointSpy.wait(); | ||||
79 | auto args = endpointSpy.takeFirst(); | ||||
80 | QCOMPARE(args.at(0).toString(), m_endpoint->objectPath().path()); | ||||
81 | QCOMPARE(args.at(1).value<QVariantMap>(), props); | ||||
82 | } | ||||
83 | | ||||
84 | void MediaTest::selectConfigurationTest() | ||||
85 | { | ||||
86 | QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationSelected(QByteArray,QByteArray))); | ||||
87 | | ||||
88 | a2dp_sbc_t sbcConfiguration; | ||||
89 | sbcConfiguration.frequency = SBC_SAMPLING_FREQ_44100; | ||||
90 | sbcConfiguration.channel_mode = SBC_CHANNEL_MODE_STEREO; | ||||
91 | sbcConfiguration.block_length = SBC_BLOCK_LENGTH_16; | ||||
92 | sbcConfiguration.subbands = SBC_SUBBANDS_8; | ||||
93 | sbcConfiguration.allocation_method = SBC_ALLOCATION_LOUDNESS; | ||||
94 | sbcConfiguration.min_bitpool = 2; | ||||
95 | sbcConfiguration.max_bitpool = 53; | ||||
96 | | ||||
97 | QVariantMap params; | ||||
98 | params.insert(QStringLiteral("Capabilities"), QByteArray(reinterpret_cast<const char*>(&sbcCapabilities), sizeof(sbcCapabilities))); | ||||
99 | FakeBluez::runAction(QStringLiteral("media"), QStringLiteral("select-configuration"), params); | ||||
100 | endpointSpy.wait(); | ||||
101 | auto args = endpointSpy.takeFirst(); | ||||
102 | QCOMPARE(args.at(0).toByteArray(), QByteArray(reinterpret_cast<const char*>(&sbcCapabilities), sizeof(sbcCapabilities))); | ||||
103 | QCOMPARE(args.at(1).toByteArray(), QByteArray(reinterpret_cast<const char*>(&sbcConfiguration), sizeof(sbcConfiguration))); | ||||
104 | | ||||
105 | params.insert(QStringLiteral("Capabilities"), QByteArray()); | ||||
106 | FakeBluez::runAction(QStringLiteral("media"), QStringLiteral("select-configuration"), params); | ||||
107 | endpointSpy.wait(); | ||||
108 | args = endpointSpy.takeFirst(); | ||||
109 | QCOMPARE(args.at(0).toByteArray(), QByteArray()); | ||||
110 | QCOMPARE(args.at(1).toByteArray(), QByteArray()); | ||||
111 | } | ||||
112 | | ||||
113 | void MediaTest::clearConfigurationTest() | ||||
114 | { | ||||
115 | QSignalSpy endpointSpy(m_endpoint, SIGNAL(configurationCleared(QString))); | ||||
116 | | ||||
117 | QVariantMap params; | ||||
118 | params.insert(QStringLiteral("Transport"), QVariant::fromValue(m_endpoint->objectPath())); | ||||
119 | FakeBluez::runAction(QStringLiteral("media"), QStringLiteral("clear-configuration"), params); | ||||
120 | endpointSpy.wait(); | ||||
121 | auto args = endpointSpy.takeFirst(); | ||||
122 | QCOMPARE(args.at(0).toString(), m_endpoint->objectPath().path()); | ||||
123 | } | ||||
124 | | ||||
125 | void MediaTest::releaseTest() | ||||
126 | { | ||||
127 | QCOMPARE(m_endpoint->m_releaseCalled, false); | ||||
128 | | ||||
129 | FakeBluez::runAction(QStringLiteral("media"), QStringLiteral("release")); | ||||
130 | | ||||
131 | QTRY_COMPARE(m_endpoint->m_releaseCalled, true); | ||||
132 | } | ||||
133 | | ||||
134 | QTEST_MAIN(MediaTest) |