blob: 3f898f17c49f566f962410ebb1983657249b842f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QtTest>
#include <QtCore/qlocale.h>
#include <qaudiodevice.h>
#include <QStringList>
#include <QList>
#include <QMediaDevices>
#include <private/mediabackendutils_p.h>
#include <private/osdetection_p.h>
class tst_QAudioDeviceBackend : public QObject
{
Q_OBJECT
public:
tst_QAudioDeviceBackend(QObject* parent=nullptr) : QObject(parent) {}
private slots:
void initTestCase();
void checkAvailableDefaultInput();
void checkAvailableDefaultOutput();
void channels();
void sampleFormat();
void sampleRates();
void isFormatSupported();
void preferred();
void assignOperator();
void id();
void defaultConstructor();
void equalityOperator();
private:
std::unique_ptr<QAudioDevice> device;
};
void tst_QAudioDeviceBackend::initTestCase()
{
// Only perform tests if audio output device exists!
QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
if (devices.size() == 0) {
QSKIP("NOTE: no audio output device found, no tests will be performed");
} else {
device = std::make_unique<QAudioDevice>(devices.at(0));
}
}
void tst_QAudioDeviceBackend::checkAvailableDefaultInput()
{
// Only perform tests if audio input device exists!
QList<QAudioDevice> devices = QMediaDevices::audioInputs();
if (devices.size() > 0) {
auto defaultInput = QMediaDevices::defaultAudioInput();
QVERIFY(!defaultInput.isNull());
QCOMPARE(std::count(devices.begin(), devices.end(), defaultInput), 1);
}
}
void tst_QAudioDeviceBackend::checkAvailableDefaultOutput()
{
// Only perform tests if audio input device exists!
QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
if (devices.size() > 0) {
auto defaultOutput = QMediaDevices::defaultAudioOutput();
QVERIFY(!defaultOutput.isNull());
QCOMPARE(std::count(devices.begin(), devices.end(), defaultOutput), 1);
}
}
void tst_QAudioDeviceBackend::channels()
{
QVERIFY(device->minimumChannelCount() > 0);
QVERIFY(device->maximumChannelCount() >= device->minimumChannelCount());
}
void tst_QAudioDeviceBackend::sampleFormat()
{
QList<QAudioFormat::SampleFormat> avail = device->supportedSampleFormats();
QVERIFY(avail.size() > 0);
}
void tst_QAudioDeviceBackend::sampleRates()
{
QVERIFY(device->minimumSampleRate() > 0);
QVERIFY(device->maximumSampleRate() >= device->minimumSampleRate());
}
void tst_QAudioDeviceBackend::isFormatSupported()
{
if (isCI() && isMacOS)
QSKIP("MacOS vms don't seem to support 44100hz on CI?");
QAudioFormat format;
format.setSampleRate(44100);
format.setChannelCount(2);
format.setSampleFormat(QAudioFormat::Int16);
// Should always be true for these format
QVERIFY(device->isFormatSupported(format));
}
void tst_QAudioDeviceBackend::preferred()
{
auto isPrefferedSupported = [] (const QAudioDevice& dev) {
QAudioFormat format = dev.preferredFormat();
QVERIFY(format.isValid());
QVERIFY(dev.isFormatSupported(format));
};
for (const auto &dev: QMediaDevices::audioOutputs())
isPrefferedSupported(dev);
for (const auto &dev: QMediaDevices::audioInputs())
isPrefferedSupported(dev);
}
// QAudioDevice's assignOperator method
void tst_QAudioDeviceBackend::assignOperator()
{
QAudioDevice dev;
QVERIFY(dev.id().isNull());
QVERIFY(dev.isNull() == true);
QList<QAudioDevice> devices = QMediaDevices::audioOutputs();
QVERIFY(devices.size() > 0);
QAudioDevice dev1(devices.at(0));
dev = dev1;
QVERIFY(dev.isNull() == false);
QVERIFY(dev.id() == dev1.id());
}
void tst_QAudioDeviceBackend::id()
{
QVERIFY(!device->id().isNull());
QVERIFY(device->id() == QMediaDevices::audioOutputs().at(0).id());
}
// QAudioDevice's defaultConstructor method
void tst_QAudioDeviceBackend::defaultConstructor()
{
QAudioDevice dev;
QVERIFY(dev.isNull() == true);
QVERIFY(dev.id().isNull());
}
void tst_QAudioDeviceBackend::equalityOperator()
{
// Get some default device infos
QAudioDevice dev1;
QAudioDevice dev2;
QVERIFY(dev1 == dev2);
QVERIFY(!(dev1 != dev2));
// Make sure each available device is not equal to null
const auto infos = QMediaDevices::audioOutputs();
for (const QAudioDevice &info : infos) {
QVERIFY(dev1 != info);
QVERIFY(!(dev1 == info));
dev2 = info;
QVERIFY(dev2 == info);
QVERIFY(!(dev2 != info));
QVERIFY(dev1 != dev2);
QVERIFY(!(dev1 == dev2));
}
// XXX Perhaps each available device should not be equal to any other
}
QTEST_MAIN(tst_QAudioDeviceBackend)
#include "tst_qaudiodevicebackend.moc"
|