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 test suite 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#ifndef MOCKRECORDERCONTROL_H
30#define MOCKRECORDERCONTROL_H
31
32#include <QUrl>
33
34#include "qmediarecordercontrol.h"
35
36class MockMediaRecorderControl : public QMediaRecorderControl
37{
38 Q_OBJECT
39
40public:
41 MockMediaRecorderControl(QObject *parent = 0):
42 QMediaRecorderControl(parent),
43 m_state(QMediaRecorder::StoppedState),
44 m_status(QMediaRecorder::LoadedStatus),
45 m_position(0),
46 m_muted(false),
47 m_volume(1.0),
48 m_settingAppliedCount(0)
49 {
50 }
51
52 QUrl outputLocation() const
53 {
54 return m_sink;
55 }
56
57 bool setOutputLocation(const QUrl &sink)
58 {
59 m_sink = sink;
60 return true;
61 }
62
63 QMediaRecorder::State state() const
64 {
65 return m_state;
66 }
67
68 QMediaRecorder::Status status() const
69 {
70 return m_status;
71 }
72
73 qint64 duration() const
74 {
75 return m_position;
76 }
77
78 bool isMuted() const
79 {
80 return m_muted;
81 }
82
83 qreal volume() const
84 {
85 return m_volume;
86 }
87
88 void applySettings()
89 {
90 m_settingAppliedCount++;
91 }
92
93 using QMediaRecorderControl::error;
94
95public slots:
96 void record()
97 {
98 m_state = QMediaRecorder::RecordingState;
99 m_status = QMediaRecorder::RecordingStatus;
100 m_position=1;
101 emit stateChanged(state: m_state);
102 emit statusChanged(status: m_status);
103 emit durationChanged(position: m_position);
104
105 QUrl actualLocation = m_sink.isEmpty() ? QUrl::fromLocalFile(localfile: "default_name.mp4") : m_sink;
106 emit actualLocationChanged(location: actualLocation);
107 }
108
109 void pause()
110 {
111 m_state = QMediaRecorder::PausedState;
112 m_status = QMediaRecorder::PausedStatus;
113 emit stateChanged(state: m_state);
114 emit statusChanged(status: m_status);
115 }
116
117 void stop()
118 {
119 m_position=0;
120 m_state = QMediaRecorder::StoppedState;
121 m_status = QMediaRecorder::LoadedStatus;
122 emit stateChanged(state: m_state);
123 emit statusChanged(status: m_status);
124 }
125
126 void setState(QMediaRecorder::State state)
127 {
128 switch (state) {
129 case QMediaRecorder::StoppedState:
130 stop();
131 break;
132 case QMediaRecorder::PausedState:
133 pause();
134 break;
135 case QMediaRecorder::RecordingState:
136 record();
137 break;
138 }
139 }
140
141
142 void setMuted(bool muted)
143 {
144 if (m_muted != muted)
145 emit mutedChanged(muted: m_muted = muted);
146 }
147
148 void setVolume(qreal volume)
149 {
150 if (!qFuzzyCompare(p1: m_volume, p2: volume))
151 emit volumeChanged(volume: m_volume = volume);
152 }
153
154public:
155 QUrl m_sink;
156 QMediaRecorder::State m_state;
157 QMediaRecorder::Status m_status;
158 qint64 m_position;
159 bool m_muted;
160 qreal m_volume;
161 int m_settingAppliedCount;
162};
163
164#endif // MOCKRECORDERCONTROL_H
165

source code of qtmultimedia/tests/auto/unit/qmultimedia_common/mockmediarecordercontrol.h