author | hgs |
Fri, 03 Sep 2010 12:25:04 +0300 | |
changeset 47 | 74b7c6e79031 |
parent 28 | 075425b8d9a4 |
child 51 | bbebb0235466 |
permissions | -rw-r--r-- |
24 | 1 |
/* |
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: radiostation test implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#define UNIT_TESTS_FOR_10_1 |
|
19 |
#ifdef UNIT_TESTS_FOR_10_1 |
|
20 |
#include <e32base.h> |
|
21 |
#include <eikenv.h> |
|
22 |
#endif |
|
23 |
#include "t_radiostation.h" |
|
24 |
#include "radiopresetstorage.h" |
|
25 |
#include "radiostation.h" |
|
26 |
#include "radiostationmodel.h" |
|
27 |
#include "radiohistorymodel.h" |
|
28 |
#include "radioenginewrapper.h" |
|
29 |
#include "radiouiengine.h" |
|
47 | 30 |
#include "radioengineutils.h" |
28
075425b8d9a4
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
31 |
#include "radiologger.h" //Radio::connect |
47 | 32 |
#include "trace.h" |
24 | 33 |
|
34 |
// Constants |
|
35 |
const uint KTestFrequency1 = 89000000; |
|
36 |
const uint KTestFrequency2 = 89500000; |
|
37 |
const uint KTestFrequency3 = 90000000; |
|
38 |
const uint KTestFrequency4 = 90500000; |
|
39 |
const uint KTestFrequency5 = 91000000; |
|
40 |
const uint KTestFrequency6 = 91500000; |
|
41 |
const uint KTestGenre1 = 1; |
|
42 |
const uint KTestGenre2 = 2; |
|
43 |
const QString KTestStationName1 = "Radio Noice"; |
|
44 |
const QString KTestStationName2 = "RN RENAMED"; |
|
45 |
const QString KTestUrl1 = "http://qt.nokia.com"; |
|
46 |
const QString KTestUrl2 = "http://www.radionoice.com"; |
|
47 |
const QString KTestFrequencyString1 = "89000000"; |
|
48 |
const QString KTestFrequencyString2 = "89500000"; |
|
49 |
const QString KTestFrequencyString3 = "90000000"; |
|
50 |
const QString KTestFrequencyString6 = "91500000"; |
|
51 |
const QString KTestArtist1 = "Eläkeläiset"; |
|
52 |
const QString KTestArtist2 = "Jope"; |
|
53 |
const QString KTestArtist3 = "Motorhead"; |
|
54 |
const QString KTestTitle1 = "Humppa^2"; |
|
55 |
const QString KTestTitle2 = "´åäö´ ^&%¤^"; |
|
56 |
const QString KTestTitle3 = "Dancing queen"; |
|
57 |
const QString KTestRadioTextRadioText = "NOW! Metallica - Enter sandman in MusicStore for free"; |
|
58 |
const QString KTestRadioTextPlusArtist = "Metallica"; |
|
59 |
const QString KTestRadioTextPlusTitle = "Enter sandman"; |
|
60 |
const QString KTestRadioTextPlusUrl = "www.metallica.com"; |
|
61 |
const QString KTestRadioTextPlusUnsupportedTag = "*#*#*#"; |
|
62 |
const QString KTestDynamicPSText = "MAKKARAA"; |
|
63 |
||
64 |
/*! |
|
65 |
* |
|
66 |
*/ |
|
67 |
int main(int /* argc*/, char *argv[]) |
|
68 |
{ |
|
47 | 69 |
FUNC_LOG; |
24 | 70 |
TestRadioUiEngine tv; |
71 |
||
72 |
char *pass[3]; |
|
73 |
pass[0] = argv[0]; |
|
74 |
pass[1] = "-o"; |
|
75 |
pass[2] = "c:\\data\\testradiouiengine.txt"; |
|
76 |
||
77 |
int res = QTest::qExec(&tv, 3, pass); |
|
78 |
||
79 |
return res; |
|
80 |
} |
|
81 |
||
82 |
||
83 |
TestRadioUiEngine::TestRadioUiEngine() |
|
84 |
{ |
|
47 | 85 |
FUNC_LOG; |
24 | 86 |
} |
87 |
||
88 |
||
89 |
void TestRadioUiEngine::tunedToFrequency( uint /* frequency */, int /* commandSender */) |
|
90 |
{ |
|
47 | 91 |
FUNC_LOG; |
24 | 92 |
} |
93 |
||
94 |
||
47 | 95 |
void TestRadioUiEngine::seekingStarted( Seek::Direction /* direction */) |
24 | 96 |
{ |
47 | 97 |
FUNC_LOG; |
24 | 98 |
} |
99 |
||
100 |
void TestRadioUiEngine::radioStatusChanged( bool /* radioIsOn */) |
|
101 |
{ |
|
47 | 102 |
FUNC_LOG; |
24 | 103 |
} |
104 |
||
105 |
void TestRadioUiEngine::rdsAvailabilityChanged( bool /* available */) |
|
106 |
{ |
|
47 | 107 |
FUNC_LOG; |
24 | 108 |
} |
109 |
||
110 |
void TestRadioUiEngine::volumeChanged( int /* volume */) |
|
111 |
{ |
|
47 | 112 |
FUNC_LOG; |
24 | 113 |
} |
114 |
||
115 |
void TestRadioUiEngine::muteChanged( bool /* muted */) |
|
116 |
{ |
|
47 | 117 |
FUNC_LOG; |
24 | 118 |
} |
119 |
||
120 |
void TestRadioUiEngine::audioRouteChanged( bool /* loudspeaker */) |
|
121 |
{ |
|
47 | 122 |
FUNC_LOG; |
24 | 123 |
} |
124 |
||
125 |
void TestRadioUiEngine::scanAndSaveFinished() |
|
126 |
{ |
|
47 | 127 |
FUNC_LOG; |
24 | 128 |
} |
129 |
||
130 |
||
131 |
void TestRadioUiEngine::headsetStatusChanged( bool /* connected */) |
|
132 |
{ |
|
47 | 133 |
FUNC_LOG; |
24 | 134 |
} |
135 |
||
136 |
void TestRadioUiEngine::skipPrevious() |
|
137 |
{ |
|
47 | 138 |
FUNC_LOG; |
24 | 139 |
} |
140 |
||
141 |
void TestRadioUiEngine::skipNext() |
|
142 |
{ |
|
47 | 143 |
FUNC_LOG; |
24 | 144 |
} |
145 |
||
146 |
/*! |
|
147 |
* Destructor |
|
148 |
*/ |
|
149 |
TestRadioUiEngine::~TestRadioUiEngine() |
|
150 |
{ |
|
47 | 151 |
FUNC_LOG; |
24 | 152 |
delete mUiEngine; |
153 |
} |
|
154 |
||
155 |
/*! |
|
156 |
* called before each testfunction is executed |
|
157 |
*/ |
|
158 |
void TestRadioUiEngine::init() |
|
159 |
{ |
|
47 | 160 |
FUNC_LOG; |
24 | 161 |
} |
162 |
||
163 |
/*! |
|
164 |
* called after every testfunction |
|
165 |
*/ |
|
166 |
void TestRadioUiEngine::cleanup() |
|
167 |
{ |
|
47 | 168 |
FUNC_LOG; |
24 | 169 |
} |
170 |
||
171 |
/*! |
|
172 |
* called before the first testfunction is executed |
|
173 |
*/ |
|
174 |
void TestRadioUiEngine::initTestCase() |
|
175 |
{ |
|
47 | 176 |
FUNC_LOG; |
24 | 177 |
#ifdef UNIT_TESTS_FOR_10_1 |
178 |
// Workaround for the below panic, occured after porting to 10.1 |
|
179 |
// Main Panic E32USER-CBase 44 |
|
180 |
// Create and install the active scheduler |
|
181 |
CActiveScheduler* scheduler = new(ELeave) CActiveScheduler; |
|
182 |
CleanupStack::PushL(scheduler); |
|
183 |
CActiveScheduler::Install(scheduler); |
|
184 |
#endif |
|
47 | 185 |
RadioEngineUtils::InitializeL(); |
24 | 186 |
mUiEngine = new RadioUiEngine; |
47 | 187 |
mUiEngine->init(); |
24 | 188 |
|
47 | 189 |
mEngineWrapper.reset( new RadioEngineWrapper( mUiEngine->stationModel().stationHandlerIf() ) ); |
190 |
mEngineWrapper->init(); |
|
24 | 191 |
mPresetStorage.reset( new RadioPresetStorage() ); |
47 | 192 |
mUiEngine->stationModel().initialize( mPresetStorage.data(), mEngineWrapper.data() ); |
24 | 193 |
|
194 |
//TODO:: Check why ASSERT fails when mModel->rowCount() == 0 |
|
47 | 195 |
if(mUiEngine->stationModel().rowCount()>0) |
24 | 196 |
{ |
47 | 197 |
mUiEngine->stationModel().removeAll(); //ASSERT: \"last >= first\" in file qabstractitemmodel.cpp, line 2110 |
24 | 198 |
} |
199 |
||
47 | 200 |
Radio::connect( &mUiEngine->stationModel(), SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), |
24 | 201 |
this, SLOT(dataChanged(const QModelIndex, const QModelIndex)) ); |
202 |
||
47 | 203 |
Radio::connect( &mUiEngine->stationModel(), SIGNAL(stationDataChanged(RadioStation)), |
24 | 204 |
this, SLOT(stationDataChanged(RadioStation)) ); |
205 |
||
47 | 206 |
Radio::connect( &mUiEngine->stationModel(), SIGNAL(favoriteChanged(RadioStation)), |
24 | 207 |
this, SLOT(favoriteChanged(RadioStation)) ); |
208 |
||
47 | 209 |
Radio::connect( &mUiEngine->historyModel(), SIGNAL(itemAdded()), |
24 | 210 |
this, SLOT(itemAdded()) ); |
211 |
} |
|
212 |
||
213 |
/*! |
|
214 |
* called after the last testfunction was executed |
|
215 |
*/ |
|
216 |
void TestRadioUiEngine::cleanupTestCase() |
|
217 |
{ |
|
47 | 218 |
FUNC_LOG; |
219 |
delete &mUiEngine->stationModel(); |
|
24 | 220 |
delete mUiEngine; |
221 |
} |
|
222 |
||
223 |
/*! |
|
224 |
* |
|
225 |
*/ |
|
226 |
void TestRadioUiEngine::dataChanged(const QModelIndex /* topLeft */, const QModelIndex /* bottomRight */) |
|
227 |
{ |
|
47 | 228 |
FUNC_LOG; |
24 | 229 |
mEnteredSlots |= DataChanged; |
230 |
} |
|
231 |
||
232 |
/*! |
|
233 |
* |
|
234 |
*/ |
|
235 |
void TestRadioUiEngine::stationDataChanged( RadioStation /* addedStation */ ) |
|
236 |
{ |
|
47 | 237 |
FUNC_LOG; |
24 | 238 |
mEnteredSlots |= StationDataChanged; |
239 |
} |
|
240 |
||
241 |
/*! |
|
242 |
* |
|
243 |
*/ |
|
244 |
void TestRadioUiEngine::favoriteChanged( RadioStation /* addedStation */) |
|
245 |
{ |
|
47 | 246 |
FUNC_LOG; |
24 | 247 |
mEnteredSlots |= FavoriteChanged; |
248 |
} |
|
249 |
||
250 |
/*! |
|
251 |
* |
|
252 |
*/ |
|
253 |
void TestRadioUiEngine::itemAdded() |
|
254 |
{ |
|
47 | 255 |
FUNC_LOG; |
24 | 256 |
mEnteredSlots |= ItemAdded; |
257 |
} |
|
258 |
||
259 |
||
260 |
/*! |
|
261 |
* Testing of implicit sharing a.k.a. copy-on-write |
|
262 |
*/ |
|
263 |
void TestRadioUiEngine::testImplicitSharing() |
|
264 |
{ |
|
47 | 265 |
FUNC_LOG; |
24 | 266 |
RadioStation t_RadioStation_1; |
267 |
||
268 |
int originalPresetIndex = t_RadioStation_1.presetIndex(); |
|
269 |
// before any values assigned into any data field |
|
270 |
QVERIFY2(( originalPresetIndex == RadioStation::SharedNull ), "API:Radiostation init failed 1"); |
|
271 |
t_RadioStation_1.setName("Noice"); |
|
272 |
originalPresetIndex = t_RadioStation_1.presetIndex(); |
|
273 |
// once some value assigned into some other data field |
|
274 |
QVERIFY2(( originalPresetIndex == RadioStation::Invalid ), "API:Radiostation init failed 2"); |
|
275 |
||
276 |
t_RadioStation_1.setFrequency( KTestFrequency1 ); |
|
277 |
//const int newIndex = mModel->findUnusedPresetIndex(); |
|
278 |
t_RadioStation_1.setPresetIndex( 2 ); |
|
279 |
t_RadioStation_1.setGenre(1); |
|
280 |
t_RadioStation_1.setUrl("http://qt.nokia.com"); |
|
281 |
||
282 |
RadioStation* t_RadioStation_2 = new RadioStation(t_RadioStation_1); |
|
283 |
// test that changing the content of copied data doesn't cause |
|
284 |
// detach in the copying data structure |
|
285 |
uint originalFrequency = t_RadioStation_1.frequency(); |
|
286 |
t_RadioStation_1.setFrequency( originalFrequency + 1 ); |
|
287 |
// should be detached |
|
288 |
bool detached = t_RadioStation_2->isDetached(); |
|
289 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ freq 1"); |
|
290 |
||
291 |
// test that changing the content of data sets detach true |
|
292 |
originalFrequency = t_RadioStation_2->frequency(); |
|
293 |
t_RadioStation_2->setFrequency( originalFrequency + 1 ); |
|
294 |
// should be detached |
|
295 |
detached = t_RadioStation_2->isDetached(); |
|
296 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ freq 2"); |
|
297 |
delete t_RadioStation_2; |
|
298 |
t_RadioStation_2 = NULL; |
|
299 |
||
300 |
//------------------------------------------------------------------------- |
|
301 |
// test that changing the content of copied data doesn't cause |
|
302 |
// detach in the copying data structure |
|
303 |
t_RadioStation_2 = new RadioStation(t_RadioStation_1); |
|
304 |
// should not be detached |
|
305 |
detached = t_RadioStation_2->isDetached(); |
|
306 |
QVERIFY2(!detached, "API:Radiostation Implicit sharing/ preset index 1"); |
|
307 |
originalPresetIndex = t_RadioStation_1.presetIndex(); |
|
308 |
t_RadioStation_1.setPresetIndex( originalPresetIndex + 1 ); |
|
309 |
// should be detached |
|
310 |
detached = t_RadioStation_2->isDetached(); |
|
311 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ preset index 2"); |
|
312 |
||
313 |
// test that changing the content of data sets detach true |
|
314 |
originalPresetIndex = t_RadioStation_2->presetIndex(); |
|
315 |
//newIndex = mModel->findUnusedPresetIndex(); |
|
316 |
t_RadioStation_2->setPresetIndex( originalPresetIndex + 1 ); |
|
317 |
// should be detached |
|
318 |
detached = t_RadioStation_2->isDetached(); |
|
319 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ preset index 3"); |
|
320 |
delete t_RadioStation_2; |
|
321 |
t_RadioStation_2 = NULL; |
|
322 |
||
323 |
// test that changing the content of copied data doesn't cause |
|
324 |
// detach in the copying data structure |
|
325 |
t_RadioStation_2 = new RadioStation(t_RadioStation_1); |
|
326 |
// should not be detached |
|
327 |
detached = t_RadioStation_2->isDetached(); |
|
328 |
QVERIFY2(!detached, "API:Radiostation Implicit sharing/ name 1"); |
|
329 |
//QString originalName = t_RadioStation_1.name(); |
|
330 |
t_RadioStation_1.setName("RadioOne"); |
|
331 |
// should be detached |
|
332 |
detached = t_RadioStation_2->isDetached(); |
|
333 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ name 2"); |
|
334 |
// test that changing the content of data sets detach true |
|
335 |
t_RadioStation_2->setName("RadioTwo"); |
|
336 |
// should be detached |
|
337 |
detached = t_RadioStation_2->isDetached(); |
|
338 |
QVERIFY2(detached, "API:Radiostation Implicit sharing/ name 3"); |
|
339 |
} |
|
340 |
||
341 |
/*! |
|
342 |
* Testing of change flags set by RadioStation class |
|
343 |
*/ |
|
344 |
void TestRadioUiEngine::testChangeFlags() |
|
345 |
{ |
|
47 | 346 |
FUNC_LOG; |
24 | 347 |
RadioStation t_RadioStation; |
348 |
||
349 |
QVERIFY2(!t_RadioStation.isValid(), "API:Radiostation Init failure"); |
|
350 |
t_RadioStation.setUserDefinedName(""); |
|
351 |
t_RadioStation.setUserDefinedName("Radio Noice"); |
|
352 |
t_RadioStation.setFrequency( KTestFrequency1 ); |
|
353 |
//const int newIndex = mModel->findUnusedPresetIndex(); |
|
354 |
t_RadioStation.setPresetIndex( 2 ); |
|
355 |
t_RadioStation.setGenre( KTestGenre1 ); |
|
356 |
t_RadioStation.setUrl( KTestUrl1 ); |
|
357 |
||
358 |
t_RadioStation.resetChangeFlags(); |
|
359 |
bool persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
360 |
QVERIFY2(!persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 1"); |
|
361 |
t_RadioStation.setUserDefinedName("Radio Noice+"); |
|
362 |
bool nameChanged = t_RadioStation.hasDataChanged( RadioStation::NameChanged ); |
|
363 |
QVERIFY2(nameChanged, "API:Radiostation Change flags/ NameChanged"); |
|
364 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
365 |
QVERIFY2(persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 2"); |
|
366 |
t_RadioStation.resetChangeFlags(); |
|
367 |
||
368 |
uint originalGenre = t_RadioStation.genre(); |
|
369 |
t_RadioStation.setGenre( originalGenre + 1 ); |
|
370 |
bool genreChanged = t_RadioStation.hasDataChanged( RadioStation::GenreChanged ); |
|
371 |
QVERIFY2(genreChanged, "API:Radiostation Change flags/ GenreChanged"); |
|
372 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
373 |
QVERIFY2(persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 3"); |
|
374 |
t_RadioStation.resetChangeFlags(); |
|
375 |
||
376 |
QString originalUrl = t_RadioStation.url(); |
|
377 |
t_RadioStation.setUrl(originalUrl); |
|
378 |
// previous url set so no url or persistent data change flags should be set |
|
379 |
bool urlChanged = t_RadioStation.hasDataChanged( RadioStation::UrlChanged ); |
|
380 |
QVERIFY2(!urlChanged, "API:Radiostation Change flags/ UrlChanged"); |
|
381 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
382 |
QVERIFY2(!persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 4"); |
|
383 |
t_RadioStation.resetChangeFlags(); |
|
384 |
||
385 |
QString originalRadioText = t_RadioStation.radioText(); |
|
386 |
t_RadioStation.setRadioText( originalRadioText + "buy sausage" ); |
|
387 |
bool radioTextChanged = t_RadioStation.hasDataChanged( RadioStation::RadioTextChanged ); |
|
388 |
QVERIFY2(radioTextChanged, "API:Radiostation Change flags/ RadioTextChanged"); |
|
389 |
// radio text not stored into cenrep |
|
390 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
391 |
QVERIFY2(!persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 5"); |
|
392 |
t_RadioStation.resetChangeFlags(); |
|
393 |
t_RadioStation.setRadioText( t_RadioStation.radioText() ); |
|
394 |
// because current radio text is reset change flags must not be affected |
|
395 |
radioTextChanged = t_RadioStation.hasDataChanged( RadioStation::RadioTextChanged ); |
|
396 |
QVERIFY2(!radioTextChanged, "API:Radiostation Change flags/ RadioTextChanged"); |
|
397 |
t_RadioStation.resetChangeFlags(); |
|
398 |
||
399 |
QVERIFY2((t_RadioStation.psType()==RadioStation::Unknown), "API:Radiostation PS type check"); |
|
400 |
t_RadioStation.setPsType( RadioStation::Dynamic ); |
|
401 |
bool psTypeChanged = t_RadioStation.hasDataChanged( RadioStation::PsTypeChanged ); |
|
402 |
QVERIFY2(psTypeChanged, "API:Radiostation Change flags/ PsTypeChanged"); |
|
403 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
404 |
// PS type not stored as persistent data |
|
405 |
QVERIFY2(!persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 6"); |
|
406 |
t_RadioStation.resetChangeFlags(); |
|
407 |
||
408 |
t_RadioStation.setFavorite(t_RadioStation.isFavorite()); |
|
409 |
bool favouriteChanged = t_RadioStation.hasDataChanged( RadioStation::FavoriteChanged ); |
|
410 |
QVERIFY2(!favouriteChanged, "API:Radiostation Change flags/ FavoriteChanged"); |
|
411 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
412 |
QVERIFY2(!persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 7"); |
|
413 |
t_RadioStation.resetChangeFlags(); |
|
414 |
||
415 |
// initially there should not be PI code defined |
|
416 |
QVERIFY2(!t_RadioStation.hasPiCode(), "API:Radiostation Pi code check"); |
|
417 |
// non-clear channel |
|
418 |
t_RadioStation.setPiCode(0xC004, RadioRegion::Default); //88.1 CBEE-FM - Chatham, ON |
|
419 |
bool piCodeChanged = t_RadioStation.hasDataChanged( RadioStation::PiCodeChanged ); |
|
420 |
QVERIFY2(piCodeChanged, "API:Radiostation Change flags/ PiCodeChanged"); |
|
421 |
persistentDataChanged = t_RadioStation.hasDataChanged( RadioStation::PersistentDataChanged ); |
|
422 |
QVERIFY2(persistentDataChanged, "API:Radiostation Change flags/ PersistentDataChanged 8"); |
|
423 |
} |
|
424 |
||
425 |
/*! |
|
426 |
* Testing of call sign integer to char conversion |
|
427 |
*/ |
|
428 |
void TestRadioUiEngine::TestCallSignChar() |
|
429 |
{ |
|
47 | 430 |
FUNC_LOG; |
431 |
/* |
|
24 | 432 |
for(uint i = 0; i < KLastCallSignCharCode; i++) |
433 |
{ |
|
434 |
RadioStation t_RadioStation; |
|
435 |
bool passed = t_RadioStation.callSignChar(i) == static_cast<char>( 'A' + i ); |
|
436 |
QVERIFY2(passed, "API:Radiostation TestCallSignChar 1"); |
|
437 |
} |
|
438 |
RadioStation t_RadioStation; |
|
439 |
bool passed = t_RadioStation.callSignChar(KLastCallSignCharCode + 1) == static_cast<char>( '?' ); |
|
440 |
QVERIFY2(passed, "API:Radiostation TestCallSignChar 2"); |
|
47 | 441 |
*/ |
24 | 442 |
} |
443 |
||
444 |
/*! |
|
445 |
* Testing of PI code to call sign conversion |
|
446 |
*/ |
|
447 |
void TestRadioUiEngine::testPICodeToCallSign() |
|
448 |
{ |
|
47 | 449 |
FUNC_LOG; |
450 |
/* |
|
451 |
RadioStation t_RadioStation; |
|
24 | 452 |
|
453 |
// boundary values, two typical values and three chars call sign case |
|
454 |
QString callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst - 1 ); |
|
455 |
QVERIFY2((callSign==""), "API:Radiostation Call sign <"); |
|
456 |
callSign = t_RadioStation.piCodeToCallSign( KKxxxCallSignPiFirst ); |
|
457 |
QVERIFY2((callSign=="KAAA"), "API:Radiostation Call sign KAAA"); |
|
458 |
callSign = t_RadioStation.piCodeToCallSign( 0x243F ); |
|
459 |
QVERIFY2((callSign=="KHRJ"), "API:Radiostation Call sign KHRJ"); |
|
460 |
callSign = t_RadioStation.piCodeToCallSign( KWxxxCallSignPiFirst - 1 ); |
|
461 |
QVERIFY2((callSign=="KZZZ"), "API:Radiostation Call sign KZZZ"); |
|
462 |
callSign = t_RadioStation.piCodeToCallSign( KWxxxCallSignPiFirst ); |
|
463 |
QVERIFY2((callSign=="WAAA"), "API:Radiostation Call sign WAAA"); |
|
464 |
callSign = t_RadioStation.piCodeToCallSign( 0x74B9 ); |
|
465 |
QVERIFY2((callSign=="WMDT"), "API:Radiostation Call sign WMDT"); |
|
466 |
callSign = t_RadioStation.piCodeToCallSign( KWxxxCallSignPiLast ); |
|
467 |
QVERIFY2((callSign=="WZZZ"), "API:Radiostation Call sign WZZZ"); |
|
468 |
callSign = t_RadioStation.piCodeToCallSign( KWxxxCallSignPiLast + 1 ); |
|
469 |
QVERIFY2((callSign=="KEX"), "API:Radiostation Call sign KEX"); |
|
470 |
callSign = t_RadioStation.piCodeToCallSign( 0x99B5 ); |
|
471 |
QVERIFY2((callSign=="WJZ"), "API:Radiostation Call sign WJZ"); |
|
472 |
callSign = t_RadioStation.piCodeToCallSign( 0x99C0 ); |
|
473 |
QVERIFY2((callSign==""), "API:Radiostation Call sign ????"); |
|
47 | 474 |
*/ |
24 | 475 |
} |
476 |
||
477 |
/*! |
|
478 |
* Testing of RadioStationModel initial state |
|
479 |
*/ |
|
480 |
void TestRadioUiEngine::testRadioStationModelInit() |
|
481 |
{ |
|
47 | 482 |
FUNC_LOG; |
24 | 483 |
//TODO:: Check why ASSERT fails when mModel->rowCount() == 0 |
47 | 484 |
if( mUiEngine->stationModel().rowCount()>0 ) |
24 | 485 |
{ |
47 | 486 |
mUiEngine->stationModel().removeAll(); |
487 |
QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioStationModel removeAll()"); |
|
24 | 488 |
} |
489 |
||
490 |
RadioStation foundStation; |
|
491 |
// no stations in the model in this phase |
|
47 | 492 |
QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency1, foundStation )), |
24 | 493 |
"API:RadioStationModel findFrequency 1"); |
494 |
} |
|
495 |
||
496 |
/*! |
|
497 |
* Testing of RadioStationModel addStation method and resulting RadioStationModel signals |
|
498 |
*/ |
|
499 |
void TestRadioUiEngine::testAddStation1() |
|
500 |
{ |
|
47 | 501 |
FUNC_LOG; |
24 | 502 |
RadioStation station; |
503 |
station.setFrequency( KTestFrequency1 ); |
|
504 |
station.setFrequency( KTestFrequency1 ); |
|
505 |
station.setGenre( KTestGenre1 ); |
|
506 |
station.setGenre( KTestGenre1 ); |
|
507 |
station.setUrl( KTestUrl1 ); |
|
508 |
station.setType( RadioStation::LocalStation ); |
|
509 |
station.setType( RadioStation::LocalStation ); |
|
510 |
station.setName(""); |
|
511 |
station.setName( KTestStationName1 ); |
|
512 |
station.setDynamicPsText( KTestDynamicPSText ); |
|
513 |
station.setPiCode( 0xC004, RadioRegion::America ); //88.1 CBEE-FM - Chatham, ON |
|
514 |
QVERIFY2(!(station.dynamicPsText().compare(KTestDynamicPSText)), "API:RadioStationModel addStation 1"); |
|
515 |
station.setDynamicPsText( KTestDynamicPSText ); |
|
516 |
// check that adding station increases model row count |
|
47 | 517 |
mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; |
24 | 518 |
mStationToBeAdded = station.name(); |
47 | 519 |
mUiEngine->stationModel().addStation( station ); |
520 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 2"); |
|
521 |
bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged ); |
|
24 | 522 |
|
47 | 523 |
bool frequencyUpdated = station.frequency() == KTestFrequency1; |
24 | 524 |
QVERIFY2(frequencyUpdated, "API:RadioStationModel addStation 1"); |
525 |
// check that correct signals received |
|
526 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel addStation 3"); |
|
527 |
mEnteredSlots = NoSlotsEntered; |
|
528 |
||
529 |
// check that added station can be found by frequency |
|
47 | 530 |
int index( KErrNotFound ); |
531 |
index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency1 ); |
|
532 |
QVERIFY2(index != KErrNotFound, "Added station not found from model!"); |
|
533 |
||
534 |
RadioStation readStation ( mUiEngine->stationModel().stationAt( index ) ); |
|
535 |
QVERIFY2( !readStation.name().compare(KTestStationName1), "Added station's name not found from model!"); |
|
24 | 536 |
} |
537 |
||
538 |
/*! |
|
539 |
* Testing of RadioStationModel saveStation method and resulting RadioStationModel signals |
|
540 |
*/ |
|
541 |
void TestRadioUiEngine::testSaveStation1() |
|
542 |
{ |
|
47 | 543 |
FUNC_LOG; |
24 | 544 |
RadioStation newStation1; |
545 |
// check that find by frequency works |
|
546 |
// this is needed for preset index to be updated into newStation1 |
|
47 | 547 |
QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), |
24 | 548 |
"API:RadioStationModel findFrequency 2"); |
549 |
newStation1.setType( RadioStation::Favorite ); |
|
47 | 550 |
mEnteredSlots = NoSlotsEntered; |
551 |
mUiEngine->stationModel().saveStation( newStation1 ); |
|
24 | 552 |
bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && |
553 |
mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged );; |
|
554 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 1"); |
|
47 | 555 |
mEnteredSlots = NoSlotsEntered; |
24 | 556 |
|
557 |
newStation1.setGenre(newStation1.genre()+1); |
|
47 | 558 |
mUiEngine->stationModel().saveStation( newStation1 ); |
24 | 559 |
correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged ); |
560 |
// check that correct signals received |
|
561 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2"); |
|
47 | 562 |
mEnteredSlots = NoSlotsEntered; |
24 | 563 |
} |
564 |
||
565 |
/*! |
|
566 |
* Testing of RadioStationModel addStation method and rowCount methods |
|
567 |
*/ |
|
568 |
void TestRadioUiEngine::testAddStation2() |
|
569 |
{ |
|
47 | 570 |
FUNC_LOG; |
24 | 571 |
RadioStation newStation2; |
572 |
newStation2.setFrequency( KTestFrequency2 ); |
|
573 |
newStation2.setGenre( KTestGenre2 ); |
|
574 |
newStation2.setUrl( KTestUrl2 ); |
|
575 |
newStation2.setType( RadioStation::LocalStation | RadioStation::Favorite ); |
|
576 |
newStation2.setName("Radio ice"); |
|
577 |
// check that adding station increases model row count |
|
47 | 578 |
mExpectedStationCount = mUiEngine->stationModel().rowCount()+1; |
24 | 579 |
mStationToBeAdded = newStation2.name(); |
47 | 580 |
mUiEngine->stationModel().addStation( newStation2 ); |
24 | 581 |
|
47 | 582 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); |
24 | 583 |
mEnteredSlots = NoSlotsEntered; |
584 |
} |
|
585 |
||
586 |
/*! |
|
587 |
* Testing of RadioStationModel saveStation method special cases |
|
588 |
*/ |
|
589 |
void TestRadioUiEngine::testSaveStation2() |
|
590 |
{ |
|
47 | 591 |
FUNC_LOG; |
24 | 592 |
RadioStation newStation1; |
593 |
// this is needed for preset index to be updated into newStation1 |
|
47 | 594 |
QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency1, newStation1 )), |
24 | 595 |
"API:RadioStationModel findFrequency 2"); |
596 |
||
597 |
newStation1.setFrequency( KTestFrequency2 ); |
|
47 | 598 |
mExpectedStationCount = mUiEngine->stationModel().rowCount(); |
24 | 599 |
// updating existing station data must not increase station count |
47 | 600 |
mUiEngine->stationModel().saveStation( newStation1 ); |
601 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 1"); |
|
24 | 602 |
// because frequency tried to be updated no signals should be received either |
47 | 603 |
bool correctSignalsReceived = mEnteredSlots.testFlag( DataChanged ); |
24 | 604 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 2"); |
605 |
mEnteredSlots = NoSlotsEntered; |
|
606 |
||
607 |
// original frequency resumed |
|
608 |
newStation1.setFrequency( KTestFrequency1 ); |
|
609 |
newStation1.setGenre(newStation1.genre()+1); |
|
47 | 610 |
mExpectedStationCount = mUiEngine->stationModel().rowCount(); |
24 | 611 |
// now that frequency resumed signal should be received also |
47 | 612 |
mUiEngine->stationModel().saveStation( newStation1 ); |
24 | 613 |
correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && mEnteredSlots.testFlag( DataChanged ); |
614 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel saveStation 3"); |
|
615 |
// updating existing station data must not increase station count |
|
47 | 616 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel saveStation 2"); |
24 | 617 |
|
47 | 618 |
mExpectedStationCount = mUiEngine->stationModel().rowCount(); |
24 | 619 |
mStationToBeAdded = newStation1.name(); |
620 |
// adding station must fail because the frequency is the same as previously used frequency |
|
47 | 621 |
mUiEngine->stationModel().addStation( newStation1 ); |
622 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 3"); |
|
24 | 623 |
} |
624 |
||
625 |
/*! |
|
626 |
* Testing of RadioStationModel addStation method special cases |
|
627 |
*/ |
|
628 |
void TestRadioUiEngine::testAddStation3() |
|
629 |
{ |
|
47 | 630 |
FUNC_LOG; |
24 | 631 |
RadioStation newStation3; |
632 |
newStation3.setFrequency( KTestFrequency2 ); |
|
633 |
newStation3.setGenre(3); |
|
634 |
newStation3.setUrl("http://www.radio4noice.com"); |
|
635 |
newStation3.setType( RadioStation::LocalStation | RadioStation::Favorite ); |
|
636 |
newStation3.setName("Radio e"); |
|
637 |
// adding station must fail because frequency is the same as previously used frequency |
|
47 | 638 |
mExpectedStationCount = mUiEngine->stationModel().rowCount(); |
24 | 639 |
mStationToBeAdded = newStation3.name(); |
47 | 640 |
mUiEngine->stationModel().addStation( newStation3 ); |
641 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 4"); |
|
24 | 642 |
// adding station must success because the station frequency is different now |
643 |
newStation3.setFrequency( KTestFrequency2 + 1 ); |
|
47 | 644 |
mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; |
645 |
mUiEngine->stationModel().addStation( newStation3 ); |
|
646 |
QVERIFY2((mUiEngine->stationModel().rowCount()==mExpectedStationCount), "API:RadioStationModel addStation 5"); |
|
24 | 647 |
// test that station can be found by frequency range |
648 |
QList<RadioStation> stations; |
|
47 | 649 |
stations = mUiEngine->stationModel().stationsInRange( KTestFrequency1, KTestFrequency3 ); |
24 | 650 |
QVERIFY2((stations.count()==3), "API:RadioStationModel stationsInRange"); |
651 |
} |
|
652 |
||
653 |
/*! |
|
654 |
* Testing of RadioStationModel saveStation method special cases |
|
655 |
*/ |
|
656 |
void TestRadioUiEngine::testSaveStation3() |
|
657 |
{ |
|
47 | 658 |
FUNC_LOG; |
24 | 659 |
RadioStation newStation3; |
660 |
RadioStation foundStation; |
|
47 | 661 |
QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency2 + 1, newStation3 ), |
24 | 662 |
"API:RadioStationModel findFrequency 4"); |
663 |
||
664 |
newStation3.setFrequency( KTestFrequency3 ); |
|
665 |
// because frequency or preset index don't have change flag the frequency must not be updated |
|
47 | 666 |
mUiEngine->stationModel().saveStation( newStation3 ); |
24 | 667 |
|
47 | 668 |
QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )), |
24 | 669 |
"API:RadioStationModel findFrequency 3"); |
670 |
||
671 |
newStation3.setGenre( newStation3.genre() + 1 ); |
|
672 |
// allthough genre changed so the frequency update must not become effective |
|
47 | 673 |
mUiEngine->stationModel().saveStation( newStation3 ); |
24 | 674 |
|
47 | 675 |
QVERIFY2(!(mUiEngine->stationModel().findFrequency( KTestFrequency3, foundStation )), |
24 | 676 |
"API:RadioStationModel findFrequency 4"); |
677 |
||
678 |
||
679 |
mEnteredSlots = NoSlotsEntered; |
|
47 | 680 |
foreach( const RadioStation& station, mUiEngine->stationModel().list() ) |
24 | 681 |
{ |
682 |
if ( station.frequency() == KTestFrequency2 ) |
|
683 |
{ |
|
47 | 684 |
mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency2, !station.isFavorite() ); |
24 | 685 |
} |
686 |
} |
|
687 |
bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && |
|
688 |
mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged ); |
|
689 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel findFrequency 5"); |
|
690 |
} |
|
691 |
||
692 |
||
693 |
||
694 |
/*! |
|
695 |
* Test that stations are stored into RadioStationModel in ascending frequency order |
|
696 |
*/ |
|
697 |
void TestRadioUiEngine::testSortByFrequency() |
|
698 |
{ |
|
47 | 699 |
FUNC_LOG; |
700 |
int role = RadioRole::RadioStationRole; |
|
24 | 701 |
int previousFrequency(0); // int not initialized zero as default |
702 |
||
47 | 703 |
for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ ) |
24 | 704 |
{ |
47 | 705 |
QModelIndex index = mUiEngine->stationModel().index( i, 0 ); |
706 |
QVariant stationData = mUiEngine->stationModel().data( index, role ); |
|
24 | 707 |
RadioStation station = stationData.value<RadioStation>(); |
708 |
// stations must be obtainded at ascending frequency order |
|
709 |
QVERIFY2((station.frequency()>previousFrequency), "API:RadioStationModel testSortByFrequency"); |
|
710 |
previousFrequency = station.frequency(); |
|
711 |
} |
|
712 |
} |
|
713 |
||
714 |
/*! |
|
715 |
* Test that preset indexes match |
|
716 |
*/ |
|
717 |
void TestRadioUiEngine::testFindPresetIndex() |
|
718 |
{ |
|
47 | 719 |
FUNC_LOG; |
24 | 720 |
RadioStation station; |
47 | 721 |
for (int i = 0; i< mUiEngine->stationModel().rowCount(); i++ ) |
24 | 722 |
{ |
47 | 723 |
QVERIFY2((mUiEngine->stationModel().findPresetIndex(i) != RadioStation::NotFound), |
24 | 724 |
"API:RadioStationModel testFindPresetIndex 1"); |
47 | 725 |
QVERIFY2((mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound), |
24 | 726 |
"API:RadioStationModel testFindPresetIndex 2"); |
727 |
QVERIFY2((station.presetIndex() == i), "API:RadioStationModel testFindPresetIndex 3"); |
|
728 |
} |
|
729 |
} |
|
730 |
||
731 |
/*! |
|
732 |
* Test that preset can be removed from model by frequency |
|
733 |
*/ |
|
734 |
void TestRadioUiEngine::testRemoveByFrequency() |
|
735 |
{ |
|
47 | 736 |
FUNC_LOG; |
24 | 737 |
RadioStation station; |
47 | 738 |
int initialStationCount( mUiEngine->stationModel().rowCount() ); |
24 | 739 |
int presetIndex(0); |
740 |
||
741 |
// find valid preset index |
|
47 | 742 |
for(int i = 0; i<mUiEngine->stationModel().rowCount(); i++) |
24 | 743 |
{ |
47 | 744 |
presetIndex = mUiEngine->stationModel().findPresetIndex( i, station ); |
24 | 745 |
if(presetIndex!=RadioStation::NotFound) |
746 |
break; |
|
747 |
} |
|
748 |
QVERIFY2((presetIndex != RadioStation::NotFound), "API:RadioStationModel testRemoveByFrequency 1"); |
|
749 |
||
47 | 750 |
mUiEngine->stationModel().removeByFrequency( station.frequency() ); |
751 |
QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByFrequency 2"); |
|
24 | 752 |
} |
753 |
||
754 |
/*! |
|
755 |
* Test that station can be removed from model by preset index |
|
756 |
*/ |
|
757 |
void TestRadioUiEngine::testRemoveByPresetIndex() |
|
758 |
{ |
|
47 | 759 |
FUNC_LOG; |
24 | 760 |
RadioStation station; |
761 |
station.setFrequency( KTestFrequency4 ); |
|
762 |
mStationToBeAdded = ""; |
|
47 | 763 |
mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; |
764 |
mUiEngine->stationModel().addStation( station ); |
|
24 | 765 |
// for updating station preset index |
47 | 766 |
QVERIFY2((mUiEngine->stationModel().findFrequency( KTestFrequency4, station )), |
24 | 767 |
"API:RadioStationModel testRemoveByPresetIndex 1"); |
768 |
||
47 | 769 |
int initialStationCount( mUiEngine->stationModel().rowCount() ); |
770 |
mUiEngine->stationModel().removeByPresetIndex( station.presetIndex() ); |
|
771 |
QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveByPresetIndex 2"); |
|
24 | 772 |
} |
773 |
||
774 |
/*! |
|
775 |
* Test RadioStationModel method removeStation |
|
776 |
*/ |
|
777 |
void TestRadioUiEngine::testRemoveStation() |
|
778 |
{ |
|
47 | 779 |
FUNC_LOG; |
24 | 780 |
RadioStation station; |
781 |
station.setFrequency( KTestFrequency5 ); |
|
782 |
mStationToBeAdded = ""; |
|
47 | 783 |
mExpectedStationCount = mUiEngine->stationModel().rowCount() + 1; |
784 |
mUiEngine->stationModel().addStation( station ); |
|
785 |
int initialStationCount( mUiEngine->stationModel().rowCount() ); |
|
24 | 786 |
// for updating station preset index |
47 | 787 |
QVERIFY2(mUiEngine->stationModel().findFrequency( KTestFrequency5, station ), |
24 | 788 |
"API:RadioStationModel testRemoveStation"); |
789 |
||
47 | 790 |
mUiEngine->stationModel().removeStation( station ); |
791 |
QVERIFY2((mUiEngine->stationModel().rowCount()==(initialStationCount-1)), "API:RadioStationModel testRemoveStation"); |
|
24 | 792 |
} |
793 |
||
794 |
||
795 |
/*! |
|
796 |
* Test setting and unsetting station type favourite |
|
797 |
*/ |
|
798 |
void TestRadioUiEngine::testSetFavorite() |
|
799 |
{ |
|
47 | 800 |
FUNC_LOG; |
24 | 801 |
RadioStation station; |
802 |
station.setFrequency( KTestFrequency6 ); |
|
803 |
station.setType( RadioStation::Favorite ); |
|
804 |
QVERIFY2(station.isFavorite(), "API:RadioStationModel testSetFavorite 1"); |
|
47 | 805 |
mUiEngine->stationModel().addStation( station ); |
24 | 806 |
mEnteredSlots = NoSlotsEntered; |
807 |
||
47 | 808 |
mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, false ); |
24 | 809 |
bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && |
810 |
mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged ); |
|
811 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 2"); |
|
812 |
||
47 | 813 |
mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); |
24 | 814 |
QVERIFY2(!station.isFavorite(), "API:RadioStationModel testSetFavorite 3"); |
815 |
mEnteredSlots = NoSlotsEntered; |
|
816 |
||
47 | 817 |
mUiEngine->stationModel().setFavoriteByPreset( station.presetIndex(), true ); |
24 | 818 |
correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && |
819 |
mEnteredSlots.testFlag( FavoriteChanged ) && mEnteredSlots.testFlag( DataChanged ); |
|
820 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel testSetFavorite 4"); |
|
821 |
||
822 |
// test toggling the favorite |
|
47 | 823 |
int index = mUiEngine->stationModel().indexFromFrequency( KTestFrequency6 ); |
824 |
mUiEngine->stationModel().setFavoriteByFrequency( KTestFrequency6, ETrue ); |
|
825 |
RadioStation station1 = mUiEngine->stationModel().stationAt( index ); |
|
826 |
QVERIFY2(station1.isFavorite(), "API:RadioStationModel testToggleFavourite"); |
|
24 | 827 |
|
828 |
} |
|
829 |
||
830 |
/*! |
|
831 |
* Test renaming station |
|
832 |
*/ |
|
833 |
void TestRadioUiEngine::testRenameStation() |
|
834 |
{ |
|
47 | 835 |
FUNC_LOG; |
24 | 836 |
RadioStation station; |
837 |
int presetIndex(0); |
|
838 |
// find valid preset index |
|
47 | 839 |
for( int i = 0; i<mUiEngine->stationModel().rowCount(); i++ ) |
24 | 840 |
{ |
47 | 841 |
if( mUiEngine->stationModel().findPresetIndex( i, station ) != RadioStation::NotFound ) |
24 | 842 |
{ |
843 |
presetIndex = i; |
|
844 |
break; |
|
845 |
} |
|
846 |
} |
|
847 |
QString initialStationName( station.name() ); |
|
848 |
mEnteredSlots = NoSlotsEntered; |
|
47 | 849 |
mUiEngine->stationModel().renameStation( presetIndex, initialStationName + "Renamed" ); |
24 | 850 |
bool correctSignalsReceived = mEnteredSlots.testFlag( StationDataChanged ) && |
851 |
mEnteredSlots.testFlag( DataChanged ); |
|
852 |
QVERIFY2(correctSignalsReceived, "API:RadioStationModel testRenameStation 1"); |
|
47 | 853 |
QVERIFY2(initialStationName!=mUiEngine->stationModel().stationAt(presetIndex).name(), "API:RadioStationModel testRenameStation 2"); |
24 | 854 |
|
855 |
station.setUserDefinedName( KTestStationName2 ); |
|
856 |
QVERIFY2(station.isRenamed(), "API:RadioStationModel testRenameStation 1"); |
|
857 |
||
858 |
} |
|
859 |
||
860 |
/*! |
|
861 |
* Test setting radio text |
|
862 |
*/ |
|
863 |
void TestRadioUiEngine::testSetRadioTextPlus() |
|
864 |
{ |
|
47 | 865 |
FUNC_LOG; |
24 | 866 |
RadioStation station; |
47 | 867 |
mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); |
24 | 868 |
station.setRadioText( "" ); |
869 |
station.setRadioText( KTestRadioTextRadioText ); |
|
870 |
station.setRadioText( KTestRadioTextRadioText ); |
|
871 |
station.setRadioTextPlus( RtPlus::Artist, KTestRadioTextPlusArtist ); |
|
872 |
station.setRadioTextPlus( RtPlus::Title, KTestRadioTextPlusTitle ); |
|
873 |
station.setRadioTextPlus( RtPlus::Homepage, KTestRadioTextPlusUrl ); |
|
874 |
station.setRadioTextPlus( RtPlus::Homepage + 1, KTestRadioTextPlusUnsupportedTag ); |
|
47 | 875 |
mUiEngine->stationModel().saveStation( station ); |
24 | 876 |
bool effective = station.radioText().contains( KTestRadioTextPlusArtist, Qt::CaseSensitive ); |
877 |
QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 1"); |
|
878 |
effective = station.radioText().contains( KTestRadioTextPlusTitle, Qt::CaseSensitive ); |
|
879 |
QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 2"); |
|
880 |
effective = !station.url().compare( KTestRadioTextPlusUrl ); |
|
881 |
QVERIFY2(effective, "API:RadioStationModel testSetRadioTextPlus 3"); |
|
882 |
} |
|
883 |
||
884 |
/*! |
|
885 |
* Test RadioStationModel API |
|
886 |
*/ |
|
887 |
void TestRadioUiEngine::testRadioStationModel() |
|
888 |
{ |
|
47 | 889 |
FUNC_LOG; |
24 | 890 |
testRadioStationModelInit(); |
891 |
testAddStation1(); |
|
892 |
testSaveStation1(); |
|
893 |
testAddStation2(); |
|
894 |
testSaveStation2(); |
|
895 |
testAddStation3(); |
|
896 |
testSaveStation3(); |
|
897 |
testSortByFrequency(); |
|
898 |
testFindPresetIndex(); |
|
899 |
testRemoveByFrequency(); |
|
900 |
testRemoveByPresetIndex(); |
|
901 |
testRemoveStation(); |
|
902 |
testSetFavorite(); |
|
903 |
testRenameStation(); |
|
904 |
testSetRadioTextPlus(); |
|
905 |
} |
|
906 |
/*! |
|
907 |
* Test RadioHistoryModel API |
|
908 |
*/ |
|
909 |
void TestRadioUiEngine::testhistoryModel() |
|
910 |
{ |
|
47 | 911 |
FUNC_LOG; |
24 | 912 |
testHistoryModelInit(); |
913 |
testHistoryModelAddItem(); |
|
914 |
testAddRadioTextPlus(); |
|
915 |
testClearRadioTextPlus(); |
|
916 |
} |
|
917 |
||
918 |
/*! |
|
919 |
* Testing of RadioHistoryModel initial state |
|
920 |
*/ |
|
921 |
void TestRadioUiEngine::testHistoryModelInit() |
|
922 |
{ |
|
47 | 923 |
FUNC_LOG; |
924 |
//TODO:: Check why ASSERT fails when mUiEngine->historyModel().rowCount() == 0 |
|
925 |
if( mUiEngine->historyModel().rowCount()>0 ) |
|
24 | 926 |
{ |
47 | 927 |
mUiEngine->historyModel().removeAll( EFalse ); |
928 |
QVERIFY2((mUiEngine->stationModel().rowCount()==0), "API:RadioHistoryModel removeAll() 1"); |
|
24 | 929 |
} |
47 | 930 |
QVERIFY2((mUiEngine->historyModel().rowCount()==0), "API:RadioHistoryModel removeAll() 2"); |
24 | 931 |
} |
932 |
||
933 |
/*! |
|
934 |
* |
|
935 |
*/ |
|
936 |
void TestRadioUiEngine::testHistoryModelAddItem() |
|
937 |
{ |
|
47 | 938 |
FUNC_LOG; |
939 |
RadioStation station; |
|
940 |
mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); |
|
941 |
int expectedHistoryItemCount( mUiEngine->historyModel().rowCount() + 1 ); |
|
24 | 942 |
mEnteredSlots = NoSlotsEntered; |
47 | 943 |
mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station ); |
24 | 944 |
// check that item count increases |
47 | 945 |
QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 2"); |
24 | 946 |
|
947 |
// check that artist/title stored into the model conforms to the one read from the model |
|
47 | 948 |
QModelIndex index = mUiEngine->historyModel().index( 0, 0 ); |
949 |
QStringList stringList = mUiEngine->historyModel().data( index, Qt::DisplayRole ).value<QStringList>(); |
|
24 | 950 |
QString artistTitle = stringList.at(0); |
951 |
QVERIFY2(!(artistTitle.compare(KTestArtist1+" - "+KTestTitle1)), "API:RadioHistoryModel addItem() 3"); |
|
952 |
||
953 |
||
47 | 954 |
expectedHistoryItemCount = mUiEngine->historyModel().rowCount(); |
24 | 955 |
// trying to add an item that allready exists must not increase the item count |
47 | 956 |
mUiEngine->historyModel().addItem( KTestArtist1, KTestTitle1, station ); |
957 |
QVERIFY2((mUiEngine->historyModel().rowCount()==expectedHistoryItemCount), "API:RadioHistoryModel addItem() 4"); |
|
24 | 958 |
} |
959 |
||
960 |
/*! |
|
961 |
* |
|
962 |
*/ |
|
963 |
void TestRadioUiEngine::testAddRadioTextPlus() |
|
964 |
{ |
|
47 | 965 |
FUNC_LOG; |
966 |
RadioStation station; |
|
967 |
mUiEngine->stationModel().findFrequency( KTestFrequency6, station ); |
|
968 |
mUiEngine->historyModel().addRadioTextPlus( RtPlus::Artist, KTestArtist1, station ); |
|
969 |
mUiEngine->historyModel().addRadioTextPlus( RtPlus::Title, KTestTitle1, station ); |
|
24 | 970 |
} |
971 |
||
972 |
/*! |
|
973 |
* |
|
974 |
*/ |
|
975 |
void TestRadioUiEngine::testClearRadioTextPlus() |
|
976 |
{ |
|
47 | 977 |
FUNC_LOG; |
978 |
mUiEngine->historyModel().clearRadioTextPlus(); |
|
24 | 979 |
} |
980 |
||
981 |
/*! |
|
982 |
* Test RadioHistoryModelItem API |
|
983 |
*/ |
|
984 |
void TestRadioUiEngine::testHistoryModelItem() |
|
985 |
{ |
|
47 | 986 |
FUNC_LOG; |
24 | 987 |
RadioHistoryItem* item = new RadioHistoryItem( KTestArtist3, KTestTitle3 ); |
988 |
item->setArtist( KTestArtist3 ); |
|
989 |
QVERIFY2(!(item->artist().compare(KTestArtist3)), "API:testHistoryModelItem setArtist()"); |
|
990 |
item->setTitle( KTestTitle3 ); |
|
991 |
QVERIFY2(!(item->title().compare(KTestTitle3)), "API:testHistoryModelItem setTitle()"); |
|
47 | 992 |
QVERIFY2( item->isValid(), "API:testHistoryModelItem isValid() 1"); |
993 |
item->reset(); |
|
994 |
QVERIFY2(!item->isValid(), "API:testHistoryModelItem isValid() 2"); |
|
24 | 995 |
delete item; |
996 |
item = NULL; |
|
997 |
} |