1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 |
|
42 #include <QtTest/QtTest> |
|
43 #include <QDebug> |
|
44 #include <QTimer> |
|
45 |
|
46 #include <qmediaobject.h> |
|
47 #include <qmediacontrol.h> |
|
48 #include <qmediaservice.h> |
|
49 #include <qradiotunercontrol.h> |
|
50 #include <qradiotuner.h> |
|
51 |
|
52 #include <QMessageBox> |
|
53 |
|
54 QTM_USE_NAMESPACE |
|
55 |
|
56 class tst_QRadioTuner: public QObject |
|
57 { |
|
58 Q_OBJECT |
|
59 |
|
60 public slots: |
|
61 void initTestCase(); |
|
62 void cleanupTestCase(); |
|
63 |
|
64 private slots: |
|
65 void testBand(); |
|
66 void testFrequency(); |
|
67 void testMute(); |
|
68 void testSearch(); |
|
69 void testVolume(); |
|
70 void testSignal(); |
|
71 void testStereo(); |
|
72 |
|
73 private: |
|
74 QRadioTuner *radio; |
|
75 }; |
|
76 |
|
77 void tst_QRadioTuner::initTestCase() |
|
78 { |
|
79 qRegisterMetaType<QRadioTuner::State>("QRadioTuner::State"); |
|
80 qRegisterMetaType<QRadioTuner::Band>("QRadioTuner::Band"); |
|
81 |
|
82 radio = new QRadioTuner(0); |
|
83 QVERIFY(radio->service() != 0); |
|
84 |
|
85 QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); |
|
86 |
|
87 QCOMPARE(radio->state(), QRadioTuner::StoppedState); |
|
88 radio->start(); |
|
89 QCOMPARE(radio->state(), QRadioTuner::ActiveState); |
|
90 |
|
91 QCOMPARE(stateSpy.count(), 1); |
|
92 QCOMPARE(stateSpy.first()[0].value<QRadioTuner::State>(), QRadioTuner::ActiveState); |
|
93 } |
|
94 |
|
95 void tst_QRadioTuner::cleanupTestCase() |
|
96 { |
|
97 QVERIFY(radio->error() == QRadioTuner::NoError); |
|
98 QVERIFY(radio->errorString().isEmpty()); |
|
99 |
|
100 QSignalSpy stateSpy(radio, SIGNAL(stateChanged(QRadioTuner::State))); |
|
101 |
|
102 radio->stop(); |
|
103 QCOMPARE(radio->state(), QRadioTuner::StoppedState); |
|
104 QCOMPARE(stateSpy.count(), 1); |
|
105 |
|
106 #ifdef QTM_NAMESPACE |
|
107 QEXPECT_FAIL("", "QSignalSpy doesn't grab the correct value from signal because of QtMobility namespace", Continue); |
|
108 #endif |
|
109 QCOMPARE(stateSpy.first()[0].value<QRadioTuner::State>(), QRadioTuner::StoppedState); |
|
110 |
|
111 delete radio; |
|
112 } |
|
113 |
|
114 void tst_QRadioTuner::testBand() |
|
115 { |
|
116 QVERIFY(radio->isBandSupported(QRadioTuner::FM)); |
|
117 QVERIFY(!radio->isBandSupported(QRadioTuner::SW)); |
|
118 |
|
119 if(radio->isBandSupported(QRadioTuner::AM)) { |
|
120 QSignalSpy readSignal(radio, SIGNAL(bandChanged(QRadioTuner::Band))); |
|
121 radio->setBand(QRadioTuner::AM); |
|
122 QTestEventLoop::instance().enterLoop(1); |
|
123 QVERIFY(radio->band() == QRadioTuner::AM); |
|
124 QVERIFY(readSignal.count() == 1); |
|
125 } |
|
126 } |
|
127 |
|
128 void tst_QRadioTuner::testFrequency() |
|
129 { |
|
130 QSignalSpy readSignal(radio, SIGNAL(frequencyChanged(int))); |
|
131 radio->setFrequency(104500000); |
|
132 QTestEventLoop::instance().enterLoop(1); |
|
133 QVERIFY(radio->frequency() == 104500000); |
|
134 QVERIFY(readSignal.count() == 1); |
|
135 |
|
136 // frequencyStep for FM radio is 100kHz (100000Hz) |
|
137 QVERIFY(radio->frequencyStep(QRadioTuner::FM) == 100000); |
|
138 QPair<int,int> test = radio->frequencyRange(QRadioTuner::FM); |
|
139 // frequency range for FM radio is 87,5MHz - 108MHz |
|
140 QVERIFY(test.first == 87500000); |
|
141 QVERIFY(test.second == 108000000); |
|
142 } |
|
143 |
|
144 void tst_QRadioTuner::testMute() |
|
145 { |
|
146 QSignalSpy readSignal(radio, SIGNAL(mutedChanged(bool))); |
|
147 radio->setMuted(true); |
|
148 QTestEventLoop::instance().enterLoop(1); |
|
149 QVERIFY(radio->isMuted()); |
|
150 QVERIFY(readSignal.count() == 1); |
|
151 } |
|
152 |
|
153 void tst_QRadioTuner::testSearch() |
|
154 { |
|
155 QSignalSpy readSignal(radio, SIGNAL(searchingChanged(bool))); |
|
156 QVERIFY(!radio->isSearching()); |
|
157 |
|
158 radio->searchForward(); |
|
159 QVERIFY(radio->isSearching()); |
|
160 QVERIFY(readSignal.count() == 1); |
|
161 |
|
162 radio->cancelSearch(); |
|
163 QTestEventLoop::instance().enterLoop(1); |
|
164 QVERIFY(!radio->isSearching()); |
|
165 QVERIFY(readSignal.count() == 2); |
|
166 |
|
167 radio->searchBackward(); |
|
168 QVERIFY(radio->isSearching()); |
|
169 QVERIFY(readSignal.count() == 3); |
|
170 |
|
171 radio->cancelSearch(); |
|
172 QVERIFY(!radio->isSearching()); |
|
173 } |
|
174 |
|
175 void tst_QRadioTuner::testVolume() |
|
176 { |
|
177 QVERIFY(radio->volume() == 100); |
|
178 QSignalSpy readSignal(radio, SIGNAL(volumeChanged(int))); |
|
179 radio->setVolume(50); |
|
180 QTestEventLoop::instance().enterLoop(1); |
|
181 QVERIFY(radio->volume() == 50); |
|
182 QVERIFY(readSignal.count() == 1); |
|
183 } |
|
184 |
|
185 void tst_QRadioTuner::testSignal() |
|
186 { |
|
187 QVERIFY(radio->signalStrength() == 0); |
|
188 // There is no set of this only a get, do nothing else. |
|
189 } |
|
190 |
|
191 void tst_QRadioTuner::testStereo() |
|
192 { |
|
193 QVERIFY(radio->isStereo()); |
|
194 radio->setStereoMode(QRadioTuner::ForceMono); |
|
195 QVERIFY(radio->stereoMode() == QRadioTuner::ForceMono); |
|
196 } |
|
197 |
|
198 QTEST_MAIN(tst_QRadioTuner) |
|
199 |
|
200 #include "tst_qradiotuner.moc" |
|