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 <qvideoprobe.h>
33#include <qaudiorecorder.h>
34#include <qmediaplayer.h>
35
36//TESTED_COMPONENT=src/multimedia
37
38#include "mockmediaserviceprovider.h"
39#include "mockmediarecorderservice.h"
40#include "mockmediaplayerservice.h"
41#include "mockmediaobject.h"
42
43QT_USE_NAMESPACE
44
45class tst_QVideoProbe: public QObject
46{
47 Q_OBJECT
48
49public slots:
50 void init();
51 void cleanup();
52
53private slots:
54 void testNullService();
55 void testPlayer();
56 void testPlayerDeleteRecorder();
57 void testPlayerDeleteProbe();
58 void testRecorder();
59
60private:
61 QMediaPlayer *player;
62 MockMediaPlayerService *mockMediaPlayerService;
63 MockMediaServiceProvider *mockProvider;
64
65 MockMediaRecorderControl *mockMediaRecorderControl;
66 MockMediaRecorderService *mockMediaRecorderService;
67 MockMediaServiceProvider *mockProviderRecorder;
68};
69
70void tst_QVideoProbe::init()
71{
72 mockMediaPlayerService = new MockMediaPlayerService();
73 mockProvider = new MockMediaServiceProvider(mockMediaPlayerService);
74 mockProvider->deleteServiceOnRelease = true;
75 player = 0;
76
77 mockMediaRecorderControl = new MockMediaRecorderControl(this);
78 mockMediaRecorderService = new MockMediaRecorderService(this, mockMediaRecorderControl);
79 mockProviderRecorder = new MockMediaServiceProvider(mockMediaRecorderService);
80 mockProviderRecorder->deleteServiceOnRelease = true;
81
82 QMediaServiceProvider::setDefaultServiceProvider(mockProvider);
83}
84
85void tst_QVideoProbe::cleanup()
86{
87 delete player;
88 delete mockProvider;
89 mockMediaPlayerService = 0;
90 mockProvider = 0;
91 player = 0;
92
93 delete mockMediaRecorderControl;
94 delete mockProviderRecorder;
95 mockMediaRecorderControl = 0;
96 mockMediaRecorderService = 0;
97 mockProviderRecorder = 0;
98}
99
100void tst_QVideoProbe::testNullService()
101{
102 mockProvider->service = 0;
103 player = new QMediaPlayer;
104
105 QVERIFY(!player->isAvailable());
106 QCOMPARE(player->availability(), QMultimedia::ServiceMissing);
107
108 QVideoProbe probe;
109 QVERIFY(!probe.isActive());
110 QVERIFY(!probe.setSource(player));
111 QVERIFY(!probe.isActive());
112 delete player;
113 player = 0;
114 QVERIFY(!probe.isActive());
115}
116
117void tst_QVideoProbe::testPlayer()
118{
119 player = new QMediaPlayer;
120 QVERIFY(player->isAvailable());
121
122 QVideoProbe probe;
123 QVERIFY(!probe.isActive());
124 QVERIFY(probe.setSource(player));
125 QVERIFY(probe.isActive());
126 probe.setSource((QMediaPlayer*)0);
127 QVERIFY(!probe.isActive());
128}
129
130void tst_QVideoProbe::testPlayerDeleteRecorder()
131{
132 player = new QMediaPlayer;
133 QVERIFY(player->isAvailable());
134
135 QVideoProbe probe;
136 QVERIFY(!probe.isActive());
137 QVERIFY(probe.setSource(player));
138 QVERIFY(probe.isActive());
139
140 delete player;
141 player = 0;
142 QVERIFY(!probe.isActive());
143 probe.setSource((QMediaPlayer*)0);
144 QVERIFY(!probe.isActive());
145}
146
147void tst_QVideoProbe::testPlayerDeleteProbe()
148{
149 player = new QMediaPlayer;
150 QVERIFY(player->isAvailable());
151
152 QVideoProbe *probe = new QVideoProbe;
153 QVERIFY(!probe->isActive());
154 QVERIFY(probe->setSource(player));
155 QVERIFY(probe->isActive());
156
157 delete probe;
158 QVERIFY(player->isAvailable());
159}
160
161void tst_QVideoProbe::testRecorder()
162{
163 QMediaServiceProvider::setDefaultServiceProvider(mockProviderRecorder);
164
165 QAudioRecorder recorder;
166 QVERIFY(recorder.isAvailable());
167
168 QVideoProbe probe;
169 QVERIFY(!probe.isActive());
170 QVERIFY(!probe.setSource(&recorder)); // No QMediaVideoProbeControl available
171 QVERIFY(!probe.isActive());
172}
173
174QTEST_GUILESS_MAIN(tst_QVideoProbe)
175
176#include "tst_qvideoprobe.moc"
177

source code of qtmultimedia/tests/auto/unit/qvideoprobe/tst_qvideoprobe.cpp