|
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 #include "tst_qradiotuner.h" |
|
42 |
|
43 QT_USE_NAMESPACE |
|
44 |
|
45 void tst_QRadioTuner::initTestCase() |
|
46 { |
|
47 qRegisterMetaType<QRadioTuner::State>("QRadioTuner::State"); |
|
48 qRegisterMetaType<QRadioTuner::Band>("QRadioTuner::Band"); |
|
49 |
|
50 mock = new MockControl(this); |
|
51 service = new MockService(this, mock); |
|
52 provider = new MockProvider(service); |
|
53 radio = new QRadioTuner(0,provider); |
|
54 QVERIFY(radio->service() != 0); |
|
55 |
|
56 QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); |
|
57 |
|
58 QCOMPARE(radio->state(), QRadioTuner::StoppedState); |
|
59 radio->start(); |
|
60 QCOMPARE(radio->state(), QRadioTuner::ActiveState); |
|
61 |
|
62 QCOMPARE(stateSpy.count(), 1); |
|
63 QCOMPARE(stateSpy.first()[0].value<QRadioTuner::State>(), QRadioTuner::ActiveState); |
|
64 } |
|
65 |
|
66 void tst_QRadioTuner::cleanupTestCase() |
|
67 { |
|
68 QVERIFY(radio->error() == QRadioTuner::NoError); |
|
69 QVERIFY(radio->errorString().isEmpty()); |
|
70 |
|
71 QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); |
|
72 |
|
73 radio->stop(); |
|
74 QCOMPARE(radio->state(), QRadioTuner::StoppedState); |
|
75 QCOMPARE(stateSpy.count(), 1); |
|
76 |
|
77 QCOMPARE(stateSpy.first()[0].value<QRadioTuner::State>(), QRadioTuner::StoppedState); |
|
78 |
|
79 delete radio; |
|
80 delete service; |
|
81 delete provider; |
|
82 } |
|
83 |
|
84 void tst_QRadioTuner::testNullService() |
|
85 { |
|
86 const QPair<int, int> nullRange(0, 0); |
|
87 |
|
88 MockProvider provider(0); |
|
89 QRadioTuner radio(0, &provider); |
|
90 |
|
91 radio.start(); |
|
92 QCOMPARE(radio.error(), QRadioTuner::ResourceError); |
|
93 QCOMPARE(radio.errorString(), QString()); |
|
94 QCOMPARE(radio.band(), QRadioTuner::FM); |
|
95 QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false); |
|
96 QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false); |
|
97 QCOMPARE(radio.frequency(), 0); |
|
98 QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0); |
|
99 QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0); |
|
100 QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange); |
|
101 QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange); |
|
102 QCOMPARE(radio.isStereo(), false); |
|
103 QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); |
|
104 QCOMPARE(radio.signalStrength(), 0); |
|
105 QCOMPARE(radio.volume(), 0); |
|
106 QCOMPARE(radio.isMuted(), false); |
|
107 QCOMPARE(radio.isSearching(), false); |
|
108 radio.stop(); |
|
109 } |
|
110 |
|
111 void tst_QRadioTuner::testNullControl() |
|
112 { |
|
113 const QPair<int, int> nullRange(0, 0); |
|
114 |
|
115 MockService service(0, 0); |
|
116 MockProvider provider(&service); |
|
117 QRadioTuner radio(0, &provider); |
|
118 |
|
119 radio.start(); |
|
120 |
|
121 QCOMPARE(radio.error(), QRadioTuner::ResourceError); |
|
122 QCOMPARE(radio.errorString(), QString()); |
|
123 |
|
124 QCOMPARE(radio.band(), QRadioTuner::FM); |
|
125 QCOMPARE(radio.isBandSupported(QRadioTuner::AM), false); |
|
126 QCOMPARE(radio.isBandSupported(QRadioTuner::FM), false); |
|
127 QCOMPARE(radio.frequency(), 0); |
|
128 QCOMPARE(radio.frequencyStep(QRadioTuner::AM), 0); |
|
129 QCOMPARE(radio.frequencyStep(QRadioTuner::FM), 0); |
|
130 QCOMPARE(radio.frequencyRange(QRadioTuner::AM), nullRange); |
|
131 QCOMPARE(radio.frequencyRange(QRadioTuner::FM), nullRange); |
|
132 { |
|
133 QSignalSpy bandSpy(&radio, SIGNAL(bandChanged(QRadioTuner::Band))); |
|
134 QSignalSpy frequencySpy(&radio, SIGNAL(frequencyChanged(int))); |
|
135 |
|
136 radio.setFrequency(107500); |
|
137 QCOMPARE(radio.band(), QRadioTuner::FM); |
|
138 QCOMPARE(radio.frequency(), 0); |
|
139 QCOMPARE(bandSpy.count(), 0); |
|
140 QCOMPARE(frequencySpy.count(), 0); |
|
141 |
|
142 radio.setBand(QRadioTuner::AM); |
|
143 QCOMPARE(radio.band(), QRadioTuner::FM); |
|
144 QCOMPARE(radio.frequency(), 0); |
|
145 QCOMPARE(bandSpy.count(), 0); |
|
146 QCOMPARE(frequencySpy.count(), 0); |
|
147 } |
|
148 QCOMPARE(radio.isStereo(), false); |
|
149 QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); |
|
150 |
|
151 radio.setStereoMode(QRadioTuner::ForceStereo); |
|
152 QCOMPARE(radio.stereoMode(), QRadioTuner::Auto); |
|
153 |
|
154 QCOMPARE(radio.signalStrength(), 0); |
|
155 |
|
156 QCOMPARE(radio.volume(), 0); |
|
157 QCOMPARE(radio.isMuted(), false); |
|
158 { |
|
159 QSignalSpy volumeSpy(&radio, SIGNAL(volumeChanged(int))); |
|
160 QSignalSpy muteSpy(&radio, SIGNAL(mutedChanged(bool))); |
|
161 |
|
162 radio.setVolume(76); |
|
163 QCOMPARE(radio.volume(), 0); |
|
164 QCOMPARE(volumeSpy.count(), 0); |
|
165 |
|
166 radio.setMuted(true); |
|
167 QCOMPARE(radio.isMuted(), false); |
|
168 QCOMPARE(muteSpy.count(), 0); |
|
169 } |
|
170 QCOMPARE(radio.isSearching(), false); |
|
171 { |
|
172 QSignalSpy spy(&radio, SIGNAL(searchingChanged(bool))); |
|
173 |
|
174 radio.searchBackward(); |
|
175 QCOMPARE(radio.isSearching(), false); |
|
176 QCOMPARE(spy.count(), 0); |
|
177 |
|
178 radio.searchForward(); |
|
179 QCOMPARE(radio.isSearching(), false); |
|
180 QCOMPARE(spy.count(), 0); |
|
181 |
|
182 radio.cancelSearch(); |
|
183 QCOMPARE(radio.isSearching(), false); |
|
184 QCOMPARE(spy.count(), 0); |
|
185 } |
|
186 |
|
187 radio.stop(); |
|
188 } |
|
189 |
|
190 void tst_QRadioTuner::testBand() |
|
191 { |
|
192 QVERIFY(radio->isBandSupported(QRadioTuner::FM)); |
|
193 QVERIFY(!radio->isBandSupported(QRadioTuner::SW)); |
|
194 |
|
195 if(radio->isBandSupported(QRadioTuner::AM)) { |
|
196 QSignalSpy readSignal(radio, SIGNAL(bandChanged(QRadioTuner::Band))); |
|
197 radio->setBand(QRadioTuner::AM); |
|
198 QTestEventLoop::instance().enterLoop(1); |
|
199 QVERIFY(radio->band() == QRadioTuner::AM); |
|
200 QVERIFY(readSignal.count() == 1); |
|
201 } |
|
202 } |
|
203 |
|
204 void tst_QRadioTuner::testFrequency() |
|
205 { |
|
206 QSignalSpy readSignal(radio, SIGNAL(frequencyChanged(int))); |
|
207 radio->setFrequency(104500000); |
|
208 QTestEventLoop::instance().enterLoop(1); |
|
209 QVERIFY(radio->frequency() == 104500000); |
|
210 QVERIFY(readSignal.count() == 1); |
|
211 |
|
212 QVERIFY(radio->frequencyStep(QRadioTuner::FM) == 1); |
|
213 QPair<int,int> test = radio->frequencyRange(QRadioTuner::FM); |
|
214 QVERIFY(test.first == 1); |
|
215 QVERIFY(test.second == 2); |
|
216 } |
|
217 |
|
218 void tst_QRadioTuner::testMute() |
|
219 { |
|
220 QSignalSpy readSignal(radio, SIGNAL(mutedChanged(bool))); |
|
221 radio->setMuted(true); |
|
222 QTestEventLoop::instance().enterLoop(1); |
|
223 QVERIFY(radio->isMuted()); |
|
224 QVERIFY(readSignal.count() == 1); |
|
225 } |
|
226 |
|
227 void tst_QRadioTuner::testSearch() |
|
228 { |
|
229 QSignalSpy readSignal(radio, SIGNAL(searchingChanged(bool))); |
|
230 QVERIFY(!radio->isSearching()); |
|
231 |
|
232 radio->searchForward(); |
|
233 QTestEventLoop::instance().enterLoop(1); |
|
234 QVERIFY(radio->isSearching()); |
|
235 QVERIFY(readSignal.count() == 1); |
|
236 |
|
237 radio->cancelSearch(); |
|
238 QTestEventLoop::instance().enterLoop(1); |
|
239 QVERIFY(!radio->isSearching()); |
|
240 QVERIFY(readSignal.count() == 2); |
|
241 |
|
242 radio->searchBackward(); |
|
243 QTestEventLoop::instance().enterLoop(1); |
|
244 QVERIFY(radio->isSearching()); |
|
245 QVERIFY(readSignal.count() == 3); |
|
246 |
|
247 radio->cancelSearch(); |
|
248 QVERIFY(!radio->isSearching()); |
|
249 } |
|
250 |
|
251 void tst_QRadioTuner::testVolume() |
|
252 { |
|
253 QVERIFY(radio->volume() == 100); |
|
254 QSignalSpy readSignal(radio, SIGNAL(volumeChanged(int))); |
|
255 radio->setVolume(50); |
|
256 QTestEventLoop::instance().enterLoop(1); |
|
257 QVERIFY(radio->volume() == 50); |
|
258 QVERIFY(readSignal.count() == 1); |
|
259 } |
|
260 |
|
261 void tst_QRadioTuner::testSignal() |
|
262 { |
|
263 QVERIFY(radio->signalStrength() == 0); |
|
264 // There is no set of this only a get, do nothing else. |
|
265 } |
|
266 |
|
267 void tst_QRadioTuner::testStereo() |
|
268 { |
|
269 QVERIFY(radio->isStereo()); |
|
270 radio->setStereoMode(QRadioTuner::ForceMono); |
|
271 QVERIFY(radio->stereoMode() == QRadioTuner::ForceMono); |
|
272 } |