hgcacheproxymodel/tsrc/unit/test_hgcacheproxydatamodel.cpp
changeset 3 c863538fcbb6
parent 2 49c70dcc3f17
child 6 1cdcc61142d2
equal deleted inserted replaced
2:49c70dcc3f17 3:c863538fcbb6
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 *  Version     : %version: 5 %
    16 *  Version     : %version: 8 %
    17 */
    17 */
    18 #include <QtTest/QtTest>
    18 #include <QtTest/QtTest>
    19 #include <hgwidgets/hgcacheproxymodel.h>
    19 #include <hgwidgets/hgcacheproxymodel.h>
    20 #include "test_hgcacheproxydatamodel.h"
    20 #include "test_hgcacheproxydatamodel.h"
    21 
    21 
   153     delete bm;
   153     delete bm;
   154     
   154     
   155     totalsize = 100;
   155     totalsize = 100;
   156     bufferSize = 200;
   156     bufferSize = 200;
   157     bmh = new BMHelper(totalsize);
   157     bmh = new BMHelper(totalsize);
   158     bm = new HgBufferManager(bmh, bufferSize, 40, -20, totalsize);
   158     bm = new HgBufferManager(bmh, bufferSize, 40, 2*bufferSize, totalsize);    
       
   159     bufferSize = 300;
       
   160     bm->resizeCache(bufferSize, 20);
       
   161     bm->setPosition(5);
       
   162     QVERIFY(bmh->isIntergal(bufferSize));
       
   163     bm->setPosition(5000);
       
   164     QVERIFY(bmh->isIntergal(bufferSize));
   159     delete bmh;
   165     delete bmh;
   160     delete bm;
   166     delete bm;
   161 
   167 
       
   168     bmh = new BMHelper(totalsize);
       
   169     bm = new HgBufferManager(bmh, bufferSize, 40, -10, totalsize);
       
   170     delete bmh;
       
   171     delete bm;
       
   172     
       
   173     
   162     totalsize = 1000;
   174     totalsize = 1000;
   163     bufferSize = 100;
   175     bufferSize = 100;
   164     bmh = new BMHelper(totalsize);
   176     bmh = new BMHelper(totalsize);
   165     bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize);
   177     bm = new HgBufferManager(bmh, bufferSize, 40, 0, totalsize);
   166     
   178     
   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 {
   836     cp->setDataProvider(dph);
   902     cp->setDataProvider(dph);
   837     QVERIFY(cp->DataProvider() == dph);
   903     QVERIFY(cp->DataProvider() == dph);
   838 
   904 
   839     cp->setDataProvider(dph);
   905     cp->setDataProvider(dph);
   840     QVERIFY(cp->DataProvider() == dph);
   906     QVERIFY(cp->DataProvider() == dph);
       
   907     
       
   908     QList< QPair< QVariant, int > > list;
       
   909     QString s = "NEWITEM";
       
   910     list.append( QPair< QVariant, int >(s, Qt::DisplayRole) );
       
   911     dph->testNewItem(&list, false);
       
   912     
       
   913     dph->testRemoveItems(0, 1);//should remove item
       
   914 
   841 }
   915 }
   842 
   916 
   843 void TestCacheProxy::testCP_SignalsForward()
   917 void TestCacheProxy::testCP_SignalsForward()
   844 {
   918 {
   845     cp = new HgCacheProxyModel();
   919     cp = new HgCacheProxyModel();
   846     cph = new CacheProxyHelper(cp);
   920     cph = new CacheProxyHelper(cp);
   847     dph = new DataProviderHelper(200);    
   921     dph = new DataProviderHelper(200);
   848     cp->setDataProvider(dph, 50, 20);
   922     cp->setDataProvider(dph, 50, 20);
   849     
   923     
   850     QList< QPair< int, int > > resList = cph->getSignalDataChanged();
   924     QList< QPair< int, int > > resList = cph->getSignalDataChanged();
   851     QVERIFY(resList.count() == 50);
   925     QVERIFY(resList.count() == 50);
   852     QVERIFY(resList[0].first == 0);
   926     QVERIFY(resList[0].first == 0);
   882     cph->getSignalModelReset();
   956     cph->getSignalModelReset();
   883     dph->resetModel();
   957     dph->resetModel();
   884     QVERIFY(cph->getSignalModelAboutToBeReset() == true);
   958     QVERIFY(cph->getSignalModelAboutToBeReset() == true);
   885     QVERIFY(cph->getSignalModelReset() == true);
   959     QVERIFY(cph->getSignalModelReset() == true);
   886     QVERIFY(cp->columnCount() == 1);
   960     QVERIFY(cp->columnCount() == 1);
   887     QVERIFY(cp->rowCount() == 1000);
   961     QVERIFY(cp->rowCount() == 1000);    
   888 
   962     
   889 }
   963 }
   890 
   964 
   891 void TestCacheProxy::testCP_ResizeCache()
   965 void TestCacheProxy::testCP_ResizeCache()
   892 {
   966 {
   893     cp = new HgCacheProxyModel();
   967     cp = new HgCacheProxyModel();
   894     cph = new CacheProxyHelper(cp);
   968     cph = new CacheProxyHelper(cp);
   895     dph = new DataProviderHelper(200);
   969     dph = new DataProviderHelper(200);
       
   970     cp->resizeCache(100, 20);
   896     cp->setDataProvider(dph, 50, 20);
   971     cp->setDataProvider(dph, 50, 20);
   897     dph->getLastRelease();
   972     dph->getLastRelease();
   898     dph->getLastRequest();
   973     dph->getLastRequest();
   899     cp->resizeCache(20, 5);
   974     cp->resizeCache(20, 5);
   900     
   975     
   969     map[v]=v;
  1044     map[v]=v;
   970     cp->setItemData(idx, map);
  1045     cp->setItemData(idx, map);
   971     res = cp->data(idx, v);
  1046     res = cp->data(idx, v);
   972     QCOMPARE(res.isValid(), true);
  1047     QCOMPARE(res.isValid(), true);
   973     QCOMPARE(res.toInt(), v);
  1048     QCOMPARE(res.toInt(), v);
   974 
  1049    
   975     
  1050     dph->getLastRelease();
       
  1051     dph->getLastRequest();
       
  1052     cp->release(0, 100);
       
  1053     QCOMPARE(dph->getLastRelease().count(), 101);
       
  1054     cp->release(-10, 0);
       
  1055     QCOMPARE(dph->getLastRelease().count(), 1);
       
  1056     cp->release(10, -10);
       
  1057     QCOMPARE(dph->getLastRelease().count(), 11);
       
  1058     cp->request(0, 100);
       
  1059     QCOMPARE(dph->getLastRequest().count(), 101);
       
  1060     cp->request(-10, 0);
       
  1061     QCOMPARE(dph->getLastRequest().count(), 1);
       
  1062     cp->request(-10, 10, HgBufferManagerObserver::HgRequestOrderDescending);
       
  1063     QCOMPARE(dph->getLastRequest().count(), 11);
       
  1064     
       
  1065     cp->setDataProvider(NULL, 50, 20);
       
  1066     res = cp->data(idx, v);
       
  1067     QCOMPARE(res.isValid(), false);
       
  1068 
   976 }
  1069 }
   977 
  1070 
   978 void TestCacheProxy::testCP_Sort()
  1071 void TestCacheProxy::testCP_Sort()
   979 {
  1072 {
   980     cp = new HgCacheProxyModel();
  1073     cp = new HgCacheProxyModel();
   982     dph = new DataProviderHelper(200);
  1075     dph = new DataProviderHelper(200);
   983     cp->setDataProvider(dph, 50, 20);
  1076     cp->setDataProvider(dph, 50, 20);
   984 
  1077 
   985     cp->setSortRole(Qt::UserRole+2);
  1078     cp->setSortRole(Qt::UserRole+2);
   986     QCOMPARE(cp->sortRole(), Qt::UserRole+2);
  1079     QCOMPARE(cp->sortRole(), Qt::UserRole+2);
       
  1080     cp->setSortRole(Qt::UserRole+2);
   987     cp->sort(0, Qt::AscendingOrder);
  1081     cp->sort(0, Qt::AscendingOrder);
   988     QCOMPARE(cp->sortColumn(), 0);
  1082     QCOMPARE(cp->sortColumn(), 0);
   989     QCOMPARE(cp->sortOrder(), Qt::AscendingOrder);
  1083     QCOMPARE(cp->sortOrder(), Qt::AscendingOrder);
   990     
  1084     
   991     QModelIndex idx = cp->index(10, 0);
  1085     QModelIndex idx = cp->index(10, 0);
  1005     QCOMPARE(res.toInt(), cp->rowCount(idx) -1 -50);
  1099     QCOMPARE(res.toInt(), cp->rowCount(idx) -1 -50);
  1006     
  1100     
  1007     cp->setSortRole(Qt::DisplayRole);
  1101     cp->setSortRole(Qt::DisplayRole);
  1008     cp->setSortCaseSensitivity(Qt::CaseSensitive);
  1102     cp->setSortCaseSensitivity(Qt::CaseSensitive);
  1009     QCOMPARE(cp->sortCaseSensitivity(), Qt::CaseSensitive);
  1103     QCOMPARE(cp->sortCaseSensitivity(), Qt::CaseSensitive);
       
  1104     cp->setSortCaseSensitivity(Qt::CaseSensitive);
       
  1105     cp->setSortCaseSensitivity(Qt::CaseInsensitive);
       
  1106     cp->setSortCaseSensitivity(Qt::CaseSensitive);
  1010     cp->sort(0, Qt::AscendingOrder);
  1107     cp->sort(0, Qt::AscendingOrder);
  1011     
  1108     
  1012     idx = cp->index(10, 0);
  1109     idx = cp->index(10, 0);
  1013     res = cp->data(idx, Qt::UserRole+1);
  1110     res = cp->data(idx, Qt::UserRole+1);
  1014     QCOMPARE(res.isValid(), true);
  1111     QCOMPARE(res.isValid(), true);
  1020 //    qWarning("i=%d",res.toInt());
  1117 //    qWarning("i=%d",res.toInt());
  1021     QCOMPARE(res.toInt()%2, 1);
  1118     QCOMPARE(res.toInt()%2, 1);
  1022     
  1119     
  1023     cp->setSortLocaleAware(true);
  1120     cp->setSortLocaleAware(true);
  1024     QCOMPARE(cp->isSortLocaleAware(), true);
  1121     QCOMPARE(cp->isSortLocaleAware(), true);
       
  1122     cp->setSortLocaleAware(true);
  1025     cp->setSortLocaleAware(false);
  1123     cp->setSortLocaleAware(false);
  1026     QCOMPARE(cp->isSortLocaleAware(), false);
  1124     QCOMPARE(cp->isSortLocaleAware(), false);
  1027         
  1125         
  1028     QString s = QString("AAA");
  1126     QString s = QString("AAA");
  1029     cp->setDynamicSortFilter(true);
  1127     cp->setDynamicSortFilter(true);
  1030     QCOMPARE(cp->dynamicSortFilter(), true);
  1128     QCOMPARE(cp->dynamicSortFilter(), true);
       
  1129     cp->setDynamicSortFilter(true);
  1031     cp->setSortRole(Qt::DisplayRole);
  1130     cp->setSortRole(Qt::DisplayRole);
  1032     cp->setSortCaseSensitivity(Qt::CaseSensitive);
  1131     cp->setSortCaseSensitivity(Qt::CaseSensitive);
  1033     dph->testInsertItem(10, QPair< QVariant, int >(s, Qt::DisplayRole), false);
  1132     dph->testInsertItem(10, QPair< QVariant, int >(s, Qt::DisplayRole), false);
  1034     idx = cp->index(0, 0);
  1133     idx = cp->index(0, 0);
  1035     res = cp->data(idx, Qt::DisplayRole);
  1134     res = cp->data(idx, Qt::DisplayRole);
  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);