292 { |
306 { |
293 int totalsize = 1000; |
307 int totalsize = 1000; |
294 int bufferSize = 100; |
308 int bufferSize = 100; |
295 bmh = new BMHelper(totalsize); |
309 bmh = new BMHelper(totalsize); |
296 bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize); |
310 bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize); |
|
311 bm->aboutToRemoveItem(0); |
|
312 bmh->remove(0); |
|
313 bm->removedItem(0); |
|
314 QVERIFY(bmh->isIntergal(bufferSize)); |
297 totalsize--; |
315 totalsize--; |
298 bmh->itemCountChanged(0, true, totalsize); |
316 QCOMPARE(bmh->totalSize(), totalsize); |
299 bm->itemCountChanged(0, true, totalsize); |
317 |
300 QVERIFY(bmh->isIntergal(bufferSize)); |
318 bm->aboutToRemoveItem(150); |
301 |
319 bmh->remove(150); |
|
320 bm->removedItem(150); |
|
321 QVERIFY(bmh->isIntergal(bufferSize)); |
302 totalsize--; |
322 totalsize--; |
303 bmh->itemCountChanged(150, true, totalsize); |
323 QCOMPARE(bmh->totalSize(), totalsize); |
304 bm->itemCountChanged(150, true, totalsize); |
324 |
305 QVERIFY(bmh->isIntergal(bufferSize)); |
325 bm->setPosition(100); |
306 |
326 bm->aboutToRemoveItem(150); |
|
327 bmh->remove(150); |
|
328 bm->removedItem(150); |
|
329 QVERIFY(bmh->isIntergal(bufferSize)); |
307 totalsize--; |
330 totalsize--; |
|
331 QCOMPARE(bmh->totalSize(), totalsize); |
|
332 |
|
333 bm->setPosition(891); |
|
334 bm->aboutToRemoveItem(150); |
|
335 bmh->remove(150); |
|
336 bm->removedItem(150); |
|
337 QVERIFY(bmh->isIntergal(bufferSize)); |
|
338 totalsize--; |
|
339 QCOMPARE(bmh->totalSize(), totalsize); |
|
340 |
|
341 bm->setPosition(0); |
|
342 bm->aboutToRemoveItem(150); |
|
343 bmh->remove(150); |
|
344 bm->removedItem(150); |
|
345 QVERIFY(bmh->isIntergal(bufferSize)); |
|
346 totalsize--; |
|
347 QCOMPARE(bmh->totalSize(), totalsize); |
|
348 |
|
349 bm->setPosition(900); |
|
350 bm->aboutToRemoveItem(890); |
|
351 bmh->remove(890); |
|
352 bm->removedItem(890); |
|
353 QVERIFY(bmh->isIntergal(bufferSize)); |
|
354 totalsize--; |
|
355 QCOMPARE(bmh->totalSize(), totalsize); |
|
356 |
|
357 bm->setPosition(totalsize); |
|
358 bm->aboutToRemoveItem(totalsize); |
|
359 bmh->remove(totalsize); |
|
360 bm->removedItem(totalsize); |
|
361 QVERIFY(bmh->isIntergal(bufferSize)); |
|
362 // totalsize--;//no item remove since totalsize is outside |
|
363 QCOMPARE(bmh->totalSize(), totalsize); |
|
364 |
|
365 bm->setPosition(totalsize); |
|
366 bm->aboutToRemoveItem(totalsize-1); |
|
367 bmh->remove(totalsize-1); |
|
368 bm->removedItem(totalsize-1); |
|
369 QVERIFY(bmh->isIntergal(bufferSize)); |
|
370 totalsize--; |
|
371 QCOMPARE(bmh->totalSize(), totalsize); |
|
372 |
|
373 bm->setPosition(totalsize+200); |
|
374 bm->aboutToRemoveItem(totalsize+200); |
|
375 bmh->remove(totalsize+200); |
|
376 bm->removedItem(totalsize+200); |
|
377 QVERIFY(bmh->isIntergal(bufferSize)); |
|
378 // totalsize--; //no item remove since totalsize+200 is outside |
|
379 QCOMPARE(bmh->totalSize(), totalsize); |
|
380 |
|
381 bm->aboutToRemoveItem(-20); |
|
382 bmh->remove(-20); |
|
383 bm->removedItem(-20); |
|
384 QVERIFY(bmh->isIntergal(bufferSize)); |
|
385 // totalsize--; //no item remove since totalsize+200 is outside |
|
386 QCOMPARE(bmh->totalSize(), totalsize); |
|
387 |
|
388 |
|
389 bm->aboutToRemoveItem(totalsize+10); |
|
390 bmh->remove(totalsize+10); |
|
391 bm->removedItem(totalsize+10); |
|
392 QVERIFY(bmh->isIntergal(bufferSize)); |
|
393 // totalsize--; //no item remove since totalsize+200 is outside |
|
394 QCOMPARE(bmh->totalSize(), totalsize); |
|
395 |
|
396 |
|
397 bm->resetBuffer(0, 10); |
|
398 bmh->resizeCache(10); |
|
399 bm->aboutToRemoveItem(1); |
|
400 bmh->remove(1); |
|
401 bm->removedItem(1); |
|
402 QCOMPARE(bmh->totalSize(), 9); |
|
403 |
|
404 bmh->resizeCache(totalsize); |
|
405 bm->resetBuffer(0, totalsize); |
|
406 |
|
407 //insert |
|
408 |
|
409 bm->setPosition(0); |
|
410 bm->aboutToInsertItem(0); |
|
411 bmh->insert(0); |
|
412 bm->insertedItem(0); |
|
413 QVERIFY(bmh->isIntergal(bufferSize)); |
|
414 totalsize++; |
|
415 QCOMPARE(bmh->totalSize(), totalsize); |
|
416 |
|
417 bm->aboutToInsertItem(50); |
|
418 bmh->insert(50); |
|
419 bm->insertedItem(50); |
|
420 QVERIFY(bmh->isIntergal(bufferSize)); |
|
421 totalsize++; |
|
422 QCOMPARE(bmh->totalSize(), totalsize); |
|
423 |
308 bm->setPosition(100); |
424 bm->setPosition(100); |
309 bmh->itemCountChanged(150, true, totalsize); |
425 bm->aboutToInsertItem(80); |
310 bm->itemCountChanged(150, true, totalsize); |
426 bmh->insert(80); |
311 QVERIFY(bmh->isIntergal(bufferSize)); |
427 bm->insertedItem(80); |
312 |
428 QVERIFY(bmh->isIntergal(bufferSize)); |
313 totalsize--; |
|
314 bm->setPosition(891); |
|
315 bmh->itemCountChanged(150, true, totalsize); |
|
316 bm->itemCountChanged(150, true, totalsize); |
|
317 QVERIFY(bmh->isIntergal(bufferSize)); |
|
318 |
|
319 totalsize--; |
|
320 bm->setPosition(900); |
|
321 bmh->itemCountChanged(890, true, totalsize); |
|
322 bm->itemCountChanged(890, true, totalsize); |
|
323 QVERIFY(bmh->isIntergal(bufferSize)); |
|
324 |
|
325 totalsize--; |
|
326 bm->setPosition(totalsize); |
|
327 bmh->itemCountChanged(totalsize, true, totalsize); |
|
328 bm->itemCountChanged(totalsize, true, totalsize); |
|
329 QVERIFY(bmh->isIntergal(bufferSize)); |
|
330 |
|
331 totalsize--; |
|
332 bm->setPosition(totalsize+200); |
|
333 bmh->itemCountChanged(totalsize+200, true, totalsize); |
|
334 bm->itemCountChanged(totalsize+200, true, totalsize); |
|
335 QVERIFY(bmh->isIntergal(bufferSize)); |
|
336 |
|
337 |
|
338 totalsize= totalsize - 10; |
|
339 bm->setPosition(0); |
|
340 bmh->itemCountChanged(0, true, totalsize); |
|
341 bm->itemCountChanged(0, true, totalsize); |
|
342 QVERIFY(bmh->isIntergal(bufferSize)); |
|
343 |
|
344 totalsize= totalsize - 10; |
|
345 bm->setPosition(totalsize); |
|
346 bmh->itemCountChanged(totalsize, true, totalsize); |
|
347 bm->itemCountChanged(totalsize, true, totalsize); |
|
348 QVERIFY(bmh->isIntergal(bufferSize)); |
|
349 |
|
350 totalsize= totalsize - 10; |
|
351 bm->setPosition(totalsize/2); |
|
352 bmh->itemCountChanged(totalsize/2, true, totalsize); |
|
353 bm->itemCountChanged(totalsize/2, true, totalsize); |
|
354 QVERIFY(bmh->isIntergal(bufferSize)); |
|
355 |
|
356 totalsize++; |
429 totalsize++; |
357 bm->setPosition(0); |
430 QCOMPARE(bmh->totalSize(), totalsize); |
358 bmh->itemCountChanged(0, false, totalsize); |
431 |
359 bm->itemCountChanged(0, false, totalsize); |
|
360 QVERIFY(bmh->isIntergal(bufferSize)); |
|
361 |
|
362 totalsize++; |
|
363 bmh->itemCountChanged(50, false, totalsize); |
|
364 bm->itemCountChanged(50, false, totalsize); |
|
365 QVERIFY(bmh->isIntergal(bufferSize)); |
|
366 |
|
367 totalsize++; |
|
368 bm->setPosition(100); |
|
369 bmh->itemCountChanged(80, false, totalsize); |
|
370 bm->itemCountChanged(80, false, totalsize); |
|
371 QVERIFY(bmh->isIntergal(bufferSize)); |
|
372 |
|
373 totalsize++; |
|
374 bm->setPosition(500); |
432 bm->setPosition(500); |
375 bmh->itemCountChanged(480, false, totalsize); |
433 bm->aboutToInsertItem(80); |
376 bm->itemCountChanged(480, false, totalsize); |
434 bmh->insert(80); |
377 QVERIFY(bmh->isIntergal(bufferSize)); |
435 bm->insertedItem(80); |
378 |
436 QVERIFY(bmh->isIntergal(bufferSize)); |
379 totalsize++; |
437 totalsize++; |
|
438 QCOMPARE(bmh->totalSize(), totalsize); |
|
439 |
|
440 bm->setPosition(500); |
|
441 bm->aboutToInsertItem(480); |
|
442 bmh->insert(480); |
|
443 bm->insertedItem(480); |
|
444 QVERIFY(bmh->isIntergal(bufferSize)); |
|
445 totalsize++; |
|
446 QCOMPARE(bmh->totalSize(), totalsize); |
|
447 |
380 bm->setPosition(totalsize-20); |
448 bm->setPosition(totalsize-20); |
381 bmh->itemCountChanged(totalsize, false, totalsize); |
449 bm->aboutToInsertItem(totalsize); |
382 bm->itemCountChanged(totalsize, false, totalsize); |
450 bmh->insert(totalsize); |
383 QVERIFY(bmh->isIntergal(bufferSize)); |
451 bm->insertedItem(totalsize); |
384 |
452 QVERIFY(bmh->isIntergal(bufferSize)); |
385 totalsize=totalsize+10; |
453 totalsize++; |
|
454 QCOMPARE(bmh->totalSize(), totalsize); |
|
455 |
386 bm->setPosition(totalsize-20); |
456 bm->setPosition(totalsize-20); |
387 bmh->itemCountChanged(totalsize, false, totalsize); |
457 bm->aboutToInsertItem(totalsize+20); |
388 bm->itemCountChanged(totalsize, false, totalsize); |
458 bmh->insert(totalsize+20); |
389 QVERIFY(bmh->isIntergal(bufferSize)); |
459 bm->insertedItem(totalsize+20); |
390 |
460 QVERIFY(bmh->isIntergal(bufferSize)); |
391 totalsize=totalsize+10; |
461 // totalsize++; //no insert |
392 bm->setPosition(20); |
462 QCOMPARE(bmh->totalSize(), totalsize); |
393 bmh->itemCountChanged(totalsize, false, totalsize); |
463 |
394 bm->itemCountChanged(totalsize, false, totalsize); |
464 bm->setPosition(2*totalsize); |
395 QVERIFY(bmh->isIntergal(bufferSize)); |
465 bm->aboutToInsertItem(2*totalsize); |
396 |
466 bmh->insert(2*totalsize); |
397 totalsize=totalsize+10; |
467 bm->insertedItem(2*totalsize); |
398 bm->setPosition(totalsize/2-20); |
468 QVERIFY(bmh->isIntergal(bufferSize)); |
399 bmh->itemCountChanged(totalsize, false, totalsize); |
469 // totalsize++; //no insert |
400 bm->itemCountChanged(totalsize, false, totalsize); |
470 QCOMPARE(bmh->totalSize(), totalsize); |
401 QVERIFY(bmh->isIntergal(bufferSize)); |
471 |
|
472 |
402 } |
473 } |
403 |
474 |
404 void TestCacheProxy::testBM_ResizeCache() |
475 void TestCacheProxy::testBM_ResizeCache() |
405 { |
476 { |
406 int totalsize = 1000; |
477 int totalsize = 1000; |
621 QString s = "NEWITEM"; |
709 QString s = "NEWITEM"; |
622 list.append( QPair< QVariant, int >(s, Qt::DisplayRole) ); |
710 list.append( QPair< QVariant, int >(s, Qt::DisplayRole) ); |
623 |
711 |
624 dph->testUpdate(0, &list, false); //update shouldn't change - no item |
712 dph->testUpdate(0, &list, false); //update shouldn't change - no item |
625 dph->testUpdate(-1, &list, true); //update shouldn't change - no item |
713 dph->testUpdate(-1, &list, true); //update shouldn't change - no item |
|
714 dph->testUpdate(-1, s, Qt::DisplayRole, true); //update shouldn't change - no item |
|
715 dph->testUpdateIcon(-1, s); |
626 dph->testUpdate(120000, &list, false); //update shouldn't change - no item |
716 dph->testUpdate(120000, &list, false); //update shouldn't change - no item |
627 res = dph->data(idx, Qt::DisplayRole); |
717 res = dph->data(idx, Qt::DisplayRole); |
628 QVERIFY(res.isValid() == false); |
718 QVERIFY(res.isValid() == false); |
629 QVERIFY(dph->getObserverDataUpdated().count() == 0); |
719 QVERIFY(dph->getObserverDataUpdated().count() == 0); |
630 |
720 |
631 dph->testNewItem(&list, false); |
721 dph->testNewItem(&list, false); |
632 QList< QPair< int, int > > resList = dph->getSignalRowsAboutToBeInserted(); |
722 QList< QPair< int, int > > resList = dph->getSignalRowsAboutToBeInserted(); |
633 QVERIFY(resList.count() == 1); |
723 QVERIFY(resList.count() == 1); |
634 QVERIFY(resList[0].first == 0); //for item 0 |
724 QVERIFY(resList[0].first == 0); //for item 0 |
635 QVERIFY(resList[0].second == 0); //for item 0 |
725 QVERIFY(resList[0].second == 0); //for item 0 |
636 resList = dph->getSignalRowsInserted(); |
726 resList = dph->getSignalRowsInserted(); |
637 QVERIFY(resList.count() == 1); |
727 QVERIFY(resList.count() == 1); |
638 QVERIFY(resList[0].first == 0); //for item 0 |
728 QVERIFY(resList[0].first == 0); //for item 0 |
639 QVERIFY(resList[0].second == 0); //for item 0 |
729 QVERIFY(resList[0].second == 0); //for item 0 |
|
730 |
|
731 dph->testUpdateIcon(0, s, false); |
|
732 dph->testUpdateIcon(0, s, true); |
|
733 res = dph->data(idx, Qt::DecorationRole); |
|
734 QCOMPARE(res.isValid(), true); |
|
735 QVERIFY(res == s); |
|
736 QCOMPARE(dph->getSignalDataUpdated().count(), 1); |
640 |
737 |
641 QVERIFY(dph->rowCount() == 1); |
738 QVERIFY(dph->rowCount() == 1); |
642 |
739 |
643 idx = dph->index(0,0); |
740 idx = dph->index(0,0); |
644 res = dph->data(idx, Qt::DisplayRole); |
741 res = dph->data(idx, Qt::DisplayRole); |
741 QVERIFY(resList[0].first == 100); |
838 QVERIFY(resList[0].first == 100); |
742 QVERIFY(resList[0].second == 100); |
839 QVERIFY(resList[0].second == 100); |
743 |
840 |
744 dph->getSignalRowsInserted(); |
841 dph->getSignalRowsInserted(); |
745 dph->getSignalRowsRemoved(); |
842 dph->getSignalRowsRemoved(); |
746 dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 puts it at begining |
843 dph->testInsertItem(0, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with 0 puts at begining |
747 resList = dph->getSignalRowsInserted(); |
844 resList = dph->getSignalRowsInserted(); |
748 QVERIFY(resList.count() == 1); |
845 QVERIFY(resList.count() == 1); |
749 QVERIFY(resList[0].first == 0); |
846 QVERIFY(resList[0].first == 0); |
750 QVERIFY(resList[0].second == 0); |
847 QVERIFY(resList[0].second == 0); |
|
848 |
|
849 dph->getSignalRowsInserted(); |
|
850 dph->getSignalRowsRemoved(); |
|
851 dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 not adds to collection |
|
852 resList = dph->getSignalRowsInserted(); |
|
853 QVERIFY(resList.count() == 0); |
751 dph->testRemoveItem(-10); |
854 dph->testRemoveItem(-10); |
752 resList = dph->getSignalRowsRemoved(); |
855 resList = dph->getSignalRowsRemoved(); |
753 QVERIFY(resList.count() == 0); |
856 QVERIFY(resList.count() == 0); |
754 |
857 |
755 dph->getSignalRowsInserted(); |
858 dph->getSignalRowsInserted(); |
756 dph->getSignalRowsRemoved(); |
859 dph->getSignalRowsRemoved(); |
757 dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range puts it at end |
860 dph->testInsertItem(dph->rowCount(), QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert at dph->rowCount() puts at end |
758 resList = dph->getSignalRowsInserted(); |
861 resList = dph->getSignalRowsInserted(); |
759 QVERIFY(resList.count() == 1); |
862 QVERIFY(resList.count() == 1); |
760 QVERIFY(resList[0].first == dph->rowCount()-1); |
863 QVERIFY(resList[0].first == dph->rowCount()-1); |
761 QVERIFY(resList[0].second == dph->rowCount()-1); |
864 QVERIFY(resList[0].second == dph->rowCount()-1); |
|
865 |
|
866 dph->getSignalRowsInserted(); |
|
867 dph->getSignalRowsRemoved(); |
|
868 dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range not adds to collection |
|
869 resList = dph->getSignalRowsInserted(); |
|
870 QVERIFY(resList.count() == 0); |
762 dph->testRemoveItem(100000); |
871 dph->testRemoveItem(100000); |
763 resList = dph->getSignalRowsRemoved(); |
872 resList = dph->getSignalRowsRemoved(); |
764 QVERIFY(resList.count() == 0); |
873 QVERIFY(resList.count() == 0); |
765 |
874 |
766 idx = dph->index(579,0); |
875 idx = dph->index(579,0); |
767 QMap<int, QVariant> it = dph->itemData(idx); |
876 QMap<int, QVariant> it = dph->itemData(idx); |
768 QCOMPARE(it.size(), 4); |
877 QCOMPARE(it.size(), 4); |
769 QCOMPARE(it.contains(Qt::DisplayRole), true); |
878 QCOMPARE(it.contains(Qt::DisplayRole), true); |
770 QVariant r2 = it[Qt::DisplayRole]; |
879 QVariant r2 = it[Qt::DisplayRole]; |
771 QCOMPARE(r2.isValid(), true); |
880 QCOMPARE(r2.isValid(), true); |
|
881 |
|
882 idx = dph->index(-10,0); |
|
883 it = dph->itemData(idx); |
|
884 |
772 res = dph->data(idx, Qt::DisplayRole); |
885 res = dph->data(idx, Qt::DisplayRole); |
773 QCOMPARE(res.isValid(), true); |
886 QCOMPARE(res.isValid(), false); |
774 QCOMPARE(res.toString(), r2.toString()); |
887 |
775 |
|
776 } |
888 } |
777 |
889 |
778 void TestCacheProxy::testDP_QPixmapPool() |
890 void TestCacheProxy::testDP_QPixmapPool() |
779 { |
891 { |
780 dph = new DataProviderHelper(100); |
892 dph = new DataProviderHelper(100); |
817 dph->testCreateIcon(4, pix); |
929 dph->testCreateIcon(4, pix); |
818 dph->testCreateIcon(6, pix); |
930 dph->testCreateIcon(6, pix); |
819 dph->resizeQPixmapPool(1); |
931 dph->resizeQPixmapPool(1); |
820 res = dph->testCreateIcon(10, pix); |
932 res = dph->testCreateIcon(10, pix); |
821 QVERIFY(res.isValid() == false); |
933 QVERIFY(res.isValid() == false); |
|
934 |
|
935 dph->resizeQPixmapPool(110); |
|
936 for ( int i = 0; i < 100; i ++) |
|
937 dph->testCreateIcon(i, pix); |
|
938 |
|
939 for ( int i = 20; i < 40; i ++) |
|
940 dph->testReleasePixmap(i); |
|
941 |
|
942 dph->resizeQPixmapPool(50); |
|
943 dph->testReleasePixmap(5); |
|
944 |
|
945 dph->resizeQPixmapPool(1); |
|
946 dph->testReleasePixmap(0); |
|
947 dph->testReleasePixmap(2); |
|
948 dph->testReleasePixmap(1); |
|
949 dph->resizeQPixmapPool(10); |
|
950 |
|
951 |
|
952 |
|
953 } |
|
954 |
|
955 void TestCacheProxy::testDP_IconMode() |
|
956 { |
|
957 dph = new DataProviderHelper(100); |
|
958 QCOMPARE( dph->testIconMode(), HgDataProviderModel::HgDataProviderIconHbIcon); |
|
959 dph->resizeQPixmapPool(10); |
|
960 QPixmap pix; |
|
961 QVariant res = dph->testCreateIcon(0, pix); |
|
962 QVERIFY(res.isValid() == true); |
|
963 QVERIFY(res.canConvert<HbIcon>()); |
|
964 |
|
965 dph->testChangeIconMode(HgDataProviderModel::HgDataProviderIconHbIcon); |
|
966 res = dph->testCreateIcon(0, pix); |
|
967 QVERIFY(res.isValid() == true); |
|
968 QVERIFY(res.canConvert<HbIcon>()); |
|
969 |
|
970 dph->testChangeIconMode(HgDataProviderModel::HgDataProviderIconQIcon); |
|
971 res = dph->testCreateIcon(0, pix); |
|
972 QVERIFY(res.isValid() == true); |
|
973 QVERIFY(res.canConvert<QIcon>()); |
|
974 |
|
975 dph->testChangeIconMode(HgDataProviderModel::HgDataProviderIconQImage); |
|
976 res = dph->testCreateIcon(0, pix); |
|
977 QVERIFY(res.isValid() == true); |
|
978 QVERIFY(res.canConvert<QImage>()); |
|
979 |
|
980 dph->testChangeIconMode(HgDataProviderModel::HgDataProviderIconQPixmap); |
|
981 res = dph->testCreateIcon(0, pix); |
|
982 QVERIFY(res.isValid() == true); |
|
983 QVERIFY(res.canConvert<QPixmap>()); |
|
984 |
|
985 dph->testChangeIconMode( (HgDataProviderModel::HgDataProviderIconMode)10 ); |
|
986 res = dph->testCreateIcon(0, pix); |
|
987 QVERIFY(res.isValid() == false); |
822 } |
988 } |
823 |
989 |
824 void TestCacheProxy::testCP_QAbstractItemModel() |
990 void TestCacheProxy::testCP_QAbstractItemModel() |
825 { |
991 { |
826 cp = new HgCacheProxyModel(); |
992 cp = new HgCacheProxyModel(); |
836 cp->setDataProvider(dph); |
1002 cp->setDataProvider(dph); |
837 QVERIFY(cp->DataProvider() == dph); |
1003 QVERIFY(cp->DataProvider() == dph); |
838 |
1004 |
839 cp->setDataProvider(dph); |
1005 cp->setDataProvider(dph); |
840 QVERIFY(cp->DataProvider() == dph); |
1006 QVERIFY(cp->DataProvider() == dph); |
|
1007 |
|
1008 QList< QPair< QVariant, int > > list; |
|
1009 QString s = "NEWITEM"; |
|
1010 list.append( QPair< QVariant, int >(s, Qt::DisplayRole) ); |
|
1011 dph->testNewItem(&list, false); |
|
1012 |
|
1013 dph->testRemoveItems(0, 1);//should remove item |
|
1014 |
|
1015 QModelIndex idx = cp->index(0,0); |
|
1016 QCOMPARE(cp->hasChildren(idx), true); |
|
1017 QSize s1 = cp->span(idx); |
|
1018 QSize s2 = cp->span(cp->index(1, 0)); |
|
1019 QVERIFY(s1 == s2); |
|
1020 cp->submit(); |
|
1021 cp->revert(); |
|
1022 Qt::ItemFlags f1 = cp->flags(idx); |
|
1023 Qt::ItemFlags f2 = cp->flags(cp->index(1, 0)); |
|
1024 QVERIFY(f1 == f2); |
|
1025 |
|
1026 QVariant res = cp->headerData(0, Qt::Horizontal, Qt::DecorationRole); |
|
1027 QCOMPARE(res.isValid(), false); |
|
1028 //default implementation ignores that |
|
1029 cp->setHeaderData(0, Qt::Horizontal, QString("headerdata"), Qt::DecorationRole); |
|
1030 res = cp->headerData(0, Qt::Horizontal, Qt::DecorationRole); |
|
1031 QCOMPARE(res.isValid(), false); |
|
1032 |
|
1033 QStringList li = cp->mimeTypes(); |
|
1034 QCOMPARE(li.count(), 1); |
|
1035 |
|
1036 QModelIndexList li2; |
|
1037 li2<< idx; |
|
1038 QMimeData* md1 = cp->mimeData(li2); |
|
1039 QVERIFY(md1 != NULL); |
|
1040 QCOMPARE(cp->dropMimeData(NULL, Qt::MoveAction, 10, 0, QModelIndex() ), false); |
|
1041 QCOMPARE(cp->supportedDragActions(), Qt::CopyAction); |
|
1042 |
|
1043 QCOMPARE(cp->canFetchMore(idx), false); |
|
1044 cp->fetchMore(idx); |
|
1045 |
|
1046 QModelIndex idx2 = cp->buddy(idx); |
|
1047 QCOMPARE(idx2.row(), idx.row()); |
|
1048 QCOMPARE(idx2.column(), idx.column()); |
|
1049 |
|
1050 li2 = cp->match(idx, Qt::DisplayRole, QString("ITEM"), 1000, Qt::MatchContains); |
|
1051 QCOMPARE(li2.count(), dph->getCount()); |
|
1052 |
|
1053 |
|
1054 |
|
1055 cp->setDataProvider(NULL); |
|
1056 QVERIFY(cp->DataProvider() == NULL); |
|
1057 idx = cp->index(100,0); |
|
1058 res = dph->data(idx, Qt::DisplayRole); |
|
1059 QCOMPARE(res.isValid(), false); |
|
1060 |
|
1061 QCOMPARE(cp->insertRows(0, 10), false); //default implementation returns false |
|
1062 QCOMPARE(cp->removeRows(0, 10), false);//default implementation returns false |
|
1063 |
|
1064 QCOMPARE(cp->insertRow(0), false); //default implementation returns false |
|
1065 QCOMPARE(cp->removeRow(0), false);//default implementation returns false |
|
1066 |
|
1067 QCOMPARE(cp->insertColumns(0, 10), false); //default implementation returns false |
|
1068 QCOMPARE(cp->removeColumns(0, 10), false);//default implementation returns false |
|
1069 |
|
1070 QCOMPARE(cp->insertColumn(0), false); //default implementation returns false |
|
1071 QCOMPARE(cp->removeColumn(0), false);//default implementation returns false |
|
1072 |
|
1073 |
841 } |
1074 } |
842 |
1075 |
843 void TestCacheProxy::testCP_SignalsForward() |
1076 void TestCacheProxy::testCP_SignalsForward() |
844 { |
1077 { |
845 cp = new HgCacheProxyModel(); |
1078 cp = new HgCacheProxyModel(); |
846 cph = new CacheProxyHelper(cp); |
1079 cph = new CacheProxyHelper(cp); |
847 dph = new DataProviderHelper(200); |
1080 dph = new DataProviderHelper(200); |
848 cp->setDataProvider(dph, 50, 20); |
1081 cp->setDataProvider(dph, 50, 20); |
849 |
1082 |
850 QList< QPair< int, int > > resList = cph->getSignalDataChanged(); |
1083 QList< QPair< int, int > > resList = cph->getSignalDataChanged(); |
851 QVERIFY(resList.count() == 50); |
1084 QVERIFY(resList.count() == 50); |
852 QVERIFY(resList[0].first == 0); |
1085 QVERIFY(resList[0].first == 0); |
882 cph->getSignalModelReset(); |
1115 cph->getSignalModelReset(); |
883 dph->resetModel(); |
1116 dph->resetModel(); |
884 QVERIFY(cph->getSignalModelAboutToBeReset() == true); |
1117 QVERIFY(cph->getSignalModelAboutToBeReset() == true); |
885 QVERIFY(cph->getSignalModelReset() == true); |
1118 QVERIFY(cph->getSignalModelReset() == true); |
886 QVERIFY(cp->columnCount() == 1); |
1119 QVERIFY(cp->columnCount() == 1); |
887 QVERIFY(cp->rowCount() == 1000); |
1120 QVERIFY(cp->rowCount() == 1000); |
888 |
1121 |
|
1122 cph->getSignalDataChanged(); |
|
1123 dph->testEmitDataChanged(dph->index(0,0), dph->index(10,0)); |
|
1124 resList = cph->getSignalDataChanged(); |
|
1125 QCOMPARE(resList.count(), 1); |
|
1126 QCOMPARE(resList[0].first, 0); |
|
1127 QCOMPARE(resList[0].second, 10); |
|
1128 |
|
1129 cph->getSignalColumnsAboutToBeInserted(); |
|
1130 cph->getSignalColumnsInserted(); |
|
1131 dph->testEmitColumnsInsert(dph->index(0,0),0, 10); |
|
1132 resList = cph->getSignalColumnsAboutToBeInserted(); |
|
1133 QCOMPARE(resList.count(), 1); |
|
1134 QCOMPARE(resList[0].first, 0); |
|
1135 QCOMPARE(resList[0].second, 10); |
|
1136 resList = cph->getSignalColumnsInserted(); |
|
1137 QCOMPARE(resList.count(), 1); |
|
1138 QCOMPARE(resList[0].first, 0); |
|
1139 QCOMPARE(resList[0].second, 10); |
|
1140 |
|
1141 cph->getSignalColumnsAboutToBeRemoved(); |
|
1142 cph->getSignalColumnsRemoved(); |
|
1143 dph->testEmitColumnsRemove(dph->index(0,0),0, 10); |
|
1144 resList = cph->getSignalColumnsAboutToBeRemoved(); |
|
1145 QCOMPARE(resList.count(), 1); |
|
1146 QCOMPARE(resList[0].first, 0); |
|
1147 QCOMPARE(resList[0].second, 10); |
|
1148 resList = cph->getSignalColumnsRemoved(); |
|
1149 QCOMPARE(resList.count(), 1); |
|
1150 QCOMPARE(resList[0].first, 0); |
|
1151 QCOMPARE(resList[0].second, 10); |
|
1152 |
|
1153 // cph->getSignalColumnsAboutToBeMoved(); |
|
1154 // cph->getSignalColumnsMoved(); |
|
1155 // QCOMPARE(dph->testEmitColumnsAboutToBeMoved(0, 10), false); |
|
1156 // resList = cph->getSignalColumnsAboutToBeMoved(); |
|
1157 // QCOMPARE(resList.count(), 0); |
|
1158 |
|
1159 // dph->testEmitColumnsMoved(0, 10); |
|
1160 // resList = cph->getSignalColumnsMoved(); |
|
1161 // QCOMPARE(resList.count(), 0); |
|
1162 |
|
1163 |
|
1164 // cph->getSignalRowsAboutToBeMoved(); |
|
1165 // cph->getSignalRowsMoved(); |
|
1166 // QCOMPARE(dph->testEmitRowsAboutToBeMoved(0, 10), false); |
|
1167 // resList = cph->getSignalRowsAboutToBeMoved(); |
|
1168 // QCOMPARE(resList.count(), 0); |
|
1169 |
|
1170 // dph->testEmitRowsMoved(0, 10); |
|
1171 // resList = cph->getSignalRowsMoved(); |
|
1172 // QCOMPARE(resList.count(), 0); |
|
1173 |
|
1174 |
|
1175 cph->getSignalHeaderDataChanged(); |
|
1176 dph->testEmitHeaderDataChanged(Qt::Horizontal, 0, 0); |
|
1177 resList = cph->getSignalHeaderDataChanged(); |
|
1178 QCOMPARE(resList.count(), 1); |
|
1179 QCOMPARE(resList[0].first, 0); |
|
1180 QCOMPARE(resList[0].second, 0); |
|
1181 |
|
1182 |
889 } |
1183 } |
890 |
1184 |
891 void TestCacheProxy::testCP_ResizeCache() |
1185 void TestCacheProxy::testCP_ResizeCache() |
892 { |
1186 { |
893 cp = new HgCacheProxyModel(); |
1187 cp = new HgCacheProxyModel(); |
894 cph = new CacheProxyHelper(cp); |
1188 cph = new CacheProxyHelper(cp); |
895 dph = new DataProviderHelper(200); |
1189 dph = new DataProviderHelper(200); |
|
1190 cp->resizeCache(100, 20); |
896 cp->setDataProvider(dph, 50, 20); |
1191 cp->setDataProvider(dph, 50, 20); |
897 dph->getLastRelease(); |
1192 dph->getLastRelease(); |
898 dph->getLastRequest(); |
1193 dph->getLastRequest(); |
899 cp->resizeCache(20, 5); |
1194 cp->resizeCache(20, 5); |
900 |
1195 |
1053 |
1376 |
1054 QRegExp regexp = QRegExp("ITEM*", Qt::CaseSensitive, QRegExp::Wildcard); |
1377 QRegExp regexp = QRegExp("ITEM*", Qt::CaseSensitive, QRegExp::Wildcard); |
1055 |
1378 |
1056 cp->setFilterRegExp(regexp); |
1379 cp->setFilterRegExp(regexp); |
1057 QVERIFY(cp->filterRegExp() == regexp); |
1380 QVERIFY(cp->filterRegExp() == regexp); |
|
1381 cp->setFilterRegExp(regexp); |
1058 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1382 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1059 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseSensitive); |
1383 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseSensitive); |
|
1384 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
|
1385 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
1386 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1060 |
1387 |
1061 idx = cp->index(1, 0); |
1388 idx = cp->index(1, 0); |
1062 res = cp->data(idx, Qt::DisplayRole); |
1389 res = cp->data(idx, Qt::DisplayRole); |
1063 QCOMPARE(res.isValid(), true); |
1390 QCOMPARE(res.isValid(), true); |
1064 QCOMPARE(res.toString().startsWith("item"), false); |
1391 QCOMPARE(res.toString().startsWith("item"), false); |
1065 |
1392 |
1066 cp->setFilterKeyColumn(1); |
1393 cp->setFilterKeyColumn(1); |
1067 QCOMPARE(cp->filterKeyColumn (), 1); |
1394 QCOMPARE(cp->filterKeyColumn (), 1); |
|
1395 cp->setFilterKeyColumn(1); |
1068 cp->setFilterKeyColumn(0); |
1396 cp->setFilterKeyColumn(0); |
1069 |
1397 |
1070 cp->setFilterRole(Qt::UserRole+1); |
1398 cp->setFilterRole(Qt::UserRole+1); |
1071 QCOMPARE(cp->filterRole(), Qt::UserRole+1); |
1399 QCOMPARE(cp->filterRole(), Qt::UserRole+1); |
|
1400 cp->setFilterRole(Qt::UserRole+1); |
1072 cp->setFilterRole(Qt::DisplayRole); |
1401 cp->setFilterRole(Qt::DisplayRole); |
1073 |
1402 |
1074 regexp = QRegExp("ITEM*", Qt::CaseInsensitive, QRegExp::Wildcard); |
1403 regexp = QRegExp("ITEM*", Qt::CaseInsensitive, QRegExp::Wildcard); |
1075 cp->setFilterRegExp(regexp); |
1404 cp->setFilterRegExp(regexp); |
1076 QVERIFY(cp->filterRegExp() == regexp); |
1405 QVERIFY(cp->filterRegExp() == regexp); |
1077 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1406 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1078 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseInsensitive); |
1407 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseInsensitive); |
|
1408 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1079 |
1409 |
1080 idx = cp->index(1, 0); |
1410 idx = cp->index(1, 0); |
1081 res = cp->data(idx, Qt::DisplayRole); |
1411 res = cp->data(idx, Qt::DisplayRole); |
1082 QCOMPARE(res.isValid(), true); |
1412 QCOMPARE(res.isValid(), true); |
1083 QCOMPARE(res.toString().startsWith("item"), true); |
1413 QCOMPARE(res.toString().startsWith("item"), true); |