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