1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include <QDebug>
31
32#include <qaudioprobe.h>
33#include <qaudiorecorder.h>
34
35//TESTED_COMPONENT=src/multimedia
36
37#include "mockmediaserviceprovider.h"
38#include "mockmediarecorderservice.h"
39#include "mockmediaobject.h"
40
41QT_USE_NAMESPACE
42
43class tst_QAudioProbe: public QObject
44{
45 Q_OBJECT
46
47public slots:
48 void init();
49 void cleanup();
50
51private slots:
52 void testNullService();
53 void testNullControl();
54 void testRecorder();
55 void testRecorderDeleteRecorder();
56 void testRecorderDeleteProbe();
57 void testMediaObject();
58
59private:
60 QAudioRecorder *recorder;
61 MockMediaRecorderControl *mockMediaRecorderControl;
62 MockMediaRecorderService *mockMediaRecorderService;
63 MockMediaServiceProvider *mockProvider;
64};
65
66void tst_QAudioProbe::init()
67{
68 mockMediaRecorderControl = new MockMediaRecorderControl(this);
69 mockMediaRecorderService = new MockMediaRecorderService(this, mockMediaRecorderControl);
70 mockProvider = new MockMediaServiceProvider(mockMediaRecorderService);
71 mockProvider->deleteServiceOnRelease = true;
72 recorder = 0;
73
74 QMediaServiceProvider::setDefaultServiceProvider(mockProvider);
75}
76
77void tst_QAudioProbe::cleanup()
78{
79 delete recorder;
80 delete mockProvider;
81 delete mockMediaRecorderControl;
82 mockMediaRecorderControl = 0;
83 mockMediaRecorderService = 0;
84 mockProvider = 0;
85 recorder = 0;
86}
87
88void tst_QAudioProbe::testNullService()
89{
90 mockProvider->service = 0;
91 recorder = new QAudioRecorder;
92
93 QVERIFY(!recorder->isAvailable());
94 QCOMPARE(recorder->availability(), QMultimedia::ServiceMissing);
95
96 QAudioProbe probe;
97 QVERIFY(!probe.isActive());
98 QVERIFY(!probe.setSource(recorder));
99 QVERIFY(!probe.isActive());
100 delete recorder;
101 recorder = 0;
102 QVERIFY(!probe.isActive());
103}
104
105
106void tst_QAudioProbe::testNullControl()
107{
108 mockMediaRecorderService->hasControls = false;
109 recorder = new QAudioRecorder;
110
111 QVERIFY(!recorder->isAvailable());
112 QCOMPARE(recorder->availability(), QMultimedia::ServiceMissing);
113
114 QAudioProbe probe;
115 QVERIFY(!probe.isActive());
116 QVERIFY(!probe.setSource(recorder));
117 QVERIFY(!probe.isActive());
118 delete recorder;
119 recorder = 0;
120 QVERIFY(!probe.isActive());
121}
122
123void tst_QAudioProbe::testRecorder()
124{
125 recorder = new QAudioRecorder;
126 QVERIFY(recorder->isAvailable());
127
128 QAudioProbe probe;
129 QVERIFY(!probe.isActive());
130 QVERIFY(probe.setSource(recorder));
131 QVERIFY(probe.isActive());
132 probe.setSource((QMediaRecorder*)0);
133 QVERIFY(!probe.isActive());
134}
135
136void tst_QAudioProbe::testRecorderDeleteRecorder()
137{
138 recorder = new QAudioRecorder;
139 QVERIFY(recorder->isAvailable());
140
141 QAudioProbe probe;
142 QVERIFY(!probe.isActive());
143 QVERIFY(probe.setSource(recorder));
144 QVERIFY(probe.isActive());
145
146 delete recorder;
147 recorder = 0;
148 QVERIFY(!probe.isActive());
149 probe.setSource((QMediaRecorder*)0);
150 QVERIFY(!probe.isActive());
151}
152
153void tst_QAudioProbe::testRecorderDeleteProbe()
154{
155 recorder = new QAudioRecorder;
156 QVERIFY(recorder->isAvailable());
157
158 QAudioProbe *probe = new QAudioProbe;
159 QVERIFY(!probe->isActive());
160 QVERIFY(probe->setSource(recorder));
161 QVERIFY(probe->isActive());
162
163 delete probe;
164 QVERIFY(recorder->isAvailable());
165}
166
167void tst_QAudioProbe::testMediaObject()
168{
169 QMediaObject *object = new MockMediaObject(0, mockMediaRecorderService);
170 QVERIFY(object->isAvailable());
171
172 QAudioProbe probe;
173 QVERIFY(!probe.isActive());
174 QVERIFY(probe.setSource(object));
175 QVERIFY(probe.isActive());
176 probe.setSource((QMediaObject*)0);
177 QVERIFY(!probe.isActive());
178 delete object;
179}
180
181QTEST_GUILESS_MAIN(tst_QAudioProbe)
182
183#include "tst_qaudioprobe.moc"
184

source code of qtmultimedia/tests/auto/unit/qaudioprobe/tst_qaudioprobe.cpp