hgcacheproxymodel/tsrc/unit/test_hgcacheproxydatamodel.cpp
changeset 8 15f034b8a3b5
parent 3 c863538fcbb6
child 7 5ebec3429918
equal deleted inserted replaced
5:4fa04caf0f43 8:15f034b8a3b5
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 *  Version     : %version: 8 %
    16 *  Version     : %version: 10 %
    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 
    23 #include "bmhelper.h"
    23 #include "bmhelper.h"
    24 
    24 
    25 #include "dataproviderhelper.h"
    25 #include "dataproviderhelper.h"
    26 #include "cacheproxyhelper.h"
    26 #include "cacheproxyhelper.h"
    27 #include <QtDebug>
    27 #include <QtDebug>
       
    28 #include <HbIcon>
       
    29 #include <QIcon>
       
    30 #include <QImage>
       
    31 #include <QPixmap>
       
    32 
    28 
    33 
    29 // ======== MEMBER FUNCTIONS ========
    34 // ======== MEMBER FUNCTIONS ========
    30 void TestCacheProxy::testQAbstractItemModel(QAbstractItemModel* model, int rows, int columns)
    35 void TestCacheProxy::testQAbstractItemModel(QAbstractItemModel* model, int rows, int columns)
    31 {
    36 {
    32     QVERIFY(model != 0);
    37     QVERIFY(model != 0);
    82     
    87     
    83     idx = model->parent(idx);
    88     idx = model->parent(idx);
    84     QVERIFY(idx.isValid() == false);
    89     QVERIFY(idx.isValid() == false);
    85     QVERIFY(model->columnCount() == columns);
    90     QVERIFY(model->columnCount() == columns);
    86     QVERIFY(model->rowCount() == rows);
    91     QVERIFY(model->rowCount() == rows);
    87     
    92         
    88 //    QVERIFY(model->hasChildren() == false);
       
    89 //    QVERIFY(model->headerData(0, Qt::Horizontal).isValid == false);
       
    90     
       
    91 }
    93 }
    92 
    94 
    93 void TestCacheProxy::initTestCase()
    95 void TestCacheProxy::initTestCase()
    94 {
    96 {
    95     bm = 0;
    97     bm = 0;
   382     QVERIFY(bmh->isIntergal(bufferSize));
   384     QVERIFY(bmh->isIntergal(bufferSize));
   383 //    totalsize--; //no item remove since totalsize+200 is outside
   385 //    totalsize--; //no item remove since totalsize+200 is outside
   384     QCOMPARE(bmh->totalSize(), totalsize);
   386     QCOMPARE(bmh->totalSize(), totalsize);
   385     
   387     
   386     
   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     
   387     //insert
   407     //insert
   388     
   408     
   389     bm->setPosition(0);
   409     bm->setPosition(0);
   390     bm->aboutToInsertItem(0);
   410     bm->aboutToInsertItem(0);
   391     bmh->insert(0); 
   411     bmh->insert(0); 
   438     bmh->insert(totalsize+20); 
   458     bmh->insert(totalsize+20); 
   439     bm->insertedItem(totalsize+20);
   459     bm->insertedItem(totalsize+20);
   440     QVERIFY(bmh->isIntergal(bufferSize));
   460     QVERIFY(bmh->isIntergal(bufferSize));
   441 //    totalsize++; //no insert
   461 //    totalsize++; //no insert
   442     QCOMPARE(bmh->totalSize(), totalsize);
   462     QCOMPARE(bmh->totalSize(), totalsize);
       
   463 
       
   464     bm->setPosition(2*totalsize);
       
   465     bm->aboutToInsertItem(2*totalsize);
       
   466     bmh->insert(2*totalsize); 
       
   467     bm->insertedItem(2*totalsize);
       
   468     QVERIFY(bmh->isIntergal(bufferSize));
       
   469 //    totalsize++; //no insert
       
   470     QCOMPARE(bmh->totalSize(), totalsize);
       
   471 
   443     
   472     
   444 }
   473 }
   445 
   474 
   446 void TestCacheProxy::testBM_ResizeCache()
   475 void TestCacheProxy::testBM_ResizeCache()
   447 {
   476 {
   617 
   646 
   618     idx = dph->index(2, 0);
   647     idx = dph->index(2, 0);
   619     res = dph->data(idx, Qt::DecorationRole);
   648     res = dph->data(idx, Qt::DecorationRole);
   620     QVERIFY(res == dph->defaultIcon());    
   649     QVERIFY(res == dph->defaultIcon());    
   621     
   650     
       
   651     dph->testClearItem(2, false);
       
   652     updates = dph->getSignalDataUpdated();
       
   653     QVERIFY(updates.count() == 1); //1 update
       
   654     QVERIFY(updates[0].first == 2); //for 2
       
   655     QVERIFY(updates[0].second == 2); //for 2
       
   656     QVERIFY(dph->itemData(idx).count() == 0 ); //for 2
       
   657     
       
   658     QVERIFY(dph->itemData( dph->testCreateIndex(999999, 0)).count() == 0 );
       
   659 
       
   660     dph->testClearItem(2, true);
       
   661     updates = dph->getSignalDataUpdated();
       
   662     QVERIFY(updates.count() == 0); //no updates
       
   663     
       
   664     dph->testClearItem(-10, true);
       
   665     updates = dph->getSignalDataUpdated();
       
   666     QVERIFY(updates.count() == 0); //no updates
       
   667 
   622     idx = dph->index(3, 0);
   668     idx = dph->index(3, 0);
   623     res = dph->data(idx, Qt::DecorationRole);
   669     res = dph->data(idx, Qt::DecorationRole);
   624     QVERIFY(res == dph->defaultIcon());    
   670     QVERIFY(res == dph->defaultIcon());    
   625     dph->registerObserver(NULL);
   671     dph->registerObserver(NULL);
   626     dph->request(list);
   672     dph->request(list);
   836     idx = dph->index(-10,0);
   882     idx = dph->index(-10,0);
   837     it = dph->itemData(idx);
   883     it = dph->itemData(idx);
   838     
   884     
   839     res = dph->data(idx, Qt::DisplayRole);
   885     res = dph->data(idx, Qt::DisplayRole);
   840     QCOMPARE(res.isValid(), false);
   886     QCOMPARE(res.isValid(), false);
   841     
   887 
   842 }
   888 }
   843 
   889 
   844 void TestCacheProxy::testDP_QPixmapPool()
   890 void TestCacheProxy::testDP_QPixmapPool()
   845 {
   891 {
   846     dph = new DataProviderHelper(100);
   892     dph = new DataProviderHelper(100);
   883     dph->testCreateIcon(4, pix);
   929     dph->testCreateIcon(4, pix);
   884     dph->testCreateIcon(6, pix);
   930     dph->testCreateIcon(6, pix);
   885     dph->resizeQPixmapPool(1);
   931     dph->resizeQPixmapPool(1);
   886     res = dph->testCreateIcon(10, pix);
   932     res = dph->testCreateIcon(10, pix);
   887     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);
   888 }
   988 }
   889 
   989 
   890 void TestCacheProxy::testCP_QAbstractItemModel()
   990 void TestCacheProxy::testCP_QAbstractItemModel()
   891 {
   991 {
   892     cp = new HgCacheProxyModel();
   992     cp = new HgCacheProxyModel();
   910     list.append( QPair< QVariant, int >(s, Qt::DisplayRole) );
  1010     list.append( QPair< QVariant, int >(s, Qt::DisplayRole) );
   911     dph->testNewItem(&list, false);
  1011     dph->testNewItem(&list, false);
   912     
  1012     
   913     dph->testRemoveItems(0, 1);//should remove item
  1013     dph->testRemoveItems(0, 1);//should remove item
   914 
  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     
   915 }
  1074 }
   916 
  1075 
   917 void TestCacheProxy::testCP_SignalsForward()
  1076 void TestCacheProxy::testCP_SignalsForward()
   918 {
  1077 {
   919     cp = new HgCacheProxyModel();
  1078     cp = new HgCacheProxyModel();
   957     dph->resetModel();
  1116     dph->resetModel();
   958     QVERIFY(cph->getSignalModelAboutToBeReset() == true);
  1117     QVERIFY(cph->getSignalModelAboutToBeReset() == true);
   959     QVERIFY(cph->getSignalModelReset() == true);
  1118     QVERIFY(cph->getSignalModelReset() == true);
   960     QVERIFY(cp->columnCount() == 1);
  1119     QVERIFY(cp->columnCount() == 1);
   961     QVERIFY(cp->rowCount() == 1000);    
  1120     QVERIFY(cp->rowCount() == 1000);    
       
  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 
   962     
  1182     
   963 }
  1183 }
   964 
  1184 
   965 void TestCacheProxy::testCP_ResizeCache()
  1185 void TestCacheProxy::testCP_ResizeCache()
   966 {
  1186 {
  1063     QCOMPARE(dph->getLastRequest().count(), 11);
  1283     QCOMPARE(dph->getLastRequest().count(), 11);
  1064     
  1284     
  1065     cp->setDataProvider(NULL, 50, 20);
  1285     cp->setDataProvider(NULL, 50, 20);
  1066     res = cp->data(idx, v);
  1286     res = cp->data(idx, v);
  1067     QCOMPARE(res.isValid(), false);
  1287     QCOMPARE(res.isValid(), false);
       
  1288     cp->request(0, 100, HgBufferManagerObserver::HgRequestOrderAscending);   
       
  1289     QCOMPARE(dph->getLastRequest().count(), 0);    
       
  1290     cp->release(0, 100);
       
  1291     QCOMPARE(dph->getLastRelease().count(), 0);
  1068 
  1292 
  1069 }
  1293 }
  1070 
  1294 
  1071 void TestCacheProxy::testCP_Sort()
  1295 void TestCacheProxy::testCP_Sort()
  1072 {
  1296 {