|
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: tester for methods in VideoSortFilterProxyModel |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QModelIndex> |
|
19 #include <QModelIndexList> |
|
20 #include <hbapplication.h> |
|
21 |
|
22 #define private public |
|
23 #include "videosortfilterproxymodel.h" |
|
24 #undef private |
|
25 |
|
26 #include "videocollectionwrapper.h" |
|
27 #include "videocollectioncommon.h" |
|
28 #include "testvideosortfilterproxymodel.h" |
|
29 #include "videolistdatamodel.h" |
|
30 #include "videocollectionclient.h" |
|
31 #include "videocollectioncommon.h" |
|
32 #include "videothumbnaildata.h" |
|
33 #include "filterproxytester.h" |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // main |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 int main(int argc, char *argv[]) |
|
40 { |
|
41 HbApplication app(argc, argv); |
|
42 |
|
43 TestVideoSortFilterProxyModel tv; |
|
44 |
|
45 int res; |
|
46 if(argc > 1) |
|
47 { |
|
48 res = QTest::qExec(&tv, argc, argv); |
|
49 } |
|
50 else |
|
51 { |
|
52 char *pass[3]; |
|
53 pass[0] = argv[0]; |
|
54 pass[1] = "-o"; |
|
55 pass[2] = "c:\\data\\testvideosortfilterproxymodel.txt"; |
|
56 res = QTest::qExec(&tv, 3, pass); |
|
57 } |
|
58 |
|
59 return res; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // init |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void TestVideoSortFilterProxyModel::init() |
|
67 { |
|
68 qRegisterMetaType<TMPXItemId>("TMPXItemId"); |
|
69 |
|
70 VideoListDataModel::mInitFails = false; |
|
71 VideoListDataModel::mRemoveRowsFails = false; |
|
72 VideoListDataModel::mGetMediaIdAtIndexFails = false; |
|
73 VideoCollectionClient::mFailMediaPlayback = false; |
|
74 VideoCollectionClient::mFailMediaDetails = false; |
|
75 VideoCollectionClient::mFailInit = false; |
|
76 VideoCollectionClient::mFailAddNewCollection = false; |
|
77 VideoCollectionClient::mSortOrderSetCount = 0; |
|
78 VideoCollectionClient::mAddNewCollectionName = QString(); |
|
79 VideoCollectionClient::mAddNewCollectionThumb = QString(); |
|
80 VideoCollectionClient::mAddNewCollectionIds = QList<TMPXItemId>(); |
|
81 VideoThumbnailData::mStartBackgroundFetchingCallCount = 0; |
|
82 |
|
83 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeGeneric); |
|
84 QVERIFY(mTestObject); |
|
85 |
|
86 mStubModel = new VideoListDataModel(); |
|
87 QVERIFY(mStubModel); |
|
88 |
|
89 mCollectionClient = new VideoCollectionClient(); |
|
90 QVERIFY(mCollectionClient); |
|
91 |
|
92 mCollectionModel = new VideoSortFilterProxyModel(VideoCollectionCommon::EModelTypeAllVideos); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // cleanup |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void TestVideoSortFilterProxyModel::cleanup() |
|
100 { |
|
101 delete mCollectionClient; |
|
102 mCollectionClient = 0; |
|
103 |
|
104 delete mStubModel; |
|
105 mStubModel = 0; |
|
106 |
|
107 delete mTestObject; |
|
108 mTestObject = 0; |
|
109 |
|
110 delete mCollectionModel; |
|
111 mCollectionModel = 0; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // testInitialize |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void TestVideoSortFilterProxyModel::testInitialize() |
|
119 { |
|
120 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // testInitializeSignalConnectFail |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void TestVideoSortFilterProxyModel::testInitializeSignalConnectFail() |
|
128 { |
|
129 QVERIFY(mTestObject->initialize(NULL) == -1); |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // testSecondInitialize |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void TestVideoSortFilterProxyModel::testSecondInitialize() |
|
137 { |
|
138 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
139 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // testOpen |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void TestVideoSortFilterProxyModel::testOpen() |
|
147 { |
|
148 // no mCollectionClient |
|
149 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelInvalid) == -1); |
|
150 |
|
151 mTestObject->initialize(mStubModel); |
|
152 |
|
153 // First open. |
|
154 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
155 // Open again with same level. |
|
156 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
157 // Fail open. |
|
158 VideoCollectionClient::mFailStartOpen = true; |
|
159 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == -1); |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // testDeleteItems |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 void TestVideoSortFilterProxyModel::testDeleteItems() |
|
167 { |
|
168 VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount = 0; |
|
169 VideoCollectionClient::mFailStartOpen = false; |
|
170 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
171 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
172 QString name1 = "cc"; |
|
173 QString name2 = "bb"; |
|
174 QString name3 = "aa"; |
|
175 QString name4 = "11"; |
|
176 QString name5 = "12"; |
|
177 |
|
178 mStubModel->appendData(name1); // to source model index 0, proxy index after sort 4 |
|
179 mStubModel->appendData(name2); // to source model index 1, proxy index after sort 3 |
|
180 mStubModel->appendData(name3); // to source model index 2, proxy index after sort 2 |
|
181 mStubModel->appendData(name4); // to source model index 3, proxy index after sort 0 |
|
182 mStubModel->appendData(name5); // to source model index 4, proxy index after sort 1 |
|
183 |
|
184 // sort to make sure that list order is different compared to source model |
|
185 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::AscendingOrder); |
|
186 // need to wait for awhile to make sure zero-counter gets |
|
187 // processing time. |
|
188 QTest::qWait(500); |
|
189 QVERIFY(mTestObject->sortRole() == VideoCollectionCommon::KeyTitle); |
|
190 |
|
191 int count = mTestObject->rowCount(); |
|
192 QModelIndexList list; |
|
193 QModelIndex index; |
|
194 for(int i = 0; i < 5; ++i) |
|
195 { |
|
196 index = mTestObject->index(i,0); |
|
197 list.append(index); |
|
198 } |
|
199 QModelIndexList emptyList; |
|
200 VideoThumbnailData::mStartBackgroundFetchingCallCount = 0; |
|
201 QVERIFY(mTestObject->deleteItems(emptyList) == 0); |
|
202 QCOMPARE(VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount, 2); |
|
203 QVERIFY(VideoThumbnailData::mBackgroundThumbnailFetchingEnabled == true); |
|
204 QVERIFY(mTestObject->deleteItems(list) == 0); |
|
205 QCOMPARE(VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount, 4); |
|
206 QVERIFY(VideoThumbnailData::mBackgroundThumbnailFetchingEnabled == true); |
|
207 QVERIFY(mStubModel->mLastDeletedIndexRow == 0); |
|
208 QVERIFY(VideoThumbnailData::mStartBackgroundFetchingCallCount == 2); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // testDeleteItemsModelNull |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 void TestVideoSortFilterProxyModel::testDeleteItemsModelNull() |
|
216 { |
|
217 mStubModel->appendData("Test"); |
|
218 QVERIFY(mTestObject->initialize(NULL) == -1); |
|
219 |
|
220 QModelIndex index = mStubModel->index(0, 0); |
|
221 QModelIndexList list; |
|
222 list.append(index); |
|
223 |
|
224 QVERIFY(mTestObject->deleteItems(list) == -1); |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // testDeleteItemsRemoveRowsFail |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void TestVideoSortFilterProxyModel::testDeleteItemsRemoveRowsFail() |
|
232 { |
|
233 VideoListDataModel::mRemoveRowsFails = true; |
|
234 VideoCollectionClient::mFailStartOpen = false; |
|
235 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
236 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
237 |
|
238 mStubModel->appendData("Test"); |
|
239 |
|
240 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
241 |
|
242 QModelIndex index = mTestObject->index(0, 0); |
|
243 QModelIndexList list; |
|
244 list.append(index); |
|
245 |
|
246 QVERIFY(mTestObject->deleteItems(list) == -1); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // testOpenItemInvalidId |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void TestVideoSortFilterProxyModel::testOpenItemInvalidId() |
|
254 { |
|
255 VideoListDataModel::mGetMediaIdAtIndexFails = true; |
|
256 VideoCollectionClient::mFailStartOpen = false; |
|
257 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
258 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
259 |
|
260 mStubModel->appendData("Test"); |
|
261 |
|
262 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
263 QModelIndex index = mTestObject->index(0, 0); |
|
264 TMPXItemId itemId = TMPXItemId::InvalidId(); |
|
265 |
|
266 QVERIFY(mTestObject->openItem(itemId) == -1); |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // testOpenItemCollectionNull |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void TestVideoSortFilterProxyModel::testOpenItemCollectionNull() |
|
274 { |
|
275 mStubModel->appendData("Test"); |
|
276 |
|
277 TMPXItemId itemId(1,0); |
|
278 |
|
279 QVERIFY(mTestObject->openItem(itemId) == -1); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // testOpenItemOpenVideoFails |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void TestVideoSortFilterProxyModel::testOpenItemOpenVideoFails() |
|
287 { |
|
288 VideoCollectionClient::mFailMediaPlayback = true; |
|
289 |
|
290 mStubModel->appendData("Test"); |
|
291 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
292 TMPXItemId itemId(1,0); |
|
293 |
|
294 QVERIFY(mTestObject->openItem(itemId) == -1); |
|
295 |
|
296 VideoCollectionClient::mFailMediaPlayback = false; |
|
297 } |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // testOpenItem |
|
301 // --------------------------------------------------------------------------- |
|
302 // |
|
303 void TestVideoSortFilterProxyModel::testOpenItem() |
|
304 { |
|
305 mStubModel->appendData("Test"); |
|
306 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
307 TMPXItemId itemId(1,0); |
|
308 |
|
309 // open video |
|
310 QVERIFY(mTestObject->openItem(itemId) == 0); |
|
311 |
|
312 // open category or album |
|
313 itemId = TMPXItemId(1,2); |
|
314 QVERIFY(mTestObject->openItem(itemId) == 0); |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // testBack |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 void TestVideoSortFilterProxyModel::testBack() |
|
322 { |
|
323 QVERIFY(mTestObject->back() == -1); |
|
324 |
|
325 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
326 |
|
327 QVERIFY(mTestObject->back() == 0); |
|
328 |
|
329 mTestObject->open(VideoCollectionCommon::ELevelAlbum); |
|
330 QVERIFY(mTestObject->back() == 0); |
|
331 |
|
332 // back fails |
|
333 VideoCollectionClient::mBackReturnValue = -1; |
|
334 QVERIFY(mTestObject->back() == -1); |
|
335 |
|
336 VideoCollectionClient::mBackReturnValue = 0; |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // testFetchItemDetails |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 void TestVideoSortFilterProxyModel::testFetchItemDetails() |
|
344 { |
|
345 VideoCollectionClient::mFailStartOpen = false; |
|
346 mStubModel->appendData("Test"); |
|
347 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
348 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
349 QSignalSpy fetchSpy(mTestObject, SIGNAL(shortDetailsReady(TMPXItemId))); |
|
350 |
|
351 QModelIndex index = mTestObject->index(0, 0); |
|
352 |
|
353 QList<QVariant> arguments; |
|
354 QVERIFY(mTestObject->fetchItemDetails(index) == 0); |
|
355 |
|
356 QVERIFY(fetchSpy.count() == 1); |
|
357 arguments = fetchSpy.takeFirst(); |
|
358 QVERIFY(arguments.at(0).toInt() == 0); |
|
359 arguments.clear(); |
|
360 fetchSpy.clear(); |
|
361 |
|
362 // no collection client |
|
363 VideoCollectionClient *tmp = mTestObject->mCollectionClient; |
|
364 mTestObject->mCollectionClient = 0; |
|
365 QVERIFY(mTestObject->fetchItemDetails(index) == -1); |
|
366 mTestObject->mCollectionClient = tmp; |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // testFetchItemDetails |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void TestVideoSortFilterProxyModel::testFetchItemDetailsGetMediaIdFail() |
|
374 { |
|
375 VideoListDataModel::mGetMediaIdAtIndexFails = true; |
|
376 QSignalSpy fetchSpy(mTestObject, SIGNAL(shortDetailsReady(TMPXItemId))); |
|
377 mStubModel->appendData("Test"); |
|
378 QModelIndex index = mTestObject->index(0, 0); |
|
379 |
|
380 // no model |
|
381 QVERIFY(mTestObject->fetchItemDetails(index) == -1); |
|
382 |
|
383 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
384 |
|
385 QVERIFY(mTestObject->fetchItemDetails(index) == -1); |
|
386 |
|
387 QVERIFY(fetchSpy.count() == 0); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------------------------- |
|
391 // testFetchItemDetails |
|
392 // --------------------------------------------------------------------------- |
|
393 // |
|
394 void TestVideoSortFilterProxyModel::testFetchItemDetailsGetVideoDetailsFails() |
|
395 { |
|
396 VideoCollectionClient::mFailMediaDetails = true; |
|
397 |
|
398 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
399 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
400 mStubModel->appendData("Test"); |
|
401 |
|
402 QSignalSpy fetchSpy(mTestObject, SIGNAL(shortDetailsReady(TMPXItemId))); |
|
403 QModelIndex index = mTestObject->index(0, 0); |
|
404 |
|
405 QVERIFY(mTestObject->fetchItemDetails(index) == -1); |
|
406 |
|
407 QVERIFY(fetchSpy.count() == 0); |
|
408 } |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // testLessThanProxyModelNotInitialized |
|
412 // --------------------------------------------------------------------------- |
|
413 // |
|
414 void TestVideoSortFilterProxyModel::testLessThanNoModel() |
|
415 { |
|
416 // "normal" comparisation |
|
417 QString name1 = "cc"; |
|
418 QString name2 = "bb"; |
|
419 QString name3 = "aa"; |
|
420 QString name4 = "11"; |
|
421 QString name5 = "11"; |
|
422 |
|
423 mStubModel->appendData(name1); // to index 0, position 4 |
|
424 mStubModel->appendData(name2); // to index 1, position 3 |
|
425 mStubModel->appendData(name3); // to index 2, position 2 |
|
426 mStubModel->appendData(name4); // to index 3, position 0 or 1 |
|
427 mStubModel->appendData(name5); // to index 4, position 0 or 1 |
|
428 |
|
429 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
430 |
|
431 QModelIndex left = mStubModel->index(0,0); |
|
432 QModelIndex right = mStubModel->index(1,0); |
|
433 |
|
434 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
435 } |
|
436 // --------------------------------------------------------------------------- |
|
437 // testLessThanName |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 void TestVideoSortFilterProxyModel::testLessThanName() |
|
441 { |
|
442 VideoCollectionClient::mFailStartOpen = false; |
|
443 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
444 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
445 |
|
446 // "normal" comparisation |
|
447 QString name1 = "cc"; |
|
448 QString name2 = "bb"; |
|
449 QString name3 = "aa"; |
|
450 QString name4 = "11"; |
|
451 QString name5 = "11"; |
|
452 |
|
453 mStubModel->appendData(name1); // to index 0, position 4 |
|
454 mStubModel->appendData(name2); // to index 1, position 3 |
|
455 mStubModel->appendData(name3); // to index 2, position 2 |
|
456 mStubModel->appendData(name4); // to index 3, position 0 or 1 |
|
457 mStubModel->appendData(name5); // to index 4, position 0 or 1 |
|
458 |
|
459 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
460 |
|
461 QModelIndex left = mStubModel->index(0,0); |
|
462 QModelIndex right = mStubModel->index(1,0); |
|
463 |
|
464 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
465 |
|
466 left = mStubModel->index(1,0); |
|
467 right = mStubModel->index(2,0); |
|
468 |
|
469 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
470 |
|
471 left = mStubModel->index(2,0); |
|
472 right = mStubModel->index(3,0); |
|
473 |
|
474 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
475 |
|
476 left = mStubModel->index(3,0); |
|
477 right = mStubModel->index(4,0); |
|
478 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
479 |
|
480 left = mStubModel->index(4,0); |
|
481 right = mStubModel->index(0,0); |
|
482 |
|
483 QVERIFY(mTestObject->callLessThan(left, right)); |
|
484 |
|
485 // reset model |
|
486 mStubModel->removeAll();; |
|
487 |
|
488 // case sensitive check |
|
489 name1 = "cc"; |
|
490 name2 = "CC"; |
|
491 name3 = "cC"; |
|
492 name4 = "aa"; |
|
493 name5 = "Aa"; |
|
494 QString name6 = "2Aa"; |
|
495 QString name7 = "1Aa"; |
|
496 QString name8 = "1cc"; |
|
497 mStubModel->removeAll(); |
|
498 mStubModel->appendData(name1); // to index 0, position can be 5, 6 or 7 |
|
499 mStubModel->appendData(name2); // to index 1, position can be 5, 6 or 7 |
|
500 mStubModel->appendData(name3); // to index 2, position can be 5, 6 or 7 |
|
501 mStubModel->appendData(name4); // to index 3, position can be 3 or 4 |
|
502 mStubModel->appendData(name5); // to index 4, position can be 3 or 4 |
|
503 mStubModel->appendData(name6); // to index 5, position is 2 |
|
504 mStubModel->appendData(name7); // to index 6, position is 0 |
|
505 mStubModel->appendData(name8); // to index 7, position is 1 |
|
506 |
|
507 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
508 |
|
509 left = mStubModel->index(0,0); // "cc" |
|
510 right = mStubModel->index(1,0); // "CC" |
|
511 |
|
512 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
513 |
|
514 left = mStubModel->index(1,0); // "CC" |
|
515 right = mStubModel->index(2,0); // "cC" |
|
516 |
|
517 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
518 |
|
519 left = mStubModel->index(2,0); // "cC" |
|
520 right = mStubModel->index(3,0); // "aa" |
|
521 |
|
522 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
523 |
|
524 left = mStubModel->index(3,0); // "aa" |
|
525 right = mStubModel->index(2,0); // "cC" |
|
526 |
|
527 QVERIFY(mTestObject->callLessThan(left, right)); |
|
528 |
|
529 left = mStubModel->index(3,0); // "aa" |
|
530 right = mStubModel->index(4,0); // "Aa" |
|
531 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
532 |
|
533 left = mStubModel->index(4,0); // "Aa" |
|
534 right = mStubModel->index(5,0); // "2Aa" |
|
535 |
|
536 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
537 |
|
538 left = mStubModel->index(5,0); // "2Aa" |
|
539 right = mStubModel->index(6,0); // "1Aa" |
|
540 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
541 |
|
542 left = mStubModel->index(6,0); // "1Aa" |
|
543 right = mStubModel->index(7,0); // "1cc" |
|
544 QVERIFY(mTestObject->callLessThan(left, right)); |
|
545 |
|
546 left = mStubModel->index(5,0); // "2Aa" |
|
547 right = mStubModel->index(7,0); // "1cc" |
|
548 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
549 |
|
550 left = mStubModel->index(7,0); // "1cc" |
|
551 right = mStubModel->index(0,0); // "cc" |
|
552 QVERIFY(mTestObject->callLessThan(left, right)); |
|
553 } |
|
554 |
|
555 // --------------------------------------------------------------------------- |
|
556 // testLessThanSize |
|
557 // --------------------------------------------------------------------------- |
|
558 // |
|
559 void TestVideoSortFilterProxyModel::testLessThanSize() |
|
560 { |
|
561 VideoCollectionClient::mFailStartOpen = false; |
|
562 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
563 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
564 |
|
565 quint32 size1 = 300; |
|
566 quint32 size2 = 200; |
|
567 quint32 size3 = 100; |
|
568 quint32 size4 = 99; |
|
569 quint32 size5 = 99; |
|
570 |
|
571 mStubModel->appendData(size1); // to index 0 |
|
572 mStubModel->appendData(size2); // to index 1 |
|
573 mStubModel->appendData(size3); // to index 2 |
|
574 mStubModel->appendData(size4); // to index 3 |
|
575 mStubModel->appendData(size5); // to index 4 |
|
576 |
|
577 mTestObject->setSortRole(VideoCollectionCommon::KeySizeValue); |
|
578 |
|
579 QModelIndex left = mStubModel->index(0,0); |
|
580 QModelIndex right = mStubModel->index(1,0); |
|
581 |
|
582 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
583 |
|
584 left = mStubModel->index(1,0); |
|
585 right = mStubModel->index(2,0); |
|
586 |
|
587 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
588 |
|
589 left = mStubModel->index(2,0); |
|
590 right = mStubModel->index(3,0); |
|
591 |
|
592 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
593 |
|
594 left = mStubModel->index(3,0); |
|
595 right = mStubModel->index(4,0); |
|
596 |
|
597 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
598 |
|
599 left = mStubModel->index(4,0); |
|
600 right = mStubModel->index(0,0); |
|
601 |
|
602 QVERIFY(mTestObject->callLessThan(left, right)); |
|
603 } |
|
604 |
|
605 // --------------------------------------------------------------------------- |
|
606 // testLessThanDate |
|
607 // --------------------------------------------------------------------------- |
|
608 // |
|
609 void TestVideoSortFilterProxyModel::testLessThanDateTime() |
|
610 { |
|
611 VideoCollectionClient::mFailStartOpen = false; |
|
612 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
613 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
614 |
|
615 QDateTime date1(QDate(2010, 11, 5), QTime(0,0)); |
|
616 QDateTime date2(QDate(2009, 9, 5), QTime(0,0)); |
|
617 QDateTime date3(QDate(2009, 9, 4), QTime(0,0)); |
|
618 QDateTime date4(QDate(2008, 9, 6), QTime(0,0)); |
|
619 QDateTime date5(QDate(2008, 9, 6), QTime(0,0)); |
|
620 |
|
621 mStubModel->appendData(date1); // to index 0 |
|
622 mStubModel->appendData(date2); // to index 1 |
|
623 mStubModel->appendData(date3); // to index 2 |
|
624 mStubModel->appendData(date4); // to index 3 |
|
625 mStubModel->appendData(date5); // to index 4 |
|
626 |
|
627 mTestObject->setSortRole(VideoCollectionCommon::KeyDateTime); |
|
628 |
|
629 QModelIndex left = mStubModel->index(0,0); |
|
630 QModelIndex right = mStubModel->index(1,0); |
|
631 |
|
632 QVERIFY(mTestObject->callLessThan(left, right)); |
|
633 |
|
634 left = mStubModel->index(1,0); |
|
635 right = mStubModel->index(2,0); |
|
636 |
|
637 QVERIFY(mTestObject->callLessThan(left, right)); |
|
638 |
|
639 left = mStubModel->index(2,0); |
|
640 right = mStubModel->index(3,0); |
|
641 |
|
642 QVERIFY(mTestObject->callLessThan(left, right)); |
|
643 |
|
644 left = mStubModel->index(3,0); |
|
645 right = mStubModel->index(4,0); |
|
646 |
|
647 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
648 |
|
649 left = mStubModel->index(4,0); |
|
650 right = mStubModel->index(0,0); |
|
651 |
|
652 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
|
656 // testLessThanDefaults |
|
657 // --------------------------------------------------------------------------- |
|
658 // |
|
659 void TestVideoSortFilterProxyModel::testLessThanDefaults() |
|
660 { |
|
661 VideoCollectionClient::mFailStartOpen = false; |
|
662 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
663 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelCategory) == 0); |
|
664 |
|
665 // Default categories (KVcxMvcMediaTypeCategory) |
|
666 // are always first in the following order: |
|
667 // Recently played (missing currently |
|
668 // Captured (KVcxMvcCategoryIdCaptured) |
|
669 // Downloaded (KVcxMvcCategoryIdDownloads) |
|
670 // Podcasts (missing currently) |
|
671 mStubModel->appendData(TMPXItemId(20, KVcxMvcMediaTypeAlbum)); // to source index 0 |
|
672 mStubModel->appendData(TMPXItemId(KVcxMvcCategoryIdDownloads, KVcxMvcMediaTypeCategory)); // to source index 1 |
|
673 mStubModel->appendData(TMPXItemId(KVcxMvcCategoryIdCaptured, KVcxMvcMediaTypeCategory)); // to source index 2 |
|
674 mStubModel->appendData(TMPXItemId(100, KVcxMvcMediaTypeCategory)); // to source index 3 |
|
675 mStubModel->appendData(TMPXItemId(101, KVcxMvcMediaTypeCategory)); // to source index 4 |
|
676 |
|
677 // left & right are KVcxMvcMediaTypeCategory |
|
678 // -> left == KVcxMvcCategoryIdCaptured |
|
679 QModelIndex left = mStubModel->index(2,0); |
|
680 QModelIndex right = mStubModel->index(1,0); |
|
681 // call doSorting to setup sorting order |
|
682 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
683 QVERIFY(mTestObject->callLessThan(left, right)); |
|
684 // call doSorting to setup sorting order |
|
685 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
686 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
687 |
|
688 // -> left == KVcxMvcCategoryIdDownloads |
|
689 left = mStubModel->index(1,0); |
|
690 // -> right == KVcxMvcCategoryIdCaptured |
|
691 right = mStubModel->index(2,0); |
|
692 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
693 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
694 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
695 QVERIFY(mTestObject->callLessThan(left, right)); |
|
696 |
|
697 // -> right != KVcxMvcCategoryIdCaptured |
|
698 right = mStubModel->index(3,0); |
|
699 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
700 QVERIFY(mTestObject->callLessThan(left, right)); |
|
701 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
702 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
703 |
|
704 // both are KVcxMvcMediaTypeCategory but netiher KVcxMvcCategoryIdCaptured |
|
705 // nor KVcxMvcCategoryIdDownloads |
|
706 left = mStubModel->index(3,0); |
|
707 right = mStubModel->index(4,0); |
|
708 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
709 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
710 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
711 QVERIFY(mTestObject->callLessThan(left, right)); |
|
712 |
|
713 // Left is KVcxMvcMediaTypeCategory and right is not |
|
714 left = mStubModel->index(1,0); |
|
715 right = mStubModel->index(0,0); |
|
716 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
717 QVERIFY(mTestObject->callLessThan(left, right)); |
|
718 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
719 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
720 |
|
721 // right is KVcxMvcMediaTypeCategory and left is not |
|
722 left = mStubModel->index(0,0); |
|
723 right = mStubModel->index(1,0); |
|
724 mTestObject->mWantedSortOrder = Qt::AscendingOrder; |
|
725 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
726 mTestObject->mWantedSortOrder = Qt::DescendingOrder; |
|
727 QVERIFY(mTestObject->callLessThan(left, right)); |
|
728 } |
|
729 |
|
730 // --------------------------------------------------------------------------- |
|
731 // testLessThanInvalid |
|
732 // --------------------------------------------------------------------------- |
|
733 // |
|
734 void TestVideoSortFilterProxyModel::testLessThanInvalid() |
|
735 { |
|
736 VideoCollectionClient::mFailStartOpen = false; |
|
737 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
738 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
739 |
|
740 // invalid role |
|
741 mTestObject->setSortRole(10000); |
|
742 |
|
743 QModelIndex left = mStubModel->index(0,0); |
|
744 QModelIndex right = mStubModel->index(0,0); |
|
745 |
|
746 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
747 |
|
748 // invalid role but valid data. |
|
749 |
|
750 QString name1 = "cc"; |
|
751 QString name2 = "bb"; |
|
752 QString name3 = "aa"; |
|
753 |
|
754 mStubModel->appendData(name1); // to index 0, position 4 |
|
755 mStubModel->appendData(name2); // to index 1, position 3 |
|
756 mStubModel->appendData(name3); // to index 2, position 2 |
|
757 |
|
758 mTestObject->setSortRole(INVALID_ROLE_FOR_SORTING); |
|
759 |
|
760 left = mStubModel->index(0,0); |
|
761 right = mStubModel->index(1,0); |
|
762 |
|
763 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
764 |
|
765 // invalid left index |
|
766 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
767 |
|
768 left = QModelIndex(); |
|
769 right = mStubModel->index(0,0); |
|
770 |
|
771 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
772 |
|
773 // invalid right index |
|
774 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
775 User::Heap().__DbgMarkStart(); |
|
776 left = mStubModel->index(0,0); |
|
777 right = QModelIndex(); |
|
778 |
|
779 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
780 |
|
781 // both invalid |
|
782 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
783 User::Heap().__DbgMarkStart(); |
|
784 left = QModelIndex(); |
|
785 right = QModelIndex(); |
|
786 |
|
787 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
788 |
|
789 // both same index, use size |
|
790 quint32 size1 = 99; |
|
791 |
|
792 mStubModel->appendData(size1); // to index 0 |
|
793 |
|
794 mTestObject->setSortRole(VideoCollectionCommon::KeySizeValue); |
|
795 mTestObject->setSortRole(VideoCollectionCommon::KeyTitle); |
|
796 |
|
797 left = mStubModel->index(0,0); |
|
798 right = mStubModel->index(0,0); |
|
799 QVERIFY(!mTestObject->callLessThan(left, right)); |
|
800 } |
|
801 |
|
802 // --------------------------------------------------------------------------- |
|
803 // testDoSorting |
|
804 // --------------------------------------------------------------------------- |
|
805 // |
|
806 void TestVideoSortFilterProxyModel::testDoSorting() |
|
807 { |
|
808 VideoCollectionClient::mFailStartOpen = false; |
|
809 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
810 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
811 |
|
812 // these signals are emitted during sorting procedure from the fw |
|
813 QSignalSpy spyAboutToChange(mTestObject, SIGNAL(layoutAboutToBeChanged())); |
|
814 QSignalSpy spyChanged(mTestObject, SIGNAL(layoutChanged())); |
|
815 QSignalSpy spySorted(mTestObject, SIGNAL(modelSorted())); |
|
816 |
|
817 QString name1 = "cc"; |
|
818 QString name2 = "bb"; |
|
819 QString name3 = "aa"; |
|
820 QString name4 = "11"; |
|
821 QString name5 = "11"; |
|
822 QDateTime date1(QDate(2010, 11, 5), QTime(0,0)); |
|
823 QDateTime date2(QDate(2009, 9, 5), QTime(0,0)); |
|
824 QDateTime date3(QDate(2009, 9, 4), QTime(0,0)); |
|
825 QDateTime date4(QDate(2008, 9, 6), QTime(0,0)); |
|
826 QDateTime date5(QDate(2008, 9, 6), QTime(0,0)); |
|
827 quint32 size1 = 300; |
|
828 quint32 size2 = 200; |
|
829 quint32 size3 = 100; |
|
830 quint32 size4 = 99; |
|
831 quint32 size5 = 99; |
|
832 |
|
833 mStubModel->appendData(name1); // to index 0, position 4 |
|
834 mStubModel->appendData(name2); // to index 1, position 3 |
|
835 mStubModel->appendData(name3); // to index 2, position 2 |
|
836 mStubModel->appendData(name4); // to index 3, position 0 or 1 |
|
837 mStubModel->appendData(name5); // to index 4, position 0 or 1 |
|
838 |
|
839 mStubModel->appendData(date1); // to index 0 |
|
840 mStubModel->appendData(date2); // to index 1 |
|
841 mStubModel->appendData(date3); // to index 2 |
|
842 mStubModel->appendData(date4); // to index 3 |
|
843 mStubModel->appendData(date5); // to index 4 |
|
844 |
|
845 mStubModel->appendData(size1); // to index 0 |
|
846 mStubModel->appendData(size2); // to index 1 |
|
847 mStubModel->appendData(size3); // to index 2 |
|
848 mStubModel->appendData(size4); // to index 3 |
|
849 mStubModel->appendData(size5); // to index 4 |
|
850 |
|
851 int sortingRole; |
|
852 Qt::SortOrder sortingOrder; |
|
853 |
|
854 // first sort call, includes timer creation and setup |
|
855 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::AscendingOrder); |
|
856 // need to wait for awhile to make sure zero-counter gets |
|
857 // processing time. |
|
858 QTest::qWait(500); |
|
859 QCOMPARE(spyAboutToChange.count(), 1); |
|
860 QCOMPARE(spyChanged.count(), 1); |
|
861 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
862 QCOMPARE(mTestObject->sortOrder(), Qt::AscendingOrder); |
|
863 QCOMPARE(spySorted.count(), 1); |
|
864 mTestObject->getSorting(sortingRole, sortingOrder); |
|
865 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
866 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
867 |
|
868 // reset spys |
|
869 spyAboutToChange.clear(); |
|
870 spyChanged.clear(); |
|
871 spySorted.clear(); |
|
872 |
|
873 // second sort call, should use same timer appropriately |
|
874 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::DescendingOrder); |
|
875 QTest::qWait(500); |
|
876 QCOMPARE(spyAboutToChange.count(), 1); |
|
877 QCOMPARE(spyChanged.count(), 1); |
|
878 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
879 QCOMPARE(mTestObject->sortOrder(), Qt::DescendingOrder); |
|
880 QCOMPARE(spySorted.count(), 1); |
|
881 mTestObject->getSorting(sortingRole, sortingOrder); |
|
882 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
883 QCOMPARE(sortingOrder, Qt::DescendingOrder); |
|
884 |
|
885 // reset spys |
|
886 spyAboutToChange.clear(); |
|
887 spyChanged.clear(); |
|
888 spySorted.clear(); |
|
889 |
|
890 // double call without first letting timer to timeout |
|
891 VideoThumbnailData::mStartBackgroundFetchingCallCount = 0; |
|
892 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::DescendingOrder); |
|
893 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::AscendingOrder); |
|
894 QTest::qWait(500); |
|
895 QCOMPARE(spyAboutToChange.count(), 1); |
|
896 QCOMPARE(spyChanged.count(), 1); |
|
897 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
898 QCOMPARE(mTestObject->sortOrder(), Qt::AscendingOrder); |
|
899 QCOMPARE(spySorted.count(), 1); |
|
900 mTestObject->getSorting(sortingRole, sortingOrder); |
|
901 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
902 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
903 |
|
904 spyAboutToChange.clear(); |
|
905 spyChanged.clear(); |
|
906 spySorted.clear(); |
|
907 |
|
908 // syncronous call checks |
|
909 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::DescendingOrder, false); |
|
910 QCOMPARE(spyAboutToChange.count(), 1); |
|
911 QCOMPARE(spyChanged.count(), 1); |
|
912 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
913 QCOMPARE(mTestObject->sortOrder(), Qt::DescendingOrder); |
|
914 QCOMPARE(spySorted.count(), 1); |
|
915 mTestObject->getSorting(sortingRole, sortingOrder); |
|
916 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
917 QCOMPARE(sortingOrder, Qt::DescendingOrder); |
|
918 |
|
919 spyAboutToChange.clear(); |
|
920 spyChanged.clear(); |
|
921 spySorted.clear(); |
|
922 |
|
923 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::AscendingOrder, false); |
|
924 QCOMPARE(spyAboutToChange.count(), 1); |
|
925 QCOMPARE(spyChanged.count(), 1); |
|
926 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
927 QCOMPARE(mTestObject->sortOrder(), Qt::AscendingOrder); |
|
928 QCOMPARE(spySorted.count(), 1); |
|
929 mTestObject->getSorting(sortingRole, sortingOrder); |
|
930 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
931 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
932 |
|
933 spyAboutToChange.clear(); |
|
934 spyChanged.clear(); |
|
935 spySorted.clear(); |
|
936 |
|
937 // check that layout signals are not send if the sorting values don't change. |
|
938 mTestObject->doSorting(VideoCollectionCommon::KeyTitle, Qt::AscendingOrder); |
|
939 QCOMPARE(spyAboutToChange.count(), 0); |
|
940 QCOMPARE(spyChanged.count(), 0); |
|
941 QCOMPARE(spySorted.count(), 0); |
|
942 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
943 QCOMPARE(mTestObject->sortOrder(), Qt::AscendingOrder); |
|
944 mTestObject->getSorting(sortingRole, sortingOrder); |
|
945 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyTitle); |
|
946 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
947 |
|
948 spyAboutToChange.clear(); |
|
949 spyChanged.clear(); |
|
950 spySorted.clear(); |
|
951 |
|
952 // date role check |
|
953 mTestObject->doSorting(VideoCollectionCommon::KeyDateTime, Qt::AscendingOrder); |
|
954 QTest::qWait(500); |
|
955 int count = spyAboutToChange.count(); |
|
956 QCOMPARE(spyAboutToChange.count(), 1); |
|
957 QCOMPARE(spyChanged.count(), 1); |
|
958 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyDateTime); |
|
959 QCOMPARE(spySorted.count(), 1); |
|
960 mTestObject->getSorting(sortingRole, sortingOrder); |
|
961 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyDateTime); |
|
962 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
963 |
|
964 spyAboutToChange.clear(); |
|
965 spyChanged.clear(); |
|
966 spySorted.clear(); |
|
967 |
|
968 // size role check |
|
969 mTestObject->doSorting(VideoCollectionCommon::KeySizeValue, Qt::AscendingOrder); |
|
970 QTest::qWait(500); |
|
971 QCOMPARE(spyAboutToChange.count(), 1); |
|
972 QCOMPARE(spyChanged.count(), 1); |
|
973 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeySizeValue); |
|
974 QCOMPARE(spySorted.count(), 1); |
|
975 mTestObject->getSorting(sortingRole, sortingOrder); |
|
976 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeySizeValue); |
|
977 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
978 |
|
979 spyAboutToChange.clear(); |
|
980 spyChanged.clear(); |
|
981 spySorted.clear(); |
|
982 |
|
983 // number of items role check |
|
984 mTestObject->doSorting(VideoCollectionCommon::KeyNumberOfItems, Qt::AscendingOrder); |
|
985 QTest::qWait(500); |
|
986 QCOMPARE(spyAboutToChange.count(), 1); |
|
987 QCOMPARE(spyChanged.count(), 1); |
|
988 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyNumberOfItems); |
|
989 QCOMPARE(spySorted.count(), 1); |
|
990 mTestObject->getSorting(sortingRole, sortingOrder); |
|
991 QCOMPARE(sortingRole, (int)VideoCollectionCommon::KeyNumberOfItems); |
|
992 QCOMPARE(sortingOrder, Qt::AscendingOrder); |
|
993 |
|
994 spyAboutToChange.clear(); |
|
995 spyChanged.clear(); |
|
996 spySorted.clear(); |
|
997 |
|
998 // invalid role call, sorting should be set to date |
|
999 mTestObject->mType = VideoCollectionCommon::EModelTypeAllVideos; |
|
1000 mTestObject->doSorting(VideoCollectionCommon::KeyTitle - 100, Qt::AscendingOrder); |
|
1001 QTest::qWait(500); |
|
1002 QCOMPARE(spyAboutToChange.count(), 1); |
|
1003 QCOMPARE(spyChanged.count(), 1); |
|
1004 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyDateTime); |
|
1005 QCOMPARE(spySorted.count(), 1); |
|
1006 |
|
1007 spyAboutToChange.clear(); |
|
1008 spyChanged.clear(); |
|
1009 spySorted.clear(); |
|
1010 |
|
1011 // invalid role call, model type is categories, sorting should be set to VideoCollectionCommon::KeyTitle |
|
1012 mTestObject->mType = VideoCollectionCommon::EModelTypeCollections; |
|
1013 mTestObject->doSorting(VideoCollectionCommon::KeyTitle - 100, Qt::AscendingOrder); |
|
1014 QTest::qWait(500); |
|
1015 QCOMPARE(spyAboutToChange.count(), 1); |
|
1016 QCOMPARE(spyChanged.count(), 1); |
|
1017 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyTitle); |
|
1018 QCOMPARE(spySorted.count(), 1); |
|
1019 |
|
1020 spyAboutToChange.clear(); |
|
1021 spyChanged.clear(); |
|
1022 spySorted.clear(); |
|
1023 |
|
1024 // sync sorting call for non -changing sort order (for coverity) |
|
1025 mTestObject->mType = VideoCollectionCommon::EModelTypeAllVideos; |
|
1026 mTestObject->mIdleSortTimer = 0; |
|
1027 mTestObject->doSorting(VideoCollectionCommon::KeyTitle - 100, Qt::AscendingOrder, false); |
|
1028 spyAboutToChange.clear(); |
|
1029 spyChanged.clear(); |
|
1030 mTestObject->doSorting(VideoCollectionCommon::KeyTitle - 100, Qt::AscendingOrder, false); |
|
1031 QCOMPARE(spyAboutToChange.count(), 0); |
|
1032 QCOMPARE(spyChanged.count(), 0); |
|
1033 QCOMPARE(mTestObject->sortRole(), (int)VideoCollectionCommon::KeyDateTime); |
|
1034 spyAboutToChange.clear(); |
|
1035 spyChanged.clear(); |
|
1036 QCOMPARE(spySorted.count(), 2); |
|
1037 } |
|
1038 |
|
1039 // --------------------------------------------------------------------------- |
|
1040 // testFilterAcceptsRow |
|
1041 // --------------------------------------------------------------------------- |
|
1042 // |
|
1043 void TestVideoSortFilterProxyModel::testFilterAcceptsRowVideos() |
|
1044 { |
|
1045 // source_parent can be anything, test model doesn't use it. |
|
1046 QModelIndex source_parent = QModelIndex(); |
|
1047 |
|
1048 // Not initialized: no rouce model |
|
1049 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1050 |
|
1051 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
1052 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
1053 mTestObject->mType = VideoCollectionCommon::EModelTypeAllVideos; |
|
1054 |
|
1055 // Test invalid row: below 0 |
|
1056 QVERIFY(mTestObject->callFilterAcceptsRow(-1, source_parent) == false); |
|
1057 |
|
1058 // invalid row: larger than count |
|
1059 mStubModel->appendData("test"); |
|
1060 QVERIFY(mTestObject->callFilterAcceptsRow(2, source_parent) == false); |
|
1061 |
|
1062 // correct row |
|
1063 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1064 |
|
1065 // correct row, but id not corresponds video |
|
1066 mStubModel->removeAll(); |
|
1067 mStubModel->appendData(TMPXItemId(1, KVcxMvcMediaTypeCategory)); |
|
1068 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1069 |
|
1070 } |
|
1071 |
|
1072 // --------------------------------------------------------------------------- |
|
1073 // testFilterAcceptsNoVideoTypes |
|
1074 // --------------------------------------------------------------------------- |
|
1075 // |
|
1076 void TestVideoSortFilterProxyModel::testFilterAcceptsNoVideoTypes() |
|
1077 { |
|
1078 // source_parent can be anything, test model doesn't use it. |
|
1079 QModelIndex source_parent = QModelIndex(); |
|
1080 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
1081 |
|
1082 // only one item at ondex 0 |
|
1083 mStubModel->appendData(TMPXItemId(1, KVcxMvcMediaTypeVideo)); |
|
1084 |
|
1085 // model type == VideoCollectionWrapper::ECollections |
|
1086 mTestObject->mType = VideoCollectionCommon::EModelTypeCollections; |
|
1087 // mLevel == VideoCollectionCommon::ELevelCategory, id.iId1 == KVcxMvcMediaTypeVideo |
|
1088 mTestObject->mLevel = VideoCollectionCommon::ELevelCategory; |
|
1089 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1090 // mLevel != VideoCollectionCommon::ELevelCategory |
|
1091 mTestObject->mLevel = VideoCollectionCommon::ELevelAlbum; |
|
1092 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1093 |
|
1094 // model type == VideoCollectionWrapper::ECollectionContent |
|
1095 mTestObject->mType = VideoCollectionCommon::EModelTypeCollectionContent; |
|
1096 // item belongs to album |
|
1097 VideoListDataModel::mBelongsToAlbum = true; |
|
1098 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1099 // item does not belong to album |
|
1100 VideoListDataModel::mBelongsToAlbum = false; |
|
1101 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1102 |
|
1103 // model type == VideoCollectionWrapper::EGeneric |
|
1104 mTestObject->mType = VideoCollectionCommon::EModelTypeGeneric; |
|
1105 mTestObject->mGenericFilterValue = true; |
|
1106 |
|
1107 // mLevel != VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo |
|
1108 mTestObject->mLevel = VideoCollectionCommon::ELevelAlbum; |
|
1109 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1110 |
|
1111 // mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 != KVcxMvcMediaTypeVideo |
|
1112 mTestObject->mLevel = VideoCollectionCommon::ELevelVideos; |
|
1113 mStubModel->removeAll(); |
|
1114 mStubModel->appendData(TMPXItemId(1, KVcxMvcMediaTypeCategory)); |
|
1115 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1116 |
|
1117 // mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo |
|
1118 mStubModel->removeAll(); |
|
1119 mStubModel->appendData(TMPXItemId(1, KVcxMvcMediaTypeVideo)); |
|
1120 // generic filter id == TMPXItemId::InvalidId() |
|
1121 mTestObject->mGenericFilterId = TMPXItemId::InvalidId(); |
|
1122 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1123 |
|
1124 // generic filter id == (KVcxMvcCategoryIdAll, KVcxMvcMediaTypeCategory) |
|
1125 mTestObject->mGenericFilterId = TMPXItemId(KVcxMvcCategoryIdAll, KVcxMvcMediaTypeCategory); |
|
1126 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1127 |
|
1128 // generic filter id == (100, KVcxMvcMediaTypeCategory) |
|
1129 mTestObject->mGenericFilterId = TMPXItemId(100, KVcxMvcMediaTypeCategory); |
|
1130 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1131 |
|
1132 // generic filter id == (KVcxMvcCategoryIdAll, KVcxMvcMediaTypeVideo) |
|
1133 mTestObject->mGenericFilterId = TMPXItemId(KVcxMvcCategoryIdAll, KVcxMvcMediaTypeVideo); |
|
1134 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == false); |
|
1135 |
|
1136 // generic filter id == (100, KVcxMvcMediaTypeCategory) |
|
1137 VideoListDataModel::mBelongsToAlbum = true; |
|
1138 mTestObject->mGenericFilterId = TMPXItemId(100, KVcxMvcMediaTypeCategory); |
|
1139 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1140 |
|
1141 // generic filter id == (KVcxMvcCategoryIdAll, KVcxMvcMediaTypeVideo) |
|
1142 VideoListDataModel::mBelongsToAlbum = true; |
|
1143 mTestObject->mGenericFilterId = TMPXItemId(KVcxMvcCategoryIdAll, KVcxMvcMediaTypeVideo); |
|
1144 QVERIFY(mTestObject->callFilterAcceptsRow(0, source_parent) == true); |
|
1145 } |
|
1146 |
|
1147 // --------------------------------------------------------------------------- |
|
1148 // testGetMediaFilePathForId |
|
1149 // --------------------------------------------------------------------------- |
|
1150 // |
|
1151 void TestVideoSortFilterProxyModel::testGetMediaFilePathForId() |
|
1152 { |
|
1153 // Not initialized. |
|
1154 VideoListDataModel::mMediaFilePathReturnValue = "testfile"; |
|
1155 QVERIFY(mTestObject->getMediaFilePathForId(TMPXItemId(0,0)) == ""); |
|
1156 |
|
1157 // Ok case. |
|
1158 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
1159 VideoListDataModel::mMediaFilePathReturnValue = "testfile"; |
|
1160 QVERIFY(mTestObject->getMediaFilePathForId(TMPXItemId(0,0)) == "testfile"); |
|
1161 } |
|
1162 |
|
1163 // --------------------------------------------------------------------------- |
|
1164 // testAddNewCollectionNoCollectionClient |
|
1165 // --------------------------------------------------------------------------- |
|
1166 // |
|
1167 void TestVideoSortFilterProxyModel::testAddNewCollectionNoCollectionClient() |
|
1168 { |
|
1169 QString name("testname"); |
|
1170 VideoCollectionClient::mNewAlbumId = TMPXItemId(1,1); |
|
1171 QVERIFY(mTestObject->addNewAlbum(name) == TMPXItemId::InvalidId()); |
|
1172 QVERIFY(VideoCollectionClient::mAddNewCollectionName != name); |
|
1173 } |
|
1174 |
|
1175 // --------------------------------------------------------------------------- |
|
1176 // testAddNewCollectionSucceed |
|
1177 // --------------------------------------------------------------------------- |
|
1178 // |
|
1179 void TestVideoSortFilterProxyModel::testAddNewCollectionSucceed() |
|
1180 { |
|
1181 QString name("testname"); |
|
1182 |
|
1183 mTestObject->initialize(mStubModel); |
|
1184 VideoCollectionClient::mNewAlbumId = TMPXItemId(1,1); |
|
1185 QVERIFY(mTestObject->addNewAlbum(name) == TMPXItemId(1,1)); |
|
1186 QCOMPARE(VideoCollectionClient::mAddNewCollectionName, name); |
|
1187 } |
|
1188 |
|
1189 // --------------------------------------------------------------------------- |
|
1190 // testResolveAlbumName |
|
1191 // --------------------------------------------------------------------------- |
|
1192 // |
|
1193 void TestVideoSortFilterProxyModel::testResolveAlbumName() |
|
1194 { |
|
1195 mCollectionModel->mType = VideoCollectionCommon::EModelTypeCollections; |
|
1196 |
|
1197 QString name("test"); |
|
1198 QString resolved(""); |
|
1199 // no model, same name can be used |
|
1200 resolved = mTestObject->resolveAlbumName(name); |
|
1201 QVERIFY(resolved.length()); |
|
1202 QVERIFY(resolved == name); |
|
1203 |
|
1204 mTestObject->initialize(mStubModel); |
|
1205 |
|
1206 // no collections proxy model, same name |
|
1207 resolved = mTestObject->resolveAlbumName(name); |
|
1208 QVERIFY(resolved.length()); |
|
1209 QVERIFY(resolved == name); |
|
1210 |
|
1211 mCollectionModel->initialize(mStubModel); |
|
1212 mCollectionModel->open(VideoCollectionCommon::ELevelCategory); |
|
1213 VideoCollectionWrapper::instance().mProxyModel = mCollectionModel; |
|
1214 |
|
1215 // collections proxy model exists, no source model |
|
1216 VideoListDataModel *temp = mTestObject->mModel; |
|
1217 mTestObject->mModel = 0; |
|
1218 |
|
1219 resolved = mTestObject->resolveAlbumName(name); |
|
1220 QVERIFY(resolved.length()); |
|
1221 QVERIFY(resolved == name); |
|
1222 mTestObject->mModel = temp; |
|
1223 |
|
1224 mStubModel->appendData(TMPXItemId(1,2)); |
|
1225 mStubModel->appendData(name); |
|
1226 |
|
1227 int count = mCollectionModel->rowCount(); |
|
1228 |
|
1229 // invalid data from model, same name can be used |
|
1230 VideoListDataModel::mReturnInvalid = true; |
|
1231 resolved = mTestObject->resolveAlbumName(name); |
|
1232 QVERIFY(resolved.length()); |
|
1233 QVERIFY(resolved == name); |
|
1234 VideoListDataModel::mReturnInvalid = false; |
|
1235 |
|
1236 // same name, name to be different |
|
1237 resolved = mTestObject->resolveAlbumName(name); |
|
1238 QVERIFY(resolved.length()); |
|
1239 QVERIFY(resolved != name); |
|
1240 QVERIFY(resolved.contains("1")); |
|
1241 |
|
1242 mStubModel->appendData(TMPXItemId(2,2)); |
|
1243 mStubModel->appendData(resolved); |
|
1244 |
|
1245 resolved = mTestObject->resolveAlbumName(name); |
|
1246 QVERIFY(resolved.length()); |
|
1247 QVERIFY(resolved != name); |
|
1248 QVERIFY(resolved.contains("2")); |
|
1249 |
|
1250 // different name, no changes |
|
1251 name = "Another"; |
|
1252 resolved = mTestObject->resolveAlbumName(name); |
|
1253 QVERIFY(resolved == name); |
|
1254 |
|
1255 mCollectionModel->mType = VideoCollectionCommon::EModelTypeAllVideos; |
|
1256 } |
|
1257 |
|
1258 // --------------------------------------------------------------------------- |
|
1259 // testResolveAlbumName |
|
1260 // --------------------------------------------------------------------------- |
|
1261 // |
|
1262 void TestVideoSortFilterProxyModel::testAddItemsInAlbum() |
|
1263 { |
|
1264 TMPXItemId albumId(1,2); |
|
1265 QList<TMPXItemId> items; |
|
1266 items.append(TMPXItemId(1,0)); |
|
1267 // no collection client |
|
1268 QVERIFY(mTestObject->addItemsInAlbum(albumId, items) == -1); |
|
1269 |
|
1270 mTestObject->initialize(mStubModel); |
|
1271 |
|
1272 QVERIFY(mTestObject->addItemsInAlbum(albumId, items) == 0); |
|
1273 } |
|
1274 |
|
1275 // --------------------------------------------------------------------------- |
|
1276 // testRemoveItemsFromAlbum |
|
1277 // --------------------------------------------------------------------------- |
|
1278 // |
|
1279 void TestVideoSortFilterProxyModel::testRemoveItemsFromAlbum() |
|
1280 { |
|
1281 VideoListDataModel::mRemoveFrAlbumReturn = 1; |
|
1282 TMPXItemId albumId(1,2); |
|
1283 QList<TMPXItemId> items; |
|
1284 items.append(TMPXItemId(1,0)); |
|
1285 VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount = 0; |
|
1286 // no model |
|
1287 |
|
1288 QVERIFY(mTestObject->removeItemsFromAlbum(albumId, items) == -1); |
|
1289 QCOMPARE(VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount, 2); |
|
1290 QVERIFY(VideoThumbnailData::mBackgroundThumbnailFetchingEnabled == true); |
|
1291 mTestObject->initialize(mStubModel); |
|
1292 |
|
1293 // model returns < 0 |
|
1294 VideoListDataModel::mRemoveFrAlbumReturn = -1; |
|
1295 QVERIFY(mTestObject->removeItemsFromAlbum(albumId, items) == -1); |
|
1296 QCOMPARE(VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount, 4); |
|
1297 QVERIFY(VideoThumbnailData::mBackgroundThumbnailFetchingEnabled == true); |
|
1298 |
|
1299 VideoListDataModel::mRemoveFrAlbumReturn = 11; |
|
1300 // "succeed" |
|
1301 QVERIFY(mTestObject->removeItemsFromAlbum(albumId, items) == 0); |
|
1302 QCOMPARE(VideoThumbnailData::mEnableBackgroundThumbnailFetchingCallCount, 6); |
|
1303 QVERIFY(VideoThumbnailData::mBackgroundThumbnailFetchingEnabled == true); |
|
1304 } |
|
1305 |
|
1306 // --------------------------------------------------------------------------- |
|
1307 // testGetOpenItem |
|
1308 // --------------------------------------------------------------------------- |
|
1309 // |
|
1310 void TestVideoSortFilterProxyModel::testGetOpenItem() |
|
1311 { |
|
1312 // no model nor collection client |
|
1313 QVERIFY(mTestObject->getOpenItem() == TMPXItemId::InvalidId()); |
|
1314 |
|
1315 mTestObject->initialize(mStubModel); |
|
1316 |
|
1317 // model exist, no collection client |
|
1318 VideoCollectionClient *tmpClient = mTestObject->mCollectionClient; |
|
1319 mTestObject->mCollectionClient = 0; |
|
1320 QVERIFY(mTestObject->getOpenItem() == TMPXItemId::InvalidId()); |
|
1321 mTestObject->mCollectionClient = tmpClient; |
|
1322 |
|
1323 // no model, collection client exists |
|
1324 VideoListDataModel *tmpModel = mTestObject->mModel; |
|
1325 mTestObject->mModel = 0; |
|
1326 QVERIFY(mTestObject->getOpenItem() == TMPXItemId::InvalidId()); |
|
1327 mTestObject->mModel = tmpModel; |
|
1328 |
|
1329 // type neither EAllVideos or ECollectionContent |
|
1330 QVERIFY(mTestObject->getOpenItem() == TMPXItemId::InvalidId()); |
|
1331 |
|
1332 TMPXItemId id; |
|
1333 // type EAllVideos |
|
1334 delete mTestObject; |
|
1335 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeAllVideos); |
|
1336 mTestObject->initialize(mStubModel); |
|
1337 id = mTestObject->getOpenItem(); |
|
1338 QVERIFY(id != TMPXItemId::InvalidId()); |
|
1339 QVERIFY(id.iId1 == KVcxMvcCategoryIdAll); |
|
1340 QVERIFY(id.iId2 == KVcxMvcMediaTypeCategory); |
|
1341 |
|
1342 // type ECollectionContent |
|
1343 delete mTestObject; |
|
1344 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeCollectionContent); |
|
1345 mTestObject->initialize(mStubModel); |
|
1346 id.iId1 = 1; |
|
1347 id.iId2 = KVcxMvcMediaTypeAlbum; |
|
1348 mTestObject->openItem(id); |
|
1349 id = TMPXItemId::InvalidId(); |
|
1350 id = mTestObject->getOpenItem(); |
|
1351 QVERIFY(id != TMPXItemId::InvalidId()); |
|
1352 QVERIFY(id.iId1 == 1); |
|
1353 QVERIFY(id.iId2 == KVcxMvcMediaTypeAlbum); |
|
1354 } |
|
1355 |
|
1356 // --------------------------------------------------------------------------- |
|
1357 // testRemoveAlbums |
|
1358 // --------------------------------------------------------------------------- |
|
1359 // |
|
1360 void TestVideoSortFilterProxyModel::testRemoveAlbums() |
|
1361 { |
|
1362 QModelIndexList indexList; |
|
1363 // no collection |
|
1364 QVERIFY(mTestObject->removeAlbums(indexList) == -1); |
|
1365 |
|
1366 mTestObject->initialize(mStubModel); |
|
1367 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelVideos) == 0); |
|
1368 |
|
1369 // empty list provided |
|
1370 QVERIFY(mTestObject->removeAlbums(indexList) == -1); |
|
1371 |
|
1372 mStubModel->appendData(TMPXItemId(1,0)); |
|
1373 mStubModel->appendData(TMPXItemId(2,0)); |
|
1374 mStubModel->appendData(TMPXItemId(3,0)); |
|
1375 |
|
1376 indexList.append(mTestObject->index(0,0)); |
|
1377 indexList.append(mTestObject->index(1,0)); |
|
1378 indexList.append(mTestObject->index(2,0)); |
|
1379 |
|
1380 // no albums in model |
|
1381 QVERIFY(mTestObject->removeAlbums(indexList) == -1); |
|
1382 |
|
1383 indexList.clear(); |
|
1384 mStubModel->removeAll(); |
|
1385 delete mTestObject; |
|
1386 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeCollections); |
|
1387 QVERIFY(mTestObject); |
|
1388 QVERIFY(mTestObject->initialize(mStubModel) == 0); |
|
1389 QVERIFY(mTestObject->open(VideoCollectionCommon::ELevelCategory) == 0); |
|
1390 mStubModel->appendData(TMPXItemId(1,2)); |
|
1391 mStubModel->appendData(TMPXItemId(2,2)); |
|
1392 mStubModel->appendData(TMPXItemId(3,2)); |
|
1393 indexList.append(mTestObject->index(0,0)); |
|
1394 indexList.append(mTestObject->index(1,0)); |
|
1395 indexList.append(mTestObject->index(2,0)); |
|
1396 |
|
1397 // succeed |
|
1398 QVERIFY(mTestObject->removeAlbums(indexList) == 0); |
|
1399 } |
|
1400 |
|
1401 // --------------------------------------------------------------------------- |
|
1402 // testAlbumChangedSlot |
|
1403 // --------------------------------------------------------------------------- |
|
1404 // |
|
1405 void TestVideoSortFilterProxyModel::testAlbumChangedSlot() |
|
1406 { |
|
1407 connect(this, SIGNAL(testSignal()), mTestObject, SLOT(albumChangedSlot())); |
|
1408 // cannot test anything here, just for the coverage |
|
1409 // level incorrect |
|
1410 mTestObject->initialize(mStubModel); |
|
1411 emit testSignal(); |
|
1412 delete mTestObject; |
|
1413 mTestObject = 0; |
|
1414 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeCollectionContent); |
|
1415 connect(this, SIGNAL(testSignal()), mTestObject, SLOT(albumChangedSlot())); |
|
1416 QVERIFY(mTestObject); |
|
1417 mTestObject->initialize(mStubModel); |
|
1418 emit testSignal(); |
|
1419 disconnect(this, SIGNAL(testSignal()), mTestObject, SLOT(albumChangedSlot())); |
|
1420 } |
|
1421 |
|
1422 // --------------------------------------------------------------------------- |
|
1423 // testIndexOfId |
|
1424 // --------------------------------------------------------------------------- |
|
1425 // |
|
1426 void TestVideoSortFilterProxyModel::testIndexOfId() |
|
1427 { |
|
1428 QModelIndex index; |
|
1429 // no model |
|
1430 TMPXItemId id(1,0); |
|
1431 index = mTestObject->indexOfId(id); |
|
1432 QVERIFY(!index.isValid()); |
|
1433 |
|
1434 mTestObject->initialize(mStubModel); |
|
1435 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
1436 |
|
1437 // fetching invalid |
|
1438 id = TMPXItemId::InvalidId(); |
|
1439 index = mTestObject->indexOfId(id); |
|
1440 QVERIFY(!index.isValid()); |
|
1441 |
|
1442 mStubModel->appendData(TMPXItemId(1,0)); |
|
1443 mStubModel->appendData(TMPXItemId(2,0)); |
|
1444 mStubModel->appendData(TMPXItemId(3,0)); |
|
1445 |
|
1446 id = TMPXItemId(2,0); |
|
1447 index = mTestObject->indexOfId(id); |
|
1448 QVERIFY(index.isValid()); |
|
1449 QVERIFY(index.row() == 1); |
|
1450 } |
|
1451 |
|
1452 // --------------------------------------------------------------------------- |
|
1453 // testSetGenericIdFilter |
|
1454 // --------------------------------------------------------------------------- |
|
1455 // |
|
1456 void TestVideoSortFilterProxyModel::testSetGenericIdFilter() |
|
1457 { |
|
1458 // type VideoCollectionWrapper::EGeneric |
|
1459 mTestObject->initialize(mStubModel); |
|
1460 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
1461 mTestObject->setGenericIdFilter(TMPXItemId(0,1), true); |
|
1462 |
|
1463 mStubModel->appendData(TMPXItemId(1,0)); |
|
1464 mStubModel->appendData(TMPXItemId(2,0)); |
|
1465 mStubModel->appendData(TMPXItemId(3,0)); |
|
1466 mTestObject->invalidate(); |
|
1467 QModelIndex index; |
|
1468 index = mTestObject->indexOfId(TMPXItemId(1,0)); |
|
1469 QVERIFY(index.isValid()); |
|
1470 QVERIFY(index.row() == 0); |
|
1471 |
|
1472 // other type |
|
1473 delete mTestObject; |
|
1474 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeAllVideos); |
|
1475 mTestObject->initialize(mStubModel); |
|
1476 mTestObject->open(VideoCollectionCommon::ELevelVideos); |
|
1477 |
|
1478 mTestObject->setGenericIdFilter(TMPXItemId(1,1), true); |
|
1479 mTestObject->invalidate(); |
|
1480 index = mTestObject->indexOfId(TMPXItemId(1,0)); |
|
1481 QVERIFY(index.isValid()); |
|
1482 QVERIFY(index.row() == 0); |
|
1483 } |
|
1484 |
|
1485 // --------------------------------------------------------------------------- |
|
1486 // testRenameAlbum |
|
1487 // --------------------------------------------------------------------------- |
|
1488 // |
|
1489 void TestVideoSortFilterProxyModel::testSetAlbumInUse() |
|
1490 { |
|
1491 mStubModel->mAlbumInUse = TMPXItemId::InvalidId(); |
|
1492 |
|
1493 // no model |
|
1494 mTestObject->setAlbumInUse(TMPXItemId(1,2)); |
|
1495 QVERIFY(mStubModel->mAlbumInUse == TMPXItemId::InvalidId()); |
|
1496 |
|
1497 // model exists |
|
1498 mTestObject->initialize(mStubModel); |
|
1499 mTestObject->setAlbumInUse(TMPXItemId(1,2)); |
|
1500 QVERIFY(mStubModel->mAlbumInUse == TMPXItemId(1,2)); |
|
1501 } |
|
1502 |
|
1503 // --------------------------------------------------------------------------- |
|
1504 // testRenameItem |
|
1505 // --------------------------------------------------------------------------- |
|
1506 // |
|
1507 void TestVideoSortFilterProxyModel::testRenameItem() |
|
1508 { |
|
1509 delete mTestObject; |
|
1510 mTestObject = new FilterProxyTester(VideoCollectionCommon::EModelTypeAllVideos); |
|
1511 |
|
1512 // Not initialized. |
|
1513 TMPXItemId id = TMPXItemId::InvalidId(); |
|
1514 QString name = ""; |
|
1515 QVERIFY(mTestObject->renameItem(id, name) == -1); |
|
1516 |
|
1517 // Initialized. |
|
1518 mTestObject->initialize(mStubModel); |
|
1519 QVERIFY(mTestObject->renameItem(id, name) == 0); |
|
1520 } |
|
1521 |
|
1522 // End of file |