|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #ifndef TST_QRADIOTUNER_H |
|
42 #define TST_QRADIOTUNER_H |
|
43 |
|
44 #include <QtTest/QtTest> |
|
45 #include <QDebug> |
|
46 #include <QTimer> |
|
47 |
|
48 #include <qmediaobject.h> |
|
49 #include <qmediacontrol.h> |
|
50 #include <qmediaservice.h> |
|
51 #include <qradiotunercontrol.h> |
|
52 #include <qradiotuner.h> |
|
53 |
|
54 QT_USE_NAMESPACE |
|
55 class MockControl : public QRadioTunerControl |
|
56 { |
|
57 Q_OBJECT |
|
58 |
|
59 public: |
|
60 MockControl(QObject *parent): |
|
61 QRadioTunerControl(parent), |
|
62 m_active(false), |
|
63 m_searching(false),m_muted(false),m_stereo(true), |
|
64 m_volume(100),m_signal(0),m_frequency(0), |
|
65 m_band(QRadioTuner::FM) {} |
|
66 |
|
67 QRadioTuner::State state() const |
|
68 { |
|
69 return m_active ? QRadioTuner::ActiveState : QRadioTuner::StoppedState; |
|
70 } |
|
71 bool isAvailable() const |
|
72 { |
|
73 return true; |
|
74 } |
|
75 QtMultimediaKit::AvailabilityError availabilityError() const |
|
76 { |
|
77 return QtMultimediaKit::NoError; |
|
78 } |
|
79 |
|
80 QRadioTuner::Band band() const |
|
81 { |
|
82 return m_band; |
|
83 } |
|
84 |
|
85 void setBand(QRadioTuner::Band b) |
|
86 { |
|
87 m_band = b; |
|
88 emit bandChanged(m_band); |
|
89 } |
|
90 |
|
91 bool isBandSupported(QRadioTuner::Band b) const |
|
92 { |
|
93 if(b == QRadioTuner::FM || b == QRadioTuner::AM) return true; |
|
94 |
|
95 return false; |
|
96 } |
|
97 |
|
98 int frequency() const |
|
99 { |
|
100 return m_frequency; |
|
101 } |
|
102 |
|
103 QPair<int,int> frequencyRange(QRadioTuner::Band) const |
|
104 { |
|
105 return qMakePair<int,int>(1,2); |
|
106 } |
|
107 |
|
108 int frequencyStep(QRadioTuner::Band) const |
|
109 { |
|
110 return 1; |
|
111 } |
|
112 |
|
113 void setFrequency(int frequency) |
|
114 { |
|
115 m_frequency = frequency; |
|
116 emit frequencyChanged(m_frequency); |
|
117 } |
|
118 |
|
119 bool isStereo() const |
|
120 { |
|
121 return m_stereo; |
|
122 } |
|
123 |
|
124 void setStereo(bool stereo) |
|
125 { |
|
126 emit stereoStatusChanged(m_stereo = stereo); |
|
127 } |
|
128 |
|
129 |
|
130 QRadioTuner::StereoMode stereoMode() const |
|
131 { |
|
132 return m_stereoMode; |
|
133 } |
|
134 |
|
135 void setStereoMode(QRadioTuner::StereoMode mode) |
|
136 { |
|
137 m_stereoMode = mode; |
|
138 } |
|
139 |
|
140 QRadioTuner::Error error() const |
|
141 { |
|
142 return QRadioTuner::NoError; |
|
143 } |
|
144 |
|
145 QString errorString() const |
|
146 { |
|
147 return QString(); |
|
148 } |
|
149 |
|
150 int signalStrength() const |
|
151 { |
|
152 return m_signal; |
|
153 } |
|
154 |
|
155 int volume() const |
|
156 { |
|
157 return m_volume; |
|
158 } |
|
159 |
|
160 void setVolume(int volume) |
|
161 { |
|
162 m_volume = volume; |
|
163 emit volumeChanged(m_volume); |
|
164 } |
|
165 |
|
166 bool isMuted() const |
|
167 { |
|
168 return m_muted; |
|
169 } |
|
170 |
|
171 void setMuted(bool muted) |
|
172 { |
|
173 m_muted = muted; |
|
174 emit mutedChanged(m_muted); |
|
175 } |
|
176 |
|
177 bool isSearching() const |
|
178 { |
|
179 return m_searching; |
|
180 } |
|
181 |
|
182 void searchForward() |
|
183 { |
|
184 m_searching = true; |
|
185 emit searchingChanged(m_searching); |
|
186 } |
|
187 |
|
188 void searchBackward() |
|
189 { |
|
190 m_searching = true; |
|
191 emit searchingChanged(m_searching); |
|
192 } |
|
193 |
|
194 void cancelSearch() |
|
195 { |
|
196 m_searching = false; |
|
197 emit searchingChanged(m_searching); |
|
198 } |
|
199 |
|
200 void start() |
|
201 { |
|
202 if (!m_active) { |
|
203 m_active = true; |
|
204 emit stateChanged(state()); |
|
205 } |
|
206 } |
|
207 |
|
208 void stop() |
|
209 { |
|
210 if (m_active) { |
|
211 m_active = false; |
|
212 emit stateChanged(state()); |
|
213 } |
|
214 } |
|
215 |
|
216 public: |
|
217 bool m_active; |
|
218 bool m_searching; |
|
219 bool m_muted; |
|
220 bool m_stereo; |
|
221 int m_volume; |
|
222 int m_signal; |
|
223 int m_frequency; |
|
224 QRadioTuner::StereoMode m_stereoMode; |
|
225 QRadioTuner::Band m_band; |
|
226 }; |
|
227 |
|
228 class MockService : public QMediaService |
|
229 { |
|
230 Q_OBJECT |
|
231 public: |
|
232 MockService(QObject *parent, QMediaControl *control): |
|
233 QMediaService(parent), |
|
234 mockControl(control) {} |
|
235 |
|
236 QMediaControl* requestControl(const char *) |
|
237 { |
|
238 return mockControl; |
|
239 } |
|
240 |
|
241 void releaseControl(QMediaControl*) {} |
|
242 |
|
243 QMediaControl *mockControl; |
|
244 }; |
|
245 |
|
246 class MockProvider : public QMediaServiceProvider |
|
247 { |
|
248 public: |
|
249 MockProvider(MockService *service):mockService(service) {} |
|
250 QMediaService *requestService(const QByteArray &, const QMediaServiceProviderHint &) |
|
251 { |
|
252 return mockService; |
|
253 } |
|
254 |
|
255 void releaseService(QMediaService *) {} |
|
256 |
|
257 MockService *mockService; |
|
258 }; |
|
259 |
|
260 class tst_QRadioTuner: public QObject |
|
261 { |
|
262 Q_OBJECT |
|
263 |
|
264 public slots: |
|
265 void initTestCase(); |
|
266 void cleanupTestCase(); |
|
267 |
|
268 private slots: |
|
269 void testNullService(); |
|
270 void testNullControl(); |
|
271 void testBand(); |
|
272 void testFrequency(); |
|
273 void testMute(); |
|
274 void testSearch(); |
|
275 void testVolume(); |
|
276 void testSignal(); |
|
277 void testStereo(); |
|
278 |
|
279 private: |
|
280 MockControl *mock; |
|
281 MockService *service; |
|
282 MockProvider *provider; |
|
283 QRadioTuner *radio; |
|
284 }; |
|
285 #endif |