--- a/hgcacheproxymodel/tsrc/unit/test_hgcacheproxydatamodel.cpp Fri May 14 16:57:01 2010 +0300
+++ b/hgcacheproxymodel/tsrc/unit/test_hgcacheproxydatamodel.cpp Thu May 27 13:59:05 2010 +0300
@@ -13,7 +13,7 @@
*
* Description:
*
-* Version : %version: 5 %
+* Version : %version: 8 %
*/
#include <QtTest/QtTest>
#include <hgwidgets/hgcacheproxymodel.h>
@@ -155,10 +155,22 @@
totalsize = 100;
bufferSize = 200;
bmh = new BMHelper(totalsize);
- bm = new HgBufferManager(bmh, bufferSize, 40, -20, totalsize);
+ bm = new HgBufferManager(bmh, bufferSize, 40, 2*bufferSize, totalsize);
+ bufferSize = 300;
+ bm->resizeCache(bufferSize, 20);
+ bm->setPosition(5);
+ QVERIFY(bmh->isIntergal(bufferSize));
+ bm->setPosition(5000);
+ QVERIFY(bmh->isIntergal(bufferSize));
delete bmh;
delete bm;
+ bmh = new BMHelper(totalsize);
+ bm = new HgBufferManager(bmh, bufferSize, 40, -10, totalsize);
+ delete bmh;
+ delete bm;
+
+
totalsize = 1000;
bufferSize = 100;
bmh = new BMHelper(totalsize);
@@ -294,111 +306,141 @@
int bufferSize = 100;
bmh = new BMHelper(totalsize);
bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize);
- totalsize--;
- bmh->itemCountChanged(0, true, totalsize);
- bm->itemCountChanged(0, true, totalsize);
+ bm->aboutToRemoveItem(0);
+ bmh->remove(0);
+ bm->removedItem(0);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize--;
- bmh->itemCountChanged(150, true, totalsize);
- bm->itemCountChanged(150, true, totalsize);
+ bm->aboutToRemoveItem(150);
+ bmh->remove(150);
+ bm->removedItem(150);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize--;
bm->setPosition(100);
- bmh->itemCountChanged(150, true, totalsize);
- bm->itemCountChanged(150, true, totalsize);
+ bm->aboutToRemoveItem(150);
+ bmh->remove(150);
+ bm->removedItem(150);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize--;
bm->setPosition(891);
- bmh->itemCountChanged(150, true, totalsize);
- bm->itemCountChanged(150, true, totalsize);
+ bm->aboutToRemoveItem(150);
+ bmh->remove(150);
+ bm->removedItem(150);
QVERIFY(bmh->isIntergal(bufferSize));
-
totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
+
+ bm->setPosition(0);
+ bm->aboutToRemoveItem(150);
+ bmh->remove(150);
+ bm->removedItem(150);
+ QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
+
bm->setPosition(900);
- bmh->itemCountChanged(890, true, totalsize);
- bm->itemCountChanged(890, true, totalsize);
+ bm->aboutToRemoveItem(890);
+ bmh->remove(890);
+ bm->removedItem(890);
QVERIFY(bmh->isIntergal(bufferSize));
-
totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
+
bm->setPosition(totalsize);
- bmh->itemCountChanged(totalsize, true, totalsize);
- bm->itemCountChanged(totalsize, true, totalsize);
+ bm->aboutToRemoveItem(totalsize);
+ bmh->remove(totalsize);
+ bm->removedItem(totalsize);
QVERIFY(bmh->isIntergal(bufferSize));
+// totalsize--;//no item remove since totalsize is outside
+ QCOMPARE(bmh->totalSize(), totalsize);
+ bm->setPosition(totalsize);
+ bm->aboutToRemoveItem(totalsize-1);
+ bmh->remove(totalsize-1);
+ bm->removedItem(totalsize-1);
+ QVERIFY(bmh->isIntergal(bufferSize));
totalsize--;
+ QCOMPARE(bmh->totalSize(), totalsize);
+
bm->setPosition(totalsize+200);
- bmh->itemCountChanged(totalsize+200, true, totalsize);
- bm->itemCountChanged(totalsize+200, true, totalsize);
+ bm->aboutToRemoveItem(totalsize+200);
+ bmh->remove(totalsize+200);
+ bm->removedItem(totalsize+200);
QVERIFY(bmh->isIntergal(bufferSize));
+// totalsize--; //no item remove since totalsize+200 is outside
+ QCOMPARE(bmh->totalSize(), totalsize);
+
+ bm->aboutToRemoveItem(-20);
+ bmh->remove(-20);
+ bm->removedItem(-20);
+ QVERIFY(bmh->isIntergal(bufferSize));
+// totalsize--; //no item remove since totalsize+200 is outside
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize= totalsize - 10;
- bm->setPosition(0);
- bmh->itemCountChanged(0, true, totalsize);
- bm->itemCountChanged(0, true, totalsize);
- QVERIFY(bmh->isIntergal(bufferSize));
-
- totalsize= totalsize - 10;
- bm->setPosition(totalsize);
- bmh->itemCountChanged(totalsize, true, totalsize);
- bm->itemCountChanged(totalsize, true, totalsize);
- QVERIFY(bmh->isIntergal(bufferSize));
+ //insert
- totalsize= totalsize - 10;
- bm->setPosition(totalsize/2);
- bmh->itemCountChanged(totalsize/2, true, totalsize);
- bm->itemCountChanged(totalsize/2, true, totalsize);
+ bm->setPosition(0);
+ bm->aboutToInsertItem(0);
+ bmh->insert(0);
+ bm->insertedItem(0);
QVERIFY(bmh->isIntergal(bufferSize));
-
totalsize++;
- bm->setPosition(0);
- bmh->itemCountChanged(0, false, totalsize);
- bm->itemCountChanged(0, false, totalsize);
- QVERIFY(bmh->isIntergal(bufferSize));
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize++;
- bmh->itemCountChanged(50, false, totalsize);
- bm->itemCountChanged(50, false, totalsize);
+ bm->aboutToInsertItem(50);
+ bmh->insert(50);
+ bm->insertedItem(50);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize++;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize++;
bm->setPosition(100);
- bmh->itemCountChanged(80, false, totalsize);
- bm->itemCountChanged(80, false, totalsize);
+ bm->aboutToInsertItem(80);
+ bmh->insert(80);
+ bm->insertedItem(80);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize++;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize++;
bm->setPosition(500);
- bmh->itemCountChanged(480, false, totalsize);
- bm->itemCountChanged(480, false, totalsize);
+ bm->aboutToInsertItem(80);
+ bmh->insert(80);
+ bm->insertedItem(80);
QVERIFY(bmh->isIntergal(bufferSize));
-
- totalsize++;
- bm->setPosition(totalsize-20);
- bmh->itemCountChanged(totalsize, false, totalsize);
- bm->itemCountChanged(totalsize, false, totalsize);
- QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize++;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize=totalsize+10;
- bm->setPosition(totalsize-20);
- bmh->itemCountChanged(totalsize, false, totalsize);
- bm->itemCountChanged(totalsize, false, totalsize);
+ bm->setPosition(500);
+ bm->aboutToInsertItem(480);
+ bmh->insert(480);
+ bm->insertedItem(480);
QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize++;
+ QCOMPARE(bmh->totalSize(), totalsize);
- totalsize=totalsize+10;
- bm->setPosition(20);
- bmh->itemCountChanged(totalsize, false, totalsize);
- bm->itemCountChanged(totalsize, false, totalsize);
+ bm->setPosition(totalsize-20);
+ bm->aboutToInsertItem(totalsize);
+ bmh->insert(totalsize);
+ bm->insertedItem(totalsize);
QVERIFY(bmh->isIntergal(bufferSize));
-
- totalsize=totalsize+10;
- bm->setPosition(totalsize/2-20);
- bmh->itemCountChanged(totalsize, false, totalsize);
- bm->itemCountChanged(totalsize, false, totalsize);
- QVERIFY(bmh->isIntergal(bufferSize));
+ totalsize++;
+ QCOMPARE(bmh->totalSize(), totalsize);
+
+ bm->setPosition(totalsize-20);
+ bm->aboutToInsertItem(totalsize+20);
+ bmh->insert(totalsize+20);
+ bm->insertedItem(totalsize+20);
+ QVERIFY(bmh->isIntergal(bufferSize));
+// totalsize++; //no insert
+ QCOMPARE(bmh->totalSize(), totalsize);
+
}
void TestCacheProxy::testBM_ResizeCache()
@@ -623,11 +665,13 @@
dph->testUpdate(0, &list, false); //update shouldn't change - no item
dph->testUpdate(-1, &list, true); //update shouldn't change - no item
+ dph->testUpdate(-1, s, Qt::DisplayRole, true); //update shouldn't change - no item
+ dph->testUpdateIcon(-1, s);
dph->testUpdate(120000, &list, false); //update shouldn't change - no item
res = dph->data(idx, Qt::DisplayRole);
QVERIFY(res.isValid() == false);
QVERIFY(dph->getObserverDataUpdated().count() == 0);
-
+
dph->testNewItem(&list, false);
QList< QPair< int, int > > resList = dph->getSignalRowsAboutToBeInserted();
QVERIFY(resList.count() == 1);
@@ -637,6 +681,13 @@
QVERIFY(resList.count() == 1);
QVERIFY(resList[0].first == 0); //for item 0
QVERIFY(resList[0].second == 0); //for item 0
+
+ dph->testUpdateIcon(0, s, false);
+ dph->testUpdateIcon(0, s, true);
+ res = dph->data(idx, Qt::DecorationRole);
+ QCOMPARE(res.isValid(), true);
+ QVERIFY(res == s);
+ QCOMPARE(dph->getSignalDataUpdated().count(), 1);
QVERIFY(dph->rowCount() == 1);
@@ -743,22 +794,34 @@
dph->getSignalRowsInserted();
dph->getSignalRowsRemoved();
- dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 puts it at begining
+ dph->testInsertItem(0, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with 0 puts at begining
resList = dph->getSignalRowsInserted();
- QVERIFY(resList.count() == 1);
+ QVERIFY(resList.count() == 1);
QVERIFY(resList[0].first == 0);
QVERIFY(resList[0].second == 0);
+
+ dph->getSignalRowsInserted();
+ dph->getSignalRowsRemoved();
+ dph->testInsertItem(-10, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with -10 not adds to collection
+ resList = dph->getSignalRowsInserted();
+ QVERIFY(resList.count() == 0);
dph->testRemoveItem(-10);
resList = dph->getSignalRowsRemoved();
QVERIFY(resList.count() == 0);
-
+
dph->getSignalRowsInserted();
dph->getSignalRowsRemoved();
- dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range puts it at end
+ dph->testInsertItem(dph->rowCount(), QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert at dph->rowCount() puts at end
resList = dph->getSignalRowsInserted();
QVERIFY(resList.count() == 1);
QVERIFY(resList[0].first == dph->rowCount()-1);
- QVERIFY(resList[0].second == dph->rowCount()-1);
+ QVERIFY(resList[0].second == dph->rowCount()-1);
+
+ dph->getSignalRowsInserted();
+ dph->getSignalRowsRemoved();
+ dph->testInsertItem(100000, QPair< QVariant, int >(QString(""), Qt::DisplayRole), false); //insert with beyond range not adds to collection
+ resList = dph->getSignalRowsInserted();
+ QVERIFY(resList.count() == 0);
dph->testRemoveItem(100000);
resList = dph->getSignalRowsRemoved();
QVERIFY(resList.count() == 0);
@@ -769,9 +832,12 @@
QCOMPARE(it.contains(Qt::DisplayRole), true);
QVariant r2 = it[Qt::DisplayRole];
QCOMPARE(r2.isValid(), true);
+
+ idx = dph->index(-10,0);
+ it = dph->itemData(idx);
+
res = dph->data(idx, Qt::DisplayRole);
- QCOMPARE(res.isValid(), true);
- QCOMPARE(res.toString(), r2.toString());
+ QCOMPARE(res.isValid(), false);
}
@@ -838,13 +904,21 @@
cp->setDataProvider(dph);
QVERIFY(cp->DataProvider() == dph);
+
+ QList< QPair< QVariant, int > > list;
+ QString s = "NEWITEM";
+ list.append( QPair< QVariant, int >(s, Qt::DisplayRole) );
+ dph->testNewItem(&list, false);
+
+ dph->testRemoveItems(0, 1);//should remove item
+
}
void TestCacheProxy::testCP_SignalsForward()
{
cp = new HgCacheProxyModel();
cph = new CacheProxyHelper(cp);
- dph = new DataProviderHelper(200);
+ dph = new DataProviderHelper(200);
cp->setDataProvider(dph, 50, 20);
QList< QPair< int, int > > resList = cph->getSignalDataChanged();
@@ -884,8 +958,8 @@
QVERIFY(cph->getSignalModelAboutToBeReset() == true);
QVERIFY(cph->getSignalModelReset() == true);
QVERIFY(cp->columnCount() == 1);
- QVERIFY(cp->rowCount() == 1000);
-
+ QVERIFY(cp->rowCount() == 1000);
+
}
void TestCacheProxy::testCP_ResizeCache()
@@ -893,6 +967,7 @@
cp = new HgCacheProxyModel();
cph = new CacheProxyHelper(cp);
dph = new DataProviderHelper(200);
+ cp->resizeCache(100, 20);
cp->setDataProvider(dph, 50, 20);
dph->getLastRelease();
dph->getLastRequest();
@@ -971,8 +1046,26 @@
res = cp->data(idx, v);
QCOMPARE(res.isValid(), true);
QCOMPARE(res.toInt(), v);
+
+ dph->getLastRelease();
+ dph->getLastRequest();
+ cp->release(0, 100);
+ QCOMPARE(dph->getLastRelease().count(), 101);
+ cp->release(-10, 0);
+ QCOMPARE(dph->getLastRelease().count(), 1);
+ cp->release(10, -10);
+ QCOMPARE(dph->getLastRelease().count(), 11);
+ cp->request(0, 100);
+ QCOMPARE(dph->getLastRequest().count(), 101);
+ cp->request(-10, 0);
+ QCOMPARE(dph->getLastRequest().count(), 1);
+ cp->request(-10, 10, HgBufferManagerObserver::HgRequestOrderDescending);
+ QCOMPARE(dph->getLastRequest().count(), 11);
+
+ cp->setDataProvider(NULL, 50, 20);
+ res = cp->data(idx, v);
+ QCOMPARE(res.isValid(), false);
-
}
void TestCacheProxy::testCP_Sort()
@@ -984,6 +1077,7 @@
cp->setSortRole(Qt::UserRole+2);
QCOMPARE(cp->sortRole(), Qt::UserRole+2);
+ cp->setSortRole(Qt::UserRole+2);
cp->sort(0, Qt::AscendingOrder);
QCOMPARE(cp->sortColumn(), 0);
QCOMPARE(cp->sortOrder(), Qt::AscendingOrder);
@@ -1007,6 +1101,9 @@
cp->setSortRole(Qt::DisplayRole);
cp->setSortCaseSensitivity(Qt::CaseSensitive);
QCOMPARE(cp->sortCaseSensitivity(), Qt::CaseSensitive);
+ cp->setSortCaseSensitivity(Qt::CaseSensitive);
+ cp->setSortCaseSensitivity(Qt::CaseInsensitive);
+ cp->setSortCaseSensitivity(Qt::CaseSensitive);
cp->sort(0, Qt::AscendingOrder);
idx = cp->index(10, 0);
@@ -1022,12 +1119,14 @@
cp->setSortLocaleAware(true);
QCOMPARE(cp->isSortLocaleAware(), true);
+ cp->setSortLocaleAware(true);
cp->setSortLocaleAware(false);
QCOMPARE(cp->isSortLocaleAware(), false);
QString s = QString("AAA");
cp->setDynamicSortFilter(true);
QCOMPARE(cp->dynamicSortFilter(), true);
+ cp->setDynamicSortFilter(true);
cp->setSortRole(Qt::DisplayRole);
cp->setSortCaseSensitivity(Qt::CaseSensitive);
dph->testInsertItem(10, QPair< QVariant, int >(s, Qt::DisplayRole), false);
@@ -1055,8 +1154,12 @@
cp->setFilterRegExp(regexp);
QVERIFY(cp->filterRegExp() == regexp);
+ cp->setFilterRegExp(regexp);
cp->setFilterCaseSensitivity(Qt::CaseSensitive);
QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseSensitive);
+ cp->setFilterCaseSensitivity(Qt::CaseSensitive);
+ cp->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ cp->setFilterCaseSensitivity(Qt::CaseSensitive);
idx = cp->index(1, 0);
res = cp->data(idx, Qt::DisplayRole);
@@ -1065,10 +1168,12 @@
cp->setFilterKeyColumn(1);
QCOMPARE(cp->filterKeyColumn (), 1);
+ cp->setFilterKeyColumn(1);
cp->setFilterKeyColumn(0);
cp->setFilterRole(Qt::UserRole+1);
QCOMPARE(cp->filterRole(), Qt::UserRole+1);
+ cp->setFilterRole(Qt::UserRole+1);
cp->setFilterRole(Qt::DisplayRole);
regexp = QRegExp("ITEM*", Qt::CaseInsensitive, QRegExp::Wildcard);
@@ -1076,6 +1181,7 @@
QVERIFY(cp->filterRegExp() == regexp);
cp->setFilterCaseSensitivity(Qt::CaseInsensitive);
QCOMPARE(cp->filterCaseSensitivity(), Qt::CaseInsensitive);
+ cp->setFilterCaseSensitivity(Qt::CaseInsensitive);
idx = cp->index(1, 0);
res = cp->data(idx, Qt::DisplayRole);