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