292 { |
304 { |
293 int totalsize = 1000; |
305 int totalsize = 1000; |
294 int bufferSize = 100; |
306 int bufferSize = 100; |
295 bmh = new BMHelper(totalsize); |
307 bmh = new BMHelper(totalsize); |
296 bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize); |
308 bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize); |
|
309 bm->aboutToRemoveItem(0); |
|
310 bmh->remove(0); |
|
311 bm->removedItem(0); |
|
312 QVERIFY(bmh->isIntergal(bufferSize)); |
297 totalsize--; |
313 totalsize--; |
298 bmh->itemCountChanged(0, true, totalsize); |
314 QCOMPARE(bmh->totalSize(), totalsize); |
299 bm->itemCountChanged(0, true, totalsize); |
315 |
300 QVERIFY(bmh->isIntergal(bufferSize)); |
316 bm->aboutToRemoveItem(150); |
301 |
317 bmh->remove(150); |
|
318 bm->removedItem(150); |
|
319 QVERIFY(bmh->isIntergal(bufferSize)); |
302 totalsize--; |
320 totalsize--; |
303 bmh->itemCountChanged(150, true, totalsize); |
321 QCOMPARE(bmh->totalSize(), totalsize); |
304 bm->itemCountChanged(150, true, totalsize); |
322 |
305 QVERIFY(bmh->isIntergal(bufferSize)); |
323 bm->setPosition(100); |
306 |
324 bm->aboutToRemoveItem(150); |
|
325 bmh->remove(150); |
|
326 bm->removedItem(150); |
|
327 QVERIFY(bmh->isIntergal(bufferSize)); |
307 totalsize--; |
328 totalsize--; |
|
329 QCOMPARE(bmh->totalSize(), totalsize); |
|
330 |
|
331 bm->setPosition(891); |
|
332 bm->aboutToRemoveItem(150); |
|
333 bmh->remove(150); |
|
334 bm->removedItem(150); |
|
335 QVERIFY(bmh->isIntergal(bufferSize)); |
|
336 totalsize--; |
|
337 QCOMPARE(bmh->totalSize(), totalsize); |
|
338 |
|
339 bm->setPosition(0); |
|
340 bm->aboutToRemoveItem(150); |
|
341 bmh->remove(150); |
|
342 bm->removedItem(150); |
|
343 QVERIFY(bmh->isIntergal(bufferSize)); |
|
344 totalsize--; |
|
345 QCOMPARE(bmh->totalSize(), totalsize); |
|
346 |
|
347 bm->setPosition(900); |
|
348 bm->aboutToRemoveItem(890); |
|
349 bmh->remove(890); |
|
350 bm->removedItem(890); |
|
351 QVERIFY(bmh->isIntergal(bufferSize)); |
|
352 totalsize--; |
|
353 QCOMPARE(bmh->totalSize(), totalsize); |
|
354 |
|
355 bm->setPosition(totalsize); |
|
356 bm->aboutToRemoveItem(totalsize); |
|
357 bmh->remove(totalsize); |
|
358 bm->removedItem(totalsize); |
|
359 QVERIFY(bmh->isIntergal(bufferSize)); |
|
360 // totalsize--;//no item remove since totalsize is outside |
|
361 QCOMPARE(bmh->totalSize(), totalsize); |
|
362 |
|
363 bm->setPosition(totalsize); |
|
364 bm->aboutToRemoveItem(totalsize-1); |
|
365 bmh->remove(totalsize-1); |
|
366 bm->removedItem(totalsize-1); |
|
367 QVERIFY(bmh->isIntergal(bufferSize)); |
|
368 totalsize--; |
|
369 QCOMPARE(bmh->totalSize(), totalsize); |
|
370 |
|
371 bm->setPosition(totalsize+200); |
|
372 bm->aboutToRemoveItem(totalsize+200); |
|
373 bmh->remove(totalsize+200); |
|
374 bm->removedItem(totalsize+200); |
|
375 QVERIFY(bmh->isIntergal(bufferSize)); |
|
376 // totalsize--; //no item remove since totalsize+200 is outside |
|
377 QCOMPARE(bmh->totalSize(), totalsize); |
|
378 |
|
379 bm->aboutToRemoveItem(-20); |
|
380 bmh->remove(-20); |
|
381 bm->removedItem(-20); |
|
382 QVERIFY(bmh->isIntergal(bufferSize)); |
|
383 // totalsize--; //no item remove since totalsize+200 is outside |
|
384 QCOMPARE(bmh->totalSize(), totalsize); |
|
385 |
|
386 |
|
387 //insert |
|
388 |
|
389 bm->setPosition(0); |
|
390 bm->aboutToInsertItem(0); |
|
391 bmh->insert(0); |
|
392 bm->insertedItem(0); |
|
393 QVERIFY(bmh->isIntergal(bufferSize)); |
|
394 totalsize++; |
|
395 QCOMPARE(bmh->totalSize(), totalsize); |
|
396 |
|
397 bm->aboutToInsertItem(50); |
|
398 bmh->insert(50); |
|
399 bm->insertedItem(50); |
|
400 QVERIFY(bmh->isIntergal(bufferSize)); |
|
401 totalsize++; |
|
402 QCOMPARE(bmh->totalSize(), totalsize); |
|
403 |
308 bm->setPosition(100); |
404 bm->setPosition(100); |
309 bmh->itemCountChanged(150, true, totalsize); |
405 bm->aboutToInsertItem(80); |
310 bm->itemCountChanged(150, true, totalsize); |
406 bmh->insert(80); |
311 QVERIFY(bmh->isIntergal(bufferSize)); |
407 bm->insertedItem(80); |
312 |
408 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++; |
409 totalsize++; |
357 bm->setPosition(0); |
410 QCOMPARE(bmh->totalSize(), totalsize); |
358 bmh->itemCountChanged(0, false, totalsize); |
411 |
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); |
412 bm->setPosition(500); |
375 bmh->itemCountChanged(480, false, totalsize); |
413 bm->aboutToInsertItem(80); |
376 bm->itemCountChanged(480, false, totalsize); |
414 bmh->insert(80); |
377 QVERIFY(bmh->isIntergal(bufferSize)); |
415 bm->insertedItem(80); |
378 |
416 QVERIFY(bmh->isIntergal(bufferSize)); |
379 totalsize++; |
417 totalsize++; |
|
418 QCOMPARE(bmh->totalSize(), totalsize); |
|
419 |
|
420 bm->setPosition(500); |
|
421 bm->aboutToInsertItem(480); |
|
422 bmh->insert(480); |
|
423 bm->insertedItem(480); |
|
424 QVERIFY(bmh->isIntergal(bufferSize)); |
|
425 totalsize++; |
|
426 QCOMPARE(bmh->totalSize(), totalsize); |
|
427 |
380 bm->setPosition(totalsize-20); |
428 bm->setPosition(totalsize-20); |
381 bmh->itemCountChanged(totalsize, false, totalsize); |
429 bm->aboutToInsertItem(totalsize); |
382 bm->itemCountChanged(totalsize, false, totalsize); |
430 bmh->insert(totalsize); |
383 QVERIFY(bmh->isIntergal(bufferSize)); |
431 bm->insertedItem(totalsize); |
384 |
432 QVERIFY(bmh->isIntergal(bufferSize)); |
385 totalsize=totalsize+10; |
433 totalsize++; |
|
434 QCOMPARE(bmh->totalSize(), totalsize); |
|
435 |
386 bm->setPosition(totalsize-20); |
436 bm->setPosition(totalsize-20); |
387 bmh->itemCountChanged(totalsize, false, totalsize); |
437 bm->aboutToInsertItem(totalsize+20); |
388 bm->itemCountChanged(totalsize, false, totalsize); |
438 bmh->insert(totalsize+20); |
389 QVERIFY(bmh->isIntergal(bufferSize)); |
439 bm->insertedItem(totalsize+20); |
390 |
440 QVERIFY(bmh->isIntergal(bufferSize)); |
391 totalsize=totalsize+10; |
441 // totalsize++; //no insert |
392 bm->setPosition(20); |
442 QCOMPARE(bmh->totalSize(), totalsize); |
393 bmh->itemCountChanged(totalsize, false, totalsize); |
443 |
394 bm->itemCountChanged(totalsize, false, totalsize); |
|
395 QVERIFY(bmh->isIntergal(bufferSize)); |
|
396 |
|
397 totalsize=totalsize+10; |
|
398 bm->setPosition(totalsize/2-20); |
|
399 bmh->itemCountChanged(totalsize, false, totalsize); |
|
400 bm->itemCountChanged(totalsize, false, totalsize); |
|
401 QVERIFY(bmh->isIntergal(bufferSize)); |
|
402 } |
444 } |
403 |
445 |
404 void TestCacheProxy::testBM_ResizeCache() |
446 void TestCacheProxy::testBM_ResizeCache() |
405 { |
447 { |
406 int totalsize = 1000; |
448 int totalsize = 1000; |
621 QString s = "NEWITEM"; |
663 QString s = "NEWITEM"; |
622 list.append( QPair< QVariant, int >(s, Qt::DisplayRole) ); |
664 list.append( QPair< QVariant, int >(s, Qt::DisplayRole) ); |
623 |
665 |
624 dph->testUpdate(0, &list, false); //update shouldn't change - no item |
666 dph->testUpdate(0, &list, false); //update shouldn't change - no item |
625 dph->testUpdate(-1, &list, true); //update shouldn't change - no item |
667 dph->testUpdate(-1, &list, true); //update shouldn't change - no item |
|
668 dph->testUpdate(-1, s, Qt::DisplayRole, true); //update shouldn't change - no item |
|
669 dph->testUpdateIcon(-1, s); |
626 dph->testUpdate(120000, &list, false); //update shouldn't change - no item |
670 dph->testUpdate(120000, &list, false); //update shouldn't change - no item |
627 res = dph->data(idx, Qt::DisplayRole); |
671 res = dph->data(idx, Qt::DisplayRole); |
628 QVERIFY(res.isValid() == false); |
672 QVERIFY(res.isValid() == false); |
629 QVERIFY(dph->getObserverDataUpdated().count() == 0); |
673 QVERIFY(dph->getObserverDataUpdated().count() == 0); |
630 |
674 |
631 dph->testNewItem(&list, false); |
675 dph->testNewItem(&list, false); |
632 QList< QPair< int, int > > resList = dph->getSignalRowsAboutToBeInserted(); |
676 QList< QPair< int, int > > resList = dph->getSignalRowsAboutToBeInserted(); |
633 QVERIFY(resList.count() == 1); |
677 QVERIFY(resList.count() == 1); |
634 QVERIFY(resList[0].first == 0); //for item 0 |
678 QVERIFY(resList[0].first == 0); //for item 0 |
635 QVERIFY(resList[0].second == 0); //for item 0 |
679 QVERIFY(resList[0].second == 0); //for item 0 |
636 resList = dph->getSignalRowsInserted(); |
680 resList = dph->getSignalRowsInserted(); |
637 QVERIFY(resList.count() == 1); |
681 QVERIFY(resList.count() == 1); |
638 QVERIFY(resList[0].first == 0); //for item 0 |
682 QVERIFY(resList[0].first == 0); //for item 0 |
639 QVERIFY(resList[0].second == 0); //for item 0 |
683 QVERIFY(resList[0].second == 0); //for item 0 |
|
684 |
|
685 dph->testUpdateIcon(0, s, false); |
|
686 dph->testUpdateIcon(0, s, true); |
|
687 res = dph->data(idx, Qt::DecorationRole); |
|
688 QCOMPARE(res.isValid(), true); |
|
689 QVERIFY(res == s); |
|
690 QCOMPARE(dph->getSignalDataUpdated().count(), 1); |
640 |
691 |
641 QVERIFY(dph->rowCount() == 1); |
692 QVERIFY(dph->rowCount() == 1); |
642 |
693 |
643 idx = dph->index(0,0); |
694 idx = dph->index(0,0); |
644 res = dph->data(idx, Qt::DisplayRole); |
695 res = dph->data(idx, Qt::DisplayRole); |
741 QVERIFY(resList[0].first == 100); |
792 QVERIFY(resList[0].first == 100); |
742 QVERIFY(resList[0].second == 100); |
793 QVERIFY(resList[0].second == 100); |
743 |
794 |
744 dph->getSignalRowsInserted(); |
795 dph->getSignalRowsInserted(); |
745 dph->getSignalRowsRemoved(); |
796 dph->getSignalRowsRemoved(); |
746 dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 puts it at begining |
797 dph->testInsertItem(0, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with 0 puts at begining |
747 resList = dph->getSignalRowsInserted(); |
798 resList = dph->getSignalRowsInserted(); |
748 QVERIFY(resList.count() == 1); |
799 QVERIFY(resList.count() == 1); |
749 QVERIFY(resList[0].first == 0); |
800 QVERIFY(resList[0].first == 0); |
750 QVERIFY(resList[0].second == 0); |
801 QVERIFY(resList[0].second == 0); |
|
802 |
|
803 dph->getSignalRowsInserted(); |
|
804 dph->getSignalRowsRemoved(); |
|
805 dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 not adds to collection |
|
806 resList = dph->getSignalRowsInserted(); |
|
807 QVERIFY(resList.count() == 0); |
751 dph->testRemoveItem(-10); |
808 dph->testRemoveItem(-10); |
752 resList = dph->getSignalRowsRemoved(); |
809 resList = dph->getSignalRowsRemoved(); |
753 QVERIFY(resList.count() == 0); |
810 QVERIFY(resList.count() == 0); |
754 |
811 |
755 dph->getSignalRowsInserted(); |
812 dph->getSignalRowsInserted(); |
756 dph->getSignalRowsRemoved(); |
813 dph->getSignalRowsRemoved(); |
757 dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range puts it at end |
814 dph->testInsertItem(dph->rowCount(), QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert at dph->rowCount() puts at end |
758 resList = dph->getSignalRowsInserted(); |
815 resList = dph->getSignalRowsInserted(); |
759 QVERIFY(resList.count() == 1); |
816 QVERIFY(resList.count() == 1); |
760 QVERIFY(resList[0].first == dph->rowCount()-1); |
817 QVERIFY(resList[0].first == dph->rowCount()-1); |
761 QVERIFY(resList[0].second == dph->rowCount()-1); |
818 QVERIFY(resList[0].second == dph->rowCount()-1); |
|
819 |
|
820 dph->getSignalRowsInserted(); |
|
821 dph->getSignalRowsRemoved(); |
|
822 dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range not adds to collection |
|
823 resList = dph->getSignalRowsInserted(); |
|
824 QVERIFY(resList.count() == 0); |
762 dph->testRemoveItem(100000); |
825 dph->testRemoveItem(100000); |
763 resList = dph->getSignalRowsRemoved(); |
826 resList = dph->getSignalRowsRemoved(); |
764 QVERIFY(resList.count() == 0); |
827 QVERIFY(resList.count() == 0); |
765 |
828 |
766 idx = dph->index(579,0); |
829 idx = dph->index(579,0); |
767 QMap<int, QVariant> it = dph->itemData(idx); |
830 QMap<int, QVariant> it = dph->itemData(idx); |
768 QCOMPARE(it.size(), 4); |
831 QCOMPARE(it.size(), 4); |
769 QCOMPARE(it.contains(Qt::DisplayRole), true); |
832 QCOMPARE(it.contains(Qt::DisplayRole), true); |
770 QVariant r2 = it[Qt::DisplayRole]; |
833 QVariant r2 = it[Qt::DisplayRole]; |
771 QCOMPARE(r2.isValid(), true); |
834 QCOMPARE(r2.isValid(), true); |
|
835 |
|
836 idx = dph->index(-10,0); |
|
837 it = dph->itemData(idx); |
|
838 |
772 res = dph->data(idx, Qt::DisplayRole); |
839 res = dph->data(idx, Qt::DisplayRole); |
773 QCOMPARE(res.isValid(), true); |
840 QCOMPARE(res.isValid(), false); |
774 QCOMPARE(res.toString(), r2.toString()); |
|
775 |
841 |
776 } |
842 } |
777 |
843 |
778 void TestCacheProxy::testDP_QPixmapPool() |
844 void TestCacheProxy::testDP_QPixmapPool() |
779 { |
845 { |
1053 |
1152 |
1054 QRegExp regexp = QRegExp("ITEM*", Qt::CaseSensitive, QRegExp::Wildcard); |
1153 QRegExp regexp = QRegExp("ITEM*", Qt::CaseSensitive, QRegExp::Wildcard); |
1055 |
1154 |
1056 cp->setFilterRegExp(regexp); |
1155 cp->setFilterRegExp(regexp); |
1057 QVERIFY(cp->filterRegExp() == regexp); |
1156 QVERIFY(cp->filterRegExp() == regexp); |
|
1157 cp->setFilterRegExp(regexp); |
1058 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1158 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1059 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseSensitive); |
1159 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseSensitive); |
|
1160 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
|
1161 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
1162 cp->setFilterCaseSensitivity(Qt::CaseSensitive); |
1060 |
1163 |
1061 idx = cp->index(1, 0); |
1164 idx = cp->index(1, 0); |
1062 res = cp->data(idx, Qt::DisplayRole); |
1165 res = cp->data(idx, Qt::DisplayRole); |
1063 QCOMPARE(res.isValid(), true); |
1166 QCOMPARE(res.isValid(), true); |
1064 QCOMPARE(res.toString().startsWith("item"), false); |
1167 QCOMPARE(res.toString().startsWith("item"), false); |
1065 |
1168 |
1066 cp->setFilterKeyColumn(1); |
1169 cp->setFilterKeyColumn(1); |
1067 QCOMPARE(cp->filterKeyColumn (), 1); |
1170 QCOMPARE(cp->filterKeyColumn (), 1); |
|
1171 cp->setFilterKeyColumn(1); |
1068 cp->setFilterKeyColumn(0); |
1172 cp->setFilterKeyColumn(0); |
1069 |
1173 |
1070 cp->setFilterRole(Qt::UserRole+1); |
1174 cp->setFilterRole(Qt::UserRole+1); |
1071 QCOMPARE(cp->filterRole(), Qt::UserRole+1); |
1175 QCOMPARE(cp->filterRole(), Qt::UserRole+1); |
|
1176 cp->setFilterRole(Qt::UserRole+1); |
1072 cp->setFilterRole(Qt::DisplayRole); |
1177 cp->setFilterRole(Qt::DisplayRole); |
1073 |
1178 |
1074 regexp = QRegExp("ITEM*", Qt::CaseInsensitive, QRegExp::Wildcard); |
1179 regexp = QRegExp("ITEM*", Qt::CaseInsensitive, QRegExp::Wildcard); |
1075 cp->setFilterRegExp(regexp); |
1180 cp->setFilterRegExp(regexp); |
1076 QVERIFY(cp->filterRegExp() == regexp); |
1181 QVERIFY(cp->filterRegExp() == regexp); |
1077 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1182 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1078 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseInsensitive); |
1183 QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseInsensitive); |
|
1184 cp->setFilterCaseSensitivity(Qt::CaseInsensitive); |
1079 |
1185 |
1080 idx = cp->index(1, 0); |
1186 idx = cp->index(1, 0); |
1081 res = cp->data(idx, Qt::DisplayRole); |
1187 res = cp->data(idx, Qt::DisplayRole); |
1082 QCOMPARE(res.isValid(), true); |
1188 QCOMPARE(res.isValid(), true); |
1083 QCOMPARE(res.toString().startsWith("item"), true); |
1189 QCOMPARE(res.toString().startsWith("item"), true); |