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 MOCKRADIOTUNERCONTROL_H
30#define MOCKRADIOTUNERCONTROL_H
31
32#include "qradiotunercontrol.h"
33
34class MockRadioTunerControl : public QRadioTunerControl
35{
36 Q_OBJECT
37
38public:
39 MockRadioTunerControl(QObject *parent):
40 QRadioTunerControl(parent),
41 m_active(false),
42 m_searching(false),m_muted(false),m_stereo(true),
43 m_volume(100),m_signal(0),m_frequency(0),
44 m_band(QRadioTuner::FM),m_err(QRadioTuner::NoError),
45 m_errstr("")
46 {
47 }
48
49 using QRadioTunerControl::error;
50
51 QRadioTuner::State state() const
52 {
53 return m_active ? QRadioTuner::ActiveState : QRadioTuner::StoppedState;
54 }
55
56 QRadioTuner::Band band() const
57 {
58 return m_band;
59 }
60
61 void setBand(QRadioTuner::Band b)
62 {
63 if (b == QRadioTuner::FM2 || b == QRadioTuner::LW) {
64 m_err = QRadioTuner::OutOfRangeError;
65 m_errstr.clear();
66 m_errstr = QString("band and range not supported");
67 } else {
68 m_err = QRadioTuner::NoError;
69 m_errstr.clear();
70 m_band = b;
71 emit bandChanged(band: m_band);
72 }
73 emit error(err: m_err);
74
75 }
76
77 bool isBandSupported(QRadioTuner::Band b) const
78 {
79 if (b == QRadioTuner::FM || b == QRadioTuner::AM)
80 return true;
81
82 return false;
83 }
84
85 int frequency() const
86 {
87 return m_frequency;
88 }
89
90 QPair<int,int> frequencyRange(QRadioTuner::Band) const
91 {
92 return qMakePair<int,int>(x: 1,y: 2);
93 }
94
95 int frequencyStep(QRadioTuner::Band) const
96 {
97 return 1;
98 }
99
100 void setFrequency(int frequency)
101 {
102 if (frequency >= 148500000) {
103 m_err = QRadioTuner::OutOfRangeError;
104 m_errstr.clear();
105 m_errstr = QString("band and range not supported");
106 } else {
107 m_err = QRadioTuner::NoError;
108 m_errstr.clear();
109 m_frequency = frequency;
110 emit frequencyChanged(frequency: m_frequency);
111 }
112
113 emit error(err: m_err);
114 }
115
116 bool isStereo() const
117 {
118 return m_stereo;
119 }
120
121 void setStereo(bool stereo)
122 {
123 emit stereoStatusChanged(stereo: m_stereo = stereo);
124 }
125
126
127 QRadioTuner::StereoMode stereoMode() const
128 {
129 return m_stereoMode;
130 }
131
132 void setStereoMode(QRadioTuner::StereoMode mode)
133 {
134 m_stereoMode = mode;
135 }
136
137 QRadioTuner::Error error() const
138 {
139 return m_err;
140 }
141
142 QString errorString() const
143 {
144 return m_errstr;
145 }
146
147 int signalStrength() const
148 {
149 return m_signal;
150 }
151
152 int volume() const
153 {
154 return m_volume;
155 }
156
157 void setVolume(int volume)
158 {
159 m_volume = volume;
160 emit volumeChanged(volume: m_volume);
161 }
162
163 bool isMuted() const
164 {
165 return m_muted;
166 }
167
168 void setMuted(bool muted)
169 {
170 m_muted = muted;
171 emit mutedChanged(muted: m_muted);
172 }
173
174 bool isSearching() const
175 {
176 return m_searching;
177 }
178
179 void searchForward()
180 {
181 m_searching = true;
182 emit searchingChanged(searching: m_searching);
183 }
184
185 void searchBackward()
186 {
187 m_searching = true;
188 emit searchingChanged(searching: m_searching);
189 }
190
191 void cancelSearch()
192 {
193 m_searching = false;
194 emit searchingChanged(searching: m_searching);
195 }
196
197 void findNewStation( int frequency, QString stationId )
198 {
199 setFrequency(frequency);
200 emit stationFound( frequency, stationId );
201 }
202
203 void searchAllStations(QRadioTuner::SearchMode searchMode = QRadioTuner::SearchFast)
204 {
205 QString programmeIdentifiers[3] = { "", "", "" };
206
207 if ( searchMode == QRadioTuner::SearchGetStationId ) {
208 programmeIdentifiers[0] = QString("MockProgramPI1");
209 programmeIdentifiers[1] = QString("MockProgramPI2");
210 programmeIdentifiers[2] = QString("MockProgramPI3");
211 }
212 m_searching = true;
213 emit searchingChanged(searching: m_searching);
214
215 findNewStation(frequency: 88300000, stationId: programmeIdentifiers[0]);
216 findNewStation(frequency: 95100000, stationId: programmeIdentifiers[1]);
217 findNewStation(frequency: 103100000, stationId: programmeIdentifiers[2]);
218
219 m_searching = false;
220 emit searchingChanged(searching: m_searching);
221 }
222
223 void start()
224 {
225 if (!m_active) {
226 m_active = true;
227 emit stateChanged(state: state());
228 }
229 }
230
231 void stop()
232 {
233 if (m_active) {
234 m_active = false;
235 emit stateChanged(state: state());
236 }
237 }
238
239public:
240 bool m_active;
241 bool m_searching;
242 bool m_muted;
243 bool m_stereo;
244 int m_volume;
245 int m_signal;
246 int m_frequency;
247 QRadioTuner::StereoMode m_stereoMode;
248 QRadioTuner::Band m_band;
249 QRadioTuner::Error m_err;
250 QString m_errstr;
251};
252
253#endif // MOCKRADIOTUNERCONTROL_H
254

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