|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "unittest_mediamodel.h" |
|
19 #include "glxmediamodel.h" |
|
20 #include "glxmlwrapper.h" |
|
21 #include "glxmodelparm.h" |
|
22 #include "glxcollectionpluginall.hrh" |
|
23 #include "hbicon.h" |
|
24 |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // initTestCase |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 void TestGlxMediaModel::initTestCase() |
|
31 { |
|
32 GlxModelParm modelParm; |
|
33 modelParm.setCollection( KGlxCollectionPluginAllImplementationUid ); |
|
34 modelParm.setDepth(0); |
|
35 modelParm.setContextMode( GlxContextLsGrid ) ; |
|
36 mModel = new GlxMediaModel( modelParm ); |
|
37 QTest::qWait(2000); |
|
38 |
|
39 QVERIFY( mModel ); |
|
40 QVERIFY( mModel->mMLWrapper ); |
|
41 QVERIFY( mModel->mDRMUtilityWrapper ); |
|
42 QVERIFY( mModel->m_DefaultIcon ); |
|
43 QVERIFY( mModel->m_CorruptIcon ); |
|
44 QCOMPARE( mModel->thumbnailPopulatedFlag, false ); |
|
45 QCOMPARE( mModel->mPaintPage, true ); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // init |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void TestGlxMediaModel::init() |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 void TestGlxMediaModel::rowCountTestCase() |
|
58 { |
|
59 QVERIFY( mModel->rowCount() >= 0 ); |
|
60 } |
|
61 |
|
62 void TestGlxMediaModel::columnCountTestCase() |
|
63 { |
|
64 QCOMPARE( mModel->columnCount(), 1 ); |
|
65 } |
|
66 |
|
67 void TestGlxMediaModel::parentTestCase() |
|
68 { |
|
69 QModelIndex index = mModel->parent( mModel->index( 0, 0 ) ); |
|
70 QCOMPARE( index.isValid(), false); |
|
71 } |
|
72 |
|
73 void TestGlxMediaModel::itemImageDataInvalidIndexTestCase() |
|
74 { |
|
75 QVariant variant = mModel->itemImageData( QModelIndex(), GlxFsImageRole ); |
|
76 QCOMPARE( variant.isValid(), false ); |
|
77 |
|
78 variant = mModel->itemImageData( mModel->createIndex( mModel->rowCount(), 0 ), GlxFsImageRole ); |
|
79 QCOMPARE( variant.isValid(), false ); |
|
80 } |
|
81 |
|
82 void TestGlxMediaModel::itemImageDataGridImagetestCase() |
|
83 { |
|
84 mModel->itemIconCache.insert( 0, NULL ); |
|
85 QVariant variant = mModel->itemImageData( mModel->index( 0, 0), Qt::DecorationRole ); |
|
86 QCOMPARE( variant.isValid(), true ); |
|
87 |
|
88 mModel->itemIconCache.insert( 0, new HbIcon() ); |
|
89 variant = mModel->itemImageData( mModel->index( 0, 0), Qt::DecorationRole ); |
|
90 QCOMPARE( variant.isValid(), true ); |
|
91 } |
|
92 |
|
93 void TestGlxMediaModel::itemImageDataHdmiBitmapTestCase() |
|
94 { |
|
95 QVariant variant = mModel->itemImageData( mModel->index( 0, 0), GlxHdmiBitmap ); |
|
96 QCOMPARE( variant.isValid(), true ); |
|
97 } |
|
98 |
|
99 void TestGlxMediaModel::ItemPropertyViewTitleTestCase() |
|
100 { |
|
101 QVariant variant = mModel->collectionProperty( GlxViewTitle ); |
|
102 QCOMPARE( variant.isValid(), true ); |
|
103 } |
|
104 |
|
105 void TestGlxMediaModel::ItemPropertyImageTitleTestCase() |
|
106 { |
|
107 QVariant variant = mModel->collectionProperty( GlxImageTitle ); |
|
108 QCOMPARE( variant.isValid(), false ); |
|
109 } |
|
110 |
|
111 void TestGlxMediaModel::ItemPropertyDateTestCase() |
|
112 { |
|
113 QVariant variant = mModel->collectionProperty( GlxDateRole ); |
|
114 QCOMPARE( variant.isValid(), false ); |
|
115 } |
|
116 |
|
117 void TestGlxMediaModel::ItemPropertyCorruptImageTestCase() |
|
118 { |
|
119 QVariant variant = mModel->collectionProperty( GlxImageCorruptRole ); |
|
120 QCOMPARE( variant.isValid(), false ); |
|
121 } |
|
122 |
|
123 void TestGlxMediaModel::ItemPropertyTimeTestCase() |
|
124 { |
|
125 QVariant variant = mModel->collectionProperty( GlxTimeRole ); |
|
126 QCOMPARE( variant.isValid(), false ); |
|
127 } |
|
128 |
|
129 void TestGlxMediaModel::ItemPropertySizeTestCase() |
|
130 { |
|
131 QVariant variant = mModel->collectionProperty( GlxSizeRole ); |
|
132 QCOMPARE( variant.isValid(), false ); |
|
133 } |
|
134 |
|
135 void TestGlxMediaModel::ItemPropertyDescTestCase() |
|
136 { |
|
137 QVariant variant = mModel->collectionProperty( GlxDescRole ); |
|
138 QCOMPARE( variant.isValid(), false ); |
|
139 } |
|
140 |
|
141 void TestGlxMediaModel::indexTestCase() |
|
142 { |
|
143 QModelIndex index = mModel->index( -1, 0 ); |
|
144 QCOMPARE( index.isValid(), false); |
|
145 |
|
146 index = mModel->index( 0, -1 ); |
|
147 QCOMPARE( index.isValid(), false); |
|
148 |
|
149 index = mModel->index( mModel->rowCount(), 1 ); |
|
150 QCOMPARE( index.isValid(), false); |
|
151 |
|
152 index = mModel->index( 0, 0 ); |
|
153 QCOMPARE( index.isValid(), true); |
|
154 } |
|
155 |
|
156 void TestGlxMediaModel::setDataContextRoleTestCase() |
|
157 { |
|
158 mModel->setData( mModel->index( 0, 0 ), GlxContextPtGrid, GlxContextRole ); |
|
159 QCOMPARE( mModel->mContextMode, GlxContextPtGrid ); |
|
160 |
|
161 mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxContextRole ); |
|
162 QCOMPARE( mModel->mContextMode, GlxContextPtGrid ); |
|
163 } |
|
164 |
|
165 void TestGlxMediaModel::setDataRemoveContextRoleTestCase() |
|
166 { |
|
167 mModel->setData( mModel->index( 0, 0), GlxContextPtGrid, GlxContextRole ); |
|
168 |
|
169 mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxRemoveContextRole ); |
|
170 QCOMPARE( mModel->mContextMode, GlxContextPtGrid ); |
|
171 } |
|
172 |
|
173 void TestGlxMediaModel::setDataFocusIndexRoleTestCase() |
|
174 { |
|
175 mModel->setData( mModel->index( 0, 0), 1, GlxFocusIndexRole ); |
|
176 QCOMPARE( mModel->mFocusIndex, 1 ); |
|
177 |
|
178 mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxFocusIndexRole ); |
|
179 QCOMPARE( mModel->mFocusIndex, 1 ); |
|
180 } |
|
181 |
|
182 void TestGlxMediaModel::setDataVisualIndexTestCase() |
|
183 { |
|
184 mModel->setData( mModel->index( 0, 0), 1, GlxVisualWindowIndex ); |
|
185 int visualIndex = mModel->mMLWrapper->getVisibleWindowIndex(); |
|
186 QCOMPARE( visualIndex, 1 ); |
|
187 |
|
188 mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxVisualWindowIndex ); |
|
189 visualIndex = mModel->mMLWrapper->getVisibleWindowIndex(); |
|
190 QCOMPARE( visualIndex, 1 ); |
|
191 } |
|
192 |
|
193 void TestGlxMediaModel::setDataSelectedIndexTestCase() |
|
194 { |
|
195 bool result = mModel->setData( mModel->index( 0, 0), 1, GlxSelectedIndexRole ); |
|
196 QCOMPARE( result, true ); |
|
197 |
|
198 result = mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxSelectedIndexRole ); |
|
199 QCOMPARE( result, false ); |
|
200 } |
|
201 |
|
202 void TestGlxMediaModel::setDataSubStateTestCase() |
|
203 { |
|
204 bool result = mModel->setData( mModel->index( 0, 0), 5, GlxSubStateRole ); |
|
205 QCOMPARE( result, true ); |
|
206 QCOMPARE( mModel->mSubState, 5 ); |
|
207 |
|
208 result = mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxSubStateRole ); |
|
209 QCOMPARE( result, false ); |
|
210 QCOMPARE( mModel->mSubState, 5 ); |
|
211 } |
|
212 |
|
213 void TestGlxMediaModel::setDataTempVisualIndexTestCase() |
|
214 { |
|
215 bool result = mModel->setData( mModel->index( 0, 0), 2, GlxTempVisualWindowIndex ); |
|
216 QCOMPARE( result, true ); |
|
217 QCOMPARE( mModel->mTempVisibleWindowIndex, 2 ); |
|
218 |
|
219 result = mModel->setData( mModel->index( 0, 0), QVariant( QVariant::Invalid ), GlxTempVisualWindowIndex ); |
|
220 QCOMPARE( result, false ); |
|
221 QCOMPARE( mModel->mTempVisibleWindowIndex, 2 ); |
|
222 } |
|
223 |
|
224 void TestGlxMediaModel::GetGridIconItemTestCase() |
|
225 { |
|
226 QTest::qWait( 2000 ); |
|
227 |
|
228 mModel->itemIconCache.insert( 0, NULL ); |
|
229 HbIcon *icon = mModel->GetGridIconItem( 0, GlxTBContextGrid ); |
|
230 QVERIFY( icon || icon == NULL ); |
|
231 |
|
232 mModel->itemIconCache.insert( 0, new HbIcon() ); |
|
233 icon = mModel->GetGridIconItem( 0, GlxTBContextGrid ); |
|
234 QVERIFY( icon ); |
|
235 } |
|
236 |
|
237 void TestGlxMediaModel::GetFsIconItemTestCase() |
|
238 { |
|
239 mModel->setContextMode( GlxContextPtFs ); |
|
240 HbIcon *icon = mModel->GetFsIconItem( 0, GlxTBContextPtFs ); |
|
241 QTest::qWait( 2000 ); |
|
242 QVERIFY( icon || icon == NULL ); |
|
243 mModel->setContextMode( GlxContextLsGrid ); |
|
244 } |
|
245 |
|
246 void TestGlxMediaModel::getFullScreenIconTestCase() |
|
247 { |
|
248 HbIcon icon = mModel->getFullScreenIcon( 0 ); |
|
249 QCOMPARE( icon.isNull(), false ); |
|
250 |
|
251 mModel->itemIconCache.insert( 0, NULL ); |
|
252 icon = mModel->getFullScreenIcon( 0 ); |
|
253 QCOMPARE( icon.isNull(), false ); |
|
254 |
|
255 mModel->itemIconCache.insert( 0, new HbIcon() ); |
|
256 icon = mModel->getFullScreenIcon( 0 ); |
|
257 QCOMPARE( icon.isNull(), false ); |
|
258 } |
|
259 |
|
260 void TestGlxMediaModel::getFullScreenImagetestCase() |
|
261 { |
|
262 mModel->setContextMode( GlxContextLsFs ); |
|
263 QTest::qWait( 2000 ); |
|
264 QImage img = mModel->getFullScreenImage( 0 ); |
|
265 QVERIFY( img.isNull() == true || img.isNull() == false ); |
|
266 |
|
267 mModel->setContextMode( GlxContextPtFs ); |
|
268 QTest::qWait( 2000 ); |
|
269 img = mModel->getFullScreenImage( 0 ); |
|
270 QVERIFY( img.isNull() == true || img.isNull() == false ); |
|
271 } |
|
272 |
|
273 void TestGlxMediaModel::setContextModeTestCase() |
|
274 { |
|
275 mModel->setContextMode( GlxContextPtFs ); |
|
276 QCOMPARE( mModel->mContextMode, GlxContextPtFs ); |
|
277 |
|
278 mModel->setContextMode( GlxContextComment ); |
|
279 QCOMPARE( mModel->mContextMode, GlxContextPtFs ); |
|
280 mModel->removeContextMode( GlxContextComment ); |
|
281 |
|
282 mModel->setContextMode( GlxContextLsGrid ); |
|
283 QCOMPARE( mModel->mContextMode, GlxContextLsGrid ); |
|
284 QCOMPARE( mModel->itemFsIconCache.size(), 0 ); |
|
285 QCOMPARE( mModel->itemIconCache.size(), 0 ); |
|
286 } |
|
287 |
|
288 void TestGlxMediaModel::removeContextModeTestCase() |
|
289 { |
|
290 mModel->removeContextMode( GlxContextComment ); |
|
291 QCOMPARE( mModel->mContextMode, GlxContextLsGrid ); |
|
292 } |
|
293 |
|
294 void TestGlxMediaModel::setFocusIndexTestCase() |
|
295 { |
|
296 mModel->setFocusIndex( mModel->index( 1, 0 ) ); |
|
297 QModelIndex modelIndex = mModel->getFocusIndex(); |
|
298 QCOMPARE( mModel->mFocusIndex, 1 ); |
|
299 QCOMPARE( 1, modelIndex.row() ); |
|
300 |
|
301 int index = mModel->rowCount() - 1; |
|
302 mModel->setFocusIndex( mModel->index( index, 0 ) ); |
|
303 modelIndex = mModel->getFocusIndex(); |
|
304 QCOMPARE( mModel->mFocusIndex, modelIndex.row() ); |
|
305 QCOMPARE( index, modelIndex.row() ); |
|
306 |
|
307 index = mModel->rowCount(); |
|
308 mModel->setFocusIndex( mModel->index( index, 0 ) ); |
|
309 modelIndex = mModel->getFocusIndex(); |
|
310 QCOMPARE( mModel->mFocusIndex, modelIndex.row() ); |
|
311 QCOMPARE( 0, modelIndex.row() ); |
|
312 } |
|
313 |
|
314 void TestGlxMediaModel::getFocusIndexTestcase() |
|
315 { |
|
316 mModel->mFocusIndex = -1; |
|
317 mModel->setFocusIndex( mModel->index( 1, 0 ) ); |
|
318 QModelIndex index = mModel->getFocusIndex(); |
|
319 QCOMPARE( 1, index.row() ); |
|
320 |
|
321 mModel->mFocusIndex = 2; |
|
322 mModel->setFocusIndex( mModel->index( 1, 0 ) ); |
|
323 index = mModel->getFocusIndex(); |
|
324 QCOMPARE( 1, index.row() ); |
|
325 } |
|
326 |
|
327 void TestGlxMediaModel::setSelectedIndexTestCase() |
|
328 { |
|
329 mModel->setSelectedIndex( mModel->index( 1, 0 ) ); |
|
330 } |
|
331 |
|
332 void TestGlxMediaModel::getCorruptDefaultIconTestCase() |
|
333 { |
|
334 HbIcon *icon = mModel->getCorruptDefaultIcon( mModel->index( 0, 0 ) ); |
|
335 QVERIFY( icon ); |
|
336 } |
|
337 |
|
338 void TestGlxMediaModel::thumbnailPopulatedCheckTestCase() |
|
339 { |
|
340 mModel->thumbnailPopulatedFlag = false; |
|
341 mModel->thumbnailPopulatedCheck( 1 ); |
|
342 QCOMPARE( mModel->thumbnailPopulatedFlag, false ); |
|
343 |
|
344 mModel->thumbnailPopulatedCheck( 30 ); |
|
345 QCOMPARE( mModel->thumbnailPopulatedFlag, true ); |
|
346 } |
|
347 |
|
348 void TestGlxMediaModel::itemUpdatedTestCase() |
|
349 { |
|
350 mModel->itemUpdated( 0, GlxTBContextGrid ); |
|
351 QVERIFY( mModel->itemIconCache[0] == NULL ); |
|
352 |
|
353 mModel->thumbnailPopulatedFlag = false; |
|
354 mModel->itemUpdated( 0, GlxTBContextGrid ); |
|
355 QVERIFY( mModel->itemIconCache[0] == NULL ); |
|
356 |
|
357 mModel->itemUpdated( 0, GlxTBContextPtFs ); |
|
358 QVERIFY( mModel->itemFsIconCache[0] == NULL ); |
|
359 |
|
360 mModel->itemUpdated( 0, GlxTBContextPtFs ); |
|
361 QVERIFY( mModel->itemFsIconCache[0] == NULL ); |
|
362 } |
|
363 |
|
364 void TestGlxMediaModel::itemsAddedTestCase() |
|
365 { |
|
366 mModel->itemsAdded( 1, 5 ); |
|
367 QCOMPARE( mModel->mFocusIndex, -1 ); |
|
368 QCOMPARE( mModel->itemIconCache.size(), 0 ); |
|
369 QCOMPARE( mModel->itemFsIconCache.size(), 0 ); |
|
370 } |
|
371 |
|
372 void TestGlxMediaModel::itemsRemovedTestCase() |
|
373 { |
|
374 mModel->itemsRemoved( 1, 5 ); |
|
375 QCOMPARE( mModel->mFocusIndex, -1 ); |
|
376 QCOMPARE( mModel->itemIconCache.size(), 0 ); |
|
377 QCOMPARE( mModel->itemFsIconCache.size(), 0 ); |
|
378 } |
|
379 |
|
380 void TestGlxMediaModel::itemCorruptedTestCase() |
|
381 { |
|
382 mModel->thumbnailPopulatedFlag = false; |
|
383 mModel->itemCorrupted( 1 ); |
|
384 QCOMPARE( mModel->thumbnailPopulatedFlag, false ); |
|
385 |
|
386 mModel->itemCorrupted( 30 ); |
|
387 QCOMPARE( mModel->thumbnailPopulatedFlag, true ); |
|
388 } |
|
389 |
|
390 void TestGlxMediaModel::albumTitleUpdatedTestCase() |
|
391 { |
|
392 mModel->albumTitleUpdated( QString( "Album" ) ); |
|
393 } |
|
394 |
|
395 void TestGlxMediaModel::modelpopulatedTestCase() |
|
396 { |
|
397 int visualIndex = mModel->mMLWrapper->getVisibleWindowIndex(); |
|
398 mModel->mTempVisibleWindowIndex = -1; |
|
399 mModel->modelpopulated(); |
|
400 QCOMPARE( mModel->mTempVisibleWindowIndex, -1 ); |
|
401 QCOMPARE( visualIndex, mModel->mMLWrapper->getVisibleWindowIndex() ); |
|
402 |
|
403 mModel->mTempVisibleWindowIndex = mModel->rowCount() - 1; |
|
404 mModel->modelpopulated(); |
|
405 visualIndex = mModel->mMLWrapper->getVisibleWindowIndex(); |
|
406 QCOMPARE( mModel->mTempVisibleWindowIndex, -1 ); |
|
407 QCOMPARE( visualIndex, mModel->rowCount() - 1 ); |
|
408 |
|
409 mModel->mTempVisibleWindowIndex = mModel->rowCount(); |
|
410 mModel->modelpopulated(); |
|
411 visualIndex = mModel->mMLWrapper->getVisibleWindowIndex(); |
|
412 QCOMPARE( mModel->mTempVisibleWindowIndex, -1 ); |
|
413 QCOMPARE( visualIndex, 0 ); |
|
414 } |
|
415 |
|
416 void TestGlxMediaModel::updateDetailItemsTestCase() |
|
417 { |
|
418 mModel->updateDetailItems(); |
|
419 } |
|
420 |
|
421 void TestGlxMediaModel::updateItemIconTestCase() |
|
422 { |
|
423 mModel->updateItemIcon( 1, new HbIcon(), GlxTBContextGrid ); |
|
424 QVERIFY( mModel->itemIconCache[1] ); |
|
425 |
|
426 mModel->updateItemIcon( 1, new HbIcon(), GlxTBContextLsFs ); |
|
427 QVERIFY( mModel->itemFsIconCache[1] ); |
|
428 |
|
429 mModel->updateItemIcon( 1, new HbIcon(), GlxTBContextPtFs ); |
|
430 QVERIFY( mModel->itemFsIconCache[1] ); |
|
431 } |
|
432 |
|
433 |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // cleanup |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 void TestGlxMediaModel::cleanup() |
|
440 { |
|
441 |
|
442 } |
|
443 |
|
444 // ----------------------------------------------------------------------------- |
|
445 // cleanupTestCase |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void TestGlxMediaModel::cleanupTestCase() |
|
449 { |
|
450 if( mModel ) { |
|
451 delete mModel; |
|
452 mModel = 0; |
|
453 } |
|
454 } |
|
455 |
|
456 QTEST_MAIN(TestGlxMediaModel) |
|
457 #include "moc_unittest_mediamodel.cpp" |